gd32f3x0_it.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*!
  2. \file gd32f3x0_it.c
  3. \brief interrupt service routines
  4. */
  5. /*
  6. Copyright (C) 2017 GigaDevice
  7. 2017-06-06, V1.0.0, firmware for GD32F3x0
  8. */
  9. #include "gd32f3x0_it.h"
  10. #include <stdio.h>
  11. uint16_t readvalue1 = 0, readvalue2 = 0;
  12. __IO uint16_t ccnumber = 0;
  13. __IO uint32_t count = 0;
  14. __IO float fre = 0;
  15. /*!
  16. \brief this function handles NMI exception
  17. \param[in] none
  18. \param[out] none
  19. \retval none
  20. */
  21. void NMI_Handler(void)
  22. {
  23. }
  24. /*!
  25. \brief this function handles HardFault exception
  26. \param[in] none
  27. \param[out] none
  28. \retval none
  29. */
  30. void HardFault_Handler(void)
  31. {
  32. /* if Hard Fault exception occurs, go to infinite loop */
  33. while (1);
  34. }
  35. /*!
  36. \brief this function handles MemManage exception
  37. \param[in] none
  38. \param[out] none
  39. \retval none
  40. */
  41. void MemManage_Handler(void)
  42. {
  43. /* if Memory Manage exception occurs, go to infinite loop */
  44. while (1);
  45. }
  46. /*!
  47. \brief this function handles BusFault exception
  48. \param[in] none
  49. \param[out] none
  50. \retval none
  51. */
  52. void BusFault_Handler(void)
  53. {
  54. /* if Bus Fault exception occurs, go to infinite loop */
  55. while (1);
  56. }
  57. /*!
  58. \brief this function handles UsageFault exception
  59. \param[in] none
  60. \param[out] none
  61. \retval none
  62. */
  63. void UsageFault_Handler(void)
  64. {
  65. /* if Usage Fault exception occurs, go to infinite loop */
  66. while (1);
  67. }
  68. /*!
  69. \brief this function handles SVC exception
  70. \param[in] none
  71. \param[out] none
  72. \retval none
  73. */
  74. void SVC_Handler(void)
  75. {
  76. }
  77. /*!
  78. \brief this function handles DebugMon exception
  79. \param[in] none
  80. \param[out] none
  81. \retval none
  82. */
  83. void DebugMon_Handler(void)
  84. {
  85. }
  86. /*!
  87. \brief this function handles PendSV exception
  88. \param[in] none
  89. \param[out] none
  90. \retval none
  91. */
  92. void PendSV_Handler(void)
  93. {
  94. }
  95. /*!
  96. \brief this function handles SysTick exception
  97. \param[in] none
  98. \param[out] none
  99. \retval none
  100. */
  101. void SysTick_Handler(void)
  102. {
  103. }
  104. /*!
  105. \brief this function handles TIMER2 interrupt request
  106. \param[in] none
  107. \param[out] none
  108. \retval none
  109. */
  110. void TIMER2_IRQHandler(void)
  111. {
  112. if(SET == timer_interrupt_flag_get(TIMER2,TIMER_INT_FLAG_CH0)){
  113. /* clear channel 0 interrupt bit */
  114. timer_interrupt_flag_clear(TIMER2,TIMER_INT_FLAG_CH0);
  115. if(0 == ccnumber){
  116. /* read channel 0 capture value */
  117. readvalue1 = timer_channel_capture_value_register_read(TIMER2,TIMER_CH_0);
  118. ccnumber = 1;
  119. }else if(1 == ccnumber){
  120. /* read channel 0 capture value */
  121. readvalue2 = timer_channel_capture_value_register_read(TIMER2,TIMER_CH_0);
  122. if(readvalue2 > readvalue1){
  123. count = (readvalue2 - readvalue1);
  124. }else{
  125. count = ((0xFFFF - readvalue1) + readvalue2);
  126. }
  127. fre = (float)2000 / count;
  128. printf("the value1 is %d,the value2 is %d\n",readvalue1,readvalue2);
  129. printf("the count is %d\n",count);
  130. printf("the frequence is %f\n",fre);
  131. ccnumber = 0;
  132. }
  133. }
  134. }