Skip to content

Commit

Permalink
success
Browse files Browse the repository at this point in the history
  • Loading branch information
umar-ali-mustafa committed Oct 30, 2023
1 parent e0ec9b3 commit 2b9349c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
23 changes: 23 additions & 0 deletions lm75bd/lm75bd.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,29 @@ error_code_t lm75bdInit(lm75bd_config_t *config) {

error_code_t readTempLM75BD(uint8_t devAddr, float *temp) {
/* Implement this driver function */
// Internal temperature register: 00000000 or 0x00U
if (temp == NULL) return ERR_CODE_INVALID_ARG;

error_code_t errCode;

uint8_t tempRegister[1U] = {0}; // makes all elements of the array 0
tempRegister[0] = 0x00U; // sets the internal temperature register
errCode = i2cSendTo(LM75BD_OBC_I2C_ADDR, tempRegister, 1U);

LOG_ERROR_CODE(errCode);

uint8_t tempReceive[2U] = {0};
errCode = i2cReceiveFrom(LM75BD_OBC_I2C_ADDR, tempReceive, 2U);

LOG_ERROR_CODE(errCode);

// Calculate temp in C
int16_t byte1 = ((int16_t) tempReceive[0]) << 8;
int16_t tempC = byte1 | ((int16_t) tempReceive[1]);
tempC = tempC >> 5;
*temp = tempC * 0.125;

// printConsole(*temp);

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 0x4FU

/* LM75BD Configuration Values */
#define LM75BD_DEV_OP_MODE_NORMAL 0x00U
Expand Down
37 changes: 35 additions & 2 deletions services/thermal_mgr/thermal_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,52 @@ void initThermalSystemManager(lm75bd_config_t *config) {

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

if (event == NULL) return ERR_CODE_INVALID_ARG;
if (xQueueSend(thermalMgrQueueHandle, event, 0) == errQUEUE_FULL) return ERR_CODE_QUEUE_FULL;

return ERR_CODE_SUCCESS;
}

void osHandlerLM75BD(void) {
/* Implement this function */
thermal_mgr_event_t event;
event.type = THERMAL_MGR_EVENT_INTERRUPT;
thermalMgrSendEvent(&event);
}

static void thermalMgr(void *pvParameters) {
/* Implement this task */
// if (pvParameters == NULL) return ERR_CODE_INVALID_ARG;

error_code_t errCode;
thermal_mgr_event_t event; // must be of type THERMAL_MGR_EVENT_MEASURE_TEMP_CMD
float tempC;

while (1) {

if (xQueueReceive(thermalMgrQueueHandle, &event, portMAX_DELAY) == pdTRUE) {
if (event.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD) {
errCode = readTempLM75BD(LM75BD_OBC_I2C_ADDR, &tempC);
if (errCode == ERR_CODE_SUCCESS) {
addTemperatureTelemetry(tempC);
}
// else {
// LOG_ERROR_CODE(errCode);
// }
}
else if (event.type == THERMAL_MGR_EVENT_INTERRUPT) {
errCode = readTempLM75BD(LM75BD_OBC_I2C_ADDR, &tempC);
if (errCode == ERR_CODE_SUCCESS) {
if (tempC > 75) {
overTemperatureDetected();
}
else {
safeOperatingConditions();
}
}
}
}
}

}

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

typedef enum {
THERMAL_MGR_EVENT_MEASURE_TEMP_CMD,

THERMAL_MGR_EVENT_INTERRUPT
} thermal_mgr_event_type_t;

typedef struct {
Expand Down

0 comments on commit 2b9349c

Please sign in to comment.