Definition in file rtc_wakeup_example.c.
#include <avr32/io.h>
#include "board.h"
#include "pm.h"
#include "gpio.h"
#include "rtc.h"
Go to the source code of this file.
Sleep time | |
Time in seconds the application shall sleep. The RTC wakes the application after this time.IntroductionThis example demonstrates how to the RTC can be used to wake-up a sleeping application. Operating mode: Press button 0 to enter Idle sleep mode. Press button 1 to enter Frozen sleep mode. Press button 2 to enter Standby sleep mode.The red led on the board will light up when the system is in a sleep mode. The RTC will wake-up the application after a specified time. This time may be adjusted by the user in the source file and is by default 3 seconds. Main Files
Compilation InformationThis software is written for GNU GCC for AVR32 and for IAR Embedded Workbench for Atmel AVR32. Other compilers may or may not work.Device InformationAll AVR32 devices with an RTC and GPIO controller.Configuration InformationThis example has been tested with the following configuration:
Contact InformationFor further information, visit Atmel AVR32.Support and FAQ: http://support.atmel.no/ | |
| #define | SLEEP_TIME 3 |
| int | main (void) |
| main function : init RTC, wait until a button is pressed to go to sleep. The RTC wakes up the application. | |
| #define SLEEP_TIME 3 |
| int main | ( | void | ) |
main function : init RTC, wait until a button is pressed to go to sleep. The RTC wakes up the application.
Definition at line 95 of file rtc_wakeup_example.c.
References gpio_clr_gpio_pin(), gpio_get_pin_value(), GPIO_PUSH_BUTTON_0, GPIO_PUSH_BUTTON_1, GPIO_PUSH_BUTTON_2, gpio_set_gpio_pin(), LED0_GPIO, LED4_GPIO, rtc_disable_wake_up(), rtc_enable(), rtc_enable_wake_up(), rtc_get_value(), rtc_init(), RTC_OSC_32KHZ, RTC_PSEL_32KHZ_1HZ, rtc_set_top_value(), SLEEP, and SLEEP_TIME.
00095 { 00096 int sleep_mode; 00097 00098 gpio_clr_gpio_pin(LED0_GPIO); 00099 00100 // Initialize the RTC 00101 if (!rtc_init(&AVR32_RTC, RTC_OSC_32KHZ, RTC_PSEL_32KHZ_1HZ)) 00102 { 00103 while(1); 00104 } 00105 // Enable the RTC 00106 rtc_enable(&AVR32_RTC); 00107 00108 while(1){ 00109 00110 // clear LED to indicate wake-up 00111 gpio_set_gpio_pin(LED4_GPIO); 00112 00113 // wait until button is pressed 00114 while(1) { 00115 if(gpio_get_pin_value(GPIO_PUSH_BUTTON_0) == 0) { 00116 sleep_mode = AVR32_PM_SMODE_IDLE; 00117 break; 00118 } 00119 if(gpio_get_pin_value(GPIO_PUSH_BUTTON_1) == 0){ 00120 sleep_mode = AVR32_PM_SMODE_FROZEN; 00121 break; 00122 } 00123 if(gpio_get_pin_value(GPIO_PUSH_BUTTON_2) == 0){ 00124 sleep_mode = AVR32_PM_SMODE_STANDBY; 00125 break; 00126 } 00127 } 00128 // set new wake-up time for the RTC 00129 rtc_set_top_value(&AVR32_RTC, SLEEP_TIME + rtc_get_value(&AVR32_RTC)); 00130 00131 // RTC wake-up must be disabled and activated again to enable 00132 // the wake-up feature 00133 rtc_disable_wake_up(&AVR32_RTC); 00134 rtc_enable_wake_up(&AVR32_RTC); 00135 00136 // set LED to indicate sleep 00137 gpio_clr_gpio_pin(LED4_GPIO); 00138 00139 // enter sleep mode 00140 switch(sleep_mode) { 00141 case AVR32_PM_SMODE_IDLE: 00142 SLEEP(AVR32_PM_SMODE_IDLE); 00143 break; 00144 case AVR32_PM_SMODE_FROZEN: 00145 SLEEP(AVR32_PM_SMODE_FROZEN); 00146 break; 00147 case AVR32_PM_SMODE_STANDBY: 00148 SLEEP(AVR32_PM_SMODE_STANDBY); 00149 break; 00150 default: 00151 break; 00152 } 00153 00154 00155 } 00156 00157 return 0; 00158 }
1.5.3-20071008