1
0

hpm_pwmv2_drv.h 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958
  1. /*
  2. * Copyright (c) 2023 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_PWMV2_DRV_H
  8. #define HPM_PWMV2_DRV_H
  9. #include "hpm_common.h"
  10. #include "hpm_pwmv2_regs.h"
  11. #include "hpm_soc_feature.h"
  12. /**
  13. * @brief PWM driver APIs
  14. * @defgroup pwmv2_interface PWMV2 driver APIs
  15. * @ingroup motor_interfaces
  16. * @{
  17. *
  18. */
  19. #define PWM_UNLOCK_KEY (0xB0382607UL)
  20. #define PWM_CMP_UNABLE_OUTPUT_INDEX (16)
  21. /* IRQ enable bit mask */
  22. #define PWM_IRQ_FAULT PWM_IRQEN_FAULTIRQE_MASK
  23. #define PWM_IRQ_EX_RELOAD PWM_IRQEN_XRLDIRQE_MASK
  24. #define PWM_IRQ_HALF_RELOAD PWM_IRQEN_HALFRLDIRQE_MASK
  25. #define PWM_IRQ_RELOAD PWM_IRQEN_RLDIRQE_MASK
  26. #define PWM_IRQ_CMP(x) PWM_IRQEN_CMPIRQEX_SET((1 << x))
  27. /* PWM force output mask */
  28. #define PWM_FORCE_OUTPUT(pwm_index, force_output) \
  29. (force_output << (pwm_index << 1))
  30. #define PWM_DUTY_CYCLE_FP_MAX ((1U << 24) - 1)
  31. #ifndef PWMV2_SOC_CAL_COUNT_MAX
  32. #define PWMV2_SOC_CAL_COUNT_MAX 8
  33. #endif
  34. #define PWMV2_SHADOW_INDEX(x) PWMV2_SHADOW_VAL_##x
  35. #define PWMV2_CMP_INDEX(x) PWMV2_CMP_VAL_WORK_##x
  36. #define PWMV2_CALCULATE_INDEX(x) PWMV2_CAL_##x
  37. #define PWMV2_CAL_SHADOW_OFFSET_ZERO (31)
  38. typedef enum {
  39. pwm_counter_0 = 0,
  40. pwm_counter_1 = 1,
  41. pwm_counter_2 = 2,
  42. pwm_counter_3 = 3,
  43. } pwm_counter_t;
  44. typedef enum {
  45. pwm_channel_0 = 0,
  46. pwm_channel_1 = 1,
  47. pwm_channel_2 = 2,
  48. pwm_channel_3 = 3,
  49. pwm_channel_4 = 4,
  50. pwm_channel_5 = 5,
  51. pwm_channel_6 = 6,
  52. pwm_channel_7 = 7,
  53. } pwm_channel_t;
  54. typedef enum {
  55. pwm_reload_update_on_shlk = 0,
  56. pwm_reload_update_on_compare_point = 1,
  57. pwm_reload_update_on_reload = 2,
  58. pwm_reload_update_on_trigger = 3,
  59. } pwm_reload_update_time_t;
  60. /**
  61. * @brief pwm output type
  62. *
  63. */
  64. typedef enum {
  65. pwm_force_output_0 = 0, /**< output 0 */
  66. pwm_force_output_1 = 1, /**< output 1 */
  67. pwm_force_output_high_z = 2, /**< output */
  68. pwm_force_output_no_force = 3,
  69. } pwm_force_mode_t;
  70. typedef enum {
  71. pwm_fault_output_0 = 0, /**< output 0 */
  72. pwm_fault_output_1 = 1, /**< output 1 */
  73. pwm_fault_output_high_z = 2, /**< output */
  74. } pwm_fault_mode_t;
  75. typedef enum {
  76. pad_fault_active_low = 1,
  77. pad_fault_active_high = 0,
  78. } pwm_fault_pad_polarity_t;
  79. typedef enum {
  80. pwm_shadow_register_output_polarity_on_shlk = 0,
  81. pwm_shadow_register_output_polarity_on_reload = 1,
  82. } pwm_shadow_register_output_polarity_t;
  83. typedef enum {
  84. pwm_force_update_shadow_immediately = 0, /**< after software set shlk bit of shlk register */
  85. pwm_force_update_shadow_at_cmp_point = 1,
  86. pwm_force_update_shadow_at_reload = 2, /**< immediately after the register being modified */
  87. pwm_force_update_shadow_none = 3, /**< after SHSYNCI assert */
  88. } pwm_force_shadow_trigger_t;
  89. typedef enum {
  90. pwm_force_immediately = 0, /**< after software set shlk bit of shlk register */
  91. pwm_force_at_reload = 1,
  92. pwm_force_at_trigmux = 2,
  93. pwm_force_none = 3, /**< after SHSYNCI assert */
  94. } pwm_force_trigger_t;
  95. typedef enum {
  96. pwm_logic_four_cmp_or = 0,
  97. pwm_logic_four_cmp_and = 1,
  98. pwm_logic_four_cmp_xor = 2,
  99. pwm_logic_four_cmp_cd = 3,
  100. } pwm_logic_four_cmp_cfg_t;
  101. /**
  102. * @brief select when to recover PWM output after fault
  103. *
  104. */
  105. typedef enum {
  106. pwm_fault_recovery_immediately = 0, /**< immediately*/
  107. pwm_fault_recovery_on_reload = 1, /**< after pwm timer counter reload time*/
  108. pwm_fault_recovery_on_hw_event = 2, /**< after hardware event assert*/
  109. pwm_fault_recovery_on_fault_clear = 3, /**< after software write faultclr bit in GCR register*/
  110. } pwm_fault_recovery_trigger_t;
  111. typedef enum {
  112. pwm_dac_channel_0 = 0,
  113. pwm_dac_channel_1 = 1,
  114. pwm_dac_channel_2 = 2,
  115. pwm_dac_channel_3 = 3,
  116. } pwm_dac_channel_t;
  117. typedef enum {
  118. pwm_capture_from_trigmux = 0,
  119. pwm_capture_from_gpio = 1
  120. } pwm_capture_input_select_t;
  121. typedef enum {
  122. pwm_dma_0 = 0,
  123. pwm_dma_1 = 1,
  124. pwm_dma_2 = 2,
  125. pwm_dma_3 = 3,
  126. } pwm_dma_chn_t;
  127. typedef enum {
  128. pwm_shadow_register_update_on_shlk = 0, /**< after software set shlk bit of shlk register*/
  129. pwm_shadow_register_update_on_modify = 1, /**< immediately after the register being modified*/
  130. pwm_shadow_register_update_on_reload = 2,
  131. pwm_shadow_register_update_on_trigmux = 3,
  132. pwm_shadow_register_update_on_rld_cmp_select0 = 4,
  133. pwm_shadow_register_update_on_rld_cmp_select1 = 5,
  134. pwm_shadow_register_update_on_none = 6
  135. } pwm_cmp_shadow_register_update_trigger_t;
  136. typedef enum {
  137. cmp_value_from_shadow_val = 0,
  138. cmp_value_from_calculate = 0x20,
  139. cmp_value_from_capture_posedge = 0x30,
  140. cmp_value_from_counters = 0x38,
  141. cmp_value_fffff000 = 0x3e,
  142. cmp_value_ffffff00 = 0x3f
  143. } pwm_cmp_source_t;
  144. /**
  145. * @brief pwm compare config
  146. *
  147. */
  148. typedef struct pwmv2_cmp_config {
  149. uint32_t cmp; /**< compare value */
  150. bool enable_half_cmp; /**< enable half compare value */
  151. bool enable_hrcmp; /**< enable high precision pwm */
  152. pwm_cmp_source_t cmp_source; /**< @ref pwm_cmp_source_t */
  153. pwm_counter_t cmp_use_counter; /**< select one from 4 counters, only for CMP_N>=16 */
  154. uint8_t cmp_source_index; /**< soure index */
  155. uint8_t mode; /**< compare work mode: pwm_cmp_mode_output_compare or pwm_cmp_mode_input_capture */
  156. pwm_cmp_shadow_register_update_trigger_t update_trigger; /**< compare configuration update trigger, need update trigger use pwm_shadow_register_update_on_trigmux */
  157. uint8_t update_trigger_index; /**< select one trigger from 8, should set to pulse in trig_mux */
  158. uint8_t hrcmp; /**< high precision pwm */
  159. } pwmv2_cmp_config_t;
  160. /**
  161. * @brief pwm fault source config
  162. *
  163. */
  164. typedef struct pwmv2_async_fault_source_config {
  165. uint8_t async_signal_from_pad_index; /**< select from 16bit async fault from pad*/
  166. pwm_fault_pad_polarity_t fault_async_pad_level; /**< fault polarity for input fault from pad, 1-active low; 0-active high */
  167. } pwmv2_async_fault_source_config_t;
  168. /**
  169. * @brief pwm config data
  170. *
  171. */
  172. typedef struct pwmv2_config {
  173. bool enable_output; /**< enable pwm output */
  174. bool enable_async_fault; /**< enable the input async faults from pad directly */
  175. bool enable_sync_fault; /**< enable the input faults from trig_mux */
  176. bool invert_output; /**< invert pwm output level */
  177. bool enable_four_cmp; /**< Enable the four cmp functions */
  178. pwmv2_async_fault_source_config_t async_fault_source;
  179. pwm_shadow_register_output_polarity_t update_polarity_time;
  180. pwm_logic_four_cmp_cfg_t logic; /**< valid only for pwm0/2/4/6 when trig_sel4 is set */
  181. uint8_t update_trigger; /**< pwm config update trigger */
  182. uint8_t fault_mode; /**< fault mode */
  183. pwm_fault_recovery_trigger_t fault_recovery_trigger; /**< fault recoverty trigger */
  184. uint8_t fault_recovery_trigmux_index; /**< select one trigger from 8, should set to pulse in trig_mux */
  185. uint8_t force_shadow_trigmux_index; /**< select one trigger from 8, should set to pulse in trig_mux */
  186. pwm_force_shadow_trigger_t force_shadow_trigger; /**< will load shadow register(force)mode) to force_mode_work at this time */
  187. uint8_t force_trigmux_index; /**< select one trigger from 8 as force signal */
  188. pwm_force_trigger_t force_trigger; /**< @ref pwm_force_trigger_t */
  189. uint32_t dead_zone_in_half_cycle; /**< dead zone in half cycle*/
  190. } pwmv2_config_t;
  191. /**
  192. * @brief pair pwm config
  193. *
  194. */
  195. typedef struct pwmv2_pair_config {
  196. pwmv2_config_t pwm[2]; /**< pwm config data */
  197. } pwmv2_pair_config_t;
  198. typedef struct pwmv2_cmp_calculate_cfg {
  199. uint8_t counter_index; /**< select one of 4 counter reload time */
  200. uint8_t in_index; /**< 0~3 to select one of the dac input value; 4~7 to select one of the current counter value */
  201. uint8_t in_offset_index; /**< from one of the shadow_val */
  202. int8_t t_param; /**< period parameter */
  203. int8_t d_param; /**< dac/counter value parameter */
  204. int8_t up_limit_param;
  205. uint8_t up_limit_offset_index; /**< from one of the shadow_val */
  206. int8_t low_limit_param;
  207. uint8_t low_limit_offset_index; /**< from one of the shadow_val */
  208. bool enable_up_limit;
  209. bool enbale_low_limit;
  210. } pwmv2_cmp_calculate_cfg_t;
  211. #ifdef __cplusplus
  212. extern "C" {
  213. #endif
  214. /**
  215. * @brief pwm deinitialize function
  216. *
  217. * @param[in] pwm_x PWM base address, HPM_PWMx(x=0..n)
  218. *
  219. */
  220. void pwmv2_deinit(PWMV2_Type *pwm_x);
  221. /**
  222. * @brief issue all shawdow register
  223. *
  224. * @param[in] pwm_x PWM base address, HPM_PWMx(x=0..n)
  225. */
  226. static inline void pwmv2_issue_shadow_register_lock_event(PWMV2_Type *pwm_x)
  227. {
  228. pwm_x->WORK_CTRL1 |= PWMV2_WORK_CTRL1_SHADOW_LOCK_MASK;
  229. }
  230. /**
  231. * @brief lock all shawdow register
  232. *
  233. * @param[in] pwm_x PWM base address, HPM_PWMx(x=0..n)
  234. */
  235. static inline void pwmv2_shadow_register_lock(PWMV2_Type *pwm_x)
  236. {
  237. pwm_x->WORK_CTRL1 |= PWMV2_WORK_CTRL1_SHADOW_LOCK_MASK;
  238. }
  239. /**
  240. * @brief select one trigger from 8, set to use input signal(selected by cnt_reload_trig) to reload timer
  241. *
  242. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  243. * @param counter @ref pwm_counter_t
  244. * @param trig_index one trigger from 8
  245. */
  246. static inline void pwmv2_set_counter_reload_trigmux_index(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t trig_index)
  247. {
  248. pwm_x->CNT[counter].CFG2 = (pwm_x->CNT[counter].CFG2 & ~PWMV2_CNT_CFG2_CNT_RELOAD_TRIG_MASK) | PWMV2_CNT_CFG2_CNT_RELOAD_TRIG_SET(trig_index);
  249. }
  250. /**
  251. * @brief Multiple counters are enabled at the same time
  252. *
  253. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  254. * @param mask bit0 - cnt0, bit1 - cnt1, bitn - cntn, n==3
  255. */
  256. static inline void pwmv2_enable_multi_counter_sync(PWMV2_Type *pwm_x, uint8_t mask)
  257. {
  258. pwm_x->CNT_GLBCFG &= ~(PWMV2_CNT_GLBCFG_TIMER_ENABLE_SET(mask));
  259. fencerw();
  260. pwm_x->CNT_GLBCFG |= PWMV2_CNT_GLBCFG_TIMER_ENABLE_SET(mask);
  261. }
  262. /**
  263. * @brief Multiple pwm out at the same time
  264. *
  265. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  266. * @param mask bit0 - cnt0, bit1 - cnt1, bitn - cntn, n==3
  267. */
  268. static inline void pwmv2_start_pwm_output_sync(PWMV2_Type *pwm_x, uint8_t mask)
  269. {
  270. pwm_x->CNT_GLBCFG |= PWMV2_CNT_GLBCFG_CNT_SW_START_SET(mask);
  271. }
  272. /**
  273. * @brief unlock all shadow register
  274. *
  275. * @param[in] pwm_x PWM base address, HPM_PWMx(x=0..n)
  276. */
  277. static inline void pwmv2_shadow_register_unlock(PWMV2_Type *pwm_x)
  278. {
  279. pwm_x->WORK_CTRL0 = PWM_UNLOCK_KEY;
  280. }
  281. /**
  282. * @brief The shadow registers can be updated only when related unlock_bit is set.
  283. *
  284. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  285. * @param mask bit2 to bit 29 for value_shadow, bit30 for force_mode, bit31 for polarity.
  286. */
  287. static inline void pwmv2_shadow_unlock_bit_mask(PWMV2_Type *pwm_x, uint32_t mask)
  288. {
  289. pwm_x->UNLOCK = mask;
  290. }
  291. /**
  292. * @brief Set the value of the shadow register
  293. *
  294. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  295. * @param index shadow index
  296. * @param value normal value (24bit)
  297. * @param high_resolution_tick High precision pwm values (0 -255)
  298. * @param enable_half_cycle half-cycle pwm
  299. */
  300. static inline void pwmv2_set_shadow_val(PWMV2_Type *pwm_x, uint8_t index, uint32_t value, uint8_t high_resolution_tick, bool enable_half_cycle)
  301. {
  302. pwm_x->SHADOW_VAL[index] = PWMV2_SHADOW_VAL_VALUE_SET(((value << 8) | (enable_half_cycle << 7) | (high_resolution_tick)));
  303. }
  304. /**
  305. * @brief force pwm output
  306. *
  307. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  308. * @param chn @ref pwm_channel_t
  309. * @param mode @ref pwm_force_mode_t
  310. * @param invert 0 - low level, 1 - high level
  311. */
  312. static inline void pwmv2_force_output(PWMV2_Type *pwm_x, pwm_channel_t chn, pwm_force_mode_t mode, bool invert)
  313. {
  314. pwm_x->FORCE_MODE = (pwm_x->FORCE_MODE & ~(PWMV2_FORCE_MODE_POLARITY_SET((1 << (chn << 1))) | PWMV2_FORCE_MODE_FORCE_MODE_SET((3 << (chn << 1))))) |
  315. PWMV2_FORCE_MODE_POLARITY_SET((invert << (chn << 1))) |
  316. PWMV2_FORCE_MODE_FORCE_MODE_SET((mode << (chn << 1)));
  317. }
  318. /**
  319. * @brief enable four pwm outputs
  320. *
  321. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  322. * @param chn @ref pwm_channel_t
  323. */
  324. static inline void pwmv2_enable_four_cmp(PWMV2_Type *pwm_x, pwm_channel_t chn)
  325. {
  326. pwm_x->PWM[chn].CFG0 |= PWMV2_PWM_CFG0_TRIG_SEL4_MASK;
  327. }
  328. /**
  329. * @brief disable four pwm outputs
  330. *
  331. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  332. * @param chn @ref pwm_channel_t
  333. */
  334. static inline void pwmv2_disable_four_cmp(PWMV2_Type *pwm_x, pwm_channel_t chn)
  335. {
  336. pwm_x->PWM[chn].CFG0 &= ~PWMV2_PWM_CFG0_TRIG_SEL4_MASK;
  337. }
  338. /**
  339. * @brief Direct selection of the fail signal from the pin
  340. *
  341. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  342. * @param chn @ref pwm_channel_t
  343. * @param pad_index motor pad
  344. */
  345. static inline void pwmv2_fault_signal_select_from_pad(PWMV2_Type *pwm_x, pwm_channel_t chn, uint8_t pad_index)
  346. {
  347. pwm_x->PWM[chn].CFG0 = (pwm_x->PWM[chn].CFG0 & ~PWMV2_PWM_CFG0_FAULT_SEL_ASYNC_MASK) | PWMV2_PWM_CFG0_FAULT_SEL_ASYNC_SET(pad_index);
  348. }
  349. /**
  350. * @brief Configure the polarity of the fail signal
  351. *
  352. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  353. * @param chn @ref pwm_channel_t
  354. * @param polarity @ref pwm_fault_pad_polarity_t
  355. */
  356. static inline void pwmv2_fault_signal_polarity(PWMV2_Type *pwm_x, pwm_channel_t chn, pwm_fault_pad_polarity_t polarity)
  357. {
  358. pwm_x->PWM[chn].CFG0 = (pwm_x->PWM[chn].CFG0 & ~PWMV2_PWM_CFG0_FAULT_POL_ASYNC_MASK) | PWMV2_PWM_CFG0_FAULT_POL_ASYNC_SET(polarity);
  359. }
  360. /**
  361. * @brief Enable the fault signal from the pin
  362. *
  363. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  364. * @param chn @ref pwm_channel_t
  365. */
  366. static inline void pwmv2_enable_fault_from_pad(PWMV2_Type *pwm_x, pwm_channel_t chn)
  367. {
  368. pwm_x->PWM[chn].CFG0 |= PWMV2_PWM_CFG0_FAULT_EN_ASYNC_MASK;
  369. }
  370. /**
  371. * @brief Disable the fault signal from the pin
  372. *
  373. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  374. * @param chn @ref pwm_channel_t
  375. */
  376. static inline void pwmv2_disable_fault_from_pad(PWMV2_Type *pwm_x, pwm_channel_t chn)
  377. {
  378. pwm_x->PWM[chn].CFG0 &= ~PWMV2_PWM_CFG0_FAULT_EN_ASYNC_MASK;
  379. }
  380. /**
  381. * @brief Enable the fault signal from the trigmux
  382. *
  383. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  384. * @param chn @ref pwm_channel_t
  385. */
  386. static inline void pwmv2_enable_fault_from_trigmux(PWMV2_Type *pwm_x, pwm_channel_t chn)
  387. {
  388. pwm_x->PWM[chn].CFG0 |= PWMV2_PWM_CFG0_FAULT_EN_SYNC_MASK;
  389. }
  390. /**
  391. * @brief Disable the fault signal from the trigmux
  392. *
  393. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  394. * @param chn @ref pwm_channel_t
  395. */
  396. static inline void pwmv2_disable_fault_from_trigmux(PWMV2_Type *pwm_x, pwm_channel_t chn)
  397. {
  398. pwm_x->PWM[chn].CFG0 &= ~PWMV2_PWM_CFG0_FAULT_EN_SYNC_MASK;
  399. }
  400. /**
  401. * @brief Enable pwm output invert
  402. *
  403. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  404. * @param chn @ref pwm_channel_t
  405. */
  406. static inline void pwmv2_enable_output_invert(PWMV2_Type *pwm_x, pwm_channel_t chn)
  407. {
  408. pwm_x->PWM[chn].CFG0 |= PWMV2_PWM_CFG0_OUT_POLARITY_MASK;
  409. }
  410. /**
  411. * @brief Disable pwm output invert
  412. *
  413. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  414. * @param chn @ref pwm_channel_t
  415. */
  416. static inline void pwmv2_disable_output_invert(PWMV2_Type *pwm_x, pwm_channel_t chn)
  417. {
  418. pwm_x->PWM[chn].CFG0 &= ~PWMV2_PWM_CFG0_OUT_POLARITY_MASK;
  419. }
  420. /**
  421. * @brief Enable invert operations via shadow registers
  422. *
  423. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  424. * @param chn @ref pwm_channel_t
  425. * @param update_select @ref pwm_shadow_register_output_polarity_t
  426. */
  427. static inline void pwmv2_enable_invert_by_shadow(PWMV2_Type *pwm_x, pwm_channel_t chn, pwm_shadow_register_output_polarity_t update_select)
  428. {
  429. pwm_x->PWM[chn].CFG0 |= PWMV2_PWM_CFG0_POLARITY_OPT0_MASK;
  430. pwm_x->PWM[chn].CFG0 = (pwm_x->PWM[chn].CFG0 & ~PWMV2_PWM_CFG0_POL_UPDATE_SEL_MASK) | PWMV2_PWM_CFG0_POL_UPDATE_SEL_SET(update_select);
  431. }
  432. /**
  433. * @brief Disable invert operations via shadow registers
  434. *
  435. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  436. * @param chn @ref pwm_channel_t
  437. * @param update_select @ref pwm_shadow_register_output_polarity_t
  438. */
  439. static inline void pwmv2_disable_invert_by_shadow(PWMV2_Type *pwm_x, pwm_channel_t chn)
  440. {
  441. pwm_x->PWM[chn].CFG0 &= ~PWMV2_PWM_CFG0_POLARITY_OPT0_MASK;
  442. }
  443. /**
  444. * @brief Enable pwm output
  445. *
  446. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  447. * @param chn @ref pwm_channel_t
  448. */
  449. static inline void pwmv2_channel_enable_output(PWMV2_Type *pwm_x, pwm_channel_t chn)
  450. {
  451. pwm_x->PWM[chn].CFG1 |= PWMV2_PWM_CFG1_HIGHZ_EN_N_MASK;
  452. }
  453. /**
  454. * @brief Disable pwm output
  455. *
  456. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  457. * @param chn @ref pwm_channel_t
  458. */
  459. static inline void pwmv2_channel_disable_output(PWMV2_Type *pwm_x, pwm_channel_t chn)
  460. {
  461. pwm_x->PWM[chn].CFG1 &= ~PWMV2_PWM_CFG1_HIGHZ_EN_N_MASK;
  462. }
  463. /**
  464. * @brief Forces the output configuration to be updated from the time shadow hosting takes effect
  465. *
  466. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  467. * @param chn @ref pwm_channel_t
  468. * @param update_time @ref pwm_force_shadow_trigger_t
  469. */
  470. static inline void pwmv2_force_update_time_by_shadow(PWMV2_Type *pwm_x, pwm_channel_t chn, pwm_force_shadow_trigger_t update_time)
  471. {
  472. pwm_x->PWM[chn].CFG1 = (pwm_x->PWM[chn].CFG1 & ~PWMV2_PWM_CFG1_FORCE_UPDATE_TIME_MASK) | PWMV2_PWM_CFG1_FORCE_UPDATE_TIME_SET(update_time);
  473. }
  474. /**
  475. * @brief set the fault mode
  476. *
  477. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  478. * @param chn @ref pwm_channel_t
  479. * @param mode @ref pwm_fault_mode_t
  480. */
  481. static inline void pwmv2_set_fault_mode(PWMV2_Type *pwm_x, pwm_channel_t chn, pwm_fault_mode_t mode)
  482. {
  483. pwm_x->PWM[chn].CFG1 = (pwm_x->PWM[chn].CFG1 & ~PWMV2_PWM_CFG1_FAULT_MODE_MASK) | PWMV2_PWM_CFG1_FAULT_MODE_SET(mode);
  484. }
  485. /**
  486. * @brief Set the fault mode recovery time
  487. *
  488. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  489. * @param chn @ref pwm_channel_t
  490. * @param trig @ref pwm_fault_recovery_trigger_t
  491. */
  492. static inline void pwmv2_set_fault_recovery_time(PWMV2_Type *pwm_x, pwm_channel_t chn, pwm_fault_recovery_trigger_t trig)
  493. {
  494. pwm_x->PWM[chn].CFG1 = (pwm_x->PWM[chn].CFG1 & ~PWMV2_PWM_CFG1_FAULT_REC_TIME_MASK) | PWMV2_PWM_CFG1_FAULT_REC_TIME_SET(trig);
  495. }
  496. /**
  497. * @brief Trigger forced mode by hardware signal
  498. *
  499. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  500. * @param chn @ref pwm_channel_t
  501. */
  502. static inline void pwmv2_enable_force_by_hardware(PWMV2_Type *pwm_x, pwm_channel_t chn)
  503. {
  504. pwm_x->PWM[chn].CFG1 &= ~PWMV2_PWM_CFG1_SW_FORCE_EN_MASK;
  505. }
  506. /**
  507. * @brief Enable force mode triggered by software
  508. *
  509. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  510. * @param chn @ref pwm_channel_t
  511. */
  512. static inline void pwmv2_enable_force_by_software(PWMV2_Type *pwm_x, pwm_channel_t chn)
  513. {
  514. pwm_x->PWM[chn].CFG1 |= PWMV2_PWM_CFG1_SW_FORCE_EN_MASK;
  515. }
  516. /**
  517. * @brief Disable force mode triggered by software
  518. *
  519. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  520. * @param chn @ref pwm_channel_t
  521. */
  522. static inline void pwmv2_disable_force_by_software(PWMV2_Type *pwm_x, pwm_channel_t chn)
  523. {
  524. pwm_x->PWM[chn].CFG1 &= ~PWMV2_PWM_CFG1_SW_FORCE_EN_MASK;
  525. }
  526. /**
  527. * @brief Enable pwm complementary mode
  528. *
  529. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  530. * @param chn @ref pwm_channel_t
  531. */
  532. static inline void pwmv2_enable_pair_mode(PWMV2_Type *pwm_x, pwm_channel_t chn)
  533. {
  534. pwm_x->PWM[chn].CFG1 |= PWMV2_PWM_CFG1_PAIR_MODE_MASK;
  535. }
  536. /**
  537. * @brief Disable pwm complementary mode
  538. *
  539. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  540. * @param chn @ref pwm_channel_t
  541. */
  542. static inline void pwmv2_disable_pair_mode(PWMV2_Type *pwm_x, pwm_channel_t chn)
  543. {
  544. pwm_x->PWM[chn].CFG1 &= ~PWMV2_PWM_CFG1_PAIR_MODE_MASK;
  545. }
  546. /**
  547. * @brief Configure the logic between the 4 cmp, valid only if the 4 cmp output is enabled
  548. *
  549. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  550. * @param chn @ref pwm_channel_t
  551. * @param logic @ref pwm_logic_four_cmp_cfg_t
  552. */
  553. static inline void pwmv2_set_four_cmp_logic(PWMV2_Type *pwm_x, pwm_channel_t chn, pwm_logic_four_cmp_cfg_t logic)
  554. {
  555. pwm_x->PWM[chn].CFG1 = (pwm_x->PWM[chn].CFG1 & ~PWMV2_PWM_CFG1_PWM_LOGIC_MASK) | PWMV2_PWM_CFG1_PWM_LOGIC_SET(logic);
  556. }
  557. /**
  558. * @brief Setting the effective time of forced output
  559. *
  560. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  561. * @param chn @ref pwm_channel_t
  562. * @param time @ref pwm_force_trigger_t
  563. */
  564. static inline void pwmv2_set_force_update_time(PWMV2_Type *pwm_x, pwm_channel_t chn, pwm_force_trigger_t time)
  565. {
  566. pwm_x->PWM[chn].CFG1 = (pwm_x->PWM[chn].CFG1 & ~PWMV2_PWM_CFG1_FORCE_TIME_MASK) | PWMV2_PWM_CFG1_FORCE_TIME_SET(time);
  567. }
  568. /**
  569. * @brief Selecting trigmux's signal as a forced mode trigger source
  570. *
  571. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  572. * @param chn @ref pwm_channel_t
  573. * @param trigmux_index trigmux index
  574. */
  575. static inline void pwmv2_trig_force_mode_select_trigmux_index(PWMV2_Type *pwm_x, pwm_channel_t chn, uint8_t trigmux_index)
  576. {
  577. pwm_x->PWM[chn].CFG1 = (pwm_x->PWM[chn].CFG1 & ~PWMV2_PWM_CFG1_FORCE_TRIG_SEL_MASK) | PWMV2_PWM_CFG1_FORCE_TRIG_SEL_SET(trigmux_index);
  578. }
  579. /**
  580. * @brief Selection of trigger signals for software or hardware trigmux
  581. *
  582. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  583. * @param chn @ref pwm_channel_t
  584. * @param trigmux_index select one trigger from 8
  585. */
  586. static inline void pwmv2_trig_force_hardware_or_software_select_trigmux_index(PWMV2_Type *pwm_x, pwm_channel_t chn, uint8_t trigmux_index)
  587. {
  588. pwm_x->PWM[chn].CFG1 = (pwm_x->PWM[chn].CFG1 & ~PWMV2_PWM_CFG1_FORCE_ACT_SEL_MASK) | PWMV2_PWM_CFG1_FORCE_ACT_SEL_SET(trigmux_index);
  589. }
  590. /**
  591. * @brief Select the trigger source that forces the output to take effect
  592. *
  593. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  594. * @param chn @ref pwm_channel_t
  595. * @param trigmux_index select one trigger from 8
  596. */
  597. static inline void pwmv2_select_force_trigmux_index(PWMV2_Type *pwm_x, pwm_channel_t chn, uint8_t trigmux_index)
  598. {
  599. pwm_x->PWM[chn].CFG1 = (pwm_x->PWM[chn].CFG1 & ~PWMV2_PWM_CFG1_PWM_FORCE_SEL_MASK) | PWMV2_PWM_CFG1_PWM_FORCE_SEL_SET(trigmux_index);
  600. }
  601. /**
  602. * @brief Selection of trigger signal for fault recovery
  603. *
  604. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  605. * @param chn @ref pwm_channel_t
  606. * @param trigmux_index select one trigger from 8
  607. */
  608. static inline void pwmv2_select_recovery_fault_trigmux_index(PWMV2_Type *pwm_x, pwm_channel_t chn, uint8_t trigmux_index)
  609. {
  610. pwm_x->PWM[chn].CFG1 = (pwm_x->PWM[chn].CFG1 & ~PWMV2_PWM_CFG1_FAULT_REC_SEL_MASK) | PWMV2_PWM_CFG1_FAULT_REC_SEL_SET(trigmux_index);
  611. }
  612. /**
  613. * @brief set pwm dead area
  614. *
  615. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  616. * @param chn @ref pwm_channel_t
  617. * @param dead dead area time
  618. */
  619. static inline void pwmv2_set_dead_area(PWMV2_Type *pwm_x, pwm_channel_t chn, uint32_t dead)
  620. {
  621. pwm_x->PWM[chn].DEAD_AREA = PWMV2_PWM_DEAD_AREA_DEAD_AREA_SET((dead << 8));
  622. }
  623. /**
  624. * @brief Setting the comparator as an input to trigmux
  625. *
  626. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  627. * @param trigmux_chn @ref pwm_channel_t
  628. * @param cmp_index cmp index
  629. */
  630. static inline void pwmv2_set_trigout_cmp_index(PWMV2_Type *pwm_x, pwm_channel_t trigmux_chn, uint8_t cmp_index)
  631. {
  632. pwm_x->TRIGGER_CFG[trigmux_chn] = (pwm_x->TRIGGER_CFG[trigmux_chn] & ~PWMV2_TRIGGER_CFG_TRIGGER_OUT_SEL_MASK) | PWMV2_TRIGGER_CFG_TRIGGER_OUT_SEL_SET(cmp_index);
  633. }
  634. /**
  635. * @brief Enable software forced output
  636. *
  637. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  638. * @param chn @ref pwm_channel_t
  639. */
  640. static inline void pwmv2_enable_software_force(PWMV2_Type *pwm_x, pwm_channel_t chn)
  641. {
  642. pwm_x->GLB_CTRL |= PWMV2_GLB_CTRL_SW_FORCE_SET((1 << chn));
  643. }
  644. /**
  645. * @brief Disable software forced output
  646. *
  647. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  648. * @param chn @ref pwm_channel_t
  649. */
  650. static inline void pwmv2_disable_software_force(PWMV2_Type *pwm_x, pwm_channel_t chn)
  651. {
  652. pwm_x->GLB_CTRL &= ~(PWMV2_GLB_CTRL_SW_FORCE_SET((1 << chn)));
  653. }
  654. #ifdef PWM_SOC_HRPWM_SUPPORT
  655. /**
  656. * @brief Add a delay after deadband, 0-255ths of a clock cycle
  657. *
  658. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  659. * @param delay_tick 0-255
  660. */
  661. static inline void pwmv2_add_delay_tick_after_dead_area(PWMV2_Type *pwm_x, uint8_t delay_tick)
  662. {
  663. pwm_x->GLB_CTRL = (pwm_x->GLB_CTRL & ~PWMV2_GLB_CTRL_OUTPUT_DELAY_MASK) | PWMV2_GLB_CTRL_OUTPUT_DELAY_SET(delay_tick);
  664. }
  665. /**
  666. * @brief Enable high precision pwm
  667. *
  668. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  669. */
  670. static inline void pwmv2_enable_hrpwm(PWMV2_Type *pwm_x)
  671. {
  672. pwm_x->GLB_CTRL |= PWMV2_GLB_CTRL_HR_PWM_EN_MASK;
  673. }
  674. /**
  675. * @brief Disable high precision pwm
  676. *
  677. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  678. */
  679. static inline void pwmv2_disable_hrpwm(PWMV2_Type *pwm_x)
  680. {
  681. pwm_x->GLB_CTRL &= ~PWMV2_GLB_CTRL_HR_PWM_EN_MASK;
  682. }
  683. #endif
  684. /**
  685. * @brief Enable the software dac mode
  686. *
  687. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  688. * @param dac_index @ref pwm_dac_channel_t
  689. */
  690. static inline void pwmv2_enable_software_dac_mode(PWMV2_Type *pwm_x, pwm_dac_channel_t dac_index)
  691. {
  692. pwm_x->GLB_CTRL2 |= PWMV2_GLB_CTRL2_DAC_SW_MODE_SET((1 << dac_index));
  693. }
  694. /**
  695. * @brief Disable the software dac mode
  696. *
  697. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  698. * @param dac_index @ref pwm_dac_channel_t
  699. */
  700. static inline void pwmv2_disable_software_dac_mode(PWMV2_Type *pwm_x, pwm_dac_channel_t dac_index)
  701. {
  702. pwm_x->GLB_CTRL2 &= ~PWMV2_GLB_CTRL2_DAC_SW_MODE_SET((1 << dac_index));
  703. }
  704. /**
  705. * @brief Enable debug mode
  706. *
  707. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  708. */
  709. static inline void pwmv2_enable_debug_mode(PWMV2_Type *pwm_x)
  710. {
  711. pwm_x->GLB_CTRL2 |= PWMV2_GLB_CTRL2_DEBUG_IN_EN_MASK;
  712. }
  713. /**
  714. * @brief Disable debug mode
  715. *
  716. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  717. */
  718. static inline void pwmv2_disable_debug_mode(PWMV2_Type *pwm_x)
  719. {
  720. pwm_x->GLB_CTRL2 &= ~PWMV2_GLB_CTRL2_DEBUG_IN_EN_MASK;
  721. }
  722. /**
  723. * @brief Clear fault event
  724. *
  725. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  726. * @param chn @ref pwm_channel_t
  727. */
  728. static inline void pwmv2_clear_fault_event(PWMV2_Type *pwm_x, pwm_channel_t chn)
  729. {
  730. pwm_x->GLB_CTRL2 = (pwm_x->GLB_CTRL2 & ~(PWMV2_GLB_CTRL2_FAULT_CLEAR_MASK)) | PWMV2_GLB_CTRL2_FAULT_CLEAR_SET((1 << chn));
  731. }
  732. /**
  733. * @brief Using the Shadow Register Function
  734. *
  735. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  736. */
  737. static inline void pwmv2_enable_shadow_lock_feature(PWMV2_Type *pwm_x)
  738. {
  739. pwm_x->GLB_CTRL2 |= PWMV2_GLB_CTRL2_SHADOW_LOCK_EN_MASK;
  740. }
  741. /**
  742. * @brief Do not use the shadow register function
  743. *
  744. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  745. */
  746. static inline void pwmv2_disable_shadow_lock_feature(PWMV2_Type *pwm_x)
  747. {
  748. pwm_x->GLB_CTRL2 &= ~PWMV2_GLB_CTRL2_SHADOW_LOCK_EN_MASK;
  749. }
  750. /**
  751. * @brief Get counter work status
  752. *
  753. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  754. * @param counter_index @ref pwm_counter_t
  755. * @return uint32_t status mask
  756. */
  757. static inline uint32_t pwmv2_get_counter_working_status(PWMV2_Type *pwm_x, pwm_counter_t counter_index)
  758. {
  759. return PWMV2_CNT_RELOAD_WORK_VALUE_GET(pwm_x->CNT_RELOAD_WORK[counter_index]);
  760. }
  761. /**
  762. * @brief Get cmp work status
  763. *
  764. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  765. * @param cmp_index cmp index
  766. * @return uint32_t status mask
  767. */
  768. static inline uint32_t pwmv2_get_cmp_working_status(PWMV2_Type *pwm_x, uint8_t cmp_index)
  769. {
  770. return PWMV2_CMP_VAL_WORK_VALUE_GET(pwm_x->CMP_VAL_WORK[cmp_index]);
  771. }
  772. /**
  773. * @brief Get force mode work status
  774. *
  775. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  776. * @return uint32_t status mask
  777. */
  778. static inline uint32_t pwmv2_get_force_working_status(PWMV2_Type *pwm_x)
  779. {
  780. return PWMV2_FORCE_WORK_FORCE_MODE_GET(pwm_x->FORCE_WORK);
  781. }
  782. /**
  783. * @brief Get the status of the output polarity
  784. *
  785. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  786. * @return uint32_t polarity
  787. */
  788. static inline uint32_t pwmv2_get_force_work_out_polarity_status(PWMV2_Type *pwm_x)
  789. {
  790. return PWMV2_FORCE_WORK_OUT_POLARITY_GET(pwm_x->FORCE_WORK);
  791. }
  792. /**
  793. * @brief Getting the value of a counter
  794. *
  795. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  796. * @param counter_index @ref pwm_counter_t
  797. * @return uint32_t counter value
  798. */
  799. static inline uint32_t pwmv2_get_counter_value(PWMV2_Type *pwm_x, pwm_counter_t counter_index)
  800. {
  801. return PWMV2_CNT_VAL_VALUE_GET(pwm_x->CNT_VAL[counter_index]);
  802. }
  803. /**
  804. * @brief set dac value
  805. *
  806. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  807. * @param dac_index @ref pwm_dac_channel_t
  808. * @param value dac value
  809. */
  810. static inline void pwmv2_set_dac_value(PWMV2_Type *pwm_x, pwm_dac_channel_t dac_index, uint32_t value)
  811. {
  812. pwm_x->DAC_VALUE_SV[dac_index] = PWMV2_DAC_VALUE_SV_VALUE_SET(value);
  813. }
  814. /**
  815. * @brief get capture posedge value
  816. *
  817. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  818. * @param chn @ref pwm_channel_t
  819. * @return uint32_t posedge value
  820. */
  821. static inline uint32_t pwmv2_get_capture_posedge_value(PWMV2_Type *pwm_x, pwm_channel_t chn)
  822. {
  823. return PWMV2_CAPTURE_POS_CAPTURE_POS_GET(pwm_x->CAPTURE_POS[chn]);
  824. }
  825. /**
  826. * @brief Select the input source for the captured signal
  827. *
  828. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  829. * @param chn @ref pwm_channel_t
  830. * @param select @ref pwm_capture_input_select_t
  831. */
  832. static inline void pwmv2_capture_selection_input_source(PWMV2_Type *pwm_x, pwm_channel_t chn, pwm_capture_input_select_t select)
  833. {
  834. pwm_x->CAPTURE_POS[chn] = (pwm_x->CAPTURE_POS[chn] & ~PWMV2_CAPTURE_POS_CAPTURE_SELGPIO_MASK) |
  835. PWMV2_CAPTURE_POS_CAPTURE_SELGPIO_SET(select);
  836. }
  837. /**
  838. * @brief Set the counter to be used for the capture channel
  839. *
  840. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  841. * @param chn @ref pwm_channel_t
  842. * @param counter_index counter index
  843. */
  844. static inline void pwmv2_set_capture_counter_index(PWMV2_Type *pwm_x, pwm_channel_t chn, uint8_t counter_index)
  845. {
  846. pwm_x->CAPTURE_POS[chn] = (pwm_x->CAPTURE_POS[chn] & ~PWMV2_CAPTURE_POS_CNT_INDEX_MASK) |
  847. PWMV2_CAPTURE_POS_CNT_INDEX_SET(counter_index);
  848. }
  849. /**
  850. * @brief get capture negedge value
  851. *
  852. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  853. * @param chn @ref pwm_channel_t
  854. * @return uint32_t posedge value
  855. */
  856. static inline uint32_t pwmv2_get_capture_negedge_value(PWMV2_Type *pwm_x, pwm_channel_t chn)
  857. {
  858. return PWMV2_CAPTURE_NEG_CAPTURE_NEG_GET(pwm_x->CAPTURE_NEG[chn]);
  859. }
  860. /**
  861. * @brief Get all interrupt status
  862. *
  863. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  864. * @return uint32_t irq status mask
  865. */
  866. static inline uint32_t pwmv2_get_irq_status_all(PWMV2_Type *pwm_x)
  867. {
  868. return pwm_x->IRQ_STS;
  869. }
  870. /**
  871. * @brief clear calculate overflow irq status
  872. *
  873. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  874. */
  875. static inline void pwmv2_clear_calculate_overflow_irq_status(PWMV2_Type *pwm_x)
  876. {
  877. pwm_x->IRQ_STS &= PWMV2_IRQ_STS_IRQ_CAL_OVERFLOW_MASK;
  878. }
  879. /**
  880. * @brief enable calculate overflow irq
  881. *
  882. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  883. */
  884. static inline void pwmv2_enable_calculate_overflow_irq(PWMV2_Type *pwm_x)
  885. {
  886. pwm_x->IRQ_EN |= PWMV2_IRQ_EN_IRQ_EN_OVERFLOW_MASK;
  887. }
  888. /**
  889. * @brief Disable calculate overflow irq
  890. *
  891. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  892. */
  893. static inline void pwmv2_disable_calculate_overflow_irq(PWMV2_Type *pwm_x)
  894. {
  895. pwm_x->IRQ_EN &= ~PWMV2_IRQ_EN_IRQ_EN_OVERFLOW_MASK;
  896. }
  897. /**
  898. * @brief Get cmp irq status
  899. *
  900. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  901. * @return uint32_t irq status
  902. */
  903. static inline uint32_t pwmv2_get_cmp_irq_status(PWMV2_Type *pwm_x)
  904. {
  905. return PWMV2_IRQ_STS_CMP_IRQ_STS_CMP_GET(pwm_x->IRQ_STS_CMP);
  906. }
  907. /**
  908. * @brief Clear cmp irq status
  909. *
  910. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  911. * @param mask uint32_t irq status
  912. */
  913. static inline void pwmv2_clear_cmp_irq_status(PWMV2_Type *pwm_x, uint32_t mask)
  914. {
  915. pwm_x->IRQ_STS_CMP = PWMV2_IRQ_STS_CMP_IRQ_STS_CMP_SET(mask);
  916. }
  917. /**
  918. * @brief Get reload irq status
  919. *
  920. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  921. * @return uint32_t reload irq status
  922. */
  923. static inline uint32_t pwmv2_get_reload_irq_status(PWMV2_Type *pwm_x)
  924. {
  925. return PWMV2_IRQ_STS_RELOAD_IRQ_STS_RELOAD_GET(pwm_x->IRQ_STS_RELOAD);
  926. }
  927. /**
  928. * @brief Clear reload irq status
  929. *
  930. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  931. * @param mask irq status mask
  932. */
  933. static inline void pwmv2_clear_reload_irq_status(PWMV2_Type *pwm_x, uint32_t mask)
  934. {
  935. pwm_x->IRQ_STS_RELOAD = PWMV2_IRQ_STS_RELOAD_IRQ_STS_RELOAD_SET(mask);
  936. }
  937. /**
  938. * @brief Get capture posedge irq status
  939. *
  940. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  941. * @return uint32_t irq status
  942. */
  943. static inline uint32_t pwmv2_get_capture_posedge_irq_status(PWMV2_Type *pwm_x)
  944. {
  945. return PWMV2_IRQ_STS_CAP_POS_IRQ_STS_CAP_POS_GET(pwm_x->IRQ_STS_CAP_POS);
  946. }
  947. /**
  948. * @brief Clear capture posedge irq status
  949. *
  950. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  951. * @param mask capture posedge irq mask
  952. */
  953. static inline void pwmv2_clear_capture_posedge_irq_status(PWMV2_Type *pwm_x, uint32_t mask)
  954. {
  955. pwm_x->IRQ_STS_CAP_POS = PWMV2_IRQ_STS_CAP_POS_IRQ_STS_CAP_POS_SET(mask);
  956. }
  957. /**
  958. * @brief Get capture negedge irq status
  959. *
  960. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  961. * @return uint32_t irq status
  962. */
  963. static inline uint32_t pwmv2_get_capture_negedge_irq_status(PWMV2_Type *pwm_x)
  964. {
  965. return PWMV2_IRQ_STS_CAP_NEG_IRQ_STS_CAP_NEG_GET(pwm_x->IRQ_STS_CAP_NEG);
  966. }
  967. /**
  968. * @brief Clear capture negedge irq status
  969. *
  970. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  971. * @param mask capture posedge irq mask
  972. */
  973. static inline void pwmv2_clear_capture_negedge_irq_status(PWMV2_Type *pwm_x, uint32_t mask)
  974. {
  975. pwm_x->IRQ_STS_CAP_NEG = PWMV2_IRQ_STS_CAP_NEG_IRQ_STS_CAP_NEG_SET(mask);
  976. }
  977. /**
  978. * @brief Get fault irq status
  979. *
  980. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  981. * @return uint32_t irq status
  982. */
  983. static inline uint32_t pwmv2_get_fault_irq_status(PWMV2_Type *pwm_x)
  984. {
  985. return PWMV2_IRQ_STS_FAULT_IRQ_STS_FAULT_GET(pwm_x->IRQ_STS_FAULT);
  986. }
  987. /**
  988. * @brief Clear fault irq status
  989. *
  990. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  991. * @return uint32_t irq status
  992. */
  993. static inline void pwmv2_clear_fault_irq_status(PWMV2_Type *pwm_x, uint32_t mask)
  994. {
  995. pwm_x->IRQ_STS_FAULT = PWMV2_IRQ_STS_FAULT_IRQ_STS_FAULT_SET(mask);
  996. }
  997. /**
  998. * @brief Get burstend irq status
  999. *
  1000. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1001. * @return uint32_t irq status
  1002. */
  1003. static inline uint32_t pwmv2_get_burstend_irq_status(PWMV2_Type *pwm_x)
  1004. {
  1005. return PWMV2_IRQ_STS_BURSTEND_IRQ_STS_BURSTEND_GET(pwm_x->IRQ_STS_BURSTEND);
  1006. }
  1007. /**
  1008. * @brief Clear burstend irq status
  1009. *
  1010. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1011. * @param mask mask status
  1012. */
  1013. static inline void pwmv2_clear_burstend__irq_status(PWMV2_Type *pwm_x, uint32_t mask)
  1014. {
  1015. pwm_x->IRQ_STS_BURSTEND = PWMV2_IRQ_STS_BURSTEND_IRQ_STS_BURSTEND_SET(mask);
  1016. }
  1017. /**
  1018. * @brief enable cmp irq
  1019. *
  1020. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1021. * @param cmp_index cmp index
  1022. */
  1023. static inline void pwmv2_enable_cmp_irq(PWMV2_Type *pwm_x, uint8_t cmp_index)
  1024. {
  1025. pwm_x->IRQ_EN_CMP |= PWMV2_IRQ_EN_CMP_IRQ_EN_CMP_SET(1 << cmp_index);
  1026. }
  1027. /**
  1028. * @brief disable cmp irq
  1029. *
  1030. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1031. * @param cmp_index cmp index
  1032. */
  1033. static inline void pwmv2_disable_cmp_irq(PWMV2_Type *pwm_x, uint8_t cmp_index)
  1034. {
  1035. pwm_x->IRQ_EN_CMP &= ~PWMV2_IRQ_EN_CMP_IRQ_EN_CMP_SET(1 << cmp_index);
  1036. }
  1037. /**
  1038. * @brief enable reload irq
  1039. *
  1040. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1041. * @param counter_index @ref pwm_counter_t
  1042. */
  1043. static inline void pwmv2_enable_reload_irq(PWMV2_Type *pwm_x, pwm_counter_t counter_index)
  1044. {
  1045. pwm_x->IRQ_EN_RELOAD |= PWMV2_IRQ_EN_RELOAD_IRQ_EN_RELOAD_SET(1 << counter_index);
  1046. }
  1047. /**
  1048. * @brief disable reload irq
  1049. *
  1050. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1051. * @param counter_index @ref pwm_counter_t
  1052. */
  1053. static inline void pwmv2_disable_reload_irq(PWMV2_Type *pwm_x, pwm_counter_t counter_index)
  1054. {
  1055. pwm_x->IRQ_EN_RELOAD &= ~PWMV2_IRQ_EN_RELOAD_IRQ_EN_RELOAD_SET(1 << counter_index);
  1056. }
  1057. /**
  1058. * @brief enable capture posedge irq
  1059. *
  1060. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1061. * @param channel_index @ref pwm_counter_t
  1062. */
  1063. static inline void pwmv2_enable_capture_posedge_irq(PWMV2_Type *pwm_x, pwm_channel_t channel_index)
  1064. {
  1065. pwm_x->IRQ_EN_CAP_POS |= PWMV2_IRQ_EN_CAP_POS_IRQ_EN_CAP_POS_SET(1 << channel_index);
  1066. }
  1067. /**
  1068. * @brief disable capture posedge irq
  1069. *
  1070. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1071. * @param channel_index @ref pwm_counter_t
  1072. */
  1073. static inline void pwmv2_disable_capture_posedge_irq(PWMV2_Type *pwm_x, pwm_channel_t channel_index)
  1074. {
  1075. pwm_x->IRQ_EN_CAP_POS &= ~PWMV2_IRQ_EN_CAP_POS_IRQ_EN_CAP_POS_SET(1 << channel_index);
  1076. }
  1077. /**
  1078. * @brief enable capture nedege irq
  1079. *
  1080. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1081. * @param channel_index @ref pwm_channel_t
  1082. */
  1083. static inline void pwmv2_enable_capture_nededge_irq(PWMV2_Type *pwm_x, pwm_channel_t channel_index)
  1084. {
  1085. pwm_x->IRQ_EN_CAP_NEG |= PWMV2_IRQ_EN_CAP_NEG_IRQ_EN_CAP_NEG_SET(1 << channel_index);
  1086. }
  1087. /**
  1088. * @brief disable capture nedege irq
  1089. *
  1090. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1091. * @param channel_index @ref pwm_channel_t
  1092. */
  1093. static inline void pwmv2_disable_capture_nededge_irq(PWMV2_Type *pwm_x, pwm_channel_t channel_index)
  1094. {
  1095. pwm_x->IRQ_EN_CAP_NEG &= ~PWMV2_IRQ_EN_CAP_NEG_IRQ_EN_CAP_NEG_SET(1 << channel_index);
  1096. }
  1097. /**
  1098. * @brief enable fault irq
  1099. *
  1100. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1101. * @param channel_index @ref pwm_channel_t
  1102. */
  1103. static inline void pwmv2_enable_fault_irq(PWMV2_Type *pwm_x, pwm_channel_t channel_index)
  1104. {
  1105. pwm_x->IRQ_EN_FAULT |= PWMV2_IRQ_EN_FAULT_IRQ_EN_FAULT_SET(1 << channel_index);
  1106. }
  1107. /**
  1108. * @brief disable fault irq
  1109. *
  1110. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1111. * @param channel_index @ref pwm_channel_t
  1112. */
  1113. static inline void pwmv2_disable_fault_irq(PWMV2_Type *pwm_x, pwm_channel_t channel_index)
  1114. {
  1115. pwm_x->IRQ_EN_FAULT &= ~PWMV2_IRQ_EN_FAULT_IRQ_EN_FAULT_SET(1 << channel_index);
  1116. }
  1117. /**
  1118. * @brief enable burstend irq
  1119. *
  1120. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1121. * @param counter_index @ref pwm_counter_t
  1122. */
  1123. static inline void pwmv2_enable_burstend_irq(PWMV2_Type *pwm_x, pwm_counter_t counter_index)
  1124. {
  1125. pwm_x->IRQ_EN_BURSTEND |= PWMV2_IRQ_EN_FAULT_IRQ_EN_FAULT_SET(1 << counter_index);
  1126. }
  1127. /**
  1128. * @brief disable burstend irq
  1129. *
  1130. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1131. * @param counter_index @ref pwm_counter_t
  1132. */
  1133. static inline void pwmv2_disable_burstend_irq(PWMV2_Type *pwm_x, pwm_counter_t counter_index)
  1134. {
  1135. pwm_x->IRQ_EN_BURSTEND &= ~PWMV2_IRQ_EN_FAULT_IRQ_EN_FAULT_SET(1 << counter_index);
  1136. }
  1137. /**
  1138. * @brief enable dma at compare point
  1139. *
  1140. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1141. * @param dma_channel @ref pwm_dma_chn_t
  1142. * @param cmp_index cmp index
  1143. */
  1144. static inline void pwmv2_enable_dma_at_compare_point(PWMV2_Type *pwm_x, pwm_dma_chn_t dma_channel, uint8_t cmp_index)
  1145. {
  1146. pwm_x->DMA_EN = (pwm_x->DMA_EN & ~((PWMV2_DMA_EN_DMA0_SEL_MASK | PWMV2_DMA_EN_DMA0_EN_MASK) << (PWMV2_DMA_EN_DMA1_SEL_SHIFT * dma_channel))) |
  1147. ((PWMV2_DMA_EN_DMA0_SEL_SET(cmp_index) | PWMV2_DMA_EN_DMA0_EN_MASK) << (PWMV2_DMA_EN_DMA1_SEL_SHIFT * dma_channel));
  1148. }
  1149. /**
  1150. * @brief disable dma at compare point
  1151. *
  1152. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1153. * @param dma_channel @ref pwm_dma_chn_t
  1154. */
  1155. static inline void pwmv2_disable_dma_at_compare_point(PWMV2_Type *pwm_x, pwm_dma_chn_t dma_channel)
  1156. {
  1157. pwm_x->DMA_EN &= ~((PWMV2_DMA_EN_DMA0_SEL_MASK | PWMV2_DMA_EN_DMA0_EN_MASK) << (PWMV2_DMA_EN_DMA1_SEL_SHIFT * dma_channel));
  1158. }
  1159. /**
  1160. * @brief enable dma at reload point
  1161. *
  1162. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1163. * @param dma_channel @ref pwm_dma_chn_t
  1164. * @param reload_index @ref pwm_counter_t
  1165. */
  1166. static inline void pwmv2_enable_dma_at_reload_point(PWMV2_Type *pwm_x, pwm_dma_chn_t dma_channel, pwm_counter_t reload_index)
  1167. {
  1168. pwm_x->DMA_EN = (pwm_x->DMA_EN & ~((PWMV2_DMA_EN_DMA0_SEL_MASK | PWMV2_DMA_EN_DMA0_EN_MASK) << (PWMV2_DMA_EN_DMA1_SEL_SHIFT * dma_channel))) |
  1169. ((PWMV2_DMA_EN_DMA0_SEL_SET(reload_index + 24) | PWMV2_DMA_EN_DMA0_EN_MASK) << (PWMV2_DMA_EN_DMA1_SEL_SHIFT * dma_channel));
  1170. }
  1171. /**
  1172. * @brief disable dma at reload point
  1173. *
  1174. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1175. * @param dma_channel @ref pwm_dma_chn_t
  1176. */
  1177. static inline void pwmv2_disable_dma_at_reload_point(PWMV2_Type *pwm_x, pwm_dma_chn_t dma_channel)
  1178. {
  1179. pwm_x->DMA_EN &= ~((PWMV2_DMA_EN_DMA0_SEL_MASK | PWMV2_DMA_EN_DMA0_EN_MASK) << (PWMV2_DMA_EN_DMA1_SEL_SHIFT * dma_channel));
  1180. }
  1181. /**
  1182. * @brief select compare point 0 index
  1183. *
  1184. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1185. * @param counter @ref pwm_counter_t
  1186. * @param cmp_index cmp index
  1187. */
  1188. static inline void pwmv2_reload_select_compare_point0_index(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t cmp_index)
  1189. {
  1190. pwm_x->CNT[counter].CFG0 = (pwm_x->CNT[counter].CFG0 & ~(PWMV2_CNT_CFG0_RLD_CMP_SEL0_MASK)) | PWMV2_CNT_CFG0_RLD_CMP_SEL0_SET(cmp_index);
  1191. }
  1192. /**
  1193. * @brief select compare point 1 index
  1194. *
  1195. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1196. * @param counter @ref pwm_counter_t
  1197. * @param cmp_index cmp index
  1198. */
  1199. static inline void pwmv2_reload_select_compare_point1_index(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t cmp_index)
  1200. {
  1201. pwm_x->CNT[counter].CFG0 = (pwm_x->CNT[counter].CFG0 & ~(PWMV2_CNT_CFG0_RLD_CMP_SEL1_MASK)) | PWMV2_CNT_CFG0_RLD_CMP_SEL1_SET(cmp_index);
  1202. }
  1203. /**
  1204. * @brief Select the input trigger source for the reload point
  1205. *
  1206. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1207. * @param counter @ref pwm_counter_t
  1208. * @param trig_index trig index
  1209. */
  1210. static inline void pwmv2_reload_select_input_trigger(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t trig_index)
  1211. {
  1212. pwm_x->CNT[counter].CFG0 = (pwm_x->CNT[counter].CFG0 & ~(PWMV2_CNT_CFG0_RLD_TRIG_SEL_MASK)) | PWMV2_CNT_CFG0_RLD_TRIG_SEL_SET(trig_index);
  1213. }
  1214. /**
  1215. * @brief Set reload update time
  1216. *
  1217. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1218. * @param counter @ref pwm_counter_t
  1219. * @param update @ref pwm_reload_update_time_t
  1220. */
  1221. static inline void pwmv2_set_reload_update_time(PWMV2_Type *pwm_x, pwm_counter_t counter, pwm_reload_update_time_t update)
  1222. {
  1223. pwm_x->CNT[counter].CFG0 = (pwm_x->CNT[counter].CFG0 & ~(PWMV2_CNT_CFG0_RLD_UPDATE_TIME_MASK)) | PWMV2_CNT_CFG0_RLD_UPDATE_TIME_SET(update);
  1224. }
  1225. /**
  1226. * @brief Set dac data parameter
  1227. *
  1228. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1229. * @param counter @ref pwm_counter_t
  1230. * @param dac_parameter dac parameter
  1231. */
  1232. static inline void pwmv2_counter_set_dac_data_parameter(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t dac_parameter)
  1233. {
  1234. pwm_x->CNT[counter].CFG0 = (pwm_x->CNT[counter].CFG0 & ~PWMV2_CNT_CFG0_CNT_D_PARAM_MASK) | PWMV2_CNT_CFG0_CNT_D_PARAM_SET(dac_parameter);
  1235. }
  1236. /**
  1237. * @brief Select dac index
  1238. *
  1239. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1240. * @param counter @ref pwm_counter_t
  1241. * @param dac_index @ref pwm_dac_channel_t
  1242. */
  1243. static inline void pwmv2_conuter_select_dac_index(PWMV2_Type *pwm_x, pwm_counter_t counter, pwm_dac_channel_t dac_index)
  1244. {
  1245. pwm_x->CNT[counter].CFG1 = (pwm_x->CNT[counter].CFG1 & ~PWMV2_CNT_CFG1_CNT_DAC_INDEX_MASK) | PWMV2_CNT_CFG1_CNT_DAC_INDEX_SET(dac_index);
  1246. }
  1247. /**
  1248. * @brief Enable the upper limit of the calculation unit
  1249. *
  1250. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1251. * @param counter @ref pwm_counter_t
  1252. */
  1253. static inline void pwmv2_counter_up_limit_enable(PWMV2_Type *pwm_x, pwm_counter_t counter)
  1254. {
  1255. pwm_x->CNT[counter].CFG1 |= PWMV2_CNT_CFG1_CNT_LU_EN_MASK;
  1256. }
  1257. /**
  1258. * @brief Disable the upper limit of the calculation unit
  1259. *
  1260. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1261. * @param counter @ref pwm_counter_t
  1262. */
  1263. static inline void pwmv2_counter_up_limit_disable(PWMV2_Type *pwm_x, pwm_counter_t counter)
  1264. {
  1265. pwm_x->CNT[counter].CFG1 &= ~PWMV2_CNT_CFG1_CNT_LU_EN_MASK;
  1266. }
  1267. /**
  1268. * @brief Select the upper limit from the shadow register
  1269. *
  1270. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1271. * @param counter @ref pwm_counter_t
  1272. * @param index shadow index
  1273. */
  1274. static inline void pwmv2_counter_select_up_limit_from_shadow_value(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t index)
  1275. {
  1276. pwm_x->CNT[counter].CFG1 = (pwm_x->CNT[counter].CFG1 & ~PWMV2_CNT_CFG1_CNT_LIM_UP_MASK) | PWMV2_CNT_CFG1_CNT_LIM_UP_SET(index);
  1277. }
  1278. /**
  1279. * @brief Enable the lower limit of the calculation unit
  1280. *
  1281. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1282. * @param counter @ref pwm_counter_t
  1283. */
  1284. static inline void pwmv2_counter_low_limit_enable(PWMV2_Type *pwm_x, pwm_counter_t counter)
  1285. {
  1286. pwm_x->CNT[counter].CFG1 |= PWMV2_CNT_CFG1_CNT_LL_EN_MASK;
  1287. }
  1288. /**
  1289. * @brief Disable the lower limit of the calculation unit
  1290. *
  1291. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1292. * @param counter @ref pwm_counter_t
  1293. */
  1294. static inline void pwmv2_counter_low_limit_disable(PWMV2_Type *pwm_x, pwm_counter_t counter)
  1295. {
  1296. pwm_x->CNT[counter].CFG1 &= ~PWMV2_CNT_CFG1_CNT_LL_EN_MASK;
  1297. }
  1298. /**
  1299. * @brief Select the lower limit from the shadow register
  1300. *
  1301. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1302. * @param counter @ref pwm_counter_t
  1303. * @param index shadow index
  1304. */
  1305. static inline void pwmv2_counter_select_low_limit_from_shadow_value(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t index)
  1306. {
  1307. pwm_x->CNT[counter].CFG1 = (pwm_x->CNT[counter].CFG1 & ~PWMV2_CNT_CFG1_CNT_LIM_LO_MASK) | PWMV2_CNT_CFG1_CNT_LIM_LO_SET(index);
  1308. }
  1309. /**
  1310. * @brief Select data offset from shadow register
  1311. *
  1312. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1313. * @param counter @ref pwm_counter_t
  1314. * @param index shadow index
  1315. */
  1316. static inline void pwmv2_counter_select_data_offset_from_shadow_value(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t index)
  1317. {
  1318. pwm_x->CNT[counter].CFG1 = (pwm_x->CNT[counter].CFG1 & ~PWMV2_CNT_CFG1_CNT_IN_OFF_MASK) | PWMV2_CNT_CFG1_CNT_IN_OFF_SET(index);
  1319. }
  1320. /**
  1321. * @brief enable counter reload by trigmux
  1322. *
  1323. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1324. * @param counter @ref pwm_counter_t
  1325. */
  1326. static inline void pwmv2_counter_enable_reload_by_trig(PWMV2_Type *pwm_x, pwm_counter_t counter)
  1327. {
  1328. pwm_x->CNT[counter].CFG2 |= PWMV2_CNT_CFG2_CNT_RELOAD_EN_MASK;
  1329. }
  1330. /**
  1331. * @brief disable counter reload by trigmux
  1332. *
  1333. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1334. * @param counter @ref pwm_counter_t
  1335. */
  1336. static inline void pwmv2_counter_disable_reload_by_trig(PWMV2_Type *pwm_x, pwm_counter_t counter)
  1337. {
  1338. pwm_x->CNT[counter].CFG2 &= ~PWMV2_CNT_CFG2_CNT_RELOAD_EN_MASK;
  1339. }
  1340. /**
  1341. * @brief Select counter update by trigmux1
  1342. *
  1343. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1344. * @param counter @ref pwm_counter_t
  1345. * @param trig_index trigmux index
  1346. */
  1347. static inline void pwmv2_counter_update_trig1(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t trig_index)
  1348. {
  1349. pwm_x->CNT[counter].CFG2 = (pwm_x->CNT[counter].CFG2 & ~PWMV2_CNT_CFG2_CNT_UPDATE_TRIG1_MASK) | PWMV2_CNT_CFG2_CNT_UPDATE_TRIG1_SET(trig_index);
  1350. }
  1351. /**
  1352. * @brief Enable counter update by trigmux1
  1353. *
  1354. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1355. * @param counter @ref pwm_counter_t
  1356. */
  1357. static inline void pwmv2_counter_enable_update_trig1(PWMV2_Type *pwm_x, pwm_counter_t counter)
  1358. {
  1359. pwm_x->CNT[counter].CFG2 |= PWMV2_CNT_CFG2_CNT_UPDATE_EN1_MASK;
  1360. }
  1361. /**
  1362. * @brief Disable counter update by trigmux1
  1363. *
  1364. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1365. * @param counter @ref pwm_counter_t
  1366. */
  1367. static inline void pwmv2_counter_disable_update_trig1(PWMV2_Type *pwm_x, pwm_counter_t counter)
  1368. {
  1369. pwm_x->CNT[counter].CFG2 &= ~PWMV2_CNT_CFG2_CNT_UPDATE_EN1_MASK;
  1370. }
  1371. /**
  1372. * @brief Enable change counter value to one of the calculation cell output when cnt_update_triger1 issued
  1373. *
  1374. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1375. * @param counter @ref pwm_counter_t
  1376. * @param cal_index cal index
  1377. */
  1378. static inline void pwmv2_counter_set_trig1_calculate_cell_index(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t cal_index)
  1379. {
  1380. pwm_x->CNT[counter].CFG2 = (pwm_x->CNT[counter].CFG2 & ~PWMV2_CNT_CFG2_CNT_TRIG1_MASK) | PWMV2_CNT_CFG2_CNT_TRIG1_SET(cal_index);
  1381. }
  1382. /**
  1383. * @brief Select counter update by trigmux0
  1384. *
  1385. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1386. * @param counter @ref pwm_counter_t
  1387. * @param trig_index trigmux index
  1388. */
  1389. static inline void pwmv2_counter_update_trig0(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t trig_index)
  1390. {
  1391. pwm_x->CNT[counter].CFG2 = (pwm_x->CNT[counter].CFG2 & ~PWMV2_CNT_CFG2_CNT_UPDATE_TRIG0_MASK) | PWMV2_CNT_CFG2_CNT_UPDATE_TRIG0_SET(trig_index);
  1392. }
  1393. /**
  1394. * @brief Enable counter update by trigmux0
  1395. *
  1396. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1397. * @param counter @ref pwm_counter_t
  1398. */
  1399. static inline void pwmv2_counter_enable_update_trig0(PWMV2_Type *pwm_x, pwm_counter_t counter)
  1400. {
  1401. pwm_x->CNT[counter].CFG2 |= PWMV2_CNT_CFG2_CNT_UPDATE_EN0_MASK;
  1402. }
  1403. /**
  1404. * @brief Disable counter update by trigmux0
  1405. *
  1406. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1407. * @param counter @ref pwm_counter_t
  1408. */
  1409. static inline void pwmv2_counter_disable_update_trig0(PWMV2_Type *pwm_x, pwm_counter_t counter)
  1410. {
  1411. pwm_x->CNT[counter].CFG2 &= ~PWMV2_CNT_CFG2_CNT_UPDATE_EN0_MASK;
  1412. }
  1413. /**
  1414. * @brief Enable change counter value to one of the calculation cell output when cnt_update_triger0 issued
  1415. *
  1416. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1417. * @param counter @ref pwm_counter_t
  1418. * @param cal_index cal index
  1419. */
  1420. static inline void pwmv2_counter_set_trig0_calculate_cell_index(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t cal_index)
  1421. {
  1422. pwm_x->CNT[counter].CFG2 = (pwm_x->CNT[counter].CFG2 & ~PWMV2_CNT_CFG2_CNT_TRIG0_MASK) | PWMV2_CNT_CFG2_CNT_TRIG0_SET(cal_index);
  1423. }
  1424. /**
  1425. * @brief Set trigmux index to start counter
  1426. *
  1427. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1428. * @param counter @ref pwm_counter_t
  1429. * @param trig_index trig index
  1430. */
  1431. static inline void pwmv2_counter_start_select_trigger_index(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t trig_index)
  1432. {
  1433. pwm_x->CNT[counter].CFG3 = (pwm_x->CNT[counter].CFG3 & ~PWMV2_CNT_CFG3_CNT_START_SEL_MASK) | PWMV2_CNT_CFG3_CNT_START_SEL_SET(trig_index);
  1434. }
  1435. /**
  1436. * @brief Enable trigmux to trigger counter initiation
  1437. *
  1438. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1439. * @param counter @ref pwm_counter_t
  1440. */
  1441. static inline void pwmv2_counter_start_trigger_enable(PWMV2_Type *pwm_x, pwm_counter_t counter)
  1442. {
  1443. pwm_x->CNT[counter].CFG3 |= PWMV2_CNT_CFG3_CNT_HW_START_EN_MASK;
  1444. }
  1445. /**
  1446. * @brief Disable trigmux to trigger counter initiation
  1447. *
  1448. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1449. * @param counter @ref pwm_counter_t
  1450. */
  1451. static inline void pwmv2_counter_start_trigger_disable(PWMV2_Type *pwm_x, pwm_counter_t counter)
  1452. {
  1453. pwm_x->CNT[counter].CFG3 &= ~PWMV2_CNT_CFG3_CNT_HW_START_EN_MASK;
  1454. }
  1455. /**
  1456. * @brief Set counter burst value
  1457. *
  1458. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1459. * @param counter @ref pwm_counter_t
  1460. * @param burst burst value
  1461. */
  1462. static inline void pwmv2_set_counter_burst(PWMV2_Type *pwm_x, pwm_counter_t counter, uint16_t burst)
  1463. {
  1464. pwm_x->CNT[counter].CFG3 |= PWMV2_CNT_CFG3_CNT_BURST_SET(burst);
  1465. }
  1466. /**
  1467. * @brief Disable counter burst function
  1468. *
  1469. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1470. * @param counter @ref pwm_counter_t
  1471. */
  1472. static inline void pwmv2_counter_burst_disable(PWMV2_Type *pwm_x, pwm_counter_t counter)
  1473. {
  1474. pwm_x->CNT[counter].CFG3 |= PWMV2_CNT_CFG3_CNT_BURST_MASK;
  1475. }
  1476. /**
  1477. * @brief start pwm output
  1478. *
  1479. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1480. * @param counter @ref pwm_counter_t
  1481. */
  1482. static inline void pwmv2_start_pwm_output(PWMV2_Type *pwm_x, pwm_counter_t counter)
  1483. {
  1484. pwm_x->CNT_GLBCFG |= PWMV2_CNT_GLBCFG_CNT_SW_START_SET((1 << counter));
  1485. }
  1486. /**
  1487. * @brief Reset pwm counter
  1488. *
  1489. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1490. * @param counter @ref pwm_counter_t
  1491. */
  1492. static inline void pwmv2_reset_counter(PWMV2_Type *pwm_x, pwm_counter_t counter)
  1493. {
  1494. pwm_x->CNT_GLBCFG |= PWMV2_CNT_GLBCFG_TIMER_RESET_SET((1 << counter));
  1495. }
  1496. /**
  1497. * @brief Enable pwm counter
  1498. *
  1499. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1500. * @param counter @ref pwm_counter_t
  1501. */
  1502. static inline void pwmv2_enable_counter(PWMV2_Type *pwm_x, pwm_counter_t counter)
  1503. {
  1504. pwm_x->CNT_GLBCFG |= PWMV2_CNT_GLBCFG_TIMER_ENABLE_SET((1 << counter));
  1505. }
  1506. /**
  1507. * @brief Disable pwm counter
  1508. *
  1509. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1510. * @param counter @ref pwm_counter_t
  1511. */
  1512. static inline void pwmv2_disable_counter(PWMV2_Type *pwm_x, pwm_counter_t counter)
  1513. {
  1514. pwm_x->CNT_GLBCFG &= ~PWMV2_CNT_GLBCFG_TIMER_ENABLE_SET((1 << counter));
  1515. }
  1516. /**
  1517. * @brief Set calculate up limit parameter
  1518. *
  1519. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1520. * @param cal_index calculate index
  1521. * @param value parameter
  1522. */
  1523. static inline void pwmv2_calculate_set_up_limit_parameter(PWMV2_Type *pwm_x, uint8_t cal_index, uint8_t value)
  1524. {
  1525. pwm_x->CAL[cal_index].CFG0 = (pwm_x->CAL[cal_index].CFG0 & ~PWMV2_CAL_CFG0_CAL_LU_PARAM_MASK) | PWMV2_CAL_CFG0_CAL_LU_PARAM_SET(value);
  1526. }
  1527. /**
  1528. * @brief Set calculate low limit parameter
  1529. *
  1530. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1531. * @param cal_index calculate index
  1532. * @param value parameter
  1533. */
  1534. static inline void pwmv2_calculate_set_low_limit_parameter(PWMV2_Type *pwm_x, uint8_t cal_index, uint8_t value)
  1535. {
  1536. pwm_x->CAL[cal_index].CFG0 = (pwm_x->CAL[cal_index].CFG0 & ~PWMV2_CAL_CFG0_CAL_LL_PARAM_MASK) | PWMV2_CAL_CFG0_CAL_LL_PARAM_SET(value);
  1537. }
  1538. /**
  1539. * @brief Set calculate period parameter
  1540. *
  1541. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1542. * @param cal_index calculate index
  1543. * @param value parameter
  1544. */
  1545. static inline void pwmv2_calculate_set_period_parameter(PWMV2_Type *pwm_x, uint8_t cal_index, uint8_t value)
  1546. {
  1547. pwm_x->CAL[cal_index].CFG0 = (pwm_x->CAL[cal_index].CFG0 & ~PWMV2_CAL_CFG0_CAL_T_PARAM_MASK) | PWMV2_CAL_CFG0_CAL_T_PARAM_SET(value);
  1548. }
  1549. /**
  1550. * @brief Set calculate dac value parameter
  1551. *
  1552. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1553. * @param cal_index calculate index
  1554. * @param value parameter
  1555. */
  1556. static inline void pwmv2_calculate_set_dac_value_parameter(PWMV2_Type *pwm_x, uint8_t cal_index, uint8_t value)
  1557. {
  1558. pwm_x->CAL[cal_index].CFG0 = (pwm_x->CAL[cal_index].CFG0 & ~PWMV2_CAL_CFG0_CAL_D_PARAM_MASK) | PWMV2_CAL_CFG0_CAL_D_PARAM_SET(value);
  1559. }
  1560. /**
  1561. * @brief Select calculate index to counter
  1562. *
  1563. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1564. * @param cal_index calculate index
  1565. * @param counter_calculate counter index
  1566. */
  1567. static inline void pwmv2_calculate_select_counter_calculate_index(PWMV2_Type *pwm_x, uint8_t cal_index, uint8_t counter_calculate)
  1568. {
  1569. pwm_x->CAL[cal_index].CFG1 = (pwm_x->CAL[cal_index].CFG1 & ~PWMV2_CAL_CFG1_CAL_T_INDEX_MASK) | PWMV2_CAL_CFG1_CAL_T_INDEX_SET(counter_calculate);
  1570. }
  1571. /**
  1572. * @brief Select calculate input value
  1573. *
  1574. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1575. * @param cal_index calculate index
  1576. * @param index shadow index
  1577. */
  1578. static inline void pwmv2_calculate_select_in_value(PWMV2_Type *pwm_x, uint8_t cal_index, uint8_t index)
  1579. {
  1580. pwm_x->CAL[cal_index].CFG1 = (pwm_x->CAL[cal_index].CFG1 & ~PWMV2_CAL_CFG1_CAL_IN_INDEX_MASK) | PWMV2_CAL_CFG1_CAL_IN_INDEX_SET(index);
  1581. }
  1582. /**
  1583. * @brief enable calculate up limit
  1584. *
  1585. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1586. * @param cal_index calculate index
  1587. */
  1588. static inline void pwmv2_calculate_enable_up_limit(PWMV2_Type *pwm_x, uint8_t cal_index)
  1589. {
  1590. pwm_x->CAL[cal_index].CFG1 |= PWMV2_CAL_CFG1_CAL_LU_EN_MASK;
  1591. }
  1592. /**
  1593. * @brief disable calculate up limit
  1594. *
  1595. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1596. * @param cal_index calculate index
  1597. */
  1598. static inline void pwmv2_calculate_disable_up_limit(PWMV2_Type *pwm_x, uint8_t cal_index)
  1599. {
  1600. pwm_x->CAL[cal_index].CFG1 &= ~PWMV2_CAL_CFG1_CAL_LU_EN_MASK;
  1601. }
  1602. /**
  1603. * @brief Select up limit offset from shadow index
  1604. *
  1605. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1606. * @param cal_index calculate index
  1607. * @param shadow_index shadow index
  1608. */
  1609. static inline void pwmv2_calculate_select_up_limit_offset(PWMV2_Type *pwm_x, uint8_t cal_index, uint8_t shadow_index)
  1610. {
  1611. pwm_x->CAL[cal_index].CFG1 = (pwm_x->CAL[cal_index].CFG1 & ~PWMV2_CAL_CFG1_CAL_LIM_UP_MASK) | PWMV2_CAL_CFG1_CAL_LIM_UP_SET(shadow_index);
  1612. }
  1613. /**
  1614. * @brief Select low limit offset from shadow index
  1615. *
  1616. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1617. * @param cal_index calculate index
  1618. * @param shadow_index shadow index
  1619. */
  1620. static inline void pwmv2_calculate_select_low_limit_offset(PWMV2_Type *pwm_x, uint8_t cal_index, uint8_t shadow_index)
  1621. {
  1622. pwm_x->CAL[cal_index].CFG1 = (pwm_x->CAL[cal_index].CFG1 & ~PWMV2_CAL_CFG1_CAL_LIM_LO_MASK) | PWMV2_CAL_CFG1_CAL_LIM_LO_SET(shadow_index);
  1623. }
  1624. /**
  1625. * @brief Select offset from shadow index
  1626. *
  1627. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1628. * @param cal_index calculate index
  1629. * @param shadow_index shadow index
  1630. */
  1631. static inline void pwmv2_calculate_select_in_offset(PWMV2_Type *pwm_x, uint8_t cal_index, uint8_t shadow_index)
  1632. {
  1633. pwm_x->CAL[cal_index].CFG1 = (pwm_x->CAL[cal_index].CFG1 & ~PWMV2_CAL_CFG1_CAL_IN_OFF_MASK) | PWMV2_CAL_CFG1_CAL_IN_OFF_SET(shadow_index);
  1634. }
  1635. /**
  1636. * @brief enable low limit
  1637. *
  1638. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1639. * @param cal_index calculate index
  1640. */
  1641. static inline void pwmv2_calculate_enable_low_limit(PWMV2_Type *pwm_x, uint8_t cal_index)
  1642. {
  1643. pwm_x->CAL[cal_index].CFG1 |= PWMV2_CAL_CFG1_CAL_LL_EN_MASK;
  1644. }
  1645. /**
  1646. * @brief disable low limit
  1647. *
  1648. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1649. * @param cal_index calculate index
  1650. */
  1651. static inline void pwmv2_calculate_disable_low_limit(PWMV2_Type *pwm_x, uint8_t cal_index)
  1652. {
  1653. pwm_x->CAL[cal_index].CFG1 &= ~PWMV2_CAL_CFG1_CAL_LL_EN_MASK;
  1654. }
  1655. /**
  1656. * @brief Select cmp trigmux index
  1657. *
  1658. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1659. * @param cmp_index cmp index
  1660. * @param trig_index trigmux index
  1661. */
  1662. static inline void pwmv2_select_cmp_trigmux(PWMV2_Type *pwm_x, uint8_t cmp_index, uint8_t trig_index)
  1663. {
  1664. pwm_x->CMP[cmp_index].CFG = (pwm_x->CMP[cmp_index].CFG & ~PWMV2_CMP_CFG_CMP_TRIG_SEL_MASK) | PWMV2_CMP_CFG_CMP_TRIG_SEL_SET(trig_index);
  1665. }
  1666. /**
  1667. * @brief Select cmp update trigmux time
  1668. *
  1669. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1670. * @param cmp_index cmp index
  1671. * @param trig_time @ref pwm_cmp_shadow_register_update_trigger_t
  1672. */
  1673. static inline void pwmv2_cmp_update_trig_time(PWMV2_Type *pwm_x, uint8_t cmp_index, pwm_cmp_shadow_register_update_trigger_t trig_time)
  1674. {
  1675. pwm_x->CMP[cmp_index].CFG = (pwm_x->CMP[cmp_index].CFG & ~PWMV2_CMP_CFG_CMP_UPDATE_TIME_MASK) | PWMV2_CMP_CFG_CMP_UPDATE_TIME_SET(trig_time);
  1676. }
  1677. /**
  1678. * @brief Select cmp source
  1679. *
  1680. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1681. * @param cmp_index cmp index
  1682. * @param cmp_sel @ref pwm_cmp_source_t
  1683. * @param index source index
  1684. */
  1685. static inline void pwmv2_select_cmp_source(PWMV2_Type *pwm_x, uint8_t cmp_index, pwm_cmp_source_t cmp_sel, uint8_t index)
  1686. {
  1687. pwm_x->CMP[cmp_index].CFG = (pwm_x->CMP[cmp_index].CFG & ~PWMV2_CMP_CFG_CMP_IN_SEL_MASK) | PWMV2_CMP_CFG_CMP_IN_SEL_SET((cmp_sel + index));
  1688. }
  1689. /**
  1690. * @brief Select cmp use counter
  1691. *
  1692. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1693. * @param cmp_index cmp index
  1694. * @param counter_index @ref pwm_counter_t
  1695. */
  1696. static inline void pwmv2_cmp_select_counter(PWMV2_Type *pwm_x, uint8_t cmp_index, pwm_counter_t counter_index)
  1697. {
  1698. if (cmp_index >= 16) {
  1699. pwm_x->CMP[cmp_index].CFG = (pwm_x->CMP[cmp_index].CFG & ~PWMV2_CMP_CFG_CMP_CNT_MASK) | PWMV2_CMP_CFG_CMP_CNT_SET((counter_index));
  1700. }
  1701. }
  1702. /**
  1703. * @brief config pwm cmp
  1704. *
  1705. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1706. * @param index cmp index
  1707. * @param config @ref pwmv2_cmp_config_t
  1708. */
  1709. void pwmv2_config_cmp(PWMV2_Type *pwm_x, uint8_t index, pwmv2_cmp_config_t *config);
  1710. /**
  1711. * @brief config async fault source
  1712. *
  1713. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1714. * @param index cmp index
  1715. * @param config @ref pwmv2_async_fault_source_config_t
  1716. */
  1717. void pwmv2_config_async_fault_source(PWMV2_Type *pwm_x, pwm_channel_t index, pwmv2_async_fault_source_config_t *config);
  1718. /**
  1719. * @brief config pwm
  1720. *
  1721. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1722. * @param index @ref pwm_channel_t
  1723. * @param config @ref pwmv2_config_t
  1724. * @param enable_pair_mode bool
  1725. */
  1726. void pwmv2_config_pwm(PWMV2_Type *pwm_x, pwm_channel_t index, pwmv2_config_t *config, bool enable_pair_mode);
  1727. /**
  1728. * @brief Set pwm waveform
  1729. *
  1730. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1731. * @param chn @ref pwm_channel_t
  1732. * @param pwm_config @ref pwmv2_config_t
  1733. * @param cmp_start_index cmp start index
  1734. * @param cmp @ref pwmv2_cmp_config_t
  1735. * @param cmp_num cmp number
  1736. * @return hpm_stat_t @ref hpm_stat_t
  1737. */
  1738. hpm_stat_t pwmv2_setup_waveform(PWMV2_Type *pwm_x,
  1739. pwm_channel_t chn, pwmv2_config_t *pwm_config,
  1740. uint8_t cmp_start_index, pwmv2_cmp_config_t *cmp, uint8_t cmp_num);
  1741. /**
  1742. * @brief set the pwm waveform complementary mode
  1743. *
  1744. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1745. * @param chn @ref pwm_channel_t
  1746. * @param pwm_pair_config @ref pwmv2_pair_config_t
  1747. * @param cmp_start_index cmp start index
  1748. * @param cmp @ref pwmv2_cmp_config_t
  1749. * @param cmp_num cmp number
  1750. * @return hpm_stat_t @ref hpm_stat_t
  1751. */
  1752. hpm_stat_t pwmv2_setup_waveform_in_pair(PWMV2_Type *pwm_x, pwm_channel_t chn,
  1753. pwmv2_pair_config_t *pwm_pair_config, uint8_t cmp_start_index,
  1754. pwmv2_cmp_config_t *cmp, uint8_t cmp_num);
  1755. /**
  1756. * @brief Configure the cmp calculate unit
  1757. *
  1758. * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
  1759. * @param cal_index calculate index
  1760. * @param cal @ref pwmv2_cmp_calculate_cfg_t
  1761. */
  1762. void pwmv2_setup_cmp_calculate(PWMV2_Type *pwm_x, uint8_t cal_index, pwmv2_cmp_calculate_cfg_t *cal);
  1763. #ifdef __cplusplus
  1764. }
  1765. #endif
  1766. /**
  1767. * @}
  1768. */
  1769. #endif /* HPM_PWMV2_DRV_H */