-
Notifications
You must be signed in to change notification settings - Fork 171
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
Prepare for PR #195
base: level3
Are you sure you want to change the base?
Prepare for PR #195
Conversation
lm75bd/lm75bd.c
Outdated
@@ -27,7 +27,33 @@ error_code_t lm75bdInit(lm75bd_config_t *config) { | |||
|
|||
error_code_t readTempLM75BD(uint8_t devAddr, float *temp) { | |||
/* Implement this driver function */ | |||
|
|||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check if temp is NULL and return invalid arg err code if it is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test
* @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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check that temp isnt null before use
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall good start. Some changes are needed to improve the code
|
||
// Stores temperature register value | ||
uint8_t sendBuffer = 0x0U; | ||
uint8_t buffer[2]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize the buffer
i2cSendTo(devAddr, &sendBuffer, 1U); | ||
|
||
// Get data on temperature sensor | ||
i2cReceiveFrom(devAddr, buffer, 2U); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Wrap both calls inside the RETURN_IF_ERROR_CODE macro
- Use sizeof(sendBuffer) instead of 1
- Use sizeof(buffer) instead of 2
// Stores temperature register value | ||
uint8_t sendBuffer = 0x0U; | ||
uint8_t buffer[2]; | ||
uint16_t temperature = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move this down to after the i2c calls as this variable will not be used if the calls fails with the RETURN_IF_ERROR_CODE macro. Also, make this an int16_t
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If temperature is a int16_t then you don't need to do these lines just *temp=(float)(temperature * 0.125);
will do
@@ -5,7 +5,8 @@ | |||
#include <stdint.h> | |||
|
|||
/* LM75BD I2C Device Address */ | |||
#define LM75BD_OBC_I2C_ADDR /* Define the address here */ | |||
#define LM75BD_OBC_I2C_ADDR 0x4FU /* Define the address here */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We just use the hex value without the U ending of the team
float temperature; | ||
readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temperature); | ||
if(temperature > 75.0){ // only below T hys is safe | ||
overTemperatureDetected(); | ||
} | ||
else safeOperatingConditions(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't be reading the temperature inside of the isr as the i2c calls are blocking. Just send an event and have the the thermal mgr task handle the event
static void thermalMgr(void *pvParameters) { | ||
/* Implement this task */ | ||
while (1) { | ||
|
||
thermal_mgr_event_t data = *(thermal_mgr_event_t *) pvParameters; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, pvParameters isnt of type thermal_mgr_event_t but of the config which isn't the same. So I would just change the line to initialize an empty event instead
if(xQueueReceive(thermalMgrQueueHandle, pvParameters, 0) == pdTRUE && data.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD){ | ||
float temperature; | ||
readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temperature); | ||
addTemperatureTelemetry(temperature); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't get to this line if the readTemp fails
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log the error code returned
void osHandlerLM75BD(void) { | ||
/* Implement this function */ | ||
float temperature; | ||
readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temperature); | ||
if(temperature > 75.0){ // only below T hys is safe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the macros defined in the lm75bd.h file instead of hardcoding 75
Purpose
Explain the purpose of the PR here, including references to any existing Notion tasks.
New Changes
Testing
Outstanding Changes