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_scs_entries.c
T
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

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;
}