00001 /*This file has been prepared for Doxygen automatic documentation generation.*/ 00092 #include <avr32/io.h> 00093 #include "compiler.h" 00094 #include "gpio.h" 00095 #include "power_clocks_lib.h" 00096 #include "board.h" 00097 #include "eic.h" 00098 00101 00102 #if BOARD==EVK1100 00103 // With the UC3A datasheet, in section "Peripheral Multiplexing on I/O lines" in 00104 // the table "GPIO Controller Function Multiplexing", we see that the NMI is 00105 // mapped on GPIO 20 (i.e. PA20). Using the EVK1100 schematics, we see that the 00106 // joystick push event is connected to PA20. Thus, a push on the joystick will 00107 // generate an NMI. The External Interrupt number 8 is the NMI. 00108 // Note: AVR32_EIC_EXTINT_8_PIN & AVR32_EIC_EXTINT_8_FUNCTION defines are found 00109 // in the uc3axxxx.h part-specific header file. 00110 # define EXT_INT_EXAMPLE_PIN_LINE AVR32_EIC_EXTINT_8_PIN 00111 # define EXT_INT_EXAMPLE_FUNCTION_LINE AVR32_EIC_EXTINT_8_FUNCTION 00112 # define EXT_INT_EXAMPLE_LINE EXT_NMI 00113 #elif BOARD==EVK1101 00114 // With the UC3B datasheet, in section "Peripheral Multiplexing on I/O lines" in 00115 // the table "GPIO Controller Function Multiplexing", we see that the External 00116 // Interrupt 6 is mapped on GPIO 34 (i.e. PB02). Using the EVK1101 schematics, 00117 // we see that the pushbutton 0 press event is connected to PB02. Thus, a press 00118 // on PB0 will generate the external interrupt 6. 00119 // Note: On EVK1101 Rev. B, PB0 is named PB2. 00120 // Note: AVR32_EIC_EXTINT_6_PIN & AVR32_EIC_EXTINT_6_FUNCTION defines are found 00121 // in the uc3bxxxx.h part-specific header file. 00122 # define EXT_INT_EXAMPLE_PIN_LINE AVR32_EIC_EXTINT_6_PIN 00123 # define EXT_INT_EXAMPLE_FUNCTION_LINE AVR32_EIC_EXTINT_6_FUNCTION 00124 # define EXT_INT_EXAMPLE_LINE EXT_INT6 00125 #elif BOARD==EVK1104 00126 // With the UC3A3 datasheet, in section "Peripheral Multiplexing on I/O lines" 00127 // in the table "GPIO Controller Function Multiplexing", we see that the NMI is 00128 // mapped on GPIO 20 (i.e. PA20). Using the EVK1104 schematics, we see that the 00129 // J17.7 pin is connected to PA20. Thus, a low level on J17.7 will generate an 00130 // NMI. The External Interrupt number 8 is the NMI. 00131 // Note: AVR32_EIC_EXTINT_8_PIN & AVR32_EIC_EXTINT_8_FUNCTION defines are found 00132 // in the uc3a3xxx.h part-specific header file. 00133 # define EXT_INT_EXAMPLE_PIN_LINE AVR32_EIC_EXTINT_8_PIN 00134 # define EXT_INT_EXAMPLE_FUNCTION_LINE AVR32_EIC_EXTINT_8_FUNCTION 00135 # define EXT_INT_EXAMPLE_LINE EXT_NMI 00136 #elif BOARD==UC3C_EK 00137 // With the UC3C datasheet, in section "Peripheral Multiplexing on I/O lines" 00138 // in the table "GPIO Controller Function Multiplexing", we see that the NMI is 00139 // mapped on GPIO 29 (i.e. PA29). Using the UC3C_EK schematics, we see that the 00140 // SW5 Button is connected to PA29. Thus, a low level on SW5 will generate an 00141 // NMI. The External Interrupt number 8 is the NMI. 00142 // Note: AVR32_EIC_EXTINT_0_PIN & AVR32_EIC_EXTINT_0_FUNCTION defines are found 00143 // in the uc3a3xxx.h part-specific header file. 00144 # define EXT_INT_EXAMPLE_PIN_LINE AVR32_EIC_EXTINT_0_0_PIN 00145 # define EXT_INT_EXAMPLE_FUNCTION_LINE AVR32_EIC_EXTINT_0_0_FUNCTION 00146 # define EXT_INT_EXAMPLE_LINE EXT_NMI 00147 #endif 00149 00150 00151 /* \brief Toggle Led0 for a short while. 00152 * 00153 */ 00154 static void ToggleLed0Delay(void) 00155 { 00156 volatile int i; 00157 volatile int j = 30; 00158 do{ 00159 j--; 00160 i=1000; 00161 while(i--); 00162 gpio_tgl_gpio_pin(LED0_GPIO); // Toggle the LED0. 00163 }while(j); 00164 } 00165 00166 00167 /* 00168 * \brief main function : do init and loop to wake up CPU through EIC controller 00169 */ 00170 int main(void) 00171 { 00172 eic_options_t eic_options; // Structure holding the configuration parameters 00173 // of the EIC module. 00174 00175 // Enable LED0_GPIO on the EVK 00176 gpio_enable_gpio_pin(LED0_GPIO); 00177 00178 // Enable level-triggered interrupt. 00179 eic_options.eic_mode = EIC_MODE_LEVEL_TRIGGERED; 00180 // Interrupt will trigger on low-level. 00181 eic_options.eic_level = EIC_LEVEL_LOW_LEVEL; 00182 // Enable filter. 00183 eic_options.eic_filter = EIC_FILTER_ENABLED; 00184 // For Wake Up mode, initialize in asynchronous mode 00185 eic_options.eic_async = EIC_ASYNCH_MODE; 00186 // Choose External Interrupt Controller Line 00187 eic_options.eic_line = EXT_INT_EXAMPLE_LINE; // Enable the chosen external interrupt line. 00188 00189 // Map the interrupt line to the GPIO pin with the right peripheral function. 00190 gpio_enable_module_pin(EXT_INT_EXAMPLE_PIN_LINE,EXT_INT_EXAMPLE_FUNCTION_LINE); 00191 00192 // Init the EIC controller with the options 00193 eic_init(&AVR32_EIC, &eic_options,1); 00194 // Enable External Interrupt Controller Line 00195 eic_enable_line(&AVR32_EIC, EXT_INT_EXAMPLE_LINE); 00196 00197 // Switch the CPU to static sleep mode. 00198 // When the CPU is idle, it is possible to switch off the CPU clock and optionally other 00199 // clock domains to save power. This is activated by the sleep instruction, which takes the sleep 00200 // mode index number as argument. SLEEP function is defined in \DRIVERS\PM\pm.h. 00201 // In static mode, all oscillators, including 32KHz and RC oscillator are stopped. 00202 // Bandgap voltage reference BOD detector is turned off. 00203 SLEEP(AVR32_PM_SMODE_STATIC); 00204 00205 // Activate LED0 pin in GPIO output mode and switch LED0 off. 00206 gpio_set_gpio_pin(LED0_GPIO); 00207 00208 // Cpu now is in static sleep mode. When the wake-up external interrupt occurs, 00209 // the CPU resumes execution here and enter the while(1) loop. 00210 while(1) 00211 { 00212 ToggleLed0Delay(); // Toggle LED0 for a short while 00213 // Interrupt Line must be cleared to enable next SLEEP action 00214 eic_clear_interrupt_line(&AVR32_EIC, EXT_INT_EXAMPLE_LINE); 00215 00216 SLEEP(AVR32_PM_SMODE_STATIC); // re-enter sleep mode. 00217 // Cpu now is in static sleep mode. When the wake-up external interrupt occurs, 00218 // the CPU resumes execution back from the top of the while loop. 00219 } 00220 }