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

Fatma J Onboarding #196

Open
wants to merge 2 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
1 change: 1 addition & 0 deletions Testing/Temporary/CTestCostData.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
3 changes: 3 additions & 0 deletions Testing/Temporary/LastTest.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Start testing: Oct 31 19:30 EDT
----------------------------------------------------------
End testing: Oct 31 19:30 EDT
15 changes: 15 additions & 0 deletions lm75bd/lm75bd.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,22 @@ error_code_t lm75bdInit(lm75bd_config_t *config) {

error_code_t readTempLM75BD(uint8_t devAddr, float *temp) {
Yarik-Popov marked this conversation as resolved.
Show resolved Hide resolved
/* Implement this driver function */
error_code_t errCode;

if(temp == NULL) return ERR_CODE_INVALID_ARG;

uint8_t sendBuf[1] = {0x0U};
uint8_t buffer[2] = {0U, 0U};
RETURN_IF_ERROR_CODE(i2cSendTo (devAddr, sendBuf, sizeof(sendBuf)));
RETURN_IF_ERROR_CODE(i2cReceiveFrom (devAddr, buffer, sizeof(buffer)));
uint8_t a = 1U;
uint8_t mask = a << 7;
int16_t temperature = ((buffer[0] << 8) | buffer[1]) >> 5;
if (!(buffer[0] & mask)) {
*temp = temperature * 0.125;
} else {
*temp = -((~temperature & 0b0000011111111111) + 1) * 0.125;
}
Comment on lines +38 to +45

Choose a reason for hiding this comment

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

Out of these lines, you only need lines 40 and 42. You might need to cast the temperature before assign it to temp

return ERR_CODE_SUCCESS;
}

Expand Down
3 changes: 2 additions & 1 deletion lm75bd/lm75bd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

/* LM75BD Configuration Values */
#define LM75BD_DEV_OP_MODE_NORMAL 0x00U
Expand Down
36 changes: 33 additions & 3 deletions services/thermal_mgr/thermal_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "errors.h"
#include "lm75bd.h"
#include "console.h"
#include "logging.h"

#include <FreeRTOS.h>
#include <os_task.h>
Expand Down Expand Up @@ -43,18 +44,47 @@ void initThermalSystemManager(lm75bd_config_t *config) {

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

return ERR_CODE_SUCCESS;
if(thermalMgrQueueHandle != NULL && event != NULL) {

Choose a reason for hiding this comment

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

  • return invalid argument if event is null
  • return invalid state if thermal mgr queue handle is null as its not an argument but a state variable

xQueueSend(thermalMgrQueueHandle, event, 0);

Choose a reason for hiding this comment

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

In general, you should check the return of non-void functions for error codes and handle them

return ERR_CODE_SUCCESS;
} else {
return ERR_CODE_INVALID_ARG;
}
}

void osHandlerLM75BD(void) {
/* Implement this function */
thermal_mgr_event_t event;
event.type = THERMAL_MGR_EVENT_OS_INTERRUPT;
thermalMgrSendEvent(&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.

PvParameters is not of type thermal mgr event but of the lm75bd config so you shouldn't do this. Just thermal_mgr_event_t event={0};


error_code_t errCodeEvent = xQueueReceive(thermalMgrQueueHandle, pvParameters, portMAX_DELAY);

Choose a reason for hiding this comment

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

The return type of xQueueReceive isn't error_code_t. Only the functions we write on the team use that custom error code. Libraries have there own


if(errCodeEvent == pdTRUE) { // ensure about the tick time + how to checl the type ajsdkfk
float temp;
if (data.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD) {
error_code_t errCode = readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temp);
if(errCode != ERR_CODE_SUCCESS) {
LOG_ERROR_CODE(errCode);
continue;
}
addTemperatureTelemetry(temp);
} else if(data.type == THERMAL_MGR_EVENT_OS_INTERRUPT) {
if(temp > LM75BD_DEFAULT_OT_THRESH) {

Choose a reason for hiding this comment

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

You should be reading the temperature when you get an over temperature event as if temp wasn't read for a while the value might be stale and not represent the current temperature

overTemperatureDetected();
} else if(temp < LM75BD_DEFAULT_HYST_THRESH) {
safeOperatingConditions();
}
}
} else {
LOG_ERROR_CODE(errCodeEvent);
}
}
}

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_OS_INTERRUPT

} thermal_mgr_event_type_t;

Expand Down
1 change: 0 additions & 1 deletion test/test_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ TEST(TestLm75bdDriver, TestReadTempLm75bdPosTempSuccess) {
customTempBuff[1] = 0x00U;

i2cReceiveFrom_fake.custom_fake = getTemp_custom_fake;

ASSERT_EQ(readTempLM75BD(addr, &temp), ERR_CODE_SUCCESS);
EXPECT_EQ(temp, 127.0f);
}
Expand Down
Loading