bsp_timer.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "Platform.h"
  2. #include "bsp_register_macro.h"
  3. /* ---------------------------------------------------------------------------------------------------
  4. - 函数名称: xc_timer_init
  5. - 函数功能: 定时器初始化
  6. - 函数形参:定时器号,定时多少us
  7. - 创建日期: 2019-04-22
  8. - 创 建 人:陈俊伟
  9. ----------------------------------------------------------------------------------------------------*/
  10. void xc_timer_init(uint8_t timer_num,uint32_t us)
  11. {
  12. __write_hw_reg32(CPR_CTLAPBCLKEN_GRCTL,0x80008); //TIMER_PCLK 时钟使能
  13. __write_hw_reg32(CPR_TIMER_CLK_CTL(timer_num),0x0F);//TIMERx_CLK 时钟控制寄存器 mclk_in(32MHz)/2*(0x0F + 0x1)
  14. __write_hw_reg32(TIMERx_TCR(timer_num),0x0);//不屏蔽定时器中断,不使能定时器timer_num,
  15. __write_hw_reg32(TIMERx_TCR(timer_num),0x2);//设置定时器工作在用户定义计数模式
  16. __write_hw_reg32(TIMERx_TLC(timer_num),us);//载入计数器计数初值(32bits),该值应大于等于 0x4
  17. __write_hw_reg32(TIMERx_TCR(timer_num),0x3);//使能定时器timer_num
  18. NVIC_EnableIRQ((IRQn_Type)(TIMER0_IRQn+timer_num));
  19. }
  20. /* ---------------------------------------------------------------------------------------------------
  21. - 函数名称: TIMER3_Handler
  22. - 函数功能: 定时器3服务函数
  23. - 函数形参:无
  24. - 创建日期: 2019-04-22
  25. - 创 建 人:陈俊伟
  26. ----------------------------------------------------------------------------------------------------*/
  27. void TIMER3_Handler(void)
  28. {
  29. uint32_t val=0;
  30. __read_hw_reg32(TIMER3_TIC , val);
  31. //需要处理的定时器任务
  32. printf("TIMER3_Handler\n");
  33. }