drv_timer.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 "interrupt.h"
  12. #include "common.h"
  13. #include <rthw.h>
  14. #include <rtthread.h>
  15. /**
  16. * This is the timer interrupt service routine.
  17. *
  18. */
  19. void rt_hw_systick_isr(void)
  20. {
  21. /* enter interrupt */
  22. rt_interrupt_enter();
  23. rt_tick_increase();
  24. /* leave interrupt */
  25. rt_interrupt_leave();
  26. }
  27. /**
  28. * The function initial system timer interrupt.
  29. */
  30. void rt_hw_system_timer_init(void)
  31. {
  32. // initial system timer interrupt, map local timer interrupt to INT14
  33. gp_cgem_regs->INTMUX3 = (CSL_GEM_TINTLN << CSL_CGEM_INTMUX3_INTSEL14_SHIFT);
  34. // enable CPU INT14
  35. rt_hw_interrupt_umask(1 << 14);
  36. return ;
  37. }
  38. /**
  39. * The function initial system timer.
  40. * Use local timer (== DNUM of a core) to generate a clock on TIMO0,interrupts are generated as well
  41. *
  42. */
  43. void rt_hw_system_timer_start(void)
  44. {
  45. Timer64_Config tmrCfg;
  46. // select output on TIMO0 from local timer.
  47. gp_bootcfg_regs->TOUTSEL = (DNUM*2) << CSL_BOOTCFG_TOUTSEL_TOUTSEL0_SHIFT;
  48. // configure the timer to generate clocks and interrupts
  49. tmrCfg.timer_num = DNUM;
  50. tmrCfg.timerMode = TIMER_PERIODIC_CLOCK;
  51. tmrCfg.period = (unsigned long long) RT_TICK_PER_SECOND * DSP_CORE_SPEED_HZ / 6000;
  52. tmrCfg.reload_period = 0;
  53. // initial timer
  54. timer64_init(&tmrCfg);
  55. }