STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
board.h
Go to the documentation of this file.
1#ifndef STAR_BOARD_H
2#define STAR_BOARD_H
3
4/*
5 * Board layer: the code that knows how the flight computer is wired.
6 * Everything that touches a pin, a reset line or a HAL handle lives under
7 * board_*; the portable modules (self_test*, idle*) only see callbacks.
8 */
9
10#include <stdbool.h>
11#include <stdint.h>
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17/*
18 * CubeMX's MX_*_Init() functions call Error_Handler() on any HAL failure, and
19 * Error_Handler() halts the chip. That is right for on-chip peripherals but
20 * wrong for ones that talk to an external chip during init (the eMMC): a
21 * missing or dead part would brick the whole board.
22 *
23 * board_soft_init() runs such an init with Error_Handler() made non-fatal and
24 * returns false if it was hit. Error_Handler() calls board_error_is_soft().
25 */
26bool board_soft_init(void (*init)(void));
27bool board_error_is_soft(void);
28
29/*
30 * Put a buffer where DMA can reach it: the .dma_buffers section in AXI SRAM
31 * (RAM_D1, see STM32H723xx_FLASH.ld). Default .bss is DTCM, which the SDMMC
32 * IDMA and DMA1/2 cannot access. 32-byte alignment = one D-cache line, so
33 * cache clean/invalidate never touches a neighbour. Not zeroed at boot.
34 * static uint8_t buf[512] BOARD_DMA_BUFFER;
35 */
36#define BOARD_DMA_BUFFER __attribute__((section(".dma_buffers"), aligned(32)))
37
38/* Milliseconds since boot (HAL tick, TIM6). Wraps after ~49 days. */
39uint32_t board_now_ms(void);
40
41/* True once now_ms has reached deadline_ms (modular comparison). */
42static inline bool board_deadline_passed(uint32_t deadline_ms) {
43 return (int32_t)(board_now_ms() - deadline_ms) >= 0;
44}
45
46/* Milliseconds left before deadline_ms, 0 if it has passed. */
47static inline uint32_t board_ms_left(uint32_t deadline_ms) {
48 int32_t left = (int32_t)(deadline_ms - board_now_ms());
49 return left > 0 ? (uint32_t)left : 0U;
50}
51
52#ifdef __cplusplus
53}
54#endif
55#endif
uint32_t board_now_ms(void)
Definition board.c:24
static bool board_deadline_passed(uint32_t deadline_ms)
Definition board.h:42
static uint32_t board_ms_left(uint32_t deadline_ms)
Definition board.h:47
bool board_error_is_soft(void)
Definition board.c:8
bool board_soft_init(void(*init)(void))
Definition board.c:16