From f49cd47e8316a309869b4ae4c7c6527c726906d1 Mon Sep 17 00:00:00 2001 From: knmcguire Date: Tue, 9 Feb 2021 14:11:16 +0100 Subject: [PATCH] (#679) moved timer functions to lighthouse.c for unit tests --- src/deck/drivers/src/lighthouse.c | 15 +++- .../interface/lighthouse/lighthouse_core.h | 2 + src/modules/src/lighthouse/lighthouse_core.c | 75 +++++++++---------- .../src/lighthouse/test_lighthouse_core.c | 6 +- 4 files changed, 56 insertions(+), 42 deletions(-) diff --git a/src/deck/drivers/src/lighthouse.c b/src/deck/drivers/src/lighthouse.c index bce9ae5ee2..502ce3f43b 100644 --- a/src/deck/drivers/src/lighthouse.c +++ b/src/deck/drivers/src/lighthouse.c @@ -33,15 +33,20 @@ #include "deck.h" #include "param.h" +#include "stm32fxxx.h" #include "config.h" #include "FreeRTOS.h" #include "task.h" +#include "timers.h" #include "lighthouse_core.h" +// LED timer +static StaticTimer_t timerBuffer; +#define FIFTH_SECOND 200 +static void ledTimerHandle(xTimerHandle timer); static bool isInit = false; - // lighthouseBaseStationsGeometry has been moved to lighthouse_core.c static void lighthouseInit(DeckInfo *info) @@ -54,10 +59,18 @@ static void lighthouseInit(DeckInfo *info) xTaskCreate(lighthouseCoreTask, LIGHTHOUSE_TASK_NAME, 2*configMINIMAL_STACK_SIZE, NULL, LIGHTHOUSE_TASK_PRI, NULL); + + xTimerHandle timer; + timer = xTimerCreateStatic("ledTimer", M2T(FIFTH_SECOND), pdTRUE, + NULL, ledTimerHandle, &timerBuffer); + xTimerStart(timer, M2T(0)); isInit = true; } +static void ledTimerHandle(xTimerHandle timer) { + ledTimer(); +} static const DeckDriver lighthouse_deck = { .vid = 0xBC, diff --git a/src/modules/interface/lighthouse/lighthouse_core.h b/src/modules/interface/lighthouse/lighthouse_core.h index ba6d2ffe21..2287a1be6d 100644 --- a/src/modules/interface/lighthouse/lighthouse_core.h +++ b/src/modules/interface/lighthouse/lighthouse_core.h @@ -79,3 +79,5 @@ typedef enum { * @param green State of the green LED */ void lighthouseCoreSetLeds(lighthouseCoreLedState_t red, lighthouseCoreLedState_t orange, lighthouseCoreLedState_t green); + +void ledTimer(); diff --git a/src/modules/src/lighthouse/lighthouse_core.c b/src/modules/src/lighthouse/lighthouse_core.c index 02ca8665e0..5494aee987 100644 --- a/src/modules/src/lighthouse/lighthouse_core.c +++ b/src/modules/src/lighthouse/lighthouse_core.c @@ -28,7 +28,6 @@ #include "stm32fxxx.h" #include "FreeRTOS.h" #include "task.h" -#include "timers.h" #include #include @@ -92,6 +91,7 @@ static uint16_t baseStationActiveMap; // An overall system status indicating if data is sent to the estimator static lhSystemStatus_t systemStatus; static lhSystemStatus_t systemStatusWs; +static lhSystemStatus_t ledInternalStatus = statusToEstimator; static const uint32_t SYSTEM_STATUS_UPDATE_INTERVAL = FIFTH_SECOND; static uint32_t nextUpdateTimeOfSystemStatus = 0; @@ -150,46 +150,43 @@ static baseStationGeometry_t geoBuffer; TESTABLE_STATIC void initializeGeoDataFromStorage(); static lighthouseCalibration_t calibBuffer; TESTABLE_STATIC void initializeCalibDataFromStorage(); +static bool deckIsFlashed = false; -// LED timer -static xTimerHandle timer; -static StaticTimer_t timerBuffer; -static lhSystemStatus_t ledInternalStatus = statusToEstimator; - -static void ledTimer(xTimerHandle timer) -{ - switch (systemStatus) - { - case statusNotReceiving: - if(ledInternalStatus != systemStatus) - { - lighthouseCoreSetLeds(lh_led_off, lh_led_on, lh_led_off); - ledInternalStatus = systemStatus; - } - break; - case statusMissingData: - if(ledInternalStatus != systemStatus) - { - lighthouseCoreSetLeds(lh_led_off, lh_led_slow_blink, lh_led_off); - ledInternalStatus = systemStatus; - } - break; - case statusToEstimator: - if(ledInternalStatus != systemStatus) - { - lighthouseCoreSetLeds(lh_led_off, lh_led_off, lh_led_on); - ledInternalStatus = systemStatus; - } - break; - default: - ASSERT(false); - } -} void lighthouseCoreInit() { lighthousePositionEstInit(); - timer = xTimerCreateStatic("ledTimer", M2T(FIFTH_SECOND), pdTRUE, - NULL, ledTimer, &timerBuffer); +} + +void ledTimer() +{ + if (deckIsFlashed){ + switch (systemStatus) + { + case statusNotReceiving: + if(ledInternalStatus != systemStatus) + { + lighthouseCoreSetLeds(lh_led_off, lh_led_on, lh_led_off); + ledInternalStatus = systemStatus; + } + break; + case statusMissingData: + if(ledInternalStatus != systemStatus) + { + lighthouseCoreSetLeds(lh_led_off, lh_led_slow_blink, lh_led_off); + ledInternalStatus = systemStatus; + } + break; + case statusToEstimator: + if(ledInternalStatus != systemStatus) + { + lighthouseCoreSetLeds(lh_led_off, lh_led_off, lh_led_on); + ledInternalStatus = systemStatus; + } + break; + default: + ASSERT(false); + } + } } TESTABLE_STATIC bool getUartFrameRaw(lighthouseUartFrame_t *frame) { @@ -449,10 +446,10 @@ void lighthouseCoreTask(void *param) { initializeCalibDataFromStorage(); lighthouseDeckFlasherCheckVersionAndBoot(); + deckIsFlashed = true; - vTaskDelay(M2T(100)); - xTimerStart(timer, M2T(0)); + vTaskDelay(M2T(100)); memset(&bsIdentificationData, 0, sizeof(bsIdentificationData)); diff --git a/test/modules/src/lighthouse/test_lighthouse_core.c b/test/modules/src/lighthouse/test_lighthouse_core.c index 3fe3c9333d..63ab855f96 100644 --- a/test/modules/src/lighthouse/test_lighthouse_core.c +++ b/test/modules/src/lighthouse/test_lighthouse_core.c @@ -35,7 +35,7 @@ initializeCalibDataFromStorage(); // Dummy mocks timer uint32_t xTaskGetTickCount() {return 0;} void vTaskDelay(const uint32_t ignore) {} -struct tmrTimerControl; +/*struct tmrTimerControl; typedef struct tmrTimerControl * TimerHandle_t; int timerBuffer; int timer; @@ -50,7 +50,9 @@ short xTimerGenericCommand( TimerHandle_t xTimer, const short xCommandID, const uint32_t xOptionalValue, short * const pxHigherPriorityTaskWoken, - const uint32_t xTicksToWait ) {return 0;} + const uint32_t xTicksToWait ) {return 0;}*/ +void initLedTimer() {} +void startLedTimer() {} static int nrOfCallsToStorageFetchForCalib = 0;