Skip to content

Commit 14c0ae0

Browse files
committed
Finished the thermal manager implementation for Comms, and RTC
1 parent 4af5a8d commit 14c0ae0

File tree

7 files changed

+107
-40
lines changed

7 files changed

+107
-40
lines changed

obc/app/modules/comms_link_mgr/comms_manager.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ static uint8_t cc1120TransmitQueueStack[CC1120_TRANSMIT_QUEUE_LENGTH * CC1120_TR
6161
static const uint8_t TEMP_STATIC_KEY[AES_KEY_SIZE] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
6262
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
6363

64+
#define CC1120_TEMP_QUEUE_LENGTH 1
65+
#define CC1120_TEMP_QUEUE_ITEM_SIZE sizeof(uint32_t)
66+
67+
QueueHandle_t cc1120TempQueueHandle = NULL;
68+
static StaticQueue_t cc1120TempQueue;
69+
static uint32_t cc1120TempQueueStack[COMMS_MANAGER_QUEUE_LENGTH];
70+
6471
/**
6572
* @brief determines what the next Comms Manager state should be and sets it to
6673
* that state
@@ -126,6 +133,12 @@ void obcTaskInitCommsMgr(void) {
126133
cc1120TransmitQueueStack, &cc1120TransmitQueue);
127134
}
128135

136+
ASSERT((cc1120TempQueueStack != NULL) && (&cc1120TempQueue != NULL));
137+
if (cc1120TempQueueHandle == NULL) {
138+
cc1120TempQueueHandle = xQueueCreateStatic(CC1120_TEMP_QUEUE_LENGTH, CC1120_TEMP_QUEUE_ITEM_SIZE,
139+
cc1120TempQueueStack, &cc1120TempQueue);
140+
}
141+
129142
// TODO: Implement a key exchange algorithm instead of using Pre-Shared/static
130143
// key
131144
initializeAesCtx(TEMP_STATIC_KEY);
@@ -299,6 +312,13 @@ obc_error_code_t sendToFrontCommsManagerQueue(comms_event_t *event) {
299312
return OBC_ERR_CODE_QUEUE_FULL;
300313
}
301314

315+
obc_error_code_t postCommsManagerTempQueue(uint32_t value) {
316+
if (xQueueOverwrite(cc1120TempQueueHandle, &value) != pdPASS) {
317+
return OBC_ERR_CODE_UNKNOWN;
318+
}
319+
return OBC_ERR_CODE_INVALID_STATE;
320+
}
321+
302322
// NOTE: This is created on startup
303323
void obcTaskFunctionCommsMgr(void *pvParameters) {
304324
obc_error_code_t errCode;

obc/app/modules/comms_link_mgr/comms_manager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#define U_FRAME_COMMS_RECV_SIZE 30
1414
#define I_FRAME_COMMS_RECV_SIZE 300
1515

16+
extern QueueHandle_t cc1120TempQueueHandle;
17+
1618
/**
1719
* @enum comms_event_id_t
1820
* @brief comms event ID enum.

obc/app/modules/health_collector/health_collector.c

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include "thermal_mgr.h"
2+
#include "lm75bd.h"
3+
#include "obc_time.h"
4+
#include "telemetry_manager.h"
5+
#include "obc_errors.h"
6+
#include "obc_logging.h"
7+
#include "obc_scheduler_config.h"
8+
#include "comms_manager.h"
9+
10+
#include <FreeRTOS.h>
11+
#include <os_task.h>
12+
#include <sys_common.h>
13+
14+
#define HEALTH_COLLECTION_PERIOD_MS 60000UL
15+
16+
static obc_error_code_t collectThermalData(void);
17+
static obc_error_code_t readCC1120Temp(float* temp);
18+
19+
void obcTaskInitThermalMgr(void) {}
20+
21+
void obcTaskFunctionThermalMgr(void* pvParameters) {
22+
obc_error_code_t errCode;
23+
24+
while (1) {
25+
LOG_IF_ERROR_CODE(collectThermalData());
26+
vTaskDelay(pdMS_TO_TICKS(HEALTH_COLLECTION_PERIOD_MS));
27+
}
28+
}
29+
30+
static obc_error_code_t collectThermalData(void) {
31+
obc_error_code_t errCode;
32+
33+
float lm75bdTemp = 0.0f;
34+
RETURN_IF_ERROR_CODE(readTempLM75BD(LM75BD_OBC_I2C_ADDR, &lm75bdTemp));
35+
36+
float cc1120Temp = 0.0f;
37+
RETURN_IF_ERROR_CODE(readCC1120Temp(&cc1120Temp));
38+
39+
float rtcTemp = 0.0f;
40+
RETURN_IF_ERROR_CODE(readRTCTemp(&rtcTemp));
41+
42+
telemetry_data_t obcTempVal = {.obcTemp = lm75bdTemp, .id = TELEM_OBC_TEMP, .timestamp = getCurrentUnixTime()};
43+
44+
RETURN_IF_ERROR_CODE(addTelemetryData(&obcTempVal));
45+
46+
return OBC_ERR_CODE_SUCCESS;
47+
}
48+
49+
static obc_error_code_t readCC1120Temp(float* data) {
50+
if (xQueuePeek(cc1120TempQueueHandle, data, 0) != pdPASS) {
51+
return OBC_ERR_CODE_QUEUE_EMPTY;
52+
}
53+
return OBC_ERR_CODE_SUCCESS;
54+
}
55+
56+
static obc_error_code_t readRTCTemp(float* data) {
57+
if (xQueuePeek(cc1120TempQueueHandle, data, 0) != pdPASS) {
58+
return OBC_ERR_CODE_QUEUE_EMPTY;
59+
}
60+
return OBC_ERR_CODE_SUCCESS;
61+
}
File renamed without changes.

obc/app/modules/timekeeper/timekeeper.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,31 @@
1111
#include <os_task.h>
1212
#include <os_timer.h>
1313
#include <sys_common.h>
14+
#include <os_queue.h>
1415

1516
#define LOCAL_TIME_SYNC_PERIOD_S 60UL
1617

17-
void obcTaskInitTimekeeper(void) {}
18+
#define RTC_TEMP_QUEUE_LENGTH 1
19+
#define RTC_TEMP_QUEUE_ITEM_SIZE sizeof(uint32_t)
20+
21+
QueueHandle_t rtcTempQueueHandle = NULL;
22+
static StaticQueue_t rtcTempQueue;
23+
static uint32_t rtcTempQueueStack[RTC_TEMP_QUEUE_LENGTH];
24+
25+
void obcTaskInitTimekeeper(void) {
26+
ASSERT((rtcTempQueueStack != NULL) && (&rtcTempQueue != NULL));
27+
if (rtcTempQueueHandle == NULL) {
28+
rtcTempQueueHandle =
29+
xQueueCreateStatic(RTC_TEMP_QUEUE_LENGTH, RTC_TEMP_QUEUE_ITEM_SIZE, rtcTempQueueStack, &rtcTempQueue);
30+
}
31+
}
32+
33+
obc_error_code_t postRtcTempQueue(uint32_t value) {
34+
if (xQueueOverwrite(rtcTempQueueHandle, &value) != pdPASS) {
35+
return OBC_ERR_CODE_UNKNOWN;
36+
}
37+
return OBC_ERR_CODE_INVALID_STATE;
38+
}
1839

1940
void obcTaskFunctionTimekeeper(void *pvParameters) {
2041
/*
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
#pragma once
2+
3+
extern QueueHandle_t rtcTempQueueHandle;

0 commit comments

Comments
 (0)