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

Tyler Chen Onboarding #163

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

Tyler Chen Onboarding #163

wants to merge 4 commits into from

Conversation

SubwayMan
Copy link

No description provided.

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, mainly you're code just needs better error handling

Comment on lines +34 to +35
errCode = i2cSendTo(devAddr, buff, CONF_WRITE_POINTER_BUFF_SIZE);
if (errCode != ERR_CODE_SUCCESS) return errCode;

Choose a reason for hiding this comment

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

Better to use RETURN_IF_ERROR_CODE macro instead

Comment on lines +38 to +39
errCode = i2cReceiveFrom(devAddr, temp_bytes, 2);
if (errCode != ERR_CODE_SUCCESS) return errCode;

Choose a reason for hiding this comment

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

Better to use the RETURN_IF_ERROR_CODE macro instead

if (errCode != ERR_CODE_SUCCESS) return errCode;

uint8_t temp_bytes[2U] = {0}; // first interpret data as unsigned
errCode = i2cReceiveFrom(devAddr, temp_bytes, 2);

Choose a reason for hiding this comment

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

Use sizeof(temp_bytes) instead of 2. Also you should use the naming convention of camelCase

}

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.

Add error handling for this:

  • check that the event is not null, return invalid argument otherwise
  • check that the thermalMgrQueueHandle is not null, otherwise return invalid state
  • check the return value of the xQueueSend

Also this should be 0 and not PORTMAX_DELAY as this will block the task which might not be the intended behavior especially in ISR

}

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

thermal_mgr_event_t event;
if (xQueueReceive(thermalMgrQueueHandle, &event, portMAX_DELAY)) {

Choose a reason for hiding this comment

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

Explicitly check against pdTRUE


thermal_mgr_event_t event;
if (xQueueReceive(thermalMgrQueueHandle, &event, portMAX_DELAY)) {
const lm75bd_config_t data = *(lm75bd_config_t *) pvParameters;

Choose a reason for hiding this comment

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

This should be outside of the loop so we don't constantly re create it the data and better to use a pointer instead of a regular struct

if (xQueueReceive(thermalMgrQueueHandle, &event, portMAX_DELAY)) {
const lm75bd_config_t data = *(lm75bd_config_t *) pvParameters;
float temperature;
readTempLM75BD(data.devAddr, &temperature);

Choose a reason for hiding this comment

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

In general, you should be checking the return of non-void functions for error codes. This should be wrapped inside of a LOG_IF_ERROR_CODE and if(errCode!= success) continue;
Also this should be moved to each event that needs it. You don't want to read the temp on all events

Comment on lines +41 to +43
int data = temp_bytes[0];
data -= 2 * ((1 << 7) & data); // handle signed bit
data = (data << 3) | (temp_bytes[1] >> 5); // get LSbyte

Choose a reason for hiding this comment

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

This code can be simplified to int16_t data = ( (tempBytes[0] << 8) | tempBytes[1]) >> 5;

errCode = i2cSendTo(devAddr, buff, CONF_WRITE_POINTER_BUFF_SIZE);
if (errCode != ERR_CODE_SUCCESS) return errCode;

uint8_t temp_bytes[2U] = {0}; // first interpret data as unsigned

Choose a reason for hiding this comment

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

If you are going to define a macro for the length above, probably best to define a macro here as well

@@ -25,9 +26,22 @@ error_code_t lm75bdInit(lm75bd_config_t *config) {
return ERR_CODE_SUCCESS;
}

#define CONF_WRITE_POINTER_BUFF_SIZE 1U
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

Comment on lines +34 to +35
errCode = i2cSendTo(devAddr, buff, CONF_WRITE_POINTER_BUFF_SIZE);
if (errCode != ERR_CODE_SUCCESS) return errCode;
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use RETURN_IF_ERROR_CODE to simplify this

if (errCode != ERR_CODE_SUCCESS) return errCode;

uint8_t temp_bytes[2U] = {0}; // first interpret data as unsigned
errCode = i2cReceiveFrom(devAddr, temp_bytes, 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

use sizeof(temp_bytes) rather than hardcoding 2

}

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

Copy link
Contributor

Choose a reason for hiding this comment

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

check to make sure event is not NULL and that the queue has been created already

}

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

xQueueSend(thermalMgrQueueHandle, event, portMAX_DELAY);
Copy link
Contributor

Choose a reason for hiding this comment

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

Always check the return value for non-void functions

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, since you are calling this function in an ISR, the block time should be 0 since you should never be blocking in an ISR

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