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

Prepare for PR #195

Open
wants to merge 4 commits into
base: level3
Choose a base branch
from
Open

Prepare for PR #195

wants to merge 4 commits into from

Conversation

Navtajh04
Copy link
Contributor

Purpose

Explain the purpose of the PR here, including references to any existing Notion tasks.

New Changes

  • Explain new changes

Testing

  • Explain tests that you ran to verify code functionality.

Outstanding Changes

  • If there are non-critical changes (i.e. additional features) that can be made to this feature in the future, indicate them here.

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

/*
Copy link
Contributor Author

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

Copy link

@Yarik-Popov Yarik-Popov left a 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) {

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

Copy link

@Yarik-Popov Yarik-Popov left a 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];

Choose a reason for hiding this comment

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

Initialize the buffer

Comment on lines +43 to +46
i2cSendTo(devAddr, &sendBuffer, 1U);

// Get data on temperature sensor
i2cReceiveFrom(devAddr, buffer, 2U);

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;

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

Comment on lines +51 to +53
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;

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

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

Comment on lines +62 to +67
float temperature;
readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temperature);
if(temperature > 75.0){ // only below T hys is safe
overTemperatureDetected();
}
else safeOperatingConditions();

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;

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);

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);

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants