clock_scaling_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 
00088 #include <avr32/io.h>
00089 #include "board.h"
00090 #include "pm.h"
00091 #include "gpio.h"
00092 
00093 #define CLOCK_DIV_ON 1
00094 #define CLOCK_DIV_OFF 0
00095 #define DIV_HALF 0
00096 #define DIV_FOURTH 1
00097 
00101 int main(void) {
00102         unsigned int pbasel = DIV_FOURTH;
00103         unsigned int pbbsel = DIV_FOURTH;
00104         
00105         // set synchronous clock source to external oscillator 0
00106         pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);
00107         
00108         // set lower frequency on peripheral busses
00109         // the pm_cksel function takes care of safe clock adjustments
00110         pm_cksel(&AVR32_PM, CLOCK_DIV_ON, pbasel, CLOCK_DIV_ON, pbbsel,
00111                         CLOCK_DIV_OFF, 0);
00112         
00113         // indicate full speed with LED
00114         gpio_clr_gpio_pin(LED0_GPIO);
00115         
00116         while(1){
00117                 
00118                 // Set CPU speed according to the pressed button
00119 
00120                         if(gpio_get_pin_value(GPIO_PUSH_BUTTON_0) == 0) {
00121                                 // No clock division for CPU
00122                                 pm_cksel(&AVR32_PM, CLOCK_DIV_ON, pbasel, CLOCK_DIV_ON, pbbsel,
00123                                                 CLOCK_DIV_OFF, 0);
00124                                 gpio_clr_gpio_pin(LED0_GPIO);
00125                                 gpio_set_gpio_pin(LED1_GPIO);
00126                                 gpio_set_gpio_pin(LED2_GPIO);
00127                         }
00128                         if(gpio_get_pin_value(GPIO_PUSH_BUTTON_1) == 0){
00129                                 // CPU speed = 1/2 * oscillator0
00130                                 pm_cksel(&AVR32_PM, CLOCK_DIV_ON, pbasel, CLOCK_DIV_ON, pbbsel,
00131                                                 CLOCK_DIV_ON, DIV_HALF);
00132                                 gpio_clr_gpio_pin(LED1_GPIO);
00133                                 gpio_set_gpio_pin(LED0_GPIO);
00134                                 gpio_set_gpio_pin(LED2_GPIO);
00135                         }
00136                         if(gpio_get_pin_value(GPIO_PUSH_BUTTON_2) == 0){
00137                                 // CPU speed = 1/4 * oscillator0
00138                                 pm_cksel(&AVR32_PM, CLOCK_DIV_ON, pbasel, CLOCK_DIV_ON, pbbsel,
00139                                                 CLOCK_DIV_ON, DIV_FOURTH);
00140                                 gpio_clr_gpio_pin(LED2_GPIO);
00141                                 gpio_set_gpio_pin(LED0_GPIO);
00142                                 gpio_set_gpio_pin(LED1_GPIO);
00143                         }
00144                                 
00145         }
00146         return 0;
00147 }

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