rtc_wakeup_example.c

Go to the documentation of this file.
00001 /*This file is prepared for Doxygen automatic documentation generation.*/
00015 /* Copyright (c) 2007, Atmel Corporation All rights reserved.
00016  *
00017  * Redistribution and use in source and binary forms, with or without
00018  * modification, are permitted provided that the following conditions are met:
00019  *
00020  * 1. Redistributions of source code must retain the above copyright notice,
00021  * this list of conditions and the following disclaimer.
00022  *
00023  * 2. Redistributions in binary form must reproduce the above copyright notice,
00024  * this list of conditions and the following disclaimer in the documentation
00025  * and/or other materials provided with the distribution.
00026  *
00027  * 3. The name of ATMEL may not be used to endorse or promote products derived
00028  * from this software without specific prior written permission.
00029  *
00030  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
00031  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00032  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
00033  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00034  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00035  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00036  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00037  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00038  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00039  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00040  */
00041 
00079 #include <avr32/io.h>
00080 #include "board.h"
00081 #include "pm.h"
00082 #include "gpio.h"
00083 #include "rtc.h"
00084 
00089 #define SLEEP_TIME      3
00090 
00095 int main(void) {
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 }

Generated on Wed May 7 14:40:10 2008 for AVR32114 Using the AVR32 LCD Controller by  doxygen 1.5.3-20071008