gd32f3x0_it.c 3.1 KB

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