drv_timer.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (c) 2021, Shenzhen Academy of Aerospace Technology
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-11-16 Dystopia the first version
  9. */
  10. #include "drv_timer.h"
  11. #include "KeyStone_common.h"
  12. #include <rthw.h>
  13. #include <rtthread.h>
  14. /**
  15. * This is the timer interrupt service routine.
  16. *
  17. */
  18. void rt_hw_systick_isr(void)
  19. {
  20. /* enter interrupt */
  21. rt_interrupt_enter();
  22. rt_tick_increase();
  23. /* leave interrupt */
  24. rt_interrupt_leave();
  25. }
  26. /**
  27. * The function initial system timer interrupt.
  28. */
  29. void rt_hw_system_timer_init(void)
  30. {
  31. // initial system timer interrupt, map local timer interrupt to INT14
  32. gpCGEM_regs->INTMUX3 = (CSL_GEM_TINTLN<<CSL_CGEM_INTMUX3_INTSEL14_SHIFT);
  33. // enable CPU INT14
  34. CPU_interrupt_enable(1<<14);
  35. return ;
  36. }
  37. /**
  38. * The function initial system timer.
  39. * Use local timer (==DNUM of a core) to generate a clock on TIMO0,interrupts are generated as well
  40. *
  41. */
  42. void rt_hw_system_timer_start(void)
  43. {
  44. Timer64_Config tmrCfg;
  45. // select output on TIMO0 from local timer.
  46. gpBootCfgRegs->TOUTSEL = (DNUM*2)<<CSL_BOOTCFG_TOUTSEL_TOUTSEL0_SHIFT;
  47. // configure the timer to generate clocks and interrupts
  48. tmrCfg.timer_num = DNUM;
  49. tmrCfg.timerMode = TIMER_PERIODIC_CLOCK;
  50. tmrCfg.period = (unsigned long long) RT_TICK_PER_SECOND*gDSP_Core_Speed_Hz/6000;
  51. tmrCfg.reload_period = 0;
  52. // initial timer
  53. Timer64_Init(&tmrCfg);
  54. }