drv_ost.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * File : board_timer.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2008 - 2016, 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. * 2015-11-19 Urey the first version
  23. */
  24. #include <rthw.h>
  25. #include <rtthread.h>
  26. #include <rtdevice.h>
  27. #include <stdint.h>
  28. #include "board.h"
  29. #include "drv_clock.h"
  30. #include "drv_ost.h"
  31. /**
  32. * This is the OST timer interrupt service routine.
  33. */
  34. void rt_hw_ost_handler(void)
  35. {
  36. /* increase a OS tick */
  37. rt_tick_increase();
  38. /* clear flag */
  39. REG_OSTFR = 0;
  40. }
  41. int rt_hw_ost_init(void)
  42. {
  43. rt_uint32_t cnt, div;
  44. struct clk *clk;
  45. div = OST_DIV16;
  46. cnt = BOARD_EXTAL_CLK / 16;
  47. /* enable OST clock */
  48. clk = clk_get("sys_ost");
  49. clk_enable(clk);
  50. /* Disable OST (channel 1/2) */
  51. REG_OSTECR = 0x3;
  52. /* clear counter */
  53. REG_OSTCR = 0x01;
  54. REG_OST1CNT = 0;
  55. /* set timer data (channel 1) */
  56. REG_OST1DFR = (cnt / RT_TICK_PER_SECOND - 1);
  57. /* set prescale ext clk */
  58. REG_OSTCCR = div;
  59. /* unmask interrupt */
  60. REG_OSTMR = 0;
  61. /* enable OST (channel 1) */
  62. REG_OSTESR = 0x01;
  63. clk_put(clk);
  64. return 0;
  65. }
  66. #include <finsh.h>
  67. int ost(int argc, char** argv)
  68. {
  69. rt_kprintf("OSTCCR = 0x%08x\n", REG_OSTCCR);
  70. rt_kprintf("OSTER = 0x%08x\n", REG_OSTER);
  71. rt_kprintf("count = 0x%08x\n", REG_OST1CNT);
  72. rt_kprintf("TCU_TER = 0x%08x\n", REG_TCU_TER);
  73. return 0;
  74. }
  75. MSH_CMD_EXPORT(ost, ost debug);