Refactor
This commit is contained in:
+8
-1
@@ -14,7 +14,7 @@
|
|||||||
#include "mmr_can_types.h"
|
#include "mmr_can_types.h"
|
||||||
#include "mmr_can_optimize.h"
|
#include "mmr_can_optimize.h"
|
||||||
#include "mmr_can_binary_literals.h"
|
#include "mmr_can_binary_literals.h"
|
||||||
#include "mmr_can_scs_manager.h"
|
#include "mmr_can_scs.h"
|
||||||
|
|
||||||
#ifndef MMR_CAN_RX_FIFO
|
#ifndef MMR_CAN_RX_FIFO
|
||||||
#define MMR_CAN_RX_FIFO CAN_RX_FIFO0
|
#define MMR_CAN_RX_FIFO CAN_RX_FIFO0
|
||||||
@@ -182,6 +182,13 @@ extern MmrCanTickProvider __mmr_can_tickProvider;
|
|||||||
*/
|
*/
|
||||||
void MMR_CAN_SetTickProvider(MmrCanTickProvider tickProvider);
|
void MMR_CAN_SetTickProvider(MmrCanTickProvider tickProvider);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
* Returns the current tick by calling the
|
||||||
|
* configured tick provider.
|
||||||
|
*/
|
||||||
|
uint32_t MMR_CAN_GetCurrentTick();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
* Configures the filters with the default configuration
|
* Configures the filters with the default configuration
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ void MMR_CAN_SetTickProvider(MmrCanTickProvider tickProvider) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t MMR_CAN_GetCurrentTick() {
|
||||||
|
return __mmr_can_tickProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
HalStatus MMR_CAN_BasicSetupAndStart(CanHandle *hcan) {
|
HalStatus MMR_CAN_BasicSetupAndStart(CanHandle *hcan) {
|
||||||
return
|
return
|
||||||
MMR_CAN_FilterConfigDefault(hcan) |
|
MMR_CAN_FilterConfigDefault(hcan) |
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
#include "mmr_can_scs_manager.h"
|
#include "mmr_can_scs.h"
|
||||||
|
|
||||||
|
#define EMPTY_HEADER ((MmrCanHeader){})
|
||||||
|
#define EMPTY_ENTRY ((MmrCanScsEntry){})
|
||||||
|
|
||||||
static MmrCanScsEntry __scsEntries[MMR_CAN_SCS_ENTRIES_COUNT];
|
static MmrCanScsEntry __scsEntries[MMR_CAN_SCS_ENTRIES_COUNT];
|
||||||
|
|
||||||
@@ -15,14 +18,14 @@ MmrCanScsEntry* MMR_CAN_GetNextScsEntry() {
|
|||||||
|
|
||||||
|
|
||||||
MmrCanScsEntry* MMR_CAN_PutScsEntry(MmrCanHeader header) {
|
MmrCanScsEntry* MMR_CAN_PutScsEntry(MmrCanHeader header) {
|
||||||
MmrCanScsEntry *entry = findEntry((MmrCanHeader){});
|
MmrCanScsEntry *entry = MMR_CAN_FindScsEntry(EMPTY_HEADER);
|
||||||
if (entry == NULL) {
|
if (entry == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
*entry = (MmrCanScsEntry){
|
*entry = (MmrCanScsEntry){
|
||||||
.header = header,
|
.header = header,
|
||||||
.counter = getCurrentTime(),
|
.counter = MMR_CAN_GetCurrentTick(),
|
||||||
};
|
};
|
||||||
|
|
||||||
return entry;
|
return entry;
|
||||||
@@ -30,12 +33,12 @@ MmrCanScsEntry* MMR_CAN_PutScsEntry(MmrCanHeader header) {
|
|||||||
|
|
||||||
|
|
||||||
MmrCanScsEntry* MMR_CAN_ClearScsEntry(MmrCanHeader header) {
|
MmrCanScsEntry* MMR_CAN_ClearScsEntry(MmrCanHeader header) {
|
||||||
MmrCanScsEntry *entry = findEntry(header);
|
MmrCanScsEntry *entry = MMR_CAN_FindScsEntry(header);
|
||||||
if (entry == NULL) {
|
if (entry == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
*entry = (MmrCanScsEntry){};
|
*entry = EMPTY_ENTRY;
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "mmr_can_scs_manager.h"
|
#include "mmr_can_scs.h"
|
||||||
|
|
||||||
static void maybeIncrementRtr(MmrCanScsEntry *entry);
|
static void maybeIncrementRtr(MmrCanScsEntry *entry);
|
||||||
static TimerRange getCurrentTime();
|
|
||||||
static HalStatus sendScs(CanHandle *hcan, MmrCanHeader header);
|
static HalStatus sendScs(CanHandle *hcan, MmrCanHeader header);
|
||||||
static MmrCanScsCheckResult checkScs(MmrCanScsEntry *entry);
|
static MmrCanScsCheckResult checkScs(MmrCanScsEntry *entry);
|
||||||
|
|
||||||
@@ -64,7 +63,7 @@ HalStatus MMR_CAN_HandleNextScs(CanHandle *hcan) {
|
|||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry->counter = getCurrentTime();
|
entry->counter = MMR_CAN_GetCurrentTick();
|
||||||
return sendScs(hcan, entry->header);
|
return sendScs(hcan, entry->header);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,14 +86,8 @@ static MmrCanScsCheckResult checkScs(MmrCanScsEntry *entry) {
|
|||||||
MMR_CAN_SCS_CHECK_OK;
|
MMR_CAN_SCS_CHECK_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static TimerRange getCurrentTime() {
|
|
||||||
return __mmr_can_tickProvider();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void maybeIncrementRtr(MmrCanScsEntry *entry) {
|
static void maybeIncrementRtr(MmrCanScsEntry *entry) {
|
||||||
TimerRange now = getCurrentTime();
|
TimerRange now = MMR_CAN_GetCurrentTick();
|
||||||
TimerRange delay = now - entry->counter;
|
TimerRange delay = now - entry->counter;
|
||||||
|
|
||||||
if (delay >= MMR_CAN_MAX_TIMEOUT) {
|
if (delay >= MMR_CAN_MAX_TIMEOUT) {
|
||||||
|
|||||||
Reference in New Issue
Block a user