fh_timer.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * This file is part of FH8620 BSP for RT-Thread distribution.
  3. *
  4. * Copyright (c) 2016 Shanghai Fullhan Microelectronics Co., Ltd.
  5. * All rights reserved
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. *
  21. * Visit http://www.fullhan.com to get contact with Fullhan.
  22. *
  23. * Change Logs:
  24. * Date Author Notes
  25. */
  26. /*****************************************************************************
  27. * Include Section
  28. * add all #include here
  29. *****************************************************************************/
  30. #include "inc/fh_driverlib.h"
  31. /*****************************************************************************
  32. * Define section
  33. * add all #define here
  34. *****************************************************************************/
  35. /****************************************************************************
  36. * ADT section
  37. * add definition of user defined Data Type that only be used in this file here
  38. ***************************************************************************/
  39. /******************************************************************************
  40. * Function prototype section
  41. * add prototypes for all functions called by this file,execepting those
  42. * declared in header file
  43. *****************************************************************************/
  44. /*****************************************************************************
  45. * Global variables section - Exported
  46. * add declaration of global variables that will be exported here
  47. * e.g.
  48. * int8_t foo;
  49. ****************************************************************************/
  50. /*****************************************************************************
  51. * Global variables section - Local
  52. * define global variables(will be refered only in this file) here,
  53. * static keyword should be used to limit scope of local variable to this file
  54. * e.g.
  55. * static uint8_t ufoo;
  56. *****************************************************************************/
  57. /* function body */
  58. /*****************************************************************************
  59. * Description:
  60. * add funtion description here
  61. * Parameters:
  62. * description for each argument, new argument starts at new line
  63. * Return:
  64. * what does this function returned?
  65. *****************************************************************************/
  66. int timer_init(timer *tim)
  67. {
  68. tim->TIMER_CTRL_REG = 0;
  69. }
  70. int timer_set_mode(timer *tim, enum timer_mode mode)
  71. {
  72. switch (mode)
  73. {
  74. case TIMER_MODE_PERIODIC:
  75. tim->TIMER_CTRL_REG |= TIMER_CTRL_MODE;
  76. break;
  77. case TIMER_MODE_ONESHOT:
  78. tim->TIMER_CTRL_REG |= TIMER_CTRL_MODE;
  79. break;
  80. default:
  81. rt_kprintf("Not support TIMER mode\n");
  82. return -1;
  83. break;
  84. }
  85. return 0;
  86. }
  87. void timer_set_period(timer *tim, UINT32 period, UINT32 clock)
  88. {
  89. tim->TIMER_LOAD_COUNT = clock/period;
  90. }
  91. void timer_enable(timer *tim)
  92. {
  93. tim->TIMER_CTRL_REG |= TIMER_CTRL_ENABLE;
  94. }
  95. void timer_disable(timer *tim)
  96. {
  97. tim->TIMER_CTRL_REG &= ~TIMER_CTRL_ENABLE;
  98. }
  99. void timer_enable_irq(timer *tim)
  100. {
  101. tim->TIMER_CTRL_REG &= ~TIMER_CTRL_INTMASK;
  102. }
  103. void timer_disable_irq(timer *tim)
  104. {
  105. tim->TIMER_CTRL_REG |= TIMER_CTRL_INTMASK;
  106. }
  107. UINT32 timer_get_status(timer *tim)
  108. {
  109. return tim->TIMER_INT_STATUS;
  110. }
  111. UINT32 timer_get_eoi(timer *tim)
  112. {
  113. return tim->TIMER_EOI;
  114. }
  115. UINT32 timer_get_value(timer *tim)
  116. {
  117. return tim->TIMER_LOAD_COUNT - tim->TIMER_CURRENT_VALUE;
  118. }