gd32f30x_it.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*!
  2. \file gd32f30x_it.c
  3. \brief interrupt service routines for gd32f30x
  4. \version 2017-02-10, V1.0.0, firmware for GD32F30x
  5. \version 2018-10-10, V1.1.0, firmware for GD32F30x
  6. \version 2018-12-25, V2.0.0, firmware for GD32F30x
  7. \version 2020-09-30, V2.1.0, firmware for GD32F30x
  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 "gd32f30x_it.h"
  33. #include <stdio.h>
  34. #include "systick.h"
  35. uint16_t readvalue1 = 0, readvalue2 = 0;
  36. __IO uint16_t ccnumber = 0;
  37. __IO uint32_t count = 0;
  38. __IO uint16_t fre = 0;
  39. /*!
  40. \brief this function handles NMI exception
  41. \param[in] none
  42. \param[out] none
  43. \retval none
  44. */
  45. void NMI_Handler(void)
  46. {
  47. }
  48. /*!
  49. \brief this function handles HardFault exception
  50. \param[in] none
  51. \param[out] none
  52. \retval none
  53. */
  54. void HardFault_Handler(void)
  55. {
  56. /* if Hard Fault exception occurs, go to infinite loop */
  57. while (1){
  58. }
  59. }
  60. /*!
  61. \brief this function handles MemManage exception
  62. \param[in] none
  63. \param[out] none
  64. \retval none
  65. */
  66. void MemManage_Handler(void)
  67. {
  68. /* if Memory Manage exception occurs, go to infinite loop */
  69. while (1){
  70. }
  71. }
  72. /*!
  73. \brief this function handles BusFault exception
  74. \param[in] none
  75. \param[out] none
  76. \retval none
  77. */
  78. void BusFault_Handler(void)
  79. {
  80. /* if Bus Fault exception occurs, go to infinite loop */
  81. while (1){
  82. }
  83. }
  84. /*!
  85. \brief this function handles UsageFault exception
  86. \param[in] none
  87. \param[out] none
  88. \retval none
  89. */
  90. void UsageFault_Handler(void)
  91. {
  92. /* if Usage Fault exception occurs, go to infinite loop */
  93. while (1){
  94. }
  95. }
  96. /*!
  97. \brief this function handles SVC exception
  98. \param[in] none
  99. \param[out] none
  100. \retval none
  101. */
  102. void SVC_Handler(void)
  103. {
  104. }
  105. /*!
  106. \brief this function handles DebugMon exception
  107. \param[in] none
  108. \param[out] none
  109. \retval none
  110. */
  111. void DebugMon_Handler(void)
  112. {
  113. }
  114. /*!
  115. \brief this function handles PendSV exception
  116. \param[in] none
  117. \param[out] none
  118. \retval none
  119. */
  120. void PendSV_Handler(void)
  121. {
  122. }
  123. /*!
  124. \brief this function handles SysTick exception
  125. \param[in] none
  126. \param[out] none
  127. \retval none
  128. */
  129. void SysTick_Handler(void)
  130. {
  131. delay_decrement();
  132. }
  133. /*!
  134. \brief this function handles TIMER2 interrupt request.
  135. \param[in] none
  136. \param[out] none
  137. \retval none
  138. */
  139. void TIMER2_IRQHandler(void)
  140. {
  141. if(SET == timer_interrupt_flag_get(TIMER2,TIMER_INT_FLAG_CH0)){
  142. /* clear channel 0 interrupt bit */
  143. timer_interrupt_flag_clear(TIMER2,TIMER_INT_FLAG_CH0);
  144. if(0 == ccnumber){
  145. /* read channel 0 capture value */
  146. readvalue1 = timer_channel_capture_value_register_read(TIMER2,TIMER_CH_0)+1;
  147. ccnumber = 1;
  148. }else if(1 == ccnumber){
  149. /* read channel 0 capture value */
  150. readvalue2 = timer_channel_capture_value_register_read(TIMER2,TIMER_CH_0)+1;
  151. if(readvalue2 > readvalue1){
  152. count = (readvalue2 - readvalue1);
  153. }else{
  154. count = ((0xFFFFU - readvalue1) + readvalue2);
  155. }
  156. fre = 1000000U / count;
  157. ccnumber = 0;
  158. }
  159. }
  160. }