diff --git a/lm75bd/lm75bd.c b/lm75bd/lm75bd.c index 7d63da66..03b519d9 100644 --- a/lm75bd/lm75bd.c +++ b/lm75bd/lm75bd.c @@ -25,9 +25,33 @@ error_code_t lm75bdInit(lm75bd_config_t *config) { return ERR_CODE_SUCCESS; } +/** + * @brief Converts data from LM75B temperature sensor to Celcius + * + * @param devAddr - I2C device address of sensor + * @param temp - Pointer to store converted temperature value in Celsius + * @return ERR_CODE_SUCCESS if reading and conversion succeed + */ error_code_t readTempLM75BD(uint8_t devAddr, float *temp) { - /* Implement this driver function */ - + + // Stores temperature register value + uint8_t sendBuffer = 0x0U; + uint8_t buffer[2]; + uint16_t temperature = 0; + + // Use pointer register to select internal temperature register + i2cSendTo(devAddr, &sendBuffer, 1U); + + // Get data on temperature sensor + i2cReceiveFrom(devAddr, buffer, 2U); + + // Convert buffer to one binary integer + temperature = ((buffer[0] << 8) | buffer[1]) >> 5; + + if((temperature >> 10) == 0) *temp = (float)(temperature * 0.125); + // 0xFFFF deletes extra ones from flipped temperature data + else *temp = -(((~temperature) & (0xFFFF >> 5)) + 1)*0.125; + return ERR_CODE_SUCCESS; } diff --git a/lm75bd/lm75bd.h b/lm75bd/lm75bd.h index 9a2356af..43308575 100644 --- a/lm75bd/lm75bd.h +++ b/lm75bd/lm75bd.h @@ -5,7 +5,8 @@ #include /* LM75BD I2C Device Address */ -#define LM75BD_OBC_I2C_ADDR /* Define the address here */ +#define LM75BD_OBC_I2C_ADDR 0x4FU /* Define the address here */ +// A0, A1, A2 all connected to VCC /* 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..770cc995 100644 --- a/services/thermal_mgr/thermal_mgr.c +++ b/services/thermal_mgr/thermal_mgr.c @@ -41,20 +41,46 @@ void initThermalSystemManager(lm75bd_config_t *config) { } +/** + * @brief Sends event to thermal manager queue + * + * @param event - Pointer to thermal manager event to send + * @return ERR_CODE_SUCCESS if the event is successfully sent + */ error_code_t thermalMgrSendEvent(thermal_mgr_event_t *event) { /* Send an event to the thermal manager queue */ - + xQueueSend(thermalMgrQueueHandle, event, 0); return ERR_CODE_SUCCESS; } +/** + * @brief OS interrupt handler for LM75B temperature sensor + * + */ void osHandlerLM75BD(void) { /* Implement this function */ + float temperature; + readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temperature); + if(temperature > 75.0){ // only below T hys is safe + overTemperatureDetected(); + } + else safeOperatingConditions(); } +/** + * @brief Thermal management task for temperature events + * + * @param pvParameters - Pointer to parameters passed to task + */ static void thermalMgr(void *pvParameters) { /* Implement this task */ while (1) { - + thermal_mgr_event_t data = *(thermal_mgr_event_t *) pvParameters; + if(xQueueReceive(thermalMgrQueueHandle, pvParameters, 0) == pdTRUE && data.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD){ + float temperature; + readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temperature); + addTemperatureTelemetry(temperature); + } } } diff --git a/sys/logging/logging.h b/sys/logging/logging.h index a7d5298d..4710a527 100644 --- a/sys/logging/logging.h +++ b/sys/logging/logging.h @@ -70,6 +70,7 @@ void logSetLevel(log_level_t newLogLevel); * @return error_code_t * */ + error_code_t logLog(log_level_t msgLevel, const char *file, uint32_t line, const char *s, ...); #ifdef __cplusplus