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

Completed Bootcamp #93

Closed
wants to merge 4 commits into from
Closed

Completed Bootcamp #93

wants to merge 4 commits into from

Conversation

orekk
Copy link

@orekk orekk commented Sep 17, 2023

Purpose

  • Implemented Temperature Sensor Driver Functions.
  • Created Thermal Management Task.
  • Added OS Handler for temperature sensor interrupts.

Changes

  • Defined LM75BD sensor's I2C device address.
  • Implemented readTempLM75BD function.
  • Created Thermal Management Task to collect temperature data.
  • Added OS Handler for LM75BD temperature sensor interrupts.

Testing

  • Unit tests passed for implemented functions.

Outstanding Changes

None.

Copy link
Contributor

@Navtajh04 Navtajh04 left a comment

Choose a reason for hiding this comment

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

Looks good, just a few things, but I would try to fix the indentation to make it easier to read and review

lm75bd/lm75bd.c Outdated Show resolved Hide resolved
lm75bd/lm75bd.c Outdated
Comment on lines 76 to 77
const uint16_t sign_bit_mask = 0x0400;
const uint16_t temperature_bits_mask = 0x03FF;
Copy link
Contributor

Choose a reason for hiding this comment

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

use macros for these instead of const variables

lm75bd/lm75bd.c Outdated


// uint16_t numBytes = 2;
errCode = i2cSendTo(devAddr,&pointer_register_value, 1U); // read the temperature from the sensor
Copy link
Contributor

Choose a reason for hiding this comment

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

not need to explicitly typecast the constant

Comment on lines 58 to 66
error_code_t errCode = readTempLM75BD(LM75BD_OBC_I2C_ADDR, temperature); // Use your readTempLM75BD function

if (temperature > HYS_THRESHOLD) {
// Temperature is above or equal to the overtemperature threshold
overTemperatureDetected();
} else if (temperature <= HYS_THRESHOLD) {
// Temperature is below or equal to the hysteresis threshold
safeOperatingConditions();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

we should not be calling readTemp in an ISR for 2 reasons

  1. readTemp will call the i2c helper functions which will block on the I2C bus mutex and we should never be trying to block in an ISR
  2. I2C is relatively slow and we want ISRs to always be as short and quick as possible to keep our system responsive

Comment on lines 56 to 58
float* temperature;
// Question: a, I using the correct devAddr
error_code_t errCode = readTempLM75BD(LM75BD_OBC_I2C_ADDR, temperature); // Use your readTempLM75BD function
Copy link
Contributor

Choose a reason for hiding this comment

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

since you are declaring temperature to be a pointer to a float but not setting it to anything, when you pass it into this function it is a NULL pointer so readTemp will return an error

@@ -43,18 +46,46 @@ void initThermalSystemManager(lm75bd_config_t *config) {

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 if event is null

@@ -43,18 +46,46 @@ void initThermalSystemManager(lm75bd_config_t *config) {

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 queue has been created

Comment on lines 49 to 50
BaseType_t send = xQueueSend(thermalMgrQueueHandle, event, 0); // 0 ticks to wait
if (send != pdPASS) return ERR_CODE_INVALID_QUEUE_MSG/*failed case*/;
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 just do if(xQueueSend(thermalMgrQueueHandle, event, 0) != pdPASS) instead of declaring a new variable

Comment on lines 84 to 86
if (errCode != ERR_CODE_SUCCESS) /*do something*/;
// Send it as telemetry
addTemperatureTelemetry(*temperature);
Copy link
Contributor

Choose a reason for hiding this comment

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

you shuld only be adding the telemetry temperature if the read was successful

// Kemi: Obtain type how
if (receivedEvent.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD) {
// collect temperature data using drive fcn
float* temperature;
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment as in the os handler

Copy link
Contributor

@Navtajh04 Navtajh04 left a comment

Choose a reason for hiding this comment

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

Just a couple more small changes

lm75bd/lm75bd.c Outdated

// to implement this we need to select the sensor's internaltemeprature register (7.4.1)
uint8_t pointer_register_value = 0x00; // Point to the Temperature Register
devAddr = LM75BD_OBC_I2C_ADDR;
Copy link
Contributor

Choose a reason for hiding this comment

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

device address is passed into the function, so you don't need to set it again. You can just use the address that was passed in, this is because if we have multiple lm75bd temperature sensors each would have a different address, so we would want the address to be a parameter to choose which sensor we want to read from


if(event == NULL) return ERR_CODE_INVALID_ARG;
if(thermalMgrQueueHandle == NULL) return ERR_CODE_INVALID_QUEUE_MSG;
if (xQueueSend(thermalMgrQueueHandle, event, 0) != pdPASS) return ERR_CODE_INVALID_QUEUE_MSG/*failed case*/;
Copy link
Contributor

Choose a reason for hiding this comment

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

this function would only fail if the queue is full, not due to an invalid queue msg

// Team Lead -> u dont necessarily need to read the temperature in the OShandler, u just need a way to communicate that an
// interrupt has happened so that u can read the temperature and deal with it from outside to OS handler
float temperature;
error_code_t errCode = readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temperature); // Use your readTempLM75BD function
Copy link
Contributor

Choose a reason for hiding this comment

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

check whether the readTempLM75BD was successful or not

Copy link
Contributor

@Navtajh04 Navtajh04 left a comment

Choose a reason for hiding this comment

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

LGTM

@Navtajh04 Navtajh04 closed this Sep 25, 2023
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