gd32e23x_timer.c 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058
  1. /*!
  2. \file gd32e23x_timer.c
  3. \brief TIMER driver
  4. \version 2019-02-19, V1.0.0, firmware for GD32E23x
  5. \version 2020-12-12, V1.1.0, firmware for GD32E23x
  6. */
  7. /*
  8. Copyright (c) 2020, GigaDevice Semiconductor Inc.
  9. Redistribution and use in source and binary forms, with or without modification,
  10. are permitted provided that the following conditions are met:
  11. 1. Redistributions of source code must retain the above copyright notice, this
  12. list of conditions and the following disclaimer.
  13. 2. Redistributions in binary form must reproduce the above copyright notice,
  14. this list of conditions and the following disclaimer in the documentation
  15. and/or other materials provided with the distribution.
  16. 3. Neither the name of the copyright holder nor the names of its contributors
  17. may be used to endorse or promote products derived from this software without
  18. specific prior written permission.
  19. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  23. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  24. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  26. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  28. OF SUCH DAMAGE.
  29. */
  30. #include "gd32e23x_timer.h"
  31. /* TIMER init parameter mask */
  32. #define ALIGNEDMODE_MASK ((uint32_t)0x00000060U) /*!< TIMER init parameter aligne dmode mask */
  33. #define COUNTERDIRECTION_MASK ((uint32_t)0x00000010U) /*!< TIMER init parameter counter direction mask */
  34. #define CLOCKDIVISION_MASK ((uint32_t)0x00000300U) /*!< TIMER init parameter clock division value mask */
  35. /*!
  36. \brief deinit a TIMER
  37. \param[in] timer_periph: TIMERx(x=0,2,5,13..16)
  38. \param[out] none
  39. \retval none
  40. */
  41. void timer_deinit(uint32_t timer_periph)
  42. {
  43. switch(timer_periph){
  44. case TIMER0:
  45. /* reset TIMER0 */
  46. rcu_periph_reset_enable(RCU_TIMER0RST);
  47. rcu_periph_reset_disable(RCU_TIMER0RST);
  48. break;
  49. case TIMER2:
  50. /* reset TIMER2 */
  51. rcu_periph_reset_enable(RCU_TIMER2RST);
  52. rcu_periph_reset_disable(RCU_TIMER2RST);
  53. break;
  54. case TIMER5:
  55. /* reset TIMER5 */
  56. rcu_periph_reset_enable(RCU_TIMER5RST);
  57. rcu_periph_reset_disable(RCU_TIMER5RST);
  58. break;
  59. case TIMER13:
  60. /* reset TIMER13 */
  61. rcu_periph_reset_enable(RCU_TIMER13RST);
  62. rcu_periph_reset_disable(RCU_TIMER13RST);
  63. break;
  64. case TIMER14:
  65. /* reset TIMER14 */
  66. rcu_periph_reset_enable(RCU_TIMER14RST);
  67. rcu_periph_reset_disable(RCU_TIMER14RST);
  68. break;
  69. case TIMER15:
  70. /* reset TIMER15 */
  71. rcu_periph_reset_enable(RCU_TIMER15RST);
  72. rcu_periph_reset_disable(RCU_TIMER15RST);
  73. break;
  74. case TIMER16:
  75. /* reset TIMER16 */
  76. rcu_periph_reset_enable(RCU_TIMER16RST);
  77. rcu_periph_reset_disable(RCU_TIMER16RST);
  78. break;
  79. default:
  80. break;
  81. }
  82. }
  83. /*!
  84. \brief initialize TIMER init parameter struct with a default value
  85. \param[in] initpara: init parameter struct
  86. \param[out] none
  87. \retval none
  88. */
  89. void timer_struct_para_init(timer_parameter_struct* initpara)
  90. {
  91. /* initialize the init parameter struct member with the default value */
  92. initpara->prescaler = 0U;
  93. initpara->alignedmode = TIMER_COUNTER_EDGE;
  94. initpara->counterdirection = TIMER_COUNTER_UP;
  95. initpara->period = 65535U;
  96. initpara->clockdivision = TIMER_CKDIV_DIV1;
  97. initpara->repetitioncounter = 0U;
  98. }
  99. /*!
  100. \brief initialize TIMER counter
  101. \param[in] timer_periph: TIMERx(x=0,2,5,13..16)
  102. \param[in] initpara: init parameter struct
  103. prescaler: prescaler value of the counter clock, 0~65535
  104. alignedmode: TIMER_COUNTER_EDGE, TIMER_COUNTER_CENTER_DOWN, TIMER_COUNTER_CENTER_UP, TIMER_COUNTER_CENTER_BOTH
  105. counterdirection: TIMER_COUNTER_UP, TIMER_COUNTER_DOWN
  106. period: counter auto reload value, 0~65535
  107. clockdivision: TIMER_CKDIV_DIV1, TIMER_CKDIV_DIV2, TIMER_CKDIV_DIV4
  108. repetitioncounter: counter repetition value, 0~255
  109. \param[out] none
  110. \retval none
  111. */
  112. void timer_init(uint32_t timer_periph, timer_parameter_struct* initpara)
  113. {
  114. /* configure the counter prescaler value */
  115. TIMER_PSC(timer_periph) = (uint16_t)initpara->prescaler;
  116. /* configure the counter direction and aligned mode */
  117. if((TIMER0 == timer_periph) || (TIMER2 == timer_periph)){
  118. TIMER_CTL0(timer_periph) &= ~(uint32_t)(TIMER_CTL0_DIR|TIMER_CTL0_CAM);
  119. TIMER_CTL0(timer_periph) |= (uint32_t)initpara->alignedmode;
  120. TIMER_CTL0(timer_periph) |= (uint32_t)initpara->counterdirection;
  121. }
  122. /* configure the autoreload value */
  123. TIMER_CAR(timer_periph) = (uint32_t)initpara->period;
  124. if((TIMER0 == timer_periph) || (TIMER2 == timer_periph) || (TIMER13 == timer_periph)
  125. || (TIMER14 == timer_periph) || (TIMER15 == timer_periph) || (TIMER16 == timer_periph)){
  126. /* reset the CKDIV bit */
  127. TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_CKDIV;
  128. TIMER_CTL0(timer_periph) |= (uint32_t)initpara->clockdivision;
  129. }
  130. if((TIMER0 == timer_periph) || (TIMER14 == timer_periph) || (TIMER15 == timer_periph) || (TIMER16 == timer_periph)){
  131. /* configure the repetition counter value */
  132. TIMER_CREP(timer_periph) = (uint32_t)initpara->repetitioncounter;
  133. }
  134. /* generate an update event */
  135. TIMER_SWEVG(timer_periph) |= (uint32_t)TIMER_SWEVG_UPG;
  136. }
  137. /*!
  138. \brief enable a TIMER
  139. \param[in] timer_periph: TIMERx(x=0,2,5,13..16)
  140. \param[out] none
  141. \retval none
  142. */
  143. void timer_enable(uint32_t timer_periph)
  144. {
  145. TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_CEN;
  146. }
  147. /*!
  148. \brief disable a TIMER
  149. \param[in] timer_periph: TIMERx(x=0,2,5,13..16)
  150. \param[out] none
  151. \retval none
  152. */
  153. void timer_disable(uint32_t timer_periph)
  154. {
  155. TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_CEN;
  156. }
  157. /*!
  158. \brief enable the auto reload shadow function
  159. \param[in] timer_periph: TIMERx(x=0,2,5,13..16)
  160. \param[out] none
  161. \retval none
  162. */
  163. void timer_auto_reload_shadow_enable(uint32_t timer_periph)
  164. {
  165. TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_ARSE;
  166. }
  167. /*!
  168. \brief disable the auto reload shadow function
  169. \param[in] timer_periph: TIMERx(x=0,2,5,13..16)
  170. \param[out] none
  171. \retval none
  172. */
  173. void timer_auto_reload_shadow_disable(uint32_t timer_periph)
  174. {
  175. TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_ARSE;
  176. }
  177. /*!
  178. \brief enable the update event
  179. \param[in] timer_periph: TIMERx(x=0,2,5,13..16)
  180. \param[out] none
  181. \retval none
  182. */
  183. void timer_update_event_enable(uint32_t timer_periph)
  184. {
  185. TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_UPDIS;
  186. }
  187. /*!
  188. \brief disable the update event
  189. \param[in] timer_periph: TIMERx(x=0,2,5,13..16)
  190. \param[out] none
  191. \retval none
  192. */
  193. void timer_update_event_disable(uint32_t timer_periph)
  194. {
  195. TIMER_CTL0(timer_periph) |= (uint32_t) TIMER_CTL0_UPDIS;
  196. }
  197. /*!
  198. \brief set TIMER counter alignment mode
  199. \param[in] timer_periph: TIMERx(x=0,2)
  200. \param[in] aligned:
  201. only one parameter can be selected which is shown as below:
  202. \arg TIMER_COUNTER_EDGE: edge-aligned mode
  203. \arg TIMER_COUNTER_CENTER_DOWN: center-aligned and counting down assert mode
  204. \arg TIMER_COUNTER_CENTER_UP: center-aligned and counting up assert mode
  205. \arg TIMER_COUNTER_CENTER_BOTH: center-aligned and counting up/down assert mode
  206. \param[out] none
  207. \retval none
  208. */
  209. void timer_counter_alignment(uint32_t timer_periph, uint16_t aligned)
  210. {
  211. TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_CAM;
  212. TIMER_CTL0(timer_periph) |= (uint32_t)aligned;
  213. }
  214. /*!
  215. \brief set TIMER counter up direction
  216. \param[in] timer_periph: TIMERx(x=0,2)
  217. \param[out] none
  218. \retval none
  219. */
  220. void timer_counter_up_direction(uint32_t timer_periph)
  221. {
  222. TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_DIR;
  223. }
  224. /*!
  225. \brief set TIMER counter down direction
  226. \param[in] timer_periph: TIMERx(x=0,2)
  227. \param[out] none
  228. \retval none
  229. */
  230. void timer_counter_down_direction(uint32_t timer_periph)
  231. {
  232. TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_DIR;
  233. }
  234. /*!
  235. \brief configure TIMER prescaler
  236. \param[in] timer_periph: TIMERx(x=0,2,5,13..16)
  237. \param[in] prescaler: prescaler value,0~65535
  238. \param[in] pscreload: prescaler reload mode
  239. only one parameter can be selected which is shown as below:
  240. \arg TIMER_PSC_RELOAD_NOW: the prescaler is loaded right now
  241. \arg TIMER_PSC_RELOAD_UPDATE: the prescaler is loaded at the next update event
  242. \param[out] none
  243. \retval none
  244. */
  245. void timer_prescaler_config(uint32_t timer_periph, uint16_t prescaler, uint8_t pscreload)
  246. {
  247. TIMER_PSC(timer_periph) = (uint32_t)prescaler;
  248. if(TIMER_PSC_RELOAD_NOW == pscreload){
  249. TIMER_SWEVG(timer_periph) |= (uint32_t)TIMER_SWEVG_UPG;
  250. }
  251. }
  252. /*!
  253. \brief configure TIMER repetition register value
  254. \param[in] timer_periph: TIMERx(x=0,15,16)
  255. \param[in] repetition: the counter repetition value,0~255
  256. \param[out] none
  257. \retval none
  258. */
  259. void timer_repetition_value_config(uint32_t timer_periph, uint16_t repetition)
  260. {
  261. TIMER_CREP(timer_periph) = (uint32_t)repetition;
  262. }
  263. /*!
  264. \brief configure TIMER autoreload register value
  265. \param[in] timer_periph: TIMERx(x=0,2,5,13..16)
  266. \param[in] autoreload: the counter auto-reload value,0~65535
  267. \param[out] none
  268. \retval none
  269. */
  270. void timer_autoreload_value_config(uint32_t timer_periph, uint16_t autoreload)
  271. {
  272. TIMER_CAR(timer_periph) = (uint32_t)autoreload;
  273. }
  274. /*!
  275. \brief configure TIMER counter register value
  276. \param[in] timer_periph: TIMERx(x=0,2,5,13..16)
  277. \param[in] counter: the counter value,0~65535
  278. \param[out] none
  279. \retval none
  280. */
  281. void timer_counter_value_config(uint32_t timer_periph, uint16_t counter)
  282. {
  283. TIMER_CNT(timer_periph) = (uint32_t)counter;
  284. }
  285. /*!
  286. \brief read TIMER counter value
  287. \param[in] timer_periph: TIMERx(x=0,2,5,13..16)
  288. \param[out] none
  289. \retval counter value
  290. */
  291. uint32_t timer_counter_read(uint32_t timer_periph)
  292. {
  293. uint32_t count_value = 0U;
  294. count_value = TIMER_CNT(timer_periph);
  295. return (count_value);
  296. }
  297. /*!
  298. \brief read TIMER prescaler value
  299. \param[in] timer_periph: TIMERx(x=0,2,5,13..16)
  300. \param[out] none
  301. \retval prescaler register value
  302. */
  303. uint16_t timer_prescaler_read(uint32_t timer_periph)
  304. {
  305. uint16_t prescaler_value = 0U;
  306. prescaler_value = (uint16_t)(TIMER_PSC(timer_periph));
  307. return (prescaler_value);
  308. }
  309. /*!
  310. \brief configure TIMER single pulse mode
  311. \param[in] timer_periph: TIMERx(x=0,2,5,14..16)
  312. \param[in] spmode:
  313. only one parameter can be selected which is shown as below:
  314. \arg TIMER_SP_MODE_SINGLE: single pulse mode
  315. \arg TIMER_SP_MODE_REPETITIVE: repetitive pulse mode
  316. \param[out] none
  317. \retval none
  318. */
  319. void timer_single_pulse_mode_config(uint32_t timer_periph, uint32_t spmode)
  320. {
  321. if(TIMER_SP_MODE_SINGLE == spmode){
  322. TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_SPM;
  323. }else if(TIMER_SP_MODE_REPETITIVE == spmode){
  324. TIMER_CTL0(timer_periph) &= ~((uint32_t)TIMER_CTL0_SPM);
  325. }else{
  326. /* illegal parameters */
  327. }
  328. }
  329. /*!
  330. \brief configure TIMER update source
  331. \param[in] timer_periph: TIMERx(x=0,2,5,13..16)
  332. \param[in] update:
  333. only one parameter can be selected which is shown as below:
  334. \arg TIMER_UPDATE_SRC_GLOBAL: update generate by setting of UPG bit or the counter overflow/underflow,or the slave mode controller trigger
  335. \arg TIMER_UPDATE_SRC_REGULAR: update generate only by counter overflow/underflow
  336. \param[out] none
  337. \retval none
  338. */
  339. void timer_update_source_config(uint32_t timer_periph, uint32_t update)
  340. {
  341. if(TIMER_UPDATE_SRC_REGULAR == update){
  342. TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_UPS;
  343. }else if(TIMER_UPDATE_SRC_GLOBAL == update){
  344. TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_UPS;
  345. }else{
  346. /* illegal parameters */
  347. }
  348. }
  349. /*!
  350. \brief configure TIMER OCPRE clear source selection
  351. \param[in] timer_periph: TIMERx(x=0,2)
  352. \param[in] ocpreclear:
  353. only one parameter can be selected which is shown as below:
  354. \arg TIMER_OCPRE_CLEAR_SOURCE_CLR: OCPRE_CLR_INT is connected to the OCPRE_CLR input
  355. \arg TIMER_OCPRE_CLEAR_SOURCE_ETIF: OCPRE_CLR_INT is connected to ETIF
  356. \param[out] none
  357. \retval none
  358. */
  359. void timer_ocpre_clear_source_config(uint32_t timer_periph, uint8_t ocpreclear)
  360. {
  361. if(TIMER_OCPRE_CLEAR_SOURCE_ETIF == ocpreclear){
  362. TIMER_SMCFG(timer_periph) |= (uint32_t)TIMER_SMCFG_OCRC;
  363. }else if(TIMER_OCPRE_CLEAR_SOURCE_CLR == ocpreclear){
  364. TIMER_SMCFG(timer_periph) &= ~(uint32_t)TIMER_SMCFG_OCRC;
  365. }else{
  366. /* illegal parameters */
  367. }
  368. }
  369. /*!
  370. \brief enable the TIMER interrupt
  371. \param[in] timer_periph: please refer to the following parameters
  372. \param[in] interrupt: timer interrupt enable source
  373. only one parameter can be selected which is shown as below:
  374. \arg TIMER_INT_UP: update interrupt enable, TIMERx(x=0,2,5,13..16)
  375. \arg TIMER_INT_CH0: channel 0 interrupt enable, TIMERx(x=0,2,13..16)
  376. \arg TIMER_INT_CH1: channel 1 interrupt enable, TIMERx(x=0,2,14)
  377. \arg TIMER_INT_CH2: channel 2 interrupt enable, TIMERx(x=0,2)
  378. \arg TIMER_INT_CH3: channel 3 interrupt enable , TIMERx(x=0,2)
  379. \arg TIMER_INT_CMT: commutation interrupt enable, TIMERx(x=0,14..16)
  380. \arg TIMER_INT_TRG: trigger interrupt enable, TIMERx(x=0,2,14)
  381. \arg TIMER_INT_BRK: break interrupt enable, TIMERx(x=0,14..16)
  382. \param[out] none
  383. \retval none
  384. */
  385. void timer_interrupt_enable(uint32_t timer_periph, uint32_t interrupt)
  386. {
  387. TIMER_DMAINTEN(timer_periph) |= (uint32_t) interrupt;
  388. }
  389. /*!
  390. \brief disable the TIMER interrupt
  391. \param[in] timer_periph: please refer to the following parameters
  392. \param[in] interrupt: timer interrupt source disable
  393. only one parameter can be selected which is shown as below:
  394. \arg TIMER_INT_UP: update interrupt enable, TIMERx(x=0,2,5,13..16)
  395. \arg TIMER_INT_CH0: channel 0 interrupt disable, TIMERx(x=0,2,13..16)
  396. \arg TIMER_INT_CH1: channel 1 interrupt disable, TIMERx(x=0,2,14)
  397. \arg TIMER_INT_CH2: channel 2 interrupt disable, TIMERx(x=0,2)
  398. \arg TIMER_INT_CH3: channel 3 interrupt disable , TIMERx(x=0,2)
  399. \arg TIMER_INT_CMT: commutation interrupt disable, TIMERx(x=0,14..16)
  400. \arg TIMER_INT_TRG: trigger interrupt disable, TIMERx(x=0,2,14)
  401. \arg TIMER_INT_BRK: break interrupt disable, TIMERx(x=0,14..16)
  402. \param[out] none
  403. \retval none
  404. */
  405. void timer_interrupt_disable(uint32_t timer_periph, uint32_t interrupt)
  406. {
  407. TIMER_DMAINTEN(timer_periph) &= (~(uint32_t)interrupt);
  408. }
  409. /*!
  410. \brief get timer interrupt flag
  411. \param[in] timer_periph: please refer to the following parameters
  412. \param[in] interrupt: the timer interrupt bits
  413. only one parameter can be selected which is shown as below:
  414. \arg TIMER_INT_FLAG_UP: update interrupt flag,TIMERx(x=0,2,5,13..16)
  415. \arg TIMER_INT_FLAG_CH0: channel 0 interrupt flag,TIMERx(x=0,2,13..16)
  416. \arg TIMER_INT_FLAG_CH1: channel 1 interrupt flag,TIMERx(x=0,2,14)
  417. \arg TIMER_INT_FLAG_CH2: channel 2 interrupt flag,TIMERx(x=0,2)
  418. \arg TIMER_INT_FLAG_CH3: channel 3 interrupt flag,TIMERx(x=0,2)
  419. \arg TIMER_INT_FLAG_CMT: channel commutation interrupt flag,TIMERx(x=0,14..16)
  420. \arg TIMER_INT_FLAG_TRG: trigger interrupt flag,TIMERx(x=0,2,14)
  421. \arg TIMER_INT_FLAG_BRK: break interrupt flag,TIMERx(x=0,14..16)
  422. \param[out] none
  423. \retval FlagStatus: SET or RESET
  424. */
  425. FlagStatus timer_interrupt_flag_get(uint32_t timer_periph, uint32_t interrupt)
  426. {
  427. uint32_t val;
  428. val = (TIMER_DMAINTEN(timer_periph) & interrupt);
  429. if((RESET != (TIMER_INTF(timer_periph) & interrupt) ) && (RESET != val)){
  430. return SET;
  431. }else{
  432. return RESET;
  433. }
  434. }
  435. /*!
  436. \brief clear TIMER interrupt flag
  437. \param[in] timer_periph: please refer to the following parameters
  438. \param[in] interrupt: the timer interrupt bits
  439. only one parameter can be selected which is shown as below:
  440. \arg TIMER_INT_FLAG_UP: update interrupt flag, TIMERx(x=0,2,5,13..16)
  441. \arg TIMER_INT_FLAG_CH0: channel 0 interrupt flag, TIMERx(x=0,2,13..16)
  442. \arg TIMER_INT_FLAG_CH1: channel 1 interrupt flag, TIMERx(x=0,2,14)
  443. \arg TIMER_INT_FLAG_CH2: channel 2 interrupt flag, TIMERx(x=0,2)
  444. \arg TIMER_INT_FLAG_CH3: channel 3 interrupt flag, TIMERx(x=0,2)
  445. \arg TIMER_INT_FLAG_CMT: channel commutation interrupt flag, TIMERx(x=0,14..16)
  446. \arg TIMER_INT_FLAG_TRG: trigger interrupt flag, TIMERx(x=0,2,14)
  447. \arg TIMER_INT_FLAG_BRK: break interrupt flag, TIMERx(x=0,14..16)
  448. \param[out] none
  449. \retval none
  450. */
  451. void timer_interrupt_flag_clear(uint32_t timer_periph, uint32_t interrupt)
  452. {
  453. TIMER_INTF(timer_periph) = (~(uint32_t)interrupt);
  454. }
  455. /*!
  456. \brief get TIMER flags
  457. \param[in] timer_periph: please refer to the following parameters
  458. \param[in] flag: the timer interrupt flags
  459. only one parameter can be selected which is shown as below:
  460. \arg TIMER_FLAG_UP: update flag, TIMERx(x=0,2,5,13..16)
  461. \arg TIMER_FLAG_CH0: channel 0 flag, TIMERx(x=0,2,13..16)
  462. \arg TIMER_FLAG_CH1: channel 1 flag, TIMERx(x=0,2,14)
  463. \arg TIMER_FLAG_CH2: channel 2 flag, TIMERx(x=0,2)
  464. \arg TIMER_FLAG_CH3: channel 3 flag, TIMERx(x=0,2)
  465. \arg TIMER_FLAG_CMT: channel control update flag, TIMERx(x=0,14..16)
  466. \arg TIMER_FLAG_TRG: trigger flag, TIMERx(x=0,2,14)
  467. \arg TIMER_FLAG_BRK: break flag,TIMERx(x=0,14..16)
  468. \arg TIMER_FLAG_CH0O: channel 0 overcapture flag, TIMERx(x=0,2,13..16)
  469. \arg TIMER_FLAG_CH1O: channel 1 overcapture flag, TIMERx(x=0,2,14)
  470. \arg TIMER_FLAG_CH2O: channel 2 overcapture flag, TIMERx(x=0,2)
  471. \arg TIMER_FLAG_CH3O: channel 3 overcapture flag, TIMERx(x=0,2)
  472. \param[out] none
  473. \retval FlagStatus: SET or RESET
  474. */
  475. FlagStatus timer_flag_get(uint32_t timer_periph, uint32_t flag)
  476. {
  477. if(RESET != (TIMER_INTF(timer_periph) & flag)){
  478. return SET;
  479. }else{
  480. return RESET;
  481. }
  482. }
  483. /*!
  484. \brief clear TIMER flags
  485. \param[in] timer_periph: please refer to the following parameters
  486. \param[in] flag: the timer interrupt flags
  487. only one parameter can be selected which is shown as below:
  488. \arg TIMER_FLAG_UP: update flag, TIMERx(x=0,2,5,13..16)
  489. \arg TIMER_FLAG_CH0: channel 0 flag, TIMERx(x=0,2,13..16)
  490. \arg TIMER_FLAG_CH1: channel 1 flag, TIMERx(x=0,2,14)
  491. \arg TIMER_FLAG_CH2: channel 2 flag, TIMERx(x=0,2)
  492. \arg TIMER_FLAG_CH3: channel 3 flag, TIMERx(x=0,2)
  493. \arg TIMER_FLAG_CMT: channel control update flag, TIMERx(x=0,14..16)
  494. \arg TIMER_FLAG_TRG: trigger flag, TIMERx(x=0,2,14)
  495. \arg TIMER_FLAG_BRK: break flag,TIMERx(x=0,14..16)
  496. \arg TIMER_FLAG_CH0O: channel 0 overcapture flag, TIMERx(x=0,2,13..16)
  497. \arg TIMER_FLAG_CH1O: channel 1 overcapture flag, TIMERx(x=0,2,14)
  498. \arg TIMER_FLAG_CH2O: channel 2 overcapture flag, TIMERx(x=0,2)
  499. \arg TIMER_FLAG_CH3O: channel 3 overcapture flag, TIMERx(x=0,2)
  500. \param[out] none
  501. \retval none
  502. */
  503. void timer_flag_clear(uint32_t timer_periph, uint32_t flag)
  504. {
  505. TIMER_INTF(timer_periph) = (~(uint32_t)flag);
  506. }
  507. /*!
  508. \brief enable the TIMER DMA
  509. \param[in] timer_periph: please refer to the following parameters
  510. \param[in] dma: specify which DMA to enable
  511. one or more parameters can be selected which is shown as below:
  512. \arg TIMER_DMA_UPD: update DMA, TIMERx(x=0,2,5,14..16)
  513. \arg TIMER_DMA_CH0D: channel 0 DMA request, TIMERx(x=0,2,14..16)
  514. \arg TIMER_DMA_CH1D: channel 1 DMA request, TIMERx(x=0,2,14)
  515. \arg TIMER_DMA_CH2D: channel 2 DMA request, TIMERx(x=0,2)
  516. \arg TIMER_DMA_CH3D: channel 3 DMA request, TIMERx(x=0,2)
  517. \arg TIMER_DMA_CMTD: commutation DMA request, TIMERx(x=0,14)
  518. \arg TIMER_DMA_TRGD: trigger DMA request, TIMERx(x=0,2,14)
  519. \param[out] none
  520. \retval none
  521. */
  522. void timer_dma_enable(uint32_t timer_periph, uint16_t dma)
  523. {
  524. TIMER_DMAINTEN(timer_periph) |= (uint32_t) dma;
  525. }
  526. /*!
  527. \brief disable the TIMER DMA
  528. \param[in] timer_periph: please refer to the following parameters
  529. \param[in] dma: specify which DMA to disable
  530. one or more parameters can be selected which are shown as below:
  531. \arg TIMER_DMA_UPD: update DMA, TIMERx(x=0,2,5,14..16)
  532. \arg TIMER_DMA_CH0D: channel 0 DMA request, TIMERx(x=0,2,14..16)
  533. \arg TIMER_DMA_CH1D: channel 1 DMA request, TIMERx(x=0,2,14)
  534. \arg TIMER_DMA_CH2D: channel 2 DMA request, TIMERx(x=0,2)
  535. \arg TIMER_DMA_CH3D: channel 3 DMA request, TIMERx(x=0,2)
  536. \arg TIMER_DMA_CMTD: commutation DMA request , TIMERx(x=0,14)
  537. \arg TIMER_DMA_TRGD: trigger DMA request, TIMERx(x=0,2,14)
  538. \param[out] none
  539. \retval none
  540. */
  541. void timer_dma_disable(uint32_t timer_periph, uint16_t dma)
  542. {
  543. TIMER_DMAINTEN(timer_periph) &= (~(uint32_t)(dma));
  544. }
  545. /*!
  546. \brief channel DMA request source selection
  547. \param[in] timer_periph: TIMERx(x=0,2,14..16)
  548. \param[in] dma_request: channel DMA request source selection
  549. only one parameter can be selected which is shown as below:
  550. \arg TIMER_DMAREQUEST_CHANNELEVENT: DMA request of channel y is sent when channel y event occurs
  551. \arg TIMER_DMAREQUEST_UPDATEEVENT: DMA request of channel y is sent when update event occurs
  552. \param[out] none
  553. \retval none
  554. */
  555. void timer_channel_dma_request_source_select(uint32_t timer_periph, uint8_t dma_request)
  556. {
  557. if(TIMER_DMAREQUEST_UPDATEEVENT == dma_request){
  558. TIMER_CTL1(timer_periph) |= (uint32_t)TIMER_CTL1_DMAS;
  559. }else if(TIMER_DMAREQUEST_CHANNELEVENT == dma_request){
  560. TIMER_CTL1(timer_periph) &= ~(uint32_t)TIMER_CTL1_DMAS;
  561. }else{
  562. /* illegal parameters */
  563. }
  564. }
  565. /*!
  566. \brief configure the TIMER DMA transfer
  567. \param[in] timer_periph: TIMERx(x=0,2,14..16)
  568. \param[in] dma_baseaddr:
  569. only one parameter can be selected which is shown as below:
  570. \arg TIMER_DMACFG_DMATA_CTL0: DMA transfer address is TIMER_CTL0, TIMERx(x=0,2,14..16)
  571. \arg TIMER_DMACFG_DMATA_CTL1: DMA transfer address is TIMER_CTL1, TIMERx(x=0,2,14..16)
  572. \arg TIMER_DMACFG_DMATA_SMCFG: DMA transfer address is TIMER_SMCFG, TIMERx(x=0,2,14)
  573. \arg TIMER_DMACFG_DMATA_DMAINTEN: DMA transfer address is TIMER_DMAINTEN, TIMERx(x=0,2,14..16)
  574. \arg TIMER_DMACFG_DMATA_INTF: DMA transfer address is TIMER_INTF, TIMERx(x=0,2,14..16)
  575. \arg TIMER_DMACFG_DMATA_SWEVG: DMA transfer address is TIMER_SWEVG, TIMERx(x=0,2,14..16)
  576. \arg TIMER_DMACFG_DMATA_CHCTL0: DMA transfer address is TIMER_CHCTL0, TIMERx(x=0,2,14..16)
  577. \arg TIMER_DMACFG_DMATA_CHCTL1: DMA transfer address is TIMER_CHCTL1, TIMERx(x=0,2)
  578. \arg TIMER_DMACFG_DMATA_CHCTL2: DMA transfer address is TIMER_CHCTL2, TIMERx(x=0,2,14..16)
  579. \arg TIMER_DMACFG_DMATA_CNT: DMA transfer address is TIMER_CNT, TIMERx(x=0,2,14..16)
  580. \arg TIMER_DMACFG_DMATA_PSC: DMA transfer address is TIMER_PSC, TIMERx(x=0,2,14..16)
  581. \arg TIMER_DMACFG_DMATA_CAR: DMA transfer address is TIMER_CAR, TIMERx(x=0,2,14..16)
  582. \arg TIMER_DMACFG_DMATA_CREP: DMA transfer address is TIMER_CREP, TIMERx(x=0,14..16)
  583. \arg TIMER_DMACFG_DMATA_CH0CV: DMA transfer address is TIMER_CH0CV, TIMERx(x=0,2,14..16)
  584. \arg TIMER_DMACFG_DMATA_CH1CV: DMA transfer address is TIMER_CH1CV, TIMERx(x=0,2,14)
  585. \arg TIMER_DMACFG_DMATA_CH2CV: DMA transfer address is TIMER_CH2CV, TIMERx(x=0,2)
  586. \arg TIMER_DMACFG_DMATA_CH3CV: DMA transfer address is TIMER_CH3CV, TIMERx(x=0,2)
  587. \arg TIMER_DMACFG_DMATA_CCHP: DMA transfer address is TIMER_CCHP, TIMERx(x=0,14..16)
  588. \arg TIMER_DMACFG_DMATA_DMACFG: DMA transfer address is TIMER_DMACFG, TIMERx(x=0,2,14..16)
  589. \param[in] dma_lenth:
  590. only one parameter can be selected which is shown as below:
  591. \arg TIMER_DMACFG_DMATC_xTRANSFER(x=1..18): DMA transfer x time
  592. \param[out] none
  593. \retval none
  594. */
  595. void timer_dma_transfer_config(uint32_t timer_periph, uint32_t dma_baseaddr, uint32_t dma_lenth)
  596. {
  597. TIMER_DMACFG(timer_periph) &= (~(uint32_t)(TIMER_DMACFG_DMATA | TIMER_DMACFG_DMATC));
  598. TIMER_DMACFG(timer_periph) |= (uint32_t)(dma_baseaddr | dma_lenth);
  599. }
  600. /*!
  601. \brief software generate events
  602. \param[in] timer_periph: please refer to the following parameters
  603. \param[in] event: the timer software event generation sources
  604. one or more parameters can be selected which are shown as below:
  605. \arg TIMER_EVENT_SRC_UPG: update event,TIMERx(x=0,2,5,13..16)
  606. \arg TIMER_EVENT_SRC_CH0G: channel 0 capture or compare event generation, TIMERx(x=0,2,13..16)
  607. \arg TIMER_EVENT_SRC_CH1G: channel 1 capture or compare event generation, TIMERx(x=0,2,14)
  608. \arg TIMER_EVENT_SRC_CH2G: channel 2 capture or compare event generation, TIMERx(x=0,2)
  609. \arg TIMER_EVENT_SRC_CH3G: channel 3 capture or compare event generation, TIMERx(x=0,2)
  610. \arg TIMER_EVENT_SRC_CMTG: channel commutation event generation, TIMERx(x=0,14..16)
  611. \arg TIMER_EVENT_SRC_TRGG: trigger event generation, TIMERx(x=0,2,14)
  612. \arg TIMER_EVENT_SRC_BRKG: break event generation, TIMERx(x=0,14..16)
  613. \param[out] none
  614. \retval none
  615. */
  616. void timer_event_software_generate(uint32_t timer_periph, uint16_t event)
  617. {
  618. TIMER_SWEVG(timer_periph) |= (uint32_t)event;
  619. }
  620. /*!
  621. \brief initialize TIMER break parameter struct with a default value
  622. \param[in] breakpara: TIMER break parameter struct
  623. \param[out] none
  624. \retval none
  625. */
  626. void timer_break_struct_para_init(timer_break_parameter_struct* breakpara)
  627. {
  628. /* initialize the break parameter struct member with the default value */
  629. breakpara->runoffstate = TIMER_ROS_STATE_DISABLE;
  630. breakpara->ideloffstate = TIMER_IOS_STATE_DISABLE;
  631. breakpara->deadtime = 0U;
  632. breakpara->breakpolarity = TIMER_BREAK_POLARITY_LOW;
  633. breakpara->outputautostate = TIMER_OUTAUTO_DISABLE;
  634. breakpara->protectmode = TIMER_CCHP_PROT_OFF;
  635. breakpara->breakstate = TIMER_BREAK_DISABLE;
  636. }
  637. /*!
  638. \brief configure TIMER break function
  639. \param[in] timer_periph: TIMERx(x=0,14..16)
  640. \param[in] breakpara: TIMER break parameter struct
  641. runoffstate: TIMER_ROS_STATE_ENABLE,TIMER_ROS_STATE_DISABLE
  642. ideloffstate: TIMER_IOS_STATE_ENABLE,TIMER_IOS_STATE_DISABLE
  643. deadtime: 0~255
  644. breakpolarity: TIMER_BREAK_POLARITY_LOW,TIMER_BREAK_POLARITY_HIGH
  645. outputautostate: TIMER_OUTAUTO_ENABLE,TIMER_OUTAUTO_DISABLE
  646. protectmode: TIMER_CCHP_PROT_OFF,TIMER_CCHP_PROT_0,TIMER_CCHP_PROT_1,TIMER_CCHP_PROT_2
  647. breakstate: TIMER_BREAK_ENABLE,TIMER_BREAK_DISABLE
  648. \param[out] none
  649. \retval none
  650. */
  651. void timer_break_config(uint32_t timer_periph, timer_break_parameter_struct* breakpara)
  652. {
  653. TIMER_CCHP(timer_periph) = (uint32_t)(((uint32_t)(breakpara->runoffstate))|
  654. ((uint32_t)(breakpara->ideloffstate))|
  655. ((uint32_t)(breakpara->deadtime))|
  656. ((uint32_t)(breakpara->breakpolarity))|
  657. ((uint32_t)(breakpara->outputautostate)) |
  658. ((uint32_t)(breakpara->protectmode))|
  659. ((uint32_t)(breakpara->breakstate))) ;
  660. }
  661. /*!
  662. \brief enable TIMER break function
  663. \param[in] timer_periph: TIMERx(x=0,14..16)
  664. \param[out] none
  665. \retval none
  666. */
  667. void timer_break_enable(uint32_t timer_periph)
  668. {
  669. TIMER_CCHP(timer_periph) |= (uint32_t)TIMER_CCHP_BRKEN;
  670. }
  671. /*!
  672. \brief disable TIMER break function
  673. \param[in] timer_periph: TIMERx(x=0,14..16)
  674. \param[out] none
  675. \retval none
  676. */
  677. void timer_break_disable(uint32_t timer_periph)
  678. {
  679. TIMER_CCHP(timer_periph) &= ~(uint32_t)TIMER_CCHP_BRKEN;
  680. }
  681. /*!
  682. \brief enable TIMER output automatic function
  683. \param[in] timer_periph: TIMERx(x=0,14..16)
  684. \param[out] none
  685. \retval none
  686. */
  687. void timer_automatic_output_enable(uint32_t timer_periph)
  688. {
  689. TIMER_CCHP(timer_periph) |= (uint32_t)TIMER_CCHP_OAEN;
  690. }
  691. /*!
  692. \brief disable TIMER output automatic function
  693. \param[in] timer_periph: TIMERx(x=0,14..16)
  694. \param[out] none
  695. \retval none
  696. */
  697. void timer_automatic_output_disable(uint32_t timer_periph)
  698. {
  699. TIMER_CCHP(timer_periph) &= ~(uint32_t)TIMER_CCHP_OAEN;
  700. }
  701. /*!
  702. \brief configure TIMER primary output function
  703. \param[in] timer_periph: TIMERx(x=0,14..16)
  704. \param[in] newvalue: ENABLE or DISABLE
  705. \param[out] none
  706. \retval none
  707. */
  708. void timer_primary_output_config(uint32_t timer_periph, ControlStatus newvalue)
  709. {
  710. if(ENABLE == newvalue){
  711. TIMER_CCHP(timer_periph) |= (uint32_t)TIMER_CCHP_POEN;
  712. }else{
  713. TIMER_CCHP(timer_periph) &= (~(uint32_t)TIMER_CCHP_POEN);
  714. }
  715. }
  716. /*!
  717. \brief enable or disable channel capture/compare control shadow register
  718. \param[in] timer_periph: TIMERx(x=0,14..16)
  719. \param[in] newvalue: ENABLE or DISABLE
  720. \param[out] none
  721. \retval none
  722. */
  723. void timer_channel_control_shadow_config(uint32_t timer_periph, ControlStatus newvalue)
  724. {
  725. if(ENABLE == newvalue){
  726. TIMER_CTL1(timer_periph) |= (uint32_t)TIMER_CTL1_CCSE;
  727. }else{
  728. TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_CCSE);
  729. }
  730. }
  731. /*!
  732. \brief configure TIMER channel control shadow register update control
  733. \param[in] timer_periph: TIMERx(x=0,14..16)
  734. \param[in] ccuctl: channel control shadow register update control
  735. only one parameter can be selected which is shown as below:
  736. \arg TIMER_UPDATECTL_CCU: the shadow registers update by when CMTG bit is set
  737. \arg TIMER_UPDATECTL_CCUTRI: the shadow registers update by when CMTG bit is set or an rising edge of TRGI occurs
  738. \param[out] none
  739. \retval none
  740. */
  741. void timer_channel_control_shadow_update_config(uint32_t timer_periph, uint8_t ccuctl)
  742. {
  743. if(TIMER_UPDATECTL_CCU == ccuctl){
  744. TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_CCUC);
  745. }else if(TIMER_UPDATECTL_CCUTRI == ccuctl){
  746. TIMER_CTL1(timer_periph) |= (uint32_t)TIMER_CTL1_CCUC;
  747. }else{
  748. /* illegal parameters */
  749. }
  750. }
  751. /*!
  752. \brief initialize TIMER channel output parameter struct with a default value
  753. \param[in] ocpara: TIMER channel n output parameter struct
  754. \param[out] none
  755. \retval none
  756. */
  757. void timer_channel_output_struct_para_init(timer_oc_parameter_struct* ocpara)
  758. {
  759. /* initialize the channel output parameter struct member with the default value */
  760. ocpara->outputstate = (uint16_t)TIMER_CCX_DISABLE;
  761. ocpara->outputnstate = TIMER_CCXN_DISABLE;
  762. ocpara->ocpolarity = TIMER_OC_POLARITY_HIGH;
  763. ocpara->ocnpolarity = TIMER_OCN_POLARITY_HIGH;
  764. ocpara->ocidlestate = TIMER_OC_IDLE_STATE_LOW;
  765. ocpara->ocnidlestate = TIMER_OCN_IDLE_STATE_LOW;
  766. }
  767. /*!
  768. \brief configure TIMER channel output function
  769. \param[in] timer_periph: please refer to the following parameters
  770. \param[in] channel:
  771. only one parameter can be selected which is shown as below:
  772. \arg TIMER_CH_0: TIMER channel 0(TIMERx(x=0,2,13..16))
  773. \arg TIMER_CH_1: TIMER channel 1(TIMERx(x=0,2,14))
  774. \arg TIMER_CH_2: TIMER channel 2(TIMERx(x=0,2))
  775. \arg TIMER_CH_3: TIMER channel 3(TIMERx(x=0,2))
  776. \param[in] ocpara: TIMER channeln output parameter struct
  777. outputstate: TIMER_CCX_ENABLE,TIMER_CCX_DISABLE
  778. outputnstate: TIMER_CCXN_ENABLE,TIMER_CCXN_DISABLE
  779. ocpolarity: TIMER_OC_POLARITY_HIGH,TIMER_OC_POLARITY_LOW
  780. ocnpolarity: TIMER_OCN_POLARITY_HIGH,TIMER_OCN_POLARITY_LOW
  781. ocidlestate: TIMER_OC_IDLE_STATE_LOW,TIMER_OC_IDLE_STATE_HIGH
  782. ocnidlestate: TIMER_OCN_IDLE_STATE_LOW,TIMER_OCN_IDLE_STATE_HIGH
  783. \param[out] none
  784. \retval none
  785. */
  786. void timer_channel_output_config(uint32_t timer_periph, uint16_t channel, timer_oc_parameter_struct* ocpara)
  787. {
  788. switch(channel){
  789. /* configure TIMER_CH_0 */
  790. case TIMER_CH_0:
  791. /* reset the CH0EN bit */
  792. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0EN);
  793. TIMER_CHCTL0(timer_periph) &= ~(uint32_t)TIMER_CHCTL0_CH0MS;
  794. /* set the CH0EN bit */
  795. TIMER_CHCTL2(timer_periph) |= (uint32_t)ocpara->outputstate;
  796. /* reset the CH0P bit */
  797. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0P);
  798. /* set the CH0P bit */
  799. TIMER_CHCTL2(timer_periph) |= (uint32_t)ocpara->ocpolarity;
  800. if((TIMER0 == timer_periph) || (TIMER14 == timer_periph) || (TIMER15 == timer_periph) || (TIMER16 == timer_periph)){
  801. /* reset the CH0NEN bit */
  802. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0NEN);
  803. /* set the CH0NEN bit */
  804. TIMER_CHCTL2(timer_periph) |= (uint32_t)ocpara->outputnstate;
  805. /* reset the CH0NP bit */
  806. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0NP);
  807. /* set the CH0NP bit */
  808. TIMER_CHCTL2(timer_periph) |= (uint32_t)ocpara->ocnpolarity;
  809. /* reset the ISO0 bit */
  810. TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_ISO0);
  811. /* set the ISO0 bit */
  812. TIMER_CTL1(timer_periph) |= (uint32_t)ocpara->ocidlestate;
  813. /* reset the ISO0N bit */
  814. TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_ISO0N);
  815. /* set the ISO0N bit */
  816. TIMER_CTL1(timer_periph) |= (uint32_t)ocpara->ocnidlestate;
  817. }
  818. break;
  819. /* configure TIMER_CH_1 */
  820. case TIMER_CH_1:
  821. /* reset the CH1EN bit */
  822. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
  823. TIMER_CHCTL0(timer_periph) &= ~(uint32_t)TIMER_CHCTL0_CH1MS;
  824. /* set the CH1EN bit */
  825. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)ocpara->outputstate << 4U);
  826. /* reset the CH1P bit */
  827. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1P);
  828. /* set the CH1P bit */
  829. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocpolarity) << 4U);
  830. if(TIMER0 == timer_periph){
  831. /* reset the CH1NEN bit */
  832. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1NEN);
  833. /* set the CH1NEN bit */
  834. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->outputnstate) << 4U);
  835. /* reset the CH1NP bit */
  836. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1NP);
  837. /* set the CH1NP bit */
  838. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocnpolarity) << 4U);
  839. /* reset the ISO1 bit */
  840. TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_ISO1);
  841. /* set the ISO1 bit */
  842. TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocidlestate) << 2U);
  843. /* reset the ISO1N bit */
  844. TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_ISO1N);
  845. /* set the ISO1N bit */
  846. TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocnidlestate) << 2U);
  847. }
  848. if(TIMER14 == timer_periph){
  849. /* reset the ISO1 bit */
  850. TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_ISO1);
  851. /* set the ISO1 bit */
  852. TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocidlestate) << 2U);
  853. }
  854. break;
  855. /* configure TIMER_CH_2 */
  856. case TIMER_CH_2:
  857. /* reset the CH2EN bit */
  858. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2EN);
  859. TIMER_CHCTL1(timer_periph) &= ~(uint32_t)TIMER_CHCTL1_CH2MS;
  860. /* set the CH2EN bit */
  861. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)ocpara->outputstate << 8U);
  862. /* reset the CH2P bit */
  863. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2P);
  864. /* set the CH2P bit */
  865. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocpolarity) << 8U);
  866. if(TIMER0 == timer_periph){
  867. /* reset the CH2NEN bit */
  868. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2NEN);
  869. /* set the CH2NEN bit */
  870. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->outputnstate) << 8U);
  871. /* reset the CH2NP bit */
  872. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2NP);
  873. /* set the CH2NP bit */
  874. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocnpolarity) << 8U);
  875. /* reset the ISO2 bit */
  876. TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_ISO2);
  877. /* set the ISO2 bit */
  878. TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocidlestate) << 4U);
  879. /* reset the ISO2N bit */
  880. TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_ISO2N);
  881. /* set the ISO2N bit */
  882. TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocnidlestate) << 4U);
  883. }
  884. break;
  885. /* configure TIMER_CH_3 */
  886. case TIMER_CH_3:
  887. /* reset the CH3EN bit */
  888. TIMER_CHCTL2(timer_periph) &=(~(uint32_t)TIMER_CHCTL2_CH3EN);
  889. TIMER_CHCTL1(timer_periph) &= ~(uint32_t)TIMER_CHCTL1_CH3MS;
  890. /* set the CH3EN bit */
  891. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)ocpara->outputstate << 12U);
  892. /* reset the CH3P bit */
  893. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH3P);
  894. /* set the CH3P bit */
  895. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocpolarity) << 12U);
  896. if(TIMER0 == timer_periph){
  897. /* reset the ISO3 bit */
  898. TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_ISO3);
  899. /* set the ISO3 bit */
  900. TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocidlestate) << 6U);
  901. }
  902. break;
  903. default:
  904. break;
  905. }
  906. }
  907. /*!
  908. \brief configure TIMER channel output compare mode
  909. \param[in] timer_periph: please refer to the following parameters
  910. \param[in] channel:
  911. only one parameter can be selected which is shown as below:
  912. \arg TIMER_CH_0: TIMER channel0(TIMERx(x=0,2,13..16))
  913. \arg TIMER_CH_1: TIMER channel1(TIMERx(x=0,2,14))
  914. \arg TIMER_CH_2: TIMER channel2(TIMERx(x=0,2))
  915. \arg TIMER_CH_3: TIMER channel3(TIMERx(x=0,2))
  916. \param[in] ocmode: channel output compare mode
  917. only one parameter can be selected which is shown as below:
  918. \arg TIMER_OC_MODE_TIMING: timing mode
  919. \arg TIMER_OC_MODE_ACTIVE: active mode
  920. \arg TIMER_OC_MODE_INACTIVE: inactive mode
  921. \arg TIMER_OC_MODE_TOGGLE: toggle mode
  922. \arg TIMER_OC_MODE_LOW: force low mode
  923. \arg TIMER_OC_MODE_HIGH: force high mode
  924. \arg TIMER_OC_MODE_PWM0: PWM0 mode
  925. \arg TIMER_OC_MODE_PWM1: PWM1 mode
  926. \param[out] none
  927. \retval none
  928. */
  929. void timer_channel_output_mode_config(uint32_t timer_periph, uint16_t channel, uint16_t ocmode)
  930. {
  931. switch(channel){
  932. /* configure TIMER_CH_0 */
  933. case TIMER_CH_0:
  934. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0COMCTL);
  935. TIMER_CHCTL0(timer_periph) |= (uint32_t)ocmode;
  936. break;
  937. /* configure TIMER_CH_1 */
  938. case TIMER_CH_1:
  939. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1COMCTL);
  940. TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(ocmode) << 8U);
  941. break;
  942. /* configure TIMER_CH_2 */
  943. case TIMER_CH_2:
  944. TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH2COMCTL);
  945. TIMER_CHCTL1(timer_periph) |= (uint32_t)ocmode;
  946. break;
  947. /* configure TIMER_CH_3 */
  948. case TIMER_CH_3:
  949. TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH3COMCTL);
  950. TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)(ocmode) << 8U);
  951. break;
  952. default:
  953. break;
  954. }
  955. }
  956. /*!
  957. \brief configure TIMER channel output pulse value
  958. \param[in] timer_periph: please refer to the following parameters
  959. \param[in] channel:
  960. only one parameter can be selected which is shown as below:
  961. \arg TIMER_CH_0: TIMER channel0(TIMERx(x=0,2,13..16))
  962. \arg TIMER_CH_1: TIMER channel1(TIMERx(x=0,2,14))
  963. \arg TIMER_CH_2: TIMER channel2(TIMERx(x=0,2))
  964. \arg TIMER_CH_3: TIMER channel3(TIMERx(x=0,2))
  965. \param[in] pulse: channel output pulse value,0~65535
  966. \param[out] none
  967. \retval none
  968. */
  969. void timer_channel_output_pulse_value_config(uint32_t timer_periph, uint16_t channel, uint32_t pulse)
  970. {
  971. switch(channel){
  972. /* configure TIMER_CH_0 */
  973. case TIMER_CH_0:
  974. TIMER_CH0CV(timer_periph) = (uint32_t)pulse;
  975. break;
  976. /* configure TIMER_CH_1 */
  977. case TIMER_CH_1:
  978. TIMER_CH1CV(timer_periph) = (uint32_t)pulse;
  979. break;
  980. /* configure TIMER_CH_2 */
  981. case TIMER_CH_2:
  982. TIMER_CH2CV(timer_periph) = (uint32_t)pulse;
  983. break;
  984. /* configure TIMER_CH_3 */
  985. case TIMER_CH_3:
  986. TIMER_CH3CV(timer_periph) = (uint32_t)pulse;
  987. break;
  988. default:
  989. break;
  990. }
  991. }
  992. /*!
  993. \brief configure TIMER channel output shadow function
  994. \param[in] timer_periph: please refer to the following parameters
  995. \param[in] channel:
  996. only one parameter can be selected which is shown as below:
  997. \arg TIMER_CH_0: TIMER channel0(TIMERx(x=0,2,13..16))
  998. \arg TIMER_CH_1: TIMER channel1(TIMERx(x=0,2,14))
  999. \arg TIMER_CH_2: TIMER channel2(TIMERx(x=0,2))
  1000. \arg TIMER_CH_3: TIMER channel3(TIMERx(x=0,2))
  1001. \param[in] ocshadow: channel output shadow state
  1002. only one parameter can be selected which is shown as below:
  1003. \arg TIMER_OC_SHADOW_ENABLE: channel output shadow state enable
  1004. \arg TIMER_OC_SHADOW_DISABLE: channel output shadow state disable
  1005. \param[out] none
  1006. \retval none
  1007. */
  1008. void timer_channel_output_shadow_config(uint32_t timer_periph, uint16_t channel, uint16_t ocshadow)
  1009. {
  1010. switch(channel){
  1011. /* configure TIMER_CH_0 */
  1012. case TIMER_CH_0:
  1013. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0COMSEN);
  1014. TIMER_CHCTL0(timer_periph) |= (uint32_t)ocshadow;
  1015. break;
  1016. /* configure TIMER_CH_1 */
  1017. case TIMER_CH_1:
  1018. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1COMSEN);
  1019. TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(ocshadow) << 8U);
  1020. break;
  1021. /* configure TIMER_CH_2 */
  1022. case TIMER_CH_2:
  1023. TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH2COMSEN);
  1024. TIMER_CHCTL1(timer_periph) |= (uint32_t)ocshadow;
  1025. break;
  1026. /* configure TIMER_CH_3 */
  1027. case TIMER_CH_3:
  1028. TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH3COMSEN);
  1029. TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)(ocshadow) << 8U);
  1030. break;
  1031. default:
  1032. break;
  1033. }
  1034. }
  1035. /*!
  1036. \brief configure TIMER channel output fast function
  1037. \param[in] timer_periph: please refer to the following parameters
  1038. \param[in] channel:
  1039. only one parameter can be selected which is shown as below:
  1040. \arg TIMER_CH_0: TIMER channel0(TIMERx(x=0,2,13..16))
  1041. \arg TIMER_CH_1: TIMER channel1(TIMERx(x=0,2,14))
  1042. \arg TIMER_CH_2: TIMER channel2(TIMERx(x=0,2))
  1043. \arg TIMER_CH_3: TIMER channel3(TIMERx(x=0,2))
  1044. \param[in] ocfast: channel output fast function
  1045. only one parameter can be selected which is shown as below:
  1046. \arg TIMER_OC_FAST_ENABLE: channel output fast function enable
  1047. \arg TIMER_OC_FAST_DISABLE: channel output fast function disable
  1048. \param[out] none
  1049. \retval none
  1050. */
  1051. void timer_channel_output_fast_config(uint32_t timer_periph, uint16_t channel, uint16_t ocfast)
  1052. {
  1053. switch(channel){
  1054. /* configure TIMER_CH_0 */
  1055. case TIMER_CH_0:
  1056. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0COMFEN);
  1057. TIMER_CHCTL0(timer_periph) |= (uint32_t)ocfast;
  1058. break;
  1059. /* configure TIMER_CH_1 */
  1060. case TIMER_CH_1:
  1061. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1COMFEN);
  1062. TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)ocfast << 8U);
  1063. break;
  1064. /* configure TIMER_CH_2 */
  1065. case TIMER_CH_2:
  1066. TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH2COMFEN);
  1067. TIMER_CHCTL1(timer_periph) |= (uint32_t)ocfast;
  1068. break;
  1069. /* configure TIMER_CH_3 */
  1070. case TIMER_CH_3:
  1071. TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH3COMFEN);
  1072. TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)ocfast << 8U);
  1073. break;
  1074. default:
  1075. break;
  1076. }
  1077. }
  1078. /*!
  1079. \brief configure TIMER channel output clear function
  1080. \param[in] timer_periph: please refer to the following parameters
  1081. \param[in] channel:
  1082. only one parameter can be selected which is shown as below:
  1083. \arg TIMER_CH_0: TIMER channel0(TIMERx(x=0,2))
  1084. \arg TIMER_CH_1: TIMER channel1(TIMERx(x=0,2))
  1085. \arg TIMER_CH_2: TIMER channel2(TIMERx(x=0,2))
  1086. \arg TIMER_CH_3: TIMER channel3(TIMERx(x=0,2))
  1087. \param[in] occlear: channel output clear function
  1088. only one parameter can be selected which is shown as below:
  1089. \arg TIMER_OC_CLEAR_ENABLE: channel output clear function enable
  1090. \arg TIMER_OC_CLEAR_DISABLE: channel output clear function disable
  1091. \param[out] none
  1092. \retval none
  1093. */
  1094. void timer_channel_output_clear_config(uint32_t timer_periph, uint16_t channel, uint16_t occlear)
  1095. {
  1096. switch(channel){
  1097. /* configure TIMER_CH_0 */
  1098. case TIMER_CH_0:
  1099. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0COMCEN);
  1100. TIMER_CHCTL0(timer_periph) |= (uint32_t)occlear;
  1101. break;
  1102. /* configure TIMER_CH_1 */
  1103. case TIMER_CH_1:
  1104. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1COMCEN);
  1105. TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)occlear << 8U);
  1106. break;
  1107. /* configure TIMER_CH_2 */
  1108. case TIMER_CH_2:
  1109. TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH2COMCEN);
  1110. TIMER_CHCTL1(timer_periph) |= (uint32_t)occlear;
  1111. break;
  1112. /* configure TIMER_CH_3 */
  1113. case TIMER_CH_3:
  1114. TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH3COMCEN);
  1115. TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)occlear << 8U);
  1116. break;
  1117. default:
  1118. break;
  1119. }
  1120. }
  1121. /*!
  1122. \brief configure TIMER channel output polarity
  1123. \param[in] timer_periph: please refer to the following parameters
  1124. \param[in] channel:
  1125. only one parameter can be selected which is shown as below:
  1126. \arg TIMER_CH_0: TIMER channel0(TIMERx(x=0,2,13..16))
  1127. \arg TIMER_CH_1: TIMER channel1(TIMERx(x=0,2,14))
  1128. \arg TIMER_CH_2: TIMER channel2(TIMERx(x=0,2))
  1129. \arg TIMER_CH_3: TIMER channel3(TIMERx(x=0,2))
  1130. \param[in] ocpolarity: channel output polarity
  1131. only one parameter can be selected which is shown as below:
  1132. \arg TIMER_OC_POLARITY_HIGH: channel output polarity is high
  1133. \arg TIMER_OC_POLARITY_LOW: channel output polarity is low
  1134. \param[out] none
  1135. \retval none
  1136. */
  1137. void timer_channel_output_polarity_config(uint32_t timer_periph, uint16_t channel, uint16_t ocpolarity)
  1138. {
  1139. switch(channel){
  1140. /* configure TIMER_CH_0 */
  1141. case TIMER_CH_0:
  1142. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0P);
  1143. TIMER_CHCTL2(timer_periph) |= (uint32_t)ocpolarity;
  1144. break;
  1145. /* configure TIMER_CH_1 */
  1146. case TIMER_CH_1:
  1147. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1P);
  1148. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)ocpolarity << 4U);
  1149. break;
  1150. /* configure TIMER_CH_2 */
  1151. case TIMER_CH_2:
  1152. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2P);
  1153. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)ocpolarity << 8U);
  1154. break;
  1155. /* configure TIMER_CH_3 */
  1156. case TIMER_CH_3:
  1157. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH3P);
  1158. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)ocpolarity << 12U);
  1159. break;
  1160. default:
  1161. break;
  1162. }
  1163. }
  1164. /*!
  1165. \brief configure TIMER channel complementary output polarity
  1166. \param[in] timer_periph: TIMERx(x=0,2,14)
  1167. \param[in] channel:
  1168. only one parameter can be selected which is shown as below:
  1169. \arg TIMER_CH_0: TIMER channel0(TIMERx(x=0,2,13..16))
  1170. \arg TIMER_CH_1: TIMER channel1(TIMERx(x=0,2,14))
  1171. \arg TIMER_CH_2: TIMER channel2(TIMERx(x=0,2))
  1172. \arg TIMER_CH_3: TIMER channel2(TIMERx(x=0,2))
  1173. \param[in] ocnpolarity: channel complementary output polarity
  1174. only one parameter can be selected which is shown as below:
  1175. \arg TIMER_OCN_POLARITY_HIGH: channel complementary output polarity is high
  1176. \arg TIMER_OCN_POLARITY_LOW: channel complementary output polarity is low
  1177. \param[out] none
  1178. \retval none
  1179. */
  1180. void timer_channel_complementary_output_polarity_config(uint32_t timer_periph, uint16_t channel, uint16_t ocnpolarity)
  1181. {
  1182. switch(channel){
  1183. /* configure TIMER_CH_0 */
  1184. case TIMER_CH_0:
  1185. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0NP);
  1186. TIMER_CHCTL2(timer_periph) |= (uint32_t)ocnpolarity;
  1187. break;
  1188. /* configure TIMER_CH_1 */
  1189. case TIMER_CH_1:
  1190. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1NP);
  1191. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)ocnpolarity << 4U);
  1192. break;
  1193. /* configure TIMER_CH_2 */
  1194. case TIMER_CH_2:
  1195. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2NP);
  1196. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)ocnpolarity << 8U);
  1197. break;
  1198. /* configure TIMER_CH_3 */
  1199. case TIMER_CH_3:
  1200. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH3NP);
  1201. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)ocnpolarity << 12U);
  1202. break;
  1203. default:
  1204. break;
  1205. }
  1206. }
  1207. /*!
  1208. \brief configure TIMER channel enable state
  1209. \param[in] timer_periph: please refer to the following parameters
  1210. \param[in] channel:
  1211. only one parameter can be selected which is shown as below:
  1212. \arg TIMER_CH_0: TIMER channel0(TIMERx(x=0,2,13..16))
  1213. \arg TIMER_CH_1: TIMER channel1(TIMERx(x=0,2,14))
  1214. \arg TIMER_CH_2: TIMER channel2(TIMERx(x=0,2))
  1215. \arg TIMER_CH_3: TIMER channel3(TIMERx(x=0,2))
  1216. \param[in] state: TIMER channel enable state
  1217. only one parameter can be selected which is shown as below:
  1218. \arg TIMER_CCX_ENABLE: channel enable
  1219. \arg TIMER_CCX_DISABLE: channel disable
  1220. \param[out] none
  1221. \retval none
  1222. */
  1223. void timer_channel_output_state_config(uint32_t timer_periph, uint16_t channel, uint32_t state)
  1224. {
  1225. switch(channel){
  1226. /* configure TIMER_CH_0 */
  1227. case TIMER_CH_0:
  1228. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0EN);
  1229. TIMER_CHCTL2(timer_periph) |= (uint32_t)state;
  1230. break;
  1231. /* configure TIMER_CH_1 */
  1232. case TIMER_CH_1:
  1233. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
  1234. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)state << 4U);
  1235. break;
  1236. /* configure TIMER_CH_2 */
  1237. case TIMER_CH_2:
  1238. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2EN);
  1239. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)state << 8U);
  1240. break;
  1241. /* configure TIMER_CH_3 */
  1242. case TIMER_CH_3:
  1243. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH3EN);
  1244. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)state << 12U);
  1245. break;
  1246. default:
  1247. break;
  1248. }
  1249. }
  1250. /*!
  1251. \brief configure TIMER channel complementary output enable state
  1252. \param[in] timer_periph: TIMERx(x=0,14..16)
  1253. \param[in] channel:
  1254. only one parameter can be selected which is shown as below:
  1255. \arg TIMER_CH_0: TIMER channel0(TIMERx(x=0,14..16))
  1256. \arg TIMER_CH_1: TIMER channel1(TIMERx(x=0))
  1257. \arg TIMER_CH_2: TIMER channel2(TIMERx(x=0))
  1258. \param[in] ocnstate: TIMER channel complementary output enable state
  1259. only one parameter can be selected which is shown as below:
  1260. \arg TIMER_CCXN_ENABLE: channel complementary enable
  1261. \arg TIMER_CCXN_DISABLE: channel complementary disable
  1262. \param[out] none
  1263. \retval none
  1264. */
  1265. void timer_channel_complementary_output_state_config(uint32_t timer_periph, uint16_t channel, uint16_t ocnstate)
  1266. {
  1267. switch(channel){
  1268. /* configure TIMER_CH_0 */
  1269. case TIMER_CH_0:
  1270. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0NEN);
  1271. TIMER_CHCTL2(timer_periph) |= (uint32_t)ocnstate;
  1272. break;
  1273. /* configure TIMER_CH_1 */
  1274. case TIMER_CH_1:
  1275. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1NEN);
  1276. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)ocnstate << 4U);
  1277. break;
  1278. /* configure TIMER_CH_2 */
  1279. case TIMER_CH_2:
  1280. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2NEN);
  1281. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)ocnstate << 8U);
  1282. break;
  1283. default:
  1284. break;
  1285. }
  1286. }
  1287. /*!
  1288. \brief initialize TIMER channel input parameter struct with a default value
  1289. \param[in] icpara: TIMER channel intput parameter struct
  1290. \param[out] none
  1291. \retval none
  1292. */
  1293. void timer_channel_input_struct_para_init(timer_ic_parameter_struct* icpara)
  1294. {
  1295. /* initialize the channel input parameter struct member with the default value */
  1296. icpara->icpolarity = TIMER_IC_POLARITY_RISING;
  1297. icpara->icselection = TIMER_IC_SELECTION_DIRECTTI;
  1298. icpara->icprescaler = TIMER_IC_PSC_DIV1;
  1299. icpara->icfilter = 0U;
  1300. }
  1301. /*!
  1302. \brief configure TIMER input capture parameter
  1303. \param[in] timer_periph: please refer to the following parameters
  1304. \param[in] channel:
  1305. only one parameter can be selected which is shown as below:
  1306. \arg TIMER_CH_0: TIMER channel0(TIMERx(x=0,2,13..16))
  1307. \arg TIMER_CH_1: TIMER channel1(TIMERx(x=0,2,14))
  1308. \arg TIMER_CH_2: TIMER channel2(TIMERx(x=0,2))
  1309. \arg TIMER_CH_3: TIMER channel3(TIMERx(x=0,2))
  1310. \param[in] icpara: TIMER channel intput parameter struct
  1311. icpolarity: TIMER_IC_POLARITY_RISING,TIMER_IC_POLARITY_FALLING,TIMER_IC_POLARITY_BOTH_EDGE
  1312. icselection: TIMER_IC_SELECTION_DIRECTTI,TIMER_IC_SELECTION_INDIRECTTI,TIMER_IC_SELECTION_ITS
  1313. icprescaler: TIMER_IC_PSC_DIV1,TIMER_IC_PSC_DIV2,TIMER_IC_PSC_DIV4,TIMER_IC_PSC_DIV8
  1314. icfilter: 0~15
  1315. \param[out] none
  1316. \retval none
  1317. */
  1318. void timer_input_capture_config(uint32_t timer_periph,uint16_t channel, timer_ic_parameter_struct* icpara)
  1319. {
  1320. switch(channel){
  1321. /* configure TIMER_CH_0 */
  1322. case TIMER_CH_0:
  1323. /* reset the CH0EN bit */
  1324. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0EN);
  1325. /* reset the CH0P and CH0NP bits */
  1326. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH0P | TIMER_CHCTL2_CH0NP));
  1327. TIMER_CHCTL2(timer_periph) |= (uint32_t)(icpara->icpolarity);
  1328. /* reset the CH0MS bit */
  1329. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0MS);
  1330. TIMER_CHCTL0(timer_periph) |= (uint32_t)(icpara->icselection);
  1331. /* reset the CH0CAPFLT bit */
  1332. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0CAPFLT);
  1333. TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(icpara->icfilter) << 4U);
  1334. /* set the CH0EN bit */
  1335. TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH0EN;
  1336. break;
  1337. /* configure TIMER_CH_1 */
  1338. case TIMER_CH_1:
  1339. /* reset the CH1EN bit */
  1340. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
  1341. /* reset the CH1P and CH1NP bits */
  1342. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH1P | TIMER_CHCTL2_CH1NP));
  1343. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(icpara->icpolarity) << 4U);
  1344. /* reset the CH1MS bit */
  1345. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1MS);
  1346. TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(icpara->icselection) << 8U);
  1347. /* reset the CH1CAPFLT bit */
  1348. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1CAPFLT);
  1349. TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(icpara->icfilter) << 12U);
  1350. /* set the CH1EN bit */
  1351. TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH1EN;
  1352. break;
  1353. /* configure TIMER_CH_2 */
  1354. case TIMER_CH_2:
  1355. /* reset the CH2EN bit */
  1356. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2EN);
  1357. /* reset the CH2P and CH2NP bits */
  1358. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH2P|TIMER_CHCTL2_CH2NP));
  1359. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(icpara->icpolarity) << 8U);
  1360. /* reset the CH2MS bit */
  1361. TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH2MS);
  1362. TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)(icpara->icselection));
  1363. /* reset the CH2CAPFLT bit */
  1364. TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH2CAPFLT);
  1365. TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)(icpara->icfilter) << 4U);
  1366. /* set the CH2EN bit */
  1367. TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH2EN;
  1368. break;
  1369. /* configure TIMER_CH_3 */
  1370. case TIMER_CH_3:
  1371. /* reset the CH3EN bit */
  1372. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH3EN);
  1373. /* reset the CH3P and CH3NP bits */
  1374. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH3P|TIMER_CHCTL2_CH3NP));
  1375. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(icpara->icpolarity) << 12U);
  1376. /* reset the CH3MS bit */
  1377. TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH3MS);
  1378. TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)(icpara->icselection) << 8U);
  1379. /* reset the CH3CAPFLT bit */
  1380. TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH3CAPFLT);
  1381. TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)(icpara->icfilter) << 12U);
  1382. /* set the CH3EN bit */
  1383. TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH3EN;
  1384. break;
  1385. default:
  1386. break;
  1387. }
  1388. /* configure TIMER channel input capture prescaler value */
  1389. timer_channel_input_capture_prescaler_config(timer_periph, channel, (uint16_t)(icpara->icprescaler));
  1390. }
  1391. /*!
  1392. \brief configure TIMER channel input capture prescaler value
  1393. \param[in] timer_periph: please refer to the following parameters
  1394. \param[in] channel:
  1395. only one parameter can be selected which is shown as below:
  1396. \arg TIMER_CH_0: TIMER channel0(TIMERx(x=0,2,13..16))
  1397. \arg TIMER_CH_1: TIMER channel1(TIMERx(x=0,2,14))
  1398. \arg TIMER_CH_2: TIMER channel2(TIMERx(x=0,2))
  1399. \arg TIMER_CH_3: TIMER channel3(TIMERx(x=0,2))
  1400. \param[in] prescaler: channel input capture prescaler value
  1401. only one parameter can be selected which is shown as below:
  1402. \arg TIMER_IC_PSC_DIV1: no prescaler
  1403. \arg TIMER_IC_PSC_DIV2: divided by 2
  1404. \arg TIMER_IC_PSC_DIV4: divided by 4
  1405. \arg TIMER_IC_PSC_DIV8: divided by 8
  1406. \param[out] none
  1407. \retval none
  1408. */
  1409. void timer_channel_input_capture_prescaler_config(uint32_t timer_periph, uint16_t channel, uint16_t prescaler)
  1410. {
  1411. switch(channel){
  1412. /* configure TIMER_CH_0 */
  1413. case TIMER_CH_0:
  1414. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0CAPPSC);
  1415. TIMER_CHCTL0(timer_periph) |= (uint32_t)prescaler;
  1416. break;
  1417. /* configure TIMER_CH_1 */
  1418. case TIMER_CH_1:
  1419. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1CAPPSC);
  1420. TIMER_CHCTL0(timer_periph) |= ((uint32_t)prescaler << 8U);
  1421. break;
  1422. /* configure TIMER_CH_2 */
  1423. case TIMER_CH_2:
  1424. TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH2CAPPSC);
  1425. TIMER_CHCTL1(timer_periph) |= (uint32_t)prescaler;
  1426. break;
  1427. /* configure TIMER_CH_3 */
  1428. case TIMER_CH_3:
  1429. TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH3CAPPSC);
  1430. TIMER_CHCTL1(timer_periph) |= ((uint32_t)prescaler << 8U);
  1431. break;
  1432. default:
  1433. break;
  1434. }
  1435. }
  1436. /*!
  1437. \brief read TIMER channel capture compare register value
  1438. \param[in] timer_periph: please refer to the following parameters
  1439. \param[in] channel:
  1440. only one parameter can be selected which is shown as below:
  1441. \arg TIMER_CH_0: TIMER channel0(TIMERx(x=0,2,13..16))
  1442. \arg TIMER_CH_1: TIMER channel1(TIMERx(x=0,2,14))
  1443. \arg TIMER_CH_2: TIMER channel2(TIMERx(x=0,2))
  1444. \arg TIMER_CH_3: TIMER channel3(TIMERx(x=0,2))
  1445. \param[out] none
  1446. \retval channel capture compare register value
  1447. */
  1448. uint32_t timer_channel_capture_value_register_read(uint32_t timer_periph, uint16_t channel)
  1449. {
  1450. uint32_t count_value = 0U;
  1451. switch(channel){
  1452. /* read TIMER channel 0 capture compare register value */
  1453. case TIMER_CH_0:
  1454. count_value = TIMER_CH0CV(timer_periph);
  1455. break;
  1456. /* read TIMER channel 1 capture compare register value */
  1457. case TIMER_CH_1:
  1458. count_value = TIMER_CH1CV(timer_periph);
  1459. break;
  1460. /* read TIMER channel 2 capture compare register value */
  1461. case TIMER_CH_2:
  1462. count_value = TIMER_CH2CV(timer_periph);
  1463. break;
  1464. /* read TIMER channel 3 capture compare register value */
  1465. case TIMER_CH_3:
  1466. count_value = TIMER_CH3CV(timer_periph);
  1467. break;
  1468. default:
  1469. break;
  1470. }
  1471. return (count_value);
  1472. }
  1473. /*!
  1474. \brief configure TIMER input pwm capture function
  1475. \param[in] timer_periph: TIMERx(x=0,2,14)
  1476. \param[in] channel:
  1477. only one parameter can be selected which is shown as below:
  1478. \arg TIMER_CH_0: TIMER channel0
  1479. \arg TIMER_CH_1: TIMER channel1
  1480. \param[in] icpwm:TIMER channel intput pwm parameter struct
  1481. icpolarity: TIMER_IC_POLARITY_RISING,TIMER_IC_POLARITY_FALLING
  1482. icselection: TIMER_IC_SELECTION_DIRECTTI,TIMER_IC_SELECTION_INDIRECTTI
  1483. icprescaler: TIMER_IC_PSC_DIV1,TIMER_IC_PSC_DIV2,TIMER_IC_PSC_DIV4,TIMER_IC_PSC_DIV8
  1484. icfilter: 0~15
  1485. \param[out] none
  1486. \retval none
  1487. */
  1488. void timer_input_pwm_capture_config(uint32_t timer_periph, uint16_t channel, timer_ic_parameter_struct* icpwm)
  1489. {
  1490. uint16_t icpolarity = 0x0U;
  1491. uint16_t icselection = 0x0U;
  1492. /* Set channel input polarity */
  1493. if(TIMER_IC_POLARITY_RISING == icpwm->icpolarity){
  1494. icpolarity = TIMER_IC_POLARITY_FALLING;
  1495. }else{
  1496. icpolarity = TIMER_IC_POLARITY_RISING;
  1497. }
  1498. /* Set channel input mode selection */
  1499. if(TIMER_IC_SELECTION_DIRECTTI == icpwm->icselection){
  1500. icselection = TIMER_IC_SELECTION_INDIRECTTI;
  1501. }else{
  1502. icselection = TIMER_IC_SELECTION_DIRECTTI;
  1503. }
  1504. if(TIMER_CH_0 == channel){
  1505. /* reset the CH0EN bit */
  1506. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0EN);
  1507. /* reset the CH0P and CH0NP bits */
  1508. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH0P|TIMER_CHCTL2_CH0NP));
  1509. /* set the CH0P and CH0NP bits */
  1510. TIMER_CHCTL2(timer_periph) |= (uint32_t)(icpwm->icpolarity);
  1511. /* reset the CH0MS bit */
  1512. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0MS);
  1513. /* set the CH0MS bit */
  1514. TIMER_CHCTL0(timer_periph) |= (uint32_t)(icpwm->icselection);
  1515. /* reset the CH0CAPFLT bit */
  1516. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0CAPFLT);
  1517. /* set the CH0CAPFLT bit */
  1518. TIMER_CHCTL0(timer_periph) |= ((uint32_t)(icpwm->icfilter) << 4U);
  1519. /* set the CH0EN bit */
  1520. TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH0EN;
  1521. /* configure TIMER channel input capture prescaler value */
  1522. timer_channel_input_capture_prescaler_config(timer_periph,TIMER_CH_0,(uint16_t)(icpwm->icprescaler));
  1523. /* reset the CH1EN bit */
  1524. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
  1525. /* reset the CH1P and CH1NP bits */
  1526. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH1P|TIMER_CHCTL2_CH1NP));
  1527. /* set the CH1P and CH1NP bits */
  1528. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)icpolarity << 4U);
  1529. /* reset the CH1MS bit */
  1530. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1MS);
  1531. /* set the CH1MS bit */
  1532. TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)icselection << 8U);
  1533. /* reset the CH1CAPFLT bit */
  1534. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1CAPFLT);
  1535. /* set the CH1CAPFLT bit */
  1536. TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(icpwm->icfilter) << 12U);
  1537. /* set the CH1EN bit */
  1538. TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH1EN;
  1539. /* configure TIMER channel input capture prescaler value */
  1540. timer_channel_input_capture_prescaler_config(timer_periph,TIMER_CH_1,(uint16_t)(icpwm->icprescaler));
  1541. }else{
  1542. /* reset the CH1EN bit */
  1543. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
  1544. /* reset the CH1P and CH1NP bits */
  1545. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH1P|TIMER_CHCTL2_CH1NP));
  1546. /* set the CH1P and CH1NP bits */
  1547. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(icpwm->icpolarity) << 4U);
  1548. /* reset the CH1MS bit */
  1549. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1MS);
  1550. /* set the CH1MS bit */
  1551. TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(icpwm->icselection) << 8U);
  1552. /* reset the CH1CAPFLT bit */
  1553. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1CAPFLT);
  1554. /* set the CH1CAPFLT bit */
  1555. TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(icpwm->icfilter) << 12U);
  1556. /* set the CH1EN bit */
  1557. TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH1EN;
  1558. /* configure TIMER channel input capture prescaler value */
  1559. timer_channel_input_capture_prescaler_config(timer_periph, TIMER_CH_1, (uint16_t)(icpwm->icprescaler));
  1560. /* reset the CH0EN bit */
  1561. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0EN);
  1562. /* reset the CH0P and CH0NP bits */
  1563. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH0P|TIMER_CHCTL2_CH0NP));
  1564. /* set the CH0P and CH0NP bits */
  1565. TIMER_CHCTL2(timer_periph) |= (uint32_t)icpolarity;
  1566. /* reset the CH0MS bit */
  1567. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0MS);
  1568. /* set the CH0MS bit */
  1569. TIMER_CHCTL0(timer_periph) |= (uint32_t)icselection;
  1570. /* reset the CH0CAPFLT bit */
  1571. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0CAPFLT);
  1572. /* set the CH0CAPFLT bit */
  1573. TIMER_CHCTL0(timer_periph) |= ((uint32_t)(icpwm->icfilter) << 4U);
  1574. /* set the CH0EN bit */
  1575. TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH0EN;
  1576. /* configure TIMER channel input capture prescaler value */
  1577. timer_channel_input_capture_prescaler_config(timer_periph, TIMER_CH_0, (uint16_t)(icpwm->icprescaler));
  1578. }
  1579. }
  1580. /*!
  1581. \brief configure TIMER hall sensor mode
  1582. \param[in] timer_periph: TIMERx(x=0,2)
  1583. \param[in] hallmode:
  1584. only one parameter can be selected which is shown as below:
  1585. \arg TIMER_HALLINTERFACE_ENABLE: TIMER hall sensor mode enable
  1586. \arg TIMER_HALLINTERFACE_DISABLE: TIMER hall sensor mode disable
  1587. \param[out] none
  1588. \retval none
  1589. */
  1590. void timer_hall_mode_config(uint32_t timer_periph, uint32_t hallmode)
  1591. {
  1592. if(TIMER_HALLINTERFACE_ENABLE == hallmode){
  1593. TIMER_CTL1(timer_periph) |= (uint32_t)TIMER_CTL1_TI0S;
  1594. }else if(TIMER_HALLINTERFACE_DISABLE == hallmode){
  1595. TIMER_CTL1(timer_periph) &= ~(uint32_t)TIMER_CTL1_TI0S;
  1596. }else{
  1597. /* illegal parameters */
  1598. }
  1599. }
  1600. /*!
  1601. \brief select TIMER input trigger source
  1602. \param[in] timer_periph: TIMERx(x=0,2,14)
  1603. \param[in] intrigger:
  1604. only one parameter can be selected which is shown as below:
  1605. \arg TIMER_SMCFG_TRGSEL_ITI0: internal trigger 0(TIMERx(x=0,2,14))
  1606. \arg TIMER_SMCFG_TRGSEL_ITI1: internal trigger 1(TIMERx(x=0,2,14))
  1607. \arg TIMER_SMCFG_TRGSEL_ITI2: internal trigger 2(TIMERx(x=0,2))
  1608. \arg TIMER_SMCFG_TRGSEL_CI0F_ED: TI0 edge detector(TIMERx(x=0,2,14))
  1609. \arg TIMER_SMCFG_TRGSEL_CI0FE0: filtered TIMER input 0(TIMERx(x=0,2,14))
  1610. \arg TIMER_SMCFG_TRGSEL_CI1FE1: filtered TIMER input 1(TIMERx(x=0,2,14))
  1611. \arg TIMER_SMCFG_TRGSEL_ETIFP: external trigger(TIMERx(x=0,2))
  1612. \param[out] none
  1613. \retval none
  1614. */
  1615. void timer_input_trigger_source_select(uint32_t timer_periph, uint32_t intrigger)
  1616. {
  1617. TIMER_SMCFG(timer_periph) &= (~(uint32_t)TIMER_SMCFG_TRGS);
  1618. TIMER_SMCFG(timer_periph) |= (uint32_t)intrigger;
  1619. }
  1620. /*!
  1621. \brief select TIMER master mode output trigger source
  1622. \param[in] timer_periph: TIMERx(x=0,2,5,14)
  1623. \param[in] outrigger:
  1624. only one parameter can be selected which is shown as below:
  1625. \arg TIMER_TRI_OUT_SRC_RESET: the UPG bit as trigger output(TIMERx(x=0,2,5,14))
  1626. \arg TIMER_TRI_OUT_SRC_ENABLE: the counter enable signal TIMER_CTL0_CEN as trigger output(TIMERx(x=0,2,5,14))
  1627. \arg TIMER_TRI_OUT_SRC_UPDATE: update event as trigger output(TIMERx(x=0,2,5,14))
  1628. \arg TIMER_TRI_OUT_SRC_CH0: a capture or a compare match occurred in channal0 as trigger output TRGO(TIMERx(x=0,2,14))
  1629. \arg TIMER_TRI_OUT_SRC_O0CPRE: O0CPRE as trigger output(TIMERx(x=0,2,14))
  1630. \arg TIMER_TRI_OUT_SRC_O1CPRE: O1CPRE as trigger output(TIMERx(x=0,2,14))
  1631. \arg TIMER_TRI_OUT_SRC_O2CPRE: O2CPRE as trigger output(TIMERx(x=0,2,14))
  1632. \arg TIMER_TRI_OUT_SRC_O3CPRE: O3CPRE as trigger output(TIMERx(x=0,2,14))
  1633. \param[out] none
  1634. \retval none
  1635. */
  1636. void timer_master_output_trigger_source_select(uint32_t timer_periph, uint32_t outrigger)
  1637. {
  1638. TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_MMC);
  1639. TIMER_CTL1(timer_periph) |= (uint32_t)outrigger;
  1640. }
  1641. /*!
  1642. \brief select TIMER slave mode
  1643. \param[in] timer_periph: TIMERx(x=0,2,14)
  1644. \param[in] slavemode:
  1645. only one parameter can be selected which is shown as below:
  1646. \arg TIMER_SLAVE_MODE_DISABLE: slave mode disable(TIMERx(x=0,2,14))
  1647. \arg TIMER_ENCODER_MODE0: encoder mode 0(TIMERx(x=0,2))
  1648. \arg TIMER_ENCODER_MODE1: encoder mode 1(TIMERx(x=0,2))
  1649. \arg TIMER_ENCODER_MODE2: encoder mode 2(TIMERx(x=0,2))
  1650. \arg TIMER_SLAVE_MODE_RESTART: restart mode(TIMERx(x=0,2,14))
  1651. \arg TIMER_SLAVE_MODE_PAUSE: pause mode(TIMERx(x=0,2,14))
  1652. \arg TIMER_SLAVE_MODE_EVENT: event mode(TIMERx(x=0,2,14))
  1653. \arg TIMER_SLAVE_MODE_EXTERNAL0: external clock mode 0(TIMERx(x=0,2,14))
  1654. \param[out] none
  1655. \retval none
  1656. */
  1657. void timer_slave_mode_select(uint32_t timer_periph, uint32_t slavemode)
  1658. {
  1659. TIMER_SMCFG(timer_periph) &= (~(uint32_t)TIMER_SMCFG_SMC);
  1660. TIMER_SMCFG(timer_periph) |= (uint32_t)slavemode;
  1661. }
  1662. /*!
  1663. \brief configure TIMER master slave mode
  1664. \param[in] timer_periph: TIMERx(x=0,2,14)
  1665. \param[in] masterslave:
  1666. only one parameter can be selected which is shown as below:
  1667. \arg TIMER_MASTER_SLAVE_MODE_ENABLE: master slave mode enable
  1668. \arg TIMER_MASTER_SLAVE_MODE_DISABLE: master slave mode disable
  1669. \param[out] none
  1670. \retval none
  1671. */
  1672. void timer_master_slave_mode_config(uint32_t timer_periph, uint32_t masterslave)
  1673. {
  1674. if(TIMER_MASTER_SLAVE_MODE_ENABLE == masterslave){
  1675. TIMER_SMCFG(timer_periph) |= (uint32_t)TIMER_SMCFG_MSM;
  1676. }else if(TIMER_MASTER_SLAVE_MODE_DISABLE == masterslave){
  1677. TIMER_SMCFG(timer_periph) &= ~(uint32_t)TIMER_SMCFG_MSM;
  1678. }else{
  1679. /* illegal parameters */
  1680. }
  1681. }
  1682. /*!
  1683. \brief configure TIMER external trigger input
  1684. \param[in] timer_periph: TIMERx(x=0,2)
  1685. \param[in] extprescaler:
  1686. only one parameter can be selected which is shown as below:
  1687. \arg TIMER_EXT_TRI_PSC_OFF: no divided
  1688. \arg TIMER_EXT_TRI_PSC_DIV2: divided by 2
  1689. \arg TIMER_EXT_TRI_PSC_DIV4: divided by 4
  1690. \arg TIMER_EXT_TRI_PSC_DIV8: divided by 8
  1691. \param[in] extpolarity:
  1692. only one parameter can be selected which is shown as below:
  1693. \arg TIMER_ETP_FALLING: active low or falling edge active
  1694. \arg TIMER_ETP_RISING: active high or rising edge active
  1695. \param[in] extfilter: a value between 0 and 15
  1696. \param[out] none
  1697. \retval none
  1698. */
  1699. void timer_external_trigger_config(uint32_t timer_periph, uint32_t extprescaler,
  1700. uint32_t extpolarity, uint32_t extfilter)
  1701. {
  1702. TIMER_SMCFG(timer_periph) &= (~(uint32_t)(TIMER_SMCFG_ETP | TIMER_SMCFG_ETPSC | TIMER_SMCFG_ETFC));
  1703. TIMER_SMCFG(timer_periph) |= (uint32_t)(extprescaler | extpolarity);
  1704. TIMER_SMCFG(timer_periph) |= (uint32_t)(extfilter << 8U);
  1705. }
  1706. /*!
  1707. \brief configure TIMER quadrature decoder mode
  1708. \param[in] timer_periph: TIMERx(x=0,2)
  1709. \param[in] decomode:
  1710. only one parameter can be selected which is shown as below:
  1711. \arg TIMER_ENCODER_MODE0: counter counts on CI0FE0 edge depending on CI1FE1 level
  1712. \arg TIMER_ENCODER_MODE1: counter counts on CI1FE1 edge depending on CI0FE0 level
  1713. \arg TIMER_ENCODER_MODE2: counter counts on both CI0FE0 and CI1FE1 edges depending on the level of the other input
  1714. \param[in] ic0polarity:
  1715. only one parameter can be selected which is shown as below:
  1716. \arg TIMER_IC_POLARITY_RISING: capture rising edge
  1717. \arg TIMER_IC_POLARITY_FALLING: capture falling edge
  1718. \param[in] ic1polarity:
  1719. only one parameter can be selected which is shown as below:
  1720. \arg TIMER_IC_POLARITY_RISING: capture rising edge
  1721. \arg TIMER_IC_POLARITY_FALLING: capture falling edge
  1722. \param[out] none
  1723. \retval none
  1724. */
  1725. void timer_quadrature_decoder_mode_config(uint32_t timer_periph, uint32_t decomode,
  1726. uint16_t ic0polarity, uint16_t ic1polarity)
  1727. {
  1728. TIMER_SMCFG(timer_periph) &= (~(uint32_t)TIMER_SMCFG_SMC);
  1729. TIMER_SMCFG(timer_periph) |= (uint32_t)decomode;
  1730. TIMER_CHCTL0(timer_periph) &= (uint32_t)(((~(uint32_t)TIMER_CHCTL0_CH0MS))&((~(uint32_t)TIMER_CHCTL0_CH1MS)));
  1731. TIMER_CHCTL0(timer_periph) |= (uint32_t)(TIMER_IC_SELECTION_DIRECTTI|((uint32_t)TIMER_IC_SELECTION_DIRECTTI << 8U));
  1732. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH0P|TIMER_CHCTL2_CH0NP));
  1733. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH1P|TIMER_CHCTL2_CH1NP));
  1734. TIMER_CHCTL2(timer_periph) |= ((uint32_t)ic0polarity|((uint32_t)ic1polarity << 4U));
  1735. }
  1736. /*!
  1737. \brief configure TIMER internal clock mode
  1738. \param[in] timer_periph: TIMERx(x=0,2,14)
  1739. \param[out] none
  1740. \retval none
  1741. */
  1742. void timer_internal_clock_config(uint32_t timer_periph)
  1743. {
  1744. TIMER_SMCFG(timer_periph) &= ~(uint32_t)TIMER_SMCFG_SMC;
  1745. }
  1746. /*!
  1747. \brief configure TIMER the internal trigger as external clock input
  1748. \param[in] timer_periph: TIMERx(x=0,2,14)
  1749. \param[in] intrigger:
  1750. only one parameter can be selected which is shown as below:
  1751. \arg TIMER_SMCFG_TRGSEL_ITI0: internal trigger 0(TIMERx(x=0,2,14))
  1752. \arg TIMER_SMCFG_TRGSEL_ITI1: internal trigger 1(TIMERx(x=0,2,14))
  1753. \arg TIMER_SMCFG_TRGSEL_ITI2: internal trigger 2(TIMERx(x=0,2))
  1754. \param[out] none
  1755. \retval none
  1756. */
  1757. void timer_internal_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t intrigger)
  1758. {
  1759. timer_input_trigger_source_select(timer_periph, intrigger);
  1760. TIMER_SMCFG(timer_periph) &= ~(uint32_t)TIMER_SMCFG_SMC;
  1761. TIMER_SMCFG(timer_periph) |= (uint32_t)TIMER_SLAVE_MODE_EXTERNAL0;
  1762. }
  1763. /*!
  1764. \brief configure TIMER the external trigger as external clock input
  1765. \param[in] timer_periph: TIMERx(x=0,2,14)
  1766. \param[in] extrigger:
  1767. only one parameter can be selected which is shown as below:
  1768. \arg TIMER_SMCFG_TRGSEL_CI0F_ED: TI0 edge detector
  1769. \arg TIMER_SMCFG_TRGSEL_CI0FE0: filtered TIMER input 0
  1770. \arg TIMER_SMCFG_TRGSEL_CI1FE1: filtered TIMER input 1
  1771. \param[in] extpolarity:
  1772. only one parameter can be selected which is shown as below:
  1773. \arg TIMER_IC_POLARITY_RISING: active high or rising edge active
  1774. \arg TIMER_IC_POLARITY_FALLING: active low or falling edge active
  1775. \arg TIMER_IC_POLARITY_BOTH_EDGE: active both edge
  1776. \param[in] extfilter: a value between 0 and 15
  1777. \param[out] none
  1778. \retval none
  1779. */
  1780. void timer_external_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t extrigger,
  1781. uint16_t extpolarity, uint32_t extfilter)
  1782. {
  1783. if(TIMER_SMCFG_TRGSEL_CI1FE1 == extrigger){
  1784. /* reset the CH1EN bit */
  1785. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
  1786. /* reset the CH1NP bit */
  1787. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH1P|TIMER_CHCTL2_CH1NP));
  1788. /* set the CH1NP bit */
  1789. TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)extpolarity << 4U);
  1790. /* reset the CH1MS bit */
  1791. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1MS);
  1792. /* set the CH1MS bit */
  1793. TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)TIMER_IC_SELECTION_DIRECTTI << 8U);
  1794. /* reset the CH1CAPFLT bit */
  1795. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1CAPFLT);
  1796. /* set the CH1CAPFLT bit */
  1797. TIMER_CHCTL0(timer_periph) |= (uint32_t)(extfilter << 12U);
  1798. /* set the CH1EN bit */
  1799. TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH1EN;
  1800. }else{
  1801. /* reset the CH0EN bit */
  1802. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0EN);
  1803. /* reset the CH0P and CH0NP bits */
  1804. TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH0P|TIMER_CHCTL2_CH0NP));
  1805. /* set the CH0P and CH0NP bits */
  1806. TIMER_CHCTL2(timer_periph) |= (uint32_t)extpolarity;
  1807. /* reset the CH0MS bit */
  1808. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0MS);
  1809. /* set the CH0MS bit */
  1810. TIMER_CHCTL0(timer_periph) |= (uint32_t)TIMER_IC_SELECTION_DIRECTTI;
  1811. /* reset the CH0CAPFLT bit */
  1812. TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0CAPFLT);
  1813. /* reset the CH0CAPFLT bit */
  1814. TIMER_CHCTL0(timer_periph) |= (uint32_t)(extfilter << 4U);
  1815. /* set the CH0EN bit */
  1816. TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH0EN;
  1817. }
  1818. /* select TIMER input trigger source */
  1819. timer_input_trigger_source_select(timer_periph,extrigger);
  1820. /* reset the SMC bit */
  1821. TIMER_SMCFG(timer_periph) &= (~(uint32_t)TIMER_SMCFG_SMC);
  1822. /* set the SMC bit */
  1823. TIMER_SMCFG(timer_periph) |= (uint32_t)TIMER_SLAVE_MODE_EXTERNAL0;
  1824. }
  1825. /*!
  1826. \brief configure TIMER the external clock mode0
  1827. \param[in] timer_periph: TIMERx(x=0,2)
  1828. \param[in] extprescaler:
  1829. only one parameter can be selected which is shown as below:
  1830. \arg TIMER_EXT_TRI_PSC_OFF: no divided
  1831. \arg TIMER_EXT_TRI_PSC_DIV2: divided by 2
  1832. \arg TIMER_EXT_TRI_PSC_DIV4: divided by 4
  1833. \arg TIMER_EXT_TRI_PSC_DIV8: divided by 8
  1834. \param[in] extpolarity:
  1835. only one parameter can be selected which is shown as below:
  1836. \arg TIMER_ETP_FALLING: active low or falling edge active
  1837. \arg TIMER_ETP_RISING: active high or rising edge active
  1838. \param[in] extfilter: a value between 0 and 15
  1839. \param[out] none
  1840. \retval none
  1841. */
  1842. void timer_external_clock_mode0_config(uint32_t timer_periph, uint32_t extprescaler,
  1843. uint32_t extpolarity, uint32_t extfilter)
  1844. {
  1845. /* configure TIMER external trigger input */
  1846. timer_external_trigger_config(timer_periph, extprescaler, extpolarity, extfilter);
  1847. /* reset the SMC bit,TRGS bit */
  1848. TIMER_SMCFG(timer_periph) &= (~(uint32_t)(TIMER_SMCFG_SMC | TIMER_SMCFG_TRGS));
  1849. /* set the SMC bit,TRGS bit */
  1850. TIMER_SMCFG(timer_periph) |= (uint32_t)(TIMER_SLAVE_MODE_EXTERNAL0 | TIMER_SMCFG_TRGSEL_ETIFP);
  1851. }
  1852. /*!
  1853. \brief configure TIMER the external clock mode1
  1854. \param[in] timer_periph: TIMERx(x=0,2)
  1855. \param[in] extprescaler:
  1856. only one parameter can be selected which is shown as below:
  1857. \arg TIMER_EXT_TRI_PSC_OFF: no divided
  1858. \arg TIMER_EXT_TRI_PSC_DIV2: divided by 2
  1859. \arg TIMER_EXT_TRI_PSC_DIV4: divided by 4
  1860. \arg TIMER_EXT_TRI_PSC_DIV8: divided by 8
  1861. \param[in] extpolarity:
  1862. only one parameter can be selected which is shown as below:
  1863. \arg TIMER_ETP_FALLING: active low or falling edge active
  1864. \arg TIMER_ETP_RISING: active high or rising edge active
  1865. \param[in] extfilter: a value between 0 and 15
  1866. \param[out] none
  1867. \retval none
  1868. */
  1869. void timer_external_clock_mode1_config(uint32_t timer_periph, uint32_t extprescaler,
  1870. uint32_t extpolarity, uint32_t extfilter)
  1871. {
  1872. /* configure TIMER external trigger input */
  1873. timer_external_trigger_config(timer_periph, extprescaler, extpolarity, extfilter);
  1874. TIMER_SMCFG(timer_periph) |= (uint32_t)TIMER_SMCFG_SMC1;
  1875. }
  1876. /*!
  1877. \brief disable TIMER the external clock mode1
  1878. \param[in] timer_periph: TIMERx(x=0,2)
  1879. \param[out] none
  1880. \retval none
  1881. */
  1882. void timer_external_clock_mode1_disable(uint32_t timer_periph)
  1883. {
  1884. TIMER_SMCFG(timer_periph) &= ~(uint32_t)TIMER_SMCFG_SMC1;
  1885. }
  1886. /*!
  1887. \brief configure TIMER channel remap function
  1888. \param[in] timer_periph: TIMERx(x=13)
  1889. \param[in] remap:
  1890. only one parameter can be selected which is shown as below:
  1891. \arg TIMER13_CI0_RMP_GPIO: timer13 channel 0 input is connected to GPIO(TIMER13_CH0)
  1892. \arg TIMER13_CI0_RMP_RTCCLK: timer13 channel 0 input is connected to the RTCCLK
  1893. \arg TIMER13_CI0_RMP_HXTAL_DIV32: timer13 channel 0 input is connected to HXTAL/32 clock
  1894. \arg TIMER13_CI0_RMP_CKOUTSEL: timer13 channel 0 input is connected to CKOUTSEL
  1895. \param[out] none
  1896. \retval none
  1897. */
  1898. void timer_channel_remap_config(uint32_t timer_periph, uint32_t remap)
  1899. {
  1900. TIMER_IRMP(timer_periph) = (uint32_t)remap;
  1901. }
  1902. /*!
  1903. \brief configure TIMER write CHxVAL register selection
  1904. \param[in] timer_periph: TIMERx(x=0,2,13..16)
  1905. \param[in] ccsel:
  1906. only one parameter can be selected which is shown as below:
  1907. \arg TIMER_CHVSEL_DISABLE: no effect
  1908. \arg TIMER_CHVSEL_ENABLE: when write the CHxVAL register, if the write value is same as the CHxVAL value, the write access is ignored
  1909. \param[out] none
  1910. \retval none
  1911. */
  1912. void timer_write_chxval_register_config(uint32_t timer_periph, uint16_t ccsel)
  1913. {
  1914. if(TIMER_CHVSEL_ENABLE == ccsel){
  1915. TIMER_CFG(timer_periph) |= (uint32_t)TIMER_CFG_CHVSEL;
  1916. }else if(TIMER_CHVSEL_DISABLE == ccsel){
  1917. TIMER_CFG(timer_periph) &= ~(uint32_t)TIMER_CFG_CHVSEL;
  1918. }else{
  1919. /* illegal parameters */
  1920. }
  1921. }
  1922. /*!
  1923. \brief configure TIMER output value selection
  1924. \param[in] timer_periph: TIMERx(x=0,14..16)
  1925. \param[in] outsel:
  1926. only one parameter can be selected which is shown as below:
  1927. \arg TIMER_OUTSEL_DISABLE: no effect
  1928. \arg TIMER_OUTSEL_ENABLE: if POEN and IOS is 0, the output disabled
  1929. \param[out] none
  1930. \retval none
  1931. */
  1932. void timer_output_value_selection_config(uint32_t timer_periph, uint16_t outsel)
  1933. {
  1934. if(TIMER_OUTSEL_ENABLE == outsel){
  1935. TIMER_CFG(timer_periph) |= (uint32_t)TIMER_CFG_OUTSEL;
  1936. }else if(TIMER_OUTSEL_DISABLE == outsel){
  1937. TIMER_CFG(timer_periph) &= ~(uint32_t)TIMER_CFG_OUTSEL;
  1938. }else{
  1939. /* illegal parameters */
  1940. }
  1941. }