board_coretimer.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * File : board_coretimer.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2017-01-01 Urey first version
  23. */
  24. #include <rthw.h>
  25. #include <rtthread.h>
  26. #include "board.h"
  27. #include "board_coretimer.h"
  28. #include <stdint.h>
  29. static inline unsigned int readreg32(volatile unsigned int *addr)
  30. {
  31. return *(volatile unsigned int *)addr;
  32. }
  33. static inline void writereg32(unsigned int b, volatile unsigned int *addr)
  34. {
  35. *(volatile unsigned int *)addr = b;
  36. }
  37. void CKTimerInit(uint32_t timer_id, uint32_t freq)
  38. {
  39. uint32_t reg;
  40. writereg32(APB_DEFAULT_FREQ / freq, CORET_RVR);
  41. writereg32(0, CORET_CVR);
  42. reg = readreg32(CORET_CSR);
  43. reg |= CORETIM_TXCONTROL_ENABLE;
  44. reg |= CORETIM_TXCONTROL_INTMASK;
  45. writereg32(reg, CORET_CSR);
  46. return;
  47. }
  48. void CKTimerClear(uint32_t timer_id)
  49. {
  50. uint32_t reg;
  51. reg = readreg32(CORET_CSR);
  52. reg |= ~CORETIM_TXCONTROL_MODE;
  53. writereg32(reg, CORET_CSR);
  54. }
  55. uint32_t CKTimer_CurrentValue(void)
  56. {
  57. return readreg32(CORET_CVR);
  58. }
  59. void __attribute__((isr)) SysTick_Handler(void)
  60. {
  61. CKTimerClear(0x1);
  62. /* enter interrupt */
  63. rt_interrupt_enter();
  64. rt_tick_increase();
  65. /* leave interrupt */
  66. rt_interrupt_leave();
  67. }