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

Successfully completed the Onboarding Challenge #160

Open
wants to merge 3 commits into
base: level3
Choose a base branch
from
Open
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
Binary file added .DS_Store
Binary file not shown.
20 changes: 20 additions & 0 deletions lm75bd/lm75bd.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,27 @@ error_code_t lm75bdInit(lm75bd_config_t *config) {

error_code_t readTempLM75BD(uint8_t devAddr, float *temp) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check that the temp is not null before use

/* Implement this driver function */
error_code_t errCode;

uint8_t pointerRegister = 0x00;
uint8_t tempData[2];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally a good idea to initialize all variables. uint8_t tempData[2] = {0};

int16_t rawTemperature;

i2cSendTo(devAddr, &pointerRegister, sizeof(pointerRegister));
i2cReceiveFrom(devAddr, tempData, sizeof(tempData));
Comment on lines +36 to +37

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be wrapped inside of the RETURN_IF_ERROR_CODE macro


rawTemperature = (tempData[0] << 8) | tempData[1];
//discards the 5 least significant bits
rawTemperature >>= 5;
if (rawTemperature & 0x0400) {
// If the 11th bit is set, take the two's complement of the 11-bit number
rawTemperature |= 0xF800;
*temp = rawTemperature * 0.125;
} else {
// If the 11th bit is not set, temperature is positive
*temp = rawTemperature * 0.125;
}
Comment on lines +42 to +49

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is redundant, just do multiplication and store it


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 //1001111

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

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

xQueueSend(thermalMgrQueueHandle, event, portMAX_DELAY);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of things need to be changed here

  • always check non-void functions for a return code
  • check that the event and thermalMgrQueueHandle aren't null, returning the appropriate error codes
  • the delay should be 0 and not portMAX_DELAY as that will block when called in isr if the queue is full which is not what we want

return ERR_CODE_SUCCESS;
}

void osHandlerLM75BD(void) {
/* Implement this function */
thermal_mgr_event_type_t event = THERMAL_MGR_EVENT_INTERUPT;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is of type thermal_mgr_event_type_t, but the receiving queue is expecting type thermal_mgr_event_t

xQueueSend(thermalMgrQueueHandle, &event, 0);
}

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

thermal_mgr_event_t pvbuffer;
if(xQueueReceive(thermalMgrQueueHandle, &pvbuffer, portMAX_DELAY)) {
if (pvbuffer.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an else clause that logs a custom error code for invalid events received

float temp;
lm75bd_config_t config = *(lm75bd_config_t *) pvParameters;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull this to be before the loop

readTempLM75BD(config.devAddr, &temp);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOG_IF_ERROR_CODE followed by a if(errCode != success) continue; line

addTemperatureTelemetry(temp);
}
if (pvbuffer.type == THERMAL_MGR_EVENT_INTERUPT) {
float temp;
lm75bd_config_t config = *(lm75bd_config_t *) pvParameters;
readTempLM75BD(config.devAddr, &temp);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here

if(temp > config.overTempThresholdCelsius) {
overTemperatureDetected();
} else if (temp < config.hysteresisThresholdCelsius) {
safeOperatingConditions();
}
}
}
}
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this name more descriptive by including OS or OVER_TEMP inside of it


} thermal_mgr_event_type_t;

Expand Down
Loading