timer.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. #include "W25Q64.h"
  41. /*************<macro>******************/
  42. /*************<enum>*******************/
  43. /*************<union>******************/
  44. /*************<struct>*****************/
  45. /*************<variable>***************/
  46. extern uint32_t g_timer0Cnt;
  47. /*************<prototype>**************/
  48. void Timer_Callback(void *device, uint32_t wpara, uint32_t lpara);
  49. extern void Process_Timer0_CB(void);
  50. extern void Process_Timer1_CB(void);
  51. extern void Rs485_Timer1_CB(void);
  52. /**
  53. * @prototype Timer0_Init(void)
  54. *
  55. * @param[in] void
  56. * @return void
  57. *
  58. * @brief 初始化定时器通道0 , 用于ADC 规则组采集功能.
  59. */
  60. void Timer0_Init(void)
  61. {
  62. TIMER_ConfigType tmrConfig;
  63. /*清零变量.*/
  64. memset(&tmrConfig, 0x00, sizeof(tmrConfig));
  65. /*配置定时器.*/
  66. tmrConfig.linkModeEn = DISABLE;
  67. tmrConfig.interruptEn = ENABLE;
  68. tmrConfig.periodValue = TIM_PRD_5ms;
  69. tmrConfig.timerEn = ENABLE;
  70. tmrConfig.callBack = Timer_Callback;
  71. TIMER_Init(TIMER_CHANNEL0, &tmrConfig);
  72. NVIC_SetPriority(TIMER_CHANNEL0_IRQn, 1);
  73. NVIC_ClearPendingIRQ(TIMER_CHANNEL0_IRQn);
  74. NVIC_EnableIRQ(TIMER_CHANNEL0_IRQn);
  75. }
  76. /**
  77. * @prototype Timer1_Init(void)
  78. *
  79. * @param[in] void
  80. * @return void
  81. *
  82. * @brief 初始化定时器通道1, 用于记数.
  83. */
  84. void Timer1_Init(void)
  85. {
  86. TIMER_ConfigType tmrConfig;
  87. /*清零变量.*/
  88. memset(&tmrConfig, 0x00, sizeof(tmrConfig));
  89. /*配置定时器.*/
  90. tmrConfig.linkModeEn = DISABLE;
  91. tmrConfig.interruptEn = ENABLE;
  92. tmrConfig.periodValue = TIM_PRD_1ms;
  93. tmrConfig.timerEn = ENABLE;
  94. tmrConfig.callBack = Timer_Callback;
  95. TIMER_Init(TIMER_CHANNEL1, &tmrConfig);
  96. NVIC_SetPriority(TIMER_CHANNEL1_IRQn, 1);
  97. NVIC_ClearPendingIRQ(TIMER_CHANNEL1_IRQn);
  98. NVIC_EnableIRQ(TIMER_CHANNEL1_IRQn);
  99. }
  100. /**
  101. * @prototype TIM_CHN2_Callback(void *device, uint32_t wpara, uint32_t lpara)
  102. *
  103. * @param[in] ...
  104. * @return void
  105. *
  106. * @brief 定时器通道2中断回调函数.
  107. */
  108. void Timer_Callback(void *device, uint32_t wpara, uint32_t lpara)
  109. {
  110. if (TIMER_CHANNEL0 == device){
  111. g_timer0Cnt++;
  112. Process_Timer0_CB();
  113. }else if(TIMER_CHANNEL1 == device){
  114. Process_Timer1_CB();
  115. Rs485_Timer1_CB();
  116. /*
  117. if (g_blinkLedTime < 0xFFFF)
  118. {
  119. g_blinkLedTime++;
  120. }
  121. if(rs485_info.dmasend_count < 0xFF){
  122. rs485_info.dmasend_count++;
  123. }
  124. if(g_detectTime < 0xFF){
  125. g_detectTime++;
  126. }
  127. if (g_flashWrRdRdy)
  128. {
  129. g_flashWrRdTime++;
  130. }
  131. if(g_runReady){
  132. g_runTime++;
  133. }
  134. if(g_period1000ms < 0xFFFF)
  135. {
  136. g_period1000ms++;
  137. }
  138. */
  139. }
  140. }
  141. /*************<end>********************/