Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions include/canhardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ class CanHardware

CanHardware();
virtual void SetBaudrate(enum baudrates baudrate) = 0;
void Send(uint32_t canId, uint32_t data[2]) { Send(canId, data, 8); }
void Send(uint32_t canId, uint8_t data[8], uint8_t len) { Send(canId, (uint32_t*)data, len); }
virtual void Send(uint32_t canId, uint32_t data[2], uint8_t len) = 0;
void Send(uint32_t canId, uint32_t data[2]) { Send(canId, data, 8, false); }
void Send(uint32_t canId, uint8_t data[8], uint8_t len) { Send(canId, (uint32_t*)data, len, false); }
void Send(uint32_t canId, uint8_t data[8], uint8_t len, bool ext) { Send(canId, (uint32_t*)data, len, ext); }
void Send(uint32_t canId, uint32_t data[2], uint8_t len) { Send(canId, (uint32_t*)data, len, false); }
virtual void Send(uint32_t canId, uint32_t data[2], uint8_t len, bool ext) = 0;
void HandleRx(uint32_t canId, uint32_t data[2], uint8_t dlc);
bool AddCallback(CanCallback* cb);
bool RegisterUserMessage(uint32_t canId, uint32_t mask = 0);
Expand Down
2 changes: 1 addition & 1 deletion include/stm32_can.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Stm32Can: public CanHardware
public:
Stm32Can(uint32_t baseAddr, enum baudrates baudrate, bool remap = false);
void SetBaudrate(enum baudrates baudrate);
void Send(uint32_t canId, uint32_t data[2], uint8_t len);
void Send(uint32_t canId, uint32_t data[2], uint8_t len, bool ext);
void HandleTx();
void HandleMessage(int fifo);
static Stm32Can* GetInterface(int index);
Expand Down
33 changes: 25 additions & 8 deletions src/stm32_can.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,38 @@ void Stm32Can::SetBaudrate(enum baudrates baudrate)
* \return void
*
*/
void Stm32Can::Send(uint32_t canId, uint32_t data[2], uint8_t len)
void Stm32Can::Send(uint32_t canId, uint32_t data[2], uint8_t len, bool ext)
{
DISABLE_CAN_USER_INTERRUPTS();

can_disable_irq(canDev, CAN_IER_TMEIE);

if (can_transmit(canDev, canId, canId > 0x7FF, false, len, (uint8_t*)data) < 0 && sendCnt < SENDBUFFER_LEN)
if(ext)
{
/* enqueue in send buffer if all TX mailboxes are full */
sendBuffer[sendCnt].id = canId;
sendBuffer[sendCnt].len = len;
sendBuffer[sendCnt].data[0] = data[0];
sendBuffer[sendCnt].data[1] = data[1];
sendCnt++;
if (can_transmit(canDev, canId, ext, false, len, (uint8_t*)data) < 0 && sendCnt < SENDBUFFER_LEN)
{
/* enqueue in send buffer if all TX mailboxes are full */
sendBuffer[sendCnt].id = canId;
sendBuffer[sendCnt].len = len;
sendBuffer[sendCnt].data[0] = data[0];
sendBuffer[sendCnt].data[1] = data[1];
sendCnt++;
}
}
else
{
if (can_transmit(canDev, canId, canId > 0x7FF, false, len, (uint8_t*)data) < 0 && sendCnt < SENDBUFFER_LEN)
{
/* enqueue in send buffer if all TX mailboxes are full */
sendBuffer[sendCnt].id = canId;
sendBuffer[sendCnt].len = len;
sendBuffer[sendCnt].data[0] = data[0];
sendBuffer[sendCnt].data[1] = data[1];
sendCnt++;
}

}


if (sendCnt > 0)
{
Expand Down
Loading