Skip to content

Commit

Permalink
Seth Onboarding
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth-Winton committed Nov 2, 2024
1 parent 7e1a8dc commit 91111d9
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 9 deletions.
20 changes: 19 additions & 1 deletion lm75bd/lm75bd.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

/* LM75BD Registers (p.8) */
#define LM75BD_REG_CONF 0x01U /* Configuration Register (R/W) */
#define LM75BD_REG_TEMP 0x00 /* Temperature register*/

error_code_t lm75bdInit(lm75bd_config_t *config) {
error_code_t errCode;
Expand All @@ -26,7 +27,24 @@ error_code_t lm75bdInit(lm75bd_config_t *config) {
}

error_code_t readTempLM75BD(uint8_t devAddr, float *temp) {
/* Implement this driver function */
error_code_t errCode;
uint8_t tempReg = LM75BD_REG_TEMP;
errCode = i2cSendTo(devAddr, &tempReg, 1); /* Select temperature register*/
if (errCode != ERR_CODE_SUCCESS) return errCode;

uint8_t buff[2] = {0};
errCode = i2cReceiveFrom(devAddr, buff, 2); /* Read temp data */
if (errCode != ERR_CODE_SUCCESS) return errCode;

uint16_t val = ((buff[0] << 3) + (buff[1] >> 5)); /* Combine MSB and LSB */
if (val >> 10) {
/* Negative */
*temp = ((~val + 1) & 0x7FF) * -0.125;
}
else {
/* Positive */
*temp = val * 0.125;
}

return ERR_CODE_SUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion lm75bd/lm75bd.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stdint.h>

/* 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
Expand Down
41 changes: 34 additions & 7 deletions services/thermal_mgr/thermal_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "errors.h"
#include "lm75bd.h"
#include "console.h"
#include "logging/logging.h"

#include <FreeRTOS.h>
#include <os_task.h>
Expand Down Expand Up @@ -42,20 +43,46 @@ void initThermalSystemManager(lm75bd_config_t *config) {
}

error_code_t thermalMgrSendEvent(thermal_mgr_event_t *event) {
/* Send an event to the thermal manager queue */

// Send an event to the thermal manager queue
if (xQueueSend(thermalMgrQueueHandle, event, 1000) != pdTRUE) {
return ERR_CODE_QUEUE_FULL;
}
return ERR_CODE_SUCCESS;
}

void osHandlerLM75BD(void) {
/* Implement this function */
// Send event to handle OS interrupt
thermal_mgr_event_t event;
event.type = THERMAL_MGR_EVENT_HANDLE_OS_CMD;
if (xQueueSendFromISR(thermalMgrQueueHandle, &event, NULL) != pdTRUE) {
LOG_ERROR_CODE(ERR_CODE_QUEUE_FULL);
}
}

static void thermalMgr(void *pvParameters) {
/* Implement this task */
while (1) {

}
while (1) {
if (xQueueReceive(thermalMgrQueueHandle, pvParameters, 0) == pdTRUE) {
thermal_mgr_event_t event = *(thermal_mgr_event_t *) pvParameters;

// Handle event received from queue
if (event.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD) {
float temp;
readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temp);
addTemperatureTelemetry(temp);
}
else if (event.type == THERMAL_MGR_EVENT_HANDLE_OS_CMD) {
float temp;
readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temp);
if (temp > LM75BD_DEFAULT_HYST_THRESH) {
overTemperatureDetected();
}
else {
safeOperatingConditions();
}

}
}
}
}

void addTemperatureTelemetry(float tempC) {
Expand Down
1 change: 1 addition & 0 deletions services/thermal_mgr/thermal_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

typedef enum {
THERMAL_MGR_EVENT_MEASURE_TEMP_CMD,
THERMAL_MGR_EVENT_HANDLE_OS_CMD

} thermal_mgr_event_type_t;

Expand Down

0 comments on commit 91111d9

Please sign in to comment.