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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

InterruptManagement.h 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2012.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
  9. Permission to use, copy, modify, distribute, and sell this
  10. software and its documentation for any purpose is hereby granted
  11. without fee, provided that the above copyright notice appear in
  12. all copies and that both that the copyright notice and this
  13. permission notice and warranty disclaimer appear in supporting
  14. documentation, and that the name of the author not be used in
  15. advertising or publicity pertaining to distribution of the
  16. software without specific, written prior permission.
  17. The author disclaim all warranties with regard to this
  18. software, including all implied warranties of merchantability
  19. and fitness. In no event shall the author be liable for any
  20. special, indirect or consequential damages or any damages
  21. whatsoever resulting from loss of use, data or profits, whether
  22. in an action of contract, negligence or other tortious action,
  23. arising out of or in connection with the use or performance of
  24. this software.
  25. */
  26. /** \file
  27. * \brief Interrupt Controller Driver for the AVR32 UC3 microcontrollers.
  28. *
  29. * Interrupt controller driver for the AVR32 UC3 microcontrollers, for the configuration of interrupt
  30. * handlers within the device.
  31. */
  32. /** \ingroup Group_PlatformDrivers_UC3
  33. * \defgroup Group_PlatformDrivers_UC3Interrupts Interrupt Controller Driver - LUFA/Platform/UC3/InterruptManagement.h
  34. * \brief Interrupt Controller Driver for the AVR32 UC3 microcontrollers.
  35. *
  36. * \section Sec_Dependencies Module Source Dependencies
  37. * The following files must be built with any user project that uses this module:
  38. * - LUFA/Platform/UC3/InterruptManagement.c <i>(Makefile source module name: LUFA_SRC_PLATFORM)</i>
  39. * - LUFA/Platform/UC3/Exception.S <i>(Makefile source module name: LUFA_SRC_PLATFORM)</i>
  40. *
  41. * \section Sec_ModDescription Module Description
  42. * Interrupt controller driver for the AVR32 UC3 microcontrollers, for the configuration of interrupt
  43. * handlers within the device.
  44. *
  45. * Usage Example:
  46. * \code
  47. * #include <LUFA/Platform/UC3/InterruptManagement.h>
  48. *
  49. * ISR(USB_Group_IRQ_Handler)
  50. * {
  51. * // USB group handler code here
  52. * }
  53. *
  54. * void main(void)
  55. * {
  56. * INTC_Init();
  57. * INTC_RegisterGroupHandler(INTC_IRQ_GROUP(AVR32_USBB_IRQ), AVR32_INTC_INT0, USB_Group_IRQ_Handler);
  58. * }
  59. * \endcode
  60. *
  61. * @{
  62. */
  63. #ifndef _UC3_INTERRUPT_MANAGEMENT_H_
  64. #define _UC3_INTERRUPT_MANAGEMENT_H_
  65. /* Includes: */
  66. #include "../../Common/Common.h"
  67. /* Enable C linkage for C++ Compilers: */
  68. #if defined(__cplusplus)
  69. extern "C" {
  70. #endif
  71. /* Private Interface - For use in library only: */
  72. #if !defined(__DOXYGEN__)
  73. /* Type Defines: */
  74. typedef void (*InterruptHandlerPtr_t)(void);
  75. /* External Variables: */
  76. #if defined(__INCLUDE_FROM_INTMANAGEMENT_C)
  77. extern const void EVBA_Table;
  78. #endif
  79. extern InterruptHandlerPtr_t InterruptHandlers[AVR32_INTC_NUM_INT_GRPS];
  80. extern const uint32_t Autovector_Table[];
  81. #endif
  82. /* Public Interface - May be used in end-application: */
  83. /* Macros: */
  84. /** Converts a given interrupt index into its associated interrupt group.
  85. *
  86. * \param[in] IRQIndex Index of the interrupt request to convert.
  87. *
  88. * \return Interrupt group number associated with the interrupt index.
  89. */
  90. #define INTC_IRQ_GROUP(IRQIndex) (IRQIndex / 32)
  91. /** Converts a given interrupt index into its associated interrupt line.
  92. *
  93. * \param[in] IRQIndex Index of the interrupt request to convert.
  94. *
  95. * \return Interrupt line number associated with the interrupt index.
  96. */
  97. #define INTC_IRQ_LINE(IRQIndex) (IRQIndex % 32)
  98. /* Function Prototypes: */
  99. void INTC_Init(void);
  100. InterruptHandlerPtr_t INTC_GetInterruptHandler(const uint_reg_t InterruptLevel);
  101. /* Inline Functions: */
  102. /** Registers a handler for a given interrupt group. On the AVR32 UC3 devices, interrupts are grouped by
  103. * peripheral. To save on SRAM used, a single ISR handles all interrupt lines within a single group - to
  104. * determine the exact line that has interrupted within the group ISR handler, use \ref INTC_GetGroupInterrupts().
  105. *
  106. * If multiple interrupts with the same group are registered, the last registered handler will become the
  107. * handler called for interrupts raised within that group.
  108. *
  109. * To obtain the group number of a specific interrupt index, use the \ref INTC_IRQ_GROUP() macro.
  110. *
  111. * \param[in] GroupNumber Group number of the interrupt group to register a handler for.
  112. * \param[in] InterruptLevel Priority level for the specified interrupt, a \c AVR32_INTC_INT* mask.
  113. * \param[in] Handler Address of the ISR handler for the interrupt group.
  114. */
  115. static inline void INTC_RegisterGroupHandler(const uint16_t GroupNumber,
  116. const uint8_t InterruptLevel,
  117. const InterruptHandlerPtr_t Handler) ATTR_ALWAYS_INLINE;
  118. static inline void INTC_RegisterGroupHandler(const uint16_t GroupNumber,
  119. const uint8_t InterruptLevel,
  120. const InterruptHandlerPtr_t Handler)
  121. {
  122. InterruptHandlers[GroupNumber] = Handler;
  123. AVR32_INTC.ipr[GroupNumber] = Autovector_Table[InterruptLevel];
  124. }
  125. /** Retrieves the pending interrupts for a given interrupt group. The result of this function should be masked
  126. * against interrupt request indexes converted to a request line number via the \ref INTC_IRQ_LINE() macro. To
  127. * obtain the group number of a given interrupt request, use the \ref INTC_IRQ_GROUP() macro.
  128. *
  129. * \param[in] GroupNumber Group number of the interrupt group to check.
  130. *
  131. * \return Mask of pending interrupt lines for the given interrupt group.
  132. */
  133. static inline uint_reg_t INTC_GetGroupInterrupts(const uint16_t GroupNumber) ATTR_ALWAYS_INLINE;
  134. static inline uint_reg_t INTC_GetGroupInterrupts(const uint16_t GroupNumber)
  135. {
  136. return AVR32_INTC.irr[GroupNumber];
  137. }
  138. /* Disable C linkage for C++ Compilers: */
  139. #if defined(__cplusplus)
  140. }
  141. #endif
  142. #endif
  143. /** @} */