| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642 |
- /**
- *********************************************************************************
- *
- * @file ald_timer.c
- * @brief TIMER module driver.
- * This is the common part of the TIMER initialization
- *
- * @version V1.0
- * @date 03 Mar. 2023
- * @author AE Team
- * @note
- * Change Logs:
- * Date Author Notes
- * 03 Mar. 2023 Lisq The first version
- *
- * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the License); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- **********************************************************************************
- */
- #include <string.h>
- #include "ald_timer.h"
- /** @addtogroup ES32VF2264_ALD
- * @{
- */
- /** @defgroup TIMER TIMER
- * @brief TIMER module driver
- * @{
- */
- /** @defgroup TIMER_Private_Functions TIMER Private Functions
- * @{
- */
- static void timer_base_set_config(TIMER_TypeDef *TIMERx, ald_timer_base_init_t *init);
- static void timer_oc1_set_config(TIMER_TypeDef *TIMERx, ald_timer_oc_init_t *oc_config);
- static void timer_oc2_set_config(TIMER_TypeDef *TIMERx, ald_timer_oc_init_t *oc_config);
- static void timer_oc3_set_config(TIMER_TypeDef *TIMERx, ald_timer_oc_init_t *oc_config);
- static void timer_oc4_set_config(TIMER_TypeDef *TIMERx, ald_timer_oc_init_t *oc_config);
- static void timer_ccx_channel_cmd(TIMER_TypeDef* TIMERx, ald_timer_channel_t ch, type_func_t state);
- static void timer_ccxn_channel_cmd(TIMER_TypeDef* TIMERx, ald_timer_channel_t ch, type_func_t state);
- static void timer_ti1_set_config(TIMER_TypeDef *TIMERx, ald_timer_ic_polarity_t polarity,
- ald_timer_ic_select_t sel, uint32_t filter);
- static void timer_ti1_set_config_stage(TIMER_TypeDef *TIMERx, ald_timer_ic_polarity_t polarity, uint32_t filter);
- static void timer_ti2_set_config(TIMER_TypeDef *TIMERx, ald_timer_ic_polarity_t polarity,
- ald_timer_ic_select_t sel, uint32_t filter);
- static void timer_ti2_set_config_stage(TIMER_TypeDef *TIMERx, ald_timer_ic_polarity_t polarity, uint32_t filter);
- static void timer_ti3_set_config(TIMER_TypeDef *TIMERx, ald_timer_ic_polarity_t polarity,
- ald_timer_ic_select_t sel, uint32_t filter);
- static void timer_ti4_set_config(TIMER_TypeDef *TIMERx, ald_timer_ic_polarity_t polarity,
- ald_timer_ic_select_t sel, uint32_t filter);
- static void timer_etr_set_config(TIMER_TypeDef* TIMERx, ald_timer_etr_psc_t psc, ald_timer_clock_polarity_t polarity, uint32_t filter);
- static void timer_slave_set_config(ald_timer_handle_t *hperh, ald_timer_slave_config_t *config);
- static void timer_dma_oc_cplt(void *arg);
- static void timer_dma_capture_cplt(void *arg);
- static void timer_dma_period_elapse_cplt(void *arg);
- static void timer_dma_msel(TIMER_TypeDef *hperh, ald_dma_config_t *config);
- /**
- * @}
- */
- /** @defgroup TIMER_Public_Functions TIMER Public Functions
- * @{
- */
- /** @defgroup TIMER_Public_Functions_Group1 TIMER Base functions
- * @brief Time Base functions
- *
- * @verbatim
- ==============================================================================
- ##### Timer Base functions #####
- ==============================================================================
- [..]
- This section provides functions allowing to:
- (+) Initialize and configure the TIMER base.
- (+) Reset the TIMER base.
- (+) Start the Time Base.
- (+) Stop the Time Base.
- (+) Start the Time Base and enable interrupt.
- (+) Stop the Time Base and disable interrupt.
- (+) Start the Time Base and enable DMA transfer.
- (+) Stop the Time Base and disable DMA transfer.
- @endverbatim
- * @{
- */
- /**
- * @brief Initializes the TIMER Time base Unit according to the specified
- * parameters in the timer_handle_t and create the associated handle.
- * @param hperh: TIMER base handle
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_base_init(ald_timer_handle_t *hperh)
- {
- if (hperh == NULL)
- return ALD_ERROR;
- assert_param(IS_TIMER_INSTANCE(hperh->perh));
- assert_param(IS_TIMER_COUNTER_MODE(hperh->init.mode));
- assert_param(IS_TIMER_CLOCK_DIVISION(hperh->init.clk_div));
- if (hperh->state == ALD_TIMER_STATE_RESET)
- hperh->lock = UNLOCK;
- hperh->state = ALD_TIMER_STATE_BUSY;
- timer_base_set_config(hperh->perh, &hperh->init);
- hperh->state = ALD_TIMER_STATE_READY;
- return ALD_OK;
- }
- /**
- * @brief Reset the TIMER base peripheral
- * @param hperh: TIMER base handle
- * @retval Status, see @ref ald_status_t.
- */
- void ald_timer_base_reset(ald_timer_handle_t *hperh)
- {
- assert_param(IS_TIMER_INSTANCE(hperh->perh));
- hperh->state = ALD_TIMER_STATE_BUSY;
- ALD_TIMER_DISABLE(hperh);
- hperh->state = ALD_TIMER_STATE_RESET;
- __UNLOCK(hperh);
- return;
- }
- /**
- * @brief Starts the TIMER Base generation.
- * @param hperh: TIMER handle
- * @retval None
- */
- void ald_timer_base_start(ald_timer_handle_t *hperh)
- {
- assert_param(IS_TIMER_INSTANCE(hperh->perh));
- hperh->state = ALD_TIMER_STATE_BUSY;
- ALD_TIMER_ENABLE(hperh);
- hperh->state = ALD_TIMER_STATE_READY;
- return;
- }
- /**
- * @brief Stops the TIMER Base generation.
- * @param hperh: TIMER handle
- * @retval None
- */
- void ald_timer_base_stop(ald_timer_handle_t *hperh)
- {
- assert_param(IS_TIMER_INSTANCE(hperh->perh));
- hperh->state = ALD_TIMER_STATE_BUSY;
- ALD_TIMER_DISABLE(hperh);
- hperh->state = ALD_TIMER_STATE_READY;
- return;
- }
- /**
- * @brief Starts the TIMER Base generation in interrupt mode.
- * @param hperh: TIMER handle
- * @retval None
- */
- void ald_timer_base_start_by_it(ald_timer_handle_t *hperh)
- {
- assert_param(IS_TIMER_INSTANCE(hperh->perh));
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_UPDATE, ENABLE);
- ALD_TIMER_ENABLE(hperh);
- return;
- }
- /**
- * @brief Stops the TIMER Base generation in interrupt mode.
- * @param hperh: TIMER handle
- * @retval None
- */
- void ald_timer_base_stop_by_it(ald_timer_handle_t *hperh)
- {
- assert_param(IS_TIMER_INSTANCE(hperh->perh));
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_UPDATE, DISABLE);
- ALD_TIMER_DISABLE(hperh);
- return;
- }
- /**
- * @brief Starts the TIMER Base generation in DMA mode.
- * @param hperh: TIMER handle
- * @param buf: The source Buffer address.
- * @param len: The length of buffer to be transferred from memory to TIMER peripheral
- * @param dma_ch: Channel of DMA.
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_base_start_by_dma(ald_timer_handle_t *hperh,
- uint16_t *buf, uint32_t len, uint8_t dma_ch)
- {
- assert_param(IS_TIMER_INSTANCE(hperh->perh));
- if ((hperh->state == ALD_TIMER_STATE_BUSY))
- return ALD_BUSY;
- if ((hperh->state == ALD_TIMER_STATE_READY)) {
- if (((uint32_t)buf == 0 ) || (len == 0))
- return ALD_ERROR;
- }
- hperh->state = ALD_TIMER_STATE_BUSY;
- if (hperh->hdma1.perh == NULL)
- hperh->hdma1.perh = DMA;
- hperh->hdma1.cplt_tc_cbk = timer_dma_period_elapse_cplt;
- hperh->hdma1.cplt_tc_arg = (void *)hperh;
- ald_dma_config_struct(&hperh->hdma1.config);
- hperh->hdma1.config.src = (void *)buf;
- hperh->hdma1.config.dst = (void *)&hperh->perh->AR;
- hperh->hdma1.config.size = len;
- hperh->hdma1.config.src_data_width = ALD_DMA_DATA_SIZE_HALFWORD;
- hperh->hdma1.config.dst_data_width = ALD_DMA_DATA_SIZE_HALFWORD;
- hperh->hdma1.config.src_inc = ALD_DMA_DATA_INC_ENABLE;
- hperh->hdma1.config.dst_inc = ALD_DMA_DATA_INC_DISABLE;
- hperh->hdma1.config.msigsel = ALD_DMA_MSIGSEL_TIMER_UPDATE;
- hperh->hdma1.config.channel = dma_ch;
- timer_dma_msel(hperh->perh, &hperh->hdma1.config);
- ald_dma_config_basic(&hperh->hdma1);
- ald_dma_interrupt_config(dma_ch, ALD_DMA_IT_FLAG_TC, ENABLE);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_UPDATE, ENABLE);
- ALD_TIMER_ENABLE(hperh);
- return ALD_OK;
- }
- /**
- * @brief Stops the TIMER Base generation in DMA mode.
- * @param hperh: TIMER handle
- * @retval None
- */
- void ald_timer_base_stop_by_dma(ald_timer_handle_t *hperh)
- {
- assert_param(IS_TIMER_INSTANCE(hperh->perh));
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_UPDATE, DISABLE);
- ALD_TIMER_DISABLE(hperh);
- hperh->state = ALD_TIMER_STATE_READY;
- return;
- }
- /**
- * @}
- */
- /** @defgroup TIMER_Public_Functions_Group2 TIMER Output Compare functions
- * @brief Time Output Compare functions
- *
- * @verbatim
- ==============================================================================
- ##### Time Output Compare functions #####
- ==============================================================================
- [..]
- This section provides functions allowing to:
- (+) Initialize and configure the TIMER Output Compare.
- (+) Start the Time Output Compare.
- (+) Stop the Time Output Compare.
- (+) Start the Time Output Compare and enable interrupt.
- (+) Stop the Time Output Compare and disable interrupt.
- (+) Start the Time Output Compare and enable DMA transfer.
- (+) Stop the Time Output Compare and disable DMA transfer.
- @endverbatim
- * @{
- */
- /**
- * @brief Initializes the TIMER Output Compare according to the specified
- * parameters in the timer_handle_t and create the associated handle.
- * @param hperh: TIMER handle
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_oc_init(ald_timer_handle_t *hperh)
- {
- return ald_timer_base_init(hperh);
- }
- /**
- * @brief Starts the TIMER Output Compare signal generation.
- * @param hperh: TIMER handle
- * @param ch : TIMER Channel to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4: TIMER Channel 4 selected
- * @retval None
- */
- void ald_timer_oc_start(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CCX_INSTANCE(hperh->perh, ch));
- timer_ccx_channel_cmd(hperh->perh, ch, ENABLE);
- if (IS_TIMER_BREAK_INSTANCE(hperh->perh) != RESET)
- ALD_TIMER_MOE_ENABLE(hperh);
- ALD_TIMER_ENABLE(hperh);
- return;
- }
- /**
- * @brief Stops the TIMER Output Compare signal generation.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channel to be disabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4: TIMER Channel 4 selected
- * @retval None
- */
- void ald_timer_oc_stop(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CCX_INSTANCE(hperh->perh, ch));
- timer_ccx_channel_cmd(hperh->perh, ch, DISABLE);
- if (IS_TIMER_BREAK_INSTANCE(hperh->perh) != RESET)
- ALD_TIMER_MOE_DISABLE(hperh);
- ALD_TIMER_DISABLE(hperh);
- hperh->state = ALD_TIMER_STATE_READY;
- return;
- }
- /**
- * @brief Starts the TIMER Output Compare signal generation in interrupt mode.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channel to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4: TIMER Channel 4 selected
- * @retval None
- */
- void ald_timer_oc_start_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CCX_INSTANCE(hperh->perh, ch));
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC1, ENABLE);
- break;
- case ALD_TIMER_CHANNEL_2:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC2, ENABLE);
- break;
- case ALD_TIMER_CHANNEL_3:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC3, ENABLE);
- break;
- case ALD_TIMER_CHANNEL_4:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC4, ENABLE);
- break;
- default:
- break;
- }
- timer_ccx_channel_cmd(hperh->perh, ch, ENABLE);
- if (IS_TIMER_BREAK_INSTANCE(hperh->perh) != RESET)
- ALD_TIMER_MOE_ENABLE(hperh);
- ALD_TIMER_ENABLE(hperh);
- return;
- }
- /**
- * @brief Stops the TIMER Output Compare signal generation in interrupt mode.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channel to be disabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4: TIMER Channel 4 selected
- * @retval None
- */
- void ald_timer_oc_stop_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CCX_INSTANCE(hperh->perh, ch));
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC1, DISABLE);
- break;
- case ALD_TIMER_CHANNEL_2:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC2, DISABLE);
- break;
- case ALD_TIMER_CHANNEL_3:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC3, DISABLE);
- break;
- case ALD_TIMER_CHANNEL_4:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC4, DISABLE);
- break;
- default:
- break;
- }
- timer_ccx_channel_cmd(hperh->perh, ch, DISABLE);
- if (IS_TIMER_BREAK_INSTANCE(hperh->perh) != RESET)
- ALD_TIMER_MOE_DISABLE(hperh);
- ALD_TIMER_DISABLE(hperh);
- hperh->state = ALD_TIMER_STATE_READY;
- return;
- }
- /**
- * @brief Starts the TIMER Output Compare signal generation in DMA mode.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4: TIMER Channel 4 selected
- * @param buf: The source Buffer address.
- * @param len: The length of buffer to be transferred from memory to TIMER peripheral
- * @param dma_ch: Channel of DMA.
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_oc_start_by_dma(ald_timer_handle_t *hperh, ald_timer_channel_t ch,
- uint16_t *buf, uint32_t len, uint8_t dma_ch)
- {
- assert_param(IS_TIMER_CCX_INSTANCE(hperh->perh, ch));
- if ((hperh->state == ALD_TIMER_STATE_BUSY))
- return ALD_BUSY;
- if ((hperh->state == ALD_TIMER_STATE_READY)) {
- if (((uint32_t)buf == 0 ) || (len == 0))
- return ALD_ERROR;
- }
- hperh->state = ALD_TIMER_STATE_BUSY;
- if (hperh->hdma1.perh == NULL)
- hperh->hdma1.perh = DMA;
- hperh->hdma1.cplt_tc_cbk = timer_dma_oc_cplt;
- hperh->hdma1.cplt_tc_arg = (void *)hperh;
- ald_dma_config_struct(&hperh->hdma1.config);
- hperh->hdma1.config.src = (void *)buf;
- hperh->hdma1.config.size = len;
- hperh->hdma1.config.src_data_width = ALD_DMA_DATA_SIZE_HALFWORD;
- hperh->hdma1.config.dst_data_width = ALD_DMA_DATA_SIZE_HALFWORD;
- hperh->hdma1.config.src_inc = ALD_DMA_DATA_INC_ENABLE;
- hperh->hdma1.config.dst_inc = ALD_DMA_DATA_INC_DISABLE;
- hperh->hdma1.config.channel = dma_ch;
- timer_dma_msel(hperh->perh, &hperh->hdma1.config);
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- hperh->hdma1.config.dst = (void *)&hperh->perh->CCVAL1;
- hperh->hdma1.config.msigsel = ALD_DMA_MSIGSEL_TIMER_CH1;
- ald_dma_config_basic(&hperh->hdma1);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC1, ENABLE);
- hperh->ch = ALD_TIMER_ACTIVE_CHANNEL_1;
- break;
- case ALD_TIMER_CHANNEL_2:
- hperh->hdma1.config.dst = (void *)&hperh->perh->CCVAL2;
- hperh->hdma1.config.msigsel = ALD_DMA_MSIGSEL_TIMER_CH2;
- ald_dma_config_basic(&hperh->hdma1);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC2, ENABLE);
- hperh->ch = ALD_TIMER_ACTIVE_CHANNEL_2;
- break;
- case ALD_TIMER_CHANNEL_3:
- hperh->hdma1.config.dst = (void *)&hperh->perh->CCVAL3;
- hperh->hdma1.config.msigsel = ALD_DMA_MSIGSEL_TIMER_CH3;
- ald_dma_config_basic(&hperh->hdma1);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC3, ENABLE);
- hperh->ch = ALD_TIMER_ACTIVE_CHANNEL_3;
- break;
- case ALD_TIMER_CHANNEL_4:
- hperh->hdma1.config.dst = (void *)&hperh->perh->CCVAL4;
- hperh->hdma1.config.msigsel = ALD_DMA_MSIGSEL_TIMER_CH4;
- ald_dma_config_basic(&hperh->hdma1);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC4, ENABLE);
- hperh->ch = ALD_TIMER_ACTIVE_CHANNEL_4;
- break;
- default:
- break;
- }
- ald_dma_interrupt_config(dma_ch, ALD_DMA_IT_FLAG_TC, ENABLE);
- timer_ccx_channel_cmd(hperh->perh, ch, ENABLE);
- if (IS_TIMER_BREAK_INSTANCE(hperh->perh) != RESET)
- ALD_TIMER_MOE_ENABLE(hperh);
- ALD_TIMER_ENABLE(hperh);
- return ALD_OK;
- }
- /**
- * @brief Stops the TIMER Output Compare signal generation in DMA mode.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be disabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4: TIMER Channel 4 selected
- * @retval None
- */
- void ald_timer_oc_stop_by_dma(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CCX_INSTANCE(hperh->perh, ch));
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC1, DISABLE);
- break;
- case ALD_TIMER_CHANNEL_2:
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC2, DISABLE);
- break;
- case ALD_TIMER_CHANNEL_3:
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC3, DISABLE);
- break;
- case ALD_TIMER_CHANNEL_4:
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC4, DISABLE);
- break;
- default:
- break;
- }
- timer_ccx_channel_cmd(hperh->perh, ch, DISABLE);
- if (IS_TIMER_BREAK_INSTANCE(hperh->perh) != RESET)
- ALD_TIMER_MOE_DISABLE(hperh);
- ALD_TIMER_DISABLE(hperh);
- hperh->state = ALD_TIMER_STATE_READY;
- return;
- }
- /**
- * @}
- */
- /** @defgroup TIMER_Public_Functions_Group3 TIMER PWM functions
- * @brief TIMER PWM functions
- *
- * @verbatim
- ==============================================================================
- ##### Time PWM functions #####
- ==============================================================================
- [..]
- This section provides functions allowing to:
- (+) Initialize and configure the TIMER PWM.
- (+) Start the Time PWM.
- (+) Stop the Time PWM.
- (+) Start the Time PWM and enable interrupt.
- (+) Stop the Time PWM and disable interrupt.
- (+) Start the Time PWM and enable DMA transfer.
- (+) Stop the Time PWM and disable DMA transfer.
- @endverbatim
- * @{
- */
- /**
- * @brief Initializes the TIMER PWM Time Base according to the specified
- * parameters in the timer_handle_t and create the associated handle.
- * @param hperh: TIMER handle
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_pwm_init(ald_timer_handle_t *hperh)
- {
- return ald_timer_base_init(hperh);
- }
- /**
- * @brief Starts the PWM signal generation.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4: TIMER Channel 4 selected
- * @retval None
- */
- void ald_timer_pwm_start(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- ald_timer_oc_start(hperh, ch);
- return;
- }
- /**
- * @brief Stops the PWM signal generation.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be disabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4: TIMER Channel 4 selected
- * @retval None
- */
- void ald_timer_pwm_stop(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- ald_timer_oc_stop(hperh, ch);
- return;
- }
- /**
- * @brief Starts the PWM signal generation in interrupt mode.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channel to be disabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4: TIMER Channel 4 selected
- * @retval None
- */
- void ald_timer_pwm_start_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- ald_timer_oc_start_by_it(hperh, ch);
- return;
- }
- /**
- * @brief Stops the PWM signal generation in interrupt mode.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be disabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4: TIMER Channel 4 selected
- * @retval None
- */
- void ald_timer_pwm_stop_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- ald_timer_oc_stop_by_it(hperh, ch);
- return;
- }
- /**
- * @brief Starts the TIMER PWM signal generation in DMA mode.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4: TIMER Channel 4 selected
- * @param buf: The source Buffer address.
- * @param len: The length of buffer to be transferred from memory to TIMER peripheral
- * @param dma_ch: Channel of DMA.
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_pwm_start_by_dma(ald_timer_handle_t *hperh, ald_timer_channel_t ch,
- uint16_t *buf, uint32_t len, uint8_t dma_ch)
- {
- return ald_timer_oc_start_by_dma(hperh, ch, buf, len, dma_ch);
- }
- /**
- * @brief Stops the TIMER PWM signal generation in DMA mode.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be disabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4: TIMER Channel 4 selected
- * @retval None
- */
- void ald_timer_pwm_stop_by_dma(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- ald_timer_oc_stop_by_dma(hperh, ch);
- return;
- }
- /**
- * @brief Set the PWM freq.
- * @param hperh: TIMER handle
- * @param freq: PWM freq to set
- * @retval None
- */
- void ald_timer_pwm_set_freq(ald_timer_handle_t *hperh, uint32_t freq)
- {
- uint32_t _arr;
- if (freq == 0)
- return;
- _arr = ald_cmu_get_pclk_clock() / (hperh->init.prescaler + 1) / freq - 1;
- WRITE_REG(hperh->perh->AR, _arr);
- hperh->init.period = _arr;
- }
- /**
- * @brief Set the PWM duty.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4: TIMER Channel 4 selected
- * @param duty: PWM duty to set [0, 100]
- * @retval None
- */
- void ald_timer_pwm_set_duty(ald_timer_handle_t *hperh, ald_timer_channel_t ch, uint16_t duty)
- {
- uint32_t tmp = (hperh->init.period + 1) * duty / 100;
- if (ch == ALD_TIMER_CHANNEL_1)
- WRITE_REG(hperh->perh->CCVAL1, tmp);
- else if (ch == ALD_TIMER_CHANNEL_2)
- WRITE_REG(hperh->perh->CCVAL2, tmp);
- else if (ch == ALD_TIMER_CHANNEL_3)
- WRITE_REG(hperh->perh->CCVAL3, tmp);
- else if (ch == ALD_TIMER_CHANNEL_4)
- WRITE_REG(hperh->perh->CCVAL4, tmp);
- }
- /**
- * @brief Set capture the PWM.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be captured the PWM
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @retval None
- */
- void ald_timer_pwm_set_input(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_PWM_INPUT_INSTANCE(hperh->perh, ch));
- CLEAR_BIT(hperh->perh->SMCON, TIMER_SMCON_SMODS_MSK);
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- MODIFY_REG(hperh->perh->CHMR1, TIMER_CHMR1_CC1SSEL_MSK, ALD_TIMER_IC_SEL_DIRECT << TIMER_CHMR1_CC1SSEL_POSS);
- MODIFY_REG(hperh->perh->CHMR1, TIMER_CHMR1_CC2SSEL_MSK, ALD_TIMER_IC_SEL_INDIRECT << TIMER_CHMR1_CC2SSEL_POSS);
- MODIFY_REG(hperh->perh->CCEP, TIMER_CCEP_CC1POL_MSK, ALD_TIMER_IC_POLARITY_RISE << TIMER_CCEP_CC1POL_POS);
- MODIFY_REG(hperh->perh->CCEP, TIMER_CCEP_CC1NPOL_MSK, ALD_TIMER_IC_POLARITY_RISE << TIMER_CCEP_CC1NPOL_POS);
- MODIFY_REG(hperh->perh->CCEP, TIMER_CCEP_CC2POL_MSK, ALD_TIMER_IC_POLARITY_FALL << TIMER_CCEP_CC2POL_POS);
- MODIFY_REG(hperh->perh->CCEP, TIMER_CCEP_CC2NPOL_MSK, ALD_TIMER_IC_POLARITY_FALL << TIMER_CCEP_CC2NPOL_POS);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_TSSEL_MSK, ALD_TIMER_TS_TI1FP1 << TIMER_SMCON_TSSEL_POSS);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_SMODS_MSK, ALD_TIMER_MODE_RESET << TIMER_SMCON_SMODS_POSS);
- break;
- case ALD_TIMER_CHANNEL_2:
- MODIFY_REG(hperh->perh->CHMR1, TIMER_CHMR1_CC1SSEL_MSK, ALD_TIMER_IC_SEL_INDIRECT << TIMER_CHMR1_CC1SSEL_POSS);
- MODIFY_REG(hperh->perh->CHMR1, TIMER_CHMR1_CC2SSEL_MSK, ALD_TIMER_IC_SEL_DIRECT << TIMER_CHMR1_CC2SSEL_POSS);
- MODIFY_REG(hperh->perh->CCEP, TIMER_CCEP_CC1POL_MSK, ALD_TIMER_IC_POLARITY_RISE << TIMER_CCEP_CC1POL_POS);
- MODIFY_REG(hperh->perh->CCEP, TIMER_CCEP_CC1NPOL_MSK, ALD_TIMER_IC_POLARITY_FALL << TIMER_CCEP_CC1NPOL_POS);
- MODIFY_REG(hperh->perh->CCEP, TIMER_CCEP_CC2POL_MSK, ALD_TIMER_IC_POLARITY_FALL << TIMER_CCEP_CC2POL_POS);
- MODIFY_REG(hperh->perh->CCEP, TIMER_CCEP_CC2NPOL_MSK, ALD_TIMER_IC_POLARITY_RISE << TIMER_CCEP_CC2NPOL_POS);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_TSSEL_MSK, ALD_TIMER_TS_TI2FP2 << TIMER_SMCON_TSSEL_POSS);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_SMODS_MSK, ALD_TIMER_MODE_RESET << TIMER_SMCON_SMODS_POSS);
- break;
- default:
- break;
- }
- SET_BIT(hperh->perh->CCEP, TIMER_CCEP_CC1EN_MSK);
- SET_BIT(hperh->perh->CCEP, TIMER_CCEP_CC2EN_MSK);
- return;
- }
- /**
- * @}
- */
- /** @defgroup TIMER_Public_Functions_Group4 TIMER Input Capture functions
- * @brief Time Input Capture functions
- *
- * @verbatim
- ==============================================================================
- ##### Time Input Capture functions #####
- ==============================================================================
- [..]
- This section provides functions allowing to:
- (+) Initialize and configure the TIMER Input Capture.
- (+) Start the Time Input Capture.
- (+) Stop the Time Input Capture.
- (+) Start the Time Input Capture and enable interrupt.
- (+) Stop the Time Input Capture and disable interrupt.
- (+) Start the Time Input Capture and enable DMA transfer.
- (+) Stop the Time Input Capture and disable DMA transfer.
- * @endverbatim
- * @{
- */
- /**
- * @brief Initializes the TIMER Input Capture Time base according to the specified
- * parameters in the timer_handle_t and create the associated handle.
- * @param hperh: TIMER handle
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_ic_init(ald_timer_handle_t *hperh)
- {
- return ald_timer_base_init(hperh);
- }
- /**
- * @brief Starts the TIMER Input Capture measurement.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4: TIMER Channel 4 selected
- * @retval None
- */
- void ald_timer_ic_start(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CCX_INSTANCE(hperh->perh, ch));
- timer_ccx_channel_cmd(hperh->perh, ch, ENABLE);
- ALD_TIMER_ENABLE(hperh);
- return;
- }
- /**
- * @brief Stops the TIMER Input Capture measurement.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be disabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4: TIMER Channel 4 selected
- * @retval None
- */
- void ald_timer_ic_stop(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CCX_INSTANCE(hperh->perh, ch));
- timer_ccx_channel_cmd(hperh->perh, ch, DISABLE);
- ALD_TIMER_DISABLE(hperh);
- return;
- }
- /**
- * @brief Starts the TIMER Input Capture measurement in interrupt mode.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4: TIMER Channel 4 selected
- * @retval None
- */
- void ald_timer_ic_start_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CCX_INSTANCE(hperh->perh, ch));
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC1, ENABLE);
- break;
- case ALD_TIMER_CHANNEL_2:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC2, ENABLE);
- break;
- case ALD_TIMER_CHANNEL_3:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC3, ENABLE);
- break;
- case ALD_TIMER_CHANNEL_4:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC4, ENABLE);
- break;
- default:
- break;
- }
- timer_ccx_channel_cmd(hperh->perh, ch, ENABLE);
- ALD_TIMER_ENABLE(hperh);
- return;
- }
- /**
- * @brief Stops the TIMER Input Capture measurement in interrupt mode.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be disabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4: TIMER Channel 4 selected
- * @retval None
- */
- void ald_timer_ic_stop_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CCX_INSTANCE(hperh->perh, ch));
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC1, DISABLE);
- break;
- case ALD_TIMER_CHANNEL_2:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC2, DISABLE);
- break;
- case ALD_TIMER_CHANNEL_3:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC3, DISABLE);
- break;
- case ALD_TIMER_CHANNEL_4:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC4, DISABLE);
- break;
- default:
- break;
- }
- timer_ccx_channel_cmd(hperh->perh, ch, DISABLE);
- ALD_TIMER_DISABLE(hperh);
- return;
- }
- /**
- * @brief Starts the TIMER Input Capture measurement in DMA mode.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4: TIMER Channel 4 selected
- * @param buf: The destination Buffer address.
- * @param len: The length of buffer to be transferred TIMER peripheral to memory
- * @param dma_ch: Channel of DMA.
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_ic_start_by_dma(ald_timer_handle_t *hperh, ald_timer_channel_t ch,
- uint16_t *buf, uint32_t len, uint8_t dma_ch)
- {
- assert_param(IS_TIMER_CCX_INSTANCE(hperh->perh, ch));
- if ((hperh->state == ALD_TIMER_STATE_BUSY))
- return ALD_BUSY;
- if ((hperh->state == ALD_TIMER_STATE_READY)) {
- if (((uint32_t)buf == 0 ) || (len == 0))
- return ALD_ERROR;
- }
- hperh->state = ALD_TIMER_STATE_BUSY;
- if (hperh->perh == NULL)
- hperh->hdma1.perh = DMA;
- hperh->hdma1.cplt_tc_cbk = timer_dma_capture_cplt;
- hperh->hdma1.cplt_tc_arg = (void *)hperh;
- ald_dma_config_struct(&hperh->hdma1.config);
- hperh->hdma1.config.dst = (void *)buf;
- hperh->hdma1.config.size = len;
- hperh->hdma1.config.src_data_width = ALD_DMA_DATA_SIZE_HALFWORD;
- hperh->hdma1.config.dst_data_width = ALD_DMA_DATA_SIZE_HALFWORD;
- hperh->hdma1.config.src_inc = ALD_DMA_DATA_INC_DISABLE;
- hperh->hdma1.config.dst_inc = ALD_DMA_DATA_INC_ENABLE;
- hperh->hdma1.config.circle_mode = ENABLE;
- hperh->hdma1.config.channel = dma_ch;
- timer_dma_msel(hperh->perh, &hperh->hdma1.config);
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- hperh->hdma1.config.src = (void *)&hperh->perh->CCVAL1;
- hperh->hdma1.config.msigsel = ALD_DMA_MSIGSEL_TIMER_CH1;
- ald_dma_config_basic(&hperh->hdma1);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC1, ENABLE);
- hperh->ch = ALD_TIMER_ACTIVE_CHANNEL_1;
- break;
- case ALD_TIMER_CHANNEL_2:
- hperh->hdma1.config.src = (void *)&hperh->perh->CCVAL2;
- hperh->hdma1.config.msigsel = ALD_DMA_MSIGSEL_TIMER_CH2;
- ald_dma_config_basic(&hperh->hdma1);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC2, ENABLE);
- hperh->ch = ALD_TIMER_ACTIVE_CHANNEL_2;
- break;
- case ALD_TIMER_CHANNEL_3:
- hperh->hdma1.config.src = (void *)&hperh->perh->CCVAL3;
- hperh->hdma1.config.msigsel = ALD_DMA_MSIGSEL_TIMER_CH3;
- ald_dma_config_basic(&hperh->hdma1);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC3, ENABLE);
- hperh->ch = ALD_TIMER_ACTIVE_CHANNEL_3;
- break;
- case ALD_TIMER_CHANNEL_4:
- hperh->hdma1.config.src = (void *)&hperh->perh->CCVAL4;
- hperh->hdma1.config.msigsel = ALD_DMA_MSIGSEL_TIMER_CH4;
- ald_dma_config_basic(&hperh->hdma1);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC4, ENABLE);
- hperh->ch = ALD_TIMER_ACTIVE_CHANNEL_4;
- break;
- default:
- break;
- }
- ald_dma_interrupt_config(dma_ch, ALD_DMA_IT_FLAG_TC, ENABLE);
- timer_ccx_channel_cmd(hperh->perh, ch, ENABLE);
- ALD_TIMER_ENABLE(hperh);
- return ALD_OK;
- }
- /**
- * @brief Stops the TIMER Input Capture measurement in DMA mode.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be disabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4: TIMER Channel 4 selected
- * @retval None
- */
- void ald_timer_ic_stop_by_dma(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CCX_INSTANCE(hperh->perh, ch));
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC1, DISABLE);
- break;
- case ALD_TIMER_CHANNEL_2:
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC2, DISABLE);
- break;
- case ALD_TIMER_CHANNEL_3:
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC3, DISABLE);
- break;
- case ALD_TIMER_CHANNEL_4:
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC4, DISABLE);
- break;
- default:
- break;
- }
- timer_ccx_channel_cmd(hperh->perh, ch, DISABLE);
- ALD_TIMER_DISABLE(hperh);
- hperh->state = ALD_TIMER_STATE_READY;
- return;
- }
- /**
- * @}
- */
- /** @defgroup TIMER_Public_Functions_Group5 TIMER One Pulse functions
- * @brief Time One Pulse functions
- *
- * @verbatim
- ==============================================================================
- ##### Time One Pulse functions #####
- ==============================================================================
- [..]
- This section provides functions allowing to:
- (+) Initialize and configure the TIMER One Pulse.
- (+) Start the Time One Pulse.
- (+) Stop the Time One Pulse.
- (+) Start the Time One Pulse and enable interrupt.
- (+) Stop the Time One Pulse and disable interrupt.
- (+) Start the Time One Pulse and enable DMA transfer.
- (+) Stop the Time One Pulse and disable DMA transfer.
- * @endverbatim
- * @{
- */
- /**
- * @brief Initializes the TIMER One Pulse Time Base according to the specified
- * parameters in the timer_handle_t and create the associated handle.
- * @param hperh: TIMER handle
- * @param mode: Select the One pulse mode.
- * This parameter can be one of the following values:
- * @arg TIMER_OP_MODE_SINGLE: Only one pulse will be generated.
- * @arg TIMER_OP_MODE_REPEAT: Repetitive pulses wil be generated.
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_one_pulse_init(ald_timer_handle_t *hperh, ald_timer_op_mode_t mode)
- {
- if (hperh == NULL)
- return ALD_ERROR;
- assert_param(IS_TIMER_INSTANCE(hperh->perh));
- assert_param(IS_TIMER_COUNTER_MODE(hperh->init.mode));
- assert_param(IS_TIMER_CLOCK_DIVISION(hperh->init.clk_div));
- assert_param(IS_TIMER_OP_MODE(mode));
- if (hperh->state == ALD_TIMER_STATE_RESET)
- hperh->lock = UNLOCK;
- hperh->state = ALD_TIMER_STATE_BUSY;
- timer_base_set_config(hperh->perh, &hperh->init);
- MODIFY_REG(hperh->perh->CON1, TIMER_CON1_SPMEN_MSK, mode << TIMER_CON1_SPMEN_POS);
- hperh->state = ALD_TIMER_STATE_READY;
- return ALD_OK;
- }
- /**
- * @brief Starts the TIMER One Pulse signal generation.
- * @param hperh: TIMER One Pulse handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_OP_OUTPUT_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_OP_OUTPUT_CHANNEL_2: TIMER Channel 2 selected
- * @retval None
- */
- void ald_timer_one_pulse_start(ald_timer_handle_t *hperh, ald_timer_op_output_channel_t ch)
- {
- /* Enable the Capture compare and the Input Capture channels
- * (in the OPM Mode the two possible channels that can be used are TIMER_CHANNEL_1 and TIMER_CHANNEL_2)
- * if TIMER_CHANNEL_1 is used as output, the TIMER_CHANNEL_2 will be used as input and
- * if TIMER_CHANNEL_1 is used as input, the TIMER_CHANNEL_2 will be used as output
- * in all combinations, the TIMER_CHANNEL_1 and TIMER_CHANNEL_2 should be enabled together
- */
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, ENABLE);
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_2, ENABLE);
- if (IS_TIMER_BREAK_INSTANCE(hperh->perh) != RESET)
- ALD_TIMER_MOE_ENABLE(hperh);
- return;
- }
- /**
- * @brief Stops the TIMER One Pulse signal generation.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_OP_OUTPUT_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_OP_OUTPUT_CHANNEL_2: TIMER Channel 2 selected
- * @retval None
- */
- void ald_timer_one_pulse_stop(ald_timer_handle_t *hperh, ald_timer_op_output_channel_t ch)
- {
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, DISABLE);
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_2, DISABLE);
- if (IS_TIMER_BREAK_INSTANCE(hperh->perh) != RESET)
- ALD_TIMER_MOE_DISABLE(hperh);
- ALD_TIMER_DISABLE(hperh);
- return;
- }
- /**
- * @brief Starts the TIMER One Pulse signal generation in interrupt mode.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_OP_OUTPUT_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_OP_OUTPUT_CHANNEL_2: TIMER Channel 2 selected
- * @retval None
- */
- void ald_timer_one_pulse_start_by_it(ald_timer_handle_t *hperh, ald_timer_op_output_channel_t ch)
- {
- /* Enable the Capture compare and the Input Capture channels
- * (in the OPM Mode the two possible channels that can be used are TIMER_CHANNEL_1 and TIMER_CHANNEL_2)
- * if TIMER_CHANNEL_1 is used as output, the TIMER_CHANNEL_2 will be used as input and
- * if TIMER_CHANNEL_1 is used as input, the TIMER_CHANNEL_2 will be used as output
- * in all combinations, the TIMER_CHANNEL_1 and TIMER_CHANNEL_2 should be enabled together
- */
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC1, ENABLE);
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC2, ENABLE);
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, ENABLE);
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_2, ENABLE);
- if (IS_TIMER_BREAK_INSTANCE(hperh->perh) != RESET)
- ALD_TIMER_MOE_ENABLE(hperh);
- return;
- }
- /**
- * @brief Stops the TIMER One Pulse signal generation in interrupt mode.
- * @param hperh : TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_OP_OUTPUT_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_OP_OUTPUT_CHANNEL_2: TIMER Channel 2 selected
- * @retval None
- */
- void ald_timer_one_pulse_stop_by_it(ald_timer_handle_t *hperh, ald_timer_op_output_channel_t ch)
- {
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC1, DISABLE);
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC2, DISABLE);
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, DISABLE);
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_2, DISABLE);
- if (IS_TIMER_BREAK_INSTANCE(hperh->perh) != RESET)
- ALD_TIMER_MOE_DISABLE(hperh);
- ALD_TIMER_DISABLE(hperh);
- return;
- }
- /**
- * @}
- */
- /** @defgroup TIMER_Public_Functions_Group6 TIMER Encoder functions
- * @brief TIMER Encoder functions
- *
- * @verbatim
- ==============================================================================
- ##### Time Encoder functions #####
- ==============================================================================
- [..]
- This section provides functions allowing to:
- (+) Initialize and configure the TIMER Encoder.
- (+) Start the Time Encoder.
- (+) Stop the Time Encoder.
- (+) Start the Time Encoder and enable interrupt.
- (+) Stop the Time Encoder and disable interrupt.
- (+) Start the Time Encoder and enable DMA transfer.
- (+) Stop the Time Encoder and disable DMA transfer.
- * @endverbatim
- * @{
- */
- /**
- * @brief Initializes the TIMER Encoder Interface and create the associated handle.
- * @param hperh: TIMER handle
- * @param config: TIMER Encoder Interface configuration structure
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_encoder_init(ald_timer_handle_t *hperh, ald_timer_encoder_init_t *config)
- {
- if (hperh == NULL)
- return ALD_ERROR;
- assert_param(IS_TIMER_CC2_INSTANCE(hperh->perh));
- assert_param(IS_TIMER_ENCODER_MODE(config->mode));
- assert_param(IS_TIMER_IC_POLARITY(config->ic1_polarity));
- assert_param(IS_TIMER_IC_POLARITY(config->ic2_polarity));
- assert_param(IS_TIMER_IC_SELECT(config->ic1_sel));
- assert_param(IS_TIMER_IC_SELECT(config->ic2_sel));
- assert_param(IS_TIMER_IC_PSC(config->ic1_psc));
- assert_param(IS_TIMER_IC_PSC(config->ic2_psc));
- assert_param(IS_TIMER_IC_FILTER(config->ic1_filter));
- assert_param(IS_TIMER_IC_FILTER(config->ic2_filter));
- if (hperh->state == ALD_TIMER_STATE_RESET)
- hperh->lock = UNLOCK;
- hperh->state = ALD_TIMER_STATE_BUSY;
- CLEAR_BIT(hperh->perh->SMCON, TIMER_SMCON_SMODS_MSK);
- timer_base_set_config(hperh->perh, &hperh->init);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_SMODS_MSK, config->mode << TIMER_SMCON_SMODS_POSS);
- MODIFY_REG(hperh->perh->CHMR1, TIMER_CHMR1_CC1SSEL_MSK, config->ic1_sel << TIMER_CHMR1_CC1SSEL_POSS);
- MODIFY_REG(hperh->perh->CHMR1, TIMER_CHMR1_CC2SSEL_MSK, config->ic2_sel << TIMER_CHMR1_CC2SSEL_POSS);
- MODIFY_REG(hperh->perh->CHMR1, TIMER_CHMR1_IC1PRES_MSK, config->ic1_psc << TIMER_CHMR1_IC1PRES_POSS);
- MODIFY_REG(hperh->perh->CHMR1, TIMER_CHMR1_IC2PRES_MSK, config->ic2_psc << TIMER_CHMR1_IC2PRES_POSS);
- MODIFY_REG(hperh->perh->CHMR1, TIMER_CHMR1_I1FLT_MSK, config->ic1_filter << TIMER_CHMR1_I1FLT_POSS);
- MODIFY_REG(hperh->perh->CHMR1, TIMER_CHMR1_I2FLT_MSK, config->ic2_filter << TIMER_CHMR1_I2FLT_POSS);
- MODIFY_REG(hperh->perh->CCEP, TIMER_CCEP_CC1POL_MSK, (config->ic1_polarity & 0x1) << TIMER_CCEP_CC1POL_POS);
- MODIFY_REG(hperh->perh->CCEP, TIMER_CCEP_CC1NPOL_MSK, ((config->ic1_polarity >> 1) & 0x1) << TIMER_CCEP_CC1NPOL_POS);
- MODIFY_REG(hperh->perh->CCEP, TIMER_CCEP_CC2POL_MSK, (config->ic2_polarity & 0x1) << TIMER_CCEP_CC2POL_POS);
- MODIFY_REG(hperh->perh->CCEP, TIMER_CCEP_CC2NPOL_MSK, ((config->ic2_polarity >> 1) & 0x1) << TIMER_CCEP_CC2NPOL_POS);
- hperh->state = ALD_TIMER_STATE_READY;
- return ALD_OK;
- }
- /**
- * @brief Starts the TIMER Encoder Interface.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_ALL: TIMER Channel 1 and TIMER Channel 2 are selected
- * @retval None
- */
- void ald_timer_encoder_start(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CC2_INSTANCE(hperh->perh));
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, ENABLE);
- break;
- case ALD_TIMER_CHANNEL_2:
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_2, ENABLE);
- break;
- default:
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, ENABLE);
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_2, ENABLE);
- break;
- }
- ALD_TIMER_ENABLE(hperh);
- return;
- }
- /**
- * @brief Stops the TIMER Encoder Interface.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_ALL: TIMER Channel 1 and TIMER Channel 2 are selected
- * @retval None
- */
- void ald_timer_encoder_stop(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CC2_INSTANCE(hperh->perh));
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, DISABLE);
- break;
- case ALD_TIMER_CHANNEL_2:
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_2, DISABLE);
- break;
- default:
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, DISABLE);
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_2, DISABLE);
- break;
- }
- ALD_TIMER_DISABLE(hperh);
- return;
- }
- /**
- * @brief Starts the TIMER Encoder Interface in interrupt mode.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_ALL: TIMER Channel 1 and TIMER Channel 2 are selected
- * @retval None
- */
- void ald_timer_encoder_start_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CC2_INSTANCE(hperh->perh));
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, ENABLE);
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC1, ENABLE);
- break;
- case ALD_TIMER_CHANNEL_2:
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_2, ENABLE);
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC2, ENABLE);
- break;
- default:
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, ENABLE);
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_2, ENABLE);
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC1, ENABLE);
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC2, ENABLE);
- break;
- }
- ALD_TIMER_ENABLE(hperh);
- return;
- }
- /**
- * @brief Stops the TIMER Encoder Interface in interrupt mode.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_ALL: TIMER Channel 1 and TIMER Channel 2 are selected
- * @retval None
- */
- void ald_timer_encoder_stop_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CC2_INSTANCE(hperh->perh));
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, DISABLE);
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC1, DISABLE);
- break;
- case ALD_TIMER_CHANNEL_2:
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_2, DISABLE);
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC2, DISABLE);
- break;
- default:
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, DISABLE);
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_2, DISABLE);
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC1, DISABLE);
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC2, DISABLE);
- break;
- }
- ALD_TIMER_DISABLE(hperh);
- hperh->state = ALD_TIMER_STATE_READY;
- return;
- }
- /**
- * @brief Starts the TIMER Encoder Interface in DMA mode.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_ALL: TIMER Channel 1 and TIMER Channel 2 are selected
- * @param buf1: The destination Buffer address. Reading data from CCR1.
- * @param buf2: The destination Buffer address. Reading data from CCR2.
- * @param len: The length of buffer to be transferred TIMER peripheral to memory
- * @param dma_ch1: Channel of DMA.
- * @param dma_ch2: Channel of DMA.
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_encoder_start_by_dma(ald_timer_handle_t *hperh, ald_timer_channel_t ch,
- uint16_t *buf1, uint16_t *buf2, uint32_t len,
- uint8_t dma_ch1, uint8_t dma_ch2)
- {
- assert_param(IS_TIMER_CC2_INSTANCE(hperh->perh));
- if ((hperh->state == ALD_TIMER_STATE_BUSY))
- return ALD_BUSY;
- if ((hperh->state == ALD_TIMER_STATE_READY)) {
- if (((uint32_t)buf1 == 0) || ((uint32_t)buf2 == 0) || (len == 0))
- return ALD_ERROR;
- }
- if (hperh->hdma1.perh == NULL)
- hperh->hdma1.perh = DMA;
- if (hperh->hdma2.perh == NULL)
- hperh->hdma2.perh = DMA;
- hperh->state = ALD_TIMER_STATE_BUSY;
- hperh->hdma1.cplt_tc_cbk = timer_dma_capture_cplt;
- hperh->hdma1.cplt_tc_arg = (void *)hperh;
- ald_dma_config_struct(&hperh->hdma1.config);
- hperh->hdma1.config.size = len;
- hperh->hdma1.config.src_data_width = ALD_DMA_DATA_SIZE_HALFWORD;
- hperh->hdma1.config.dst_data_width = ALD_DMA_DATA_SIZE_HALFWORD;
- hperh->hdma1.config.src_inc = ALD_DMA_DATA_INC_DISABLE;
- hperh->hdma1.config.dst_inc = ALD_DMA_DATA_INC_ENABLE;
- timer_dma_msel(hperh->perh, &hperh->hdma1.config);
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- hperh->hdma1.config.src = (void *)&hperh->perh->CCVAL1;
- hperh->hdma1.config.dst = (void *)buf1;
- hperh->hdma1.config.msigsel = ALD_DMA_MSIGSEL_TIMER_CH1;
- hperh->hdma1.config.channel = dma_ch1;
- ald_dma_config_basic(&hperh->hdma1);
- ald_dma_interrupt_config(dma_ch1, ALD_DMA_IT_FLAG_TC, ENABLE);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC1, ENABLE);
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, ENABLE);
- ALD_TIMER_ENABLE(hperh);
- break;
- case ALD_TIMER_CHANNEL_2:
- hperh->hdma1.config.src = (void *)&hperh->perh->CCVAL2;
- hperh->hdma1.config.dst = (void *)buf2;
- hperh->hdma1.config.msigsel = ALD_DMA_MSIGSEL_TIMER_CH2;
- hperh->hdma1.config.channel = dma_ch2;
- ald_dma_config_basic(&hperh->hdma1);
- ald_dma_interrupt_config(dma_ch2, ALD_DMA_IT_FLAG_TC, ENABLE);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC2, ENABLE);
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_2, ENABLE);
- ALD_TIMER_ENABLE(hperh);
- break;
- default:
- hperh->hdma2.cplt_tc_cbk = timer_dma_capture_cplt;
- hperh->hdma2.cplt_tc_arg = (void *)hperh;
- memcpy(&hperh->hdma2.config, &hperh->hdma1.config, sizeof(ald_dma_config_t));
- hperh->hdma1.config.src = (void *)&hperh->perh->CCVAL1;
- hperh->hdma1.config.dst = (void *)buf1;
- hperh->hdma1.config.msigsel = ALD_DMA_MSIGSEL_TIMER_CH1;
- hperh->hdma1.config.channel = dma_ch1;
- ald_dma_config_basic(&hperh->hdma1);
- ald_dma_interrupt_config(dma_ch1, ALD_DMA_IT_FLAG_TC, ENABLE);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC1, ENABLE);
- hperh->hdma2.config.src = (void *)&hperh->perh->CCVAL2;
- hperh->hdma2.config.dst = (void *)buf2;
- hperh->hdma2.config.msigsel = ALD_DMA_MSIGSEL_TIMER_CH2;
- hperh->hdma2.config.channel = dma_ch2;
- ald_dma_config_basic(&hperh->hdma2);
- ald_dma_interrupt_config(dma_ch2, ALD_DMA_IT_FLAG_TC, ENABLE);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC2, ENABLE);
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, ENABLE);
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_2, ENABLE);
- ALD_TIMER_ENABLE(hperh);
- break;
- }
- return ALD_OK;
- }
- /**
- * @brief Stops the TIMER Encoder Interface in DMA mode.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be disabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_ALL: TIMER Channel 1 and TIMER Channel 2 are selected
- * @retval None
- */
- void ald_timer_encoder_stop_by_dma(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CC2_INSTANCE(hperh->perh));
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, DISABLE);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC1, DISABLE);
- break;
- case ALD_TIMER_CHANNEL_2:
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_2, DISABLE);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC2, DISABLE);
- break;
- default:
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, DISABLE);
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_2, DISABLE);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC1, DISABLE);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC2, DISABLE);
- break;
- }
- ALD_TIMER_DISABLE(hperh);
- hperh->state = ALD_TIMER_STATE_READY;
- return;
- }
- /**
- * @}
- */
- /** @defgroup TIMER_Public_Functions_Group7 TIMER Hall Sensor functions
- * @brief TIMER Hall Sensor functions
- *
- * @verbatim
- ==============================================================================
- ##### Time Hall Sensor functions #####
- ==============================================================================
- [..]
- This section provides functions allowing to:
- (+) Initialize and configure the TIMER hall sensor.
- (+) Start the hall sensor.
- (+) Stop the hall sensor.
- (+) Start the hall sensor and enable interrupt.
- (+) Stop the hall sensor and disable interrupt.
- (+) Start the hall sensor and enable DMA transfer.
- (+) Stop the hal sensor and disable DMA transfer.
- * @endverbatim
- * @{
- */
- /**
- * @brief Initializes the TIMER Encoder Interface and create the associated handle.
- * @param hperh: TIMER handle
- * @param config: TIMER Encoder Interface configuration structure
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_hall_sensor_init(ald_timer_handle_t *hperh, ald_timer_hall_sensor_init_t *config)
- {
- ald_timer_oc_init_t oc;
- assert_param(IS_TIMER_XOR_INSTANCE(hperh->perh));
- assert_param(IS_TIMER_COUNTER_MODE(hperh->init.mode));
- assert_param(IS_TIMER_CLOCK_DIVISION(hperh->init.clk_div));
- assert_param(IS_TIMER_IC_POLARITY(config->polarity));
- assert_param(IS_TIMER_IC_PSC(config->psc));
- assert_param(IS_TIMER_IC_FILTER(config->filter));
- if (hperh->state == ALD_TIMER_STATE_RESET)
- hperh->lock = UNLOCK;
- hperh->state = ALD_TIMER_STATE_READY;
- timer_base_set_config(hperh->perh, &hperh->init);
- timer_ti1_set_config(hperh->perh, config->polarity, ALD_TIMER_IC_SEL_TRC, config->filter);
- MODIFY_REG(hperh->perh->CHMR1, TIMER_CHMR1_IC1PRES_MSK, config->psc << TIMER_CHMR1_IC1PRES_POSS);
- SET_BIT(hperh->perh->CON2, TIMER_CON2_I1FSEL_MSK);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_TSSEL_MSK, ALD_TIMER_TS_TI1F_ED << TIMER_SMCON_TSSEL_POSS);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_SMODS_MSK, ALD_TIMER_MODE_RESET << TIMER_SMCON_SMODS_POSS);
- oc.oc_mode = ALD_TIMER_OC_MODE_PWM2;
- oc.pulse = config->delay;
- oc.oc_polarity = ALD_TIMER_OC_POLARITY_HIGH;
- oc.ocn_polarity = ALD_TIMER_OCN_POLARITY_HIGH;
- oc.oc_fast_en = DISABLE;
- oc.oc_idle = ALD_TIMER_OC_IDLE_RESET;
- oc.ocn_idle = ALD_TIMER_OCN_IDLE_RESET;
- timer_oc2_set_config(hperh->perh, &oc);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_SMODS_MSK, ALD_TIMER_TRGO_OC2REF << TIMER_SMCON_SMODS_POSS);
- return ALD_OK;
- }
- /**
- * @brief Starts the TIMER hall sensor interface.
- * @param hperh: TIMER handle
- * @retval None
- */
- void ald_timer_hall_sensor_start(ald_timer_handle_t *hperh)
- {
- assert_param(IS_TIMER_XOR_INSTANCE(hperh->perh));
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, ENABLE);
- ALD_TIMER_ENABLE(hperh);
- return;
- }
- /**
- * @brief Stops the TIMER hall sensor interface.
- * @param hperh: TIMER handle
- * @retval None
- */
- void ald_timer_hall_sensor_stop(ald_timer_handle_t *hperh)
- {
- assert_param(IS_TIMER_XOR_INSTANCE(hperh->perh));
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, DISABLE);
- ALD_TIMER_DISABLE(hperh);
- return;
- }
- /**
- * @brief Starts the TIMER hall sensor interface in interrupt mode.
- * @param hperh: TIMER handle
- * @retval None
- */
- void ald_timer_hall_sensor_start_by_it(ald_timer_handle_t *hperh)
- {
- assert_param(IS_TIMER_XOR_INSTANCE(hperh->perh));
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC1, ENABLE);
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, ENABLE);
- ALD_TIMER_ENABLE(hperh);
- return;
- }
- /**
- * @brief Stops the TIMER hall sensor interface in interrupt mode.
- * @param hperh: TIMER handle
- * @retval None
- */
- void ald_timer_hall_sensor_stop_by_it(ald_timer_handle_t *hperh)
- {
- assert_param(IS_TIMER_XOR_INSTANCE(hperh->perh));
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, DISABLE);
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC1, DISABLE);
- ALD_TIMER_DISABLE(hperh);
- return;
- }
- /**
- * @brief Starts the TIMER hall sensor interface in DMA mode.
- * @param hperh: TIMER handle
- * @param buf: The destination Buffer address. Reading data from CCR1.
- * @param len: The length of buffer to be transferred TIMER peripheral to memory
- * @param dma_ch: Channel of DMA.
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_hall_sensor_start_by_dma(ald_timer_handle_t *hperh,
- uint16_t *buf, uint32_t len, uint8_t dma_ch)
- {
- assert_param(IS_TIMER_XOR_INSTANCE(hperh->perh));
- if ((hperh->state == ALD_TIMER_STATE_BUSY))
- return ALD_BUSY;
- if ((hperh->state == ALD_TIMER_STATE_READY)) {
- if (((uint32_t)buf == 0) || (len == 0))
- return ALD_ERROR;
- }
- if (hperh->hdma1.perh == NULL)
- hperh->hdma1.perh = DMA;
- hperh->state = ALD_TIMER_STATE_BUSY;
- hperh->hdma1.cplt_tc_cbk = timer_dma_capture_cplt;
- hperh->hdma1.cplt_tc_arg = (void *)hperh;
- ald_dma_config_struct(&hperh->hdma1.config);
- hperh->hdma1.config.size = len;
- hperh->hdma1.config.src_data_width = ALD_DMA_DATA_SIZE_HALFWORD;
- hperh->hdma1.config.dst_data_width = ALD_DMA_DATA_SIZE_HALFWORD;
- hperh->hdma1.config.src_inc = ALD_DMA_DATA_INC_DISABLE;
- hperh->hdma1.config.dst_inc = ALD_DMA_DATA_INC_ENABLE;
- timer_dma_msel(hperh->perh, &hperh->hdma1.config);
- hperh->hdma1.config.src = (void *)&hperh->perh->CCVAL1;
- hperh->hdma1.config.dst = (void *)buf;
- hperh->hdma1.config.msigsel = ALD_DMA_MSIGSEL_TIMER_CH1;
- hperh->hdma1.config.channel = dma_ch;
- ald_dma_config_basic(&hperh->hdma1);
- ald_dma_interrupt_config(dma_ch, ALD_DMA_IT_FLAG_TC, ENABLE);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC1, ENABLE);
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, ENABLE);
- ALD_TIMER_ENABLE(hperh);
- return ALD_OK;
- }
- /**
- * @brief Stops the TIMER hall sensor interface in DMA mode.
- * @param hperh: TIMER handle
- * @retval None
- */
- void ald_timer_hall_sensor_stop_by_dma(ald_timer_handle_t *hperh)
- {
- assert_param(IS_TIMER_XOR_INSTANCE(hperh->perh));
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC1, DISABLE);
- timer_ccx_channel_cmd(hperh->perh, ALD_TIMER_CHANNEL_1, DISABLE);
- ALD_TIMER_DISABLE(hperh);
- return;
- }
- /**
- * @}
- */
- /** @defgroup TIMER_Public_Functions_Group8 TIMER complementary output compare functions
- * @brief TIMER complementary output compare functions
- *
- * @verbatim
- ==============================================================================
- ##### Time complementary output compare functions #####
- ==============================================================================
- [..]
- This section provides functions allowing to:
- (+) Start the Time complementary output compare.
- (+) Stop the Time complementary output compare.
- (+) Start the Time complementary output compare and enable interrupt.
- (+) Stop the Time complementary output compare and disable interrupt.
- (+) Start the Time complementary output compare and enable DMA transfer.
- (+) Stop the Time complementary output compare and disable DMA transfer.
- * @endverbatim
- * @{
- */
- /**
- * @brief Starts the TIMER output compare signal generation on the complementary output.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @retval None
- */
- void ald_timer_ocn_start(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CCXN_INSTANCE(hperh->perh, ch));
- timer_ccxn_channel_cmd(hperh->perh, ch, ENABLE);
- ALD_TIMER_MOE_ENABLE(hperh);
- ALD_TIMER_ENABLE(hperh);
- return;
- }
- /**
- * @brief Stops the TIMER output compare signal generation on the complementary output.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be disabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @retval None
- */
- void ald_timer_ocn_stop(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CCXN_INSTANCE(hperh->perh, ch));
- timer_ccxn_channel_cmd(hperh->perh, ch, DISABLE);
- ALD_TIMER_MOE_DISABLE(hperh);
- ALD_TIMER_DISABLE(hperh);
- return;
- }
- /**
- * @brief Starts the TIMER output compare signal generation on the complementary output.
- * in interrupt mode
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @retval None
- */
- void ald_timer_ocn_start_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CCXN_INSTANCE(hperh->perh, ch));
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC1, ENABLE);
- break;
- case ALD_TIMER_CHANNEL_2:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC2, ENABLE);
- break;
- case ALD_TIMER_CHANNEL_3:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC3, ENABLE);
- break;
- default:
- break;
- }
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_BREAK, ENABLE);
- timer_ccxn_channel_cmd(hperh->perh, ch, ENABLE);
- ALD_TIMER_MOE_ENABLE(hperh);
- ALD_TIMER_ENABLE(hperh);
- return;
- }
- /**
- * @brief Stops the TIMER output compare signal generation on the complementary output.
- * in interrupt mode
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be disabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @retval None
- */
- void ald_timer_ocn_stop_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CCXN_INSTANCE(hperh->perh, ch));
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC1, DISABLE);
- break;
- case ALD_TIMER_CHANNEL_2:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC2, DISABLE);
- break;
- case ALD_TIMER_CHANNEL_3:
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_CC3, DISABLE);
- break;
- default:
- break;
- }
- if ((!(READ_BIT(hperh->perh->CCEP, TIMER_CCEP_CC1NE_MSK)))
- && (!(READ_BIT(hperh->perh->CCEP, TIMER_CCEP_CC2NE_MSK)))
- && (!(READ_BIT(hperh->perh->CCEP, TIMER_CCEP_CC3NE_MSK)))) {
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_BREAK, DISABLE);
- }
- timer_ccxn_channel_cmd(hperh->perh, ch, DISABLE);
- ALD_TIMER_MOE_DISABLE(hperh);
- ALD_TIMER_DISABLE(hperh);
- return;
- }
- /**
- * @brief Starts the TIMER output compare signal generation on the complementary output.
- * in DMA mode
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @param buf: The destination Buffer address. Reading data from CCRx.
- * @param len: The length of buffer to be transferred TIMER peripheral to memory
- * @param dma_ch: Channel of DMA.
- * @retval None
- */
- ald_status_t ald_timer_ocn_start_by_dma(ald_timer_handle_t *hperh,
- ald_timer_channel_t ch, uint16_t *buf, uint32_t len, uint8_t dma_ch)
- {
- assert_param(IS_TIMER_CCXN_INSTANCE(hperh->perh, ch));
- if ((hperh->state == ALD_TIMER_STATE_BUSY))
- return ALD_BUSY;
- if ((hperh->state == ALD_TIMER_STATE_READY)) {
- if (((uint32_t)buf == 0 ) || (len == 0))
- return ALD_ERROR;
- }
- hperh->state = ALD_TIMER_STATE_BUSY;
- if (hperh->hdma1.perh == NULL)
- hperh->hdma1.perh = DMA;
- hperh->hdma1.cplt_tc_cbk = timer_dma_oc_cplt;
- hperh->hdma1.cplt_tc_arg = (void *)hperh;
- ald_dma_config_struct(&hperh->hdma1.config);
- hperh->hdma1.config.src = (void *)buf;
- hperh->hdma1.config.size = len;
- hperh->hdma1.config.src_data_width = ALD_DMA_DATA_SIZE_HALFWORD;
- hperh->hdma1.config.dst_data_width = ALD_DMA_DATA_SIZE_HALFWORD;
- hperh->hdma1.config.src_inc = ALD_DMA_DATA_INC_ENABLE;
- hperh->hdma1.config.dst_inc = ALD_DMA_DATA_INC_DISABLE;
- hperh->hdma1.config.channel = dma_ch;
- hperh->hdma1.config.msel = ALD_DMA_MSEL_AD16C4T;
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- hperh->hdma1.config.dst = (void *)&hperh->perh->CCVAL1;
- hperh->hdma1.config.msigsel = ALD_DMA_MSIGSEL_TIMER_CH1;
- ald_dma_config_basic(&hperh->hdma1);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC1, ENABLE);
- hperh->ch = ALD_TIMER_ACTIVE_CHANNEL_1;
- break;
- case ALD_TIMER_CHANNEL_2:
- hperh->hdma1.config.dst = (void *)&hperh->perh->CCVAL2;
- hperh->hdma1.config.msigsel = ALD_DMA_MSIGSEL_TIMER_CH2;
- ald_dma_config_basic(&hperh->hdma1);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC2, ENABLE);
- hperh->ch = ALD_TIMER_ACTIVE_CHANNEL_2;
- break;
- case ALD_TIMER_CHANNEL_3:
- hperh->hdma1.config.dst = (void *)&hperh->perh->CCVAL3;
- hperh->hdma1.config.msigsel = ALD_DMA_MSIGSEL_TIMER_CH3;
- ald_dma_config_basic(&hperh->hdma1);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC3, ENABLE);
- hperh->ch = ALD_TIMER_ACTIVE_CHANNEL_3;
- break;
- default:
- break;
- }
- ald_dma_interrupt_config(dma_ch, ALD_DMA_IT_FLAG_TC, ENABLE);
- timer_ccx_channel_cmd(hperh->perh, ch, ENABLE);
- ALD_TIMER_MOE_ENABLE(hperh);
- ALD_TIMER_ENABLE(hperh);
- return ALD_OK;
- }
- /**
- * @brief Starts the TIMER output compare signal generation on the complementary output.
- * in DMA mode
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be disabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @retval None
- */
- void ald_timer_ocn_stop_by_dma(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CCXN_INSTANCE(hperh->perh, ch));
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC1, DISABLE);
- break;
- case ALD_TIMER_CHANNEL_2:
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC2, DISABLE);
- break;
- case ALD_TIMER_CHANNEL_3:
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_CC3, DISABLE);
- break;
- default:
- break;
- }
- timer_ccxn_channel_cmd(hperh->perh, ch, DISABLE);
- ALD_TIMER_MOE_DISABLE(hperh);
- ALD_TIMER_DISABLE(hperh);
- return;
- }
- /**
- * @}
- */
- /** @defgroup TIMER_Public_Functions_Group9 TIMER complementary PWM functions
- * @brief TIMER complementary PWM functions
- *
- * @verbatim
- ==============================================================================
- ##### Time complementary PWM functions #####
- ==============================================================================
- [..]
- This section provides functions allowing to:
- (+) Start the Time complementary PWM.
- (+) Stop the Time complementary PWM.
- (+) Start the Time complementary PWM and enable interrupt.
- (+) Stop the Time complementary PWM and disable interrupt.
- (+) Start the Time complementary PWM and enable DMA transfer.
- (+) Stop the Time complementary PWM and disable DMA transfer.
- * @endverbatim
- * @{
- */
- /**
- * @brief Starts the TIMER PWM signal generation on the complementary output.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @retval None
- */
- void ald_timer_pwmn_start(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- ald_timer_ocn_start(hperh, ch);
- }
- /**
- * @brief Stops the TIMER PWM signal generation on the complementary output.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be disabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @retval None
- */
- void ald_timer_pwmn_stop(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- ald_timer_ocn_stop(hperh, ch);
- }
- /**
- * @brief Starts the TIMER PWM signal generation on the complementary output.
- * in interrupt mode
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @retval None
- */
- void ald_timer_pwmn_start_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- ald_timer_ocn_start_by_it(hperh, ch);
- }
- /**
- * @brief Stops the TIMER PWM signal generation on the complementary output.
- * in interrupt mode
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be disabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @retval None
- */
- void ald_timer_pwmn_stop_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- ald_timer_ocn_stop_by_it(hperh, ch);
- }
- /**
- * @brief Starts the TIMER PWM signal generation on the complementary output.
- * in DMA mode
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @param buf: The destination Buffer address. Reading data from CCRx.
- * @param len: The length of buffer to be transferred TIMER peripheral to memory
- * @param dma_ch: Channel of DMA.
- * @retval None
- */
- ald_status_t ald_timer_pwmn_start_by_dma(ald_timer_handle_t *hperh,
- ald_timer_channel_t ch, uint16_t *buf, uint32_t len, uint8_t dma_ch)
- {
- return ald_timer_ocn_start_by_dma(hperh, ch, buf, len, dma_ch);
- }
- /**
- * @brief Starts the TIMER PWM signal generation on the complementary output.
- * in DMA mode
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be disabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @retval None
- */
- void ald_timer_pwmn_stop_by_dma(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- ald_timer_ocn_stop_by_dma(hperh, ch);
- }
- /**
- * @}
- */
- /** @defgroup TIMER_Public_Functions_Group10 TIMER complementary one pulse functions
- * @brief TIMER complementary one pulse functions
- *
- * @verbatim
- ==============================================================================
- ##### Time complementary one pulse functions #####
- ==============================================================================
- [..]
- This section provides functions allowing to:
- (+) Start the Time complementary one pulse.
- (+) Stop the Time complementary one pulse.
- (+) Start the Time complementary one pulse and enable interrupt.
- (+) Stop the Time complementary one pulse and disable interrupt.
- * @endverbatim
- * @{
- */
- /**
- * @brief Starts the TIMER one pulse signal generation on the complementary output.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @retval None
- */
- void ald_timer_one_pulse_n_start(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- ald_timer_ocn_start(hperh, ch);
- }
- /**
- * @brief Stops the TIMER one pulse signal generation on the complementary output.
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be disabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @retval None
- */
- void ald_timer_one_pulse_n_stop(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- ald_timer_ocn_stop(hperh, ch);
- }
- /**
- * @brief Starts the TIMER one pulse signal generation on the complementary output.
- * in interrupt mode
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @retval None
- */
- void ald_timer_one_pulse_n_start_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- ald_timer_ocn_start_by_it(hperh, ch);
- }
- /**
- * @brief Stops the TIMER one pulse signal generation on the complementary output.
- * in interrupt mode
- * @param hperh: TIMER handle
- * @param ch: TIMER Channels to be disabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @retval None
- */
- void ald_timer_one_pulse_n_stop_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- ald_timer_ocn_stop_by_it(hperh, ch);
- }
- /**
- * @}
- */
- /** @defgroup TIMER_Public_Functions_Group11 Peripheral Control functions
- * @brief Peripheral Control functions
- *
- * @verbatim
- ==============================================================================
- ##### Peripheral Control functions #####
- ==============================================================================
- [..]
- This section provides functions allowing to:
- (+) Configure The Input Output channels for OC, PWM, IC or One Pulse mode.
- (+) Configure External Clock source.
- (+) Configure Complementary channels, break features and dead timere.
- (+) Configure Master and the Slave synchronization.
- (+) Handle TIMER interrupt.
- (+) Get TIMER compare register's vale.
- (+) Configure TIMER interrupt ENABLE/DISABLE.
- (+) Get TIMER interrupt source status.
- (+) Get TIMER interrupt flag status.
- (+) Clear TIMER interrupt flag.
- @endverbatim
- * @{
- */
- /**
- * @brief Initializes the TIMER Output Compare Channels according to the specified
- * parameters in the timer_oc_init_t.
- * @param hperh: TIMER handle
- * @param config: TIMER Output Compare configuration structure
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4: TIMER Channel 4 selected
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_oc_config_channel(ald_timer_handle_t *hperh, ald_timer_oc_init_t* config, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CCX_INSTANCE(hperh->perh, ch));
- assert_param(IS_TIMER_OC_MODE(config->oc_mode));
- assert_param(IS_TIMER_OC_POLARITY(config->oc_polarity));
- __LOCK(hperh);
- hperh->state = ALD_TIMER_STATE_BUSY;
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- timer_oc1_set_config(hperh->perh, config);
- break;
- case ALD_TIMER_CHANNEL_2:
- timer_oc2_set_config(hperh->perh, config);
- break;
- case ALD_TIMER_CHANNEL_3:
- timer_oc3_set_config(hperh->perh, config);
- break;
- case ALD_TIMER_CHANNEL_4:
- timer_oc4_set_config(hperh->perh, config);
- break;
- default:
- break;
- }
- hperh->state = ALD_TIMER_STATE_READY;
- __UNLOCK(hperh);
- return ALD_OK;
- }
- /**
- * @brief Initializes the TIMER Input Capture Channels according to the specified
- * parameters in the timer_ic_init_t.
- * @param hperh: TIMER handle
- * @param config: TIMER Input Capture configuration structure
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3: TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4: TIMER Channel 4 selected
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_ic_config_channel(ald_timer_handle_t *hperh, ald_timer_ic_init_t* config, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CC2_INSTANCE(hperh->perh));
- assert_param(IS_TIMER_IC_POLARITY(config->polarity));
- assert_param(IS_TIMER_IC_SELECT(config->sel));
- assert_param(IS_TIMER_IC_PSC(config->psc));
- assert_param(IS_TIMER_IC_FILTER(config->filter));
- __LOCK(hperh);
- hperh->state = ALD_TIMER_STATE_BUSY;
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- timer_ti1_set_config(hperh->perh, config->polarity, config->sel, config->filter);
- MODIFY_REG(hperh->perh->CHMR1, TIMER_CHMR1_IC1PRES_MSK, config->psc << TIMER_CHMR1_IC1PRES_POSS);
- break;
- case ALD_TIMER_CHANNEL_2:
- timer_ti2_set_config(hperh->perh, config->polarity, config->sel, config->filter);
- MODIFY_REG(hperh->perh->CHMR1, TIMER_CHMR1_IC2PRES_MSK, config->psc << TIMER_CHMR1_IC2PRES_POSS);
- break;
- case ALD_TIMER_CHANNEL_3:
- timer_ti3_set_config(hperh->perh, config->polarity, config->sel, config->filter);
- MODIFY_REG(hperh->perh->CHMR2, TIMER_CHMR2_IC3PRES_MSK, config->psc << TIMER_CHMR2_IC3PRES_POSS);
- break;
- case ALD_TIMER_CHANNEL_4:
- timer_ti4_set_config(hperh->perh, config->polarity, config->sel, config->filter);
- MODIFY_REG(hperh->perh->CHMR2, TIMER_CHMR2_IC4PRES_MSK, config->psc << TIMER_CHMR2_IC4PRES_POSS);
- break;
- default:
- break;
- }
- hperh->state = ALD_TIMER_STATE_READY;
- __UNLOCK(hperh);
- return ALD_OK;
- }
- /**
- * @brief Initializes the TIMER One Pulse Channels according to the specified
- * parameters in the timer_one_pulse_init_t.
- * @param hperh: TIMER handle
- * @param config: TIMER One Pulse configuration structure
- * @param ch_out: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @param ch_in: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2: TIMER Channel 2 selected
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_one_pulse_config_channel(ald_timer_handle_t *hperh, ald_timer_one_pulse_init_t *config,
- ald_timer_channel_t ch_out, ald_timer_channel_t ch_in)
- {
- ald_timer_oc_init_t tmp;
- assert_param(IS_TIMER_CC2_INSTANCE(hperh->perh));
- assert_param(IS_TIMER_OC_MODE(config->mode));
- assert_param(IS_TIMER_OC_POLARITY(config->oc_polarity));
- assert_param(IS_TIMER_OCN_POLARITY(config->ocn_polarity));
- assert_param(IS_TIMER_OCIDLE_STATE(config->oc_idle));
- assert_param(IS_TIMER_OCNIDLE_STATE(config->ocn_idle));
- assert_param(IS_TIMER_IC_POLARITY(config->polarity));
- assert_param(IS_TIMER_IC_SELECT(config->sel));
- assert_param(IS_TIMER_IC_FILTER(config->filter));
- if (ch_out == ch_in)
- return ALD_ERROR;
- __LOCK(hperh);
- hperh->state = ALD_TIMER_STATE_BUSY;
- tmp.oc_mode = config->mode;
- tmp.pulse = config->pulse;
- tmp.oc_polarity = config->oc_polarity;
- tmp.ocn_polarity = config->ocn_polarity;
- tmp.oc_idle = config->oc_idle;
- tmp.ocn_idle = config->ocn_idle;
- switch (ch_out) {
- case ALD_TIMER_CHANNEL_1:
- timer_oc1_set_config(hperh->perh, &tmp);
- break;
- case ALD_TIMER_CHANNEL_2:
- timer_oc2_set_config(hperh->perh, &tmp);
- break;
- default:
- break;
- }
- switch (ch_in) {
- case ALD_TIMER_CHANNEL_1:
- timer_ti1_set_config(hperh->perh, config->polarity, config->sel, config->filter);
- CLEAR_BIT(hperh->perh->CHMR1, TIMER_CHMR1_IC1PRES_MSK);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_TSSEL_MSK, ALD_TIMER_TS_TI1FP1 << TIMER_SMCON_TSSEL_POSS);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_SMODS_MSK, ALD_TIMER_MODE_TRIG << TIMER_SMCON_SMODS_POSS);
- break;
- case ALD_TIMER_CHANNEL_2:
- timer_ti2_set_config(hperh->perh, config->polarity, config->sel, config->filter);
- CLEAR_BIT(hperh->perh->CHMR1, TIMER_CHMR1_IC2PRES_MSK);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_TSSEL_MSK, ALD_TIMER_TS_TI2FP2 << TIMER_SMCON_TSSEL_POSS);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_SMODS_MSK, ALD_TIMER_MODE_TRIG << TIMER_SMCON_SMODS_POSS);
- break;
- default:
- break;
- }
- hperh->state = ALD_TIMER_STATE_READY;
- __UNLOCK(hperh);
- return ALD_OK;
- }
- /**
- * @brief Configures the OCRef clear feature
- * @param hperh: TIMER handle
- * @param config: pointer to a TIMER_ClearInputConfigTypeDef structure that
- * contains the OCREF clear feature and parameters for the TIMER peripheral.
- * @param ch: specifies the TIMER Channel
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1
- * @arg TIMER_CHANNEL_2: TIMER Channel 2
- * @arg TIMER_CHANNEL_3: TIMER Channel 3
- * @arg TIMER_CHANNEL_4: TIMER Channel 4
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_config_oc_ref_clear(ald_timer_handle_t *hperh, ald_timer_clear_input_config_t *config, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CC2_INSTANCE(hperh->perh));
- assert_param(IS_FUNC_STATE(config->state));
- assert_param(IS_TIMER_CLEAR_INPUT_SOURCE(config->source));
- assert_param(IS_TIMER_CLEAR_INPUT_POLARITY(config->polarity));
- assert_param(IS_TIMER_ETR_PSC(config->psc));
- assert_param(IS_TIMER_CHNREF_CLEAR(config->clrsel));
- assert_param(IS_TIMER_IC_FILTER(config->filter));
- if (config->source == ALD_TIMER_INPUT_NONE) {
- timer_etr_set_config(hperh->perh, ALD_TIMER_ETR_PSC_DIV1, ALD_TIMER_CLK_POLARITY_NO_INV, 0);
- }
- else {
- timer_etr_set_config(hperh->perh, config->psc,
- (ald_timer_clock_polarity_t)config->polarity, config->filter);
- }
- if (config->clrsel == ALD_TIMER_CHNREF_CLR_CMP_IN) {
- CLEAR_BIT(hperh->perh->SMCON, TIMER_SMCON_OCCS_MSK);
- }
- else {
- SET_BIT(hperh->perh->SMCON, TIMER_SMCON_OCCS_MSK);
- }
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- MODIFY_REG(hperh->perh->CHMR1, TIMER_CHMR1_CH1OCLREN_MSK, config->state << TIMER_CHMR1_CH1OCLREN_POS);
- break;
- case ALD_TIMER_CHANNEL_2:
- MODIFY_REG(hperh->perh->CHMR1, TIMER_CHMR1_CH2OCLREN_MSK, config->state << TIMER_CHMR1_CH2OCLREN_POS);
- break;
- case ALD_TIMER_CHANNEL_3:
- assert_param(IS_TIMER_CC4_INSTANCE(hperh->perh));
- MODIFY_REG(hperh->perh->CHMR2, TIMER_CHMR2_CH3OCLREN_MSK, config->state << TIMER_CHMR2_CH3OCLREN_POS);
- break;
- case ALD_TIMER_CHANNEL_4:
- assert_param(IS_TIMER_CC4_INSTANCE(hperh->perh));
- MODIFY_REG(hperh->perh->CHMR2, TIMER_CHMR2_CH4OCLREN_MSK, config->state << TIMER_CHMR2_CH4OCLREN_POS);
- break;
- default:
- break;
- }
- return ALD_OK;
- }
- /**
- * @brief Configures the clock source to be used
- * @param hperh: TIMER handle
- * @param config: pointer to a timer_clock_config_t structure that
- * contains the clock source information for the TIMER peripheral.
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_config_clock_source(ald_timer_handle_t *hperh, ald_timer_clock_config_t *config)
- {
- assert_param(IS_TIMER_INSTANCE(hperh->perh));
- assert_param(IS_TIMER_CLOCK_SOURCE(config->source));
- assert_param(IS_TIMER_CLOCK_POLARITY(config->polarity));
- assert_param(IS_TIMER_ETR_PSC(config->psc));
- assert_param(IS_TIMER_IC_FILTER(config->filter));
- __LOCK(hperh);
- hperh->state = ALD_TIMER_STATE_BUSY;
- WRITE_REG(hperh->perh->SMCON, 0x0);
- switch (config->source) {
- case ALD_TIMER_SRC_INTER:
- CLEAR_BIT(hperh->perh->SMCON, TIMER_SMCON_SMODS_MSK);
- break;
- case ALD_TIMER_SRC_ETRMODE1:
- timer_etr_set_config(hperh->perh, config->psc, config->polarity, config->filter);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_TSSEL_MSK, ALD_TIMER_TS_ETRF << TIMER_SMCON_TSSEL_POSS);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_SMODS_MSK, ALD_TIMER_MODE_EXTERNAL1 << TIMER_SMCON_SMODS_POSS);
- break;
- case ALD_TIMER_SRC_ETRMODE2:
- timer_etr_set_config(hperh->perh, config->psc, config->polarity, config->filter);
- SET_BIT(hperh->perh->SMCON, TIMER_SMCON_ECM2EN_MSK);
- break;
- case ALD_TIMER_SRC_TI1:
- timer_ti1_set_config_stage(hperh->perh, (ald_timer_ic_polarity_t)config->polarity, config->filter);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_TSSEL_MSK, ALD_TIMER_TS_TI1FP1 << TIMER_SMCON_TSSEL_POSS);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_SMODS_MSK, ALD_TIMER_MODE_EXTERNAL1 << TIMER_SMCON_SMODS_POSS);
- break;
- case ALD_TIMER_SRC_TI2:
- timer_ti2_set_config_stage(hperh->perh, (ald_timer_ic_polarity_t)config->polarity, config->filter);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_TSSEL_MSK, ALD_TIMER_TS_TI2FP2 << TIMER_SMCON_TSSEL_POSS);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_SMODS_MSK, ALD_TIMER_MODE_EXTERNAL1 << TIMER_SMCON_SMODS_POSS);
- break;
- case ALD_TIMER_SRC_TI1ED:
- timer_ti1_set_config_stage(hperh->perh, (ald_timer_ic_polarity_t)config->polarity, config->filter);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_TSSEL_MSK, ALD_TIMER_TS_TI1F_ED << TIMER_SMCON_TSSEL_POSS);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_SMODS_MSK, ALD_TIMER_MODE_EXTERNAL1 << TIMER_SMCON_SMODS_POSS);
- break;
- case ALD_TIMER_SRC_ITR0:
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_TSSEL_MSK, ALD_TIMER_TS_ITR0 << TIMER_SMCON_TSSEL_POSS);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_SMODS_MSK, ALD_TIMER_MODE_EXTERNAL1 << TIMER_SMCON_SMODS_POSS);
- break;
- case ALD_TIMER_SRC_ITR1:
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_TSSEL_MSK, ALD_TIMER_TS_ITR1 << TIMER_SMCON_TSSEL_POSS);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_SMODS_MSK, ALD_TIMER_MODE_EXTERNAL1 << TIMER_SMCON_SMODS_POSS);
- break;
- case ALD_TIMER_SRC_ITR2:
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_TSSEL_MSK, ALD_TIMER_TS_ITR2 << TIMER_SMCON_TSSEL_POSS);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_SMODS_MSK, ALD_TIMER_MODE_EXTERNAL1 << TIMER_SMCON_SMODS_POSS);
- break;
- case ALD_TIMER_SRC_ITR3:
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_TSSEL_MSK, ALD_TIMER_TS_ITR3 << TIMER_SMCON_TSSEL_POSS);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_SMODS_MSK, ALD_TIMER_MODE_EXTERNAL1 << TIMER_SMCON_SMODS_POSS);
- break;
- default:
- break;
- }
- hperh->state = ALD_TIMER_STATE_READY;
- __UNLOCK(hperh);
- return ALD_OK;
- }
- /**
- * @brief Selects the signal connected to the TI1 input: direct from CH1_input
- * or a XOR combination between CH1_input, CH2_input & CH3_input
- * @param hperh: TIMER handle.
- * @param ti1_select: Indicate whether or not channel 1 is connected to the
- * output of a XOR gate.
- * This parameter can be one of the following values:
- * @arg 0: The TIMERx_CH1 pin is connected to TI1 input
- * @arg 1: The TIMERx_CH1, CH2 and CH3
- * pins are connected to the TI1 input (XOR combination)
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_config_ti1_input(ald_timer_handle_t *hperh, uint32_t ti1_select)
- {
- assert_param(IS_TIMER_INSTANCE(hperh->perh));
- MODIFY_REG(hperh->perh->CON2, TIMER_CON2_I1FSEL_MSK, ti1_select << TIMER_CON2_I1FSEL_POS);
- return ALD_OK;
- }
- /**
- * @brief Configures the TIMER in Slave mode
- * @param hperh: TIMER handle.
- * @param config: pointer to a timer_slave_config_t structure that
- * contains the selected trigger (internal trigger input, filtered
- * timerer input or external trigger input) and the Slave
- * mode (Disable, Reset, Gated, Trigger, External clock mode 1).
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_slave_config_sync(ald_timer_handle_t *hperh, ald_timer_slave_config_t *config)
- {
- assert_param(IS_TIMER_INSTANCE(hperh->perh));
- assert_param(IS_TIMER_SLAVE_MODE(config->mode));
- assert_param(IS_TIMER_TS(config->input));
- assert_param(IS_TIMER_CLOCK_POLARITY(config->polarity));
- assert_param(IS_TIMER_ETR_PSC(config->psc));
- assert_param(IS_TIMER_IC_FILTER(config->filter));
- __LOCK(hperh);
- hperh->state = ALD_TIMER_STATE_BUSY;
- timer_slave_set_config(hperh, config);
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_TRIGGER, DISABLE);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_TRIGGER, DISABLE);
- hperh->state = ALD_TIMER_STATE_READY;
- __UNLOCK(hperh);
- return ALD_OK;
- }
- /**
- * @brief Configures the TIMER in Slave mode in interrupt mode
- * @param hperh: TIMER handle.
- * @param config: pointer to a timer_slave_config_t structure that
- * contains the selected trigger (internal trigger input, filtered
- * timerer input or external trigger input) and the ) and the Slave
- * mode (Disable, Reset, Gated, Trigger, External clock mode 1).
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_slave_config_sync_by_it(ald_timer_handle_t *hperh, ald_timer_slave_config_t *config)
- {
- assert_param(IS_TIMER_INSTANCE(hperh->perh));
- assert_param(IS_TIMER_SLAVE_MODE(config->mode));
- assert_param(IS_TIMER_TS(config->input));
- assert_param(IS_TIMER_CLOCK_POLARITY(config->polarity));
- assert_param(IS_TIMER_ETR_PSC(config->psc));
- assert_param(IS_TIMER_IC_FILTER(config->filter));
- __LOCK(hperh);
- hperh->state = ALD_TIMER_STATE_BUSY;
- timer_slave_set_config(hperh, config);
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_TRIGGER, ENABLE);
- ald_timer_dma_req_config(hperh, ALD_TIMER_DMA_TRIGGER, DISABLE);
- hperh->state = ALD_TIMER_STATE_READY;
- __UNLOCK(hperh);
- return ALD_OK;
- }
- /**
- * @brief Generate a software event
- * @param hperh: TIMER handle
- * @param event: specifies the event source.
- * @retval Status, see @ref ald_status_t.
- */
- ald_status_t ald_timer_generate_event(ald_timer_handle_t *hperh, ald_timer_event_source_t event)
- {
- assert_param(IS_TIMER_INSTANCE(hperh->perh));
- assert_param(IS_TIMER_EVENT_SOURCE(event));
- __LOCK(hperh);
- hperh->state = ALD_TIMER_STATE_BUSY;
- WRITE_REG(hperh->perh->SGE, event);
- hperh->state = ALD_TIMER_STATE_READY;
- __UNLOCK(hperh);
- return ALD_OK;
- }
- /**
- * @brief Read the captured value from Capture Compare unit
- * @param hperh: TIMER handle.
- * @param ch: TIMER Channels to be enabled
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1 : TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2 : TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3 : TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4 : TIMER Channel 4 selected
- * @retval Captured value
- */
- uint32_t ald_timer_read_capture_value(ald_timer_handle_t *hperh, ald_timer_channel_t ch)
- {
- uint32_t tmp;
- __LOCK(hperh);
- hperh->state = ALD_TIMER_STATE_BUSY;
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- tmp = hperh->perh->CCVAL1;
- break;
- case ALD_TIMER_CHANNEL_2:
- tmp = hperh->perh->CCVAL2;
- break;
- case ALD_TIMER_CHANNEL_3:
- tmp = hperh->perh->CCVAL3;
- break;
- case ALD_TIMER_CHANNEL_4:
- tmp = hperh->perh->CCVAL4;
- break;
- default:
- tmp = hperh->perh->CCVAL1;
- break;
- }
- hperh->state = ALD_TIMER_STATE_READY;
- __UNLOCK(hperh);
- return tmp;
- }
- /**
- * @brief Sets TIMER output mode.
- * @param hperh: TIMER handle.
- * @param mode: TIMER output mode.
- * @param ch: TIMER Channels.
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1 : TIMER Channel 1 selected
- * @arg TIMER_CHANNEL_2 : TIMER Channel 2 selected
- * @arg TIMER_CHANNEL_3 : TIMER Channel 3 selected
- * @arg TIMER_CHANNEL_4 : TIMER Channel 4 selected
- * @retval None
- */
- void ald_timer_set_output_mode(ald_timer_handle_t *hperh, ald_timer_oc_mode_t mode, ald_timer_channel_t ch)
- {
- assert_param(IS_TIMER_CC2_INSTANCE(hperh->perh));
- assert_param(IS_TIMER_OC_MODE(mode));
- assert_param(IS_TIMER_CHANNELS(ch));
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- MODIFY_REG(hperh->perh->CHMR1, TIMER_CHMR1_CH1OMOD_MSK, mode << TIMER_CHMR1_CH1OMOD_POSS);
- break;
- case ALD_TIMER_CHANNEL_2:
- MODIFY_REG(hperh->perh->CHMR1, TIMER_CHMR1_CH2OMOD_MSK, mode << TIMER_CHMR1_CH2OMOD_POSS);
- break;
- case ALD_TIMER_CHANNEL_3:
- MODIFY_REG(hperh->perh->CHMR2, TIMER_CHMR2_CH3OMOD_MSK, mode << TIMER_CHMR2_CH3OMOD_POSS);
- break;
- case ALD_TIMER_CHANNEL_4:
- MODIFY_REG(hperh->perh->CHMR2, TIMER_CHMR2_CH4OMOD_MSK, mode << TIMER_CHMR2_CH4OMOD_POSS);
- break;
- default:
- break;
- }
- return;
- }
- /**
- * @brief Configure the channel in commutation event.
- * @param hperh: TIMER handel
- * @param config: Parameters of the channel.
- * @retval None
- */
- void ald_timer_com_change_config(ald_timer_handle_t *hperh, ald_timer_com_channel_config_t *config)
- {
- uint32_t cm1, cm2, cce;
- assert_param(IS_TIMER_COM_EVENT_INSTANCE(hperh->perh));
- assert_param(IS_FUNC_STATE(config->ch[0].en));
- assert_param(IS_FUNC_STATE(config->ch[0].n_en));
- assert_param(IS_TIMER_OC_MODE(config->ch[0].mode));
- assert_param(IS_FUNC_STATE(config->ch[1].en));
- assert_param(IS_FUNC_STATE(config->ch[1].n_en));
- assert_param(IS_TIMER_OC_MODE(config->ch[1].mode));
- assert_param(IS_FUNC_STATE(config->ch[2].en));
- assert_param(IS_FUNC_STATE(config->ch[2].n_en));
- assert_param(IS_TIMER_OC_MODE(config->ch[2].mode));
- ALD_TIMER_MOE_DISABLE(hperh);
- ALD_TIMER_DISABLE(hperh);
- cm1 = hperh->perh->CHMR1;
- cm2 = hperh->perh->CHMR2;
- cce = hperh->perh->CCEP;
- MODIFY_REG(cm1, (0x7 << 4), (config->ch[0].mode << 4));
- MODIFY_REG(cm1, (0x7 << 12), (config->ch[1].mode << 12));
- MODIFY_REG(cm2, (0x7 << 4), (config->ch[2].mode << 4));
- MODIFY_REG(cce, (0x1 << 0), (config->ch[0].en << 0));
- MODIFY_REG(cce, (0x1 << 2), (config->ch[0].n_en << 2));
- MODIFY_REG(cce, (0x1 << 4), (config->ch[1].en << 4));
- MODIFY_REG(cce, (0x1 << 6), (config->ch[1].n_en << 6));
- MODIFY_REG(cce, (0x1 << 8), (config->ch[2].en << 8));
- MODIFY_REG(cce, (0x1 << 10), (config->ch[2].n_en << 10));
- WRITE_REG(hperh->perh->CHMR1, cm1);
- WRITE_REG(hperh->perh->CHMR2, cm2);
- WRITE_REG(hperh->perh->CCEP, cce);
- ALD_TIMER_MOE_ENABLE(hperh);
- ALD_TIMER_ENABLE(hperh);
- return;
- }
- /**
- * @brief Configure the TIMER commutation event sequence.
- * @param hperh: TIMER handel
- * @param ts: the internal trigger corresponding to the timerer interfacing
- * with the hall sensor.
- * This parameter can be one of the following values:
- * @arg TIMER_TS_ITR0
- * @arg TIMER_TS_ITR1
- * @arg TIMER_TS_ITR2
- * @arg TIMER_TS_ITR3
- * @param trgi: the commutation event source.
- * This parameter can be one of the following values:
- * @arg ENABLE: Commutation event source is TRGI
- * @arg DISABLE: Commutation event source is set by software using the COMG bit
- * @retval None
- */
- void ald_timer_com_event_config(ald_timer_handle_t *hperh, ald_timer_ts_t ts, type_func_t trgi)
- {
- assert_param(IS_TIMER_COM_EVENT_INSTANCE(hperh->perh));
- assert_param(IS_TIMER_TS(ts));
- assert_param(IS_FUNC_STATE(trgi));
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_TSSEL_MSK, ts << TIMER_SMCON_TSSEL_POSS);
- SET_BIT(hperh->perh->CON2, TIMER_CON2_CCPCEN_MSK);
- MODIFY_REG(hperh->perh->CON2, TIMER_CON2_CCUSEL_MSK, trgi << TIMER_CON2_CCUSEL_POS);
- return;
- }
- /**
- * @brief Configure the TIMER commutation event sequence with interrupt.
- * @param hperh: TIMER handel
- * @param ts: the internal trigger corresponding to the timerer interfacing
- * with the hall sensor.
- * This parameter can be one of the following values:
- * @arg TIMER_TS_ITR0
- * @arg TIMER_TS_ITR1
- * @arg TIMER_TS_ITR2
- * @arg TIMER_TS_ITR3
- * @param trgi: the commutation event source.
- * This parameter can be one of the following values:
- * @arg ENABLE: Commutation event source is TRGI
- * @arg DISABLE: Commutation event source is set by software using the COMG bit
- * @retval None
- */
- void ald_timer_com_event_config_it(ald_timer_handle_t *hperh, ald_timer_ts_t ts, type_func_t trgi)
- {
- ald_timer_com_event_config(hperh, ts, trgi);
- ald_timer_interrupt_config(hperh, ALD_TIMER_IT_COM, ENABLE);
- }
- /**
- * @brief Configure the break, dead timere, lock level state.
- * @param hperh: TIMER handle
- * @param config: Pointer to the timer_break_dead_timere_t structure.
- * @retval None
- */
- void ald_timer_break_dead_time_config(ald_timer_handle_t *hperh, ald_timer_break_dead_time_t *config)
- {
- uint32_t tmp;
- assert_param(IS_TIMER_BREAK_INSTANCE(hperh->perh));
- assert_param(IS_FUNC_STATE(config->off_run));
- assert_param(IS_FUNC_STATE(config->off_idle));
- assert_param(IS_TIMER_CLOCK_LEVEL(config->lock_level));
- assert_param(IS_TIMER_DEAD_TIMERE(config->dead_time));
- assert_param(IS_FUNC_STATE(config->break_state));
- assert_param(IS_TIMER_BREAK_POLARITY(config->polarity));
- assert_param(IS_FUNC_STATE(config->auto_out));
- tmp = READ_REG(hperh->perh->BDCFG);
- MODIFY_REG(tmp, TIMER_BDCFG_OFFSSR_MSK, config->off_run << TIMER_BDCFG_OFFSSR_POS);
- MODIFY_REG(tmp, TIMER_BDCFG_OFFSSI_MSK, config->off_idle << TIMER_BDCFG_OFFSSI_POS);
- MODIFY_REG(tmp, TIMER_BDCFG_LOCKLVL_MSK, config->lock_level << TIMER_BDCFG_LOCKLVL_POSS);
- MODIFY_REG(tmp, TIMER_BDCFG_DT_MSK, config->dead_time << TIMER_BDCFG_DT_POSS);
- MODIFY_REG(tmp, TIMER_BDCFG_BRKEN_MSK, config->break_state << TIMER_BDCFG_BRKEN_POS);
- MODIFY_REG(tmp, TIMER_BDCFG_BRKP_MSK, config->polarity << TIMER_BDCFG_BRKP_POS);
- MODIFY_REG(tmp, TIMER_BDCFG_AOEN_MSK, config->auto_out << TIMER_BDCFG_AOEN_POS);
- WRITE_REG(hperh->perh->BDCFG, tmp);
- hperh->state = ALD_TIMER_STATE_READY;
- return;
- }
- /**
- * @brief Configure the master mode
- * @param hperh: TIMER handle
- * @param config: Pointer to the timer_master_config_t structure.
- * @retval None
- */
- void ald_timer_master_sync_config(ald_timer_handle_t *hperh, ald_timer_master_config_t *config)
- {
- assert_param(IS_TIMER_INSTANCE(hperh->perh));
- assert_param(IS_TIMER_MASTER_MODE_SEL(config->sel));
- assert_param(IS_FUNC_STATE(config->master_en));
- hperh->state = ALD_TIMER_STATE_BUSY;
- MODIFY_REG(hperh->perh->CON2, TIMER_CON2_TRGOSEL_MSK, config->sel << TIMER_CON2_TRGOSEL_POSS);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_MSCFG_MSK, config->master_en << TIMER_SMCON_MSCFG_POS);
- hperh->state = ALD_TIMER_STATE_READY;
- return;
- }
- /**
- * @brief This function handles TIMER interrupts requests.
- * @param hperh: TIMER handle
- * @retval None
- */
- void ald_timer_irq_handler(ald_timer_handle_t *hperh)
- {
- uint32_t reg = hperh->perh->IFM;
- /* Capture or compare 1 event */
- if (READ_BIT(reg, ALD_TIMER_FLAG_CC1)) {
- ald_timer_clear_flag_status(hperh, ALD_TIMER_FLAG_CC1);
- hperh->ch = ALD_TIMER_ACTIVE_CHANNEL_1;
- /* Input capture event */
- if (READ_BIT(hperh->perh->CHMR1, TIMER_CHMR1_CC1SSEL_MSK)) {
- if (hperh->capture_cbk)
- hperh->capture_cbk(hperh);
- }
- else { /* Output compare event */
- if (hperh->delay_elapse_cbk)
- hperh->delay_elapse_cbk(hperh);
- if (hperh->pwm_pulse_finish_cbk)
- hperh->pwm_pulse_finish_cbk(hperh);
- }
- hperh->ch = ALD_TIMER_ACTIVE_CHANNEL_CLEARED;
- }
- /* Capture or compare 2 event */
- if (READ_BIT(reg, ALD_TIMER_FLAG_CC2)) {
- ald_timer_clear_flag_status(hperh, ALD_TIMER_FLAG_CC2);
- hperh->ch = ALD_TIMER_ACTIVE_CHANNEL_2;
- /* Input capture event */
- if (READ_BIT(hperh->perh->CHMR1, TIMER_CHMR1_CC2SSEL_MSK)) {
- if (hperh->capture_cbk)
- hperh->capture_cbk(hperh);
- }
- else { /* Output compare event */
- if (hperh->delay_elapse_cbk)
- hperh->delay_elapse_cbk(hperh);
- if (hperh->pwm_pulse_finish_cbk)
- hperh->pwm_pulse_finish_cbk(hperh);
- }
- hperh->ch = ALD_TIMER_ACTIVE_CHANNEL_CLEARED;
- }
- /* Capture or compare 3 event */
- if (READ_BIT(reg, ALD_TIMER_FLAG_CC3)) {
- ald_timer_clear_flag_status(hperh, ALD_TIMER_FLAG_CC3);
- hperh->ch = ALD_TIMER_ACTIVE_CHANNEL_3;
- /* Input capture event */
- if (READ_BIT(hperh->perh->CHMR2, TIMER_CHMR2_CC3SSEL_MSK)) {
- if (hperh->capture_cbk)
- hperh->capture_cbk(hperh);
- }
- else { /* Output compare event */
- if (hperh->delay_elapse_cbk)
- hperh->delay_elapse_cbk(hperh);
- if (hperh->pwm_pulse_finish_cbk)
- hperh->pwm_pulse_finish_cbk(hperh);
- }
- hperh->ch = ALD_TIMER_ACTIVE_CHANNEL_CLEARED;
- }
- /* Capture or compare 4 event */
- if (READ_BIT(reg, ALD_TIMER_FLAG_CC4)) {
- ald_timer_clear_flag_status(hperh, ALD_TIMER_FLAG_CC4);
- hperh->ch = ALD_TIMER_ACTIVE_CHANNEL_4;
- /* Input capture event */
- if (READ_BIT(hperh->perh->CHMR2, TIMER_CHMR2_CC4SSEL_MSK)) {
- if (hperh->capture_cbk)
- hperh->capture_cbk(hperh);
- }
- else { /* Output compare event */
- if (hperh->delay_elapse_cbk)
- hperh->delay_elapse_cbk(hperh);
- if (hperh->pwm_pulse_finish_cbk)
- hperh->pwm_pulse_finish_cbk(hperh);
- }
- hperh->ch = ALD_TIMER_ACTIVE_CHANNEL_CLEARED;
- }
- /* TIMER Update event */
- if (READ_BIT(reg, ALD_TIMER_FLAG_UPDATE)) {
- ald_timer_clear_flag_status(hperh, ALD_TIMER_FLAG_UPDATE);
- if (hperh->period_elapse_cbk)
- hperh->period_elapse_cbk(hperh);
- }
- /* TIMER Break input event */
- if (READ_BIT(reg, ALD_TIMER_FLAG_BREAK)) {
- ald_timer_clear_flag_status(hperh, ALD_TIMER_FLAG_BREAK);
- if (hperh->break_cbk)
- hperh->break_cbk(hperh);
- }
- /* TIMER Trigger detection event */
- if (READ_BIT(reg, ALD_TIMER_FLAG_TRIGGER)) {
- ald_timer_clear_flag_status(hperh, ALD_TIMER_FLAG_TRIGGER);
- if (hperh->trigger_cbk)
- hperh->trigger_cbk(hperh);
- }
- /* TIMER commutation event */
- if (READ_BIT(reg, ALD_TIMER_FLAG_COM)) {
- ald_timer_clear_flag_status(hperh, ALD_TIMER_FLAG_COM);
- if (hperh->com_cbk)
- hperh->com_cbk(hperh);
- }
- return;
- }
- /**
- * @brief Configure DMA request source.
- * @param hperh: TIMER handle
- * @param req: DMA request source.
- * @param state: New state of the specified DMA request.
- * @retval None
- */
- void ald_timer_dma_req_config(ald_timer_handle_t *hperh, ald_timer_dma_req_t req, type_func_t state)
- {
- assert_param(IS_TIMER_INSTANCE(hperh->perh));
- assert_param(IS_TIMER_DMA_REQ(req));
- assert_param(IS_FUNC_STATE(state));
- if (state == ENABLE)
- SET_BIT(hperh->perh->DMAEN, req);
- else
- CLEAR_BIT(hperh->perh->DMAEN, req);
- return;
- }
- /**
- * @brief Enable/disable the specified TIMER interrupts.
- * @param hperh: Pointer to a timer_handle_t structure.
- * @param it: Specifies the timer interrupt sources to be enabled or disabled.
- * This parameter can be one of the @ref timer_it_t.
- * @param state: New state of the specified TIMER interrupts.
- * This parameter can be:
- * @arg ENABLE
- * @arg DISABLE
- * @retval None
- */
- void ald_timer_interrupt_config(ald_timer_handle_t *hperh, ald_timer_it_t it, type_func_t state)
- {
- assert_param(IS_TIMER_INSTANCE(hperh->perh));
- assert_param(IS_TIMER_IT(it));
- assert_param(IS_FUNC_STATE(state));
- if (state == ENABLE)
- SET_BIT(hperh->perh->IER, it);
- else
- SET_BIT(hperh->perh->IDR, it);
- return;
- }
- /**
- * @brief Get the status of TIMER interrupt source.
- * @param hperh: Pointer to a timer_handle_t structure.
- * @param it: Specifies the TIMER interrupt source.
- * This parameter can be one of the @ref timer_it_t.
- * @retval Status:
- * - 0: RESET
- * - 1: SET
- */
- it_status_t ald_timer_get_it_status(ald_timer_handle_t *hperh, ald_timer_it_t it)
- {
- assert_param(IS_TIMER_INSTANCE(hperh->perh));
- assert_param(IS_TIMER_IT(it));
- if (hperh->perh->IVS & it)
- return SET;
- return RESET;
- }
- /**
- * @brief Get the status of TIMER interrupt flag.
- * @param hperh: Pointer to a timer_handle_t structure.
- * @param flag: Specifies the TIMER interrupt flag.
- * This parameter can be one of the @ref timer_flag_t.
- * @retval Status:
- * - 0: RESET
- * - 1: SET
- */
- flag_status_t ald_timer_get_flag_status(ald_timer_handle_t *hperh, ald_timer_flag_t flag)
- {
- assert_param(IS_TIMER_INSTANCE(hperh->perh));
- assert_param(IS_TIMER_FLAG(flag));
- if (hperh->perh->RIF & flag)
- return SET;
- return RESET;
- }
- /**
- * @brief Clear the TIMER interrupt flag.
- * @param hperh: Pointer to a timer_handle_t structure.
- * @param flag: Specifies the TIMER interrupt flag.
- * This parameter can be one of the @ref timer_flag_t.
- * @retval None
- */
- void ald_timer_clear_flag_status(ald_timer_handle_t *hperh, ald_timer_flag_t flag)
- {
- assert_param(IS_TIMER_INSTANCE(hperh->perh));
- assert_param(IS_TIMER_FLAG(flag));
- hperh->perh->ICR = flag;
- return;
- }
- /**
- * @}
- */
- /** @defgroup TIMER_Public_Functions_Group12 Peripheral State functions
- * @brief Peripheral State functions
- *
- * @verbatim
- ==============================================================================
- ##### Peripheral State functions #####
- ==============================================================================
- [..]
- This subsection permit to get in run-timere the status of the peripheral
- and the data flow.
- @endverbatim
- * @{
- */
- /**
- * @brief Return the TIMER Base state
- * @param hperh: TIMER handle
- * @retval TIMER peripheral state
- */
- ald_timer_state_t ald_timer_get_state(ald_timer_handle_t *hperh)
- {
- return hperh->state;
- }
- /**
- * @}
- */
- /**
- * @}
- */
- /** @addtogroup TIMER_Private_Functions
- * @{
- */
- /**
- * @brief TIMER DMA out compare complete callback.
- * @param arg: pointer to TIMER handle.
- * @retval None
- */
- void timer_dma_oc_cplt(void *arg)
- {
- ald_timer_handle_t *hperh = (ald_timer_handle_t *)arg;
- if (hperh->delay_elapse_cbk)
- hperh->delay_elapse_cbk(hperh);
- if (hperh->pwm_pulse_finish_cbk)
- hperh->pwm_pulse_finish_cbk(hperh);
- hperh->ch = ALD_TIMER_ACTIVE_CHANNEL_CLEARED;
- return;
- }
- /**
- * @brief TIMER DMA Capture complete callback.
- * @param arg: pointer to TIMER handle.
- * @retval None
- */
- void timer_dma_capture_cplt(void *arg)
- {
- ald_timer_handle_t *hperh = (ald_timer_handle_t *)arg;
- if (hperh->capture_cbk)
- hperh->capture_cbk(hperh);
- hperh->ch = ALD_TIMER_ACTIVE_CHANNEL_CLEARED;
- return;
- }
- /**
- * @brief TIMER DMA Period Elapse complete callback.
- * @param arg: pointer to TIMER handle.
- * @retval None
- */
- void timer_dma_period_elapse_cplt(void *arg)
- {
- ald_timer_handle_t *hperh = (ald_timer_handle_t *)arg;
- if (hperh->period_elapse_cbk)
- hperh->period_elapse_cbk(hperh);
- hperh->state = ALD_TIMER_STATE_READY;
- return;
- }
- /**
- * @brief Time Base configuration
- * @param TIMERx: TIMER periheral
- * @param init: TIMER Base configuration structure
- * @retval None
- */
- static void timer_base_set_config(TIMER_TypeDef *TIMERx, ald_timer_base_init_t *init)
- {
- assert_param(IS_TIMER_COUNTER_MODE(init->mode));
- assert_param(IS_TIMER_CLOCK_DIVISION(init->clk_div));
- if (init->mode == ALD_TIMER_CNT_MODE_UP || init->mode == ALD_TIMER_CNT_MODE_DOWN) {
- CLEAR_BIT(TIMERx->CON1, TIMER_CON1_CMSEL_MSK);
- MODIFY_REG(TIMERx->CON1, TIMER_CON1_DIRSEL_MSK, init->mode << TIMER_CON1_DIRSEL_POS);
- }
- else {
- MODIFY_REG(TIMERx->CON1, TIMER_CON1_CMSEL_MSK, (init->mode - 1) << TIMER_CON1_CMSEL_POSS);
- }
- if (IS_TIMER_CLOCK_DIVISION_INSTANCE(TIMERx))
- MODIFY_REG(TIMERx->CON1, TIMER_CON1_DFCKSEL_MSK, init->clk_div << TIMER_CON1_DFCKSEL_POSS);
- WRITE_REG(TIMERx->AR, init->period);
- WRITE_REG(TIMERx->PRES, init->prescaler);
- if (IS_TIMER_REPETITION_COUNTER_INSTANCE(TIMERx))
- WRITE_REG(TIMERx->REPAR, init->re_cnt);
- return;
- }
- /**
- * @brief Time Ouput Compare 1 configuration
- * @param TIMERx: Select the TIMER peripheral
- * @param oc_config: The ouput configuration structure
- * @retval None
- */
- static void timer_oc1_set_config(TIMER_TypeDef *TIMERx, ald_timer_oc_init_t *oc_config)
- {
- CLEAR_BIT(TIMERx->CCEP, TIMER_CCEP_CC1EN_MSK);
- CLEAR_BIT(TIMERx->CHMR1, TIMER_CHMR1_CH1OMOD_MSK);
- CLEAR_BIT(TIMERx->CHMR1, TIMER_CHMR1_CC1SSEL_MSK);
- MODIFY_REG(TIMERx->CHMR1, TIMER_CHMR1_CH1OMOD_MSK, oc_config->oc_mode << TIMER_CHMR1_CH1OMOD_POSS);
- MODIFY_REG(TIMERx->CCEP, TIMER_CCEP_CC1POL_MSK, oc_config->oc_polarity << TIMER_CCEP_CC1POL_POS);
- if (IS_TIMER_CCXN_INSTANCE(TIMERx, ALD_TIMER_CHANNEL_1)) {
- assert_param(IS_TIMER_OCN_POLARITY(oc_config->ocn_polarity));
- MODIFY_REG(TIMERx->CCEP, TIMER_CCEP_CC1NPOL_MSK, oc_config->ocn_polarity << TIMER_CCEP_CC1NPOL_POS);
- CLEAR_BIT(TIMERx->CCEP, TIMER_CCEP_CC1NE_MSK);
- }
- if (IS_TIMER_BREAK_INSTANCE(TIMERx)) {
- assert_param(IS_TIMER_OCNIDLE_STATE(oc_config->ocn_idle));
- assert_param(IS_TIMER_OCIDLE_STATE(oc_config->oc_idle));
- MODIFY_REG(TIMERx->CON2, TIMER_CON2_OISS1_MSK, oc_config->oc_idle << TIMER_CON2_OISS1_POS);
- MODIFY_REG(TIMERx->CON2, TIMER_CON2_OISS1N_MSK, oc_config->ocn_idle << TIMER_CON2_OISS1N_POS);
- }
- WRITE_REG(TIMERx->CCVAL1, oc_config->pulse);
- }
- /**
- * @brief Time Ouput Compare 2 configuration
- * @param TIMERx: Select the TIMER peripheral
- * @param oc_config: The ouput configuration structure
- * @retval None
- */
- static void timer_oc2_set_config(TIMER_TypeDef *TIMERx, ald_timer_oc_init_t *oc_config)
- {
- CLEAR_BIT(TIMERx->CCEP, TIMER_CCEP_CC2EN_MSK);
- CLEAR_BIT(TIMERx->CHMR1, TIMER_CHMR1_CH2OMOD_MSK);
- CLEAR_BIT(TIMERx->CHMR1, TIMER_CHMR1_CC2SSEL_MSK);
- MODIFY_REG(TIMERx->CHMR1, TIMER_CHMR1_CH2OMOD_MSK, oc_config->oc_mode << TIMER_CHMR1_CH2OMOD_POSS);
- MODIFY_REG(TIMERx->CCEP, TIMER_CCEP_CC2POL_MSK, oc_config->oc_polarity << TIMER_CCEP_CC2POL_POS);
- if (IS_TIMER_CCXN_INSTANCE(TIMERx, ALD_TIMER_CHANNEL_2)) {
- assert_param(IS_TIMER_OCN_POLARITY(oc_config->ocn_polarity));
- MODIFY_REG(TIMERx->CCEP, TIMER_CCEP_CC2NPOL_MSK, oc_config->ocn_polarity << TIMER_CCEP_CC2NPOL_POS);
- CLEAR_BIT(TIMERx->CCEP, TIMER_CCEP_CC2NE_MSK);
- }
- if (IS_TIMER_BREAK_INSTANCE(TIMERx)) {
- assert_param(IS_TIMER_OCNIDLE_STATE(oc_config->ocn_idle));
- assert_param(IS_TIMER_OCIDLE_STATE(oc_config->oc_idle));
- MODIFY_REG(TIMERx->CON2, TIMER_CON2_OISS2_MSK, oc_config->oc_idle << TIMER_CON2_OISS2_POS);
- MODIFY_REG(TIMERx->CON2, TIMER_CON2_OISS2N_MSK, oc_config->ocn_idle << TIMER_CON2_OISS2N_POS);
- }
- WRITE_REG(TIMERx->CCVAL2, oc_config->pulse);
- }
- /**
- * @brief Time Ouput Compare 3 configuration
- * @param TIMERx: Select the TIMER peripheral
- * @param oc_config: The ouput configuration structure
- * @retval None
- */
- static void timer_oc3_set_config(TIMER_TypeDef *TIMERx, ald_timer_oc_init_t *oc_config)
- {
- CLEAR_BIT(TIMERx->CCEP, TIMER_CCEP_CC3EN_MSK);
- CLEAR_BIT(TIMERx->CHMR2, TIMER_CHMR2_CH3OMOD_MSK);
- CLEAR_BIT(TIMERx->CHMR2, TIMER_CHMR2_CC3SSEL_MSK);
- MODIFY_REG(TIMERx->CHMR2, TIMER_CHMR2_CH3OMOD_MSK, oc_config->oc_mode << TIMER_CHMR2_CH3OMOD_POSS);
- MODIFY_REG(TIMERx->CCEP, TIMER_CCEP_CC3POL_MSK, oc_config->oc_polarity << TIMER_CCEP_CC3POL_POS);
- if (IS_TIMER_CCXN_INSTANCE(TIMERx, ALD_TIMER_CHANNEL_3)) {
- assert_param(IS_TIMER_OCN_POLARITY(oc_config->ocn_polarity));
- MODIFY_REG(TIMERx->CCEP, TIMER_CCEP_CC3NPOL_MSK, oc_config->ocn_polarity << TIMER_CCEP_CC3NPOL_POS);
- CLEAR_BIT(TIMERx->CCEP, TIMER_CCEP_CC3NE_MSK);
- }
- if (IS_TIMER_BREAK_INSTANCE(TIMERx)) {
- assert_param(IS_TIMER_OCNIDLE_STATE(oc_config->ocn_idle));
- assert_param(IS_TIMER_OCIDLE_STATE(oc_config->oc_idle));
- MODIFY_REG(TIMERx->CON2, TIMER_CON2_OISS3_MSK, oc_config->oc_idle << TIMER_CON2_OISS3_POS);
- MODIFY_REG(TIMERx->CON2, TIMER_CON2_OISS3N_MSK, oc_config->ocn_idle << TIMER_CON2_OISS3N_POS);
- }
- WRITE_REG(TIMERx->CCVAL3, oc_config->pulse);
- }
- /**
- * @brief Time Ouput Compare 4 configuration
- * @param TIMERx: Select the TIMER peripheral
- * @param oc_config: The ouput configuration structure
- * @retval None
- */
- static void timer_oc4_set_config(TIMER_TypeDef *TIMERx, ald_timer_oc_init_t *oc_config)
- {
- CLEAR_BIT(TIMERx->CCEP, TIMER_CCEP_CC4EN_MSK);
- CLEAR_BIT(TIMERx->CHMR2, TIMER_CHMR2_CH4OMOD_MSK);
- CLEAR_BIT(TIMERx->CHMR2, TIMER_CHMR2_CC4SSEL_MSK);
- MODIFY_REG(TIMERx->CHMR2, TIMER_CHMR2_CH4OMOD_MSK, oc_config->oc_mode << TIMER_CHMR2_CH4OMOD_POSS);
- MODIFY_REG(TIMERx->CCEP, TIMER_CCEP_CC4POL_MSK, oc_config->oc_polarity << TIMER_CCEP_CC4POL_POS);
- if (IS_TIMER_BREAK_INSTANCE(TIMERx)) {
- assert_param(IS_TIMER_OCIDLE_STATE(oc_config->oc_idle));
- MODIFY_REG(TIMERx->CON2, TIMER_CON2_OISS4_MSK, oc_config->oc_idle << TIMER_CON2_OISS4_POS);
- }
- WRITE_REG(TIMERx->CCVAL4, oc_config->pulse);
- }
- /**
- * @brief Enables or disables the TIMER Capture Compare Channel x.
- * @param TIMERx: Select the TIMER peripheral
- * @param ch: specifies the TIMER Channel
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1
- * @arg TIMER_CHANNEL_2: TIMER Channel 2
- * @arg TIMER_CHANNEL_3: TIMER Channel 3
- * @arg TIMER_CHANNEL_4: TIMER Channel 4
- * @param state: specifies the TIMER Channel CCxE bit new state.
- * @retval None
- */
- static void timer_ccx_channel_cmd(TIMER_TypeDef* TIMERx, ald_timer_channel_t ch, type_func_t state)
- {
- assert_param(IS_TIMER_CC2_INSTANCE(TIMERx));
- assert_param(IS_TIMER_CHANNELS(ch));
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- MODIFY_REG(TIMERx->CCEP, TIMER_CCEP_CC1EN_MSK, state << TIMER_CCEP_CC1EN_POS);
- break;
- case ALD_TIMER_CHANNEL_2:
- MODIFY_REG(TIMERx->CCEP, TIMER_CCEP_CC2EN_MSK, state << TIMER_CCEP_CC2EN_POS);
- break;
- case ALD_TIMER_CHANNEL_3:
- MODIFY_REG(TIMERx->CCEP, TIMER_CCEP_CC3EN_MSK, state << TIMER_CCEP_CC3EN_POS);
- break;
- case ALD_TIMER_CHANNEL_4:
- MODIFY_REG(TIMERx->CCEP, TIMER_CCEP_CC4EN_MSK, state << TIMER_CCEP_CC4EN_POS);
- break;
- default:
- break;
- }
- }
- /**
- * @brief Enables or disables the TIMER Capture Compare Channel xN.
- * @param TIMERx: Select the TIMER peripheral
- * @param ch: specifies the TIMER Channel
- * This parameter can be one of the following values:
- * @arg TIMER_CHANNEL_1: TIMER Channel 1
- * @arg TIMER_CHANNEL_2: TIMER Channel 2
- * @arg TIMER_CHANNEL_3: TIMER Channel 3
- * @param state: specifies the TIMER Channel CCxNE bit new state.
- * @retval None
- */
- static void timer_ccxn_channel_cmd(TIMER_TypeDef* TIMERx, ald_timer_channel_t ch, type_func_t state)
- {
- switch (ch) {
- case ALD_TIMER_CHANNEL_1:
- MODIFY_REG(TIMERx->CCEP, TIMER_CCEP_CC1NE_MSK, state << TIMER_CCEP_CC1NE_POS);
- break;
- case ALD_TIMER_CHANNEL_2:
- MODIFY_REG(TIMERx->CCEP, TIMER_CCEP_CC2NE_MSK, state << TIMER_CCEP_CC2NE_POS);
- break;
- case ALD_TIMER_CHANNEL_3:
- MODIFY_REG(TIMERx->CCEP, TIMER_CCEP_CC3NE_MSK, state << TIMER_CCEP_CC3NE_POS);
- break;
- default:
- break;
- }
- }
- /**
- * @brief Configure the TI1 as Input.
- * @param TIMERx: Select the TIMER peripheral.
- * @param polarity: The Input Polarity.
- * @param sel: specifies the input to be used.
- * @param filter: Specifies the Input Capture Filter.
- * This parameter must be a value between 0x00 and 0x0F.
- * @retval None
- */
- static void timer_ti1_set_config(TIMER_TypeDef *TIMERx, ald_timer_ic_polarity_t polarity,
- ald_timer_ic_select_t sel, uint32_t filter)
- {
- CLEAR_BIT(TIMERx->CCEP, TIMER_CCEP_CC1EN_MSK);
- MODIFY_REG(TIMERx->CHMR1, TIMER_CHMR1_CC1SSEL_MSK, sel << TIMER_CHMR1_CC1SSEL_POSS);
- MODIFY_REG(TIMERx->CHMR1, TIMER_CHMR1_I1FLT_MSK, filter << TIMER_CHMR1_I1FLT_POSS);
- MODIFY_REG(TIMERx->CCEP, TIMER_CCEP_CC1POL_MSK, polarity << TIMER_CCEP_CC1POL_POS);
- return;
- }
- /**
- * @brief Configure the Polarity and Filter for TI1.
- * @param TIMERx: Select the TIMER peripheral.
- * @param polarity: The Input Polarity.
- * @param filter: Specifies the Input Capture Filter.
- * This parameter must be a value between 0x00 and 0x0F.
- * @retval None
- */
- static void timer_ti1_set_config_stage(TIMER_TypeDef *TIMERx, ald_timer_ic_polarity_t polarity, uint32_t filter)
- {
- MODIFY_REG(TIMERx->CHMR1, TIMER_CHMR1_I1FLT_MSK, filter << TIMER_CHMR1_I1FLT_POSS);
- MODIFY_REG(TIMERx->CCEP, TIMER_CCEP_CC1POL_MSK, polarity << TIMER_CCEP_CC1POL_POS);
- return;
- }
- /**
- * @brief Configure the TI2 as Input.
- * @param TIMERx: Select the TIMER peripheral.
- * @param polarity: The Input Polarity.
- * @param sel: specifies the input to be used.
- * @param filter: Specifies the Input Capture Filter.
- * This parameter must be a value between 0x00 and 0x0F.
- * @retval None
- */
- static void timer_ti2_set_config(TIMER_TypeDef *TIMERx, ald_timer_ic_polarity_t polarity,
- ald_timer_ic_select_t sel, uint32_t filter)
- {
- CLEAR_BIT(TIMERx->CCEP, TIMER_CCEP_CC2EN_MSK);
- MODIFY_REG(TIMERx->CHMR1, TIMER_CHMR1_CC2SSEL_MSK, sel << TIMER_CHMR1_CC2SSEL_POSS);
- MODIFY_REG(TIMERx->CHMR1, TIMER_CHMR1_I2FLT_MSK, filter << TIMER_CHMR1_I2FLT_POSS);
- MODIFY_REG(TIMERx->CCEP, TIMER_CCEP_CC2POL_MSK, polarity << TIMER_CCEP_CC2POL_POS);
- return;
- }
- /**
- * @brief Configure the Polarity and Filter for TI2.
- * @param TIMERx: Select the TIMER peripheral.
- * @param polarity: The Input Polarity.
- * @param filter: Specifies the Input Capture Filter.
- * This parameter must be a value between 0x00 and 0x0F.
- * @retval None
- */
- static void timer_ti2_set_config_stage(TIMER_TypeDef *TIMERx, ald_timer_ic_polarity_t polarity, uint32_t filter)
- {
- MODIFY_REG(TIMERx->CHMR1, TIMER_CHMR1_I2FLT_MSK, filter << TIMER_CHMR1_I2FLT_POSS);
- MODIFY_REG(TIMERx->CCEP, TIMER_CCEP_CC2POL_MSK, polarity << TIMER_CCEP_CC2POL_POS);
- return;
- }
- /**
- * @brief Configure the TI3 as Input.
- * @param TIMERx: Select the TIMER peripheral.
- * @param polarity: The Input Polarity.
- * @param sel: specifies the input to be used.
- * @param filter: Specifies the Input Capture Filter.
- * This parameter must be a value between 0x00 and 0x0F.
- * @retval None
- */
- static void timer_ti3_set_config(TIMER_TypeDef *TIMERx, ald_timer_ic_polarity_t polarity,
- ald_timer_ic_select_t sel, uint32_t filter)
- {
- CLEAR_BIT(TIMERx->CCEP, TIMER_CCEP_CC3EN_MSK);
- MODIFY_REG(TIMERx->CHMR2, TIMER_CHMR2_CC3SSEL_MSK, sel << TIMER_CHMR2_CC3SSEL_POSS);
- MODIFY_REG(TIMERx->CHMR2, TIMER_CHMR2_I3FLT_MSK, filter << TIMER_CHMR2_I3FLT_POSS);
- MODIFY_REG(TIMERx->CCEP, TIMER_CCEP_CC3POL_MSK, polarity << TIMER_CCEP_CC3POL_POS);
- return;
- }
- /**
- * @brief Configure the TI4 as Input.
- * @param TIMERx: Select the TIMER peripheral.
- * @param polarity: The Input Polarity.
- * @param sel: specifies the input to be used.
- * @param filter: Specifies the Input Capture Filter.
- * This parameter must be a value between 0x00 and 0x0F.
- * @retval None
- */
- static void timer_ti4_set_config(TIMER_TypeDef *TIMERx, ald_timer_ic_polarity_t polarity,
- ald_timer_ic_select_t sel, uint32_t filter)
- {
- CLEAR_BIT(TIMERx->CCEP, TIMER_CCEP_CC4EN_MSK);
- MODIFY_REG(TIMERx->CHMR2, TIMER_CHMR2_CC4SSEL_MSK, sel << TIMER_CHMR2_CC4SSEL_POSS);
- MODIFY_REG(TIMERx->CHMR2, TIMER_CHMR2_I4FLT_MSK, filter << TIMER_CHMR2_I4FLT_POSS);
- MODIFY_REG(TIMERx->CCEP, TIMER_CCEP_CC4POL_MSK, polarity << TIMER_CCEP_CC4POL_POS);
- return;
- }
- /**
- * @brief Configures the TIMERx External Trigger (ETR).
- * @param TIMERx: Select the TIMER peripheral
- * @param psc: The external Trigger Prescaler.
- * @param polarity: The external Trigger Polarity.
- * @param filter: External Trigger Filter.
- * This parameter must be a value between 0x00 and 0x0F
- * @retval None
- */
- static void timer_etr_set_config(TIMER_TypeDef* TIMERx, ald_timer_etr_psc_t psc, ald_timer_clock_polarity_t polarity, uint32_t filter)
- {
- MODIFY_REG(TIMERx->SMCON, TIMER_SMCON_ETFLT_MSK, filter << TIMER_SMCON_ETFLT_POSS);
- MODIFY_REG(TIMERx->SMCON, TIMER_SMCON_ETPSEL_MSK, psc << TIMER_SMCON_ETPSEL_POSS);
- CLEAR_BIT(TIMERx->SMCON, TIMER_SMCON_ECM2EN_MSK);
- MODIFY_REG(TIMERx->SMCON, TIMER_SMCON_ETPOL_MSK, polarity << TIMER_SMCON_ETPOL_POS);
- return;
- }
- /**
- * @brief Time Slave configuration
- * @param hperh: pointer to a timer_handle_t structure that contains
- * the configuration information for TIMER module.
- * @param config: The slave configuration structure
- * @retval None
- */
- static void timer_slave_set_config(ald_timer_handle_t *hperh, ald_timer_slave_config_t *config)
- {
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_TSSEL_MSK, config->input << TIMER_SMCON_TSSEL_POSS);
- MODIFY_REG(hperh->perh->SMCON, TIMER_SMCON_SMODS_MSK, config->mode << TIMER_SMCON_SMODS_POSS);
- switch (config->input) {
- case ALD_TIMER_TS_ETRF:
- timer_etr_set_config(hperh->perh, config->psc, config->polarity, config->filter);
- break;
- case ALD_TIMER_TS_TI1F_ED:
- CLEAR_BIT(hperh->perh->CCEP, TIMER_CCEP_CC1EN_MSK);
- MODIFY_REG(hperh->perh->CHMR1, TIMER_CHMR1_I1FLT_MSK, config->filter << TIMER_CHMR1_I1FLT_POSS);
- break;
- case ALD_TIMER_TS_TI1FP1:
- timer_ti1_set_config_stage(hperh->perh, (ald_timer_ic_polarity_t)config->polarity, config->filter);
- break;
- case ALD_TIMER_TS_TI2FP2:
- timer_ti2_set_config_stage(hperh->perh, (ald_timer_ic_polarity_t)config->polarity, config->filter);
- break;
- default:
- break;
- }
- }
- /**
- * @brief Timer DMA msel signal configuration
- * @param hperh: pointer to a timer_handle_t structure that contains
- * the configuration information for TIMER module.
- * @param config: DMA configuration structure
- * @retval None
- */
- static void timer_dma_msel(TIMER_TypeDef *hperh, ald_dma_config_t *config)
- {
- if (hperh == AD16C4T)
- config->msel = ALD_DMA_MSEL_AD16C4T;
- if (hperh == BS16T)
- config->msel = ALD_DMA_MSEL_BS16T;
- if (hperh == GP16C4T0)
- config->msel = ALD_DMA_MSEL_GP16C4T0;
- if (hperh == GP16C4T1)
- config->msel = ALD_DMA_MSEL_GP16C4T1;
- if (hperh == GP16C4T2)
- config->msel = ALD_DMA_MSEL_GP16C4T2;
- }
- /**
- * @}
- */
- /**
- * @}
- */
- /**
- * @}
- */
|