stm32_isr.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file STM32L0xx/stm32_isr.h
  15. * @brief STM32L0xx ISR handler code.
  16. *
  17. * @addtogroup STM32L0xx_ISR
  18. * @{
  19. */
  20. #include "hal.h"
  21. /*===========================================================================*/
  22. /* Driver local definitions. */
  23. /*===========================================================================*/
  24. /*===========================================================================*/
  25. /* Driver exported variables. */
  26. /*===========================================================================*/
  27. /*===========================================================================*/
  28. /* Driver local variables. */
  29. /*===========================================================================*/
  30. /*===========================================================================*/
  31. /* Driver local functions. */
  32. /*===========================================================================*/
  33. #define exti_serve_irq(pr, channel) { \
  34. \
  35. if ((pr) & (1U << (channel))) { \
  36. _pal_isr_code(channel); \
  37. } \
  38. }
  39. /*===========================================================================*/
  40. /* Driver interrupt handlers. */
  41. /*===========================================================================*/
  42. #if (HAL_USE_PAL && (PAL_USE_WAIT || PAL_USE_CALLBACKS)) || defined(__DOXYGEN__)
  43. #if !defined(STM32_DISABLE_EXTI0_1_HANDLER)
  44. /**
  45. * @brief EXTI[0]...EXTI[1] interrupt handler.
  46. *
  47. * @isr
  48. */
  49. OSAL_IRQ_HANDLER(Vector54) {
  50. uint32_t pr;
  51. OSAL_IRQ_PROLOGUE();
  52. pr = EXTI->PR;
  53. pr &= ((1U << 0) | (1U << 1));
  54. EXTI->PR = pr;
  55. exti_serve_irq(pr, 0);
  56. exti_serve_irq(pr, 1);
  57. OSAL_IRQ_EPILOGUE();
  58. }
  59. #endif
  60. /**
  61. * @brief EXTI[2]...EXTI[3] interrupt handler.
  62. *
  63. * @isr
  64. */
  65. #if !defined(STM32_DISABLE_EXTI2_3_HANDLER)
  66. OSAL_IRQ_HANDLER(Vector58) {
  67. uint32_t pr;
  68. OSAL_IRQ_PROLOGUE();
  69. pr = EXTI->PR;
  70. pr &= ((1U << 2) | (1U << 3));
  71. EXTI->PR = pr;
  72. exti_serve_irq(pr, 2);
  73. exti_serve_irq(pr, 3);
  74. OSAL_IRQ_EPILOGUE();
  75. }
  76. #endif
  77. #if !defined(STM32_DISABLE_EXTI4_15_HANDLER)
  78. /**
  79. * @brief EXTI[4]...EXTI[15] interrupt handler.
  80. *
  81. * @isr
  82. */
  83. OSAL_IRQ_HANDLER(Vector5C) {
  84. uint32_t pr;
  85. OSAL_IRQ_PROLOGUE();
  86. pr = EXTI->PR;
  87. pr &= ((1U << 4) | (1U << 5) | (1U << 6) | (1U << 7) | (1U << 8) |
  88. (1U << 9) | (1U << 10) | (1U << 11) | (1U << 12) | (1U << 13) |
  89. (1U << 14) | (1U << 15));
  90. EXTI->PR = pr;
  91. exti_serve_irq(pr, 4);
  92. exti_serve_irq(pr, 5);
  93. exti_serve_irq(pr, 6);
  94. exti_serve_irq(pr, 7);
  95. exti_serve_irq(pr, 8);
  96. exti_serve_irq(pr, 9);
  97. exti_serve_irq(pr, 10);
  98. exti_serve_irq(pr, 11);
  99. exti_serve_irq(pr, 12);
  100. exti_serve_irq(pr, 13);
  101. exti_serve_irq(pr, 14);
  102. exti_serve_irq(pr, 15);
  103. OSAL_IRQ_EPILOGUE();
  104. }
  105. #endif
  106. #endif /* HAL_USE_PAL && (PAL_USE_WAIT || PAL_USE_CALLBACKS) */
  107. /*===========================================================================*/
  108. /* Driver exported functions. */
  109. /*===========================================================================*/
  110. /**
  111. * @brief Enables IRQ sources.
  112. *
  113. * @notapi
  114. */
  115. void irqInit(void) {
  116. #if HAL_USE_PAL
  117. nvicEnableVector(STM32_EXTI_LINE01_NUMBER, STM32_IRQ_EXTI0_1_PRIORITY);
  118. nvicEnableVector(STM32_EXTI_LINE23_NUMBER, STM32_IRQ_EXTI2_3_PRIORITY);
  119. nvicEnableVector(STM32_EXTI_LINE4_15_NUMBER, STM32_IRQ_EXTI4_15_PRIORITY);
  120. nvicEnableVector(STM32_EXTI_LINE16_NUMBER, STM32_IRQ_EXTI16_PRIORITY);
  121. #endif
  122. }
  123. /**
  124. * @brief Disables IRQ sources.
  125. *
  126. * @notapi
  127. */
  128. void irqDeinit(void) {
  129. #if HAL_USE_PAL
  130. nvicDisableVector(STM32_EXTI_LINE01_NUMBER);
  131. nvicDisableVector(STM32_EXTI_LINE23_NUMBER);
  132. nvicDisableVector(STM32_EXTI_LINE4_15_NUMBER);
  133. nvicDisableVector(STM32_EXTI_LINE16_NUMBER);
  134. nvicDisableVector(STM32_EXTI_LINE2122_NUMBER);
  135. #endif
  136. }
  137. /** @} */