irqs.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #include "gd32f3x0.h"
  2. #include "nv_storage.h"
  3. #include "shark_rtc.h"
  4. extern void system_reboot(void);
  5. /*!
  6. \brief this function handles NMI exception
  7. \param[in] none
  8. \param[out] none
  9. \retval none
  10. */
  11. void NMI_Handler(void)
  12. {
  13. }
  14. /*!
  15. \brief this function handles HardFault exception
  16. \param[in] none
  17. \param[out] none
  18. \retval none
  19. */
  20. void HardFault_Handler(void){
  21. /* if Hard Fault exception occurs, go to infinite loop */
  22. nv_save_all_soc();
  23. shark_rtc_set_backup(0x2000);
  24. while (1){
  25. system_reboot();
  26. }
  27. }
  28. /*!
  29. \brief this function handles MemManage exception
  30. \param[in] none
  31. \param[out] none
  32. \retval none
  33. */
  34. void MemManage_Handler(void)
  35. {
  36. /* if Memory Manage exception occurs, go to infinite loop */
  37. nv_save_all_soc();
  38. shark_rtc_set_backup(0x2001);
  39. while (1){
  40. system_reboot();
  41. }
  42. }
  43. /*!
  44. \brief this function handles BusFault exception
  45. \param[in] none
  46. \param[out] none
  47. \retval none
  48. */
  49. void BusFault_Handler(void)
  50. {
  51. /* if Bus Fault exception occurs, go to infinite loop */
  52. nv_save_all_soc();
  53. shark_rtc_set_backup(0x2002);
  54. while (1){
  55. system_reboot();
  56. }
  57. }
  58. /*!
  59. \brief this function handles UsageFault exception
  60. \param[in] none
  61. \param[out] none
  62. \retval none
  63. */
  64. void UsageFault_Handler(void)
  65. {
  66. /* if Usage Fault exception occurs, go to infinite loop */
  67. nv_save_all_soc();
  68. shark_rtc_set_backup(0x2003);
  69. while (1){
  70. system_reboot();
  71. }
  72. }
  73. /*!
  74. \brief this function handles DebugMon exception
  75. \param[in] none
  76. \param[out] none
  77. \retval none
  78. */
  79. void DebugMon_Handler(void)
  80. {
  81. }
  82. void __weak gpio_key_irq_handler(void) {}
  83. void EXTI0_1_IRQHandler(void){
  84. if(RESET != exti_interrupt_flag_get(EXTI_0)){
  85. exti_interrupt_flag_clear(EXTI_0);
  86. gpio_key_irq_handler();
  87. }
  88. if(RESET != exti_interrupt_flag_get(EXTI_1)){
  89. exti_interrupt_flag_clear(EXTI_1);
  90. }
  91. }
  92. void EXTI2_3_IRQHandler(void){
  93. if(RESET != exti_interrupt_flag_get(EXTI_2)){
  94. exti_interrupt_flag_clear(EXTI_2);
  95. }
  96. if(RESET != exti_interrupt_flag_get(EXTI_3)){
  97. exti_interrupt_flag_clear(EXTI_3);
  98. }
  99. }
  100. void __weak ml5238_irq_handler(void){}
  101. void __weak charger_detect_irq_handler(void){}
  102. void __weak hall1_detect_irq_handler(void){}
  103. void __weak hall2_detect_irq_handler(void){}
  104. void __weak small_current_short_irq_handler(void){}
  105. void __weak dcdc_pwr_detect_irq_handler(void) {}
  106. void EXTI4_15_IRQHandler(void){
  107. if(RESET != exti_flag_get(EXTI_4)){
  108. exti_flag_clear(EXTI_4);
  109. }
  110. if(RESET != exti_flag_get(EXTI_5)){
  111. exti_flag_clear(EXTI_5);
  112. }
  113. if(RESET != exti_flag_get(EXTI_6)){
  114. exti_flag_clear(EXTI_6);
  115. }
  116. if(RESET != exti_flag_get(EXTI_7)){
  117. exti_flag_clear(EXTI_7);
  118. dcdc_pwr_detect_irq_handler();
  119. }
  120. if(RESET != exti_flag_get(EXTI_8)){
  121. exti_flag_clear(EXTI_8);
  122. }
  123. if(RESET != exti_flag_get(EXTI_9)){
  124. exti_flag_clear(EXTI_9);
  125. }
  126. if(RESET != exti_flag_get(EXTI_10)){
  127. exti_flag_clear(EXTI_10);
  128. charger_detect_irq_handler();
  129. }
  130. if(RESET != exti_flag_get(EXTI_11)){
  131. exti_flag_clear(EXTI_11);
  132. small_current_short_irq_handler();
  133. }
  134. //ms5238 irq
  135. if(RESET != exti_flag_get(EXTI_12)){
  136. exti_flag_clear(EXTI_12);
  137. ml5238_irq_handler();
  138. }
  139. if(RESET != exti_flag_get(EXTI_13)){
  140. exti_flag_clear(EXTI_13);
  141. hall2_detect_irq_handler();
  142. }
  143. if(RESET != exti_flag_get(EXTI_14)){
  144. exti_flag_clear(EXTI_14);
  145. }
  146. if(RESET != exti_flag_get(EXTI_15)){
  147. exti_flag_clear(EXTI_15);
  148. hall1_detect_irq_handler();
  149. }
  150. }