STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
bringup_task.c
Go to the documentation of this file.
1#include "bringup_task.h"
2
3#include <string.h>
4
5#include "app.h"
6#include "board.h"
7#include "board_bringup.h"
8#include "boot_report.h"
9#include "cmsis_os2.h"
10#include "main.h"
11#include "mode.h"
12#include "self_test.h"
13#include "self_test_devices.h"
14
16
17/* Large state stays off the task stack. */
20
21/*
22 * Required vs warn-only follows Inez's proposal in #137 section 7 (the team
23 * has not approved an arming policy; this only decides LED2).
24 */
25static const self_test_config_t config = {
26 .device_count = 8,
27 .devices =
28 {
34 {SELF_TEST_DEVICE_GNSS, false},
36 {SELF_TEST_DEVICE_NAND, false},
37 },
38 .probe_timeout_ms = 3000,
39 .retry_interval_ms = 200,
40 .heartbeat_interval_ms = 1000,
41 .battery_interval_ms = 1000,
42 .battery_max_age_ms = 3000,
43 /* GNSS listens up to 1.5 s and SD init up to 1 s in one call; the
44 * coordinator requires callback_budget <= tick_budget / 3. */
45 .callback_budget_ms = 2000,
46 .tick_budget_ms = 6000,
47 .probe_max_attempts = 3, /* #137: 3 attempts; GNSS alternates baud */
48 .publication_max_attempts = 1,
49 .session_timeout_ms = 0, /* default 29 s: always finishes, #137 */
50};
51
52static void led(GPIO_TypeDef* port, uint16_t pin, bool on) {
53 /* LEDs are active low: 3V3 -> resistor -> LED -> pin. */
55}
56
57static void bringup_task(void* argument) {
58 (void)argument;
61
62 const self_test_port_t port = {
63 .probe = board_bringup_probe,
64 .read_battery = board_bringup_read_battery,
65 .publish_status = NULL, /* radio TX not written yet */
66 };
67 bool running =
69 uint32_t blink = 0;
70 while (running) {
73 if (!status || status->probes_complete) {
74 break;
75 }
76 g_bringup_report.self_test = *status; /* live view in the debugger */
77 led(LED1_GPIO_Port, LED1_Pin, (++blink & 4U) != 0U); /* ~6 Hz */
78 osDelay(20);
79 }
80
82 if (status) {
83 g_bringup_report.self_test = *status;
84 }
86
87 /* Battery: the coordinator's last sample (taken during the checks,
88 * before anything transmits), or one fresh reading if it had none. */
89 self_test_battery_t sample =
90 status ? status->battery : (self_test_battery_t){0};
91 if (!sample.valid) {
93 }
97 board_now_ms());
98 g_bringup_report.finished_at_ms = board_now_ms();
99 g_bringup_report.finished = true;
100
101 /* Chips are out of reset and checked: start the application tasks. */
102 g_bringup_report.app_started = app_start();
103
104 /* LED1: 1 Hz alive. LED2: off READY, blinking WARN, solid FAIL. In
105 * Idle the board sleeps: LED1 is the Idle loop's (one flash per
106 * heartbeat) and LED2 only shows FAIL, so no LED burns through Stop. */
107 boot_verdict_t verdict = g_bringup_report.report.verdict;
108 for (bool on = true;; on = !on) {
109 if (app_state() == FLIGHT_IDLE) {
110 led(LED2_GPIO_Port, LED2_Pin, verdict == BOOT_FAIL);
111 osDelay(1000);
112 continue;
113 }
116 verdict == BOOT_FAIL || (verdict == BOOT_WARN && on));
117 osDelay(on ? 100 : 900);
118 }
119}
120
122 return &bringup;
123}
124
126 static const osThreadAttr_t attributes = {
127 .name = "bringup",
128 .stack_size = 6 * 1024,
129 .priority = osPriorityNormal,
130 };
131 osThreadNew(bringup_task, NULL, &attributes);
132}
#define LED1_GPIO_Port
Definition main.h:194
#define LED2_GPIO_Port
Definition main.h:196
#define LED2_Pin
Definition main.h:195
#define LED1_Pin
Definition main.h:193
@ FLIGHT_IDLE
bool app_start(void)
Definition app.c:30
battery_t battery_assess(bool valid, uint32_t counts, bool on_usb)
Definition battery.c:12
uint32_t board_now_ms(void)
Definition board.c:24
void board_adc_snapshot(board_adc_snapshot_t *snapshot, uint32_t timeout_ms)
Definition board_adc.c:54
bool board_bringup_on_usb(void)
self_test_battery_t board_bringup_read_battery(void *context, uint32_t now_ms, uint32_t budget_ms)
self_test_reply_t board_bringup_probe(void *context, uint16_t device_id, uint8_t attempt, uint32_t now_ms, uint32_t budget_ms)
void board_bringup_power_up(board_bringup_t *b)
void boot_report_build(boot_report_t *r, const self_test_status_t *s, battery_t battery, uint32_t now_ms)
Definition boot_report.c:81
boot_verdict_t
Definition boot_report.h:30
@ BOOT_WARN
Definition boot_report.h:30
@ BOOT_FAIL
Definition boot_report.h:30
board_bringup_t * bringup_task_board(void)
static board_bringup_t bringup
static void led(GPIO_TypeDef *port, uint16_t pin, bool on)
bringup_report_t g_bringup_report
static void bringup_task(void *argument)
static self_test_t self_test
void bringup_task_start(void)
static std::atomic< bool > running
osThreadId_t osThreadNew(osThreadFunc_t func, void *argument, const osThreadAttr_t *attr)
Create a thread and add it to Active Threads.
Definition cmsis_os2.c:577
@ osPriorityNormal
Priority: normal.
Definition cmsis_os2.h:123
osStatus_t osDelay(uint32_t ticks)
Wait for Timeout (Time Delay).
Definition cmsis_os2.c:1094
static const emmc_port_t port
Definition emmc_stm32.c:210
void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
@ GPIO_PIN_SET
@ GPIO_PIN_RESET
#define NULL
Definition usbd_def.h:44
static const idle_config_t config
Definition idle_task.c:17
flight_state_t app_state(void)
Definition mode.c:48
bool self_test_init(self_test_t *t, const self_test_config_t *config, const self_test_port_t *port, void *context, uint32_t now_ms)
Definition self_test.c:98
void self_test_tick(self_test_t *t, uint32_t now_ms)
Definition self_test.c:244
const self_test_status_t * self_test_status(const self_test_t *t)
Definition self_test.c:270
@ SELF_TEST_DEVICE_ETHERNET
@ SELF_TEST_DEVICE_IMU
@ SELF_TEST_DEVICE_GNSS
@ SELF_TEST_DEVICE_HIGH_G
@ SELF_TEST_DEVICE_NAND
@ SELF_TEST_DEVICE_RADIO
@ SELF_TEST_DEVICE_BAROMETER
@ SELF_TEST_DEVICE_EMMC
General Purpose I/O.
Attributes structure for thread.
Definition cmsis_os2.h:240
static self_test_battery_t battery(void *context, uint32_t now_ms, uint32_t budget_ms)