Skip to content
Open
4 changes: 2 additions & 2 deletions obc/app/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(INCLUDES
${CMAKE_CURRENT_SOURCE_DIR}/digital_watchdog_mgr
${CMAKE_CURRENT_SOURCE_DIR}/eps_mgr
${CMAKE_CURRENT_SOURCE_DIR}/gnc_mgr
${CMAKE_CURRENT_SOURCE_DIR}/health_collector
${CMAKE_CURRENT_SOURCE_DIR}/thermal_mgr
${CMAKE_CURRENT_SOURCE_DIR}/state_mgr
${CMAKE_CURRENT_SOURCE_DIR}/telemetry_mgr
${CMAKE_CURRENT_SOURCE_DIR}/timekeeper
Expand All @@ -35,7 +35,7 @@ set(SOURCES

${CMAKE_CURRENT_SOURCE_DIR}/gnc_mgr/gnc_manager.c

${CMAKE_CURRENT_SOURCE_DIR}/health_collector/health_collector.c
${CMAKE_CURRENT_SOURCE_DIR}/thermal_mgr/thermal_mgr.c

${CMAKE_CURRENT_SOURCE_DIR}/state_mgr/state_mgr.c

Expand Down
38 changes: 37 additions & 1 deletion obc/app/modules/comms_link_mgr/comms_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
/* Comms Manager event queue config */
#define COMMS_MANAGER_QUEUE_LENGTH 10U
#define COMMS_MANAGER_QUEUE_ITEM_SIZE sizeof(comms_event_t)
#define COMMS_MANAGER_QUEUE_RX_WAIT_PERIOD pdMS_TO_TICKS(10)
#define COMMS_MANAGER_QUEUE_RX_WAIT_PERIOD pdMS_TO_TICKS(1000)
#define COMMS_MANAGER_QUEUE_TX_WAIT_PERIOD pdMS_TO_TICKS(10)

static QueueHandle_t commsQueueHandle = NULL;
Expand All @@ -61,6 +61,13 @@ static uint8_t cc1120TransmitQueueStack[CC1120_TRANSMIT_QUEUE_LENGTH * CC1120_TR
static const uint8_t TEMP_STATIC_KEY[AES_KEY_SIZE] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};

#define CC1120_TEMP_QUEUE_LENGTH 1
#define CC1120_TEMP_QUEUE_ITEM_SIZE sizeof(uint32_t)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same type mismatch as mentioned in the other comment


QueueHandle_t cc1120TempQueueHandle = NULL;
static StaticQueue_t cc1120TempQueue;
static uint8_t cc1120TempQueueStack[COMMS_MANAGER_QUEUE_LENGTH * CC1120_TEMP_QUEUE_ITEM_SIZE];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you using the queue length of the comms manager here?


/**
* @brief determines what the next Comms Manager state should be and sets it to
* that state
Expand Down Expand Up @@ -96,6 +103,13 @@ static obc_error_code_t handleEnterEmergencyState(void);
static obc_error_code_t handleEmergUplinkState(void);
/* COMMS STATE HANDLER FUNCTIONS END */

/**
* @brief Reading the temperature using driver functions and adding that temperature to
* the mailbox temperature queue
* @return error code
*/
static obc_error_code_t postCommsManagerTempQueue();

typedef obc_error_code_t (*comms_state_func_t)(void);

static const comms_state_func_t commsStateFns[] = {
Expand Down Expand Up @@ -126,6 +140,12 @@ void obcTaskInitCommsMgr(void) {
cc1120TransmitQueueStack, &cc1120TransmitQueue);
}

ASSERT((cc1120TempQueueStack != NULL) && (&cc1120TempQueue != NULL));
if (cc1120TempQueueHandle == NULL) {
cc1120TempQueueHandle = xQueueCreateStatic(CC1120_TEMP_QUEUE_LENGTH, CC1120_TEMP_QUEUE_ITEM_SIZE,
cc1120TempQueueStack, &cc1120TempQueue);
}

// TODO: Implement a key exchange algorithm instead of using Pre-Shared/static
// key
initializeAesCtx(TEMP_STATIC_KEY);
Expand Down Expand Up @@ -299,6 +319,21 @@ obc_error_code_t sendToFrontCommsManagerQueue(comms_event_t *event) {
return OBC_ERR_CODE_QUEUE_FULL;
}

static obc_error_code_t postCommsManagerTempQueue() {
float value = 0.0f; // dummy value, replace with actual temp reading function
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Label this as a TODO: and add it to outstanding changes

if (xQueueOverwrite(cc1120TempQueueHandle, &value) != pdPASS) {
return OBC_ERR_CODE_UNKNOWN;
}
return OBC_ERR_CODE_SUCCESS;
}

obc_error_code_t readCC1120Temp(float *temp) {
if (xQueuePeek(cc1120TempQueueHandle, temp, pdMS_TO_TICKS(1000)) != pdPASS) {
return OBC_ERR_CODE_QUEUE_EMPTY;
}
return OBC_ERR_CODE_SUCCESS;
}

// NOTE: This is created on startup
void obcTaskFunctionCommsMgr(void *pvParameters) {
obc_error_code_t errCode;
Expand All @@ -311,6 +346,7 @@ void obcTaskFunctionCommsMgr(void *pvParameters) {
comms_event_t queueMsg;

if (xQueueReceive(commsQueueHandle, &queueMsg, COMMS_MANAGER_QUEUE_RX_WAIT_PERIOD) != pdPASS) {
postCommsManagerTempQueue();
continue;
}

Expand Down
17 changes: 17 additions & 0 deletions obc/app/modules/comms_link_mgr/comms_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#define U_FRAME_COMMS_RECV_SIZE 30
#define I_FRAME_COMMS_RECV_SIZE 300

extern QueueHandle_t cc1120TempQueueHandle;

/**
* @enum comms_event_id_t
* @brief comms event ID enum.
Expand Down Expand Up @@ -76,6 +78,13 @@ typedef enum {
*/
obc_error_code_t sendToCommsManagerQueue(comms_event_t *event);

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recognize that this declaration is commented out due to what is mentioned in the PR description, but you also have the same declaration written below, uncommented

* @brief Get the temperature from the mailbox temperature queue of the CC1120
* @param temp The memory address that stores the temperature in the mailbox queue
* @return The error code
*/
// obc_error_code_t readCC1120Temp(float* temp);

/**
* @brief Send an event to the front of the Comms Manager queue
*
Expand All @@ -92,3 +101,11 @@ obc_error_code_t sendToFrontCommsManagerQueue(comms_event_t *event);
* @return obc_error_code_t OBC_ERR_CODE_SUCCESS if the packet was sent to the queue
*/
obc_error_code_t sendToCC1120TransmitQueue(transmit_event_t *event);

/**
* @brief Reads temperature from the CC1120 Temperature Queue
*
* @param temp - Pointer to the variable that will store the temperature.
* @return obc_error_code_t OBC_ERR_CODE_SUCCESS if data was retrieved from queue successfully.
*/
obc_error_code_t readCC1120Temp(float *temp);
6 changes: 3 additions & 3 deletions obc/app/modules/digital_watchdog_mgr/digital_watchdog_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#define TASK_PAYLOAD_MGR_WATCHDOG_TIMEOUT portMAX_DELAY
#define TASK_TIMEKEEPER_WATCHDOG_TIMEOUT portMAX_DELAY
#define TASK_ALARM_MGR_WATCHDOG_TIMEOUT portMAX_DELAY
#define TASK_HEALTH_COLLECTOR_WATCHDOG_TIMEOUT portMAX_DELAY
#define TASK_THERMAL_MGR_WATCHDOG_TIMEOUT portMAX_DELAY
#define TASK_STATS_COLLECTOR_WATCHDOG_TIMEOUT portMAX_DELAY
#define TASK_LOGGER_WATCHDOG_TIMEOUT portMAX_DELAY
#define TASK_DIGITAL_WATCHDOG_MGR_WATCHDOG_TIMEOUT portMAX_DELAY
Expand Down Expand Up @@ -76,9 +76,9 @@ static watchdog_task_info_t watchdogTaskArray[] = {
{
.taskTimeoutTicks = TASK_ALARM_MGR_WATCHDOG_TIMEOUT,
},
[OBC_SCHEDULER_CONFIG_ID_HEALTH_COLLECTOR] =
[OBC_SCHEDULER_CONFIG_ID_THERMAL_MGR] =
{
.taskTimeoutTicks = TASK_HEALTH_COLLECTOR_WATCHDOG_TIMEOUT,
.taskTimeoutTicks = TASK_THERMAL_MGR_WATCHDOG_TIMEOUT,
},
[OBC_SCHEDULER_CONFIG_ID_LOGGER] =
{
Expand Down
39 changes: 0 additions & 39 deletions obc/app/modules/health_collector/health_collector.c

This file was deleted.

4 changes: 2 additions & 2 deletions obc/app/modules/state_mgr/state_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void obcTaskFunctionStateMgr(void *pvParameters) {
obcSchedulerInitTask(OBC_SCHEDULER_CONFIG_ID_COMMS_DOWNLINK_ENCODER);
obcSchedulerInitTask(OBC_SCHEDULER_CONFIG_ID_EPS_MGR);
obcSchedulerInitTask(OBC_SCHEDULER_CONFIG_ID_PAYLOAD_MGR);
obcSchedulerInitTask(OBC_SCHEDULER_CONFIG_ID_HEALTH_COLLECTOR);
obcSchedulerInitTask(OBC_SCHEDULER_CONFIG_ID_THERMAL_MGR);
obcSchedulerInitTask(OBC_SCHEDULER_CONFIG_ID_GNC_MGR);
#if ENABLE_TASK_STATS_COLLECTOR == 1
obcSchedulerInitTask(OBC_SCHEDULER_CONFIG_ID_STATS_COLLECTOR);
Expand All @@ -149,7 +149,7 @@ void obcTaskFunctionStateMgr(void *pvParameters) {
obcSchedulerCreateTask(OBC_SCHEDULER_CONFIG_ID_COMMS_DOWNLINK_ENCODER);
obcSchedulerCreateTask(OBC_SCHEDULER_CONFIG_ID_EPS_MGR);
obcSchedulerCreateTask(OBC_SCHEDULER_CONFIG_ID_PAYLOAD_MGR);
obcSchedulerCreateTask(OBC_SCHEDULER_CONFIG_ID_HEALTH_COLLECTOR);
obcSchedulerCreateTask(OBC_SCHEDULER_CONFIG_ID_THERMAL_MGR);
obcSchedulerCreateTask(OBC_SCHEDULER_CONFIG_ID_GNC_MGR);
#if ENABLE_TASK_STATS_COLLECTOR == 1
obcSchedulerCreateTask(OBC_SCHEDULER_CONFIG_ID_STATS_COLLECTOR);
Expand Down
50 changes: 50 additions & 0 deletions obc/app/modules/thermal_mgr/thermal_mgr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "thermal_mgr.h"
#include "lm75bd.h"
#include "obc_time.h"
#include "telemetry_manager.h"
#include "obc_errors.h"
#include "obc_logging.h"
#include "obc_scheduler_config.h"
#include "comms_manager.h"
#include "timekeeper.h"

#include <FreeRTOS.h>
#include <os_task.h>
#include <sys_common.h>

#define HEALTH_COLLECTION_PERIOD_MS 60000UL

static obc_error_code_t collectThermalData(void);

void obcTaskInitThermalMgr(void) {}

void obcTaskFunctionThermalMgr(void* pvParameters) {
obc_error_code_t errCode;

while (1) {
LOG_IF_ERROR_CODE(collectThermalData());
vTaskDelay(pdMS_TO_TICKS(HEALTH_COLLECTION_PERIOD_MS));
}
}

static obc_error_code_t collectThermalData(void) {
obc_error_code_t errCode;

float lm75bdTemp = 0.0f;
RETURN_IF_ERROR_CODE(readTempLM75BD(LM75BD_OBC_I2C_ADDR, &lm75bdTemp));
telemetry_data_t lm75bdTempVal = {.obcTemp = lm75bdTemp, .id = TELEM_OBC_TEMP, .timestamp = getCurrentUnixTime()};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do all three temp structs have the same id?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You call getCurrentUnixTime() separately for each temp value, but this can cause a race condition if time increases between these calls and we may get a discrepancy

RETURN_IF_ERROR_CODE(addTelemetryData(&lm75bdTempVal));

/* Uncomment this if comms manager task being suspened issue is fixed.
float cc1120Temp = 0.0f;
RETURN_IF_ERROR_CODE(readCC1120Temp(&cc1120Temp));
telemetry_data_t cc1120TempVal = {.obcTemp = lm75bdTemp, .id = TELEM_OBC_TEMP, .timestamp = getCurrentUnixTime()};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is commented out, but this should not be lm75bdTemp

RETURN_IF_ERROR_CODE(addTelemetryData(&cc1120TempVal));
*/
float rtcTemp = 0.0f;
RETURN_IF_ERROR_CODE(readRTCTemp(&rtcTemp));
telemetry_data_t rtcTempVal = {.obcTemp = lm75bdTemp, .id = TELEM_OBC_TEMP, .timestamp = getCurrentUnixTime()};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be lm75bdTemp here

RETURN_IF_ERROR_CODE(addTelemetryData(&rtcTempVal));

return OBC_ERR_CODE_SUCCESS;
}
46 changes: 44 additions & 2 deletions obc/app/modules/timekeeper/timekeeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,48 @@
#include <os_task.h>
#include <os_timer.h>
#include <sys_common.h>
#include <stdint.h>

#define LOCAL_TIME_SYNC_PERIOD_S 60UL

void obcTaskInitTimekeeper(void) {}
#define RTC_TEMP_QUEUE_LENGTH 1
#define RTC_TEMP_QUEUE_ITEM_SIZE sizeof(uint32_t)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though we can assume floats on our architecture are 32 bit, a type mismatch like this is unideal and not portable. We should define the size as being the same as the type of data we store in the queue.
Separate from this task, the driver function should probably be written to read this value as a fixed-point value rather than a floating-point number, which would avoid floats altogether


QueueHandle_t rtcTempQueueHandle = NULL;
static StaticQueue_t rtcTempQueue;
static uint8_t rtcTempQueueStack[RTC_TEMP_QUEUE_LENGTH * RTC_TEMP_QUEUE_ITEM_SIZE];

/**
* @brief Reading the temperature using driver functions and adding that temperature to
* the mailbox temperature queue
* @return error code
*/
static obc_error_code_t postRtcTempQueue();

void obcTaskInitTimekeeper(void) {
ASSERT((rtcTempQueueStack != NULL) && (&rtcTempQueue != NULL));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking the address of a static variable like rtcTempQueue will never result in NULL

if (rtcTempQueueHandle == NULL) {
rtcTempQueueHandle =
xQueueCreateStatic(RTC_TEMP_QUEUE_LENGTH, RTC_TEMP_QUEUE_ITEM_SIZE, rtcTempQueueStack, &rtcTempQueue);
}
}

static obc_error_code_t postRtcTempQueue() {
obc_error_code_t errCode;
float temp;
RETURN_IF_ERROR_CODE(getTemperatureRTC(&temp));
if (xQueueOverwrite(rtcTempQueueHandle, &temp) != pdPASS) {
return OBC_ERR_CODE_UNKNOWN;
}
return OBC_ERR_CODE_SUCCESS;
}

obc_error_code_t readRTCTemp(float *data) {
if (xQueuePeek(rtcTempQueueHandle, data, 0) != pdPASS) {
return OBC_ERR_CODE_QUEUE_EMPTY;
}
return OBC_ERR_CODE_SUCCESS;
}

void obcTaskFunctionTimekeeper(void *pvParameters) {
/*
Expand Down Expand Up @@ -46,7 +84,11 @@ void obcTaskFunctionTimekeeper(void *pvParameters) {
vPortExitCritical();
}

// Send Unix time to fram
// Post temperature into mailbox queue

postRtcTempQueue();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignoring the return value of this function, which is an error code?


// Send Unix time to frame
unixTime.unixTime = getCurrentUnixTime();
LOG_IF_ERROR_CODE(
setPersistentData(OBC_PERSIST_SECTION_ID_OBC_TIME, (uint8_t *)&unixTime, sizeof(obc_time_persist_data_t)));
Expand Down
13 changes: 13 additions & 0 deletions obc/app/modules/timekeeper/timekeeper.h
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
#pragma once

#include <FreeRTOS.h>
#include <os_queue.h>
#include "obc_errors.h"

extern QueueHandle_t rtcTempQueueHandle;

/**
* @brief Get the temperature from the mailbox temperature queue of the ds3232
* @param temp The memory address that stores the temperature in the mailbox queue
* @return The error code
*/
obc_error_code_t readRTCTemp(float* data);
20 changes: 10 additions & 10 deletions obc/app/rtos/obc_scheduler_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extern void obcTaskInitEpsMgr(void);
extern void obcTaskInitPayloadMgr(void);
extern void obcTaskInitTimekeeper(void);
extern void obcTaskInitAlarmMgr(void);
extern void obcTaskInitHealthCollector(void);
extern void obcTaskInitThermalMgr(void);
extern void obcTaskInitStatsCollector(void);
extern void obcTaskInitLogger(void);
extern void obcTaskInitGncMgr(void);
Expand All @@ -56,7 +56,7 @@ extern void obcTaskFunctionPayloadMgr(void *params);
extern void obcTaskFunctionTimekeeper(void *params);
extern void obcTaskFunctionSwWatchdog(void *params);
extern void obcTaskFunctionAlarmMgr(void *params);
extern void obcTaskFunctionHealthCollector(void *params);
extern void obcTaskFunctionThermalMgr(void *params);
extern void obcTaskFunctionStatsCollector(void *params);
extern void obcTaskFunctionLogger(void *params);
extern void obcTaskFunctionGncMgr(void *params);
Expand Down Expand Up @@ -87,8 +87,8 @@ static StackType_t obcTaskStackSwWatchdog[128U];
static StaticTask_t obcTaskBufferSwWatchdog;
static StackType_t obcTaskStackAlarmMgr[512U];
static StaticTask_t obcTaskBufferAlarmMgr;
static StackType_t obcTaskStackHealthCollector[256U];
static StaticTask_t obcTaskBufferHealthCollector;
static StackType_t obcTaskStackThermalMgr[256U];
static StaticTask_t obcTaskBufferThermalMgr;
#if ENABLE_TASK_STATS_COLLECTOR == 1
static StackType_t obcTaskStackStatsCollector[1024U];
static StaticTask_t obcTaskBufferStatsCollector;
Expand Down Expand Up @@ -209,15 +209,15 @@ static obc_scheduler_config_t obcSchedulerConfig[] = {
.taskFunc = obcTaskFunctionAlarmMgr,
.taskInit = obcTaskInitAlarmMgr,
},
[OBC_SCHEDULER_CONFIG_ID_HEALTH_COLLECTOR] =
[OBC_SCHEDULER_CONFIG_ID_THERMAL_MGR] =
{
.taskName = "health_collector",
.taskStack = obcTaskStackHealthCollector,
.taskBuffer = &obcTaskBufferHealthCollector,
.taskName = "thermal_mgr",
.taskStack = obcTaskStackThermalMgr,
.taskBuffer = &obcTaskBufferThermalMgr,
.stackSize = 256U,
.priority = 1U,
.taskFunc = obcTaskFunctionHealthCollector,
.taskInit = obcTaskInitHealthCollector,
.taskFunc = obcTaskFunctionThermalMgr,
.taskInit = obcTaskInitThermalMgr,
},
#if ENABLE_TASK_STATS_COLLECTOR == 1
[OBC_SCHEDULER_CONFIG_ID_STATS_COLLECTOR] =
Expand Down
Loading
Loading