gd32f10x_it.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. /*!
  41. \brief this function handles NMI exception
  42. \param[in] none
  43. \param[out] none
  44. \retval none
  45. */
  46. void NMI_Handler(void)
  47. {
  48. }
  49. /*!
  50. \brief this function handles HardFault exception
  51. \param[in] none
  52. \param[out] none
  53. \retval none
  54. */
  55. void HardFault_Handler(void)
  56. {
  57. /* if Hard Fault exception occurs, go to infinite loop */
  58. while (1)
  59. {
  60. }
  61. }
  62. /*!
  63. \brief this function handles MemManage exception
  64. \param[in] none
  65. \param[out] none
  66. \retval none
  67. */
  68. void MemManage_Handler(void)
  69. {
  70. /* if Memory Manage exception occurs, go to infinite loop */
  71. while (1)
  72. {
  73. }
  74. }
  75. /*!
  76. \brief this function handles BusFault exception
  77. \param[in] none
  78. \param[out] none
  79. \retval none
  80. */
  81. void BusFault_Handler(void)
  82. {
  83. /* if Bus Fault exception occurs, go to infinite loop */
  84. while (1)
  85. {
  86. }
  87. }
  88. /*!
  89. \brief this function handles UsageFault exception
  90. \param[in] none
  91. \param[out] none
  92. \retval none
  93. */
  94. void UsageFault_Handler(void)
  95. {
  96. /* if Usage Fault exception occurs, go to infinite loop */
  97. while (1)
  98. {
  99. }
  100. }
  101. /*!
  102. \brief this function handles SVC exception
  103. \param[in] none
  104. \param[out] none
  105. \retval none
  106. */
  107. void SVC_Handler(void)
  108. {
  109. }
  110. /*!
  111. \brief this function handles DebugMon exception
  112. \param[in] none
  113. \param[out] none
  114. \retval none
  115. */
  116. void DebugMon_Handler(void)
  117. {
  118. }
  119. /*!
  120. \brief this function handles PendSV exception
  121. \param[in] none
  122. \param[out] none
  123. \retval none
  124. */
  125. void PendSV_Handler(void)
  126. {
  127. }
  128. /*!
  129. \brief this function handles SysTick exception
  130. \param[in] none
  131. \param[out] none
  132. \retval none
  133. */
  134. void SysTick_Handler(void)
  135. {
  136. delay_decrement();
  137. runtime_increment();
  138. }
  139. // 4G模块
  140. void USART0_IRQHandler(void)
  141. {
  142. if (RESET != usart_interrupt_flag_get(USART0, USART_INT_FLAG_IDLE)) // 空闲中断
  143. {
  144. usart_interrupt_flag_clear(USART0, USART_INT_FLAG_IDLE); /* 清除空闲中断标志位 */
  145. usart_data_receive(USART0); /* 清除接收完成标志位 */
  146. dma_channel_disable(DMA0, DMA_CH4); /* 关闭DMA传输 */
  147. UART0_RX_NUM = sizeof(UART0_RX_BUF) - dma_transfer_number_get(DMA0, DMA_CH4);
  148. UART0_RX_BUF[UART0_RX_NUM] = '\0'; /* 添加字符串结束符 */
  149. UART0_RX_STAT = 0x01; /* 接受状态 0x01:已接收到数据 */
  150. dma_memory_address_config(DMA0, DMA_CH4, (uint32_t)UART0_RX_BUF);
  151. dma_transfer_number_config(DMA0, DMA_CH4, sizeof(UART0_RX_BUF));
  152. dma_channel_enable(DMA0, DMA_CH4);
  153. Receive_MQTT_DataPack(); // 判别是否为mqtt触发的中断
  154. }
  155. }
  156. // 485
  157. void USART1_IRQHandler(void)
  158. {
  159. // 接收到的数据解析数据
  160. if(protocol==2){ //modbus为2
  161. mmodbus_callback();
  162. }
  163. else if(protocol==1){ //645为1
  164. dlt_callback();
  165. }
  166. }
  167. // log
  168. //void USART2_IRQHandler(void)
  169. //{
  170. // mbus232_callback();
  171. //
  172. //}
  173. void DMA0_Channel4_IRQHandler(void)
  174. {
  175. dma_interrupt_flag_clear(DMA0, DMA_CH4, DMA_INT_FLAG_G);
  176. }
  177. //extern uint32_t timedisplay;
  178. //void RTC_IRQHandler(void)
  179. //{
  180. // if (rtc_flag_get(RTC_FLAG_SECOND) != RESET){
  181. // /* clear the RTC second interrupt flag*/
  182. // rtc_flag_clear(RTC_FLAG_SECOND);
  183. // /* enable time update */
  184. // timedisplay = 1;
  185. // /* wait until last write operation on RTC registers has finished */
  186. // rtc_lwoff_wait();
  187. // /* reset RTC counter when time is 23:59:59 */
  188. // if (rtc_counter_get() == 0x00015180){
  189. // rtc_counter_set(0x0);
  190. // /* wait until last write operation on RTC registers has finished */
  191. // rtc_lwoff_wait();
  192. // }
  193. // }
  194. //}