forked from raspberrypi/pico-examples
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Might get rid of all the RTC examples - why use RTC?
- Loading branch information
1 parent
6e0db9d
commit ff3ba53
Showing
3 changed files
with
81 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
add_executable(hello_sleep | ||
hello_sleep.c | ||
add_executable(hello_sleep_rtc | ||
hello_sleep_rtc.c | ||
) | ||
target_link_libraries(hello_sleep_rtc | ||
pico_stdlib | ||
hardware_sleep | ||
) | ||
pico_add_extra_outputs(hello_sleep_rtc) | ||
|
||
target_link_libraries(hello_sleep pico_stdlib hardware_sleep) | ||
|
||
# create map/bin/hex file etc. | ||
pico_add_extra_outputs(hello_sleep) | ||
add_executable(hello_sleep_alarm | ||
hello_sleep_alarm.c | ||
) | ||
target_link_libraries(hello_sleep_alarm | ||
pico_stdlib | ||
hardware_sleep | ||
) | ||
pico_add_extra_outputs(hello_sleep_alarm) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* 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 "hardware/clocks.h" | ||
#include "hardware/pll.h" | ||
|
||
static bool awake; | ||
|
||
static void alarm_sleep_callback(uint alarm_id) { | ||
printf("timer woke us up\n"); | ||
uart_default_tx_wait_blocking(); | ||
awake = true; | ||
|
||
hardware_alarm_set_callback(alarm_id, NULL); | ||
hardware_alarm_unclaim(alarm_id); | ||
} | ||
|
||
int main() { | ||
|
||
stdio_init_all(); | ||
|
||
printf("Hello Alarm Sleep!\n"); | ||
|
||
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 necessary before sending the pico to sleep | ||
sleep_run_from_xosc(); | ||
|
||
printf("Switched to XOSC\n"); | ||
|
||
awake = false; | ||
|
||
// Go to sleep until the alarm interrupt is generated after 10 seconds | ||
printf("Sleeping for 10 seconds\n"); | ||
uart_default_tx_wait_blocking(); | ||
|
||
int alarm_id = -1; | ||
sleep_goto_sleep_for(10000, &alarm_sleep_callback, &alarm_id); | ||
if (alarm_id >= 0) { | ||
// 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters