drv_ost.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2015-11-19 Urey the first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include <rtdevice.h>
  13. #include <stdint.h>
  14. #include "board.h"
  15. #include "drv_clock.h"
  16. #include "drv_ost.h"
  17. /**
  18. * This is the OST timer interrupt service routine.
  19. */
  20. void rt_hw_ost_handler(void)
  21. {
  22. /* increase a OS tick */
  23. rt_tick_increase();
  24. /* clear flag */
  25. REG_OSTFR = 0;
  26. }
  27. int rt_hw_ost_init(void)
  28. {
  29. rt_uint32_t cnt, div;
  30. struct clk *clk;
  31. div = OST_DIV16;
  32. cnt = BOARD_EXTAL_CLK / 16;
  33. /* enable OST clock */
  34. clk = clk_get("sys_ost");
  35. clk_enable(clk);
  36. /* Disable OST (channel 1/2) */
  37. REG_OSTECR = 0x3;
  38. /* clear counter */
  39. REG_OSTCR = 0x01;
  40. REG_OST1CNT = 0;
  41. /* set timer data (channel 1) */
  42. REG_OST1DFR = (cnt / RT_TICK_PER_SECOND - 1);
  43. /* set prescale ext clk */
  44. REG_OSTCCR = div;
  45. /* unmask interrupt */
  46. REG_OSTMR = 0;
  47. /* enable OST (channel 1) */
  48. REG_OSTESR = 0x01;
  49. clk_put(clk);
  50. return 0;
  51. }
  52. #include <finsh.h>
  53. int ost(int argc, char** argv)
  54. {
  55. rt_kprintf("OSTCCR = 0x%08x\n", REG_OSTCCR);
  56. rt_kprintf("OSTER = 0x%08x\n", REG_OSTER);
  57. rt_kprintf("count = 0x%08x\n", REG_OST1CNT);
  58. rt_kprintf("TCU_TER = 0x%08x\n", REG_TCU_TER);
  59. return 0;
  60. }
  61. MSH_CMD_EXPORT(ost, ost debug);