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

Rohan Mandhotra: UWOrbital Onboarding #125

Open
wants to merge 2 commits into
base: level3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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: Jan 23 15:15 EST
----------------------------------------------------------
End testing: Jan 23 15:15 EST
26 changes: 22 additions & 4 deletions lm75bd/lm75bd.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <math.h>

/* LM75BD Registers (p.8) */
#define LM75BD_REG_CONF 0x01U /* Configuration Register (R/W) */

#define LM75BD_REG_CONF 0x01U /* Configuration Register (R/W) */
#define LM75BD_REG_TEMP 0x00U /* Temperature Register (R) */
error_code_t lm75bdInit(lm75bd_config_t *config) {
error_code_t errCode;

Expand All @@ -24,11 +24,29 @@ error_code_t lm75bdInit(lm75bd_config_t *config) {

return ERR_CODE_SUCCESS;
}

error_code_t readTempLM75BD(uint8_t devAddr, float *temp) {
/* Implement this driver 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 if temp is NULL

error_code_t errCode;

/* Set pointer to the sensor's temperature register */
uint8_t tempPointer = LM75BD_REG_TEMP;

/* Selects sensor's temperature register */
RETURN_IF_ERROR_CODE(i2cSendTo(devAddr, &tempPointer, 1));

uint8_t tempData[2] = {0};

/* Receives temperature data from the sensor, stores it in tempData */
RETURN_IF_ERROR_CODE(i2cReceiveFrom(devAddr, tempData, 2));

/* Converts tempData to a signedValue int16_t */
int16_t tempVal = tempData[1] | (tempData[0] << 8);

/* Sets temp pointer to the decimal value of the sensor temperature, and eliminates 5 LSBytes to the right */
*temp = (float)(tempVal >> 5) * 0.125;
return ERR_CODE_SUCCESS;


}

#define CONF_WRITE_BUFF_SIZE 2U
Expand Down
2 changes: 1 addition & 1 deletion lm75bd/lm75bd.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stdint.h>

/* LM75BD I2C Device Address */
#define LM75BD_OBC_I2C_ADDR /* Define the address here */
#define LM75BD_OBC_I2C_ADDR 0x4F/* Define the address here */

/* LM75BD Configuration Values */
#define LM75BD_DEV_OP_MODE_NORMAL 0x00U
Expand Down
37 changes: 35 additions & 2 deletions services/thermal_mgr/thermal_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@

#include <string.h>

#include "logging.h"

#define THERMAL_MGR_STACK_SIZE 256U
#define I2C_TEMP_OT_THRESH 80.0f
#define I2C_TEMP_HYST_THRESH 75.0f

static TaskHandle_t thermalMgrTaskHandle;
static StaticTask_t thermalMgrTaskBuffer;
Expand Down Expand Up @@ -43,18 +47,47 @@ void initThermalSystemManager(lm75bd_config_t *config) {

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


if(event == NULL) return ERR_CODE_INVALID_ARG;
if(thermalMgrQueueHandle == NULL) return ERR_CODE_INVALID_STATE;
if(xQueueSend(thermalMgrQueueHandle, event, 0) == errQUEUE_FULL) return ERR_CODE_QUEUE_FULL;
return ERR_CODE_SUCCESS;
}

void osHandlerLM75BD(void) {
/* Implement this function */
thermal_mgr_event_t event = {.type = THERMAL_MGR_EVENT_INTERRUPT};
thermalMgrSendEvent(&event);
}

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

error_code_t errCode;
thermal_mgr_event_t tempEvent;
float tempVal;


if (xQueueReceive(thermalMgrQueueHandle, &tempEvent, portMAX_DELAY) == pdTRUE){
if (tempEvent.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD)
{
RohanMandhotra marked this conversation as resolved.
Show resolved Hide resolved
errCode = readTempLM75BD(LM75BD_OBC_I2C_ADDR, &tempVal);
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be logged if it does not return success

if(errCode == ERR_CODE_SUCCESS) {
addTemperatureTelemetry(tempVal);
}
}
else if (tempEvent.type == THERMAL_MGR_EVENT_INTERRUPT) {
errCode = readTempLM75BD(LM75BD_OBC_I2C_ADDR, &tempVal);
if (errCode == ERR_CODE_SUCCESS) {
if (tempVal >= I2C_TEMP_OT_THRESH) {
overTemperatureDetected();
}
if (tempVal <= I2C_TEMP_HYST_THRESH) {
safeOperatingConditions();
}
}
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion services/thermal_mgr/thermal_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

typedef enum {
THERMAL_MGR_EVENT_MEASURE_TEMP_CMD,

THERMAL_MGR_EVENT_INTERRUPT,
} thermal_mgr_event_type_t;

typedef struct {
Expand Down
Loading