This repository has been archived on 2026-02-22. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
can/Src/mmr_can_events.c
Stefano Calabretti 4d5c1934a4 Scs (#3)
* Add send scs

* Create scs dict

* Fix compilation errors

* Fix compile error

* Change default include

* Add Timer SCS manager

* Remove unused files

* Fix bugs

* Add documentation

* Add SCS manager

bozza

* Refactor

* Use same naming convention

* Add tick provider

* Update header

* Fix header bit translation

* Test HandleNext OK

* Remove linting

* Remove indents

* Add documentation

* Improve docs

* Remove pointer

* Remove mailbox

* Remove useless comment

* Add newline

* Fix compile errors

* Separate scs entries from manager

* Refactor

* Fix include guards

Co-authored-by: nicolagutierrez <nicolagutierrez.ng@gmail.com>
2022-02-23 21:08:47 +01:00

68 lines
1.5 KiB
C

#include "mmr_can.h"
#include "mmr_can_events.h"
static const MmrCanEventList *_rxEvents = NULL;
static void __handleCanRxInterrupt(CanHandle *hcan);
static void __invokeAll(const MmrCanEventList *events, const MmrCanMessage *event);
static void __maybeInvoke(const MmrCanEventHandler handler, const MmrCanMessage *event);
HalStatus MMR_CAN_InitRxHandlers(CanHandle *hcan, const MmrCanEventList *rxEvents) {
_rxEvents = rxEvents;
return HAL_CAN_ActivateNotification(hcan, MMR_CAN_RX_INTERRUPT);
}
/**
* @brief
* Stores the message inside a byte buffer,
* and then sends it to every registered event handler
*/
static void __handleCanRxInterrupt(CanHandle *hcan) {
static CanRxBuffer buffer = {};
static MmrCanMessage event = {
.store = buffer,
};
MMR_CAN_Receive(hcan, &event);
__invokeAll(_rxEvents, &event);
}
static void __invokeAll(
const MmrCanEventList *events,
const MmrCanMessage *event
) {
if (!events) {
return;
}
short i;
for (i = 0; i < events->count; i++) {
__maybeInvoke(events->handlers[i], event);
}
}
static always_inline void __maybeInvoke(
const MmrCanEventHandler handler,
const MmrCanMessage *event
) {
if (handler) {
handler(event);
}
}
#if MMR_CAN_RX_FIFO == CAN_RX_FIFO0
void HAL_CAN_RxFifo0MsgPendingCallback(CanHandle *hcan) {
__handleCanRxInterrupt(hcan);
}
#elif MMR_CAN_RX_FIFO == CAN_RX_FIFO1
void HAL_CAN_RxFifo1MsgPendingCallback(CanHandle *hcan) {
__handleCanRxInterrupt(hcan);
}
#endif