diff --git a/obc/app/modules/CMakeLists.txt b/obc/app/modules/CMakeLists.txt index 3da7e5da8..7e3c58cc8 100644 --- a/obc/app/modules/CMakeLists.txt +++ b/obc/app/modules/CMakeLists.txt @@ -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 @@ -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 diff --git a/obc/app/modules/comms_link_mgr/comms_manager.c b/obc/app/modules/comms_link_mgr/comms_manager.c index f39c9ba52..6b6e916de 100644 --- a/obc/app/modules/comms_link_mgr/comms_manager.c +++ b/obc/app/modules/comms_link_mgr/comms_manager.c @@ -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; @@ -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) + +QueueHandle_t cc1120TempQueueHandle = NULL; +static StaticQueue_t cc1120TempQueue; +static uint8_t cc1120TempQueueStack[COMMS_MANAGER_QUEUE_LENGTH * CC1120_TEMP_QUEUE_ITEM_SIZE]; + /** * @brief determines what the next Comms Manager state should be and sets it to * that state @@ -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[] = { @@ -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); @@ -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 + 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; @@ -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; } diff --git a/obc/app/modules/comms_link_mgr/comms_manager.h b/obc/app/modules/comms_link_mgr/comms_manager.h index 4bb34ba5b..3dd176d33 100644 --- a/obc/app/modules/comms_link_mgr/comms_manager.h +++ b/obc/app/modules/comms_link_mgr/comms_manager.h @@ -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. @@ -76,6 +78,13 @@ typedef enum { */ obc_error_code_t sendToCommsManagerQueue(comms_event_t *event); +/** + * @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 * @@ -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); diff --git a/obc/app/modules/digital_watchdog_mgr/digital_watchdog_mgr.c b/obc/app/modules/digital_watchdog_mgr/digital_watchdog_mgr.c index a290680c9..213b60709 100644 --- a/obc/app/modules/digital_watchdog_mgr/digital_watchdog_mgr.c +++ b/obc/app/modules/digital_watchdog_mgr/digital_watchdog_mgr.c @@ -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 @@ -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] = { diff --git a/obc/app/modules/health_collector/health_collector.c b/obc/app/modules/health_collector/health_collector.c deleted file mode 100644 index 90f938dba..000000000 --- a/obc/app/modules/health_collector/health_collector.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "health_collector.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 -#include -#include - -#define HEALTH_COLLECTION_PERIOD_MS 60000UL - -static obc_error_code_t collectObcLm75bdTemp(void); - -void obcTaskInitHealthCollector(void) {} - -void obcTaskFunctionHealthCollector(void* pvParameters) { - obc_error_code_t errCode; - - while (1) { - LOG_IF_ERROR_CODE(collectObcLm75bdTemp()); - vTaskDelay(pdMS_TO_TICKS(HEALTH_COLLECTION_PERIOD_MS)); - } -} - -static obc_error_code_t collectObcLm75bdTemp(void) { - obc_error_code_t errCode; - - float temp = 0.0f; - RETURN_IF_ERROR_CODE(readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temp)); - - telemetry_data_t obcTempVal = {.obcTemp = temp, .id = TELEM_OBC_TEMP, .timestamp = getCurrentUnixTime()}; - - RETURN_IF_ERROR_CODE(addTelemetryData(&obcTempVal)); - - return OBC_ERR_CODE_SUCCESS; -} diff --git a/obc/app/modules/state_mgr/state_mgr.c b/obc/app/modules/state_mgr/state_mgr.c index 0358ac57c..227554167 100644 --- a/obc/app/modules/state_mgr/state_mgr.c +++ b/obc/app/modules/state_mgr/state_mgr.c @@ -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); @@ -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); diff --git a/obc/app/modules/thermal_mgr/thermal_mgr.c b/obc/app/modules/thermal_mgr/thermal_mgr.c new file mode 100644 index 000000000..a043b6637 --- /dev/null +++ b/obc/app/modules/thermal_mgr/thermal_mgr.c @@ -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 +#include +#include + +#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()}; + 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()}; + 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()}; + RETURN_IF_ERROR_CODE(addTelemetryData(&rtcTempVal)); + + return OBC_ERR_CODE_SUCCESS; +} diff --git a/obc/app/modules/health_collector/health_collector.h b/obc/app/modules/thermal_mgr/thermal_mgr.h similarity index 100% rename from obc/app/modules/health_collector/health_collector.h rename to obc/app/modules/thermal_mgr/thermal_mgr.h diff --git a/obc/app/modules/timekeeper/timekeeper.c b/obc/app/modules/timekeeper/timekeeper.c index 822e74f4c..ce7494e6f 100644 --- a/obc/app/modules/timekeeper/timekeeper.c +++ b/obc/app/modules/timekeeper/timekeeper.c @@ -11,10 +11,48 @@ #include #include #include +#include #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) + +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)); + 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) { /* @@ -46,7 +84,11 @@ void obcTaskFunctionTimekeeper(void *pvParameters) { vPortExitCritical(); } - // Send Unix time to fram + // Post temperature into mailbox queue + + postRtcTempQueue(); + + // 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))); diff --git a/obc/app/modules/timekeeper/timekeeper.h b/obc/app/modules/timekeeper/timekeeper.h index 6f70f09be..a9ce97594 100644 --- a/obc/app/modules/timekeeper/timekeeper.h +++ b/obc/app/modules/timekeeper/timekeeper.h @@ -1 +1,14 @@ #pragma once + +#include +#include +#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); diff --git a/obc/app/rtos/obc_scheduler_config.c b/obc/app/rtos/obc_scheduler_config.c index c31182780..2eb22cabf 100644 --- a/obc/app/rtos/obc_scheduler_config.c +++ b/obc/app/rtos/obc_scheduler_config.c @@ -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); @@ -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); @@ -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; @@ -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] = diff --git a/obc/app/rtos/obc_scheduler_config.h b/obc/app/rtos/obc_scheduler_config.h index aaa4edffc..52abc4036 100644 --- a/obc/app/rtos/obc_scheduler_config.h +++ b/obc/app/rtos/obc_scheduler_config.h @@ -15,7 +15,7 @@ typedef enum { OBC_SCHEDULER_CONFIG_ID_TIMEKEEPER, OBC_SCHEDULER_CONFIG_ID_DIGITAL_WATCHDOG_MGR, OBC_SCHEDULER_CONFIG_ID_ALARM_MGR, - OBC_SCHEDULER_CONFIG_ID_HEALTH_COLLECTOR, + OBC_SCHEDULER_CONFIG_ID_THERMAL_MGR, #if ENABLE_TASK_STATS_COLLECTOR == 1 OBC_SCHEDULER_CONFIG_ID_STATS_COLLECTOR, #endif diff --git a/obc/app/rtos/scheduler_config.toml b/obc/app/rtos/scheduler_config.toml index bc1b81b50..856dc33b4 100644 --- a/obc/app/rtos/scheduler_config.toml +++ b/obc/app/rtos/scheduler_config.toml @@ -83,11 +83,11 @@ function_stem = "AlarmMgr" config_id_stem = "ALARM_MGR" [[tasks]] -task_name = "health_collector" +task_name = "thermal_mgr" stack_size = 256 priority = "1U" -function_stem = "HealthCollector" -config_id_stem = "HEALTH_COLLECTOR" +function_stem = "ThermalMgr" +config_id_stem = "THERMAL_MGR" [[tasks]] task_name = "stats_collector"