stm32h7xx_hal_fdcan.c 161 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775
  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_fdcan.c
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 21-April-2017
  7. * @brief FDCAN HAL module driver.
  8. * This file provides firmware functions to manage the following
  9. * functionalities of the Flexible DataRate Controller Area Network
  10. * (FDCAN) peripheral:
  11. * + Initialization and de-initialization functions
  12. * + IO operation functions
  13. * + Peripheral Configuration and Control functions
  14. * + Peripheral State and Error functions
  15. *
  16. @verbatim
  17. ==============================================================================
  18. ##### How to use this driver #####
  19. ==============================================================================
  20. [..]
  21. (#) Initialize the FDCAN peripheral using HAL_FDCAN_Init function.
  22. (#) If needed , configure the reception filters and optional features using
  23. the following configuration functions:
  24. (++) HAL_FDCAN_ConfigClockCalibration
  25. (++) HAL_FDCAN_ConfigFilter
  26. (++) HAL_FDCAN_ConfigGlobalFilter
  27. (++) HAL_FDCAN_ConfigExtendedIdMask
  28. (++) HAL_FDCAN_ConfigRxFifoOverwrite
  29. (++) HAL_FDCAN_ConfigFifoWatermark
  30. (++) HAL_FDCAN_ConfigRamWatchdog
  31. (++) HAL_FDCAN_ConfigTimestampCounter
  32. (++) HAL_FDCAN_EnableTimestampCounter
  33. (++) HAL_FDCAN_DisableTimestampCounter
  34. (++) HAL_FDCAN_ConfigTimeoutCounter
  35. (++) HAL_FDCAN_EnableTimeoutCounter
  36. (++) HAL_FDCAN_DisableTimeoutCounter
  37. (++) HAL_FDCAN_ConfigTxDelayCompensation
  38. (++) HAL_FDCAN_EnableTxDelayCompensation
  39. (++) HAL_FDCAN_DisableTxDelayCompensation
  40. (++) HAL_FDCAN_TT_ConfigOperation
  41. (++) HAL_FDCAN_TT_ConfigReferenceMessage
  42. (++) HAL_FDCAN_TT_ConfigTrigger
  43. (#) Start the FDCAN module using HAL_FDCAN_Start function. At this level
  44. the node is active on the bus: it can send and receive messages.
  45. (#) The following Tx control functions can only be called when the FDCAN
  46. module is started:
  47. (++) HAL_FDCAN_AddMessageToTxFifoQ
  48. (++) HAL_FDCAN_EnableTxBufferRequest
  49. (++) HAL_FDCAN_AbortTxRequest
  50. (#) When a message is received into the FDCAN message RAM, it can be
  51. retrieved using the HAL_FDCAN_GetRxMessage function.
  52. (#) Calling the HAL_FDCAN_Stop function stops the FDCAN module by entering
  53. it to initialization mode and re-enabling access to configuration
  54. registers through the configuration functions listed here above.
  55. (#) All other control functions can be called any time after initialization
  56. phase, no matter if the FDCAN module is started or stoped.
  57. *** Polling mode operation ***
  58. ==============================
  59. [..]
  60. (#) Reception and transmission states can be monitored via the following
  61. functions:
  62. (++) HAL_FDCAN_IsRxBufferMessageAvailable
  63. (++) HAL_FDCAN_IsTxBufferMessagePending
  64. (++) HAL_FDCAN_GetRxFifoFillLevel
  65. (++) HAL_FDCAN_GetTxFifoFreeLevel
  66. *** Interrupt mode operation ***
  67. ================================
  68. [..]
  69. (#) There are two interrupt lines: line 0 and 1.
  70. By default, all interrupts are assigned to line 0. Interrupt lines
  71. can be configured using HAL_FDCAN_ConfigInterruptLines function.
  72. (#) Notifications are activated using HAL_FDCAN_ActivateNotification
  73. function. Then, the process can be controlled through one of the
  74. available user callbacks: HAL_FDCAN_xxxCallback.
  75. @endverbatim
  76. ******************************************************************************
  77. * @attention
  78. *
  79. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  80. *
  81. * Redistribution and use in source and binary forms, with or without modification,
  82. * are permitted provided that the following conditions are met:
  83. * 1. Redistributions of source code must retain the above copyright notice,
  84. * this list of conditions and the following disclaimer.
  85. * 2. Redistributions in binary form must reproduce the above copyright notice,
  86. * this list of conditions and the following disclaimer in the documentation
  87. * and/or other materials provided with the distribution.
  88. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  89. * may be used to endorse or promote products derived from this software
  90. * without specific prior written permission.
  91. *
  92. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  93. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  94. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  95. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  96. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  97. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  98. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  99. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  100. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  101. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  102. *
  103. ******************************************************************************
  104. */
  105. /* Includes ------------------------------------------------------------------*/
  106. #include "stm32h7xx_hal.h"
  107. /** @addtogroup STM32H7xx_HAL_Driver
  108. * @{
  109. */
  110. /** @defgroup FDCAN FDCAN
  111. * @brief FDCAN HAL module driver
  112. * @{
  113. */
  114. #ifdef HAL_FDCAN_MODULE_ENABLED
  115. /* Private typedef -----------------------------------------------------------*/
  116. /* Private define ------------------------------------------------------------*/
  117. /** @addtogroup FDCAN_Private_Constants
  118. * @{
  119. */
  120. #define FDCAN_TIMEOUT_VALUE 10
  121. #define FDCAN_TX_EVENT_FIFO_MASK (FDCAN_IR_TEFL | FDCAN_IR_TEFF | FDCAN_IR_TEFW | FDCAN_IR_TEFN)
  122. #define FDCAN_RX_FIFO0_MASK (FDCAN_IR_RF0L | FDCAN_IR_RF0F | FDCAN_IR_RF0W | FDCAN_IR_RF0N)
  123. #define FDCAN_RX_FIFO1_MASK (FDCAN_IR_RF1L | FDCAN_IR_RF1F | FDCAN_IR_RF1W | FDCAN_IR_RF1N)
  124. #define FDCAN_ERROR_MASK (FDCAN_IR_ELO | FDCAN_IR_EP | FDCAN_IR_EW | FDCAN_IR_BO | \
  125. FDCAN_IR_WDI | FDCAN_IR_PEA | FDCAN_IR_PED | FDCAN_IR_ARA)
  126. #define FDCAN_TT_SCHEDULE_SYNC_MASK (FDCAN_TTIR_SBC | FDCAN_TTIR_SMC | FDCAN_TTIR_CSM | FDCAN_TTIR_SOG)
  127. #define FDCAN_TT_TIME_MARK_MASK (FDCAN_TTIR_RTMI | FDCAN_TTIR_TTMI)
  128. #define FDCAN_TT_GLOBAL_TIME_MASK (FDCAN_TTIR_GTW | FDCAN_TTIR_GTD)
  129. #define FDCAN_TT_DISTURBING_ERROR_MASK (FDCAN_TTIR_GTE | FDCAN_TTIR_TXU | FDCAN_TTIR_TXO | \
  130. FDCAN_TTIR_SE1 | FDCAN_TTIR_SE2 | FDCAN_TTIR_ELC)
  131. #define FDCAN_TT_FATAL_ERROR_MASK (FDCAN_TTIR_IWT | FDCAN_TTIR_WT | FDCAN_TTIR_AW | FDCAN_TTIR_CER)
  132. #define FDCAN_ELEMENT_MASK_STDID ((uint32_t)0x1FFC0000U) /* Standard Identifier */
  133. #define FDCAN_ELEMENT_MASK_EXTID ((uint32_t)0x1FFFFFFFU) /* Extended Identifier */
  134. #define FDCAN_ELEMENT_MASK_RTR ((uint32_t)0x20000000U) /* Remote Transmission Request */
  135. #define FDCAN_ELEMENT_MASK_XTD ((uint32_t)0x40000000U) /* Extended Identifier */
  136. #define FDCAN_ELEMENT_MASK_ESI ((uint32_t)0x80000000U) /* Error State Indicator */
  137. #define FDCAN_ELEMENT_MASK_TS ((uint32_t)0x0000FFFFU) /* Timestamp */
  138. #define FDCAN_ELEMENT_MASK_DLC ((uint32_t)0x000F0000U) /* Data Length Code */
  139. #define FDCAN_ELEMENT_MASK_BRS ((uint32_t)0x00100000U) /* Bit Rate Switch */
  140. #define FDCAN_ELEMENT_MASK_FDF ((uint32_t)0x00200000U) /* FD Format */
  141. #define FDCAN_ELEMENT_MASK_EFC ((uint32_t)0x00800000U) /* Event FIFO Control */
  142. #define FDCAN_ELEMENT_MASK_MM ((uint32_t)0xFF000000U) /* Message Marker */
  143. #define FDCAN_ELEMENT_MASK_FIDX ((uint32_t)0x7F000000U) /* Filter Index */
  144. #define FDCAN_ELEMENT_MASK_ANMF ((uint32_t)0x80000000U) /* Accepted Non-matching Frame */
  145. #define FDCAN_ELEMENT_MASK_ET ((uint32_t)0x00C00000U) /* Event type */
  146. /**
  147. * @}
  148. */
  149. /* Private macro -------------------------------------------------------------*/
  150. /* Private variables ---------------------------------------------------------*/
  151. static const uint8_t DLCtoBytes[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64};
  152. static const uint8_t CvtEltSize[] = {0, 0, 0, 0, 0, 1, 2, 3, 4, 0, 5, 0, 0, 0, 6, 0, 0, 0, 7};
  153. /* Private function prototypes -----------------------------------------------*/
  154. /** @addtogroup FDCAN_Private_Functions_Prototypes
  155. * @{
  156. */
  157. static HAL_StatusTypeDef FDCAN_CalcultateRamBlockAddresses(FDCAN_HandleTypeDef *hfdcan);
  158. static HAL_StatusTypeDef FDCAN_CopyMessageToRAM(FDCAN_HandleTypeDef *hfdcan, FDCAN_TxHeaderTypeDef *pTxHeader, uint8_t *pTxData, uint32_t BufferIndex);
  159. /**
  160. * @}
  161. */
  162. /* Exported functions --------------------------------------------------------*/
  163. /** @defgroup FDCAN_Exported_Functions FDCAN Exported Functions
  164. * @{
  165. */
  166. /** @defgroup FDCAN_Exported_Functions_Group1 Initialization and de-initialization functions
  167. * @brief Initialization and Configuration functions
  168. *
  169. @verbatim
  170. ==============================================================================
  171. ##### Initialization and de-initialization functions #####
  172. ==============================================================================
  173. [..] This section provides functions allowing to:
  174. (+) Initialize and configure the FDCAN.
  175. (+) De-initialize the FDCAN.
  176. (+) Enter FDCAN peripheral in power down mode.
  177. (+) Exit power down mode.
  178. @endverbatim
  179. * @{
  180. */
  181. /**
  182. * @brief Initializes the FDCAN peripheral according to the specified
  183. * parameters in the FDCAN_InitTypeDef structure.
  184. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  185. * the configuration information for the specified FDCAN.
  186. * @retval HAL status
  187. */
  188. HAL_StatusTypeDef HAL_FDCAN_Init(FDCAN_HandleTypeDef* hfdcan)
  189. {
  190. uint32_t tickstart = 0U;
  191. /* Check FDCAN handle */
  192. if(hfdcan == NULL)
  193. {
  194. return HAL_ERROR;
  195. }
  196. /* Check FDCAN instance */
  197. if(hfdcan->Instance == FDCAN1)
  198. {
  199. hfdcan->ttcan = (TTCAN_TypeDef *)((uint32_t)hfdcan->Instance + 0x100);
  200. }
  201. /* Check function parameters */
  202. assert_param(IS_FDCAN_ALL_INSTANCE(hfdcan->Instance));
  203. assert_param(IS_FDCAN_FRAME_FORMAT(hfdcan->Init.FrameFormat));
  204. assert_param(IS_FDCAN_MODE(hfdcan->Init.Mode));
  205. assert_param(IS_FUNCTIONAL_STATE(hfdcan->Init.AutoRetransmission));
  206. assert_param(IS_FUNCTIONAL_STATE(hfdcan->Init.TransmitPause));
  207. assert_param(IS_FUNCTIONAL_STATE(hfdcan->Init.ProtocolException));
  208. assert_param(IS_FDCAN_NOMINAL_PRESCALER(hfdcan->Init.NominalPrescaler));
  209. assert_param(IS_FDCAN_NOMINAL_SJW(hfdcan->Init.NominalSyncJumpWidth));
  210. assert_param(IS_FDCAN_NOMINAL_TSEG1(hfdcan->Init.NominalTimeSeg1));
  211. assert_param(IS_FDCAN_NOMINAL_TSEG2(hfdcan->Init.NominalTimeSeg2));
  212. if(hfdcan->Init.FrameFormat == FDCAN_FRAME_FD_BRS)
  213. {
  214. assert_param(IS_FDCAN_DATA_PRESCALER(hfdcan->Init.DataPrescaler));
  215. assert_param(IS_FDCAN_DATA_SJW(hfdcan->Init.DataSyncJumpWidth));
  216. assert_param(IS_FDCAN_DATA_TSEG1(hfdcan->Init.DataTimeSeg1));
  217. assert_param(IS_FDCAN_DATA_TSEG2(hfdcan->Init.DataTimeSeg2));
  218. }
  219. assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.StdFiltersNbr, 128));
  220. assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.ExtFiltersNbr, 64));
  221. assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.RxFifo0ElmtsNbr, 64));
  222. if(hfdcan->Init.RxFifo0ElmtsNbr > 0)
  223. {
  224. assert_param(IS_FDCAN_DATA_SIZE(hfdcan->Init.RxFifo0ElmtSize));
  225. }
  226. assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.RxFifo1ElmtsNbr, 64));
  227. if(hfdcan->Init.RxFifo1ElmtsNbr > 0)
  228. {
  229. assert_param(IS_FDCAN_DATA_SIZE(hfdcan->Init.RxFifo1ElmtSize));
  230. }
  231. assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.RxBuffersNbr, 64));
  232. if(hfdcan->Init.RxBuffersNbr > 0)
  233. {
  234. assert_param(IS_FDCAN_DATA_SIZE(hfdcan->Init.RxBufferSize));
  235. }
  236. assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.TxEventsNbr, 32));
  237. assert_param(IS_FDCAN_MAX_VALUE((hfdcan->Init.TxBuffersNbr + hfdcan->Init.TxFifoQueueElmtsNbr), 32));
  238. if(hfdcan->Init.TxFifoQueueElmtsNbr > 0)
  239. {
  240. assert_param(IS_FDCAN_TX_FIFO_QUEUE_MODE(hfdcan->Init.TxFifoQueueMode));
  241. }
  242. if((hfdcan->Init.TxBuffersNbr + hfdcan->Init.TxFifoQueueElmtsNbr) > 0)
  243. {
  244. assert_param(IS_FDCAN_DATA_SIZE(hfdcan->Init.TxElmtSize));
  245. }
  246. if(hfdcan->State == HAL_FDCAN_STATE_RESET)
  247. {
  248. /* Allocate lock resource and initialize it */
  249. hfdcan->Lock = HAL_UNLOCKED;
  250. /* Init the low level hardware */
  251. HAL_FDCAN_MspInit(hfdcan);
  252. }
  253. /* Exit from Sleep mode */
  254. CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CSR);
  255. /* Get tick */
  256. tickstart = HAL_GetTick();
  257. /* Check Sleep mode acknowledge */
  258. while((hfdcan->Instance->CCCR & FDCAN_CCCR_CSA) == FDCAN_CCCR_CSA)
  259. {
  260. if((HAL_GetTick() - tickstart) > FDCAN_TIMEOUT_VALUE)
  261. {
  262. /* Update error code */
  263. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  264. /* Change FDCAN state */
  265. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  266. return HAL_ERROR;
  267. }
  268. }
  269. /* Request initialisation */
  270. SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT);
  271. /* Get tick */
  272. tickstart = HAL_GetTick();
  273. /* Wait until the INIT bit into CCCR register is set */
  274. while((hfdcan->Instance->CCCR & FDCAN_CCCR_INIT) == RESET)
  275. {
  276. /* Check for the Timeout */
  277. if((HAL_GetTick() - tickstart) > FDCAN_TIMEOUT_VALUE)
  278. {
  279. /* Update error code */
  280. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  281. /* Change FDCAN state */
  282. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  283. return HAL_ERROR;
  284. }
  285. }
  286. /* Enable configuration change */
  287. SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CCE);
  288. /* Set the no automatic retransmission */
  289. if(hfdcan->Init.AutoRetransmission == ENABLE)
  290. {
  291. CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_DAR);
  292. }
  293. else
  294. {
  295. SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_DAR);
  296. }
  297. /* Set the transmit pause feature */
  298. if(hfdcan->Init.TransmitPause == ENABLE)
  299. {
  300. SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_TXP);
  301. }
  302. else
  303. {
  304. CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_TXP);
  305. }
  306. /* Set the Protocol Exception Handling */
  307. if(hfdcan->Init.ProtocolException == ENABLE)
  308. {
  309. CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_PXHD);
  310. }
  311. else
  312. {
  313. SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_PXHD);
  314. }
  315. /* Set FDCAN Frame Format */
  316. MODIFY_REG(hfdcan->Instance->CCCR, FDCAN_FRAME_FD_BRS, hfdcan->Init.FrameFormat);
  317. /* Set FDCAN Operating Mode:
  318. | Normal | Restricted | Bus | Internal | External
  319. | | Operation | Monitoring | LoopBack | LoopBack
  320. CCCR.TEST | 0 | 0 | 0 | 1 | 1
  321. CCCR.MON | 0 | 0 | 1 | 0 | 1
  322. TEST.LBCK | 0 | 0 | 0 | 1 | 1
  323. CCCR.ASM | 0 | 1 | 0 | 0 | 0
  324. */
  325. if(hfdcan->Init.Mode == FDCAN_MODE_RESTRICTED_OPERATION)
  326. {
  327. /* Enable Restricted Operation mode */
  328. SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_ASM);
  329. }
  330. else if(hfdcan->Init.Mode != FDCAN_MODE_NORMAL)
  331. {
  332. if(hfdcan->Init.Mode != FDCAN_MODE_BUS_MONITORING)
  333. {
  334. /* Enable write access to TEST register */
  335. SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_TEST);
  336. /* Enable LoopBack mode */
  337. SET_BIT(hfdcan->Instance->TEST, FDCAN_TEST_LBCK);
  338. if(hfdcan->Init.Mode == FDCAN_MODE_EXTERNAL_LOOPBACK)
  339. {
  340. SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_MON);
  341. }
  342. }
  343. else
  344. {
  345. /* Enable bus monitoring mode */
  346. SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_MON);
  347. }
  348. }
  349. /* Set the nominal bit timing register */
  350. hfdcan->Instance->NBTP = ((((uint32_t)hfdcan->Init.NominalSyncJumpWidth - 1) << 25) | \
  351. (((uint32_t)hfdcan->Init.NominalTimeSeg1 - 1) << 8) | \
  352. ((uint32_t)hfdcan->Init.NominalTimeSeg2 - 1) | \
  353. (((uint32_t)hfdcan->Init.NominalPrescaler - 1) << 16));
  354. /* If FD operation with BRS is selected, set the data bit timing register */
  355. if(hfdcan->Init.FrameFormat == FDCAN_FRAME_FD_BRS)
  356. {
  357. hfdcan->Instance->DBTP = (((uint32_t)hfdcan->Init.DataSyncJumpWidth - 1) | \
  358. (((uint32_t)hfdcan->Init.DataTimeSeg1 - 1) << 8) | \
  359. (((uint32_t)hfdcan->Init.DataTimeSeg2 - 1) << 4) | \
  360. (((uint32_t)hfdcan->Init.DataPrescaler - 1) << 16));
  361. }
  362. if(hfdcan->Init.TxFifoQueueElmtsNbr > 0)
  363. {
  364. /* Select between Tx FIFO and Tx Queue operation modes */
  365. SET_BIT(hfdcan->Instance->TXBC, hfdcan->Init.TxFifoQueueMode);
  366. }
  367. /* Configure Tx element size */
  368. if((hfdcan->Init.TxBuffersNbr + hfdcan->Init.TxFifoQueueElmtsNbr) > 0)
  369. {
  370. MODIFY_REG(hfdcan->Instance->TXESC, FDCAN_TXESC_TBDS, CvtEltSize[hfdcan->Init.TxElmtSize]);
  371. }
  372. /* Configure Rx FIFO 0 element size */
  373. if(hfdcan->Init.RxFifo0ElmtsNbr > 0)
  374. {
  375. MODIFY_REG(hfdcan->Instance->RXESC, FDCAN_RXESC_F0DS, CvtEltSize[hfdcan->Init.RxFifo0ElmtSize]);
  376. }
  377. /* Configure Rx FIFO 1 element size */
  378. if(hfdcan->Init.RxFifo1ElmtsNbr > 0)
  379. {
  380. MODIFY_REG(hfdcan->Instance->RXESC, FDCAN_RXESC_F1DS, (CvtEltSize[hfdcan->Init.RxFifo1ElmtSize] << 4));
  381. }
  382. /* Configure Rx buffer element size */
  383. if(hfdcan->Init.RxBuffersNbr > 0)
  384. {
  385. MODIFY_REG(hfdcan->Instance->RXESC, FDCAN_RXESC_RBDS, (CvtEltSize[hfdcan->Init.RxBufferSize] << 8));
  386. }
  387. /* By default operation mode is set to Event-driven communication.
  388. If Time-triggered communication is needed, user should call the
  389. HAL_FDCAN_TT_ConfigOperation function just after the HAL_FDCAN_Init */
  390. if(hfdcan->Instance == FDCAN1)
  391. {
  392. CLEAR_BIT(hfdcan->ttcan->TTOCF, FDCAN_TTOCF_OM);
  393. }
  394. /* Calculate each RAM block address */
  395. FDCAN_CalcultateRamBlockAddresses(hfdcan);
  396. /* Initialize the error code */
  397. hfdcan->ErrorCode = HAL_FDCAN_ERROR_NONE;
  398. /* Initialize the FDCAN state */
  399. hfdcan->State = HAL_FDCAN_STATE_READY;
  400. /* Return function status */
  401. return HAL_OK;
  402. }
  403. /**
  404. * @brief Deinitializes the FDCAN peripheral registers to their default reset values.
  405. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  406. * the configuration information for the specified FDCAN.
  407. * @retval HAL status
  408. */
  409. HAL_StatusTypeDef HAL_FDCAN_DeInit(FDCAN_HandleTypeDef* hfdcan)
  410. {
  411. /* Check FDCAN handle */
  412. if(hfdcan == NULL)
  413. {
  414. return HAL_ERROR;
  415. }
  416. /* Check function parameters */
  417. assert_param(IS_FDCAN_ALL_INSTANCE(hfdcan->Instance));
  418. /* Stop the FDCAN module */
  419. HAL_FDCAN_Stop(hfdcan);
  420. /* DeInit the low level hardware */
  421. HAL_FDCAN_MspDeInit(hfdcan);
  422. /* Reset the FDCAN ErrorCode */
  423. hfdcan->ErrorCode = HAL_FDCAN_ERROR_NONE;
  424. /* Change FDCAN state */
  425. hfdcan->State = HAL_FDCAN_STATE_RESET;
  426. /* Return function status */
  427. return HAL_OK;
  428. }
  429. /**
  430. * @brief Initializes the FDCAN MSP.
  431. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  432. * the configuration information for the specified FDCAN.
  433. * @retval None
  434. */
  435. __weak void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* hfdcan)
  436. {
  437. /* Prevent unused argument(s) compilation warning */
  438. UNUSED(hfdcan);
  439. /* NOTE : This function Should not be modified, when the callback is needed,
  440. the HAL_FDCAN_MspInit could be implemented in the user file
  441. */
  442. }
  443. /**
  444. * @brief DeInitializes the FDCAN MSP.
  445. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  446. * the configuration information for the specified FDCAN.
  447. * @retval None
  448. */
  449. __weak void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* hfdcan)
  450. {
  451. /* Prevent unused argument(s) compilation warning */
  452. UNUSED(hfdcan);
  453. /* NOTE : This function Should not be modified, when the callback is needed,
  454. the HAL_FDCAN_MspDeInit could be implemented in the user file
  455. */
  456. }
  457. /**
  458. * @brief Enter FDCAN peripheral in sleep mode.
  459. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  460. * the configuration information for the specified FDCAN.
  461. * @retval HAL status
  462. */
  463. HAL_StatusTypeDef HAL_FDCAN_EnterPowerDownMode(FDCAN_HandleTypeDef *hfdcan)
  464. {
  465. uint32_t tickstart = 0U;
  466. /* Request clock stop */
  467. SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CSR);
  468. /* Get tick */
  469. tickstart = HAL_GetTick();
  470. /* Wait until FDCAN is ready for power down */
  471. while((hfdcan->Instance->CCCR & FDCAN_CCCR_CSA) == RESET)
  472. {
  473. if((HAL_GetTick() - tickstart) > FDCAN_TIMEOUT_VALUE)
  474. {
  475. /* Update error code */
  476. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  477. /* Change FDCAN state */
  478. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  479. return HAL_ERROR;
  480. }
  481. }
  482. /* Return function status */
  483. return HAL_OK;
  484. }
  485. /**
  486. * @brief Exit power down mode.
  487. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  488. * the configuration information for the specified FDCAN.
  489. * @retval HAL status
  490. */
  491. HAL_StatusTypeDef HAL_FDCAN_ExitPowerDownMode(FDCAN_HandleTypeDef *hfdcan)
  492. {
  493. uint32_t tickstart = 0U;
  494. /* Reset clock stop request */
  495. CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CSR);
  496. /* Get tick */
  497. tickstart = HAL_GetTick();
  498. /* Wait until FDCAN exits sleep mode */
  499. while((hfdcan->Instance->CCCR & FDCAN_CCCR_CSA) == FDCAN_CCCR_CSA)
  500. {
  501. if((HAL_GetTick() - tickstart) > FDCAN_TIMEOUT_VALUE)
  502. {
  503. /* Update error code */
  504. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  505. /* Change FDCAN state */
  506. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  507. return HAL_ERROR;
  508. }
  509. }
  510. /* Enter normal operation */
  511. CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT);
  512. /* Return function status */
  513. return HAL_OK;
  514. }
  515. /**
  516. * @}
  517. */
  518. /** @defgroup FDCAN_Exported_Functions_Group2 Configuration functions
  519. * @brief FDCAN Configuration functions.
  520. *
  521. @verbatim
  522. ==============================================================================
  523. ##### Configuration functions #####
  524. ==============================================================================
  525. [..] This section provides functions allowing to:
  526. (+) HAL_FDCAN_ConfigClockCalibration : Configure the FDCAN clock calibration unit
  527. (+) HAL_FDCAN_GetClockCalibrationState : Get the clock calibration state
  528. (+) HAL_FDCAN_ResetClockCalibrationState : Reset the clock calibration state
  529. (+) HAL_FDCAN_GetClockCalibrationCounter : Get the clock calibration counters values
  530. (+) HAL_FDCAN_ConfigFilter : Configure the FDCAN reception filters
  531. (+) HAL_FDCAN_ConfigGlobalFilter : Configure the FDCAN global filter
  532. (+) HAL_FDCAN_ConfigExtendedIdMask : Configure the extended ID mask
  533. (+) HAL_FDCAN_ConfigRxFifoOverwrite : Configure the Rx FIFO operation mode
  534. (+) HAL_FDCAN_ConfigFifoWatermark : Configure the FIFO watermark
  535. (+) HAL_FDCAN_ConfigRamWatchdog : Configure the RAM watchdog
  536. (+) HAL_FDCAN_ConfigTimestampCounter : Configure the timestamp counter
  537. (+) HAL_FDCAN_EnableTimestampCounter : Enable the timestamp counter
  538. (+) HAL_FDCAN_DisableTimestampCounter : Disable the timestamp counter
  539. (+) HAL_FDCAN_GetTimestampCounter : Get the timestamp counter value
  540. (+) HAL_FDCAN_ResetTimestampCounter : Reset the timestamp counter to zero
  541. (+) HAL_FDCAN_ConfigTimeoutCounter : Configure the timeout counter
  542. (+) HAL_FDCAN_EnableTimeoutCounter : Enable the timeout counter
  543. (+) HAL_FDCAN_DisableTimeoutCounter : Disable the timeout counter
  544. (+) HAL_FDCAN_GetTimeoutCounter : Get the timeout counter value
  545. (+) HAL_FDCAN_ResetTimeoutCounter : Reset the timeout counter to its start value
  546. (+) HAL_FDCAN_ConfigTxDelayCompensation : Configure the transmitter delay compensation
  547. (+) HAL_FDCAN_EnableTxDelayCompensation : Enable the transmitter delay compensation
  548. (+) HAL_FDCAN_DisableTxDelayCompensation : Disable the transmitter delay compensation
  549. @endverbatim
  550. * @{
  551. */
  552. /**
  553. * @brief Configure the FDCAN clock calibration unit according to the specified
  554. * parameters in the FDCAN_ClkCalUnitTypeDef structure.
  555. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  556. * the configuration information for the specified FDCAN.
  557. * @param sCcuConfig: pointer to an FDCAN_ClkCalUnitTypeDef structure that
  558. * contains the clock calibration information
  559. * @retval HAL status
  560. */
  561. HAL_StatusTypeDef HAL_FDCAN_ConfigClockCalibration(FDCAN_HandleTypeDef* hfdcan, FDCAN_ClkCalUnitTypeDef* sCcuConfig)
  562. {
  563. /* Check function parameters */
  564. assert_param(IS_FUNCTIONAL_STATE(sCcuConfig->ClockCalibration));
  565. if(sCcuConfig->ClockCalibration == DISABLE)
  566. {
  567. assert_param(IS_FDCAN_CKDIV(sCcuConfig->ClockDivider));
  568. }
  569. else
  570. {
  571. assert_param(IS_FDCAN_MAX_VALUE(sCcuConfig->MinOscClkPeriods, 0xFF));
  572. assert_param(IS_FDCAN_CALIBRATION_FIELD_LENGTH(sCcuConfig->CalFieldLength));
  573. assert_param(IS_FDCAN_MIN_VALUE(sCcuConfig->TimeQuantaPerBitTime, 4));
  574. assert_param(IS_FDCAN_MAX_VALUE(sCcuConfig->TimeQuantaPerBitTime, 0x25));
  575. assert_param(IS_FDCAN_MAX_VALUE(sCcuConfig->WatchdogStartValue, 0xFFFF));
  576. }
  577. /* FDCAN1 should be initialized in order to use clock calibration */
  578. if(hfdcan->Instance != FDCAN1)
  579. {
  580. /* Update error code */
  581. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  582. return HAL_ERROR;
  583. }
  584. if(hfdcan->State == HAL_FDCAN_STATE_READY)
  585. {
  586. if(sCcuConfig->ClockCalibration == DISABLE)
  587. {
  588. /* Bypass clock calibration */
  589. SET_BIT(FDCAN_CCU->CCFG, FDCANCCU_CCFG_BCC);
  590. /* Configure clock divider */
  591. MODIFY_REG(FDCAN_CCU->CCFG, FDCANCCU_CCFG_CDIV, sCcuConfig->ClockDivider);
  592. }
  593. else /* sCcuConfig->ClockCalibration == ENABLE */
  594. {
  595. /* Clock calibration unit generates time quanta clock */
  596. CLEAR_BIT(FDCAN_CCU->CCFG, FDCANCCU_CCFG_BCC);
  597. /* Configure clock calibration unit */
  598. MODIFY_REG(FDCAN_CCU->CCFG,
  599. (FDCANCCU_CCFG_TQBT | FDCANCCU_CCFG_CFL | FDCANCCU_CCFG_OCPM),
  600. (sCcuConfig->TimeQuantaPerBitTime | sCcuConfig->CalFieldLength | (sCcuConfig->MinOscClkPeriods << 8)));
  601. /* Configure the start value of the calibration watchdog counter */
  602. MODIFY_REG(FDCAN_CCU->CWD, FDCANCCU_CWD_WDC, sCcuConfig->WatchdogStartValue);
  603. }
  604. /* Return function status */
  605. return HAL_OK;
  606. }
  607. else
  608. {
  609. /* Update error code */
  610. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
  611. return HAL_ERROR;
  612. }
  613. }
  614. /**
  615. * @brief Get the clock calibration state.
  616. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  617. * the configuration information for the specified FDCAN.
  618. * @retval State: clock calibration state (can be a value of @arg FDCAN_calibration_state)
  619. */
  620. uint32_t HAL_FDCAN_GetClockCalibrationState(FDCAN_HandleTypeDef* hfdcan)
  621. {
  622. return (FDCAN_CCU->CSTAT & FDCANCCU_CSTAT_CALS);
  623. }
  624. /**
  625. * @brief Reset the clock calibration state.
  626. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  627. * the configuration information for the specified FDCAN.
  628. * @retval HAL status
  629. */
  630. HAL_StatusTypeDef HAL_FDCAN_ResetClockCalibrationState(FDCAN_HandleTypeDef* hfdcan)
  631. {
  632. /* Calibration software reset */
  633. SET_BIT(FDCAN_CCU->CCFG, FDCANCCU_CCFG_SWR);
  634. /* Return function status */
  635. return HAL_OK;
  636. }
  637. /**
  638. * @brief Get the clock calibration counter value.
  639. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  640. * the configuration information for the specified FDCAN.
  641. * @param Counter: clock calibration counter.
  642. * This parameter can be a value of @arg FDCAN_calibration_counter.
  643. * @retval Value: clock calibration counter value
  644. */
  645. uint32_t HAL_FDCAN_GetClockCalibrationCounter(FDCAN_HandleTypeDef* hfdcan, uint32_t Counter)
  646. {
  647. if(Counter == FDCAN_CALIB_TIME_QUANTA_COUNTER)
  648. {
  649. return ((FDCAN_CCU->CSTAT & FDCANCCU_CSTAT_TQC) >> 18);
  650. }
  651. else if(Counter == FDCAN_CALIB_CLOCK_PERIOD_COUNTER)
  652. {
  653. return (FDCAN_CCU->CSTAT & FDCANCCU_CSTAT_OCPC);
  654. }
  655. else /* Counter == FDCAN_CALIB_WATCHDOG_COUNTER */
  656. {
  657. return ((FDCAN_CCU->CWD & FDCANCCU_CWD_WDV) >> 16);
  658. }
  659. }
  660. /**
  661. * @brief Configure the FDCAN reception filter according to the specified
  662. * parameters in the FDCAN_FilterTypeDef structure.
  663. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  664. * the configuration information for the specified FDCAN.
  665. * @param sFilterConfig: pointer to an FDCAN_FilterTypeDef structure that
  666. * contains the filter configuration information
  667. * @retval HAL status
  668. */
  669. HAL_StatusTypeDef HAL_FDCAN_ConfigFilter(FDCAN_HandleTypeDef* hfdcan, FDCAN_FilterTypeDef* sFilterConfig)
  670. {
  671. uint32_t FilterElementW1;
  672. uint32_t FilterElementW2;
  673. uint32_t *FilterAddress;
  674. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  675. {
  676. /* Check function parameters */
  677. assert_param(IS_FDCAN_ID_TYPE(sFilterConfig->IdType));
  678. assert_param(IS_FDCAN_FILTER_CFG(sFilterConfig->FilterConfig));
  679. if(sFilterConfig->FilterConfig == FDCAN_FILTER_TO_RXBUFFER)
  680. {
  681. assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->RxBufferIndex, 63));
  682. assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->IsCalibrationMsg, 1));
  683. }
  684. if(sFilterConfig->IdType == FDCAN_STANDARD_ID)
  685. {
  686. /* Check function parameters */
  687. assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterIndex, (hfdcan->Init.StdFiltersNbr - 1)));
  688. assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterID1, 0x7FF));
  689. if(sFilterConfig->FilterConfig != FDCAN_FILTER_TO_RXBUFFER)
  690. {
  691. assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterID2, 0x7FF));
  692. assert_param(IS_FDCAN_STD_FILTER_TYPE(sFilterConfig->FilterType));
  693. }
  694. /* Build filter element */
  695. if(sFilterConfig->FilterConfig == FDCAN_FILTER_TO_RXBUFFER)
  696. {
  697. FilterElementW1 = ((FDCAN_FILTER_TO_RXBUFFER << 27) |
  698. (sFilterConfig->FilterID1 << 16) |
  699. (sFilterConfig->IsCalibrationMsg << 8) |
  700. sFilterConfig->RxBufferIndex );
  701. }
  702. else
  703. {
  704. FilterElementW1 = ((sFilterConfig->FilterType << 30) |
  705. (sFilterConfig->FilterConfig << 27) |
  706. (sFilterConfig->FilterID1 << 16) |
  707. sFilterConfig->FilterID2 );
  708. }
  709. /* Calculate filter address */
  710. FilterAddress = (uint32_t *)(hfdcan->msgRam.StandardFilterSA + (sFilterConfig->FilterIndex * 4));
  711. /* Write filter element to the message RAM */
  712. *FilterAddress = FilterElementW1;
  713. }
  714. else /* sFilterConfig->IdType == FDCAN_EXTENDED_ID */
  715. {
  716. /* Check function parameters */
  717. assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterIndex, (hfdcan->Init.ExtFiltersNbr - 1)));
  718. assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterID1, 0x1FFFFFFF));
  719. if(sFilterConfig->FilterConfig != FDCAN_FILTER_TO_RXBUFFER)
  720. {
  721. assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterID2, 0x1FFFFFFF));
  722. assert_param(IS_FDCAN_EXT_FILTER_TYPE(sFilterConfig->FilterType));
  723. }
  724. /* Build first word of filter element */
  725. FilterElementW1 = ((sFilterConfig->FilterConfig << 29) | sFilterConfig->FilterID1);
  726. /* Build second word of filter element */
  727. if(sFilterConfig->FilterConfig == FDCAN_FILTER_TO_RXBUFFER)
  728. {
  729. FilterElementW2 = sFilterConfig->RxBufferIndex;
  730. }
  731. else
  732. {
  733. FilterElementW2 = ((sFilterConfig->FilterType << 30) | sFilterConfig->FilterID2);
  734. }
  735. /* Calculate filter address */
  736. FilterAddress = (uint32_t *)(hfdcan->msgRam.ExtendedFilterSA + (sFilterConfig->FilterIndex * 4 * 2));
  737. /* Write filter element to the message RAM */
  738. *FilterAddress++ = FilterElementW1;
  739. *FilterAddress = FilterElementW2;
  740. }
  741. /* Return function status */
  742. return HAL_OK;
  743. }
  744. else
  745. {
  746. /* Update error code */
  747. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  748. return HAL_ERROR;
  749. }
  750. }
  751. /**
  752. * @brief Configure the FDCAN global filter.
  753. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  754. * the configuration information for the specified FDCAN.
  755. * @param NonMatchingStd: Defines how received messages with 11-bit IDs that
  756. do not match any element of the filter list are treated.
  757. This parameter can be a value of @arg FDCAN_Non_Matching_Frames.
  758. * @param NonMatchingExt: Defines how received messages with 29-bit IDs that
  759. do not match any element of the filter list are treated.
  760. This parameter can be a value of @arg FDCAN_Non_Matching_Frames.
  761. * @param RejectRemoteStd: Enable or disable the remote standard frames rejection.
  762. This parameter can be set to ENABLE or DISABLE.
  763. * @param RejectRemoteExt: Enable or disable the remote extended frames rejection.
  764. This parameter can be set to ENABLE or DISABLE.
  765. * @retval HAL status
  766. */
  767. HAL_StatusTypeDef HAL_FDCAN_ConfigGlobalFilter(FDCAN_HandleTypeDef *hfdcan,
  768. uint32_t NonMatchingStd,
  769. uint32_t NonMatchingExt,
  770. uint32_t RejectRemoteStd,
  771. uint32_t RejectRemoteExt)
  772. {
  773. /* Check function parameters */
  774. assert_param(IS_FDCAN_NON_MATCHING(NonMatchingStd));
  775. assert_param(IS_FDCAN_NON_MATCHING(NonMatchingExt));
  776. assert_param(IS_FUNCTIONAL_STATE(RejectRemoteStd));
  777. assert_param(IS_FUNCTIONAL_STATE(RejectRemoteExt));
  778. if(hfdcan->State == HAL_FDCAN_STATE_READY)
  779. {
  780. /* Configure global filter */
  781. hfdcan->Instance->GFC = ((NonMatchingStd << 4U) | (NonMatchingExt << 2U) | (RejectRemoteStd << 1U) | RejectRemoteExt);
  782. /* Return function status */
  783. return HAL_OK;
  784. }
  785. else
  786. {
  787. /* Update error code */
  788. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
  789. return HAL_ERROR;
  790. }
  791. }
  792. /**
  793. * @brief Configure the extended ID mask.
  794. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  795. * the configuration information for the specified FDCAN.
  796. * @param Mask: Extended ID Mask.
  797. This parameter must be a number between 0 and 0x1FFFFFFF
  798. * @retval HAL status
  799. */
  800. HAL_StatusTypeDef HAL_FDCAN_ConfigExtendedIdMask(FDCAN_HandleTypeDef *hfdcan, uint32_t Mask)
  801. {
  802. /* Check function parameters */
  803. assert_param(IS_FDCAN_MAX_VALUE(Mask, 0x1FFFFFFF));
  804. if(hfdcan->State == HAL_FDCAN_STATE_READY)
  805. {
  806. /* Configure the extended ID mask */
  807. hfdcan->Instance->XIDAM = Mask;
  808. /* Return function status */
  809. return HAL_OK;
  810. }
  811. else
  812. {
  813. /* Update error code */
  814. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
  815. return HAL_ERROR;
  816. }
  817. }
  818. /**
  819. * @brief Configure the Rx FIFO operation mode.
  820. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  821. * the configuration information for the specified FDCAN.
  822. * @param RxFifo: Rx FIFO.
  823. * This parameter can be one of the following values:
  824. * @arg FDCAN_RX_FIFO0: Rx FIFO 0
  825. * @arg FDCAN_RX_FIFO1: Rx FIFO 1
  826. * @param OperationMode: operation mode.
  827. * This parameter can be a value of @arg FDCAN_Rx_FIFO_operation_mode.
  828. * @retval HAL status
  829. */
  830. HAL_StatusTypeDef HAL_FDCAN_ConfigRxFifoOverwrite(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo, uint32_t OperationMode)
  831. {
  832. /* Check function parameters */
  833. assert_param(IS_FDCAN_RX_FIFO(RxFifo));
  834. assert_param(IS_FDCAN_RX_FIFO_MODE(OperationMode));
  835. if(hfdcan->State == HAL_FDCAN_STATE_READY)
  836. {
  837. if(RxFifo == FDCAN_RX_FIFO0)
  838. {
  839. /* Select FIFO 0 Operation Mode */
  840. MODIFY_REG(hfdcan->Instance->RXF0C, FDCAN_RXF0C_F0OM, OperationMode);
  841. }
  842. else /* RxFifo == FDCAN_RX_FIFO1 */
  843. {
  844. /* Select FIFO 1 Operation Mode */
  845. MODIFY_REG(hfdcan->Instance->RXF1C, FDCAN_RXF1C_F1OM, OperationMode);
  846. }
  847. /* Return function status */
  848. return HAL_OK;
  849. }
  850. else
  851. {
  852. /* Update error code */
  853. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
  854. return HAL_ERROR;
  855. }
  856. }
  857. /**
  858. * @brief Configure the FIFO watermark.
  859. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  860. * the configuration information for the specified FDCAN.
  861. * @param FIFO: select the FIFO to be configured.
  862. * This parameter can be a value of @arg FDCAN_FIFO_watermark.
  863. * @param Watermark: level for FIFO watermark interrupt.
  864. * This parameter must be a number between:
  865. * - 0 and 32, if FIFO is FDCAN_CFG_TX_EVENT_FIFO
  866. * - 0 and 64, if FIFO is FDCAN_CFG_RX_FIFO0 or FDCAN_CFG_RX_FIFO1
  867. * @retval HAL status
  868. */
  869. HAL_StatusTypeDef HAL_FDCAN_ConfigFifoWatermark(FDCAN_HandleTypeDef *hfdcan, uint32_t FIFO, uint32_t Watermark)
  870. {
  871. /* Check function parameters */
  872. assert_param(IS_FDCAN_FIFO_WATERMARK(FIFO));
  873. if(FIFO == FDCAN_CFG_TX_EVENT_FIFO)
  874. {
  875. assert_param(IS_FDCAN_MAX_VALUE(Watermark, 32));
  876. }
  877. else /* (FIFO == FDCAN_CFG_RX_FIFO0) || (FIFO == FDCAN_CFG_RX_FIFO1) */
  878. {
  879. assert_param(IS_FDCAN_MAX_VALUE(Watermark, 64));
  880. }
  881. if(hfdcan->State == HAL_FDCAN_STATE_READY)
  882. {
  883. /* Set the level for FIFO watermark interrupt */
  884. if(FIFO == FDCAN_CFG_TX_EVENT_FIFO)
  885. {
  886. MODIFY_REG(hfdcan->Instance->TXEFC, FDCAN_TXEFC_EFWM, (Watermark << 24));
  887. }
  888. else if(FIFO == FDCAN_CFG_RX_FIFO0)
  889. {
  890. MODIFY_REG(hfdcan->Instance->RXF0C, FDCAN_RXF0C_F0WM, (Watermark << 24));
  891. }
  892. else /* FIFO == FDCAN_CFG_RX_FIFO1 */
  893. {
  894. MODIFY_REG(hfdcan->Instance->RXF1C, FDCAN_RXF1C_F1WM, (Watermark << 24));
  895. }
  896. /* Return function status */
  897. return HAL_OK;
  898. }
  899. else
  900. {
  901. /* Update error code */
  902. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
  903. return HAL_ERROR;
  904. }
  905. }
  906. /**
  907. * @brief Configure the RAM watchdog.
  908. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  909. * the configuration information for the specified FDCAN.
  910. * @param CounterStartValue: Start value of the Message RAM Watchdog Counter,
  911. * This parameter must be a number between 0x00 and 0xFF,
  912. * with the reset value of 0x00 the counter is disabled.
  913. * @retval HAL status
  914. */
  915. HAL_StatusTypeDef HAL_FDCAN_ConfigRamWatchdog(FDCAN_HandleTypeDef *hfdcan, uint32_t CounterStartValue)
  916. {
  917. /* Check function parameters */
  918. assert_param(IS_FDCAN_MAX_VALUE(CounterStartValue, 0xFF));
  919. if(hfdcan->State == HAL_FDCAN_STATE_READY)
  920. {
  921. /* Configure the RAM watchdog counter start value */
  922. MODIFY_REG(hfdcan->Instance->RWD, FDCAN_RWD_WDC, CounterStartValue);
  923. /* Return function status */
  924. return HAL_OK;
  925. }
  926. else
  927. {
  928. /* Update error code */
  929. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
  930. return HAL_ERROR;
  931. }
  932. }
  933. /**
  934. * @brief Configure the timestamp counter.
  935. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  936. * the configuration information for the specified FDCAN.
  937. * @param TimestampPrescaler: Timestamp Counter Prescaler.
  938. * This parameter can be a value of @arg FDCAN_Timestamp_Prescaler.
  939. * @retval HAL status
  940. */
  941. HAL_StatusTypeDef HAL_FDCAN_ConfigTimestampCounter(FDCAN_HandleTypeDef *hfdcan, uint32_t TimestampPrescaler)
  942. {
  943. /* Check function parameters */
  944. assert_param(IS_FDCAN_TIMESTAMP_PRESCALER(TimestampPrescaler));
  945. if(hfdcan->State == HAL_FDCAN_STATE_READY)
  946. {
  947. /* Configure prescaler */
  948. MODIFY_REG(hfdcan->Instance->TSCC, FDCAN_TSCC_TCP, TimestampPrescaler);
  949. /* Return function status */
  950. return HAL_OK;
  951. }
  952. else
  953. {
  954. /* Update error code */
  955. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
  956. return HAL_ERROR;
  957. }
  958. }
  959. /**
  960. * @brief Enable the timestamp counter.
  961. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  962. * the configuration information for the specified FDCAN.
  963. * @param TimestampOperation: Timestamp counter operation.
  964. * This parameter can be a value of @arg FDCAN_Timestamp.
  965. * @retval HAL status
  966. */
  967. HAL_StatusTypeDef HAL_FDCAN_EnableTimestampCounter(FDCAN_HandleTypeDef *hfdcan, uint32_t TimestampOperation)
  968. {
  969. /* Check function parameters */
  970. assert_param(IS_FDCAN_TIMESTAMP(TimestampOperation));
  971. if(hfdcan->State == HAL_FDCAN_STATE_READY)
  972. {
  973. /* Enable timestamp counter */
  974. MODIFY_REG(hfdcan->Instance->TSCC, FDCAN_TSCC_TSS, TimestampOperation);
  975. /* Return function status */
  976. return HAL_OK;
  977. }
  978. else
  979. {
  980. /* Update error code */
  981. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
  982. return HAL_ERROR;
  983. }
  984. }
  985. /**
  986. * @brief Disable the timestamp counter.
  987. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  988. * the configuration information for the specified FDCAN.
  989. * @retval HAL status
  990. */
  991. HAL_StatusTypeDef HAL_FDCAN_DisableTimestampCounter(FDCAN_HandleTypeDef *hfdcan)
  992. {
  993. if(hfdcan->State == HAL_FDCAN_STATE_READY)
  994. {
  995. /* Disable timestamp counter */
  996. CLEAR_BIT(hfdcan->Instance->TSCC, FDCAN_TSCC_TSS);
  997. /* Return function status */
  998. return HAL_OK;
  999. }
  1000. else
  1001. {
  1002. /* Update error code */
  1003. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
  1004. return HAL_ERROR;
  1005. }
  1006. }
  1007. /**
  1008. * @brief Get the timestamp counter value.
  1009. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1010. * the configuration information for the specified FDCAN.
  1011. * @retval Value: Timestamp counter value
  1012. */
  1013. uint16_t HAL_FDCAN_GetTimestampCounter(FDCAN_HandleTypeDef *hfdcan)
  1014. {
  1015. return (uint16_t)(hfdcan->Instance->TSCV);
  1016. }
  1017. /**
  1018. * @brief Reset the timestamp counter to zero.
  1019. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1020. * the configuration information for the specified FDCAN.
  1021. * @retval HAL status
  1022. */
  1023. HAL_StatusTypeDef HAL_FDCAN_ResetTimestampCounter(FDCAN_HandleTypeDef *hfdcan)
  1024. {
  1025. if((hfdcan->Instance->TSCC & FDCAN_TSCC_TSS) != FDCAN_TIMESTAMP_EXTERNAL)
  1026. {
  1027. /* Reset timestamp counter.
  1028. Actually any write operation to TSCV clears the counter */
  1029. CLEAR_REG(hfdcan->Instance->TSCV);
  1030. }
  1031. else
  1032. {
  1033. /* Update error code.
  1034. Unable to reset external counter */
  1035. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
  1036. return HAL_ERROR;
  1037. }
  1038. /* Return function status */
  1039. return HAL_OK;
  1040. }
  1041. /**
  1042. * @brief Configure the timeout counter.
  1043. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1044. * the configuration information for the specified FDCAN.
  1045. * @param TimeoutOperation: Timeout counter operation.
  1046. * This parameter can be a value of @arg FDCAN_Timeout_Operation.
  1047. * @param TimeoutPeriod: Start value of the timeout down-counter.
  1048. * This parameter must be a number between 0x0000 and 0xFFFF
  1049. * @retval HAL status
  1050. */
  1051. HAL_StatusTypeDef HAL_FDCAN_ConfigTimeoutCounter(FDCAN_HandleTypeDef *hfdcan, uint32_t TimeoutOperation, uint32_t TimeoutPeriod)
  1052. {
  1053. /* Check function parameters */
  1054. assert_param(IS_FDCAN_TIMEOUT(TimeoutOperation));
  1055. assert_param(IS_FDCAN_MAX_VALUE(TimeoutPeriod, 0xFFFF));
  1056. if(hfdcan->State == HAL_FDCAN_STATE_READY)
  1057. {
  1058. /* Select timeout operation and configure period */
  1059. MODIFY_REG(hfdcan->Instance->TOCC, (FDCAN_TOCC_TOS | FDCAN_TOCC_TOP), (TimeoutOperation | (TimeoutPeriod << 16)));
  1060. /* Return function status */
  1061. return HAL_OK;
  1062. }
  1063. else
  1064. {
  1065. /* Update error code */
  1066. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
  1067. return HAL_ERROR;
  1068. }
  1069. }
  1070. /**
  1071. * @brief Enable the timeout counter.
  1072. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1073. * the configuration information for the specified FDCAN.
  1074. * @retval HAL status
  1075. */
  1076. HAL_StatusTypeDef HAL_FDCAN_EnableTimeoutCounter(FDCAN_HandleTypeDef *hfdcan)
  1077. {
  1078. if(hfdcan->State == HAL_FDCAN_STATE_READY)
  1079. {
  1080. /* Enable timeout counter */
  1081. SET_BIT(hfdcan->Instance->TOCC, FDCAN_TOCC_ETOC);
  1082. /* Return function status */
  1083. return HAL_OK;
  1084. }
  1085. else
  1086. {
  1087. /* Update error code */
  1088. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
  1089. return HAL_ERROR;
  1090. }
  1091. }
  1092. /**
  1093. * @brief Disable the timeout counter.
  1094. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1095. * the configuration information for the specified FDCAN.
  1096. * @retval HAL status
  1097. */
  1098. HAL_StatusTypeDef HAL_FDCAN_DisableTimeoutCounter(FDCAN_HandleTypeDef *hfdcan)
  1099. {
  1100. if(hfdcan->State == HAL_FDCAN_STATE_READY)
  1101. {
  1102. /* Disable timeout counter */
  1103. CLEAR_BIT(hfdcan->Instance->TOCC, FDCAN_TOCC_ETOC);
  1104. /* Return function status */
  1105. return HAL_OK;
  1106. }
  1107. else
  1108. {
  1109. /* Update error code */
  1110. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
  1111. return HAL_ERROR;
  1112. }
  1113. }
  1114. /**
  1115. * @brief Get the timeout counter value.
  1116. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1117. * the configuration information for the specified FDCAN.
  1118. * @retval Value: Timeout counter value
  1119. */
  1120. uint16_t HAL_FDCAN_GetTimeoutCounter(FDCAN_HandleTypeDef *hfdcan)
  1121. {
  1122. return (uint16_t)(hfdcan->Instance->TOCV);
  1123. }
  1124. /**
  1125. * @brief Reset the timeout counter to its start value.
  1126. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1127. * the configuration information for the specified FDCAN.
  1128. * @retval HAL status
  1129. */
  1130. HAL_StatusTypeDef HAL_FDCAN_ResetTimeoutCounter(FDCAN_HandleTypeDef *hfdcan)
  1131. {
  1132. if((hfdcan->Instance->TOCC & FDCAN_TOCC_TOS) != FDCAN_TIMEOUT_CONTINUOUS)
  1133. {
  1134. /* Reset timestamp counter to start value */
  1135. CLEAR_REG(hfdcan->Instance->TOCV);
  1136. /* Return function status */
  1137. return HAL_OK;
  1138. }
  1139. else
  1140. {
  1141. /* Update error code.
  1142. Unable to reset counter: controlled only by FIFO empty state */
  1143. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
  1144. return HAL_ERROR;
  1145. }
  1146. }
  1147. /**
  1148. * @brief Configure the transmitter delay compensation.
  1149. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1150. * the configuration information for the specified FDCAN.
  1151. * @param TdcOffset: Transmitter Delay Compensation Offset.
  1152. * This parameter must be a number between 0x00 and 0xFF.
  1153. * @param TdcFilter: Transmitter Delay Compensation Filter Window Length.
  1154. * This parameter must be a number between 0x00 and 0xFF.
  1155. * @retval HAL status
  1156. */
  1157. HAL_StatusTypeDef HAL_FDCAN_ConfigTxDelayCompensation(FDCAN_HandleTypeDef *hfdcan, uint32_t TdcOffset, uint32_t TdcFilter)
  1158. {
  1159. /* Check function parameters */
  1160. assert_param(IS_FDCAN_MAX_VALUE(TdcOffset, 0xFF));
  1161. assert_param(IS_FDCAN_MAX_VALUE(TdcFilter, 0xFF));
  1162. if(hfdcan->State == HAL_FDCAN_STATE_READY)
  1163. {
  1164. /* Configure TDC offset and filter window */
  1165. hfdcan->Instance->TDCR = (TdcFilter | (TdcOffset << 8));
  1166. /* Return function status */
  1167. return HAL_OK;
  1168. }
  1169. else
  1170. {
  1171. /* Update error code */
  1172. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
  1173. return HAL_ERROR;
  1174. }
  1175. }
  1176. /**
  1177. * @brief Enable the transmitter delay compensation.
  1178. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1179. * the configuration information for the specified FDCAN.
  1180. * @retval HAL status
  1181. */
  1182. HAL_StatusTypeDef HAL_FDCAN_EnableTxDelayCompensation(FDCAN_HandleTypeDef *hfdcan)
  1183. {
  1184. if(hfdcan->State == HAL_FDCAN_STATE_READY)
  1185. {
  1186. /* Enable transmitter delay compensation */
  1187. SET_BIT(hfdcan->Instance->DBTP, FDCAN_DBTP_TDC);
  1188. /* Return function status */
  1189. return HAL_OK;
  1190. }
  1191. else
  1192. {
  1193. /* Update error code */
  1194. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
  1195. return HAL_ERROR;
  1196. }
  1197. }
  1198. /**
  1199. * @brief Disable the transmitter delay compensation.
  1200. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1201. * the configuration information for the specified FDCAN.
  1202. * @retval HAL status
  1203. */
  1204. HAL_StatusTypeDef HAL_FDCAN_DisableTxDelayCompensation(FDCAN_HandleTypeDef *hfdcan)
  1205. {
  1206. if(hfdcan->State == HAL_FDCAN_STATE_READY)
  1207. {
  1208. /* Disable transmitter delay compensation */
  1209. CLEAR_BIT(hfdcan->Instance->DBTP, FDCAN_DBTP_TDC);
  1210. /* Return function status */
  1211. return HAL_OK;
  1212. }
  1213. else
  1214. {
  1215. /* Update error code */
  1216. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
  1217. return HAL_ERROR;
  1218. }
  1219. }
  1220. /**
  1221. * @}
  1222. */
  1223. /** @defgroup FDCAN_Exported_Functions_Group3 Control functions
  1224. * @brief Control functions
  1225. *
  1226. @verbatim
  1227. ==============================================================================
  1228. ##### Control functions #####
  1229. ==============================================================================
  1230. [..] This section provides functions allowing to:
  1231. (+) HAL_FDCAN_Start : Start the FDCAN module
  1232. (+) HAL_FDCAN_Stop : Stop the FDCAN module and enable access to configuration registers
  1233. (+) HAL_FDCAN_AddMessageToTxFifoQ : Add a message to the Tx FIFO/Queue and activate the corresponding transmission request
  1234. (+) HAL_FDCAN_AddMessageToTxBuffer : Add a message to a dedicated Tx buffer
  1235. (+) HAL_FDCAN_EnableTxBufferRequest : Enable transmission request
  1236. (+) HAL_FDCAN_AbortTxRequest : Abort transmission request
  1237. (+) HAL_FDCAN_GetRxMessage : Get an FDCAN frame from the Rx Buffer/FIFO zone into the message RAM
  1238. (+) HAL_FDCAN_GetTxEvent : Get an FDCAN Tx event from the Tx Event FIFO zone into the message RAM
  1239. (+) HAL_FDCAN_GetHighPriorityMessageStatus : Get high priority message status
  1240. (+) HAL_FDCAN_GetProtocolStatus : Get protocol status
  1241. (+) HAL_FDCAN_GetErrorCounters : Get error counter values
  1242. (+) HAL_FDCAN_IsRxBufferMessageAvailable : Check if a new message is received in the selected Rx buffer
  1243. (+) HAL_FDCAN_IsTxBufferMessagePending : Check if a transmission request is pending on the selected Tx buffer
  1244. (+) HAL_FDCAN_GetRxFifoFillLevel : Return Rx FIFO fill level
  1245. (+) HAL_FDCAN_GetTxFifoFreeLevel : Return Tx FIFO free level
  1246. (+) HAL_FDCAN_IsRestrictedOperationMode : Check if the FDCAN peripheral entered Restricted Operation Mode
  1247. (+) HAL_FDCAN_ExitRestrictedOperationMode : Exit Restricted Operation Mode
  1248. @endverbatim
  1249. * @{
  1250. */
  1251. /**
  1252. * @brief Start the FDCAN module.
  1253. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1254. * the configuration information for the specified FDCAN.
  1255. * @retval HAL status
  1256. */
  1257. HAL_StatusTypeDef HAL_FDCAN_Start(FDCAN_HandleTypeDef *hfdcan)
  1258. {
  1259. if(hfdcan->State == HAL_FDCAN_STATE_READY)
  1260. {
  1261. /* Change FDCAN peripheral state */
  1262. hfdcan->State = HAL_FDCAN_STATE_BUSY;
  1263. /* Request leave initialisation */
  1264. CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT);
  1265. /* Reset the FDCAN ErrorCode */
  1266. hfdcan->ErrorCode = HAL_FDCAN_ERROR_NONE;
  1267. /* Return function status */
  1268. return HAL_OK;
  1269. }
  1270. else
  1271. {
  1272. /* Update error code */
  1273. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
  1274. return HAL_ERROR;
  1275. }
  1276. }
  1277. /**
  1278. * @brief Stop the FDCAN module and enable access to configuration registers.
  1279. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1280. * the configuration information for the specified FDCAN.
  1281. * @retval HAL status
  1282. */
  1283. HAL_StatusTypeDef HAL_FDCAN_Stop(FDCAN_HandleTypeDef *hfdcan)
  1284. {
  1285. uint32_t Counter = 0U;
  1286. if(hfdcan->State == HAL_FDCAN_STATE_BUSY)
  1287. {
  1288. /* Request initialisation */
  1289. SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT);
  1290. /* Wait until the INIT bit into CCCR register is set */
  1291. while((hfdcan->Instance->CCCR & FDCAN_CCCR_INIT) == RESET)
  1292. {
  1293. /* Check for the Timeout */
  1294. if(Counter++ > FDCAN_TIMEOUT_VALUE)
  1295. {
  1296. /* Update error code */
  1297. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  1298. /* Change FDCAN state */
  1299. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  1300. return HAL_ERROR;
  1301. }
  1302. }
  1303. /* Enable configuration change */
  1304. SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CCE);
  1305. /* Change FDCAN peripheral state */
  1306. hfdcan->State = HAL_FDCAN_STATE_READY;
  1307. /* Return function status */
  1308. return HAL_OK;
  1309. }
  1310. else
  1311. {
  1312. /* Update error code */
  1313. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
  1314. return HAL_ERROR;
  1315. }
  1316. }
  1317. /**
  1318. * @brief Add a message to the Tx FIFO/Queue and activate the corresponding transmission request
  1319. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1320. * the configuration information for the specified FDCAN.
  1321. * @param pTxHeader: pointer to a FDCAN_TxHeaderTypeDef structure.
  1322. * @param pTxData: pointer to a buffer containing the payload of the Tx frame.
  1323. * @retval HAL status
  1324. */
  1325. HAL_StatusTypeDef HAL_FDCAN_AddMessageToTxFifoQ(FDCAN_HandleTypeDef *hfdcan, FDCAN_TxHeaderTypeDef *pTxHeader, uint8_t *pTxData)
  1326. {
  1327. uint32_t PutIndex;
  1328. /* Check function parameters */
  1329. assert_param(IS_FDCAN_ID_TYPE(pTxHeader->IdType));
  1330. if(pTxHeader->IdType == FDCAN_STANDARD_ID)
  1331. {
  1332. assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->Identifier, 0x7FF));
  1333. }
  1334. else /* pTxHeader->IdType == FDCAN_EXTENDED_ID */
  1335. {
  1336. assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->Identifier, 0x1FFFFFFF));
  1337. }
  1338. assert_param(IS_FDCAN_FRAME_TYPE(pTxHeader->TxFrameType));
  1339. assert_param(IS_FDCAN_DLC(pTxHeader->DataLength));
  1340. assert_param(IS_FDCAN_ESI(pTxHeader->ErrorStateIndicator));
  1341. assert_param(IS_FDCAN_BRS(pTxHeader->BitRateSwitch));
  1342. assert_param(IS_FDCAN_FDF(pTxHeader->FDFormat));
  1343. assert_param(IS_FDCAN_EFC(pTxHeader->TxEventFifoControl));
  1344. assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->MessageMarker, 0xFF));
  1345. if(hfdcan->State == HAL_FDCAN_STATE_BUSY)
  1346. {
  1347. /* Check that the Tx FIFO/Queue has an allocated area into the RAM */
  1348. if((hfdcan->Instance->TXBC & FDCAN_TXBC_TFQS) == 0)
  1349. {
  1350. /* Update error code */
  1351. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
  1352. return HAL_ERROR;
  1353. }
  1354. /* Check that the Tx FIFO/Queue is not full */
  1355. if((hfdcan->Instance->TXFQS & FDCAN_TXFQS_TFQF) != 0)
  1356. {
  1357. /* Update error code */
  1358. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
  1359. return HAL_ERROR;
  1360. }
  1361. else
  1362. {
  1363. /* Retrieve the Tx FIFO PutIndex */
  1364. PutIndex = ((hfdcan->Instance->TXFQS & FDCAN_TXFQS_TFQPI) >> 16);
  1365. /* Add the message to the Tx FIFO/Queue */
  1366. FDCAN_CopyMessageToRAM(hfdcan, pTxHeader, pTxData, PutIndex);
  1367. /* Activate the corresponding transmission request */
  1368. hfdcan->Instance->TXBAR = (1 << PutIndex);
  1369. }
  1370. /* Return function status */
  1371. return HAL_OK;
  1372. }
  1373. else
  1374. {
  1375. /* Update error code */
  1376. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
  1377. return HAL_ERROR;
  1378. }
  1379. }
  1380. /**
  1381. * @brief Add a message to a dedicated Tx buffer
  1382. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1383. * the configuration information for the specified FDCAN.
  1384. * @param pTxHeader: pointer to a FDCAN_TxHeaderTypeDef structure.
  1385. * @param pTxData: pointer to a buffer containing the payload of the Tx frame.
  1386. * @param BufferIndex: index of the buffer to be configured.
  1387. * This parameter can be a value of @arg FDCAN_Tx_location.
  1388. * @retval HAL status
  1389. */
  1390. HAL_StatusTypeDef HAL_FDCAN_AddMessageToTxBuffer(FDCAN_HandleTypeDef *hfdcan, FDCAN_TxHeaderTypeDef *pTxHeader, uint8_t *pTxData, uint32_t BufferIndex)
  1391. {
  1392. /* Check function parameters */
  1393. assert_param(IS_FDCAN_ID_TYPE(pTxHeader->IdType));
  1394. if(pTxHeader->IdType == FDCAN_STANDARD_ID)
  1395. {
  1396. assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->Identifier, 0x7FF));
  1397. }
  1398. else /* pTxHeader->IdType == FDCAN_EXTENDED_ID */
  1399. {
  1400. assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->Identifier, 0x1FFFFFFF));
  1401. }
  1402. assert_param(IS_FDCAN_FRAME_TYPE(pTxHeader->TxFrameType));
  1403. assert_param(IS_FDCAN_DLC(pTxHeader->DataLength));
  1404. assert_param(IS_FDCAN_ESI(pTxHeader->ErrorStateIndicator));
  1405. assert_param(IS_FDCAN_BRS(pTxHeader->BitRateSwitch));
  1406. assert_param(IS_FDCAN_FDF(pTxHeader->FDFormat));
  1407. assert_param(IS_FDCAN_EFC(pTxHeader->TxEventFifoControl));
  1408. assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->MessageMarker, 0xFF));
  1409. assert_param(IS_FDCAN_TX_LOCATION(BufferIndex));
  1410. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  1411. {
  1412. /* Check that the selected buffer has an allocated area into the RAM */
  1413. if(POSITION_VAL(BufferIndex) >= ((hfdcan->Instance->TXBC & FDCAN_TXBC_NDTB) >> 16))
  1414. {
  1415. /* Update error code */
  1416. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
  1417. return HAL_ERROR;
  1418. }
  1419. /* Check that there is no transmittion request pending for the selected buffer */
  1420. if((hfdcan->Instance->TXBRP & BufferIndex) != 0)
  1421. {
  1422. /* Update error code */
  1423. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PENDING;
  1424. return HAL_ERROR;
  1425. }
  1426. else
  1427. {
  1428. /* Add the message to the Tx buffer */
  1429. FDCAN_CopyMessageToRAM(hfdcan, pTxHeader, pTxData, POSITION_VAL(BufferIndex));
  1430. }
  1431. /* Return function status */
  1432. return HAL_OK;
  1433. }
  1434. else
  1435. {
  1436. /* Update error code */
  1437. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  1438. return HAL_ERROR;
  1439. }
  1440. }
  1441. /**
  1442. * @brief Enable transmission request.
  1443. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1444. * the configuration information for the specified FDCAN.
  1445. * @param BufferIndex: buffer index.
  1446. * This parameter can be any combination of @arg FDCAN_Tx_location.
  1447. * @retval HAL status
  1448. */
  1449. HAL_StatusTypeDef HAL_FDCAN_EnableTxBufferRequest(FDCAN_HandleTypeDef *hfdcan, uint32_t BufferIndex)
  1450. {
  1451. if(hfdcan->State == HAL_FDCAN_STATE_BUSY)
  1452. {
  1453. /* Add transmission request */
  1454. hfdcan->Instance->TXBAR = BufferIndex;
  1455. /* Return function status */
  1456. return HAL_OK;
  1457. }
  1458. else
  1459. {
  1460. /* Update error code */
  1461. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
  1462. return HAL_ERROR;
  1463. }
  1464. }
  1465. /**
  1466. * @brief Abort transmission request
  1467. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1468. * the configuration information for the specified FDCAN.
  1469. * @param BufferIndex: buffer index.
  1470. * This parameter can be any combination of @arg FDCAN_Tx_location.
  1471. * @retval HAL status
  1472. */
  1473. HAL_StatusTypeDef HAL_FDCAN_AbortTxRequest(FDCAN_HandleTypeDef *hfdcan, uint32_t BufferIndex)
  1474. {
  1475. if(hfdcan->State == HAL_FDCAN_STATE_BUSY)
  1476. {
  1477. /* Add cancellation request */
  1478. hfdcan->Instance->TXBCR = BufferIndex;
  1479. /* Return function status */
  1480. return HAL_OK;
  1481. }
  1482. else
  1483. {
  1484. /* Update error code */
  1485. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
  1486. return HAL_ERROR;
  1487. }
  1488. }
  1489. /**
  1490. * @brief Get an FDCAN frame from the Rx Buffer/FIFO zone into the message RAM.
  1491. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1492. * the configuration information for the specified FDCAN.
  1493. * @param RxLocation: Location of the received message to be read.
  1494. This parameter can be a value of @arg FDCAN_Rx_location.
  1495. * @param pRxHeader: pointer to a FDCAN_RxHeaderTypeDef structure.
  1496. * @param pRxData: pointer to a buffer where the payload of the Rx frame will be stored.
  1497. * @retval HAL status
  1498. */
  1499. HAL_StatusTypeDef HAL_FDCAN_GetRxMessage(FDCAN_HandleTypeDef *hfdcan, uint32_t RxLocation, FDCAN_RxHeaderTypeDef *pRxHeader, uint8_t *pRxData)
  1500. {
  1501. uint32_t *RxAddress;
  1502. uint8_t *pData;
  1503. uint32_t ByteCounter;
  1504. uint32_t GetIndex = 0;
  1505. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  1506. {
  1507. if(RxLocation == FDCAN_RX_FIFO0) /* Rx element is assigned to the Rx FIFO 0 */
  1508. {
  1509. /* Check that the Rx FIFO 0 has an allocated area into the RAM */
  1510. if((hfdcan->Instance->RXF0C & FDCAN_RXF0C_F0S) == 0)
  1511. {
  1512. /* Update error code */
  1513. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
  1514. return HAL_ERROR;
  1515. }
  1516. /* Check that the Rx FIFO 0 is not empty */
  1517. if((hfdcan->Instance->RXF0S & FDCAN_RXF0S_F0FL) == 0)
  1518. {
  1519. /* Update error code */
  1520. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
  1521. return HAL_ERROR;
  1522. }
  1523. else
  1524. {
  1525. /* Calculate Rx FIFO 0 element address */
  1526. GetIndex = ((hfdcan->Instance->RXF0S & FDCAN_RXF0S_F0GI) >> 8);
  1527. RxAddress = (uint32_t *)(hfdcan->msgRam.RxFIFO0SA + (GetIndex * hfdcan->Init.RxFifo0ElmtSize * 4));
  1528. }
  1529. }
  1530. else if(RxLocation == FDCAN_RX_FIFO1) /* Rx element is assigned to the Rx FIFO 1 */
  1531. {
  1532. /* Check that the Rx FIFO 1 has an allocated area into the RAM */
  1533. if((hfdcan->Instance->RXF1C & FDCAN_RXF1C_F1S) == 0)
  1534. {
  1535. /* Update error code */
  1536. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
  1537. return HAL_ERROR;
  1538. }
  1539. /* Check that the Rx FIFO 0 is not empty */
  1540. if((hfdcan->Instance->RXF1S & FDCAN_RXF1S_F1FL) == 0)
  1541. {
  1542. /* Update error code */
  1543. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
  1544. return HAL_ERROR;
  1545. }
  1546. else
  1547. {
  1548. /* Calculate Rx FIFO 1 element address */
  1549. GetIndex = ((hfdcan->Instance->RXF1S & FDCAN_RXF1S_F1GI) >> 8);
  1550. RxAddress = (uint32_t *)(hfdcan->msgRam.RxFIFO1SA + (GetIndex * hfdcan->Init.RxFifo1ElmtSize * 4));
  1551. }
  1552. }
  1553. else /* Rx element is assigned to a dedicated Rx buffer */
  1554. {
  1555. /* Check that the selected buffer has an allocated area into the RAM */
  1556. if(RxLocation >= hfdcan->Init.RxBuffersNbr)
  1557. {
  1558. /* Update error code */
  1559. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
  1560. return HAL_ERROR;
  1561. }
  1562. else
  1563. {
  1564. /* Calculate Rx buffer address */
  1565. RxAddress = (uint32_t *)(hfdcan->msgRam.RxBufferSA + (RxLocation * hfdcan->Init.RxBufferSize * 4));
  1566. }
  1567. }
  1568. /* Retrieve IdType */
  1569. pRxHeader->IdType = *RxAddress & FDCAN_ELEMENT_MASK_XTD;
  1570. /* Retrieve Identifier */
  1571. if(pRxHeader->IdType == FDCAN_STANDARD_ID) /* Standard ID element */
  1572. {
  1573. pRxHeader->Identifier = ((*RxAddress & FDCAN_ELEMENT_MASK_STDID) >> 18);
  1574. }
  1575. else /* Extended ID element */
  1576. {
  1577. pRxHeader->Identifier = (*RxAddress & FDCAN_ELEMENT_MASK_EXTID);
  1578. }
  1579. /* Retrieve RxFrameType */
  1580. pRxHeader->RxFrameType = (*RxAddress & FDCAN_ELEMENT_MASK_RTR);
  1581. /* Retrieve ErrorStateIndicator */
  1582. pRxHeader->ErrorStateIndicator = (*RxAddress++ & FDCAN_ELEMENT_MASK_ESI);
  1583. /* Retrieve RxTimestamp */
  1584. pRxHeader->RxTimestamp = (*RxAddress & FDCAN_ELEMENT_MASK_TS);
  1585. /* Retrieve DataLength */
  1586. pRxHeader->DataLength = (*RxAddress & FDCAN_ELEMENT_MASK_DLC);
  1587. /* Retrieve BitRateSwitch */
  1588. pRxHeader->BitRateSwitch = (*RxAddress & FDCAN_ELEMENT_MASK_BRS);
  1589. /* Retrieve FDFormat */
  1590. pRxHeader->FDFormat = (*RxAddress & FDCAN_ELEMENT_MASK_FDF);
  1591. /* Retrieve FilterIndex */
  1592. pRxHeader->FilterIndex = ((*RxAddress & FDCAN_ELEMENT_MASK_FIDX) >> 24);
  1593. /* Retrieve NonMatchingFrame */
  1594. pRxHeader->IsFilterMatchingFrame = ((*RxAddress++ & FDCAN_ELEMENT_MASK_ANMF) >> 31);
  1595. /* Retrieve Rx payload */
  1596. pData = (uint8_t *)RxAddress;
  1597. for(ByteCounter = 0; ByteCounter < DLCtoBytes[pRxHeader->DataLength >> 16]; ByteCounter++)
  1598. {
  1599. *pRxData++ = *pData++;
  1600. }
  1601. if(RxLocation == FDCAN_RX_FIFO0) /* Rx element is assigned to the Rx FIFO 0 */
  1602. {
  1603. /* Acknowledge the Rx FIFO 0 that the oldest element is read so that it increments the GetIndex */
  1604. hfdcan->Instance->RXF0A = GetIndex;
  1605. }
  1606. else if(RxLocation == FDCAN_RX_FIFO1) /* Rx element is assigned to the Rx FIFO 1 */
  1607. {
  1608. /* Acknowledge the Rx FIFO 1 that the oldest element is read so that it increments the GetIndex */
  1609. hfdcan->Instance->RXF1A = GetIndex;
  1610. }
  1611. else /* Rx element is assigned to a dedicated Rx buffer */
  1612. {
  1613. /* Clear the New Data flag of the current Rx buffer */
  1614. if(RxLocation < FDCAN_RX_BUFFER32)
  1615. {
  1616. hfdcan->Instance->NDAT1 = (1 << RxLocation);
  1617. }
  1618. else /* FDCAN_RX_BUFFER32 <= RxLocation <= FDCAN_RX_BUFFER63 */
  1619. {
  1620. hfdcan->Instance->NDAT2 = (1 << (RxLocation - 0x20));
  1621. }
  1622. }
  1623. /* Return function status */
  1624. return HAL_OK;
  1625. }
  1626. else
  1627. {
  1628. /* Update error code */
  1629. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  1630. return HAL_ERROR;
  1631. }
  1632. }
  1633. /**
  1634. * @brief Get an FDCAN Tx event from the Tx Event FIFO zone into the message RAM.
  1635. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1636. * the configuration information for the specified FDCAN.
  1637. * @param pTxEvent: pointer to a FDCAN_TxEventFifoTypeDef structure.
  1638. * @retval HAL status
  1639. */
  1640. HAL_StatusTypeDef HAL_FDCAN_GetTxEvent(FDCAN_HandleTypeDef *hfdcan, FDCAN_TxEventFifoTypeDef *pTxEvent)
  1641. {
  1642. uint32_t *TxEventAddress;
  1643. uint32_t GetIndex;
  1644. /* Check function parameters */
  1645. assert_param(IS_FDCAN_MIN_VALUE(hfdcan->Init.TxEventsNbr, 1));
  1646. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  1647. {
  1648. /* Check that the Tx Event FIFO has an allocated area into the RAM */
  1649. if((hfdcan->Instance->TXEFC & FDCAN_TXEFC_EFS) == 0)
  1650. {
  1651. /* Update error code */
  1652. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
  1653. return HAL_ERROR;
  1654. }
  1655. /* Check that the Tx event FIFO is not empty */
  1656. if((hfdcan->Instance->TXEFS & FDCAN_TXEFS_EFFL) == 0)
  1657. {
  1658. /* Update error code */
  1659. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
  1660. return HAL_ERROR;
  1661. }
  1662. /* Calculate Tx event FIFO element address */
  1663. GetIndex = ((hfdcan->Instance->TXEFS & FDCAN_TXEFS_EFGI) >> 8);
  1664. TxEventAddress = (uint32_t *)(hfdcan->msgRam.TxEventFIFOSA + (GetIndex * 2 * 4));
  1665. /* Retrieve IdType */
  1666. pTxEvent->IdType = *TxEventAddress & FDCAN_ELEMENT_MASK_XTD;
  1667. /* Retrieve Identifier */
  1668. if(pTxEvent->IdType == FDCAN_STANDARD_ID) /* Standard ID element */
  1669. {
  1670. pTxEvent->Identifier = ((*TxEventAddress & FDCAN_ELEMENT_MASK_STDID) >> 18);
  1671. }
  1672. else /* Extended ID element */
  1673. {
  1674. pTxEvent->Identifier = (*TxEventAddress & FDCAN_ELEMENT_MASK_EXTID);
  1675. }
  1676. /* Retrieve RxFrameType */
  1677. pTxEvent->TxFrameType = (*TxEventAddress & FDCAN_ELEMENT_MASK_RTR);
  1678. /* Retrieve ErrorStateIndicator */
  1679. pTxEvent->ErrorStateIndicator = (*TxEventAddress++ & FDCAN_ELEMENT_MASK_ESI);
  1680. /* Retrieve RxTimestamp */
  1681. pTxEvent->TxTimestamp = (*TxEventAddress & FDCAN_ELEMENT_MASK_TS);
  1682. /* Retrieve DataLength */
  1683. pTxEvent->DataLength = (*TxEventAddress & FDCAN_ELEMENT_MASK_DLC);
  1684. /* Retrieve BitRateSwitch */
  1685. pTxEvent->BitRateSwitch = (*TxEventAddress & FDCAN_ELEMENT_MASK_BRS);
  1686. /* Retrieve FDFormat */
  1687. pTxEvent->FDFormat = (*TxEventAddress & FDCAN_ELEMENT_MASK_FDF);
  1688. /* Retrieve EventType */
  1689. pTxEvent->EventType = (*TxEventAddress & FDCAN_ELEMENT_MASK_ET);
  1690. /* Retrieve MessageMarker */
  1691. pTxEvent->MessageMarker = ((*TxEventAddress & FDCAN_ELEMENT_MASK_MM) >> 24);
  1692. /* Acknowledge the Tx Event FIFO that the oldest element is read so that it increments the GetIndex */
  1693. hfdcan->Instance->TXEFA = GetIndex;
  1694. /* Return function status */
  1695. return HAL_OK;
  1696. }
  1697. else
  1698. {
  1699. /* Update error code */
  1700. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  1701. return HAL_ERROR;
  1702. }
  1703. }
  1704. /**
  1705. * @brief Get high priority message status.
  1706. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1707. * the configuration information for the specified FDCAN.
  1708. * @param HpMsgStatus: pointer to an FDCAN_HpMsgStatusTypeDef structure.
  1709. * @retval HAL status
  1710. */
  1711. HAL_StatusTypeDef HAL_FDCAN_GetHighPriorityMessageStatus(FDCAN_HandleTypeDef *hfdcan, FDCAN_HpMsgStatusTypeDef *HpMsgStatus)
  1712. {
  1713. HpMsgStatus->FilterList = ((hfdcan->Instance->HPMS & FDCAN_HPMS_FLST) >> 15);
  1714. HpMsgStatus->FilterIndex = ((hfdcan->Instance->HPMS & FDCAN_HPMS_FIDX) >> 8);
  1715. HpMsgStatus->MessageStorage = (hfdcan->Instance->HPMS & FDCAN_HPMS_MSI);
  1716. HpMsgStatus->MessageIndex = (hfdcan->Instance->HPMS & FDCAN_HPMS_BIDX);
  1717. /* Return function status */
  1718. return HAL_OK;
  1719. }
  1720. /**
  1721. * @brief Get protocol status.
  1722. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1723. * the configuration information for the specified FDCAN.
  1724. * @param ProtocolStatus: pointer to an FDCAN_ProtocolStatusTypeDef structure.
  1725. * @retval HAL status
  1726. */
  1727. HAL_StatusTypeDef HAL_FDCAN_GetProtocolStatus(FDCAN_HandleTypeDef *hfdcan, FDCAN_ProtocolStatusTypeDef *ProtocolStatus)
  1728. {
  1729. uint32_t StatusReg;
  1730. /* Read the protocol status register */
  1731. StatusReg = READ_REG(hfdcan->Instance->PSR);
  1732. /* Fill the protocol status structure */
  1733. ProtocolStatus->LastErrorCode = (StatusReg & FDCAN_PSR_LEC);
  1734. ProtocolStatus->DataLastErrorCode = ((StatusReg & FDCAN_PSR_DLEC) >> 8);
  1735. ProtocolStatus->Activity = (StatusReg & FDCAN_PSR_ACT);
  1736. ProtocolStatus->ErrorPassive = ((StatusReg & FDCAN_PSR_EP) >> 5);
  1737. ProtocolStatus->Warning = ((StatusReg & FDCAN_PSR_EW) >> 6);
  1738. ProtocolStatus->BusOff = ((StatusReg & FDCAN_PSR_BO) >> 7);
  1739. ProtocolStatus->RxESIflag = ((StatusReg & FDCAN_PSR_RESI) >> 11);
  1740. ProtocolStatus->RxBRSflag = ((StatusReg & FDCAN_PSR_RBRS) >> 12);
  1741. ProtocolStatus->RxFDFflag = ((StatusReg & FDCAN_PSR_REDL) >> 13);
  1742. ProtocolStatus->ProtocolException = ((StatusReg & FDCAN_PSR_PXE) >> 14);
  1743. ProtocolStatus->TDCvalue = ((StatusReg & FDCAN_PSR_TDCV) >> 16);
  1744. /* Return function status */
  1745. return HAL_OK;
  1746. }
  1747. /**
  1748. * @brief Get error counter values.
  1749. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1750. * the configuration information for the specified FDCAN.
  1751. * @param ErrorCounters: pointer to an FDCAN_ErrorCountersTypeDef structure.
  1752. * @retval HAL status
  1753. */
  1754. HAL_StatusTypeDef HAL_FDCAN_GetErrorCounters(FDCAN_HandleTypeDef *hfdcan, FDCAN_ErrorCountersTypeDef *ErrorCounters)
  1755. {
  1756. uint32_t CountersReg;
  1757. /* Read the error counters register */
  1758. CountersReg = READ_REG(hfdcan->Instance->ECR);
  1759. /* Fill the error counters structure */
  1760. ErrorCounters->TxErrorCnt = (CountersReg & FDCAN_ECR_TEC);
  1761. ErrorCounters->RxErrorCnt = ((CountersReg & FDCAN_ECR_TREC) >> 8);
  1762. ErrorCounters->RxErrorPassive = ((CountersReg & FDCAN_ECR_RP) >> 15);
  1763. ErrorCounters->ErrorLogging = ((CountersReg & FDCAN_ECR_CEL) >> 16);
  1764. /* Return function status */
  1765. return HAL_OK;
  1766. }
  1767. /**
  1768. * @brief Check if a new message is received in the selected Rx buffer.
  1769. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1770. * the configuration information for the specified FDCAN.
  1771. * @param RxBufferIndex: Rx buffer index.
  1772. * This parameter must be a number between 0 and 63.
  1773. * @retval Status:
  1774. * - 0 : No new message on RxBufferIndex.
  1775. * - 1 : New message received on RxBufferIndex.
  1776. */
  1777. uint32_t HAL_FDCAN_IsRxBufferMessageAvailable(FDCAN_HandleTypeDef *hfdcan, uint32_t RxBufferIndex)
  1778. {
  1779. /* Check function parameters */
  1780. assert_param(IS_FDCAN_MAX_VALUE(RxBufferIndex, 63));
  1781. /* Check new message reception on the selected buffer */
  1782. if(((RxBufferIndex < 32) && ((hfdcan->Instance->NDAT1 & (1 << RxBufferIndex)) == 0)) ||
  1783. ((RxBufferIndex >= 32) && ((hfdcan->Instance->NDAT2 & (1 << (RxBufferIndex - 0x20))) == 0)))
  1784. {
  1785. return 0;
  1786. }
  1787. /* Clear the New Data flag of the current Rx buffer */
  1788. if(RxBufferIndex < 32)
  1789. {
  1790. hfdcan->Instance->NDAT1 = (1 << RxBufferIndex);
  1791. }
  1792. else /* 32 <= RxBufferIndex <= 63 */
  1793. {
  1794. hfdcan->Instance->NDAT2 = (1 << (RxBufferIndex - 0x20));
  1795. }
  1796. return 1;
  1797. }
  1798. /**
  1799. * @brief Check if a transmission request is pending on the selected Tx buffer.
  1800. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1801. * the configuration information for the specified FDCAN.
  1802. * @param TxBufferIndex: Tx buffer index.
  1803. * This parameter can be a value of @arg FDCAN_Tx_location.
  1804. * @retval Status:
  1805. * - 0 : No pending transmission request on RxBufferIndex.
  1806. * - 1 : Pending transmission request on RxBufferIndex.
  1807. */
  1808. uint32_t HAL_FDCAN_IsTxBufferMessagePending(FDCAN_HandleTypeDef *hfdcan, uint32_t TxBufferIndex)
  1809. {
  1810. /* Check function parameters */
  1811. assert_param(IS_FDCAN_TX_LOCATION(TxBufferIndex));
  1812. /* Check pending transmittion request on the selected buffer */
  1813. if((hfdcan->Instance->TXBRP & TxBufferIndex) == 0)
  1814. {
  1815. return 0;
  1816. }
  1817. return 1;
  1818. }
  1819. /**
  1820. * @brief Return Rx FIFO fill level.
  1821. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1822. * the configuration information for the specified FDCAN.
  1823. * @param RxFifo: Rx FIFO.
  1824. * This parameter can be one of the following values:
  1825. * @arg FDCAN_RX_FIFO0: Rx FIFO 0
  1826. * @arg FDCAN_RX_FIFO1: Rx FIFO 1
  1827. * @retval Level: Rx FIFO fill level.
  1828. */
  1829. uint32_t HAL_FDCAN_GetRxFifoFillLevel(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo)
  1830. {
  1831. uint32_t FillLevel;
  1832. /* Check function parameters */
  1833. assert_param(IS_FDCAN_RX_FIFO(RxFifo));
  1834. if(RxFifo == FDCAN_RX_FIFO0)
  1835. {
  1836. FillLevel = hfdcan->Instance->RXF0S & FDCAN_RXF0S_F0FL;
  1837. }
  1838. else /* RxFifo == FDCAN_RX_FIFO1 */
  1839. {
  1840. FillLevel = hfdcan->Instance->RXF1S & FDCAN_RXF1S_F1FL;
  1841. }
  1842. /* Return Rx FIFO fill level */
  1843. return FillLevel;
  1844. }
  1845. /**
  1846. * @brief Return Tx FIFO free level: number of consecutive free Tx FIFO
  1847. * elements starting from Tx FIFO GetIndex.
  1848. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1849. * the configuration information for the specified FDCAN.
  1850. * @retval Level: Tx FIFO free level.
  1851. */
  1852. uint32_t HAL_FDCAN_GetTxFifoFreeLevel(FDCAN_HandleTypeDef *hfdcan)
  1853. {
  1854. uint32_t FreeLevel;
  1855. FreeLevel = hfdcan->Instance->TXFQS & FDCAN_TXFQS_TFFL;
  1856. /* Return Tx FIFO free level */
  1857. return FreeLevel;
  1858. }
  1859. /**
  1860. * @brief Check if the FDCAN peripheral entered Restricted Operation Mode.
  1861. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1862. * the configuration information for the specified FDCAN.
  1863. * @retval Status:
  1864. * - 0 : Normal FDCAN operation.
  1865. * - 1 : Restricted Operation Mode active.
  1866. */
  1867. uint32_t HAL_FDCAN_IsRestrictedOperationMode(FDCAN_HandleTypeDef *hfdcan)
  1868. {
  1869. uint32_t OperationMode;
  1870. /* Get Operation Mode */
  1871. OperationMode = ((hfdcan->Instance->CCCR & FDCAN_CCCR_ASM) >> 2);
  1872. return OperationMode;
  1873. }
  1874. /**
  1875. * @brief Exit Restricted Operation Mode.
  1876. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1877. * the configuration information for the specified FDCAN.
  1878. * @retval HAL status
  1879. */
  1880. HAL_StatusTypeDef HAL_FDCAN_ExitRestrictedOperationMode(FDCAN_HandleTypeDef *hfdcan)
  1881. {
  1882. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  1883. {
  1884. /* Exit Restricted Operation mode */
  1885. CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_ASM);
  1886. /* Return function status */
  1887. return HAL_OK;
  1888. }
  1889. else
  1890. {
  1891. /* Update error code */
  1892. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  1893. return HAL_ERROR;
  1894. }
  1895. }
  1896. /**
  1897. * @}
  1898. */
  1899. /** @defgroup FDCAN_Exported_Functions_Group4 TT Configuration and control functions
  1900. * @brief TT Configuration and control functions
  1901. *
  1902. @verbatim
  1903. ==============================================================================
  1904. ##### TT Configuration and control functions #####
  1905. ==============================================================================
  1906. [..] This section provides functions allowing to:
  1907. (+) HAL_FDCAN_TT_ConfigOperation : Initialize TT operation parameters
  1908. (+) HAL_FDCAN_TT_ConfigReferenceMessage : Configure the reference message
  1909. (+) HAL_FDCAN_TT_ConfigTrigger : Configure the FDCAN trigger
  1910. (+) HAL_FDCAN_TT_SetGlobalTime : Schedule global time adjustment
  1911. (+) HAL_FDCAN_TT_SetClockSynchronization : Schedule TUR numerator update
  1912. (+) HAL_FDCAN_TT_ConfigStopWatch : Configure stop watch source and polarity
  1913. (+) HAL_FDCAN_TT_ConfigRegisterTimeMark : Configure register time mark pulse generation
  1914. (+) HAL_FDCAN_TT_EnableRegisterTimeMarkPulse : Enable register time mark pulse generation
  1915. (+) HAL_FDCAN_TT_DisableRegisterTimeMarkPulse : Disable register time mark pulse generation
  1916. (+) HAL_FDCAN_TT_EnableTriggerTimeMarkPulse : Enable trigger time mark pulse generation
  1917. (+) HAL_FDCAN_TT_DisableTriggerTimeMarkPulse : Disable trigger time mark pulse generation
  1918. (+) HAL_FDCAN_TT_EnableHardwareGapControl : Enable gap control by input pin fdcan1_evt
  1919. (+) HAL_FDCAN_TT_DisableHardwareGapControl : Disable gap control by input pin fdcan1_evt
  1920. (+) HAL_FDCAN_TT_EnableTimeMarkGapControl : Enable gap control (finish only) by register time mark interrupt
  1921. (+) HAL_FDCAN_TT_DisableTimeMarkGapControl : Disable gap control by register time mark interrupt
  1922. (+) HAL_FDCAN_TT_SetNextIsGap : Transmit next reference message with Next_is_Gap = "1"
  1923. (+) HAL_FDCAN_TT_SetEndOfGap : Finish a Gap by requesting start of reference message
  1924. (+) HAL_FDCAN_TT_ConfigExternalSyncPhase : Configure target phase used for external synchronization
  1925. (+) HAL_FDCAN_TT_EnableExternalSynchronization : Synchronize the phase of the FDCAN schedule to an external schedule
  1926. (+) HAL_FDCAN_TT_DisableExternalSynchronization : Disable external schedule synchronization
  1927. (+) HAL_FDCAN_TT_GetOperationStatus : Get TT operation status
  1928. @endverbatim
  1929. * @{
  1930. */
  1931. /**
  1932. * @brief Initialize TT operation parameters.
  1933. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  1934. * the configuration information for the specified FDCAN.
  1935. * @param pTTParams: pointer to a FDCAN_TT_ConfigTypeDef structure.
  1936. * @retval HAL status
  1937. */
  1938. HAL_StatusTypeDef HAL_FDCAN_TT_ConfigOperation(FDCAN_HandleTypeDef *hfdcan, FDCAN_TT_ConfigTypeDef *pTTParams)
  1939. {
  1940. uint32_t tickstart = 0U;
  1941. uint32_t RAMcounter;
  1942. /* Check function parameters */
  1943. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  1944. assert_param(IS_FDCAN_TT_TUR_NUMERATOR(pTTParams->TURNumerator));
  1945. assert_param(IS_FDCAN_TT_TUR_DENOMINATOR(pTTParams->TURDenominator));
  1946. assert_param(IS_FDCAN_TT_TIME_MASTER(pTTParams->TimeMaster));
  1947. assert_param(IS_FDCAN_MAX_VALUE(pTTParams->SyncDevLimit, 7));
  1948. assert_param(IS_FDCAN_MAX_VALUE(pTTParams->InitRefTrigOffset, 127));
  1949. assert_param(IS_FDCAN_MAX_VALUE(pTTParams->TriggerMemoryNbr, 64));
  1950. assert_param(IS_FDCAN_TT_CYCLE_START_SYNC(pTTParams->CycleStartSync));
  1951. assert_param(IS_FDCAN_TT_STOP_WATCH_TRIGGER(pTTParams->StopWatchTrigSel));
  1952. assert_param(IS_FDCAN_TT_EVENT_TRIGGER(pTTParams->EventTrigSel));
  1953. if(pTTParams->TimeMaster == FDCAN_TT_POTENTIAL_MASTER)
  1954. {
  1955. assert_param(IS_FDCAN_TT_BASIC_CYCLES_NUMBER(pTTParams->BasicCyclesNbr));
  1956. }
  1957. if(pTTParams->OperationMode != FDCAN_TT_COMMUNICATION_LEVEL0)
  1958. {
  1959. assert_param(IS_FDCAN_TT_OPERATION(pTTParams->GapEnable));
  1960. assert_param(IS_FDCAN_MAX_VALUE(pTTParams->AppWdgLimit, 255));
  1961. assert_param(IS_FDCAN_TT_EVENT_TRIGGER_POLARITY(pTTParams->EvtTrigPolarity));
  1962. assert_param(IS_FDCAN_TT_TX_ENABLE_WINDOW(pTTParams->TxEnableWindow));
  1963. assert_param(IS_FDCAN_MAX_VALUE(pTTParams->ExpTxTrigNbr, 4095));
  1964. }
  1965. if(pTTParams->OperationMode != FDCAN_TT_COMMUNICATION_LEVEL1)
  1966. {
  1967. assert_param(IS_FDCAN_TT_TUR_LEVEL_0_2(pTTParams->TURNumerator, pTTParams->TURDenominator));
  1968. assert_param(IS_FDCAN_TT_EXTERNAL_CLK_SYNC(pTTParams->ExternalClkSync));
  1969. assert_param(IS_FDCAN_TT_GLOBAL_TIME_FILTERING(pTTParams->GlobalTimeFilter));
  1970. assert_param(IS_FDCAN_TT_AUTO_CLK_CALIBRATION(pTTParams->ClockCalibration));
  1971. }
  1972. else
  1973. {
  1974. assert_param(IS_FDCAN_TT_TUR_LEVEL_1(pTTParams->TURNumerator, pTTParams->TURDenominator));
  1975. }
  1976. if(hfdcan->State == HAL_FDCAN_STATE_READY)
  1977. {
  1978. /* Stop local time in order to enable write access to the other bits of TURCF register */
  1979. CLEAR_BIT(hfdcan->ttcan->TURCF, FDCAN_TURCF_ELT);
  1980. /* Get tick */
  1981. tickstart = HAL_GetTick();
  1982. /* Wait until the ELT bit into TURCF register is reset */
  1983. while((hfdcan->ttcan->TURCF & FDCAN_TURCF_ELT) != RESET)
  1984. {
  1985. /* Check for the Timeout */
  1986. if((HAL_GetTick() - tickstart) > FDCAN_TIMEOUT_VALUE)
  1987. {
  1988. /* Update error code */
  1989. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  1990. /* Change FDCAN state */
  1991. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  1992. return HAL_ERROR;
  1993. }
  1994. }
  1995. /* Configure TUR (Time Unit Ratio) */
  1996. MODIFY_REG(hfdcan->ttcan->TURCF,
  1997. (FDCAN_TURCF_NCL | FDCAN_TURCF_DC),
  1998. ((pTTParams->TURNumerator - 0x10000) | (pTTParams->TURDenominator << 16)));
  1999. /* Enable local time */
  2000. SET_BIT(hfdcan->ttcan->TURCF, FDCAN_TURCF_ELT);
  2001. /* Configure TT operation */
  2002. MODIFY_REG(hfdcan->ttcan->TTOCF,
  2003. (FDCAN_TTOCF_OM | FDCAN_TTOCF_TM | FDCAN_TTOCF_LDSDL | FDCAN_TTOCF_IRTO),
  2004. (pTTParams->OperationMode | \
  2005. pTTParams->TimeMaster | \
  2006. (pTTParams->SyncDevLimit << 5) | \
  2007. (pTTParams->InitRefTrigOffset << 8)));
  2008. if(pTTParams->OperationMode != FDCAN_TT_COMMUNICATION_LEVEL0)
  2009. {
  2010. MODIFY_REG(hfdcan->ttcan->TTOCF,
  2011. (FDCAN_TTOCF_GEN | FDCAN_TTOCF_AWL | FDCAN_TTOCF_EVTP),
  2012. (pTTParams->GapEnable | \
  2013. (pTTParams->AppWdgLimit << 16) | \
  2014. pTTParams->EvtTrigPolarity));
  2015. }
  2016. if(pTTParams->OperationMode != FDCAN_TT_COMMUNICATION_LEVEL1)
  2017. {
  2018. MODIFY_REG(hfdcan->ttcan->TTOCF,
  2019. (FDCAN_TTOCF_EECS | FDCAN_TTOCF_EGTF | FDCAN_TTOCF_ECC),
  2020. (pTTParams->ExternalClkSync | \
  2021. pTTParams->GlobalTimeFilter | \
  2022. pTTParams->ClockCalibration));
  2023. }
  2024. /* Configure system matrix limits */
  2025. MODIFY_REG(hfdcan->ttcan->TTMLM, FDCAN_TTMLM_CSS, pTTParams->CycleStartSync);
  2026. if(pTTParams->OperationMode != FDCAN_TT_COMMUNICATION_LEVEL0)
  2027. {
  2028. MODIFY_REG(hfdcan->ttcan->TTMLM,
  2029. (FDCAN_TTMLM_TXEW | FDCAN_TTMLM_ENTT),
  2030. (((pTTParams->TxEnableWindow - 1) << 8) | (pTTParams->ExpTxTrigNbr << 16)));
  2031. }
  2032. if(pTTParams->TimeMaster == FDCAN_TT_POTENTIAL_MASTER)
  2033. {
  2034. MODIFY_REG(hfdcan->ttcan->TTMLM, FDCAN_TTMLM_CCM, pTTParams->BasicCyclesNbr);
  2035. }
  2036. /* Configure input triggers: Stop watch and Event */
  2037. MODIFY_REG(hfdcan->ttcan->TTTS,
  2038. (FDCAN_TTTS_SWTSEL | FDCAN_TTTS_EVTSEL),
  2039. (pTTParams->StopWatchTrigSel | pTTParams->EventTrigSel));
  2040. /* Configure trigger memory start address */
  2041. hfdcan->msgRam.TTMemorySA = (hfdcan->msgRam.EndAddress - SRAMCAN_BASE) / 4;
  2042. MODIFY_REG(hfdcan->ttcan->TTTMC, FDCAN_TTTMC_TMSA, (hfdcan->msgRam.TTMemorySA << 2));
  2043. /* Trigger memory elements number */
  2044. MODIFY_REG(hfdcan->ttcan->TTTMC, FDCAN_TTTMC_TME, (pTTParams->TriggerMemoryNbr << 16));
  2045. /* Recalculate End Address */
  2046. hfdcan->msgRam.TTMemorySA = SRAMCAN_BASE + (hfdcan->msgRam.TTMemorySA * 4);
  2047. hfdcan->msgRam.EndAddress = hfdcan->msgRam.TTMemorySA + (pTTParams->TriggerMemoryNbr * 2 * 4);
  2048. if(hfdcan->msgRam.EndAddress > 0x4000B5FC) /* Last address of the Message RAM */
  2049. {
  2050. /* Update error code.
  2051. Message RAM overflow */
  2052. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
  2053. return HAL_ERROR;
  2054. }
  2055. else
  2056. {
  2057. /* Flush the allocated Message RAM area */
  2058. for(RAMcounter = hfdcan->msgRam.TTMemorySA; RAMcounter < hfdcan->msgRam.EndAddress; RAMcounter += 4)
  2059. {
  2060. *(__IO uint32_t *)(RAMcounter) = 0x00000000;
  2061. }
  2062. }
  2063. /* Return function status */
  2064. return HAL_OK;
  2065. }
  2066. else
  2067. {
  2068. /* Update error code */
  2069. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
  2070. return HAL_ERROR;
  2071. }
  2072. }
  2073. /**
  2074. * @brief Configure the reference message.
  2075. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  2076. * the configuration information for the specified FDCAN.
  2077. * @param IdType: Identifier Type.
  2078. * This parameter can be a value of @arg FDCAN_id_type.
  2079. * @param Identifier: Reference Identifier.
  2080. * This parameter must be a number between:
  2081. * - 0 and 0x7FF, if IdType is FDCAN_STANDARD_ID
  2082. * - 0 and 0x1FFFFFFF, if IdType is FDCAN_EXTENDED_ID
  2083. * @param Payload: Enable or disable the additional payload.
  2084. * This parameter can be a value of @arg FDCAN_TT_Reference_Message_Payload.
  2085. * This parameter is ignored in case of time slaves.
  2086. * If this parameter is set to FDCAN_TT_REF_MESSAGE_ADD_PAYLOAD, the
  2087. * following elements are taken from Tx Buffer 0:
  2088. * - MessageMarker
  2089. * - TxEventFifoControl
  2090. * - DataLength
  2091. * - Data Bytes (payload):
  2092. * - bytes 2-8, for Level 1
  2093. * - bytes 5-8, for Level 0 and Level 2
  2094. * @retval HAL status
  2095. */
  2096. HAL_StatusTypeDef HAL_FDCAN_TT_ConfigReferenceMessage(FDCAN_HandleTypeDef *hfdcan, uint32_t IdType, uint32_t Identifier, uint32_t Payload)
  2097. {
  2098. /* Check function parameters */
  2099. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  2100. assert_param(IS_FDCAN_ID_TYPE(IdType));
  2101. if(IdType == FDCAN_STANDARD_ID)
  2102. {
  2103. assert_param(IS_FDCAN_MAX_VALUE(Identifier, 0x7FF));
  2104. }
  2105. else /* IdType == FDCAN_EXTENDED_ID */
  2106. {
  2107. assert_param(IS_FDCAN_MAX_VALUE(Identifier, 0x1FFFFFFF));
  2108. }
  2109. assert_param(IS_FDCAN_TT_REFERENCE_MESSAGE_PAYLOAD(Payload));
  2110. if(hfdcan->State == HAL_FDCAN_STATE_READY)
  2111. {
  2112. /* Configure reference message identifier type, identifier and payload */
  2113. if(IdType == FDCAN_EXTENDED_ID)
  2114. {
  2115. MODIFY_REG(hfdcan->ttcan->TTRMC, (FDCAN_TTRMC_RID | FDCAN_TTRMC_XTD | FDCAN_TTRMC_RMPS), (Payload | IdType | Identifier));
  2116. }
  2117. else /* IdType == FDCAN_STANDARD_ID */
  2118. {
  2119. MODIFY_REG(hfdcan->ttcan->TTRMC, (FDCAN_TTRMC_RID | FDCAN_TTRMC_XTD | FDCAN_TTRMC_RMPS), (Payload | IdType | (Identifier << 18)));
  2120. }
  2121. /* Return function status */
  2122. return HAL_OK;
  2123. }
  2124. else
  2125. {
  2126. /* Update error code */
  2127. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
  2128. return HAL_ERROR;
  2129. }
  2130. }
  2131. /**
  2132. * @brief Configure the FDCAN trigger according to the specified
  2133. * parameters in the FDCAN_TriggerTypeDef structure.
  2134. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  2135. * the configuration information for the specified FDCAN.
  2136. * @param sTriggerConfig: pointer to an FDCAN_TriggerTypeDef structure that
  2137. * contains the trigger configuration information
  2138. * @retval HAL status
  2139. */
  2140. HAL_StatusTypeDef HAL_FDCAN_TT_ConfigTrigger(FDCAN_HandleTypeDef* hfdcan, FDCAN_TriggerTypeDef* sTriggerConfig)
  2141. {
  2142. uint32_t CycleCode;
  2143. uint32_t MessageNumber;
  2144. uint32_t TriggerElementW1;
  2145. uint32_t TriggerElementW2;
  2146. uint32_t *TriggerAddress;
  2147. /* Check function parameters */
  2148. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  2149. assert_param(IS_FDCAN_MAX_VALUE(sTriggerConfig->TriggerIndex, 63));
  2150. assert_param(IS_FDCAN_MAX_VALUE(sTriggerConfig->TimeMark, 0xFFFF));
  2151. assert_param(IS_FDCAN_TT_REPEAT_FACTOR(sTriggerConfig->RepeatFactor));
  2152. if(sTriggerConfig->RepeatFactor != FDCAN_TT_REPEAT_EVERY_CYCLE)
  2153. {
  2154. assert_param(IS_FDCAN_MAX_VALUE(sTriggerConfig->StartCycle, (sTriggerConfig->RepeatFactor - 1)));
  2155. }
  2156. assert_param(IS_FDCAN_TT_TM_EVENT_INTERNAL(sTriggerConfig->TmEventInt));
  2157. assert_param(IS_FDCAN_TT_TM_EVENT_EXTERNAL(sTriggerConfig->TmEventExt));
  2158. assert_param(IS_FDCAN_TT_TRIGGER_TYPE(sTriggerConfig->TriggerType));
  2159. assert_param(IS_FDCAN_ID_TYPE(sTriggerConfig->FilterType));
  2160. if((sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_SINGLE ) ||
  2161. (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_CONTINUOUS ) ||
  2162. (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_ARBITRATION) ||
  2163. (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_MERGED ))
  2164. {
  2165. assert_param(IS_FDCAN_TX_LOCATION(sTriggerConfig->TxBufferIndex));
  2166. }
  2167. if(sTriggerConfig->TriggerType == FDCAN_TT_RX_TRIGGER)
  2168. {
  2169. if(sTriggerConfig->FilterType == FDCAN_STANDARD_ID)
  2170. {
  2171. assert_param(IS_FDCAN_MAX_VALUE(sTriggerConfig->FilterIndex, 63));
  2172. }
  2173. else /* sTriggerConfig->FilterType == FDCAN_EXTENDED_ID */
  2174. {
  2175. assert_param(IS_FDCAN_MAX_VALUE(sTriggerConfig->FilterIndex, 127));
  2176. }
  2177. }
  2178. if(hfdcan->State == HAL_FDCAN_STATE_READY)
  2179. {
  2180. /* Calculate cycle code */
  2181. if(sTriggerConfig->RepeatFactor == FDCAN_TT_REPEAT_EVERY_CYCLE)
  2182. {
  2183. CycleCode = FDCAN_TT_REPEAT_EVERY_CYCLE;
  2184. }
  2185. else /* sTriggerConfig->RepeatFactor != FDCAN_TT_REPEAT_EVERY_CYCLE */
  2186. {
  2187. CycleCode = sTriggerConfig->RepeatFactor + sTriggerConfig->StartCycle;
  2188. }
  2189. /* Build first word of trigger element */
  2190. TriggerElementW1 = ((sTriggerConfig->TimeMark << 16) | \
  2191. (CycleCode << 8) | \
  2192. sTriggerConfig->TmEventInt | \
  2193. sTriggerConfig->TmEventExt | \
  2194. sTriggerConfig->TriggerType);
  2195. /* Select message number depending on trigger type (transmission or reception) */
  2196. if(sTriggerConfig->TriggerType == FDCAN_TT_RX_TRIGGER)
  2197. {
  2198. MessageNumber = sTriggerConfig->FilterIndex;
  2199. }
  2200. else if((sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_SINGLE ) ||
  2201. (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_CONTINUOUS ) ||
  2202. (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_ARBITRATION) ||
  2203. (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_MERGED ))
  2204. {
  2205. MessageNumber = POSITION_VAL(sTriggerConfig->TxBufferIndex);
  2206. }
  2207. else
  2208. {
  2209. MessageNumber = 0U;
  2210. }
  2211. /* Build second word of trigger element */
  2212. TriggerElementW2 = ((sTriggerConfig->FilterType >> 7) | (MessageNumber << 16));
  2213. /* Calculate trigger address */
  2214. TriggerAddress = (uint32_t *)(hfdcan->msgRam.TTMemorySA + (sTriggerConfig->TriggerIndex * 4 * 2));
  2215. /* Write trigger element to the message RAM */
  2216. *TriggerAddress++ = TriggerElementW1;
  2217. *TriggerAddress = TriggerElementW2;
  2218. /* Return function status */
  2219. return HAL_OK;
  2220. }
  2221. else
  2222. {
  2223. /* Update error code */
  2224. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
  2225. return HAL_ERROR;
  2226. }
  2227. }
  2228. /**
  2229. * @brief Schedule global time adjustment for the next reference message.
  2230. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  2231. * the configuration information for the specified FDCAN.
  2232. * @param TimePreset: time preset value.
  2233. * This parameter must be a number between:
  2234. * - 0x0000 and 0x7FFF, Next_Master_Ref_Mark = Current_Master_Ref_Mark + TimePreset
  2235. * or:
  2236. * - 0x8001 and 0xFFFF, Next_Master_Ref_Mark = Current_Master_Ref_Mark - (0x10000 - TimePreset)
  2237. * @retval HAL status
  2238. */
  2239. HAL_StatusTypeDef HAL_FDCAN_TT_SetGlobalTime(FDCAN_HandleTypeDef* hfdcan, uint32_t TimePreset)
  2240. {
  2241. uint32_t Counter = 0U;
  2242. /* Check function parameters */
  2243. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  2244. assert_param(IS_FDCAN_TT_TIME_PRESET(TimePreset));
  2245. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  2246. {
  2247. /* Check that the external clock synchronization is enabled */
  2248. if((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_EECS) != FDCAN_TTOCF_EECS)
  2249. {
  2250. /* Update error code */
  2251. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
  2252. return HAL_ERROR;
  2253. }
  2254. /* Check that no global time preset is pending */
  2255. if((hfdcan->ttcan->TTOST & FDCAN_TTOST_WGTD) == FDCAN_TTOST_WGTD)
  2256. {
  2257. /* Update error code */
  2258. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PENDING;
  2259. return HAL_ERROR;
  2260. }
  2261. /* Configure time preset */
  2262. MODIFY_REG(hfdcan->ttcan->TTGTP, FDCAN_TTGTP_TP, TimePreset);
  2263. /* Wait until the LCKC bit into TTOCN register is reset */
  2264. while((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != RESET)
  2265. {
  2266. /* Check for the Timeout */
  2267. if(Counter++ > FDCAN_TIMEOUT_VALUE)
  2268. {
  2269. /* Update error code */
  2270. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  2271. /* Change FDCAN state */
  2272. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  2273. return HAL_ERROR;
  2274. }
  2275. }
  2276. /* Schedule time preset to take effect by the next reference message */
  2277. SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_SGT);
  2278. /* Return function status */
  2279. return HAL_OK;
  2280. }
  2281. else
  2282. {
  2283. /* Update error code */
  2284. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  2285. return HAL_ERROR;
  2286. }
  2287. }
  2288. /**
  2289. * @brief Schedule TUR numerator update for the next reference message.
  2290. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  2291. * the configuration information for the specified FDCAN.
  2292. * @param NewTURNumerator: new value of the TUR numerator.
  2293. * This parameter must be a number between 0x10000 and 0x1FFFF.
  2294. * @retval HAL status
  2295. */
  2296. HAL_StatusTypeDef HAL_FDCAN_TT_SetClockSynchronization(FDCAN_HandleTypeDef* hfdcan, uint32_t NewTURNumerator)
  2297. {
  2298. uint32_t Counter = 0U;
  2299. /* Check function parameters */
  2300. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  2301. assert_param(IS_FDCAN_TT_TUR_NUMERATOR(NewTURNumerator));
  2302. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  2303. {
  2304. /* Check that the external clock synchronization is enabled */
  2305. if((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_EECS) != FDCAN_TTOCF_EECS)
  2306. {
  2307. /* Update error code */
  2308. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
  2309. return HAL_ERROR;
  2310. }
  2311. /* Check that no external clock synchronization is pending */
  2312. if((hfdcan->ttcan->TTOST & FDCAN_TTOST_WECS) == FDCAN_TTOST_WECS)
  2313. {
  2314. /* Update error code */
  2315. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PENDING;
  2316. return HAL_ERROR;
  2317. }
  2318. /* Configure new TUR numerator */
  2319. MODIFY_REG(hfdcan->ttcan->TURCF, FDCAN_TURCF_NCL, (NewTURNumerator - 0x10000));
  2320. /* Wait until the LCKC bit into TTOCN register is reset */
  2321. while((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != RESET)
  2322. {
  2323. /* Check for the Timeout */
  2324. if(Counter++ > FDCAN_TIMEOUT_VALUE)
  2325. {
  2326. /* Update error code */
  2327. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  2328. /* Change FDCAN state */
  2329. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  2330. return HAL_ERROR;
  2331. }
  2332. }
  2333. /* Schedule TUR numerator update by the next reference message */
  2334. SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_ECS);
  2335. /* Return function status */
  2336. return HAL_OK;
  2337. }
  2338. else
  2339. {
  2340. /* Update error code */
  2341. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  2342. return HAL_ERROR;
  2343. }
  2344. }
  2345. /**
  2346. * @brief Configure stop watch source and polarity.
  2347. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  2348. * the configuration information for the specified FDCAN.
  2349. * @param Source: stop watch source.
  2350. * This parameter can be a value of @arg FDCAN_TT_stop_watch_source.
  2351. * @param Polarity: stop watch polarity.
  2352. * This parameter can be a value of @arg FDCAN_TT_stop_watch_polarity.
  2353. * @retval HAL status
  2354. */
  2355. HAL_StatusTypeDef HAL_FDCAN_TT_ConfigStopWatch(FDCAN_HandleTypeDef* hfdcan, uint32_t Source, uint32_t Polarity)
  2356. {
  2357. uint32_t Counter = 0U;
  2358. /* Check function parameters */
  2359. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  2360. assert_param(IS_FDCAN_TT_STOP_WATCH_SOURCE(Source));
  2361. assert_param(IS_FDCAN_TT_STOP_WATCH_POLARITY(Polarity));
  2362. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  2363. {
  2364. /* Wait until the LCKC bit into TTOCN register is reset */
  2365. while((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != RESET)
  2366. {
  2367. /* Check for the Timeout */
  2368. if(Counter++ > FDCAN_TIMEOUT_VALUE)
  2369. {
  2370. /* Update error code */
  2371. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  2372. /* Change FDCAN state */
  2373. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  2374. return HAL_ERROR;
  2375. }
  2376. }
  2377. /* Select stop watch source and polarity */
  2378. MODIFY_REG(hfdcan->ttcan->TTOCN, (FDCAN_TTOCN_SWS | FDCAN_TTOCN_SWP), (Source | Polarity));
  2379. /* Return function status */
  2380. return HAL_OK;
  2381. }
  2382. else
  2383. {
  2384. /* Update error code */
  2385. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  2386. return HAL_ERROR;
  2387. }
  2388. }
  2389. /**
  2390. * @brief Configure register time mark pulse generation.
  2391. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  2392. * the configuration information for the specified FDCAN.
  2393. * @param TimeMarkSource: time mark source.
  2394. * This parameter can be a value of @arg FDCAN_TT_time_mark_source.
  2395. * @param TimeMarkValue: time mark value (reference).
  2396. * This parameter must be a number between 0 and 0xFFFF.
  2397. * @param RepeatFactor: repeat factor of the cycle for which the time mark is valid.
  2398. * This parameter can be a value of @arg FDCAN_TT_Repeat_Factor.
  2399. * @param StartCycle: index of the first cycle in which the time mark becomes valid.
  2400. * This parameter is ignored if RepeatFactor is set to FDCAN_TT_REPEAT_EVERY_CYCLE.
  2401. * This parameter must be a number between 0 and RepeatFactor.
  2402. * @retval HAL status
  2403. */
  2404. HAL_StatusTypeDef HAL_FDCAN_TT_ConfigRegisterTimeMark(FDCAN_HandleTypeDef* hfdcan,
  2405. uint32_t TimeMarkSource, uint32_t TimeMarkValue,
  2406. uint32_t RepeatFactor, uint32_t StartCycle)
  2407. {
  2408. uint32_t Counter = 0U;
  2409. uint32_t CycleCode;
  2410. /* Check function parameters */
  2411. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  2412. assert_param(IS_FDCAN_TT_REGISTER_TIME_MARK_SOURCE(TimeMarkSource));
  2413. assert_param(IS_FDCAN_MAX_VALUE(TimeMarkValue, 0xFFFF));
  2414. assert_param(IS_FDCAN_TT_REPEAT_FACTOR(RepeatFactor));
  2415. if(RepeatFactor != FDCAN_TT_REPEAT_EVERY_CYCLE)
  2416. {
  2417. assert_param(IS_FDCAN_MAX_VALUE(StartCycle, (RepeatFactor - 1)));
  2418. }
  2419. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  2420. {
  2421. /* Wait until the LCKC bit into TTOCN register is reset */
  2422. while((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != RESET)
  2423. {
  2424. /* Check for the Timeout */
  2425. if(Counter++ > FDCAN_TIMEOUT_VALUE)
  2426. {
  2427. /* Update error code */
  2428. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  2429. /* Change FDCAN state */
  2430. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  2431. return HAL_ERROR;
  2432. }
  2433. }
  2434. /* Disable the time mark compare function */
  2435. CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TMC);
  2436. if(TimeMarkSource != FDCAN_TT_REG_TIMEMARK_DIABLED)
  2437. {
  2438. /* Calculate cycle code */
  2439. if(RepeatFactor == FDCAN_TT_REPEAT_EVERY_CYCLE)
  2440. {
  2441. CycleCode = FDCAN_TT_REPEAT_EVERY_CYCLE;
  2442. }
  2443. else /* RepeatFactor != FDCAN_TT_REPEAT_EVERY_CYCLE */
  2444. {
  2445. CycleCode = RepeatFactor + StartCycle;
  2446. }
  2447. Counter = 0U;
  2448. /* Wait until the LCKM bit into TTTMK register is reset */
  2449. while((hfdcan->ttcan->TTTMK & FDCAN_TTTMK_LCKM) != RESET)
  2450. {
  2451. /* Check for the Timeout */
  2452. if(Counter++ > FDCAN_TIMEOUT_VALUE)
  2453. {
  2454. /* Update error code */
  2455. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  2456. /* Change FDCAN state */
  2457. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  2458. return HAL_ERROR;
  2459. }
  2460. }
  2461. /* Configure time mark value and cycle code */
  2462. hfdcan->ttcan->TTTMK = (TimeMarkValue | (CycleCode << 16));
  2463. Counter = 0U;
  2464. /* Wait until the LCKC bit into TTOCN register is reset */
  2465. while((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != RESET)
  2466. {
  2467. /* Check for the Timeout */
  2468. if(Counter++ > FDCAN_TIMEOUT_VALUE)
  2469. {
  2470. /* Update error code */
  2471. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  2472. /* Change FDCAN state */
  2473. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  2474. return HAL_ERROR;
  2475. }
  2476. }
  2477. /* Update the register time mark compare source */
  2478. MODIFY_REG(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TMC, TimeMarkSource);
  2479. }
  2480. /* Return function status */
  2481. return HAL_OK;
  2482. }
  2483. else
  2484. {
  2485. /* Update error code */
  2486. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  2487. return HAL_ERROR;
  2488. }
  2489. }
  2490. /**
  2491. * @brief Enable register time mark pulse generation.
  2492. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  2493. * the configuration information for the specified FDCAN.
  2494. * @retval HAL status
  2495. */
  2496. HAL_StatusTypeDef HAL_FDCAN_TT_EnableRegisterTimeMarkPulse(FDCAN_HandleTypeDef *hfdcan)
  2497. {
  2498. uint32_t Counter = 0U;
  2499. /* Check function parameters */
  2500. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  2501. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  2502. {
  2503. /* Wait until the LCKC bit into TTOCN register is reset */
  2504. while((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != RESET)
  2505. {
  2506. /* Check for the Timeout */
  2507. if(Counter++ > FDCAN_TIMEOUT_VALUE)
  2508. {
  2509. /* Update error code */
  2510. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  2511. /* Change FDCAN state */
  2512. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  2513. return HAL_ERROR;
  2514. }
  2515. }
  2516. /* Enable Register Time Mark Interrupt output on fdcan1_rtp */
  2517. SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_RTIE);
  2518. /* Return function status */
  2519. return HAL_OK;
  2520. }
  2521. else
  2522. {
  2523. /* Update error code */
  2524. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  2525. return HAL_ERROR;
  2526. }
  2527. }
  2528. /**
  2529. * @brief Disable register time mark pulse generation.
  2530. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  2531. * the configuration information for the specified FDCAN.
  2532. * @retval HAL status
  2533. */
  2534. HAL_StatusTypeDef HAL_FDCAN_TT_DisableRegisterTimeMarkPulse(FDCAN_HandleTypeDef *hfdcan)
  2535. {
  2536. uint32_t Counter = 0U;
  2537. /* Check function parameters */
  2538. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  2539. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  2540. {
  2541. /* Wait until the LCKC bit into TTOCN register is reset */
  2542. while((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != RESET)
  2543. {
  2544. /* Check for the Timeout */
  2545. if(Counter++ > FDCAN_TIMEOUT_VALUE)
  2546. {
  2547. /* Update error code */
  2548. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  2549. /* Change FDCAN state */
  2550. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  2551. return HAL_ERROR;
  2552. }
  2553. }
  2554. /* Disable Register Time Mark Interrupt output on fdcan1_rtp */
  2555. CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_RTIE);
  2556. /* Return function status */
  2557. return HAL_OK;
  2558. }
  2559. else
  2560. {
  2561. /* Update error code */
  2562. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  2563. return HAL_ERROR;
  2564. }
  2565. }
  2566. /**
  2567. * @brief Enable trigger time mark pulse generation.
  2568. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  2569. * the configuration information for the specified FDCAN.
  2570. * @retval HAL status
  2571. */
  2572. HAL_StatusTypeDef HAL_FDCAN_TT_EnableTriggerTimeMarkPulse(FDCAN_HandleTypeDef *hfdcan)
  2573. {
  2574. uint32_t Counter = 0U;
  2575. /* Check function parameters */
  2576. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  2577. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  2578. {
  2579. if((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
  2580. {
  2581. /* Wait until the LCKC bit into TTOCN register is reset */
  2582. while((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != RESET)
  2583. {
  2584. /* Check for the Timeout */
  2585. if(Counter++ > FDCAN_TIMEOUT_VALUE)
  2586. {
  2587. /* Update error code */
  2588. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  2589. /* Change FDCAN state */
  2590. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  2591. return HAL_ERROR;
  2592. }
  2593. }
  2594. /* Enable Trigger Time Mark Interrupt output on fdcan1_tmp */
  2595. SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TTIE);
  2596. /* Return function status */
  2597. return HAL_OK;
  2598. }
  2599. else
  2600. {
  2601. /* Update error code.
  2602. Feature not supported for TT Level 0 */
  2603. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
  2604. return HAL_ERROR;
  2605. }
  2606. }
  2607. else
  2608. {
  2609. /* Update error code */
  2610. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  2611. return HAL_ERROR;
  2612. }
  2613. }
  2614. /**
  2615. * @brief Disable trigger time mark pulse generation.
  2616. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  2617. * the configuration information for the specified FDCAN.
  2618. * @retval HAL status
  2619. */
  2620. HAL_StatusTypeDef HAL_FDCAN_TT_DisableTriggerTimeMarkPulse(FDCAN_HandleTypeDef *hfdcan)
  2621. {
  2622. uint32_t Counter = 0U;
  2623. /* Check function parameters */
  2624. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  2625. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  2626. {
  2627. if((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
  2628. {
  2629. /* Wait until the LCKC bit into TTOCN register is reset */
  2630. while((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != RESET)
  2631. {
  2632. /* Check for the Timeout */
  2633. if(Counter++ > FDCAN_TIMEOUT_VALUE)
  2634. {
  2635. /* Update error code */
  2636. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  2637. /* Change FDCAN state */
  2638. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  2639. return HAL_ERROR;
  2640. }
  2641. }
  2642. /* Disable Trigger Time Mark Interrupt output on fdcan1_rtp */
  2643. CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TTIE);
  2644. /* Return function status */
  2645. return HAL_OK;
  2646. }
  2647. else
  2648. {
  2649. /* Update error code.
  2650. Feature not supported for TT Level 0 */
  2651. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
  2652. return HAL_ERROR;
  2653. }
  2654. }
  2655. else
  2656. {
  2657. /* Update error code */
  2658. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  2659. return HAL_ERROR;
  2660. }
  2661. }
  2662. /**
  2663. * @brief Enable gap control by input pin fdcan1_evt.
  2664. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  2665. * the configuration information for the specified FDCAN.
  2666. * @retval HAL status
  2667. */
  2668. HAL_StatusTypeDef HAL_FDCAN_TT_EnableHardwareGapControl(FDCAN_HandleTypeDef *hfdcan)
  2669. {
  2670. uint32_t Counter = 0U;
  2671. /* Check function parameters */
  2672. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  2673. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  2674. {
  2675. if((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
  2676. {
  2677. /* Wait until the LCKC bit into TTOCN register is reset */
  2678. while((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != RESET)
  2679. {
  2680. /* Check for the Timeout */
  2681. if(Counter++ > FDCAN_TIMEOUT_VALUE)
  2682. {
  2683. /* Update error code */
  2684. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  2685. /* Change FDCAN state */
  2686. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  2687. return HAL_ERROR;
  2688. }
  2689. }
  2690. /* Enable gap control by pin fdcan1_evt */
  2691. SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_GCS);
  2692. /* Return function status */
  2693. return HAL_OK;
  2694. }
  2695. else
  2696. {
  2697. /* Update error code.
  2698. Feature not supported for TT Level 0 */
  2699. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
  2700. return HAL_ERROR;
  2701. }
  2702. }
  2703. else
  2704. {
  2705. /* Update error code */
  2706. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  2707. return HAL_ERROR;
  2708. }
  2709. }
  2710. /**
  2711. * @brief Disable gap control by input pin fdcan1_evt.
  2712. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  2713. * the configuration information for the specified FDCAN.
  2714. * @retval HAL status
  2715. */
  2716. HAL_StatusTypeDef HAL_FDCAN_TT_DisableHardwareGapControl(FDCAN_HandleTypeDef *hfdcan)
  2717. {
  2718. uint32_t Counter = 0U;
  2719. /* Check function parameters */
  2720. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  2721. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  2722. {
  2723. if((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
  2724. {
  2725. /* Wait until the LCKC bit into TTOCN register is reset */
  2726. while((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != RESET)
  2727. {
  2728. /* Check for the Timeout */
  2729. if(Counter++ > FDCAN_TIMEOUT_VALUE)
  2730. {
  2731. /* Update error code */
  2732. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  2733. /* Change FDCAN state */
  2734. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  2735. return HAL_ERROR;
  2736. }
  2737. }
  2738. /* Disable gap control by pin fdcan1_evt */
  2739. CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_GCS);
  2740. /* Return function status */
  2741. return HAL_OK;
  2742. }
  2743. else
  2744. {
  2745. /* Update error code.
  2746. Feature not supported for TT Level 0 */
  2747. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
  2748. return HAL_ERROR;
  2749. }
  2750. }
  2751. else
  2752. {
  2753. /* Update error code */
  2754. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  2755. return HAL_ERROR;
  2756. }
  2757. }
  2758. /**
  2759. * @brief Enable gap control (finish only) by register time mark interrupt.
  2760. * The next register time mark interrupt (TTIR.RTMI = "1") will finish
  2761. * the Gap and start the reference message.
  2762. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  2763. * the configuration information for the specified FDCAN.
  2764. * @retval HAL status
  2765. */
  2766. HAL_StatusTypeDef HAL_FDCAN_TT_EnableTimeMarkGapControl(FDCAN_HandleTypeDef *hfdcan)
  2767. {
  2768. uint32_t Counter = 0U;
  2769. /* Check function parameters */
  2770. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  2771. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  2772. {
  2773. if((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
  2774. {
  2775. /* Wait until the LCKC bit into TTOCN register is reset */
  2776. while((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != RESET)
  2777. {
  2778. /* Check for the Timeout */
  2779. if(Counter++ > FDCAN_TIMEOUT_VALUE)
  2780. {
  2781. /* Update error code */
  2782. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  2783. /* Change FDCAN state */
  2784. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  2785. return HAL_ERROR;
  2786. }
  2787. }
  2788. /* Enable gap control by register time mark interrupt */
  2789. SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TMG);
  2790. /* Return function status */
  2791. return HAL_OK;
  2792. }
  2793. else
  2794. {
  2795. /* Update error code.
  2796. Feature not supported for TT Level 0 */
  2797. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
  2798. return HAL_ERROR;
  2799. }
  2800. }
  2801. else
  2802. {
  2803. /* Update error code */
  2804. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  2805. return HAL_ERROR;
  2806. }
  2807. }
  2808. /**
  2809. * @brief Disable gap control by register time mark interrupt.
  2810. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  2811. * the configuration information for the specified FDCAN.
  2812. * @retval HAL status
  2813. */
  2814. HAL_StatusTypeDef HAL_FDCAN_TT_DisableTimeMarkGapControl(FDCAN_HandleTypeDef *hfdcan)
  2815. {
  2816. uint32_t Counter = 0U;
  2817. /* Check function parameters */
  2818. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  2819. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  2820. {
  2821. if((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
  2822. {
  2823. /* Wait until the LCKC bit into TTOCN register is reset */
  2824. while((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != RESET)
  2825. {
  2826. /* Check for the Timeout */
  2827. if(Counter++ > FDCAN_TIMEOUT_VALUE)
  2828. {
  2829. /* Update error code */
  2830. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  2831. /* Change FDCAN state */
  2832. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  2833. return HAL_ERROR;
  2834. }
  2835. }
  2836. /* Disable gap control by register time mark interrupt */
  2837. CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TMG);
  2838. /* Return function status */
  2839. return HAL_OK;
  2840. }
  2841. else
  2842. {
  2843. /* Update error code.
  2844. Feature not supported for TT Level 0 */
  2845. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
  2846. return HAL_ERROR;
  2847. }
  2848. }
  2849. else
  2850. {
  2851. /* Update error code */
  2852. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  2853. return HAL_ERROR;
  2854. }
  2855. }
  2856. /**
  2857. * @brief Transmit next reference message with Next_is_Gap = "1".
  2858. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  2859. * the configuration information for the specified FDCAN.
  2860. * @retval HAL status
  2861. */
  2862. HAL_StatusTypeDef HAL_FDCAN_TT_SetNextIsGap(FDCAN_HandleTypeDef *hfdcan)
  2863. {
  2864. uint32_t Counter = 0U;
  2865. /* Check function parameters */
  2866. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  2867. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  2868. {
  2869. /* Check that the node is configured for external event-synchronized TT operation */
  2870. if((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_GEN) != FDCAN_TTOCF_GEN)
  2871. {
  2872. /* Update error code */
  2873. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
  2874. return HAL_ERROR;
  2875. }
  2876. if((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
  2877. {
  2878. /* Wait until the LCKC bit into TTOCN register is reset */
  2879. while((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != RESET)
  2880. {
  2881. /* Check for the Timeout */
  2882. if(Counter++ > FDCAN_TIMEOUT_VALUE)
  2883. {
  2884. /* Update error code */
  2885. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  2886. /* Change FDCAN state */
  2887. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  2888. return HAL_ERROR;
  2889. }
  2890. }
  2891. /* Set Next is Gap */
  2892. SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_NIG);
  2893. /* Return function status */
  2894. return HAL_OK;
  2895. }
  2896. else
  2897. {
  2898. /* Update error code.
  2899. Feature not supported for TT Level 0 */
  2900. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
  2901. return HAL_ERROR;
  2902. }
  2903. }
  2904. else
  2905. {
  2906. /* Update error code */
  2907. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  2908. return HAL_ERROR;
  2909. }
  2910. }
  2911. /**
  2912. * @brief Finish a Gap by requesting start of reference message.
  2913. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  2914. * the configuration information for the specified FDCAN.
  2915. * @retval HAL status
  2916. */
  2917. HAL_StatusTypeDef HAL_FDCAN_TT_SetEndOfGap(FDCAN_HandleTypeDef *hfdcan)
  2918. {
  2919. uint32_t Counter = 0U;
  2920. /* Check function parameters */
  2921. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  2922. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  2923. {
  2924. /* Check that the node is configured for external event-synchronized TT operation */
  2925. if((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_GEN) != FDCAN_TTOCF_GEN)
  2926. {
  2927. /* Update error code */
  2928. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
  2929. return HAL_ERROR;
  2930. }
  2931. if((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
  2932. {
  2933. /* Wait until the LCKC bit into TTOCN register is reset */
  2934. while((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != RESET)
  2935. {
  2936. /* Check for the Timeout */
  2937. if(Counter++ > FDCAN_TIMEOUT_VALUE)
  2938. {
  2939. /* Update error code */
  2940. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  2941. /* Change FDCAN state */
  2942. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  2943. return HAL_ERROR;
  2944. }
  2945. }
  2946. /* Set Finish Gap */
  2947. SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_FGP);
  2948. /* Return function status */
  2949. return HAL_OK;
  2950. }
  2951. else
  2952. {
  2953. /* Update error code.
  2954. Feature not supported for TT Level 0 */
  2955. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
  2956. return HAL_ERROR;
  2957. }
  2958. }
  2959. else
  2960. {
  2961. /* Update error code */
  2962. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  2963. return HAL_ERROR;
  2964. }
  2965. }
  2966. /**
  2967. * @brief Configure target phase used for external synchronization by event
  2968. * trigger input pin fdcan1_evt.
  2969. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  2970. * the configuration information for the specified FDCAN.
  2971. * @param TargetPhase: defines target value of cycle time when a rising edge
  2972. * of fdcan1_evt is expected.
  2973. * This parameter must be a number between 0 and 0xFFFF.
  2974. * @retval HAL status
  2975. */
  2976. HAL_StatusTypeDef HAL_FDCAN_TT_ConfigExternalSyncPhase(FDCAN_HandleTypeDef *hfdcan, uint32_t TargetPhase)
  2977. {
  2978. /* Check function parameters */
  2979. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  2980. assert_param(IS_FDCAN_MAX_VALUE(TargetPhase, 0xFFFF));
  2981. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  2982. {
  2983. /* Check that no external schedule synchronization is pending */
  2984. if((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_ESCN) == FDCAN_TTOCN_ESCN)
  2985. {
  2986. /* Update error code */
  2987. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PENDING;
  2988. return HAL_ERROR;
  2989. }
  2990. /* Configure cycle time target phase */
  2991. MODIFY_REG(hfdcan->ttcan->TTGTP, FDCAN_TTGTP_CTP, (TargetPhase << 16));
  2992. /* Return function status */
  2993. return HAL_OK;
  2994. }
  2995. else
  2996. {
  2997. /* Update error code */
  2998. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  2999. return HAL_ERROR;
  3000. }
  3001. }
  3002. /**
  3003. * @brief Synchronize the phase of the FDCAN schedule to an external schedule
  3004. * using event trigger input pin fdcan1_evt.
  3005. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3006. * the configuration information for the specified FDCAN.
  3007. * @retval HAL status
  3008. */
  3009. HAL_StatusTypeDef HAL_FDCAN_TT_EnableExternalSynchronization(FDCAN_HandleTypeDef *hfdcan)
  3010. {
  3011. uint32_t Counter = 0U;
  3012. /* Check function parameters */
  3013. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  3014. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  3015. {
  3016. /* Wait until the LCKC bit into TTOCN register is reset */
  3017. while((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != RESET)
  3018. {
  3019. /* Check for the Timeout */
  3020. if(Counter++ > FDCAN_TIMEOUT_VALUE)
  3021. {
  3022. /* Update error code */
  3023. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  3024. /* Change FDCAN state */
  3025. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  3026. return HAL_ERROR;
  3027. }
  3028. }
  3029. /* Enable external synchronization */
  3030. SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_ESCN);
  3031. /* Return function status */
  3032. return HAL_OK;
  3033. }
  3034. else
  3035. {
  3036. /* Update error code */
  3037. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  3038. return HAL_ERROR;
  3039. }
  3040. }
  3041. /**
  3042. * @brief Disable external schedule synchronization.
  3043. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3044. * the configuration information for the specified FDCAN.
  3045. * @retval HAL status
  3046. */
  3047. HAL_StatusTypeDef HAL_FDCAN_TT_DisableExternalSynchronization(FDCAN_HandleTypeDef *hfdcan)
  3048. {
  3049. uint32_t Counter = 0U;
  3050. /* Check function parameters */
  3051. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  3052. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  3053. {
  3054. /* Wait until the LCKC bit into TTOCN register is reset */
  3055. while((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != RESET)
  3056. {
  3057. /* Check for the Timeout */
  3058. if(Counter++ > FDCAN_TIMEOUT_VALUE)
  3059. {
  3060. /* Update error code */
  3061. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
  3062. /* Change FDCAN state */
  3063. hfdcan->State = HAL_FDCAN_STATE_ERROR;
  3064. return HAL_ERROR;
  3065. }
  3066. }
  3067. /* Disable external synchronization */
  3068. CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_ESCN);
  3069. /* Return function status */
  3070. return HAL_OK;
  3071. }
  3072. else
  3073. {
  3074. /* Update error code */
  3075. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  3076. return HAL_ERROR;
  3077. }
  3078. }
  3079. /**
  3080. * @brief Get TT operation status.
  3081. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3082. * the configuration information for the specified FDCAN.
  3083. * @param TTOpStatus: pointer to an FDCAN_TTOperationStatusTypeDef structure.
  3084. * @retval HAL status
  3085. */
  3086. HAL_StatusTypeDef HAL_FDCAN_TT_GetOperationStatus(FDCAN_HandleTypeDef *hfdcan, FDCAN_TTOperationStatusTypeDef *TTOpStatus)
  3087. {
  3088. uint32_t TTStatusReg;
  3089. /* Check function parameters */
  3090. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  3091. /* Read the TT operation status register */
  3092. TTStatusReg = READ_REG(hfdcan->ttcan->TTOST);
  3093. /* Fill the TT operation status structure */
  3094. TTOpStatus->ErrorLevel = (TTStatusReg & FDCAN_TTOST_EL);
  3095. TTOpStatus->MasterState = (TTStatusReg & FDCAN_TTOST_MS);
  3096. TTOpStatus->SyncState = (TTStatusReg & FDCAN_TTOST_SYS);
  3097. TTOpStatus->GTimeQuality = ((TTStatusReg & FDCAN_TTOST_QGTP) >> 6);
  3098. TTOpStatus->ClockQuality = ((TTStatusReg & FDCAN_TTOST_QCS) >> 7);
  3099. TTOpStatus->RefTrigOffset = ((TTStatusReg & FDCAN_TTOST_RTO) >> 8);
  3100. TTOpStatus->GTimeDiscPending = ((TTStatusReg & FDCAN_TTOST_WGTD) >> 22);
  3101. TTOpStatus->GapFinished = ((TTStatusReg & FDCAN_TTOST_GFI) >> 23);
  3102. TTOpStatus->MasterPriority = ((TTStatusReg & FDCAN_TTOST_TMP) >> 24);
  3103. TTOpStatus->GapStarted = ((TTStatusReg & FDCAN_TTOST_GSI) >> 27);
  3104. TTOpStatus->WaitForEvt = ((TTStatusReg & FDCAN_TTOST_WFE) >> 28);
  3105. TTOpStatus->AppWdgEvt = ((TTStatusReg & FDCAN_TTOST_AWE) >> 29);
  3106. TTOpStatus->ECSPending = ((TTStatusReg & FDCAN_TTOST_WECS) >> 30);
  3107. TTOpStatus->PhaseLock = ((TTStatusReg & FDCAN_TTOST_SPL) >> 31);
  3108. /* Return function status */
  3109. return HAL_OK;
  3110. }
  3111. /**
  3112. * @}
  3113. */
  3114. /** @defgroup FDCAN_Exported_Functions_Group5 Interrupts management
  3115. * @brief Interrupts management
  3116. *
  3117. @verbatim
  3118. ==============================================================================
  3119. ##### Interrupts management #####
  3120. ==============================================================================
  3121. [..] This section provides functions allowing to:
  3122. (+) HAL_FDCAN_ConfigInterruptLines : Assign interrupts to either Interrupt line 0 or 1
  3123. (+) HAL_FDCAN_TT_ConfigInterruptLines : Assign TT interrupts to either Interrupt line 0 or 1
  3124. (+) HAL_FDCAN_ActivateNotification : Enable interrupts
  3125. (+) HAL_FDCAN_DeactivateNotification : Disable interrupts
  3126. (+) HAL_FDCAN_TT_ActivateNotification : Enable TT interrupts
  3127. (+) HAL_FDCAN_TT_DeactivateNotification : Disable TT interrupts
  3128. (+) HAL_FDCAN_IRQHandler : Handles FDCAN interrupt request
  3129. @endverbatim
  3130. * @{
  3131. */
  3132. /**
  3133. * @brief Assign interrupts to either Interrupt line 0 or 1.
  3134. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3135. * the configuration information for the specified FDCAN.
  3136. * @param ITList: indicates which interrupts will be assigned to the selected interrupt line.
  3137. * This parameter can be any combination of @arg FDCAN_Interrupts.
  3138. * @param InterruptLine: Interrupt line.
  3139. * This parameter can be a value of @arg FDCAN_Interrupt_Line.
  3140. * @retval HAL status
  3141. */
  3142. HAL_StatusTypeDef HAL_FDCAN_ConfigInterruptLines(FDCAN_HandleTypeDef *hfdcan, uint32_t ITList, uint32_t InterruptLine)
  3143. {
  3144. /* Check function parameters */
  3145. assert_param(IS_FDCAN_IT(ITList));
  3146. assert_param(IS_FDCAN_IT_LINE(InterruptLine));
  3147. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  3148. {
  3149. /* Assign list of interrupts to the selected line */
  3150. if(InterruptLine == FDCAN_INTERRUPT_LINE0)
  3151. {
  3152. CLEAR_BIT(hfdcan->Instance->ILS, ITList);
  3153. }
  3154. else /* InterruptLine == FDCAN_INTERRUPT_LINE1 */
  3155. {
  3156. SET_BIT(hfdcan->Instance->ILS, ITList);
  3157. }
  3158. /* Return function status */
  3159. return HAL_OK;
  3160. }
  3161. else
  3162. {
  3163. /* Update error code */
  3164. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  3165. return HAL_ERROR;
  3166. }
  3167. }
  3168. /**
  3169. * @brief Assign TT interrupts to either Interrupt line 0 or 1.
  3170. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3171. * the configuration information for the specified FDCAN.
  3172. * @param TTITList: indicates which interrupts will be assigned to the selected interrupt line.
  3173. * This parameter can be any combination of @arg FDCAN_TTInterrupts.
  3174. * @param InterruptLine: Interrupt line.
  3175. * This parameter can be a value of @arg FDCAN_Interrupt_Line.
  3176. * @retval HAL status
  3177. */
  3178. HAL_StatusTypeDef HAL_FDCAN_TT_ConfigInterruptLines(FDCAN_HandleTypeDef *hfdcan, uint32_t TTITList, uint32_t InterruptLine)
  3179. {
  3180. /* Check function parameters */
  3181. assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
  3182. assert_param(IS_FDCAN_TT_IT(TTITList));
  3183. assert_param(IS_FDCAN_IT_LINE(InterruptLine));
  3184. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  3185. {
  3186. /* Assign list of interrupts to the selected line */
  3187. if(InterruptLine == FDCAN_INTERRUPT_LINE0)
  3188. {
  3189. CLEAR_BIT(hfdcan->ttcan->TTILS, TTITList);
  3190. }
  3191. else /* InterruptLine == FDCAN_INTERRUPT_LINE1 */
  3192. {
  3193. SET_BIT(hfdcan->ttcan->TTILS, TTITList);
  3194. }
  3195. /* Return function status */
  3196. return HAL_OK;
  3197. }
  3198. else
  3199. {
  3200. /* Update error code */
  3201. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  3202. return HAL_ERROR;
  3203. }
  3204. }
  3205. /**
  3206. * @brief Enable interrupts.
  3207. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3208. * the configuration information for the specified FDCAN.
  3209. * @param ActiveITs: indicates which interrupts will be enabled.
  3210. * This parameter can be any combination of @arg FDCAN_Interrupts.
  3211. * @param BufferIndexes: Tx Buffer Indexes.
  3212. * This parameter can be any combination of @arg FDCAN_Tx_location.
  3213. * This parameter is ignored if ActiveITs does not include one of the following:
  3214. * - FDCAN_IT_TX_COMPLETE
  3215. * - FDCAN_IT_TX_ABORT_COMPLETE
  3216. * @retval HAL status
  3217. */
  3218. HAL_StatusTypeDef HAL_FDCAN_ActivateNotification(FDCAN_HandleTypeDef *hfdcan, uint32_t ActiveITs, uint32_t BufferIndexes)
  3219. {
  3220. /* Check function parameters */
  3221. assert_param(IS_FDCAN_IT(ActiveITs));
  3222. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  3223. {
  3224. /* Enable Interrupt lines */
  3225. if((ActiveITs & hfdcan->Instance->ILS) == RESET)
  3226. {
  3227. /* Enable Interrupt line 0 */
  3228. SET_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE0);
  3229. }
  3230. else if((ActiveITs & hfdcan->Instance->ILS) == ActiveITs)
  3231. {
  3232. /* Enable Interrupt line 1 */
  3233. SET_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE1);
  3234. }
  3235. else
  3236. {
  3237. /* Enable Interrupt lines 0 and 1 */
  3238. hfdcan->Instance->ILE = (FDCAN_INTERRUPT_LINE0 | FDCAN_INTERRUPT_LINE1);
  3239. }
  3240. if((ActiveITs & FDCAN_IT_TX_COMPLETE) != RESET)
  3241. {
  3242. /* Enable Tx Buffer Transmission Interrupt to set TC flag in IR register,
  3243. but interrupt will only occure if TC is enabled in IE register */
  3244. SET_BIT(hfdcan->Instance->TXBTIE, BufferIndexes);
  3245. }
  3246. if((ActiveITs & FDCAN_IT_TX_ABORT_COMPLETE) != RESET)
  3247. {
  3248. /* Enable Tx Buffer Cancellation Finished Interrupt to set TCF flag in IR register,
  3249. but interrupt will only occure if TCF is enabled in IE register */
  3250. SET_BIT(hfdcan->Instance->TXBCIE, BufferIndexes);
  3251. }
  3252. /* Enable the selected interrupts */
  3253. __HAL_FDCAN_ENABLE_IT(hfdcan, ActiveITs);
  3254. /* Return function status */
  3255. return HAL_OK;
  3256. }
  3257. else
  3258. {
  3259. /* Update error code */
  3260. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  3261. return HAL_ERROR;
  3262. }
  3263. }
  3264. /**
  3265. * @brief Disable interrupts.
  3266. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3267. * the configuration information for the specified FDCAN.
  3268. * @param InactiveITs: indicates which interrupts will be disabled.
  3269. * This parameter can be any combination of @arg FDCAN_Interrupts.
  3270. * @retval HAL status
  3271. */
  3272. HAL_StatusTypeDef HAL_FDCAN_DeactivateNotification(FDCAN_HandleTypeDef *hfdcan, uint32_t InactiveITs)
  3273. {
  3274. /* Check function parameters */
  3275. assert_param(IS_FDCAN_IT(InactiveITs));
  3276. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  3277. {
  3278. /* Disable the selected interrupts */
  3279. __HAL_FDCAN_DISABLE_IT(hfdcan, InactiveITs);
  3280. /* Return function status */
  3281. return HAL_OK;
  3282. }
  3283. else
  3284. {
  3285. /* Update error code */
  3286. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  3287. return HAL_ERROR;
  3288. }
  3289. }
  3290. /**
  3291. * @brief Enable TT interrupts.
  3292. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3293. * the configuration information for the specified FDCAN.
  3294. * @param ActiveTTITs: indicates which TT interrupts will be enabled.
  3295. * This parameter can be any combination of @arg FDCAN_TTInterrupts.
  3296. * @retval HAL status
  3297. */
  3298. HAL_StatusTypeDef HAL_FDCAN_TT_ActivateNotification(FDCAN_HandleTypeDef *hfdcan, uint32_t ActiveTTITs)
  3299. {
  3300. /* Check function parameters */
  3301. assert_param(IS_FDCAN_TT_IT(ActiveTTITs));
  3302. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  3303. {
  3304. /* Enable Interrupt lines */
  3305. if((ActiveTTITs & hfdcan->ttcan->TTILS) == RESET)
  3306. {
  3307. /* Enable Interrupt line 0 */
  3308. SET_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE0);
  3309. }
  3310. else if((ActiveTTITs & hfdcan->ttcan->TTILS) == ActiveTTITs)
  3311. {
  3312. /* Enable Interrupt line 1 */
  3313. SET_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE1);
  3314. }
  3315. else
  3316. {
  3317. /* Enable Interrupt lines 0 and 1 */
  3318. hfdcan->Instance->ILE = (FDCAN_INTERRUPT_LINE0 | FDCAN_INTERRUPT_LINE1);
  3319. }
  3320. /* Enable the selected TT interrupts */
  3321. __HAL_FDCAN_TT_ENABLE_IT(hfdcan, ActiveTTITs);
  3322. /* Return function status */
  3323. return HAL_OK;
  3324. }
  3325. else
  3326. {
  3327. /* Update error code */
  3328. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  3329. return HAL_ERROR;
  3330. }
  3331. }
  3332. /**
  3333. * @brief Disable TT interrupts.
  3334. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3335. * the configuration information for the specified FDCAN.
  3336. * @param InactiveTTITs: indicates which TT interrupts will be disabled.
  3337. * This parameter can be any combination of @arg FDCAN_TTInterrupts.
  3338. * @retval HAL status
  3339. */
  3340. HAL_StatusTypeDef HAL_FDCAN_TT_DeactivateNotification(FDCAN_HandleTypeDef *hfdcan, uint32_t InactiveTTITs)
  3341. {
  3342. /* Check function parameters */
  3343. assert_param(IS_FDCAN_TT_IT(InactiveTTITs));
  3344. if((hfdcan->State == HAL_FDCAN_STATE_READY) || (hfdcan->State == HAL_FDCAN_STATE_BUSY))
  3345. {
  3346. /* Disable the selected TT interrupts */
  3347. __HAL_FDCAN_TT_DISABLE_IT(hfdcan, InactiveTTITs);
  3348. /* Return function status */
  3349. return HAL_OK;
  3350. }
  3351. else
  3352. {
  3353. /* Update error code */
  3354. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
  3355. return HAL_ERROR;
  3356. }
  3357. }
  3358. /**
  3359. * @brief Handles FDCAN interrupt request.
  3360. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3361. * the configuration information for the specified FDCAN.
  3362. * @retval HAL status
  3363. */
  3364. void HAL_FDCAN_IRQHandler(FDCAN_HandleTypeDef *hfdcan)
  3365. {
  3366. uint32_t ClkCalibrationITs;
  3367. uint32_t TxEventFifoITs;
  3368. uint32_t RxFifo0ITs;
  3369. uint32_t RxFifo1ITs;
  3370. uint32_t ErrStatus;
  3371. uint32_t TransmittedBuffers;
  3372. uint32_t AbortedBuffers;
  3373. uint32_t TTSchedSyncITs;
  3374. uint32_t TTTimeMarkITs;
  3375. uint32_t TTGlobTimeITs;
  3376. uint32_t TTDistErrors;
  3377. uint32_t TTFatalErrors;
  3378. uint32_t SWTime;
  3379. uint32_t SWCycleCount;
  3380. ClkCalibrationITs = (FDCAN_CCU->IR << 30);
  3381. ClkCalibrationITs &= (FDCAN_CCU->IE << 30);
  3382. TxEventFifoITs = hfdcan->Instance->IR & FDCAN_TX_EVENT_FIFO_MASK;
  3383. TxEventFifoITs &= hfdcan->Instance->IE;
  3384. RxFifo0ITs = hfdcan->Instance->IR & FDCAN_RX_FIFO0_MASK;
  3385. RxFifo0ITs &= hfdcan->Instance->IE;
  3386. RxFifo1ITs = hfdcan->Instance->IR & FDCAN_RX_FIFO1_MASK;
  3387. RxFifo1ITs &= hfdcan->Instance->IE;
  3388. ErrStatus = hfdcan->Instance->IR & FDCAN_ERROR_MASK;
  3389. ErrStatus &= hfdcan->Instance->IE;
  3390. /* High Priority Message interrupt management *******************************/
  3391. if(__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_RX_HIGH_PRIORITY_MSG) != RESET)
  3392. {
  3393. if(__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_RX_HIGH_PRIORITY_MSG) != RESET)
  3394. {
  3395. /* Disable the High Priority Message interrupt */
  3396. __HAL_FDCAN_DISABLE_IT(hfdcan, FDCAN_IT_RX_HIGH_PRIORITY_MSG);
  3397. /* Clear the High Priority Message flag */
  3398. __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_RX_HIGH_PRIORITY_MSG);
  3399. /* High Priority Message Callback */
  3400. HAL_FDCAN_HighPriorityMessageCallback(hfdcan);
  3401. }
  3402. }
  3403. /* Transmission Abort interrupt management **********************************/
  3404. if(__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_TX_ABORT_COMPLETE) != RESET)
  3405. {
  3406. if(__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_TX_ABORT_COMPLETE) != RESET)
  3407. {
  3408. /* Disable the Transmission Cancellation interrupt */
  3409. __HAL_FDCAN_DISABLE_IT(hfdcan, FDCAN_IT_TX_ABORT_COMPLETE);
  3410. /* List of aborted monitored buffers */
  3411. AbortedBuffers = hfdcan->Instance->TXBCF;
  3412. AbortedBuffers &= hfdcan->Instance->TXBCIE;
  3413. /* Disable the Tx Buffer Cancellation Finished Interrupt */
  3414. CLEAR_BIT(hfdcan->Instance->TXBCIE, AbortedBuffers);
  3415. /* Clear the Transmission Cancellation flag */
  3416. __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_TX_ABORT_COMPLETE);
  3417. /* Transmission Cancellation Callback */
  3418. HAL_FDCAN_TxBufferAbortCallback(hfdcan, AbortedBuffers);
  3419. }
  3420. }
  3421. /* Clock calibration unit interrupts management *****************************/
  3422. if(ClkCalibrationITs != 0U)
  3423. {
  3424. /* Disable the Clock Calibration interrupts */
  3425. __HAL_FDCAN_DISABLE_IT(hfdcan, ClkCalibrationITs);
  3426. /* Clear the Clock Calibration flags */
  3427. __HAL_FDCAN_CLEAR_FLAG(hfdcan, ClkCalibrationITs);
  3428. /* Clock Calibration Callback */
  3429. HAL_FDCAN_ClockCalibrationCallback(hfdcan, ClkCalibrationITs);
  3430. }
  3431. /* Tx event FIFO interrupts management **************************************/
  3432. if(TxEventFifoITs != 0U)
  3433. {
  3434. /* Disable the Tx Event FIFO interrupts */
  3435. __HAL_FDCAN_DISABLE_IT(hfdcan, TxEventFifoITs);
  3436. /* Clear the Tx Event FIFO flags */
  3437. __HAL_FDCAN_CLEAR_FLAG(hfdcan, TxEventFifoITs);
  3438. /* Tx Event FIFO Callback */
  3439. HAL_FDCAN_TxEventFifoCallback(hfdcan, TxEventFifoITs);
  3440. }
  3441. /* Rx FIFO 0 interrupts management ******************************************/
  3442. if(RxFifo0ITs != 0U)
  3443. {
  3444. /* Disable the Rx FIFO 0 interrupts */
  3445. __HAL_FDCAN_DISABLE_IT(hfdcan, RxFifo0ITs);
  3446. /* Clear the Rx FIFO 0 flags */
  3447. __HAL_FDCAN_CLEAR_FLAG(hfdcan, RxFifo0ITs);
  3448. /* Rx FIFO 0 Callback */
  3449. HAL_FDCAN_RxFifo0Callback(hfdcan, RxFifo0ITs);
  3450. }
  3451. /* Rx FIFO 1 interrupts management ******************************************/
  3452. if(RxFifo1ITs != 0U)
  3453. {
  3454. /* Disable the Rx FIFO 1 interrupts */
  3455. __HAL_FDCAN_DISABLE_IT(hfdcan, RxFifo1ITs);
  3456. /* Clear the Rx FIFO 1 flags */
  3457. __HAL_FDCAN_CLEAR_FLAG(hfdcan, RxFifo1ITs);
  3458. /* Rx FIFO 1 Callback */
  3459. HAL_FDCAN_RxFifo1Callback(hfdcan, RxFifo1ITs);
  3460. }
  3461. /* Tx FIFO empty interrupt management ***************************************/
  3462. if(__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_TX_FIFO_EMPTY) != RESET)
  3463. {
  3464. if(__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_TX_FIFO_EMPTY) != RESET)
  3465. {
  3466. /* Disable the Tx FIFO empty interrupt */
  3467. __HAL_FDCAN_DISABLE_IT(hfdcan, FDCAN_IT_TX_FIFO_EMPTY);
  3468. /* Clear the Tx FIFO empty flag */
  3469. __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_TX_FIFO_EMPTY);
  3470. /* Tx FIFO empty Callback */
  3471. HAL_FDCAN_TxFifoEmptyCallback(hfdcan);
  3472. }
  3473. }
  3474. /* Transmission Complete interrupt management *******************************/
  3475. if(__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_TX_COMPLETE) != RESET)
  3476. {
  3477. if(__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_TX_COMPLETE) != RESET)
  3478. {
  3479. /* Disable the Transmission Complete interrupt */
  3480. __HAL_FDCAN_DISABLE_IT(hfdcan, FDCAN_IT_TX_COMPLETE);
  3481. /* List of transmitted monitored buffers */
  3482. TransmittedBuffers = hfdcan->Instance->TXBTO;
  3483. TransmittedBuffers &= hfdcan->Instance->TXBTIE;
  3484. /* Disable the Tx Buffer Transmission Interrupt */
  3485. CLEAR_BIT(hfdcan->Instance->TXBTIE, TransmittedBuffers);
  3486. /* Clear the Transmission Complete flag */
  3487. __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_TX_COMPLETE);
  3488. /* Transmission Complete Callback */
  3489. HAL_FDCAN_TxBufferCompleteCallback(hfdcan, TransmittedBuffers);
  3490. }
  3491. }
  3492. /* Rx Buffer New Message interrupt management *******************************/
  3493. if(__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_RX_BUFFER_NEW_MESSAGE) != RESET)
  3494. {
  3495. if(__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_RX_BUFFER_NEW_MESSAGE) != RESET)
  3496. {
  3497. /* Disable the Rx Buffer New Message interrupt */
  3498. __HAL_FDCAN_DISABLE_IT(hfdcan, FDCAN_IT_RX_BUFFER_NEW_MESSAGE);
  3499. /* Clear the Rx Buffer New Message flag */
  3500. __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_RX_BUFFER_NEW_MESSAGE);
  3501. /* Rx Buffer New Message Callback */
  3502. HAL_FDCAN_RxBufferNewMessageCallback(hfdcan);
  3503. }
  3504. }
  3505. /* Timestamp Wraparound interrupt management ********************************/
  3506. if(__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_TIMESTAMP_WRAPAROUND) != RESET)
  3507. {
  3508. if(__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_TIMESTAMP_WRAPAROUND) != RESET)
  3509. {
  3510. /* Disable the Timestamp Wraparound interrupt */
  3511. __HAL_FDCAN_DISABLE_IT(hfdcan, FDCAN_IT_TIMESTAMP_WRAPAROUND);
  3512. /* Clear the Timestamp Wraparound flag */
  3513. __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_TIMESTAMP_WRAPAROUND);
  3514. /* Timestamp Wraparound Callback */
  3515. HAL_FDCAN_TimestampWraparoundCallback(hfdcan);
  3516. }
  3517. }
  3518. /* Timeout Occurred interrupt management ************************************/
  3519. if(__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_TIMEOUT_OCCURRED) != RESET)
  3520. {
  3521. if(__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_TIMEOUT_OCCURRED) != RESET)
  3522. {
  3523. /* Disable the Timeout Occurred interrupt */
  3524. __HAL_FDCAN_DISABLE_IT(hfdcan, FDCAN_IT_TIMEOUT_OCCURRED);
  3525. /* Clear the Timeout Occurred flag */
  3526. __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_TIMEOUT_OCCURRED);
  3527. /* Timeout Occurred Callback */
  3528. HAL_FDCAN_TimeoutOccurredCallback(hfdcan);
  3529. }
  3530. }
  3531. /* Message RAM access failure interrupt management **************************/
  3532. if(__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_RAM_ACCESS_FAILURE) != RESET)
  3533. {
  3534. if(__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_RAM_ACCESS_FAILURE) != RESET)
  3535. {
  3536. /* Disable the Timeout Occurred interrupt */
  3537. __HAL_FDCAN_DISABLE_IT(hfdcan, FDCAN_IT_RAM_ACCESS_FAILURE);
  3538. /* Clear the Timeout Occurred flag */
  3539. __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_RAM_ACCESS_FAILURE);
  3540. /* Update error code */
  3541. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_RAM_ACCESS;
  3542. }
  3543. }
  3544. /* Error interrupts management **********************************************/
  3545. if(ErrStatus != 0U)
  3546. {
  3547. /* Disable the Error interrupts */
  3548. __HAL_FDCAN_DISABLE_IT(hfdcan, ErrStatus);
  3549. /* Clear the Error flags */
  3550. __HAL_FDCAN_CLEAR_FLAG(hfdcan, ErrStatus);
  3551. /* Update error code */
  3552. hfdcan->ErrorCode |= ErrStatus;
  3553. }
  3554. if((hfdcan->Instance == FDCAN1) && \
  3555. ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != 0))
  3556. {
  3557. TTSchedSyncITs = hfdcan->ttcan->TTIR & FDCAN_TT_SCHEDULE_SYNC_MASK;
  3558. TTSchedSyncITs &= hfdcan->ttcan->TTIE;
  3559. TTTimeMarkITs = hfdcan->ttcan->TTIR & FDCAN_TT_TIME_MARK_MASK;
  3560. TTTimeMarkITs &= hfdcan->ttcan->TTIE;
  3561. TTGlobTimeITs = hfdcan->ttcan->TTIR & FDCAN_TT_GLOBAL_TIME_MASK;
  3562. TTGlobTimeITs &= hfdcan->ttcan->TTIE;
  3563. TTDistErrors = hfdcan->ttcan->TTIR & FDCAN_TT_DISTURBING_ERROR_MASK;
  3564. TTDistErrors &= hfdcan->ttcan->TTIE;
  3565. TTFatalErrors = hfdcan->ttcan->TTIR & FDCAN_TT_FATAL_ERROR_MASK;
  3566. TTFatalErrors &= hfdcan->ttcan->TTIE;
  3567. /* TT Schedule Synchronization interrupts management **********************/
  3568. if(TTSchedSyncITs != 0U)
  3569. {
  3570. /* Disable the TT Schedule Synchronization interrupts */
  3571. __HAL_FDCAN_TT_DISABLE_IT(hfdcan, TTSchedSyncITs);
  3572. /* Clear the TT Schedule Synchronization flags */
  3573. __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, TTSchedSyncITs);
  3574. /* TT Schedule Synchronization Callback */
  3575. HAL_FDCAN_TT_ScheduleSyncCallback(hfdcan, TTSchedSyncITs);
  3576. }
  3577. /* TT Time Mark interrupts management *************************************/
  3578. if(TTTimeMarkITs != 0U)
  3579. {
  3580. /* Disable the TT Time Mark interrupts */
  3581. __HAL_FDCAN_TT_DISABLE_IT(hfdcan, TTTimeMarkITs);
  3582. /* Clear the TT Time Mark flags */
  3583. __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, TTTimeMarkITs);
  3584. /* TT Time Mark Callback */
  3585. HAL_FDCAN_TT_TimeMarkCallback(hfdcan, TTTimeMarkITs);
  3586. }
  3587. /* TT Stop Watch interrupt management *************************************/
  3588. if(__HAL_FDCAN_TT_GET_FLAG(hfdcan, FDCAN_TT_FLAG_STOP_WATCH) != RESET)
  3589. {
  3590. if(__HAL_FDCAN_TT_GET_IT_SOURCE(hfdcan, FDCAN_TT_IT_STOP_WATCH) != RESET)
  3591. {
  3592. /* Disable the TT Stop Watch interrupt */
  3593. __HAL_FDCAN_TT_DISABLE_IT(hfdcan, FDCAN_TT_IT_STOP_WATCH);
  3594. /* Retrieve Stop watch Time and Cycle count */
  3595. SWTime = ((hfdcan->ttcan->TTCPT & FDCAN_TTCPT_SWV) >> 16);
  3596. SWCycleCount = hfdcan->ttcan->TTCPT & FDCAN_TTCPT_CCV;
  3597. /* Clear the TT Stop Watch flag */
  3598. __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, FDCAN_TT_FLAG_STOP_WATCH);
  3599. /* TT Stop Watch Callback */
  3600. HAL_FDCAN_TT_StopWatchCallback(hfdcan, SWTime, SWCycleCount);
  3601. }
  3602. }
  3603. /* TT Global Time interrupts management ***********************************/
  3604. if(TTGlobTimeITs != 0U)
  3605. {
  3606. /* Disable the TT Global Time interrupts */
  3607. __HAL_FDCAN_TT_DISABLE_IT(hfdcan, TTGlobTimeITs);
  3608. /* Clear the TT Global Time flags */
  3609. __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, TTGlobTimeITs);
  3610. /* TT Global Time Callback */
  3611. HAL_FDCAN_TT_GlobalTimeCallback(hfdcan, TTGlobTimeITs);
  3612. }
  3613. /* TT Disturbing Error interrupts management ******************************/
  3614. if(TTDistErrors != 0U)
  3615. {
  3616. /* Disable the TT Disturbing Error interrupts */
  3617. __HAL_FDCAN_TT_DISABLE_IT(hfdcan, TTDistErrors);
  3618. /* Clear the TT Disturbing Error flags */
  3619. __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, TTDistErrors);
  3620. /* Update error code */
  3621. hfdcan->ErrorCode |= TTDistErrors;
  3622. }
  3623. /* TT Fatal Error interrupts management ***********************************/
  3624. if(TTFatalErrors != 0U)
  3625. {
  3626. /* Disable the TT Fatal Error interrupts */
  3627. __HAL_FDCAN_TT_DISABLE_IT(hfdcan, TTFatalErrors);
  3628. /* Clear the TT Fatal Error flags */
  3629. __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, TTFatalErrors);
  3630. /* Update error code */
  3631. hfdcan->ErrorCode |= TTFatalErrors;
  3632. }
  3633. }
  3634. if(hfdcan->ErrorCode != HAL_FDCAN_ERROR_NONE)
  3635. {
  3636. /* Error Callback */
  3637. HAL_FDCAN_ErrorCallback(hfdcan);
  3638. }
  3639. }
  3640. /**
  3641. * @}
  3642. */
  3643. /** @defgroup FDCAN_Exported_Functions_Group6 Callback functions
  3644. * @brief FDCAN Callback functions
  3645. *
  3646. @verbatim
  3647. ==============================================================================
  3648. ##### Callback functions #####
  3649. ==============================================================================
  3650. [..]
  3651. This subsection provides the following callback functions:
  3652. (+) HAL_FDCAN_ClockCalibrationCallback
  3653. (+) HAL_FDCAN_TxEventFifoCallback
  3654. (+) HAL_FDCAN_RxFifo0Callback
  3655. (+) HAL_FDCAN_RxFifo1Callback
  3656. (+) HAL_FDCAN_TxFifoEmptyCallback
  3657. (+) HAL_FDCAN_TxBufferCompleteCallback
  3658. (+) HAL_FDCAN_TxBufferAbortCallback
  3659. (+) HAL_FDCAN_RxBufferNewMessageCallback
  3660. (+) HAL_FDCAN_HighPriorityMessageCallback
  3661. (+) HAL_FDCAN_TimestampWraparoundCallback
  3662. (+) HAL_FDCAN_TimeoutOccurredCallback
  3663. (+) HAL_FDCAN_ErrorCallback
  3664. (+) HAL_FDCAN_TTSchedSyncCallback
  3665. (+) HAL_FDCAN_TTTimeMarkCallback
  3666. (+) HAL_FDCAN_TTStopWatchCallback
  3667. (+) HAL_FDCAN_TTGlobalTimeCallback
  3668. @endverbatim
  3669. * @{
  3670. */
  3671. /**
  3672. * @brief Clock Calibration callback.
  3673. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3674. * the configuration information for the specified FDCAN.
  3675. * @param ClkCalibrationITs: indicates which Clock Calibration interrupts are signalled.
  3676. * This parameter can be any combination of @arg FDCAN_Clock_Calibration_Interrupts.
  3677. * @retval None
  3678. */
  3679. __weak void HAL_FDCAN_ClockCalibrationCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t ClkCalibrationITs)
  3680. {
  3681. /* Prevent unused argument(s) compilation warning */
  3682. UNUSED(hfdcan);
  3683. UNUSED(ClkCalibrationITs);
  3684. /* NOTE : This function Should not be modified, when the callback is needed,
  3685. the HAL_FDCAN_ClockCalibrationCallback could be implemented in the user file
  3686. */
  3687. }
  3688. /**
  3689. * @brief Tx Event callback.
  3690. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3691. * the configuration information for the specified FDCAN.
  3692. * @param TxEventFifoITs: indicates which Tx Event FIFO interrupts are signalled.
  3693. * This parameter can be any combination of @arg FDCAN_Tx_Event_Fifo_Interrupts.
  3694. * @retval None
  3695. */
  3696. __weak void HAL_FDCAN_TxEventFifoCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t TxEventFifoITs)
  3697. {
  3698. /* Prevent unused argument(s) compilation warning */
  3699. UNUSED(hfdcan);
  3700. UNUSED(TxEventFifoITs);
  3701. /* NOTE : This function Should not be modified, when the callback is needed,
  3702. the HAL_FDCAN_TxEventFifoCallback could be implemented in the user file
  3703. */
  3704. }
  3705. /**
  3706. * @brief Rx FIFO 0 callback.
  3707. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3708. * the configuration information for the specified FDCAN.
  3709. * @param RxFifo0ITs: indicates which Rx FIFO 0 interrupts are signalled.
  3710. * This parameter can be any combination of @arg FDCAN_Rx_Fifo0_Interrupts.
  3711. * @retval None
  3712. */
  3713. __weak void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
  3714. {
  3715. /* Prevent unused argument(s) compilation warning */
  3716. UNUSED(hfdcan);
  3717. UNUSED(RxFifo0ITs);
  3718. /* NOTE : This function Should not be modified, when the callback is needed,
  3719. the HAL_FDCAN_RxFifo0Callback could be implemented in the user file
  3720. */
  3721. }
  3722. /**
  3723. * @brief Rx FIFO 1 callback.
  3724. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3725. * the configuration information for the specified FDCAN.
  3726. * @param RxFifo1ITs: indicates which Rx FIFO 1 interrupts are signalled.
  3727. * This parameter can be any combination of @arg FDCAN_Rx_Fifo1_Interrupts.
  3728. * @retval None
  3729. */
  3730. __weak void HAL_FDCAN_RxFifo1Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo1ITs)
  3731. {
  3732. /* Prevent unused argument(s) compilation warning */
  3733. UNUSED(hfdcan);
  3734. UNUSED(RxFifo1ITs);
  3735. /* NOTE : This function Should not be modified, when the callback is needed,
  3736. the HAL_FDCAN_RxFifo1Callback could be implemented in the user file
  3737. */
  3738. }
  3739. /**
  3740. * @brief Tx FIFO Empty callback.
  3741. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3742. * the configuration information for the specified FDCAN.
  3743. * @retval None
  3744. */
  3745. __weak void HAL_FDCAN_TxFifoEmptyCallback(FDCAN_HandleTypeDef *hfdcan)
  3746. {
  3747. /* Prevent unused argument(s) compilation warning */
  3748. UNUSED(hfdcan);
  3749. /* NOTE : This function Should not be modified, when the callback is needed,
  3750. the HAL_FDCAN_TxFifoEmptyCallback could be implemented in the user file
  3751. */
  3752. }
  3753. /**
  3754. * @brief Transmission Complete callback.
  3755. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3756. * the configuration information for the specified FDCAN.
  3757. * @param BufferIndexes: Indexes of the transmitted buffers.
  3758. * This parameter can be any combination of @arg FDCAN_Tx_location.
  3759. * @retval None
  3760. */
  3761. __weak void HAL_FDCAN_TxBufferCompleteCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t BufferIndexes)
  3762. {
  3763. /* Prevent unused argument(s) compilation warning */
  3764. UNUSED(hfdcan);
  3765. UNUSED(BufferIndexes);
  3766. /* NOTE : This function Should not be modified, when the callback is needed,
  3767. the HAL_FDCAN_TxBufferCompleteCallback could be implemented in the user file
  3768. */
  3769. }
  3770. /**
  3771. * @brief Transmission Cancellation callback.
  3772. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3773. * the configuration information for the specified FDCAN.
  3774. * @param BufferIndexes: Indexes of the aborted buffers.
  3775. * This parameter can be any combination of @arg FDCAN_Tx_location.
  3776. * @retval None
  3777. */
  3778. __weak void HAL_FDCAN_TxBufferAbortCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t BufferIndexes)
  3779. {
  3780. /* Prevent unused argument(s) compilation warning */
  3781. UNUSED(hfdcan);
  3782. UNUSED(BufferIndexes);
  3783. /* NOTE : This function Should not be modified, when the callback is needed,
  3784. the HAL_FDCAN_TxBufferAbortCallback could be implemented in the user file
  3785. */
  3786. }
  3787. /**
  3788. * @brief Rx Buffer New Message callback.
  3789. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3790. * the configuration information for the specified FDCAN.
  3791. * @retval None
  3792. */
  3793. __weak void HAL_FDCAN_RxBufferNewMessageCallback(FDCAN_HandleTypeDef *hfdcan)
  3794. {
  3795. /* Prevent unused argument(s) compilation warning */
  3796. UNUSED(hfdcan);
  3797. /* NOTE : This function Should not be modified, when the callback is needed,
  3798. the HAL_FDCAN_RxBufferNewMessageCallback could be implemented in the user file
  3799. */
  3800. }
  3801. /**
  3802. * @brief Timestamp Wraparound callback.
  3803. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3804. * the configuration information for the specified FDCAN.
  3805. * @retval None
  3806. */
  3807. __weak void HAL_FDCAN_TimestampWraparoundCallback(FDCAN_HandleTypeDef *hfdcan)
  3808. {
  3809. /* Prevent unused argument(s) compilation warning */
  3810. UNUSED(hfdcan);
  3811. /* NOTE : This function Should not be modified, when the callback is needed,
  3812. the HAL_FDCAN_TimestampWraparoundCallback could be implemented in the user file
  3813. */
  3814. }
  3815. /**
  3816. * @brief Timeout Occurred callback.
  3817. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3818. * the configuration information for the specified FDCAN.
  3819. * @retval None
  3820. */
  3821. __weak void HAL_FDCAN_TimeoutOccurredCallback(FDCAN_HandleTypeDef *hfdcan)
  3822. {
  3823. /* Prevent unused argument(s) compilation warning */
  3824. UNUSED(hfdcan);
  3825. /* NOTE : This function Should not be modified, when the callback is needed,
  3826. the HAL_FDCAN_TimeoutOccurredCallback could be implemented in the user file
  3827. */
  3828. }
  3829. /**
  3830. * @brief High Priority Message callback.
  3831. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3832. * the configuration information for the specified FDCAN.
  3833. * @retval None
  3834. */
  3835. __weak void HAL_FDCAN_HighPriorityMessageCallback(FDCAN_HandleTypeDef *hfdcan)
  3836. {
  3837. /* Prevent unused argument(s) compilation warning */
  3838. UNUSED(hfdcan);
  3839. /* NOTE : This function Should not be modified, when the callback is needed,
  3840. the HAL_FDCAN_HighPriorityMessageCallback could be implemented in the user file
  3841. */
  3842. }
  3843. /**
  3844. * @brief Error callback.
  3845. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3846. * the configuration information for the specified FDCAN.
  3847. * @retval None
  3848. */
  3849. __weak void HAL_FDCAN_ErrorCallback(FDCAN_HandleTypeDef *hfdcan)
  3850. {
  3851. /* Prevent unused argument(s) compilation warning */
  3852. UNUSED(hfdcan);
  3853. /* NOTE : This function Should not be modified, when the callback is needed,
  3854. the HAL_FDCAN_ErrorCallback could be implemented in the user file
  3855. */
  3856. }
  3857. /**
  3858. * @brief TT Schedule Synchronization callback.
  3859. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3860. * the configuration information for the specified FDCAN.
  3861. * @param TTSchedSyncITs: indicates which TT Schedule Synchronization interrupts are signalled.
  3862. * This parameter can be any combination of @arg FDCAN_TTScheduleSynchronization_Interrupts.
  3863. * @retval None
  3864. */
  3865. __weak void HAL_FDCAN_TT_ScheduleSyncCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t TTSchedSyncITs)
  3866. {
  3867. /* Prevent unused argument(s) compilation warning */
  3868. UNUSED(hfdcan);
  3869. UNUSED(TTSchedSyncITs);
  3870. /* NOTE : This function Should not be modified, when the callback is needed,
  3871. the HAL_FDCAN_TTSchedSyncCallback could be implemented in the user file
  3872. */
  3873. }
  3874. /**
  3875. * @brief TT Time Mark callback.
  3876. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3877. * the configuration information for the specified FDCAN.
  3878. * @param TTTimeMarkITs: indicates which TT Schedule Synchronization interrupts are signalled.
  3879. * This parameter can be any combination of @arg FDCAN_TTTimeMark_Interrupts.
  3880. * @retval None
  3881. */
  3882. __weak void HAL_FDCAN_TT_TimeMarkCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t TTTimeMarkITs)
  3883. {
  3884. /* Prevent unused argument(s) compilation warning */
  3885. UNUSED(hfdcan);
  3886. UNUSED(TTTimeMarkITs);
  3887. /* NOTE : This function Should not be modified, when the callback is needed,
  3888. the HAL_FDCAN_TTTimeMarkCallback could be implemented in the user file
  3889. */
  3890. }
  3891. /**
  3892. * @brief TT Stop Watch callback.
  3893. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3894. * the configuration information for the specified FDCAN.
  3895. * @param SWTime: Time Value captured at the Stop Watch Trigger pin (fdcan1_swt) falling/rising
  3896. * edge (as configured via HAL_FDCAN_TTConfigStopWatch).
  3897. * This parameter is a number between 0 and 0xFFFF.
  3898. * @param SWCycleCount: Cycle count value captured together with SWTime.
  3899. * This parameter is a number between 0 and 0x3F.
  3900. * @retval None
  3901. */
  3902. __weak void HAL_FDCAN_TT_StopWatchCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t SWTime, uint32_t SWCycleCount)
  3903. {
  3904. /* Prevent unused argument(s) compilation warning */
  3905. UNUSED(hfdcan);
  3906. UNUSED(SWTime);
  3907. UNUSED(SWCycleCount);
  3908. /* NOTE : This function Should not be modified, when the callback is needed,
  3909. the HAL_FDCAN_TTStopWatchCallback could be implemented in the user file
  3910. */
  3911. }
  3912. /**
  3913. * @brief TT Global Time callback.
  3914. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3915. * the configuration information for the specified FDCAN.
  3916. * @param TTGlobTimeITs: indicates which TT Global Time interrupts are signalled.
  3917. * This parameter can be any combination of @arg FDCAN_TTGlobalTime_Interrupts.
  3918. * @retval None
  3919. */
  3920. __weak void HAL_FDCAN_TT_GlobalTimeCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t TTGlobTimeITs)
  3921. {
  3922. /* Prevent unused argument(s) compilation warning */
  3923. UNUSED(hfdcan);
  3924. UNUSED(TTGlobTimeITs);
  3925. /* NOTE : This function Should not be modified, when the callback is needed,
  3926. the HAL_FDCAN_TTGlobalTimeCallback could be implemented in the user file
  3927. */
  3928. }
  3929. /**
  3930. * @}
  3931. */
  3932. /** @defgroup FDCAN_Exported_Functions_Group7 Peripheral State functions
  3933. * @brief FDCAN Peripheral State functions
  3934. *
  3935. @verbatim
  3936. ==============================================================================
  3937. ##### Peripheral State functions #####
  3938. ==============================================================================
  3939. [..]
  3940. This subsection provides functions allowing to :
  3941. (+) HAL_FDCAN_GetState() : Return the FDCAN state.
  3942. (+) HAL_FDCAN_GetError() : Return the FDCAN error code if any.
  3943. @endverbatim
  3944. * @{
  3945. */
  3946. /**
  3947. * @brief Return the FDCAN state
  3948. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3949. * the configuration information for the specified FDCAN.
  3950. * @retval HAL state
  3951. */
  3952. HAL_FDCAN_StateTypeDef HAL_FDCAN_GetState(FDCAN_HandleTypeDef* hfdcan)
  3953. {
  3954. /* Return FDCAN state */
  3955. return hfdcan->State;
  3956. }
  3957. /**
  3958. * @brief Return the FDCAN error code
  3959. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3960. * the configuration information for the specified FDCAN.
  3961. * @retval FDCAN Error Code
  3962. */
  3963. uint32_t HAL_FDCAN_GetError(FDCAN_HandleTypeDef *hfdcan)
  3964. {
  3965. /* Return FDCAN error code */
  3966. return hfdcan->ErrorCode;
  3967. }
  3968. /**
  3969. * @}
  3970. */
  3971. /**
  3972. * @}
  3973. */
  3974. /** @addtogroup FDCAN_Private_Functions
  3975. * @{
  3976. */
  3977. /**
  3978. * @brief Calculate each RAM block start address and size
  3979. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  3980. * the configuration information for the specified FDCAN.
  3981. * @retval HAL status
  3982. */
  3983. static HAL_StatusTypeDef FDCAN_CalcultateRamBlockAddresses(FDCAN_HandleTypeDef *hfdcan)
  3984. {
  3985. uint32_t RAMcounter;
  3986. hfdcan->msgRam.StandardFilterSA = hfdcan->Init.MessageRAMOffset;
  3987. /* Standard filter list start address */
  3988. MODIFY_REG(hfdcan->Instance->SIDFC, FDCAN_SIDFC_FLSSA, (hfdcan->msgRam.StandardFilterSA << 2));
  3989. /* Standard filter elements number */
  3990. MODIFY_REG(hfdcan->Instance->SIDFC, FDCAN_SIDFC_LSS, (hfdcan->Init.StdFiltersNbr << 16));
  3991. /* Extended filter list start address */
  3992. hfdcan->msgRam.ExtendedFilterSA = hfdcan->msgRam.StandardFilterSA + hfdcan->Init.StdFiltersNbr;
  3993. MODIFY_REG(hfdcan->Instance->XIDFC, FDCAN_XIDFC_FLESA, (hfdcan->msgRam.ExtendedFilterSA << 2));
  3994. /* Extended filter elements number */
  3995. MODIFY_REG(hfdcan->Instance->XIDFC, FDCAN_XIDFC_LSE, (hfdcan->Init.ExtFiltersNbr << 16));
  3996. /* Rx FIFO 0 start address */
  3997. hfdcan->msgRam.RxFIFO0SA = hfdcan->msgRam.ExtendedFilterSA + (hfdcan->Init.ExtFiltersNbr * 2);
  3998. MODIFY_REG(hfdcan->Instance->RXF0C, FDCAN_RXF0C_F0SA, (hfdcan->msgRam.RxFIFO0SA << 2));
  3999. /* Rx FIFO 0 elements number */
  4000. MODIFY_REG(hfdcan->Instance->RXF0C, FDCAN_RXF0C_F0S, (hfdcan->Init.RxFifo0ElmtsNbr << 16));
  4001. /* Rx FIFO 1 start address */
  4002. hfdcan->msgRam.RxFIFO1SA = hfdcan->msgRam.RxFIFO0SA + (hfdcan->Init.RxFifo0ElmtsNbr * hfdcan->Init.RxFifo0ElmtSize);
  4003. MODIFY_REG(hfdcan->Instance->RXF1C, FDCAN_RXF1C_F1SA, (hfdcan->msgRam.RxFIFO1SA << 2));
  4004. /* Rx FIFO 1 elements number */
  4005. MODIFY_REG(hfdcan->Instance->RXF1C, FDCAN_RXF1C_F1S, (hfdcan->Init.RxFifo1ElmtsNbr << 16));
  4006. /* Rx buffer list start address */
  4007. hfdcan->msgRam.RxBufferSA = hfdcan->msgRam.RxFIFO1SA + (hfdcan->Init.RxFifo1ElmtsNbr * hfdcan->Init.RxFifo1ElmtSize);
  4008. MODIFY_REG(hfdcan->Instance->RXBC, FDCAN_RXBC_RBSA, (hfdcan->msgRam.RxBufferSA << 2));
  4009. /* Tx event FIFO start address */
  4010. hfdcan->msgRam.TxEventFIFOSA = hfdcan->msgRam.RxBufferSA + (hfdcan->Init.RxBuffersNbr * hfdcan->Init.RxBufferSize);
  4011. MODIFY_REG(hfdcan->Instance->TXEFC, FDCAN_TXEFC_EFSA, (hfdcan->msgRam.TxEventFIFOSA << 2));
  4012. /* Tx event FIFO elements number */
  4013. MODIFY_REG(hfdcan->Instance->TXEFC, FDCAN_TXEFC_EFS, (hfdcan->Init.TxEventsNbr << 16));
  4014. /* Tx buffer list start address */
  4015. hfdcan->msgRam.TxBufferSA = hfdcan->msgRam.TxEventFIFOSA + (hfdcan->Init.TxEventsNbr * 2);
  4016. MODIFY_REG(hfdcan->Instance->TXBC, FDCAN_TXBC_TBSA, (hfdcan->msgRam.TxBufferSA << 2));
  4017. /* Dedicated Tx buffers number */
  4018. MODIFY_REG(hfdcan->Instance->TXBC, FDCAN_TXBC_NDTB, (hfdcan->Init.TxBuffersNbr << 16));
  4019. /* Tx FIFO/queue start address */
  4020. hfdcan->msgRam.TxFIFOQSA = hfdcan->msgRam.TxBufferSA + (hfdcan->Init.TxBuffersNbr * hfdcan->Init.TxElmtSize);
  4021. /* Tx FIFO/queue elements number */
  4022. MODIFY_REG(hfdcan->Instance->TXBC, FDCAN_TXBC_TFQS, (hfdcan->Init.TxFifoQueueElmtsNbr << 24));
  4023. hfdcan->msgRam.StandardFilterSA = SRAMCAN_BASE + (hfdcan->Init.MessageRAMOffset * 4);
  4024. hfdcan->msgRam.ExtendedFilterSA = hfdcan->msgRam.StandardFilterSA + (hfdcan->Init.StdFiltersNbr * 4);
  4025. hfdcan->msgRam.RxFIFO0SA = hfdcan->msgRam.ExtendedFilterSA + (hfdcan->Init.ExtFiltersNbr * 2 * 4);
  4026. hfdcan->msgRam.RxFIFO1SA = hfdcan->msgRam.RxFIFO0SA + (hfdcan->Init.RxFifo0ElmtsNbr * hfdcan->Init.RxFifo0ElmtSize * 4);
  4027. hfdcan->msgRam.RxBufferSA = hfdcan->msgRam.RxFIFO1SA + (hfdcan->Init.RxFifo1ElmtsNbr * hfdcan->Init.RxFifo1ElmtSize * 4);
  4028. hfdcan->msgRam.TxEventFIFOSA = hfdcan->msgRam.RxBufferSA + (hfdcan->Init.RxBuffersNbr * hfdcan->Init.RxBufferSize * 4);
  4029. hfdcan->msgRam.TxBufferSA = hfdcan->msgRam.TxEventFIFOSA + (hfdcan->Init.TxEventsNbr * 2 * 4);
  4030. hfdcan->msgRam.TxFIFOQSA = hfdcan->msgRam.TxBufferSA + (hfdcan->Init.TxBuffersNbr * hfdcan->Init.TxElmtSize * 4);
  4031. hfdcan->msgRam.EndAddress = hfdcan->msgRam.TxFIFOQSA + (hfdcan->Init.TxFifoQueueElmtsNbr * hfdcan->Init.TxElmtSize * 4);
  4032. if(hfdcan->msgRam.EndAddress > 0x4000B5FC) /* Last address of the Message RAM */
  4033. {
  4034. /* Update error code.
  4035. Message RAM overflow */
  4036. hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
  4037. return HAL_ERROR;
  4038. }
  4039. else
  4040. {
  4041. /* Flush the allocated Message RAM area */
  4042. for(RAMcounter = hfdcan->msgRam.StandardFilterSA; RAMcounter < hfdcan->msgRam.EndAddress; RAMcounter += 4)
  4043. {
  4044. *(__IO uint32_t *)(RAMcounter) = 0x00000000;
  4045. }
  4046. }
  4047. /* Return function status */
  4048. return HAL_OK;
  4049. }
  4050. /**
  4051. * @brief Copy Tx message to the message RAM.
  4052. * @param hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
  4053. * the configuration information for the specified FDCAN.
  4054. * @param pTxHeader: pointer to a FDCAN_TxHeaderTypeDef structure.
  4055. * @param pTxData: pointer to a buffer containing the payload of the Tx frame.
  4056. * @param BufferIndex: index of the buffer to be configured.
  4057. * @retval HAL status
  4058. */
  4059. static HAL_StatusTypeDef FDCAN_CopyMessageToRAM(FDCAN_HandleTypeDef *hfdcan, FDCAN_TxHeaderTypeDef *pTxHeader, uint8_t *pTxData, uint32_t BufferIndex)
  4060. {
  4061. uint32_t TxElementW1;
  4062. uint32_t TxElementW2;
  4063. uint32_t *TxAddress;
  4064. uint32_t ByteCounter;
  4065. /* Build first word of Tx header element */
  4066. if(pTxHeader->IdType == FDCAN_STANDARD_ID)
  4067. {
  4068. TxElementW1 = (pTxHeader->ErrorStateIndicator |
  4069. FDCAN_STANDARD_ID |
  4070. pTxHeader->TxFrameType |
  4071. (pTxHeader->Identifier << 18));
  4072. }
  4073. else /* pTxHeader->IdType == FDCAN_EXTENDED_ID */
  4074. {
  4075. TxElementW1 = (pTxHeader->ErrorStateIndicator |
  4076. FDCAN_EXTENDED_ID |
  4077. pTxHeader->TxFrameType |
  4078. pTxHeader->Identifier);
  4079. }
  4080. /* Build second word of Tx header element */
  4081. TxElementW2 = ((pTxHeader->MessageMarker << 24) |
  4082. pTxHeader->TxEventFifoControl |
  4083. pTxHeader->FDFormat |
  4084. pTxHeader->BitRateSwitch |
  4085. pTxHeader->DataLength);
  4086. /* Calculate Tx element address */
  4087. TxAddress = (uint32_t *)(hfdcan->msgRam.TxBufferSA + (BufferIndex * hfdcan->Init.TxElmtSize * 4));
  4088. /* Write Tx element header to the message RAM */
  4089. *TxAddress++ = TxElementW1;
  4090. *TxAddress++ = TxElementW2;
  4091. /* Write Tx payload to the message RAM */
  4092. for(ByteCounter = 0; ByteCounter < DLCtoBytes[pTxHeader->DataLength >> 16]; ByteCounter += 4)
  4093. {
  4094. *TxAddress++ = ((pTxData[ByteCounter+3] << 24) |
  4095. (pTxData[ByteCounter+2] << 16) |
  4096. (pTxData[ByteCounter+1] << 8) |
  4097. pTxData[ByteCounter]);
  4098. }
  4099. /* Return function status */
  4100. return HAL_OK;
  4101. }
  4102. /**
  4103. * @}
  4104. */
  4105. #endif /* HAL_FDCAN_MODULE_ENABLED */
  4106. /**
  4107. * @}
  4108. */
  4109. /**
  4110. * @}
  4111. */
  4112. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/