Definition in file clock_scaling_example.c.
#include <avr32/io.h>
#include "board.h"
#include "pm.h"
#include "gpio.h"
Go to the source code of this file.
Defines | |
| #define | CLOCK_DIV_OFF 0 |
| #define | CLOCK_DIV_ON 1 |
| #define | DIV_FOURTH 1 |
| #define | DIV_HALF 0 |
Functions | |
| int | main (void) |
| main function : set clock scaling according to pressed button. | |
| #define CLOCK_DIV_OFF 0 |
Definition at line 94 of file clock_scaling_example.c.
| #define CLOCK_DIV_ON 1 |
Depending on the current CPU speed a LED is turned on. LED0 = full speed LED1 = half speed LED2 = forth speed
NOTE: If the user of this software intends to change division factors for the clocks or use the PLL take following rules into account:
Flash wait states must be added when high frequencies are used
Definition at line 93 of file clock_scaling_example.c.
| #define DIV_FOURTH 1 |
Definition at line 96 of file clock_scaling_example.c.
| #define DIV_HALF 0 |
Definition at line 95 of file clock_scaling_example.c.
| int main | ( | void | ) |
main function : set clock scaling according to pressed button.
Definition at line 101 of file clock_scaling_example.c.
References CLOCK_DIV_OFF, CLOCK_DIV_ON, DIV_FOURTH, DIV_HALF, FOSC0, 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, LED1_GPIO, LED2_GPIO, OSC0_STARTUP, pm_cksel(), and pm_switch_to_osc0().
00101 { 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 }
1.5.3-20071008