Skip to content

Commit

Permalink
(#679) moved timer functions to lighthouse.c for unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
knmcguire committed Feb 9, 2021
1 parent ea72bd8 commit f49cd47
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 42 deletions.
15 changes: 14 additions & 1 deletion src/deck/drivers/src/lighthouse.c
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/modules/interface/lighthouse/lighthouse_core.h
Expand Up @@ -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();
75 changes: 36 additions & 39 deletions src/modules/src/lighthouse/lighthouse_core.c
Expand Up @@ -28,7 +28,6 @@
#include "stm32fxxx.h"
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"

#include <math.h>
#include <stdbool.h>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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));

Expand Down
6 changes: 4 additions & 2 deletions test/modules/src/lighthouse/test_lighthouse_core.c
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit f49cd47

Please sign in to comment.