Definition in file eic_example3.c.
#include <avr32/io.h>
#include "compiler.h"
#include "gpio.h"
#include "pm.h"
#include "board.h"
#include "eic.h"
#include "intc.h"
Go to the source code of this file.
Defines | |
External Interrupt pin Mappings | |
#define | EXT_INT_EXAMPLE_FUNCTION_LINE1 AVR32_EIC_EXTINT_6_FUNCTION |
#define | EXT_INT_EXAMPLE_FUNCTION_LINE2 AVR32_EIC_EXTINT_7_FUNCTION |
#define | EXT_INT_EXAMPLE_IRQ_LINE1 AVR32_EIC_IRQ_6 |
#define | EXT_INT_EXAMPLE_IRQ_LINE2 AVR32_EIC_IRQ_7 |
#define | EXT_INT_EXAMPLE_LINE1 EXT_INT6 |
#define | EXT_INT_EXAMPLE_LINE2 EXT_INT7 |
#define | EXT_INT_EXAMPLE_PIN_LINE1 AVR32_EIC_EXTINT_6_PIN |
#define | EXT_INT_EXAMPLE_PIN_LINE2 AVR32_EIC_EXTINT_7_PIN |
#define | EXT_SCAN_EXAMPLE_FUNCTION_LINE1 ATPASTE4(AVR32_EIC_SCAN_,SCAN_COL1_IDX,SCAN_COL1_MUX,_FUNCTION) |
#define | EXT_SCAN_EXAMPLE_FUNCTION_LINE2 ATPASTE4(AVR32_EIC_SCAN_,SCAN_COL2_IDX,SCAN_COL2_MUX,_FUNCTION) |
#define | EXT_SCAN_EXAMPLE_PIN_LINE1 ATPASTE4(AVR32_EIC_SCAN_,SCAN_COL1_IDX,SCAN_COL1_MUX,_PIN) |
#define | EXT_SCAN_EXAMPLE_PIN_LINE2 ATPASTE4(AVR32_EIC_SCAN_,SCAN_COL2_IDX,SCAN_COL2_MUX,_PIN) |
Keypad scan index configuration | |
Choose the scan index for each scan column in the [0,7] range.
| |
#define | SCAN_COL1_IDX 4 |
#define | SCAN_COL1_MUX |
#define | SCAN_COL2_IDX 5 |
#define | SCAN_COL2_MUX |
Functions | |
static void | eic_int_handler1 (void) |
Interrupt handler of the External interrupt line "1". | |
static void | eic_int_handler2 (void) |
Interrupt handler of the External interrupt line "2". | |
int | main (void) |
static void | software_delay (void) |
Variables | |
static volatile Bool | bCancelSwDelay = FALSE |
Global var used to cancel the software delay if an External Interrupt occurs. | |
eic_options_t | eic_options [2] |
Structure holding the configuration parameters of the EIC module. | |
unsigned char | key_number = 0 |
Global var used to switch between different LED patterns. |
#define EXT_INT_EXAMPLE_FUNCTION_LINE1 AVR32_EIC_EXTINT_6_FUNCTION |
#define EXT_INT_EXAMPLE_FUNCTION_LINE2 AVR32_EIC_EXTINT_7_FUNCTION |
#define EXT_INT_EXAMPLE_IRQ_LINE1 AVR32_EIC_IRQ_6 |
#define EXT_INT_EXAMPLE_IRQ_LINE2 AVR32_EIC_IRQ_7 |
#define EXT_INT_EXAMPLE_LINE1 EXT_INT6 |
#define EXT_INT_EXAMPLE_LINE2 EXT_INT7 |
#define EXT_INT_EXAMPLE_PIN_LINE1 AVR32_EIC_EXTINT_6_PIN |
#define EXT_INT_EXAMPLE_PIN_LINE2 AVR32_EIC_EXTINT_7_PIN |
#define EXT_SCAN_EXAMPLE_FUNCTION_LINE1 ATPASTE4(AVR32_EIC_SCAN_,SCAN_COL1_IDX,SCAN_COL1_MUX,_FUNCTION) |
#define EXT_SCAN_EXAMPLE_FUNCTION_LINE2 ATPASTE4(AVR32_EIC_SCAN_,SCAN_COL2_IDX,SCAN_COL2_MUX,_FUNCTION) |
#define EXT_SCAN_EXAMPLE_PIN_LINE1 ATPASTE4(AVR32_EIC_SCAN_,SCAN_COL1_IDX,SCAN_COL1_MUX,_PIN) |
#define EXT_SCAN_EXAMPLE_PIN_LINE2 ATPASTE4(AVR32_EIC_SCAN_,SCAN_COL2_IDX,SCAN_COL2_MUX,_PIN) |
#define SCAN_COL1_IDX 4 |
Definition at line 166 of file eic_example3.c.
Referenced by eic_int_handler1(), and eic_int_handler2().
#define SCAN_COL1_MUX |
Definition at line 167 of file eic_example3.c.
#define SCAN_COL2_IDX 5 |
Definition at line 168 of file eic_example3.c.
Referenced by eic_int_handler1(), and eic_int_handler2().
#define SCAN_COL2_MUX |
Definition at line 169 of file eic_example3.c.
static void eic_int_handler1 | ( | void | ) | [static] |
Interrupt handler of the External interrupt line "1".
Definition at line 252 of file eic_example3.c.
References bCancelSwDelay, eic_clear_interrupt_line(), eic_get_interrupt_pad_scan(), EXT_INT_EXAMPLE_LINE1, key_number, SCAN_COL1_IDX, and SCAN_COL2_IDX.
Referenced by main().
00253 { 00254 int line_number; 00255 line_number = eic_get_interrupt_pad_scan(&AVR32_EIC); 00256 switch (line_number) 00257 { 00258 case SCAN_COL1_IDX : 00259 key_number = 1; 00260 break; 00261 case SCAN_COL2_IDX : 00262 key_number = 2; 00263 break; 00264 } 00265 bCancelSwDelay = TRUE; 00266 eic_clear_interrupt_line(&AVR32_EIC, EXT_INT_EXAMPLE_LINE1); 00267 }
static void eic_int_handler2 | ( | void | ) | [static] |
Interrupt handler of the External interrupt line "2".
Definition at line 278 of file eic_example3.c.
References bCancelSwDelay, eic_clear_interrupt_line(), eic_get_interrupt_pad_scan(), EXT_INT_EXAMPLE_LINE2, key_number, SCAN_COL1_IDX, and SCAN_COL2_IDX.
Referenced by main().
00279 { 00280 int line_number; 00281 line_number = eic_get_interrupt_pad_scan(&AVR32_EIC); 00282 switch (line_number) 00283 { 00284 case SCAN_COL1_IDX : 00285 key_number = 3; 00286 break; 00287 case SCAN_COL2_IDX : 00288 key_number = 4; 00289 break; 00290 } 00291 bCancelSwDelay = TRUE; 00292 eic_clear_interrupt_line(&AVR32_EIC, EXT_INT_EXAMPLE_LINE2); 00293 }
int main | ( | void | ) |
Definition at line 311 of file eic_example3.c.
References eic_options_t::eic_async, eic_options_t::eic_edge, EIC_EDGE_FALLING_EDGE, eic_enable_interrupt_lines(), eic_enable_interrupt_scan(), eic_enable_lines(), eic_init(), eic_int_handler1(), eic_int_handler2(), eic_options_t::eic_line, eic_options_t::eic_mode, EIC_MODE_EDGE_TRIGGERED, EIC_SYNCH_MODE, EXT_INT_EXAMPLE_FUNCTION_LINE1, EXT_INT_EXAMPLE_FUNCTION_LINE2, EXT_INT_EXAMPLE_IRQ_LINE1, EXT_INT_EXAMPLE_IRQ_LINE2, EXT_INT_EXAMPLE_LINE1, EXT_INT_EXAMPLE_LINE2, EXT_INT_EXAMPLE_PIN_LINE1, EXT_INT_EXAMPLE_PIN_LINE2, EXT_SCAN_EXAMPLE_FUNCTION_LINE1, EXT_SCAN_EXAMPLE_FUNCTION_LINE2, EXT_SCAN_EXAMPLE_PIN_LINE1, EXT_SCAN_EXAMPLE_PIN_LINE2, key_number, and software_delay().
00312 { 00313 // Enable edge-triggered interrupt. 00314 eic_options[0].eic_mode = EIC_MODE_EDGE_TRIGGERED; 00315 // Interrupt will trigger on falling edge (this is a must-do for the keypad scan 00316 // feature if the chosen mode is edge-triggered). 00317 eic_options[0].eic_edge = EIC_EDGE_FALLING_EDGE; 00318 // Initialize in synchronous mode : interrupt is synchronized to the clock 00319 eic_options[0].eic_async = EIC_SYNCH_MODE; 00320 // Set the interrupt line number. 00321 eic_options[0].eic_line = EXT_INT_EXAMPLE_LINE1; 00322 00323 00324 // Enable edge-triggered interrupt. 00325 eic_options[1].eic_mode = EIC_MODE_EDGE_TRIGGERED; 00326 // Interrupt will trigger on falling edge (this is a must-do for the keypad scan 00327 // feature if the chosen mode is edge-triggered). 00328 eic_options[1].eic_edge = EIC_EDGE_FALLING_EDGE; 00329 // Initialize in synchronous mode : interrupt is synchronized to the clock 00330 eic_options[1].eic_async = EIC_SYNCH_MODE; 00331 // Set the interrupt line number. 00332 eic_options[1].eic_line = EXT_INT_EXAMPLE_LINE2; 00333 00334 00335 // Activate LED0 & LED1 & LED2 & LED3 pins in GPIO output mode and switch them off. 00336 gpio_set_gpio_pin(LED0_GPIO); 00337 gpio_set_gpio_pin(LED1_GPIO); 00338 gpio_set_gpio_pin(LED2_GPIO); 00339 gpio_set_gpio_pin(LED3_GPIO); 00340 00341 // Map the interrupt lines to the GPIO pins with the right peripheral functions. 00342 static const gpio_map_t EIC_GPIO_MAP = 00343 { 00344 {EXT_INT_EXAMPLE_PIN_LINE1, EXT_INT_EXAMPLE_FUNCTION_LINE1}, 00345 {EXT_INT_EXAMPLE_PIN_LINE2, EXT_INT_EXAMPLE_FUNCTION_LINE2}, 00346 {EXT_SCAN_EXAMPLE_PIN_LINE1, EXT_SCAN_EXAMPLE_FUNCTION_LINE1}, 00347 {EXT_SCAN_EXAMPLE_PIN_LINE2, EXT_SCAN_EXAMPLE_FUNCTION_LINE2} 00348 }; 00349 gpio_enable_module(EIC_GPIO_MAP, sizeof(EIC_GPIO_MAP) / sizeof(EIC_GPIO_MAP[0])); 00350 // Enable GPIO pullups for the rows. 00351 gpio_enable_pin_pull_up(EXT_INT_EXAMPLE_PIN_LINE1); 00352 gpio_enable_pin_pull_up(EXT_INT_EXAMPLE_PIN_LINE2); 00353 00354 // Disable all interrupts. 00355 Disable_global_interrupt(); 00356 00357 // Initialize interrupt vectors. 00358 INTC_init_interrupts(); 00359 00360 // Register the EIC interrupt handler to the interrupt controller. 00361 // eic_int_handler1 and eic_int_handler2 are the interrupt handlers to register. 00362 // EXT_INT_EXAMPLE_IRQ_LINE1 and EXT_INT_EXAMPLE_IRQ_LINE2 are the IRQ of the 00363 // interrupt handlers to register. 00364 // AVR32_INTC_INT0 is the interrupt priority level to assign to the group of this IRQ. 00365 // void INTC_register_interrupt(__int_handler handler, unsigned int irq, unsigned int int_level); 00366 INTC_register_interrupt(&eic_int_handler1, EXT_INT_EXAMPLE_IRQ_LINE1, AVR32_INTC_INT0); 00367 INTC_register_interrupt(&eic_int_handler2, EXT_INT_EXAMPLE_IRQ_LINE2, AVR32_INTC_INT0); 00368 00369 // Init the EIC controller with the options 00370 eic_init(&AVR32_EIC, eic_options, 2); 00371 // Enable the EIC lines. 00372 eic_enable_lines(&AVR32_EIC, (1<<eic_options[1].eic_line)|(1<<eic_options[0].eic_line)); 00373 // Enable the interrupt for each EIC line. 00374 eic_enable_interrupt_lines(&AVR32_EIC, (1<<eic_options[1].eic_line)|(1<<eic_options[0].eic_line)); 00375 // Enable the keypad scanning feature and configure the scan rate to 18ms (== pow(2,(10+1))*RCOsc). 00376 eic_enable_interrupt_scan(&AVR32_EIC,10); 00377 00378 // Enable all interrupts. 00379 Enable_global_interrupt(); 00380 00381 00382 // Loop infinitely, toggling the leds depending on the latest pressed key. 00383 while(1) 00384 { 00385 switch (key_number) 00386 { 00387 case 1 : 00388 gpio_clr_gpio_pin(LED0_GPIO); 00389 gpio_set_gpio_pin(LED1_GPIO); 00390 gpio_set_gpio_pin(LED2_GPIO); 00391 gpio_set_gpio_pin(LED3_GPIO); 00392 key_number = 0; 00393 software_delay(); 00394 break; 00395 case 2 : 00396 gpio_set_gpio_pin(LED0_GPIO); 00397 gpio_clr_gpio_pin(LED1_GPIO); 00398 gpio_set_gpio_pin(LED2_GPIO); 00399 gpio_set_gpio_pin(LED3_GPIO); 00400 key_number = 0; 00401 software_delay(); 00402 break; 00403 case 3 : 00404 gpio_set_gpio_pin(LED0_GPIO); 00405 gpio_set_gpio_pin(LED1_GPIO); 00406 gpio_clr_gpio_pin(LED2_GPIO); 00407 gpio_set_gpio_pin(LED3_GPIO); 00408 key_number = 0; 00409 software_delay(); 00410 break; 00411 case 4 : 00412 gpio_set_gpio_pin(LED0_GPIO); 00413 gpio_set_gpio_pin(LED1_GPIO); 00414 gpio_set_gpio_pin(LED2_GPIO); 00415 gpio_clr_gpio_pin(LED3_GPIO); 00416 key_number = 0; 00417 software_delay(); 00418 break; 00419 default : 00420 gpio_set_gpio_pin(LED0_GPIO); 00421 gpio_set_gpio_pin(LED1_GPIO); 00422 gpio_set_gpio_pin(LED2_GPIO); 00423 gpio_set_gpio_pin(LED3_GPIO); 00424 break; 00425 } 00426 } 00427 }
static void software_delay | ( | void | ) | [static] |
Definition at line 299 of file eic_example3.c.
References bCancelSwDelay.
Referenced by main().
00300 { 00301 volatile int i; 00302 bCancelSwDelay = FALSE; 00303 for (i=10000; (i>=0)&&(FALSE == bCancelSwDelay); i--); 00304 }
volatile Bool bCancelSwDelay = FALSE [static] |
Global var used to cancel the software delay if an External Interrupt occurs.
Definition at line 241 of file eic_example3.c.
Referenced by eic_int_handler1(), eic_int_handler2(), and software_delay().
Structure holding the configuration parameters of the EIC module.
Definition at line 235 of file eic_example3.c.
unsigned char key_number = 0 |
Global var used to switch between different LED patterns.
Definition at line 238 of file eic_example3.c.
Referenced by eic_int_handler1(), eic_int_handler2(), and main().