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_timer_scs.c
T
Nicola Gutierrez 607817389c Add SCS manager
bozza
2022-02-17 17:22:27 +01:00

63 lines
1.4 KiB
C

#include "mmr_can_timer_scs.h"
static MmrTimerSCS arr_timer[MMR_SCS_NR_TIMERS];
static MmrTimerSCS* findTimer(MmrCanMessageId scsId, CanId receiverId);
void MMR_CAN_InitTimerSCS() {
for (int i = 0; i < MMR_SCS_NR_TIMERS; i++)
{
arr_timer[i].scsId = 0;
arr_timer[i].receiverId = 0;
arr_timer[i].counter = 0;
}
}
bool MMR_CAN_ClearTimerSCS(MmrCanMessageId scsId, CanId receiverId) {
MmrTimerSCS *timer = findTimer(scsId, receiverId);
if (timer == NULL) return false;
timer->scsId = 0;
timer->receiverId = 0;
timer->counter = 0;
return true;
}
bool MMR_CAN_SetTimerSCS(MmrCanMessageId scsId, CanId receiverId, TimerRange currentTime) {
MmrTimerSCS *timer = findTimer(0, 0);
if (timer == NULL) return false;
timer->scsId = scsId;
timer->receiverId = receiverId;
timer->counter = currentTime;
return true;
}
bool MMR_CAN_GetTimerSCS(MmrCanMessageId scsId, CanId receiverId, int *rtr, TimerRange currentTime, TimerRange thresholdDelay) {
MmrTimerSCS *timer = findTimer(scsId, receiverId);
if (timer == NULL) return false;
if (currentTime - timer->counter >= thresholdDelay) {
rtr++;
}
return true;
}
MmrTimerSCS* findTimer(MmrCanMessageId scsId, CanId receiverId) {
int i = 0;
for (; i < MMR_SCS_NR_TIMERS; i++) {
MmrTimerSCS *timer = arr_timer + i;
if (timer->scsId == scsId && timer->receiverId == receiverId) {
return timer;
}
}
return NULL;
}