gd32e23x_timer.c 87 KB

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