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

Implement Thermal Mgr Task #285

Open
wants to merge 7 commits into
base: main
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
2 changes: 2 additions & 0 deletions obc/app/drivers/cc1120/cc1120.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,5 @@ obc_error_code_t cc1120GetState(cc1120_state_t *stateNum);
* @return obc_error_code_t - Whether or not the setup was a success
*/
obc_error_code_t cc1120Init(void);

obc_error_code_t readTempCC1120(float *temp);
Copy link

Choose a reason for hiding this comment

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

68 changes: 9 additions & 59 deletions obc/app/modules/thermal_mgr/thermal_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
void obcTaskInitThermalMgr() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

This task should init the lm75bd

static obc_error_code_t collectObcLm75bdTemp(void);
static obc_error_code_t collectObcDs3232Temp(void);

static obc_error_code_t collectObcCC1120Temp(void);
static obc_error_code_t setObcCC1120TempReading(void);
static obc_error_code_t resetObcCC120TempConfig(void);
Copy link

Choose a reason for hiding this comment

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

This will be handled in a different PR (driver functions are being written in it - not in the scope of this PR)


void obcTaskFunctionThermalMgr(void* pvParameters) {
obc_error_code_t errCode;
Expand All @@ -39,7 +36,9 @@ void obcTaskFunctionThermalMgr(void* pvParameters) {
while (1) {
LOG_IF_ERROR_CODE(collectObcLm75bdTemp());
LOG_IF_ERROR_CODE(collectObcCC1120Temp());
LOG_IF_ERROR_CODE(collectObcDs3232Temp());
LOG_IF_ERROR_CODE(collectObcDs3232Temp()); // RTC
// BMS in pr https://github.com/UWOrbital/OBC-firmware/pull/187

Copy link

Choose a reason for hiding this comment

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

BMS driver code does not exist; still in PR #187

digitalWatchdogTaskCheckIn(OBC_SCHEDULER_CONFIG_ID_THERMAL_MGR);

vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(THERMAL_MGR_PERIOD_MS));
Expand All @@ -60,64 +59,15 @@ static obc_error_code_t collectObcLm75bdTemp(void) {
}

static obc_error_code_t collectObcCC1120Temp(void) {
obc_error_code_t errCode;
// function commented out due to cc1120 driver function being implemented in a different PR
// obc_error_code_t errCode;

float temp = 0.0f;
RETURN_IF_ERROR_CODE(setObcCC1120TempReading());

uint8_t tempData = 0;
// read output voltage on GPIO1
RETURN_IF_ERROR_CODE(
cc1120ReadSpi(CC1120_REGS_IOCFG1, &tempData,
sizeof(tempData))); // this voltage represents the PTAT voltage but has an error of +/- 10C
// float temp = 0.0f;
// RETURN_IF_ERROR_CODE(readTempCC1120(&temp));

// Use Single Point Calibration to get a more accurate temperature reading (within +/- 1C for limited temperature
// range or +/- 2C across -40C to 85C) Can also use Two Point Calibtration for better accuracy
// See sections 1.4 and 1.5 of https://www.ti.com/lit/an/swra415d/swra415d.pdf?ts=1730233031162 (CC112x datasheet)
// for more information
// telemetry_data_t obcTempVal = {.obcTemp = temp, .id = TELEM_OBC_TEMP, .timestamp = getCurrentUnixTime()};

telemetry_data_t obcTempVal = {.obcTemp = temp, .id = TELEM_OBC_TEMP, .timestamp = getCurrentUnixTime()};

RETURN_IF_ERROR_CODE(addTelemetryData(&obcTempVal));

RETURN_IF_ERROR_CODE(resetObcCC120TempConfig());

return OBC_ERR_CODE_SUCCESS;
}

static obc_error_code_t setObcCC1120TempReading(void) {
obc_error_code_t errCode;

// To read the temperature sensor on the CC1120, first set the GPIO1 pin to analog output via setting 0x80 on IOCFG1
// (It has no digital reading for temperature)
uint8_t data = 0x80;
RETURN_IF_ERROR_CODE(cc1120WriteSpi(CC1120_REGS_IOCFG1, &data, sizeof(data)));

// Conifiguration of registers to read output: GBIAS1 to 0x07, ATEST_MODE to 0x0C, ATEST to 0x2A
data = 0x07;
RETURN_IF_ERROR_CODE(cc1120WriteExtAddrSpi(CC1120_REGS_EXT_GBIAS1, &data, sizeof(data)));
data = 0x0C;
RETURN_IF_ERROR_CODE(cc1120WriteExtAddrSpi(CC1120_REGS_EXT_ATEST_MODE, &data, sizeof(data)));
data = 0x2A;
RETURN_IF_ERROR_CODE(cc1120WriteExtAddrSpi(CC1120_REGS_EXT_ATEST, &data, sizeof(data)));

return OBC_ERR_CODE_SUCCESS;
}

static obc_error_code_t resetObcCC120TempConfig(void) {
obc_error_code_t errCode;
// reset registers

uint8_t data = 0;
data = 0x30;
RETURN_IF_ERROR_CODE(cc1120WriteSpi(CC1120_REGS_IOCFG1, &data, sizeof(data)));

data = CC1120_EXT_DEFAULTS_GBIAS1;
RETURN_IF_ERROR_CODE(cc1120WriteExtAddrSpi(CC1120_REGS_EXT_GBIAS1, &data, sizeof(data)));
data = CC1120_EXT_DEFAULTS_ATEST_MODE;
RETURN_IF_ERROR_CODE(cc1120WriteExtAddrSpi(CC1120_REGS_EXT_ATEST_MODE, &data, sizeof(data)));
data = CC1120_EXT_DEFAULTS_ATEST;
RETURN_IF_ERROR_CODE(cc1120WriteExtAddrSpi(CC1120_REGS_EXT_ATEST, &data, sizeof(data)));
// RETURN_IF_ERROR_CODE(addTelemetryData(&obcTempVal));

return OBC_ERR_CODE_SUCCESS;
}
Expand Down
Loading