Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finished onboarding challenge #102

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lm75bd/lm75bd.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ error_code_t lm75bdInit(lm75bd_config_t *config) {

error_code_t readTempLM75BD(uint8_t devAddr, float *temp) {
/* Implement this driver function */
if (!temp) return ERR_CODE_INVALID_ARG;

error_code_t errCode;

uint8_t pointerTempValue = 0;
uint8_t pointerRegisterSize = 1;
RETURN_IF_ERROR_CODE(i2cSendTo(LM75BD_OBC_I2C_ADDR, &pointerTempValue, pointerRegisterSize));

uint8_t tempRegisterSize = 2;
uint8_t tempBuff[2] = {0};
RETURN_IF_ERROR_CODE(i2cReceiveFrom(LM75BD_OBC_I2C_ADDR, tempBuff, tempRegisterSize));

uint8_t isNegative = tempBuff[0] >> 7;
uint16_t tempData = (tempBuff[0] << 3) + (tempBuff[1] >> 5);
*temp = isNegative ? -1 * ((tempData ^ 0x7FF) + 1) : tempData;
*temp *= 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 0x4FU

/* LM75BD Configuration Values */
#define LM75BD_DEV_OP_MODE_NORMAL 0x00U
Expand Down
39 changes: 38 additions & 1 deletion 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.h"

#include <FreeRTOS.h>
#include <os_task.h>
Expand Down Expand Up @@ -43,18 +44,54 @@ void initThermalSystemManager(lm75bd_config_t *config) {

error_code_t thermalMgrSendEvent(thermal_mgr_event_t *event) {
andrei-paraschiv marked this conversation as resolved.
Show resolved Hide resolved
/* Send an event to the thermal manager queue */
andrei-paraschiv marked this conversation as resolved.
Show resolved Hide resolved
if (!event) return ERR_CODE_INVALID_ARG;
if (!thermalMgrQueueHandle) return ERR_CODE_QUEUE_NOT_CREATED;

if (xQueueSend(thermalMgrQueueHandle, event, 0) != pdTRUE) 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 */
lm75bd_config_t config = *(lm75bd_config_t *)pvParameters;
thermal_mgr_event_t event;
float temp;

while (1) {

error_code_t error;

if (xQueueReceive(thermalMgrQueueHandle, &event, portMAX_DELAY) == pdTRUE) {
switch (event.type) {
case THERMAL_MGR_EVENT_MEASURE_TEMP_CMD:
error = readTempLM75BD(config.devAddr, &temp);
if (error != ERR_CODE_SUCCESS) {
LOG_ERROR_CODE(error);
break;
}
addTemperatureTelemetry(temp);
break;
case THERMAL_MGR_EVENT_INTERRUPT:
error = readTempLM75BD(config.devAddr, &temp);
if (error != ERR_CODE_SUCCESS) {
LOG_ERROR_CODE(error);
break;
}
if (temp > config.hysteresisThresholdCelsius) {
overTemperatureDetected();
} else {
safeOperatingConditions();
}
break;
}
}
}
}

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_INTERRUPT,

} thermal_mgr_event_type_t;

Expand Down
1 change: 1 addition & 0 deletions sys/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ typedef enum {
ERR_CODE_MUTEX_TIMEOUT = 100,
ERR_CODE_QUEUE_FULL = 101,
ERR_CODE_INVALID_QUEUE_MSG = 102,
ERR_CODE_QUEUE_NOT_CREATED = 103,

/* Driver errors */
ERR_CODE_I2C_TRANSFER_TIMEOUT = 200,
Expand Down