From cc50f5bab49d723606c9c5728f88ab06e242ec19 Mon Sep 17 00:00:00 2001 From: Ahmed Elsaigh Date: Tue, 29 Oct 2024 21:42:32 -0400 Subject: [PATCH] Implement OS Handler --- lm75bd/lm75bd.c | 4 ++-- services/thermal_mgr/thermal_mgr.c | 22 ++++++++++++++++++---- services/thermal_mgr/thermal_mgr.h | 1 + 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lm75bd/lm75bd.c b/lm75bd/lm75bd.c index d27df54f..f386d17d 100644 --- a/lm75bd/lm75bd.c +++ b/lm75bd/lm75bd.c @@ -43,8 +43,8 @@ error_code_t readTempLM75BD(uint8_t devAddr, float *temp) { // if 11 bit is set, sign is -ve, so convert the 11 bit val to its equivalent 16 bit val // otherwise, sign is +ve, and the 11 bit val will be the same in 16 bits if (temp_reg_val & 0x0400U) { - // by simply setting everything above the 11 bits to 1 (top 5 bits here) - temp_reg_val |= 0xF800U; + // by simply setting everything above the 11 bits to 1 (top 5 bits here) + temp_reg_val |= 0xF800U; } printf("Temperature Register Value: %i\n", temp_reg_val); diff --git a/services/thermal_mgr/thermal_mgr.c b/services/thermal_mgr/thermal_mgr.c index 8bb8416e..fabfa0d4 100644 --- a/services/thermal_mgr/thermal_mgr.c +++ b/services/thermal_mgr/thermal_mgr.c @@ -51,6 +51,10 @@ error_code_t thermalMgrSendEvent(thermal_mgr_event_t *event) { void osHandlerLM75BD(void) { /* Implement this function */ + thermal_mgr_event_t osEvent = {0}; + osEvent.type = THERMAL_MGR_EVENT_OS_CMD; + + thermalMgrSendEvent(&osEvent); } static void thermalMgr(void *pvParameters) { // what is pvParameters used for? @@ -60,12 +64,22 @@ static void thermalMgr(void *pvParameters) { // what is pvParameters used for? while (1) { - if (xQueueReceive(thermalMgrQueueHandle, &queueEventItemBuffer, (TickType_t) 10) == pdPASS - && queueEventItemBuffer.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD) { + if (xQueueReceive(thermalMgrQueueHandle, &queueEventItemBuffer, (TickType_t) 10) == pdPASS) { + + float tempC; + readTempLM75BD(LM75BD_OBC_I2C_ADDR, &tempC); - float tempC; - readTempLM75BD(LM75BD_OBC_I2C_ADDR, &tempC); + if (queueEventItemBuffer.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD) { addTemperatureTelemetry(tempC); + } else if (queueEventItemBuffer.type == THERMAL_MGR_EVENT_OS_CMD) { + if (tempC > 75.0) { + overTemperatureDetected(); + } else { + safeOperatingConditions(); + } + // To reset the OS interrupt + readTempLM75BD(LM75BD_OBC_I2C_ADDR, &tempC); + } } } } diff --git a/services/thermal_mgr/thermal_mgr.h b/services/thermal_mgr/thermal_mgr.h index 466b3e26..c619da6f 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, + THERMAL_MGR_EVENT_OS_CMD, } thermal_mgr_event_type_t;