stm32g4xx_hal_fmac.c 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539
  1. /**
  2. ******************************************************************************
  3. * @file stm32g4xx_hal_fmac.c
  4. * @author MCD Application Team
  5. * @brief FMAC HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the FMAC peripheral:
  8. * + Initialization and de-initialization functions
  9. * + Peripheral Control functions
  10. * + Callback functions
  11. * + IRQ handler management
  12. * + Peripheral State and Error functions
  13. *
  14. ******************************************************************************
  15. * @attention
  16. *
  17. * Copyright (c) 2019 STMicroelectronics.
  18. * All rights reserved.
  19. *
  20. * This software is licensed under terms that can be found in the LICENSE file
  21. * in the root directory of this software component.
  22. * If no LICENSE file comes with this software, it is provided AS-IS.
  23. *
  24. ******************************************************************************
  25. *
  26. * @verbatim
  27. ================================================================================
  28. ##### How to use this driver #####
  29. ================================================================================
  30. [..]
  31. The FMAC HAL driver can be used as follows:
  32. (#) Initialize the FMAC low level resources by implementing the HAL_FMAC_MspInit():
  33. (++) Enable the FMAC interface clock using __HAL_RCC_FMAC_CLK_ENABLE().
  34. (++) In case of using interrupts (e.g. access configured as FMAC_BUFFER_ACCESS_IT):
  35. (+++) Configure the FMAC interrupt priority using HAL_NVIC_SetPriority().
  36. (+++) Enable the FMAC IRQ handler using HAL_NVIC_EnableIRQ().
  37. (+++) In FMAC IRQ handler, call HAL_FMAC_IRQHandler().
  38. (++) In case of using DMA to control data transfer (e.g. access configured
  39. as FMAC_BUFFER_ACCESS_DMA):
  40. (+++) Enable the DMA interface clock using __HAL_RCC_DMA1_CLK_ENABLE()
  41. or __HAL_RCC_DMA2_CLK_ENABLE() depending on the used DMA instance.
  42. (+++) Enable the DMAMUX1 interface clock using __HAL_RCC_DMAMUX1_CLK_ENABLE().
  43. (+++) If the initialization of the internal buffers (coefficients, input,
  44. output) is done via DMA, configure and enable one DMA channel for
  45. managing data transfer from memory to memory (preload channel).
  46. (+++) If the input buffer is accessed via DMA, configure and enable one
  47. DMA channel for managing data transfer from memory to peripheral
  48. (input channel).
  49. (+++) If the output buffer is accessed via DMA, configure and enable
  50. one DMA channel for managing data transfer from peripheral to
  51. memory (output channel).
  52. (+++) Associate the initialized DMA handle(s) to the FMAC DMA handle(s)
  53. using __HAL_LINKDMA().
  54. (+++) Configure the priority and enable the NVIC for the transfer complete
  55. interrupt on the enabled DMA channel(s) using HAL_NVIC_SetPriority()
  56. and HAL_NVIC_EnableIRQ().
  57. (#) Initialize the FMAC HAL using HAL_FMAC_Init(). This function
  58. resorts to HAL_FMAC_MspInit() for low-level initialization.
  59. (#) Configure the FMAC processing (filter) using HAL_FMAC_FilterConfig()
  60. or HAL_FMAC_FilterConfig_DMA().
  61. This function:
  62. (++) Defines the memory area within the FMAC internal memory
  63. (input, coefficients, output) and the associated threshold (input, output).
  64. (++) Configures the filter and its parameters:
  65. (+++) Finite Impulse Response (FIR) filter (also known as convolution).
  66. (+++) Infinite Impulse Response (IIR) filter (direct form 1).
  67. (++) Choose the way to access to the input and output buffers: none, polling,
  68. DMA, IT. "none" means the input and/or output data will be handled by
  69. another IP (ADC, DAC, etc.).
  70. (++) Enable the error interruptions in the input access and/or the output
  71. access is done through IT/DMA. If an error occurs, the interruption
  72. will be triggered in loop. In order to recover, the user will have
  73. to reset the IP with the sequence HAL_FMAC_DeInit / HAL_FMAC_Init.
  74. Optionally, he can also disable the interrupt using __HAL_FMAC_DISABLE_IT;
  75. the error status will be kept, but no more interrupt will be triggered.
  76. (++) Write the provided coefficients into the internal memory using polling
  77. mode ( HAL_FMAC_FilterConfig() ) or DMA ( HAL_FMAC_FilterConfig_DMA() ).
  78. In the DMA case, HAL_FMAC_FilterConfigCallback() is called when
  79. the handling is over.
  80. (#) Optionally, the user can enable the error interruption related to
  81. saturation by calling __HAL_FMAC_ENABLE_IT. This helps in debugging the
  82. filter. If a saturation occurs, the interruption will be triggered in loop.
  83. In order to recover, the user will have to:
  84. (++) Disable the interruption by calling __HAL_FMAC_DISABLE_IT if
  85. the user wishes to continue all the same.
  86. (++) Reset the IP with the sequence HAL_FMAC_DeInit / HAL_FMAC_Init.
  87. (#) Optionally, preload input (FIR, IIR) and output (IIR) data using
  88. HAL_FMAC_FilterPreload() or HAL_FMAC_FilterPreload_DMA().
  89. In the DMA case, HAL_FMAC_FilterPreloadCallback() is called when
  90. the handling is over.
  91. This step is optional as the filter can be started without preloaded
  92. data.
  93. (#) Start the FMAC processing (filter) using HAL_FMAC_FilterStart().
  94. This function also configures the output buffer that will be filled from
  95. the circular internal output buffer. The function returns immediately
  96. without updating the provided buffer. The IP processing will be active until
  97. HAL_FMAC_FilterStop() is called.
  98. (#) If the input internal buffer is accessed via DMA, HAL_FMAC_HalfGetDataCallback()
  99. will be called to indicate that half of the input buffer has been handled.
  100. (#) If the input internal buffer is accessed via DMA or interrupt, HAL_FMAC_GetDataCallback()
  101. will be called to require new input data. It will be provided through
  102. HAL_FMAC_AppendFilterData() if the DMA isn't in circular mode.
  103. (#) If the output internal buffer is accessed via DMA, HAL_FMAC_HalfOutputDataReadyCallback()
  104. will be called to indicate that half of the output buffer has been handled.
  105. (#) If the output internal buffer is accessed via DMA or interrupt,
  106. HAL_FMAC_OutputDataReadyCallback() will be called to require a new output
  107. buffer. It will be provided through HAL_FMAC_ConfigFilterOutputBuffer()
  108. if the DMA isn't in circular mode.
  109. (#) In all modes except none, provide new input data to be processed via HAL_FMAC_AppendFilterData().
  110. This function should only be called once the previous input data has been handled
  111. (the preloaded input data isn't concerned).
  112. (#) In all modes except none, provide a new output buffer to be filled via
  113. HAL_FMAC_ConfigFilterOutputBuffer(). This function should only be called once the previous
  114. user's output buffer has been filled.
  115. (#) In polling mode, handle the input and output data using HAL_FMAC_PollFilterData().
  116. This function:
  117. (++) Write the user's input data (provided via HAL_FMAC_AppendFilterData())
  118. into the FMAC input memory area.
  119. (++) Read the FMAC output memory area and write it into the user's output buffer.
  120. It will return either when:
  121. (++) the user's output buffer is filled.
  122. (++) the user's input buffer has been handled.
  123. The unused data (unread input data or free output data) will not be saved.
  124. The user will have to use the updated input and output sizes to keep track
  125. of them.
  126. (#) Stop the FMAC processing (filter) using HAL_FMAC_FilterStop().
  127. (#) Call HAL_FMAC_DeInit() to de-initialize the FMAC peripheral. This function
  128. resorts to HAL_FMAC_MspDeInit() for low-level de-initialization.
  129. ##### Callback registration #####
  130. ==================================
  131. [..]
  132. The compilation define USE_HAL_FMAC_REGISTER_CALLBACKS when set to 1
  133. allows the user to configure dynamically the driver callbacks.
  134. [..]
  135. Use Function HAL_FMAC_RegisterCallback() to register a user callback.
  136. Function HAL_FMAC_RegisterCallback() allows to register following callbacks:
  137. (+) ErrorCallback : Error Callback.
  138. (+) HalfGetDataCallback : Get Half Data Callback.
  139. (+) GetDataCallback : Get Data Callback.
  140. (+) HalfOutputDataReadyCallback : Half Output Data Ready Callback.
  141. (+) OutputDataReadyCallback : Output Data Ready Callback.
  142. (+) FilterConfigCallback : Filter Configuration Callback.
  143. (+) FilterPreloadCallback : Filter Preload Callback.
  144. (+) MspInitCallback : FMAC MspInit.
  145. (+) MspDeInitCallback : FMAC MspDeInit.
  146. This function takes as parameters the HAL peripheral handle, the Callback ID
  147. and a pointer to the user callback function.
  148. [..]
  149. Use function HAL_FMAC_UnRegisterCallback() to reset a callback to the default
  150. weak function.
  151. HAL_FMAC_UnRegisterCallback() takes as parameters the HAL peripheral handle
  152. and the Callback ID.
  153. This function allows to reset following callbacks:
  154. (+) ErrorCallback : Error Callback.
  155. (+) HalfGetDataCallback : Get Half Data Callback.
  156. (+) GetDataCallback : Get Data Callback.
  157. (+) HalfOutputDataReadyCallback : Half Output Data Ready Callback.
  158. (+) OutputDataReadyCallback : Output Data Ready Callback.
  159. (+) FilterConfigCallback : Filter Configuration Callback.
  160. (+) FilterPreloadCallback : Filter Preload Callback.
  161. (+) MspInitCallback : FMAC MspInit.
  162. (+) MspDeInitCallback : FMAC MspDeInit.
  163. [..]
  164. By default, after the HAL_FMAC_Init() and when the state is HAL_FMAC_STATE_RESET
  165. all callbacks are set to the corresponding weak functions:
  166. examples GetDataCallback(), OutputDataReadyCallback().
  167. Exception done for MspInit and MspDeInit functions that are respectively
  168. reset to the legacy weak functions in the HAL_FMAC_Init()
  169. and HAL_FMAC_DeInit() only when these callbacks are null (not registered beforehand).
  170. If not, MspInit or MspDeInit are not null, the HAL_FMAC_Init() and HAL_FMAC_DeInit()
  171. keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
  172. [..]
  173. Callbacks can be registered/unregistered in HAL_FMAC_STATE_READY state only.
  174. Exception done MspInit/MspDeInit that can be registered/unregistered
  175. in HAL_FMAC_STATE_READY or HAL_FMAC_STATE_RESET state, thus registered (user)
  176. MspInit/DeInit callbacks can be used during the Init/DeInit.
  177. In that case first register the MspInit/MspDeInit user callbacks
  178. using HAL_FMAC_RegisterCallback() before calling HAL_FMAC_DeInit()
  179. or HAL_FMAC_Init() function.
  180. [..]
  181. When the compilation define USE_HAL_FMAC_REGISTER_CALLBACKS is set to 0 or
  182. not defined, the callback registration feature is not available
  183. and weak callbacks are used.
  184. @endverbatim
  185. *
  186. */
  187. /* Includes ------------------------------------------------------------------*/
  188. #include "stm32g4xx_hal.h"
  189. #if defined(FMAC)
  190. #ifdef HAL_FMAC_MODULE_ENABLED
  191. /** @addtogroup STM32G4xx_HAL_Driver
  192. * @{
  193. */
  194. /** @defgroup FMAC FMAC
  195. * @brief FMAC HAL driver module
  196. * @{
  197. */
  198. /* Private typedef -----------------------------------------------------------*/
  199. /* Private defines -----------------------------------------------------------*/
  200. /** @defgroup FMAC_Private_Constants FMAC Private Constants
  201. * @{
  202. */
  203. #define MAX_FILTER_DATA_SIZE_TO_HANDLE ((uint16_t) 0xFFU)
  204. #define MAX_PRELOAD_INDEX 0xFFU
  205. #define PRELOAD_ACCESS_DMA 0x00U
  206. #define PRELOAD_ACCESS_POLLING 0x01U
  207. #define POLLING_DISABLED 0U
  208. #define POLLING_ENABLED 1U
  209. #define POLLING_NOT_STOPPED 0U
  210. #define POLLING_STOPPED 1U
  211. /* FMAC polling-based communications time-out value */
  212. #define HAL_FMAC_TIMEOUT_VALUE 1000U
  213. /* FMAC reset time-out value */
  214. #define HAL_FMAC_RESET_TIMEOUT_VALUE 500U
  215. /* DMA Read Requests Enable */
  216. #define FMAC_DMA_REN FMAC_CR_DMAREN
  217. /* DMA Write Channel Enable */
  218. #define FMAC_DMA_WEN FMAC_CR_DMAWEN
  219. /* FMAC Execution Enable */
  220. #define FMAC_START FMAC_PARAM_START
  221. /**
  222. * @}
  223. */
  224. /* Private macros ------------------------------------------------------------*/
  225. /** @defgroup FMAC_Private_Macros FMAC Private Macros
  226. * @{
  227. */
  228. /**
  229. * @brief Get the X1 memory area size.
  230. * @param __HANDLE__ FMAC handle.
  231. * @retval X1_BUF_SIZE
  232. */
  233. #define FMAC_GET_X1_SIZE(__HANDLE__) \
  234. ((((__HANDLE__)->Instance->X1BUFCFG) & (FMAC_X1BUFCFG_X1_BUF_SIZE)) >> (FMAC_X1BUFCFG_X1_BUF_SIZE_Pos))
  235. /**
  236. * @brief Get the X1 watermark.
  237. * @param __HANDLE__ FMAC handle.
  238. * @retval FULL_WM
  239. */
  240. #define FMAC_GET_X1_FULL_WM(__HANDLE__) \
  241. (((__HANDLE__)->Instance->X1BUFCFG) & (FMAC_X1BUFCFG_FULL_WM))
  242. /**
  243. * @brief Get the X2 memory area size.
  244. * @param __HANDLE__ FMAC handle.
  245. * @retval X2_BUF_SIZE
  246. */
  247. #define FMAC_GET_X2_SIZE(__HANDLE__) \
  248. ((((__HANDLE__)->Instance->X2BUFCFG) & (FMAC_X2BUFCFG_X2_BUF_SIZE)) >> (FMAC_X2BUFCFG_X2_BUF_SIZE_Pos))
  249. /**
  250. * @brief Get the Y memory area size.
  251. * @param __HANDLE__ FMAC handle.
  252. * @retval Y_BUF_SIZE
  253. */
  254. #define FMAC_GET_Y_SIZE(__HANDLE__) \
  255. ((((__HANDLE__)->Instance->YBUFCFG) & (FMAC_YBUFCFG_Y_BUF_SIZE)) >> (FMAC_YBUFCFG_Y_BUF_SIZE_Pos))
  256. /**
  257. * @brief Get the Y watermark.
  258. * @param __HANDLE__ FMAC handle.
  259. * @retval EMPTY_WM
  260. */
  261. #define FMAC_GET_Y_EMPTY_WM(__HANDLE__) \
  262. (((__HANDLE__)->Instance->YBUFCFG) & (FMAC_YBUFCFG_EMPTY_WM))
  263. /**
  264. * @brief Get the start bit state.
  265. * @param __HANDLE__ FMAC handle.
  266. * @retval START
  267. */
  268. #define FMAC_GET_START_BIT(__HANDLE__) \
  269. ((((__HANDLE__)->Instance->PARAM) & (FMAC_PARAM_START)) >> (FMAC_PARAM_START_Pos))
  270. /**
  271. * @brief Get the threshold matching the watermark.
  272. * @param __WM__ Watermark value.
  273. * @retval THRESHOLD
  274. */
  275. #define FMAC_GET_THRESHOLD_FROM_WM(__WM__) (((__WM__) == FMAC_THRESHOLD_1)? 1U: \
  276. ((__WM__) == FMAC_THRESHOLD_2)? 2U: \
  277. ((__WM__) == FMAC_THRESHOLD_4)? 4U:8U)
  278. /**
  279. * @}
  280. */
  281. /* Private variables ---------------------------------------------------------*/
  282. /* Global variables ----------------------------------------------------------*/
  283. /* Private function prototypes -----------------------------------------------*/
  284. static HAL_StatusTypeDef FMAC_Reset(FMAC_HandleTypeDef *hfmac);
  285. static void FMAC_ResetDataPointers(FMAC_HandleTypeDef *hfmac);
  286. static void FMAC_ResetOutputStateAndDataPointers(FMAC_HandleTypeDef *hfmac);
  287. static void FMAC_ResetInputStateAndDataPointers(FMAC_HandleTypeDef *hfmac);
  288. static HAL_StatusTypeDef FMAC_FilterConfig(FMAC_HandleTypeDef *hfmac, FMAC_FilterConfigTypeDef *pConfig,
  289. uint8_t PreloadAccess);
  290. static HAL_StatusTypeDef FMAC_FilterPreload(FMAC_HandleTypeDef *hfmac, int16_t *pInput, uint8_t InputSize,
  291. int16_t *pOutput, uint8_t OutputSize, uint8_t PreloadAccess);
  292. static void FMAC_WritePreloadDataIncrementPtr(FMAC_HandleTypeDef *hfmac, int16_t **ppData, uint8_t Size);
  293. static HAL_StatusTypeDef FMAC_WaitOnStartUntilTimeout(FMAC_HandleTypeDef *hfmac, uint32_t Tickstart, uint32_t Timeout);
  294. static HAL_StatusTypeDef FMAC_AppendFilterDataUpdateState(FMAC_HandleTypeDef *hfmac, int16_t *pInput,
  295. uint16_t *pInputSize);
  296. static HAL_StatusTypeDef FMAC_ConfigFilterOutputBufferUpdateState(FMAC_HandleTypeDef *hfmac, int16_t *pOutput,
  297. uint16_t *pOutputSize);
  298. static void FMAC_WriteDataIncrementPtr(FMAC_HandleTypeDef *hfmac, uint16_t MaxSizeToWrite);
  299. static void FMAC_ReadDataIncrementPtr(FMAC_HandleTypeDef *hfmac, uint16_t MaxSizeToRead);
  300. static void FMAC_DMAHalfGetData(DMA_HandleTypeDef *hdma);
  301. static void FMAC_DMAGetData(DMA_HandleTypeDef *hdma);
  302. static void FMAC_DMAHalfOutputDataReady(DMA_HandleTypeDef *hdma);
  303. static void FMAC_DMAOutputDataReady(DMA_HandleTypeDef *hdma);
  304. static void FMAC_DMAFilterConfig(DMA_HandleTypeDef *hdma);
  305. static void FMAC_DMAFilterPreload(DMA_HandleTypeDef *hdma);
  306. static void FMAC_DMAError(DMA_HandleTypeDef *hdma);
  307. /* Functions Definition ------------------------------------------------------*/
  308. /** @defgroup FMAC_Exported_Functions FMAC Exported Functions
  309. * @{
  310. */
  311. /** @defgroup FMAC_Exported_Functions_Group1 Initialization and de-initialization functions
  312. * @brief Initialization and Configuration functions
  313. *
  314. @verbatim
  315. ===============================================================================
  316. ##### Initialization and de-initialization functions #####
  317. ===============================================================================
  318. [..] This section provides functions allowing to:
  319. (+) Initialize the FMAC peripheral and the associated handle
  320. (+) DeInitialize the FMAC peripheral
  321. (+) Initialize the FMAC MSP (MCU Specific Package)
  322. (+) De-Initialize the FMAC MSP
  323. (+) Register a User FMAC Callback
  324. (+) Unregister a FMAC CallBack
  325. [..]
  326. @endverbatim
  327. * @{
  328. */
  329. /**
  330. * @brief Initialize the FMAC peripheral and the associated handle.
  331. * @param hfmac pointer to a FMAC_HandleTypeDef structure.
  332. * @retval HAL_StatusTypeDef HAL status
  333. */
  334. HAL_StatusTypeDef HAL_FMAC_Init(FMAC_HandleTypeDef *hfmac)
  335. {
  336. HAL_StatusTypeDef status;
  337. /* Check the FMAC handle allocation */
  338. if (hfmac == NULL)
  339. {
  340. return HAL_ERROR;
  341. }
  342. /* Check the instance */
  343. assert_param(IS_FMAC_ALL_INSTANCE(hfmac->Instance));
  344. if (hfmac->State == HAL_FMAC_STATE_RESET)
  345. {
  346. /* Initialize lock resource */
  347. hfmac->Lock = HAL_UNLOCKED;
  348. #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
  349. /* Register the default callback functions */
  350. hfmac->ErrorCallback = HAL_FMAC_ErrorCallback;
  351. hfmac->HalfGetDataCallback = HAL_FMAC_HalfGetDataCallback;
  352. hfmac->GetDataCallback = HAL_FMAC_GetDataCallback;
  353. hfmac->HalfOutputDataReadyCallback = HAL_FMAC_HalfOutputDataReadyCallback;
  354. hfmac->OutputDataReadyCallback = HAL_FMAC_OutputDataReadyCallback;
  355. hfmac->FilterConfigCallback = HAL_FMAC_FilterConfigCallback;
  356. hfmac->FilterPreloadCallback = HAL_FMAC_FilterPreloadCallback;
  357. if (hfmac->MspInitCallback == NULL)
  358. {
  359. hfmac->MspInitCallback = HAL_FMAC_MspInit;
  360. }
  361. /* Init the low level hardware */
  362. hfmac->MspInitCallback(hfmac);
  363. #else
  364. /* Init the low level hardware */
  365. HAL_FMAC_MspInit(hfmac);
  366. #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
  367. }
  368. /* Reset pInput and pOutput */
  369. hfmac->FilterParam = 0U;
  370. FMAC_ResetDataPointers(hfmac);
  371. /* Reset FMAC unit (internal pointers) */
  372. if (FMAC_Reset(hfmac) == HAL_ERROR)
  373. {
  374. /* Update FMAC error code and FMAC peripheral state */
  375. hfmac->ErrorCode |= HAL_FMAC_ERROR_RESET;
  376. hfmac->State = HAL_FMAC_STATE_TIMEOUT;
  377. status = HAL_ERROR;
  378. }
  379. else
  380. {
  381. /* Update FMAC error code and FMAC peripheral state */
  382. hfmac->ErrorCode = HAL_FMAC_ERROR_NONE;
  383. hfmac->State = HAL_FMAC_STATE_READY;
  384. status = HAL_OK;
  385. }
  386. __HAL_UNLOCK(hfmac);
  387. return status;
  388. }
  389. /**
  390. * @brief De-initialize the FMAC peripheral.
  391. * @param hfmac pointer to a FMAC structure.
  392. * @retval HAL_StatusTypeDef HAL status
  393. */
  394. HAL_StatusTypeDef HAL_FMAC_DeInit(FMAC_HandleTypeDef *hfmac)
  395. {
  396. /* Check the FMAC handle allocation */
  397. if (hfmac == NULL)
  398. {
  399. return HAL_ERROR;
  400. }
  401. /* Check the parameters */
  402. assert_param(IS_FMAC_ALL_INSTANCE(hfmac->Instance));
  403. /* Change FMAC peripheral state */
  404. hfmac->State = HAL_FMAC_STATE_BUSY;
  405. /* Set FMAC error code to none */
  406. hfmac->ErrorCode = HAL_FMAC_ERROR_NONE;
  407. /* Reset pInput and pOutput */
  408. hfmac->FilterParam = 0U;
  409. FMAC_ResetDataPointers(hfmac);
  410. #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
  411. if (hfmac->MspDeInitCallback == NULL)
  412. {
  413. hfmac->MspDeInitCallback = HAL_FMAC_MspDeInit;
  414. }
  415. /* DeInit the low level hardware */
  416. hfmac->MspDeInitCallback(hfmac);
  417. #else
  418. /* DeInit the low level hardware: CLOCK, NVIC, DMA */
  419. HAL_FMAC_MspDeInit(hfmac);
  420. #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
  421. /* Change FMAC peripheral state */
  422. hfmac->State = HAL_FMAC_STATE_RESET;
  423. /* Always release Lock in case of de-initialization */
  424. __HAL_UNLOCK(hfmac);
  425. return HAL_OK;
  426. }
  427. /**
  428. * @brief Initialize the FMAC MSP.
  429. * @param hfmac FMAC handle.
  430. * @retval None
  431. */
  432. __weak void HAL_FMAC_MspInit(FMAC_HandleTypeDef *hfmac)
  433. {
  434. /* Prevent unused argument(s) compilation warning */
  435. UNUSED(hfmac);
  436. /* NOTE : This function should not be modified, when the callback is needed,
  437. the HAL_FMAC_MspInit can be implemented in the user file
  438. */
  439. }
  440. /**
  441. * @brief De-initialize the FMAC MSP.
  442. * @param hfmac FMAC handle.
  443. * @retval None
  444. */
  445. __weak void HAL_FMAC_MspDeInit(FMAC_HandleTypeDef *hfmac)
  446. {
  447. /* Prevent unused argument(s) compilation warning */
  448. UNUSED(hfmac);
  449. /* NOTE : This function should not be modified, when the callback is needed,
  450. the HAL_FMAC_MspDeInit can be implemented in the user file
  451. */
  452. }
  453. #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
  454. /**
  455. * @brief Register a User FMAC Callback.
  456. * @note The User FMAC Callback is to be used instead of the weak predefined callback.
  457. * @note The HAL_FMAC_RegisterCallback() may be called before HAL_FMAC_Init() in HAL_FMAC_STATE_RESET to register
  458. * callbacks for HAL_FMAC_MSPINIT_CB_ID and HAL_FMAC_MSPDEINIT_CB_ID.
  459. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  460. * the configuration information for FMAC module.
  461. * @param CallbackID ID of the callback to be registered.
  462. * This parameter can be one of the following values:
  463. * @arg @ref HAL_FMAC_ERROR_CB_ID Error Callback ID
  464. * @arg @ref HAL_FMAC_HALF_GET_DATA_CB_ID Get Half Data Callback ID
  465. * @arg @ref HAL_FMAC_GET_DATA_CB_ID Get Data Callback ID
  466. * @arg @ref HAL_FMAC_HALF_OUTPUT_DATA_READY_CB_ID Half Output Data Ready Callback ID
  467. * @arg @ref HAL_FMAC_OUTPUT_DATA_READY_CB_ID Output Data Ready Callback ID
  468. * @arg @ref HAL_FMAC_FILTER_CONFIG_CB_ID Filter Configuration Callback ID
  469. * @arg @ref HAL_FMAC_FILTER_PRELOAD_CB_ID Filter Preload Callback ID
  470. * @arg @ref HAL_FMAC_MSPINIT_CB_ID FMAC MspInit ID
  471. * @arg @ref HAL_FMAC_MSPDEINIT_CB_ID FMAC MspDeInit ID
  472. * @param pCallback pointer to the Callback function.
  473. * @retval HAL_StatusTypeDef HAL status
  474. */
  475. HAL_StatusTypeDef HAL_FMAC_RegisterCallback(FMAC_HandleTypeDef *hfmac, HAL_FMAC_CallbackIDTypeDef CallbackID,
  476. pFMAC_CallbackTypeDef pCallback)
  477. {
  478. HAL_StatusTypeDef status = HAL_OK;
  479. /* Check the FMAC handle allocation */
  480. if (hfmac == NULL)
  481. {
  482. return HAL_ERROR;
  483. }
  484. if (pCallback == NULL)
  485. {
  486. /* Update the error code */
  487. hfmac->ErrorCode |= HAL_FMAC_ERROR_INVALID_CALLBACK;
  488. return HAL_ERROR;
  489. }
  490. if (hfmac->State == HAL_FMAC_STATE_READY)
  491. {
  492. switch (CallbackID)
  493. {
  494. case HAL_FMAC_ERROR_CB_ID :
  495. hfmac->ErrorCallback = pCallback;
  496. break;
  497. case HAL_FMAC_HALF_GET_DATA_CB_ID :
  498. hfmac->HalfGetDataCallback = pCallback;
  499. break;
  500. case HAL_FMAC_GET_DATA_CB_ID :
  501. hfmac->GetDataCallback = pCallback;
  502. break;
  503. case HAL_FMAC_HALF_OUTPUT_DATA_READY_CB_ID :
  504. hfmac->HalfOutputDataReadyCallback = pCallback;
  505. break;
  506. case HAL_FMAC_OUTPUT_DATA_READY_CB_ID :
  507. hfmac->OutputDataReadyCallback = pCallback;
  508. break;
  509. case HAL_FMAC_FILTER_CONFIG_CB_ID :
  510. hfmac->FilterConfigCallback = pCallback;
  511. break;
  512. case HAL_FMAC_FILTER_PRELOAD_CB_ID :
  513. hfmac->FilterPreloadCallback = pCallback;
  514. break;
  515. case HAL_FMAC_MSPINIT_CB_ID :
  516. hfmac->MspInitCallback = pCallback;
  517. break;
  518. case HAL_FMAC_MSPDEINIT_CB_ID :
  519. hfmac->MspDeInitCallback = pCallback;
  520. break;
  521. default :
  522. /* Update the error code */
  523. hfmac->ErrorCode |= HAL_FMAC_ERROR_INVALID_CALLBACK;
  524. /* Return error status */
  525. status = HAL_ERROR;
  526. break;
  527. }
  528. }
  529. else if (hfmac->State == HAL_FMAC_STATE_RESET)
  530. {
  531. switch (CallbackID)
  532. {
  533. case HAL_FMAC_MSPINIT_CB_ID :
  534. hfmac->MspInitCallback = pCallback;
  535. break;
  536. case HAL_FMAC_MSPDEINIT_CB_ID :
  537. hfmac->MspDeInitCallback = pCallback;
  538. break;
  539. default :
  540. /* Update the error code */
  541. hfmac->ErrorCode |= HAL_FMAC_ERROR_INVALID_CALLBACK;
  542. /* Return error status */
  543. status = HAL_ERROR;
  544. break;
  545. }
  546. }
  547. else
  548. {
  549. /* Update the error code */
  550. hfmac->ErrorCode |= HAL_FMAC_ERROR_INVALID_CALLBACK;
  551. /* Return error status */
  552. status = HAL_ERROR;
  553. }
  554. return status;
  555. }
  556. /**
  557. * @brief Unregister a FMAC CallBack.
  558. * @note The FMAC callback is redirected to the weak predefined callback.
  559. * @note The HAL_FMAC_UnRegisterCallback() may be called before HAL_FMAC_Init() in HAL_FMAC_STATE_RESET to register
  560. * callbacks for HAL_FMAC_MSPINIT_CB_ID and HAL_FMAC_MSPDEINIT_CB_ID.
  561. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  562. * the configuration information for FMAC module
  563. * @param CallbackID ID of the callback to be unregistered.
  564. * This parameter can be one of the following values:
  565. * @arg @ref HAL_FMAC_ERROR_CB_ID Error Callback ID
  566. * @arg @ref HAL_FMAC_HALF_GET_DATA_CB_ID Get Half Data Callback ID
  567. * @arg @ref HAL_FMAC_GET_DATA_CB_ID Get Data Callback ID
  568. * @arg @ref HAL_FMAC_HALF_OUTPUT_DATA_READY_CB_ID Half Output Data Ready Callback ID
  569. * @arg @ref HAL_FMAC_OUTPUT_DATA_READY_CB_ID Output Data Ready Callback ID
  570. * @arg @ref HAL_FMAC_FILTER_CONFIG_CB_ID Filter Configuration Callback ID
  571. * @arg @ref HAL_FMAC_FILTER_PRELOAD_CB_ID Filter Preload Callback ID
  572. * @arg @ref HAL_FMAC_MSPINIT_CB_ID FMAC MspInit ID
  573. * @arg @ref HAL_FMAC_MSPDEINIT_CB_ID FMAC MspDeInit ID
  574. * @retval HAL_StatusTypeDef HAL status
  575. */
  576. HAL_StatusTypeDef HAL_FMAC_UnRegisterCallback(FMAC_HandleTypeDef *hfmac, HAL_FMAC_CallbackIDTypeDef CallbackID)
  577. {
  578. HAL_StatusTypeDef status = HAL_OK;
  579. /* Check the FMAC handle allocation */
  580. if (hfmac == NULL)
  581. {
  582. return HAL_ERROR;
  583. }
  584. if (hfmac->State == HAL_FMAC_STATE_READY)
  585. {
  586. switch (CallbackID)
  587. {
  588. case HAL_FMAC_ERROR_CB_ID :
  589. hfmac->ErrorCallback = HAL_FMAC_ErrorCallback; /* Legacy weak ErrorCallback */
  590. break;
  591. case HAL_FMAC_HALF_GET_DATA_CB_ID :
  592. hfmac->HalfGetDataCallback = HAL_FMAC_HalfGetDataCallback; /* Legacy weak HalfGetDataCallback */
  593. break;
  594. case HAL_FMAC_GET_DATA_CB_ID :
  595. hfmac->GetDataCallback = HAL_FMAC_GetDataCallback; /* Legacy weak GetDataCallback */
  596. break;
  597. case HAL_FMAC_HALF_OUTPUT_DATA_READY_CB_ID :
  598. hfmac->HalfOutputDataReadyCallback = HAL_FMAC_HalfOutputDataReadyCallback; /* Legacy weak
  599. HalfOutputDataReadyCallback */
  600. break;
  601. case HAL_FMAC_OUTPUT_DATA_READY_CB_ID :
  602. hfmac->OutputDataReadyCallback = HAL_FMAC_OutputDataReadyCallback; /* Legacy weak
  603. OutputDataReadyCallback */
  604. break;
  605. case HAL_FMAC_FILTER_CONFIG_CB_ID :
  606. hfmac->FilterConfigCallback = HAL_FMAC_FilterConfigCallback; /* Legacy weak
  607. FilterConfigCallback */
  608. break;
  609. case HAL_FMAC_FILTER_PRELOAD_CB_ID :
  610. hfmac->FilterPreloadCallback = HAL_FMAC_FilterPreloadCallback; /* Legacy weak FilterPreloadCallba */
  611. break;
  612. case HAL_FMAC_MSPINIT_CB_ID :
  613. hfmac->MspInitCallback = HAL_FMAC_MspInit; /* Legacy weak MspInitCallback */
  614. break;
  615. case HAL_FMAC_MSPDEINIT_CB_ID :
  616. hfmac->MspDeInitCallback = HAL_FMAC_MspDeInit; /* Legacy weak MspDeInitCallback */
  617. break;
  618. default :
  619. /* Update the error code */
  620. hfmac->ErrorCode |= HAL_FMAC_ERROR_INVALID_CALLBACK;
  621. /* Return error status */
  622. status = HAL_ERROR;
  623. break;
  624. }
  625. }
  626. else if (hfmac->State == HAL_FMAC_STATE_RESET)
  627. {
  628. switch (CallbackID)
  629. {
  630. case HAL_FMAC_MSPINIT_CB_ID :
  631. hfmac->MspInitCallback = HAL_FMAC_MspInit;
  632. break;
  633. case HAL_FMAC_MSPDEINIT_CB_ID :
  634. hfmac->MspDeInitCallback = HAL_FMAC_MspDeInit;
  635. break;
  636. default :
  637. /* Update the error code */
  638. hfmac->ErrorCode |= HAL_FMAC_ERROR_INVALID_CALLBACK;
  639. /* Return error status */
  640. status = HAL_ERROR;
  641. break;
  642. }
  643. }
  644. else
  645. {
  646. /* Update the error code */
  647. hfmac->ErrorCode |= HAL_FMAC_ERROR_INVALID_CALLBACK;
  648. /* Return error status */
  649. status = HAL_ERROR;
  650. }
  651. return status;
  652. }
  653. #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
  654. /**
  655. * @}
  656. */
  657. /** @defgroup FMAC_Exported_Functions_Group2 Peripheral Control functions
  658. * @brief Control functions.
  659. *
  660. @verbatim
  661. ==============================================================================
  662. ##### Peripheral Control functions #####
  663. ==============================================================================
  664. [..] This section provides functions allowing to:
  665. (+) Configure the FMAC peripheral: memory area, filter type and parameters,
  666. way to access to the input and output memory area (none, polling, IT, DMA).
  667. (+) Start the FMAC processing (filter).
  668. (+) Handle the input data that will be provided into FMAC.
  669. (+) Handle the output data provided by FMAC.
  670. (+) Stop the FMAC processing (filter).
  671. @endverbatim
  672. * @{
  673. */
  674. /**
  675. * @brief Configure the FMAC filter.
  676. * @note The configuration is done according to the parameters
  677. * specified in the FMAC_FilterConfigTypeDef structure.
  678. * The provided data will be loaded using polling mode.
  679. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  680. * the configuration information for FMAC module.
  681. * @param pConfig pointer to a FMAC_FilterConfigTypeDef structure that
  682. * contains the FMAC configuration information.
  683. * @retval HAL_StatusTypeDef HAL status
  684. */
  685. HAL_StatusTypeDef HAL_FMAC_FilterConfig(FMAC_HandleTypeDef *hfmac, FMAC_FilterConfigTypeDef *pConfig)
  686. {
  687. return (FMAC_FilterConfig(hfmac, pConfig, PRELOAD_ACCESS_POLLING));
  688. }
  689. /**
  690. * @brief Configure the FMAC filter.
  691. * @note The configuration is done according to the parameters
  692. * specified in the FMAC_FilterConfigTypeDef structure.
  693. * The provided data will be loaded using DMA.
  694. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  695. * the configuration information for FMAC module.
  696. * @param pConfig pointer to a FMAC_FilterConfigTypeDef structure that
  697. * contains the FMAC configuration information.
  698. * @retval HAL_StatusTypeDef HAL status
  699. */
  700. HAL_StatusTypeDef HAL_FMAC_FilterConfig_DMA(FMAC_HandleTypeDef *hfmac, FMAC_FilterConfigTypeDef *pConfig)
  701. {
  702. return (FMAC_FilterConfig(hfmac, pConfig, PRELOAD_ACCESS_DMA));
  703. }
  704. /**
  705. * @brief Preload the input (FIR, IIR) and output data (IIR) of the FMAC filter.
  706. * @note The set(s) of data will be used by FMAC as soon as @ref HAL_FMAC_FilterStart is called.
  707. * The provided data will be loaded using polling mode.
  708. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  709. * the configuration information for FMAC module.
  710. * @param pInput Preloading of the first elements of the input buffer (X1).
  711. * If not needed (no data available when starting), it should be set to NULL.
  712. * @param InputSize Size of the input vector.
  713. * As pInput is used for preloading data, it cannot be bigger than the input memory area.
  714. * @param pOutput [IIR] Preloading of the first elements of the output vector (Y).
  715. * If not needed, it should be set to NULL.
  716. * @param OutputSize Size of the output vector.
  717. * As pOutput is used for preloading data, it cannot be bigger than the output memory area.
  718. * @note The input and the output buffers can be filled by calling several times @ref HAL_FMAC_FilterPreload
  719. * (each call filling partly the buffers). In case of overflow (too much data provided through
  720. * all these calls), an error will be returned.
  721. * @retval HAL_StatusTypeDef HAL status
  722. */
  723. HAL_StatusTypeDef HAL_FMAC_FilterPreload(FMAC_HandleTypeDef *hfmac, int16_t *pInput, uint8_t InputSize,
  724. int16_t *pOutput, uint8_t OutputSize)
  725. {
  726. return (FMAC_FilterPreload(hfmac, pInput, InputSize, pOutput, OutputSize, PRELOAD_ACCESS_POLLING));
  727. }
  728. /**
  729. * @brief Preload the input (FIR, IIR) and output data (IIR) of the FMAC filter.
  730. * @note The set(s) of data will be used by FMAC as soon as @ref HAL_FMAC_FilterStart is called.
  731. * The provided data will be loaded using DMA.
  732. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  733. * the configuration information for FMAC module.
  734. * @param pInput Preloading of the first elements of the input buffer (X1).
  735. * If not needed (no data available when starting), it should be set to NULL.
  736. * @param InputSize Size of the input vector.
  737. * As pInput is used for preloading data, it cannot be bigger than the input memory area.
  738. * @param pOutput [IIR] Preloading of the first elements of the output vector (Y).
  739. * If not needed, it should be set to NULL.
  740. * @param OutputSize Size of the output vector.
  741. * As pOutput is used for preloading data, it cannot be bigger than the output memory area.
  742. * @note The input and the output buffers can be filled by calling several times @ref HAL_FMAC_FilterPreload
  743. * (each call filling partly the buffers). In case of overflow (too much data provided through
  744. * all these calls), an error will be returned.
  745. * @retval HAL_StatusTypeDef HAL status
  746. */
  747. HAL_StatusTypeDef HAL_FMAC_FilterPreload_DMA(FMAC_HandleTypeDef *hfmac, int16_t *pInput, uint8_t InputSize,
  748. int16_t *pOutput, uint8_t OutputSize)
  749. {
  750. return (FMAC_FilterPreload(hfmac, pInput, InputSize, pOutput, OutputSize, PRELOAD_ACCESS_DMA));
  751. }
  752. /**
  753. * @brief Start the FMAC processing according to the existing FMAC configuration.
  754. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  755. * the configuration information for FMAC module.
  756. * @param pOutput pointer to buffer where output data of FMAC processing will be stored
  757. * in the next steps.
  758. * If it is set to NULL, the output will not be read and it will be up to
  759. * an external IP to empty the output buffer.
  760. * @param pOutputSize pointer to the size of the output buffer. The number of read data will be written here.
  761. * @retval HAL_StatusTypeDef HAL status
  762. */
  763. HAL_StatusTypeDef HAL_FMAC_FilterStart(FMAC_HandleTypeDef *hfmac, int16_t *pOutput, uint16_t *pOutputSize)
  764. {
  765. uint32_t tmpcr = 0U;
  766. HAL_StatusTypeDef status;
  767. /* Check the START bit state */
  768. if (FMAC_GET_START_BIT(hfmac) != 0U)
  769. {
  770. return HAL_ERROR;
  771. }
  772. /* Check that a valid configuration was done previously */
  773. if (hfmac->FilterParam == 0U)
  774. {
  775. return HAL_ERROR;
  776. }
  777. /* Check handle state is ready */
  778. if (hfmac->State == HAL_FMAC_STATE_READY)
  779. {
  780. /* Change the FMAC state */
  781. hfmac->State = HAL_FMAC_STATE_BUSY;
  782. /* CR: Configure the input access (error interruptions enabled only for IT or DMA) */
  783. if (hfmac->InputAccess == FMAC_BUFFER_ACCESS_DMA)
  784. {
  785. tmpcr |= FMAC_DMA_WEN;
  786. }
  787. else if (hfmac->InputAccess == FMAC_BUFFER_ACCESS_IT)
  788. {
  789. tmpcr |= FMAC_IT_WIEN;
  790. }
  791. else
  792. {
  793. /* nothing to do */
  794. }
  795. /* CR: Configure the output access (error interruptions enabled only for IT or DMA) */
  796. if (hfmac->OutputAccess == FMAC_BUFFER_ACCESS_DMA)
  797. {
  798. tmpcr |= FMAC_DMA_REN;
  799. }
  800. else if (hfmac->OutputAccess == FMAC_BUFFER_ACCESS_IT)
  801. {
  802. tmpcr |= FMAC_IT_RIEN;
  803. }
  804. else
  805. {
  806. /* nothing to do */
  807. }
  808. /* CR: Write the configuration */
  809. MODIFY_REG(hfmac->Instance->CR, \
  810. FMAC_IT_RIEN | FMAC_IT_WIEN | FMAC_DMA_REN | FMAC_CR_DMAWEN, \
  811. tmpcr);
  812. /* Register the new output buffer */
  813. status = FMAC_ConfigFilterOutputBufferUpdateState(hfmac, pOutput, pOutputSize);
  814. if (status == HAL_OK)
  815. {
  816. /* PARAM: Start the filter ( this can generate interrupts before the end of the HAL_FMAC_FilterStart ) */
  817. WRITE_REG(hfmac->Instance->PARAM, (uint32_t)(hfmac->FilterParam));
  818. }
  819. /* Reset the busy flag (do not overwrite the possible write and read flag) */
  820. hfmac->State = HAL_FMAC_STATE_READY;
  821. }
  822. else
  823. {
  824. status = HAL_ERROR;
  825. }
  826. return status;
  827. }
  828. /**
  829. * @brief Provide a new input buffer that will be loaded into the FMAC input memory area.
  830. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  831. * the configuration information for FMAC module.
  832. * @param pInput New input vector (additional input data).
  833. * @param pInputSize Size of the input vector (if all the data can't be
  834. * written, it will be updated with the number of data read from FMAC).
  835. * @retval HAL_StatusTypeDef HAL status
  836. */
  837. HAL_StatusTypeDef HAL_FMAC_AppendFilterData(FMAC_HandleTypeDef *hfmac, int16_t *pInput, uint16_t *pInputSize)
  838. {
  839. HAL_StatusTypeDef status;
  840. /* Check the function parameters */
  841. if ((pInput == NULL) || (pInputSize == NULL))
  842. {
  843. return HAL_ERROR;
  844. }
  845. if (*pInputSize == 0U)
  846. {
  847. return HAL_ERROR;
  848. }
  849. /* Check the START bit state */
  850. if (FMAC_GET_START_BIT(hfmac) == 0U)
  851. {
  852. return HAL_ERROR;
  853. }
  854. /* Check the FMAC configuration */
  855. if (hfmac->InputAccess == FMAC_BUFFER_ACCESS_NONE)
  856. {
  857. return HAL_ERROR;
  858. }
  859. /* Check whether the previous input vector has been handled */
  860. if ((hfmac->pInputSize != NULL) && (hfmac->InputCurrentSize < * (hfmac->pInputSize)))
  861. {
  862. return HAL_ERROR;
  863. }
  864. /* Check that FMAC was initialized and that no writing is already ongoing */
  865. if (hfmac->WrState == HAL_FMAC_STATE_READY)
  866. {
  867. /* Register the new input buffer */
  868. status = FMAC_AppendFilterDataUpdateState(hfmac, pInput, pInputSize);
  869. }
  870. else
  871. {
  872. status = HAL_ERROR;
  873. }
  874. return status;
  875. }
  876. /**
  877. * @brief Provide a new output buffer to be filled with the data computed by FMAC unit.
  878. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  879. * the configuration information for FMAC module.
  880. * @param pOutput New output vector.
  881. * @param pOutputSize Size of the output vector (if the vector can't
  882. * be entirely filled, pOutputSize will be updated with the number
  883. * of data read from FMAC).
  884. * @retval HAL_StatusTypeDef HAL status
  885. */
  886. HAL_StatusTypeDef HAL_FMAC_ConfigFilterOutputBuffer(FMAC_HandleTypeDef *hfmac, int16_t *pOutput, uint16_t *pOutputSize)
  887. {
  888. HAL_StatusTypeDef status;
  889. /* Check the function parameters */
  890. if ((pOutput == NULL) || (pOutputSize == NULL))
  891. {
  892. return HAL_ERROR;
  893. }
  894. if (*pOutputSize == 0U)
  895. {
  896. return HAL_ERROR;
  897. }
  898. /* Check the START bit state */
  899. if (FMAC_GET_START_BIT(hfmac) == 0U)
  900. {
  901. return HAL_ERROR;
  902. }
  903. /* Check the FMAC configuration */
  904. if (hfmac->OutputAccess == FMAC_BUFFER_ACCESS_NONE)
  905. {
  906. return HAL_ERROR;
  907. }
  908. /* Check whether the previous output vector has been handled */
  909. if ((hfmac->pOutputSize != NULL) && (hfmac->OutputCurrentSize < * (hfmac->pOutputSize)))
  910. {
  911. return HAL_ERROR;
  912. }
  913. /* Check that FMAC was initialized and that not reading is already ongoing */
  914. if (hfmac->RdState == HAL_FMAC_STATE_READY)
  915. {
  916. /* Register the new output buffer */
  917. status = FMAC_ConfigFilterOutputBufferUpdateState(hfmac, pOutput, pOutputSize);
  918. }
  919. else
  920. {
  921. status = HAL_ERROR;
  922. }
  923. return status;
  924. }
  925. /**
  926. * @brief Handle the input and/or output data in polling mode
  927. * @note This function writes the previously provided user's input data and
  928. * fills the previously provided user's output buffer,
  929. * according to the existing FMAC configuration (polling mode only).
  930. * The function returns when the input data has been handled or
  931. * when the output data is filled. The possible unused data isn't
  932. * kept. It will be up to the user to handle it. The previously
  933. * provided pInputSize and pOutputSize will be used to indicate to the
  934. * size of the read/written data to the user.
  935. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  936. * the configuration information for FMAC module.
  937. * @param Timeout timeout value.
  938. * @retval HAL_StatusTypeDef HAL status
  939. */
  940. HAL_StatusTypeDef HAL_FMAC_PollFilterData(FMAC_HandleTypeDef *hfmac, uint32_t Timeout)
  941. {
  942. uint32_t tickstart;
  943. uint8_t inpolling;
  944. uint8_t inpollingover = POLLING_NOT_STOPPED;
  945. uint8_t outpolling;
  946. uint8_t outpollingover = POLLING_NOT_STOPPED;
  947. HAL_StatusTypeDef status;
  948. /* Check the START bit state */
  949. if (FMAC_GET_START_BIT(hfmac) == 0U)
  950. {
  951. return HAL_ERROR;
  952. }
  953. /* Check the configuration */
  954. /* Get the input and output mode (if no buffer was previously provided, nothing will be read/written) */
  955. if ((hfmac->InputAccess == FMAC_BUFFER_ACCESS_POLLING) && (hfmac->pInput != NULL))
  956. {
  957. inpolling = POLLING_ENABLED;
  958. }
  959. else
  960. {
  961. inpolling = POLLING_DISABLED;
  962. }
  963. if ((hfmac->OutputAccess == FMAC_BUFFER_ACCESS_POLLING) && (hfmac->pOutput != NULL))
  964. {
  965. outpolling = POLLING_ENABLED;
  966. }
  967. else
  968. {
  969. outpolling = POLLING_DISABLED;
  970. }
  971. /* Check the configuration */
  972. if ((inpolling == POLLING_DISABLED) && (outpolling == POLLING_DISABLED))
  973. {
  974. return HAL_ERROR;
  975. }
  976. /* Check handle state is ready */
  977. if (hfmac->State == HAL_FMAC_STATE_READY)
  978. {
  979. /* Change the FMAC state */
  980. hfmac->State = HAL_FMAC_STATE_BUSY;
  981. /* Get tick */
  982. tickstart = HAL_GetTick();
  983. /* Loop on reading and writing until timeout */
  984. while ((HAL_GetTick() - tickstart) < Timeout)
  985. {
  986. /* X1: Check the mode: polling or none */
  987. if (inpolling != POLLING_DISABLED)
  988. {
  989. FMAC_WriteDataIncrementPtr(hfmac, MAX_FILTER_DATA_SIZE_TO_HANDLE);
  990. if (hfmac->InputCurrentSize == *(hfmac->pInputSize))
  991. {
  992. inpollingover = POLLING_STOPPED;
  993. }
  994. }
  995. /* Y: Check the mode: polling or none */
  996. if (outpolling != POLLING_DISABLED)
  997. {
  998. FMAC_ReadDataIncrementPtr(hfmac, MAX_FILTER_DATA_SIZE_TO_HANDLE);
  999. if (hfmac->OutputCurrentSize == *(hfmac->pOutputSize))
  1000. {
  1001. outpollingover = POLLING_STOPPED;
  1002. }
  1003. }
  1004. /* Exit if there isn't data to handle anymore on one side or another */
  1005. if ((inpollingover != POLLING_NOT_STOPPED) || (outpollingover != POLLING_NOT_STOPPED))
  1006. {
  1007. break;
  1008. }
  1009. }
  1010. /* Change the FMAC state; update the input and output sizes; reset the indexes */
  1011. if (inpolling != POLLING_DISABLED)
  1012. {
  1013. (*(hfmac->pInputSize)) = hfmac->InputCurrentSize;
  1014. FMAC_ResetInputStateAndDataPointers(hfmac);
  1015. }
  1016. if (outpolling != POLLING_DISABLED)
  1017. {
  1018. (*(hfmac->pOutputSize)) = hfmac->OutputCurrentSize;
  1019. FMAC_ResetOutputStateAndDataPointers(hfmac);
  1020. }
  1021. /* Reset the busy flag (do not overwrite the possible write and read flag) */
  1022. hfmac->State = HAL_FMAC_STATE_READY;
  1023. if ((HAL_GetTick() - tickstart) >= Timeout)
  1024. {
  1025. hfmac->ErrorCode |= HAL_FMAC_ERROR_TIMEOUT;
  1026. status = HAL_ERROR;
  1027. }
  1028. else
  1029. {
  1030. status = HAL_OK;
  1031. }
  1032. }
  1033. else
  1034. {
  1035. status = HAL_ERROR;
  1036. }
  1037. return status;
  1038. }
  1039. /**
  1040. * @brief Stop the FMAC processing.
  1041. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  1042. * the configuration information for FMAC module.
  1043. * @retval HAL_StatusTypeDef HAL status
  1044. */
  1045. HAL_StatusTypeDef HAL_FMAC_FilterStop(FMAC_HandleTypeDef *hfmac)
  1046. {
  1047. HAL_StatusTypeDef status = HAL_OK;
  1048. /* Check handle state is ready */
  1049. if (hfmac->State == HAL_FMAC_STATE_READY)
  1050. {
  1051. /* Change the FMAC state */
  1052. hfmac->State = HAL_FMAC_STATE_BUSY;
  1053. /* Set the START bit to 0 (stop the previously configured filter) */
  1054. CLEAR_BIT(hfmac->Instance->PARAM, FMAC_PARAM_START);
  1055. /* Disable the interrupts in order to avoid crossing cases */
  1056. CLEAR_BIT(hfmac->Instance->CR, FMAC_DMA_REN | FMAC_DMA_WEN | FMAC_IT_RIEN | FMAC_IT_WIEN);
  1057. /* In case of IT, update the sizes */
  1058. if ((hfmac->InputAccess == FMAC_BUFFER_ACCESS_IT) && (hfmac->pInput != NULL))
  1059. {
  1060. (*(hfmac->pInputSize)) = hfmac->InputCurrentSize;
  1061. }
  1062. if ((hfmac->OutputAccess == FMAC_BUFFER_ACCESS_IT) && (hfmac->pOutput != NULL))
  1063. {
  1064. (*(hfmac->pOutputSize)) = hfmac->OutputCurrentSize;
  1065. }
  1066. if (hfmac->InputAccess == FMAC_BUFFER_ACCESS_DMA)
  1067. {
  1068. /* Disable the DMA stream managing FMAC input data */
  1069. status = HAL_DMA_Abort_IT(hfmac->hdmaIn);
  1070. }
  1071. if ((hfmac->OutputAccess == FMAC_BUFFER_ACCESS_DMA) && (status == HAL_OK))
  1072. {
  1073. /* Disable the DMA stream managing FMAC output data */
  1074. status = HAL_DMA_Abort_IT(hfmac->hdmaOut);
  1075. }
  1076. /* Reset FMAC unit (internal pointers) */
  1077. if (FMAC_Reset(hfmac) == HAL_ERROR)
  1078. {
  1079. /* Update FMAC error code and FMAC peripheral state */
  1080. hfmac->ErrorCode = HAL_FMAC_ERROR_RESET;
  1081. hfmac->State = HAL_FMAC_STATE_TIMEOUT;
  1082. status = HAL_ERROR;
  1083. }
  1084. else
  1085. {
  1086. /* Reset the data pointers */
  1087. FMAC_ResetDataPointers(hfmac);
  1088. }
  1089. /* Reset the busy flag */
  1090. hfmac->State = HAL_FMAC_STATE_READY;
  1091. }
  1092. else
  1093. {
  1094. status = HAL_ERROR;
  1095. }
  1096. return status;
  1097. }
  1098. /**
  1099. * @}
  1100. */
  1101. /** @defgroup FMAC_Exported_Functions_Group3 Callback functions
  1102. * @brief Callback functions.
  1103. *
  1104. @verbatim
  1105. ==============================================================================
  1106. ##### Callback functions #####
  1107. ==============================================================================
  1108. [..] This section provides Interruption and DMA callback functions:
  1109. (+) DMA or Interrupt: the user's input data is half written (DMA only)
  1110. or completely written.
  1111. (+) DMA or Interrupt: the user's output buffer is half filled (DMA only)
  1112. or completely filled.
  1113. (+) DMA or Interrupt: error handling.
  1114. @endverbatim
  1115. * @{
  1116. */
  1117. /**
  1118. * @brief FMAC error callback.
  1119. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  1120. * the configuration information for FMAC module.
  1121. * @retval None
  1122. */
  1123. __weak void HAL_FMAC_ErrorCallback(FMAC_HandleTypeDef *hfmac)
  1124. {
  1125. /* Prevent unused argument(s) compilation warning */
  1126. UNUSED(hfmac);
  1127. /* NOTE : This function should not be modified; when the callback is needed,
  1128. the HAL_FMAC_ErrorCallback can be implemented in the user file.
  1129. */
  1130. }
  1131. /**
  1132. * @brief FMAC get half data callback.
  1133. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  1134. * the configuration information for FMAC module.
  1135. * @retval None
  1136. */
  1137. __weak void HAL_FMAC_HalfGetDataCallback(FMAC_HandleTypeDef *hfmac)
  1138. {
  1139. /* Prevent unused argument(s) compilation warning */
  1140. UNUSED(hfmac);
  1141. /* NOTE : This function should not be modified; when the callback is needed,
  1142. the HAL_FMAC_HalfGetDataCallback can be implemented in the user file.
  1143. */
  1144. }
  1145. /**
  1146. * @brief FMAC get data callback.
  1147. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  1148. * the configuration information for FMAC module.
  1149. * @retval None
  1150. */
  1151. __weak void HAL_FMAC_GetDataCallback(FMAC_HandleTypeDef *hfmac)
  1152. {
  1153. /* Prevent unused argument(s) compilation warning */
  1154. UNUSED(hfmac);
  1155. /* NOTE : This function should not be modified; when the callback is needed,
  1156. the HAL_FMAC_GetDataCallback can be implemented in the user file.
  1157. */
  1158. }
  1159. /**
  1160. * @brief FMAC half output data ready callback.
  1161. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  1162. * the configuration information for FMAC module.
  1163. * @retval None
  1164. */
  1165. __weak void HAL_FMAC_HalfOutputDataReadyCallback(FMAC_HandleTypeDef *hfmac)
  1166. {
  1167. /* Prevent unused argument(s) compilation warning */
  1168. UNUSED(hfmac);
  1169. /* NOTE : This function should not be modified; when the callback is needed,
  1170. the HAL_FMAC_HalfOutputDataReadyCallback can be implemented in the user file.
  1171. */
  1172. }
  1173. /**
  1174. * @brief FMAC output data ready callback.
  1175. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  1176. * the configuration information for FMAC module.
  1177. * @retval None
  1178. */
  1179. __weak void HAL_FMAC_OutputDataReadyCallback(FMAC_HandleTypeDef *hfmac)
  1180. {
  1181. /* Prevent unused argument(s) compilation warning */
  1182. UNUSED(hfmac);
  1183. /* NOTE : This function should not be modified; when the callback is needed,
  1184. the HAL_FMAC_OutputDataReadyCallback can be implemented in the user file.
  1185. */
  1186. }
  1187. /**
  1188. * @brief FMAC filter configuration callback.
  1189. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  1190. * the configuration information for FMAC module.
  1191. * @retval None
  1192. */
  1193. __weak void HAL_FMAC_FilterConfigCallback(FMAC_HandleTypeDef *hfmac)
  1194. {
  1195. /* Prevent unused argument(s) compilation warning */
  1196. UNUSED(hfmac);
  1197. /* NOTE : This function should not be modified; when the callback is needed,
  1198. the HAL_FMAC_FilterConfigCallback can be implemented in the user file.
  1199. */
  1200. }
  1201. /**
  1202. * @brief FMAC filter preload callback.
  1203. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  1204. * the configuration information for FMAC module.
  1205. * @retval None
  1206. */
  1207. __weak void HAL_FMAC_FilterPreloadCallback(FMAC_HandleTypeDef *hfmac)
  1208. {
  1209. /* Prevent unused argument(s) compilation warning */
  1210. UNUSED(hfmac);
  1211. /* NOTE : This function should not be modified; when the callback is needed,
  1212. the HAL_FMAC_FilterPreloadCallback can be implemented in the user file.
  1213. */
  1214. }
  1215. /**
  1216. * @}
  1217. */
  1218. /** @defgroup FMAC_Exported_Functions_Group4 IRQ handler management
  1219. * @brief IRQ handler.
  1220. *
  1221. @verbatim
  1222. ==============================================================================
  1223. ##### IRQ handler management #####
  1224. ==============================================================================
  1225. [..] This section provides IRQ handler function.
  1226. @endverbatim
  1227. * @{
  1228. */
  1229. /**
  1230. * @brief Handle FMAC interrupt request.
  1231. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  1232. * the configuration information for FMAC module.
  1233. * @retval None
  1234. */
  1235. void HAL_FMAC_IRQHandler(FMAC_HandleTypeDef *hfmac)
  1236. {
  1237. uint32_t itsource;
  1238. /* Check if the read interrupt is enabled and if Y buffer empty flag isn't set */
  1239. itsource = __HAL_FMAC_GET_IT_SOURCE(hfmac, FMAC_IT_RIEN);
  1240. if ((__HAL_FMAC_GET_FLAG(hfmac, FMAC_FLAG_YEMPTY) == 0U) && (itsource != 0U))
  1241. {
  1242. /* Read some data if possible (Y size is used as a pseudo timeout in order
  1243. to not get stuck too long under IT if FMAC keeps on processing input
  1244. data reloaded via DMA for instance). */
  1245. if (hfmac->pOutput != NULL)
  1246. {
  1247. FMAC_ReadDataIncrementPtr(hfmac, (uint16_t)FMAC_GET_Y_SIZE(hfmac));
  1248. }
  1249. /* Indicate that data is ready to be read */
  1250. if ((hfmac->pOutput == NULL) || (hfmac->OutputCurrentSize == *(hfmac->pOutputSize)))
  1251. {
  1252. /* Reset the pointers to indicate new data will be needed */
  1253. FMAC_ResetOutputStateAndDataPointers(hfmac);
  1254. /* Call the output data ready callback */
  1255. #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
  1256. hfmac->OutputDataReadyCallback(hfmac);
  1257. #else
  1258. HAL_FMAC_OutputDataReadyCallback(hfmac);
  1259. #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
  1260. }
  1261. }
  1262. /* Check if the write interrupt is enabled and if X1 buffer full flag isn't set */
  1263. itsource = __HAL_FMAC_GET_IT_SOURCE(hfmac, FMAC_IT_WIEN);
  1264. if ((__HAL_FMAC_GET_FLAG(hfmac, FMAC_FLAG_X1FULL) == 0U) && (itsource != 0U))
  1265. {
  1266. /* Write some data if possible (X1 size is used as a pseudo timeout in order
  1267. to not get stuck too long under IT if FMAC keep on processing input
  1268. data whereas its output emptied via DMA for instance). */
  1269. if (hfmac->pInput != NULL)
  1270. {
  1271. FMAC_WriteDataIncrementPtr(hfmac, (uint16_t)FMAC_GET_X1_SIZE(hfmac));
  1272. }
  1273. /* Indicate that new data will be needed */
  1274. if ((hfmac->pInput == NULL) || (hfmac->InputCurrentSize == *(hfmac->pInputSize)))
  1275. {
  1276. /* Reset the pointers to indicate new data will be needed */
  1277. FMAC_ResetInputStateAndDataPointers(hfmac);
  1278. /* Call the get data callback */
  1279. #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
  1280. hfmac->GetDataCallback(hfmac);
  1281. #else
  1282. HAL_FMAC_GetDataCallback(hfmac);
  1283. #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
  1284. }
  1285. }
  1286. /* Check if the overflow error interrupt is enabled and if overflow error flag is raised */
  1287. itsource = __HAL_FMAC_GET_IT_SOURCE(hfmac, FMAC_IT_OVFLIEN);
  1288. if ((__HAL_FMAC_GET_FLAG(hfmac, FMAC_FLAG_OVFL) != 0U) && (itsource != 0U))
  1289. {
  1290. hfmac->ErrorCode |= HAL_FMAC_ERROR_OVFL;
  1291. }
  1292. /* Check if the underflow error interrupt is enabled and if underflow error flag is raised */
  1293. itsource = __HAL_FMAC_GET_IT_SOURCE(hfmac, FMAC_IT_UNFLIEN);
  1294. if ((__HAL_FMAC_GET_FLAG(hfmac, FMAC_FLAG_UNFL) != 0U) && (itsource != 0U))
  1295. {
  1296. hfmac->ErrorCode |= HAL_FMAC_ERROR_UNFL;
  1297. }
  1298. /* Check if the saturation error interrupt is enabled and if saturation error flag is raised */
  1299. itsource = __HAL_FMAC_GET_IT_SOURCE(hfmac, FMAC_IT_SATIEN);
  1300. if ((__HAL_FMAC_GET_FLAG(hfmac, FMAC_FLAG_SAT) != 0U) && (itsource != 0U))
  1301. {
  1302. hfmac->ErrorCode |= HAL_FMAC_ERROR_SAT;
  1303. }
  1304. /* Call the error callback if an error occurred */
  1305. if (hfmac->ErrorCode != HAL_FMAC_ERROR_NONE)
  1306. {
  1307. /* Call the error callback */
  1308. #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
  1309. hfmac->ErrorCallback(hfmac);
  1310. #else
  1311. HAL_FMAC_ErrorCallback(hfmac);
  1312. #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
  1313. }
  1314. }
  1315. /**
  1316. * @}
  1317. */
  1318. /** @defgroup FMAC_Exported_Functions_Group5 Peripheral State and Error functions
  1319. * @brief Peripheral State and Error functions.
  1320. *
  1321. @verbatim
  1322. ==============================================================================
  1323. ##### Peripheral State and Error functions #####
  1324. ==============================================================================
  1325. [..] This subsection provides functions allowing to
  1326. (+) Check the FMAC state
  1327. (+) Get error code
  1328. @endverbatim
  1329. * @{
  1330. */
  1331. /**
  1332. * @brief Return the FMAC state.
  1333. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  1334. * the configuration information for FMAC module.
  1335. * @retval HAL_FMAC_StateTypeDef FMAC state
  1336. */
  1337. HAL_FMAC_StateTypeDef HAL_FMAC_GetState(const FMAC_HandleTypeDef *hfmac)
  1338. {
  1339. /* Return FMAC state */
  1340. return hfmac->State;
  1341. }
  1342. /**
  1343. * @brief Return the FMAC peripheral error.
  1344. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  1345. * the configuration information for FMAC module.
  1346. * @note The returned error is a bit-map combination of possible errors.
  1347. * @retval uint32_t Error bit-map based on @ref FMAC_Error_Code
  1348. */
  1349. uint32_t HAL_FMAC_GetError(const FMAC_HandleTypeDef *hfmac)
  1350. {
  1351. /* Return FMAC error code */
  1352. return hfmac->ErrorCode;
  1353. }
  1354. /**
  1355. * @}
  1356. */
  1357. /**
  1358. * @}
  1359. */
  1360. /** @defgroup FMAC_Private_Functions FMAC Private Functions
  1361. * @{
  1362. */
  1363. /**
  1364. ==============================================================================
  1365. ##### FMAC Private Functions #####
  1366. ==============================================================================
  1367. */
  1368. /**
  1369. * @brief Perform a reset of the FMAC unit.
  1370. * @param hfmac FMAC handle.
  1371. * @retval HAL_StatusTypeDef HAL status
  1372. */
  1373. static HAL_StatusTypeDef FMAC_Reset(FMAC_HandleTypeDef *hfmac)
  1374. {
  1375. uint32_t tickstart;
  1376. /* Init tickstart for timeout management*/
  1377. tickstart = HAL_GetTick();
  1378. /* Perform the reset */
  1379. SET_BIT(hfmac->Instance->CR, FMAC_CR_RESET);
  1380. /* Wait until flag is reset */
  1381. while (READ_BIT(hfmac->Instance->CR, FMAC_CR_RESET) != 0U)
  1382. {
  1383. if ((HAL_GetTick() - tickstart) > HAL_FMAC_RESET_TIMEOUT_VALUE)
  1384. {
  1385. hfmac->ErrorCode |= HAL_FMAC_ERROR_TIMEOUT;
  1386. return HAL_ERROR;
  1387. }
  1388. }
  1389. hfmac->ErrorCode = HAL_FMAC_ERROR_NONE;
  1390. return HAL_OK;
  1391. }
  1392. /**
  1393. * @brief Reset the data pointers of the FMAC unit.
  1394. * @param hfmac FMAC handle.
  1395. * @retval None
  1396. */
  1397. static void FMAC_ResetDataPointers(FMAC_HandleTypeDef *hfmac)
  1398. {
  1399. FMAC_ResetInputStateAndDataPointers(hfmac);
  1400. FMAC_ResetOutputStateAndDataPointers(hfmac);
  1401. }
  1402. /**
  1403. * @brief Reset the input data pointers of the FMAC unit.
  1404. * @param hfmac FMAC handle.
  1405. * @retval None
  1406. */
  1407. static void FMAC_ResetInputStateAndDataPointers(FMAC_HandleTypeDef *hfmac)
  1408. {
  1409. hfmac->pInput = NULL;
  1410. hfmac->pInputSize = NULL;
  1411. hfmac->InputCurrentSize = 0U;
  1412. hfmac->WrState = HAL_FMAC_STATE_READY;
  1413. }
  1414. /**
  1415. * @brief Reset the output data pointers of the FMAC unit.
  1416. * @param hfmac FMAC handle.
  1417. * @retval None
  1418. */
  1419. static void FMAC_ResetOutputStateAndDataPointers(FMAC_HandleTypeDef *hfmac)
  1420. {
  1421. hfmac->pOutput = NULL;
  1422. hfmac->pOutputSize = NULL;
  1423. hfmac->OutputCurrentSize = 0U;
  1424. hfmac->RdState = HAL_FMAC_STATE_READY;
  1425. }
  1426. /**
  1427. * @brief Configure the FMAC filter.
  1428. * @note The configuration is done according to the parameters
  1429. * specified in the FMAC_FilterConfigTypeDef structure.
  1430. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  1431. * the configuration information for FMAC module.
  1432. * @param pConfig pointer to a FMAC_FilterConfigTypeDef structure that
  1433. * contains the FMAC configuration information.
  1434. * @param PreloadAccess access mode used for the preload (polling or DMA).
  1435. * @retval HAL_StatusTypeDef HAL status
  1436. */
  1437. static HAL_StatusTypeDef FMAC_FilterConfig(FMAC_HandleTypeDef *hfmac, FMAC_FilterConfigTypeDef *pConfig,
  1438. uint8_t PreloadAccess)
  1439. {
  1440. uint32_t tickstart;
  1441. uint32_t tmpcr;
  1442. #if defined(USE_FULL_ASSERT)
  1443. uint32_t x2size;
  1444. #endif /* USE_FULL_ASSERT */
  1445. /* Check the parameters */
  1446. assert_param(IS_FMAC_THRESHOLD(pConfig->InputThreshold));
  1447. assert_param(IS_FMAC_THRESHOLD(pConfig->OutputThreshold));
  1448. assert_param(IS_FMAC_BUFFER_ACCESS(pConfig->InputAccess));
  1449. assert_param(IS_FMAC_BUFFER_ACCESS(pConfig->OutputAccess));
  1450. assert_param(IS_FMAC_CLIP_STATE(pConfig->Clip));
  1451. assert_param(IS_FMAC_FILTER_FUNCTION(pConfig->Filter));
  1452. assert_param(IS_FMAC_PARAM_P(pConfig->Filter, pConfig->P));
  1453. assert_param(IS_FMAC_PARAM_Q(pConfig->Filter, pConfig->Q));
  1454. assert_param(IS_FMAC_PARAM_R(pConfig->Filter, pConfig->R));
  1455. /* Check the START bit state */
  1456. if (FMAC_GET_START_BIT(hfmac) != 0U)
  1457. {
  1458. return HAL_ERROR;
  1459. }
  1460. /* Check handle state is ready */
  1461. if (hfmac->State != HAL_FMAC_STATE_READY)
  1462. {
  1463. return HAL_ERROR;
  1464. }
  1465. /* Change the FMAC state */
  1466. hfmac->State = HAL_FMAC_STATE_BUSY;
  1467. /* Get tick */
  1468. tickstart = HAL_GetTick();
  1469. /* Indicate that there is no valid configuration done */
  1470. hfmac->FilterParam = 0U;
  1471. /* FMAC_X1BUFCFG: Configure the input buffer within the internal memory if required */
  1472. if (pConfig->InputBufferSize != 0U)
  1473. {
  1474. MODIFY_REG(hfmac->Instance->X1BUFCFG, \
  1475. (FMAC_X1BUFCFG_X1_BASE | FMAC_X1BUFCFG_X1_BUF_SIZE), \
  1476. (((((uint32_t)(pConfig->InputBaseAddress)) << FMAC_X1BUFCFG_X1_BASE_Pos) & FMAC_X1BUFCFG_X1_BASE) | \
  1477. ((((uint32_t)(pConfig->InputBufferSize)) << FMAC_X1BUFCFG_X1_BUF_SIZE_Pos) & \
  1478. FMAC_X1BUFCFG_X1_BUF_SIZE)));
  1479. }
  1480. /* FMAC_X1BUFCFG: Configure the input threshold if valid when compared to the configured X1 size */
  1481. if (pConfig->InputThreshold != FMAC_THRESHOLD_NO_VALUE)
  1482. {
  1483. /* Check the parameter */
  1484. assert_param(IS_FMAC_THRESHOLD_APPLICABLE(FMAC_GET_X1_SIZE(hfmac), pConfig->InputThreshold, pConfig->InputAccess));
  1485. MODIFY_REG(hfmac->Instance->X1BUFCFG, \
  1486. FMAC_X1BUFCFG_FULL_WM, \
  1487. ((pConfig->InputThreshold) & FMAC_X1BUFCFG_FULL_WM));
  1488. }
  1489. /* FMAC_X2BUFCFG: Configure the coefficient buffer within the internal memory */
  1490. if (pConfig->CoeffBufferSize != 0U)
  1491. {
  1492. MODIFY_REG(hfmac->Instance->X2BUFCFG, \
  1493. (FMAC_X2BUFCFG_X2_BASE | FMAC_X2BUFCFG_X2_BUF_SIZE), \
  1494. (((((uint32_t)(pConfig->CoeffBaseAddress)) << FMAC_X2BUFCFG_X2_BASE_Pos) & FMAC_X2BUFCFG_X2_BASE) | \
  1495. ((((uint32_t)(pConfig->CoeffBufferSize)) << FMAC_X2BUFCFG_X2_BUF_SIZE_Pos) &\
  1496. FMAC_X2BUFCFG_X2_BUF_SIZE)));
  1497. }
  1498. /* FMAC_YBUFCFG: Configure the output buffer within the internal memory if required */
  1499. if (pConfig->OutputBufferSize != 0U)
  1500. {
  1501. MODIFY_REG(hfmac->Instance->YBUFCFG, \
  1502. (FMAC_YBUFCFG_Y_BASE | FMAC_YBUFCFG_Y_BUF_SIZE), \
  1503. (((((uint32_t)(pConfig->OutputBaseAddress)) << FMAC_YBUFCFG_Y_BASE_Pos) & FMAC_YBUFCFG_Y_BASE) | \
  1504. ((((uint32_t)(pConfig->OutputBufferSize)) << FMAC_YBUFCFG_Y_BUF_SIZE_Pos) & FMAC_YBUFCFG_Y_BUF_SIZE)));
  1505. }
  1506. /* FMAC_YBUFCFG: Configure the output threshold if valid when compared to the configured Y size */
  1507. if (pConfig->OutputThreshold != FMAC_THRESHOLD_NO_VALUE)
  1508. {
  1509. /* Check the parameter */
  1510. assert_param(IS_FMAC_THRESHOLD_APPLICABLE(FMAC_GET_Y_SIZE(hfmac), pConfig->OutputThreshold, pConfig->OutputAccess));
  1511. MODIFY_REG(hfmac->Instance->YBUFCFG, \
  1512. FMAC_YBUFCFG_EMPTY_WM, \
  1513. ((pConfig->OutputThreshold) & FMAC_YBUFCFG_EMPTY_WM));
  1514. }
  1515. /* FMAC_CR: Configure the clip feature */
  1516. tmpcr = pConfig->Clip & FMAC_CR_CLIPEN;
  1517. /* FMAC_CR: If IT or DMA will be used, enable error interrupts.
  1518. * Being more a debugging feature, FMAC_CR_SATIEN isn't enabled by default. */
  1519. if ((pConfig->InputAccess == FMAC_BUFFER_ACCESS_DMA) || (pConfig->InputAccess == FMAC_BUFFER_ACCESS_IT) ||
  1520. (pConfig->OutputAccess == FMAC_BUFFER_ACCESS_DMA) || (pConfig->OutputAccess == FMAC_BUFFER_ACCESS_IT))
  1521. {
  1522. tmpcr |= FMAC_IT_UNFLIEN | FMAC_IT_OVFLIEN;
  1523. }
  1524. /* FMAC_CR: write the value */
  1525. WRITE_REG(hfmac->Instance->CR, tmpcr);
  1526. /* Save the input/output accesses in order to configure RIEN, WIEN, DMAREN and DMAWEN during filter start */
  1527. hfmac->InputAccess = pConfig->InputAccess;
  1528. hfmac->OutputAccess = pConfig->OutputAccess;
  1529. /* Check whether the configured X2 is big enough for the filter */
  1530. #if defined(USE_FULL_ASSERT)
  1531. x2size = FMAC_GET_X2_SIZE(hfmac);
  1532. #endif /* USE_FULL_ASSERT */
  1533. assert_param(((pConfig->Filter == FMAC_FUNC_CONVO_FIR) && (x2size >= pConfig->P)) || \
  1534. ((pConfig->Filter == FMAC_FUNC_IIR_DIRECT_FORM_1) && \
  1535. (x2size >= ((uint32_t)pConfig->P + (uint32_t)pConfig->Q))));
  1536. /* Build the PARAM value that will be used when starting the filter */
  1537. hfmac->FilterParam = (FMAC_PARAM_START | pConfig->Filter | \
  1538. ((((uint32_t)(pConfig->P)) << FMAC_PARAM_P_Pos) & FMAC_PARAM_P) | \
  1539. ((((uint32_t)(pConfig->Q)) << FMAC_PARAM_Q_Pos) & FMAC_PARAM_Q) | \
  1540. ((((uint32_t)(pConfig->R)) << FMAC_PARAM_R_Pos) & FMAC_PARAM_R));
  1541. /* Initialize the coefficient buffer if required (pCoeffA for FIR only) */
  1542. if ((pConfig->pCoeffB != NULL) && (pConfig->CoeffBSize != 0U))
  1543. {
  1544. /* FIR/IIR: The provided coefficients should match X2 size */
  1545. assert_param(((uint32_t)pConfig->CoeffASize + (uint32_t)pConfig->CoeffBSize) <= x2size);
  1546. /* FIR/IIR: The size of pCoeffB should match the parameter P */
  1547. assert_param(pConfig->CoeffBSize >= pConfig->P);
  1548. /* pCoeffA should be provided for IIR but not for FIR */
  1549. /* IIR : if pCoeffB is provided, pCoeffA should also be there */
  1550. /* IIR: The size of pCoeffA should match the parameter Q */
  1551. assert_param(((pConfig->Filter == FMAC_FUNC_CONVO_FIR) &&
  1552. (pConfig->pCoeffA == NULL) && (pConfig->CoeffASize == 0U)) ||
  1553. ((pConfig->Filter == FMAC_FUNC_IIR_DIRECT_FORM_1) &&
  1554. (pConfig->pCoeffA != NULL) && (pConfig->CoeffASize != 0U) &&
  1555. (pConfig->CoeffASize >= pConfig->Q)));
  1556. /* Write number of values to be loaded, the data load function and start the operation */
  1557. WRITE_REG(hfmac->Instance->PARAM, \
  1558. (((uint32_t)(pConfig->CoeffBSize) << FMAC_PARAM_P_Pos) | \
  1559. ((uint32_t)(pConfig->CoeffASize) << FMAC_PARAM_Q_Pos) | \
  1560. FMAC_FUNC_LOAD_X2 | FMAC_PARAM_START));
  1561. if (PreloadAccess == PRELOAD_ACCESS_POLLING)
  1562. {
  1563. /* Load the buffer into the internal memory */
  1564. FMAC_WritePreloadDataIncrementPtr(hfmac, &(pConfig->pCoeffB), pConfig->CoeffBSize);
  1565. /* Load pCoeffA if needed */
  1566. if ((pConfig->pCoeffA != NULL) && (pConfig->CoeffASize != 0U))
  1567. {
  1568. /* Load the buffer into the internal memory */
  1569. FMAC_WritePreloadDataIncrementPtr(hfmac, &(pConfig->pCoeffA), pConfig->CoeffASize);
  1570. }
  1571. /* Wait for the end of the writing */
  1572. if (FMAC_WaitOnStartUntilTimeout(hfmac, tickstart, HAL_FMAC_TIMEOUT_VALUE) != HAL_OK)
  1573. {
  1574. hfmac->ErrorCode |= HAL_FMAC_ERROR_TIMEOUT;
  1575. hfmac->State = HAL_FMAC_STATE_TIMEOUT;
  1576. return HAL_ERROR;
  1577. }
  1578. /* Change the FMAC state */
  1579. hfmac->State = HAL_FMAC_STATE_READY;
  1580. }
  1581. else
  1582. {
  1583. hfmac->pInput = pConfig->pCoeffA;
  1584. hfmac->InputCurrentSize = pConfig->CoeffASize;
  1585. /* Set the FMAC DMA transfer complete callback */
  1586. hfmac->hdmaPreload->XferHalfCpltCallback = NULL;
  1587. hfmac->hdmaPreload->XferCpltCallback = FMAC_DMAFilterConfig;
  1588. /* Set the DMA error callback */
  1589. hfmac->hdmaPreload->XferErrorCallback = FMAC_DMAError;
  1590. /* Enable the DMA stream managing FMAC preload data write */
  1591. return (HAL_DMA_Start_IT(hfmac->hdmaPreload, (uint32_t)pConfig->pCoeffB, (uint32_t)&hfmac->Instance->WDATA,
  1592. pConfig->CoeffBSize));
  1593. }
  1594. }
  1595. else
  1596. {
  1597. /* Change the FMAC state */
  1598. hfmac->State = HAL_FMAC_STATE_READY;
  1599. }
  1600. return HAL_OK;
  1601. }
  1602. /**
  1603. * @brief Preload the input (FIR, IIR) and output data (IIR) of the FMAC filter.
  1604. * @note The set(s) of data will be used by FMAC as soon as @ref HAL_FMAC_FilterStart is called.
  1605. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  1606. * the configuration information for FMAC module.
  1607. * @param pInput Preloading of the first elements of the input buffer (X1).
  1608. * If not needed (no data available when starting), it should be set to NULL.
  1609. * @param InputSize Size of the input vector.
  1610. * As pInput is used for preloading data, it cannot be bigger than the input memory area.
  1611. * @param pOutput [IIR] Preloading of the first elements of the output vector (Y).
  1612. * If not needed, it should be set to NULL.
  1613. * @param OutputSize Size of the output vector.
  1614. * As pOutput is used for preloading data, it cannot be bigger than the output memory area.
  1615. * @param PreloadAccess access mode used for the preload (polling or DMA).
  1616. * @note The input and the output buffers can be filled by calling several times @ref HAL_FMAC_FilterPreload
  1617. * (each call filling partly the buffers). In case of overflow (too much data provided through
  1618. * all these calls), an error will be returned.
  1619. * @retval HAL_StatusTypeDef HAL status
  1620. */
  1621. static HAL_StatusTypeDef FMAC_FilterPreload(FMAC_HandleTypeDef *hfmac, int16_t *pInput, uint8_t InputSize,
  1622. int16_t *pOutput, uint8_t OutputSize, uint8_t PreloadAccess)
  1623. {
  1624. uint32_t tickstart;
  1625. HAL_StatusTypeDef status;
  1626. /* Check the START bit state */
  1627. if (FMAC_GET_START_BIT(hfmac) != 0U)
  1628. {
  1629. return HAL_ERROR;
  1630. }
  1631. /* Check that a valid configuration was done previously */
  1632. if (hfmac->FilterParam == 0U)
  1633. {
  1634. return HAL_ERROR;
  1635. }
  1636. /* Check the preload input buffers isn't too big */
  1637. if ((InputSize > FMAC_GET_X1_SIZE(hfmac)) && (pInput != NULL))
  1638. {
  1639. return HAL_ERROR;
  1640. }
  1641. /* Check the preload output buffer isn't too big */
  1642. if ((OutputSize > FMAC_GET_Y_SIZE(hfmac)) && (pOutput != NULL))
  1643. {
  1644. return HAL_ERROR;
  1645. }
  1646. /* Check handle state is ready */
  1647. if (hfmac->State != HAL_FMAC_STATE_READY)
  1648. {
  1649. return HAL_ERROR;
  1650. }
  1651. /* Change the FMAC state */
  1652. hfmac->State = HAL_FMAC_STATE_BUSY;
  1653. /* Get tick */
  1654. tickstart = HAL_GetTick();
  1655. /* Preload the input buffer if required */
  1656. if ((pInput != NULL) && (InputSize != 0U))
  1657. {
  1658. /* Write number of values to be loaded, the data load function and start the operation */
  1659. WRITE_REG(hfmac->Instance->PARAM, \
  1660. (((uint32_t)InputSize << FMAC_PARAM_P_Pos) | FMAC_FUNC_LOAD_X1 | FMAC_PARAM_START));
  1661. if (PreloadAccess == PRELOAD_ACCESS_POLLING)
  1662. {
  1663. /* Load the buffer into the internal memory */
  1664. FMAC_WritePreloadDataIncrementPtr(hfmac, &pInput, InputSize);
  1665. /* Wait for the end of the writing */
  1666. if (FMAC_WaitOnStartUntilTimeout(hfmac, tickstart, HAL_FMAC_TIMEOUT_VALUE) != HAL_OK)
  1667. {
  1668. hfmac->ErrorCode |= HAL_FMAC_ERROR_TIMEOUT;
  1669. hfmac->State = HAL_FMAC_STATE_TIMEOUT;
  1670. return HAL_ERROR;
  1671. }
  1672. }
  1673. else
  1674. {
  1675. hfmac->pInput = pOutput;
  1676. hfmac->InputCurrentSize = OutputSize;
  1677. /* Set the FMAC DMA transfer complete callback */
  1678. hfmac->hdmaPreload->XferHalfCpltCallback = NULL;
  1679. hfmac->hdmaPreload->XferCpltCallback = FMAC_DMAFilterPreload;
  1680. /* Set the DMA error callback */
  1681. hfmac->hdmaPreload->XferErrorCallback = FMAC_DMAError;
  1682. /* Enable the DMA stream managing FMAC preload data write */
  1683. return (HAL_DMA_Start_IT(hfmac->hdmaPreload, (uint32_t)pInput, (uint32_t)&hfmac->Instance->WDATA, InputSize));
  1684. }
  1685. }
  1686. /* Preload the output buffer if required */
  1687. if ((pOutput != NULL) && (OutputSize != 0U))
  1688. {
  1689. /* Write number of values to be loaded, the data load function and start the operation */
  1690. WRITE_REG(hfmac->Instance->PARAM, \
  1691. (((uint32_t)OutputSize << FMAC_PARAM_P_Pos) | FMAC_FUNC_LOAD_Y | FMAC_PARAM_START));
  1692. if (PreloadAccess == PRELOAD_ACCESS_POLLING)
  1693. {
  1694. /* Load the buffer into the internal memory */
  1695. FMAC_WritePreloadDataIncrementPtr(hfmac, &pOutput, OutputSize);
  1696. /* Wait for the end of the writing */
  1697. if (FMAC_WaitOnStartUntilTimeout(hfmac, tickstart, HAL_FMAC_TIMEOUT_VALUE) != HAL_OK)
  1698. {
  1699. hfmac->ErrorCode |= HAL_FMAC_ERROR_TIMEOUT;
  1700. hfmac->State = HAL_FMAC_STATE_TIMEOUT;
  1701. return HAL_ERROR;
  1702. }
  1703. }
  1704. else
  1705. {
  1706. hfmac->pInput = NULL;
  1707. hfmac->InputCurrentSize = 0U;
  1708. /* Set the FMAC DMA transfer complete callback */
  1709. hfmac->hdmaPreload->XferHalfCpltCallback = NULL;
  1710. hfmac->hdmaPreload->XferCpltCallback = FMAC_DMAFilterPreload;
  1711. /* Set the DMA error callback */
  1712. hfmac->hdmaPreload->XferErrorCallback = FMAC_DMAError;
  1713. /* Enable the DMA stream managing FMAC preload data write */
  1714. return (HAL_DMA_Start_IT(hfmac->hdmaPreload, (uint32_t)pOutput, (uint32_t)&hfmac->Instance->WDATA, OutputSize));
  1715. }
  1716. }
  1717. /* Update the error codes */
  1718. if (__HAL_FMAC_GET_FLAG(hfmac, FMAC_FLAG_OVFL))
  1719. {
  1720. hfmac->ErrorCode |= HAL_FMAC_ERROR_OVFL;
  1721. }
  1722. if (__HAL_FMAC_GET_FLAG(hfmac, FMAC_FLAG_UNFL))
  1723. {
  1724. hfmac->ErrorCode |= HAL_FMAC_ERROR_UNFL;
  1725. }
  1726. if (__HAL_FMAC_GET_FLAG(hfmac, FMAC_FLAG_SAT))
  1727. {
  1728. hfmac->ErrorCode |= HAL_FMAC_ERROR_SAT;
  1729. }
  1730. /* Change the FMAC state */
  1731. hfmac->State = HAL_FMAC_STATE_READY;
  1732. /* Return function status */
  1733. if (hfmac->ErrorCode == HAL_FMAC_ERROR_NONE)
  1734. {
  1735. status = HAL_OK;
  1736. }
  1737. else
  1738. {
  1739. status = HAL_ERROR;
  1740. }
  1741. return status;
  1742. }
  1743. /**
  1744. * @brief Write data into FMAC internal memory through WDATA and increment input buffer pointer.
  1745. * @note This function is only used with preload functions.
  1746. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  1747. * the configuration information for FMAC module.
  1748. * @param ppData pointer to pointer to the data buffer.
  1749. * @param Size size of the data buffer.
  1750. * @retval None
  1751. */
  1752. static void FMAC_WritePreloadDataIncrementPtr(FMAC_HandleTypeDef *hfmac, int16_t **ppData, uint8_t Size)
  1753. {
  1754. uint8_t index;
  1755. /* Load the buffer into the internal memory */
  1756. for (index = Size; index > 0U; index--)
  1757. {
  1758. WRITE_REG(hfmac->Instance->WDATA, (((uint32_t)(*(*ppData))) & FMAC_WDATA_WDATA));
  1759. (*ppData)++;
  1760. }
  1761. }
  1762. /**
  1763. * @brief Handle FMAC Function Timeout.
  1764. * @param hfmac FMAC handle.
  1765. * @param Tickstart Tick start value.
  1766. * @param Timeout Timeout duration.
  1767. * @retval HAL_StatusTypeDef HAL status
  1768. */
  1769. static HAL_StatusTypeDef FMAC_WaitOnStartUntilTimeout(FMAC_HandleTypeDef *hfmac, uint32_t Tickstart, uint32_t Timeout)
  1770. {
  1771. /* Wait until flag changes */
  1772. while (READ_BIT(hfmac->Instance->PARAM, FMAC_PARAM_START) != 0U)
  1773. {
  1774. if ((HAL_GetTick() - Tickstart) > Timeout)
  1775. {
  1776. hfmac->ErrorCode |= HAL_FMAC_ERROR_TIMEOUT;
  1777. return HAL_ERROR;
  1778. }
  1779. }
  1780. return HAL_OK;
  1781. }
  1782. /**
  1783. * @brief Register the new input buffer, update DMA configuration if needed and change the FMAC state.
  1784. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  1785. * the configuration information for FMAC module.
  1786. * @param pInput New input vector (additional input data).
  1787. * @param pInputSize Size of the input vector (if all the data can't be
  1788. * written, it will be updated with the number of data read from FMAC).
  1789. * @retval HAL_StatusTypeDef HAL status
  1790. */
  1791. static HAL_StatusTypeDef FMAC_AppendFilterDataUpdateState(FMAC_HandleTypeDef *hfmac, int16_t *pInput,
  1792. uint16_t *pInputSize)
  1793. {
  1794. /* Change the FMAC state */
  1795. hfmac->WrState = HAL_FMAC_STATE_BUSY_WR;
  1796. /* Reset the current size */
  1797. hfmac->InputCurrentSize = 0U;
  1798. /* Handle the pointer depending on the input access */
  1799. if (hfmac->InputAccess == FMAC_BUFFER_ACCESS_DMA)
  1800. {
  1801. hfmac->pInput = NULL;
  1802. hfmac->pInputSize = NULL;
  1803. /* Set the FMAC DMA transfer complete callback */
  1804. hfmac->hdmaIn->XferHalfCpltCallback = FMAC_DMAHalfGetData;
  1805. hfmac->hdmaIn->XferCpltCallback = FMAC_DMAGetData;
  1806. /* Set the DMA error callback */
  1807. hfmac->hdmaIn->XferErrorCallback = FMAC_DMAError;
  1808. /* Enable the DMA stream managing FMAC input data write */
  1809. return (HAL_DMA_Start_IT(hfmac->hdmaIn, (uint32_t)pInput, (uint32_t)&hfmac->Instance->WDATA, *pInputSize));
  1810. }
  1811. else
  1812. {
  1813. /* Update the input data information (polling, IT) */
  1814. hfmac->pInput = pInput;
  1815. hfmac->pInputSize = pInputSize;
  1816. }
  1817. return HAL_OK;
  1818. }
  1819. /**
  1820. * @brief Register the new output buffer, update DMA configuration if needed and change the FMAC state.
  1821. * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
  1822. * the configuration information for FMAC module.
  1823. * @param pOutput New output vector.
  1824. * @param pOutputSize Size of the output vector (if the vector can't
  1825. * be entirely filled, pOutputSize will be updated with the number
  1826. * of data read from FMAC).
  1827. * @retval HAL_StatusTypeDef HAL status
  1828. */
  1829. static HAL_StatusTypeDef FMAC_ConfigFilterOutputBufferUpdateState(FMAC_HandleTypeDef *hfmac, int16_t *pOutput,
  1830. uint16_t *pOutputSize)
  1831. {
  1832. /* Reset the current size */
  1833. hfmac->OutputCurrentSize = 0U;
  1834. /* Check whether a valid pointer was provided */
  1835. if ((pOutput == NULL) || (pOutputSize == NULL) || (*pOutputSize == 0U))
  1836. {
  1837. /* The user will have to provide a valid configuration later */
  1838. hfmac->pOutput = NULL;
  1839. hfmac->pOutputSize = NULL;
  1840. hfmac->RdState = HAL_FMAC_STATE_READY;
  1841. }
  1842. /* Handle the pointer depending on the input access */
  1843. else if (hfmac->OutputAccess == FMAC_BUFFER_ACCESS_DMA)
  1844. {
  1845. hfmac->pOutput = NULL;
  1846. hfmac->pOutputSize = NULL;
  1847. hfmac->RdState = HAL_FMAC_STATE_BUSY_RD;
  1848. /* Set the FMAC DMA transfer complete callback */
  1849. hfmac->hdmaOut->XferHalfCpltCallback = FMAC_DMAHalfOutputDataReady;
  1850. hfmac->hdmaOut->XferCpltCallback = FMAC_DMAOutputDataReady;
  1851. /* Set the DMA error callback */
  1852. hfmac->hdmaOut->XferErrorCallback = FMAC_DMAError;
  1853. /* Enable the DMA stream managing FMAC output data read */
  1854. return (HAL_DMA_Start_IT(hfmac->hdmaOut, (uint32_t)&hfmac->Instance->RDATA, (uint32_t)pOutput, *pOutputSize));
  1855. }
  1856. else if (hfmac->OutputAccess == FMAC_BUFFER_ACCESS_NONE)
  1857. {
  1858. hfmac->pOutput = NULL;
  1859. hfmac->pOutputSize = NULL;
  1860. hfmac->RdState = HAL_FMAC_STATE_READY;
  1861. }
  1862. else
  1863. {
  1864. /* Update the output data information (polling, IT) */
  1865. hfmac->pOutput = pOutput;
  1866. hfmac->pOutputSize = pOutputSize;
  1867. hfmac->RdState = HAL_FMAC_STATE_BUSY_RD;
  1868. }
  1869. return HAL_OK;
  1870. }
  1871. /**
  1872. * @brief Read available output data until Y EMPTY is set.
  1873. * @param hfmac FMAC handle.
  1874. * @param MaxSizeToRead Maximum number of data to read (this serves as a timeout
  1875. * if FMAC continuously writes into the output buffer).
  1876. * @retval None
  1877. */
  1878. static void FMAC_ReadDataIncrementPtr(FMAC_HandleTypeDef *hfmac, uint16_t MaxSizeToRead)
  1879. {
  1880. uint16_t maxsize;
  1881. uint16_t threshold;
  1882. uint32_t tmpvalue;
  1883. /* Check if there is data to read */
  1884. if (READ_BIT(hfmac->Instance->SR, FMAC_SR_YEMPTY) != 0U)
  1885. {
  1886. return;
  1887. }
  1888. /* Get the maximum index (no wait allowed, no overstepping of the output buffer) */
  1889. if ((hfmac->OutputCurrentSize + MaxSizeToRead) > *(hfmac->pOutputSize))
  1890. {
  1891. maxsize = *(hfmac->pOutputSize);
  1892. }
  1893. else
  1894. {
  1895. maxsize = hfmac->OutputCurrentSize + MaxSizeToRead;
  1896. }
  1897. /* Read until there is no more room or no more data */
  1898. do
  1899. {
  1900. /* If there is no more room, return */
  1901. if (!(hfmac->OutputCurrentSize < maxsize))
  1902. {
  1903. return;
  1904. }
  1905. /* Read the available data */
  1906. tmpvalue = ((READ_REG(hfmac->Instance->RDATA))& FMAC_RDATA_RDATA);
  1907. *(hfmac->pOutput) = (int16_t)tmpvalue;
  1908. hfmac->pOutput++;
  1909. hfmac->OutputCurrentSize++;
  1910. } while (READ_BIT(hfmac->Instance->SR, FMAC_SR_YEMPTY) == 0U);
  1911. /* Y buffer empty flag has just be raised, read the threshold */
  1912. threshold = (uint16_t)FMAC_GET_THRESHOLD_FROM_WM(FMAC_GET_Y_EMPTY_WM(hfmac)) - 1U;
  1913. /* Update the maximum size if needed (limited data available) */
  1914. if ((hfmac->OutputCurrentSize + threshold) < maxsize)
  1915. {
  1916. maxsize = hfmac->OutputCurrentSize + threshold;
  1917. }
  1918. /* Read the available data */
  1919. while (hfmac->OutputCurrentSize < maxsize)
  1920. {
  1921. tmpvalue = ((READ_REG(hfmac->Instance->RDATA))& FMAC_RDATA_RDATA);
  1922. *(hfmac->pOutput) = (int16_t)tmpvalue;
  1923. hfmac->pOutput++;
  1924. hfmac->OutputCurrentSize++;
  1925. }
  1926. }
  1927. /**
  1928. * @brief Write available input data until X1 FULL is set.
  1929. * @param hfmac FMAC handle.
  1930. * @param MaxSizeToWrite Maximum number of data to write (this serves as a timeout
  1931. * if FMAC continuously empties the input buffer).
  1932. * @retval None
  1933. */
  1934. static void FMAC_WriteDataIncrementPtr(FMAC_HandleTypeDef *hfmac, uint16_t MaxSizeToWrite)
  1935. {
  1936. uint16_t maxsize;
  1937. uint16_t threshold;
  1938. /* Check if there is room in FMAC */
  1939. if (READ_BIT(hfmac->Instance->SR, FMAC_SR_X1FULL) != 0U)
  1940. {
  1941. return;
  1942. }
  1943. /* Get the maximum index (no wait allowed, no overstepping of the output buffer) */
  1944. if ((hfmac->InputCurrentSize + MaxSizeToWrite) > *(hfmac->pInputSize))
  1945. {
  1946. maxsize = *(hfmac->pInputSize);
  1947. }
  1948. else
  1949. {
  1950. maxsize = hfmac->InputCurrentSize + MaxSizeToWrite;
  1951. }
  1952. /* Write until there is no more room or no more data */
  1953. do
  1954. {
  1955. /* If there is no more room, return */
  1956. if (!(hfmac->InputCurrentSize < maxsize))
  1957. {
  1958. return;
  1959. }
  1960. /* Write the available data */
  1961. WRITE_REG(hfmac->Instance->WDATA, (((uint32_t)(*(hfmac->pInput))) & FMAC_WDATA_WDATA));
  1962. hfmac->pInput++;
  1963. hfmac->InputCurrentSize++;
  1964. } while (READ_BIT(hfmac->Instance->SR, FMAC_SR_X1FULL) == 0U);
  1965. /* X1 buffer full flag has just be raised, read the threshold */
  1966. threshold = (uint16_t)FMAC_GET_THRESHOLD_FROM_WM(FMAC_GET_X1_FULL_WM(hfmac)) - 1U;
  1967. /* Update the maximum size if needed (limited data available) */
  1968. if ((hfmac->InputCurrentSize + threshold) < maxsize)
  1969. {
  1970. maxsize = hfmac->InputCurrentSize + threshold;
  1971. }
  1972. /* Write the available data */
  1973. while (hfmac->InputCurrentSize < maxsize)
  1974. {
  1975. WRITE_REG(hfmac->Instance->WDATA, (((uint32_t)(*(hfmac->pInput))) & FMAC_WDATA_WDATA));
  1976. hfmac->pInput++;
  1977. hfmac->InputCurrentSize++;
  1978. }
  1979. }
  1980. /**
  1981. * @brief DMA FMAC Input Data process half complete callback.
  1982. * @param hdma DMA handle.
  1983. * @retval None
  1984. */
  1985. static void FMAC_DMAHalfGetData(DMA_HandleTypeDef *hdma)
  1986. {
  1987. FMAC_HandleTypeDef *hfmac = (FMAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  1988. /* Call half get data callback */
  1989. #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
  1990. hfmac->HalfGetDataCallback(hfmac);
  1991. #else
  1992. HAL_FMAC_HalfGetDataCallback(hfmac);
  1993. #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
  1994. }
  1995. /**
  1996. * @brief DMA FMAC Input Data process complete callback.
  1997. * @param hdma DMA handle.
  1998. * @retval None
  1999. */
  2000. static void FMAC_DMAGetData(DMA_HandleTypeDef *hdma)
  2001. {
  2002. FMAC_HandleTypeDef *hfmac = (FMAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  2003. /* Reset the pointers to indicate new data will be needed */
  2004. FMAC_ResetInputStateAndDataPointers(hfmac);
  2005. /* Call get data callback */
  2006. #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
  2007. hfmac->GetDataCallback(hfmac);
  2008. #else
  2009. HAL_FMAC_GetDataCallback(hfmac);
  2010. #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
  2011. }
  2012. /**
  2013. * @brief DMA FMAC Output Data process half complete callback.
  2014. * @param hdma DMA handle.
  2015. * @retval None
  2016. */
  2017. static void FMAC_DMAHalfOutputDataReady(DMA_HandleTypeDef *hdma)
  2018. {
  2019. FMAC_HandleTypeDef *hfmac = (FMAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  2020. /* Call half output data ready callback */
  2021. #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
  2022. hfmac->HalfOutputDataReadyCallback(hfmac);
  2023. #else
  2024. HAL_FMAC_HalfOutputDataReadyCallback(hfmac);
  2025. #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
  2026. }
  2027. /**
  2028. * @brief DMA FMAC Output Data process complete callback.
  2029. * @param hdma DMA handle.
  2030. * @retval None
  2031. */
  2032. static void FMAC_DMAOutputDataReady(DMA_HandleTypeDef *hdma)
  2033. {
  2034. FMAC_HandleTypeDef *hfmac = (FMAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  2035. /* Reset the pointers to indicate new data will be needed */
  2036. FMAC_ResetOutputStateAndDataPointers(hfmac);
  2037. /* Call output data ready callback */
  2038. #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
  2039. hfmac->OutputDataReadyCallback(hfmac);
  2040. #else
  2041. HAL_FMAC_OutputDataReadyCallback(hfmac);
  2042. #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
  2043. }
  2044. /**
  2045. * @brief DMA FMAC Filter Configuration process complete callback.
  2046. * @param hdma DMA handle.
  2047. * @retval None
  2048. */
  2049. static void FMAC_DMAFilterConfig(DMA_HandleTypeDef *hdma)
  2050. {
  2051. uint8_t index;
  2052. FMAC_HandleTypeDef *hfmac = (FMAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  2053. /* If needed, write CoeffA and exit */
  2054. if (hfmac->pInput != NULL)
  2055. {
  2056. /* Set the FMAC DMA transfer complete callback */
  2057. hfmac->hdmaPreload->XferHalfCpltCallback = NULL;
  2058. hfmac->hdmaPreload->XferCpltCallback = FMAC_DMAFilterConfig;
  2059. /* Set the DMA error callback */
  2060. hfmac->hdmaPreload->XferErrorCallback = FMAC_DMAError;
  2061. /* Enable the DMA stream managing FMAC preload data write */
  2062. if (HAL_DMA_Start_IT(hfmac->hdmaPreload, (uint32_t)hfmac->pInput, (uint32_t)&hfmac->Instance->WDATA,
  2063. hfmac->InputCurrentSize) == HAL_OK)
  2064. {
  2065. hfmac->pInput = NULL;
  2066. hfmac->InputCurrentSize = 0U;
  2067. return;
  2068. }
  2069. /* If not exited, there was an error: set FMAC handle state to error */
  2070. hfmac->State = HAL_FMAC_STATE_ERROR;
  2071. }
  2072. else
  2073. {
  2074. /* Wait for the end of the writing */
  2075. for (index = 0U; index < MAX_PRELOAD_INDEX; index++)
  2076. {
  2077. if (READ_BIT(hfmac->Instance->PARAM, FMAC_PARAM_START) == 0U)
  2078. {
  2079. break;
  2080. }
  2081. }
  2082. /* If 'START' is still set, there was a timeout: set FMAC handle state to timeout */
  2083. if (READ_BIT(hfmac->Instance->PARAM, FMAC_PARAM_START) != 0U)
  2084. {
  2085. hfmac->State = HAL_FMAC_STATE_TIMEOUT;
  2086. }
  2087. else
  2088. {
  2089. /* Change the FMAC state */
  2090. hfmac->State = HAL_FMAC_STATE_READY;
  2091. /* Call output data ready callback */
  2092. #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
  2093. hfmac->FilterConfigCallback(hfmac);
  2094. #else
  2095. HAL_FMAC_FilterConfigCallback(hfmac);
  2096. #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
  2097. return;
  2098. }
  2099. }
  2100. /* If not exited, there was an error: set FMAC handle error code to DMA error */
  2101. hfmac->ErrorCode |= HAL_FMAC_ERROR_DMA;
  2102. /* Call user callback */
  2103. #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
  2104. hfmac->ErrorCallback(hfmac);
  2105. #else
  2106. HAL_FMAC_ErrorCallback(hfmac);
  2107. #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
  2108. }
  2109. /**
  2110. * @brief DMA FMAC Filter Configuration process complete callback.
  2111. * @param hdma DMA handle.
  2112. * @retval None
  2113. */
  2114. static void FMAC_DMAFilterPreload(DMA_HandleTypeDef *hdma)
  2115. {
  2116. uint8_t index;
  2117. FMAC_HandleTypeDef *hfmac = (FMAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  2118. /* Wait for the end of the X1 writing */
  2119. for (index = 0U; index < MAX_PRELOAD_INDEX; index++)
  2120. {
  2121. if (READ_BIT(hfmac->Instance->PARAM, FMAC_PARAM_START) == 0U)
  2122. {
  2123. break;
  2124. }
  2125. }
  2126. /* If 'START' is still set, there was an error: set FMAC handle state to error */
  2127. if (READ_BIT(hfmac->Instance->PARAM, FMAC_PARAM_START) != 0U)
  2128. {
  2129. hfmac->State = HAL_FMAC_STATE_TIMEOUT;
  2130. hfmac->ErrorCode |= HAL_FMAC_ERROR_TIMEOUT;
  2131. }
  2132. /* If needed, preload Y buffer */
  2133. else if ((hfmac->pInput != NULL) && (hfmac->InputCurrentSize != 0U))
  2134. {
  2135. /* Write number of values to be loaded, the data load function and start the operation */
  2136. WRITE_REG(hfmac->Instance->PARAM, \
  2137. (((uint32_t)(hfmac->InputCurrentSize) << FMAC_PARAM_P_Pos) | FMAC_FUNC_LOAD_Y | FMAC_PARAM_START));
  2138. /* Set the FMAC DMA transfer complete callback */
  2139. hfmac->hdmaPreload->XferHalfCpltCallback = NULL;
  2140. hfmac->hdmaPreload->XferCpltCallback = FMAC_DMAFilterPreload;
  2141. /* Set the DMA error callback */
  2142. hfmac->hdmaPreload->XferErrorCallback = FMAC_DMAError;
  2143. /* Enable the DMA stream managing FMAC preload data write */
  2144. if (HAL_DMA_Start_IT(hfmac->hdmaPreload, (uint32_t)hfmac->pInput, (uint32_t)&hfmac->Instance->WDATA,
  2145. hfmac->InputCurrentSize) == HAL_OK)
  2146. {
  2147. hfmac->pInput = NULL;
  2148. hfmac->InputCurrentSize = 0U;
  2149. return;
  2150. }
  2151. /* If not exited, there was an error */
  2152. hfmac->ErrorCode = HAL_FMAC_ERROR_DMA;
  2153. hfmac->State = HAL_FMAC_STATE_ERROR;
  2154. }
  2155. else
  2156. {
  2157. /* nothing to do */
  2158. }
  2159. if (hfmac->ErrorCode == HAL_FMAC_ERROR_NONE)
  2160. {
  2161. /* Change the FMAC state */
  2162. hfmac->State = HAL_FMAC_STATE_READY;
  2163. /* Call output data ready callback */
  2164. #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
  2165. hfmac->FilterPreloadCallback(hfmac);
  2166. #else
  2167. HAL_FMAC_FilterPreloadCallback(hfmac);
  2168. #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
  2169. }
  2170. else
  2171. {
  2172. /* Call user callback */
  2173. #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
  2174. hfmac->ErrorCallback(hfmac);
  2175. #else
  2176. HAL_FMAC_ErrorCallback(hfmac);
  2177. #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
  2178. }
  2179. }
  2180. /**
  2181. * @brief DMA FMAC communication error callback.
  2182. * @param hdma DMA handle.
  2183. * @retval None
  2184. */
  2185. static void FMAC_DMAError(DMA_HandleTypeDef *hdma)
  2186. {
  2187. FMAC_HandleTypeDef *hfmac = (FMAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  2188. /* Set FMAC handle state to error */
  2189. hfmac->State = HAL_FMAC_STATE_ERROR;
  2190. /* Set FMAC handle error code to DMA error */
  2191. hfmac->ErrorCode |= HAL_FMAC_ERROR_DMA;
  2192. /* Call user callback */
  2193. #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
  2194. hfmac->ErrorCallback(hfmac);
  2195. #else
  2196. HAL_FMAC_ErrorCallback(hfmac);
  2197. #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
  2198. }
  2199. /**
  2200. * @}
  2201. */
  2202. /**
  2203. * @}
  2204. */
  2205. /**
  2206. * @}
  2207. */
  2208. #endif /* HAL_FMAC_MODULE_ENABLED */
  2209. #endif /* FMAC */