STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
board_exti.c
Go to the documentation of this file.
1#include "board_exti.h"
2
3#include "board_time.h"
4#include "main.h"
5
6typedef struct {
7 uint16_t pin;
9 uint32_t volatile flags;
10 uint32_t volatile last_us;
11} route_t;
12
13static route_t routes[] = {
14 {IMU_INT1_Pin, NULL, 0, 0},
15 {ACCEL_INT_1_Pin, NULL, 0, 0},
16 {RADIO_DIO1_Pin, NULL, 0, 0},
17 {ETH_INT_Pin, NULL, 0, 0},
18};
19
20static route_t* find(uint16_t pin) {
21 for (unsigned i = 0; i < sizeof(routes) / sizeof(routes[0]); ++i) {
22 if (routes[i].pin == pin) {
23 return &routes[i];
24 }
25 }
26 return NULL;
27}
28
29bool board_exti_route(uint16_t pin, osThreadId_t thread, uint32_t flags) {
30 route_t* r = find(pin);
31 if (!r || !thread || !flags) {
32 return false;
33 }
34 r->flags = flags;
35 r->thread = thread; /* last: the ISR reads thread, then flags */
36 return true;
37}
38
39uint32_t board_exti_last_us(uint16_t pin) {
40 route_t* r = find(pin);
41 return r ? r->last_us : 0U;
42}
43
44/* HAL weak override, called from each EXTIx_IRQHandler. */
45void HAL_GPIO_EXTI_Callback(uint16_t pin) {
46 route_t* r = find(pin);
47 if (!r) {
48 return;
49 }
50 r->last_us = board_time_us();
51 osThreadId_t thread = r->thread;
52 if (thread) {
53 (void)osThreadFlagsSet(thread, r->flags); /* ISR-safe */
54 }
55}
#define ACCEL_INT_1_Pin
Definition main.h:170
#define IMU_INT1_Pin
Definition main.h:163
#define RADIO_DIO1_Pin
Definition main.h:111
#define ETH_INT_Pin
Definition main.h:122
static route_t routes[]
Definition board_exti.c:13
bool board_exti_route(uint16_t pin, osThreadId_t thread, uint32_t flags)
Definition board_exti.c:29
static route_t * find(uint16_t pin)
Definition board_exti.c:20
uint32_t board_exti_last_us(uint16_t pin)
Definition board_exti.c:39
uint32_t board_time_us(void)
Definition board_time.c:34
void * osThreadId_t
Definition cmsis_os2.h:211
uint32_t osThreadFlagsSet(osThreadId_t thread_id, uint32_t flags)
Set the specified Thread Flags of a thread.
static osThreadId_t thread
Definition gnss_task.c:13
void HAL_GPIO_EXTI_Callback(uint16_t pin)
Definition board_exti.c:45
#define NULL
Definition usbd_def.h:44
osThreadId_t volatile thread
Definition board_exti.c:8
uint16_t pin
Definition board_exti.c:7
uint32_t volatile flags
Definition board_exti.c:9
uint32_t volatile last_us
Definition board_exti.c:10
static boot_report_t r