feat(can): tx callback

This commit is contained in:
CarlWachter 2024-10-02 10:11:34 +02:00
parent 6c92ad7735
commit 0b24d78835
2 changed files with 18 additions and 1 deletions

View File

@ -79,6 +79,11 @@ namespace sta
*/
void canCallback(uint32_t fifo);
/**
* @brief Notify the system that a message was transmitted. Used to avoid overwriting the message buffer.
*/
void txCallback();
void init() override;
void func() override;

View File

@ -35,7 +35,7 @@ namespace sta
void CanBus::func()
{
messageEvent.clear(STA_RTOS_CAN_ANY);
uint32_t flags = messageEvent.wait(STA_RTOS_CAN_ANY, osWaitForever);
uint32_t flags = messageEvent.wait(STA_RTOS_CAN_FLAG_SYS_QUEUED | STA_RTOS_CAN_FLAG_MSG_AVAIL, osWaitForever);
if (flags != static_cast<uint32_t>(osErrorTimeout))
{
@ -47,6 +47,8 @@ namespace sta
CanSysMsg msg;
while (CanBus::_instance->getCanBusMsg(&msg, 0))
{
// wait for the mailbox to be free, but only for a very short time
messageEvent.wait(STA_RTOS_TX_MAILBOX_COMPLETE, 1);
canBus_.send(msg);
}
}
@ -132,6 +134,11 @@ namespace sta
return (canBusSysQueue_.get(msg, timeout));
}
void CanBus::txCallback()
{
messageEvent.set(STA_RTOS_TX_MAILBOX_COMPLETE);
}
CanBus *CanBus::_instance = nullptr;
RtosEvent CanBus::messageEvent;
@ -147,6 +154,11 @@ namespace sta
sta::tacos::CanBus::instance()->canCallback(fifo);
}
void CanBus_TxMailboxCompleteCallback()
{
sta::tacos::CanBus::instance()->txCallback();
}
namespace tacos
{
STA_WEAK