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
2022-02-12 10:44:47 +01:00

73 lines
1.5 KiB
C

#include "mmr_can.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(scsId, receiverId);
if (timer == NULL) {
return false;
}
timer->scsId = scsId;
timer->receiverId = receiverId;
timer->counter = currentTime;
return true;
}
bool MMR_CAN_GetTimerSCS(RTRresponse *rtrResponse, TimerRange currentTime, TimerRange thresholdDelay) {
MmrTimerSCS *timer = findTimer(
rtrResponse->scsId,
rtrResponse->receiverId
);
if (timer == NULL) {
return false;
}
if (currentTime - timer->counter >= thresholdDelay) {
rtrResponse->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 && arr_timer->receiverId == receiverId) {
return timer;
}
}
return NULL;
}