amiro-os / boards / PowerManagement / wakeup.c @ 2af9778e
History | View | Annotate | Download (1.082 KB)
1 |
#include <ch.h> |
---|---|
2 |
#include <hal.h> |
3 |
|
4 |
#include <board.h> |
5 |
#include "wakeup.h" |
6 |
|
7 |
enum wakeup_mode wakeup_mode;
|
8 |
enum wakeup_source wakeup_source;
|
9 |
|
10 |
void standby_wakeup_source(void) { |
11 |
|
12 |
uint32_t csr = PWR->CSR; |
13 |
uint32_t gpioc_val = palReadPort(GPIOC); |
14 |
|
15 |
// default to POR
|
16 |
wakeup_mode = WAKE_MODE_POR; |
17 |
wakeup_source = WAKE_SRC_UNKN; |
18 |
|
19 |
// make sure reset while powered on looks like POR
|
20 |
PWR->CR |= (PWR_CR_CSBF); |
21 |
|
22 |
if ((csr & (PWR_CSR_SBF | PWR_CSR_WUF)) == (PWR_CSR_SBF | PWR_CSR_WUF)) {
|
23 |
|
24 |
// wakeup or RTC event from standby mode
|
25 |
// default to WKUP
|
26 |
wakeup_mode = WAKE_MODE_STDBY; |
27 |
wakeup_source = WAKE_SRC_WKUP; |
28 |
|
29 |
if (gpioc_val & (1u << GPIOC_PATH_DC)) |
30 |
wakeup_source |= WAKE_SRC_PATHDC_CONNECT; |
31 |
|
32 |
if (!(gpioc_val & (1u << GPIOC_TOUCH_INT_N))) |
33 |
wakeup_source |= WAKE_SRC_TOUCH_INT; |
34 |
|
35 |
/*
|
36 |
* default to SYS_PD_N source when
|
37 |
* no other reason for wakeup was found.
|
38 |
*/
|
39 |
if (wakeup_source == WAKE_SRC_WKUP)
|
40 |
wakeup_source |= WAKE_SRC_SYS_PD_N; |
41 |
|
42 |
} |
43 |
|
44 |
} |
45 |
|
46 |
void stop_wakeup_source(void) { |
47 |
|
48 |
wakeup_mode = WAKE_MODE_STOP; |
49 |
wakeup_source = WAKE_SRC_UNKN; |
50 |
|
51 |
} |