gd32f10x_it.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*!
  2. \file gd32f10x_it.c
  3. \brief interrupt service routines
  4. \version 2014-12-26, V1.0.0, firmware for GD32F10x
  5. \version 2017-06-20, V2.0.0, firmware for GD32F10x
  6. \version 2018-07-31, V2.1.0, firmware for GD32F10x
  7. \version 2020-09-30, V2.2.0, firmware for GD32F10x
  8. */
  9. /*
  10. Copyright (c) 2020, GigaDevice Semiconductor Inc.
  11. Redistribution and use in source and binary forms, with or without modification,
  12. are permitted provided that the following conditions are met:
  13. 1. Redistributions of source code must retain the above copyright notice, this
  14. list of conditions and the following disclaimer.
  15. 2. Redistributions in binary form must reproduce the above copyright notice,
  16. this list of conditions and the following disclaimer in the documentation
  17. and/or other materials provided with the distribution.
  18. 3. Neither the name of the copyright holder nor the names of its contributors
  19. may be used to endorse or promote products derived from this software without
  20. specific prior written permission.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  23. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  24. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  25. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  30. OF SUCH DAMAGE.
  31. */
  32. #include "gd32f10x_it.h"
  33. #include "main.h"
  34. #include "usart.h"
  35. #include "mmodbus.h"
  36. #include "log.h"
  37. #include "mqttRecv.h"
  38. #include "systick.h"
  39. #include "dlt645_port.h"
  40. #include "parseDeviceMessage.h"
  41. /*!
  42. \brief this function handles NMI exception
  43. \param[in] none
  44. \param[out] none
  45. \retval none
  46. */
  47. void NMI_Handler(void)
  48. {
  49. }
  50. /*!
  51. \brief this function handles HardFault exception
  52. \param[in] none
  53. \param[out] none
  54. \retval none
  55. */
  56. void HardFault_Handler(void)
  57. {
  58. /* if Hard Fault exception occurs, go to infinite loop */
  59. while (1)
  60. {
  61. }
  62. }
  63. /*!
  64. \brief this function handles MemManage exception
  65. \param[in] none
  66. \param[out] none
  67. \retval none
  68. */
  69. void MemManage_Handler(void)
  70. {
  71. /* if Memory Manage exception occurs, go to infinite loop */
  72. while (1)
  73. {
  74. }
  75. }
  76. /*!
  77. \brief this function handles BusFault exception
  78. \param[in] none
  79. \param[out] none
  80. \retval none
  81. */
  82. void BusFault_Handler(void)
  83. {
  84. /* if Bus Fault exception occurs, go to infinite loop */
  85. while (1)
  86. {
  87. }
  88. }
  89. /*!
  90. \brief this function handles UsageFault exception
  91. \param[in] none
  92. \param[out] none
  93. \retval none
  94. */
  95. void UsageFault_Handler(void)
  96. {
  97. /* if Usage Fault exception occurs, go to infinite loop */
  98. while (1)
  99. {
  100. }
  101. }
  102. /*!
  103. \brief this function handles SVC exception
  104. \param[in] none
  105. \param[out] none
  106. \retval none
  107. */
  108. void SVC_Handler(void)
  109. {
  110. }
  111. /*!
  112. \brief this function handles DebugMon exception
  113. \param[in] none
  114. \param[out] none
  115. \retval none
  116. */
  117. void DebugMon_Handler(void)
  118. {
  119. }
  120. /*!
  121. \brief this function handles PendSV exception
  122. \param[in] none
  123. \param[out] none
  124. \retval none
  125. */
  126. void PendSV_Handler(void)
  127. {
  128. }
  129. /*!
  130. \brief this function handles SysTick exception
  131. \param[in] none
  132. \param[out] none
  133. \retval none
  134. */
  135. void SysTick_Handler(void)
  136. {
  137. delay_decrement();
  138. runtime_increment();
  139. }
  140. // 4G模块
  141. void USART0_IRQHandler(void)
  142. {
  143. if (RESET != usart_interrupt_flag_get(USART0, USART_INT_FLAG_IDLE)) // 空闲中断
  144. {
  145. usart_interrupt_flag_clear(USART0, USART_INT_FLAG_IDLE); /* 清除空闲中断标志位 */
  146. usart_data_receive(USART0); /* 清除接收完成标志位 */
  147. dma_channel_disable(DMA0, DMA_CH4); /* 关闭DMA传输 */
  148. // UART0_RX_NUM = sizeof(UART0_RX_BUF) - dma_transfer_number_get(DMA0, DMA_CH4);
  149. // UART0_RX_BUF[UART0_RX_NUM] = '\0'; /* 添加字符串结束符 */
  150. UART0_RX_STAT = 0x01; /* 接受状态 0x01:已接收到数据 */
  151. // dma_memory_address_config(DMA0, DMA_CH4, (uint32_t)UART0_RX_BUF);
  152. // dma_transfer_number_config(DMA0, DMA_CH4, sizeof(UART0_RX_BUF));
  153. dma_channel_enable(DMA0, DMA_CH4);
  154. Receive_MQTT_DataPack(); // 判别是否为mqtt触发的中断
  155. }
  156. }
  157. // 485
  158. void USART1_IRQHandler(void)
  159. {
  160. // 接收到的数据解析数据
  161. if(protocol==2){ //modbus为2
  162. mmodbus_callback();
  163. }
  164. else if(protocol==1){ //645为1
  165. dlt_callback();
  166. }
  167. }
  168. // log
  169. //void USART2_IRQHandler(void)
  170. //{
  171. // mbus232_callback();
  172. //
  173. //}
  174. void DMA0_Channel4_IRQHandler(void)
  175. {
  176. dma_interrupt_flag_clear(DMA0, DMA_CH4, DMA_INT_FLAG_G);
  177. }
  178. //extern uint32_t timedisplay;
  179. //void RTC_IRQHandler(void)
  180. //{
  181. // if (rtc_flag_get(RTC_FLAG_SECOND) != RESET){
  182. // /* clear the RTC second interrupt flag*/
  183. // rtc_flag_clear(RTC_FLAG_SECOND);
  184. // /* enable time update */
  185. // timedisplay = 1;
  186. // /* wait until last write operation on RTC registers has finished */
  187. // rtc_lwoff_wait();
  188. // /* reset RTC counter when time is 23:59:59 */
  189. // if (rtc_counter_get() == 0x00015180){
  190. // rtc_counter_set(0x0);
  191. // /* wait until last write operation on RTC registers has finished */
  192. // rtc_lwoff_wait();
  193. // }
  194. // }
  195. //}