-
Notifications
You must be signed in to change notification settings - Fork 99
/
hello_sleep_aon.c
70 lines (51 loc) · 1.64 KB
/
hello_sleep_aon.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/sleep.h"
#include "pico/aon_timer.h"
static bool awake;
static void sleep_callback(void) {
printf("AON Timer woke us up\n");
uart_default_tx_wait_blocking();
awake = true;
}
static void aon_sleep(void) {
// Get the time from the aon timer and set our alarm time
struct timespec ts;
aon_timer_get_time(&ts);
ts.tv_sec += 10;
printf("Sleeping for 10 seconds\n");
uart_default_tx_wait_blocking();
// Go to sleep
sleep_goto_sleep_until(&ts, &sleep_callback);
}
int main() {
stdio_init_all();
printf("Hello AON timer Sleep!\n");
struct timespec ts = { .tv_sec = 1723124088, .tv_nsec = 0 };
aon_timer_start(&ts);
do {
printf("Awake for 10 seconds\n");
sleep_ms(1000 * 10);
printf("Switching to XOSC\n");
// Wait for the fifo to be drained so we get reliable output
uart_default_tx_wait_blocking();
// Set the crystal oscillator as the dormant clock source, UART will be reconfigured from here
// This is only really necessary before sending the pico into dormancy but running from xosc while asleep saves power
sleep_run_from_xosc();
// Go to sleep until an interrupt is generated after 10 seconds
awake = false;
aon_sleep();
// Make sure we don't wake
while (!awake) {
printf("Should be sleeping\n");
}
// Re-enabling clock sources and generators.
sleep_power_up();
} while(true);
return 0;
}