t_timer.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "t_define.h"
  2. #include "t_bk3231sf.h"
  3. //#include "t_uart.h"
  4. #include "t_gpio.h"
  5. #include "t_icu.h"
  6. #include "t_timer.h"
  7. //¸ÃÎļþûÓÃÉϵÄ
  8. static TIMER_INT_HANDLE_CB_PFN timerIntHandleCbPfn = NULL;
  9. void TimerGenCfg(uint8 timerid, uint8 en, uint8 inten, uint16 period)
  10. {
  11. REG_TIMER_CFG = SET_VALUE(REG_TIMER_CFG,
  12. (BM_TIMER_EN|BM_TIMER_INT_EN)<<(timerid<<1),
  13. (((uint32)en<<BO_TIMER_EN) |((uint32)inten<<BO_TIMER_INT_EN))<<(timerid<<1));
  14. *((volatile uint32 *)(REG_TIMER_BASE+0x08ul+(timerid<<3))) = ((uint32)period<<BO_TIMER_PERIOD_CNT);
  15. }
  16. void TimerPeriodCntCfg(uint8 timerid, uint16 period)
  17. {
  18. *((volatile uint32 *)(REG_TIMER_BASE+0x08ul+(timerid<<3))) = ((uint32)period<<BO_TIMER_PERIOD_CNT);
  19. }
  20. uint32 TimerGetIntSta(void)
  21. {
  22. return REG_TIMER_INT_STA;
  23. }
  24. void TimerClearIntSta(uint32 timerintsta)
  25. {
  26. REG_TIMER_INT_STA = timerintsta;
  27. }
  28. uint16 TimerGetCurrCnt(uint8 timerid)
  29. {
  30. return (uint16)((*((volatile uint32 *)(REG_TIMER_BASE+0x08ul+(timerid<<3)+0x04ul))) & BM_TIMER_CNT) >> BO_TIMER_CNT;
  31. }
  32. void TimerIntHandleCbCfg(TIMER_INT_HANDLE_CB_PFN cbpfn)
  33. {
  34. timerIntHandleCbPfn = cbpfn;
  35. }
  36. void TimerIntHandle(void)
  37. {
  38. uint32 timerintsta = REG_TIMER_INT_STA;
  39. REG_TIMER_INT_STA = timerintsta;
  40. if(timerIntHandleCbPfn != NULL)
  41. {
  42. (*timerIntHandleCbPfn)(timerintsta);
  43. }
  44. }