From 17681a7d8b928ec508bd77e1f32dfc930686b3d8 Mon Sep 17 00:00:00 2001 From: Sean Zhang Date: Tue, 7 Nov 2023 23:01:30 -0500 Subject: [PATCH 01/12] implemented necessary functions and tasks --- lm75bd/lm75bd.c | 16 ++++++++++++- lm75bd/lm75bd.h | 2 +- services/thermal_mgr/thermal_mgr.c | 36 +++++++++++++++++++++++++----- services/thermal_mgr/thermal_mgr.h | 2 +- 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/lm75bd/lm75bd.c b/lm75bd/lm75bd.c index 7d63da66..dd40c46f 100644 --- a/lm75bd/lm75bd.c +++ b/lm75bd/lm75bd.c @@ -26,8 +26,22 @@ error_code_t lm75bdInit(lm75bd_config_t *config) { } error_code_t readTempLM75BD(uint8_t devAddr, float *temp) { - /* Implement this driver function */ + // declare error code variable + error_code_t errCode; + // set pointer register to 'temperature sensor' + uint8_t writeBuf[] = {0}; + errCode = i2cSendTo(devAddr, writeBuf, 1); + RETURN_IF_ERROR_CODE(errCode); + + // read temperature from sensor + uint8_t readBuf[2] = {0}; + errCode = i2cReceiveFrom(devAddr, readBuf, 2); + RETURN_IF_ERROR_CODE(errCode); + + // convert temperature reading to celsius + *temp = ((readBuf[0] << 3) | (readBuf[1] >> 5)) * 0.125; + return ERR_CODE_SUCCESS; } diff --git a/lm75bd/lm75bd.h b/lm75bd/lm75bd.h index 9a2356af..92b15bc6 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 /* LM75BD Configuration Values */ #define LM75BD_DEV_OP_MODE_NORMAL 0x00U diff --git a/services/thermal_mgr/thermal_mgr.c b/services/thermal_mgr/thermal_mgr.c index b41301ba..a6f6f836 100644 --- a/services/thermal_mgr/thermal_mgr.c +++ b/services/thermal_mgr/thermal_mgr.c @@ -42,19 +42,43 @@ void initThermalSystemManager(lm75bd_config_t *config) { } error_code_t thermalMgrSendEvent(thermal_mgr_event_t *event) { - /* Send an event to the thermal manager queue */ - - return ERR_CODE_SUCCESS; + if (&thermalMgrQueueHandle != NULL) + if (event != NULL) { + if (xQueueSend(thermalMgrQueueHandle, event, 0 == pdPASS)) + return ERR_CODE_SUCCESS; + else + return ERR_CODE_QUEUE_FULL; + } + else + return ERR_CODE_INVALID_ARG; + + return ERR_CODE_INVALID_QUEUE_MSG; } void osHandlerLM75BD(void) { - /* Implement this function */ + thermal_mgr_event_t event; + event.type = THERMAL_MGR_EVENT_INTERRUPT_CMD; + thermalMgr(&event); } static void thermalMgr(void *pvParameters) { - /* Implement this task */ + thermal_mgr_event_t eventBuf; + while (1) { - + if (xQueueReceive(thermalMgrQueueHandle, &eventBuf, 10)) { + if (eventBuf.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD) { + float *temp; + if (readTemperature(LM75BD_OBC_I2C_ADDR, temp) == ERR_CODE_SUCCESS) + addTemperatureTelemetry(*temp); + } + else if (eventBuf.type == THERMAL_MGR_EVENT_INTERRUPT_CMD) { + float *temp; + if (readTemperature(LM75BD_OBC_I2C_ADDR, temp) >= 75) + overTemperatureDetected(); + else + safeOperatingConditions(); + } + } } } diff --git a/services/thermal_mgr/thermal_mgr.h b/services/thermal_mgr/thermal_mgr.h index 466b3e26..5a58c833 100644 --- a/services/thermal_mgr/thermal_mgr.h +++ b/services/thermal_mgr/thermal_mgr.h @@ -5,7 +5,7 @@ typedef enum { THERMAL_MGR_EVENT_MEASURE_TEMP_CMD, - + THERMAL_MGR_EVENT_INTERRUPT_CMD, } thermal_mgr_event_type_t; typedef struct { From d45359418d51f4eb00b1d58fa1597a4080d8daad Mon Sep 17 00:00:00 2001 From: Sean Zhang Date: Wed, 8 Nov 2023 08:40:41 -0500 Subject: [PATCH 02/12] made changes to thermal management task --- services/thermal_mgr/thermal_mgr.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/services/thermal_mgr/thermal_mgr.c b/services/thermal_mgr/thermal_mgr.c index a6f6f836..66a7cc77 100644 --- a/services/thermal_mgr/thermal_mgr.c +++ b/services/thermal_mgr/thermal_mgr.c @@ -42,15 +42,14 @@ void initThermalSystemManager(lm75bd_config_t *config) { } error_code_t thermalMgrSendEvent(thermal_mgr_event_t *event) { - if (&thermalMgrQueueHandle != NULL) - if (event != NULL) { - if (xQueueSend(thermalMgrQueueHandle, event, 0 == pdPASS)) - return ERR_CODE_SUCCESS; - else - return ERR_CODE_QUEUE_FULL; - } + if (event != NULL) { + if (xQueueSend(thermalMgrQueueHandle, event, 0 == pdPASS)) + return ERR_CODE_SUCCESS; else - return ERR_CODE_INVALID_ARG; + return ERR_CODE_QUEUE_FULL; + } + else + return ERR_CODE_INVALID_ARG; return ERR_CODE_INVALID_QUEUE_MSG; } From a4f78d4133aba678969285d90ac3da4a74056fe7 Mon Sep 17 00:00:00 2001 From: Sean Zhang Date: Wed, 8 Nov 2023 08:52:36 -0500 Subject: [PATCH 03/12] fixed temperature conversion --- lm75bd/lm75bd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lm75bd/lm75bd.c b/lm75bd/lm75bd.c index dd40c46f..c211691d 100644 --- a/lm75bd/lm75bd.c +++ b/lm75bd/lm75bd.c @@ -40,7 +40,10 @@ error_code_t readTempLM75BD(uint8_t devAddr, float *temp) { RETURN_IF_ERROR_CODE(errCode); // convert temperature reading to celsius - *temp = ((readBuf[0] << 3) | (readBuf[1] >> 5)) * 0.125; + int16_t MSByte = readBuf[0] << 3; + int16_t LSByte = readBuf[1] >> 5; + + *temp = (MSByte | LSByte) * 0.125; return ERR_CODE_SUCCESS; } From 0c1594f54f252bd312c3632835642074cf7b1ef2 Mon Sep 17 00:00:00 2001 From: Sean Zhang Date: Wed, 8 Nov 2023 11:01:07 -0500 Subject: [PATCH 04/12] fixed temperature conversion for negative values --- lm75bd/lm75bd.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lm75bd/lm75bd.c b/lm75bd/lm75bd.c index c211691d..04a8f68a 100644 --- a/lm75bd/lm75bd.c +++ b/lm75bd/lm75bd.c @@ -40,10 +40,9 @@ error_code_t readTempLM75BD(uint8_t devAddr, float *temp) { RETURN_IF_ERROR_CODE(errCode); // convert temperature reading to celsius - int16_t MSByte = readBuf[0] << 3; - int16_t LSByte = readBuf[1] >> 5; - - *temp = (MSByte | LSByte) * 0.125; + int16_t tempC = (readBuf[0] << 8) | readBuf[1]; + tempC >>= 5; + *temp = tempC * 0.125; return ERR_CODE_SUCCESS; } From c571d44ba5eac3f0905a1c3b833b27a7d2b2e79d Mon Sep 17 00:00:00 2001 From: Sean Zhang Date: Wed, 8 Nov 2023 11:01:49 -0500 Subject: [PATCH 05/12] made minor function call changes --- services/thermal_mgr/thermal_mgr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/thermal_mgr/thermal_mgr.c b/services/thermal_mgr/thermal_mgr.c index 66a7cc77..f95806ad 100644 --- a/services/thermal_mgr/thermal_mgr.c +++ b/services/thermal_mgr/thermal_mgr.c @@ -67,12 +67,12 @@ static void thermalMgr(void *pvParameters) { if (xQueueReceive(thermalMgrQueueHandle, &eventBuf, 10)) { if (eventBuf.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD) { float *temp; - if (readTemperature(LM75BD_OBC_I2C_ADDR, temp) == ERR_CODE_SUCCESS) + if (readTempLM75BD(LM75BD_OBC_I2C_ADDR, temp) == ERR_CODE_SUCCESS) addTemperatureTelemetry(*temp); } else if (eventBuf.type == THERMAL_MGR_EVENT_INTERRUPT_CMD) { float *temp; - if (readTemperature(LM75BD_OBC_I2C_ADDR, temp) >= 75) + if (readTempLM75BD(LM75BD_OBC_I2C_ADDR, temp) >= 75) overTemperatureDetected(); else safeOperatingConditions(); From 1f83d8420331d47a8441cd1f15520c1d1a8b233f Mon Sep 17 00:00:00 2001 From: Sean Zhang Date: Wed, 8 Nov 2023 12:17:06 -0500 Subject: [PATCH 06/12] modified over-temperature condition --- services/thermal_mgr/thermal_mgr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/thermal_mgr/thermal_mgr.c b/services/thermal_mgr/thermal_mgr.c index f95806ad..366c51ee 100644 --- a/services/thermal_mgr/thermal_mgr.c +++ b/services/thermal_mgr/thermal_mgr.c @@ -72,7 +72,7 @@ static void thermalMgr(void *pvParameters) { } else if (eventBuf.type == THERMAL_MGR_EVENT_INTERRUPT_CMD) { float *temp; - if (readTempLM75BD(LM75BD_OBC_I2C_ADDR, temp) >= 75) + if (readTempLM75BD(LM75BD_OBC_I2C_ADDR, temp) > 75) overTemperatureDetected(); else safeOperatingConditions(); From 0ed88c8874bad031392a768a1c7accc92dedccce Mon Sep 17 00:00:00 2001 From: Sean Zhang Date: Wed, 8 Nov 2023 13:31:16 -0500 Subject: [PATCH 07/12] major bug fixes --- services/thermal_mgr/thermal_mgr.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/services/thermal_mgr/thermal_mgr.c b/services/thermal_mgr/thermal_mgr.c index 366c51ee..ed4e62bc 100644 --- a/services/thermal_mgr/thermal_mgr.c +++ b/services/thermal_mgr/thermal_mgr.c @@ -43,7 +43,7 @@ void initThermalSystemManager(lm75bd_config_t *config) { error_code_t thermalMgrSendEvent(thermal_mgr_event_t *event) { if (event != NULL) { - if (xQueueSend(thermalMgrQueueHandle, event, 0 == pdPASS)) + if (xQueueSend(thermalMgrQueueHandle, (void *) event, (TickType_t) 0) == pdPASS) return ERR_CODE_SUCCESS; else return ERR_CODE_QUEUE_FULL; @@ -57,22 +57,23 @@ error_code_t thermalMgrSendEvent(thermal_mgr_event_t *event) { void osHandlerLM75BD(void) { thermal_mgr_event_t event; event.type = THERMAL_MGR_EVENT_INTERRUPT_CMD; - thermalMgr(&event); + thermalMgrSendEvent(&event); } static void thermalMgr(void *pvParameters) { thermal_mgr_event_t eventBuf; while (1) { - if (xQueueReceive(thermalMgrQueueHandle, &eventBuf, 10)) { + + float temp; + error_code_t errCode = readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temp); + if (xQueueReceive(thermalMgrQueueHandle, &eventBuf, 10) == pdPASS) { if (eventBuf.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD) { - float *temp; - if (readTempLM75BD(LM75BD_OBC_I2C_ADDR, temp) == ERR_CODE_SUCCESS) - addTemperatureTelemetry(*temp); + if (errCode == ERR_CODE_SUCCESS) + addTemperatureTelemetry(temp); } else if (eventBuf.type == THERMAL_MGR_EVENT_INTERRUPT_CMD) { - float *temp; - if (readTempLM75BD(LM75BD_OBC_I2C_ADDR, temp) > 75) + if (temp > 75) overTemperatureDetected(); else safeOperatingConditions(); From fb1b03efe52d77416815ca037ba255572b7a1055 Mon Sep 17 00:00:00 2001 From: Sean Zhang Date: Wed, 8 Nov 2023 17:40:44 -0500 Subject: [PATCH 08/12] made suggested changes --- lm75bd/lm75bd.c | 8 +++----- services/thermal_mgr/thermal_mgr.c | 21 ++++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lm75bd/lm75bd.c b/lm75bd/lm75bd.c index 04a8f68a..48df5210 100644 --- a/lm75bd/lm75bd.c +++ b/lm75bd/lm75bd.c @@ -30,14 +30,12 @@ error_code_t readTempLM75BD(uint8_t devAddr, float *temp) { error_code_t errCode; // set pointer register to 'temperature sensor' - uint8_t writeBuf[] = {0}; - errCode = i2cSendTo(devAddr, writeBuf, 1); - RETURN_IF_ERROR_CODE(errCode); + uint8_t writeBuf[1] = {0}; + RETURN_IF_ERROR_CODE(i2cSendTo(devAddr, writeBuf, 1)); // read temperature from sensor uint8_t readBuf[2] = {0}; - errCode = i2cReceiveFrom(devAddr, readBuf, 2); - RETURN_IF_ERROR_CODE(errCode); + RETURN_IF_ERROR_CODE(i2cReceiveFrom(devAddr, readBuf, 2)); // convert temperature reading to celsius int16_t tempC = (readBuf[0] << 8) | readBuf[1]; diff --git a/services/thermal_mgr/thermal_mgr.c b/services/thermal_mgr/thermal_mgr.c index ed4e62bc..89e9ac27 100644 --- a/services/thermal_mgr/thermal_mgr.c +++ b/services/thermal_mgr/thermal_mgr.c @@ -42,14 +42,16 @@ void initThermalSystemManager(lm75bd_config_t *config) { } error_code_t thermalMgrSendEvent(thermal_mgr_event_t *event) { - if (event != NULL) { - if (xQueueSend(thermalMgrQueueHandle, (void *) event, (TickType_t) 0) == pdPASS) - return ERR_CODE_SUCCESS; + if (&thermalMgrQueueHandle != NULL) { + if (event != NULL) { + if (xQueueSend(thermalMgrQueueHandle, (void *) event, (TickType_t) 0) == pdPASS) + return ERR_CODE_SUCCESS; + else + return ERR_CODE_QUEUE_FULL; + } else - return ERR_CODE_QUEUE_FULL; + return ERR_CODE_INVALID_ARG; } - else - return ERR_CODE_INVALID_ARG; return ERR_CODE_INVALID_QUEUE_MSG; } @@ -61,18 +63,19 @@ void osHandlerLM75BD(void) { } static void thermalMgr(void *pvParameters) { - thermal_mgr_event_t eventBuf; - while (1) { + thermal_mgr_event_t eventBuf; float temp; - error_code_t errCode = readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temp); + if (xQueueReceive(thermalMgrQueueHandle, &eventBuf, 10) == pdPASS) { if (eventBuf.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD) { + error_code_t errCode = readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temp); if (errCode == ERR_CODE_SUCCESS) addTemperatureTelemetry(temp); } else if (eventBuf.type == THERMAL_MGR_EVENT_INTERRUPT_CMD) { + error_code_t errCode = readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temp); if (temp > 75) overTemperatureDetected(); else From 8c180a1e81bda1f2f0947faeb7599964d05e4b26 Mon Sep 17 00:00:00 2001 From: SeanZhang425 <146991529+SeanZhang425@users.noreply.github.com> Date: Mon, 18 Dec 2023 19:43:46 -0500 Subject: [PATCH 09/12] Modified thermalMgr function to log any errors and check if the readTemp function call was successful --- services/thermal_mgr/thermal_mgr.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/services/thermal_mgr/thermal_mgr.c b/services/thermal_mgr/thermal_mgr.c index 89e9ac27..521bee14 100644 --- a/services/thermal_mgr/thermal_mgr.c +++ b/services/thermal_mgr/thermal_mgr.c @@ -73,13 +73,17 @@ static void thermalMgr(void *pvParameters) { error_code_t errCode = readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temp); if (errCode == ERR_CODE_SUCCESS) addTemperatureTelemetry(temp); + else + LOG_ERROR_CODE(errCode); } else if (eventBuf.type == THERMAL_MGR_EVENT_INTERRUPT_CMD) { error_code_t errCode = readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temp); - if (temp > 75) - overTemperatureDetected(); - else - safeOperatingConditions(); + if (errCode == ERR_CODE_SUCCESS) { + if (temp > 75) + overTemperatureDetected(); + else + safeOperatingConditions(); + } } } } From 381670c9f74809eec2f8cb1bf8828d9104df23fa Mon Sep 17 00:00:00 2001 From: Sean Zhang Date: Mon, 18 Dec 2023 23:40:36 -0500 Subject: [PATCH 10/12] Bug fixes for recent changes --- Testing/Temporary/CTestCostData.txt | 1 + Testing/Temporary/LastTest.log | 3 +++ services/thermal_mgr/thermal_mgr.c | 14 ++++++++++---- 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 Testing/Temporary/CTestCostData.txt create mode 100644 Testing/Temporary/LastTest.log diff --git a/Testing/Temporary/CTestCostData.txt b/Testing/Temporary/CTestCostData.txt new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/Testing/Temporary/CTestCostData.txt @@ -0,0 +1 @@ +--- diff --git a/Testing/Temporary/LastTest.log b/Testing/Temporary/LastTest.log new file mode 100644 index 00000000..33b7c184 --- /dev/null +++ b/Testing/Temporary/LastTest.log @@ -0,0 +1,3 @@ +Start testing: Dec 18 23:32 EST +---------------------------------------------------------- +End testing: Dec 18 23:32 EST diff --git a/services/thermal_mgr/thermal_mgr.c b/services/thermal_mgr/thermal_mgr.c index 89e9ac27..6c737601 100644 --- a/services/thermal_mgr/thermal_mgr.c +++ b/services/thermal_mgr/thermal_mgr.c @@ -2,7 +2,7 @@ #include "errors.h" #include "lm75bd.h" #include "console.h" - +#include "logging.h" #include #include #include @@ -73,13 +73,19 @@ static void thermalMgr(void *pvParameters) { error_code_t errCode = readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temp); if (errCode == ERR_CODE_SUCCESS) addTemperatureTelemetry(temp); + else + LOG_ERROR_CODE(errCode); } else if (eventBuf.type == THERMAL_MGR_EVENT_INTERRUPT_CMD) { error_code_t errCode = readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temp); - if (temp > 75) - overTemperatureDetected(); + if (errCode == ERR_CODE_SUCCESS) { + if (temp > 75) + overTemperatureDetected(); + else + safeOperatingConditions(); + } else - safeOperatingConditions(); + LOG_ERROR_CODE(errCode); } } } From fbf8d8660c67e348f4720106da121805942a0be8 Mon Sep 17 00:00:00 2001 From: SeanZhang425 <146991529+SeanZhang425@users.noreply.github.com> Date: Thu, 21 Dec 2023 21:54:39 -0500 Subject: [PATCH 11/12] Reformatted conditions in the thermalMgrSendEvent() function --- services/thermal_mgr/thermal_mgr.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/services/thermal_mgr/thermal_mgr.c b/services/thermal_mgr/thermal_mgr.c index 6c737601..77525e48 100644 --- a/services/thermal_mgr/thermal_mgr.c +++ b/services/thermal_mgr/thermal_mgr.c @@ -42,18 +42,16 @@ void initThermalSystemManager(lm75bd_config_t *config) { } error_code_t thermalMgrSendEvent(thermal_mgr_event_t *event) { - if (&thermalMgrQueueHandle != NULL) { - if (event != NULL) { - if (xQueueSend(thermalMgrQueueHandle, (void *) event, (TickType_t) 0) == pdPASS) - return ERR_CODE_SUCCESS; - else - return ERR_CODE_QUEUE_FULL; - } - else - return ERR_CODE_INVALID_ARG; - } - - return ERR_CODE_INVALID_QUEUE_MSG; + if (&thermalMgrQueueHandle != NULL) + return ERR_CODE_INVALID_STATE; + + if (event != NULL) + return ERR_CODE_INVALID_ARG; + + if (xQueueSend(thermalMgrQueueHandle, (void *) event, (TickType_t) 0) != pdPASS) + return ERR_CODE_QUEUE_FULL; + + return ERR_CODE_SUCCESS; } void osHandlerLM75BD(void) { From a6917c6cfce0e42e778af8028b5eae4b4039d03c Mon Sep 17 00:00:00 2001 From: SeanZhang425 <146991529+SeanZhang425@users.noreply.github.com> Date: Sun, 24 Dec 2023 08:08:47 -0800 Subject: [PATCH 12/12] Bug fixes I don't know how this slipped sorry --- services/thermal_mgr/thermal_mgr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/thermal_mgr/thermal_mgr.c b/services/thermal_mgr/thermal_mgr.c index 77525e48..2a8e889b 100644 --- a/services/thermal_mgr/thermal_mgr.c +++ b/services/thermal_mgr/thermal_mgr.c @@ -42,10 +42,10 @@ void initThermalSystemManager(lm75bd_config_t *config) { } error_code_t thermalMgrSendEvent(thermal_mgr_event_t *event) { - if (&thermalMgrQueueHandle != NULL) + if (&thermalMgrQueueHandle == NULL) return ERR_CODE_INVALID_STATE; - if (event != NULL) + if (event == NULL) return ERR_CODE_INVALID_ARG; if (xQueueSend(thermalMgrQueueHandle, (void *) event, (TickType_t) 0) != pdPASS)