ihndlr.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #ifndef _ARCH_AVR32_INTERRUPT_HANDLER_H_
  2. #define _ARCH_AVR32_INTERRUPT_HANDLER_H_
  3. /*!
  4. * Copyright (C) 2001-2010 by egnite Software GmbH
  5. *
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the name of the copyright holders nor the names of
  18. * contributors may be used to endorse or promote products derived
  19. * from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  31. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. *
  34. * For additional information see http://www.ethernut.de/
  35. */
  36. /*
  37. * $Log: ihndlr.h,v $
  38. *
  39. */
  40. //
  41. // W A R N I N G
  42. // -------------
  43. //
  44. // This file is not part of the Nut/OS API. It exists for the convenience
  45. // of Interrupt Handling. This header file may change from version
  46. // to version without notice, or even be removed.
  47. //
  48. // We mean it.
  49. //
  50. //
  51. //! Pointer to interrupt handler.
  52. #if __GNUC__
  53. typedef void (*__int_handler)(void);
  54. #elif __ICCAVR32__
  55. typedef void (__interrupt *__int_handler)(void);
  56. #endif
  57. extern void init_interrupts(void);
  58. extern void register_interrupt(__int_handler handler, unsigned int irq, unsigned int int_lev);
  59. /*
  60. WHEN CHANGING PLEASE NOTICE:
  61. Errata 41.5.5.5 reads:
  62. "Need two NOPs instruction after instructions masking interrupts
  63. The instructions following in the pipeline the instruction masking the interrupt through SR
  64. may behave abnormally.
  65. Fix/Workaround
  66. Place two NOPs instructions after each SSRF or MTSR instruction setting IxM or GM in SR."
  67. */
  68. #define IRQ_ENTRY() \
  69. { \
  70. /* Prevent preempted interrupts disabling global interrupts */ \
  71. __asm__ __volatile__ ("ssrf\t%0; nop; nop" :: "i" (AVR32_SR_GM_OFFSET) : "memory"); \
  72. \
  73. /* Save R0..R7. Other registers are saved by the CPU if __AVR32_UC__ */ \
  74. /* Or by exception.S if __AVR32_AP7000__ */ \
  75. __asm__ __volatile__ ("pushm r0-r7"); \
  76. }
  77. #define IRQ_EXIT() \
  78. { \
  79. /* Restore R0..R7 */ \
  80. __asm__ __volatile__ ("popm r0-r7"); \
  81. \
  82. /* Prevent preempted interrupts disabling global interrupts */ \
  83. __asm__ __volatile__ ("csrf\t%0" :: "i" (AVR32_SR_GM_OFFSET) : "memory"); \
  84. }
  85. #endif // _ARCH_AVR32_INTERRUPT_HANDLER_H_