ARM7 based quadrocopter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

at91_pio.c 2.8 KiB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /***************************************************************************
  2. * sam7fc - Pinchange Interrupt Handler *
  3. * *
  4. * Copyright (C) 01/2008 by Olaf Rempel *
  5. * razzor@kopf-tisch.de *
  6. * *
  7. * This program is free software; you can redistribute it and/or modify *
  8. * it under the terms of the GNU General Public License as published by *
  9. * the Free Software Foundation; version 2 of the License *
  10. * *
  11. * This program is distributed in the hope that it will be useful, *
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  14. * GNU General Public License for more details. *
  15. * *
  16. * You should have received a copy of the GNU General Public License *
  17. * along with this program; if not, write to the *
  18. * Free Software Foundation, Inc., *
  19. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  20. ***************************************************************************/
  21. #include <stdint.h>
  22. #include <stdio.h>
  23. #include "AT91SAM7S256.h"
  24. #include "board.h"
  25. #include "at91_pio.h"
  26. /* extern symbols, defined in ldscript */
  27. extern struct pio_pinchange_isr _pio_isr_table;
  28. extern struct pio_pinchange_isr _pio_isr_table_end;
  29. static void pio_isr(void)
  30. {
  31. uint32_t status = *AT91C_PIOA_ISR;
  32. uint32_t input = *AT91C_PIOA_PDSR;
  33. struct pio_pinchange_isr *isr;
  34. for (isr = &_pio_isr_table; isr < &_pio_isr_table_end; isr++)
  35. if (isr->mask & status)
  36. isr->func(status, input);
  37. }
  38. void pio_trigger_isr(uint32_t mask)
  39. {
  40. uint32_t input = *AT91C_PIOA_PDSR;
  41. struct pio_pinchange_isr *isr;
  42. for (isr = &_pio_isr_table; isr < &_pio_isr_table_end; isr++)
  43. if (isr->mask & mask)
  44. isr->func(mask, input);
  45. }
  46. void at91_pio_init(void)
  47. {
  48. /* enable PIO clock */
  49. *AT91C_PMC_PCER = (1 << AT91C_ID_PIOA);
  50. /* enable pinchange interrupts */
  51. struct pio_pinchange_isr *isr;
  52. for (isr = &_pio_isr_table; isr < &_pio_isr_table_end; isr++)
  53. *AT91C_PIOA_IER = isr->mask;
  54. /* dummy read to clear interrupts */
  55. uint32_t dummy = *AT91C_PIOA_ISR;
  56. dummy = dummy;
  57. /* low priority, level triggered, own vector */
  58. AT91S_AIC *aic = AT91C_BASE_AIC;
  59. aic->AIC_SMR[AT91C_ID_PIOA] = IRQPRIO_PIOA | AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL;
  60. aic->AIC_SVR[AT91C_ID_PIOA] = (uint32_t)pio_isr;
  61. aic->AIC_IECR = (1 << AT91C_ID_PIOA);
  62. }