@@ -216,11 +216,13 @@ template <typename SPI, typename CS, typename INT>
216
216
bool
217
217
modm::Mcp2515<SPI, CS, INT>::sendMessage(const can::Message& message)
218
218
{
219
+ bool success = true ;
219
220
if (not modm_assert_continue_ignore (txQueue.push (message), " mcp2515.can.tx" ,
220
221
" CAN transmit software buffer overflowed!" , 1 )) {
221
- return false ;
222
+ // / buffer full, could not send
223
+ success = false ;
222
224
}
223
- return true ;
225
+ return success ;
224
226
}
225
227
226
228
// ----------------------------------------------------------------------------
@@ -297,8 +299,9 @@ modm::Mcp2515<SPI, CS, INT>::update(){
297
299
// / check if device accepts messages and start emptying the transmit queue if not empty
298
300
if (txQueue.isNotEmpty ())
299
301
{
300
- hasSend_ = RF_CALL (mcp2515SendMessage (txQueue.get ()));
301
- txQueue.pop ();
302
+ if (RF_CALL (mcp2515SendMessage (txQueue.get ()))){
303
+ txQueue.pop ();
304
+ }
302
305
}
303
306
RF_END ();
304
307
}
@@ -336,12 +339,10 @@ modm::Mcp2515<SPI, CS, INT>::mcp2515IsReadyToSend(uint8_t status)
336
339
// all buffers currently in use
337
340
ready = false ;
338
341
}
339
-
340
342
return ready;
341
343
}
342
344
343
345
// ----------------------------------------------------------------------------
344
-
345
346
template <typename SPI, typename CS, typename INT>
346
347
modm::ResumableResult<bool >
347
348
modm::Mcp2515<SPI, CS, INT>::mcp2515SendMessage(const can::Message& message)
@@ -351,52 +352,55 @@ modm::Mcp2515<SPI, CS, INT>::mcp2515SendMessage(const can::Message& message)
351
352
352
353
statusBufferS_ = RF_CALL (readStatus (READ_STATUS));
353
354
354
- // / wait for ready to send status flags
355
- RF_WAIT_UNTIL (mcp2515IsReadyToSend (statusBufferS_));
356
-
357
- if ((statusBufferS_ & TXB0CNTRL_TXREQ) == 0 )
358
- {
359
- addressBufferS_ = 0x00 ; // TXB0SIDH
360
- } else if ((statusBufferS_ & TXB1CNTRL_TXREQ) == 0 )
361
- {
362
- addressBufferS_ = 0x02 ; // TXB1SIDH
363
- } else if ((statusBufferS_ & TXB2CNTRL_TXREQ) == 0 )
364
- {
365
- addressBufferS_ = 0x04 ; // TXB2SIDH
366
- } else
367
- {
368
- // all buffer are in use => could not send the message
369
- }
355
+ addressBufferS_ = static_cast <uint8_t >(false );
370
356
371
- if (addressBufferS_ == 0x00 || addressBufferS_ == 0x02 || addressBufferS_ == 0x04 )
357
+ // /// send if ready, else return that nothing was sent
358
+ if (mcp2515IsReadyToSend (statusBufferS_))
372
359
{
373
- RF_WAIT_UNTIL (this ->acquireMaster ());
374
- chipSelect.reset ();
375
- RF_CALL (spi.transfer (WRITE_TX | addressBufferS_));
376
- RF_CALL (writeIdentifier (message.identifier , message.flags .extended ));
377
-
378
- // if the message is a rtr-frame, is has a length but no attached data
379
- if (message.flags .rtr )
360
+ if ((statusBufferS_ & TXB0CNTRL_TXREQ) == 0 )
380
361
{
381
- RF_CALL (spi.transfer (MCP2515_RTR | message.length ));
362
+ addressBufferS_ = 0x00 ; // TXB0SIDH
363
+ } else if ((statusBufferS_ & TXB1CNTRL_TXREQ) == 0 )
364
+ {
365
+ addressBufferS_ = 0x02 ; // TXB1SIDH
366
+ } else if ((statusBufferS_ & TXB2CNTRL_TXREQ) == 0 )
367
+ {
368
+ addressBufferS_ = 0x04 ; // TXB2SIDH
382
369
} else
383
370
{
384
- RF_CALL (spi.transfer (message.length ));
371
+ // all buffer are in use => could not send the message
372
+ }
385
373
386
- for (i_ = 0 ; i_ < message.length ; ++i_) {
387
- RF_CALL (spi.transfer (message.data [i_]));
374
+ if (addressBufferS_ == 0x00 || addressBufferS_ == 0x02 || addressBufferS_ == 0x04 )
375
+ {
376
+ RF_WAIT_UNTIL (this ->acquireMaster ());
377
+ chipSelect.reset ();
378
+ RF_CALL (spi.transfer (WRITE_TX | addressBufferS_));
379
+ RF_CALL (writeIdentifier (message.identifier , message.flags .extended ));
380
+
381
+ // if the message is a rtr-frame, is has a length but no attached data
382
+ if (message.flags .rtr )
383
+ {
384
+ RF_CALL (spi.transfer (MCP2515_RTR | message.length ));
385
+ } else
386
+ {
387
+ RF_CALL (spi.transfer (message.length ));
388
+
389
+ for (i_ = 0 ; i_ < message.length ; ++i_) {
390
+ RF_CALL (spi.transfer (message.data [i_]));
391
+ }
388
392
}
393
+ delayS_.restart (1ms);
394
+ chipSelect.set ();
395
+ RF_WAIT_UNTIL (delayS_.isExpired ());
396
+
397
+ // send message via RTS command
398
+ chipSelect.reset ();
399
+ addressBufferS_ = (addressBufferS_ == 0 ) ? 1 : addressBufferS_; // 0 2 4 => 1 2 4
400
+ RF_CALL (spi.transfer (RTS | addressBufferS_));
401
+ RF_WAIT_UNTIL (this ->releaseMaster ());
402
+ chipSelect.set ();
389
403
}
390
- delayS_.restart (1ms);
391
- chipSelect.set ();
392
- RF_WAIT_UNTIL (delayS_.isExpired ());
393
-
394
- // send message via RTS command
395
- chipSelect.reset ();
396
- addressBufferS_ = (addressBufferS_ == 0 ) ? 1 : addressBufferS_; // 0 2 4 => 1 2 4
397
- RF_CALL (spi.transfer (RTS | addressBufferS_));
398
- RF_WAIT_UNTIL (this ->releaseMaster ());
399
- chipSelect.set ();
400
404
}
401
405
402
406
RF_END_RETURN (static_cast <bool >(addressBufferS_));
0 commit comments