gd32vw55x_timer.c 84 KB

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