Advertisement
Guest User

EIC Handler

a guest
May 2nd, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.83 KB | None | 0 0
  1. typedef struct  
  2. {
  3.     PORT_PINCFG_Type pin_cfg;
  4.     PORT_PMUX_Type pin_mux;
  5.     uint16_t driveRegister; /* == 0 or (1<<11) */
  6. } port_cfg;
  7.  
  8.  
  9. port_cfg port_config[16] = {
  10.     [0].pin_cfg.bit = { .PMUXEN = 0, .INEN = 1 },
  11.     /* [1...6] */
  12.     [7].pin_cfg.bit = { .PMUXEN = 1, .INEN = 1 },
  13.     [8].pin_cfg.bit = { .PMUXEN = 1, .INEN = 1 },
  14.     [9].pin_cfg.bit = { .PMUXEN = 1, .INEN = 1 },
  15.     /* [10...15] / [0...6] */
  16.     [7].pin_mux.bit = { .PMUXO = MUX_PA11E_TC1_WO1 },
  17.     [8].pin_mux.bit = { .PMUXO = MUX_PA11C_SERCOM0_PAD3 },
  18.     [9].pin_mux.bit = { .PMUXO = MUX_PA11C_SERCOM0_PAD3 },
  19.     /* [10...15] */
  20. };
  21.  
  22. void EIC_Handler(void)
  23. {
  24.     // a shared interrupt handler for changes on five different external pins:
  25.  
  26.     // EXTINT0 = PA00 = SEL - interrupt on rising or falling edge
  27.     // EXTINT1 = PA01 = PH0 - interrupt on rising or falling edge
  28.     // EXTINT2 = PA02 = PH1 - interrupt on rising or falling edge
  29.     // EXTINT3 = PA03 = PH2 - interrupt on rising or falling edge
  30.     // EXTINT4 = PA04 = PH3 - interrupt on rising edge
  31.     // PA11 = output
  32.  
  33.     uint32_t flags = EIC->INTFLAG.reg; // a 1 bit means a change was detected on that pin
  34.  
  35.     // clear EXTINT0-4 flags, if they were set.
  36.     EIC->INTFLAG.reg = (flags & 0x1F); // writing a 1 bit clears the interrupt flags
  37.  
  38.     // mask the 4 lowest bits and use them as the address of the desired drive register
  39.     uint32_t localSelectedDriveRegister = PORT->Group[GPIO_PORTA].IN.reg & 0xF;
  40.  
  41.     PORT->Group[GPIO_PORTA].OUTSET.reg = port_config[localSelectedDriveRegister].driveRegister;
  42.     PORT->Group[GPIO_PORTA].OUTCLR.reg = (~port_config[localSelectedDriveRegister].driveRegister)&(1<<11);
  43.     PORT->Group[GPIO_PORTA].PINCFG[11] = port_config[localSelectedDriveRegister].pin_cfg;
  44.     PORT->Group[GPIO_PORTA].PMUX[11>>1] = port_config[localSelectedDriveRegister].pin_mux;
  45.        
  46.     selectedDriveRegister = localSelectedDriveRegister;
  47.    
  48.     /*...*/
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement