4d5c1934a4
* 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>
61 lines
1.2 KiB
C
61 lines
1.2 KiB
C
#include "mmr_can_scs.h"
|
|
|
|
#define EMPTY_HEADER ((MmrCanHeader){})
|
|
#define EMPTY_ENTRY ((MmrCanScsEntry){})
|
|
|
|
static MmrCanScsEntry __scsEntries[MMR_CAN_SCS_ENTRIES_COUNT];
|
|
|
|
|
|
MmrCanScsEntry* MMR_CAN_GetNextScsEntry() {
|
|
static int counter = 0;
|
|
|
|
MmrCanScsEntry *entry = __scsEntries + counter;
|
|
counter++;
|
|
counter %= MMR_CAN_SCS_ENTRIES_COUNT;
|
|
|
|
return entry;
|
|
}
|
|
|
|
|
|
MmrCanScsEntry* MMR_CAN_PutScsEntry(MmrCanHeader header) {
|
|
MmrCanScsEntry *entry = MMR_CAN_FindScsEntry(EMPTY_HEADER);
|
|
if (entry == NULL) {
|
|
return NULL;
|
|
}
|
|
|
|
*entry = (MmrCanScsEntry){
|
|
.header = header,
|
|
.counter = MMR_CAN_GetCurrentTick(),
|
|
};
|
|
|
|
return entry;
|
|
}
|
|
|
|
|
|
MmrCanScsEntry* MMR_CAN_ClearScsEntry(MmrCanHeader header) {
|
|
MmrCanScsEntry *entry = MMR_CAN_FindScsEntry(header);
|
|
if (entry == NULL) {
|
|
return NULL;
|
|
}
|
|
|
|
*entry = EMPTY_ENTRY;
|
|
return entry;
|
|
}
|
|
|
|
|
|
MmrCanScsEntry* MMR_CAN_FindScsEntry(MmrCanHeader header) {
|
|
uint32_t target = MMR_CAN_HeaderToBits(header);
|
|
uint32_t i = 0;
|
|
|
|
for (; i < MMR_CAN_SCS_ENTRIES_COUNT; i++) {
|
|
MmrCanScsEntry *entry = __scsEntries + i;
|
|
uint32_t curr = MMR_CAN_HeaderToBits(entry->header);
|
|
|
|
if (curr == target) {
|
|
return entry;
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|