stm32g4xx_hal_hrtim.c 381 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077
  1. /**
  2. ******************************************************************************
  3. * @file stm32g4xx_hal_hrtim.c
  4. * @author MCD Application Team
  5. * @brief TIM HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the High Resolution Timer (HRTIM) peripheral:
  8. * + HRTIM Initialization
  9. * + DLL Calibration Start
  10. * + Timer Time Base Unit Configuration
  11. * + Simple Time Base Start/Stop
  12. * + Simple Time Base Start/Stop Interrupt
  13. * + Simple Time Base Start/Stop DMA Request
  14. * + Simple Output Compare/PWM Channel Configuration
  15. * + Simple Output Compare/PWM Channel Start/Stop Interrupt
  16. * + Simple Output Compare/PWM Channel Start/Stop DMA Request
  17. * + Simple Input Capture Channel Configuration
  18. * + Simple Input Capture Channel Start/Stop Interrupt
  19. * + Simple Input Capture Channel Start/Stop DMA Request
  20. * + Simple One Pulse Channel Configuration
  21. * + Simple One Pulse Channel Start/Stop Interrupt
  22. * + HRTIM External Synchronization Configuration
  23. * + HRTIM Burst Mode Controller Configuration
  24. * + HRTIM Burst Mode Controller Enabling
  25. * + HRTIM External Events Conditioning Configuration
  26. * + HRTIM Faults Conditioning Configuration
  27. * + HRTIM Faults Enabling
  28. * + HRTIM ADC trigger Configuration
  29. * + Waveform Timer Configuration
  30. * + Waveform Event Filtering Configuration
  31. * + Waveform Dead Time Insertion Configuration
  32. * + Waveform Chopper Mode Configuration
  33. * + Waveform Compare Unit Configuration
  34. * + Waveform Capture Unit Configuration
  35. * + Waveform Output Configuration
  36. * + Waveform Counter Start/Stop
  37. * + Waveform Counter Start/Stop Interrupt
  38. * + Waveform Counter Start/Stop DMA Request
  39. * + Waveform Output Enabling
  40. * + Waveform Output Level Set/Get
  41. * + Waveform Output State Get
  42. * + Waveform Burst DMA Operation Configuration
  43. * + Waveform Burst DMA Operation Start
  44. * + Waveform Timer Counter Software Reset
  45. * + Waveform Capture Software Trigger
  46. * + Waveform Burst Mode Controller Software Trigger
  47. * + Waveform Timer Pre-loadable Registers Update Enabling
  48. * + Waveform Timer Pre-loadable Registers Software Update
  49. * + Waveform Timer Delayed Protection Status Get
  50. * + Waveform Timer Burst Status Get
  51. * + Waveform Timer Push-Pull Status Get
  52. * + Peripheral State Get
  53. *
  54. ******************************************************************************
  55. * @attention
  56. *
  57. * Copyright (c) 2019 STMicroelectronics.
  58. * All rights reserved.
  59. *
  60. * This software is licensed under terms that can be found in the LICENSE file
  61. * in the root directory of this software component.
  62. * If no LICENSE file comes with this software, it is provided AS-IS.
  63. *
  64. ******************************************************************************
  65. @verbatim
  66. ==============================================================================
  67. ##### Simple mode v.s. waveform mode #####
  68. ==============================================================================
  69. [..] The HRTIM HAL API is split into 2 categories:
  70. (#)Simple functions: these functions allow for using a HRTIM timer as a
  71. general purpose timer with high resolution capabilities.
  72. HRTIM simple modes are managed through the set of functions named
  73. HAL_HRTIM_Simple<Function>. These functions are similar in name and usage
  74. to the one defined for the TIM peripheral. When a HRTIM timer operates in
  75. simple mode, only a very limited set of HRTIM features are used.
  76. Following simple modes are proposed:
  77. (++)Output compare mode,
  78. (++)PWM output mode,
  79. (++)Input capture mode,
  80. (++)One pulse mode.
  81. (#)Waveform functions: These functions allow taking advantage of the HRTIM
  82. flexibility to produce numerous types of control signal. When a HRTIM timer
  83. operates in waveform mode, all the HRTIM features are accessible without
  84. any restriction. HRTIM waveform modes are managed through the set of
  85. functions named HAL_HRTIM_Waveform<Function>
  86. ##### How to use this driver #####
  87. ==============================================================================
  88. [..]
  89. (#)Initialize the HRTIM low level resources by implementing the
  90. HAL_HRTIM_MspInit() function:
  91. (##)Enable the HRTIM clock source using __HRTIMx_CLK_ENABLE()
  92. (##)Connect HRTIM pins to MCU I/Os
  93. (+++) Enable the clock for the HRTIM GPIOs using the following
  94. function: __HAL_RCC_GPIOx_CLK_ENABLE()
  95. (+++) Configure these GPIO pins in Alternate Function mode using
  96. HAL_GPIO_Init()
  97. (##)When using DMA to control data transfer (e.g HAL_HRTIM_SimpleBaseStart_DMA())
  98. (+++)Enable the DMAx interface clock using __DMAx_CLK_ENABLE()
  99. (+++)Initialize the DMA handle
  100. (+++)Associate the initialized DMA handle to the appropriate DMA
  101. handle of the HRTIM handle using __HAL_LINKDMA()
  102. (+++)Initialize the DMA channel using HAL_DMA_Init()
  103. (+++)Configure the priority and enable the NVIC for the transfer
  104. complete interrupt on the DMA channel using HAL_NVIC_SetPriority()
  105. and HAL_NVIC_EnableIRQ()
  106. (##)In case of using interrupt mode (e.g HAL_HRTIM_SimpleBaseStart_IT())
  107. (+++)Configure the priority and enable the NVIC for the concerned
  108. HRTIM interrupt using HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ()
  109. (#)Initialize the HRTIM HAL using HAL_HRTIM_Init(). The HRTIM configuration
  110. structure (field of the HRTIM handle) specifies which global interrupt of
  111. whole HRTIM must be enabled (Burst mode period, System fault, Faults).
  112. It also contains the HRTIM external synchronization configuration. HRTIM
  113. can act as a master (generating a synchronization signal) or as a slave
  114. (waiting for a trigger to be synchronized).
  115. (#)Start the high resolution unit using HAL_HRTIM_DLLCalibrationStart(). DLL
  116. calibration is executed periodically and compensate for potential voltage
  117. and temperature drifts. DLL calibration period is specified by the
  118. CalibrationRate argument.
  119. (#)HRTIM timers cannot be used until the high resolution unit is ready. This
  120. can be checked using HAL_HRTIM_PollForDLLCalibration(): this function returns
  121. HAL_OK if DLL calibration is completed or HAL_TIMEOUT if the DLL calibration
  122. is still going on when timeout given as argument expires. DLL calibration
  123. can also be started in interrupt mode using HAL_HRTIM_DLLCalibrationStart_IT().
  124. In that case an interrupt is generated when the DLL calibration is completed.
  125. Note that as DLL calibration is executed on a periodic basis an interrupt
  126. will be generated at the end of every DLL calibration operation
  127. (worst case: one interrupt every 14 micro seconds !).
  128. (#) Configure HRTIM resources shared by all HRTIM timers
  129. (##)Burst Mode Controller:
  130. (+++)HAL_HRTIM_BurstModeConfig(): configures the HRTIM burst mode
  131. controller: operating mode (continuous or one-shot mode), clock
  132. (source, prescaler) , trigger(s), period, idle duration.
  133. (##)External Events Conditioning:
  134. (+++)HAL_HRTIM_EventConfig(): configures the conditioning of an
  135. external event channel: source, polarity, edge-sensitivity.
  136. External event can be used as triggers (timer reset, input
  137. capture, burst mode, ADC triggers, delayed protection)
  138. They can also be used to set or reset timer outputs. Up to
  139. 10 event channels are available.
  140. (+++)HAL_HRTIM_EventPrescalerConfig(): configures the external
  141. event sampling clock (used for digital filtering).
  142. (##)Fault Conditioning:
  143. (+++)HAL_HRTIM_FaultConfig(): configures the conditioning of a
  144. fault channel: source, polarity, edge-sensitivity. Fault
  145. channels are used to disable the outputs in case of an
  146. abnormal operation. Up to 6 fault channels are available.
  147. (+++)HAL_HRTIM_FaultPrescalerConfig(): configures the fault
  148. sampling clock (used for digital filtering).
  149. (+++)HAL_HRTIM_FaultModeCtl(): Enables or disables fault input(s)
  150. circuitry. By default all fault inputs are disabled.
  151. (##)ADC trigger:
  152. (+++)HAL_HRTIM_ADCTriggerConfig(): configures the source triggering
  153. the update of the ADC trigger register and the ADC trigger.
  154. 4 independent triggers are available to start both the regular
  155. and the injected sequencers of the 2 ADCs
  156. (#) Configure HRTIM timer time base using HAL_HRTIM_TimeBaseConfig(). This
  157. function must be called whatever the HRTIM timer operating mode is
  158. (simple v.s. waveform). It configures mainly:
  159. (##)The HRTIM timer counter operating mode (continuous v.s. one shot)
  160. (##)The HRTIM timer clock prescaler
  161. (##)The HRTIM timer period
  162. (##)The HRTIM timer repetition counter
  163. *** If the HRTIM timer operates in simple mode ***
  164. ===================================================
  165. [..]
  166. (#) Start or Stop simple timers
  167. (++)Simple time base: HAL_HRTIM_SimpleBaseStart(),HAL_HRTIM_SimpleBaseStop(),
  168. HAL_HRTIM_SimpleBaseStart_IT(),HAL_HRTIM_SimpleBaseStop_IT(),
  169. HAL_HRTIM_SimpleBaseStart_DMA(),HAL_HRTIM_SimpleBaseStop_DMA().
  170. (++)Simple output compare: HAL_HRTIM_SimpleOCChannelConfig(),
  171. HAL_HRTIM_SimpleOCStart(),HAL_HRTIM_SimpleOCStop(),
  172. HAL_HRTIM_SimpleOCStart_IT(),HAL_HRTIM_SimpleOCStop_IT(),
  173. HAL_HRTIM_SimpleOCStart_DMA(),HAL_HRTIM_SimpleOCStop_DMA(),
  174. (++)Simple PWM output: HAL_HRTIM_SimplePWMChannelConfig(),
  175. HAL_HRTIM_SimplePWMStart(),HAL_HRTIM_SimplePWMStop(),
  176. HAL_HRTIM_SimplePWMStart_IT(),HAL_HRTIM_SimplePWMStop_IT(),
  177. HAL_HRTIM_SimplePWMStart_DMA(),HAL_HRTIM_SimplePWMStop_DMA(),
  178. (++)Simple input capture: HAL_HRTIM_SimpleCaptureChannelConfig(),
  179. HAL_HRTIM_SimpleCaptureStart(),HAL_HRTIM_SimpleCaptureStop(),
  180. HAL_HRTIM_SimpleCaptureStart_IT(),HAL_HRTIM_SimpleCaptureStop_IT(),
  181. HAL_HRTIM_SimpleCaptureStart_DMA(),HAL_HRTIM_SimpleCaptureStop_DMA().
  182. (++)Simple one pulse: HAL_HRTIM_SimpleOnePulseChannelConfig(),
  183. HAL_HRTIM_SimpleOnePulseStart(),HAL_HRTIM_SimpleOnePulseStop(),
  184. HAL_HRTIM_SimpleOnePulseStart_IT(),HAL_HRTIM_SimpleOnePulseStop_It().
  185. *** If the HRTIM timer operates in waveform mode ***
  186. ====================================================
  187. [..]
  188. (#) Completes waveform timer configuration
  189. (++)HAL_HRTIM_WaveformTimerConfig(): configuration of a HRTIM timer
  190. operating in wave form mode mainly consists in:
  191. (+++)Enabling the HRTIM timer interrupts and DMA requests.
  192. (+++)Enabling the half mode for the HRTIM timer.
  193. (+++)Defining how the HRTIM timer reacts to external synchronization input.
  194. (+++)Enabling the push-pull mode for the HRTIM timer.
  195. (+++)Enabling the fault channels for the HRTIM timer.
  196. (+++)Enabling the dead-time insertion for the HRTIM timer.
  197. (+++)Setting the delayed protection mode for the HRTIM timer (source and outputs
  198. on which the delayed protection are applied).
  199. (+++)Specifying the HRTIM timer update and reset triggers.
  200. (+++)Specifying the HRTIM timer registers update policy (e.g. pre-load enabling).
  201. (++)HAL_HRTIM_TimerEventFilteringConfig(): configures external
  202. event blanking and windowing circuitry of a HRTIM timer:
  203. (+++)Blanking: to mask external events during a defined time period a defined time period
  204. (+++)Windowing, to enable external events only during a defined time period
  205. (++)HAL_HRTIM_DeadTimeConfig(): configures the dead-time insertion
  206. unit for a HRTIM timer. Allows to generate a couple of
  207. complementary signals from a single reference waveform,
  208. with programmable delays between active state.
  209. (++)HAL_HRTIM_ChopperModeConfig(): configures the parameters of
  210. the high-frequency carrier signal added on top of the timing
  211. unit output. Chopper mode can be enabled or disabled for each
  212. timer output separately (see HAL_HRTIM_WaveformOutputConfig()).
  213. (++)HAL_HRTIM_BurstDMAConfig(): configures the burst DMA burst
  214. controller. Allows having multiple HRTIM registers updated
  215. with a single DMA request. The burst DMA operation is started
  216. by calling HAL_HRTIM_BurstDMATransfer().
  217. (++)HAL_HRTIM_WaveformCompareConfig():configures the compare unit
  218. of a HRTIM timer. This operation consists in setting the
  219. compare value and possibly specifying the auto delayed mode
  220. for compare units 2 and 4 (allows to have compare events
  221. generated relatively to capture events). Note that when auto
  222. delayed mode is needed, the capture unit associated to the
  223. compare unit must be configured separately.
  224. (++)HAL_HRTIM_WaveformCaptureConfig(): configures the capture unit
  225. of a HRTIM timer. This operation consists in specifying the
  226. source(s) triggering the capture (timer register update event,
  227. external event, timer output set/reset event, other HRTIM
  228. timer related events).
  229. (++)HAL_HRTIM_WaveformOutputConfig(): configuration of a HRTIM timer
  230. output mainly consists in:
  231. (+++)Setting the output polarity (active high or active low),
  232. (+++)Defining the set/reset crossbar for the output,
  233. (+++)Specifying the fault level (active or inactive) in IDLE and FAULT states.,
  234. (#) Set waveform timer output(s) level
  235. (++)HAL_HRTIM_WaveformSetOutputLevel(): forces the output to its
  236. active or inactive level. For example, when deadtime insertion
  237. is enabled it is necessary to force the output level by software
  238. to have the outputs in a complementary state as soon as the RUN mode is entered.
  239. (#) Enable or Disable waveform timer output(s)
  240. (++)HAL_HRTIM_WaveformOutputStart(),HAL_HRTIM_WaveformOutputStop().
  241. (#) Start or Stop waveform HRTIM timer(s).
  242. (++)HAL_HRTIM_WaveformCountStart(),HAL_HRTIM_WaveformCountStop(),
  243. (++)HAL_HRTIM_WaveformCountStart_IT(),HAL_HRTIM_WaveformCountStop_IT(),
  244. (++)HAL_HRTIM_WaveformCountStart_DMA(),HAL_HRTIM_WaveformCountStop_DMA(),
  245. (#) Burst mode controller enabling:
  246. (++)HAL_HRTIM_BurstModeCtl(): activates or de-activates the
  247. burst mode controller.
  248. (#) Some HRTIM operations can be triggered by software:
  249. (++)HAL_HRTIM_BurstModeSoftwareTrigger(): calling this function
  250. trigs the burst operation.
  251. (++)HAL_HRTIM_SoftwareCapture(): calling this function trigs the
  252. capture of the HRTIM timer counter.
  253. (++)HAL_HRTIM_SoftwareUpdate(): calling this function trigs the
  254. update of the pre-loadable registers of the HRTIM timer
  255. (++)HAL_HRTIM_SoftwareReset():calling this function resets the
  256. HRTIM timer counter.
  257. (#) Some functions can be used any time to retrieve HRTIM timer related
  258. information
  259. (++)HAL_HRTIM_GetCapturedValue(): returns actual value of the
  260. capture register of the designated capture unit.
  261. (++)HAL_HRTIM_WaveformGetOutputLevel(): returns actual level
  262. (ACTIVE/INACTIVE) of the designated timer output.
  263. (++)HAL_HRTIM_WaveformGetOutputState():returns actual state
  264. (IDLE/RUN/FAULT) of the designated timer output.
  265. (++)HAL_HRTIM_GetDelayedProtectionStatus():returns actual level
  266. (ACTIVE/INACTIVE) of the designated output when the delayed
  267. protection was triggered.
  268. (++)HAL_HRTIM_GetBurstStatus(): returns the actual status
  269. (ACTIVE/INACTIVE) of the burst mode controller.
  270. (++)HAL_HRTIM_GetCurrentPushPullStatus(): when the push-pull mode
  271. is enabled for the HRTIM timer (see HAL_HRTIM_WaveformTimerConfig()),
  272. the push-pull status indicates on which output the signal is currently
  273. active (e.g signal applied on output 1 and output 2 forced
  274. inactive or vice versa).
  275. (++)HAL_HRTIM_GetIdlePushPullStatus(): when the push-pull mode
  276. is enabled for the HRTIM timer (see HAL_HRTIM_WaveformTimerConfig()),
  277. the idle push-pull status indicates during which period the
  278. delayed protection request occurred (e.g. protection occurred
  279. when the output 1 was active and output 2 forced inactive or
  280. vice versa).
  281. (#) Some functions can be used any time to retrieve actual HRTIM status
  282. (++)HAL_HRTIM_GetState(): returns actual HRTIM instance HAL state.
  283. *** Callback registration ***
  284. =============================
  285. [..]
  286. The compilation flag USE_HAL_HRTIM_REGISTER_CALLBACKS when set to 1
  287. allows the user to configure dynamically the driver callbacks.
  288. Use Functions HAL_HRTIM_RegisterCallback() or HAL_HRTIM_TIMxRegisterCallback()
  289. to register an interrupt callback.
  290. [..]
  291. Function HAL_HRTIM_RegisterCallback() allows to register following callbacks:
  292. (+) Fault1Callback : Fault 1 interrupt callback function
  293. (+) Fault2Callback : Fault 2 interrupt callback function
  294. (+) Fault3Callback : Fault 3 interrupt callback function
  295. (+) Fault4Callback : Fault 4 interrupt callback function
  296. (+) Fault5Callback : Fault 5 interrupt callback function
  297. (+) Fault6Callback : Fault 6 interrupt callback function
  298. (+) SystemFaultCallback : System fault interrupt callback function
  299. (+) DLLCalibrationReadyCallback : DLL Ready interrupt callback function
  300. (+) BurstModePeriodCallback : Burst mode period interrupt callback function
  301. (+) SynchronizationEventCallback : Sync Input interrupt callback function
  302. (+) ErrorCallback : DMA error callback function
  303. (+) MspInitCallback : HRTIM MspInit callback function
  304. (+) MspDeInitCallback : HRTIM MspInit callback function
  305. [..]
  306. Function HAL_HRTIM_TIMxRegisterCallback() allows to register following callbacks:
  307. (+) RegistersUpdateCallback : Timer x Update interrupt callback function
  308. (+) RepetitionEventCallback : Timer x Repetition interrupt callback function
  309. (+) Compare1EventCallback : Timer x Compare 1 match interrupt callback function
  310. (+) Compare2EventCallback : Timer x Compare 2 match interrupt callback function
  311. (+) Compare3EventCallback : Timer x Compare 3 match interrupt callback function
  312. (+) Compare4EventCallback : Timer x Compare 4 match interrupt callback function
  313. (+) Capture1EventCallback : Timer x Capture 1 interrupts callback function
  314. (+) Capture2EventCallback : Timer x Capture 2 interrupts callback function
  315. (+) DelayedProtectionCallback : Timer x Delayed protection interrupt callback function
  316. (+) CounterResetCallback : Timer x counter reset/roll-over interrupt callback function
  317. (+) Output1SetCallback : Timer x output 1 set interrupt callback function
  318. (+) Output1ResetCallback : Timer x output 1 reset interrupt callback function
  319. (+) Output2SetCallback : Timer x output 2 set interrupt callback function
  320. (+) Output2ResetCallback : Timer x output 2 reset interrupt callback function
  321. (+) BurstDMATransferCallback : Timer x Burst DMA completed interrupt callback function
  322. [..]
  323. Both functions take as parameters the HAL peripheral handle, the Callback ID
  324. and a pointer to the user callback function.
  325. [..]
  326. Use function HAL_HRTIM_UnRegisterCallback or HAL_HRTIM_TIMxUnRegisterCallback
  327. to reset a callback to the default weak function. Both functions take as parameters
  328. the HAL peripheral handle and the Callback ID.
  329. [..]
  330. By default, after the HAL_HRTIM_Init() and when the state is HAL_HRTIM_STATE_RESET
  331. all callbacks are set to the corresponding weak functions (e.g HAL_HRTIM_Fault1Callback)
  332. Exception done for MspInit and MspDeInit functions that are reset to the legacy
  333. weak functions in the HAL_HRTIM_Init()/ HAL_HRTIM_DeInit() only when these
  334. callbacks are null (not registered beforehand). If MspInit or MspDeInit are
  335. not null, the HAL_HRTIM_Init()/ HAL_HRTIM_DeInit() keep and use the user
  336. MspInit/MspDeInit callbacks (registered beforehand) whatever the state.
  337. [..]
  338. Callbacks can be registered/unregistered in HAL_HRTIM_STATE_READY state only.
  339. Exception done MspInit/MspDeInit functions that can be registered/unregistered
  340. in HAL_HRTIM_STATE_READY or HAL_HRTIM_STATE_RESET states, thus registered
  341. (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
  342. Then, the user first registers the MspInit/MspDeInit user callbacks
  343. using HAL_HRTIM_RegisterCallback() before calling HAL_HRTIM_DeInit()
  344. or HAL_HRTIM_Init() function.
  345. [..]
  346. When the compilation flag USE_HAL_HRTIM_REGISTER_CALLBACKS is set to 0 or
  347. not defined, the callback registration feature is not available and all
  348. callbacks are set to the corresponding weak functions.
  349. @endverbatim
  350. ******************************************************************************
  351. */
  352. /* Includes ------------------------------------------------------------------*/
  353. #include "stm32g4xx_hal.h"
  354. /** @addtogroup STM32G4xx_HAL_Driver
  355. * @{
  356. */
  357. #ifdef HAL_HRTIM_MODULE_ENABLED
  358. #if defined(HRTIM1)
  359. /** @defgroup HRTIM HRTIM
  360. * @brief HRTIM HAL module driver
  361. * @{
  362. */
  363. /* Private typedef -----------------------------------------------------------*/
  364. /* Private define ------------------------------------------------------------*/
  365. /** @defgroup HRTIM_Private_Defines HRTIM Private Define
  366. * @{
  367. */
  368. #define HRTIM_FLTR_FLTxEN (HRTIM_FLTR_FLT1EN |\
  369. HRTIM_FLTR_FLT2EN |\
  370. HRTIM_FLTR_FLT3EN |\
  371. HRTIM_FLTR_FLT4EN | \
  372. HRTIM_FLTR_FLT5EN | \
  373. HRTIM_FLTR_FLT6EN)
  374. #define HRTIM_TIMCR_TIMUPDATETRIGGER (HRTIM_TIMUPDATETRIGGER_MASTER |\
  375. HRTIM_TIMUPDATETRIGGER_TIMER_A |\
  376. HRTIM_TIMUPDATETRIGGER_TIMER_B |\
  377. HRTIM_TIMUPDATETRIGGER_TIMER_C |\
  378. HRTIM_TIMUPDATETRIGGER_TIMER_D |\
  379. HRTIM_TIMUPDATETRIGGER_TIMER_E |\
  380. HRTIM_TIMUPDATETRIGGER_TIMER_F)
  381. #define HRTIM_FLTINR1_FLTxLCK ((HRTIM_FAULTLOCK_READONLY) | \
  382. (HRTIM_FAULTLOCK_READONLY << 8U) | \
  383. (HRTIM_FAULTLOCK_READONLY << 16U) | \
  384. (HRTIM_FAULTLOCK_READONLY << 24U))
  385. #define HRTIM_FLTINR2_FLTxLCK ((HRTIM_FAULTLOCK_READONLY) | \
  386. (HRTIM_FAULTLOCK_READONLY << 8U))
  387. /**
  388. * @}
  389. */
  390. /* Private macro -------------------------------------------------------------*/
  391. /* Private variables ---------------------------------------------------------*/
  392. /** @defgroup HRTIM_Private_Variables HRTIM Private Variables
  393. * @{
  394. */
  395. static uint32_t TimerIdxToTimerId[] =
  396. {
  397. HRTIM_TIMERID_TIMER_A,
  398. HRTIM_TIMERID_TIMER_B,
  399. HRTIM_TIMERID_TIMER_C,
  400. HRTIM_TIMERID_TIMER_D,
  401. HRTIM_TIMERID_TIMER_E,
  402. HRTIM_TIMERID_TIMER_F,
  403. HRTIM_TIMERID_MASTER,
  404. };
  405. /**
  406. * @}
  407. */
  408. /* Private function prototypes -----------------------------------------------*/
  409. /** @defgroup HRTIM_Private_Functions HRTIM Private Functions
  410. * @{
  411. */
  412. static void HRTIM_MasterBase_Config(HRTIM_HandleTypeDef *hhrtim,
  413. const HRTIM_TimeBaseCfgTypeDef *pTimeBaseCfg);
  414. static void HRTIM_TimingUnitBase_Config(HRTIM_HandleTypeDef *hhrtim,
  415. uint32_t TimerIdx,
  416. const HRTIM_TimeBaseCfgTypeDef *pTimeBaseCfg);
  417. static void HRTIM_MasterWaveform_Config(HRTIM_HandleTypeDef *hhrtim,
  418. const HRTIM_TimerCfgTypeDef *pTimerCfg);
  419. static void HRTIM_TimingUnitWaveform_Config(HRTIM_HandleTypeDef *hhrtim,
  420. uint32_t TimerIdx,
  421. const HRTIM_TimerCfgTypeDef *pTimerCfg);
  422. static void HRTIM_TimingUnitWaveform_Control(HRTIM_HandleTypeDef *hhrtim,
  423. uint32_t TimerIdx,
  424. const HRTIM_TimerCtlTypeDef *pTimerCtl);
  425. static void HRTIM_TimingUnitRollOver_Config(HRTIM_HandleTypeDef *hhrtim,
  426. uint32_t TimerIdx,
  427. uint32_t pRollOverMode);
  428. static void HRTIM_CaptureUnitConfig(HRTIM_HandleTypeDef *hhrtim,
  429. uint32_t TimerIdx,
  430. uint32_t CaptureUnit,
  431. uint32_t Event);
  432. static void HRTIM_OutputConfig(HRTIM_HandleTypeDef *hhrtim,
  433. uint32_t TimerIdx,
  434. uint32_t Output,
  435. const HRTIM_OutputCfgTypeDef *pOutputCfg);
  436. static void HRTIM_EventConfig(HRTIM_HandleTypeDef *hhrtim,
  437. uint32_t Event,
  438. const HRTIM_EventCfgTypeDef *pEventCfg);
  439. static void HRTIM_TIM_ResetConfig(HRTIM_HandleTypeDef *hhrtim,
  440. uint32_t TimerIdx,
  441. uint32_t Event);
  442. static uint32_t HRTIM_GetITFromOCMode(const HRTIM_HandleTypeDef *hhrtim,
  443. uint32_t TimerIdx,
  444. uint32_t OCChannel);
  445. static uint32_t HRTIM_GetDMAFromOCMode(const HRTIM_HandleTypeDef *hhrtim,
  446. uint32_t TimerIdx,
  447. uint32_t OCChannel);
  448. static DMA_HandleTypeDef *HRTIM_GetDMAHandleFromTimerIdx(const HRTIM_HandleTypeDef *hhrtim,
  449. uint32_t TimerIdx);
  450. static uint32_t GetTimerIdxFromDMAHandle(const HRTIM_HandleTypeDef *hhrtim,
  451. const DMA_HandleTypeDef *hdma);
  452. static void HRTIM_ForceRegistersUpdate(HRTIM_HandleTypeDef *hhrtim,
  453. uint32_t TimerIdx);
  454. static void HRTIM_HRTIM_ISR(HRTIM_HandleTypeDef *hhrtim);
  455. static void HRTIM_Master_ISR(HRTIM_HandleTypeDef *hhrtim);
  456. static void HRTIM_Timer_ISR(HRTIM_HandleTypeDef *hhrtim,
  457. uint32_t TimerIdx);
  458. static void HRTIM_DMAMasterCplt(DMA_HandleTypeDef *hdma);
  459. static void HRTIM_DMATimerxCplt(DMA_HandleTypeDef *hdma);
  460. static void HRTIM_DMAError(DMA_HandleTypeDef *hdma);
  461. static void HRTIM_BurstDMACplt(DMA_HandleTypeDef *hdma);
  462. /**
  463. * @}
  464. */
  465. /* Exported functions ---------------------------------------------------------*/
  466. /** @defgroup HRTIM_Exported_Functions HRTIM Exported Functions
  467. * @{
  468. */
  469. /** @defgroup HRTIM_Exported_Functions_Group1 Initialization and de-initialization functions
  470. * @brief Initialization and Configuration functions
  471. @verbatim
  472. ===============================================================================
  473. ##### Initialization and Time Base Configuration functions #####
  474. ===============================================================================
  475. [..] This section provides functions allowing to:
  476. (+) Initialize a HRTIM instance
  477. (+) De-initialize a HRTIM instance
  478. (+) Initialize the HRTIM MSP
  479. (+) De-initialize the HRTIM MSP
  480. (+) Start the high-resolution unit (start DLL calibration)
  481. (+) Check that the high resolution unit is ready (DLL calibration done)
  482. (+) Configure the time base unit of a HRTIM timer
  483. @endverbatim
  484. * @{
  485. */
  486. /**
  487. * @brief Initialize a HRTIM instance
  488. * @param hhrtim pointer to HAL HRTIM handle
  489. * @retval HAL status
  490. */
  491. HAL_StatusTypeDef HAL_HRTIM_Init(HRTIM_HandleTypeDef *hhrtim)
  492. {
  493. uint8_t timer_idx;
  494. uint32_t hrtim_mcr;
  495. /* Check the HRTIM handle allocation */
  496. if (hhrtim == NULL)
  497. {
  498. return HAL_ERROR;
  499. }
  500. /* Check the parameters */
  501. assert_param(IS_HRTIM_ALL_INSTANCE(hhrtim->Instance));
  502. assert_param(IS_HRTIM_IT(hhrtim->Init.HRTIMInterruptRequests));
  503. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  504. if (hhrtim->State == HAL_HRTIM_STATE_RESET)
  505. {
  506. /* Initialize callback function pointers to their default values */
  507. hhrtim->Fault1Callback = HAL_HRTIM_Fault1Callback;
  508. hhrtim->Fault2Callback = HAL_HRTIM_Fault2Callback;
  509. hhrtim->Fault3Callback = HAL_HRTIM_Fault3Callback;
  510. hhrtim->Fault4Callback = HAL_HRTIM_Fault4Callback;
  511. hhrtim->Fault5Callback = HAL_HRTIM_Fault5Callback;
  512. hhrtim->Fault6Callback = HAL_HRTIM_Fault6Callback;
  513. hhrtim->SystemFaultCallback = HAL_HRTIM_SystemFaultCallback;
  514. hhrtim->DLLCalibrationReadyCallback = HAL_HRTIM_DLLCalibrationReadyCallback;
  515. hhrtim->BurstModePeriodCallback = HAL_HRTIM_BurstModePeriodCallback;
  516. hhrtim->SynchronizationEventCallback = HAL_HRTIM_SynchronizationEventCallback;
  517. hhrtim->ErrorCallback = HAL_HRTIM_ErrorCallback;
  518. hhrtim->RegistersUpdateCallback = HAL_HRTIM_RegistersUpdateCallback;
  519. hhrtim->RepetitionEventCallback = HAL_HRTIM_RepetitionEventCallback;
  520. hhrtim->Compare1EventCallback = HAL_HRTIM_Compare1EventCallback;
  521. hhrtim->Compare2EventCallback = HAL_HRTIM_Compare2EventCallback;
  522. hhrtim->Compare3EventCallback = HAL_HRTIM_Compare3EventCallback;
  523. hhrtim->Compare4EventCallback = HAL_HRTIM_Compare4EventCallback;
  524. hhrtim->Capture1EventCallback = HAL_HRTIM_Capture1EventCallback;
  525. hhrtim->Capture2EventCallback = HAL_HRTIM_Capture2EventCallback;
  526. hhrtim->DelayedProtectionCallback = HAL_HRTIM_DelayedProtectionCallback;
  527. hhrtim->CounterResetCallback = HAL_HRTIM_CounterResetCallback;
  528. hhrtim->Output1SetCallback = HAL_HRTIM_Output1SetCallback;
  529. hhrtim->Output1ResetCallback = HAL_HRTIM_Output1ResetCallback;
  530. hhrtim->Output2SetCallback = HAL_HRTIM_Output2SetCallback;
  531. hhrtim->Output2ResetCallback = HAL_HRTIM_Output2ResetCallback;
  532. hhrtim->BurstDMATransferCallback = HAL_HRTIM_BurstDMATransferCallback;
  533. if (hhrtim->MspInitCallback == NULL)
  534. {
  535. hhrtim->MspInitCallback = HAL_HRTIM_MspInit;
  536. }
  537. }
  538. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  539. /* Set the HRTIM state */
  540. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  541. /* Initialize the DMA handles */
  542. hhrtim->hdmaMaster = (DMA_HandleTypeDef *)NULL;
  543. hhrtim->hdmaTimerA = (DMA_HandleTypeDef *)NULL;
  544. hhrtim->hdmaTimerB = (DMA_HandleTypeDef *)NULL;
  545. hhrtim->hdmaTimerC = (DMA_HandleTypeDef *)NULL;
  546. hhrtim->hdmaTimerD = (DMA_HandleTypeDef *)NULL;
  547. hhrtim->hdmaTimerE = (DMA_HandleTypeDef *)NULL;
  548. hhrtim->hdmaTimerF = (DMA_HandleTypeDef *)NULL;
  549. /* HRTIM output synchronization configuration (if required) */
  550. if ((hhrtim->Init.SyncOptions & HRTIM_SYNCOPTION_MASTER) != (uint32_t)RESET)
  551. {
  552. /* Check parameters */
  553. assert_param(IS_HRTIM_SYNCOUTPUTSOURCE(hhrtim->Init.SyncOutputSource));
  554. assert_param(IS_HRTIM_SYNCOUTPUTPOLARITY(hhrtim->Init.SyncOutputPolarity));
  555. /* The synchronization output initialization procedure must be done prior
  556. to the configuration of the MCU outputs (done within HAL_HRTIM_MspInit)
  557. */
  558. if (hhrtim->Instance == HRTIM1)
  559. {
  560. /* Enable the HRTIM peripheral clock */
  561. __HAL_RCC_HRTIM1_CLK_ENABLE();
  562. }
  563. hrtim_mcr = hhrtim->Instance->sMasterRegs.MCR;
  564. /* Set the event to be sent on the synchronization output */
  565. hrtim_mcr &= ~(HRTIM_MCR_SYNC_SRC);
  566. hrtim_mcr |= (hhrtim->Init.SyncOutputSource & HRTIM_MCR_SYNC_SRC);
  567. /* Set the polarity of the synchronization output */
  568. hrtim_mcr &= ~(HRTIM_MCR_SYNC_OUT);
  569. hrtim_mcr |= (hhrtim->Init.SyncOutputPolarity & HRTIM_MCR_SYNC_OUT);
  570. /* Update the HRTIM registers */
  571. hhrtim->Instance->sMasterRegs.MCR = hrtim_mcr;
  572. }
  573. /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
  574. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  575. hhrtim->MspInitCallback(hhrtim);
  576. #else
  577. HAL_HRTIM_MspInit(hhrtim);
  578. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  579. /* HRTIM input synchronization configuration (if required) */
  580. if ((hhrtim->Init.SyncOptions & HRTIM_SYNCOPTION_SLAVE) != (uint32_t)RESET)
  581. {
  582. /* Check parameters */
  583. assert_param(IS_HRTIM_SYNCINPUTSOURCE(hhrtim->Init.SyncInputSource));
  584. hrtim_mcr = hhrtim->Instance->sMasterRegs.MCR;
  585. /* Set the synchronization input source */
  586. hrtim_mcr &= ~(HRTIM_MCR_SYNC_IN);
  587. hrtim_mcr |= (hhrtim->Init.SyncInputSource & HRTIM_MCR_SYNC_IN);
  588. /* Update the HRTIM registers */
  589. hhrtim->Instance->sMasterRegs.MCR = hrtim_mcr;
  590. }
  591. /* Initialize the HRTIM state*/
  592. hhrtim->State = HAL_HRTIM_STATE_READY;
  593. /* Initialize the lock status of the HRTIM HAL API */
  594. __HAL_UNLOCK(hhrtim);
  595. /* Initialize timer related parameters */
  596. for (timer_idx = HRTIM_TIMERINDEX_TIMER_A ;
  597. timer_idx <= HRTIM_TIMERINDEX_MASTER ;
  598. timer_idx++)
  599. {
  600. hhrtim->TimerParam[timer_idx].CaptureTrigger1 = HRTIM_CAPTURETRIGGER_NONE;
  601. hhrtim->TimerParam[timer_idx].CaptureTrigger2 = HRTIM_CAPTURETRIGGER_NONE;
  602. hhrtim->TimerParam[timer_idx].InterruptRequests = HRTIM_IT_NONE;
  603. hhrtim->TimerParam[timer_idx].DMARequests = HRTIM_IT_NONE;
  604. hhrtim->TimerParam[timer_idx].DMASrcAddress = 0U;
  605. hhrtim->TimerParam[timer_idx].DMASize = 0U;
  606. }
  607. return HAL_OK;
  608. }
  609. /**
  610. * @brief De-initialize a HRTIM instance
  611. * @param hhrtim pointer to HAL HRTIM handle
  612. * @retval HAL status
  613. */
  614. HAL_StatusTypeDef HAL_HRTIM_DeInit(HRTIM_HandleTypeDef *hhrtim)
  615. {
  616. /* Check the HRTIM handle allocation */
  617. if (hhrtim == NULL)
  618. {
  619. return HAL_ERROR;
  620. }
  621. /* Check the parameters */
  622. assert_param(IS_HRTIM_ALL_INSTANCE(hhrtim->Instance));
  623. /* Set the HRTIM state */
  624. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  625. /* DeInit the low level hardware */
  626. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  627. if (hhrtim->MspDeInitCallback == NULL)
  628. {
  629. hhrtim->MspDeInitCallback = HAL_HRTIM_MspDeInit;
  630. }
  631. hhrtim->MspDeInitCallback(hhrtim);
  632. #else
  633. HAL_HRTIM_MspDeInit(hhrtim);
  634. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  635. hhrtim->State = HAL_HRTIM_STATE_READY;
  636. return HAL_OK;
  637. }
  638. /**
  639. * @brief MSP initialization for a HRTIM instance
  640. * @param hhrtim pointer to HAL HRTIM handle
  641. * @retval None
  642. */
  643. __weak void HAL_HRTIM_MspInit(HRTIM_HandleTypeDef *hhrtim)
  644. {
  645. /* Prevent unused argument(s) compilation warning */
  646. UNUSED(hhrtim);
  647. /* NOTE: This function should not be modified, when the callback is needed,
  648. the HAL_HRTIM_MspInit could be implemented in the user file
  649. */
  650. }
  651. /**
  652. * @brief MSP de-initialization of a HRTIM instance
  653. * @param hhrtim pointer to HAL HRTIM handle
  654. * @retval None
  655. */
  656. __weak void HAL_HRTIM_MspDeInit(HRTIM_HandleTypeDef *hhrtim)
  657. {
  658. /* Prevent unused argument(s) compilation warning */
  659. UNUSED(hhrtim);
  660. /* NOTE: This function should not be modified, when the callback is needed,
  661. the HAL_HRTIM_MspDeInit could be implemented in the user file
  662. */
  663. }
  664. /**
  665. * @brief Start the DLL calibration
  666. * @param hhrtim pointer to HAL HRTIM handle
  667. * @param CalibrationRate DLL calibration period
  668. * This parameter can be one of the following values:
  669. * @arg HRTIM_SINGLE_CALIBRATION: One shot DLL calibration
  670. * @arg HRTIM_CALIBRATIONRATE_0: Periodic DLL calibration. T=6.168 ms
  671. * @arg HRTIM_CALIBRATIONRATE_1: Periodic DLL calibration. T=0.771 ms
  672. * @arg HRTIM_CALIBRATIONRATE_2: Periodic DLL calibration. T=0.096 ms
  673. * @arg HRTIM_CALIBRATIONRATE_3: Periodic DLL calibration. T=0.012 ms
  674. * @retval HAL status
  675. * @note This function locks the HRTIM instance. HRTIM instance is unlocked
  676. * within the HAL_HRTIM_PollForDLLCalibration function, just before
  677. * exiting the function.
  678. */
  679. HAL_StatusTypeDef HAL_HRTIM_DLLCalibrationStart(HRTIM_HandleTypeDef *hhrtim,
  680. uint32_t CalibrationRate)
  681. {
  682. /* Check the parameters */
  683. assert_param(IS_HRTIM_CALIBRATIONRATE(CalibrationRate));
  684. /* Process Locked */
  685. __HAL_LOCK(hhrtim);
  686. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  687. if (CalibrationRate == HRTIM_SINGLE_CALIBRATION)
  688. {
  689. /* One shot DLL calibration */
  690. CLEAR_BIT(hhrtim->Instance->sCommonRegs.DLLCR, HRTIM_DLLCR_CALEN);
  691. SET_BIT(hhrtim->Instance->sCommonRegs.DLLCR, HRTIM_DLLCR_CAL);
  692. }
  693. else
  694. {
  695. /* Periodic DLL calibration */
  696. SET_BIT(hhrtim->Instance->sCommonRegs.DLLCR, HRTIM_DLLCR_CALEN);
  697. MODIFY_REG(hhrtim->Instance->sCommonRegs.DLLCR, HRTIM_DLLCR_CALRTE, CalibrationRate);
  698. SET_BIT(hhrtim->Instance->sCommonRegs.DLLCR, HRTIM_DLLCR_CAL);
  699. }
  700. /* Set HRTIM state */
  701. hhrtim->State = HAL_HRTIM_STATE_READY;
  702. return HAL_OK;
  703. }
  704. /**
  705. * @brief Start the DLL calibration.
  706. * DLL ready interrupt is enabled
  707. * @param hhrtim pointer to HAL HRTIM handle
  708. * @param CalibrationRate DLL calibration period
  709. * This parameter can be one of the following values:
  710. * @arg HRTIM_SINGLE_CALIBRATION: One shot DLL calibration
  711. * @arg HRTIM_CALIBRATIONRATE_0: Periodic DLL calibration. T=6.168 ms
  712. * @arg HRTIM_CALIBRATIONRATE_1: Periodic DLL calibration. T=0.771 ms
  713. * @arg HRTIM_CALIBRATIONRATE_2: Periodic DLL calibration. T=0.096 ms
  714. * @arg HRTIM_CALIBRATIONRATE_3: Periodic DLL calibration. T=0.012 ms
  715. * @retval HAL status
  716. * @note This function locks the HRTIM instance. HRTIM instance is unlocked
  717. * within the IRQ processing function when processing the DLL ready
  718. * interrupt.
  719. * @note If this function is called for periodic calibration, the DLLRDY
  720. * interrupt is generated every time the calibration completes which
  721. * will significantly increases the overall interrupt rate.
  722. */
  723. HAL_StatusTypeDef HAL_HRTIM_DLLCalibrationStart_IT(HRTIM_HandleTypeDef *hhrtim,
  724. uint32_t CalibrationRate)
  725. {
  726. /* Check the parameters */
  727. assert_param(IS_HRTIM_CALIBRATIONRATE(CalibrationRate));
  728. /* Process Locked */
  729. __HAL_LOCK(hhrtim);
  730. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  731. /* Enable DLL Ready interrupt flag */
  732. __HAL_HRTIM_ENABLE_IT(hhrtim, HRTIM_IT_DLLRDY);
  733. if (CalibrationRate == HRTIM_SINGLE_CALIBRATION)
  734. {
  735. /* One shot DLL calibration */
  736. CLEAR_BIT(hhrtim->Instance->sCommonRegs.DLLCR, HRTIM_DLLCR_CALEN);
  737. SET_BIT(hhrtim->Instance->sCommonRegs.DLLCR, HRTIM_DLLCR_CAL);
  738. }
  739. else
  740. {
  741. /* Periodic DLL calibration */
  742. SET_BIT(hhrtim->Instance->sCommonRegs.DLLCR, HRTIM_DLLCR_CALEN);
  743. MODIFY_REG(hhrtim->Instance->sCommonRegs.DLLCR, HRTIM_DLLCR_CALRTE, CalibrationRate);
  744. SET_BIT(hhrtim->Instance->sCommonRegs.DLLCR, HRTIM_DLLCR_CAL);
  745. }
  746. /* Set HRTIM state */
  747. hhrtim->State = HAL_HRTIM_STATE_READY;
  748. return HAL_OK;
  749. }
  750. /**
  751. * @brief Poll the DLL calibration ready flag and returns when the flag is
  752. * set (DLL calibration completed) or upon timeout expiration.
  753. * @param hhrtim pointer to HAL HRTIM handle
  754. * @param Timeout Timeout duration in millisecond
  755. * @retval HAL status
  756. */
  757. HAL_StatusTypeDef HAL_HRTIM_PollForDLLCalibration(HRTIM_HandleTypeDef *hhrtim,
  758. uint32_t Timeout)
  759. {
  760. uint32_t tickstart;
  761. tickstart = HAL_GetTick();
  762. /* Check End of conversion flag */
  763. while (__HAL_HRTIM_GET_FLAG(hhrtim, HRTIM_IT_DLLRDY) == (uint32_t)RESET)
  764. {
  765. if (Timeout != HAL_MAX_DELAY)
  766. {
  767. if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
  768. {
  769. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  770. return HAL_TIMEOUT;
  771. }
  772. }
  773. }
  774. /* Set HRTIM State */
  775. hhrtim->State = HAL_HRTIM_STATE_READY;
  776. /* Process unlocked */
  777. __HAL_UNLOCK(hhrtim);
  778. return HAL_OK;
  779. }
  780. /**
  781. * @brief Configure the time base unit of a timer
  782. * @param hhrtim pointer to HAL HRTIM handle
  783. * @param TimerIdx Timer index
  784. * This parameter can be one of the following values:
  785. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  786. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  787. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  788. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  789. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  790. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  791. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  792. * @param pTimeBaseCfg pointer to the time base configuration structure
  793. * @note This function must be called prior starting the timer
  794. * @note The time-base unit initialization parameters specify:
  795. * The timer counter operating mode (continuous, one shot),
  796. * The timer clock prescaler,
  797. * The timer period,
  798. * The timer repetition counter.
  799. * @retval HAL status
  800. */
  801. HAL_StatusTypeDef HAL_HRTIM_TimeBaseConfig(HRTIM_HandleTypeDef *hhrtim,
  802. uint32_t TimerIdx,
  803. const HRTIM_TimeBaseCfgTypeDef *pTimeBaseCfg)
  804. {
  805. /* Check the parameters */
  806. assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  807. assert_param(IS_HRTIM_PRESCALERRATIO(pTimeBaseCfg->PrescalerRatio));
  808. assert_param(IS_HRTIM_MODE(pTimeBaseCfg->Mode));
  809. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  810. {
  811. return HAL_BUSY;
  812. }
  813. /* Set the HRTIM state */
  814. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  815. if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
  816. {
  817. /* Configure master timer time base unit */
  818. HRTIM_MasterBase_Config(hhrtim, pTimeBaseCfg);
  819. }
  820. else
  821. {
  822. /* Configure timing unit time base unit */
  823. HRTIM_TimingUnitBase_Config(hhrtim, TimerIdx, pTimeBaseCfg);
  824. }
  825. /* Set HRTIM state */
  826. hhrtim->State = HAL_HRTIM_STATE_READY;
  827. return HAL_OK;
  828. }
  829. /**
  830. * @}
  831. */
  832. /** @defgroup HRTIM_Exported_Functions_Group2 Simple time base mode functions
  833. * @brief Simple time base mode functions.
  834. @verbatim
  835. ===============================================================================
  836. ##### Simple time base mode functions #####
  837. ===============================================================================
  838. [..] This section provides functions allowing to:
  839. (+) Start simple time base
  840. (+) Stop simple time base
  841. (+) Start simple time base and enable interrupt
  842. (+) Stop simple time base and disable interrupt
  843. (+) Start simple time base and enable DMA transfer
  844. (+) Stop simple time base and disable DMA transfer
  845. -@- When a HRTIM timer operates in simple time base mode, the timer
  846. counter counts from 0 to the period value.
  847. @endverbatim
  848. * @{
  849. */
  850. /**
  851. * @brief Start the counter of a timer operating in simple time base mode.
  852. * @param hhrtim pointer to HAL HRTIM handle
  853. * @param TimerIdx Timer index.
  854. * This parameter can be one of the following values:
  855. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  856. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  857. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  858. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  859. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  860. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  861. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  862. * @retval HAL status
  863. */
  864. HAL_StatusTypeDef HAL_HRTIM_SimpleBaseStart(HRTIM_HandleTypeDef *hhrtim,
  865. uint32_t TimerIdx)
  866. {
  867. /* Check the parameters */
  868. assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  869. /* Process Locked */
  870. __HAL_LOCK(hhrtim);
  871. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  872. /* Enable the timer counter */
  873. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  874. hhrtim->State = HAL_HRTIM_STATE_READY;
  875. /* Process Unlocked */
  876. __HAL_UNLOCK(hhrtim);
  877. return HAL_OK;
  878. }
  879. /**
  880. * @brief Stop the counter of a timer operating in simple time base mode.
  881. * @param hhrtim pointer to HAL HRTIM handle
  882. * @param TimerIdx Timer index.
  883. * This parameter can be one of the following values:
  884. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  885. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  886. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  887. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  888. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  889. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  890. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  891. * @retval HAL status
  892. */
  893. HAL_StatusTypeDef HAL_HRTIM_SimpleBaseStop(HRTIM_HandleTypeDef *hhrtim,
  894. uint32_t TimerIdx)
  895. {
  896. /* Check the parameters */
  897. assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  898. /* Process Locked */
  899. __HAL_LOCK(hhrtim);
  900. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  901. /* Disable the timer counter */
  902. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  903. hhrtim->State = HAL_HRTIM_STATE_READY;
  904. /* Process Unlocked */
  905. __HAL_UNLOCK(hhrtim);
  906. return HAL_OK;
  907. }
  908. /**
  909. * @brief Start the counter of a timer operating in simple time base mode
  910. * (Timer repetition interrupt is enabled).
  911. * @param hhrtim pointer to HAL HRTIM handle
  912. * @param TimerIdx Timer index.
  913. * This parameter can be one of the following values:
  914. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  915. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  916. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  917. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  918. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  919. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  920. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  921. * @retval HAL status
  922. */
  923. HAL_StatusTypeDef HAL_HRTIM_SimpleBaseStart_IT(HRTIM_HandleTypeDef *hhrtim,
  924. uint32_t TimerIdx)
  925. {
  926. /* Check the parameters */
  927. assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  928. /* Process Locked */
  929. __HAL_LOCK(hhrtim);
  930. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  931. /* Enable the repetition interrupt */
  932. if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
  933. {
  934. __HAL_HRTIM_MASTER_ENABLE_IT(hhrtim, HRTIM_MASTER_IT_MREP);
  935. }
  936. else
  937. {
  938. __HAL_HRTIM_TIMER_ENABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_REP);
  939. }
  940. /* Enable the timer counter */
  941. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  942. hhrtim->State = HAL_HRTIM_STATE_READY;
  943. /* Process Unlocked */
  944. __HAL_UNLOCK(hhrtim);
  945. return HAL_OK;
  946. }
  947. /**
  948. * @brief Stop the counter of a timer operating in simple time base mode
  949. * (Timer repetition interrupt is disabled).
  950. * @param hhrtim pointer to HAL HRTIM handle
  951. * @param TimerIdx Timer index.
  952. * This parameter can be one of the following values:
  953. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  954. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  955. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  956. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  957. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  958. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  959. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  960. * @retval HAL status
  961. */
  962. HAL_StatusTypeDef HAL_HRTIM_SimpleBaseStop_IT(HRTIM_HandleTypeDef *hhrtim,
  963. uint32_t TimerIdx)
  964. {
  965. /* Check the parameters */
  966. assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  967. /* Process Locked */
  968. __HAL_LOCK(hhrtim);
  969. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  970. /* Disable the repetition interrupt */
  971. if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
  972. {
  973. __HAL_HRTIM_MASTER_DISABLE_IT(hhrtim, HRTIM_MASTER_IT_MREP);
  974. }
  975. else
  976. {
  977. __HAL_HRTIM_TIMER_DISABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_REP);
  978. }
  979. /* Disable the timer counter */
  980. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  981. hhrtim->State = HAL_HRTIM_STATE_READY;
  982. /* Process Unlocked */
  983. __HAL_UNLOCK(hhrtim);
  984. return HAL_OK;
  985. }
  986. /**
  987. * @brief Start the counter of a timer operating in simple time base mode
  988. * (Timer repetition DMA request is enabled).
  989. * @param hhrtim pointer to HAL HRTIM handle
  990. * @param TimerIdx Timer index.
  991. * This parameter can be one of the following values:
  992. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  993. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  994. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  995. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  996. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  997. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  998. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  999. * @param SrcAddr DMA transfer source address
  1000. * @param DestAddr DMA transfer destination address
  1001. * @param Length The length of data items (data size) to be transferred
  1002. * from source to destination
  1003. */
  1004. HAL_StatusTypeDef HAL_HRTIM_SimpleBaseStart_DMA(HRTIM_HandleTypeDef *hhrtim,
  1005. uint32_t TimerIdx,
  1006. uint32_t SrcAddr,
  1007. uint32_t DestAddr,
  1008. uint32_t Length)
  1009. {
  1010. DMA_HandleTypeDef *hdma;
  1011. /* Check the parameters */
  1012. assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  1013. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  1014. {
  1015. return HAL_BUSY;
  1016. }
  1017. if (hhrtim->State == HAL_HRTIM_STATE_READY)
  1018. {
  1019. if ((SrcAddr == 0U) || (DestAddr == 0U) || (Length == 0U))
  1020. {
  1021. return HAL_ERROR;
  1022. }
  1023. else
  1024. {
  1025. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1026. }
  1027. }
  1028. /* Process Locked */
  1029. __HAL_LOCK(hhrtim);
  1030. /* Get the timer DMA handler */
  1031. hdma = HRTIM_GetDMAHandleFromTimerIdx(hhrtim, TimerIdx);
  1032. if (hdma == NULL)
  1033. {
  1034. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1035. /* Process Unlocked */
  1036. __HAL_UNLOCK(hhrtim);
  1037. return HAL_ERROR;
  1038. }
  1039. /* Set the DMA transfer completed callback */
  1040. if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
  1041. {
  1042. hdma->XferCpltCallback = HRTIM_DMAMasterCplt;
  1043. }
  1044. else
  1045. {
  1046. hdma->XferCpltCallback = HRTIM_DMATimerxCplt;
  1047. }
  1048. /* Set the DMA error callback */
  1049. hdma->XferErrorCallback = HRTIM_DMAError ;
  1050. /* Enable the DMA channel */
  1051. if (HAL_DMA_Start_IT(hdma, SrcAddr, DestAddr, Length) != HAL_OK)
  1052. {
  1053. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1054. /* Process Unlocked */
  1055. __HAL_UNLOCK(hhrtim);
  1056. return HAL_ERROR;
  1057. }
  1058. /* Enable the timer repetition DMA request */
  1059. if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
  1060. {
  1061. __HAL_HRTIM_MASTER_ENABLE_DMA(hhrtim, HRTIM_MASTER_DMA_MREP);
  1062. }
  1063. else
  1064. {
  1065. __HAL_HRTIM_TIMER_ENABLE_DMA(hhrtim, TimerIdx, HRTIM_TIM_DMA_REP);
  1066. }
  1067. /* Enable the timer counter */
  1068. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1069. hhrtim->State = HAL_HRTIM_STATE_READY;
  1070. /* Process Unlocked */
  1071. __HAL_UNLOCK(hhrtim);
  1072. return HAL_OK;
  1073. }
  1074. /**
  1075. * @brief Stop the counter of a timer operating in simple time base mode
  1076. * (Timer repetition DMA request is disabled).
  1077. * @param hhrtim pointer to HAL HRTIM handle
  1078. * @param TimerIdx Timer index.
  1079. * This parameter can be one of the following values:
  1080. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  1081. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1082. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1083. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1084. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1085. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1086. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  1087. * @retval HAL status
  1088. */
  1089. HAL_StatusTypeDef HAL_HRTIM_SimpleBaseStop_DMA(HRTIM_HandleTypeDef *hhrtim,
  1090. uint32_t TimerIdx)
  1091. {
  1092. DMA_HandleTypeDef *hdma;
  1093. /* Check the parameters */
  1094. assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  1095. /* Process Locked */
  1096. __HAL_LOCK(hhrtim);
  1097. if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
  1098. {
  1099. hhrtim->State = HAL_HRTIM_STATE_READY;
  1100. /* Disable the DMA */
  1101. if (HAL_DMA_Abort(hhrtim->hdmaMaster) != HAL_OK)
  1102. {
  1103. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1104. }
  1105. /* Disable the timer repetition DMA request */
  1106. __HAL_HRTIM_MASTER_DISABLE_DMA(hhrtim, HRTIM_MASTER_DMA_MREP);
  1107. }
  1108. else
  1109. {
  1110. /* Get the timer DMA handler */
  1111. hdma = HRTIM_GetDMAHandleFromTimerIdx(hhrtim, TimerIdx);
  1112. if (hdma == NULL)
  1113. {
  1114. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1115. }
  1116. else
  1117. {
  1118. hhrtim->State = HAL_HRTIM_STATE_READY;
  1119. /* Disable the DMA */
  1120. if (HAL_DMA_Abort(hdma) != HAL_OK)
  1121. {
  1122. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1123. }
  1124. /* Disable the timer repetition DMA request */
  1125. __HAL_HRTIM_TIMER_DISABLE_DMA(hhrtim, TimerIdx, HRTIM_TIM_DMA_REP);
  1126. }
  1127. }
  1128. /* Disable the timer counter */
  1129. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1130. /* Process Unlocked */
  1131. __HAL_UNLOCK(hhrtim);
  1132. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  1133. {
  1134. return HAL_ERROR;
  1135. }
  1136. else
  1137. {
  1138. return HAL_OK;
  1139. }
  1140. }
  1141. /**
  1142. * @}
  1143. */
  1144. /** @defgroup HRTIM_Exported_Functions_Group3 Simple output compare mode functions
  1145. * @brief Simple output compare functions
  1146. @verbatim
  1147. ===============================================================================
  1148. ##### Simple output compare functions #####
  1149. ===============================================================================
  1150. [..] This section provides functions allowing to:
  1151. (+) Configure simple output channel
  1152. (+) Start simple output compare
  1153. (+) Stop simple output compare
  1154. (+) Start simple output compare and enable interrupt
  1155. (+) Stop simple output compare and disable interrupt
  1156. (+) Start simple output compare and enable DMA transfer
  1157. (+) Stop simple output compare and disable DMA transfer
  1158. -@- When a HRTIM timer operates in simple output compare mode
  1159. the output level is set to a programmable value when a match
  1160. is found between the compare register and the counter.
  1161. Compare unit 1 is automatically associated to output 1
  1162. Compare unit 2 is automatically associated to output 2
  1163. @endverbatim
  1164. * @{
  1165. */
  1166. /**
  1167. * @brief Configure an output in simple output compare mode
  1168. * @param hhrtim pointer to HAL HRTIM handle
  1169. * @param TimerIdx Timer index
  1170. * This parameter can be one of the following values:
  1171. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1172. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1173. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1174. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1175. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1176. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  1177. * @param OCChannel Timer output
  1178. * This parameter can be one of the following values:
  1179. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1180. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1181. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1182. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1183. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1184. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1185. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1186. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1187. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1188. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1189. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  1190. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  1191. * @param pSimpleOCChannelCfg pointer to the simple output compare output configuration structure
  1192. * @note When the timer operates in simple output compare mode:
  1193. * Output 1 is implicitly controlled by the compare unit 1
  1194. * Output 2 is implicitly controlled by the compare unit 2
  1195. * Output Set/Reset crossbar is set according to the selected output compare mode:
  1196. * Toggle: SETxyR = RSTxyR = CMPy
  1197. * Active: SETxyR = CMPy, RSTxyR = 0
  1198. * Inactive: SETxy =0, RSTxy = CMPy
  1199. * @retval HAL status
  1200. */
  1201. HAL_StatusTypeDef HAL_HRTIM_SimpleOCChannelConfig(HRTIM_HandleTypeDef *hhrtim,
  1202. uint32_t TimerIdx,
  1203. uint32_t OCChannel,
  1204. const HRTIM_SimpleOCChannelCfgTypeDef *pSimpleOCChannelCfg)
  1205. {
  1206. uint32_t CompareUnit = (uint32_t)RESET;
  1207. HRTIM_OutputCfgTypeDef OutputCfg;
  1208. /* Check parameters */
  1209. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OCChannel));
  1210. assert_param(IS_HRTIM_BASICOCMODE(pSimpleOCChannelCfg->Mode));
  1211. assert_param(IS_HRTIM_OUTPUTPULSE(pSimpleOCChannelCfg->Pulse));
  1212. assert_param(IS_HRTIM_OUTPUTPOLARITY(pSimpleOCChannelCfg->Polarity));
  1213. assert_param(IS_HRTIM_OUTPUTIDLELEVEL(pSimpleOCChannelCfg->IdleLevel));
  1214. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  1215. {
  1216. return HAL_BUSY;
  1217. }
  1218. /* Process Locked */
  1219. __HAL_LOCK(hhrtim);
  1220. /* Set HRTIM state */
  1221. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1222. /* Configure timer compare unit */
  1223. switch (OCChannel)
  1224. {
  1225. case HRTIM_OUTPUT_TA1:
  1226. case HRTIM_OUTPUT_TB1:
  1227. case HRTIM_OUTPUT_TC1:
  1228. case HRTIM_OUTPUT_TD1:
  1229. case HRTIM_OUTPUT_TE1:
  1230. case HRTIM_OUTPUT_TF1:
  1231. {
  1232. CompareUnit = HRTIM_COMPAREUNIT_1;
  1233. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP1xR = pSimpleOCChannelCfg->Pulse;
  1234. break;
  1235. }
  1236. case HRTIM_OUTPUT_TA2:
  1237. case HRTIM_OUTPUT_TB2:
  1238. case HRTIM_OUTPUT_TC2:
  1239. case HRTIM_OUTPUT_TD2:
  1240. case HRTIM_OUTPUT_TE2:
  1241. case HRTIM_OUTPUT_TF2:
  1242. {
  1243. CompareUnit = HRTIM_COMPAREUNIT_2;
  1244. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP2xR = pSimpleOCChannelCfg->Pulse;
  1245. break;
  1246. }
  1247. default:
  1248. {
  1249. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1250. /* Process Unlocked */
  1251. __HAL_UNLOCK(hhrtim);
  1252. break;
  1253. }
  1254. }
  1255. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  1256. {
  1257. return HAL_ERROR;
  1258. }
  1259. /* Configure timer output */
  1260. OutputCfg.Polarity = (pSimpleOCChannelCfg->Polarity & HRTIM_OUTR_POL1);
  1261. OutputCfg.IdleLevel = (pSimpleOCChannelCfg->IdleLevel & HRTIM_OUTR_IDLES1);
  1262. OutputCfg.FaultLevel = HRTIM_OUTPUTFAULTLEVEL_NONE;
  1263. OutputCfg.IdleMode = HRTIM_OUTPUTIDLEMODE_NONE;
  1264. OutputCfg.ChopperModeEnable = HRTIM_OUTPUTCHOPPERMODE_DISABLED;
  1265. OutputCfg.BurstModeEntryDelayed = HRTIM_OUTPUTBURSTMODEENTRY_REGULAR;
  1266. switch (pSimpleOCChannelCfg->Mode)
  1267. {
  1268. case HRTIM_BASICOCMODE_TOGGLE:
  1269. {
  1270. if (CompareUnit == HRTIM_COMPAREUNIT_1)
  1271. {
  1272. OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP1;
  1273. }
  1274. else
  1275. {
  1276. OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP2;
  1277. }
  1278. OutputCfg.ResetSource = OutputCfg.SetSource;
  1279. break;
  1280. }
  1281. case HRTIM_BASICOCMODE_ACTIVE:
  1282. {
  1283. if (CompareUnit == HRTIM_COMPAREUNIT_1)
  1284. {
  1285. OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP1;
  1286. }
  1287. else
  1288. {
  1289. OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP2;
  1290. }
  1291. OutputCfg.ResetSource = HRTIM_OUTPUTRESET_NONE;
  1292. break;
  1293. }
  1294. case HRTIM_BASICOCMODE_INACTIVE:
  1295. {
  1296. if (CompareUnit == HRTIM_COMPAREUNIT_1)
  1297. {
  1298. OutputCfg.ResetSource = HRTIM_OUTPUTRESET_TIMCMP1;
  1299. }
  1300. else
  1301. {
  1302. OutputCfg.ResetSource = HRTIM_OUTPUTRESET_TIMCMP2;
  1303. }
  1304. OutputCfg.SetSource = HRTIM_OUTPUTSET_NONE;
  1305. break;
  1306. }
  1307. default:
  1308. {
  1309. OutputCfg.SetSource = HRTIM_OUTPUTSET_NONE;
  1310. OutputCfg.ResetSource = HRTIM_OUTPUTRESET_NONE;
  1311. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1312. /* Process Unlocked */
  1313. __HAL_UNLOCK(hhrtim);
  1314. break;
  1315. }
  1316. }
  1317. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  1318. {
  1319. return HAL_ERROR;
  1320. }
  1321. HRTIM_OutputConfig(hhrtim,
  1322. TimerIdx,
  1323. OCChannel,
  1324. &OutputCfg);
  1325. /* Set HRTIM state */
  1326. hhrtim->State = HAL_HRTIM_STATE_READY;
  1327. /* Process Unlocked */
  1328. __HAL_UNLOCK(hhrtim);
  1329. return HAL_OK;
  1330. }
  1331. /**
  1332. * @brief Start the output compare signal generation on the designed timer output
  1333. * @param hhrtim pointer to HAL HRTIM handle
  1334. * @param TimerIdx Timer index
  1335. * This parameter can be one of the following values:
  1336. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1337. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1338. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1339. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1340. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1341. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  1342. * @param OCChannel Timer output
  1343. * This parameter can be one of the following values:
  1344. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1345. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1346. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1347. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1348. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1349. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1350. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1351. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1352. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1353. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1354. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  1355. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  1356. * @retval HAL status
  1357. */
  1358. HAL_StatusTypeDef HAL_HRTIM_SimpleOCStart(HRTIM_HandleTypeDef *hhrtim,
  1359. uint32_t TimerIdx,
  1360. uint32_t OCChannel)
  1361. {
  1362. /* Check the parameters */
  1363. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OCChannel));
  1364. /* Process Locked */
  1365. __HAL_LOCK(hhrtim);
  1366. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1367. /* Enable the timer output */
  1368. hhrtim->Instance->sCommonRegs.OENR |= OCChannel;
  1369. /* Enable the timer counter */
  1370. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1371. hhrtim->State = HAL_HRTIM_STATE_READY;
  1372. /* Process Unlocked */
  1373. __HAL_UNLOCK(hhrtim);
  1374. return HAL_OK;
  1375. }
  1376. /**
  1377. * @brief Stop the output compare signal generation on the designed timer output
  1378. * @param hhrtim pointer to HAL HRTIM handle
  1379. * @param TimerIdx Timer index
  1380. * This parameter can be one of the following values:
  1381. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1382. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1383. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1384. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1385. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1386. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  1387. * @param OCChannel Timer output
  1388. * This parameter can be one of the following values:
  1389. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1390. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1391. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1392. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1393. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1394. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1395. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1396. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1397. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1398. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1399. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  1400. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  1401. * @retval HAL status
  1402. */
  1403. HAL_StatusTypeDef HAL_HRTIM_SimpleOCStop(HRTIM_HandleTypeDef *hhrtim,
  1404. uint32_t TimerIdx,
  1405. uint32_t OCChannel)
  1406. {
  1407. /* Check the parameters */
  1408. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OCChannel));
  1409. /* Process Locked */
  1410. __HAL_LOCK(hhrtim);
  1411. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1412. /* Disable the timer output */
  1413. hhrtim->Instance->sCommonRegs.ODISR |= OCChannel;
  1414. /* Disable the timer counter */
  1415. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1416. hhrtim->State = HAL_HRTIM_STATE_READY;
  1417. /* Process Unlocked */
  1418. __HAL_UNLOCK(hhrtim);
  1419. return HAL_OK;
  1420. }
  1421. /**
  1422. * @brief Start the output compare signal generation on the designed timer output
  1423. * (Interrupt is enabled (see note note below)).
  1424. * @param hhrtim pointer to HAL HRTIM handle
  1425. * @param TimerIdx Timer index
  1426. * This parameter can be one of the following values:
  1427. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1428. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1429. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1430. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1431. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1432. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  1433. * @param OCChannel Timer output
  1434. * This parameter can be one of the following values:
  1435. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1436. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1437. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1438. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1439. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1440. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1441. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1442. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1443. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1444. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1445. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  1446. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  1447. * @note Interrupt enabling depends on the chosen output compare mode
  1448. * Output toggle: compare match interrupt is enabled
  1449. * Output set active: output set interrupt is enabled
  1450. * Output set inactive: output reset interrupt is enabled
  1451. * @retval HAL status
  1452. */
  1453. HAL_StatusTypeDef HAL_HRTIM_SimpleOCStart_IT(HRTIM_HandleTypeDef *hhrtim,
  1454. uint32_t TimerIdx,
  1455. uint32_t OCChannel)
  1456. {
  1457. uint32_t interrupt;
  1458. /* Check the parameters */
  1459. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OCChannel));
  1460. /* Process Locked */
  1461. __HAL_LOCK(hhrtim);
  1462. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1463. /* Get the interrupt to enable (depends on the output compare mode) */
  1464. interrupt = HRTIM_GetITFromOCMode(hhrtim, TimerIdx, OCChannel);
  1465. /* Enable the timer output */
  1466. hhrtim->Instance->sCommonRegs.OENR |= OCChannel;
  1467. /* Enable the timer interrupt (depends on the output compare mode) */
  1468. __HAL_HRTIM_TIMER_ENABLE_IT(hhrtim, TimerIdx, interrupt);
  1469. /* Enable the timer counter */
  1470. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1471. hhrtim->State = HAL_HRTIM_STATE_READY;
  1472. /* Process Unlocked */
  1473. __HAL_UNLOCK(hhrtim);
  1474. return HAL_OK;
  1475. }
  1476. /**
  1477. * @brief Stop the output compare signal generation on the designed timer output
  1478. * (Interrupt is disabled).
  1479. * @param hhrtim pointer to HAL HRTIM handle
  1480. * @param TimerIdx Timer index
  1481. * This parameter can be one of the following values:
  1482. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1483. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1484. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1485. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1486. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1487. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  1488. * @param OCChannel Timer output
  1489. * This parameter can be one of the following values:
  1490. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1491. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1492. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1493. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1494. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1495. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1496. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1497. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1498. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1499. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1500. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  1501. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  1502. * @retval HAL status
  1503. */
  1504. HAL_StatusTypeDef HAL_HRTIM_SimpleOCStop_IT(HRTIM_HandleTypeDef *hhrtim,
  1505. uint32_t TimerIdx,
  1506. uint32_t OCChannel)
  1507. {
  1508. uint32_t interrupt;
  1509. /* Check the parameters */
  1510. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OCChannel));
  1511. /* Process Locked */
  1512. __HAL_LOCK(hhrtim);
  1513. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1514. /* Disable the timer output */
  1515. hhrtim->Instance->sCommonRegs.ODISR |= OCChannel;
  1516. /* Get the interrupt to disable (depends on the output compare mode) */
  1517. interrupt = HRTIM_GetITFromOCMode(hhrtim, TimerIdx, OCChannel);
  1518. /* Disable the timer interrupt */
  1519. __HAL_HRTIM_TIMER_DISABLE_IT(hhrtim, TimerIdx, interrupt);
  1520. /* Disable the timer counter */
  1521. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1522. hhrtim->State = HAL_HRTIM_STATE_READY;
  1523. /* Process Unlocked */
  1524. __HAL_UNLOCK(hhrtim);
  1525. return HAL_OK;
  1526. }
  1527. /**
  1528. * @brief Start the output compare signal generation on the designed timer output
  1529. * (DMA request is enabled (see note below)).
  1530. * @param hhrtim pointer to HAL HRTIM handle
  1531. * @param TimerIdx Timer index
  1532. * This parameter can be one of the following values:
  1533. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1534. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1535. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1536. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1537. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1538. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  1539. * @param OCChannel Timer output
  1540. * This parameter can be one of the following values:
  1541. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1542. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1543. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1544. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1545. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1546. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1547. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1548. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1549. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1550. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1551. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  1552. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  1553. * @param SrcAddr DMA transfer source address
  1554. * @param DestAddr DMA transfer destination address
  1555. * @param Length The length of data items (data size) to be transferred
  1556. * from source to destination
  1557. * @note DMA request enabling depends on the chosen output compare mode
  1558. * Output toggle: compare match DMA request is enabled
  1559. * Output set active: output set DMA request is enabled
  1560. * Output set inactive: output reset DMA request is enabled
  1561. * @retval HAL status
  1562. */
  1563. HAL_StatusTypeDef HAL_HRTIM_SimpleOCStart_DMA(HRTIM_HandleTypeDef *hhrtim,
  1564. uint32_t TimerIdx,
  1565. uint32_t OCChannel,
  1566. uint32_t SrcAddr,
  1567. uint32_t DestAddr,
  1568. uint32_t Length)
  1569. {
  1570. DMA_HandleTypeDef *hdma;
  1571. uint32_t dma_request;
  1572. /* Check the parameters */
  1573. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OCChannel));
  1574. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  1575. {
  1576. return HAL_BUSY;
  1577. }
  1578. if (hhrtim->State == HAL_HRTIM_STATE_READY)
  1579. {
  1580. if ((SrcAddr == 0U) || (DestAddr == 0U) || (Length == 0U))
  1581. {
  1582. return HAL_ERROR;
  1583. }
  1584. else
  1585. {
  1586. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1587. }
  1588. }
  1589. /* Process Locked */
  1590. __HAL_LOCK(hhrtim);
  1591. /* Enable the timer output */
  1592. hhrtim->Instance->sCommonRegs.OENR |= OCChannel;
  1593. /* Get the DMA request to enable */
  1594. dma_request = HRTIM_GetDMAFromOCMode(hhrtim, TimerIdx, OCChannel);
  1595. /* Get the timer DMA handler */
  1596. hdma = HRTIM_GetDMAHandleFromTimerIdx(hhrtim, TimerIdx);
  1597. if (hdma == NULL)
  1598. {
  1599. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1600. /* Process Unlocked */
  1601. __HAL_UNLOCK(hhrtim);
  1602. return HAL_ERROR;
  1603. }
  1604. /* Set the DMA error callback */
  1605. hdma->XferErrorCallback = HRTIM_DMAError ;
  1606. /* Set the DMA transfer completed callback */
  1607. hdma->XferCpltCallback = HRTIM_DMATimerxCplt;
  1608. /* Enable the DMA channel */
  1609. if (HAL_DMA_Start_IT(hdma, SrcAddr, DestAddr, Length) != HAL_OK)
  1610. {
  1611. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1612. /* Process Unlocked */
  1613. __HAL_UNLOCK(hhrtim);
  1614. return HAL_ERROR;
  1615. }
  1616. /* Enable the timer DMA request */
  1617. __HAL_HRTIM_TIMER_ENABLE_DMA(hhrtim, TimerIdx, dma_request);
  1618. /* Enable the timer counter */
  1619. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1620. hhrtim->State = HAL_HRTIM_STATE_READY;
  1621. /* Process Unlocked */
  1622. __HAL_UNLOCK(hhrtim);
  1623. return HAL_OK;
  1624. }
  1625. /**
  1626. * @brief Stop the output compare signal generation on the designed timer output
  1627. * (DMA request is disabled).
  1628. * @param hhrtim pointer to HAL HRTIM handle
  1629. * @param TimerIdx Timer index
  1630. * This parameter can be one of the following values:
  1631. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1632. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1633. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1634. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1635. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1636. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  1637. * @param OCChannel Timer output
  1638. * This parameter can be one of the following values:
  1639. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1640. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1641. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1642. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1643. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1644. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1645. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1646. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1647. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1648. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1649. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  1650. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  1651. * @retval HAL status
  1652. */
  1653. HAL_StatusTypeDef HAL_HRTIM_SimpleOCStop_DMA(HRTIM_HandleTypeDef *hhrtim,
  1654. uint32_t TimerIdx,
  1655. uint32_t OCChannel)
  1656. {
  1657. uint32_t dma_request;
  1658. /* Check the parameters */
  1659. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OCChannel));
  1660. /* Process Locked */
  1661. __HAL_LOCK(hhrtim);
  1662. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1663. /* Disable the timer output */
  1664. hhrtim->Instance->sCommonRegs.ODISR |= OCChannel;
  1665. /* Get the timer DMA handler */
  1666. /* Disable the DMA */
  1667. if (HAL_DMA_Abort(HRTIM_GetDMAHandleFromTimerIdx(hhrtim, TimerIdx)) != HAL_OK)
  1668. {
  1669. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1670. /* Process Unlocked */
  1671. __HAL_UNLOCK(hhrtim);
  1672. return HAL_ERROR;
  1673. }
  1674. /* Get the DMA request to disable */
  1675. dma_request = HRTIM_GetDMAFromOCMode(hhrtim, TimerIdx, OCChannel);
  1676. /* Disable the timer DMA request */
  1677. __HAL_HRTIM_TIMER_DISABLE_DMA(hhrtim, TimerIdx, dma_request);
  1678. /* Disable the timer counter */
  1679. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1680. hhrtim->State = HAL_HRTIM_STATE_READY;
  1681. /* Process Unlocked */
  1682. __HAL_UNLOCK(hhrtim);
  1683. return HAL_OK;
  1684. }
  1685. /**
  1686. * @}
  1687. */
  1688. /** @defgroup HRTIM_Exported_Functions_Group4 Simple PWM output mode functions
  1689. * @brief Simple PWM output functions
  1690. @verbatim
  1691. ===============================================================================
  1692. ##### Simple PWM output functions #####
  1693. ===============================================================================
  1694. [..] This section provides functions allowing to:
  1695. (+) Configure simple PWM output channel
  1696. (+) Start simple PWM output
  1697. (+) Stop simple PWM output
  1698. (+) Start simple PWM output and enable interrupt
  1699. (+) Stop simple PWM output and disable interrupt
  1700. (+) Start simple PWM output and enable DMA transfer
  1701. (+) Stop simple PWM output and disable DMA transfer
  1702. -@- When a HRTIM timer operates in simple PWM output mode
  1703. the output level is set to a programmable value when a match is
  1704. found between the compare register and the counter and reset when
  1705. the timer period is reached. Duty cycle is determined by the
  1706. comparison value.
  1707. Compare unit 1 is automatically associated to output 1
  1708. Compare unit 2 is automatically associated to output 2
  1709. @endverbatim
  1710. * @{
  1711. */
  1712. /**
  1713. * @brief Configure an output in simple PWM mode
  1714. * @param hhrtim pointer to HAL HRTIM handle
  1715. * @param TimerIdx Timer index
  1716. * This parameter can be one of the following values:
  1717. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1718. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1719. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1720. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1721. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1722. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  1723. * @param PWMChannel Timer output
  1724. * This parameter can be one of the following values:
  1725. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1726. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1727. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1728. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1729. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1730. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1731. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1732. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1733. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1734. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1735. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  1736. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  1737. * @param pSimplePWMChannelCfg pointer to the simple PWM output configuration structure
  1738. * @note When the timer operates in simple PWM output mode:
  1739. * Output 1 is implicitly controlled by the compare unit 1
  1740. * Output 2 is implicitly controlled by the compare unit 2
  1741. * Output Set/Reset crossbar is set as follows:
  1742. * Output 1: SETx1R = CMP1, RSTx1R = PER
  1743. * Output 2: SETx2R = CMP2, RST2R = PER
  1744. * @note When Simple PWM mode is used the registers preload mechanism is
  1745. * enabled (otherwise the behavior is not guaranteed).
  1746. * @retval HAL status
  1747. */
  1748. HAL_StatusTypeDef HAL_HRTIM_SimplePWMChannelConfig(HRTIM_HandleTypeDef *hhrtim,
  1749. uint32_t TimerIdx,
  1750. uint32_t PWMChannel,
  1751. const HRTIM_SimplePWMChannelCfgTypeDef *pSimplePWMChannelCfg)
  1752. {
  1753. HRTIM_OutputCfgTypeDef OutputCfg;
  1754. uint32_t hrtim_timcr;
  1755. /* Check parameters */
  1756. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, PWMChannel));
  1757. assert_param(IS_HRTIM_OUTPUTPOLARITY(pSimplePWMChannelCfg->Polarity));
  1758. assert_param(IS_HRTIM_OUTPUTPULSE(pSimplePWMChannelCfg->Pulse));
  1759. assert_param(IS_HRTIM_OUTPUTIDLELEVEL(pSimplePWMChannelCfg->IdleLevel));
  1760. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  1761. {
  1762. return HAL_BUSY;
  1763. }
  1764. /* Process Locked */
  1765. __HAL_LOCK(hhrtim);
  1766. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1767. /* Configure timer compare unit */
  1768. switch (PWMChannel)
  1769. {
  1770. case HRTIM_OUTPUT_TA1:
  1771. case HRTIM_OUTPUT_TB1:
  1772. case HRTIM_OUTPUT_TC1:
  1773. case HRTIM_OUTPUT_TD1:
  1774. case HRTIM_OUTPUT_TE1:
  1775. case HRTIM_OUTPUT_TF1:
  1776. {
  1777. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP1xR = pSimplePWMChannelCfg->Pulse;
  1778. OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP1;
  1779. break;
  1780. }
  1781. case HRTIM_OUTPUT_TA2:
  1782. case HRTIM_OUTPUT_TB2:
  1783. case HRTIM_OUTPUT_TC2:
  1784. case HRTIM_OUTPUT_TD2:
  1785. case HRTIM_OUTPUT_TE2:
  1786. case HRTIM_OUTPUT_TF2:
  1787. {
  1788. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP2xR = pSimplePWMChannelCfg->Pulse;
  1789. OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP2;
  1790. break;
  1791. }
  1792. default:
  1793. {
  1794. OutputCfg.SetSource = HRTIM_OUTPUTSET_NONE;
  1795. OutputCfg.ResetSource = HRTIM_OUTPUTRESET_NONE;
  1796. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1797. /* Process Unlocked */
  1798. __HAL_UNLOCK(hhrtim);
  1799. break;
  1800. }
  1801. }
  1802. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  1803. {
  1804. return HAL_ERROR;
  1805. }
  1806. /* Configure timer output */
  1807. OutputCfg.Polarity = (pSimplePWMChannelCfg->Polarity & HRTIM_OUTR_POL1);
  1808. OutputCfg.IdleLevel = (pSimplePWMChannelCfg->IdleLevel & HRTIM_OUTR_IDLES1);
  1809. OutputCfg.FaultLevel = HRTIM_OUTPUTFAULTLEVEL_NONE;
  1810. OutputCfg.IdleMode = HRTIM_OUTPUTIDLEMODE_NONE;
  1811. OutputCfg.ChopperModeEnable = HRTIM_OUTPUTCHOPPERMODE_DISABLED;
  1812. OutputCfg.BurstModeEntryDelayed = HRTIM_OUTPUTBURSTMODEENTRY_REGULAR;
  1813. OutputCfg.ResetSource = HRTIM_OUTPUTRESET_TIMPER;
  1814. HRTIM_OutputConfig(hhrtim,
  1815. TimerIdx,
  1816. PWMChannel,
  1817. &OutputCfg);
  1818. /* Enable the registers preload mechanism */
  1819. hrtim_timcr = hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR;
  1820. hrtim_timcr |= HRTIM_TIMCR_PREEN;
  1821. hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR = hrtim_timcr;
  1822. hhrtim->State = HAL_HRTIM_STATE_READY;
  1823. /* Process Unlocked */
  1824. __HAL_UNLOCK(hhrtim);
  1825. return HAL_OK;
  1826. }
  1827. /**
  1828. * @brief Start the PWM output signal generation on the designed timer output
  1829. * @param hhrtim pointer to HAL HRTIM handle
  1830. * @param TimerIdx Timer index
  1831. * This parameter can be one of the following values:
  1832. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1833. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1834. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1835. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1836. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1837. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  1838. * @param PWMChannel Timer output
  1839. * This parameter can be one of the following values:
  1840. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1841. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1842. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1843. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1844. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1845. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1846. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1847. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1848. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1849. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1850. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  1851. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  1852. * @retval HAL status
  1853. */
  1854. HAL_StatusTypeDef HAL_HRTIM_SimplePWMStart(HRTIM_HandleTypeDef *hhrtim,
  1855. uint32_t TimerIdx,
  1856. uint32_t PWMChannel)
  1857. {
  1858. /* Check the parameters */
  1859. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, PWMChannel));
  1860. /* Process Locked */
  1861. __HAL_LOCK(hhrtim);
  1862. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1863. /* Enable the timer output */
  1864. hhrtim->Instance->sCommonRegs.OENR |= PWMChannel;
  1865. /* Enable the timer counter */
  1866. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1867. hhrtim->State = HAL_HRTIM_STATE_READY;
  1868. /* Process Unlocked */
  1869. __HAL_UNLOCK(hhrtim);
  1870. return HAL_OK;
  1871. }
  1872. /**
  1873. * @brief Stop the PWM output signal generation on the designed timer output
  1874. * @param hhrtim pointer to HAL HRTIM handle
  1875. * @param TimerIdx Timer index
  1876. * This parameter can be one of the following values:
  1877. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1878. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1879. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1880. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1881. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1882. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  1883. * @param PWMChannel Timer output
  1884. * This parameter can be one of the following values:
  1885. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1886. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1887. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1888. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1889. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1890. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1891. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1892. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1893. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1894. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1895. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  1896. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  1897. * @retval HAL status
  1898. */
  1899. HAL_StatusTypeDef HAL_HRTIM_SimplePWMStop(HRTIM_HandleTypeDef *hhrtim,
  1900. uint32_t TimerIdx,
  1901. uint32_t PWMChannel)
  1902. {
  1903. /* Check the parameters */
  1904. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, PWMChannel));
  1905. /* Process Locked */
  1906. __HAL_LOCK(hhrtim);
  1907. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1908. /* Disable the timer output */
  1909. hhrtim->Instance->sCommonRegs.ODISR |= PWMChannel;
  1910. /* Disable the timer counter */
  1911. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1912. hhrtim->State = HAL_HRTIM_STATE_READY;
  1913. /* Process Unlocked */
  1914. __HAL_UNLOCK(hhrtim);
  1915. return HAL_OK;
  1916. }
  1917. /**
  1918. * @brief Start the PWM output signal generation on the designed timer output
  1919. * (The compare interrupt is enabled).
  1920. * @param hhrtim pointer to HAL HRTIM handle
  1921. * @param TimerIdx Timer index
  1922. * This parameter can be one of the following values:
  1923. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1924. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1925. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1926. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1927. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1928. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  1929. * @param PWMChannel Timer output
  1930. * This parameter can be one of the following values:
  1931. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1932. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1933. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1934. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1935. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1936. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1937. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1938. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1939. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1940. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1941. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  1942. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  1943. * @retval HAL status
  1944. */
  1945. HAL_StatusTypeDef HAL_HRTIM_SimplePWMStart_IT(HRTIM_HandleTypeDef *hhrtim,
  1946. uint32_t TimerIdx,
  1947. uint32_t PWMChannel)
  1948. {
  1949. /* Check the parameters */
  1950. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, PWMChannel));
  1951. /* Process Locked */
  1952. __HAL_LOCK(hhrtim);
  1953. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1954. /* Enable the timer output */
  1955. hhrtim->Instance->sCommonRegs.OENR |= PWMChannel;
  1956. /* Enable the timer interrupt (depends on the PWM output) */
  1957. switch (PWMChannel)
  1958. {
  1959. case HRTIM_OUTPUT_TA1:
  1960. case HRTIM_OUTPUT_TB1:
  1961. case HRTIM_OUTPUT_TC1:
  1962. case HRTIM_OUTPUT_TD1:
  1963. case HRTIM_OUTPUT_TE1:
  1964. case HRTIM_OUTPUT_TF1:
  1965. {
  1966. __HAL_HRTIM_TIMER_ENABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP1);
  1967. break;
  1968. }
  1969. case HRTIM_OUTPUT_TA2:
  1970. case HRTIM_OUTPUT_TB2:
  1971. case HRTIM_OUTPUT_TC2:
  1972. case HRTIM_OUTPUT_TD2:
  1973. case HRTIM_OUTPUT_TE2:
  1974. case HRTIM_OUTPUT_TF2:
  1975. {
  1976. __HAL_HRTIM_TIMER_ENABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP2);
  1977. break;
  1978. }
  1979. default:
  1980. {
  1981. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1982. /* Process Unlocked */
  1983. __HAL_UNLOCK(hhrtim);
  1984. break;
  1985. }
  1986. }
  1987. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  1988. {
  1989. return HAL_ERROR;
  1990. }
  1991. /* Enable the timer counter */
  1992. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1993. hhrtim->State = HAL_HRTIM_STATE_READY;
  1994. /* Process Unlocked */
  1995. __HAL_UNLOCK(hhrtim);
  1996. return HAL_OK;
  1997. }
  1998. /**
  1999. * @brief Stop the PWM output signal generation on the designed timer output
  2000. * (The compare interrupt is disabled).
  2001. * @param hhrtim pointer to HAL HRTIM handle
  2002. * @param TimerIdx Timer index
  2003. * This parameter can be one of the following values:
  2004. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2005. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2006. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2007. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2008. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2009. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  2010. * @param PWMChannel Timer output
  2011. * This parameter can be one of the following values:
  2012. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  2013. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  2014. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  2015. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  2016. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  2017. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  2018. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  2019. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  2020. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  2021. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  2022. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  2023. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  2024. * @retval HAL status
  2025. */
  2026. HAL_StatusTypeDef HAL_HRTIM_SimplePWMStop_IT(HRTIM_HandleTypeDef *hhrtim,
  2027. uint32_t TimerIdx,
  2028. uint32_t PWMChannel)
  2029. {
  2030. /* Check the parameters */
  2031. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, PWMChannel));
  2032. /* Process Locked */
  2033. __HAL_LOCK(hhrtim);
  2034. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2035. /* Disable the timer output */
  2036. hhrtim->Instance->sCommonRegs.ODISR |= PWMChannel;
  2037. /* Disable the timer interrupt (depends on the PWM output) */
  2038. switch (PWMChannel)
  2039. {
  2040. case HRTIM_OUTPUT_TA1:
  2041. case HRTIM_OUTPUT_TB1:
  2042. case HRTIM_OUTPUT_TC1:
  2043. case HRTIM_OUTPUT_TD1:
  2044. case HRTIM_OUTPUT_TE1:
  2045. case HRTIM_OUTPUT_TF1:
  2046. {
  2047. __HAL_HRTIM_TIMER_DISABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP1);
  2048. break;
  2049. }
  2050. case HRTIM_OUTPUT_TA2:
  2051. case HRTIM_OUTPUT_TB2:
  2052. case HRTIM_OUTPUT_TC2:
  2053. case HRTIM_OUTPUT_TD2:
  2054. case HRTIM_OUTPUT_TE2:
  2055. case HRTIM_OUTPUT_TF2:
  2056. {
  2057. __HAL_HRTIM_TIMER_DISABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP2);
  2058. break;
  2059. }
  2060. default:
  2061. {
  2062. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2063. /* Process Unlocked */
  2064. __HAL_UNLOCK(hhrtim);
  2065. break;
  2066. }
  2067. }
  2068. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  2069. {
  2070. return HAL_ERROR;
  2071. }
  2072. /* Disable the timer counter */
  2073. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  2074. hhrtim->State = HAL_HRTIM_STATE_READY;
  2075. /* Process Unlocked */
  2076. __HAL_UNLOCK(hhrtim);
  2077. return HAL_OK;
  2078. }
  2079. /**
  2080. * @brief Start the PWM output signal generation on the designed timer output
  2081. * (The compare DMA request is enabled).
  2082. * @param hhrtim pointer to HAL HRTIM handle
  2083. * @param TimerIdx Timer index
  2084. * This parameter can be one of the following values:
  2085. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2086. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2087. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2088. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2089. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2090. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  2091. * @param PWMChannel Timer output
  2092. * This parameter can be one of the following values:
  2093. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  2094. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  2095. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  2096. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  2097. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  2098. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  2099. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  2100. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  2101. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  2102. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  2103. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  2104. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  2105. * @param SrcAddr DMA transfer source address
  2106. * @param DestAddr DMA transfer destination address
  2107. * @param Length The length of data items (data size) to be transferred
  2108. * from source to destination
  2109. * @retval HAL status
  2110. */
  2111. HAL_StatusTypeDef HAL_HRTIM_SimplePWMStart_DMA(HRTIM_HandleTypeDef *hhrtim,
  2112. uint32_t TimerIdx,
  2113. uint32_t PWMChannel,
  2114. uint32_t SrcAddr,
  2115. uint32_t DestAddr,
  2116. uint32_t Length)
  2117. {
  2118. DMA_HandleTypeDef *hdma;
  2119. /* Check the parameters */
  2120. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, PWMChannel));
  2121. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  2122. {
  2123. return HAL_BUSY;
  2124. }
  2125. if (hhrtim->State == HAL_HRTIM_STATE_READY)
  2126. {
  2127. if ((SrcAddr == 0U) || (DestAddr == 0U) || (Length == 0U))
  2128. {
  2129. return HAL_ERROR;
  2130. }
  2131. else
  2132. {
  2133. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2134. }
  2135. }
  2136. /* Process Locked */
  2137. __HAL_LOCK(hhrtim);
  2138. /* Enable the timer output */
  2139. hhrtim->Instance->sCommonRegs.OENR |= PWMChannel;
  2140. /* Get the timer DMA handler */
  2141. hdma = HRTIM_GetDMAHandleFromTimerIdx(hhrtim, TimerIdx);
  2142. if (hdma == NULL)
  2143. {
  2144. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2145. /* Process Unlocked */
  2146. __HAL_UNLOCK(hhrtim);
  2147. return HAL_ERROR;
  2148. }
  2149. /* Set the DMA error callback */
  2150. hdma->XferErrorCallback = HRTIM_DMAError ;
  2151. /* Set the DMA transfer completed callback */
  2152. hdma->XferCpltCallback = HRTIM_DMATimerxCplt;
  2153. /* Enable the DMA channel */
  2154. if (HAL_DMA_Start_IT(hdma, SrcAddr, DestAddr, Length) != HAL_OK)
  2155. {
  2156. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2157. /* Process Unlocked */
  2158. __HAL_UNLOCK(hhrtim);
  2159. return HAL_ERROR;
  2160. }
  2161. /* Enable the timer DMA request */
  2162. switch (PWMChannel)
  2163. {
  2164. case HRTIM_OUTPUT_TA1:
  2165. case HRTIM_OUTPUT_TB1:
  2166. case HRTIM_OUTPUT_TC1:
  2167. case HRTIM_OUTPUT_TD1:
  2168. case HRTIM_OUTPUT_TE1:
  2169. case HRTIM_OUTPUT_TF1:
  2170. {
  2171. __HAL_HRTIM_TIMER_ENABLE_DMA(hhrtim, TimerIdx, HRTIM_TIM_DMA_CMP1);
  2172. break;
  2173. }
  2174. case HRTIM_OUTPUT_TA2:
  2175. case HRTIM_OUTPUT_TB2:
  2176. case HRTIM_OUTPUT_TC2:
  2177. case HRTIM_OUTPUT_TD2:
  2178. case HRTIM_OUTPUT_TE2:
  2179. case HRTIM_OUTPUT_TF2:
  2180. {
  2181. __HAL_HRTIM_TIMER_ENABLE_DMA(hhrtim, TimerIdx, HRTIM_TIM_DMA_CMP2);
  2182. break;
  2183. }
  2184. default:
  2185. {
  2186. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2187. /* Process Unlocked */
  2188. __HAL_UNLOCK(hhrtim);
  2189. break;
  2190. }
  2191. }
  2192. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  2193. {
  2194. return HAL_ERROR;
  2195. }
  2196. /* Enable the timer counter */
  2197. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  2198. hhrtim->State = HAL_HRTIM_STATE_READY;
  2199. /* Process Unlocked */
  2200. __HAL_UNLOCK(hhrtim);
  2201. return HAL_OK;
  2202. }
  2203. /**
  2204. * @brief Stop the PWM output signal generation on the designed timer output
  2205. * (The compare DMA request is disabled).
  2206. * @param hhrtim pointer to HAL HRTIM handle
  2207. * @param TimerIdx Timer index
  2208. * This parameter can be one of the following values:
  2209. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2210. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2211. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2212. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2213. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2214. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  2215. * @param PWMChannel Timer output
  2216. * This parameter can be one of the following values:
  2217. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  2218. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  2219. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  2220. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  2221. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  2222. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  2223. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  2224. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  2225. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  2226. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  2227. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  2228. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  2229. * @retval HAL status
  2230. */
  2231. HAL_StatusTypeDef HAL_HRTIM_SimplePWMStop_DMA(HRTIM_HandleTypeDef *hhrtim,
  2232. uint32_t TimerIdx,
  2233. uint32_t PWMChannel)
  2234. {
  2235. /* Check the parameters */
  2236. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, PWMChannel));
  2237. /* Process Locked */
  2238. __HAL_LOCK(hhrtim);
  2239. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2240. /* Disable the timer output */
  2241. hhrtim->Instance->sCommonRegs.ODISR |= PWMChannel;
  2242. /* Get the timer DMA handler */
  2243. /* Disable the DMA */
  2244. if (HAL_DMA_Abort(HRTIM_GetDMAHandleFromTimerIdx(hhrtim, TimerIdx)) != HAL_OK)
  2245. {
  2246. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2247. /* Process Unlocked */
  2248. __HAL_UNLOCK(hhrtim);
  2249. return HAL_ERROR;
  2250. }
  2251. /* Disable the timer DMA request */
  2252. switch (PWMChannel)
  2253. {
  2254. case HRTIM_OUTPUT_TA1:
  2255. case HRTIM_OUTPUT_TB1:
  2256. case HRTIM_OUTPUT_TC1:
  2257. case HRTIM_OUTPUT_TD1:
  2258. case HRTIM_OUTPUT_TE1:
  2259. case HRTIM_OUTPUT_TF1:
  2260. {
  2261. __HAL_HRTIM_TIMER_DISABLE_DMA(hhrtim, TimerIdx, HRTIM_TIM_DMA_CMP1);
  2262. break;
  2263. }
  2264. case HRTIM_OUTPUT_TA2:
  2265. case HRTIM_OUTPUT_TB2:
  2266. case HRTIM_OUTPUT_TC2:
  2267. case HRTIM_OUTPUT_TD2:
  2268. case HRTIM_OUTPUT_TE2:
  2269. case HRTIM_OUTPUT_TF2:
  2270. {
  2271. __HAL_HRTIM_TIMER_DISABLE_DMA(hhrtim, TimerIdx, HRTIM_TIM_DMA_CMP2);
  2272. break;
  2273. }
  2274. default:
  2275. {
  2276. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2277. /* Process Unlocked */
  2278. __HAL_UNLOCK(hhrtim);
  2279. break;
  2280. }
  2281. }
  2282. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  2283. {
  2284. return HAL_ERROR;
  2285. }
  2286. /* Disable the timer counter */
  2287. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  2288. hhrtim->State = HAL_HRTIM_STATE_READY;
  2289. /* Process Unlocked */
  2290. __HAL_UNLOCK(hhrtim);
  2291. return HAL_OK;
  2292. }
  2293. /**
  2294. * @}
  2295. */
  2296. /** @defgroup HRTIM_Exported_Functions_Group5 Simple input capture functions
  2297. * @brief Simple input capture functions
  2298. @verbatim
  2299. ===============================================================================
  2300. ##### Simple input capture functions #####
  2301. ===============================================================================
  2302. [..] This section provides functions allowing to:
  2303. (+) Configure simple input capture channel
  2304. (+) Start simple input capture
  2305. (+) Stop simple input capture
  2306. (+) Start simple input capture and enable interrupt
  2307. (+) Stop simple input capture and disable interrupt
  2308. (+) Start simple input capture and enable DMA transfer
  2309. (+) Stop simple input capture and disable DMA transfer
  2310. -@- When a HRTIM timer operates in simple input capture mode
  2311. the Capture Register (HRTIM_CPT1/2xR) is used to latch the
  2312. value of the timer counter counter after a transition detected
  2313. on a given external event input.
  2314. @endverbatim
  2315. * @{
  2316. */
  2317. /**
  2318. * @brief Configure a simple capture
  2319. * @param hhrtim pointer to HAL HRTIM handle
  2320. * @param TimerIdx Timer index
  2321. * This parameter can be one of the following values:
  2322. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2323. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2324. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2325. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2326. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2327. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  2328. * @param CaptureChannel Capture unit
  2329. * This parameter can be one of the following values:
  2330. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  2331. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  2332. * @param pSimpleCaptureChannelCfg pointer to the simple capture configuration structure
  2333. * @note When the timer operates in simple capture mode the capture is triggered
  2334. * by the designated external event and GPIO input is implicitly used as event source.
  2335. * The cature can be triggered by a rising edge, a falling edge or both
  2336. * edges on event channel.
  2337. * @retval HAL status
  2338. */
  2339. HAL_StatusTypeDef HAL_HRTIM_SimpleCaptureChannelConfig(HRTIM_HandleTypeDef *hhrtim,
  2340. uint32_t TimerIdx,
  2341. uint32_t CaptureChannel,
  2342. const HRTIM_SimpleCaptureChannelCfgTypeDef *pSimpleCaptureChannelCfg)
  2343. {
  2344. HRTIM_EventCfgTypeDef EventCfg;
  2345. /* Check parameters */
  2346. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  2347. assert_param(IS_HRTIM_CAPTUREUNIT(CaptureChannel));
  2348. assert_param(IS_HRTIM_EVENT(pSimpleCaptureChannelCfg->Event));
  2349. assert_param(IS_HRTIM_EVENTPOLARITY(pSimpleCaptureChannelCfg->EventSensitivity,
  2350. pSimpleCaptureChannelCfg->EventPolarity));
  2351. assert_param(IS_HRTIM_EVENTSENSITIVITY(pSimpleCaptureChannelCfg->EventSensitivity));
  2352. assert_param(IS_HRTIM_EVENTFILTER(pSimpleCaptureChannelCfg->Event,
  2353. pSimpleCaptureChannelCfg->EventFilter));
  2354. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  2355. {
  2356. return HAL_BUSY;
  2357. }
  2358. /* Process Locked */
  2359. __HAL_LOCK(hhrtim);
  2360. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2361. /* Configure external event channel */
  2362. EventCfg.FastMode = HRTIM_EVENTFASTMODE_DISABLE;
  2363. EventCfg.Filter = (pSimpleCaptureChannelCfg->EventFilter & HRTIM_EECR3_EE6F);
  2364. EventCfg.Polarity = (pSimpleCaptureChannelCfg->EventPolarity & HRTIM_EECR1_EE1POL);
  2365. EventCfg.Sensitivity = (pSimpleCaptureChannelCfg->EventSensitivity & HRTIM_EECR1_EE1SNS);
  2366. EventCfg.Source = HRTIM_EEV1SRC_GPIO; /* source 1 for External Event */
  2367. HRTIM_EventConfig(hhrtim,
  2368. pSimpleCaptureChannelCfg->Event,
  2369. &EventCfg);
  2370. /* Memorize capture trigger (will be configured when the capture is started */
  2371. HRTIM_CaptureUnitConfig(hhrtim,
  2372. TimerIdx,
  2373. CaptureChannel,
  2374. pSimpleCaptureChannelCfg->Event);
  2375. hhrtim->State = HAL_HRTIM_STATE_READY;
  2376. /* Process Unlocked */
  2377. __HAL_UNLOCK(hhrtim);
  2378. return HAL_OK;
  2379. }
  2380. /**
  2381. * @brief Enable a simple capture on the designed capture unit
  2382. * @param hhrtim pointer to HAL HRTIM handle
  2383. * @param TimerIdx Timer index
  2384. * This parameter can be one of the following values:
  2385. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2386. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2387. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2388. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2389. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2390. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  2391. * @param CaptureChannel Timer output
  2392. * This parameter can be one of the following values:
  2393. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  2394. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  2395. * @retval HAL status
  2396. * @note The external event triggering the capture is available for all timing
  2397. * units. It can be used directly and is active as soon as the timing
  2398. * unit counter is enabled.
  2399. */
  2400. HAL_StatusTypeDef HAL_HRTIM_SimpleCaptureStart(HRTIM_HandleTypeDef *hhrtim,
  2401. uint32_t TimerIdx,
  2402. uint32_t CaptureChannel)
  2403. {
  2404. /* Check the parameters */
  2405. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  2406. assert_param(IS_HRTIM_CAPTUREUNIT(CaptureChannel));
  2407. /* Process Locked */
  2408. __HAL_LOCK(hhrtim);
  2409. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2410. /* Set the capture unit trigger */
  2411. switch (CaptureChannel)
  2412. {
  2413. case HRTIM_CAPTUREUNIT_1:
  2414. {
  2415. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR = hhrtim->TimerParam[TimerIdx].CaptureTrigger1;
  2416. break;
  2417. }
  2418. case HRTIM_CAPTUREUNIT_2:
  2419. {
  2420. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR = hhrtim->TimerParam[TimerIdx].CaptureTrigger2;
  2421. break;
  2422. }
  2423. default:
  2424. {
  2425. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2426. /* Process Unlocked */
  2427. __HAL_UNLOCK(hhrtim);
  2428. break;
  2429. }
  2430. }
  2431. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  2432. {
  2433. return HAL_ERROR;
  2434. }
  2435. /* Enable the timer counter */
  2436. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  2437. hhrtim->State = HAL_HRTIM_STATE_READY;
  2438. /* Process Unlocked */
  2439. __HAL_UNLOCK(hhrtim);
  2440. return HAL_OK;
  2441. }
  2442. /**
  2443. * @brief Disable a simple capture on the designed capture unit
  2444. * @param hhrtim pointer to HAL HRTIM handle
  2445. * @param TimerIdx Timer index
  2446. * This parameter can be one of the following values:
  2447. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2448. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2449. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2450. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2451. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2452. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  2453. * @param CaptureChannel Timer output
  2454. * This parameter can be one of the following values:
  2455. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  2456. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  2457. * @retval HAL status
  2458. */
  2459. HAL_StatusTypeDef HAL_HRTIM_SimpleCaptureStop(HRTIM_HandleTypeDef *hhrtim,
  2460. uint32_t TimerIdx,
  2461. uint32_t CaptureChannel)
  2462. {
  2463. uint32_t hrtim_cpt1cr;
  2464. uint32_t hrtim_cpt2cr;
  2465. /* Check the parameters */
  2466. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  2467. assert_param(IS_HRTIM_CAPTUREUNIT(CaptureChannel));
  2468. /* Process Locked */
  2469. __HAL_LOCK(hhrtim);
  2470. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2471. /* Set the capture unit trigger */
  2472. switch (CaptureChannel)
  2473. {
  2474. case HRTIM_CAPTUREUNIT_1:
  2475. {
  2476. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR = HRTIM_CAPTURETRIGGER_NONE;
  2477. break;
  2478. }
  2479. case HRTIM_CAPTUREUNIT_2:
  2480. {
  2481. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR = HRTIM_CAPTURETRIGGER_NONE;
  2482. break;
  2483. }
  2484. default:
  2485. {
  2486. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2487. /* Process Unlocked */
  2488. __HAL_UNLOCK(hhrtim);
  2489. break;
  2490. }
  2491. }
  2492. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  2493. {
  2494. return HAL_ERROR;
  2495. }
  2496. hrtim_cpt1cr = hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR;
  2497. hrtim_cpt2cr = hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR;
  2498. /* Disable the timer counter */
  2499. if ((hrtim_cpt1cr == HRTIM_CAPTURETRIGGER_NONE) &&
  2500. (hrtim_cpt2cr == HRTIM_CAPTURETRIGGER_NONE))
  2501. {
  2502. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  2503. }
  2504. hhrtim->State = HAL_HRTIM_STATE_READY;
  2505. /* Process Unlocked */
  2506. __HAL_UNLOCK(hhrtim);
  2507. return HAL_OK;
  2508. }
  2509. /**
  2510. * @brief Enable a simple capture on the designed capture unit
  2511. * (Capture interrupt is enabled).
  2512. * @param hhrtim pointer to HAL HRTIM handle
  2513. * @param TimerIdx Timer index
  2514. * This parameter can be one of the following values:
  2515. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2516. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2517. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2518. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2519. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2520. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  2521. * @param CaptureChannel Timer output
  2522. * This parameter can be one of the following values:
  2523. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  2524. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  2525. * @retval HAL status
  2526. */
  2527. HAL_StatusTypeDef HAL_HRTIM_SimpleCaptureStart_IT(HRTIM_HandleTypeDef *hhrtim,
  2528. uint32_t TimerIdx,
  2529. uint32_t CaptureChannel)
  2530. {
  2531. /* Check the parameters */
  2532. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  2533. assert_param(IS_HRTIM_CAPTUREUNIT(CaptureChannel));
  2534. /* Process Locked */
  2535. __HAL_LOCK(hhrtim);
  2536. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2537. /* Set the capture unit trigger */
  2538. switch (CaptureChannel)
  2539. {
  2540. case HRTIM_CAPTUREUNIT_1:
  2541. {
  2542. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR = hhrtim->TimerParam[TimerIdx].CaptureTrigger1;
  2543. /* Enable the capture unit 1 interrupt */
  2544. __HAL_HRTIM_TIMER_ENABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CPT1);
  2545. break;
  2546. }
  2547. case HRTIM_CAPTUREUNIT_2:
  2548. {
  2549. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR = hhrtim->TimerParam[TimerIdx].CaptureTrigger2;
  2550. /* Enable the capture unit 2 interrupt */
  2551. __HAL_HRTIM_TIMER_ENABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CPT2);
  2552. break;
  2553. }
  2554. default:
  2555. {
  2556. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2557. /* Process Unlocked */
  2558. __HAL_UNLOCK(hhrtim);
  2559. break;
  2560. }
  2561. }
  2562. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  2563. {
  2564. return HAL_ERROR;
  2565. }
  2566. /* Enable the timer counter */
  2567. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  2568. hhrtim->State = HAL_HRTIM_STATE_READY;
  2569. /* Process Unlocked */
  2570. __HAL_UNLOCK(hhrtim);
  2571. return HAL_OK;
  2572. }
  2573. /**
  2574. * @brief Disable a simple capture on the designed capture unit
  2575. * (Capture interrupt is disabled).
  2576. * @param hhrtim pointer to HAL HRTIM handle
  2577. * @param TimerIdx Timer index
  2578. * This parameter can be one of the following values:
  2579. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2580. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2581. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2582. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2583. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2584. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  2585. * @param CaptureChannel Timer output
  2586. * This parameter can be one of the following values:
  2587. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  2588. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  2589. * @retval HAL status
  2590. */
  2591. HAL_StatusTypeDef HAL_HRTIM_SimpleCaptureStop_IT(HRTIM_HandleTypeDef *hhrtim,
  2592. uint32_t TimerIdx,
  2593. uint32_t CaptureChannel)
  2594. {
  2595. uint32_t hrtim_cpt1cr;
  2596. uint32_t hrtim_cpt2cr;
  2597. /* Check the parameters */
  2598. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  2599. assert_param(IS_HRTIM_CAPTUREUNIT(CaptureChannel));
  2600. /* Process Locked */
  2601. __HAL_LOCK(hhrtim);
  2602. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2603. /* Set the capture unit trigger */
  2604. switch (CaptureChannel)
  2605. {
  2606. case HRTIM_CAPTUREUNIT_1:
  2607. {
  2608. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR = HRTIM_CAPTURETRIGGER_NONE;
  2609. /* Disable the capture unit 1 interrupt */
  2610. __HAL_HRTIM_TIMER_DISABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CPT1);
  2611. break;
  2612. }
  2613. case HRTIM_CAPTUREUNIT_2:
  2614. {
  2615. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR = HRTIM_CAPTURETRIGGER_NONE;
  2616. /* Disable the capture unit 2 interrupt */
  2617. __HAL_HRTIM_TIMER_DISABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CPT2);
  2618. break;
  2619. }
  2620. default:
  2621. {
  2622. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2623. /* Process Unlocked */
  2624. __HAL_UNLOCK(hhrtim);
  2625. break;
  2626. }
  2627. }
  2628. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  2629. {
  2630. return HAL_ERROR;
  2631. }
  2632. hrtim_cpt1cr = hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR;
  2633. hrtim_cpt2cr = hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR;
  2634. /* Disable the timer counter */
  2635. if ((hrtim_cpt1cr == HRTIM_CAPTURETRIGGER_NONE) &&
  2636. (hrtim_cpt2cr == HRTIM_CAPTURETRIGGER_NONE))
  2637. {
  2638. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  2639. }
  2640. hhrtim->State = HAL_HRTIM_STATE_READY;
  2641. /* Process Unlocked */
  2642. __HAL_UNLOCK(hhrtim);
  2643. return HAL_OK;
  2644. }
  2645. /**
  2646. * @brief Enable a simple capture on the designed capture unit
  2647. * (Capture DMA request is enabled).
  2648. * @param hhrtim pointer to HAL HRTIM handle
  2649. * @param TimerIdx Timer index
  2650. * This parameter can be one of the following values:
  2651. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2652. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2653. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2654. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2655. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2656. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  2657. * @param CaptureChannel Timer output
  2658. * This parameter can be one of the following values:
  2659. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  2660. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  2661. * @param SrcAddr DMA transfer source address
  2662. * @param DestAddr DMA transfer destination address
  2663. * @param Length The length of data items (data size) to be transferred
  2664. * from source to destination
  2665. * @retval HAL status
  2666. */
  2667. HAL_StatusTypeDef HAL_HRTIM_SimpleCaptureStart_DMA(HRTIM_HandleTypeDef *hhrtim,
  2668. uint32_t TimerIdx,
  2669. uint32_t CaptureChannel,
  2670. uint32_t SrcAddr,
  2671. uint32_t DestAddr,
  2672. uint32_t Length)
  2673. {
  2674. DMA_HandleTypeDef *hdma;
  2675. /* Check the parameters */
  2676. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  2677. assert_param(IS_HRTIM_CAPTUREUNIT(CaptureChannel));
  2678. /* Process Locked */
  2679. __HAL_LOCK(hhrtim);
  2680. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2681. /* Get the timer DMA handler */
  2682. hdma = HRTIM_GetDMAHandleFromTimerIdx(hhrtim, TimerIdx);
  2683. if (hdma == NULL)
  2684. {
  2685. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2686. /* Process Unlocked */
  2687. __HAL_UNLOCK(hhrtim);
  2688. return HAL_ERROR;
  2689. }
  2690. /* Set the DMA error callback */
  2691. hdma->XferErrorCallback = HRTIM_DMAError ;
  2692. /* Set the DMA transfer completed callback */
  2693. hdma->XferCpltCallback = HRTIM_DMATimerxCplt;
  2694. /* Enable the DMA channel */
  2695. if (HAL_DMA_Start_IT(hdma, SrcAddr, DestAddr, Length) != HAL_OK)
  2696. {
  2697. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2698. /* Process Unlocked */
  2699. __HAL_UNLOCK(hhrtim);
  2700. return HAL_ERROR;
  2701. }
  2702. switch (CaptureChannel)
  2703. {
  2704. case HRTIM_CAPTUREUNIT_1:
  2705. {
  2706. /* Set the capture unit trigger */
  2707. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR = hhrtim->TimerParam[TimerIdx].CaptureTrigger1;
  2708. __HAL_HRTIM_TIMER_ENABLE_DMA(hhrtim, TimerIdx, HRTIM_TIM_DMA_CPT1);
  2709. break;
  2710. }
  2711. case HRTIM_CAPTUREUNIT_2:
  2712. {
  2713. /* Set the capture unit trigger */
  2714. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR = hhrtim->TimerParam[TimerIdx].CaptureTrigger2;
  2715. /* Enable the timer DMA request */
  2716. __HAL_HRTIM_TIMER_ENABLE_DMA(hhrtim, TimerIdx, HRTIM_TIM_DMA_CPT2);
  2717. break;
  2718. }
  2719. default:
  2720. {
  2721. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2722. /* Process Unlocked */
  2723. __HAL_UNLOCK(hhrtim);
  2724. break;
  2725. }
  2726. }
  2727. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  2728. {
  2729. return HAL_ERROR;
  2730. }
  2731. /* Enable the timer counter */
  2732. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  2733. hhrtim->State = HAL_HRTIM_STATE_READY;
  2734. /* Process Unlocked */
  2735. __HAL_UNLOCK(hhrtim);
  2736. return HAL_OK;
  2737. }
  2738. /**
  2739. * @brief Disable a simple capture on the designed capture unit
  2740. * (Capture DMA request is disabled).
  2741. * @param hhrtim pointer to HAL HRTIM handle
  2742. * @param TimerIdx Timer index
  2743. * This parameter can be one of the following values:
  2744. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2745. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2746. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2747. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2748. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2749. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  2750. * @param CaptureChannel Timer output
  2751. * This parameter can be one of the following values:
  2752. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  2753. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  2754. * @retval HAL status
  2755. */
  2756. HAL_StatusTypeDef HAL_HRTIM_SimpleCaptureStop_DMA(HRTIM_HandleTypeDef *hhrtim,
  2757. uint32_t TimerIdx,
  2758. uint32_t CaptureChannel)
  2759. {
  2760. uint32_t hrtim_cpt1cr;
  2761. uint32_t hrtim_cpt2cr;
  2762. /* Check the parameters */
  2763. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  2764. assert_param(IS_HRTIM_CAPTUREUNIT(CaptureChannel));
  2765. /* Process Locked */
  2766. __HAL_LOCK(hhrtim);
  2767. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2768. /* Get the timer DMA handler */
  2769. /* Disable the DMA */
  2770. if (HAL_DMA_Abort(HRTIM_GetDMAHandleFromTimerIdx(hhrtim, TimerIdx)) != HAL_OK)
  2771. {
  2772. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2773. /* Process Unlocked */
  2774. __HAL_UNLOCK(hhrtim);
  2775. return HAL_ERROR;
  2776. }
  2777. switch (CaptureChannel)
  2778. {
  2779. case HRTIM_CAPTUREUNIT_1:
  2780. {
  2781. /* Reset the capture unit trigger */
  2782. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR = HRTIM_CAPTURETRIGGER_NONE;
  2783. /* Disable the capture unit 1 DMA request */
  2784. __HAL_HRTIM_TIMER_DISABLE_DMA(hhrtim, TimerIdx, HRTIM_TIM_DMA_CPT1);
  2785. break;
  2786. }
  2787. case HRTIM_CAPTUREUNIT_2:
  2788. {
  2789. /* Reset the capture unit trigger */
  2790. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR = HRTIM_CAPTURETRIGGER_NONE;
  2791. /* Disable the capture unit 2 DMA request */
  2792. __HAL_HRTIM_TIMER_DISABLE_DMA(hhrtim, TimerIdx, HRTIM_TIM_DMA_CPT2);
  2793. break;
  2794. }
  2795. default:
  2796. {
  2797. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2798. /* Process Unlocked */
  2799. __HAL_UNLOCK(hhrtim);
  2800. break;
  2801. }
  2802. }
  2803. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  2804. {
  2805. return HAL_ERROR;
  2806. }
  2807. hrtim_cpt1cr = hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR;
  2808. hrtim_cpt2cr = hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR;
  2809. /* Disable the timer counter */
  2810. if ((hrtim_cpt1cr == HRTIM_CAPTURETRIGGER_NONE) &&
  2811. (hrtim_cpt2cr == HRTIM_CAPTURETRIGGER_NONE))
  2812. {
  2813. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  2814. }
  2815. hhrtim->State = HAL_HRTIM_STATE_READY;
  2816. /* Process Unlocked */
  2817. __HAL_UNLOCK(hhrtim);
  2818. return HAL_OK;
  2819. }
  2820. /**
  2821. * @}
  2822. */
  2823. /** @defgroup HRTIM_Exported_Functions_Group6 Simple one pulse functions
  2824. * @brief Simple one pulse functions
  2825. @verbatim
  2826. ===============================================================================
  2827. ##### Simple one pulse functions #####
  2828. ===============================================================================
  2829. [..] This section provides functions allowing to:
  2830. (+) Configure one pulse channel
  2831. (+) Start one pulse generation
  2832. (+) Stop one pulse generation
  2833. (+) Start one pulse generation and enable interrupt
  2834. (+) Stop one pulse generation and disable interrupt
  2835. -@- When a HRTIM timer operates in simple one pulse mode
  2836. the timer counter is started in response to transition detected
  2837. on a given external event input to generate a pulse with a
  2838. programmable length after a programmable delay.
  2839. @endverbatim
  2840. * @{
  2841. */
  2842. /**
  2843. * @brief Configure an output simple one pulse mode
  2844. * @param hhrtim pointer to HAL HRTIM handle
  2845. * @param TimerIdx Timer index
  2846. * This parameter can be one of the following values:
  2847. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2848. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2849. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2850. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2851. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2852. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  2853. * @param OnePulseChannel Timer output
  2854. * This parameter can be one of the following values:
  2855. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  2856. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  2857. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  2858. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  2859. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  2860. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  2861. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  2862. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  2863. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  2864. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  2865. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  2866. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  2867. * @param pSimpleOnePulseChannelCfg pointer to the simple one pulse output configuration structure
  2868. * @note When the timer operates in simple one pulse mode:
  2869. * the timer counter is implicitly started by the reset event,
  2870. * the reset of the timer counter is triggered by the designated external event
  2871. * GPIO input is implicitly used as event source,
  2872. * Output 1 is implicitly controlled by the compare unit 1,
  2873. * Output 2 is implicitly controlled by the compare unit 2.
  2874. * Output Set/Reset crossbar is set as follows:
  2875. * Output 1: SETx1R = CMP1, RSTx1R = PER
  2876. * Output 2: SETx2R = CMP2, RST2R = PER
  2877. * @retval HAL status
  2878. * @note If HAL_HRTIM_SimpleOnePulseChannelConfig is called for both timer
  2879. * outputs, the reset event related configuration data provided in the
  2880. * second call will override the reset event related configuration data
  2881. * provided in the first call.
  2882. */
  2883. HAL_StatusTypeDef HAL_HRTIM_SimpleOnePulseChannelConfig(HRTIM_HandleTypeDef *hhrtim,
  2884. uint32_t TimerIdx,
  2885. uint32_t OnePulseChannel,
  2886. const HRTIM_SimpleOnePulseChannelCfgTypeDef *pSimpleOnePulseChannelCfg)
  2887. {
  2888. HRTIM_OutputCfgTypeDef OutputCfg;
  2889. HRTIM_EventCfgTypeDef EventCfg;
  2890. /* Check parameters */
  2891. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OnePulseChannel));
  2892. assert_param(IS_HRTIM_OUTPUTPULSE(pSimpleOnePulseChannelCfg->Pulse));
  2893. assert_param(IS_HRTIM_OUTPUTPOLARITY(pSimpleOnePulseChannelCfg->OutputPolarity));
  2894. assert_param(IS_HRTIM_OUTPUTIDLELEVEL(pSimpleOnePulseChannelCfg->OutputIdleLevel));
  2895. assert_param(IS_HRTIM_EVENT(pSimpleOnePulseChannelCfg->Event));
  2896. assert_param(IS_HRTIM_EVENTPOLARITY(pSimpleOnePulseChannelCfg->EventSensitivity,
  2897. pSimpleOnePulseChannelCfg->EventPolarity));
  2898. assert_param(IS_HRTIM_EVENTSENSITIVITY(pSimpleOnePulseChannelCfg->EventSensitivity));
  2899. assert_param(IS_HRTIM_EVENTFILTER(pSimpleOnePulseChannelCfg->Event,
  2900. pSimpleOnePulseChannelCfg->EventFilter));
  2901. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  2902. {
  2903. return HAL_BUSY;
  2904. }
  2905. /* Process Locked */
  2906. __HAL_LOCK(hhrtim);
  2907. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2908. /* Configure timer compare unit */
  2909. switch (OnePulseChannel)
  2910. {
  2911. case HRTIM_OUTPUT_TA1:
  2912. case HRTIM_OUTPUT_TB1:
  2913. case HRTIM_OUTPUT_TC1:
  2914. case HRTIM_OUTPUT_TD1:
  2915. case HRTIM_OUTPUT_TE1:
  2916. case HRTIM_OUTPUT_TF1:
  2917. {
  2918. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP1xR = pSimpleOnePulseChannelCfg->Pulse;
  2919. OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP1;
  2920. break;
  2921. }
  2922. case HRTIM_OUTPUT_TA2:
  2923. case HRTIM_OUTPUT_TB2:
  2924. case HRTIM_OUTPUT_TC2:
  2925. case HRTIM_OUTPUT_TD2:
  2926. case HRTIM_OUTPUT_TE2:
  2927. case HRTIM_OUTPUT_TF2:
  2928. {
  2929. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP2xR = pSimpleOnePulseChannelCfg->Pulse;
  2930. OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP2;
  2931. break;
  2932. }
  2933. default:
  2934. {
  2935. OutputCfg.SetSource = HRTIM_OUTPUTSET_NONE;
  2936. OutputCfg.ResetSource = HRTIM_OUTPUTRESET_NONE;
  2937. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2938. /* Process Unlocked */
  2939. __HAL_UNLOCK(hhrtim);
  2940. break;
  2941. }
  2942. }
  2943. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  2944. {
  2945. return HAL_ERROR;
  2946. }
  2947. /* Configure timer output */
  2948. OutputCfg.Polarity = (pSimpleOnePulseChannelCfg->OutputPolarity & HRTIM_OUTR_POL1);
  2949. OutputCfg.IdleLevel = (pSimpleOnePulseChannelCfg->OutputIdleLevel & HRTIM_OUTR_IDLES1);
  2950. OutputCfg.FaultLevel = HRTIM_OUTPUTFAULTLEVEL_NONE;
  2951. OutputCfg.IdleMode = HRTIM_OUTPUTIDLEMODE_NONE;
  2952. OutputCfg.ChopperModeEnable = HRTIM_OUTPUTCHOPPERMODE_DISABLED;
  2953. OutputCfg.BurstModeEntryDelayed = HRTIM_OUTPUTBURSTMODEENTRY_REGULAR;
  2954. OutputCfg.ResetSource = HRTIM_OUTPUTRESET_TIMPER;
  2955. HRTIM_OutputConfig(hhrtim,
  2956. TimerIdx,
  2957. OnePulseChannel,
  2958. &OutputCfg);
  2959. /* Configure external event channel */
  2960. EventCfg.FastMode = HRTIM_EVENTFASTMODE_DISABLE;
  2961. EventCfg.Filter = (pSimpleOnePulseChannelCfg->EventFilter & HRTIM_EECR3_EE6F);
  2962. EventCfg.Polarity = (pSimpleOnePulseChannelCfg->EventPolarity & HRTIM_OUTR_POL1);
  2963. EventCfg.Sensitivity = (pSimpleOnePulseChannelCfg->EventSensitivity & HRTIM_EECR1_EE1SNS);
  2964. EventCfg.Source = HRTIM_EEV1SRC_GPIO; /* source 1 for External Event */
  2965. HRTIM_EventConfig(hhrtim,
  2966. pSimpleOnePulseChannelCfg->Event,
  2967. &EventCfg);
  2968. /* Configure the timer reset register */
  2969. HRTIM_TIM_ResetConfig(hhrtim,
  2970. TimerIdx,
  2971. pSimpleOnePulseChannelCfg->Event);
  2972. hhrtim->State = HAL_HRTIM_STATE_READY;
  2973. /* Process Unlocked */
  2974. __HAL_UNLOCK(hhrtim);
  2975. return HAL_OK;
  2976. }
  2977. /**
  2978. * @brief Enable the simple one pulse signal generation on the designed output
  2979. * @param hhrtim pointer to HAL HRTIM handle
  2980. * @param TimerIdx Timer index
  2981. * This parameter can be one of the following values:
  2982. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2983. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2984. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2985. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2986. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2987. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  2988. * @param OnePulseChannel Timer output
  2989. * This parameter can be one of the following values:
  2990. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  2991. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  2992. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  2993. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  2994. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  2995. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  2996. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  2997. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  2998. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  2999. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  3000. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  3001. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  3002. * @retval HAL status
  3003. */
  3004. HAL_StatusTypeDef HAL_HRTIM_SimpleOnePulseStart(HRTIM_HandleTypeDef *hhrtim,
  3005. uint32_t TimerIdx,
  3006. uint32_t OnePulseChannel)
  3007. {
  3008. /* Check the parameters */
  3009. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OnePulseChannel));
  3010. /* Process Locked */
  3011. __HAL_LOCK(hhrtim);
  3012. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3013. /* Enable the timer output */
  3014. hhrtim->Instance->sCommonRegs.OENR |= OnePulseChannel;
  3015. /* Enable the timer counter */
  3016. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  3017. hhrtim->State = HAL_HRTIM_STATE_READY;
  3018. /* Process Unlocked */
  3019. __HAL_UNLOCK(hhrtim);
  3020. return HAL_OK;
  3021. }
  3022. /**
  3023. * @brief Disable the simple one pulse signal generation on the designed output
  3024. * @param hhrtim pointer to HAL HRTIM handle
  3025. * @param TimerIdx Timer index
  3026. * This parameter can be one of the following values:
  3027. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  3028. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  3029. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  3030. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  3031. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  3032. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  3033. * @param OnePulseChannel Timer output
  3034. * This parameter can be one of the following values:
  3035. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  3036. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  3037. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  3038. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  3039. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  3040. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  3041. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  3042. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  3043. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  3044. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  3045. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  3046. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  3047. * @retval HAL status
  3048. */
  3049. HAL_StatusTypeDef HAL_HRTIM_SimpleOnePulseStop(HRTIM_HandleTypeDef *hhrtim,
  3050. uint32_t TimerIdx,
  3051. uint32_t OnePulseChannel)
  3052. {
  3053. /* Check the parameters */
  3054. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OnePulseChannel));
  3055. /* Process Locked */
  3056. __HAL_LOCK(hhrtim);
  3057. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3058. /* Disable the timer output */
  3059. hhrtim->Instance->sCommonRegs.ODISR |= OnePulseChannel;
  3060. /* Disable the timer counter */
  3061. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  3062. hhrtim->State = HAL_HRTIM_STATE_READY;
  3063. /* Process Unlocked */
  3064. __HAL_UNLOCK(hhrtim);
  3065. return HAL_OK;
  3066. }
  3067. /**
  3068. * @brief Enable the simple one pulse signal generation on the designed output
  3069. * (The compare interrupt is enabled (pulse start)).
  3070. * @param hhrtim pointer to HAL HRTIM handle
  3071. * @param TimerIdx Timer index
  3072. * This parameter can be one of the following values:
  3073. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  3074. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  3075. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  3076. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  3077. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  3078. * @arg HRTIM_TIMERINDEX_TIMER_F for timer E
  3079. * @param OnePulseChannel Timer output
  3080. * This parameter can be one of the following values:
  3081. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  3082. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  3083. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  3084. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  3085. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  3086. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  3087. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  3088. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  3089. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  3090. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  3091. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  3092. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  3093. * @retval HAL status
  3094. */
  3095. HAL_StatusTypeDef HAL_HRTIM_SimpleOnePulseStart_IT(HRTIM_HandleTypeDef *hhrtim,
  3096. uint32_t TimerIdx,
  3097. uint32_t OnePulseChannel)
  3098. {
  3099. /* Check the parameters */
  3100. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OnePulseChannel));
  3101. /* Process Locked */
  3102. __HAL_LOCK(hhrtim);
  3103. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3104. /* Enable the timer output */
  3105. hhrtim->Instance->sCommonRegs.OENR |= OnePulseChannel;
  3106. /* Enable the timer interrupt (depends on the OnePulse output) */
  3107. switch (OnePulseChannel)
  3108. {
  3109. case HRTIM_OUTPUT_TA1:
  3110. case HRTIM_OUTPUT_TB1:
  3111. case HRTIM_OUTPUT_TC1:
  3112. case HRTIM_OUTPUT_TD1:
  3113. case HRTIM_OUTPUT_TE1:
  3114. case HRTIM_OUTPUT_TF1:
  3115. {
  3116. __HAL_HRTIM_TIMER_ENABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP1);
  3117. break;
  3118. }
  3119. case HRTIM_OUTPUT_TA2:
  3120. case HRTIM_OUTPUT_TB2:
  3121. case HRTIM_OUTPUT_TC2:
  3122. case HRTIM_OUTPUT_TD2:
  3123. case HRTIM_OUTPUT_TE2:
  3124. case HRTIM_OUTPUT_TF2:
  3125. {
  3126. __HAL_HRTIM_TIMER_ENABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP2);
  3127. break;
  3128. }
  3129. default:
  3130. {
  3131. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  3132. /* Process Unlocked */
  3133. __HAL_UNLOCK(hhrtim);
  3134. break;
  3135. }
  3136. }
  3137. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  3138. {
  3139. return HAL_ERROR;
  3140. }
  3141. /* Enable the timer counter */
  3142. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  3143. hhrtim->State = HAL_HRTIM_STATE_READY;
  3144. /* Process Unlocked */
  3145. __HAL_UNLOCK(hhrtim);
  3146. return HAL_OK;
  3147. }
  3148. /**
  3149. * @brief Disable the simple one pulse signal generation on the designed output
  3150. * (The compare interrupt is disabled).
  3151. * @param hhrtim pointer to HAL HRTIM handle
  3152. * @param TimerIdx Timer index
  3153. * This parameter can be one of the following values:
  3154. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  3155. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  3156. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  3157. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  3158. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  3159. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  3160. * @param OnePulseChannel Timer output
  3161. * This parameter can be one of the following values:
  3162. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  3163. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  3164. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  3165. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  3166. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  3167. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  3168. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  3169. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  3170. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  3171. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  3172. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  3173. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  3174. * @retval HAL status
  3175. */
  3176. HAL_StatusTypeDef HAL_HRTIM_SimpleOnePulseStop_IT(HRTIM_HandleTypeDef *hhrtim,
  3177. uint32_t TimerIdx,
  3178. uint32_t OnePulseChannel)
  3179. {
  3180. /* Check the parameters */
  3181. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OnePulseChannel));
  3182. /* Process Locked */
  3183. __HAL_LOCK(hhrtim);
  3184. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3185. /* Disable the timer output */
  3186. hhrtim->Instance->sCommonRegs.ODISR |= OnePulseChannel;
  3187. /* Disable the timer interrupt (depends on the OnePulse output) */
  3188. switch (OnePulseChannel)
  3189. {
  3190. case HRTIM_OUTPUT_TA1:
  3191. case HRTIM_OUTPUT_TB1:
  3192. case HRTIM_OUTPUT_TC1:
  3193. case HRTIM_OUTPUT_TD1:
  3194. case HRTIM_OUTPUT_TE1:
  3195. case HRTIM_OUTPUT_TF1:
  3196. {
  3197. __HAL_HRTIM_TIMER_DISABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP1);
  3198. break;
  3199. }
  3200. case HRTIM_OUTPUT_TA2:
  3201. case HRTIM_OUTPUT_TB2:
  3202. case HRTIM_OUTPUT_TC2:
  3203. case HRTIM_OUTPUT_TD2:
  3204. case HRTIM_OUTPUT_TE2:
  3205. case HRTIM_OUTPUT_TF2:
  3206. {
  3207. __HAL_HRTIM_TIMER_DISABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP2);
  3208. break;
  3209. }
  3210. default:
  3211. {
  3212. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  3213. /* Process Unlocked */
  3214. __HAL_UNLOCK(hhrtim);
  3215. break;
  3216. }
  3217. }
  3218. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  3219. {
  3220. return HAL_ERROR;
  3221. }
  3222. /* Disable the timer counter */
  3223. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  3224. hhrtim->State = HAL_HRTIM_STATE_READY;
  3225. /* Process Unlocked */
  3226. __HAL_UNLOCK(hhrtim);
  3227. return HAL_OK;
  3228. }
  3229. /**
  3230. * @}
  3231. */
  3232. /** @defgroup HRTIM_Exported_Functions_Group7 Configuration functions
  3233. * @brief HRTIM configuration functions
  3234. @verbatim
  3235. ===============================================================================
  3236. ##### HRTIM configuration functions #####
  3237. ===============================================================================
  3238. [..] This section provides functions allowing to configure the HRTIM
  3239. resources shared by all the HRTIM timers operating in waveform mode:
  3240. (+) Configure the burst mode controller
  3241. (+) Configure an external event conditioning
  3242. (+) Configure the external events sampling clock
  3243. (+) Configure a fault conditioning
  3244. (+) Enable or disable fault inputs
  3245. (+) Configure the faults sampling clock
  3246. (+) Configure an ADC trigger
  3247. @endverbatim
  3248. * @{
  3249. */
  3250. /**
  3251. * @brief Configure the burst mode feature of the HRTIM
  3252. * @param hhrtim pointer to HAL HRTIM handle
  3253. * @param pBurstModeCfg pointer to the burst mode configuration structure
  3254. * @retval HAL status
  3255. * @note This function must be called before starting the burst mode
  3256. * controller
  3257. */
  3258. HAL_StatusTypeDef HAL_HRTIM_BurstModeConfig(HRTIM_HandleTypeDef *hhrtim,
  3259. const HRTIM_BurstModeCfgTypeDef *pBurstModeCfg)
  3260. {
  3261. uint32_t hrtim_bmcr;
  3262. /* Check parameters */
  3263. assert_param(IS_HRTIM_BURSTMODE(pBurstModeCfg->Mode));
  3264. assert_param(IS_HRTIM_BURSTMODECLOCKSOURCE(pBurstModeCfg->ClockSource));
  3265. assert_param(IS_HRTIM_HRTIM_BURSTMODEPRESCALER(pBurstModeCfg->Prescaler));
  3266. assert_param(IS_HRTIM_BURSTMODEPRELOAD(pBurstModeCfg->PreloadEnable));
  3267. assert_param(IS_HRTIM_BURSTMODETRIGGER(pBurstModeCfg->Trigger));
  3268. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  3269. {
  3270. return HAL_BUSY;
  3271. }
  3272. /* Process Locked */
  3273. __HAL_LOCK(hhrtim);
  3274. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3275. hrtim_bmcr = hhrtim->Instance->sCommonRegs.BMCR;
  3276. /* Set the burst mode operating mode */
  3277. hrtim_bmcr &= ~(HRTIM_BMCR_BMOM);
  3278. hrtim_bmcr |= (pBurstModeCfg->Mode & HRTIM_BMCR_BMOM);
  3279. /* Set the burst mode clock source */
  3280. hrtim_bmcr &= ~(HRTIM_BMCR_BMCLK);
  3281. hrtim_bmcr |= (pBurstModeCfg->ClockSource & HRTIM_BMCR_BMCLK);
  3282. /* Set the burst mode prescaler */
  3283. hrtim_bmcr &= ~(HRTIM_BMCR_BMPRSC);
  3284. hrtim_bmcr |= pBurstModeCfg->Prescaler;
  3285. /* Enable/disable burst mode registers preload */
  3286. hrtim_bmcr &= ~(HRTIM_BMCR_BMPREN);
  3287. hrtim_bmcr |= (pBurstModeCfg->PreloadEnable & HRTIM_BMCR_BMPREN);
  3288. /* Set the burst mode trigger */
  3289. hhrtim->Instance->sCommonRegs.BMTRGR = pBurstModeCfg->Trigger;
  3290. /* Set the burst mode compare value */
  3291. hhrtim->Instance->sCommonRegs.BMCMPR = pBurstModeCfg->IdleDuration;
  3292. /* Set the burst mode period */
  3293. hhrtim->Instance->sCommonRegs.BMPER = pBurstModeCfg->Period;
  3294. /* Update the HRTIM registers */
  3295. hhrtim->Instance->sCommonRegs.BMCR = hrtim_bmcr;
  3296. hhrtim->State = HAL_HRTIM_STATE_READY;
  3297. /* Process Unlocked */
  3298. __HAL_UNLOCK(hhrtim);
  3299. return HAL_OK;
  3300. }
  3301. /**
  3302. * @brief Configure the conditioning of an external event
  3303. * @param hhrtim pointer to HAL HRTIM handle
  3304. * @param Event external event to configure
  3305. * This parameter can be one of the following values:
  3306. * @arg HRTIM_EVENT_NONE: no external Event
  3307. * @arg HRTIM_EVENT_1: External event 1
  3308. * @arg HRTIM_EVENT_2: External event 2
  3309. * @arg HRTIM_EVENT_3: External event 3
  3310. * @arg HRTIM_EVENT_4: External event 4
  3311. * @arg HRTIM_EVENT_5: External event 5
  3312. * @arg HRTIM_EVENT_6: External event 6
  3313. * @arg HRTIM_EVENT_7: External event 7
  3314. * @arg HRTIM_EVENT_8: External event 8
  3315. * @arg HRTIM_EVENT_9: External event 9
  3316. * @arg HRTIM_EVENT_10: External event 10
  3317. * @param pEventCfg pointer to the event conditioning configuration structure
  3318. * @note This function must be called before starting the timer
  3319. * @retval HAL status
  3320. */
  3321. HAL_StatusTypeDef HAL_HRTIM_EventConfig(HRTIM_HandleTypeDef *hhrtim,
  3322. uint32_t Event,
  3323. const HRTIM_EventCfgTypeDef *pEventCfg)
  3324. {
  3325. /* Check parameters */
  3326. assert_param(IS_HRTIM_EVENT(Event));
  3327. assert_param(IS_HRTIM_EVENTSRC(Event, pEventCfg->Source));
  3328. assert_param(IS_HRTIM_EVENTPOLARITY(pEventCfg->Sensitivity, pEventCfg->Polarity));
  3329. assert_param(IS_HRTIM_EVENTSENSITIVITY(pEventCfg->Sensitivity));
  3330. assert_param(IS_HRTIM_EVENTFASTMODE(Event, pEventCfg->FastMode));
  3331. assert_param(IS_HRTIM_EVENTFILTER(Event, pEventCfg->Filter));
  3332. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  3333. {
  3334. return HAL_BUSY;
  3335. }
  3336. /* Process Locked */
  3337. __HAL_LOCK(hhrtim);
  3338. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3339. /* Configure the event channel */
  3340. HRTIM_EventConfig(hhrtim, Event, pEventCfg);
  3341. hhrtim->State = HAL_HRTIM_STATE_READY;
  3342. /* Process Unlocked */
  3343. __HAL_UNLOCK(hhrtim);
  3344. return HAL_OK;
  3345. }
  3346. /**
  3347. * @brief Configure the external event conditioning block prescaler
  3348. * @param hhrtim pointer to HAL HRTIM handle
  3349. * @param Prescaler Prescaler value
  3350. * This parameter can be one of the following values:
  3351. * @arg HRTIM_EVENTPRESCALER_DIV1: fEEVS=fHRTIM
  3352. * @arg HRTIM_EVENTPRESCALER_DIV2: fEEVS=fHRTIM / 2
  3353. * @arg HRTIM_EVENTPRESCALER_DIV4: fEEVS=fHRTIM / 4
  3354. * @arg HRTIM_EVENTPRESCALER_DIV8: fEEVS=fHRTIM / 8
  3355. * @note This function must be called before starting the timer
  3356. * @retval HAL status
  3357. */
  3358. HAL_StatusTypeDef HAL_HRTIM_EventPrescalerConfig(HRTIM_HandleTypeDef *hhrtim,
  3359. uint32_t Prescaler)
  3360. {
  3361. /* Check parameters */
  3362. assert_param(IS_HRTIM_EVENTPRESCALER(Prescaler));
  3363. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  3364. {
  3365. return HAL_BUSY;
  3366. }
  3367. /* Process Locked */
  3368. __HAL_LOCK(hhrtim);
  3369. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3370. /* Set the external event prescaler */
  3371. MODIFY_REG(hhrtim->Instance->sCommonRegs.EECR3, HRTIM_EECR3_EEVSD, (Prescaler & HRTIM_EECR3_EEVSD));
  3372. hhrtim->State = HAL_HRTIM_STATE_READY;
  3373. /* Process Unlocked */
  3374. __HAL_UNLOCK(hhrtim);
  3375. return HAL_OK;
  3376. }
  3377. /**
  3378. * @brief Configure the conditioning of fault input
  3379. * @param hhrtim pointer to HAL HRTIM handle
  3380. * @param Fault fault input to configure
  3381. * This parameter can be one of the following values:
  3382. * @arg HRTIM_FAULT_1: Fault input 1
  3383. * @arg HRTIM_FAULT_2: Fault input 2
  3384. * @arg HRTIM_FAULT_3: Fault input 3
  3385. * @arg HRTIM_FAULT_4: Fault input 4
  3386. * @arg HRTIM_FAULT_5: Fault input 5
  3387. * @arg HRTIM_FAULT_6: Fault input 6
  3388. * @param pFaultCfg pointer to the fault conditioning configuration structure
  3389. * @note This function must be called before starting the timer and before
  3390. * enabling faults inputs
  3391. * @retval HAL status
  3392. */
  3393. HAL_StatusTypeDef HAL_HRTIM_FaultConfig(HRTIM_HandleTypeDef *hhrtim,
  3394. uint32_t Fault,
  3395. const HRTIM_FaultCfgTypeDef *pFaultCfg)
  3396. {
  3397. uint32_t hrtim_fltinr1;
  3398. uint32_t hrtim_fltinr2;
  3399. uint32_t source0, source1;
  3400. /* Check parameters */
  3401. assert_param(IS_HRTIM_FAULT(Fault));
  3402. assert_param(IS_HRTIM_FAULTSOURCE(pFaultCfg->Source));
  3403. assert_param(IS_HRTIM_FAULTPOLARITY(pFaultCfg->Polarity));
  3404. assert_param(IS_HRTIM_FAULTFILTER(pFaultCfg->Filter));
  3405. assert_param(IS_HRTIM_FAULTLOCK(pFaultCfg->Lock));
  3406. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  3407. {
  3408. return HAL_BUSY;
  3409. }
  3410. /* Process Locked */
  3411. __HAL_LOCK(hhrtim);
  3412. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3413. /* Configure fault channel */
  3414. hrtim_fltinr1 = hhrtim->Instance->sCommonRegs.FLTINR1;
  3415. hrtim_fltinr2 = hhrtim->Instance->sCommonRegs.FLTINR2;
  3416. source0 = (pFaultCfg->Source & 1U);
  3417. source1 = ((pFaultCfg->Source & 2U) >> 1);
  3418. switch (Fault)
  3419. {
  3420. case HRTIM_FAULT_1:
  3421. {
  3422. hrtim_fltinr1 &= ~(HRTIM_FLTINR1_FLT1P | HRTIM_FLTINR1_FLT1SRC_0 | HRTIM_FLTINR1_FLT1F | HRTIM_FLTINR1_FLT1LCK);
  3423. hrtim_fltinr1 |= (pFaultCfg->Polarity & HRTIM_FLTINR1_FLT1P);
  3424. hrtim_fltinr1 |= (source0 << HRTIM_FLTINR1_FLT1SRC_0_Pos);
  3425. hrtim_fltinr2 &= ~(HRTIM_FLTINR2_FLT1SRC_1);
  3426. hrtim_fltinr2 |= (source1 << HRTIM_FLTINR2_FLT1SRC_1_Pos);
  3427. hrtim_fltinr1 |= (pFaultCfg->Filter & HRTIM_FLTINR1_FLT1F);
  3428. hrtim_fltinr1 |= (pFaultCfg->Lock & HRTIM_FLTINR1_FLT1LCK);
  3429. break;
  3430. }
  3431. case HRTIM_FAULT_2:
  3432. {
  3433. hrtim_fltinr1 &= ~(HRTIM_FLTINR1_FLT2P | HRTIM_FLTINR1_FLT2SRC_0 | HRTIM_FLTINR1_FLT2F | HRTIM_FLTINR1_FLT2LCK);
  3434. hrtim_fltinr1 |= ((pFaultCfg->Polarity << 8U) & HRTIM_FLTINR1_FLT2P);
  3435. hrtim_fltinr1 |= (source0 << HRTIM_FLTINR1_FLT2SRC_0_Pos);
  3436. hrtim_fltinr2 &= ~(HRTIM_FLTINR2_FLT2SRC_1);
  3437. hrtim_fltinr2 |= (source1 << HRTIM_FLTINR2_FLT2SRC_1_Pos);
  3438. hrtim_fltinr1 |= ((pFaultCfg->Filter << 8U) & HRTIM_FLTINR1_FLT2F);
  3439. hrtim_fltinr1 |= ((pFaultCfg->Lock << 8U) & HRTIM_FLTINR1_FLT2LCK);
  3440. break;
  3441. }
  3442. case HRTIM_FAULT_3:
  3443. {
  3444. hrtim_fltinr1 &= ~(HRTIM_FLTINR1_FLT3P | HRTIM_FLTINR1_FLT3SRC_0 | HRTIM_FLTINR1_FLT3F | HRTIM_FLTINR1_FLT3LCK);
  3445. hrtim_fltinr1 |= ((pFaultCfg->Polarity << 16U) & HRTIM_FLTINR1_FLT3P);
  3446. hrtim_fltinr1 |= (source0 << HRTIM_FLTINR1_FLT3SRC_0_Pos);
  3447. hrtim_fltinr2 &= ~(HRTIM_FLTINR2_FLT3SRC_1);
  3448. hrtim_fltinr2 |= (source1 << HRTIM_FLTINR2_FLT3SRC_1_Pos);
  3449. hrtim_fltinr1 |= ((pFaultCfg->Filter << 16U) & HRTIM_FLTINR1_FLT3F);
  3450. hrtim_fltinr1 |= ((pFaultCfg->Lock << 16U) & HRTIM_FLTINR1_FLT3LCK);
  3451. break;
  3452. }
  3453. case HRTIM_FAULT_4:
  3454. {
  3455. hrtim_fltinr1 &= ~(HRTIM_FLTINR1_FLT4P | HRTIM_FLTINR1_FLT4SRC_0 | HRTIM_FLTINR1_FLT4F | HRTIM_FLTINR1_FLT4LCK);
  3456. hrtim_fltinr1 |= ((pFaultCfg->Polarity << 24U) & HRTIM_FLTINR1_FLT4P);
  3457. hrtim_fltinr1 |= (source0 << HRTIM_FLTINR1_FLT4SRC_0_Pos);
  3458. hrtim_fltinr2 &= ~(HRTIM_FLTINR2_FLT4SRC_1);
  3459. hrtim_fltinr2 |= (source1 << HRTIM_FLTINR2_FLT4SRC_1_Pos);
  3460. hrtim_fltinr1 |= ((pFaultCfg->Filter << 24U) & HRTIM_FLTINR1_FLT4F);
  3461. hrtim_fltinr1 |= ((pFaultCfg->Lock << 24U) & HRTIM_FLTINR1_FLT4LCK);
  3462. break;
  3463. }
  3464. case HRTIM_FAULT_5:
  3465. {
  3466. hrtim_fltinr2 &= ~(HRTIM_FLTINR2_FLT5P | HRTIM_FLTINR2_FLT5SRC_0 | HRTIM_FLTINR2_FLT5F | HRTIM_FLTINR2_FLT5LCK);
  3467. hrtim_fltinr2 |= (pFaultCfg->Polarity & HRTIM_FLTINR2_FLT5P);
  3468. hrtim_fltinr2 |= (source0 << HRTIM_FLTINR2_FLT5SRC_0_Pos);
  3469. hrtim_fltinr2 &= ~(HRTIM_FLTINR2_FLT5SRC_1);
  3470. hrtim_fltinr2 |= (source1 << HRTIM_FLTINR2_FLT5SRC_1_Pos);
  3471. hrtim_fltinr2 |= (pFaultCfg->Filter & HRTIM_FLTINR2_FLT5F);
  3472. hrtim_fltinr2 |= (pFaultCfg->Lock & HRTIM_FLTINR2_FLT5LCK);
  3473. break;
  3474. }
  3475. case HRTIM_FAULT_6:
  3476. {
  3477. hrtim_fltinr2 &= ~(HRTIM_FLTINR2_FLT6P | HRTIM_FLTINR2_FLT6SRC_0 | HRTIM_FLTINR2_FLT6F | HRTIM_FLTINR2_FLT6LCK);
  3478. hrtim_fltinr2 |= ((pFaultCfg->Polarity << 8U) & HRTIM_FLTINR2_FLT6P);
  3479. hrtim_fltinr2 |= (source0 << HRTIM_FLTINR2_FLT6SRC_0_Pos);
  3480. hrtim_fltinr2 &= ~(HRTIM_FLTINR2_FLT6SRC_1);
  3481. hrtim_fltinr2 |= (source1 << HRTIM_FLTINR2_FLT6SRC_1_Pos);
  3482. hrtim_fltinr2 |= ((pFaultCfg->Filter << 8U) & HRTIM_FLTINR2_FLT6F);
  3483. hrtim_fltinr2 |= ((pFaultCfg->Lock << 8U) & HRTIM_FLTINR2_FLT6LCK);
  3484. break;
  3485. }
  3486. default:
  3487. {
  3488. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  3489. /* Process Unlocked */
  3490. __HAL_UNLOCK(hhrtim);
  3491. break;
  3492. }
  3493. }
  3494. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  3495. {
  3496. return HAL_ERROR;
  3497. }
  3498. /* Update the HRTIM registers except LOCK bit */
  3499. hhrtim->Instance->sCommonRegs.FLTINR1 = (hrtim_fltinr1 & (~(HRTIM_FLTINR1_FLTxLCK)));
  3500. hhrtim->Instance->sCommonRegs.FLTINR2 = (hrtim_fltinr2 & (~(HRTIM_FLTINR2_FLTxLCK)));
  3501. /* Update the HRTIM registers LOCK bit */
  3502. SET_BIT(hhrtim->Instance->sCommonRegs.FLTINR1, (hrtim_fltinr1 & HRTIM_FLTINR1_FLTxLCK));
  3503. SET_BIT(hhrtim->Instance->sCommonRegs.FLTINR2, (hrtim_fltinr2 & HRTIM_FLTINR2_FLTxLCK));
  3504. hhrtim->State = HAL_HRTIM_STATE_READY;
  3505. /* Process Unlocked */
  3506. __HAL_UNLOCK(hhrtim);
  3507. return HAL_OK;
  3508. }
  3509. /**
  3510. * @brief Configure the fault conditioning block prescaler
  3511. * @param hhrtim pointer to HAL HRTIM handle
  3512. * @param Prescaler Prescaler value
  3513. * This parameter can be one of the following values:
  3514. * @arg HRTIM_FAULTPRESCALER_DIV1: fFLTS=fHRTIM
  3515. * @arg HRTIM_FAULTPRESCALER_DIV2: fFLTS=fHRTIM / 2
  3516. * @arg HRTIM_FAULTPRESCALER_DIV4: fFLTS=fHRTIM / 4
  3517. * @arg HRTIM_FAULTPRESCALER_DIV8: fFLTS=fHRTIM / 8
  3518. * @retval HAL status
  3519. * @note This function must be called before starting the timer and before
  3520. * enabling faults inputs
  3521. */
  3522. HAL_StatusTypeDef HAL_HRTIM_FaultPrescalerConfig(HRTIM_HandleTypeDef *hhrtim,
  3523. uint32_t Prescaler)
  3524. {
  3525. /* Check parameters */
  3526. assert_param(IS_HRTIM_FAULTPRESCALER(Prescaler));
  3527. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  3528. {
  3529. return HAL_BUSY;
  3530. }
  3531. /* Process Locked */
  3532. __HAL_LOCK(hhrtim);
  3533. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3534. /* Set the external event prescaler */
  3535. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR2, HRTIM_FLTINR2_FLTSD, (Prescaler & HRTIM_FLTINR2_FLTSD));
  3536. hhrtim->State = HAL_HRTIM_STATE_READY;
  3537. /* Process Unlocked */
  3538. __HAL_UNLOCK(hhrtim);
  3539. return HAL_OK;
  3540. }
  3541. /**
  3542. * @brief Configure and Enable the blanking source of a Fault input
  3543. * @param hhrtim pointer to HAL HRTIM handle
  3544. * @param Fault fault input to configure
  3545. * This parameter can be one of the following values:
  3546. * @arg HRTIM_FAULT_1: Fault input 1
  3547. * @arg HRTIM_FAULT_2: Fault input 2
  3548. * @arg HRTIM_FAULT_3: Fault input 3
  3549. * @arg HRTIM_FAULT_4: Fault input 4
  3550. * @arg HRTIM_FAULT_5: Fault input 5
  3551. * @arg HRTIM_FAULT_6: Fault input 6
  3552. * @param pFaultBlkCfg: pointer to the fault conditioning configuration structure
  3553. * @note This function automatically enables the Blanking on Fault
  3554. * @note This function must be called when fault is not enabled
  3555. * @retval HAL status
  3556. */
  3557. HAL_StatusTypeDef HAL_HRTIM_FaultBlankingConfigAndEnable(HRTIM_HandleTypeDef *hhrtim,
  3558. uint32_t Fault,
  3559. const HRTIM_FaultBlankingCfgTypeDef *pFaultBlkCfg)
  3560. {
  3561. /* Check parameters */
  3562. assert_param(IS_HRTIM_FAULT(Fault));
  3563. assert_param(IS_HRTIM_FAULTBLANKNGMODE(pFaultBlkCfg->BlankingSource));
  3564. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  3565. {
  3566. return HAL_BUSY;
  3567. }
  3568. /* Process Locked */
  3569. __HAL_LOCK(hhrtim);
  3570. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3571. switch (Fault)
  3572. {
  3573. case HRTIM_FAULT_1:
  3574. {
  3575. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR3,
  3576. (HRTIM_FLTINR3_FLT1BLKS | HRTIM_FLTINR3_FLT1BLKE),
  3577. ((pFaultBlkCfg->BlankingSource << HRTIM_FLTINR3_FLT1BLKS_Pos) |
  3578. HRTIM_FLTINR3_FLT1BLKE));
  3579. break;
  3580. }
  3581. case HRTIM_FAULT_2:
  3582. {
  3583. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR3,
  3584. (HRTIM_FLTINR3_FLT2BLKS | HRTIM_FLTINR3_FLT2BLKE),
  3585. ((pFaultBlkCfg->BlankingSource << HRTIM_FLTINR3_FLT2BLKS_Pos) |
  3586. HRTIM_FLTINR3_FLT2BLKE));
  3587. break;
  3588. }
  3589. case HRTIM_FAULT_3:
  3590. {
  3591. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR3,
  3592. (HRTIM_FLTINR3_FLT3BLKS | HRTIM_FLTINR3_FLT3BLKE),
  3593. ((pFaultBlkCfg->BlankingSource << HRTIM_FLTINR3_FLT3BLKS_Pos) |
  3594. HRTIM_FLTINR3_FLT3BLKE));
  3595. break;
  3596. }
  3597. case HRTIM_FAULT_4:
  3598. {
  3599. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR3,
  3600. (HRTIM_FLTINR3_FLT4BLKS | HRTIM_FLTINR3_FLT4BLKE),
  3601. ((pFaultBlkCfg->BlankingSource << HRTIM_FLTINR3_FLT4BLKS_Pos) |
  3602. HRTIM_FLTINR3_FLT4BLKE));
  3603. break;
  3604. }
  3605. case HRTIM_FAULT_5:
  3606. {
  3607. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR4,
  3608. (HRTIM_FLTINR4_FLT5BLKS | HRTIM_FLTINR4_FLT5BLKE),
  3609. ((pFaultBlkCfg->BlankingSource << HRTIM_FLTINR4_FLT5BLKS_Pos) |
  3610. HRTIM_FLTINR4_FLT5BLKE));
  3611. break;
  3612. }
  3613. case HRTIM_FAULT_6:
  3614. {
  3615. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR4,
  3616. (HRTIM_FLTINR4_FLT6BLKS | HRTIM_FLTINR4_FLT6BLKE),
  3617. ((pFaultBlkCfg->BlankingSource << HRTIM_FLTINR4_FLT6BLKS_Pos) |
  3618. HRTIM_FLTINR4_FLT6BLKE));
  3619. break;
  3620. }
  3621. default:
  3622. {
  3623. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  3624. /* Process Unlocked */
  3625. __HAL_UNLOCK(hhrtim);
  3626. break;
  3627. }
  3628. }
  3629. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  3630. {
  3631. return HAL_ERROR;
  3632. }
  3633. hhrtim->State = HAL_HRTIM_STATE_READY;
  3634. /* Process Unlocked */
  3635. __HAL_UNLOCK(hhrtim);
  3636. return HAL_OK;
  3637. }
  3638. /**
  3639. * @brief Configure the Fault Counter (Threshold and Reset Mode)
  3640. * @param hhrtim pointer to HAL HRTIM handle
  3641. * @param Fault fault input to configure
  3642. * This parameter can be one of the following values:
  3643. * @arg HRTIM_FAULT_1: Fault input 1
  3644. * @arg HRTIM_FAULT_2: Fault input 2
  3645. * @arg HRTIM_FAULT_3: Fault input 3
  3646. * @arg HRTIM_FAULT_4: Fault input 4
  3647. * @arg HRTIM_FAULT_5: Fault input 5
  3648. * @arg HRTIM_FAULT_6: Fault input 6
  3649. * @param pFaultBlkCfg: pointer to the fault conditioning configuration structure
  3650. * @retval HAL status
  3651. * @note A fault is considered valid when the number of
  3652. * events is equal to the (FLTxCNT[3:0]+1) value
  3653. *
  3654. * @retval HAL status
  3655. */
  3656. HAL_StatusTypeDef HAL_HRTIM_FaultCounterConfig(HRTIM_HandleTypeDef *hhrtim,
  3657. uint32_t Fault,
  3658. const HRTIM_FaultBlankingCfgTypeDef *pFaultBlkCfg)
  3659. {
  3660. /* Check parameters */
  3661. assert_param(IS_HRTIM_FAULT(Fault));
  3662. assert_param(IS_HRTIM_FAULTCOUNTER(pFaultBlkCfg->Threshold));
  3663. assert_param(IS_HRTIM_FAULTCOUNTERRST(pFaultBlkCfg->ResetMode));
  3664. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  3665. {
  3666. return HAL_BUSY;
  3667. }
  3668. /* Process Locked */
  3669. __HAL_LOCK(hhrtim);
  3670. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3671. switch (Fault)
  3672. {
  3673. case HRTIM_FAULT_1:
  3674. {
  3675. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR3,
  3676. (HRTIM_FLTINR3_FLT1RSTM | HRTIM_FLTINR3_FLT1CNT),
  3677. (pFaultBlkCfg->Threshold << HRTIM_FLTINR3_FLT1CNT_Pos) |
  3678. (pFaultBlkCfg->ResetMode << HRTIM_FLTINR3_FLT1RSTM_Pos));
  3679. break;
  3680. }
  3681. case HRTIM_FAULT_2:
  3682. {
  3683. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR3,
  3684. (HRTIM_FLTINR3_FLT2RSTM | HRTIM_FLTINR3_FLT2CNT),
  3685. (pFaultBlkCfg->Threshold << HRTIM_FLTINR3_FLT2CNT_Pos) |
  3686. (pFaultBlkCfg->ResetMode << HRTIM_FLTINR3_FLT2RSTM_Pos));
  3687. break;
  3688. }
  3689. case HRTIM_FAULT_3:
  3690. {
  3691. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR3,
  3692. (HRTIM_FLTINR3_FLT3RSTM | HRTIM_FLTINR3_FLT3CNT),
  3693. (pFaultBlkCfg->Threshold << HRTIM_FLTINR3_FLT3CNT_Pos) |
  3694. (pFaultBlkCfg->ResetMode << HRTIM_FLTINR3_FLT3RSTM_Pos));
  3695. break;
  3696. }
  3697. case HRTIM_FAULT_4:
  3698. {
  3699. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR3,
  3700. (HRTIM_FLTINR3_FLT4RSTM | HRTIM_FLTINR3_FLT4CNT),
  3701. (pFaultBlkCfg->Threshold << HRTIM_FLTINR3_FLT4CNT_Pos) |
  3702. (pFaultBlkCfg->ResetMode << HRTIM_FLTINR3_FLT4RSTM_Pos));
  3703. break;
  3704. }
  3705. case HRTIM_FAULT_5:
  3706. {
  3707. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR4,
  3708. (HRTIM_FLTINR4_FLT5RSTM | HRTIM_FLTINR4_FLT5CNT),
  3709. (pFaultBlkCfg->Threshold << HRTIM_FLTINR4_FLT5CNT_Pos) |
  3710. (pFaultBlkCfg->ResetMode << HRTIM_FLTINR4_FLT5RSTM_Pos));
  3711. break;
  3712. }
  3713. case HRTIM_FAULT_6:
  3714. {
  3715. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR4,
  3716. (HRTIM_FLTINR4_FLT6RSTM | HRTIM_FLTINR4_FLT6CNT),
  3717. (pFaultBlkCfg->Threshold << HRTIM_FLTINR4_FLT6CNT_Pos) |
  3718. (pFaultBlkCfg->ResetMode << HRTIM_FLTINR4_FLT6RSTM_Pos));
  3719. break;
  3720. }
  3721. default:
  3722. {
  3723. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  3724. /* Process Unlocked */
  3725. __HAL_UNLOCK(hhrtim);
  3726. break;
  3727. }
  3728. }
  3729. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  3730. {
  3731. return HAL_ERROR;
  3732. }
  3733. hhrtim->State = HAL_HRTIM_STATE_READY;
  3734. /* Process Unlocked */
  3735. __HAL_UNLOCK(hhrtim);
  3736. return HAL_OK;
  3737. }
  3738. /**
  3739. * @brief Reset the fault Counter Reset
  3740. * @param hhrtim pointer to HAL HRTIM handle
  3741. * @param Fault fault input to reset
  3742. * This parameter can be one of the following values:
  3743. * @arg HRTIM_FAULT_1: Fault input 1
  3744. * @arg HRTIM_FAULT_2: Fault input 2
  3745. * @arg HRTIM_FAULT_3: Fault input 3
  3746. * @arg HRTIM_FAULT_4: Fault input 4
  3747. * @arg HRTIM_FAULT_5: Fault input 5
  3748. * @arg HRTIM_FAULT_6: Fault input 6
  3749. * @retval HAL status
  3750. */
  3751. HAL_StatusTypeDef HAL_HRTIM_FaultCounterReset(HRTIM_HandleTypeDef *hhrtim,
  3752. uint32_t Fault)
  3753. {
  3754. /* Check parameters */
  3755. assert_param(IS_HRTIM_FAULT(Fault));
  3756. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  3757. {
  3758. return HAL_BUSY;
  3759. }
  3760. /* Process Locked */
  3761. __HAL_LOCK(hhrtim);
  3762. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3763. switch (Fault)
  3764. {
  3765. case HRTIM_FAULT_1:
  3766. {
  3767. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR3, HRTIM_FLTINR3_FLT1CRES, HRTIM_FLTINR3_FLT1CRES) ;
  3768. break;
  3769. }
  3770. case HRTIM_FAULT_2:
  3771. {
  3772. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR3, HRTIM_FLTINR3_FLT2CRES, HRTIM_FLTINR3_FLT2CRES) ;
  3773. break;
  3774. }
  3775. case HRTIM_FAULT_3:
  3776. {
  3777. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR3, HRTIM_FLTINR3_FLT3CRES, HRTIM_FLTINR3_FLT3CRES) ;
  3778. break;
  3779. }
  3780. case HRTIM_FAULT_4:
  3781. {
  3782. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR3, HRTIM_FLTINR3_FLT4CRES, HRTIM_FLTINR3_FLT4CRES) ;
  3783. break;
  3784. }
  3785. case HRTIM_FAULT_5:
  3786. {
  3787. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR4, HRTIM_FLTINR4_FLT5CRES, HRTIM_FLTINR4_FLT5CRES) ;
  3788. break;
  3789. }
  3790. case HRTIM_FAULT_6:
  3791. {
  3792. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR4, HRTIM_FLTINR4_FLT6CRES, HRTIM_FLTINR4_FLT6CRES) ;
  3793. break;
  3794. }
  3795. default:
  3796. {
  3797. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  3798. /* Process Unlocked */
  3799. __HAL_UNLOCK(hhrtim);
  3800. break;
  3801. }
  3802. }
  3803. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  3804. {
  3805. return HAL_ERROR;
  3806. }
  3807. hhrtim->State = HAL_HRTIM_STATE_READY;
  3808. /* Process Unlocked */
  3809. __HAL_UNLOCK(hhrtim);
  3810. return HAL_OK;
  3811. }
  3812. /**
  3813. * @brief Enable or disables the HRTIMx Fault mode.
  3814. * @param hhrtim pointer to HAL HRTIM handle
  3815. * @param Faults fault input(s) to enable or disable
  3816. * This parameter can be any combination of the following values:
  3817. * @arg HRTIM_FAULT_1: Fault input 1
  3818. * @arg HRTIM_FAULT_2: Fault input 2
  3819. * @arg HRTIM_FAULT_3: Fault input 3
  3820. * @arg HRTIM_FAULT_4: Fault input 4
  3821. * @arg HRTIM_FAULT_5: Fault input 5
  3822. * @arg HRTIM_FAULT_6: Fault input 6
  3823. * @param Enable Fault(s) enabling
  3824. * This parameter can be one of the following values:
  3825. * @arg HRTIM_FAULTMODECTL_ENABLED: Fault(s) enabled
  3826. * @arg HRTIM_FAULTMODECTL_DISABLED: Fault(s) disabled
  3827. * @retval None
  3828. */
  3829. void HAL_HRTIM_FaultModeCtl(HRTIM_HandleTypeDef *hhrtim,
  3830. uint32_t Faults,
  3831. uint32_t Enable)
  3832. {
  3833. /* Check parameters */
  3834. assert_param(IS_HRTIM_FAULT(Faults));
  3835. assert_param(IS_HRTIM_FAULTMODECTL(Enable));
  3836. if ((Faults & HRTIM_FAULT_1) != (uint32_t)RESET)
  3837. {
  3838. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR1, HRTIM_FLTINR1_FLT1E, (Enable & HRTIM_FLTINR1_FLT1E));
  3839. }
  3840. if ((Faults & HRTIM_FAULT_2) != (uint32_t)RESET)
  3841. {
  3842. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR1, HRTIM_FLTINR1_FLT2E, ((Enable << 8U) & HRTIM_FLTINR1_FLT2E));
  3843. }
  3844. if ((Faults & HRTIM_FAULT_3) != (uint32_t)RESET)
  3845. {
  3846. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR1, HRTIM_FLTINR1_FLT3E, ((Enable << 16U) & HRTIM_FLTINR1_FLT3E));
  3847. }
  3848. if ((Faults & HRTIM_FAULT_4) != (uint32_t)RESET)
  3849. {
  3850. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR1, HRTIM_FLTINR1_FLT4E, ((Enable << 24U) & HRTIM_FLTINR1_FLT4E));
  3851. }
  3852. if ((Faults & HRTIM_FAULT_5) != (uint32_t)RESET)
  3853. {
  3854. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR2, HRTIM_FLTINR2_FLT5E, ((Enable) & HRTIM_FLTINR2_FLT5E));
  3855. }
  3856. if ((Faults & HRTIM_FAULT_6) != (uint32_t)RESET)
  3857. {
  3858. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR2, HRTIM_FLTINR2_FLT6E, ((Enable << 8U) & HRTIM_FLTINR2_FLT6E));
  3859. }
  3860. }
  3861. /**
  3862. * @brief Configure both the ADC trigger register update source and the ADC
  3863. * trigger source.
  3864. * @param hhrtim pointer to HAL HRTIM handle
  3865. * @param ADCTrigger ADC trigger to configure
  3866. * This parameter can be one of the following values:
  3867. * @arg HRTIM_ADCTRIGGER_1: ADC trigger 1
  3868. * @arg HRTIM_ADCTRIGGER_2: ADC trigger 2
  3869. * @arg HRTIM_ADCTRIGGER_3: ADC trigger 3
  3870. * @arg HRTIM_ADCTRIGGER_4: ADC trigger 4
  3871. * @arg HRTIM_ADCTRIGGER_5: ADC trigger 5
  3872. * @arg HRTIM_ADCTRIGGER_6: ADC trigger 6
  3873. * @arg HRTIM_ADCTRIGGER_7: ADC trigger 7
  3874. * @arg HRTIM_ADCTRIGGER_8: ADC trigger 8
  3875. * @arg HRTIM_ADCTRIGGER_9: ADC trigger 9
  3876. * @arg HRTIM_ADCTRIGGER_10: ADC trigger 10
  3877. * @param pADCTriggerCfg pointer to the ADC trigger configuration structure
  3878. * for Trigger nb (1..4): pADCTriggerCfg->Trigger parameter
  3879. * can be a combination of the following values
  3880. * @arg HRTIM_ADCTRIGGEREVENT13_...
  3881. * @arg HRTIM_ADCTRIGGEREVENT24_...
  3882. * for Trigger nb (5..10): pADCTriggerCfg->Trigger parameter
  3883. * can be one of the following values
  3884. * @arg HRTIM_ADCTRIGGEREVENT579_...
  3885. * @arg HRTIM_ADCTRIGGEREVENT6810_...
  3886. * @retval HAL status
  3887. * @note This function must be called before starting the timer
  3888. */
  3889. HAL_StatusTypeDef HAL_HRTIM_ADCTriggerConfig(HRTIM_HandleTypeDef *hhrtim,
  3890. uint32_t ADCTrigger,
  3891. const HRTIM_ADCTriggerCfgTypeDef *pADCTriggerCfg)
  3892. {
  3893. uint32_t hrtim_cr1;
  3894. uint32_t hrtim_adcur;
  3895. /* Check parameters */
  3896. assert_param(IS_HRTIM_ADCTRIGGER(ADCTrigger));
  3897. assert_param(IS_HRTIM_ADCTRIGGERUPDATE(pADCTriggerCfg->UpdateSource));
  3898. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  3899. {
  3900. return HAL_BUSY;
  3901. }
  3902. /* Process Locked */
  3903. __HAL_LOCK(hhrtim);
  3904. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3905. /* Set the ADC trigger update source */
  3906. hrtim_cr1 = hhrtim->Instance->sCommonRegs.CR1;
  3907. hrtim_adcur = hhrtim->Instance->sCommonRegs.ADCUR;
  3908. switch (ADCTrigger)
  3909. {
  3910. case HRTIM_ADCTRIGGER_1:
  3911. {
  3912. hrtim_cr1 &= ~(HRTIM_CR1_ADC1USRC);
  3913. hrtim_cr1 |= (pADCTriggerCfg->UpdateSource & HRTIM_CR1_ADC1USRC);
  3914. /* Set the ADC trigger 1 source */
  3915. hhrtim->Instance->sCommonRegs.ADC1R = pADCTriggerCfg->Trigger;
  3916. break;
  3917. }
  3918. case HRTIM_ADCTRIGGER_2:
  3919. {
  3920. hrtim_cr1 &= ~(HRTIM_CR1_ADC2USRC);
  3921. hrtim_cr1 |= ((pADCTriggerCfg->UpdateSource << 3U) & HRTIM_CR1_ADC2USRC);
  3922. /* Set the ADC trigger 2 source */
  3923. hhrtim->Instance->sCommonRegs.ADC2R = pADCTriggerCfg->Trigger;
  3924. break;
  3925. }
  3926. case HRTIM_ADCTRIGGER_3:
  3927. {
  3928. hrtim_cr1 &= ~(HRTIM_CR1_ADC3USRC);
  3929. hrtim_cr1 |= ((pADCTriggerCfg->UpdateSource << 6U) & HRTIM_CR1_ADC3USRC);
  3930. /* Set the ADC trigger 3 source */
  3931. hhrtim->Instance->sCommonRegs.ADC3R = pADCTriggerCfg->Trigger;
  3932. break;
  3933. }
  3934. case HRTIM_ADCTRIGGER_4:
  3935. {
  3936. hrtim_cr1 &= ~(HRTIM_CR1_ADC4USRC);
  3937. hrtim_cr1 |= ((pADCTriggerCfg->UpdateSource << 9U) & HRTIM_CR1_ADC4USRC);
  3938. /* Set the ADC trigger 4 source */
  3939. hhrtim->Instance->sCommonRegs.ADC4R = pADCTriggerCfg->Trigger;
  3940. break;
  3941. }
  3942. case HRTIM_ADCTRIGGER_5:
  3943. {
  3944. hrtim_adcur &= ~(HRTIM_ADCUR_AD5USRC);
  3945. hrtim_adcur |= ((pADCTriggerCfg->UpdateSource >> 16U) & HRTIM_ADCUR_AD5USRC);
  3946. /* Set the ADC trigger 5 source */
  3947. hhrtim->Instance->sCommonRegs.ADCER &= ~(HRTIM_ADCER_AD5TRG);
  3948. hhrtim->Instance->sCommonRegs.ADCER |= ((pADCTriggerCfg->Trigger << HRTIM_ADCER_AD5TRG_Pos) & HRTIM_ADCER_AD5TRG);
  3949. break;
  3950. }
  3951. case HRTIM_ADCTRIGGER_6:
  3952. {
  3953. hrtim_adcur &= ~(HRTIM_ADCUR_AD6USRC);
  3954. hrtim_adcur |= ((pADCTriggerCfg->UpdateSource >> 12U) & HRTIM_ADCUR_AD6USRC);
  3955. /* Set the ADC trigger 6 source */
  3956. hhrtim->Instance->sCommonRegs.ADCER &= ~(HRTIM_ADCER_AD6TRG);
  3957. hhrtim->Instance->sCommonRegs.ADCER |= ((pADCTriggerCfg->Trigger << HRTIM_ADCER_AD6TRG_Pos) & HRTIM_ADCER_AD6TRG);
  3958. break;
  3959. }
  3960. case HRTIM_ADCTRIGGER_7:
  3961. {
  3962. hrtim_adcur &= ~(HRTIM_ADCUR_AD7USRC);
  3963. hrtim_adcur |= ((pADCTriggerCfg->UpdateSource >> 8U) & HRTIM_ADCUR_AD7USRC);
  3964. /* Set the ADC trigger 7 source */
  3965. hhrtim->Instance->sCommonRegs.ADCER &= ~(HRTIM_ADCER_AD7TRG);
  3966. hhrtim->Instance->sCommonRegs.ADCER |= ((pADCTriggerCfg->Trigger << HRTIM_ADCER_AD7TRG_Pos) & HRTIM_ADCER_AD7TRG);
  3967. break;
  3968. }
  3969. case HRTIM_ADCTRIGGER_8:
  3970. {
  3971. hrtim_adcur &= ~(HRTIM_ADCUR_AD8USRC);
  3972. hrtim_adcur |= ((pADCTriggerCfg->UpdateSource >> 4U) & HRTIM_ADCUR_AD8USRC);
  3973. /* Set the ADC trigger 8 source */
  3974. hhrtim->Instance->sCommonRegs.ADCER &= ~(HRTIM_ADCER_AD8TRG);
  3975. hhrtim->Instance->sCommonRegs.ADCER |= ((pADCTriggerCfg->Trigger << HRTIM_ADCER_AD8TRG_Pos) & HRTIM_ADCER_AD8TRG);
  3976. break;
  3977. }
  3978. case HRTIM_ADCTRIGGER_9:
  3979. {
  3980. hrtim_adcur &= ~(HRTIM_ADCUR_AD9USRC);
  3981. hrtim_adcur |= ((pADCTriggerCfg->UpdateSource) & HRTIM_ADCUR_AD9USRC);
  3982. /* Set the ADC trigger 9 source */
  3983. hhrtim->Instance->sCommonRegs.ADCER &= ~(HRTIM_ADCER_AD9TRG);
  3984. hhrtim->Instance->sCommonRegs.ADCER |= ((pADCTriggerCfg->Trigger << HRTIM_ADCER_AD9TRG_Pos) & HRTIM_ADCER_AD9TRG);
  3985. break;
  3986. }
  3987. case HRTIM_ADCTRIGGER_10:
  3988. {
  3989. hrtim_adcur &= ~(HRTIM_ADCUR_AD10USRC);
  3990. hrtim_adcur |= ((pADCTriggerCfg->UpdateSource << 4U) & HRTIM_ADCUR_AD10USRC);
  3991. /* Set the ADC trigger 10 source */
  3992. hhrtim->Instance->sCommonRegs.ADCER &= ~(HRTIM_ADCER_AD10TRG);
  3993. hhrtim->Instance->sCommonRegs.ADCER |= ((pADCTriggerCfg->Trigger << HRTIM_ADCER_AD10TRG_Pos) & HRTIM_ADCER_AD10TRG);
  3994. break;
  3995. }
  3996. default:
  3997. {
  3998. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  3999. /* Process Unlocked */
  4000. __HAL_UNLOCK(hhrtim);
  4001. break;
  4002. }
  4003. }
  4004. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  4005. {
  4006. return HAL_ERROR;
  4007. }
  4008. /* Update the HRTIM registers */
  4009. if (ADCTrigger < HRTIM_ADCTRIGGER_5)
  4010. {
  4011. hhrtim->Instance->sCommonRegs.CR1 = hrtim_cr1;
  4012. }
  4013. else
  4014. {
  4015. hhrtim->Instance->sCommonRegs.ADCUR = hrtim_adcur;
  4016. }
  4017. hhrtim->State = HAL_HRTIM_STATE_READY;
  4018. /* Process Unlocked */
  4019. __HAL_UNLOCK(hhrtim);
  4020. return HAL_OK;
  4021. }
  4022. /**
  4023. * @brief Configure the ADC trigger postscaler register of the ADC
  4024. * trigger source.
  4025. * @param hhrtim pointer to HAL HRTIM handle
  4026. * @param ADCTrigger ADC trigger to configure
  4027. * This parameter can be one of the following values:
  4028. * @arg HRTIM_ADCTRIGGER_1: ADC trigger 1
  4029. * @arg HRTIM_ADCTRIGGER_2: ADC trigger 2
  4030. * @arg HRTIM_ADCTRIGGER_3: ADC trigger 3
  4031. * @arg HRTIM_ADCTRIGGER_4: ADC trigger 4
  4032. * @arg HRTIM_ADCTRIGGER_5: ADC trigger 5
  4033. * @arg HRTIM_ADCTRIGGER_6: ADC trigger 6
  4034. * @arg HRTIM_ADCTRIGGER_7: ADC trigger 7
  4035. * @arg HRTIM_ADCTRIGGER_8: ADC trigger 8
  4036. * @arg HRTIM_ADCTRIGGER_9: ADC trigger 9
  4037. * @arg HRTIM_ADCTRIGGER_10: ADC trigger 10
  4038. * @param Postscaler value 0..1F
  4039. * @retval HAL status
  4040. * @note This function must be called before starting the timer
  4041. */
  4042. HAL_StatusTypeDef HAL_HRTIM_ADCPostScalerConfig(HRTIM_HandleTypeDef *hhrtim,
  4043. uint32_t ADCTrigger,
  4044. uint32_t Postscaler)
  4045. {
  4046. /* Check parameters */
  4047. assert_param(IS_HRTIM_ADCTRIGGER(ADCTrigger));
  4048. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4049. {
  4050. return HAL_BUSY;
  4051. }
  4052. /* Process Locked */
  4053. __HAL_LOCK(hhrtim);
  4054. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4055. switch (ADCTrigger)
  4056. {
  4057. case HRTIM_ADCTRIGGER_1:
  4058. {
  4059. MODIFY_REG(hhrtim->Instance->sCommonRegs.ADCPS1, HRTIM_ADCPS1_AD1PSC, (Postscaler & HRTIM_ADCPS1_AD1PSC));
  4060. break;
  4061. }
  4062. case HRTIM_ADCTRIGGER_2:
  4063. {
  4064. MODIFY_REG(hhrtim->Instance->sCommonRegs.ADCPS1, HRTIM_ADCPS1_AD2PSC, ((Postscaler << HRTIM_ADCPS1_AD2PSC_Pos) & HRTIM_ADCPS1_AD2PSC));
  4065. break;
  4066. }
  4067. case HRTIM_ADCTRIGGER_3:
  4068. {
  4069. MODIFY_REG(hhrtim->Instance->sCommonRegs.ADCPS1, HRTIM_ADCPS1_AD3PSC, ((Postscaler << HRTIM_ADCPS1_AD3PSC_Pos) & HRTIM_ADCPS1_AD3PSC));
  4070. break;
  4071. }
  4072. case HRTIM_ADCTRIGGER_4:
  4073. {
  4074. MODIFY_REG(hhrtim->Instance->sCommonRegs.ADCPS1, HRTIM_ADCPS1_AD4PSC, ((Postscaler << HRTIM_ADCPS1_AD4PSC_Pos) & HRTIM_ADCPS1_AD4PSC));
  4075. break;
  4076. }
  4077. case HRTIM_ADCTRIGGER_5:
  4078. {
  4079. MODIFY_REG(hhrtim->Instance->sCommonRegs.ADCPS1, HRTIM_ADCPS1_AD5PSC, ((Postscaler << HRTIM_ADCPS1_AD5PSC_Pos) & HRTIM_ADCPS1_AD5PSC));
  4080. break;
  4081. }
  4082. case HRTIM_ADCTRIGGER_6:
  4083. {
  4084. MODIFY_REG(hhrtim->Instance->sCommonRegs.ADCPS2, HRTIM_ADCPS2_AD6PSC, ((Postscaler << HRTIM_ADCPS2_AD6PSC_Pos) & HRTIM_ADCPS2_AD6PSC));
  4085. break;
  4086. }
  4087. case HRTIM_ADCTRIGGER_7:
  4088. {
  4089. MODIFY_REG(hhrtim->Instance->sCommonRegs.ADCPS2, HRTIM_ADCPS2_AD7PSC, ((Postscaler << HRTIM_ADCPS2_AD7PSC_Pos) & HRTIM_ADCPS2_AD7PSC));
  4090. break;
  4091. }
  4092. case HRTIM_ADCTRIGGER_8:
  4093. {
  4094. MODIFY_REG(hhrtim->Instance->sCommonRegs.ADCPS2, HRTIM_ADCPS2_AD8PSC, ((Postscaler << HRTIM_ADCPS2_AD8PSC_Pos) & HRTIM_ADCPS2_AD8PSC));
  4095. break;
  4096. }
  4097. case HRTIM_ADCTRIGGER_9:
  4098. {
  4099. MODIFY_REG(hhrtim->Instance->sCommonRegs.ADCPS2, HRTIM_ADCPS2_AD9PSC, ((Postscaler << HRTIM_ADCPS2_AD9PSC_Pos) & HRTIM_ADCPS2_AD9PSC));
  4100. break;
  4101. }
  4102. case HRTIM_ADCTRIGGER_10:
  4103. {
  4104. MODIFY_REG(hhrtim->Instance->sCommonRegs.ADCPS2, HRTIM_ADCPS2_AD10PSC, ((Postscaler << HRTIM_ADCPS2_AD10PSC_Pos) & HRTIM_ADCPS2_AD10PSC));
  4105. break;
  4106. }
  4107. default:
  4108. {
  4109. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  4110. /* Process Unlocked */
  4111. __HAL_UNLOCK(hhrtim);
  4112. break;
  4113. }
  4114. }
  4115. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  4116. {
  4117. return HAL_ERROR;
  4118. }
  4119. hhrtim->State = HAL_HRTIM_STATE_READY;
  4120. /* Process Unlocked */
  4121. __HAL_UNLOCK(hhrtim);
  4122. return HAL_OK;
  4123. }
  4124. /**
  4125. * @brief Configure the ADC Roll-Over mode of the ADC
  4126. * trigger source.
  4127. * @param hhrtim pointer to HAL HRTIM handle
  4128. * @param TimerIdx Timer index
  4129. * This parameter can be one of the following values:
  4130. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  4131. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  4132. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  4133. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  4134. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  4135. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  4136. * @param RollOverCfg This parameter can be a combination of all the following values:
  4137. * @arg HRTIM_TIM_FEROM_BOTH or HRTIM_TIM_FEROM_CREST or HRTIM_TIM_FEROM_VALLEY
  4138. * @arg HRTIM_TIM_BMROM_BOTH or HRTIM_TIM_BMROM_CREST or HRTIM_TIM_BMROM_VALLEY
  4139. * @arg HRTIM_TIM_ADROM_BOTH or HRTIM_TIM_ADROM_CREST or HRTIM_TIM_ADROM_VALLEY
  4140. * @arg HRTIM_TIM_OUTROM_BOTH or HRTIM_TIM_OUTROM_CREST or HRTIM_TIM_OUTROM_VALLEY
  4141. * @arg HRTIM_TIM_ROM_BOTH or HRTIM_TIM_ROM_CREST or HRTIM_TIM_ROM_VALLEY
  4142. * @note This function must be called before starting the timer
  4143. */
  4144. HAL_StatusTypeDef HAL_HRTIM_RollOverModeConfig(HRTIM_HandleTypeDef *hhrtim,
  4145. uint32_t TimerIdx,
  4146. uint32_t RollOverCfg)
  4147. {
  4148. /* Check parameters */
  4149. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  4150. assert_param(IS_HRTIM_ROLLOVERMODE(RollOverCfg));
  4151. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4152. {
  4153. return HAL_BUSY;
  4154. }
  4155. /* Process Locked */
  4156. __HAL_LOCK(hhrtim);
  4157. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4158. HRTIM_TimingUnitRollOver_Config(hhrtim, TimerIdx, RollOverCfg);
  4159. hhrtim->State = HAL_HRTIM_STATE_READY;
  4160. /* Process Unlocked */
  4161. __HAL_UNLOCK(hhrtim);
  4162. return HAL_OK;
  4163. }
  4164. /**
  4165. * @}
  4166. */
  4167. /** @defgroup HRTIM_Exported_Functions_Group8 Timer waveform configuration and functions
  4168. * @brief HRTIM timer configuration and control functions
  4169. @verbatim
  4170. ===============================================================================
  4171. ##### HRTIM timer configuration and control functions #####
  4172. ===============================================================================
  4173. [..] This section provides functions used to configure and control a
  4174. HRTIM timer operating in waveform mode:
  4175. (+) Configure HRTIM timer general behavior
  4176. (+) Configure HRTIM timer event filtering
  4177. (+) Configure HRTIM timer deadtime insertion
  4178. (+) Configure HRTIM timer chopper mode
  4179. (+) Configure HRTIM timer burst DMA
  4180. (+) Configure HRTIM timer compare unit
  4181. (+) Configure HRTIM timer capture unit
  4182. (+) Configure HRTIM timer output
  4183. (+) Set HRTIM timer output level
  4184. (+) Enable HRTIM timer output
  4185. (+) Disable HRTIM timer output
  4186. (+) Start HRTIM timer
  4187. (+) Stop HRTIM timer
  4188. (+) Start HRTIM timer and enable interrupt
  4189. (+) Stop HRTIM timer and disable interrupt
  4190. (+) Start HRTIM timer and enable DMA transfer
  4191. (+) Stop HRTIM timer and disable DMA transfer
  4192. (+) Enable or disable the burst mode controller
  4193. (+) Start the burst mode controller (by software)
  4194. (+) Trigger a Capture (by software)
  4195. (+) Update the HRTIM timer preloadable registers (by software)
  4196. (+) Reset the HRTIM timer counter (by software)
  4197. (+) Start a burst DMA transfer
  4198. (+) Enable timer register update
  4199. (+) Disable timer register update
  4200. @endverbatim
  4201. * @{
  4202. */
  4203. /**
  4204. * @brief Configure the general behavior of a timer operating in waveform mode
  4205. * @param hhrtim pointer to HAL HRTIM handle
  4206. * @param TimerIdx Timer index
  4207. * This parameter can be one of the following values:
  4208. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  4209. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  4210. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  4211. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  4212. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  4213. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  4214. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  4215. * @param pTimerCfg pointer to the timer configuration structure
  4216. * @note When the timer operates in waveform mode, all the features supported by
  4217. * the HRTIM are available without any limitation.
  4218. * @retval HAL status
  4219. * @note This function must be called before starting the timer
  4220. */
  4221. HAL_StatusTypeDef HAL_HRTIM_WaveformTimerConfig(HRTIM_HandleTypeDef *hhrtim,
  4222. uint32_t TimerIdx,
  4223. const HRTIM_TimerCfgTypeDef *pTimerCfg)
  4224. {
  4225. /* Check parameters */
  4226. assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  4227. /* Relevant for all HRTIM timers, including the master */
  4228. assert_param(IS_HRTIM_HALFMODE(pTimerCfg->HalfModeEnable));
  4229. assert_param(IS_HRTIM_INTERLEAVEDMODE(pTimerCfg->InterleavedMode));
  4230. assert_param(IS_HRTIM_SYNCSTART(pTimerCfg->StartOnSync));
  4231. assert_param(IS_HRTIM_SYNCRESET(pTimerCfg->ResetOnSync));
  4232. assert_param(IS_HRTIM_DACSYNC(pTimerCfg->DACSynchro));
  4233. assert_param(IS_HRTIM_PRELOAD(pTimerCfg->PreloadEnable));
  4234. assert_param(IS_HRTIM_TIMERBURSTMODE(pTimerCfg->BurstMode));
  4235. assert_param(IS_HRTIM_UPDATEONREPETITION(pTimerCfg->RepetitionUpdate));
  4236. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4237. {
  4238. return HAL_BUSY;
  4239. }
  4240. /* Process Locked */
  4241. __HAL_LOCK(hhrtim);
  4242. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4243. if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
  4244. {
  4245. /* Check parameters */
  4246. assert_param(IS_HRTIM_UPDATEGATING_MASTER(pTimerCfg->UpdateGating));
  4247. assert_param(IS_HRTIM_MASTER_IT(pTimerCfg->InterruptRequests));
  4248. assert_param(IS_HRTIM_MASTER_DMA(pTimerCfg->DMARequests));
  4249. /* Configure master timer */
  4250. HRTIM_MasterWaveform_Config(hhrtim, pTimerCfg);
  4251. }
  4252. else
  4253. {
  4254. /* Check parameters */
  4255. assert_param(IS_HRTIM_UPDATEGATING_TIM(pTimerCfg->UpdateGating));
  4256. assert_param(IS_HRTIM_TIM_IT(pTimerCfg->InterruptRequests));
  4257. assert_param(IS_HRTIM_TIM_DMA(pTimerCfg->DMARequests));
  4258. assert_param(IS_HRTIM_TIMPUSHPULLMODE(pTimerCfg->PushPull));
  4259. assert_param(IS_HRTIM_TIMFAULTENABLE(pTimerCfg->FaultEnable));
  4260. assert_param(IS_HRTIM_TIMFAULTLOCK(pTimerCfg->FaultLock));
  4261. assert_param(IS_HRTIM_TIMDEADTIMEINSERTION(pTimerCfg->PushPull,
  4262. pTimerCfg->DeadTimeInsertion));
  4263. assert_param(IS_HRTIM_TIMDELAYEDPROTECTION(pTimerCfg->PushPull,
  4264. pTimerCfg->DelayedProtectionMode));
  4265. assert_param(IS_HRTIM_OUTPUTBALANCEDIDLE(pTimerCfg->BalancedIdleAutomaticResume));
  4266. assert_param(IS_HRTIM_TIMUPDATETRIGGER(pTimerCfg->UpdateTrigger));
  4267. assert_param(IS_HRTIM_TIMRESETTRIGGER(pTimerCfg->ResetTrigger));
  4268. assert_param(IS_HRTIM_TIMUPDATEONRESET(pTimerCfg->ResetUpdate));
  4269. assert_param(IS_HRTIM_TIMSYNCUPDATE(pTimerCfg->ReSyncUpdate));
  4270. /* Configure timing unit */
  4271. HRTIM_TimingUnitWaveform_Config(hhrtim, TimerIdx, pTimerCfg);
  4272. }
  4273. /* Update timer parameters */
  4274. hhrtim->TimerParam[TimerIdx].InterruptRequests = pTimerCfg->InterruptRequests;
  4275. hhrtim->TimerParam[TimerIdx].DMARequests = pTimerCfg->DMARequests;
  4276. hhrtim->TimerParam[TimerIdx].DMASrcAddress = pTimerCfg->DMASrcAddress;
  4277. hhrtim->TimerParam[TimerIdx].DMADstAddress = pTimerCfg->DMADstAddress;
  4278. hhrtim->TimerParam[TimerIdx].DMASize = pTimerCfg->DMASize;
  4279. /* Force a software update */
  4280. HRTIM_ForceRegistersUpdate(hhrtim, TimerIdx);
  4281. /* Configure slave timer update re-synchronization */
  4282. if ((TimerIdx != HRTIM_TIMERINDEX_MASTER)
  4283. && (pTimerCfg->UpdateGating == HRTIM_UPDATEGATING_INDEPENDENT))
  4284. {
  4285. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR,
  4286. HRTIM_TIMCR_RSYNCU_Msk,
  4287. pTimerCfg->ReSyncUpdate << HRTIM_TIMCR_RSYNCU_Pos);
  4288. }
  4289. hhrtim->State = HAL_HRTIM_STATE_READY;
  4290. /* Process Unlocked */
  4291. __HAL_UNLOCK(hhrtim);
  4292. return HAL_OK;
  4293. }
  4294. /**
  4295. * @brief Configure the general behavior of a timer operating in waveform mode
  4296. * @param hhrtim pointer to HAL HRTIM handle
  4297. * @param TimerIdx Timer index
  4298. * This parameter can be one of the following values:
  4299. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  4300. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  4301. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  4302. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  4303. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  4304. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  4305. * @param pTimerCtl pointer to the timer configuration structure
  4306. * @note When the timer operates in waveform mode, all the features supported by
  4307. * the HRTIM are available without any limitation.
  4308. * @retval HAL status
  4309. * @note This function must be called before starting the timer
  4310. */
  4311. HAL_StatusTypeDef HAL_HRTIM_WaveformTimerControl(HRTIM_HandleTypeDef *hhrtim,
  4312. uint32_t TimerIdx,
  4313. const HRTIM_TimerCtlTypeDef *pTimerCtl)
  4314. {
  4315. /* Check parameters */
  4316. assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  4317. /* Relevant for all A..F HRTIM timers */
  4318. assert_param(IS_HRTIM_TIMERUPDOWNMODE(pTimerCtl->UpDownMode));
  4319. assert_param(IS_HRTIM_TIMERTRGHLFMODE(pTimerCtl->TrigHalf));
  4320. assert_param(IS_HRTIM_TIMERGTCMP3(pTimerCtl->GreaterCMP3));
  4321. assert_param(IS_HRTIM_TIMERGTCMP1(pTimerCtl->GreaterCMP1));
  4322. assert_param(IS_HRTIM_DUALDAC_RESET(pTimerCtl->DualChannelDacReset));
  4323. assert_param(IS_HRTIM_DUALDAC_STEP(pTimerCtl->DualChannelDacStep));
  4324. assert_param(IS_HRTIM_DUALDAC_ENABLE(pTimerCtl->DualChannelDacEnable));
  4325. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4326. {
  4327. return HAL_BUSY;
  4328. }
  4329. /* Process Locked */
  4330. __HAL_LOCK(hhrtim);
  4331. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4332. /* Configure timing unit */
  4333. HRTIM_TimingUnitWaveform_Control(hhrtim, TimerIdx, pTimerCtl);
  4334. /* Force a software update */
  4335. HRTIM_ForceRegistersUpdate(hhrtim, TimerIdx);
  4336. hhrtim->State = HAL_HRTIM_STATE_READY;
  4337. /* Process Unlocked */
  4338. __HAL_UNLOCK(hhrtim);
  4339. return HAL_OK;
  4340. }
  4341. /**
  4342. * @brief Configure the Dual Channel Dac behavior of a timer operating in waveform mode
  4343. * @param hhrtim: pointer to HAL HRTIM handle
  4344. * @param TimerIdx Timer index
  4345. * This parameter can be one of the following values:
  4346. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  4347. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  4348. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  4349. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  4350. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  4351. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  4352. * @param pTimerCtl pointer to the timer DualChannel Dac configuration structure
  4353. * @note When the timer operates in waveform mode, all the features supported by
  4354. * the HRTIM are available without any limitation.
  4355. * @retval HAL status
  4356. * @note This function must be called before starting the timer
  4357. */
  4358. HAL_StatusTypeDef HAL_HRTIM_TimerDualChannelDacConfig(HRTIM_HandleTypeDef *hhrtim,
  4359. uint32_t TimerIdx,
  4360. const HRTIM_TimerCtlTypeDef *pTimerCtl)
  4361. {
  4362. assert_param(IS_HRTIM_DUALDAC_RESET(pTimerCtl->DualChannelDacReset));
  4363. assert_param(IS_HRTIM_DUALDAC_STEP(pTimerCtl->DualChannelDacStep));
  4364. assert_param(IS_HRTIM_DUALDAC_ENABLE(pTimerCtl->DualChannelDacEnable));
  4365. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4366. {
  4367. return HAL_BUSY;
  4368. }
  4369. /* Process Locked */
  4370. __HAL_LOCK(hhrtim);
  4371. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4372. /* clear DCDS,DCDR,DCDE bits */
  4373. CLEAR_BIT(hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR2,
  4374. (HRTIM_TIMER_DCDE_ENABLED |
  4375. HRTIM_TIMER_DCDS_OUT1RST |
  4376. HRTIM_TIMER_DCDR_OUT1SET));
  4377. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR2,
  4378. (HRTIM_TIMER_DCDE_ENABLED |
  4379. HRTIM_TIMER_DCDS_OUT1RST |
  4380. HRTIM_TIMER_DCDR_OUT1SET),
  4381. (pTimerCtl->DualChannelDacReset |
  4382. pTimerCtl->DualChannelDacStep |
  4383. pTimerCtl->DualChannelDacEnable));
  4384. hhrtim->State = HAL_HRTIM_STATE_READY;
  4385. /* Process Unlocked */
  4386. __HAL_UNLOCK(hhrtim);
  4387. return HAL_OK;
  4388. }
  4389. /**
  4390. * @brief Configure the event filtering capabilities of a timer (blanking, windowing)
  4391. * @param hhrtim pointer to HAL HRTIM handle
  4392. * @param TimerIdx Timer index
  4393. * This parameter can be one of the following values:
  4394. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  4395. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  4396. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  4397. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  4398. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  4399. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  4400. * @param Event external event for which timer event filtering must be configured
  4401. * This parameter can be one of the following values:
  4402. * @arg HRTIM_EVENT_1: External event 1
  4403. * @arg HRTIM_EVENT_2: External event 2
  4404. * @arg HRTIM_EVENT_3: External event 3
  4405. * @arg HRTIM_EVENT_4: External event 4
  4406. * @arg HRTIM_EVENT_5: External event 5
  4407. * @arg HRTIM_EVENT_6: External event 6
  4408. * @arg HRTIM_EVENT_7: External event 7
  4409. * @arg HRTIM_EVENT_8: External event 8
  4410. * @arg HRTIM_EVENT_9: External event 9
  4411. * @arg HRTIM_EVENT_10: External event 10
  4412. * @param pTimerEventFilteringCfg pointer to the timer event filtering configuration structure
  4413. * @note This function must be called before starting the timer
  4414. * @retval HAL status
  4415. */
  4416. HAL_StatusTypeDef HAL_HRTIM_TimerEventFilteringConfig(HRTIM_HandleTypeDef *hhrtim,
  4417. uint32_t TimerIdx,
  4418. uint32_t Event,
  4419. const HRTIM_TimerEventFilteringCfgTypeDef *pTimerEventFilteringCfg)
  4420. {
  4421. /* Check parameters */
  4422. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  4423. assert_param(IS_HRTIM_EVENT(Event));
  4424. assert_param(IS_HRTIM_TIMEVENTFILTER(TimerIdx, pTimerEventFilteringCfg->Filter));
  4425. assert_param(IS_HRTIM_TIMEVENTLATCH(pTimerEventFilteringCfg->Latch));
  4426. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4427. {
  4428. return HAL_BUSY;
  4429. }
  4430. /* Process Locked */
  4431. __HAL_LOCK(hhrtim);
  4432. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4433. /* Configure timer event filtering capabilities */
  4434. switch (Event)
  4435. {
  4436. case HRTIM_EVENT_NONE:
  4437. {
  4438. CLEAR_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR1);
  4439. CLEAR_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR2);
  4440. break;
  4441. }
  4442. case HRTIM_EVENT_1:
  4443. {
  4444. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR1, (HRTIM_EEFR1_EE1FLTR | HRTIM_EEFR1_EE1LTCH),
  4445. (pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch));
  4446. break;
  4447. }
  4448. case HRTIM_EVENT_2:
  4449. {
  4450. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR1, (HRTIM_EEFR1_EE2FLTR | HRTIM_EEFR1_EE2LTCH),
  4451. ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 6U));
  4452. break;
  4453. }
  4454. case HRTIM_EVENT_3:
  4455. {
  4456. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR1, (HRTIM_EEFR1_EE3FLTR | HRTIM_EEFR1_EE3LTCH),
  4457. ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 12U));
  4458. break;
  4459. }
  4460. case HRTIM_EVENT_4:
  4461. {
  4462. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR1, (HRTIM_EEFR1_EE4FLTR | HRTIM_EEFR1_EE4LTCH),
  4463. ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 18U));
  4464. break;
  4465. }
  4466. case HRTIM_EVENT_5:
  4467. {
  4468. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR1, (HRTIM_EEFR1_EE5FLTR | HRTIM_EEFR1_EE5LTCH),
  4469. ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 24U));
  4470. break;
  4471. }
  4472. case HRTIM_EVENT_6:
  4473. {
  4474. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR2, (HRTIM_EEFR2_EE6FLTR | HRTIM_EEFR2_EE6LTCH),
  4475. (pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch));
  4476. break;
  4477. }
  4478. case HRTIM_EVENT_7:
  4479. {
  4480. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR2, (HRTIM_EEFR2_EE7FLTR | HRTIM_EEFR2_EE7LTCH),
  4481. ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 6U));
  4482. break;
  4483. }
  4484. case HRTIM_EVENT_8:
  4485. {
  4486. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR2, (HRTIM_EEFR2_EE8FLTR | HRTIM_EEFR2_EE8LTCH),
  4487. ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 12U));
  4488. break;
  4489. }
  4490. case HRTIM_EVENT_9:
  4491. {
  4492. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR2, (HRTIM_EEFR2_EE9FLTR | HRTIM_EEFR2_EE9LTCH),
  4493. ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 18U));
  4494. break;
  4495. }
  4496. case HRTIM_EVENT_10:
  4497. {
  4498. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR2, (HRTIM_EEFR2_EE10FLTR | HRTIM_EEFR2_EE10LTCH),
  4499. ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 24U));
  4500. break;
  4501. }
  4502. default:
  4503. {
  4504. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  4505. /* Process Unlocked */
  4506. __HAL_UNLOCK(hhrtim);
  4507. break;
  4508. }
  4509. }
  4510. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  4511. {
  4512. return HAL_ERROR;
  4513. }
  4514. hhrtim->State = HAL_HRTIM_STATE_READY;
  4515. /* Process Unlocked */
  4516. __HAL_UNLOCK(hhrtim);
  4517. return HAL_OK;
  4518. }
  4519. /**
  4520. * @brief Configure the external Event Counter A or B of a timer (source, threshold, reset mode)
  4521. * but does not enable : call HAL_HRTIM_ExternalEventCounterEnable afterwards
  4522. * @param hhrtim pointer to HAL HRTIM handle
  4523. * @param TimerIdx Timer index
  4524. * This parameter can be one of the following values:
  4525. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  4526. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  4527. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  4528. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  4529. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  4530. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  4531. * @param EventCounter external event Counter A or B for which timer event must be configured
  4532. * This parameter can be one of the following values:
  4533. * @arg HRTIM_EVENTCOUNTER_A
  4534. * @arg HRTIM_EVENTCOUNTER_B
  4535. * @param pTimerExternalEventCfg: pointer to the timer external event configuration structure
  4536. * @note This function must be called before starting the timer
  4537. * @retval HAL status
  4538. */
  4539. HAL_StatusTypeDef HAL_HRTIM_ExtEventCounterConfig(HRTIM_HandleTypeDef *hhrtim,
  4540. uint32_t TimerIdx,
  4541. uint32_t EventCounter,
  4542. const HRTIM_ExternalEventCfgTypeDef *pTimerExternalEventCfg)
  4543. {
  4544. uint32_t hrtim_eefr3;
  4545. /* Check parameters */
  4546. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  4547. assert_param(IS_HRTIM_TIMEEVENT(EventCounter));
  4548. assert_param(IS_HRTIM_TIMEEVENT_RESETMODE(pTimerExternalEventCfg->ResetMode));
  4549. assert_param(IS_HRTIM_TIMEEVENT_COUNTER(pTimerExternalEventCfg->Counter));
  4550. assert_param(IS_HRTIM_EVENT(pTimerExternalEventCfg->Source));
  4551. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4552. {
  4553. return HAL_BUSY;
  4554. }
  4555. /* Process Locked */
  4556. __HAL_LOCK(hhrtim);
  4557. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4558. if ((EventCounter & HRTIM_EVENTCOUNTER_A) != 0U)
  4559. {
  4560. if (pTimerExternalEventCfg->Source == HRTIM_EVENT_NONE)
  4561. {
  4562. /* reset External EventCounter A */
  4563. WRITE_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR3, 0xFFFF0000U);
  4564. }
  4565. else
  4566. {
  4567. /* Set timer External EventCounter A configuration */
  4568. hrtim_eefr3 = (pTimerExternalEventCfg->ResetMode) << HRTIM_EEFR3_EEVARSTM_Pos;
  4569. hrtim_eefr3 |= ((pTimerExternalEventCfg->Source - 1U)) << HRTIM_EEFR3_EEVASEL_Pos;
  4570. hrtim_eefr3 |= (pTimerExternalEventCfg->Counter) << HRTIM_EEFR3_EEVACNT_Pos;
  4571. /* do not enable, use HAL_HRTIM_TimerExternalEventEnable function */
  4572. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR3,
  4573. (HRTIM_EEFR3_EEVARSTM | HRTIM_EEFR3_EEVASEL | HRTIM_EEFR3_EEVACNT), hrtim_eefr3);
  4574. }
  4575. }
  4576. if ((EventCounter & HRTIM_EVENTCOUNTER_B) != 0U)
  4577. {
  4578. if (pTimerExternalEventCfg->Source == HRTIM_EVENT_NONE)
  4579. {
  4580. /* reset External EventCounter B */
  4581. WRITE_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR3, 0x0000FFFFU);
  4582. }
  4583. else
  4584. {
  4585. /* Set timer External EventCounter B configuration */
  4586. hrtim_eefr3 = (pTimerExternalEventCfg->ResetMode) << HRTIM_EEFR3_EEVBRSTM_Pos;
  4587. hrtim_eefr3 |= ((pTimerExternalEventCfg->Source - 1U)) << HRTIM_EEFR3_EEVBSEL_Pos;
  4588. hrtim_eefr3 |= (pTimerExternalEventCfg->Counter) << HRTIM_EEFR3_EEVBCNT_Pos;
  4589. /* do not enable, use HAL_HRTIM_TimerExternalEventEnable function */
  4590. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR3,
  4591. (HRTIM_EEFR3_EEVBRSTM | HRTIM_EEFR3_EEVBSEL | HRTIM_EEFR3_EEVBCNT), hrtim_eefr3);
  4592. }
  4593. }
  4594. hhrtim->State = HAL_HRTIM_STATE_READY;
  4595. /* Process Unlocked */
  4596. __HAL_UNLOCK(hhrtim);
  4597. return HAL_OK;
  4598. }
  4599. /**
  4600. * @brief Enable the external event Counter A or B of a timer
  4601. * @param hhrtim: pointer to HAL HRTIM handle
  4602. * @param TimerIdx: Timer index
  4603. * This parameter can be one of the following values:
  4604. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  4605. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  4606. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  4607. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  4608. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  4609. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  4610. * @param EventCounter external Event Counter A or B for which timer event must be configured
  4611. * This parameter can be a one of the following values:
  4612. * @arg HRTIM_EVENTCOUNTER_A
  4613. * @arg HRTIM_EVENTCOUNTER_B
  4614. * @note This function must be called before starting the timer
  4615. * @retval HAL status
  4616. */
  4617. HAL_StatusTypeDef HAL_HRTIM_ExtEventCounterEnable(HRTIM_HandleTypeDef *hhrtim,
  4618. uint32_t TimerIdx,
  4619. uint32_t EventCounter)
  4620. {
  4621. /* Check parameters */
  4622. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  4623. assert_param(IS_HRTIM_TIMEEVENT(EventCounter));
  4624. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4625. {
  4626. return HAL_BUSY;
  4627. }
  4628. /* Process Locked */
  4629. __HAL_LOCK(hhrtim);
  4630. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4631. if ((EventCounter & HRTIM_EVENTCOUNTER_A) != 0U)
  4632. {
  4633. SET_BIT(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR3, HRTIM_EEFR3_EEVACE);
  4634. }
  4635. if ((EventCounter & HRTIM_EVENTCOUNTER_B) != 0U)
  4636. {
  4637. SET_BIT(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR3, HRTIM_EEFR3_EEVBCE);
  4638. }
  4639. hhrtim->State = HAL_HRTIM_STATE_READY;
  4640. /* Process Unlocked */
  4641. __HAL_UNLOCK(hhrtim);
  4642. return HAL_OK;
  4643. }
  4644. /**
  4645. * @brief Disable the external event Counter A or B of a timer
  4646. * @param hhrtim: pointer to HAL HRTIM handle
  4647. * @param TimerIdx: Timer index
  4648. * This parameter can be one of the following values:
  4649. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  4650. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  4651. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  4652. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  4653. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  4654. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  4655. * @param EventCounter external event Counter A or B for which timer event must be configured
  4656. * This parameter can be a one of the following values:
  4657. * @arg HRTIM_EVENTCOUNTER_A
  4658. * @arg HRTIM_EVENTCOUNTER_B
  4659. * @retval HAL status
  4660. */
  4661. HAL_StatusTypeDef HAL_HRTIM_ExtEventCounterDisable(HRTIM_HandleTypeDef *hhrtim,
  4662. uint32_t TimerIdx,
  4663. uint32_t EventCounter)
  4664. {
  4665. /* Check parameters */
  4666. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  4667. assert_param(IS_HRTIM_TIMEEVENT(EventCounter));
  4668. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4669. {
  4670. return HAL_BUSY;
  4671. }
  4672. /* Process Locked */
  4673. __HAL_LOCK(hhrtim);
  4674. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4675. if ((EventCounter & HRTIM_EVENTCOUNTER_A) != 0U)
  4676. {
  4677. CLEAR_BIT(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR3, HRTIM_EEFR3_EEVACE);
  4678. }
  4679. if ((EventCounter & HRTIM_EVENTCOUNTER_B) != 0U)
  4680. {
  4681. CLEAR_BIT(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR3, HRTIM_EEFR3_EEVBCE);
  4682. }
  4683. hhrtim->State = HAL_HRTIM_STATE_READY;
  4684. /* Process Unlocked */
  4685. __HAL_UNLOCK(hhrtim);
  4686. return HAL_OK;
  4687. }
  4688. /**
  4689. * @brief Reset the external event Counter A or B of a timer
  4690. * @param hhrtim pointer to HAL HRTIM handle
  4691. * @param TimerIdx Timer index
  4692. * This parameter can be one of the following values:
  4693. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  4694. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  4695. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  4696. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  4697. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  4698. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  4699. * @param EventCounter external event Counter A or B for which timer event must be configured
  4700. * This parameter can be one of the following values:
  4701. * @arg HRTIM_EVENTCOUNTER_A
  4702. * @arg HRTIM_EVENTCOUNTER_B
  4703. * @note This function must be called before starting the timer
  4704. * @retval HAL status
  4705. */
  4706. HAL_StatusTypeDef HAL_HRTIM_ExtEventCounterReset(HRTIM_HandleTypeDef *hhrtim,
  4707. uint32_t TimerIdx,
  4708. uint32_t EventCounter)
  4709. {
  4710. /* Check parameters */
  4711. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  4712. assert_param(IS_HRTIM_TIMEEVENT(EventCounter));
  4713. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4714. {
  4715. return HAL_BUSY;
  4716. }
  4717. /* Process Locked */
  4718. __HAL_LOCK(hhrtim);
  4719. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4720. if ((EventCounter & HRTIM_EVENTCOUNTER_A) != 0U)
  4721. {
  4722. SET_BIT(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR3, HRTIM_EEFR3_EEVACRES);
  4723. }
  4724. if ((EventCounter & HRTIM_EVENTCOUNTER_B) != 0U)
  4725. {
  4726. SET_BIT(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR3, HRTIM_EEFR3_EEVBCRES);
  4727. }
  4728. hhrtim->State = HAL_HRTIM_STATE_READY;
  4729. /* Process Unlocked */
  4730. __HAL_UNLOCK(hhrtim);
  4731. return HAL_OK;
  4732. }
  4733. /**
  4734. * @brief Configure the dead-time insertion feature for a timer
  4735. * @param hhrtim pointer to HAL HRTIM handle
  4736. * @param TimerIdx Timer index
  4737. * This parameter can be one of the following values:
  4738. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  4739. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  4740. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  4741. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  4742. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  4743. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  4744. * @param pDeadTimeCfg pointer to the deadtime insertion configuration structure
  4745. * @retval HAL status
  4746. * @note This function must be called before starting the timer
  4747. */
  4748. HAL_StatusTypeDef HAL_HRTIM_DeadTimeConfig(HRTIM_HandleTypeDef *hhrtim,
  4749. uint32_t TimerIdx,
  4750. const HRTIM_DeadTimeCfgTypeDef *pDeadTimeCfg)
  4751. {
  4752. uint32_t hrtim_dtr;
  4753. /* Check parameters */
  4754. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  4755. assert_param(IS_HRTIM_TIMDEADTIME_PRESCALERRATIO(pDeadTimeCfg->Prescaler));
  4756. assert_param(IS_HRTIM_TIMDEADTIME_RISINGSIGN(pDeadTimeCfg->RisingSign));
  4757. assert_param(IS_HRTIM_TIMDEADTIME_RISINGLOCK(pDeadTimeCfg->RisingLock));
  4758. assert_param(IS_HRTIM_TIMDEADTIME_RISINGSIGNLOCK(pDeadTimeCfg->RisingSignLock));
  4759. assert_param(IS_HRTIM_TIMDEADTIME_FALLINGSIGN(pDeadTimeCfg->FallingSign));
  4760. assert_param(IS_HRTIM_TIMDEADTIME_FALLINGLOCK(pDeadTimeCfg->FallingLock));
  4761. assert_param(IS_HRTIM_TIMDEADTIME_FALLINGSIGNLOCK(pDeadTimeCfg->FallingSignLock));
  4762. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4763. {
  4764. return HAL_BUSY;
  4765. }
  4766. /* Process Locked */
  4767. __HAL_LOCK(hhrtim);
  4768. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4769. /* Set timer deadtime configuration */
  4770. hrtim_dtr = (pDeadTimeCfg->Prescaler & HRTIM_DTR_DTPRSC);
  4771. hrtim_dtr |= (pDeadTimeCfg->RisingValue & HRTIM_DTR_DTR);
  4772. hrtim_dtr |= (pDeadTimeCfg->RisingSign & HRTIM_DTR_SDTR);
  4773. hrtim_dtr |= (pDeadTimeCfg->RisingSignLock & HRTIM_DTR_DTRSLK);
  4774. hrtim_dtr |= (pDeadTimeCfg->RisingLock & HRTIM_DTR_DTRLK);
  4775. hrtim_dtr |= ((pDeadTimeCfg->FallingValue << 16U) & HRTIM_DTR_DTF);
  4776. hrtim_dtr |= (pDeadTimeCfg->FallingSign & HRTIM_DTR_SDTF);
  4777. hrtim_dtr |= (pDeadTimeCfg->FallingSignLock & HRTIM_DTR_DTFSLK);
  4778. hrtim_dtr |= (pDeadTimeCfg->FallingLock & HRTIM_DTR_DTFLK);
  4779. /* Update the HRTIM registers */
  4780. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].DTxR, (
  4781. HRTIM_DTR_DTR | HRTIM_DTR_SDTR | HRTIM_DTR_DTPRSC |
  4782. HRTIM_DTR_DTRSLK | HRTIM_DTR_DTRLK | HRTIM_DTR_DTF |
  4783. HRTIM_DTR_SDTF | HRTIM_DTR_DTFSLK | HRTIM_DTR_DTFLK), hrtim_dtr);
  4784. hhrtim->State = HAL_HRTIM_STATE_READY;
  4785. /* Process Unlocked */
  4786. __HAL_UNLOCK(hhrtim);
  4787. return HAL_OK;
  4788. }
  4789. /**
  4790. * @brief Configure the chopper mode feature for a timer
  4791. * @param hhrtim pointer to HAL HRTIM handle
  4792. * @param TimerIdx Timer index
  4793. * This parameter can be one of the following values:
  4794. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  4795. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  4796. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  4797. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  4798. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  4799. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  4800. * @param pChopperModeCfg pointer to the chopper mode configuration structure
  4801. * @retval HAL status
  4802. * @note This function must be called before configuring the timer output(s)
  4803. */
  4804. HAL_StatusTypeDef HAL_HRTIM_ChopperModeConfig(HRTIM_HandleTypeDef *hhrtim,
  4805. uint32_t TimerIdx,
  4806. const HRTIM_ChopperModeCfgTypeDef *pChopperModeCfg)
  4807. {
  4808. uint32_t hrtim_chpr;
  4809. /* Check parameters */
  4810. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  4811. assert_param(IS_HRTIM_CHOPPER_PRESCALERRATIO(pChopperModeCfg->CarrierFreq));
  4812. assert_param(IS_HRTIM_CHOPPER_DUTYCYCLE(pChopperModeCfg->DutyCycle));
  4813. assert_param(IS_HRTIM_CHOPPER_PULSEWIDTH(pChopperModeCfg->StartPulse));
  4814. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4815. {
  4816. return HAL_BUSY;
  4817. }
  4818. /* Process Locked */
  4819. __HAL_LOCK(hhrtim);
  4820. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4821. /* Set timer choppe mode configuration */
  4822. hrtim_chpr = (pChopperModeCfg->CarrierFreq & HRTIM_CHPR_CARFRQ);
  4823. hrtim_chpr |= (pChopperModeCfg->DutyCycle & HRTIM_CHPR_CARDTY);
  4824. hrtim_chpr |= (pChopperModeCfg->StartPulse & HRTIM_CHPR_STRPW);
  4825. /* Update the HRTIM registers */
  4826. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].CHPxR,
  4827. (HRTIM_CHPR_CARFRQ | HRTIM_CHPR_CARDTY | HRTIM_CHPR_STRPW),
  4828. hrtim_chpr);
  4829. hhrtim->State = HAL_HRTIM_STATE_READY;
  4830. /* Process Unlocked */
  4831. __HAL_UNLOCK(hhrtim);
  4832. return HAL_OK;
  4833. }
  4834. /**
  4835. * @brief Configure the burst DMA controller for a timer
  4836. * @param hhrtim pointer to HAL HRTIM handle
  4837. * @param TimerIdx Timer index
  4838. * This parameter can be one of the following values:
  4839. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  4840. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  4841. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  4842. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  4843. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  4844. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  4845. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  4846. * @param RegistersToUpdate registers to be written by DMA
  4847. * This parameter can be any combination of the following values:
  4848. * @arg HRTIM_BURSTDMA_CR: HRTIM_MCR or HRTIM_TIMxCR
  4849. * @arg HRTIM_BURSTDMA_ICR: HRTIM_MICR or HRTIM_TIMxICR
  4850. * @arg HRTIM_BURSTDMA_DIER: HRTIM_MDIER or HRTIM_TIMxDIER
  4851. * @arg HRTIM_BURSTDMA_CNT: HRTIM_MCNT or HRTIM_TIMxCNT
  4852. * @arg HRTIM_BURSTDMA_PER: HRTIM_MPER or HRTIM_TIMxPER
  4853. * @arg HRTIM_BURSTDMA_REP: HRTIM_MREP or HRTIM_TIMxREP
  4854. * @arg HRTIM_BURSTDMA_CMP1: HRTIM_MCMP1 or HRTIM_TIMxCMP1
  4855. * @arg HRTIM_BURSTDMA_CMP2: HRTIM_MCMP2 or HRTIM_TIMxCMP2
  4856. * @arg HRTIM_BURSTDMA_CMP3: HRTIM_MCMP3 or HRTIM_TIMxCMP3
  4857. * @arg HRTIM_BURSTDMA_CMP4: HRTIM_MCMP4 or HRTIM_TIMxCMP4
  4858. * @arg HRTIM_BURSTDMA_DTR: HRTIM_TIMxDTR
  4859. * @arg HRTIM_BURSTDMA_SET1R: HRTIM_TIMxSET1R
  4860. * @arg HRTIM_BURSTDMA_RST1R: HRTIM_TIMxRST1R
  4861. * @arg HRTIM_BURSTDMA_SET2R: HRTIM_TIMxSET2R
  4862. * @arg HRTIM_BURSTDMA_RST2R: HRTIM_TIMxRST2R
  4863. * @arg HRTIM_BURSTDMA_EEFR1: HRTIM_TIMxEEFR1
  4864. * @arg HRTIM_BURSTDMA_EEFR2: HRTIM_TIMxEEFR2
  4865. * @arg HRTIM_BURSTDMA_RSTR: HRTIM_TIMxRSTR
  4866. * @arg HRTIM_BURSTDMA_CHPR: HRTIM_TIMxCHPR
  4867. * @arg HRTIM_BURSTDMA_OUTR: HRTIM_TIMxOUTR
  4868. * @arg HRTIM_BURSTDMA_FLTR: HRTIM_TIMxFLTR
  4869. * @retval HAL status
  4870. * @note This function must be called before starting the timer
  4871. */
  4872. HAL_StatusTypeDef HAL_HRTIM_BurstDMAConfig(HRTIM_HandleTypeDef *hhrtim,
  4873. uint32_t TimerIdx,
  4874. uint32_t RegistersToUpdate)
  4875. {
  4876. /* Check parameters */
  4877. assert_param(IS_HRTIM_TIMER_BURSTDMA(TimerIdx, RegistersToUpdate));
  4878. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4879. {
  4880. return HAL_BUSY;
  4881. }
  4882. /* Process Locked */
  4883. __HAL_LOCK(hhrtim);
  4884. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4885. /* Set the burst DMA timer update register */
  4886. switch (TimerIdx)
  4887. {
  4888. case HRTIM_TIMERINDEX_TIMER_A:
  4889. {
  4890. hhrtim->Instance->sCommonRegs.BDTAUPR = RegistersToUpdate;
  4891. break;
  4892. }
  4893. case HRTIM_TIMERINDEX_TIMER_B:
  4894. {
  4895. hhrtim->Instance->sCommonRegs.BDTBUPR = RegistersToUpdate;
  4896. break;
  4897. }
  4898. case HRTIM_TIMERINDEX_TIMER_C:
  4899. {
  4900. hhrtim->Instance->sCommonRegs.BDTCUPR = RegistersToUpdate;
  4901. break;
  4902. }
  4903. case HRTIM_TIMERINDEX_TIMER_D:
  4904. {
  4905. hhrtim->Instance->sCommonRegs.BDTDUPR = RegistersToUpdate;
  4906. break;
  4907. }
  4908. case HRTIM_TIMERINDEX_TIMER_E:
  4909. {
  4910. hhrtim->Instance->sCommonRegs.BDTEUPR = RegistersToUpdate;
  4911. break;
  4912. }
  4913. case HRTIM_TIMERINDEX_TIMER_F:
  4914. {
  4915. hhrtim->Instance->sCommonRegs.BDTFUPR = RegistersToUpdate;
  4916. break;
  4917. }
  4918. case HRTIM_TIMERINDEX_MASTER:
  4919. {
  4920. hhrtim->Instance->sCommonRegs.BDMUPR = RegistersToUpdate;
  4921. break;
  4922. }
  4923. default:
  4924. {
  4925. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  4926. /* Process Unlocked */
  4927. __HAL_UNLOCK(hhrtim);
  4928. break;
  4929. }
  4930. }
  4931. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  4932. {
  4933. return HAL_ERROR;
  4934. }
  4935. hhrtim->State = HAL_HRTIM_STATE_READY;
  4936. /* Process Unlocked */
  4937. __HAL_UNLOCK(hhrtim);
  4938. return HAL_OK;
  4939. }
  4940. /**
  4941. * @brief Configure the compare unit of a timer operating in waveform mode
  4942. * @param hhrtim pointer to HAL HRTIM handle
  4943. * @param TimerIdx Timer index
  4944. * This parameter can be one of the following values:
  4945. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  4946. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  4947. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  4948. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  4949. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  4950. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  4951. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  4952. * @param CompareUnit Compare unit to configure
  4953. * This parameter can be one of the following values:
  4954. * @arg HRTIM_COMPAREUNIT_1: Compare unit 1
  4955. * @arg HRTIM_COMPAREUNIT_2: Compare unit 2
  4956. * @arg HRTIM_COMPAREUNIT_3: Compare unit 3
  4957. * @arg HRTIM_COMPAREUNIT_4: Compare unit 4
  4958. * @param pCompareCfg pointer to the compare unit configuration structure
  4959. * @note When auto delayed mode is required for compare unit 2 or compare unit 4,
  4960. * application has to configure separately the capture unit. Capture unit
  4961. * to configure in that case depends on the compare unit auto delayed mode
  4962. * is applied to (see below):
  4963. * Auto delayed on output compare 2: capture unit 1 must be configured
  4964. * Auto delayed on output compare 4: capture unit 2 must be configured
  4965. * @retval HAL status
  4966. * @note This function must be called before starting the timer
  4967. */
  4968. HAL_StatusTypeDef HAL_HRTIM_WaveformCompareConfig(HRTIM_HandleTypeDef *hhrtim,
  4969. uint32_t TimerIdx,
  4970. uint32_t CompareUnit,
  4971. const HRTIM_CompareCfgTypeDef *pCompareCfg)
  4972. {
  4973. /* Check parameters */
  4974. assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  4975. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4976. {
  4977. return HAL_BUSY;
  4978. }
  4979. /* Process Locked */
  4980. __HAL_LOCK(hhrtim);
  4981. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4982. /* Configure the compare unit */
  4983. if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
  4984. {
  4985. switch (CompareUnit)
  4986. {
  4987. case HRTIM_COMPAREUNIT_1:
  4988. {
  4989. hhrtim->Instance->sMasterRegs.MCMP1R = pCompareCfg->CompareValue;
  4990. break;
  4991. }
  4992. case HRTIM_COMPAREUNIT_2:
  4993. {
  4994. hhrtim->Instance->sMasterRegs.MCMP2R = pCompareCfg->CompareValue;
  4995. break;
  4996. }
  4997. case HRTIM_COMPAREUNIT_3:
  4998. {
  4999. hhrtim->Instance->sMasterRegs.MCMP3R = pCompareCfg->CompareValue;
  5000. break;
  5001. }
  5002. case HRTIM_COMPAREUNIT_4:
  5003. {
  5004. hhrtim->Instance->sMasterRegs.MCMP4R = pCompareCfg->CompareValue;
  5005. break;
  5006. }
  5007. default:
  5008. {
  5009. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  5010. /* Process Unlocked */
  5011. __HAL_UNLOCK(hhrtim);
  5012. break;
  5013. }
  5014. }
  5015. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  5016. {
  5017. return HAL_ERROR;
  5018. }
  5019. }
  5020. else
  5021. {
  5022. switch (CompareUnit)
  5023. {
  5024. case HRTIM_COMPAREUNIT_1:
  5025. {
  5026. /* Set the compare value */
  5027. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP1xR = pCompareCfg->CompareValue;
  5028. break;
  5029. }
  5030. case HRTIM_COMPAREUNIT_2:
  5031. {
  5032. /* Check parameters */
  5033. assert_param(IS_HRTIM_COMPAREUNIT_AUTODELAYEDMODE(CompareUnit, pCompareCfg->AutoDelayedMode));
  5034. /* Set the compare value */
  5035. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP2xR = pCompareCfg->CompareValue;
  5036. if (pCompareCfg->AutoDelayedMode != HRTIM_AUTODELAYEDMODE_REGULAR)
  5037. {
  5038. /* Configure auto-delayed mode */
  5039. /* DELCMP2 bitfield must be reset when reprogrammed from one value */
  5040. /* to the other to reinitialize properly the auto-delayed mechanism */
  5041. hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR &= ~HRTIM_TIMCR_DELCMP2;
  5042. hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR |= pCompareCfg->AutoDelayedMode;
  5043. /* Set the compare value for timeout compare unit (if any) */
  5044. if (pCompareCfg->AutoDelayedMode == HRTIM_AUTODELAYEDMODE_AUTODELAYED_TIMEOUTCMP1)
  5045. {
  5046. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP1xR = pCompareCfg->AutoDelayedTimeout;
  5047. }
  5048. else if (pCompareCfg->AutoDelayedMode == HRTIM_AUTODELAYEDMODE_AUTODELAYED_TIMEOUTCMP3)
  5049. {
  5050. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP3xR = pCompareCfg->AutoDelayedTimeout;
  5051. }
  5052. else
  5053. {
  5054. /* nothing to do */
  5055. }
  5056. }
  5057. else
  5058. {
  5059. /* Clear HRTIM_TIMxCR.DELCMP2 bitfield */
  5060. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR, HRTIM_TIMCR_DELCMP2, 0U);
  5061. }
  5062. break;
  5063. }
  5064. case HRTIM_COMPAREUNIT_3:
  5065. {
  5066. /* Set the compare value */
  5067. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP3xR = pCompareCfg->CompareValue;
  5068. break;
  5069. }
  5070. case HRTIM_COMPAREUNIT_4:
  5071. {
  5072. /* Check parameters */
  5073. assert_param(IS_HRTIM_COMPAREUNIT_AUTODELAYEDMODE(CompareUnit, pCompareCfg->AutoDelayedMode));
  5074. /* Set the compare value */
  5075. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP4xR = pCompareCfg->CompareValue;
  5076. if (pCompareCfg->AutoDelayedMode != HRTIM_AUTODELAYEDMODE_REGULAR)
  5077. {
  5078. /* Configure auto-delayed mode */
  5079. /* DELCMP4 bitfield must be reset when reprogrammed from one value */
  5080. /* to the other to reinitialize properly the auto-delayed mechanism */
  5081. hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR &= ~HRTIM_TIMCR_DELCMP4;
  5082. hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR |= (pCompareCfg->AutoDelayedMode << 2U);
  5083. /* Set the compare value for timeout compare unit (if any) */
  5084. if (pCompareCfg->AutoDelayedMode == HRTIM_AUTODELAYEDMODE_AUTODELAYED_TIMEOUTCMP1)
  5085. {
  5086. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP1xR = pCompareCfg->AutoDelayedTimeout;
  5087. }
  5088. else if (pCompareCfg->AutoDelayedMode == HRTIM_AUTODELAYEDMODE_AUTODELAYED_TIMEOUTCMP3)
  5089. {
  5090. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP3xR = pCompareCfg->AutoDelayedTimeout;
  5091. }
  5092. else
  5093. {
  5094. /* nothing to do */
  5095. }
  5096. }
  5097. else
  5098. {
  5099. /* Clear HRTIM_TIMxCR.DELCMP4 bitfield */
  5100. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR, HRTIM_TIMCR_DELCMP4, 0U);
  5101. }
  5102. break;
  5103. }
  5104. default:
  5105. {
  5106. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  5107. /* Process Unlocked */
  5108. __HAL_UNLOCK(hhrtim);
  5109. break;
  5110. }
  5111. }
  5112. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  5113. {
  5114. return HAL_ERROR;
  5115. }
  5116. }
  5117. hhrtim->State = HAL_HRTIM_STATE_READY;
  5118. /* Process Unlocked */
  5119. __HAL_UNLOCK(hhrtim);
  5120. return HAL_OK;
  5121. }
  5122. /**
  5123. * @brief Configure the capture unit of a timer operating in waveform mode
  5124. * @param hhrtim pointer to HAL HRTIM handle
  5125. * @param TimerIdx Timer index
  5126. * This parameter can be one of the following values:
  5127. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5128. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5129. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5130. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5131. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5132. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  5133. * @param CaptureUnit Capture unit to configure
  5134. * This parameter can be one of the following values:
  5135. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  5136. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  5137. * @param pCaptureCfg pointer to the compare unit configuration structure
  5138. * @retval HAL status
  5139. * @note This function must be called before starting the timer
  5140. */
  5141. HAL_StatusTypeDef HAL_HRTIM_WaveformCaptureConfig(HRTIM_HandleTypeDef *hhrtim,
  5142. uint32_t TimerIdx,
  5143. uint32_t CaptureUnit,
  5144. const HRTIM_CaptureCfgTypeDef *pCaptureCfg)
  5145. {
  5146. uint32_t Trigger;
  5147. uint32_t TimerF_Trigger = (uint32_t)(pCaptureCfg->Trigger >> 32);
  5148. /* Check parameters */
  5149. assert_param(IS_HRTIM_TIMER_CAPTURETRIGGER(TimerIdx, (uint32_t)(pCaptureCfg->Trigger)));
  5150. assert_param(IS_HRTIM_TIMER_CAPTUREFTRIGGER(TimerIdx, TimerF_Trigger));
  5151. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  5152. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  5153. {
  5154. return HAL_BUSY;
  5155. }
  5156. /* Process Locked */
  5157. __HAL_LOCK(hhrtim);
  5158. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  5159. /* TimerF_Trigger is valid for setting other Timers than Timer F */
  5160. if (TimerIdx == HRTIM_TIMERINDEX_TIMER_A)
  5161. { Trigger = ((uint32_t)(pCaptureCfg->Trigger) & 0xFFFF0FFFU) | ((TimerF_Trigger) << HRTIM_CPT1CR_TA1SET_Pos); }
  5162. else if (TimerIdx == HRTIM_TIMERINDEX_TIMER_B)
  5163. { Trigger = ((uint32_t)(pCaptureCfg->Trigger) & 0xFFF0FFFFU) | ((TimerF_Trigger) << HRTIM_CPT1CR_TB1SET_Pos); }
  5164. else if (TimerIdx == HRTIM_TIMERINDEX_TIMER_C)
  5165. { Trigger = ((uint32_t)(pCaptureCfg->Trigger) & 0xFF0FFFFFU) | ((TimerF_Trigger) << HRTIM_CPT1CR_TC1SET_Pos); }
  5166. else if (TimerIdx == HRTIM_TIMERINDEX_TIMER_D)
  5167. { Trigger = ((uint32_t)(pCaptureCfg->Trigger) & 0xF0FFFFFFU) | ((TimerF_Trigger) << HRTIM_CPT1CR_TD1SET_Pos); }
  5168. else if (TimerIdx == HRTIM_TIMERINDEX_TIMER_E)
  5169. { Trigger = ((uint32_t)(pCaptureCfg->Trigger) & 0x0FFFFFFFU) | ((TimerF_Trigger) << HRTIM_CPT1CR_TE1SET_Pos); }
  5170. else
  5171. { Trigger = ((uint32_t)(pCaptureCfg->Trigger) & 0xFFFFFFFFU); }
  5172. /* for setting source capture on Timer F, use Trigger only (all bits are valid then) */
  5173. /* Configure the capture unit */
  5174. switch (CaptureUnit)
  5175. {
  5176. case HRTIM_CAPTUREUNIT_1:
  5177. {
  5178. WRITE_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR, Trigger);
  5179. break;
  5180. }
  5181. case HRTIM_CAPTUREUNIT_2:
  5182. {
  5183. WRITE_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR, Trigger);
  5184. break;
  5185. }
  5186. default:
  5187. {
  5188. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  5189. /* Process Unlocked */
  5190. __HAL_UNLOCK(hhrtim);
  5191. break;
  5192. }
  5193. }
  5194. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  5195. {
  5196. return HAL_ERROR;
  5197. }
  5198. hhrtim->State = HAL_HRTIM_STATE_READY;
  5199. /* Process Unlocked */
  5200. __HAL_UNLOCK(hhrtim);
  5201. return HAL_OK;
  5202. }
  5203. /**
  5204. * @brief Configure the output of a timer operating in waveform mode
  5205. * @param hhrtim pointer to HAL HRTIM handle
  5206. * @param TimerIdx Timer index
  5207. * This parameter can be one of the following values:
  5208. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5209. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5210. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5211. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5212. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5213. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  5214. * @param Output Timer output
  5215. * This parameter can be one of the following values:
  5216. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  5217. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  5218. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  5219. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  5220. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  5221. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  5222. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  5223. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  5224. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  5225. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  5226. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  5227. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  5228. * @param pOutputCfg pointer to the timer output configuration structure
  5229. * @retval HAL status
  5230. * @note This function must be called before configuring the timer and after
  5231. * configuring the deadtime insertion feature (if required).
  5232. */
  5233. HAL_StatusTypeDef HAL_HRTIM_WaveformOutputConfig(HRTIM_HandleTypeDef *hhrtim,
  5234. uint32_t TimerIdx,
  5235. uint32_t Output,
  5236. const HRTIM_OutputCfgTypeDef *pOutputCfg)
  5237. {
  5238. /* Check parameters */
  5239. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, Output));
  5240. assert_param(IS_HRTIM_OUTPUTPOLARITY(pOutputCfg->Polarity));
  5241. assert_param(IS_HRTIM_OUTPUTIDLELEVEL(pOutputCfg->IdleLevel));
  5242. assert_param(IS_HRTIM_OUTPUTIDLEMODE(pOutputCfg->IdleMode));
  5243. assert_param(IS_HRTIM_OUTPUTFAULTLEVEL(pOutputCfg->FaultLevel));
  5244. assert_param(IS_HRTIM_OUTPUTCHOPPERMODE(pOutputCfg->ChopperModeEnable));
  5245. assert_param(IS_HRTIM_OUTPUTBURSTMODEENTRY(pOutputCfg->BurstModeEntryDelayed));
  5246. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  5247. {
  5248. return HAL_BUSY;
  5249. }
  5250. /* Process Locked */
  5251. __HAL_LOCK(hhrtim);
  5252. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  5253. /* Configure the timer output */
  5254. HRTIM_OutputConfig(hhrtim,
  5255. TimerIdx,
  5256. Output,
  5257. pOutputCfg);
  5258. hhrtim->State = HAL_HRTIM_STATE_READY;
  5259. /* Process Unlocked */
  5260. __HAL_UNLOCK(hhrtim);
  5261. return HAL_OK;
  5262. }
  5263. /**
  5264. * @brief Force the timer output to its active or inactive state
  5265. * @param hhrtim pointer to HAL HRTIM handle
  5266. * @param TimerIdx Timer index
  5267. * This parameter can be one of the following values:
  5268. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5269. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5270. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5271. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5272. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5273. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  5274. * @param Output Timer output
  5275. * This parameter can be one of the following values:
  5276. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  5277. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  5278. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  5279. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  5280. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  5281. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  5282. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  5283. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  5284. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  5285. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  5286. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  5287. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  5288. * @param OutputLevel indicates whether the output is forced to its active or inactive level
  5289. * This parameter can be one of the following values:
  5290. * @arg HRTIM_OUTPUTLEVEL_ACTIVE: output is forced to its active level
  5291. * @arg HRTIM_OUTPUTLEVEL_INACTIVE: output is forced to its inactive level
  5292. * @retval HAL status
  5293. * @note The 'software set/reset trigger' bit in the output set/reset registers
  5294. * is automatically reset by hardware
  5295. */
  5296. HAL_StatusTypeDef HAL_HRTIM_WaveformSetOutputLevel(HRTIM_HandleTypeDef *hhrtim,
  5297. uint32_t TimerIdx,
  5298. uint32_t Output,
  5299. uint32_t OutputLevel)
  5300. {
  5301. /* Check parameters */
  5302. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, Output));
  5303. assert_param(IS_HRTIM_OUTPUTLEVEL(OutputLevel));
  5304. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  5305. {
  5306. return HAL_BUSY;
  5307. }
  5308. /* Process Locked */
  5309. __HAL_LOCK(hhrtim);
  5310. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  5311. /* Force timer output level */
  5312. switch (Output)
  5313. {
  5314. case HRTIM_OUTPUT_TA1:
  5315. case HRTIM_OUTPUT_TB1:
  5316. case HRTIM_OUTPUT_TC1:
  5317. case HRTIM_OUTPUT_TD1:
  5318. case HRTIM_OUTPUT_TE1:
  5319. case HRTIM_OUTPUT_TF1:
  5320. {
  5321. if (OutputLevel == HRTIM_OUTPUTLEVEL_ACTIVE)
  5322. {
  5323. /* Force output to its active state */
  5324. SET_BIT(hhrtim->Instance->sTimerxRegs[TimerIdx].SETx1R, HRTIM_SET1R_SST);
  5325. }
  5326. else
  5327. {
  5328. /* Force output to its inactive state */
  5329. SET_BIT(hhrtim->Instance->sTimerxRegs[TimerIdx].RSTx1R, HRTIM_RST1R_SRT);
  5330. }
  5331. break;
  5332. }
  5333. case HRTIM_OUTPUT_TA2:
  5334. case HRTIM_OUTPUT_TB2:
  5335. case HRTIM_OUTPUT_TC2:
  5336. case HRTIM_OUTPUT_TD2:
  5337. case HRTIM_OUTPUT_TE2:
  5338. case HRTIM_OUTPUT_TF2:
  5339. {
  5340. if (OutputLevel == HRTIM_OUTPUTLEVEL_ACTIVE)
  5341. {
  5342. /* Force output to its active state */
  5343. SET_BIT(hhrtim->Instance->sTimerxRegs[TimerIdx].SETx2R, HRTIM_SET2R_SST);
  5344. }
  5345. else
  5346. {
  5347. /* Force output to its inactive state */
  5348. SET_BIT(hhrtim->Instance->sTimerxRegs[TimerIdx].RSTx2R, HRTIM_RST2R_SRT);
  5349. }
  5350. break;
  5351. }
  5352. default:
  5353. {
  5354. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  5355. /* Process Unlocked */
  5356. __HAL_UNLOCK(hhrtim);
  5357. break;
  5358. }
  5359. }
  5360. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  5361. {
  5362. return HAL_ERROR;
  5363. }
  5364. hhrtim->State = HAL_HRTIM_STATE_READY;
  5365. /* Process Unlocked */
  5366. __HAL_UNLOCK(hhrtim);
  5367. return HAL_OK;
  5368. }
  5369. /**
  5370. * @brief Enable the generation of the waveform signal on the designated output(s)
  5371. * Outputs can be combined (ORed) to allow for simultaneous output enabling.
  5372. * @param hhrtim pointer to HAL HRTIM handle
  5373. * @param OutputsToStart Timer output(s) to enable
  5374. * This parameter can be any combination of the following values:
  5375. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  5376. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  5377. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  5378. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  5379. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  5380. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  5381. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  5382. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  5383. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  5384. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  5385. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  5386. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  5387. * @retval HAL status
  5388. */
  5389. HAL_StatusTypeDef HAL_HRTIM_WaveformOutputStart(HRTIM_HandleTypeDef *hhrtim,
  5390. uint32_t OutputsToStart)
  5391. {
  5392. /* Check the parameters */
  5393. assert_param(IS_HRTIM_OUTPUT(OutputsToStart));
  5394. /* Process Locked */
  5395. __HAL_LOCK(hhrtim);
  5396. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  5397. /* Enable the HRTIM outputs */
  5398. hhrtim->Instance->sCommonRegs.OENR |= (OutputsToStart);
  5399. hhrtim->State = HAL_HRTIM_STATE_READY;
  5400. /* Process Unlocked */
  5401. __HAL_UNLOCK(hhrtim);
  5402. return HAL_OK;
  5403. }
  5404. /**
  5405. * @brief Disable the generation of the waveform signal on the designated output(s)
  5406. * Outputs can be combined (ORed) to allow for simultaneous output disabling.
  5407. * @param hhrtim pointer to HAL HRTIM handle
  5408. * @param OutputsToStop Timer output(s) to disable
  5409. * This parameter can be any combination of the following values:
  5410. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  5411. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  5412. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  5413. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  5414. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  5415. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  5416. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  5417. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  5418. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  5419. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  5420. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  5421. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  5422. * @retval HAL status
  5423. */
  5424. HAL_StatusTypeDef HAL_HRTIM_WaveformOutputStop(HRTIM_HandleTypeDef *hhrtim,
  5425. uint32_t OutputsToStop)
  5426. {
  5427. /* Check the parameters */
  5428. assert_param(IS_HRTIM_OUTPUT(OutputsToStop));
  5429. /* Process Locked */
  5430. __HAL_LOCK(hhrtim);
  5431. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  5432. /* Enable the HRTIM outputs */
  5433. hhrtim->Instance->sCommonRegs.ODISR |= (OutputsToStop);
  5434. hhrtim->State = HAL_HRTIM_STATE_READY;
  5435. /* Process Unlocked */
  5436. __HAL_UNLOCK(hhrtim);
  5437. return HAL_OK;
  5438. }
  5439. /**
  5440. * @brief Start the counter of the designated timer(s) operating in waveform mode
  5441. * Timers can be combined (ORed) to allow for simultaneous counter start.
  5442. * @param hhrtim pointer to HAL HRTIM handle
  5443. * @param Timers Timer counter(s) to start
  5444. * This parameter can be any combination of the following values:
  5445. * @arg HRTIM_TIMERID_MASTER
  5446. * @arg HRTIM_TIMERID_TIMER_A
  5447. * @arg HRTIM_TIMERID_TIMER_B
  5448. * @arg HRTIM_TIMERID_TIMER_C
  5449. * @arg HRTIM_TIMERID_TIMER_D
  5450. * @arg HRTIM_TIMERID_TIMER_E
  5451. * @arg HRTIM_TIMERID_TIMER_F
  5452. * @retval HAL status
  5453. */
  5454. HAL_StatusTypeDef HAL_HRTIM_WaveformCountStart(HRTIM_HandleTypeDef *hhrtim,
  5455. uint32_t Timers)
  5456. {
  5457. /* Check the parameters */
  5458. assert_param(IS_HRTIM_TIMERID(Timers));
  5459. /* Process Locked */
  5460. __HAL_LOCK(hhrtim);
  5461. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  5462. /* Enable timer(s) counter */
  5463. hhrtim->Instance->sMasterRegs.MCR |= (Timers);
  5464. hhrtim->State = HAL_HRTIM_STATE_READY;
  5465. /* Process Unlocked */
  5466. __HAL_UNLOCK(hhrtim);
  5467. return HAL_OK;
  5468. }
  5469. /**
  5470. * @brief Stop the counter of the designated timer(s) operating in waveform mode
  5471. * Timers can be combined (ORed) to allow for simultaneous counter stop.
  5472. * @param hhrtim pointer to HAL HRTIM handle
  5473. * @param Timers Timer counter(s) to stop
  5474. * This parameter can be any combination of the following values:
  5475. * @arg HRTIM_TIMERID_MASTER
  5476. * @arg HRTIM_TIMERID_TIMER_A
  5477. * @arg HRTIM_TIMERID_TIMER_B
  5478. * @arg HRTIM_TIMERID_TIMER_C
  5479. * @arg HRTIM_TIMERID_TIMER_D
  5480. * @arg HRTIM_TIMERID_TIMER_E
  5481. * @arg HRTIM_TIMERID_TIMER_F
  5482. * @retval HAL status
  5483. * @note The counter of a timer is stopped only if all timer outputs are disabled
  5484. */
  5485. HAL_StatusTypeDef HAL_HRTIM_WaveformCountStop(HRTIM_HandleTypeDef *hhrtim,
  5486. uint32_t Timers)
  5487. {
  5488. /* Check the parameters */
  5489. assert_param(IS_HRTIM_TIMERID(Timers));
  5490. /* Process Locked */
  5491. __HAL_LOCK(hhrtim);
  5492. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  5493. /* Disable timer(s) counter */
  5494. hhrtim->Instance->sMasterRegs.MCR &= ~(Timers);
  5495. hhrtim->State = HAL_HRTIM_STATE_READY;
  5496. /* Process Unlocked */
  5497. __HAL_UNLOCK(hhrtim);
  5498. return HAL_OK;
  5499. }
  5500. /**
  5501. * @brief Start the counter of the designated timer(s) operating in waveform mode
  5502. * Timers can be combined (ORed) to allow for simultaneous counter start.
  5503. * @param hhrtim pointer to HAL HRTIM handle
  5504. * @param Timers Timer counter(s) to start
  5505. * This parameter can be any combination of the following values:
  5506. * @arg HRTIM_TIMERID_MASTER
  5507. * @arg HRTIM_TIMERID_TIMER_A
  5508. * @arg HRTIM_TIMERID_TIMER_B
  5509. * @arg HRTIM_TIMERID_TIMER_C
  5510. * @arg HRTIM_TIMERID_TIMER_D
  5511. * @arg HRTIM_TIMERID_TIMER_E
  5512. * @arg HRTIM_TIMERID_TIMER_F
  5513. * @note HRTIM interrupts (e.g. faults interrupts) and interrupts related
  5514. * to the timers to start are enabled within this function.
  5515. * Interrupts to enable are selected through HAL_HRTIM_WaveformTimerConfig
  5516. * function.
  5517. * @retval HAL status
  5518. */
  5519. HAL_StatusTypeDef HAL_HRTIM_WaveformCountStart_IT(HRTIM_HandleTypeDef *hhrtim,
  5520. uint32_t Timers)
  5521. {
  5522. uint8_t timer_idx;
  5523. /* Check the parameters */
  5524. assert_param(IS_HRTIM_TIMERID(Timers));
  5525. /* Process Locked */
  5526. __HAL_LOCK(hhrtim);
  5527. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  5528. /* Enable HRTIM interrupts (if required) */
  5529. __HAL_HRTIM_ENABLE_IT(hhrtim, hhrtim->Init.HRTIMInterruptRequests);
  5530. /* Enable master timer related interrupts (if required) */
  5531. if ((Timers & HRTIM_TIMERID_MASTER) != 0U)
  5532. {
  5533. __HAL_HRTIM_MASTER_ENABLE_IT(hhrtim,
  5534. hhrtim->TimerParam[HRTIM_TIMERINDEX_MASTER].InterruptRequests);
  5535. }
  5536. /* Enable timing unit related interrupts (if required) */
  5537. for (timer_idx = HRTIM_TIMERINDEX_TIMER_A ;
  5538. timer_idx < HRTIM_TIMERINDEX_MASTER ;
  5539. timer_idx++)
  5540. {
  5541. if ((Timers & TimerIdxToTimerId[timer_idx]) != 0U)
  5542. {
  5543. __HAL_HRTIM_TIMER_ENABLE_IT(hhrtim,
  5544. timer_idx,
  5545. hhrtim->TimerParam[timer_idx].InterruptRequests);
  5546. }
  5547. }
  5548. /* Enable timer(s) counter */
  5549. hhrtim->Instance->sMasterRegs.MCR |= (Timers);
  5550. hhrtim->State = HAL_HRTIM_STATE_READY;
  5551. /* Process Unlocked */
  5552. __HAL_UNLOCK(hhrtim);
  5553. return HAL_OK;
  5554. }
  5555. /**
  5556. * @brief Stop the counter of the designated timer(s) operating in waveform mode
  5557. * Timers can be combined (ORed) to allow for simultaneous counter stop.
  5558. * @param hhrtim pointer to HAL HRTIM handle
  5559. * @param Timers Timer counter(s) to stop
  5560. * This parameter can be any combination of the following values:
  5561. * @arg HRTIM_TIMERID_MASTER
  5562. * @arg HRTIM_TIMERID_TIMER_A
  5563. * @arg HRTIM_TIMERID_TIMER_B
  5564. * @arg HRTIM_TIMERID_TIMER_C
  5565. * @arg HRTIM_TIMERID_TIMER_D
  5566. * @arg HRTIM_TIMERID_TIMER_E
  5567. * @arg HRTIM_TIMERID_TIMER_F
  5568. * @retval HAL status
  5569. * @note The counter of a timer is stopped only if all timer outputs are disabled
  5570. * @note All enabled timer related interrupts are disabled.
  5571. */
  5572. HAL_StatusTypeDef HAL_HRTIM_WaveformCountStop_IT(HRTIM_HandleTypeDef *hhrtim,
  5573. uint32_t Timers)
  5574. {
  5575. /* ++ WA */
  5576. __IO uint32_t delai = (uint32_t)(0x17FU);
  5577. /* -- WA */
  5578. uint8_t timer_idx;
  5579. /* Check the parameters */
  5580. assert_param(IS_HRTIM_TIMERID(Timers));
  5581. /* Process Locked */
  5582. __HAL_LOCK(hhrtim);
  5583. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  5584. /* Disable HRTIM interrupts (if required) */
  5585. __HAL_HRTIM_DISABLE_IT(hhrtim, hhrtim->Init.HRTIMInterruptRequests);
  5586. /* Disable master timer related interrupts (if required) */
  5587. if ((Timers & HRTIM_TIMERID_MASTER) != 0U)
  5588. {
  5589. /* Interrupts enable flag must be cleared one by one */
  5590. __HAL_HRTIM_MASTER_DISABLE_IT(hhrtim, hhrtim->TimerParam[HRTIM_TIMERINDEX_MASTER].InterruptRequests);
  5591. }
  5592. /* Disable timing unit related interrupts (if required) */
  5593. for (timer_idx = HRTIM_TIMERINDEX_TIMER_A ;
  5594. timer_idx < HRTIM_TIMERINDEX_MASTER ;
  5595. timer_idx++)
  5596. {
  5597. if ((Timers & TimerIdxToTimerId[timer_idx]) != 0U)
  5598. {
  5599. __HAL_HRTIM_TIMER_DISABLE_IT(hhrtim, timer_idx, hhrtim->TimerParam[timer_idx].InterruptRequests);
  5600. }
  5601. }
  5602. /* ++ WA */
  5603. do { delai--; } while (delai != 0U);
  5604. /* -- WA */
  5605. /* Disable timer(s) counter */
  5606. hhrtim->Instance->sMasterRegs.MCR &= ~(Timers);
  5607. hhrtim->State = HAL_HRTIM_STATE_READY;
  5608. /* Process Unlocked */
  5609. __HAL_UNLOCK(hhrtim);
  5610. return HAL_OK;
  5611. }
  5612. /**
  5613. * @brief Start the counter of the designated timer(s) operating in waveform mode
  5614. * Timers can be combined (ORed) to allow for simultaneous counter start.
  5615. * @param hhrtim pointer to HAL HRTIM handle
  5616. * @param Timers Timer counter(s) to start
  5617. * This parameter can be any combination of the following values:
  5618. * @arg HRTIM_TIMERID_MASTER
  5619. * @arg HRTIM_TIMERID_TIMER_A
  5620. * @arg HRTIM_TIMERID_TIMER_B
  5621. * @arg HRTIM_TIMERID_TIMER_C
  5622. * @arg HRTIM_TIMERID_TIMER_D
  5623. * @arg HRTIM_TIMERID_TIMER_E
  5624. * @arg HRTIM_TIMERID_TIMER_F
  5625. * @retval HAL status
  5626. * @note This function enables the dma request(s) mentioned in the timer
  5627. * configuration data structure for every timers to start.
  5628. * @note The source memory address, the destination memory address and the
  5629. * size of each DMA transfer are specified at timer configuration time
  5630. * (see HAL_HRTIM_WaveformTimerConfig)
  5631. */
  5632. HAL_StatusTypeDef HAL_HRTIM_WaveformCountStart_DMA(HRTIM_HandleTypeDef *hhrtim,
  5633. uint32_t Timers)
  5634. {
  5635. uint8_t timer_idx;
  5636. DMA_HandleTypeDef *hdma;
  5637. /* Check the parameters */
  5638. assert_param(IS_HRTIM_TIMERID(Timers));
  5639. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  5640. {
  5641. return HAL_BUSY;
  5642. }
  5643. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  5644. /* Process Locked */
  5645. __HAL_LOCK(hhrtim);
  5646. if (((Timers & HRTIM_TIMERID_MASTER) != (uint32_t)RESET) &&
  5647. (hhrtim->TimerParam[HRTIM_TIMERINDEX_MASTER].DMARequests != 0U))
  5648. {
  5649. /* Set the DMA error callback */
  5650. hhrtim->hdmaMaster->XferErrorCallback = HRTIM_DMAError ;
  5651. /* Set the DMA transfer completed callback */
  5652. hhrtim->hdmaMaster->XferCpltCallback = HRTIM_DMAMasterCplt;
  5653. /* Enable the DMA channel */
  5654. if (HAL_DMA_Start_IT(hhrtim->hdmaMaster,
  5655. hhrtim->TimerParam[HRTIM_TIMERINDEX_MASTER].DMASrcAddress,
  5656. hhrtim->TimerParam[HRTIM_TIMERINDEX_MASTER].DMADstAddress,
  5657. hhrtim->TimerParam[HRTIM_TIMERINDEX_MASTER].DMASize) != HAL_OK)
  5658. {
  5659. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  5660. /* Process Unlocked */
  5661. __HAL_UNLOCK(hhrtim);
  5662. return HAL_ERROR;
  5663. }
  5664. /* Enable the timer DMA request */
  5665. __HAL_HRTIM_MASTER_ENABLE_DMA(hhrtim,
  5666. hhrtim->TimerParam[HRTIM_TIMERINDEX_MASTER].DMARequests);
  5667. }
  5668. for (timer_idx = HRTIM_TIMERINDEX_TIMER_A ;
  5669. timer_idx < HRTIM_TIMERINDEX_MASTER ;
  5670. timer_idx++)
  5671. {
  5672. if (((Timers & TimerIdxToTimerId[timer_idx]) != (uint32_t)RESET) &&
  5673. (hhrtim->TimerParam[timer_idx].DMARequests != 0U))
  5674. {
  5675. /* Get the timer DMA handler */
  5676. hdma = HRTIM_GetDMAHandleFromTimerIdx(hhrtim, timer_idx);
  5677. if (hdma == NULL)
  5678. {
  5679. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  5680. /* Process Unlocked */
  5681. __HAL_UNLOCK(hhrtim);
  5682. return HAL_ERROR;
  5683. }
  5684. /* Set the DMA error callback */
  5685. hdma->XferErrorCallback = HRTIM_DMAError ;
  5686. /* Set the DMA transfer completed callback */
  5687. hdma->XferCpltCallback = HRTIM_DMATimerxCplt;
  5688. /* Enable the DMA channel */
  5689. if (HAL_DMA_Start_IT(hdma,
  5690. hhrtim->TimerParam[timer_idx].DMASrcAddress,
  5691. hhrtim->TimerParam[timer_idx].DMADstAddress,
  5692. hhrtim->TimerParam[timer_idx].DMASize) != HAL_OK)
  5693. {
  5694. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  5695. /* Process Unlocked */
  5696. __HAL_UNLOCK(hhrtim);
  5697. return HAL_ERROR;
  5698. }
  5699. /* Enable the timer DMA request */
  5700. __HAL_HRTIM_TIMER_ENABLE_DMA(hhrtim,
  5701. timer_idx,
  5702. hhrtim->TimerParam[timer_idx].DMARequests);
  5703. }
  5704. }
  5705. /* Enable the timer counter */
  5706. __HAL_HRTIM_ENABLE(hhrtim, Timers);
  5707. hhrtim->State = HAL_HRTIM_STATE_READY;
  5708. /* Process Unlocked */
  5709. __HAL_UNLOCK(hhrtim);
  5710. return HAL_OK;
  5711. }
  5712. /**
  5713. * @brief Stop the counter of the designated timer(s) operating in waveform mode
  5714. * Timers can be combined (ORed) to allow for simultaneous counter stop.
  5715. * @param hhrtim pointer to HAL HRTIM handle
  5716. * @param Timers Timer counter(s) to stop
  5717. * This parameter can be any combination of the following values:
  5718. * @arg HRTIM_TIMERID_MASTER
  5719. * @arg HRTIM_TIMERID_TIMER_A
  5720. * @arg HRTIM_TIMERID_TIMER_B
  5721. * @arg HRTIM_TIMERID_TIMER_C
  5722. * @arg HRTIM_TIMERID_TIMER_D
  5723. * @arg HRTIM_TIMERID_TIMER_E
  5724. * @arg HRTIM_TIMERID_TIMER_F
  5725. * @retval HAL status
  5726. * @note The counter of a timer is stopped only if all timer outputs are disabled
  5727. * @note All enabled timer related DMA requests are disabled.
  5728. */
  5729. HAL_StatusTypeDef HAL_HRTIM_WaveformCountStop_DMA(HRTIM_HandleTypeDef *hhrtim,
  5730. uint32_t Timers)
  5731. {
  5732. uint8_t timer_idx;
  5733. /* Check the parameters */
  5734. assert_param(IS_HRTIM_TIMERID(Timers));
  5735. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  5736. if (((Timers & HRTIM_TIMERID_MASTER) != 0U) &&
  5737. (hhrtim->TimerParam[HRTIM_TIMERINDEX_MASTER].DMARequests != 0U))
  5738. {
  5739. /* Disable the DMA */
  5740. if (HAL_DMA_Abort(hhrtim->hdmaMaster) != HAL_OK)
  5741. {
  5742. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  5743. }
  5744. else
  5745. {
  5746. hhrtim->State = HAL_HRTIM_STATE_READY;
  5747. /* Disable the DMA request(s) */
  5748. __HAL_HRTIM_MASTER_DISABLE_DMA(hhrtim,
  5749. hhrtim->TimerParam[HRTIM_TIMERINDEX_MASTER].DMARequests);
  5750. }
  5751. }
  5752. for (timer_idx = HRTIM_TIMERINDEX_TIMER_A ;
  5753. timer_idx < HRTIM_TIMERINDEX_MASTER ;
  5754. timer_idx++)
  5755. {
  5756. if (((Timers & TimerIdxToTimerId[timer_idx]) != 0U) &&
  5757. (hhrtim->TimerParam[timer_idx].DMARequests != 0U))
  5758. {
  5759. /* Get the timer DMA handler */
  5760. /* Disable the DMA */
  5761. if (HAL_DMA_Abort(HRTIM_GetDMAHandleFromTimerIdx(hhrtim, timer_idx)) != HAL_OK)
  5762. {
  5763. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  5764. }
  5765. else
  5766. {
  5767. hhrtim->State = HAL_HRTIM_STATE_READY;
  5768. /* Disable the DMA request(s) */
  5769. __HAL_HRTIM_TIMER_DISABLE_DMA(hhrtim,
  5770. timer_idx,
  5771. hhrtim->TimerParam[timer_idx].DMARequests);
  5772. }
  5773. }
  5774. }
  5775. /* Disable the timer counter */
  5776. __HAL_HRTIM_DISABLE(hhrtim, Timers);
  5777. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  5778. {
  5779. return HAL_ERROR;
  5780. }
  5781. else
  5782. {
  5783. return HAL_OK;
  5784. }
  5785. }
  5786. /**
  5787. * @brief Enable or disables the HRTIM burst mode controller.
  5788. * @param hhrtim pointer to HAL HRTIM handle
  5789. * @param Enable Burst mode controller enabling
  5790. * This parameter can be one of the following values:
  5791. * @arg HRTIM_BURSTMODECTL_ENABLED: Burst mode enabled
  5792. * @arg HRTIM_BURSTMODECTL_DISABLED: Burst mode disabled
  5793. * @retval HAL status
  5794. * @note This function must be called after starting the timer(s)
  5795. */
  5796. HAL_StatusTypeDef HAL_HRTIM_BurstModeCtl(HRTIM_HandleTypeDef *hhrtim,
  5797. uint32_t Enable)
  5798. {
  5799. /* Check parameters */
  5800. assert_param(IS_HRTIM_BURSTMODECTL(Enable));
  5801. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  5802. {
  5803. return HAL_BUSY;
  5804. }
  5805. /* Process Locked */
  5806. __HAL_LOCK(hhrtim);
  5807. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  5808. /* Enable/Disable the burst mode controller */
  5809. MODIFY_REG(hhrtim->Instance->sCommonRegs.BMCR, HRTIM_BMCR_BME, Enable);
  5810. hhrtim->State = HAL_HRTIM_STATE_READY;
  5811. /* Process Unlocked */
  5812. __HAL_UNLOCK(hhrtim);
  5813. return HAL_OK;
  5814. }
  5815. /**
  5816. * @brief Trig the burst mode operation.
  5817. * @param hhrtim pointer to HAL HRTIM handle
  5818. * @retval HAL status
  5819. */
  5820. HAL_StatusTypeDef HAL_HRTIM_BurstModeSoftwareTrigger(HRTIM_HandleTypeDef *hhrtim)
  5821. {
  5822. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  5823. {
  5824. return HAL_BUSY;
  5825. }
  5826. /* Process Locked */
  5827. __HAL_LOCK(hhrtim);
  5828. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  5829. /* Software trigger of the burst mode controller */
  5830. SET_BIT(hhrtim->Instance->sCommonRegs.BMTRGR, HRTIM_BMTRGR_SW);
  5831. hhrtim->State = HAL_HRTIM_STATE_READY;
  5832. /* Process Unlocked */
  5833. __HAL_UNLOCK(hhrtim);
  5834. return HAL_OK;
  5835. }
  5836. /**
  5837. * @brief Trig a software capture on the designed capture unit
  5838. * @param hhrtim pointer to HAL HRTIM handle
  5839. * @param TimerIdx Timer index
  5840. * This parameter can be one of the following values:
  5841. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5842. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5843. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5844. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5845. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5846. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  5847. * @param CaptureUnit Capture unit to trig
  5848. * This parameter can be one of the following values:
  5849. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  5850. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  5851. * @retval HAL status
  5852. * @note The 'software capture' bit in the capure configuration register is
  5853. * automatically reset by hardware
  5854. */
  5855. HAL_StatusTypeDef HAL_HRTIM_SoftwareCapture(HRTIM_HandleTypeDef *hhrtim,
  5856. uint32_t TimerIdx,
  5857. uint32_t CaptureUnit)
  5858. {
  5859. /* Check parameters */
  5860. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  5861. assert_param(IS_HRTIM_CAPTUREUNIT(CaptureUnit));
  5862. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  5863. {
  5864. return HAL_BUSY;
  5865. }
  5866. /* Process Locked */
  5867. __HAL_LOCK(hhrtim);
  5868. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  5869. /* Force a software capture on concerned capture unit */
  5870. switch (CaptureUnit)
  5871. {
  5872. case HRTIM_CAPTUREUNIT_1:
  5873. {
  5874. SET_BIT(hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR, HRTIM_CPT1CR_SWCPT);
  5875. break;
  5876. }
  5877. case HRTIM_CAPTUREUNIT_2:
  5878. {
  5879. SET_BIT(hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR, HRTIM_CPT2CR_SWCPT);
  5880. break;
  5881. }
  5882. default:
  5883. {
  5884. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  5885. /* Process Unlocked */
  5886. __HAL_UNLOCK(hhrtim);
  5887. break;
  5888. }
  5889. }
  5890. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  5891. {
  5892. return HAL_ERROR;
  5893. }
  5894. hhrtim->State = HAL_HRTIM_STATE_READY;
  5895. /* Process Unlocked */
  5896. __HAL_UNLOCK(hhrtim);
  5897. return HAL_OK;
  5898. }
  5899. /**
  5900. * @brief Trig the update of the registers of one or several timers
  5901. * @param hhrtim pointer to HAL HRTIM handle
  5902. * @param Timers timers concerned with the software register update
  5903. * This parameter can be any combination of the following values:
  5904. * @arg HRTIM_TIMERUPDATE_MASTER
  5905. * @arg HRTIM_TIMERUPDATE_A
  5906. * @arg HRTIM_TIMERUPDATE_B
  5907. * @arg HRTIM_TIMERUPDATE_C
  5908. * @arg HRTIM_TIMERUPDATE_D
  5909. * @arg HRTIM_TIMERUPDATE_E
  5910. * @arg HRTIM_TIMERUPDATE_F
  5911. * @retval HAL status
  5912. * @note The 'software update' bits in the HRTIM control register 2 register are
  5913. * automatically reset by hardware
  5914. */
  5915. HAL_StatusTypeDef HAL_HRTIM_SoftwareUpdate(HRTIM_HandleTypeDef *hhrtim,
  5916. uint32_t Timers)
  5917. {
  5918. /* Check parameters */
  5919. assert_param(IS_HRTIM_TIMERUPDATE(Timers));
  5920. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  5921. {
  5922. return HAL_BUSY;
  5923. }
  5924. /* Process Locked */
  5925. __HAL_LOCK(hhrtim);
  5926. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  5927. /* Force timer(s) registers update */
  5928. hhrtim->Instance->sCommonRegs.CR2 |= Timers;
  5929. hhrtim->State = HAL_HRTIM_STATE_READY;
  5930. /* Process Unlocked */
  5931. __HAL_UNLOCK(hhrtim);
  5932. return HAL_OK;
  5933. }
  5934. /**
  5935. * @brief Swap the Timer outputs
  5936. * @param hhrtim pointer to HAL HRTIM handle
  5937. * @param Timers timers concerned with the software register update
  5938. * This parameter can be any combination of the following values:
  5939. * @arg HRTIM_TIMERSWAP_A
  5940. * @arg HRTIM_TIMERSWAP_B
  5941. * @arg HRTIM_TIMERSWAP_C
  5942. * @arg HRTIM_TIMERSWAP_D
  5943. * @arg HRTIM_TIMERSWAP_E
  5944. * @arg HRTIM_TIMERSWAP_F
  5945. * @retval HAL status
  5946. * @note The function is not significant when the Push-pull mode is enabled (PSHPLL = 1)
  5947. */
  5948. HAL_StatusTypeDef HAL_HRTIM_SwapTimerOutput(HRTIM_HandleTypeDef *hhrtim,
  5949. uint32_t Timers)
  5950. {
  5951. /* Check parameters */
  5952. assert_param(IS_HRTIM_TIMERSWAP(Timers));
  5953. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  5954. {
  5955. return HAL_BUSY;
  5956. }
  5957. /* Process Locked */
  5958. __HAL_LOCK(hhrtim);
  5959. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  5960. /* Force timer(s) registers update */
  5961. hhrtim->Instance->sCommonRegs.CR2 |= Timers;
  5962. hhrtim->State = HAL_HRTIM_STATE_READY;
  5963. /* Process Unlocked */
  5964. __HAL_UNLOCK(hhrtim);
  5965. return HAL_OK;
  5966. }
  5967. /**
  5968. * @brief Trig the reset of one or several timers
  5969. * @param hhrtim pointer to HAL HRTIM handle
  5970. * @param Timers timers concerned with the software counter reset
  5971. * This parameter can be any combination of the following values:
  5972. * @arg HRTIM_TIMERRESET_MASTER
  5973. * @arg HRTIM_TIMERRESET_TIMER_A
  5974. * @arg HRTIM_TIMERRESET_TIMER_B
  5975. * @arg HRTIM_TIMERRESET_TIMER_C
  5976. * @arg HRTIM_TIMERRESET_TIMER_D
  5977. * @arg HRTIM_TIMERRESET_TIMER_E
  5978. * @arg HRTIM_TIMERRESET_TIMER_F
  5979. * @retval HAL status
  5980. * @note The 'software reset' bits in the HRTIM control register 2 are
  5981. * automatically reset by hardware
  5982. */
  5983. HAL_StatusTypeDef HAL_HRTIM_SoftwareReset(HRTIM_HandleTypeDef *hhrtim,
  5984. uint32_t Timers)
  5985. {
  5986. /* Check parameters */
  5987. assert_param(IS_HRTIM_TIMERRESET(Timers));
  5988. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  5989. {
  5990. return HAL_BUSY;
  5991. }
  5992. /* Process Locked */
  5993. __HAL_LOCK(hhrtim);
  5994. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  5995. /* Force timer(s) registers reset */
  5996. hhrtim->Instance->sCommonRegs.CR2 = Timers;
  5997. hhrtim->State = HAL_HRTIM_STATE_READY;
  5998. /* Process Unlocked */
  5999. __HAL_UNLOCK(hhrtim);
  6000. return HAL_OK;
  6001. }
  6002. /**
  6003. * @brief Swap the output of one or several timers
  6004. * @param hhrtim: pointer to HAL HRTIM handle
  6005. * @param Timers: timers concerned with the software register update
  6006. * This parameter can be any combination of the following values:
  6007. * @arg HRTIM_TIMERSWAP_A
  6008. * @arg HRTIM_TIMERSWAP_B
  6009. * @arg HRTIM_TIMERSWAP_C
  6010. * @arg HRTIM_TIMERSWAP_D
  6011. * @arg HRTIM_TIMERSWAP_E
  6012. * @arg HRTIM_TIMERSWAP_F
  6013. * @retval HAL status
  6014. */
  6015. HAL_StatusTypeDef HAL_HRTIM_OutputSwapEnable(HRTIM_HandleTypeDef *hhrtim,
  6016. uint32_t Timers)
  6017. {
  6018. /* Check parameters */
  6019. assert_param(IS_HRTIM_TIMERSWAP(Timers));
  6020. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  6021. {
  6022. return HAL_BUSY;
  6023. }
  6024. /* Process Locked */
  6025. __HAL_LOCK(hhrtim);
  6026. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  6027. /* Force timer(s) registers update */
  6028. hhrtim->Instance->sCommonRegs.CR2 |= Timers;
  6029. hhrtim->State = HAL_HRTIM_STATE_READY;
  6030. /* Process Unlocked */
  6031. __HAL_UNLOCK(hhrtim);
  6032. return HAL_OK;
  6033. }
  6034. /**
  6035. * @brief Un-swap the output of one or several timers
  6036. * @param hhrtim: pointer to HAL HRTIM handle
  6037. * @param Timers: timers concerned with the software register update
  6038. * This parameter can be any combination of the following values:
  6039. * @arg HRTIM_TIMERSWAP_A
  6040. * @arg HRTIM_TIMERSWAP_B
  6041. * @arg HRTIM_TIMERSWAP_C
  6042. * @arg HRTIM_TIMERSWAP_D
  6043. * @arg HRTIM_TIMERSWAP_E
  6044. * @arg HRTIM_TIMERSWAP_F
  6045. * @retval HAL status
  6046. */
  6047. HAL_StatusTypeDef HAL_HRTIM_OutputSwapDisable(HRTIM_HandleTypeDef *hhrtim,
  6048. uint32_t Timers)
  6049. {
  6050. /* Check parameters */
  6051. assert_param(IS_HRTIM_TIMERSWAP(Timers));
  6052. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  6053. {
  6054. return HAL_BUSY;
  6055. }
  6056. /* Process Locked */
  6057. __HAL_LOCK(hhrtim);
  6058. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  6059. /* Force timer(s) registers update */
  6060. hhrtim->Instance->sCommonRegs.CR2 &= ~(Timers);
  6061. hhrtim->State = HAL_HRTIM_STATE_READY;
  6062. /* Process Unlocked */
  6063. __HAL_UNLOCK(hhrtim);
  6064. return HAL_OK;
  6065. }
  6066. /**
  6067. * @brief Start a burst DMA operation to update HRTIM control registers content
  6068. * @param hhrtim pointer to HAL HRTIM handle
  6069. * @param TimerIdx Timer index
  6070. * This parameter can be one of the following values:
  6071. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  6072. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  6073. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  6074. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  6075. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  6076. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  6077. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  6078. * @param BurstBufferAddress address of the buffer the HRTIM control registers
  6079. * content will be updated from.
  6080. * @param BurstBufferLength size (in WORDS) of the burst buffer.
  6081. * @retval HAL status
  6082. * @note The TimerIdx parameter determines the dma channel to be used by the
  6083. * DMA burst controller (see below)
  6084. * HRTIM_TIMERINDEX_MASTER: DMA channel 2 is used by the DMA burst controller
  6085. * HRTIM_TIMERINDEX_TIMER_A: DMA channel 3 is used by the DMA burst controller
  6086. * HRTIM_TIMERINDEX_TIMER_B: DMA channel 4 is used by the DMA burst controller
  6087. * HRTIM_TIMERINDEX_TIMER_C: DMA channel 5 is used by the DMA burst controller
  6088. * HRTIM_TIMERINDEX_TIMER_D: DMA channel 6 is used by the DMA burst controller
  6089. * HRTIM_TIMERINDEX_TIMER_E: DMA channel 7 is used by the DMA burst controller
  6090. * HRTIM_TIMERINDEX_TIMER_F: DMA channel 8 is used by the DMA burst controller
  6091. */
  6092. HAL_StatusTypeDef HAL_HRTIM_BurstDMATransfer(HRTIM_HandleTypeDef *hhrtim,
  6093. uint32_t TimerIdx,
  6094. uint32_t BurstBufferAddress,
  6095. uint32_t BurstBufferLength)
  6096. {
  6097. DMA_HandleTypeDef *hdma;
  6098. /* Check the parameters */
  6099. assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  6100. if (hhrtim->State == HAL_HRTIM_STATE_BUSY)
  6101. {
  6102. return HAL_BUSY;
  6103. }
  6104. if (hhrtim->State == HAL_HRTIM_STATE_READY)
  6105. {
  6106. if ((BurstBufferAddress == 0U) || (BurstBufferLength == 0U))
  6107. {
  6108. return HAL_ERROR;
  6109. }
  6110. else
  6111. {
  6112. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  6113. }
  6114. }
  6115. /* Process Locked */
  6116. __HAL_LOCK(hhrtim);
  6117. /* Get the timer DMA handler */
  6118. hdma = HRTIM_GetDMAHandleFromTimerIdx(hhrtim, TimerIdx);
  6119. if (hdma == NULL)
  6120. {
  6121. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  6122. /* Process Unlocked */
  6123. __HAL_UNLOCK(hhrtim);
  6124. return HAL_ERROR;
  6125. }
  6126. /* Set the DMA transfer completed callback */
  6127. hdma->XferCpltCallback = HRTIM_BurstDMACplt;
  6128. /* Set the DMA error callback */
  6129. hdma->XferErrorCallback = HRTIM_DMAError ;
  6130. /* Enable the DMA channel */
  6131. if (HAL_DMA_Start_IT(hdma,
  6132. BurstBufferAddress,
  6133. (uint32_t) &(hhrtim->Instance->sCommonRegs.BDMADR),
  6134. BurstBufferLength) != HAL_OK)
  6135. {
  6136. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  6137. /* Process Unlocked */
  6138. __HAL_UNLOCK(hhrtim);
  6139. return HAL_ERROR;
  6140. }
  6141. hhrtim->State = HAL_HRTIM_STATE_READY;
  6142. /* Process Unlocked */
  6143. __HAL_UNLOCK(hhrtim);
  6144. return HAL_OK;
  6145. }
  6146. /**
  6147. * @brief Enable the transfer from preload to active registers for one
  6148. * or several timing units (including master timer).
  6149. * @param hhrtim pointer to HAL HRTIM handle
  6150. * @param Timers Timer(s) concerned by the register preload enabling command
  6151. * This parameter can be any combination of the following values:
  6152. * @arg HRTIM_TIMERUPDATE_MASTER
  6153. * @arg HRTIM_TIMERUPDATE_A
  6154. * @arg HRTIM_TIMERUPDATE_B
  6155. * @arg HRTIM_TIMERUPDATE_C
  6156. * @arg HRTIM_TIMERUPDATE_D
  6157. * @arg HRTIM_TIMERUPDATE_E
  6158. * @arg HRTIM_TIMERUPDATE_E
  6159. * @retval HAL status
  6160. */
  6161. HAL_StatusTypeDef HAL_HRTIM_UpdateEnable(HRTIM_HandleTypeDef *hhrtim,
  6162. uint32_t Timers)
  6163. {
  6164. /* Check the parameters */
  6165. assert_param(IS_HRTIM_TIMERUPDATE(Timers));
  6166. /* Process Locked */
  6167. __HAL_LOCK(hhrtim);
  6168. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  6169. /* Enable timer(s) registers update */
  6170. hhrtim->Instance->sCommonRegs.CR1 &= ~(Timers);
  6171. hhrtim->State = HAL_HRTIM_STATE_READY;
  6172. /* Process Unlocked */
  6173. __HAL_UNLOCK(hhrtim);
  6174. return HAL_OK;
  6175. }
  6176. /**
  6177. * @brief Disable the transfer from preload to active registers for one
  6178. * or several timing units (including master timer).
  6179. * @param hhrtim pointer to HAL HRTIM handle
  6180. * @param Timers Timer(s) concerned by the register preload disabling command
  6181. * This parameter can be any combination of the following values:
  6182. * @arg HRTIM_TIMERUPDATE_MASTER
  6183. * @arg HRTIM_TIMERUPDATE_A
  6184. * @arg HRTIM_TIMERUPDATE_B
  6185. * @arg HRTIM_TIMERUPDATE_C
  6186. * @arg HRTIM_TIMERUPDATE_D
  6187. * @arg HRTIM_TIMERUPDATE_E
  6188. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  6189. * @retval HAL status
  6190. */
  6191. HAL_StatusTypeDef HAL_HRTIM_UpdateDisable(HRTIM_HandleTypeDef *hhrtim,
  6192. uint32_t Timers)
  6193. {
  6194. /* Check the parameters */
  6195. assert_param(IS_HRTIM_TIMERUPDATE(Timers));
  6196. /* Process Locked */
  6197. __HAL_LOCK(hhrtim);
  6198. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  6199. /* Enable timer(s) registers update */
  6200. hhrtim->Instance->sCommonRegs.CR1 |= (Timers);
  6201. hhrtim->State = HAL_HRTIM_STATE_READY;
  6202. /* Process Unlocked */
  6203. __HAL_UNLOCK(hhrtim);
  6204. return HAL_OK;
  6205. }
  6206. /**
  6207. * @}
  6208. */
  6209. /** @defgroup HRTIM_Exported_Functions_Group9 Peripheral state functions
  6210. * @brief Peripheral State functions
  6211. @verbatim
  6212. ===============================================================================
  6213. ##### Peripheral State functions #####
  6214. ===============================================================================
  6215. [..] This section provides functions used to get HRTIM or HRTIM timer
  6216. specific information:
  6217. (+) Get HRTIM HAL state
  6218. (+) Get captured value
  6219. (+) Get HRTIM timer output level
  6220. (+) Get HRTIM timer output state
  6221. (+) Get delayed protection status
  6222. (+) Get burst status
  6223. (+) Get current push-pull status
  6224. (+) Get idle push-pull status
  6225. @endverbatim
  6226. * @{
  6227. */
  6228. /**
  6229. * @brief Return the HRTIM HAL state
  6230. * @param hhrtim pointer to HAL HRTIM handle
  6231. * @retval HAL state
  6232. */
  6233. HAL_HRTIM_StateTypeDef HAL_HRTIM_GetState(const HRTIM_HandleTypeDef *hhrtim)
  6234. {
  6235. /* Return HRTIM state */
  6236. return hhrtim->State;
  6237. }
  6238. /**
  6239. * @brief Return actual value of the capture register of the designated capture unit
  6240. * @param hhrtim pointer to HAL HRTIM handle
  6241. * @param TimerIdx Timer index
  6242. * This parameter can be one of the following values:
  6243. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  6244. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  6245. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  6246. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  6247. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  6248. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  6249. * @param CaptureUnit Capture unit to trig
  6250. * This parameter can be one of the following values:
  6251. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  6252. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  6253. * @retval Captured value
  6254. */
  6255. uint32_t HAL_HRTIM_GetCapturedValue(const HRTIM_HandleTypeDef *hhrtim,
  6256. uint32_t TimerIdx,
  6257. uint32_t CaptureUnit)
  6258. {
  6259. uint32_t captured_value;
  6260. /* Check parameters */
  6261. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  6262. assert_param(IS_HRTIM_CAPTUREUNIT(CaptureUnit));
  6263. /* Read captured value */
  6264. switch (CaptureUnit)
  6265. {
  6266. case HRTIM_CAPTUREUNIT_1:
  6267. {
  6268. captured_value = hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xR & 0x0000FFFFU;
  6269. break;
  6270. }
  6271. case HRTIM_CAPTUREUNIT_2:
  6272. {
  6273. captured_value = hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xR & 0x0000FFFFU;
  6274. break;
  6275. }
  6276. default:
  6277. {
  6278. captured_value = 0xFFFFFFFFUL;
  6279. break;
  6280. }
  6281. }
  6282. return captured_value;
  6283. }
  6284. /**
  6285. * @brief Return actual value and direction of the capture register of the designated capture unit
  6286. * @param hhrtim pointer to HAL HRTIM handle
  6287. * @param TimerIdx Timer index
  6288. * This parameter can be one of the following values:
  6289. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  6290. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  6291. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  6292. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  6293. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  6294. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  6295. * @param CaptureUnit Capture unit to trig
  6296. * This parameter can be one of the following values:
  6297. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  6298. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  6299. * @retval captured value and direction structure
  6300. */
  6301. HRTIM_CaptureValueTypeDef HAL_HRTIM_GetCaptured(const HRTIM_HandleTypeDef *hhrtim,
  6302. uint32_t TimerIdx,
  6303. uint32_t CaptureUnit)
  6304. {
  6305. uint32_t tmp;
  6306. HRTIM_CaptureValueTypeDef captured;
  6307. /* Check parameters */
  6308. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  6309. assert_param(IS_HRTIM_CAPTUREUNIT(CaptureUnit));
  6310. /* Read captured value */
  6311. switch (CaptureUnit)
  6312. {
  6313. case HRTIM_CAPTUREUNIT_1:
  6314. tmp = hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xR;
  6315. captured.Value = tmp & HRTIM_CPT1R_CPT1R & 0x0000FFFFU;
  6316. captured.Dir = (((tmp & HRTIM_CPT1R_DIR) == HRTIM_CPT1R_DIR) ? 1U : 0U);
  6317. break;
  6318. case HRTIM_CAPTUREUNIT_2:
  6319. tmp = hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xR;
  6320. captured.Value = tmp & HRTIM_CPT2R_CPT2R & 0x0000FFFFU;
  6321. captured.Dir = (((tmp & HRTIM_CPT2R_DIR) == HRTIM_CPT2R_DIR) ? 1U : 0U);
  6322. break;
  6323. default:
  6324. captured.Value = 0xFFFFFFFFUL;
  6325. captured.Dir = 0xFFFFFFFFUL;
  6326. break;
  6327. }
  6328. return captured;
  6329. }
  6330. /**
  6331. * @brief Return actual direction of the capture register of the designated capture unit
  6332. * @param hhrtim pointer to HAL HRTIM handle
  6333. * @param TimerIdx Timer index
  6334. * This parameter can be one of the following values:
  6335. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  6336. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  6337. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  6338. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  6339. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  6340. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  6341. * @param CaptureUnit Capture unit to trig
  6342. * This parameter can be one of the following values:
  6343. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  6344. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  6345. * @retval captured direction
  6346. * @arg This parameter is one HRTIM_Timer_UpDown_Mode :
  6347. * @arg HRTIM_TIMERUPDOWNMODE_UP
  6348. * @arg HRTIM_TIMERUPDOWNMODE_UPDOWN
  6349. */
  6350. uint32_t HAL_HRTIM_GetCapturedDir(const HRTIM_HandleTypeDef *hhrtim,
  6351. uint32_t TimerIdx,
  6352. uint32_t CaptureUnit)
  6353. {
  6354. uint32_t tmp;
  6355. /* Check parameters */
  6356. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  6357. assert_param(IS_HRTIM_CAPTUREUNIT(CaptureUnit));
  6358. /* Read captured value */
  6359. switch (CaptureUnit)
  6360. {
  6361. case HRTIM_CAPTUREUNIT_1:
  6362. tmp = ((hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xR & HRTIM_CPT1R_DIR) >> HRTIM_CPT1R_DIR_Pos);
  6363. break;
  6364. case HRTIM_CAPTUREUNIT_2:
  6365. tmp = ((hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xR & HRTIM_CPT2R_DIR) >> HRTIM_CPT2R_DIR_Pos);
  6366. break;
  6367. default:
  6368. tmp = 0xFFFFFFFFU;
  6369. break;
  6370. }
  6371. return tmp;
  6372. }
  6373. /**
  6374. * @brief Return actual level (active or inactive) of the designated output
  6375. * @param hhrtim pointer to HAL HRTIM handle
  6376. * @param TimerIdx Timer index
  6377. * This parameter can be one of the following values:
  6378. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  6379. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  6380. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  6381. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  6382. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  6383. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  6384. * @param Output Timer output
  6385. * This parameter can be one of the following values:
  6386. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  6387. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  6388. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  6389. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  6390. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  6391. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  6392. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  6393. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  6394. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  6395. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  6396. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  6397. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  6398. * @retval Output level
  6399. * @note Returned output level is taken before the output stage (chopper,
  6400. * polarity).
  6401. */
  6402. uint32_t HAL_HRTIM_WaveformGetOutputLevel(const HRTIM_HandleTypeDef *hhrtim,
  6403. uint32_t TimerIdx,
  6404. uint32_t Output)
  6405. {
  6406. uint32_t output_level;
  6407. /* Check parameters */
  6408. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, Output));
  6409. /* Read the output level */
  6410. switch (Output)
  6411. {
  6412. case HRTIM_OUTPUT_TA1:
  6413. case HRTIM_OUTPUT_TB1:
  6414. case HRTIM_OUTPUT_TC1:
  6415. case HRTIM_OUTPUT_TD1:
  6416. case HRTIM_OUTPUT_TE1:
  6417. case HRTIM_OUTPUT_TF1:
  6418. {
  6419. if ((hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxISR & HRTIM_TIMISR_O1CPY) != (uint32_t)RESET)
  6420. {
  6421. output_level = HRTIM_OUTPUTLEVEL_ACTIVE;
  6422. }
  6423. else
  6424. {
  6425. output_level = HRTIM_OUTPUTLEVEL_INACTIVE;
  6426. }
  6427. break;
  6428. }
  6429. case HRTIM_OUTPUT_TA2:
  6430. case HRTIM_OUTPUT_TB2:
  6431. case HRTIM_OUTPUT_TC2:
  6432. case HRTIM_OUTPUT_TD2:
  6433. case HRTIM_OUTPUT_TE2:
  6434. case HRTIM_OUTPUT_TF2:
  6435. {
  6436. if ((hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxISR & HRTIM_TIMISR_O2CPY) != (uint32_t)RESET)
  6437. {
  6438. output_level = HRTIM_OUTPUTLEVEL_ACTIVE;
  6439. }
  6440. else
  6441. {
  6442. output_level = HRTIM_OUTPUTLEVEL_INACTIVE;
  6443. }
  6444. break;
  6445. }
  6446. default:
  6447. {
  6448. output_level = 0xFFFFFFFFUL;
  6449. break;
  6450. }
  6451. }
  6452. return output_level;
  6453. }
  6454. /**
  6455. * @brief Return actual state (RUN, IDLE, FAULT) of the designated output
  6456. * @param hhrtim pointer to HAL HRTIM handle
  6457. * @param TimerIdx Timer index
  6458. * This parameter can be one of the following values:
  6459. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  6460. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  6461. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  6462. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  6463. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  6464. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  6465. * @param Output Timer output
  6466. * This parameter can be one of the following values:
  6467. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  6468. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  6469. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  6470. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  6471. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  6472. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  6473. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  6474. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  6475. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  6476. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  6477. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  6478. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  6479. * @retval Output state
  6480. */
  6481. uint32_t HAL_HRTIM_WaveformGetOutputState(const HRTIM_HandleTypeDef *hhrtim,
  6482. uint32_t TimerIdx,
  6483. uint32_t Output)
  6484. {
  6485. uint32_t output_bit;
  6486. uint32_t output_state;
  6487. /* Check parameters */
  6488. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, Output));
  6489. /* Prevent unused argument(s) compilation warning */
  6490. UNUSED(TimerIdx);
  6491. /* Set output state according to output control status and output disable status */
  6492. switch (Output)
  6493. {
  6494. case HRTIM_OUTPUT_TA1:
  6495. {
  6496. output_bit = HRTIM_OENR_TA1OEN;
  6497. break;
  6498. }
  6499. case HRTIM_OUTPUT_TA2:
  6500. {
  6501. output_bit = HRTIM_OENR_TA2OEN;
  6502. break;
  6503. }
  6504. case HRTIM_OUTPUT_TB1:
  6505. {
  6506. output_bit = HRTIM_OENR_TB1OEN;
  6507. break;
  6508. }
  6509. case HRTIM_OUTPUT_TB2:
  6510. {
  6511. output_bit = HRTIM_OENR_TB2OEN;
  6512. break;
  6513. }
  6514. case HRTIM_OUTPUT_TC1:
  6515. {
  6516. output_bit = HRTIM_OENR_TC1OEN;
  6517. break;
  6518. }
  6519. case HRTIM_OUTPUT_TC2:
  6520. {
  6521. output_bit = HRTIM_OENR_TC2OEN;
  6522. break;
  6523. }
  6524. case HRTIM_OUTPUT_TD1:
  6525. {
  6526. output_bit = HRTIM_OENR_TD1OEN;
  6527. break;
  6528. }
  6529. case HRTIM_OUTPUT_TD2:
  6530. {
  6531. output_bit = HRTIM_OENR_TD2OEN;
  6532. break;
  6533. }
  6534. case HRTIM_OUTPUT_TE1:
  6535. {
  6536. output_bit = HRTIM_OENR_TE1OEN;
  6537. break;
  6538. }
  6539. case HRTIM_OUTPUT_TE2:
  6540. {
  6541. output_bit = HRTIM_OENR_TE2OEN;
  6542. break;
  6543. }
  6544. case HRTIM_OUTPUT_TF1:
  6545. {
  6546. output_bit = HRTIM_OENR_TF1OEN;
  6547. break;
  6548. }
  6549. case HRTIM_OUTPUT_TF2:
  6550. {
  6551. output_bit = HRTIM_OENR_TF2OEN;
  6552. break;
  6553. }
  6554. default:
  6555. {
  6556. output_bit = 0UL;
  6557. break;
  6558. }
  6559. }
  6560. if ((hhrtim->Instance->sCommonRegs.OENR & output_bit) != (uint32_t)RESET)
  6561. {
  6562. /* Output is enabled: output in RUN state (whatever output disable status is)*/
  6563. output_state = HRTIM_OUTPUTSTATE_RUN;
  6564. }
  6565. else
  6566. {
  6567. if ((hhrtim->Instance->sCommonRegs.ODSR & output_bit) != (uint32_t)RESET)
  6568. {
  6569. /* Output is disabled: output in FAULT state */
  6570. output_state = HRTIM_OUTPUTSTATE_FAULT;
  6571. }
  6572. else
  6573. {
  6574. /* Output is disabled: output in IDLE state */
  6575. output_state = HRTIM_OUTPUTSTATE_IDLE;
  6576. }
  6577. }
  6578. return (output_state);
  6579. }
  6580. /**
  6581. * @brief Return the level (active or inactive) of the designated output
  6582. * when the delayed protection was triggered.
  6583. * @param hhrtim pointer to HAL HRTIM handle
  6584. * @param TimerIdx Timer index
  6585. * This parameter can be one of the following values:
  6586. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  6587. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  6588. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  6589. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  6590. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  6591. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  6592. * @param Output Timer output
  6593. * This parameter can be one of the following values:
  6594. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  6595. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  6596. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  6597. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  6598. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  6599. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  6600. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  6601. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  6602. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  6603. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  6604. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  6605. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  6606. * @retval Delayed protection status
  6607. */
  6608. uint32_t HAL_HRTIM_GetDelayedProtectionStatus(const HRTIM_HandleTypeDef *hhrtim,
  6609. uint32_t TimerIdx,
  6610. uint32_t Output)
  6611. {
  6612. uint32_t delayed_protection_status;
  6613. /* Check parameters */
  6614. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, Output));
  6615. /* Read the delayed protection status */
  6616. switch (Output)
  6617. {
  6618. case HRTIM_OUTPUT_TA1:
  6619. case HRTIM_OUTPUT_TB1:
  6620. case HRTIM_OUTPUT_TC1:
  6621. case HRTIM_OUTPUT_TD1:
  6622. case HRTIM_OUTPUT_TE1:
  6623. case HRTIM_OUTPUT_TF1:
  6624. {
  6625. if ((hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxISR & HRTIM_TIMISR_O1STAT) != (uint32_t)RESET)
  6626. {
  6627. /* Output 1 was active when the delayed idle protection was triggered */
  6628. delayed_protection_status = HRTIM_OUTPUTLEVEL_ACTIVE;
  6629. }
  6630. else
  6631. {
  6632. /* Output 1 was inactive when the delayed idle protection was triggered */
  6633. delayed_protection_status = HRTIM_OUTPUTLEVEL_INACTIVE;
  6634. }
  6635. break;
  6636. }
  6637. case HRTIM_OUTPUT_TA2:
  6638. case HRTIM_OUTPUT_TB2:
  6639. case HRTIM_OUTPUT_TC2:
  6640. case HRTIM_OUTPUT_TD2:
  6641. case HRTIM_OUTPUT_TE2:
  6642. case HRTIM_OUTPUT_TF2:
  6643. {
  6644. if ((hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxISR & HRTIM_TIMISR_O2STAT) != (uint32_t)RESET)
  6645. {
  6646. /* Output 2 was active when the delayed idle protection was triggered */
  6647. delayed_protection_status = HRTIM_OUTPUTLEVEL_ACTIVE;
  6648. }
  6649. else
  6650. {
  6651. /* Output 2 was inactive when the delayed idle protection was triggered */
  6652. delayed_protection_status = HRTIM_OUTPUTLEVEL_INACTIVE;
  6653. }
  6654. break;
  6655. }
  6656. default:
  6657. {
  6658. delayed_protection_status = 0xFFFFFFFFUL;
  6659. break;
  6660. }
  6661. }
  6662. return delayed_protection_status;
  6663. }
  6664. /**
  6665. * @brief Return the actual status (active or inactive) of the burst mode controller
  6666. * @param hhrtim pointer to HAL HRTIM handle
  6667. * @retval Burst mode controller status
  6668. */
  6669. uint32_t HAL_HRTIM_GetBurstStatus(const HRTIM_HandleTypeDef *hhrtim)
  6670. {
  6671. uint32_t burst_mode_status;
  6672. /* Read burst mode status */
  6673. burst_mode_status = (hhrtim->Instance->sCommonRegs.BMCR & HRTIM_BMCR_BMSTAT);
  6674. return burst_mode_status;
  6675. }
  6676. /**
  6677. * @brief Indicate on which output the signal is currently active (when the
  6678. * push pull mode is enabled).
  6679. * @param hhrtim pointer to HAL HRTIM handle
  6680. * @param TimerIdx Timer index
  6681. * This parameter can be one of the following values:
  6682. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  6683. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  6684. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  6685. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  6686. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  6687. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  6688. * @retval Burst mode controller status
  6689. */
  6690. uint32_t HAL_HRTIM_GetCurrentPushPullStatus(const HRTIM_HandleTypeDef *hhrtim,
  6691. uint32_t TimerIdx)
  6692. {
  6693. uint32_t current_pushpull_status;
  6694. /* Check the parameters */
  6695. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  6696. /* Read current push pull status */
  6697. current_pushpull_status = (hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxISR & HRTIM_TIMISR_CPPSTAT);
  6698. return current_pushpull_status;
  6699. }
  6700. /**
  6701. * @brief Indicate on which output the signal was applied, in push-pull mode,
  6702. balanced fault mode or delayed idle mode, when the protection was triggered.
  6703. * @param hhrtim pointer to HAL HRTIM handle
  6704. * @param TimerIdx Timer index
  6705. * This parameter can be one of the following values:
  6706. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  6707. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  6708. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  6709. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  6710. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  6711. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  6712. * @retval Idle Push Pull Status
  6713. */
  6714. uint32_t HAL_HRTIM_GetIdlePushPullStatus(const HRTIM_HandleTypeDef *hhrtim,
  6715. uint32_t TimerIdx)
  6716. {
  6717. uint32_t idle_pushpull_status;
  6718. /* Check the parameters */
  6719. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  6720. /* Read current push pull status */
  6721. idle_pushpull_status = (hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxISR & HRTIM_TIMISR_IPPSTAT);
  6722. return idle_pushpull_status;
  6723. }
  6724. /**
  6725. * @}
  6726. */
  6727. /** @defgroup HRTIM_Exported_Functions_Group10 Interrupts handling
  6728. * @brief Functions called when HRTIM generates an interrupt
  6729. * 7 interrupts can be generated by the master timer:
  6730. * - Master timer registers update
  6731. * - Synchronization event received
  6732. * - Master timer repetition event
  6733. * - Master Compare 1 to 4 event
  6734. * 14 interrupts can be generated by each timing unit:
  6735. * - Delayed protection triggered
  6736. * - Counter reset or roll-over event
  6737. * - Output 1 and output 2 reset (transition active to inactive)
  6738. * - Output 1 and output 2 set (transition inactive to active)
  6739. * - Capture 1 and 2 events
  6740. * - Timing unit registers update
  6741. * - Repetition event
  6742. * - Compare 1 to 4 event
  6743. * 8 global interrupts are generated for the whole HRTIM:
  6744. * - System fault and Fault 1 to 5 (regardless of the timing unit attribution)
  6745. * - DLL calibration done
  6746. * - Burst mode period completed
  6747. @verbatim
  6748. ===============================================================================
  6749. ##### HRTIM interrupts handling #####
  6750. ===============================================================================
  6751. [..]
  6752. This subsection provides a set of functions allowing to manage the HRTIM
  6753. interrupts:
  6754. (+) HRTIM interrupt handler
  6755. (+) Callback function called when Fault1 interrupt occurs
  6756. (+) Callback function called when Fault2 interrupt occurs
  6757. (+) Callback function called when Fault3 interrupt occurs
  6758. (+) Callback function called when Fault4 interrupt occurs
  6759. (+) Callback function called when Fault5 interrupt occurs
  6760. (+) Callback function called when Fault6 interrupt occurs
  6761. (+) Callback function called when system Fault interrupt occurs
  6762. (+) Callback function called when DLL ready interrupt occurs
  6763. (+) Callback function called when burst mode period interrupt occurs
  6764. (+) Callback function called when synchronization input interrupt occurs
  6765. (+) Callback function called when a timer register update interrupt occurs
  6766. (+) Callback function called when a timer repetition interrupt occurs
  6767. (+) Callback function called when a compare 1 match interrupt occurs
  6768. (+) Callback function called when a compare 2 match interrupt occurs
  6769. (+) Callback function called when a compare 3 match interrupt occurs
  6770. (+) Callback function called when a compare 4 match interrupt occurs
  6771. (+) Callback function called when a capture 1 interrupt occurs
  6772. (+) Callback function called when a capture 2 interrupt occurs
  6773. (+) Callback function called when a delayed protection interrupt occurs
  6774. (+) Callback function called when a timer counter reset interrupt occurs
  6775. (+) Callback function called when a timer output 1 set interrupt occurs
  6776. (+) Callback function called when a timer output 1 reset interrupt occurs
  6777. (+) Callback function called when a timer output 2 set interrupt occurs
  6778. (+) Callback function called when a timer output 2 reset interrupt occurs
  6779. (+) Callback function called when a timer output 2 reset interrupt occurs
  6780. (+) Callback function called upon completion of a burst DMA transfer
  6781. (+) HRTIM callback function registration
  6782. (+) HRTIM callback function unregistration
  6783. (+) HRTIM Timer x callback function registration
  6784. (+) HRTIM Timer x callback function unregistration
  6785. @endverbatim
  6786. * @{
  6787. */
  6788. /**
  6789. * @brief This function handles HRTIM interrupt request.
  6790. * @param hhrtim pointer to HAL HRTIM handle
  6791. * @param TimerIdx Timer index
  6792. * This parameter can be any value of HRTIM_Timer_Index
  6793. * @retval None
  6794. */
  6795. void HAL_HRTIM_IRQHandler(HRTIM_HandleTypeDef *hhrtim,
  6796. uint32_t TimerIdx)
  6797. {
  6798. /* HRTIM interrupts handling */
  6799. if (TimerIdx == HRTIM_TIMERINDEX_COMMON)
  6800. {
  6801. HRTIM_HRTIM_ISR(hhrtim);
  6802. }
  6803. else if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
  6804. {
  6805. /* Master related interrupts handling */
  6806. HRTIM_Master_ISR(hhrtim);
  6807. }
  6808. else
  6809. {
  6810. /* Timing unit related interrupts handling */
  6811. HRTIM_Timer_ISR(hhrtim, TimerIdx);
  6812. }
  6813. }
  6814. /**
  6815. * @brief Callback function invoked when a fault 1 interrupt occurred
  6816. * @param hhrtim pointer to HAL HRTIM handle * @retval None
  6817. * @retval None
  6818. */
  6819. __weak void HAL_HRTIM_Fault1Callback(HRTIM_HandleTypeDef *hhrtim)
  6820. {
  6821. /* Prevent unused argument(s) compilation warning */
  6822. UNUSED(hhrtim);
  6823. /* NOTE : This function should not be modified, when the callback is needed,
  6824. the HAL_HRTIM_Fault1Callback could be implemented in the user file
  6825. */
  6826. }
  6827. /**
  6828. * @brief Callback function invoked when a fault 2 interrupt occurred
  6829. * @param hhrtim pointer to HAL HRTIM handle
  6830. * @retval None
  6831. */
  6832. __weak void HAL_HRTIM_Fault2Callback(HRTIM_HandleTypeDef *hhrtim)
  6833. {
  6834. /* Prevent unused argument(s) compilation warning */
  6835. UNUSED(hhrtim);
  6836. /* NOTE : This function should not be modified, when the callback is needed,
  6837. the HAL_HRTIM_Fault2Callback could be implemented in the user file
  6838. */
  6839. }
  6840. /**
  6841. * @brief Callback function invoked when a fault 3 interrupt occurred
  6842. * @param hhrtim pointer to HAL HRTIM handle
  6843. * @retval None
  6844. */
  6845. __weak void HAL_HRTIM_Fault3Callback(HRTIM_HandleTypeDef *hhrtim)
  6846. {
  6847. /* Prevent unused argument(s) compilation warning */
  6848. UNUSED(hhrtim);
  6849. /* NOTE : This function should not be modified, when the callback is needed,
  6850. the HAL_HRTIM_Fault3Callback could be implemented in the user file
  6851. */
  6852. }
  6853. /**
  6854. * @brief Callback function invoked when a fault 4 interrupt occurred
  6855. * @param hhrtim pointer to HAL HRTIM handle
  6856. * @retval None
  6857. */
  6858. __weak void HAL_HRTIM_Fault4Callback(HRTIM_HandleTypeDef *hhrtim)
  6859. {
  6860. /* Prevent unused argument(s) compilation warning */
  6861. UNUSED(hhrtim);
  6862. /* NOTE : This function should not be modified, when the callback is needed,
  6863. the HAL_HRTIM_Fault4Callback could be implemented in the user file
  6864. */
  6865. }
  6866. /**
  6867. * @brief Callback function invoked when a fault 5 interrupt occurred
  6868. * @param hhrtim pointer to HAL HRTIM handle
  6869. * @retval None
  6870. */
  6871. __weak void HAL_HRTIM_Fault5Callback(HRTIM_HandleTypeDef *hhrtim)
  6872. {
  6873. /* Prevent unused argument(s) compilation warning */
  6874. UNUSED(hhrtim);
  6875. /* NOTE : This function should not be modified, when the callback is needed,
  6876. the HAL_HRTIM_Fault5Callback could be implemented in the user file
  6877. */
  6878. }
  6879. /**
  6880. * @brief Callback function invoked when a fault 6 interrupt occurred
  6881. * @param hhrtim pointer to HAL HRTIM handle
  6882. * @retval None
  6883. */
  6884. __weak void HAL_HRTIM_Fault6Callback(HRTIM_HandleTypeDef *hhrtim)
  6885. {
  6886. /* Prevent unused argument(s) compilation warning */
  6887. UNUSED(hhrtim);
  6888. /* NOTE : This function should not be modified, when the callback is needed,
  6889. the HAL_HRTIM_Fault6Callback could be implemented in the user file
  6890. */
  6891. }
  6892. /**
  6893. * @brief Callback function invoked when a system fault interrupt occurred
  6894. * @param hhrtim pointer to HAL HRTIM handle
  6895. * @retval None
  6896. */
  6897. __weak void HAL_HRTIM_SystemFaultCallback(HRTIM_HandleTypeDef *hhrtim)
  6898. {
  6899. /* Prevent unused argument(s) compilation warning */
  6900. UNUSED(hhrtim);
  6901. /* NOTE : This function should not be modified, when the callback is needed,
  6902. the HAL_HRTIM_SystemFaultCallback could be implemented in the user file
  6903. */
  6904. }
  6905. /**
  6906. * @brief Callback function invoked when the DLL calibration is completed
  6907. * @param hhrtim pointer to HAL HRTIM handle
  6908. * @retval None
  6909. */
  6910. __weak void HAL_HRTIM_DLLCalibrationReadyCallback(HRTIM_HandleTypeDef *hhrtim)
  6911. {
  6912. /* Prevent unused argument(s) compilation warning */
  6913. UNUSED(hhrtim);
  6914. /* NOTE : This function should not be modified, when the callback is needed,
  6915. the HAL_HRTIM_DLLCalibrationCallback could be implemented in the user file
  6916. */
  6917. }
  6918. /**
  6919. * @brief Callback function invoked when the end of the burst mode period is reached
  6920. * @param hhrtim pointer to HAL HRTIM handle
  6921. * @retval None
  6922. */
  6923. __weak void HAL_HRTIM_BurstModePeriodCallback(HRTIM_HandleTypeDef *hhrtim)
  6924. {
  6925. /* Prevent unused argument(s) compilation warning */
  6926. UNUSED(hhrtim);
  6927. /* NOTE : This function should not be modified, when the callback is needed,
  6928. the HAL_HRTIM_BurstModeCallback could be implemented in the user file
  6929. */
  6930. }
  6931. /**
  6932. * @brief Callback function invoked when a synchronization input event is received
  6933. * @param hhrtim pointer to HAL HRTIM handle
  6934. * @retval None
  6935. */
  6936. __weak void HAL_HRTIM_SynchronizationEventCallback(HRTIM_HandleTypeDef *hhrtim)
  6937. {
  6938. /* Prevent unused argument(s) compilation warning */
  6939. UNUSED(hhrtim);
  6940. /* NOTE : This function should not be modified, when the callback is needed,
  6941. the HAL_HRTIM_SynchronizationEventCallback could be implemented in the user file
  6942. */
  6943. }
  6944. /**
  6945. * @brief Callback function invoked when timer registers are updated
  6946. * @param hhrtim pointer to HAL HRTIM handle
  6947. * @param TimerIdx Timer index
  6948. * This parameter can be one of the following values:
  6949. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  6950. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  6951. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  6952. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  6953. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  6954. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  6955. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  6956. * @retval None
  6957. */
  6958. __weak void HAL_HRTIM_RegistersUpdateCallback(HRTIM_HandleTypeDef *hhrtim,
  6959. uint32_t TimerIdx)
  6960. {
  6961. /* Prevent unused argument(s) compilation warning */
  6962. UNUSED(hhrtim);
  6963. UNUSED(TimerIdx);
  6964. /* NOTE : This function should not be modified, when the callback is needed,
  6965. the HAL_HRTIM_Master_RegistersUpdateCallback could be implemented in the user file
  6966. */
  6967. }
  6968. /**
  6969. * @brief Callback function invoked when timer repetition period has elapsed
  6970. * @param hhrtim pointer to HAL HRTIM handle
  6971. * @param TimerIdx Timer index
  6972. * This parameter can be one of the following values:
  6973. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  6974. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  6975. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  6976. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  6977. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  6978. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  6979. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  6980. * @retval None
  6981. */
  6982. __weak void HAL_HRTIM_RepetitionEventCallback(HRTIM_HandleTypeDef *hhrtim,
  6983. uint32_t TimerIdx)
  6984. {
  6985. /* Prevent unused argument(s) compilation warning */
  6986. UNUSED(hhrtim);
  6987. UNUSED(TimerIdx);
  6988. /* NOTE : This function should not be modified, when the callback is needed,
  6989. the HAL_HRTIM_Master_RepetitionEventCallback could be implemented in the user file
  6990. */
  6991. }
  6992. /**
  6993. * @brief Callback function invoked when the timer counter matches the value
  6994. * programmed in the compare 1 register
  6995. * @param hhrtim pointer to HAL HRTIM handle
  6996. * @param TimerIdx Timer index
  6997. * This parameter can be one of the following values:
  6998. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  6999. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  7000. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  7001. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  7002. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  7003. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  7004. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  7005. * @retval None
  7006. */
  7007. __weak void HAL_HRTIM_Compare1EventCallback(HRTIM_HandleTypeDef *hhrtim,
  7008. uint32_t TimerIdx)
  7009. {
  7010. /* Prevent unused argument(s) compilation warning */
  7011. UNUSED(hhrtim);
  7012. UNUSED(TimerIdx);
  7013. /* NOTE : This function should not be modified, when the callback is needed,
  7014. the HAL_HRTIM_Master_Compare1EventCallback could be implemented in the user file
  7015. */
  7016. }
  7017. /**
  7018. * @brief Callback function invoked when the timer counter matches the value
  7019. * programmed in the compare 2 register
  7020. * @param hhrtim pointer to HAL HRTIM handle
  7021. * @retval None
  7022. * @param TimerIdx Timer index
  7023. * This parameter can be one of the following values:
  7024. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  7025. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  7026. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  7027. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  7028. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  7029. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  7030. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  7031. */
  7032. __weak void HAL_HRTIM_Compare2EventCallback(HRTIM_HandleTypeDef *hhrtim,
  7033. uint32_t TimerIdx)
  7034. {
  7035. /* Prevent unused argument(s) compilation warning */
  7036. UNUSED(hhrtim);
  7037. UNUSED(TimerIdx);
  7038. /* NOTE : This function should not be modified, when the callback is needed,
  7039. the HAL_HRTIM_Master_Compare2EventCallback could be implemented in the user file
  7040. */
  7041. }
  7042. /**
  7043. * @brief Callback function invoked when the timer counter matches the value
  7044. * programmed in the compare 3 register
  7045. * @param hhrtim pointer to HAL HRTIM handle
  7046. * @param TimerIdx Timer index
  7047. * This parameter can be one of the following values:
  7048. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  7049. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  7050. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  7051. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  7052. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  7053. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  7054. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  7055. * @retval None
  7056. */
  7057. __weak void HAL_HRTIM_Compare3EventCallback(HRTIM_HandleTypeDef *hhrtim,
  7058. uint32_t TimerIdx)
  7059. {
  7060. /* Prevent unused argument(s) compilation warning */
  7061. UNUSED(hhrtim);
  7062. UNUSED(TimerIdx);
  7063. /* NOTE : This function should not be modified, when the callback is needed,
  7064. the HAL_HRTIM_Master_Compare3EventCallback could be implemented in the user file
  7065. */
  7066. }
  7067. /**
  7068. * @brief Callback function invoked when the timer counter matches the value
  7069. * programmed in the compare 4 register.
  7070. * @param hhrtim pointer to HAL HRTIM handle
  7071. * @param TimerIdx Timer index
  7072. * This parameter can be one of the following values:
  7073. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  7074. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  7075. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  7076. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  7077. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  7078. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  7079. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  7080. * @retval None
  7081. */
  7082. __weak void HAL_HRTIM_Compare4EventCallback(HRTIM_HandleTypeDef *hhrtim,
  7083. uint32_t TimerIdx)
  7084. {
  7085. /* Prevent unused argument(s) compilation warning */
  7086. UNUSED(hhrtim);
  7087. UNUSED(TimerIdx);
  7088. /* NOTE : This function should not be modified, when the callback is needed,
  7089. the HAL_HRTIM_Master_Compare4EventCallback could be implemented in the user file
  7090. */
  7091. }
  7092. /**
  7093. * @brief Callback function invoked when the timer x capture 1 event occurs
  7094. * @param hhrtim pointer to HAL HRTIM handle
  7095. * @param TimerIdx Timer index
  7096. * This parameter can be one of the following values:
  7097. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  7098. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  7099. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  7100. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  7101. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  7102. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  7103. * @retval None
  7104. */
  7105. __weak void HAL_HRTIM_Capture1EventCallback(HRTIM_HandleTypeDef *hhrtim,
  7106. uint32_t TimerIdx)
  7107. {
  7108. /* Prevent unused argument(s) compilation warning */
  7109. UNUSED(hhrtim);
  7110. UNUSED(TimerIdx);
  7111. /* NOTE : This function should not be modified, when the callback is needed,
  7112. the HAL_HRTIM_Timer_Capture1EventCallback could be implemented in the user file
  7113. */
  7114. }
  7115. /**
  7116. * @brief Callback function invoked when the timer x capture 2 event occurs
  7117. * @param hhrtim pointer to HAL HRTIM handle
  7118. * @param TimerIdx Timer index
  7119. * This parameter can be one of the following values:
  7120. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  7121. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  7122. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  7123. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  7124. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  7125. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  7126. * @retval None
  7127. */
  7128. __weak void HAL_HRTIM_Capture2EventCallback(HRTIM_HandleTypeDef *hhrtim,
  7129. uint32_t TimerIdx)
  7130. {
  7131. /* Prevent unused argument(s) compilation warning */
  7132. UNUSED(hhrtim);
  7133. UNUSED(TimerIdx);
  7134. /* NOTE : This function should not be modified, when the callback is needed,
  7135. the HAL_HRTIM_Timer_Capture2EventCallback could be implemented in the user file
  7136. */
  7137. }
  7138. /**
  7139. * @brief Callback function invoked when the delayed idle or balanced idle mode is
  7140. * entered.
  7141. * @param hhrtim pointer to HAL HRTIM handle
  7142. * @param TimerIdx Timer index
  7143. * This parameter can be one of the following values:
  7144. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  7145. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  7146. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  7147. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  7148. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  7149. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  7150. * @retval None
  7151. */
  7152. __weak void HAL_HRTIM_DelayedProtectionCallback(HRTIM_HandleTypeDef *hhrtim,
  7153. uint32_t TimerIdx)
  7154. {
  7155. /* Prevent unused argument(s) compilation warning */
  7156. UNUSED(hhrtim);
  7157. UNUSED(TimerIdx);
  7158. /* NOTE : This function should not be modified, when the callback is needed,
  7159. the HAL_HRTIM_Timer_DelayedProtectionCallback could be implemented in the user file
  7160. */
  7161. }
  7162. /**
  7163. * @brief Callback function invoked when the timer x counter reset/roll-over
  7164. * event occurs.
  7165. * @param hhrtim pointer to HAL HRTIM handle
  7166. * @param TimerIdx Timer index
  7167. * This parameter can be one of the following values:
  7168. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  7169. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  7170. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  7171. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  7172. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  7173. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  7174. * @retval None
  7175. */
  7176. __weak void HAL_HRTIM_CounterResetCallback(HRTIM_HandleTypeDef *hhrtim,
  7177. uint32_t TimerIdx)
  7178. {
  7179. /* Prevent unused argument(s) compilation warning */
  7180. UNUSED(hhrtim);
  7181. UNUSED(TimerIdx);
  7182. /* NOTE : This function should not be modified, when the callback is needed,
  7183. the HAL_HRTIM_Timer_CounterResetCallback could be implemented in the user file
  7184. */
  7185. }
  7186. /**
  7187. * @brief Callback function invoked when the timer x output 1 is set
  7188. * @param hhrtim pointer to HAL HRTIM handle
  7189. * @param TimerIdx Timer index
  7190. * This parameter can be one of the following values:
  7191. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  7192. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  7193. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  7194. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  7195. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  7196. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  7197. * @retval None
  7198. */
  7199. __weak void HAL_HRTIM_Output1SetCallback(HRTIM_HandleTypeDef *hhrtim,
  7200. uint32_t TimerIdx)
  7201. {
  7202. /* Prevent unused argument(s) compilation warning */
  7203. UNUSED(hhrtim);
  7204. UNUSED(TimerIdx);
  7205. /* NOTE : This function should not be modified, when the callback is needed,
  7206. the HAL_HRTIM_Timer_Output1SetCallback could be implemented in the user file
  7207. */
  7208. }
  7209. /**
  7210. * @brief Callback function invoked when the timer x output 1 is reset
  7211. * @param hhrtim pointer to HAL HRTIM handle
  7212. * @param TimerIdx Timer index
  7213. * This parameter can be one of the following values:
  7214. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  7215. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  7216. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  7217. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  7218. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  7219. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  7220. * @retval None
  7221. */
  7222. __weak void HAL_HRTIM_Output1ResetCallback(HRTIM_HandleTypeDef *hhrtim,
  7223. uint32_t TimerIdx)
  7224. {
  7225. /* Prevent unused argument(s) compilation warning */
  7226. UNUSED(hhrtim);
  7227. UNUSED(TimerIdx);
  7228. /* NOTE : This function should not be modified, when the callback is needed,
  7229. the HAL_HRTIM_Timer_Output1ResetCallback could be implemented in the user file
  7230. */
  7231. }
  7232. /**
  7233. * @brief Callback function invoked when the timer x output 2 is set
  7234. * @param hhrtim pointer to HAL HRTIM handle
  7235. * @param TimerIdx Timer index
  7236. * This parameter can be one of the following values:
  7237. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  7238. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  7239. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  7240. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  7241. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  7242. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  7243. * @retval None
  7244. */
  7245. __weak void HAL_HRTIM_Output2SetCallback(HRTIM_HandleTypeDef *hhrtim,
  7246. uint32_t TimerIdx)
  7247. {
  7248. /* Prevent unused argument(s) compilation warning */
  7249. UNUSED(hhrtim);
  7250. UNUSED(TimerIdx);
  7251. /* NOTE : This function should not be modified, when the callback is needed,
  7252. the HAL_HRTIM_Timer_Output2SetCallback could be implemented in the user file
  7253. */
  7254. }
  7255. /**
  7256. * @brief Callback function invoked when the timer x output 2 is reset
  7257. * @param hhrtim pointer to HAL HRTIM handle
  7258. * @param TimerIdx Timer index
  7259. * This parameter can be one of the following values:
  7260. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  7261. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  7262. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  7263. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  7264. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  7265. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  7266. * @retval None
  7267. */
  7268. __weak void HAL_HRTIM_Output2ResetCallback(HRTIM_HandleTypeDef *hhrtim,
  7269. uint32_t TimerIdx)
  7270. {
  7271. /* Prevent unused argument(s) compilation warning */
  7272. UNUSED(hhrtim);
  7273. UNUSED(TimerIdx);
  7274. /* NOTE : This function should not be modified, when the callback is needed,
  7275. the HAL_HRTIM_Timer_Output2ResetCallback could be implemented in the user file
  7276. */
  7277. }
  7278. /**
  7279. * @brief Callback function invoked when a DMA burst transfer is completed
  7280. * @param hhrtim pointer to HAL HRTIM handle
  7281. * @param TimerIdx Timer index
  7282. * This parameter can be one of the following values:
  7283. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  7284. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  7285. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  7286. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  7287. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  7288. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  7289. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  7290. * @retval None
  7291. */
  7292. __weak void HAL_HRTIM_BurstDMATransferCallback(HRTIM_HandleTypeDef *hhrtim,
  7293. uint32_t TimerIdx)
  7294. {
  7295. /* Prevent unused argument(s) compilation warning */
  7296. UNUSED(hhrtim);
  7297. UNUSED(TimerIdx);
  7298. /* NOTE : This function should not be modified, when the callback is needed,
  7299. the HAL_HRTIM_BurstDMATransferCallback could be implemented in the user file
  7300. */
  7301. }
  7302. /**
  7303. * @brief Callback function invoked when a DMA error occurs
  7304. * @param hhrtim pointer to HAL HRTIM handle
  7305. * @retval None
  7306. */
  7307. __weak void HAL_HRTIM_ErrorCallback(HRTIM_HandleTypeDef *hhrtim)
  7308. {
  7309. /* Prevent unused argument(s) compilation warning */
  7310. UNUSED(hhrtim);
  7311. /* NOTE : This function should not be modified, when the callback is needed,
  7312. the HAL_HRTIM_ErrorCallback could be implemented in the user file
  7313. */
  7314. }
  7315. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7316. /**
  7317. * @brief HRTIM callback function registration
  7318. * @param hhrtim pointer to HAL HRTIM handle
  7319. * @param CallbackID ID of the HRTIM callback function to register
  7320. * This parameter can be one of the following values:
  7321. * @arg HAL_HRTIM_FAULT1CALLBACK_CB_ID
  7322. * @arg HAL_HRTIM_FAULT2CALLBACK_CB_ID
  7323. * @arg HAL_HRTIM_FAULT3CALLBACK_CB_ID
  7324. * @arg HAL_HRTIM_FAULT4CALLBACK_CB_ID
  7325. * @arg HAL_HRTIM_FAULT5CALLBACK_CB_ID
  7326. * @arg HAL_HRTIM_FAULT6CALLBACK_CB_ID
  7327. * @arg HAL_HRTIM_SYSTEMFAULTCALLBACK_CB_ID
  7328. * @arg HAL_HRTIM_DLLCALBRATIONREADYCALLBACK_CB_ID
  7329. * @arg HAL_HRTIM_BURSTMODEPERIODCALLBACK_CB_ID
  7330. * @arg HAL_HRTIM_SYNCHRONIZATIONEVENTCALLBACK_CB_ID
  7331. * @arg HAL_HRTIM_ERRORCALLBACK_CB_ID
  7332. * @arg HAL_HRTIM_MSPINIT_CB_ID
  7333. * @arg HAL_HRTIM_MSPDEINIT_CB_ID
  7334. * @param pCallback Callback function pointer
  7335. * @retval HAL status
  7336. */
  7337. HAL_StatusTypeDef HAL_HRTIM_RegisterCallback(HRTIM_HandleTypeDef *hhrtim,
  7338. HAL_HRTIM_CallbackIDTypeDef CallbackID,
  7339. pHRTIM_CallbackTypeDef pCallback)
  7340. {
  7341. HAL_StatusTypeDef status = HAL_OK;
  7342. if (pCallback == NULL)
  7343. {
  7344. /* Update the state */
  7345. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  7346. return HAL_ERROR;
  7347. }
  7348. /* Process locked */
  7349. __HAL_LOCK(hhrtim);
  7350. if (HAL_HRTIM_STATE_READY == hhrtim->State)
  7351. {
  7352. switch (CallbackID)
  7353. {
  7354. case HAL_HRTIM_FAULT1CALLBACK_CB_ID :
  7355. hhrtim->Fault1Callback = pCallback;
  7356. break;
  7357. case HAL_HRTIM_FAULT2CALLBACK_CB_ID :
  7358. hhrtim->Fault2Callback = pCallback;
  7359. break;
  7360. case HAL_HRTIM_FAULT3CALLBACK_CB_ID :
  7361. hhrtim->Fault3Callback = pCallback;
  7362. break;
  7363. case HAL_HRTIM_FAULT4CALLBACK_CB_ID :
  7364. hhrtim->Fault4Callback = pCallback;
  7365. break;
  7366. case HAL_HRTIM_FAULT5CALLBACK_CB_ID :
  7367. hhrtim->Fault5Callback = pCallback;
  7368. break;
  7369. case HAL_HRTIM_FAULT6CALLBACK_CB_ID :
  7370. hhrtim->Fault6Callback = pCallback;
  7371. break;
  7372. case HAL_HRTIM_SYSTEMFAULTCALLBACK_CB_ID :
  7373. hhrtim->SystemFaultCallback = pCallback;
  7374. break;
  7375. case HAL_HRTIM_DLLCALBRATIONREADYCALLBACK_CB_ID :
  7376. hhrtim->DLLCalibrationReadyCallback = pCallback;
  7377. break;
  7378. case HAL_HRTIM_BURSTMODEPERIODCALLBACK_CB_ID :
  7379. hhrtim->BurstModePeriodCallback = pCallback;
  7380. break;
  7381. case HAL_HRTIM_SYNCHRONIZATIONEVENTCALLBACK_CB_ID :
  7382. hhrtim->SynchronizationEventCallback = pCallback;
  7383. break;
  7384. case HAL_HRTIM_ERRORCALLBACK_CB_ID :
  7385. hhrtim->ErrorCallback = pCallback;
  7386. break;
  7387. case HAL_HRTIM_MSPINIT_CB_ID :
  7388. hhrtim->MspInitCallback = pCallback;
  7389. break;
  7390. case HAL_HRTIM_MSPDEINIT_CB_ID :
  7391. hhrtim->MspDeInitCallback = pCallback;
  7392. break;
  7393. default :
  7394. /* Update the state */
  7395. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  7396. /* Return error status */
  7397. status = HAL_ERROR;
  7398. break;
  7399. }
  7400. }
  7401. else if (HAL_HRTIM_STATE_RESET == hhrtim->State)
  7402. {
  7403. switch (CallbackID)
  7404. {
  7405. case HAL_HRTIM_MSPINIT_CB_ID :
  7406. hhrtim->MspInitCallback = pCallback;
  7407. break;
  7408. case HAL_HRTIM_MSPDEINIT_CB_ID :
  7409. hhrtim->MspDeInitCallback = pCallback;
  7410. break;
  7411. default :
  7412. /* Update the state */
  7413. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  7414. /* Return error status */
  7415. status = HAL_ERROR;
  7416. break;
  7417. }
  7418. }
  7419. else
  7420. {
  7421. /* Update the state */
  7422. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  7423. /* Return error status */
  7424. status = HAL_ERROR;
  7425. }
  7426. /* Release Lock */
  7427. __HAL_UNLOCK(hhrtim);
  7428. return status;
  7429. }
  7430. /**
  7431. * @brief HRTIM callback function un-registration
  7432. * @param hhrtim pointer to HAL HRTIM handle
  7433. * @param CallbackID ID of the HRTIM callback function to unregister
  7434. * This parameter can be one of the following values:
  7435. * @arg HAL_HRTIM_FAULT1CALLBACK_CB_ID
  7436. * @arg HAL_HRTIM_FAULT2CALLBACK_CB_ID
  7437. * @arg HAL_HRTIM_FAULT3CALLBACK_CB_ID
  7438. * @arg HAL_HRTIM_FAULT4CALLBACK_CB_ID
  7439. * @arg HAL_HRTIM_FAULT5CALLBACK_CB_ID
  7440. * @arg HAL_HRTIM_FAULT6CALLBACK_CB_ID
  7441. * @arg HAL_HRTIM_SYSTEMFAULTCALLBACK_CB_ID
  7442. * @arg HAL_HRTIM_DLLCALBRATIONREADYCALLBACK_CB_ID
  7443. * @arg HAL_HRTIM_BURSTMODEPERIODCALLBACK_CB_ID
  7444. * @arg HAL_HRTIM_SYNCHRONIZATIONEVENTCALLBACK_CB_ID
  7445. * @arg HAL_HRTIM_ERRORCALLBACK_CB_ID
  7446. * @arg HAL_HRTIM_MSPINIT_CB_ID
  7447. * @arg HAL_HRTIM_MSPDEINIT_CB_ID
  7448. * @retval HAL status
  7449. */
  7450. HAL_StatusTypeDef HAL_HRTIM_UnRegisterCallback(HRTIM_HandleTypeDef *hhrtim,
  7451. HAL_HRTIM_CallbackIDTypeDef CallbackID)
  7452. {
  7453. HAL_StatusTypeDef status = HAL_OK;
  7454. /* Process locked */
  7455. __HAL_LOCK(hhrtim);
  7456. if (HAL_HRTIM_STATE_READY == hhrtim->State)
  7457. {
  7458. switch (CallbackID)
  7459. {
  7460. case HAL_HRTIM_FAULT1CALLBACK_CB_ID :
  7461. hhrtim->Fault1Callback = HAL_HRTIM_Fault1Callback;
  7462. break;
  7463. case HAL_HRTIM_FAULT2CALLBACK_CB_ID :
  7464. hhrtim->Fault2Callback = HAL_HRTIM_Fault2Callback;
  7465. break;
  7466. case HAL_HRTIM_FAULT3CALLBACK_CB_ID :
  7467. hhrtim->Fault3Callback = HAL_HRTIM_Fault3Callback;
  7468. break;
  7469. case HAL_HRTIM_FAULT4CALLBACK_CB_ID :
  7470. hhrtim->Fault4Callback = HAL_HRTIM_Fault4Callback;
  7471. break;
  7472. case HAL_HRTIM_FAULT5CALLBACK_CB_ID :
  7473. hhrtim->Fault5Callback = HAL_HRTIM_Fault5Callback;
  7474. break;
  7475. case HAL_HRTIM_FAULT6CALLBACK_CB_ID :
  7476. hhrtim->Fault6Callback = HAL_HRTIM_Fault6Callback;
  7477. break;
  7478. case HAL_HRTIM_SYSTEMFAULTCALLBACK_CB_ID :
  7479. hhrtim->SystemFaultCallback = HAL_HRTIM_SystemFaultCallback;
  7480. break;
  7481. case HAL_HRTIM_DLLCALBRATIONREADYCALLBACK_CB_ID :
  7482. hhrtim->DLLCalibrationReadyCallback = HAL_HRTIM_DLLCalibrationReadyCallback;
  7483. break;
  7484. case HAL_HRTIM_BURSTMODEPERIODCALLBACK_CB_ID :
  7485. hhrtim->BurstModePeriodCallback = HAL_HRTIM_BurstModePeriodCallback;
  7486. break;
  7487. case HAL_HRTIM_SYNCHRONIZATIONEVENTCALLBACK_CB_ID :
  7488. hhrtim->SynchronizationEventCallback = HAL_HRTIM_SynchronizationEventCallback;
  7489. break;
  7490. case HAL_HRTIM_ERRORCALLBACK_CB_ID :
  7491. hhrtim->ErrorCallback = HAL_HRTIM_ErrorCallback;
  7492. break;
  7493. case HAL_HRTIM_MSPINIT_CB_ID :
  7494. hhrtim->MspInitCallback = HAL_HRTIM_MspInit;
  7495. break;
  7496. case HAL_HRTIM_MSPDEINIT_CB_ID :
  7497. hhrtim->MspDeInitCallback = HAL_HRTIM_MspDeInit;
  7498. break;
  7499. default :
  7500. /* Update the state */
  7501. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  7502. /* Return error status */
  7503. status = HAL_ERROR;
  7504. break;
  7505. }
  7506. }
  7507. else if (HAL_HRTIM_STATE_RESET == hhrtim->State)
  7508. {
  7509. switch (CallbackID)
  7510. {
  7511. case HAL_HRTIM_MSPINIT_CB_ID :
  7512. hhrtim->MspInitCallback = HAL_HRTIM_MspInit;
  7513. break;
  7514. case HAL_HRTIM_MSPDEINIT_CB_ID :
  7515. hhrtim->MspDeInitCallback = HAL_HRTIM_MspDeInit;
  7516. break;
  7517. default :
  7518. /* Update the state */
  7519. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  7520. /* Return error status */
  7521. status = HAL_ERROR;
  7522. break;
  7523. }
  7524. }
  7525. else
  7526. {
  7527. /* Update the state */
  7528. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  7529. /* Return error status */
  7530. status = HAL_ERROR;
  7531. }
  7532. /* Release Lock */
  7533. __HAL_UNLOCK(hhrtim);
  7534. return status;
  7535. }
  7536. /**
  7537. * @brief HRTIM Timer x callback function registration
  7538. * @param hhrtim pointer to HAL HRTIM handle
  7539. * @param CallbackID ID of the HRTIM Timer x callback function to register
  7540. * This parameter can be one of the following values:
  7541. * @arg HAL_HRTIM_REGISTERSUPDATECALLBACK_CB_ID
  7542. * @arg HAL_HRTIM_REPETITIONEVENTCALLBACK_CB_ID
  7543. * @arg HAL_HRTIM_COMPARE1EVENTCALLBACK_CB_ID
  7544. * @arg HAL_HRTIM_COMPARE2EVENTCALLBACK_CB_ID
  7545. * @arg HAL_HRTIM_COMPARE3EVENTCALLBACK_CB_ID
  7546. * @arg HAL_HRTIM_COMPARE4EVENTCALLBACK_CB_ID
  7547. * @arg HAL_HRTIM_CAPTURE1EVENTCALLBACK_CB_ID
  7548. * @arg HAL_HRTIM_CAPTURE2EVENTCALLBACK_CB_ID
  7549. * @arg HAL_HRTIM_DELAYEDPROTECTIONCALLBACK_CB_ID
  7550. * @arg HAL_HRTIM_COUNTERRESETCALLBACK_CB_ID
  7551. * @arg HAL_HRTIM_OUTPUT1SETCALLBACK_CB_ID
  7552. * @arg HAL_HRTIM_OUTPUT1RESETCALLBACK_CB_ID
  7553. * @arg HAL_HRTIM_OUTPUT2SETCALLBACK_CB_ID
  7554. * @arg HAL_HRTIM_OUTPUT2RESETCALLBACK_CB_ID
  7555. * @arg HAL_HRTIM_BURSTDMATRANSFERCALLBACK_CB_ID
  7556. * @param pCallback Callback function pointer
  7557. * @retval HAL status
  7558. */
  7559. HAL_StatusTypeDef HAL_HRTIM_TIMxRegisterCallback(HRTIM_HandleTypeDef *hhrtim,
  7560. HAL_HRTIM_CallbackIDTypeDef CallbackID,
  7561. pHRTIM_TIMxCallbackTypeDef pCallback)
  7562. {
  7563. HAL_StatusTypeDef status = HAL_OK;
  7564. if (pCallback == NULL)
  7565. {
  7566. /* Update the state */
  7567. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  7568. return HAL_ERROR;
  7569. }
  7570. /* Process locked */
  7571. __HAL_LOCK(hhrtim);
  7572. if (HAL_HRTIM_STATE_READY == hhrtim->State)
  7573. {
  7574. switch (CallbackID)
  7575. {
  7576. case HAL_HRTIM_REGISTERSUPDATECALLBACK_CB_ID :
  7577. hhrtim->RegistersUpdateCallback = pCallback;
  7578. break;
  7579. case HAL_HRTIM_REPETITIONEVENTCALLBACK_CB_ID :
  7580. hhrtim->RepetitionEventCallback = pCallback;
  7581. break;
  7582. case HAL_HRTIM_COMPARE1EVENTCALLBACK_CB_ID :
  7583. hhrtim->Compare1EventCallback = pCallback;
  7584. break;
  7585. case HAL_HRTIM_COMPARE2EVENTCALLBACK_CB_ID :
  7586. hhrtim->Compare2EventCallback = pCallback;
  7587. break;
  7588. case HAL_HRTIM_COMPARE3EVENTCALLBACK_CB_ID :
  7589. hhrtim->Compare3EventCallback = pCallback;
  7590. break;
  7591. case HAL_HRTIM_COMPARE4EVENTCALLBACK_CB_ID :
  7592. hhrtim->Compare4EventCallback = pCallback;
  7593. break;
  7594. case HAL_HRTIM_CAPTURE1EVENTCALLBACK_CB_ID :
  7595. hhrtim->Capture1EventCallback = pCallback;
  7596. break;
  7597. case HAL_HRTIM_CAPTURE2EVENTCALLBACK_CB_ID :
  7598. hhrtim->Capture2EventCallback = pCallback;
  7599. break;
  7600. case HAL_HRTIM_DELAYEDPROTECTIONCALLBACK_CB_ID :
  7601. hhrtim->DelayedProtectionCallback = pCallback;
  7602. break;
  7603. case HAL_HRTIM_COUNTERRESETCALLBACK_CB_ID :
  7604. hhrtim->CounterResetCallback = pCallback;
  7605. break;
  7606. case HAL_HRTIM_OUTPUT1SETCALLBACK_CB_ID :
  7607. hhrtim->Output1SetCallback = pCallback;
  7608. break;
  7609. case HAL_HRTIM_OUTPUT1RESETCALLBACK_CB_ID :
  7610. hhrtim->Output1ResetCallback = pCallback;
  7611. break;
  7612. case HAL_HRTIM_OUTPUT2SETCALLBACK_CB_ID :
  7613. hhrtim->Output2SetCallback = pCallback;
  7614. break;
  7615. case HAL_HRTIM_OUTPUT2RESETCALLBACK_CB_ID :
  7616. hhrtim->Output2ResetCallback = pCallback;
  7617. break;
  7618. case HAL_HRTIM_BURSTDMATRANSFERCALLBACK_CB_ID :
  7619. hhrtim->BurstDMATransferCallback = pCallback;
  7620. break;
  7621. default :
  7622. /* Update the state */
  7623. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  7624. /* Return error status */
  7625. status = HAL_ERROR;
  7626. break;
  7627. }
  7628. }
  7629. else
  7630. {
  7631. /* Update the state */
  7632. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  7633. /* Return error status */
  7634. status = HAL_ERROR;
  7635. }
  7636. /* Release Lock */
  7637. __HAL_UNLOCK(hhrtim);
  7638. return status;
  7639. }
  7640. /**
  7641. * @brief HRTIM Timer x callback function un-registration
  7642. * @param hhrtim pointer to HAL HRTIM handle
  7643. * @param CallbackID ID of the HRTIM callback Timer x function to unregister
  7644. * This parameter can be one of the following values:
  7645. * @arg HAL_HRTIM_REGISTERSUPDATECALLBACK_CB_ID
  7646. * @arg HAL_HRTIM_REPETITIONEVENTCALLBACK_CB_ID
  7647. * @arg HAL_HRTIM_COMPARE1EVENTCALLBACK_CB_ID
  7648. * @arg HAL_HRTIM_COMPARE2EVENTCALLBACK_CB_ID
  7649. * @arg HAL_HRTIM_COMPARE3EVENTCALLBACK_CB_ID
  7650. * @arg HAL_HRTIM_COMPARE4EVENTCALLBACK_CB_ID
  7651. * @arg HAL_HRTIM_CAPTURE1EVENTCALLBACK_CB_ID
  7652. * @arg HAL_HRTIM_CAPTURE2EVENTCALLBACK_CB_ID
  7653. * @arg HAL_HRTIM_DELAYEDPROTECTIONCALLBACK_CB_ID
  7654. * @arg HAL_HRTIM_COUNTERRESETCALLBACK_CB_ID
  7655. * @arg HAL_HRTIM_OUTPUT1SETCALLBACK_CB_ID
  7656. * @arg HAL_HRTIM_OUTPUT1RESETCALLBACK_CB_ID
  7657. * @arg HAL_HRTIM_OUTPUT2SETCALLBACK_CB_ID
  7658. * @arg HAL_HRTIM_OUTPUT2RESETCALLBACK_CB_ID
  7659. * @arg HAL_HRTIM_BURSTDMATRANSFERCALLBACK_CB_ID
  7660. * @retval HAL status
  7661. */
  7662. HAL_StatusTypeDef HAL_HRTIM_TIMxUnRegisterCallback(HRTIM_HandleTypeDef *hhrtim,
  7663. HAL_HRTIM_CallbackIDTypeDef CallbackID)
  7664. {
  7665. HAL_StatusTypeDef status = HAL_OK;
  7666. /* Process locked */
  7667. __HAL_LOCK(hhrtim);
  7668. if (HAL_HRTIM_STATE_READY == hhrtim->State)
  7669. {
  7670. switch (CallbackID)
  7671. {
  7672. case HAL_HRTIM_REGISTERSUPDATECALLBACK_CB_ID :
  7673. hhrtim->RegistersUpdateCallback = HAL_HRTIM_RegistersUpdateCallback;
  7674. break;
  7675. case HAL_HRTIM_REPETITIONEVENTCALLBACK_CB_ID :
  7676. hhrtim->RepetitionEventCallback = HAL_HRTIM_RepetitionEventCallback;
  7677. break;
  7678. case HAL_HRTIM_COMPARE1EVENTCALLBACK_CB_ID :
  7679. hhrtim->Compare1EventCallback = HAL_HRTIM_Compare1EventCallback;
  7680. break;
  7681. case HAL_HRTIM_COMPARE2EVENTCALLBACK_CB_ID :
  7682. hhrtim->Compare2EventCallback = HAL_HRTIM_Compare2EventCallback;
  7683. break;
  7684. case HAL_HRTIM_COMPARE3EVENTCALLBACK_CB_ID :
  7685. hhrtim->Compare3EventCallback = HAL_HRTIM_Compare3EventCallback;
  7686. break;
  7687. case HAL_HRTIM_COMPARE4EVENTCALLBACK_CB_ID :
  7688. hhrtim->Compare4EventCallback = HAL_HRTIM_Compare4EventCallback;
  7689. break;
  7690. case HAL_HRTIM_CAPTURE1EVENTCALLBACK_CB_ID :
  7691. hhrtim->Capture1EventCallback = HAL_HRTIM_Capture1EventCallback;
  7692. break;
  7693. case HAL_HRTIM_CAPTURE2EVENTCALLBACK_CB_ID :
  7694. hhrtim->Capture2EventCallback = HAL_HRTIM_Capture2EventCallback;
  7695. break;
  7696. case HAL_HRTIM_DELAYEDPROTECTIONCALLBACK_CB_ID :
  7697. hhrtim->DelayedProtectionCallback = HAL_HRTIM_DelayedProtectionCallback;
  7698. break;
  7699. case HAL_HRTIM_COUNTERRESETCALLBACK_CB_ID :
  7700. hhrtim->CounterResetCallback = HAL_HRTIM_CounterResetCallback;
  7701. break;
  7702. case HAL_HRTIM_OUTPUT1SETCALLBACK_CB_ID :
  7703. hhrtim->Output1SetCallback = HAL_HRTIM_Output1SetCallback;
  7704. break;
  7705. case HAL_HRTIM_OUTPUT1RESETCALLBACK_CB_ID :
  7706. hhrtim->Output1ResetCallback = HAL_HRTIM_Output1ResetCallback;
  7707. break;
  7708. case HAL_HRTIM_OUTPUT2SETCALLBACK_CB_ID :
  7709. hhrtim->Output2SetCallback = HAL_HRTIM_Output2SetCallback;
  7710. break;
  7711. case HAL_HRTIM_OUTPUT2RESETCALLBACK_CB_ID :
  7712. hhrtim->Output2ResetCallback = HAL_HRTIM_Output2ResetCallback;
  7713. break;
  7714. case HAL_HRTIM_BURSTDMATRANSFERCALLBACK_CB_ID :
  7715. hhrtim->BurstDMATransferCallback = HAL_HRTIM_BurstDMATransferCallback;
  7716. break;
  7717. default :
  7718. /* Update the state */
  7719. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  7720. /* Return error status */
  7721. status = HAL_ERROR;
  7722. break;
  7723. }
  7724. }
  7725. else
  7726. {
  7727. /* Update the state */
  7728. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  7729. /* Return error status */
  7730. status = HAL_ERROR;
  7731. }
  7732. /* Release Lock */
  7733. __HAL_UNLOCK(hhrtim);
  7734. return status;
  7735. }
  7736. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7737. /**
  7738. * @}
  7739. */
  7740. /**
  7741. * @}
  7742. */
  7743. /** @addtogroup HRTIM_Private_Functions
  7744. * @{
  7745. */
  7746. /**
  7747. * @brief Configure the master timer time base
  7748. * @param hhrtim pointer to HAL HRTIM handle
  7749. * @param pTimeBaseCfg pointer to the time base configuration structure
  7750. * @retval None
  7751. */
  7752. static void HRTIM_MasterBase_Config(HRTIM_HandleTypeDef *hhrtim,
  7753. const HRTIM_TimeBaseCfgTypeDef *pTimeBaseCfg)
  7754. {
  7755. uint32_t hrtim_mcr;
  7756. /* Configure master timer */
  7757. hrtim_mcr = hhrtim->Instance->sMasterRegs.MCR;
  7758. /* Set the prescaler ratio */
  7759. hrtim_mcr &= (uint32_t) ~(HRTIM_MCR_CK_PSC);
  7760. hrtim_mcr |= (uint32_t)pTimeBaseCfg->PrescalerRatio;
  7761. /* Set the operating mode */
  7762. hrtim_mcr &= (uint32_t) ~(HRTIM_MCR_CONT | HRTIM_MCR_RETRIG);
  7763. hrtim_mcr |= (uint32_t)pTimeBaseCfg->Mode;
  7764. /* Update the HRTIM registers */
  7765. hhrtim->Instance->sMasterRegs.MCR = hrtim_mcr;
  7766. hhrtim->Instance->sMasterRegs.MPER = pTimeBaseCfg->Period;
  7767. hhrtim->Instance->sMasterRegs.MREP = pTimeBaseCfg->RepetitionCounter;
  7768. }
  7769. /**
  7770. * @brief Configure timing unit (Timer A to Timer F) time base
  7771. * @param hhrtim pointer to HAL HRTIM handle
  7772. * @param TimerIdx Timer index
  7773. * @param pTimeBaseCfg pointer to the time base configuration structure
  7774. * @retval None
  7775. */
  7776. static void HRTIM_TimingUnitBase_Config(HRTIM_HandleTypeDef *hhrtim,
  7777. uint32_t TimerIdx,
  7778. const HRTIM_TimeBaseCfgTypeDef *pTimeBaseCfg)
  7779. {
  7780. uint32_t hrtim_timcr;
  7781. /* Configure master timing unit */
  7782. hrtim_timcr = hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR;
  7783. /* Set the prescaler ratio */
  7784. hrtim_timcr &= (uint32_t) ~(HRTIM_TIMCR_CK_PSC);
  7785. hrtim_timcr |= (uint32_t)pTimeBaseCfg->PrescalerRatio;
  7786. /* Set the operating mode */
  7787. hrtim_timcr &= (uint32_t) ~(HRTIM_TIMCR_CONT | HRTIM_TIMCR_RETRIG);
  7788. hrtim_timcr |= (uint32_t)pTimeBaseCfg->Mode;
  7789. /* Update the HRTIM registers */
  7790. hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR = hrtim_timcr;
  7791. hhrtim->Instance->sTimerxRegs[TimerIdx].PERxR = pTimeBaseCfg->Period;
  7792. hhrtim->Instance->sTimerxRegs[TimerIdx].REPxR = pTimeBaseCfg->RepetitionCounter;
  7793. }
  7794. /**
  7795. * @brief Configure the master timer in waveform mode
  7796. * @param hhrtim pointer to HAL HRTIM handle
  7797. * @param pTimerCfg pointer to the timer configuration data structure
  7798. * @retval None
  7799. */
  7800. static void HRTIM_MasterWaveform_Config(HRTIM_HandleTypeDef *hhrtim,
  7801. const HRTIM_TimerCfgTypeDef *pTimerCfg)
  7802. {
  7803. uint32_t hrtim_mcr;
  7804. uint32_t hrtim_bmcr;
  7805. /* Configure master timer */
  7806. hrtim_mcr = hhrtim->Instance->sMasterRegs.MCR;
  7807. hrtim_bmcr = hhrtim->Instance->sCommonRegs.BMCR;
  7808. /* Enable/Disable the half mode */
  7809. hrtim_mcr &= ~(HRTIM_MCR_HALF);
  7810. hrtim_mcr |= pTimerCfg->HalfModeEnable;
  7811. /* INTLVD bits are set to 00 */
  7812. hrtim_mcr &= ~(HRTIM_MCR_INTLVD);
  7813. if ((pTimerCfg->HalfModeEnable == HRTIM_HALFMODE_ENABLED)
  7814. || (pTimerCfg->InterleavedMode == HRTIM_INTERLEAVED_MODE_DUAL))
  7815. {
  7816. /* INTLVD bits set to 00 */
  7817. hrtim_mcr &= ~(HRTIM_MCR_INTLVD);
  7818. hrtim_mcr |= (HRTIM_MCR_HALF);
  7819. }
  7820. else if (pTimerCfg->InterleavedMode == HRTIM_INTERLEAVED_MODE_TRIPLE)
  7821. {
  7822. hrtim_mcr |= (HRTIM_MCR_INTLVD_0);
  7823. hrtim_mcr &= ~(HRTIM_MCR_INTLVD_1);
  7824. }
  7825. else if (pTimerCfg->InterleavedMode == HRTIM_INTERLEAVED_MODE_QUAD)
  7826. {
  7827. hrtim_mcr |= (HRTIM_MCR_INTLVD_1);
  7828. hrtim_mcr &= ~(HRTIM_MCR_INTLVD_0);
  7829. }
  7830. else
  7831. {
  7832. hrtim_mcr &= ~(HRTIM_MCR_HALF);
  7833. hrtim_mcr &= ~(HRTIM_MCR_INTLVD);
  7834. }
  7835. /* Enable/Disable the timer start upon synchronization event reception */
  7836. hrtim_mcr &= ~(HRTIM_MCR_SYNCSTRTM);
  7837. hrtim_mcr |= pTimerCfg->StartOnSync;
  7838. /* Enable/Disable the timer reset upon synchronization event reception */
  7839. hrtim_mcr &= ~(HRTIM_MCR_SYNCRSTM);
  7840. hrtim_mcr |= pTimerCfg->ResetOnSync;
  7841. /* Enable/Disable the DAC synchronization event generation */
  7842. hrtim_mcr &= ~(HRTIM_MCR_DACSYNC);
  7843. hrtim_mcr |= pTimerCfg->DACSynchro;
  7844. /* Enable/Disable preload mechanism for timer registers */
  7845. hrtim_mcr &= ~(HRTIM_MCR_PREEN);
  7846. hrtim_mcr |= pTimerCfg->PreloadEnable;
  7847. /* Master timer registers update handling */
  7848. hrtim_mcr &= ~(HRTIM_MCR_BRSTDMA);
  7849. hrtim_mcr |= (pTimerCfg->UpdateGating << 2U);
  7850. /* Enable/Disable registers update on repetition */
  7851. hrtim_mcr &= ~(HRTIM_MCR_MREPU);
  7852. hrtim_mcr |= pTimerCfg->RepetitionUpdate;
  7853. /* Set the timer burst mode */
  7854. hrtim_bmcr &= ~(HRTIM_BMCR_MTBM);
  7855. hrtim_bmcr |= pTimerCfg->BurstMode;
  7856. /* Update the HRTIM registers */
  7857. hhrtim->Instance->sMasterRegs.MCR = hrtim_mcr;
  7858. hhrtim->Instance->sCommonRegs.BMCR = hrtim_bmcr;
  7859. }
  7860. /**
  7861. * @brief Configure timing unit (Timer A to Timer F) in waveform mode
  7862. * @param hhrtim pointer to HAL HRTIM handle
  7863. * @param TimerIdx Timer index
  7864. * @param pTimerCfg pointer to the timer configuration data structure
  7865. * @retval None
  7866. */
  7867. static void HRTIM_TimingUnitWaveform_Config(HRTIM_HandleTypeDef *hhrtim,
  7868. uint32_t TimerIdx,
  7869. const HRTIM_TimerCfgTypeDef *pTimerCfg)
  7870. {
  7871. uint32_t hrtim_timcr;
  7872. uint32_t hrtim_timfltr;
  7873. uint32_t hrtim_timoutr;
  7874. uint32_t hrtim_timrstr;
  7875. uint32_t hrtim_bmcr;
  7876. /* UPDGAT bitfield must be reset before programming a new value */
  7877. hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR &= ~(HRTIM_TIMCR_UPDGAT);
  7878. /* Configure timing unit (Timer A to Timer F) */
  7879. hrtim_timcr = hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR;
  7880. hrtim_timfltr = hhrtim->Instance->sTimerxRegs[TimerIdx].FLTxR;
  7881. hrtim_timoutr = hhrtim->Instance->sTimerxRegs[TimerIdx].OUTxR;
  7882. hrtim_bmcr = hhrtim->Instance->sCommonRegs.BMCR;
  7883. /* Enable/Disable the half mode */
  7884. hrtim_timcr &= ~(HRTIM_TIMCR_HALF);
  7885. hrtim_timcr |= pTimerCfg->HalfModeEnable;
  7886. if ((pTimerCfg->HalfModeEnable == HRTIM_HALFMODE_ENABLED)
  7887. || (pTimerCfg->InterleavedMode == HRTIM_INTERLEAVED_MODE_DUAL))
  7888. {
  7889. /* INTLVD bits set to 00 */
  7890. hrtim_timcr &= ~(HRTIM_TIMCR_INTLVD);
  7891. hrtim_timcr |= (HRTIM_TIMCR_HALF);
  7892. }
  7893. else if (pTimerCfg->InterleavedMode == HRTIM_INTERLEAVED_MODE_TRIPLE)
  7894. {
  7895. hrtim_timcr |= (HRTIM_TIMCR_INTLVD_0);
  7896. hrtim_timcr &= ~(HRTIM_TIMCR_INTLVD_1);
  7897. }
  7898. else if (pTimerCfg->InterleavedMode == HRTIM_INTERLEAVED_MODE_QUAD)
  7899. {
  7900. hrtim_timcr |= (HRTIM_TIMCR_INTLVD_1);
  7901. hrtim_timcr &= ~(HRTIM_TIMCR_INTLVD_0);
  7902. }
  7903. else
  7904. {
  7905. hrtim_timcr &= ~(HRTIM_TIMCR_HALF);
  7906. hrtim_timcr &= ~(HRTIM_TIMCR_INTLVD);
  7907. }
  7908. /* Enable/Disable the timer start upon synchronization event reception */
  7909. hrtim_timcr &= ~(HRTIM_TIMCR_SYNCSTRT);
  7910. hrtim_timcr |= pTimerCfg->StartOnSync;
  7911. /* Enable/Disable the timer reset upon synchronization event reception */
  7912. hrtim_timcr &= ~(HRTIM_TIMCR_SYNCRST);
  7913. hrtim_timcr |= pTimerCfg->ResetOnSync;
  7914. /* Enable/Disable the DAC synchronization event generation */
  7915. hrtim_timcr &= ~(HRTIM_TIMCR_DACSYNC);
  7916. hrtim_timcr |= pTimerCfg->DACSynchro;
  7917. /* Enable/Disable preload mechanism for timer registers */
  7918. hrtim_timcr &= ~(HRTIM_TIMCR_PREEN);
  7919. hrtim_timcr |= pTimerCfg->PreloadEnable;
  7920. /* Timing unit registers update handling */
  7921. hrtim_timcr &= ~(HRTIM_TIMCR_UPDGAT);
  7922. hrtim_timcr |= pTimerCfg->UpdateGating;
  7923. /* Enable/Disable registers update on repetition */
  7924. hrtim_timcr &= ~(HRTIM_TIMCR_TREPU);
  7925. if (pTimerCfg->RepetitionUpdate == HRTIM_UPDATEONREPETITION_ENABLED)
  7926. {
  7927. hrtim_timcr |= HRTIM_TIMCR_TREPU;
  7928. }
  7929. /* Set the push-pull mode */
  7930. hrtim_timcr &= ~(HRTIM_TIMCR_PSHPLL);
  7931. hrtim_timcr |= pTimerCfg->PushPull;
  7932. /* Enable/Disable registers update on timer counter reset */
  7933. hrtim_timcr &= ~(HRTIM_TIMCR_TRSTU);
  7934. hrtim_timcr |= pTimerCfg->ResetUpdate;
  7935. /* Set the timer update trigger */
  7936. hrtim_timcr &= ~(HRTIM_TIMCR_TIMUPDATETRIGGER);
  7937. hrtim_timcr |= pTimerCfg->UpdateTrigger;
  7938. /* Enable/Disable the fault channel at timer level */
  7939. hrtim_timfltr &= ~(HRTIM_FLTR_FLTxEN);
  7940. hrtim_timfltr |= (pTimerCfg->FaultEnable & HRTIM_FLTR_FLTxEN);
  7941. /* Lock/Unlock fault sources at timer level */
  7942. hrtim_timfltr &= ~(HRTIM_FLTR_FLTLCK);
  7943. hrtim_timfltr |= pTimerCfg->FaultLock;
  7944. /* Enable/Disable dead time insertion at timer level */
  7945. hrtim_timoutr &= ~(HRTIM_OUTR_DTEN);
  7946. hrtim_timoutr |= pTimerCfg->DeadTimeInsertion;
  7947. /* Enable/Disable delayed protection at timer level
  7948. Delayed Idle is available whatever the timer operating mode (regular, push-pull)
  7949. Balanced Idle is only available in push-pull mode
  7950. */
  7951. if (((pTimerCfg->DelayedProtectionMode != HRTIM_TIMER_A_B_C_DELAYEDPROTECTION_BALANCED_EEV6)
  7952. && (pTimerCfg->DelayedProtectionMode != HRTIM_TIMER_A_B_C_DELAYEDPROTECTION_BALANCED_EEV7))
  7953. || (pTimerCfg->PushPull == HRTIM_TIMPUSHPULLMODE_ENABLED))
  7954. {
  7955. hrtim_timoutr &= ~(HRTIM_OUTR_DLYPRT | HRTIM_OUTR_DLYPRTEN);
  7956. hrtim_timoutr |= pTimerCfg->DelayedProtectionMode;
  7957. }
  7958. /* Set the BIAR mode : one bit for both outputs */
  7959. hrtim_timoutr &= ~(HRTIM_OUTR_BIAR);
  7960. hrtim_timoutr |= (pTimerCfg->BalancedIdleAutomaticResume);
  7961. /* Set the timer counter reset trigger */
  7962. hrtim_timrstr = pTimerCfg->ResetTrigger;
  7963. /* Set the timer burst mode */
  7964. switch (TimerIdx)
  7965. {
  7966. case HRTIM_TIMERINDEX_TIMER_A:
  7967. {
  7968. hrtim_bmcr &= ~(HRTIM_BMCR_TABM);
  7969. hrtim_bmcr |= (pTimerCfg->BurstMode << 1U);
  7970. break;
  7971. }
  7972. case HRTIM_TIMERINDEX_TIMER_B:
  7973. {
  7974. hrtim_bmcr &= ~(HRTIM_BMCR_TBBM);
  7975. hrtim_bmcr |= (pTimerCfg->BurstMode << 2U);
  7976. break;
  7977. }
  7978. case HRTIM_TIMERINDEX_TIMER_C:
  7979. {
  7980. hrtim_bmcr &= ~(HRTIM_BMCR_TCBM);
  7981. hrtim_bmcr |= (pTimerCfg->BurstMode << 3U);
  7982. break;
  7983. }
  7984. case HRTIM_TIMERINDEX_TIMER_D:
  7985. {
  7986. hrtim_bmcr &= ~(HRTIM_BMCR_TDBM);
  7987. hrtim_bmcr |= (pTimerCfg->BurstMode << 4U);
  7988. break;
  7989. }
  7990. case HRTIM_TIMERINDEX_TIMER_E:
  7991. {
  7992. hrtim_bmcr &= ~(HRTIM_BMCR_TEBM);
  7993. hrtim_bmcr |= (pTimerCfg->BurstMode << 5U);
  7994. break;
  7995. }
  7996. case HRTIM_TIMERINDEX_TIMER_F:
  7997. {
  7998. hrtim_bmcr &= ~(HRTIM_BMCR_TFBM);
  7999. hrtim_bmcr |= (pTimerCfg->BurstMode << 6U);
  8000. break;
  8001. }
  8002. default:
  8003. break;
  8004. }
  8005. /* Update the HRTIM registers */
  8006. hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR = hrtim_timcr;
  8007. hhrtim->Instance->sTimerxRegs[TimerIdx].FLTxR = hrtim_timfltr;
  8008. hhrtim->Instance->sTimerxRegs[TimerIdx].OUTxR = hrtim_timoutr;
  8009. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = hrtim_timrstr;
  8010. hhrtim->Instance->sCommonRegs.BMCR = hrtim_bmcr;
  8011. }
  8012. /**
  8013. * @brief Control timing unit (timer A to timer F) in waveform mode
  8014. * @param hhrtim pointer to HAL HRTIM handle
  8015. * @param TimerIdx Timer index
  8016. * @param pTimerCtl pointer to the timer configuration data structure
  8017. * @retval None
  8018. */
  8019. static void HRTIM_TimingUnitWaveform_Control(HRTIM_HandleTypeDef *hhrtim,
  8020. uint32_t TimerIdx,
  8021. const HRTIM_TimerCtlTypeDef *pTimerCtl)
  8022. {
  8023. uint32_t hrtim_timcr2;
  8024. /* Configure timing unit (Timer A to Timer F) */
  8025. hrtim_timcr2 = hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR2;
  8026. /* Set the UpDown counting Mode */
  8027. hrtim_timcr2 &= ~(HRTIM_TIMCR2_UDM);
  8028. hrtim_timcr2 |= (pTimerCtl->UpDownMode << HRTIM_TIMCR2_UDM_Pos) ;
  8029. /* Set the TrigHalf Mode : requires the counter to be disabled */
  8030. hrtim_timcr2 &= ~(HRTIM_TIMCR2_TRGHLF);
  8031. hrtim_timcr2 |= pTimerCtl->TrigHalf;
  8032. /* define the compare event operating mode */
  8033. hrtim_timcr2 &= ~(HRTIM_TIMCR2_GTCMP1);
  8034. hrtim_timcr2 |= pTimerCtl->GreaterCMP1;
  8035. /* define the compare event operating mode */
  8036. hrtim_timcr2 &= ~(HRTIM_TIMCR2_GTCMP3);
  8037. hrtim_timcr2 |= pTimerCtl->GreaterCMP3;
  8038. if (pTimerCtl->DualChannelDacEnable == HRTIM_TIMER_DCDE_ENABLED)
  8039. {
  8040. /* Set the DualChannel DAC Reset trigger : requires DCDE enabled */
  8041. hrtim_timcr2 &= ~(HRTIM_TIMCR2_DCDR);
  8042. hrtim_timcr2 |= pTimerCtl->DualChannelDacReset;
  8043. /* Set the DualChannel DAC Step trigger : requires DCDE enabled */
  8044. hrtim_timcr2 &= ~(HRTIM_TIMCR2_DCDS);
  8045. hrtim_timcr2 |= pTimerCtl->DualChannelDacStep;
  8046. /* Enable the DualChannel DAC trigger */
  8047. hrtim_timcr2 &= ~(HRTIM_TIMCR2_DCDE);
  8048. hrtim_timcr2 |= pTimerCtl->DualChannelDacEnable;
  8049. }
  8050. /* Update the HRTIM registers */
  8051. hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR2 = hrtim_timcr2;
  8052. }
  8053. /**
  8054. * @brief Configure timing RollOver Mode (Timer A to Timer F)
  8055. * @param hhrtim pointer to HAL HRTIM handle
  8056. * @param TimerIdx Timer index
  8057. * @param pRollOverMode: a combination of the timer RollOver Mode configuration
  8058. * @retval None
  8059. */
  8060. static void HRTIM_TimingUnitRollOver_Config(HRTIM_HandleTypeDef *hhrtim,
  8061. uint32_t TimerIdx,
  8062. uint32_t pRollOverMode)
  8063. {
  8064. uint32_t hrtim_timcr2;
  8065. /* Configure timing unit (Timer A to Timer F) */
  8066. hrtim_timcr2 = hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR2;
  8067. if ((hrtim_timcr2 & HRTIM_TIMCR2_UDM) != 0U)
  8068. {
  8069. /* xxROM bitfield must be reset before programming a new value */
  8070. hrtim_timcr2 &= ~(HRTIM_TIMCR2_ROM | HRTIM_TIMCR2_OUTROM |
  8071. HRTIM_TIMCR2_ADROM | HRTIM_TIMCR2_BMROM | HRTIM_TIMCR2_FEROM);
  8072. /* Update the HRTIM TIMxCR2 register */
  8073. hrtim_timcr2 |= pRollOverMode & (HRTIM_TIMCR2_ROM | HRTIM_TIMCR2_OUTROM |
  8074. HRTIM_TIMCR2_ADROM | HRTIM_TIMCR2_BMROM | HRTIM_TIMCR2_FEROM);
  8075. hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR2 = hrtim_timcr2;
  8076. }
  8077. }
  8078. /**
  8079. * @brief Configure a capture unit
  8080. * @param hhrtim pointer to HAL HRTIM handle
  8081. * @param TimerIdx Timer index
  8082. * @param CaptureUnit Capture unit identifier
  8083. * @param Event Event reference
  8084. * @retval None
  8085. */
  8086. static void HRTIM_CaptureUnitConfig(HRTIM_HandleTypeDef *hhrtim,
  8087. uint32_t TimerIdx,
  8088. uint32_t CaptureUnit,
  8089. uint32_t Event)
  8090. {
  8091. uint32_t CaptureTrigger = 0xFFFFFFFFU;
  8092. switch (Event)
  8093. {
  8094. case HRTIM_EVENT_1:
  8095. {
  8096. CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_1;
  8097. break;
  8098. }
  8099. case HRTIM_EVENT_2:
  8100. {
  8101. CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_2;
  8102. break;
  8103. }
  8104. case HRTIM_EVENT_3:
  8105. {
  8106. CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_3;
  8107. break;
  8108. }
  8109. case HRTIM_EVENT_4:
  8110. {
  8111. CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_4;
  8112. break;
  8113. }
  8114. case HRTIM_EVENT_5:
  8115. {
  8116. CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_5;
  8117. break;
  8118. }
  8119. case HRTIM_EVENT_6:
  8120. {
  8121. CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_6;
  8122. break;
  8123. }
  8124. case HRTIM_EVENT_7:
  8125. {
  8126. CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_7;
  8127. break;
  8128. }
  8129. case HRTIM_EVENT_8:
  8130. {
  8131. CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_8;
  8132. break;
  8133. }
  8134. case HRTIM_EVENT_9:
  8135. {
  8136. CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_9;
  8137. break;
  8138. }
  8139. case HRTIM_EVENT_10:
  8140. {
  8141. CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_10;
  8142. break;
  8143. }
  8144. default:
  8145. break;
  8146. }
  8147. switch (CaptureUnit)
  8148. {
  8149. case HRTIM_CAPTUREUNIT_1:
  8150. {
  8151. hhrtim->TimerParam[TimerIdx].CaptureTrigger1 = CaptureTrigger;
  8152. break;
  8153. }
  8154. case HRTIM_CAPTUREUNIT_2:
  8155. {
  8156. hhrtim->TimerParam[TimerIdx].CaptureTrigger2 = CaptureTrigger;
  8157. break;
  8158. }
  8159. default:
  8160. break;
  8161. }
  8162. }
  8163. /**
  8164. * @brief Configure the output of a timing unit
  8165. * @param hhrtim pointer to HAL HRTIM handle
  8166. * @param TimerIdx Timer index
  8167. * @param Output timing unit output identifier
  8168. * @param pOutputCfg pointer to the output configuration data structure
  8169. * @retval None
  8170. */
  8171. static void HRTIM_OutputConfig(HRTIM_HandleTypeDef *hhrtim,
  8172. uint32_t TimerIdx,
  8173. uint32_t Output,
  8174. const HRTIM_OutputCfgTypeDef *pOutputCfg)
  8175. {
  8176. uint32_t hrtim_outr;
  8177. uint32_t hrtim_dtr;
  8178. uint32_t shift = 0U;
  8179. hrtim_outr = hhrtim->Instance->sTimerxRegs[TimerIdx].OUTxR;
  8180. hrtim_dtr = hhrtim->Instance->sTimerxRegs[TimerIdx].DTxR;
  8181. switch (Output)
  8182. {
  8183. case HRTIM_OUTPUT_TA1:
  8184. case HRTIM_OUTPUT_TB1:
  8185. case HRTIM_OUTPUT_TC1:
  8186. case HRTIM_OUTPUT_TD1:
  8187. case HRTIM_OUTPUT_TE1:
  8188. case HRTIM_OUTPUT_TF1:
  8189. {
  8190. /* Set the output set/reset crossbar */
  8191. hhrtim->Instance->sTimerxRegs[TimerIdx].SETx1R = pOutputCfg->SetSource;
  8192. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTx1R = pOutputCfg->ResetSource;
  8193. break;
  8194. }
  8195. case HRTIM_OUTPUT_TA2:
  8196. case HRTIM_OUTPUT_TB2:
  8197. case HRTIM_OUTPUT_TC2:
  8198. case HRTIM_OUTPUT_TD2:
  8199. case HRTIM_OUTPUT_TE2:
  8200. case HRTIM_OUTPUT_TF2:
  8201. {
  8202. /* Set the output set/reset crossbar */
  8203. hhrtim->Instance->sTimerxRegs[TimerIdx].SETx2R = pOutputCfg->SetSource;
  8204. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTx2R = pOutputCfg->ResetSource;
  8205. shift = 16U;
  8206. break;
  8207. }
  8208. default:
  8209. break;
  8210. }
  8211. /* Clear output config */
  8212. hrtim_outr &= ~((HRTIM_OUTR_POL1 |
  8213. HRTIM_OUTR_IDLM1 |
  8214. HRTIM_OUTR_IDLES1 |
  8215. HRTIM_OUTR_FAULT1 |
  8216. HRTIM_OUTR_CHP1 |
  8217. HRTIM_OUTR_DIDL1) << shift);
  8218. /* Set the polarity */
  8219. hrtim_outr |= (pOutputCfg->Polarity << shift);
  8220. /* Set the IDLE mode */
  8221. hrtim_outr |= (pOutputCfg->IdleMode << shift);
  8222. /* Set the IDLE state */
  8223. hrtim_outr |= (pOutputCfg->IdleLevel << shift);
  8224. /* Set the FAULT state */
  8225. hrtim_outr |= (pOutputCfg->FaultLevel << shift);
  8226. /* Set the chopper mode */
  8227. hrtim_outr |= (pOutputCfg->ChopperModeEnable << shift);
  8228. /* Set the burst mode entry mode : deadtime insertion when entering the idle
  8229. state during a burst mode operation is allowed only under the following
  8230. conditions:
  8231. - the outputs is active during the burst mode (IDLES=1U)
  8232. - positive deadtimes (SDTR/SDTF set to 0U)
  8233. */
  8234. if ((pOutputCfg->IdleLevel == HRTIM_OUTPUTIDLELEVEL_ACTIVE) &&
  8235. ((hrtim_dtr & HRTIM_DTR_SDTR) == (uint32_t)RESET) &&
  8236. ((hrtim_dtr & HRTIM_DTR_SDTF) == (uint32_t)RESET))
  8237. {
  8238. hrtim_outr |= (pOutputCfg->BurstModeEntryDelayed << shift);
  8239. }
  8240. /* Update HRTIM register */
  8241. hhrtim->Instance->sTimerxRegs[TimerIdx].OUTxR = hrtim_outr;
  8242. }
  8243. /**
  8244. * @brief Configure an external event channel
  8245. * @param hhrtim pointer to HAL HRTIM handle
  8246. * @param Event Event channel identifier
  8247. * @param pEventCfg pointer to the event channel configuration data structure
  8248. * @retval None
  8249. */
  8250. static void HRTIM_EventConfig(HRTIM_HandleTypeDef *hhrtim,
  8251. uint32_t Event,
  8252. const HRTIM_EventCfgTypeDef *pEventCfg)
  8253. {
  8254. uint32_t hrtim_eecr1;
  8255. uint32_t hrtim_eecr2;
  8256. uint32_t hrtim_eecr3;
  8257. /* Configure external event channel */
  8258. hrtim_eecr1 = hhrtim->Instance->sCommonRegs.EECR1;
  8259. hrtim_eecr2 = hhrtim->Instance->sCommonRegs.EECR2;
  8260. hrtim_eecr3 = hhrtim->Instance->sCommonRegs.EECR3;
  8261. switch (Event)
  8262. {
  8263. case HRTIM_EVENT_NONE:
  8264. {
  8265. /* Update the HRTIM registers */
  8266. hhrtim->Instance->sCommonRegs.EECR1 = 0U;
  8267. hhrtim->Instance->sCommonRegs.EECR2 = 0U;
  8268. hhrtim->Instance->sCommonRegs.EECR3 = 0U;
  8269. break;
  8270. }
  8271. case HRTIM_EVENT_1:
  8272. {
  8273. hrtim_eecr1 &= ~(HRTIM_EECR1_EE1SRC | HRTIM_EECR1_EE1POL | HRTIM_EECR1_EE1SNS | HRTIM_EECR1_EE1FAST);
  8274. hrtim_eecr1 |= (pEventCfg->Source & HRTIM_EECR1_EE1SRC);
  8275. hrtim_eecr1 |= (pEventCfg->Polarity & HRTIM_EECR1_EE1POL);
  8276. hrtim_eecr1 |= (pEventCfg->Sensitivity & HRTIM_EECR1_EE1SNS);
  8277. /* Update the HRTIM registers (all bitfields but EE1FAST bit) */
  8278. hhrtim->Instance->sCommonRegs.EECR1 = hrtim_eecr1;
  8279. /* Update the HRTIM registers (EE1FAST bit) */
  8280. hrtim_eecr1 |= (pEventCfg->FastMode & HRTIM_EECR1_EE1FAST);
  8281. hhrtim->Instance->sCommonRegs.EECR1 = hrtim_eecr1;
  8282. break;
  8283. }
  8284. case HRTIM_EVENT_2:
  8285. {
  8286. hrtim_eecr1 &= ~(HRTIM_EECR1_EE2SRC | HRTIM_EECR1_EE2POL | HRTIM_EECR1_EE2SNS | HRTIM_EECR1_EE2FAST);
  8287. hrtim_eecr1 |= ((pEventCfg->Source << 6U) & HRTIM_EECR1_EE2SRC);
  8288. hrtim_eecr1 |= ((pEventCfg->Polarity << 6U) & HRTIM_EECR1_EE2POL);
  8289. hrtim_eecr1 |= ((pEventCfg->Sensitivity << 6U) & HRTIM_EECR1_EE2SNS);
  8290. /* Update the HRTIM registers (all bitfields but EE2FAST bit) */
  8291. hhrtim->Instance->sCommonRegs.EECR1 = hrtim_eecr1;
  8292. /* Update the HRTIM registers (EE2FAST bit) */
  8293. hrtim_eecr1 |= ((pEventCfg->FastMode << 6U) & HRTIM_EECR1_EE2FAST);
  8294. hhrtim->Instance->sCommonRegs.EECR1 = hrtim_eecr1;
  8295. break;
  8296. }
  8297. case HRTIM_EVENT_3:
  8298. {
  8299. hrtim_eecr1 &= ~(HRTIM_EECR1_EE3SRC | HRTIM_EECR1_EE3POL | HRTIM_EECR1_EE3SNS | HRTIM_EECR1_EE3FAST);
  8300. hrtim_eecr1 |= ((pEventCfg->Source << 12U) & HRTIM_EECR1_EE3SRC);
  8301. hrtim_eecr1 |= ((pEventCfg->Polarity << 12U) & HRTIM_EECR1_EE3POL);
  8302. hrtim_eecr1 |= ((pEventCfg->Sensitivity << 12U) & HRTIM_EECR1_EE3SNS);
  8303. /* Update the HRTIM registers (all bitfields but EE3FAST bit) */
  8304. hhrtim->Instance->sCommonRegs.EECR1 = hrtim_eecr1;
  8305. /* Update the HRTIM registers (EE3FAST bit) */
  8306. hrtim_eecr1 |= ((pEventCfg->FastMode << 12U) & HRTIM_EECR1_EE3FAST);
  8307. hhrtim->Instance->sCommonRegs.EECR1 = hrtim_eecr1;
  8308. break;
  8309. }
  8310. case HRTIM_EVENT_4:
  8311. {
  8312. hrtim_eecr1 &= ~(HRTIM_EECR1_EE4SRC | HRTIM_EECR1_EE4POL | HRTIM_EECR1_EE4SNS | HRTIM_EECR1_EE4FAST);
  8313. hrtim_eecr1 |= ((pEventCfg->Source << 18U) & HRTIM_EECR1_EE4SRC);
  8314. hrtim_eecr1 |= ((pEventCfg->Polarity << 18U) & HRTIM_EECR1_EE4POL);
  8315. hrtim_eecr1 |= ((pEventCfg->Sensitivity << 18U) & HRTIM_EECR1_EE4SNS);
  8316. /* Update the HRTIM registers (all bitfields but EE4FAST bit) */
  8317. hhrtim->Instance->sCommonRegs.EECR1 = hrtim_eecr1;
  8318. /* Update the HRTIM registers (EE4FAST bit) */
  8319. hrtim_eecr1 |= ((pEventCfg->FastMode << 18U) & HRTIM_EECR1_EE4FAST);
  8320. hhrtim->Instance->sCommonRegs.EECR1 = hrtim_eecr1;
  8321. break;
  8322. }
  8323. case HRTIM_EVENT_5:
  8324. {
  8325. hrtim_eecr1 &= ~(HRTIM_EECR1_EE5SRC | HRTIM_EECR1_EE5POL | HRTIM_EECR1_EE5SNS | HRTIM_EECR1_EE5FAST);
  8326. hrtim_eecr1 |= ((pEventCfg->Source << 24U) & HRTIM_EECR1_EE5SRC);
  8327. hrtim_eecr1 |= ((pEventCfg->Polarity << 24U) & HRTIM_EECR1_EE5POL);
  8328. hrtim_eecr1 |= ((pEventCfg->Sensitivity << 24U) & HRTIM_EECR1_EE5SNS);
  8329. /* Update the HRTIM registers (all bitfields but EE5FAST bit) */
  8330. hhrtim->Instance->sCommonRegs.EECR1 = hrtim_eecr1;
  8331. /* Update the HRTIM registers (EE5FAST bit) */
  8332. hrtim_eecr1 |= ((pEventCfg->FastMode << 24U) & HRTIM_EECR1_EE5FAST);
  8333. hhrtim->Instance->sCommonRegs.EECR1 = hrtim_eecr1;
  8334. break;
  8335. }
  8336. case HRTIM_EVENT_6:
  8337. {
  8338. hrtim_eecr2 &= ~(HRTIM_EECR2_EE6SRC | HRTIM_EECR2_EE6POL | HRTIM_EECR2_EE6SNS);
  8339. hrtim_eecr2 |= (pEventCfg->Source & HRTIM_EECR2_EE6SRC);
  8340. hrtim_eecr2 |= (pEventCfg->Polarity & HRTIM_EECR2_EE6POL);
  8341. hrtim_eecr2 |= (pEventCfg->Sensitivity & HRTIM_EECR2_EE6SNS);
  8342. hrtim_eecr3 &= ~(HRTIM_EECR3_EE6F);
  8343. hrtim_eecr3 |= (pEventCfg->Filter & HRTIM_EECR3_EE6F);
  8344. /* Update the HRTIM registers */
  8345. hhrtim->Instance->sCommonRegs.EECR2 = hrtim_eecr2;
  8346. hhrtim->Instance->sCommonRegs.EECR3 = hrtim_eecr3;
  8347. break;
  8348. }
  8349. case HRTIM_EVENT_7:
  8350. {
  8351. hrtim_eecr2 &= ~(HRTIM_EECR2_EE7SRC | HRTIM_EECR2_EE7POL | HRTIM_EECR2_EE7SNS);
  8352. hrtim_eecr2 |= ((pEventCfg->Source << 6U) & HRTIM_EECR2_EE7SRC);
  8353. hrtim_eecr2 |= ((pEventCfg->Polarity << 6U) & HRTIM_EECR2_EE7POL);
  8354. hrtim_eecr2 |= ((pEventCfg->Sensitivity << 6U) & HRTIM_EECR2_EE7SNS);
  8355. hrtim_eecr3 &= ~(HRTIM_EECR3_EE7F);
  8356. hrtim_eecr3 |= ((pEventCfg->Filter << 6U) & HRTIM_EECR3_EE7F);
  8357. /* Update the HRTIM registers */
  8358. hhrtim->Instance->sCommonRegs.EECR2 = hrtim_eecr2;
  8359. hhrtim->Instance->sCommonRegs.EECR3 = hrtim_eecr3;
  8360. break;
  8361. }
  8362. case HRTIM_EVENT_8:
  8363. {
  8364. hrtim_eecr2 &= ~(HRTIM_EECR2_EE8SRC | HRTIM_EECR2_EE8POL | HRTIM_EECR2_EE8SNS);
  8365. hrtim_eecr2 |= ((pEventCfg->Source << 12U) & HRTIM_EECR2_EE8SRC);
  8366. hrtim_eecr2 |= ((pEventCfg->Polarity << 12U) & HRTIM_EECR2_EE8POL);
  8367. hrtim_eecr2 |= ((pEventCfg->Sensitivity << 12U) & HRTIM_EECR2_EE8SNS);
  8368. hrtim_eecr3 &= ~(HRTIM_EECR3_EE8F);
  8369. hrtim_eecr3 |= ((pEventCfg->Filter << 12U) & HRTIM_EECR3_EE8F);
  8370. /* Update the HRTIM registers */
  8371. hhrtim->Instance->sCommonRegs.EECR2 = hrtim_eecr2;
  8372. hhrtim->Instance->sCommonRegs.EECR3 = hrtim_eecr3;
  8373. break;
  8374. }
  8375. case HRTIM_EVENT_9:
  8376. {
  8377. hrtim_eecr2 &= ~(HRTIM_EECR2_EE9SRC | HRTIM_EECR2_EE9POL | HRTIM_EECR2_EE9SNS);
  8378. hrtim_eecr2 |= ((pEventCfg->Source << 18U) & HRTIM_EECR2_EE9SRC);
  8379. hrtim_eecr2 |= ((pEventCfg->Polarity << 18U) & HRTIM_EECR2_EE9POL);
  8380. hrtim_eecr2 |= ((pEventCfg->Sensitivity << 18U) & HRTIM_EECR2_EE9SNS);
  8381. hrtim_eecr3 &= ~(HRTIM_EECR3_EE9F);
  8382. hrtim_eecr3 |= ((pEventCfg->Filter << 18U) & HRTIM_EECR3_EE9F);
  8383. /* Update the HRTIM registers */
  8384. hhrtim->Instance->sCommonRegs.EECR2 = hrtim_eecr2;
  8385. hhrtim->Instance->sCommonRegs.EECR3 = hrtim_eecr3;
  8386. break;
  8387. }
  8388. case HRTIM_EVENT_10:
  8389. {
  8390. hrtim_eecr2 &= ~(HRTIM_EECR2_EE10SRC | HRTIM_EECR2_EE10POL | HRTIM_EECR2_EE10SNS);
  8391. hrtim_eecr2 |= ((pEventCfg->Source << 24U) & HRTIM_EECR2_EE10SRC);
  8392. hrtim_eecr2 |= ((pEventCfg->Polarity << 24U) & HRTIM_EECR2_EE10POL);
  8393. hrtim_eecr2 |= ((pEventCfg->Sensitivity << 24U) & HRTIM_EECR2_EE10SNS);
  8394. hrtim_eecr3 &= ~(HRTIM_EECR3_EE10F);
  8395. hrtim_eecr3 |= ((pEventCfg->Filter << 24U) & HRTIM_EECR3_EE10F);
  8396. /* Update the HRTIM registers */
  8397. hhrtim->Instance->sCommonRegs.EECR2 = hrtim_eecr2;
  8398. hhrtim->Instance->sCommonRegs.EECR3 = hrtim_eecr3;
  8399. break;
  8400. }
  8401. default:
  8402. break;
  8403. }
  8404. }
  8405. /**
  8406. * @brief Configure the timer counter reset
  8407. * @param hhrtim pointer to HAL HRTIM handle
  8408. * @param TimerIdx Timer index
  8409. * @param Event Event channel identifier
  8410. * @retval None
  8411. */
  8412. static void HRTIM_TIM_ResetConfig(HRTIM_HandleTypeDef *hhrtim,
  8413. uint32_t TimerIdx,
  8414. uint32_t Event)
  8415. {
  8416. switch (Event)
  8417. {
  8418. case HRTIM_EVENT_1:
  8419. {
  8420. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_1;
  8421. break;
  8422. }
  8423. case HRTIM_EVENT_2:
  8424. {
  8425. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_2;
  8426. break;
  8427. }
  8428. case HRTIM_EVENT_3:
  8429. {
  8430. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_3;
  8431. break;
  8432. }
  8433. case HRTIM_EVENT_4:
  8434. {
  8435. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_4;
  8436. break;
  8437. }
  8438. case HRTIM_EVENT_5:
  8439. {
  8440. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_5;
  8441. break;
  8442. }
  8443. case HRTIM_EVENT_6:
  8444. {
  8445. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_6;
  8446. break;
  8447. }
  8448. case HRTIM_EVENT_7:
  8449. {
  8450. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_7;
  8451. break;
  8452. }
  8453. case HRTIM_EVENT_8:
  8454. {
  8455. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_8;
  8456. break;
  8457. }
  8458. case HRTIM_EVENT_9:
  8459. {
  8460. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_9;
  8461. break;
  8462. }
  8463. case HRTIM_EVENT_10:
  8464. {
  8465. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_10;
  8466. break;
  8467. }
  8468. default:
  8469. break;
  8470. }
  8471. }
  8472. /**
  8473. * @brief Return the interrupt to enable or disable according to the
  8474. * OC mode.
  8475. * @param hhrtim pointer to HAL HRTIM handle
  8476. * @param TimerIdx Timer index
  8477. * @param OCChannel Timer output
  8478. * This parameter can be one of the following values:
  8479. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  8480. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  8481. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  8482. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  8483. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  8484. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  8485. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  8486. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  8487. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  8488. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  8489. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  8490. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  8491. * @retval Interrupt to enable or disable
  8492. */
  8493. static uint32_t HRTIM_GetITFromOCMode(const HRTIM_HandleTypeDef *hhrtim,
  8494. uint32_t TimerIdx,
  8495. uint32_t OCChannel)
  8496. {
  8497. uint32_t hrtim_set;
  8498. uint32_t hrtim_reset;
  8499. uint32_t interrupt = 0U;
  8500. switch (OCChannel)
  8501. {
  8502. case HRTIM_OUTPUT_TA1:
  8503. case HRTIM_OUTPUT_TB1:
  8504. case HRTIM_OUTPUT_TC1:
  8505. case HRTIM_OUTPUT_TD1:
  8506. case HRTIM_OUTPUT_TE1:
  8507. case HRTIM_OUTPUT_TF1:
  8508. {
  8509. /* Retrieves actual OC mode and set interrupt accordingly */
  8510. hrtim_set = hhrtim->Instance->sTimerxRegs[TimerIdx].SETx1R;
  8511. hrtim_reset = hhrtim->Instance->sTimerxRegs[TimerIdx].RSTx1R;
  8512. if (((hrtim_set & HRTIM_OUTPUTSET_TIMCMP1) == HRTIM_OUTPUTSET_TIMCMP1) &&
  8513. ((hrtim_reset & HRTIM_OUTPUTRESET_TIMCMP1) == HRTIM_OUTPUTRESET_TIMCMP1))
  8514. {
  8515. /* OC mode: HRTIM_BASICOCMODE_TOGGLE */
  8516. interrupt = HRTIM_TIM_IT_CMP1;
  8517. }
  8518. else if (((hrtim_set & HRTIM_OUTPUTSET_TIMCMP1) == HRTIM_OUTPUTSET_TIMCMP1) &&
  8519. (hrtim_reset == 0U))
  8520. {
  8521. /* OC mode: HRTIM_BASICOCMODE_ACTIVE */
  8522. interrupt = HRTIM_TIM_IT_SET1;
  8523. }
  8524. else if ((hrtim_set == 0U) &&
  8525. ((hrtim_reset & HRTIM_OUTPUTRESET_TIMCMP1) == HRTIM_OUTPUTRESET_TIMCMP1))
  8526. {
  8527. /* OC mode: HRTIM_BASICOCMODE_INACTIVE */
  8528. interrupt = HRTIM_TIM_IT_RST1;
  8529. }
  8530. else
  8531. {
  8532. /* nothing to do */
  8533. }
  8534. break;
  8535. }
  8536. case HRTIM_OUTPUT_TA2:
  8537. case HRTIM_OUTPUT_TB2:
  8538. case HRTIM_OUTPUT_TC2:
  8539. case HRTIM_OUTPUT_TD2:
  8540. case HRTIM_OUTPUT_TE2:
  8541. case HRTIM_OUTPUT_TF2:
  8542. {
  8543. /* Retrieves actual OC mode and set interrupt accordingly */
  8544. hrtim_set = hhrtim->Instance->sTimerxRegs[TimerIdx].SETx2R;
  8545. hrtim_reset = hhrtim->Instance->sTimerxRegs[TimerIdx].RSTx2R;
  8546. if (((hrtim_set & HRTIM_OUTPUTSET_TIMCMP2) == HRTIM_OUTPUTSET_TIMCMP2) &&
  8547. ((hrtim_reset & HRTIM_OUTPUTRESET_TIMCMP2) == HRTIM_OUTPUTRESET_TIMCMP2))
  8548. {
  8549. /* OC mode: HRTIM_BASICOCMODE_TOGGLE */
  8550. interrupt = HRTIM_TIM_IT_CMP2;
  8551. }
  8552. else if (((hrtim_set & HRTIM_OUTPUTSET_TIMCMP2) == HRTIM_OUTPUTSET_TIMCMP2) &&
  8553. (hrtim_reset == 0U))
  8554. {
  8555. /* OC mode: HRTIM_BASICOCMODE_ACTIVE */
  8556. interrupt = HRTIM_TIM_IT_SET2;
  8557. }
  8558. else if ((hrtim_set == 0U) &&
  8559. ((hrtim_reset & HRTIM_OUTPUTRESET_TIMCMP2) == HRTIM_OUTPUTRESET_TIMCMP2))
  8560. {
  8561. /* OC mode: HRTIM_BASICOCMODE_INACTIVE */
  8562. interrupt = HRTIM_TIM_IT_RST2;
  8563. }
  8564. else
  8565. {
  8566. /* nothing to do */
  8567. }
  8568. break;
  8569. }
  8570. default:
  8571. break;
  8572. }
  8573. return interrupt;
  8574. }
  8575. /**
  8576. * @brief Return the DMA request to enable or disable according to the
  8577. * OC mode.
  8578. * @param hhrtim pointer to HAL HRTIM handle
  8579. * @param TimerIdx Timer index
  8580. * @param OCChannel Timer output
  8581. * This parameter can be one of the following values:
  8582. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  8583. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  8584. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  8585. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  8586. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  8587. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  8588. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  8589. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  8590. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  8591. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  8592. * @arg HRTIM_OUTPUT_TF1: Timer F - Output 1
  8593. * @arg HRTIM_OUTPUT_TF2: Timer F - Output 2
  8594. * @retval DMA request to enable or disable
  8595. */
  8596. static uint32_t HRTIM_GetDMAFromOCMode(const HRTIM_HandleTypeDef *hhrtim,
  8597. uint32_t TimerIdx,
  8598. uint32_t OCChannel)
  8599. {
  8600. uint32_t hrtim_set;
  8601. uint32_t hrtim_reset;
  8602. uint32_t dma_request = 0U;
  8603. switch (OCChannel)
  8604. {
  8605. case HRTIM_OUTPUT_TA1:
  8606. case HRTIM_OUTPUT_TB1:
  8607. case HRTIM_OUTPUT_TC1:
  8608. case HRTIM_OUTPUT_TD1:
  8609. case HRTIM_OUTPUT_TE1:
  8610. case HRTIM_OUTPUT_TF1:
  8611. {
  8612. /* Retrieves actual OC mode and set dma_request accordingly */
  8613. hrtim_set = hhrtim->Instance->sTimerxRegs[TimerIdx].SETx1R;
  8614. hrtim_reset = hhrtim->Instance->sTimerxRegs[TimerIdx].RSTx1R;
  8615. if (((hrtim_set & HRTIM_OUTPUTSET_TIMCMP1) == HRTIM_OUTPUTSET_TIMCMP1) &&
  8616. ((hrtim_reset & HRTIM_OUTPUTRESET_TIMCMP1) == HRTIM_OUTPUTRESET_TIMCMP1))
  8617. {
  8618. /* OC mode: HRTIM_BASICOCMODE_TOGGLE */
  8619. dma_request = HRTIM_TIM_DMA_CMP1;
  8620. }
  8621. else if (((hrtim_set & HRTIM_OUTPUTSET_TIMCMP1) == HRTIM_OUTPUTSET_TIMCMP1) &&
  8622. (hrtim_reset == 0U))
  8623. {
  8624. /* OC mode: HRTIM_BASICOCMODE_ACTIVE */
  8625. dma_request = HRTIM_TIM_DMA_SET1;
  8626. }
  8627. else if ((hrtim_set == 0U) &&
  8628. ((hrtim_reset & HRTIM_OUTPUTRESET_TIMCMP1) == HRTIM_OUTPUTRESET_TIMCMP1))
  8629. {
  8630. /* OC mode: HRTIM_BASICOCMODE_INACTIVE */
  8631. dma_request = HRTIM_TIM_DMA_RST1;
  8632. }
  8633. else
  8634. {
  8635. /* nothing to do */
  8636. }
  8637. break;
  8638. }
  8639. case HRTIM_OUTPUT_TA2:
  8640. case HRTIM_OUTPUT_TB2:
  8641. case HRTIM_OUTPUT_TC2:
  8642. case HRTIM_OUTPUT_TD2:
  8643. case HRTIM_OUTPUT_TE2:
  8644. case HRTIM_OUTPUT_TF2:
  8645. {
  8646. /* Retrieves actual OC mode and set dma_request accordingly */
  8647. hrtim_set = hhrtim->Instance->sTimerxRegs[TimerIdx].SETx2R;
  8648. hrtim_reset = hhrtim->Instance->sTimerxRegs[TimerIdx].RSTx2R;
  8649. if (((hrtim_set & HRTIM_OUTPUTSET_TIMCMP2) == HRTIM_OUTPUTSET_TIMCMP2) &&
  8650. ((hrtim_reset & HRTIM_OUTPUTRESET_TIMCMP2) == HRTIM_OUTPUTRESET_TIMCMP2))
  8651. {
  8652. /* OC mode: HRTIM_BASICOCMODE_TOGGLE */
  8653. dma_request = HRTIM_TIM_DMA_CMP2;
  8654. }
  8655. else if (((hrtim_set & HRTIM_OUTPUTSET_TIMCMP2) == HRTIM_OUTPUTSET_TIMCMP2) &&
  8656. (hrtim_reset == 0U))
  8657. {
  8658. /* OC mode: HRTIM_BASICOCMODE_ACTIVE */
  8659. dma_request = HRTIM_TIM_DMA_SET2;
  8660. }
  8661. else if ((hrtim_set == 0U) &&
  8662. ((hrtim_reset & HRTIM_OUTPUTRESET_TIMCMP2) == HRTIM_OUTPUTRESET_TIMCMP2))
  8663. {
  8664. /* OC mode: HRTIM_BASICOCMODE_INACTIVE */
  8665. dma_request = HRTIM_TIM_DMA_RST2;
  8666. }
  8667. else
  8668. {
  8669. /* nothing to do */
  8670. }
  8671. break;
  8672. }
  8673. default:
  8674. break;
  8675. }
  8676. return dma_request;
  8677. }
  8678. static DMA_HandleTypeDef *HRTIM_GetDMAHandleFromTimerIdx(const HRTIM_HandleTypeDef *hhrtim,
  8679. uint32_t TimerIdx)
  8680. {
  8681. DMA_HandleTypeDef *hdma = (DMA_HandleTypeDef *)NULL;
  8682. switch (TimerIdx)
  8683. {
  8684. case HRTIM_TIMERINDEX_MASTER:
  8685. {
  8686. hdma = hhrtim->hdmaMaster;
  8687. break;
  8688. }
  8689. case HRTIM_TIMERINDEX_TIMER_A:
  8690. {
  8691. hdma = hhrtim->hdmaTimerA;
  8692. break;
  8693. }
  8694. case HRTIM_TIMERINDEX_TIMER_B:
  8695. {
  8696. hdma = hhrtim->hdmaTimerB;
  8697. break;
  8698. }
  8699. case HRTIM_TIMERINDEX_TIMER_C:
  8700. {
  8701. hdma = hhrtim->hdmaTimerC;
  8702. break;
  8703. }
  8704. case HRTIM_TIMERINDEX_TIMER_D:
  8705. {
  8706. hdma = hhrtim->hdmaTimerD;
  8707. break;
  8708. }
  8709. case HRTIM_TIMERINDEX_TIMER_E:
  8710. {
  8711. hdma = hhrtim->hdmaTimerE;
  8712. break;
  8713. }
  8714. case HRTIM_TIMERINDEX_TIMER_F:
  8715. {
  8716. hdma = hhrtim->hdmaTimerF;
  8717. break;
  8718. }
  8719. default:
  8720. break;
  8721. }
  8722. return hdma;
  8723. }
  8724. static uint32_t GetTimerIdxFromDMAHandle(const HRTIM_HandleTypeDef *hhrtim,
  8725. const DMA_HandleTypeDef *hdma)
  8726. {
  8727. uint32_t timed_idx = 0xFFFFFFFFU;
  8728. if (hdma == hhrtim->hdmaMaster)
  8729. {
  8730. timed_idx = HRTIM_TIMERINDEX_MASTER;
  8731. }
  8732. else if (hdma == hhrtim->hdmaTimerA)
  8733. {
  8734. timed_idx = HRTIM_TIMERINDEX_TIMER_A;
  8735. }
  8736. else if (hdma == hhrtim->hdmaTimerB)
  8737. {
  8738. timed_idx = HRTIM_TIMERINDEX_TIMER_B;
  8739. }
  8740. else if (hdma == hhrtim->hdmaTimerC)
  8741. {
  8742. timed_idx = HRTIM_TIMERINDEX_TIMER_C;
  8743. }
  8744. else if (hdma == hhrtim->hdmaTimerD)
  8745. {
  8746. timed_idx = HRTIM_TIMERINDEX_TIMER_D;
  8747. }
  8748. else if (hdma == hhrtim->hdmaTimerE)
  8749. {
  8750. timed_idx = HRTIM_TIMERINDEX_TIMER_E;
  8751. }
  8752. else if (hdma == hhrtim->hdmaTimerF)
  8753. {
  8754. timed_idx = HRTIM_TIMERINDEX_TIMER_F;
  8755. }
  8756. else
  8757. {
  8758. /* nothing to do */
  8759. }
  8760. return timed_idx;
  8761. }
  8762. /**
  8763. * @brief Force an immediate transfer from the preload to the active
  8764. * registers.
  8765. * @param hhrtim pointer to HAL HRTIM handle
  8766. * @param TimerIdx Timer index
  8767. * @retval None
  8768. */
  8769. static void HRTIM_ForceRegistersUpdate(HRTIM_HandleTypeDef *hhrtim,
  8770. uint32_t TimerIdx)
  8771. {
  8772. switch (TimerIdx)
  8773. {
  8774. case HRTIM_TIMERINDEX_MASTER:
  8775. {
  8776. hhrtim->Instance->sCommonRegs.CR2 |= HRTIM_CR2_MSWU;
  8777. break;
  8778. }
  8779. case HRTIM_TIMERINDEX_TIMER_A:
  8780. {
  8781. hhrtim->Instance->sCommonRegs.CR2 |= HRTIM_CR2_TASWU;
  8782. break;
  8783. }
  8784. case HRTIM_TIMERINDEX_TIMER_B:
  8785. {
  8786. hhrtim->Instance->sCommonRegs.CR2 |= HRTIM_CR2_TBSWU;
  8787. break;
  8788. }
  8789. case HRTIM_TIMERINDEX_TIMER_C:
  8790. {
  8791. hhrtim->Instance->sCommonRegs.CR2 |= HRTIM_CR2_TCSWU;
  8792. break;
  8793. }
  8794. case HRTIM_TIMERINDEX_TIMER_D:
  8795. {
  8796. hhrtim->Instance->sCommonRegs.CR2 |= HRTIM_CR2_TDSWU;
  8797. break;
  8798. }
  8799. case HRTIM_TIMERINDEX_TIMER_E:
  8800. {
  8801. hhrtim->Instance->sCommonRegs.CR2 |= HRTIM_CR2_TESWU;
  8802. break;
  8803. }
  8804. case HRTIM_TIMERINDEX_TIMER_F:
  8805. {
  8806. hhrtim->Instance->sCommonRegs.CR2 |= HRTIM_CR2_TFSWU;
  8807. break;
  8808. }
  8809. default:
  8810. break;
  8811. }
  8812. }
  8813. /**
  8814. * @brief HRTIM interrupts service routine
  8815. * @param hhrtim pointer to HAL HRTIM handle
  8816. * @retval None
  8817. */
  8818. static void HRTIM_HRTIM_ISR(HRTIM_HandleTypeDef *hhrtim)
  8819. {
  8820. uint32_t isrflags = READ_REG(hhrtim->Instance->sCommonRegs.ISR);
  8821. uint32_t ierits = READ_REG(hhrtim->Instance->sCommonRegs.IER);
  8822. /* Fault 1 event */
  8823. if ((uint32_t)(isrflags & HRTIM_FLAG_FLT1) != (uint32_t)RESET)
  8824. {
  8825. if ((uint32_t)(ierits & HRTIM_IT_FLT1) != (uint32_t)RESET)
  8826. {
  8827. __HAL_HRTIM_CLEAR_IT(hhrtim, HRTIM_IT_FLT1);
  8828. /* Invoke Fault 1 event callback */
  8829. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  8830. hhrtim->Fault1Callback(hhrtim);
  8831. #else
  8832. HAL_HRTIM_Fault1Callback(hhrtim);
  8833. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  8834. }
  8835. }
  8836. /* Fault 2 event */
  8837. if ((uint32_t)(isrflags & HRTIM_FLAG_FLT2) != (uint32_t)RESET)
  8838. {
  8839. if ((uint32_t)(ierits & HRTIM_IT_FLT2) != (uint32_t)RESET)
  8840. {
  8841. __HAL_HRTIM_CLEAR_IT(hhrtim, HRTIM_IT_FLT2);
  8842. /* Invoke Fault 2 event callback */
  8843. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  8844. hhrtim->Fault2Callback(hhrtim);
  8845. #else
  8846. HAL_HRTIM_Fault2Callback(hhrtim);
  8847. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  8848. }
  8849. }
  8850. /* Fault 3 event */
  8851. if ((uint32_t)(isrflags & HRTIM_FLAG_FLT3) != (uint32_t)RESET)
  8852. {
  8853. if ((uint32_t)(ierits & HRTIM_IT_FLT3) != (uint32_t)RESET)
  8854. {
  8855. __HAL_HRTIM_CLEAR_IT(hhrtim, HRTIM_IT_FLT3);
  8856. /* Invoke Fault 3 event callback */
  8857. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  8858. hhrtim->Fault3Callback(hhrtim);
  8859. #else
  8860. HAL_HRTIM_Fault3Callback(hhrtim);
  8861. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  8862. }
  8863. }
  8864. /* Fault 4 event */
  8865. if ((uint32_t)(isrflags & HRTIM_FLAG_FLT4) != (uint32_t)RESET)
  8866. {
  8867. if ((uint32_t)(ierits & HRTIM_IT_FLT4) != (uint32_t)RESET)
  8868. {
  8869. __HAL_HRTIM_CLEAR_IT(hhrtim, HRTIM_IT_FLT4);
  8870. /* Invoke Fault 4 event callback */
  8871. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  8872. hhrtim->Fault4Callback(hhrtim);
  8873. #else
  8874. HAL_HRTIM_Fault4Callback(hhrtim);
  8875. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  8876. }
  8877. }
  8878. /* Fault 5 event */
  8879. if ((uint32_t)(isrflags & HRTIM_FLAG_FLT5) != (uint32_t)RESET)
  8880. {
  8881. if ((uint32_t)(ierits & HRTIM_IT_FLT5) != (uint32_t)RESET)
  8882. {
  8883. __HAL_HRTIM_CLEAR_IT(hhrtim, HRTIM_IT_FLT5);
  8884. /* Invoke Fault 5 event callback */
  8885. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  8886. hhrtim->Fault5Callback(hhrtim);
  8887. #else
  8888. HAL_HRTIM_Fault5Callback(hhrtim);
  8889. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  8890. }
  8891. }
  8892. /* Fault 6 event */
  8893. if ((uint32_t)(isrflags & HRTIM_FLAG_FLT6) != (uint32_t)RESET)
  8894. {
  8895. if ((uint32_t)(ierits & HRTIM_IT_FLT6) != (uint32_t)RESET)
  8896. {
  8897. __HAL_HRTIM_CLEAR_IT(hhrtim, HRTIM_IT_FLT6);
  8898. /* Invoke Fault 6 event callback */
  8899. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  8900. hhrtim->Fault6Callback(hhrtim);
  8901. #else
  8902. HAL_HRTIM_Fault6Callback(hhrtim);
  8903. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  8904. }
  8905. }
  8906. /* System fault event */
  8907. if ((uint32_t)(isrflags & HRTIM_FLAG_SYSFLT) != (uint32_t)RESET)
  8908. {
  8909. if ((uint32_t)(ierits & HRTIM_IT_SYSFLT) != (uint32_t)RESET)
  8910. {
  8911. __HAL_HRTIM_CLEAR_IT(hhrtim, HRTIM_IT_SYSFLT);
  8912. /* Invoke System fault event callback */
  8913. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  8914. hhrtim->SystemFaultCallback(hhrtim);
  8915. #else
  8916. HAL_HRTIM_SystemFaultCallback(hhrtim);
  8917. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  8918. }
  8919. }
  8920. }
  8921. /**
  8922. * @brief Master timer interrupts service routine
  8923. * @param hhrtim pointer to HAL HRTIM handle
  8924. * @retval None
  8925. */
  8926. static void HRTIM_Master_ISR(HRTIM_HandleTypeDef *hhrtim)
  8927. {
  8928. uint32_t isrflags = READ_REG(hhrtim->Instance->sCommonRegs.ISR);
  8929. uint32_t ierits = READ_REG(hhrtim->Instance->sCommonRegs.IER);
  8930. uint32_t misrflags = READ_REG(hhrtim->Instance->sMasterRegs.MISR);
  8931. uint32_t mdierits = READ_REG(hhrtim->Instance->sMasterRegs.MDIER);
  8932. /* DLL calibration ready event */
  8933. if ((uint32_t)(isrflags & HRTIM_FLAG_DLLRDY) != (uint32_t)RESET)
  8934. {
  8935. if ((uint32_t)(ierits & HRTIM_IT_DLLRDY) != (uint32_t)RESET)
  8936. {
  8937. __HAL_HRTIM_CLEAR_IT(hhrtim, HRTIM_IT_DLLRDY);
  8938. /* Set HRTIM State */
  8939. hhrtim->State = HAL_HRTIM_STATE_READY;
  8940. /* Process unlocked */
  8941. __HAL_UNLOCK(hhrtim);
  8942. /* Invoke System fault event callback */
  8943. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  8944. hhrtim->DLLCalibrationReadyCallback(hhrtim);
  8945. #else
  8946. HAL_HRTIM_DLLCalibrationReadyCallback(hhrtim);
  8947. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  8948. }
  8949. }
  8950. /* Burst mode period event */
  8951. if ((uint32_t)(isrflags & HRTIM_FLAG_BMPER) != (uint32_t)RESET)
  8952. {
  8953. if ((uint32_t)(ierits & HRTIM_IT_BMPER) != (uint32_t)RESET)
  8954. {
  8955. __HAL_HRTIM_CLEAR_IT(hhrtim, HRTIM_IT_BMPER);
  8956. /* Invoke Burst mode period event callback */
  8957. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  8958. hhrtim->BurstModePeriodCallback(hhrtim);
  8959. #else
  8960. HAL_HRTIM_BurstModePeriodCallback(hhrtim);
  8961. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  8962. }
  8963. }
  8964. /* Master timer compare 1 event */
  8965. if ((uint32_t)(misrflags & HRTIM_MASTER_FLAG_MCMP1) != (uint32_t)RESET)
  8966. {
  8967. if ((uint32_t)(mdierits & HRTIM_MASTER_IT_MCMP1) != (uint32_t)RESET)
  8968. {
  8969. __HAL_HRTIM_MASTER_CLEAR_IT(hhrtim, HRTIM_MASTER_IT_MCMP1);
  8970. /* Invoke compare 1 event callback */
  8971. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  8972. hhrtim->Compare1EventCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  8973. #else
  8974. HAL_HRTIM_Compare1EventCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  8975. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  8976. }
  8977. }
  8978. /* Master timer compare 2 event */
  8979. if ((uint32_t)(misrflags & HRTIM_MASTER_FLAG_MCMP2) != (uint32_t)RESET)
  8980. {
  8981. if ((uint32_t)(mdierits & HRTIM_MASTER_IT_MCMP2) != (uint32_t)RESET)
  8982. {
  8983. __HAL_HRTIM_MASTER_CLEAR_IT(hhrtim, HRTIM_MASTER_IT_MCMP2);
  8984. /* Invoke compare 2 event callback */
  8985. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  8986. hhrtim->Compare2EventCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  8987. #else
  8988. HAL_HRTIM_Compare2EventCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  8989. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  8990. }
  8991. }
  8992. /* Master timer compare 3 event */
  8993. if ((uint32_t)(misrflags & HRTIM_MASTER_FLAG_MCMP3) != (uint32_t)RESET)
  8994. {
  8995. if ((uint32_t)(mdierits & HRTIM_MASTER_IT_MCMP3) != (uint32_t)RESET)
  8996. {
  8997. __HAL_HRTIM_MASTER_CLEAR_IT(hhrtim, HRTIM_MASTER_IT_MCMP3);
  8998. /* Invoke compare 3 event callback */
  8999. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9000. hhrtim->Compare3EventCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  9001. #else
  9002. HAL_HRTIM_Compare3EventCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  9003. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9004. }
  9005. }
  9006. /* Master timer compare 4 event */
  9007. if ((uint32_t)(misrflags & HRTIM_MASTER_FLAG_MCMP4) != (uint32_t)RESET)
  9008. {
  9009. if ((uint32_t)(mdierits & HRTIM_MASTER_IT_MCMP4) != (uint32_t)RESET)
  9010. {
  9011. __HAL_HRTIM_MASTER_CLEAR_IT(hhrtim, HRTIM_MASTER_IT_MCMP4);
  9012. /* Invoke compare 4 event callback */
  9013. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9014. hhrtim->Compare4EventCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  9015. #else
  9016. HAL_HRTIM_Compare4EventCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  9017. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9018. }
  9019. }
  9020. /* Master timer repetition event */
  9021. if ((uint32_t)(misrflags & HRTIM_MASTER_FLAG_MREP) != (uint32_t)RESET)
  9022. {
  9023. if ((uint32_t)(mdierits & HRTIM_MASTER_IT_MREP) != (uint32_t)RESET)
  9024. {
  9025. __HAL_HRTIM_MASTER_CLEAR_IT(hhrtim, HRTIM_MASTER_IT_MREP);
  9026. /* Invoke repetition event callback */
  9027. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9028. hhrtim->RepetitionEventCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  9029. #else
  9030. HAL_HRTIM_RepetitionEventCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  9031. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9032. }
  9033. }
  9034. /* Synchronization input event */
  9035. if ((uint32_t)(misrflags & HRTIM_MASTER_FLAG_SYNC) != (uint32_t)RESET)
  9036. {
  9037. if ((uint32_t)(mdierits & HRTIM_MASTER_IT_SYNC) != (uint32_t)RESET)
  9038. {
  9039. __HAL_HRTIM_MASTER_CLEAR_IT(hhrtim, HRTIM_MASTER_IT_SYNC);
  9040. /* Invoke synchronization event callback */
  9041. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9042. hhrtim->SynchronizationEventCallback(hhrtim);
  9043. #else
  9044. HAL_HRTIM_SynchronizationEventCallback(hhrtim);
  9045. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9046. }
  9047. }
  9048. /* Master timer registers update event */
  9049. if ((uint32_t)(misrflags & HRTIM_MASTER_FLAG_MUPD) != (uint32_t)RESET)
  9050. {
  9051. if ((uint32_t)(mdierits & HRTIM_MASTER_IT_MUPD) != (uint32_t)RESET)
  9052. {
  9053. __HAL_HRTIM_MASTER_CLEAR_IT(hhrtim, HRTIM_MASTER_IT_MUPD);
  9054. /* Invoke registers update event callback */
  9055. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9056. hhrtim->RegistersUpdateCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  9057. #else
  9058. HAL_HRTIM_RegistersUpdateCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  9059. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9060. }
  9061. }
  9062. }
  9063. /**
  9064. * @brief Timer interrupts service routine
  9065. * @param hhrtim pointer to HAL HRTIM handle
  9066. * @param TimerIdx Timer index
  9067. * This parameter can be one of the following values:
  9068. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  9069. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  9070. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  9071. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  9072. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  9073. * @arg HRTIM_TIMERINDEX_TIMER_F for timer F
  9074. * @retval None
  9075. */
  9076. static void HRTIM_Timer_ISR(HRTIM_HandleTypeDef *hhrtim,
  9077. uint32_t TimerIdx)
  9078. {
  9079. uint32_t tisrflags = READ_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxISR);
  9080. uint32_t tdierits = READ_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxDIER);
  9081. /* Timer compare 1 event */
  9082. if ((uint32_t)(tisrflags & HRTIM_TIM_FLAG_CMP1) != (uint32_t)RESET)
  9083. {
  9084. if ((uint32_t)(tdierits & HRTIM_TIM_IT_CMP1) != (uint32_t)RESET)
  9085. {
  9086. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP1);
  9087. /* Invoke compare 1 event callback */
  9088. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9089. hhrtim->Compare1EventCallback(hhrtim, TimerIdx);
  9090. #else
  9091. HAL_HRTIM_Compare1EventCallback(hhrtim, TimerIdx);
  9092. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9093. }
  9094. }
  9095. /* Timer compare 2 event */
  9096. if ((uint32_t)(tisrflags & HRTIM_TIM_FLAG_CMP2) != (uint32_t)RESET)
  9097. {
  9098. if ((uint32_t)(tdierits & HRTIM_TIM_IT_CMP2) != (uint32_t)RESET)
  9099. {
  9100. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP2);
  9101. /* Invoke compare 2 event callback */
  9102. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9103. hhrtim->Compare2EventCallback(hhrtim, TimerIdx);
  9104. #else
  9105. HAL_HRTIM_Compare2EventCallback(hhrtim, TimerIdx);
  9106. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9107. }
  9108. }
  9109. /* Timer compare 3 event */
  9110. if ((uint32_t)(tisrflags & HRTIM_TIM_FLAG_CMP3) != (uint32_t)RESET)
  9111. {
  9112. if ((uint32_t)(tdierits & HRTIM_TIM_IT_CMP3) != (uint32_t)RESET)
  9113. {
  9114. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP3);
  9115. /* Invoke compare 3 event callback */
  9116. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9117. hhrtim->Compare3EventCallback(hhrtim, TimerIdx);
  9118. #else
  9119. HAL_HRTIM_Compare3EventCallback(hhrtim, TimerIdx);
  9120. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9121. }
  9122. }
  9123. /* Timer compare 4 event */
  9124. if ((uint32_t)(tisrflags & HRTIM_TIM_FLAG_CMP4) != (uint32_t)RESET)
  9125. {
  9126. if ((uint32_t)(tdierits & HRTIM_TIM_IT_CMP4) != (uint32_t)RESET)
  9127. {
  9128. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP4);
  9129. /* Invoke compare 4 event callback */
  9130. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9131. hhrtim->Compare4EventCallback(hhrtim, TimerIdx);
  9132. #else
  9133. HAL_HRTIM_Compare4EventCallback(hhrtim, TimerIdx);
  9134. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9135. }
  9136. }
  9137. /* Timer repetition event */
  9138. if ((uint32_t)(tisrflags & HRTIM_TIM_FLAG_REP) != (uint32_t)RESET)
  9139. {
  9140. if ((uint32_t)(tdierits & HRTIM_TIM_IT_REP) != (uint32_t)RESET)
  9141. {
  9142. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_REP);
  9143. /* Invoke repetition event callback */
  9144. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9145. hhrtim->RepetitionEventCallback(hhrtim, TimerIdx);
  9146. #else
  9147. HAL_HRTIM_RepetitionEventCallback(hhrtim, TimerIdx);
  9148. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9149. }
  9150. }
  9151. /* Timer registers update event */
  9152. if ((uint32_t)(tisrflags & HRTIM_TIM_FLAG_UPD) != (uint32_t)RESET)
  9153. {
  9154. if ((uint32_t)(tdierits & HRTIM_TIM_IT_UPD) != (uint32_t)RESET)
  9155. {
  9156. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_UPD);
  9157. /* Invoke registers update event callback */
  9158. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9159. hhrtim->RegistersUpdateCallback(hhrtim, TimerIdx);
  9160. #else
  9161. HAL_HRTIM_RegistersUpdateCallback(hhrtim, TimerIdx);
  9162. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9163. }
  9164. }
  9165. /* Timer capture 1 event */
  9166. if ((uint32_t)(tisrflags & HRTIM_TIM_FLAG_CPT1) != (uint32_t)RESET)
  9167. {
  9168. if ((uint32_t)(tdierits & HRTIM_TIM_IT_CPT1) != (uint32_t)RESET)
  9169. {
  9170. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CPT1);
  9171. /* Invoke capture 1 event callback */
  9172. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9173. hhrtim->Capture1EventCallback(hhrtim, TimerIdx);
  9174. #else
  9175. HAL_HRTIM_Capture1EventCallback(hhrtim, TimerIdx);
  9176. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9177. }
  9178. }
  9179. /* Timer capture 2 event */
  9180. if ((uint32_t)(tisrflags & HRTIM_TIM_FLAG_CPT2) != (uint32_t)RESET)
  9181. {
  9182. if ((uint32_t)(tdierits & HRTIM_TIM_IT_CPT2) != (uint32_t)RESET)
  9183. {
  9184. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CPT2);
  9185. /* Invoke capture 2 event callback */
  9186. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9187. hhrtim->Capture2EventCallback(hhrtim, TimerIdx);
  9188. #else
  9189. HAL_HRTIM_Capture2EventCallback(hhrtim, TimerIdx);
  9190. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9191. }
  9192. }
  9193. /* Timer output 1 set event */
  9194. if ((uint32_t)(tisrflags & HRTIM_TIM_FLAG_SET1) != (uint32_t)RESET)
  9195. {
  9196. if ((uint32_t)(tdierits & HRTIM_TIM_IT_SET1) != (uint32_t)RESET)
  9197. {
  9198. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_SET1);
  9199. /* Invoke output 1 set event callback */
  9200. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9201. hhrtim->Output1SetCallback(hhrtim, TimerIdx);
  9202. #else
  9203. HAL_HRTIM_Output1SetCallback(hhrtim, TimerIdx);
  9204. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9205. }
  9206. }
  9207. /* Timer output 1 reset event */
  9208. if ((uint32_t)(tisrflags & HRTIM_TIM_FLAG_RST1) != (uint32_t)RESET)
  9209. {
  9210. if ((uint32_t)(tdierits & HRTIM_TIM_IT_RST1) != (uint32_t)RESET)
  9211. {
  9212. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_RST1);
  9213. /* Invoke output 1 reset event callback */
  9214. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9215. hhrtim->Output1ResetCallback(hhrtim, TimerIdx);
  9216. #else
  9217. HAL_HRTIM_Output1ResetCallback(hhrtim, TimerIdx);
  9218. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9219. }
  9220. }
  9221. /* Timer output 2 set event */
  9222. if ((uint32_t)(tisrflags & HRTIM_TIM_FLAG_SET2) != (uint32_t)RESET)
  9223. {
  9224. if ((uint32_t)(tdierits & HRTIM_TIM_IT_SET2) != (uint32_t)RESET)
  9225. {
  9226. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_SET2);
  9227. /* Invoke output 2 set event callback */
  9228. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9229. hhrtim->Output2SetCallback(hhrtim, TimerIdx);
  9230. #else
  9231. HAL_HRTIM_Output2SetCallback(hhrtim, TimerIdx);
  9232. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9233. }
  9234. }
  9235. /* Timer output 2 reset event */
  9236. if ((uint32_t)(tisrflags & HRTIM_TIM_FLAG_RST2) != (uint32_t)RESET)
  9237. {
  9238. if ((uint32_t)(tdierits & HRTIM_TIM_IT_RST2) != (uint32_t)RESET)
  9239. {
  9240. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_RST2);
  9241. /* Invoke output 2 reset event callback */
  9242. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9243. hhrtim->Output2ResetCallback(hhrtim, TimerIdx);
  9244. #else
  9245. HAL_HRTIM_Output2ResetCallback(hhrtim, TimerIdx);
  9246. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9247. }
  9248. }
  9249. /* Timer reset event */
  9250. if ((uint32_t)(tisrflags & HRTIM_TIM_FLAG_RST) != (uint32_t)RESET)
  9251. {
  9252. if ((uint32_t)(tdierits & HRTIM_TIM_IT_RST) != (uint32_t)RESET)
  9253. {
  9254. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_RST);
  9255. /* Invoke timer reset callback */
  9256. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9257. hhrtim->CounterResetCallback(hhrtim, TimerIdx);
  9258. #else
  9259. HAL_HRTIM_CounterResetCallback(hhrtim, TimerIdx);
  9260. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9261. }
  9262. }
  9263. /* Delayed protection event */
  9264. if ((uint32_t)(tisrflags & HRTIM_TIM_FLAG_DLYPRT) != (uint32_t)RESET)
  9265. {
  9266. if ((uint32_t)(tdierits & HRTIM_TIM_IT_DLYPRT) != (uint32_t)RESET)
  9267. {
  9268. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_DLYPRT);
  9269. /* Invoke delayed protection callback */
  9270. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9271. hhrtim->DelayedProtectionCallback(hhrtim, TimerIdx);
  9272. #else
  9273. HAL_HRTIM_DelayedProtectionCallback(hhrtim, TimerIdx);
  9274. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9275. }
  9276. }
  9277. }
  9278. /**
  9279. * @brief DMA callback invoked upon master timer related DMA request completion
  9280. * @param hdma pointer to DMA handle.
  9281. * @retval None
  9282. */
  9283. static void HRTIM_DMAMasterCplt(DMA_HandleTypeDef *hdma)
  9284. {
  9285. HRTIM_HandleTypeDef *hrtim = (HRTIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  9286. if ((hrtim->Instance->sMasterRegs.MDIER & HRTIM_MASTER_DMA_MCMP1) != (uint32_t)RESET)
  9287. {
  9288. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9289. hrtim->Compare1EventCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  9290. #else
  9291. HAL_HRTIM_Compare1EventCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  9292. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9293. }
  9294. else if ((hrtim->Instance->sMasterRegs.MDIER & HRTIM_MASTER_DMA_MCMP2) != (uint32_t)RESET)
  9295. {
  9296. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9297. hrtim->Compare2EventCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  9298. #else
  9299. HAL_HRTIM_Compare2EventCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  9300. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9301. }
  9302. else if ((hrtim->Instance->sMasterRegs.MDIER & HRTIM_MASTER_DMA_MCMP3) != (uint32_t)RESET)
  9303. {
  9304. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9305. hrtim->Compare3EventCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  9306. #else
  9307. HAL_HRTIM_Compare3EventCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  9308. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9309. }
  9310. else if ((hrtim->Instance->sMasterRegs.MDIER & HRTIM_MASTER_DMA_MCMP4) != (uint32_t)RESET)
  9311. {
  9312. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9313. hrtim->Compare4EventCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  9314. #else
  9315. HAL_HRTIM_Compare4EventCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  9316. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9317. }
  9318. else if ((hrtim->Instance->sMasterRegs.MDIER & HRTIM_MASTER_DMA_SYNC) != (uint32_t)RESET)
  9319. {
  9320. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9321. hrtim->SynchronizationEventCallback(hrtim);
  9322. #else
  9323. HAL_HRTIM_SynchronizationEventCallback(hrtim);
  9324. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9325. }
  9326. else if ((hrtim->Instance->sMasterRegs.MDIER & HRTIM_MASTER_DMA_MUPD) != (uint32_t)RESET)
  9327. {
  9328. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9329. hrtim->RegistersUpdateCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  9330. #else
  9331. HAL_HRTIM_RegistersUpdateCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  9332. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9333. }
  9334. else if ((hrtim->Instance->sMasterRegs.MDIER & HRTIM_MASTER_DMA_MREP) != (uint32_t)RESET)
  9335. {
  9336. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9337. hrtim->RepetitionEventCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  9338. #else
  9339. HAL_HRTIM_RepetitionEventCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  9340. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9341. }
  9342. else
  9343. {
  9344. /* nothing to do */
  9345. }
  9346. }
  9347. /**
  9348. * @brief DMA callback invoked upon timer A..F related DMA request completion
  9349. * @param hdma pointer to DMA handle.
  9350. * @retval None
  9351. */
  9352. static void HRTIM_DMATimerxCplt(DMA_HandleTypeDef *hdma)
  9353. {
  9354. uint8_t timer_idx;
  9355. HRTIM_HandleTypeDef *hrtim = (HRTIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  9356. timer_idx = (uint8_t)GetTimerIdxFromDMAHandle(hrtim, hdma);
  9357. if (!IS_HRTIM_TIMING_UNIT(timer_idx)) {return;}
  9358. if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_CMP1) != (uint32_t)RESET)
  9359. {
  9360. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9361. hrtim->Compare1EventCallback(hrtim, timer_idx);
  9362. #else
  9363. HAL_HRTIM_Compare1EventCallback(hrtim, timer_idx);
  9364. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9365. }
  9366. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_CMP2) != (uint32_t)RESET)
  9367. {
  9368. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9369. hrtim->Compare2EventCallback(hrtim, timer_idx);
  9370. #else
  9371. HAL_HRTIM_Compare2EventCallback(hrtim, timer_idx);
  9372. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9373. }
  9374. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_CMP3) != (uint32_t)RESET)
  9375. {
  9376. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9377. hrtim->Compare3EventCallback(hrtim, timer_idx);
  9378. #else
  9379. HAL_HRTIM_Compare3EventCallback(hrtim, timer_idx);
  9380. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9381. }
  9382. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_CMP4) != (uint32_t)RESET)
  9383. {
  9384. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9385. hrtim->Compare4EventCallback(hrtim, timer_idx);
  9386. #else
  9387. HAL_HRTIM_Compare4EventCallback(hrtim, timer_idx);
  9388. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9389. }
  9390. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_UPD) != (uint32_t)RESET)
  9391. {
  9392. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9393. hrtim->RegistersUpdateCallback(hrtim, timer_idx);
  9394. #else
  9395. HAL_HRTIM_RegistersUpdateCallback(hrtim, timer_idx);
  9396. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9397. }
  9398. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_CPT1) != (uint32_t)RESET)
  9399. {
  9400. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9401. hrtim->Capture1EventCallback(hrtim, timer_idx);
  9402. #else
  9403. HAL_HRTIM_Capture1EventCallback(hrtim, timer_idx);
  9404. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9405. }
  9406. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_CPT2) != (uint32_t)RESET)
  9407. {
  9408. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9409. hrtim->Capture2EventCallback(hrtim, timer_idx);
  9410. #else
  9411. HAL_HRTIM_Capture2EventCallback(hrtim, timer_idx);
  9412. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9413. }
  9414. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_SET1) != (uint32_t)RESET)
  9415. {
  9416. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9417. hrtim->Output1SetCallback(hrtim, timer_idx);
  9418. #else
  9419. HAL_HRTIM_Output1SetCallback(hrtim, timer_idx);
  9420. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9421. }
  9422. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_RST1) != (uint32_t)RESET)
  9423. {
  9424. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9425. hrtim->Output1ResetCallback(hrtim, timer_idx);
  9426. #else
  9427. HAL_HRTIM_Output1ResetCallback(hrtim, timer_idx);
  9428. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9429. }
  9430. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_SET2) != (uint32_t)RESET)
  9431. {
  9432. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9433. hrtim->Output2SetCallback(hrtim, timer_idx);
  9434. #else
  9435. HAL_HRTIM_Output2SetCallback(hrtim, timer_idx);
  9436. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9437. }
  9438. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_RST2) != (uint32_t)RESET)
  9439. {
  9440. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9441. hrtim->Output2ResetCallback(hrtim, timer_idx);
  9442. #else
  9443. HAL_HRTIM_Output2ResetCallback(hrtim, timer_idx);
  9444. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9445. }
  9446. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_RST) != (uint32_t)RESET)
  9447. {
  9448. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9449. hrtim->CounterResetCallback(hrtim, timer_idx);
  9450. #else
  9451. HAL_HRTIM_CounterResetCallback(hrtim, timer_idx);
  9452. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9453. }
  9454. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_DLYPRT) != (uint32_t)RESET)
  9455. {
  9456. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9457. hrtim->DelayedProtectionCallback(hrtim, timer_idx);
  9458. #else
  9459. HAL_HRTIM_DelayedProtectionCallback(hrtim, timer_idx);
  9460. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9461. }
  9462. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_REP) != (uint32_t)RESET)
  9463. {
  9464. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9465. hrtim->RepetitionEventCallback(hrtim, timer_idx);
  9466. #else
  9467. HAL_HRTIM_RepetitionEventCallback(hrtim, timer_idx);
  9468. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9469. }
  9470. else
  9471. {
  9472. /* nothing to do */
  9473. }
  9474. }
  9475. /**
  9476. * @brief DMA error callback
  9477. * @param hdma pointer to DMA handle.
  9478. * @retval None
  9479. */
  9480. static void HRTIM_DMAError(DMA_HandleTypeDef *hdma)
  9481. {
  9482. HRTIM_HandleTypeDef *hrtim = (HRTIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  9483. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9484. hrtim->ErrorCallback(hrtim);
  9485. #else
  9486. HAL_HRTIM_ErrorCallback(hrtim);
  9487. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9488. }
  9489. /**
  9490. * @brief DMA callback invoked upon burst DMA transfer completion
  9491. * @param hdma pointer to DMA handle.
  9492. * @retval None
  9493. */
  9494. static void HRTIM_BurstDMACplt(DMA_HandleTypeDef *hdma)
  9495. {
  9496. HRTIM_HandleTypeDef *hrtim = (HRTIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  9497. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  9498. hrtim->BurstDMATransferCallback(hrtim, GetTimerIdxFromDMAHandle(hrtim, hdma));
  9499. #else
  9500. HAL_HRTIM_BurstDMATransferCallback(hrtim, GetTimerIdxFromDMAHandle(hrtim, hdma));
  9501. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  9502. }
  9503. /**
  9504. * @}
  9505. */
  9506. /**
  9507. * @}
  9508. */
  9509. #endif /* HRTIM1 */
  9510. #endif /* HAL_HRTIM_MODULE_ENABLED */
  9511. /**
  9512. * @}
  9513. */