fh_timer.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #ifndef FH_TIMER_H_
  27. #define FH_TIMER_H_
  28. /****************************************************************************
  29. * #include section
  30. * add #include here if any
  31. ***************************************************************************/
  32. #include "fh_def.h"
  33. /****************************************************************************
  34. * #define section
  35. * add constant #define here if any
  36. ***************************************************************************/
  37. #define TIMER_CTRL_ENABLE (1u << 0)
  38. #define TIMER_CTRL_MODE (1u << 1)
  39. #define TIMER_CTRL_INTMASK (1u << 2)
  40. #define TIMER_CTRL_PWMEN (1u << 3)
  41. /****************************************************************************
  42. * ADT section
  43. * add Abstract Data Type definition here
  44. ***************************************************************************/
  45. typedef struct {
  46. RwReg TIMER_LOAD_COUNT;
  47. RwReg TIMER_CURRENT_VALUE;
  48. RwReg TIMER_CTRL_REG;
  49. RwReg TIMER_EOI;
  50. RwReg TIMER_INT_STATUS;
  51. }timer;
  52. enum timer_mode {
  53. TIMER_MODE_PERIODIC = 0,
  54. TIMER_MODE_ONESHOT = 1,
  55. };
  56. /****************************************************************************
  57. * extern variable declaration section
  58. ***************************************************************************/
  59. /****************************************************************************
  60. * section
  61. * add function prototype here if any
  62. ***************************************************************************/
  63. int timer_init(timer *tim);
  64. int timer_set_mode(timer *tim, enum timer_mode);
  65. void timer_set_period(timer *tim, UINT32 period, UINT32 clock);
  66. void timer_enable(timer *tim);
  67. void timer_disable(timer *tim);
  68. void timer_enable_irq(timer *tim);
  69. void timer_disable_irq(timer *tim);
  70. UINT32 timer_get_status(timer *tim);
  71. void udelay(unsigned long usec);
  72. #endif /* #ifndef _TIMER_ */