STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
board_sleep.h
Go to the documentation of this file.
1
#ifndef STAR_BOARD_SLEEP_H
2
#define STAR_BOARD_SLEEP_H
3
4
/*
5
* Sleep in Stop mode on the RTC wakeup timer (Idle: ~10 s between LoRa
6
* heartbeats). RM0468 Rev 3:
7
* Stop = D1 and D2 in DStop, system Stop; any EXTI wakes it, including
8
* the RTC wakeup timer and DIO1 (PB2, EXTI2) (p.259). After wake the
9
* system clock is HSI (STOPWUCK, p.333); SystemClock_Config() restores
10
* it. RAM and GPIO levels are kept, so pyro outputs stay low (never
11
* written here).
12
* NRST_STOP_D1 = 0 makes D1 DStop a reset (p.208): then Stop is refused
13
* and board_sleep() waits awake instead.
14
* With a debugger attached, DBGMCU keeps SWD alive in Stop (p.3230); not
15
* set otherwise, so flight current is not spent on it.
16
* Time: the RTC calendar is read before and after, scaled by the LSI rate
17
* measured at init (sleep_math.h), and FreeRTOS catches up on the ticks it
18
* missed, so osKernelGetTickCount() and uptime include the sleep.
19
*/
20
21
#include <stdbool.h>
22
#include <stdint.h>
23
24
#ifdef __cplusplus
25
extern
"C"
{
26
#endif
27
28
typedef
struct
{
29
bool
ready
;
/* RTC running, LSI measured */
30
bool
stop_allowed
;
/* NRST_STOP_D1 = 1 in the option bytes */
31
uint32_t
lsi_hz
;
/* measured against TIM2 */
32
uint32_t
sleeps
,
rtc_wakes
,
early_wakes
;
33
uint32_t
awake_waits
;
/* refused: not ready, NRST_STOP_D1 = 0, USB */
34
uint32_t
last_slept_ms
;
35
}
board_sleep_info_t
;
36
37
/* Once, from a task, after board_time_start(): ~0.5 s to measure LSI. */
38
bool
board_sleep_init
(
void
);
39
40
/* Sleep up to `ms` in Stop. Returns the ms that really passed. Wakes early
41
* on any EXTI (radio DIO1). Other tasks are frozen until it returns.
42
* wake_now (may be NULL) is checked with the scheduler already suspended:
43
* true means work arrived just before (a queued command), so it returns 0
44
* without sleeping. Not ready / NRST_STOP_D1 = 0: returns 0 at once; the
45
* caller waits awake instead (board_sleep_info().stop_allowed). */
46
uint32_t
board_sleep
(uint32_t ms,
bool
(*wake_now)(
void
));
47
48
const
board_sleep_info_t
*
board_sleep_info
(
void
);
49
50
#ifdef __cplusplus
51
}
52
#endif
53
#endif
board_sleep
uint32_t board_sleep(uint32_t ms, bool(*wake_now)(void))
Definition
board_sleep.c:68
board_sleep_info
const board_sleep_info_t * board_sleep_info(void)
Definition
board_sleep.c:64
board_sleep_init
bool board_sleep_init(void)
Definition
board_sleep.c:52
board_sleep_info_t
Definition
board_sleep.h:28
board_sleep_info_t::ready
bool ready
Definition
board_sleep.h:29
board_sleep_info_t::sleeps
uint32_t sleeps
Definition
board_sleep.h:32
board_sleep_info_t::awake_waits
uint32_t awake_waits
Definition
board_sleep.h:33
board_sleep_info_t::last_slept_ms
uint32_t last_slept_ms
Definition
board_sleep.h:34
board_sleep_info_t::rtc_wakes
uint32_t rtc_wakes
Definition
board_sleep.h:32
board_sleep_info_t::stop_allowed
bool stop_allowed
Definition
board_sleep.h:30
board_sleep_info_t::early_wakes
uint32_t early_wakes
Definition
board_sleep.h:32
board_sleep_info_t::lsi_hz
uint32_t lsi_hz
Definition
board_sleep.h:31
firmware
Flight_Computer
src
board
board_sleep.h
Generated by
1.15.0