drv_gpt.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _DRV_GPT_H_
  13. #define _DRV_GPT_H_
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include <stddef.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /**
  21. * @brief the gpt channels
  22. */
  23. typedef enum
  24. {
  25. PWM_CHANNE_0,
  26. PWM_CHANNE_1,
  27. PWM_CHANNE_2,
  28. PWM_CHANNE_3,
  29. } drvPmwChanne;
  30. /**
  31. * @brief the gpt input counter selection
  32. */
  33. typedef enum
  34. {
  35. TI_COUNTER_0,
  36. TI_COUNTER_1,
  37. TI_COUNTER_2,
  38. TI_COUNTER_3,
  39. } drvGptTiCnt;
  40. /**
  41. * @brief the gpt pwm modes
  42. */
  43. typedef enum
  44. {
  45. GPT_FREEZE,
  46. GPT_EX_MODE,
  47. PWM_MODE_1 = 0x06,
  48. PWM_MODE_2,
  49. } drvPwmMode;
  50. /**
  51. * @brief the gpt triger edge selection
  52. */
  53. typedef enum
  54. {
  55. PWM_RINSING_EDGE,
  56. PWM_FALLING_EDGE,
  57. } drvPwmEdge;
  58. /**
  59. * @brief the gpt counting direction
  60. */
  61. typedef enum
  62. {
  63. PWM_COUNTER_UP,
  64. PWM_COUNTER_DOWN,
  65. } drvGptCntMode;
  66. /**
  67. * @brief the gpt modes
  68. */
  69. typedef enum
  70. {
  71. GPT_RESET_MODE,
  72. GPT_GATE_MODE,
  73. GPT_TRIG_MODE,
  74. GPT_OTHER_MODE
  75. } drvGptMode;
  76. typedef enum
  77. {
  78. GPT_TIME_IDLE,
  79. GPT1_TIMER0,
  80. GPT2_TIMER0,
  81. GPT2_TIMER1,
  82. GPT2_TIMER2,
  83. GPT3_TIMER0,
  84. GPT3_TIMER1,
  85. GPT3_TIMER2,
  86. GPT3_TIMER3,
  87. GPT3_TIMER4,
  88. GPT3_TIMER5,
  89. GPT3_TIMER6,
  90. } drvGptTimer_t;
  91. typedef enum
  92. {
  93. CLK_XTAL,
  94. CLK_XTAL_LP,
  95. CLK_RC26M,
  96. CLK_GNSS_PLL_133M,
  97. CLK_GNSS_PLL_198M,
  98. CLK_APLL_200M,
  99. CLK_APLL_250M,
  100. CLK_RTC_32K,
  101. } drvGptClkDomain;
  102. /**
  103. * @brief the gpt configuration information
  104. */
  105. typedef struct
  106. {
  107. bool isCenterAligned; //centrosymmetric counting
  108. bool clk_sel; //select clock source
  109. bool tri_cnt_en; //external counter enable
  110. bool opm; //one pulse mode
  111. uint8_t Fdts; //filter clock frequency division
  112. uint16_t arr; // auto reload counter
  113. uint16_t psc; //prescaler
  114. drvGptTiCnt TiCounter; //input counter selection
  115. drvGptMode gpt_mode; // gpt mode
  116. drvGptCntMode cnt_mode; // counting direction
  117. } drvGptCfg;
  118. /**
  119. * @brief the gpt irq mask
  120. */
  121. typedef struct
  122. {
  123. bool event_update;
  124. bool slave_trig;
  125. bool cap_int_ch0;
  126. bool cap_int_ch1;
  127. bool cap_int_ch2;
  128. bool cap_int_ch3;
  129. bool comp_int_ch0;
  130. bool comp_int_ch1;
  131. bool comp_int_ch2;
  132. bool comp_int_ch3;
  133. } drvGptIrq;
  134. /**
  135. * @brief the gpt irq callback function
  136. */
  137. typedef void (*gptCallback)(drvGptIrq cause);
  138. /**
  139. * @brief the gpt device indicator
  140. */
  141. typedef struct gpt_devide drvGpt_t;
  142. /**
  143. * @brief acquire the gpt device
  144. *
  145. * @param name name of the GPT
  146. * @return
  147. * - (NULL) fail
  148. * - otherwise the GPT instance
  149. */
  150. #ifndef CONFIG_SOC_8850
  151. drvGpt_t *drvGptRequest(uint32_t name);
  152. #else
  153. drvGpt_t *drvGptRequest(drvGptTimer_t timer);
  154. #endif
  155. /**
  156. * @brief config GPT
  157. *
  158. * @param d GPT instance
  159. * @param cfg configuration parameter of GPT
  160. */
  161. void drvGptConfig(drvGpt_t *d, drvGptCfg cfg);
  162. /**
  163. * @brief config GPT output
  164. *
  165. * @param d GPT instance
  166. * @param channel GPT channels
  167. * @param mode GPT pwm mode
  168. * @param duty duty cycle
  169. */
  170. void drvGptToConfig(drvGpt_t *d, drvPmwChanne channel, drvPwmMode mode, uint16_t duty);
  171. /**
  172. * @brief config GPT input
  173. *
  174. * @param d GPT instance
  175. * @param channel GPT channels
  176. * @param edge rising edge or falling edge
  177. * @param ic_div filter frequency division
  178. div Fdts
  179. 2'b00 PCLK
  180. 2'b01 PCLK/2
  181. 2'b10 PCLK/4
  182. 2'b11 PCLK
  183. * @param ic_filter filter frequency division
  184. filter freq N
  185. 4'b0000 Bypass 1
  186. 4'b0001 PCLK 2
  187. 4'b0010 PCLK 4
  188. 4'b0011 PCLK 8
  189. 4'b0100 Fdts/2 6
  190. 4'b0101 Fdts/2 8
  191. 4'b0110 Fdts/4 6
  192. 4'b0111 Fdts/4 8
  193. 4'b1000 Fdts/8 6
  194. 4'b1001 Fdts/8 8
  195. 4'b1010 Fdts/16 5
  196. 4'b1011 Fdts/16 6
  197. 4'b1100 Fdts/16 8
  198. 4'b1101 Fdts/32 5
  199. 4'b1110 Fdts/32 6
  200. 4'b1111 Fdts/32 8
  201. */
  202. void drvGptTiConfig(drvGpt_t *d, drvPmwChanne channel, drvPwmEdge edge, uint8_t ic_div, uint8_t ic_filter);
  203. /**
  204. * @brief config GPT irq
  205. *
  206. * @param d GPT instance
  207. * @param cfg GPT mask
  208. * @param callback GPT callback
  209. */
  210. void drvGptSetIrq(drvGpt_t *d, drvGptIrq cfg, gptCallback callback);
  211. /**
  212. * @brief clear GPT irq
  213. *
  214. * @param d GPT instance
  215. */
  216. void drvGptClearIrq(drvGpt_t *d);
  217. /**
  218. * @brief get GPT it counter
  219. *
  220. * @param d GPT instance
  221. * @param channel GPT channel
  222. */
  223. uint32_t drvGptGetTiCounter(drvGpt_t *d, drvPmwChanne channel);
  224. /**
  225. * @brief gpt enable
  226. *
  227. * @param d GPT instance
  228. * @param channel GPT channel
  229. */
  230. void drvGptEnable(drvGpt_t *d, drvPmwChanne channel);
  231. /**
  232. * @brief gpt disable
  233. *
  234. * @param d GPT instance
  235. * @param channel GPT channel
  236. */
  237. void drvGptDisable(drvGpt_t *d, drvPmwChanne channel);
  238. /**
  239. * @brief gpt release
  240. *
  241. * @param d GPT instance
  242. */
  243. void drvGptFree(drvGpt_t *d);
  244. void drvGptSetClkSource(uint32_t name, drvGptClkDomain domain);
  245. #ifdef __cplusplus
  246. }
  247. #endif
  248. #endif