From f1113d4e4c712e462fcd74cfa7615e5a2fb824f1 Mon Sep 17 00:00:00 2001 From: Shrey Varma Date: Wed, 1 Nov 2023 23:38:16 -0400 Subject: [PATCH 1/3] Completed onboarding challenge --- .gitignore | 3 ++ CMakeLists.txt | 2 +- lm75bd/lm75bd.c | 64 +++++++++++++++++++----------- lm75bd/lm75bd.h | 22 ++++++---- services/thermal_mgr/thermal_mgr.c | 56 +++++++++++++++++--------- services/thermal_mgr/thermal_mgr.h | 3 +- sys/errors.h | 28 ++++++------- sys/i2c/i2c_io.c | 34 +++++++++------- sys/i2c/i2c_io.h | 16 ++++---- 9 files changed, 138 insertions(+), 90 deletions(-) diff --git a/.gitignore b/.gitignore index 3f7671be..c231925b 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ *.a *.la *.lo +_deps # Shared objects (inc. Windows DLLs) *.dll @@ -50,10 +51,12 @@ modules.order Module.symvers Mkfile.old dkms.conf +.cache # IDE files .vscode/ .idea/ +.DS_Store .venv/ venv/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e2769e7..2958510e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ elseif(CMAKE_BUILD_TYPE MATCHES FW) sys/i2c/i2c_io.c sys/logging/logging.c services/controller/controller.c - + lm75bd/lm75bd.c services/thermal_mgr/thermal_mgr.c ) diff --git a/lm75bd/lm75bd.c b/lm75bd/lm75bd.c index 7d63da66..1490ebaa 100644 --- a/lm75bd/lm75bd.c +++ b/lm75bd/lm75bd.c @@ -1,22 +1,25 @@ #include "lm75bd.h" -#include "i2c_io.h" +#include "console.h" #include "errors.h" +#include "i2c_io.h" #include "logging.h" +#include #include #include -#include /* LM75BD Registers (p.8) */ -#define LM75BD_REG_CONF 0x01U /* Configuration Register (R/W) */ +#define LM75BD_REG_CONF 0x01U /* Configuration Register (R/W) */ error_code_t lm75bdInit(lm75bd_config_t *config) { error_code_t errCode; - if (config == NULL) return ERR_CODE_INVALID_ARG; + if (config == NULL) + return ERR_CODE_INVALID_ARG; - RETURN_IF_ERROR_CODE(writeConfigLM75BD(config->devAddr, config->osFaultQueueSize, config->osPolarity, - config->osOperationMode, config->devOperationMode)); + RETURN_IF_ERROR_CODE(writeConfigLM75BD( + config->devAddr, config->osFaultQueueSize, config->osPolarity, + config->osOperationMode, config->devOperationMode)); // Assume that the overtemperature and hysteresis thresholds are already set // Hysteresis: 75 degrees Celsius @@ -27,13 +30,25 @@ error_code_t lm75bdInit(lm75bd_config_t *config) { error_code_t readTempLM75BD(uint8_t devAddr, float *temp) { /* Implement this driver function */ - + + // set pointer register to temperature + uint8_t point_reg = 0x00; + uint8_t buf[1] = {point_reg}; + i2cSendTo(devAddr, buf, 1); + + // read data from sensor + uint8_t temp_bytes[2] = {}; + i2cReceiveFrom(devAddr, temp_bytes, 2); + int16_t combined = ((temp_bytes[0] << 8) | temp_bytes[1]); + combined = combined >> 5; + *temp = combined * 0.125; return ERR_CODE_SUCCESS; } #define CONF_WRITE_BUFF_SIZE 2U -error_code_t writeConfigLM75BD(uint8_t devAddr, uint8_t osFaultQueueSize, uint8_t osPolarity, - uint8_t osOperationMode, uint8_t devOperationMode) { +error_code_t writeConfigLM75BD(uint8_t devAddr, uint8_t osFaultQueueSize, + uint8_t osPolarity, uint8_t osOperationMode, + uint8_t devOperationMode) { error_code_t errCode; // Stores the register address and data to be written @@ -45,20 +60,20 @@ error_code_t writeConfigLM75BD(uint8_t devAddr, uint8_t osFaultQueueSize, uint8_ uint8_t osFaltQueueRegData = 0; switch (osFaultQueueSize) { - case 1: - osFaltQueueRegData = 0; - break; - case 2: - osFaltQueueRegData = 1; - break; - case 4: - osFaltQueueRegData = 2; - break; - case 6: - osFaltQueueRegData = 3; - break; - default: - return ERR_CODE_INVALID_ARG; + case 1: + osFaltQueueRegData = 0; + break; + case 2: + osFaltQueueRegData = 1; + break; + case 4: + osFaltQueueRegData = 2; + break; + case 6: + osFaltQueueRegData = 3; + break; + default: + return ERR_CODE_INVALID_ARG; } buff[1] |= (osFaltQueueRegData << 3); @@ -67,7 +82,8 @@ error_code_t writeConfigLM75BD(uint8_t devAddr, uint8_t osFaultQueueSize, uint8_ buff[1] |= devOperationMode; errCode = i2cSendTo(LM75BD_OBC_I2C_ADDR, buff, CONF_WRITE_BUFF_SIZE); - if (errCode != ERR_CODE_SUCCESS) return errCode; + if (errCode != ERR_CODE_SUCCESS) + return errCode; return ERR_CODE_SUCCESS; } diff --git a/lm75bd/lm75bd.h b/lm75bd/lm75bd.h index 9a2356af..da885eb3 100644 --- a/lm75bd/lm75bd.h +++ b/lm75bd/lm75bd.h @@ -5,7 +5,7 @@ #include /* LM75BD I2C Device Address */ -#define LM75BD_OBC_I2C_ADDR /* Define the address here */ +#define LM75BD_OBC_I2C_ADDR 0x4F /* Define the address here */ /* LM75BD Configuration Values */ #define LM75BD_DEV_OP_MODE_NORMAL 0x00U @@ -25,11 +25,14 @@ * @struct Configuration struct for LM75BD,118 temperature sensor * * @param devAddr I2C address of the LM75BD - * @param osFaultQueueSize Number of consecutive OS faults until OS output is activated (1, 2, 4, or 6) + * @param osFaultQueueSize Number of consecutive OS faults until OS output is + * activated (1, 2, 4, or 6) * @param osPolarity OS output polarity, 0 = active low, 1 = active high - * @param osOperationMode OS output operation mode, 0 = comparator, 1 = interrupt + * @param osOperationMode OS output operation mode, 0 = comparator, 1 = + * interrupt * @param devOperationMode Device operation mode, 0 = normal, 1 = shutdown - * @param overTempThreshold Overtemperature shutdown threshold, in degrees Celsius + * @param overTempThreshold Overtemperature shutdown threshold, in degrees + * Celsius * @param hysteresisThreshold Hysteresis threshold, in degrees Celsius */ typedef struct { @@ -66,14 +69,17 @@ error_code_t readTempLM75BD(uint8_t devAddr, float *temp); * @brief Write to the configuration register from the LM75BD * * @param devAddr I2C address of the LM75BD - * @param osFaultQueueSize Number of consecutive OS faults until OS output is activated (1, 2, 4, or 6) + * @param osFaultQueueSize Number of consecutive OS faults until OS output is + * activated (1, 2, 4, or 6) * @param osPolarity OS output polarity, 0 = active low, 1 = active high - * @param osOperationMode OS output operation mode, 0 = comparator, 1 = interrupt + * @param osOperationMode OS output operation mode, 0 = comparator, 1 = + * interrupt * @param devOperationMode Device operation mode, 0 = normal, 1 = shutdown * @return ERR_CODE_SUCCESS if successful, error code otherwise */ -error_code_t writeConfigLM75BD(uint8_t devAddr, uint8_t osFaultQueueSize, uint8_t osPolarity, - uint8_t osOperationMode, uint8_t devOperationMode); +error_code_t writeConfigLM75BD(uint8_t devAddr, uint8_t osFaultQueueSize, + uint8_t osPolarity, uint8_t osOperationMode, + uint8_t devOperationMode); /** * @brief Handle an OS interrupt from the LM75BD diff --git a/services/thermal_mgr/thermal_mgr.c b/services/thermal_mgr/thermal_mgr.c index b41301ba..17866fbb 100644 --- a/services/thermal_mgr/thermal_mgr.c +++ b/services/thermal_mgr/thermal_mgr.c @@ -1,12 +1,15 @@ #include "thermal_mgr.h" +#include "console.h" #include "errors.h" #include "lm75bd.h" -#include "console.h" +#include "os_portmacro.h" +#include "os_projdefs.h" #include -#include #include +#include +#include #include #define THERMAL_MGR_STACK_SIZE 256U @@ -20,41 +23,58 @@ static StackType_t thermalMgrTaskStack[THERMAL_MGR_STACK_SIZE]; static QueueHandle_t thermalMgrQueueHandle; static StaticQueue_t thermalMgrQueueBuffer; -static uint8_t thermalMgrQueueStorageArea[THERMAL_MGR_QUEUE_LENGTH * THERMAL_MGR_QUEUE_ITEM_SIZE]; +static uint8_t thermalMgrQueueStorageArea[THERMAL_MGR_QUEUE_LENGTH * + THERMAL_MGR_QUEUE_ITEM_SIZE]; static void thermalMgr(void *pvParameters); void initThermalSystemManager(lm75bd_config_t *config) { memset(&thermalMgrTaskBuffer, 0, sizeof(thermalMgrTaskBuffer)); memset(thermalMgrTaskStack, 0, sizeof(thermalMgrTaskStack)); - - thermalMgrTaskHandle = xTaskCreateStatic( - thermalMgr, "thermalMgr", THERMAL_MGR_STACK_SIZE, - config, 1, thermalMgrTaskStack, &thermalMgrTaskBuffer); + + thermalMgrTaskHandle = + xTaskCreateStatic(thermalMgr, "thermalMgr", THERMAL_MGR_STACK_SIZE, + config, 1, thermalMgrTaskStack, &thermalMgrTaskBuffer); memset(&thermalMgrQueueBuffer, 0, sizeof(thermalMgrQueueBuffer)); memset(thermalMgrQueueStorageArea, 0, sizeof(thermalMgrQueueStorageArea)); - thermalMgrQueueHandle = xQueueCreateStatic( - THERMAL_MGR_QUEUE_LENGTH, THERMAL_MGR_QUEUE_ITEM_SIZE, - thermalMgrQueueStorageArea, &thermalMgrQueueBuffer); - + thermalMgrQueueHandle = + xQueueCreateStatic(THERMAL_MGR_QUEUE_LENGTH, THERMAL_MGR_QUEUE_ITEM_SIZE, + thermalMgrQueueStorageArea, &thermalMgrQueueBuffer); } error_code_t thermalMgrSendEvent(thermal_mgr_event_t *event) { /* Send an event to the thermal manager queue */ - - return ERR_CODE_SUCCESS; + if (xQueueSend(thermalMgrQueueHandle, event, (TickType_t)10) == pdTRUE) + return ERR_CODE_SUCCESS; + else + return ERR_CODE_QUEUE_FULL; } -void osHandlerLM75BD(void) { - /* Implement this function */ +void osHandlerLM75BD(void) { /* Implement this function */ + thermal_mgr_event_t event; + event.type = THERMAL_MGR_EVENT_MEASURE_TEMP_CMD; + thermalMgrSendEvent(&event); } static void thermalMgr(void *pvParameters) { - /* Implement this task */ + lm75bd_config_t details = *(lm75bd_config_t *)pvParameters; while (1) { - + thermal_mgr_event_t event; + if (xQueueReceive(thermalMgrQueueHandle, &event, (TickType_t)10) == + pdTRUE) { + if (event.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD) { + float val; + float *temp = &val; + readTempLM75BD(details.devAddr, temp); + if (*temp > details.hysteresisThresholdCelsius) + overTemperatureDetected(); + else + safeOperatingConditions(); + addTemperatureTelemetry(*temp); + } + } } } @@ -66,6 +86,6 @@ void overTemperatureDetected(void) { printConsole("Over temperature detected!\n"); } -void safeOperatingConditions(void) { +void safeOperatingConditions(void) { printConsole("Returned to safe operating conditions!\n"); } diff --git a/services/thermal_mgr/thermal_mgr.h b/services/thermal_mgr/thermal_mgr.h index 466b3e26..6fcd263b 100644 --- a/services/thermal_mgr/thermal_mgr.h +++ b/services/thermal_mgr/thermal_mgr.h @@ -1,11 +1,10 @@ #pragma once -#include "lm75bd.h" #include "errors.h" +#include "lm75bd.h" typedef enum { THERMAL_MGR_EVENT_MEASURE_TEMP_CMD, - } thermal_mgr_event_type_t; typedef struct { diff --git a/sys/errors.h b/sys/errors.h index 975f34e9..e7b3f599 100644 --- a/sys/errors.h +++ b/sys/errors.h @@ -3,21 +3,21 @@ /* Define new error codes here if needed */ typedef enum { - /* Common Errors 0 - 99 */ - ERR_CODE_SUCCESS = 0, - ERR_CODE_UNKNOWN = 1, - ERR_CODE_INVALID_ARG = 2, - ERR_CODE_INVALID_STATE = 3, + /* Common Errors 0 - 99 */ + ERR_CODE_SUCCESS = 0, + ERR_CODE_UNKNOWN = 1, + ERR_CODE_INVALID_ARG = 2, + ERR_CODE_INVALID_STATE = 3, - /* FreeRTOS errors */ - ERR_CODE_MUTEX_TIMEOUT = 100, - ERR_CODE_QUEUE_FULL = 101, - ERR_CODE_INVALID_QUEUE_MSG = 102, + /* FreeRTOS errors */ + ERR_CODE_MUTEX_TIMEOUT = 100, + ERR_CODE_QUEUE_FULL = 101, + ERR_CODE_INVALID_QUEUE_MSG = 102, - /* Driver errors */ - ERR_CODE_I2C_TRANSFER_TIMEOUT = 200, + /* Driver errors */ + ERR_CODE_I2C_TRANSFER_TIMEOUT = 200, - /* Logging errors */ - ERR_CODE_BUFF_TOO_SMALL = 300, - ERR_CODE_LOG_MSG_SILENCED = 301, + /* Logging errors */ + ERR_CODE_BUFF_TOO_SMALL = 300, + ERR_CODE_LOG_MSG_SILENCED = 301, } error_code_t; diff --git a/sys/i2c/i2c_io.c b/sys/i2c/i2c_io.c index 3d46b858..b715c197 100644 --- a/sys/i2c/i2c_io.c +++ b/sys/i2c/i2c_io.c @@ -2,10 +2,10 @@ #include "errors.h" #include +#include #include #include #include -#include #include #include @@ -31,9 +31,11 @@ void initI2C(void) { /* MOCKED I2C Functions. DO NOT MODIFY */ error_code_t i2cSendTo(uint8_t sAddr, uint8_t *buf, uint16_t numBytes) { - if (buf == NULL || numBytes < 1) return ERR_CODE_INVALID_ARG; + if (buf == NULL || numBytes < 1) + return ERR_CODE_INVALID_ARG; - if (i2cMutex == NULL) return ERR_CODE_INVALID_STATE; + if (i2cMutex == NULL) + return ERR_CODE_INVALID_STATE; if (xSemaphoreTake(i2cMutex, I2C_MUTEX_TIMEOUT) != pdTRUE) { return ERR_CODE_MUTEX_TIMEOUT; @@ -45,15 +47,17 @@ error_code_t i2cSendTo(uint8_t sAddr, uint8_t *buf, uint16_t numBytes) { lastTxBuff[1] = buf[1]; } - xSemaphoreGive(i2cMutex); // Won't fail because the mutex is taken correctly + xSemaphoreGive(i2cMutex); // Won't fail because the mutex is taken correctly return ERR_CODE_SUCCESS; } error_code_t i2cReceiveFrom(uint8_t sAddr, uint8_t *buf, uint16_t numBytes) { - if (buf == NULL || numBytes < 1) return ERR_CODE_INVALID_ARG; + if (buf == NULL || numBytes < 1) + return ERR_CODE_INVALID_ARG; - if (i2cMutex == NULL) return ERR_CODE_INVALID_STATE; + if (i2cMutex == NULL) + return ERR_CODE_INVALID_STATE; if (xSemaphoreTake(i2cMutex, I2C_MUTEX_TIMEOUT) != pdTRUE) { return ERR_CODE_MUTEX_TIMEOUT; @@ -62,19 +66,19 @@ error_code_t i2cReceiveFrom(uint8_t sAddr, uint8_t *buf, uint16_t numBytes) { uint16_t nextTemp = getLm75bdNextTempRegVal(); switch (lastTxBuff[0]) { - case 0: - buf[0] = (nextTemp >> 8) & 0xFF; - buf[1] = nextTemp & 0xFF; - break; - default: - for (int i = 0; i < numBytes; i++) { - buf[i] = 0; - } + case 0: + buf[0] = (nextTemp >> 8) & 0xFF; + buf[1] = nextTemp & 0xFF; + break; + default: + for (int i = 0; i < numBytes; i++) { + buf[i] = 0; + } } setOsActive(0); - xSemaphoreGive(i2cMutex); // Won't fail because the mutex is taken correctly + xSemaphoreGive(i2cMutex); // Won't fail because the mutex is taken correctly return ERR_CODE_SUCCESS; } diff --git a/sys/i2c/i2c_io.h b/sys/i2c/i2c_io.h index 243fe672..a597982c 100644 --- a/sys/i2c/i2c_io.h +++ b/sys/i2c/i2c_io.h @@ -18,29 +18,29 @@ void initI2C(void); /** * @brief Sends the contents of buf to the device with address sAddr. - * + * * @param sAddr The address of the device to send to. * @param buf The buffer containing the data to send. * @param numBytes The number of bytes to send. * @return error_code_t An error code indicating the status of the operation. - * @note: Assume this function will handle transmitting the device address and setting - * the R/W bit before sending data. + * @note: Assume this function will handle transmitting the device address and + * setting the R/W bit before sending data. */ error_code_t i2cSendTo(uint8_t sAddr, uint8_t *buf, uint16_t numBytes); /** - * @brief Receives numBytes from the device with address sAddr and stores them in buf. - * + * @brief Receives numBytes from the device with address sAddr and stores them + * in buf. + * * @param sAddr The address of the device to receive from. * @param buf The buffer to store the received data in. * @param numBytes The number of bytes to receive. * @return error_code_t An error code indicating the status of the operation. - * @note: Assume this function will handle transmitting the device address and setting - * the R/W bit before receiving data. + * @note: Assume this function will handle transmitting the device address and + * setting the R/W bit before receiving data. */ error_code_t i2cReceiveFrom(uint8_t sAddr, uint8_t *buf, uint16_t numBytes); - /* Functions used to set up test environment */ /* DO NOT TOUCH */ From 53af5631d6820b64ba9261ecf1689f418c045110 Mon Sep 17 00:00:00 2001 From: Shrey Varma Date: Sat, 4 Nov 2023 02:14:51 -0400 Subject: [PATCH 2/3] implemented bug fixes and logic issues --- lm75bd/lm75bd.c | 19 +++++++++-------- lm75bd/lm75bd.h | 2 ++ services/thermal_mgr/thermal_mgr.c | 33 +++++++++++++++++++++--------- services/thermal_mgr/thermal_mgr.h | 1 + sys/errors.h | 1 + 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/lm75bd/lm75bd.c b/lm75bd/lm75bd.c index 1490ebaa..ae32ca37 100644 --- a/lm75bd/lm75bd.c +++ b/lm75bd/lm75bd.c @@ -29,17 +29,20 @@ error_code_t lm75bdInit(lm75bd_config_t *config) { } error_code_t readTempLM75BD(uint8_t devAddr, float *temp) { - /* Implement this driver function */ + // check if temp is allocated + if (!temp) + return ERR_CODE_NULL_ARG; // set pointer register to temperature - uint8_t point_reg = 0x00; - uint8_t buf[1] = {point_reg}; - i2cSendTo(devAddr, buf, 1); - + uint8_t buf[1] = {LM75BD_OBC_TEMP_REG}; + error_code_t errCode; + RETURN_IF_ERROR_CODE(i2cSendTo(devAddr, buf, 1)); // read data from sensor - uint8_t temp_bytes[2] = {}; - i2cReceiveFrom(devAddr, temp_bytes, 2); - int16_t combined = ((temp_bytes[0] << 8) | temp_bytes[1]); + uint8_t tempBytes[2] = {0}; + RETURN_IF_ERROR_CODE(i2cReceiveFrom(devAddr, tempBytes, 2)); + + // convert bytes to temperature + int16_t combined = ((tempBytes[0] << 8) | tempBytes[1]); combined = combined >> 5; *temp = combined * 0.125; return ERR_CODE_SUCCESS; diff --git a/lm75bd/lm75bd.h b/lm75bd/lm75bd.h index da885eb3..fdeb151b 100644 --- a/lm75bd/lm75bd.h +++ b/lm75bd/lm75bd.h @@ -17,6 +17,8 @@ #define LM75BD_OS_OP_MODE_COMP 0x00U #define LM75BD_OS_OP_MODE_INT 0x01U +#define LM75BD_OBC_TEMP_REG 0x00 + // Default temperature thresholds #define LM75BD_DEFAULT_OT_THRESH 80.0f #define LM75BD_DEFAULT_HYST_THRESH 75.0f diff --git a/services/thermal_mgr/thermal_mgr.c b/services/thermal_mgr/thermal_mgr.c index 17866fbb..91540348 100644 --- a/services/thermal_mgr/thermal_mgr.c +++ b/services/thermal_mgr/thermal_mgr.c @@ -2,6 +2,7 @@ #include "console.h" #include "errors.h" #include "lm75bd.h" +#include "logging.h" #include "os_portmacro.h" #include "os_projdefs.h" @@ -46,7 +47,9 @@ void initThermalSystemManager(lm75bd_config_t *config) { error_code_t thermalMgrSendEvent(thermal_mgr_event_t *event) { /* Send an event to the thermal manager queue */ - if (xQueueSend(thermalMgrQueueHandle, event, (TickType_t)10) == pdTRUE) + if (!event) + return ERR_CODE_NULL_ARG; + if (xQueueSend(thermalMgrQueueHandle, event, (TickType_t)0) == pdTRUE) return ERR_CODE_SUCCESS; else return ERR_CODE_QUEUE_FULL; @@ -54,7 +57,7 @@ error_code_t thermalMgrSendEvent(thermal_mgr_event_t *event) { void osHandlerLM75BD(void) { /* Implement this function */ thermal_mgr_event_t event; - event.type = THERMAL_MGR_EVENT_MEASURE_TEMP_CMD; + event.type = THERNAL_MGR_EVENT_CHECK_OS; thermalMgrSendEvent(&event); } @@ -64,15 +67,25 @@ static void thermalMgr(void *pvParameters) { thermal_mgr_event_t event; if (xQueueReceive(thermalMgrQueueHandle, &event, (TickType_t)10) == pdTRUE) { - if (event.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD) { + if (event.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD || + event.type == THERNAL_MGR_EVENT_CHECK_OS) { float val; - float *temp = &val; - readTempLM75BD(details.devAddr, temp); - if (*temp > details.hysteresisThresholdCelsius) - overTemperatureDetected(); - else - safeOperatingConditions(); - addTemperatureTelemetry(*temp); + error_code_t errCode = readTempLM75BD(details.devAddr, &val); + if (errCode != ERR_CODE_SUCCESS) { + LOG_ERROR_CODE(errCode); + // ensure that if CHECK_OS event was sent, that the temperature gets + // if it failed the first time attempt to CHECK_OS again + if (event.type == THERNAL_MGR_EVENT_CHECK_OS) + thermalMgrSendEvent(&event); + continue; + } + if (event.type == THERNAL_MGR_EVENT_CHECK_OS) { + if (val > details.hysteresisThresholdCelsius) + overTemperatureDetected(); + else + safeOperatingConditions(); + } + addTemperatureTelemetry(val); } } } diff --git a/services/thermal_mgr/thermal_mgr.h b/services/thermal_mgr/thermal_mgr.h index 6fcd263b..05f3b5c4 100644 --- a/services/thermal_mgr/thermal_mgr.h +++ b/services/thermal_mgr/thermal_mgr.h @@ -5,6 +5,7 @@ typedef enum { THERMAL_MGR_EVENT_MEASURE_TEMP_CMD, + THERNAL_MGR_EVENT_CHECK_OS, } thermal_mgr_event_type_t; typedef struct { diff --git a/sys/errors.h b/sys/errors.h index e7b3f599..37587e7e 100644 --- a/sys/errors.h +++ b/sys/errors.h @@ -8,6 +8,7 @@ typedef enum { ERR_CODE_UNKNOWN = 1, ERR_CODE_INVALID_ARG = 2, ERR_CODE_INVALID_STATE = 3, + ERR_CODE_NULL_ARG = 4, /* FreeRTOS errors */ ERR_CODE_MUTEX_TIMEOUT = 100, From 3891adb4024f3527e477820ce18e19d5b7137db1 Mon Sep 17 00:00:00 2001 From: Shrey Varma Date: Sun, 19 Nov 2023 02:21:20 -0500 Subject: [PATCH 3/3] Second round of fixes --- services/thermal_mgr/thermal_mgr.c | 11 +++++------ sys/errors.h | 1 + 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/services/thermal_mgr/thermal_mgr.c b/services/thermal_mgr/thermal_mgr.c index 91540348..7b2f36ac 100644 --- a/services/thermal_mgr/thermal_mgr.c +++ b/services/thermal_mgr/thermal_mgr.c @@ -49,6 +49,9 @@ error_code_t thermalMgrSendEvent(thermal_mgr_event_t *event) { /* Send an event to the thermal manager queue */ if (!event) return ERR_CODE_NULL_ARG; + if (!thermalMgrQueueHandle) + return ERR_CODE_NULL_QUEUE; + if (xQueueSend(thermalMgrQueueHandle, event, (TickType_t)0) == pdTRUE) return ERR_CODE_SUCCESS; else @@ -73,10 +76,6 @@ static void thermalMgr(void *pvParameters) { error_code_t errCode = readTempLM75BD(details.devAddr, &val); if (errCode != ERR_CODE_SUCCESS) { LOG_ERROR_CODE(errCode); - // ensure that if CHECK_OS event was sent, that the temperature gets - // if it failed the first time attempt to CHECK_OS again - if (event.type == THERNAL_MGR_EVENT_CHECK_OS) - thermalMgrSendEvent(&event); continue; } if (event.type == THERNAL_MGR_EVENT_CHECK_OS) { @@ -84,8 +83,8 @@ static void thermalMgr(void *pvParameters) { overTemperatureDetected(); else safeOperatingConditions(); - } - addTemperatureTelemetry(val); + } else + addTemperatureTelemetry(val); } } } diff --git a/sys/errors.h b/sys/errors.h index 37587e7e..20bf22ba 100644 --- a/sys/errors.h +++ b/sys/errors.h @@ -9,6 +9,7 @@ typedef enum { ERR_CODE_INVALID_ARG = 2, ERR_CODE_INVALID_STATE = 3, ERR_CODE_NULL_ARG = 4, + ERR_CODE_NULL_QUEUE = 5, /* FreeRTOS errors */ ERR_CODE_MUTEX_TIMEOUT = 100,