stm32_isr.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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 STM32F3xx/stm32_isr.h
  15. * @brief STM32F3xx ISR handler code.
  16. *
  17. * @addtogroup STM32F3xx_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_HANDLER)
  44. /**
  45. * @brief EXTI[0] interrupt handler.
  46. *
  47. * @isr
  48. */
  49. OSAL_IRQ_HANDLER(Vector58) {
  50. uint32_t pr;
  51. OSAL_IRQ_PROLOGUE();
  52. pr = EXTI->PR;
  53. pr &= EXTI->IMR & (1U << 0);
  54. EXTI->PR = pr;
  55. exti_serve_irq(pr, 0);
  56. OSAL_IRQ_EPILOGUE();
  57. }
  58. #endif
  59. #if !defined(STM32_DISABLE_EXTI1_HANDLER)
  60. /**
  61. * @brief EXTI[1] interrupt handler.
  62. *
  63. * @isr
  64. */
  65. OSAL_IRQ_HANDLER(Vector5C) {
  66. uint32_t pr;
  67. OSAL_IRQ_PROLOGUE();
  68. pr = EXTI->PR;
  69. pr &= EXTI->IMR & (1U << 1);
  70. EXTI->PR = pr;
  71. exti_serve_irq(pr, 1);
  72. OSAL_IRQ_EPILOGUE();
  73. }
  74. #endif
  75. #if !defined(STM32_DISABLE_EXTI2_HANDLER)
  76. /**
  77. * @brief EXTI[2] interrupt handler.
  78. *
  79. * @isr
  80. */
  81. OSAL_IRQ_HANDLER(Vector60) {
  82. uint32_t pr;
  83. OSAL_IRQ_PROLOGUE();
  84. pr = EXTI->PR;
  85. pr &= EXTI->IMR & (1U << 2);
  86. EXTI->PR = pr;
  87. exti_serve_irq(pr, 2);
  88. OSAL_IRQ_EPILOGUE();
  89. }
  90. #endif
  91. #if !defined(STM32_DISABLE_EXTI3_HANDLER)
  92. /**
  93. * @brief EXTI[3] interrupt handler.
  94. *
  95. * @isr
  96. */
  97. OSAL_IRQ_HANDLER(Vector64) {
  98. uint32_t pr;
  99. OSAL_IRQ_PROLOGUE();
  100. pr = EXTI->PR;
  101. pr &= EXTI->IMR & (1U << 3);
  102. EXTI->PR = pr;
  103. exti_serve_irq(pr, 3);
  104. OSAL_IRQ_EPILOGUE();
  105. }
  106. #endif
  107. #if !defined(STM32_DISABLE_EXTI4_HANDLER)
  108. /**
  109. * @brief EXTI[4] interrupt handler.
  110. *
  111. * @isr
  112. */
  113. OSAL_IRQ_HANDLER(Vector68) {
  114. uint32_t pr;
  115. OSAL_IRQ_PROLOGUE();
  116. pr = EXTI->PR;
  117. pr &= EXTI->IMR & (1U << 4);
  118. EXTI->PR = pr;
  119. exti_serve_irq(pr, 4);
  120. OSAL_IRQ_EPILOGUE();
  121. }
  122. #endif
  123. #if !defined(STM32_DISABLE_EXTI5_9_HANDLER)
  124. /**
  125. * @brief EXTI[5]...EXTI[9] interrupt handler.
  126. *
  127. * @isr
  128. */
  129. OSAL_IRQ_HANDLER(Vector9C) {
  130. uint32_t pr;
  131. OSAL_IRQ_PROLOGUE();
  132. pr = EXTI->PR;
  133. pr &= EXTI->IMR & ((1U << 5) | (1U << 6) | (1U << 7) | (1U << 8) |
  134. (1U << 9));
  135. EXTI->PR = pr;
  136. exti_serve_irq(pr, 5);
  137. exti_serve_irq(pr, 6);
  138. exti_serve_irq(pr, 7);
  139. exti_serve_irq(pr, 8);
  140. exti_serve_irq(pr, 9);
  141. OSAL_IRQ_EPILOGUE();
  142. }
  143. #endif
  144. #if !defined(STM32_DISABLE_EXTI10_15_HANDLER)
  145. /**
  146. * @brief EXTI[10]...EXTI[15] interrupt handler.
  147. *
  148. * @isr
  149. */
  150. OSAL_IRQ_HANDLER(VectorE0) {
  151. uint32_t pr;
  152. OSAL_IRQ_PROLOGUE();
  153. pr = EXTI->PR;
  154. pr &= EXTI->IMR & ((1U << 10) | (1U << 11) | (1U << 12) | (1U << 13) |
  155. (1U << 14) | (1U << 15));
  156. EXTI->PR = pr;
  157. exti_serve_irq(pr, 10);
  158. exti_serve_irq(pr, 11);
  159. exti_serve_irq(pr, 12);
  160. exti_serve_irq(pr, 13);
  161. exti_serve_irq(pr, 14);
  162. exti_serve_irq(pr, 15);
  163. OSAL_IRQ_EPILOGUE();
  164. }
  165. #endif
  166. #endif /* HAL_USE_PAL && (PAL_USE_WAIT || PAL_USE_CALLBACKS) */
  167. #if HAL_USE_GPT || HAL_USE_ICU || HAL_USE_PWM || defined(__DOXYGEN__)
  168. /**
  169. * @brief TIM1-BRK, TIM15 interrupt handler.
  170. *
  171. * @isr
  172. */
  173. OSAL_IRQ_HANDLER(VectorA0) {
  174. OSAL_IRQ_PROLOGUE();
  175. #if HAL_USE_GPT
  176. #if STM32_GPT_USE_TIM15
  177. gpt_lld_serve_interrupt(&GPTD15);
  178. #endif
  179. #endif
  180. #if HAL_USE_ICU
  181. #if STM32_ICU_USE_TIM15
  182. icu_lld_serve_interrupt(&ICUD15);
  183. #endif
  184. #endif
  185. #if HAL_USE_PWM
  186. #if STM32_PWM_USE_TIM15
  187. pwm_lld_serve_interrupt(&PWMD15);
  188. #endif
  189. #endif
  190. OSAL_IRQ_EPILOGUE();
  191. }
  192. /**
  193. * @brief TIM1-UP, TIM16 interrupt handler.
  194. *
  195. * @isr
  196. */
  197. OSAL_IRQ_HANDLER(VectorA4) {
  198. OSAL_IRQ_PROLOGUE();
  199. #if HAL_USE_GPT
  200. #if STM32_GPT_USE_TIM1
  201. gpt_lld_serve_interrupt(&GPTD1);
  202. #endif
  203. #if STM32_GPT_USE_TIM16
  204. gpt_lld_serve_interrupt(&GPTD16);
  205. #endif
  206. #endif
  207. #if HAL_USE_ICU
  208. #if STM32_ICU_USE_TIM1
  209. icu_lld_serve_interrupt(&ICUD1);
  210. #endif
  211. #endif
  212. #if HAL_USE_PWM
  213. #if STM32_PWM_USE_TIM1
  214. pwm_lld_serve_interrupt(&PWMD1);
  215. #endif
  216. #if STM32_PWM_USE_TIM16
  217. pwm_lld_serve_interrupt(&PWMD16);
  218. #endif
  219. #endif
  220. OSAL_IRQ_EPILOGUE();
  221. }
  222. /**
  223. * @brief TIM1-TRG-COM, TIM17 interrupt handler.
  224. *
  225. * @isr
  226. */
  227. OSAL_IRQ_HANDLER(VectorA8) {
  228. OSAL_IRQ_PROLOGUE();
  229. #if HAL_USE_GPT
  230. #if STM32_GPT_USE_TIM17
  231. gpt_lld_serve_interrupt(&GPTD17);
  232. #endif
  233. #endif
  234. #if HAL_USE_ICU
  235. /* Not used by ICU.*/
  236. #endif
  237. #if HAL_USE_PWM
  238. #if STM32_PWM_USE_TIM17
  239. pwm_lld_serve_interrupt(&PWMD17);
  240. #endif
  241. #endif
  242. OSAL_IRQ_EPILOGUE();
  243. }
  244. /**
  245. * @brief TIM1-CC interrupt handler.
  246. *
  247. * @isr
  248. */
  249. OSAL_IRQ_HANDLER(VectorAC) {
  250. OSAL_IRQ_PROLOGUE();
  251. #if HAL_USE_GPT
  252. /* Not used by GPT.*/
  253. #endif
  254. #if HAL_USE_ICU
  255. #if STM32_ICU_USE_TIM1
  256. icu_lld_serve_interrupt(&ICUD1);
  257. #endif
  258. #endif
  259. #if HAL_USE_PWM
  260. #if STM32_PWM_USE_TIM1
  261. pwm_lld_serve_interrupt(&PWMD1);
  262. #endif
  263. #endif
  264. OSAL_IRQ_EPILOGUE();
  265. }
  266. #endif /* HAL_USE_GPT || HAL_USE_ICU || HAL_USE_PWM */
  267. /*===========================================================================*/
  268. /* Driver exported functions. */
  269. /*===========================================================================*/
  270. /**
  271. * @brief Enables IRQ sources.
  272. *
  273. * @notapi
  274. */
  275. void irqInit(void) {
  276. #if HAL_USE_PAL
  277. nvicEnableVector(EXTI0_IRQn, STM32_IRQ_EXTI0_PRIORITY);
  278. nvicEnableVector(EXTI1_IRQn, STM32_IRQ_EXTI1_PRIORITY);
  279. nvicEnableVector(EXTI2_TSC_IRQn, STM32_IRQ_EXTI2_PRIORITY);
  280. nvicEnableVector(EXTI3_IRQn, STM32_IRQ_EXTI3_PRIORITY);
  281. nvicEnableVector(EXTI4_IRQn, STM32_IRQ_EXTI4_PRIORITY);
  282. nvicEnableVector(EXTI9_5_IRQn, STM32_IRQ_EXTI5_9_PRIORITY);
  283. nvicEnableVector(EXTI15_10_IRQn, STM32_IRQ_EXTI10_15_PRIORITY);
  284. #endif
  285. #if HAL_USE_GPT || HAL_USE_ICU || HAL_USE_PWM || defined(__DOXYGEN__)
  286. nvicEnableVector(TIM1_BRK_TIM15_IRQn, STM32_IRQ_TIM1_BRK_TIM15_PRIORITY);
  287. nvicEnableVector(TIM1_UP_TIM16_IRQn, STM32_IRQ_TIM1_UP_TIM16_PRIORITY);
  288. nvicEnableVector(TIM1_TRG_COM_TIM17_IRQn, STM32_IRQ_TIM1_TRGCO_TIM17_PRIORITY);
  289. nvicEnableVector(TIM1_CC_IRQn, STM32_IRQ_TIM1_CC_PRIORITY);
  290. #endif
  291. }
  292. /**
  293. * @brief Disables IRQ sources.
  294. *
  295. * @notapi
  296. */
  297. void irqDeinit(void) {
  298. #if HAL_USE_PAL
  299. nvicDisableVector(EXTI0_IRQn);
  300. nvicDisableVector(EXTI1_IRQn);
  301. nvicDisableVector(EXTI2_TSC_IRQn);
  302. nvicDisableVector(EXTI3_IRQn);
  303. nvicDisableVector(EXTI4_IRQn);
  304. nvicDisableVector(EXTI9_5_IRQn);
  305. nvicDisableVector(EXTI15_10_IRQn);
  306. #endif
  307. #if HAL_USE_GPT || HAL_USE_ICU || HAL_USE_PWM || defined(__DOXYGEN__)
  308. nvicDisableVector(TIM1_BRK_TIM15_IRQn);
  309. nvicDisableVector(TIM1_UP_TIM16_IRQn);
  310. nvicDisableVector(TIM1_TRG_COM_TIM17_IRQn);
  311. nvicDisableVector(TIM1_CC_IRQn);
  312. #endif
  313. }
  314. /** @} */