Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Thermal Mgr Task #285

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions obc/app/drivers/cc1120/cc1120.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,5 @@ obc_error_code_t cc1120GetState(cc1120_state_t *stateNum);
* @return obc_error_code_t - Whether or not the setup was a success
*/
obc_error_code_t cc1120Init(void);

obc_error_code_t readTempCC1120(float *temp);
Copy link

Choose a reason for hiding this comment

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

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
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 @@ -23,7 +23,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 pdMS_TO_TICKS(1000)
Copy link
Contributor

Choose a reason for hiding this comment

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

Update this with changed tick delay

Copy link
Contributor

Choose a reason for hiding this comment

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

watchdog timeout shouldl generally be 2x task rate

#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 @@ -75,9 +75,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 @@ -86,6 +86,7 @@ void obcTaskFunctionStateMgr(void *pvParameters) {
initFRAM(); // FRAM storage (OBC)

// Initialize the state of each module. This will not start any tasks.
obcSchedulerInitTask(OBC_SCHEDULER_CONFIG_ID_THERMAL_MGR);
obcSchedulerInitTask(OBC_SCHEDULER_CONFIG_ID_TIMEKEEPER);
obcSchedulerInitTask(OBC_SCHEDULER_CONFIG_ID_ALARM_MGR);
obcSchedulerInitTask(OBC_SCHEDULER_CONFIG_ID_TELEMETRY_MGR);
Expand All @@ -95,7 +96,6 @@ 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_GNC_MGR);
#if ENABLE_TASK_STATS_COLLECTOR == 1
obcSchedulerInitTask(OBC_SCHEDULER_CONFIG_ID_STATS_COLLECTOR);
Expand All @@ -112,7 +112,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
86 changes: 86 additions & 0 deletions obc/app/modules/thermal_mgr/thermal_mgr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include "thermal_mgr.h"

// sensor imports for telemetry
#include "lm75bd.h"
#include "cc1120.h"
#include "cc1120_defs.h"
#include "ds3232_mz.h"
// bd621x, fm25V025A, MAX5360, and RFFM6404 doesn't have a temperature sensors

#include "obc_time.h"
#include "telemetry_manager.h"
#include "obc_errors.h"
#include "obc_logging.h"
#include "obc_scheduler_config.h"
#include <obc_digital_watchdog.h>
#include "digital_watchdog_mgr.h"

#include <FreeRTOS.h>
#include <os_portmacro.h>
#include <os_task.h>
#include <os_queue.h>

#define THERMAL_MGR_PERIOD_MS 1000
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on our telemetry sheet, it should take the temperature once every minute, not once a sec. Also add U to the end


void obcTaskInitThermalMgr() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

This task should init the lm75bd

static obc_error_code_t collectObcLm75bdTemp(void);
static obc_error_code_t collectObcDs3232Temp(void);
static obc_error_code_t collectObcCC1120Temp(void);

void obcTaskFunctionThermalMgr(void* pvParameters) {
obc_error_code_t errCode;
TickType_t xLastWakeTime;

xLastWakeTime = xTaskGetTickCount();

while (1) {
LOG_IF_ERROR_CODE(collectObcLm75bdTemp());
LOG_IF_ERROR_CODE(collectObcCC1120Temp());
LOG_IF_ERROR_CODE(collectObcDs3232Temp()); // RTC
// BMS in pr https://github.com/UWOrbital/OBC-firmware/pull/187

Copy link

Choose a reason for hiding this comment

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

BMS driver code does not exist; still in PR #187

digitalWatchdogTaskCheckIn(OBC_SCHEDULER_CONFIG_ID_THERMAL_MGR);

vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(THERMAL_MGR_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));
Copy link
Contributor

Choose a reason for hiding this comment

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

make telem a flag that is passed in since we may want to just read the value sometimes to make sure we are safe without adding that as telemetry


return OBC_ERR_CODE_SUCCESS;
}

static obc_error_code_t collectObcCC1120Temp(void) {
// function commented out due to cc1120 driver function being implemented in a different PR
// obc_error_code_t errCode;

// float temp = 0.0f;
// RETURN_IF_ERROR_CODE(readTempCC1120(&temp));

// telemetry_data_t obcTempVal = {.obcTemp = temp, .id = TELEM_OBC_TEMP, .timestamp = getCurrentUnixTime()};

// RETURN_IF_ERROR_CODE(addTelemetryData(&obcTempVal));

return OBC_ERR_CODE_SUCCESS;
}

static obc_error_code_t collectObcDs3232Temp(void) {
obc_error_code_t errCode;

float temp = 0.0f;
RETURN_IF_ERROR_CODE(getTemperatureRTC(&temp));

telemetry_data_t obcTempVal = {.obcTemp = temp, .id = TELEM_OBC_TEMP, .timestamp = getCurrentUnixTime()};

RETURN_IF_ERROR_CODE(addTelemetryData(&obcTempVal));

return OBC_ERR_CODE_SUCCESS;
}
33 changes: 17 additions & 16 deletions obc/app/rtos/obc_scheduler_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#define TASK_TIMEKEEPER_NAME "timekeeper"
#define TASK_DIGITAL_WATCHDOG_MGR_NAME "digital_wdg_mgr"
#define TASK_ALARM_MGR_NAME "alarm_handler"
#define TASK_HEALTH_COLLECTOR_NAME "health_collector"
#define TASK_THERMAL_MGR_NAME "thermal_mgr"
#define TASK_STATS_COLLECTOR_NAME "stats_collector"
#define TASK_LOGGER_NAME "logger"
#define TASK_GNC_MGR_NAME "gnc_mgr"
Expand All @@ -40,17 +40,18 @@
#define TASK_TIMEKEEPER_STACK_SIZE 1024U
#define TASK_DIGITAL_WATCHDOG_MGR_STACK_SIZE 128U
#define TASK_ALARM_MGR_STACK_SIZE 512U
#define TASK_HEALTH_COLLECTOR_STACK_SIZE 256U

#define TASK_STATS_COLLECTOR_STACK_SIZE 1024U
#define TASK_LOGGER_STACK_SIZE 512U
#define TASK_GNC_MGR_STACK_SIZE 512U
#define TASK_GNC_MGR_STACK_SIZE 1024U
#define TASK_THERMAL_MGR_STACK_SIZE 256U

// All task priorities must be in [0, OBC_SCHEDULER_MAX_PRIORITY]
#define OBC_SCHEDULER_MAX_PRIORITY configMAX_PRIORITIES - 1U
#define TASK_IDLE_PRIORITY 0U
#define TASK_COMMAND_MGR_PRIORITY 1U
#define TASK_TELEMETRY_MGR_PRIORITY 1U
#define TASK_HEALTH_COLLECTOR_PRIORITY 1U
#define TASK_THERMAL_MGR_PRIORITY 1U
#define TASK_PAYLOAD_MGR_PRIORITY 1U
#define TASK_COMMS_PRIORITY 2U // Comms tasks must have the same priority
#define TASK_COMMS_MGR_PRIORITY TASK_COMMS_PRIORITY
Expand Down Expand Up @@ -88,7 +89,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 @@ -105,7 +106,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 @@ -147,8 +148,8 @@ static StaticTask_t obcTaskBufferSwWatchdog;
static StackType_t obcTaskStackAlarmMgr[TASK_ALARM_MGR_STACK_SIZE];
static StaticTask_t obcTaskBufferAlarmMgr;

static StackType_t obcTaskStackHealthCollector[TASK_HEALTH_COLLECTOR_STACK_SIZE];
static StaticTask_t obcTaskBufferHealthCollector;
static StackType_t obcTaskStackThermalMgr[TASK_THERMAL_MGR_STACK_SIZE];
static StaticTask_t obcTaskBufferThermalMgr;

static StackType_t obcTaskStackLogger[TASK_LOGGER_STACK_SIZE];
static StaticTask_t obcTaskBufferLogger;
Expand Down Expand Up @@ -272,15 +273,15 @@ static obc_scheduler_config_t obcSchedulerConfig[] = {
.taskFunc = obcTaskFunctionAlarmMgr,
.taskInit = obcTaskInitAlarmMgr,
},
[OBC_SCHEDULER_CONFIG_ID_HEALTH_COLLECTOR] =
[OBC_SCHEDULER_CONFIG_ID_THERMAL_MGR] =
{
.taskName = TASK_HEALTH_COLLECTOR_NAME,
.taskStack = obcTaskStackHealthCollector,
.taskBuffer = &obcTaskBufferHealthCollector,
.stackSize = TASK_HEALTH_COLLECTOR_STACK_SIZE,
.priority = TASK_HEALTH_COLLECTOR_PRIORITY,
.taskFunc = obcTaskFunctionHealthCollector,
.taskInit = obcTaskInitHealthCollector,
.taskName = TASK_THERMAL_MGR_NAME,
.taskStack = obcTaskStackThermalMgr,
.taskBuffer = &obcTaskBufferThermalMgr,
.stackSize = TASK_THERMAL_MGR_STACK_SIZE,
.priority = TASK_THERMAL_MGR_PRIORITY,
.taskFunc = obcTaskFunctionThermalMgr,
.taskInit = obcTaskInitThermalMgr,
},
[OBC_SCHEDULER_CONFIG_ID_LOGGER] =
{
Expand Down
2 changes: 1 addition & 1 deletion obc/app/rtos/obc_scheduler_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ typedef enum {
OBC_SCHEDULER_CONFIG_ID_PAYLOAD_MGR,
OBC_SCHEDULER_CONFIG_ID_TIMEKEEPER,
OBC_SCHEDULER_CONFIG_ID_ALARM_MGR,
OBC_SCHEDULER_CONFIG_ID_HEALTH_COLLECTOR,
OBC_SCHEDULER_CONFIG_ID_THERMAL_MGR,
OBC_SCHEDULER_CONFIG_ID_LOGGER,
OBC_SCHEDULER_CONFIG_ID_GNC_MGR,

Expand Down
Loading