timer.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("AutoChips Software") are
  4. * protected under relevant copyright laws. The information contained herein is
  5. * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
  6. * the prior written permission of AutoChips inc. and/or its licensors, any
  7. * reproduction, modification, use or disclosure of AutoChips Software, and
  8. * information contained herein, in whole or in part, shall be strictly
  9. * prohibited.
  10. *
  11. * AutoChips Inc. (C) 2018. All rights reserved.
  12. *
  13. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  14. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
  15. * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
  16. * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
  17. * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  19. * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
  20. * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
  21. * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
  22. * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
  23. * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
  24. * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
  25. * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
  26. * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  27. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
  28. * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
  29. * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
  30. * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
  31. * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
  32. */
  33. /*************<start>******************/
  34. /*************<include>****************/
  35. #include "string.h"
  36. //#include "gpio.h"
  37. #include "process.h"
  38. #include "uart.h"
  39. #include "timer.h"
  40. /*************<macro>******************/
  41. extern uint8_t waiting_time_ladar;
  42. /*************<enum>*******************/
  43. /*************<union>******************/
  44. /*************<struct>*****************/
  45. /*************<variable>***************/
  46. /*************<prototype>**************/
  47. void Timer_Callback(void *device, uint32_t wpara, uint32_t lpara);
  48. /**
  49. * @prototype Timer0_Init(void)
  50. *
  51. * @param[in] void
  52. * @return void
  53. *
  54. * @brief 初始化定时器通道0 , 用于ADC 规则组采集功能.
  55. */
  56. void Timer0_Init(void)
  57. {
  58. TIMER_ConfigType tmrConfig;
  59. /*清零变量.*/
  60. memset(&tmrConfig, 0x00, sizeof(tmrConfig));
  61. /*配置定时器.*/
  62. tmrConfig.linkModeEn = DISABLE;
  63. tmrConfig.interruptEn = ENABLE;
  64. tmrConfig.periodValue = TIM_PRD_10ms;
  65. tmrConfig.timerEn = ENABLE;
  66. tmrConfig.callBack = Timer_Callback;
  67. TIMER_Init(TIMER_CHANNEL0, &tmrConfig);
  68. NVIC_SetPriority(TIMER_CHANNEL0_IRQn, 1);
  69. NVIC_ClearPendingIRQ(TIMER_CHANNEL0_IRQn);
  70. NVIC_EnableIRQ(TIMER_CHANNEL0_IRQn);
  71. }
  72. /**
  73. * @prototype Timer1_Init(void)
  74. *
  75. * @param[in] void
  76. * @return void
  77. *
  78. * @brief 初始化定时器通道1.
  79. */
  80. void Timer1_Init(void)
  81. {
  82. TIMER_ConfigType tmrConfig;
  83. /*清零变量.*/
  84. memset(&tmrConfig, 0x00, sizeof(tmrConfig));
  85. /*配置定时器.*/
  86. tmrConfig.linkModeEn = DISABLE;
  87. tmrConfig.interruptEn = ENABLE;
  88. tmrConfig.periodValue = TIM_PRD_1ms;
  89. tmrConfig.timerEn = ENABLE;
  90. tmrConfig.callBack = Timer_Callback;
  91. TIMER_Init(TIMER_CHANNEL1, &tmrConfig);
  92. NVIC_SetPriority(TIMER_CHANNEL1_IRQn, 2);
  93. NVIC_ClearPendingIRQ(TIMER_CHANNEL1_IRQn);
  94. NVIC_EnableIRQ(TIMER_CHANNEL1_IRQn);
  95. }
  96. /**
  97. * @prototype TIM_CHN2_Callback(void *device, uint32_t wpara, uint32_t lpara)
  98. *
  99. * @param[in] ...
  100. * @return void
  101. *
  102. * @brief 定时器中断回调函数.
  103. */
  104. void Timer_Callback(void *device, uint32_t wpara, uint32_t lpara)
  105. {
  106. if (TIMER_CHANNEL0 == device){
  107. //g_timer0Cnt++;
  108. }else if(TIMER_CHANNEL1 == device){
  109. if(g_blinkLedTime < 0xFFFF)
  110. {
  111. g_blinkLedTime++;
  112. }
  113. if(rs485_info.dmasend_count < 0xFF){
  114. rs485_info.dmasend_count++;
  115. }
  116. if(g_mr_Interval < 0xFF){
  117. g_mr_Interval++;
  118. }
  119. if(g_print_interval < 0xFFFF){
  120. g_print_interval++;
  121. }
  122. if(waiting_time_ladar < 0xFF){
  123. waiting_time_ladar++;
  124. }
  125. /*
  126. if(g_detectTime < 0xFF){
  127. g_detectTime++;
  128. }
  129. if (g_flashWrRdRdy)
  130. {
  131. g_flashWrRdTime++;
  132. }
  133. if(g_runReady){
  134. g_runTime++;
  135. }
  136. if(g_period1000ms < 0xFFFF)
  137. {
  138. g_period1000ms++;
  139. }
  140. */
  141. }
  142. }
  143. /*************<end>********************/