STM32H735xx HAL User Manual
stm32h7xx_hal_fdcan.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32h7xx_hal_fdcan.c
00004   * @author  MCD Application Team
00005   * @brief   FDCAN HAL module driver.
00006   *          This file provides firmware functions to manage the following
00007   *          functionalities of the Flexible DataRate Controller Area Network
00008   *          (FDCAN) peripheral:
00009   *           + Initialization and de-initialization functions
00010   *           + IO operation functions
00011   *           + Peripheral Configuration and Control functions
00012   *           + Peripheral State and Error functions
00013   *
00014   ******************************************************************************
00015   * @attention
00016   *
00017   * Copyright (c) 2017 STMicroelectronics.
00018   * All rights reserved.
00019   *
00020   * This software is licensed under terms that can be found in the LICENSE file
00021   * in the root directory of this software component.
00022   * If no LICENSE file comes with this software, it is provided AS-IS.
00023   *
00024   ******************************************************************************
00025   @verbatim
00026   ==============================================================================
00027                         ##### How to use this driver #####
00028   ==============================================================================
00029     [..]
00030       (#) Initialize the FDCAN peripheral using HAL_FDCAN_Init function.
00031 
00032       (#) If needed , configure the reception filters and optional features using
00033           the following configuration functions:
00034             (++) HAL_FDCAN_ConfigClockCalibration
00035             (++) HAL_FDCAN_ConfigFilter
00036             (++) HAL_FDCAN_ConfigGlobalFilter
00037             (++) HAL_FDCAN_ConfigExtendedIdMask
00038             (++) HAL_FDCAN_ConfigRxFifoOverwrite
00039             (++) HAL_FDCAN_ConfigFifoWatermark
00040             (++) HAL_FDCAN_ConfigRamWatchdog
00041             (++) HAL_FDCAN_ConfigTimestampCounter
00042             (++) HAL_FDCAN_EnableTimestampCounter
00043             (++) HAL_FDCAN_DisableTimestampCounter
00044             (++) HAL_FDCAN_ConfigTimeoutCounter
00045             (++) HAL_FDCAN_EnableTimeoutCounter
00046             (++) HAL_FDCAN_DisableTimeoutCounter
00047             (++) HAL_FDCAN_ConfigTxDelayCompensation
00048             (++) HAL_FDCAN_EnableTxDelayCompensation
00049             (++) HAL_FDCAN_DisableTxDelayCompensation
00050             (++) HAL_FDCAN_EnableISOMode
00051             (++) HAL_FDCAN_DisableISOMode
00052             (++) HAL_FDCAN_EnableEdgeFiltering
00053             (++) HAL_FDCAN_DisableEdgeFiltering
00054             (++) HAL_FDCAN_TT_ConfigOperation
00055             (++) HAL_FDCAN_TT_ConfigReferenceMessage
00056             (++) HAL_FDCAN_TT_ConfigTrigger
00057 
00058       (#) Start the FDCAN module using HAL_FDCAN_Start function. At this level
00059           the node is active on the bus: it can send and receive messages.
00060 
00061       (#) The following Tx control functions can only be called when the FDCAN
00062           module is started:
00063             (++) HAL_FDCAN_AddMessageToTxFifoQ
00064             (++) HAL_FDCAN_EnableTxBufferRequest
00065             (++) HAL_FDCAN_AbortTxRequest
00066 
00067       (#) After having submitted a Tx request in Tx Fifo or Queue, it is possible to
00068           get Tx buffer location used to place the Tx request thanks to
00069           HAL_FDCAN_GetLatestTxFifoQRequestBuffer API.
00070           It is then possible to abort later on the corresponding Tx Request using
00071           HAL_FDCAN_AbortTxRequest API.
00072 
00073       (#) When a message is received into the FDCAN message RAM, it can be
00074           retrieved using the HAL_FDCAN_GetRxMessage function.
00075 
00076       (#) Calling the HAL_FDCAN_Stop function stops the FDCAN module by entering
00077           it to initialization mode and re-enabling access to configuration
00078           registers through the configuration functions listed here above.
00079 
00080       (#) All other control functions can be called any time after initialization
00081           phase, no matter if the FDCAN module is started or stopped.
00082 
00083       *** Polling mode operation ***
00084       ==============================
00085 
00086     [..]
00087         (#) Reception and transmission states can be monitored via the following
00088             functions:
00089               (++) HAL_FDCAN_IsRxBufferMessageAvailable
00090               (++) HAL_FDCAN_IsTxBufferMessagePending
00091               (++) HAL_FDCAN_GetRxFifoFillLevel
00092               (++) HAL_FDCAN_GetTxFifoFreeLevel
00093 
00094       *** Interrupt mode operation ***
00095       ================================
00096       [..]
00097         (#) There are two interrupt lines: line 0 and 1.
00098             By default, all interrupts are assigned to line 0. Interrupt lines
00099             can be configured using HAL_FDCAN_ConfigInterruptLines function.
00100 
00101         (#) Notifications are activated using HAL_FDCAN_ActivateNotification
00102             function. Then, the process can be controlled through one of the
00103             available user callbacks: HAL_FDCAN_xxxCallback.
00104 
00105   *** Callback registration ***
00106   =============================================
00107 
00108   The compilation define USE_HAL_FDCAN_REGISTER_CALLBACKS when set to 1
00109   allows the user to configure dynamically the driver callbacks.
00110   Use Function HAL_FDCAN_RegisterCallback() or HAL_FDCAN_RegisterXXXCallback()
00111   to register an interrupt callback.
00112 
00113   Function HAL_FDCAN_RegisterCallback() allows to register following callbacks:
00114     (+) TxFifoEmptyCallback          : Tx Fifo Empty Callback.
00115     (+) RxBufferNewMessageCallback   : Rx Buffer New Message Callback.
00116     (+) HighPriorityMessageCallback  : High Priority Message Callback.
00117     (+) TimestampWraparoundCallback  : Timestamp Wraparound Callback.
00118     (+) TimeoutOccurredCallback      : Timeout Occurred Callback.
00119     (+) ErrorCallback                : Error Callback.
00120     (+) MspInitCallback              : FDCAN MspInit.
00121     (+) MspDeInitCallback            : FDCAN MspDeInit.
00122   This function takes as parameters the HAL peripheral handle, the Callback ID
00123   and a pointer to the user callback function.
00124 
00125   For specific callbacks ClockCalibrationCallback, TxEventFifoCallback, RxFifo0Callback, RxFifo1Callback,
00126   TxBufferCompleteCallback, TxBufferAbortCallback, ErrorStatusCallback, TT_ScheduleSyncCallback, TT_TimeMarkCallback,
00127   TT_StopWatchCallback and TT_GlobalTimeCallback, use dedicated register callbacks :
00128   respectively HAL_FDCAN_RegisterClockCalibrationCallback(), HAL_FDCAN_RegisterTxEventFifoCallback(),
00129   HAL_FDCAN_RegisterRxFifo0Callback(), HAL_FDCAN_RegisterRxFifo1Callback(),
00130   HAL_FDCAN_RegisterTxBufferCompleCallback(), HAL_FDCAN_RegisterTxBufferAbortCallback(),
00131   HAL_FDCAN_RegisterErrorStatusCallback(), HAL_FDCAN_TT_RegisterScheduleSyncCallback(),
00132   HAL_FDCAN_TT_RegisterTimeMarkCallback(), HAL_FDCAN_TT_RegisterStopWatchCallback() and
00133   HAL_FDCAN_TT_RegisterGlobalTimeCallback().
00134 
00135   Use function HAL_FDCAN_UnRegisterCallback() to reset a callback to the default
00136   weak function.
00137   HAL_FDCAN_UnRegisterCallback takes as parameters the HAL peripheral handle,
00138   and the Callback ID.
00139   This function allows to reset following callbacks:
00140     (+) TxFifoEmptyCallback          : Tx Fifo Empty Callback.
00141     (+) RxBufferNewMessageCallback   : Rx Buffer New Message Callback.
00142     (+) HighPriorityMessageCallback  : High Priority Message Callback.
00143     (+) TimestampWraparoundCallback  : Timestamp Wraparound Callback.
00144     (+) TimeoutOccurredCallback      : Timeout Occurred Callback.
00145     (+) ErrorCallback                : Error Callback.
00146     (+) MspInitCallback              : FDCAN MspInit.
00147     (+) MspDeInitCallback            : FDCAN MspDeInit.
00148 
00149   For specific callbacks ClockCalibrationCallback, TxEventFifoCallback, RxFifo0Callback,
00150   RxFifo1Callback, TxBufferCompleteCallback, TxBufferAbortCallback, TT_ScheduleSyncCallback,
00151   TT_TimeMarkCallback, TT_StopWatchCallback and TT_GlobalTimeCallback, use dedicated
00152   register callbacks : respectively HAL_FDCAN_UnRegisterClockCalibrationCallback(),
00153   HAL_FDCAN_UnRegisterTxEventFifoCallback(), HAL_FDCAN_UnRegisterRxFifo0Callback(),
00154   HAL_FDCAN_UnRegisterRxFifo1Callback(), HAL_FDCAN_UnRegisterTxBufferCompleCallback(),
00155   HAL_FDCAN_UnRegisterTxBufferAbortCallback(), HAL_FDCAN_UnRegisterErrorStatusCallback(),
00156   HAL_FDCAN_TT_UnRegisterScheduleSyncCallback(), HAL_FDCAN_TT_UnRegisterTimeMarkCallback(),
00157   HAL_FDCAN_TT_UnRegisterStopWatchCallback() and HAL_FDCAN_TT_UnRegisterGlobalTimeCallback().
00158 
00159   By default, after the HAL_FDCAN_Init() and when the state is HAL_FDCAN_STATE_RESET,
00160   all callbacks are set to the corresponding weak functions:
00161   examples HAL_FDCAN_ErrorCallback().
00162   Exception done for MspInit and MspDeInit functions that are
00163   reset to the legacy weak function in the HAL_FDCAN_Init()/ HAL_FDCAN_DeInit() only when
00164   these callbacks are null (not registered beforehand).
00165   if not, MspInit or MspDeInit are not null, the HAL_FDCAN_Init()/ HAL_FDCAN_DeInit()
00166   keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
00167 
00168   Callbacks can be registered/unregistered in HAL_FDCAN_STATE_READY state only.
00169   Exception done MspInit/MspDeInit that can be registered/unregistered
00170   in HAL_FDCAN_STATE_READY or HAL_FDCAN_STATE_RESET state,
00171   thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
00172   In that case first register the MspInit/MspDeInit user callbacks
00173   using HAL_FDCAN_RegisterCallback() before calling HAL_FDCAN_DeInit()
00174   or HAL_FDCAN_Init() function.
00175 
00176   When The compilation define USE_HAL_FDCAN_REGISTER_CALLBACKS is set to 0 or
00177   not defined, the callback registration feature is not available and all callbacks
00178   are set to the corresponding weak functions.
00179 
00180   @endverbatim
00181 
00182   */
00183 
00184 /* Includes ------------------------------------------------------------------*/
00185 #include "stm32h7xx_hal.h"
00186 
00187 #if defined(FDCAN1)
00188 
00189 /** @addtogroup STM32H7xx_HAL_Driver
00190   * @{
00191   */
00192 
00193 /** @defgroup FDCAN FDCAN
00194   * @brief FDCAN HAL module driver
00195   * @{
00196   */
00197 
00198 #ifdef HAL_FDCAN_MODULE_ENABLED
00199 
00200 /* Private typedef -----------------------------------------------------------*/
00201 /* Private define ------------------------------------------------------------*/
00202 /** @addtogroup FDCAN_Private_Constants
00203   * @{
00204   */
00205 #define FDCAN_TIMEOUT_VALUE 10U
00206 #define FDCAN_TIMEOUT_COUNT 50U
00207 
00208 #define FDCAN_TX_EVENT_FIFO_MASK (FDCAN_IR_TEFL | FDCAN_IR_TEFF | FDCAN_IR_TEFW | FDCAN_IR_TEFN)
00209 #define FDCAN_RX_FIFO0_MASK (FDCAN_IR_RF0L | FDCAN_IR_RF0F | FDCAN_IR_RF0W | FDCAN_IR_RF0N)
00210 #define FDCAN_RX_FIFO1_MASK (FDCAN_IR_RF1L | FDCAN_IR_RF1F | FDCAN_IR_RF1W | FDCAN_IR_RF1N)
00211 #define FDCAN_ERROR_MASK (FDCAN_IR_ELO | FDCAN_IR_WDI | FDCAN_IR_PEA | FDCAN_IR_PED | FDCAN_IR_ARA)
00212 #define FDCAN_ERROR_STATUS_MASK (FDCAN_IR_EP | FDCAN_IR_EW | FDCAN_IR_BO)
00213 #define FDCAN_TT_SCHEDULE_SYNC_MASK (FDCAN_TTIR_SBC | FDCAN_TTIR_SMC | FDCAN_TTIR_CSM | FDCAN_TTIR_SOG)
00214 #define FDCAN_TT_TIME_MARK_MASK (FDCAN_TTIR_RTMI | FDCAN_TTIR_TTMI)
00215 #define FDCAN_TT_GLOBAL_TIME_MASK (FDCAN_TTIR_GTW | FDCAN_TTIR_GTD)
00216 #define FDCAN_TT_DISTURBING_ERROR_MASK (FDCAN_TTIR_GTE | FDCAN_TTIR_TXU | FDCAN_TTIR_TXO | \
00217                                         FDCAN_TTIR_SE1 | FDCAN_TTIR_SE2 | FDCAN_TTIR_ELC)
00218 #define FDCAN_TT_FATAL_ERROR_MASK (FDCAN_TTIR_IWT | FDCAN_TTIR_WT | FDCAN_TTIR_AW | FDCAN_TTIR_CER)
00219 
00220 #define FDCAN_ELEMENT_MASK_STDID ((uint32_t)0x1FFC0000U) /* Standard Identifier         */
00221 #define FDCAN_ELEMENT_MASK_EXTID ((uint32_t)0x1FFFFFFFU) /* Extended Identifier         */
00222 #define FDCAN_ELEMENT_MASK_RTR   ((uint32_t)0x20000000U) /* Remote Transmission Request */
00223 #define FDCAN_ELEMENT_MASK_XTD   ((uint32_t)0x40000000U) /* Extended Identifier         */
00224 #define FDCAN_ELEMENT_MASK_ESI   ((uint32_t)0x80000000U) /* Error State Indicator       */
00225 #define FDCAN_ELEMENT_MASK_TS    ((uint32_t)0x0000FFFFU) /* Timestamp                   */
00226 #define FDCAN_ELEMENT_MASK_DLC   ((uint32_t)0x000F0000U) /* Data Length Code            */
00227 #define FDCAN_ELEMENT_MASK_BRS   ((uint32_t)0x00100000U) /* Bit Rate Switch             */
00228 #define FDCAN_ELEMENT_MASK_FDF   ((uint32_t)0x00200000U) /* FD Format                   */
00229 #define FDCAN_ELEMENT_MASK_EFC   ((uint32_t)0x00800000U) /* Event FIFO Control          */
00230 #define FDCAN_ELEMENT_MASK_MM    ((uint32_t)0xFF000000U) /* Message Marker              */
00231 #define FDCAN_ELEMENT_MASK_FIDX  ((uint32_t)0x7F000000U) /* Filter Index                */
00232 #define FDCAN_ELEMENT_MASK_ANMF  ((uint32_t)0x80000000U) /* Accepted Non-matching Frame */
00233 #define FDCAN_ELEMENT_MASK_ET    ((uint32_t)0x00C00000U) /* Event type                  */
00234 
00235 #define FDCAN_MESSAGE_RAM_SIZE 0x2800U
00236 #define FDCAN_MESSAGE_RAM_END_ADDRESS (SRAMCAN_BASE + FDCAN_MESSAGE_RAM_SIZE - 0x4U) /* The Message RAM has a width of 4 Bytes */
00237 
00238 /**
00239   * @}
00240   */
00241 
00242 /* Private macro -------------------------------------------------------------*/
00243 /* Private variables ---------------------------------------------------------*/
00244 static const uint8_t DLCtoBytes[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64};
00245 
00246 /* Private function prototypes -----------------------------------------------*/
00247 /** @addtogroup FDCAN_Private_Functions_Prototypes
00248   * @{
00249   */
00250 static HAL_StatusTypeDef FDCAN_CalcultateRamBlockAddresses(FDCAN_HandleTypeDef *hfdcan);
00251 static void FDCAN_CopyMessageToRAM(FDCAN_HandleTypeDef *hfdcan, FDCAN_TxHeaderTypeDef *pTxHeader, uint8_t *pTxData, uint32_t BufferIndex);
00252 /**
00253   * @}
00254   */
00255 
00256 /* Exported functions --------------------------------------------------------*/
00257 /** @defgroup FDCAN_Exported_Functions FDCAN Exported Functions
00258   * @{
00259   */
00260 
00261 /** @defgroup FDCAN_Exported_Functions_Group1 Initialization and de-initialization functions
00262  *  @brief    Initialization and Configuration functions
00263  *
00264 @verbatim
00265   ==============================================================================
00266               ##### Initialization and de-initialization functions #####
00267   ==============================================================================
00268     [..]  This section provides functions allowing to:
00269       (+) Initialize and configure the FDCAN.
00270       (+) De-initialize the FDCAN.
00271       (+) Enter FDCAN peripheral in power down mode.
00272       (+) Exit power down mode.
00273       (+) Register callbacks.
00274       (+) Unregister callbacks.
00275 
00276 @endverbatim
00277   * @{
00278   */
00279 
00280 /**
00281   * @brief  Initializes the FDCAN peripheral according to the specified
00282   *         parameters in the FDCAN_InitTypeDef structure.
00283   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
00284   *         the configuration information for the specified FDCAN.
00285   * @retval HAL status
00286   */
00287 HAL_StatusTypeDef HAL_FDCAN_Init(FDCAN_HandleTypeDef *hfdcan)
00288 {
00289   uint32_t tickstart;
00290   HAL_StatusTypeDef status;
00291   const uint32_t CvtEltSize[] = {0, 0, 0, 0, 0, 1, 2, 3, 4, 0, 5, 0, 0, 0, 6, 0, 0, 0, 7};
00292 
00293   /* Check FDCAN handle */
00294   if (hfdcan == NULL)
00295   {
00296     return HAL_ERROR;
00297   }
00298 
00299   /* Check FDCAN instance */
00300   if (hfdcan->Instance == FDCAN1)
00301   {
00302     hfdcan->ttcan = (TTCAN_TypeDef *)((uint32_t)hfdcan->Instance + 0x100U);
00303   }
00304 
00305   /* Check function parameters */
00306   assert_param(IS_FDCAN_ALL_INSTANCE(hfdcan->Instance));
00307   assert_param(IS_FDCAN_FRAME_FORMAT(hfdcan->Init.FrameFormat));
00308   assert_param(IS_FDCAN_MODE(hfdcan->Init.Mode));
00309   assert_param(IS_FUNCTIONAL_STATE(hfdcan->Init.AutoRetransmission));
00310   assert_param(IS_FUNCTIONAL_STATE(hfdcan->Init.TransmitPause));
00311   assert_param(IS_FUNCTIONAL_STATE(hfdcan->Init.ProtocolException));
00312   assert_param(IS_FDCAN_NOMINAL_PRESCALER(hfdcan->Init.NominalPrescaler));
00313   assert_param(IS_FDCAN_NOMINAL_SJW(hfdcan->Init.NominalSyncJumpWidth));
00314   assert_param(IS_FDCAN_NOMINAL_TSEG1(hfdcan->Init.NominalTimeSeg1));
00315   assert_param(IS_FDCAN_NOMINAL_TSEG2(hfdcan->Init.NominalTimeSeg2));
00316   if (hfdcan->Init.FrameFormat == FDCAN_FRAME_FD_BRS)
00317   {
00318     assert_param(IS_FDCAN_DATA_PRESCALER(hfdcan->Init.DataPrescaler));
00319     assert_param(IS_FDCAN_DATA_SJW(hfdcan->Init.DataSyncJumpWidth));
00320     assert_param(IS_FDCAN_DATA_TSEG1(hfdcan->Init.DataTimeSeg1));
00321     assert_param(IS_FDCAN_DATA_TSEG2(hfdcan->Init.DataTimeSeg2));
00322   }
00323   assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.StdFiltersNbr, 128U));
00324   assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.ExtFiltersNbr, 64U));
00325   assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.RxFifo0ElmtsNbr, 64U));
00326   if (hfdcan->Init.RxFifo0ElmtsNbr > 0U)
00327   {
00328     assert_param(IS_FDCAN_DATA_SIZE(hfdcan->Init.RxFifo0ElmtSize));
00329   }
00330   assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.RxFifo1ElmtsNbr, 64U));
00331   if (hfdcan->Init.RxFifo1ElmtsNbr > 0U)
00332   {
00333     assert_param(IS_FDCAN_DATA_SIZE(hfdcan->Init.RxFifo1ElmtSize));
00334   }
00335   assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.RxBuffersNbr, 64U));
00336   if (hfdcan->Init.RxBuffersNbr > 0U)
00337   {
00338     assert_param(IS_FDCAN_DATA_SIZE(hfdcan->Init.RxBufferSize));
00339   }
00340   assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.TxEventsNbr, 32U));
00341   assert_param(IS_FDCAN_MAX_VALUE((hfdcan->Init.TxBuffersNbr + hfdcan->Init.TxFifoQueueElmtsNbr), 32U));
00342   if (hfdcan->Init.TxFifoQueueElmtsNbr > 0U)
00343   {
00344     assert_param(IS_FDCAN_TX_FIFO_QUEUE_MODE(hfdcan->Init.TxFifoQueueMode));
00345   }
00346   if ((hfdcan->Init.TxBuffersNbr + hfdcan->Init.TxFifoQueueElmtsNbr) > 0U)
00347   {
00348     assert_param(IS_FDCAN_DATA_SIZE(hfdcan->Init.TxElmtSize));
00349   }
00350 
00351 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
00352   if (hfdcan->State == HAL_FDCAN_STATE_RESET)
00353   {
00354     /* Allocate lock resource and initialize it */
00355     hfdcan->Lock = HAL_UNLOCKED;
00356 
00357     /* Reset callbacks to legacy functions */
00358     hfdcan->ClockCalibrationCallback    = HAL_FDCAN_ClockCalibrationCallback;    /* Legacy weak ClockCalibrationCallback    */
00359     hfdcan->TxEventFifoCallback         = HAL_FDCAN_TxEventFifoCallback;         /* Legacy weak TxEventFifoCallback         */
00360     hfdcan->RxFifo0Callback             = HAL_FDCAN_RxFifo0Callback;             /* Legacy weak RxFifo0Callback             */
00361     hfdcan->RxFifo1Callback             = HAL_FDCAN_RxFifo1Callback;             /* Legacy weak RxFifo1Callback             */
00362     hfdcan->TxFifoEmptyCallback         = HAL_FDCAN_TxFifoEmptyCallback;         /* Legacy weak TxFifoEmptyCallback         */
00363     hfdcan->TxBufferCompleteCallback    = HAL_FDCAN_TxBufferCompleteCallback;    /* Legacy weak TxBufferCompleteCallback    */
00364     hfdcan->TxBufferAbortCallback       = HAL_FDCAN_TxBufferAbortCallback;       /* Legacy weak TxBufferAbortCallback       */
00365     hfdcan->RxBufferNewMessageCallback  = HAL_FDCAN_RxBufferNewMessageCallback;  /* Legacy weak RxBufferNewMessageCallback  */
00366     hfdcan->HighPriorityMessageCallback = HAL_FDCAN_HighPriorityMessageCallback; /* Legacy weak HighPriorityMessageCallback */
00367     hfdcan->TimestampWraparoundCallback = HAL_FDCAN_TimestampWraparoundCallback; /* Legacy weak TimestampWraparoundCallback */
00368     hfdcan->TimeoutOccurredCallback     = HAL_FDCAN_TimeoutOccurredCallback;     /* Legacy weak TimeoutOccurredCallback     */
00369     hfdcan->ErrorCallback               = HAL_FDCAN_ErrorCallback;               /* Legacy weak ErrorCallback               */
00370     hfdcan->ErrorStatusCallback         = HAL_FDCAN_ErrorStatusCallback;         /* Legacy weak ErrorStatusCallback         */
00371     hfdcan->TT_ScheduleSyncCallback     = HAL_FDCAN_TT_ScheduleSyncCallback;     /* Legacy weak TT_ScheduleSyncCallback     */
00372     hfdcan->TT_TimeMarkCallback         = HAL_FDCAN_TT_TimeMarkCallback;         /* Legacy weak TT_TimeMarkCallback         */
00373     hfdcan->TT_StopWatchCallback        = HAL_FDCAN_TT_StopWatchCallback;        /* Legacy weak TT_StopWatchCallback        */
00374     hfdcan->TT_GlobalTimeCallback       = HAL_FDCAN_TT_GlobalTimeCallback;       /* Legacy weak TT_GlobalTimeCallback       */
00375 
00376     if (hfdcan->MspInitCallback == NULL)
00377     {
00378       hfdcan->MspInitCallback = HAL_FDCAN_MspInit;  /* Legacy weak MspInit */
00379     }
00380 
00381     /* Init the low level hardware: CLOCK, NVIC */
00382     hfdcan->MspInitCallback(hfdcan);
00383   }
00384 #else
00385   if (hfdcan->State == HAL_FDCAN_STATE_RESET)
00386   {
00387     /* Allocate lock resource and initialize it */
00388     hfdcan->Lock = HAL_UNLOCKED;
00389 
00390     /* Init the low level hardware: CLOCK, NVIC */
00391     HAL_FDCAN_MspInit(hfdcan);
00392   }
00393 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
00394 
00395   /* Exit from Sleep mode */
00396   CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CSR);
00397 
00398   /* Get tick */
00399   tickstart = HAL_GetTick();
00400 
00401   /* Check Sleep mode acknowledge */
00402   while ((hfdcan->Instance->CCCR & FDCAN_CCCR_CSA) == FDCAN_CCCR_CSA)
00403   {
00404     if ((HAL_GetTick() - tickstart) > FDCAN_TIMEOUT_VALUE)
00405     {
00406       /* Update error code */
00407       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
00408 
00409       /* Change FDCAN state */
00410       hfdcan->State = HAL_FDCAN_STATE_ERROR;
00411 
00412       return HAL_ERROR;
00413     }
00414   }
00415 
00416   /* Request initialisation */
00417   SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT);
00418 
00419   /* Get tick */
00420   tickstart = HAL_GetTick();
00421 
00422   /* Wait until the INIT bit into CCCR register is set */
00423   while ((hfdcan->Instance->CCCR & FDCAN_CCCR_INIT) == 0U)
00424   {
00425     /* Check for the Timeout */
00426     if ((HAL_GetTick() - tickstart) > FDCAN_TIMEOUT_VALUE)
00427     {
00428       /* Update error code */
00429       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
00430 
00431       /* Change FDCAN state */
00432       hfdcan->State = HAL_FDCAN_STATE_ERROR;
00433 
00434       return HAL_ERROR;
00435     }
00436   }
00437 
00438   /* Enable configuration change */
00439   SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CCE);
00440 
00441   /* Set the no automatic retransmission */
00442   if (hfdcan->Init.AutoRetransmission == ENABLE)
00443   {
00444     CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_DAR);
00445   }
00446   else
00447   {
00448     SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_DAR);
00449   }
00450 
00451   /* Set the transmit pause feature */
00452   if (hfdcan->Init.TransmitPause == ENABLE)
00453   {
00454     SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_TXP);
00455   }
00456   else
00457   {
00458     CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_TXP);
00459   }
00460 
00461   /* Set the Protocol Exception Handling */
00462   if (hfdcan->Init.ProtocolException == ENABLE)
00463   {
00464     CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_PXHD);
00465   }
00466   else
00467   {
00468     SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_PXHD);
00469   }
00470 
00471   /* Set FDCAN Frame Format */
00472   MODIFY_REG(hfdcan->Instance->CCCR, FDCAN_FRAME_FD_BRS, hfdcan->Init.FrameFormat);
00473 
00474   /* Reset FDCAN Operation Mode */
00475   CLEAR_BIT(hfdcan->Instance->CCCR, (FDCAN_CCCR_TEST | FDCAN_CCCR_MON | FDCAN_CCCR_ASM));
00476   CLEAR_BIT(hfdcan->Instance->TEST, FDCAN_TEST_LBCK);
00477 
00478   /* Set FDCAN Operating Mode:
00479                | Normal | Restricted |    Bus     | Internal | External
00480                |        | Operation  | Monitoring | LoopBack | LoopBack
00481      CCCR.TEST |   0    |     0      |     0      |    1     |    1
00482      CCCR.MON  |   0    |     0      |     1      |    1     |    0
00483      TEST.LBCK |   0    |     0      |     0      |    1     |    1
00484      CCCR.ASM  |   0    |     1      |     0      |    0     |    0
00485   */
00486   if (hfdcan->Init.Mode == FDCAN_MODE_RESTRICTED_OPERATION)
00487   {
00488     /* Enable Restricted Operation mode */
00489     SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_ASM);
00490   }
00491   else if (hfdcan->Init.Mode != FDCAN_MODE_NORMAL)
00492   {
00493     if (hfdcan->Init.Mode != FDCAN_MODE_BUS_MONITORING)
00494     {
00495       /* Enable write access to TEST register */
00496       SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_TEST);
00497 
00498       /* Enable LoopBack mode */
00499       SET_BIT(hfdcan->Instance->TEST, FDCAN_TEST_LBCK);
00500 
00501       if (hfdcan->Init.Mode == FDCAN_MODE_INTERNAL_LOOPBACK)
00502       {
00503         SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_MON);
00504       }
00505     }
00506     else
00507     {
00508       /* Enable bus monitoring mode */
00509       SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_MON);
00510     }
00511   }
00512   else
00513   {
00514     /* Nothing to do: normal mode */
00515   }
00516 
00517   /* Set the nominal bit timing register */
00518   hfdcan->Instance->NBTP = ((((uint32_t)hfdcan->Init.NominalSyncJumpWidth - 1U) << FDCAN_NBTP_NSJW_Pos) | \
00519                             (((uint32_t)hfdcan->Init.NominalTimeSeg1 - 1U) << FDCAN_NBTP_NTSEG1_Pos)    | \
00520                             (((uint32_t)hfdcan->Init.NominalTimeSeg2 - 1U) << FDCAN_NBTP_NTSEG2_Pos)    | \
00521                             (((uint32_t)hfdcan->Init.NominalPrescaler - 1U) << FDCAN_NBTP_NBRP_Pos));
00522 
00523   /* If FD operation with BRS is selected, set the data bit timing register */
00524   if (hfdcan->Init.FrameFormat == FDCAN_FRAME_FD_BRS)
00525   {
00526     hfdcan->Instance->DBTP = ((((uint32_t)hfdcan->Init.DataSyncJumpWidth - 1U) << FDCAN_DBTP_DSJW_Pos) | \
00527                               (((uint32_t)hfdcan->Init.DataTimeSeg1 - 1U) << FDCAN_DBTP_DTSEG1_Pos)    | \
00528                               (((uint32_t)hfdcan->Init.DataTimeSeg2 - 1U) << FDCAN_DBTP_DTSEG2_Pos)    | \
00529                               (((uint32_t)hfdcan->Init.DataPrescaler - 1U) << FDCAN_DBTP_DBRP_Pos));
00530   }
00531 
00532   if (hfdcan->Init.TxFifoQueueElmtsNbr > 0U)
00533   {
00534     /* Select between Tx FIFO and Tx Queue operation modes */
00535     SET_BIT(hfdcan->Instance->TXBC, hfdcan->Init.TxFifoQueueMode);
00536   }
00537 
00538   /* Configure Tx element size */
00539   if ((hfdcan->Init.TxBuffersNbr + hfdcan->Init.TxFifoQueueElmtsNbr) > 0U)
00540   {
00541     MODIFY_REG(hfdcan->Instance->TXESC, FDCAN_TXESC_TBDS, CvtEltSize[hfdcan->Init.TxElmtSize]);
00542   }
00543 
00544   /* Configure Rx FIFO 0 element size */
00545   if (hfdcan->Init.RxFifo0ElmtsNbr > 0U)
00546   {
00547     MODIFY_REG(hfdcan->Instance->RXESC, FDCAN_RXESC_F0DS, (CvtEltSize[hfdcan->Init.RxFifo0ElmtSize] << FDCAN_RXESC_F0DS_Pos));
00548   }
00549 
00550   /* Configure Rx FIFO 1 element size */
00551   if (hfdcan->Init.RxFifo1ElmtsNbr > 0U)
00552   {
00553     MODIFY_REG(hfdcan->Instance->RXESC, FDCAN_RXESC_F1DS, (CvtEltSize[hfdcan->Init.RxFifo1ElmtSize] << FDCAN_RXESC_F1DS_Pos));
00554   }
00555 
00556   /* Configure Rx buffer element size */
00557   if (hfdcan->Init.RxBuffersNbr > 0U)
00558   {
00559     MODIFY_REG(hfdcan->Instance->RXESC, FDCAN_RXESC_RBDS, (CvtEltSize[hfdcan->Init.RxBufferSize] << FDCAN_RXESC_RBDS_Pos));
00560   }
00561 
00562   /* By default operation mode is set to Event-driven communication.
00563      If Time-triggered communication is needed, user should call the
00564      HAL_FDCAN_TT_ConfigOperation function just after the HAL_FDCAN_Init */
00565   if (hfdcan->Instance == FDCAN1)
00566   {
00567     CLEAR_BIT(hfdcan->ttcan->TTOCF, FDCAN_TTOCF_OM);
00568   }
00569 
00570   /* Initialize the Latest Tx FIFO/Queue request buffer index */
00571   hfdcan->LatestTxFifoQRequest = 0U;
00572 
00573   /* Initialize the error code */
00574   hfdcan->ErrorCode = HAL_FDCAN_ERROR_NONE;
00575 
00576   /* Initialize the FDCAN state */
00577   hfdcan->State = HAL_FDCAN_STATE_READY;
00578 
00579   /* Calculate each RAM block address */
00580   status = FDCAN_CalcultateRamBlockAddresses(hfdcan);
00581 
00582   /* Return function status */
00583   return status;
00584 }
00585 
00586 /**
00587   * @brief  Deinitializes the FDCAN peripheral registers to their default reset values.
00588   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
00589   *         the configuration information for the specified FDCAN.
00590   * @retval HAL status
00591   */
00592 HAL_StatusTypeDef HAL_FDCAN_DeInit(FDCAN_HandleTypeDef *hfdcan)
00593 {
00594   /* Check FDCAN handle */
00595   if (hfdcan == NULL)
00596   {
00597     return HAL_ERROR;
00598   }
00599 
00600   /* Check function parameters */
00601   assert_param(IS_FDCAN_ALL_INSTANCE(hfdcan->Instance));
00602 
00603   /* Stop the FDCAN module: return value is voluntary ignored */
00604   (void)HAL_FDCAN_Stop(hfdcan);
00605 
00606   /* Disable Interrupt lines */
00607   CLEAR_BIT(hfdcan->Instance->ILE, (FDCAN_INTERRUPT_LINE0 | FDCAN_INTERRUPT_LINE1));
00608 
00609 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
00610   if (hfdcan->MspDeInitCallback == NULL)
00611   {
00612     hfdcan->MspDeInitCallback = HAL_FDCAN_MspDeInit; /* Legacy weak MspDeInit */
00613   }
00614 
00615   /* DeInit the low level hardware: CLOCK, NVIC */
00616   hfdcan->MspDeInitCallback(hfdcan);
00617 #else
00618   /* DeInit the low level hardware: CLOCK, NVIC */
00619   HAL_FDCAN_MspDeInit(hfdcan);
00620 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
00621 
00622   /* Reset the FDCAN ErrorCode */
00623   hfdcan->ErrorCode = HAL_FDCAN_ERROR_NONE;
00624 
00625   /* Change FDCAN state */
00626   hfdcan->State = HAL_FDCAN_STATE_RESET;
00627 
00628   /* Return function status */
00629   return HAL_OK;
00630 }
00631 
00632 /**
00633   * @brief  Initializes the FDCAN MSP.
00634   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
00635   *         the configuration information for the specified FDCAN.
00636   * @retval None
00637   */
00638 __weak void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *hfdcan)
00639 {
00640   /* Prevent unused argument(s) compilation warning */
00641   UNUSED(hfdcan);
00642   /* NOTE : This function Should not be modified, when the callback is needed,
00643             the HAL_FDCAN_MspInit could be implemented in the user file
00644    */
00645 }
00646 
00647 /**
00648   * @brief  DeInitializes the FDCAN MSP.
00649   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
00650   *         the configuration information for the specified FDCAN.
00651   * @retval None
00652   */
00653 __weak void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *hfdcan)
00654 {
00655   /* Prevent unused argument(s) compilation warning */
00656   UNUSED(hfdcan);
00657   /* NOTE : This function Should not be modified, when the callback is needed,
00658             the HAL_FDCAN_MspDeInit could be implemented in the user file
00659    */
00660 }
00661 
00662 /**
00663   * @brief  Enter FDCAN peripheral in sleep mode.
00664   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
00665   *         the configuration information for the specified FDCAN.
00666   * @retval HAL status
00667   */
00668 HAL_StatusTypeDef HAL_FDCAN_EnterPowerDownMode(FDCAN_HandleTypeDef *hfdcan)
00669 {
00670   uint32_t tickstart;
00671 
00672   /* Request clock stop */
00673   SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CSR);
00674 
00675   /* Get tick */
00676   tickstart = HAL_GetTick();
00677 
00678   /* Wait until FDCAN is ready for power down */
00679   while ((hfdcan->Instance->CCCR & FDCAN_CCCR_CSA) == 0U)
00680   {
00681     if ((HAL_GetTick() - tickstart) > FDCAN_TIMEOUT_VALUE)
00682     {
00683       /* Update error code */
00684       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
00685 
00686       /* Change FDCAN state */
00687       hfdcan->State = HAL_FDCAN_STATE_ERROR;
00688 
00689       return HAL_ERROR;
00690     }
00691   }
00692 
00693   /* Return function status */
00694   return HAL_OK;
00695 }
00696 
00697 /**
00698   * @brief  Exit power down mode.
00699   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
00700   *         the configuration information for the specified FDCAN.
00701   * @retval HAL status
00702   */
00703 HAL_StatusTypeDef HAL_FDCAN_ExitPowerDownMode(FDCAN_HandleTypeDef *hfdcan)
00704 {
00705   uint32_t tickstart;
00706 
00707   /* Reset clock stop request */
00708   CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CSR);
00709 
00710   /* Get tick */
00711   tickstart = HAL_GetTick();
00712 
00713   /* Wait until FDCAN exits sleep mode */
00714   while ((hfdcan->Instance->CCCR & FDCAN_CCCR_CSA) == FDCAN_CCCR_CSA)
00715   {
00716     if ((HAL_GetTick() - tickstart) > FDCAN_TIMEOUT_VALUE)
00717     {
00718       /* Update error code */
00719       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
00720 
00721       /* Change FDCAN state */
00722       hfdcan->State = HAL_FDCAN_STATE_ERROR;
00723 
00724       return HAL_ERROR;
00725     }
00726   }
00727 
00728   /* Enter normal operation */
00729   CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT);
00730 
00731   /* Return function status */
00732   return HAL_OK;
00733 }
00734 
00735 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
00736 /**
00737   * @brief  Register a FDCAN CallBack.
00738   *         To be used instead of the weak predefined callback
00739   * @param  hfdcan pointer to a FDCAN_HandleTypeDef structure that contains
00740   *         the configuration information for FDCAN module
00741   * @param  CallbackID ID of the callback to be registered
00742   *         This parameter can be one of the following values:
00743   *           @arg @ref HAL_FDCAN_TX_FIFO_EMPTY_CB_ID Tx Fifo Empty callback ID
00744   *           @arg @ref HAL_FDCAN_RX_BUFFER_NEW_MSG_CB_ID Rx buffer new message callback ID
00745   *           @arg @ref HAL_FDCAN_HIGH_PRIO_MESSAGE_CB_ID High priority message callback ID
00746   *           @arg @ref HAL_FDCAN_TIMESTAMP_WRAPAROUND_CB_ID Timestamp wraparound callback ID
00747   *           @arg @ref HAL_FDCAN_TIMEOUT_OCCURRED_CB_ID Timeout occurred callback ID
00748   *           @arg @ref HAL_FDCAN_ERROR_CALLBACK_CB_ID Error callback ID
00749   *           @arg @ref HAL_FDCAN_MSPINIT_CB_ID MspInit callback ID
00750   *           @arg @ref HAL_FDCAN_MSPDEINIT_CB_ID MspDeInit callback ID
00751   * @param  pCallback pointer to the Callback function
00752   * @retval HAL status
00753   */
00754 HAL_StatusTypeDef HAL_FDCAN_RegisterCallback(FDCAN_HandleTypeDef *hfdcan, HAL_FDCAN_CallbackIDTypeDef CallbackID, void (* pCallback)(FDCAN_HandleTypeDef *_hFDCAN))
00755 {
00756   HAL_StatusTypeDef status = HAL_OK;
00757 
00758   if (pCallback == NULL)
00759   {
00760     /* Update the error code */
00761     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
00762 
00763     return HAL_ERROR;
00764   }
00765 
00766   if (hfdcan->State == HAL_FDCAN_STATE_READY)
00767   {
00768     switch (CallbackID)
00769     {
00770       case HAL_FDCAN_TX_FIFO_EMPTY_CB_ID :
00771         hfdcan->TxFifoEmptyCallback = pCallback;
00772         break;
00773 
00774       case HAL_FDCAN_RX_BUFFER_NEW_MSG_CB_ID :
00775         hfdcan->RxBufferNewMessageCallback = pCallback;
00776         break;
00777 
00778       case HAL_FDCAN_HIGH_PRIO_MESSAGE_CB_ID :
00779         hfdcan->HighPriorityMessageCallback = pCallback;
00780         break;
00781 
00782       case HAL_FDCAN_TIMESTAMP_WRAPAROUND_CB_ID :
00783         hfdcan->TimestampWraparoundCallback = pCallback;
00784         break;
00785 
00786       case HAL_FDCAN_TIMEOUT_OCCURRED_CB_ID :
00787         hfdcan->TimeoutOccurredCallback = pCallback;
00788         break;
00789 
00790       case HAL_FDCAN_ERROR_CALLBACK_CB_ID :
00791         hfdcan->ErrorCallback = pCallback;
00792         break;
00793 
00794       case HAL_FDCAN_MSPINIT_CB_ID :
00795         hfdcan->MspInitCallback = pCallback;
00796         break;
00797 
00798       case HAL_FDCAN_MSPDEINIT_CB_ID :
00799         hfdcan->MspDeInitCallback = pCallback;
00800         break;
00801 
00802       default :
00803         /* Update the error code */
00804         hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
00805 
00806         /* Return error status */
00807         status =  HAL_ERROR;
00808         break;
00809     }
00810   }
00811   else if (hfdcan->State == HAL_FDCAN_STATE_RESET)
00812   {
00813     switch (CallbackID)
00814     {
00815       case HAL_FDCAN_MSPINIT_CB_ID :
00816         hfdcan->MspInitCallback = pCallback;
00817         break;
00818 
00819       case HAL_FDCAN_MSPDEINIT_CB_ID :
00820         hfdcan->MspDeInitCallback = pCallback;
00821         break;
00822 
00823       default :
00824         /* Update the error code */
00825         hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
00826 
00827         /* Return error status */
00828         status =  HAL_ERROR;
00829         break;
00830     }
00831   }
00832   else
00833   {
00834     /* Update the error code */
00835     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
00836 
00837     /* Return error status */
00838     status =  HAL_ERROR;
00839   }
00840 
00841   return status;
00842 }
00843 
00844 /**
00845   * @brief  Unregister a FDCAN CallBack.
00846   *         FDCAN callback is redirected to the weak predefined callback
00847   * @param  hfdcan pointer to a FDCAN_HandleTypeDef structure that contains
00848   *         the configuration information for FDCAN module
00849   * @param  CallbackID ID of the callback to be unregistered
00850   *         This parameter can be one of the following values:
00851   *           @arg @ref HAL_FDCAN_TX_FIFO_EMPTY_CB_ID Tx Fifo Empty callback ID
00852   *           @arg @ref HAL_FDCAN_RX_BUFFER_NEW_MSG_CB_ID Rx buffer new message callback ID
00853   *           @arg @ref HAL_FDCAN_HIGH_PRIO_MESSAGE_CB_ID High priority message callback ID
00854   *           @arg @ref HAL_FDCAN_TIMESTAMP_WRAPAROUND_CB_ID Timestamp wraparound callback ID
00855   *           @arg @ref HAL_FDCAN_TIMEOUT_OCCURRED_CB_ID Timeout occurred callback ID
00856   *           @arg @ref HAL_FDCAN_ERROR_CALLBACK_CB_ID Error callback ID
00857   *           @arg @ref HAL_FDCAN_MSPINIT_CB_ID MspInit callback ID
00858   *           @arg @ref HAL_FDCAN_MSPDEINIT_CB_ID MspDeInit callback ID
00859   * @retval HAL status
00860   */
00861 HAL_StatusTypeDef HAL_FDCAN_UnRegisterCallback(FDCAN_HandleTypeDef *hfdcan, HAL_FDCAN_CallbackIDTypeDef CallbackID)
00862 {
00863   HAL_StatusTypeDef status = HAL_OK;
00864 
00865   if (hfdcan->State == HAL_FDCAN_STATE_READY)
00866   {
00867     switch (CallbackID)
00868     {
00869       case HAL_FDCAN_TX_FIFO_EMPTY_CB_ID :
00870         hfdcan->TxFifoEmptyCallback = HAL_FDCAN_TxFifoEmptyCallback;
00871         break;
00872 
00873       case HAL_FDCAN_RX_BUFFER_NEW_MSG_CB_ID :
00874         hfdcan->RxBufferNewMessageCallback = HAL_FDCAN_RxBufferNewMessageCallback;
00875         break;
00876 
00877       case HAL_FDCAN_HIGH_PRIO_MESSAGE_CB_ID :
00878         hfdcan->HighPriorityMessageCallback = HAL_FDCAN_HighPriorityMessageCallback;
00879         break;
00880 
00881       case HAL_FDCAN_TIMESTAMP_WRAPAROUND_CB_ID :
00882         hfdcan->TimestampWraparoundCallback = HAL_FDCAN_TimestampWraparoundCallback;
00883         break;
00884 
00885       case HAL_FDCAN_TIMEOUT_OCCURRED_CB_ID :
00886         hfdcan->TimeoutOccurredCallback = HAL_FDCAN_TimeoutOccurredCallback;
00887         break;
00888 
00889       case HAL_FDCAN_ERROR_CALLBACK_CB_ID :
00890         hfdcan->ErrorCallback = HAL_FDCAN_ErrorCallback;
00891         break;
00892 
00893       case HAL_FDCAN_MSPINIT_CB_ID :
00894         hfdcan->MspInitCallback = HAL_FDCAN_MspInit;
00895         break;
00896 
00897       case HAL_FDCAN_MSPDEINIT_CB_ID :
00898         hfdcan->MspDeInitCallback = HAL_FDCAN_MspDeInit;
00899         break;
00900 
00901       default :
00902         /* Update the error code */
00903         hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
00904 
00905         /* Return error status */
00906         status =  HAL_ERROR;
00907         break;
00908     }
00909   }
00910   else if (hfdcan->State == HAL_FDCAN_STATE_RESET)
00911   {
00912     switch (CallbackID)
00913     {
00914       case HAL_FDCAN_MSPINIT_CB_ID :
00915         hfdcan->MspInitCallback = HAL_FDCAN_MspInit;
00916         break;
00917 
00918       case HAL_FDCAN_MSPDEINIT_CB_ID :
00919         hfdcan->MspDeInitCallback = HAL_FDCAN_MspDeInit;
00920         break;
00921 
00922       default :
00923         /* Update the error code */
00924         hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
00925 
00926         /* Return error status */
00927         status =  HAL_ERROR;
00928         break;
00929     }
00930   }
00931   else
00932   {
00933     /* Update the error code */
00934     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
00935 
00936     /* Return error status */
00937     status =  HAL_ERROR;
00938   }
00939 
00940   return status;
00941 }
00942 
00943 /**
00944   * @brief  Register Clock Calibration FDCAN Callback
00945   *         To be used instead of the weak HAL_FDCAN_ClockCalibrationCallback() predefined callback
00946   * @param  hfdcan FDCAN handle
00947   * @param  pCallback pointer to the Clock Calibration Callback function
00948   * @retval HAL status
00949   */
00950 HAL_StatusTypeDef HAL_FDCAN_RegisterClockCalibrationCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_ClockCalibrationCallbackTypeDef pCallback)
00951 {
00952   HAL_StatusTypeDef status = HAL_OK;
00953 
00954   if (pCallback == NULL)
00955   {
00956     /* Update the error code */
00957     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
00958     return HAL_ERROR;
00959   }
00960 
00961   if (hfdcan->State == HAL_FDCAN_STATE_READY)
00962   {
00963     hfdcan->ClockCalibrationCallback = pCallback;
00964   }
00965   else
00966   {
00967     /* Update the error code */
00968     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
00969 
00970     /* Return error status */
00971     status =  HAL_ERROR;
00972   }
00973 
00974   return status;
00975 }
00976 
00977 /**
00978   * @brief  UnRegister the Clock Calibration FDCAN Callback
00979   *         Clock Calibration FDCAN Callback is redirected to the weak HAL_FDCAN_ClockCalibrationCallback() predefined callback
00980   * @param  hfdcan FDCAN handle
00981   * @retval HAL status
00982   */
00983 HAL_StatusTypeDef HAL_FDCAN_UnRegisterClockCalibrationCallback(FDCAN_HandleTypeDef *hfdcan)
00984 {
00985   HAL_StatusTypeDef status = HAL_OK;
00986 
00987   if (hfdcan->State == HAL_FDCAN_STATE_READY)
00988   {
00989     hfdcan->ClockCalibrationCallback = HAL_FDCAN_ClockCalibrationCallback; /* Legacy weak ClockCalibrationCallback  */
00990   }
00991   else
00992   {
00993     /* Update the error code */
00994     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
00995 
00996     /* Return error status */
00997     status =  HAL_ERROR;
00998   }
00999 
01000   return status;
01001 }
01002 
01003 /**
01004   * @brief  Register Tx Event Fifo FDCAN Callback
01005   *         To be used instead of the weak HAL_FDCAN_TxEventFifoCallback() predefined callback
01006   * @param  hfdcan FDCAN handle
01007   * @param  pCallback pointer to the Tx Event Fifo Callback function
01008   * @retval HAL status
01009   */
01010 HAL_StatusTypeDef HAL_FDCAN_RegisterTxEventFifoCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_TxEventFifoCallbackTypeDef pCallback)
01011 {
01012   HAL_StatusTypeDef status = HAL_OK;
01013 
01014   if (pCallback == NULL)
01015   {
01016     /* Update the error code */
01017     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01018     return HAL_ERROR;
01019   }
01020 
01021   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01022   {
01023     hfdcan->TxEventFifoCallback = pCallback;
01024   }
01025   else
01026   {
01027     /* Update the error code */
01028     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01029 
01030     /* Return error status */
01031     status =  HAL_ERROR;
01032   }
01033 
01034   return status;
01035 }
01036 
01037 /**
01038   * @brief  UnRegister the Tx Event Fifo FDCAN Callback
01039   *         Tx Event Fifo FDCAN Callback is redirected to the weak HAL_FDCAN_TxEventFifoCallback() predefined callback
01040   * @param  hfdcan FDCAN handle
01041   * @retval HAL status
01042   */
01043 HAL_StatusTypeDef HAL_FDCAN_UnRegisterTxEventFifoCallback(FDCAN_HandleTypeDef *hfdcan)
01044 {
01045   HAL_StatusTypeDef status = HAL_OK;
01046 
01047   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01048   {
01049     hfdcan->TxEventFifoCallback = HAL_FDCAN_TxEventFifoCallback; /* Legacy weak TxEventFifoCallback  */
01050   }
01051   else
01052   {
01053     /* Update the error code */
01054     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01055 
01056     /* Return error status */
01057     status =  HAL_ERROR;
01058   }
01059 
01060   return status;
01061 }
01062 
01063 /**
01064   * @brief  Register Rx Fifo 0 FDCAN Callback
01065   *         To be used instead of the weak HAL_FDCAN_RxFifo0Callback() predefined callback
01066   * @param  hfdcan FDCAN handle
01067   * @param  pCallback pointer to the Rx Fifo 0 Callback function
01068   * @retval HAL status
01069   */
01070 HAL_StatusTypeDef HAL_FDCAN_RegisterRxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_RxFifo0CallbackTypeDef pCallback)
01071 {
01072   HAL_StatusTypeDef status = HAL_OK;
01073 
01074   if (pCallback == NULL)
01075   {
01076     /* Update the error code */
01077     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01078     return HAL_ERROR;
01079   }
01080 
01081   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01082   {
01083     hfdcan->RxFifo0Callback = pCallback;
01084   }
01085   else
01086   {
01087     /* Update the error code */
01088     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01089 
01090     /* Return error status */
01091     status =  HAL_ERROR;
01092   }
01093 
01094   return status;
01095 }
01096 
01097 /**
01098   * @brief  UnRegister the Rx Fifo 0 FDCAN Callback
01099   *         Rx Fifo 0 FDCAN Callback is redirected to the weak HAL_FDCAN_RxFifo0Callback() predefined callback
01100   * @param  hfdcan FDCAN handle
01101   * @retval HAL status
01102   */
01103 HAL_StatusTypeDef HAL_FDCAN_UnRegisterRxFifo0Callback(FDCAN_HandleTypeDef *hfdcan)
01104 {
01105   HAL_StatusTypeDef status = HAL_OK;
01106 
01107   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01108   {
01109     hfdcan->RxFifo0Callback = HAL_FDCAN_RxFifo0Callback; /* Legacy weak RxFifo0Callback  */
01110   }
01111   else
01112   {
01113     /* Update the error code */
01114     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01115 
01116     /* Return error status */
01117     status =  HAL_ERROR;
01118   }
01119 
01120   return status;
01121 }
01122 
01123 /**
01124   * @brief  Register Rx Fifo 1 FDCAN Callback
01125   *         To be used instead of the weak HAL_FDCAN_RxFifo1Callback() predefined callback
01126   * @param  hfdcan FDCAN handle
01127   * @param  pCallback pointer to the Rx Fifo 1 Callback function
01128   * @retval HAL status
01129   */
01130 HAL_StatusTypeDef HAL_FDCAN_RegisterRxFifo1Callback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_RxFifo1CallbackTypeDef pCallback)
01131 {
01132   HAL_StatusTypeDef status = HAL_OK;
01133 
01134   if (pCallback == NULL)
01135   {
01136     /* Update the error code */
01137     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01138     return HAL_ERROR;
01139   }
01140 
01141   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01142   {
01143     hfdcan->RxFifo1Callback = pCallback;
01144   }
01145   else
01146   {
01147     /* Update the error code */
01148     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01149 
01150     /* Return error status */
01151     status =  HAL_ERROR;
01152   }
01153 
01154   return status;
01155 }
01156 
01157 /**
01158   * @brief  UnRegister the Rx Fifo 1 FDCAN Callback
01159   *         Rx Fifo 1 FDCAN Callback is redirected to the weak HAL_FDCAN_RxFifo1Callback() predefined callback
01160   * @param  hfdcan FDCAN handle
01161   * @retval HAL status
01162   */
01163 HAL_StatusTypeDef HAL_FDCAN_UnRegisterRxFifo1Callback(FDCAN_HandleTypeDef *hfdcan)
01164 {
01165   HAL_StatusTypeDef status = HAL_OK;
01166 
01167   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01168   {
01169     hfdcan->RxFifo1Callback = HAL_FDCAN_RxFifo1Callback; /* Legacy weak RxFifo1Callback  */
01170   }
01171   else
01172   {
01173     /* Update the error code */
01174     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01175 
01176     /* Return error status */
01177     status =  HAL_ERROR;
01178   }
01179 
01180   return status;
01181 }
01182 
01183 /**
01184   * @brief  Register Tx Buffer Complete FDCAN Callback
01185   *         To be used instead of the weak HAL_FDCAN_TxBufferCompleteCallback() predefined callback
01186   * @param  hfdcan FDCAN handle
01187   * @param  pCallback pointer to the Tx Buffer Complete Callback function
01188   * @retval HAL status
01189   */
01190 HAL_StatusTypeDef HAL_FDCAN_RegisterTxBufferCompleteCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_TxBufferCompleteCallbackTypeDef pCallback)
01191 {
01192   HAL_StatusTypeDef status = HAL_OK;
01193 
01194   if (pCallback == NULL)
01195   {
01196     /* Update the error code */
01197     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01198     return HAL_ERROR;
01199   }
01200 
01201   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01202   {
01203     hfdcan->TxBufferCompleteCallback = pCallback;
01204   }
01205   else
01206   {
01207     /* Update the error code */
01208     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01209 
01210     /* Return error status */
01211     status =  HAL_ERROR;
01212   }
01213 
01214   return status;
01215 }
01216 
01217 /**
01218   * @brief  UnRegister the Tx Buffer Complete FDCAN Callback
01219   *         Tx Buffer Complete FDCAN Callback is redirected to the weak HAL_FDCAN_TxBufferCompleteCallback() predefined callback
01220   * @param  hfdcan FDCAN handle
01221   * @retval HAL status
01222   */
01223 HAL_StatusTypeDef HAL_FDCAN_UnRegisterTxBufferCompleteCallback(FDCAN_HandleTypeDef *hfdcan)
01224 {
01225   HAL_StatusTypeDef status = HAL_OK;
01226 
01227   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01228   {
01229     hfdcan->TxBufferCompleteCallback = HAL_FDCAN_TxBufferCompleteCallback; /* Legacy weak TxBufferCompleteCallback  */
01230   }
01231   else
01232   {
01233     /* Update the error code */
01234     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01235 
01236     /* Return error status */
01237     status =  HAL_ERROR;
01238   }
01239 
01240   return status;
01241 }
01242 
01243 /**
01244   * @brief  Register Tx Buffer Abort FDCAN Callback
01245   *         To be used instead of the weak HAL_FDCAN_TxBufferAbortCallback() predefined callback
01246   * @param  hfdcan FDCAN handle
01247   * @param  pCallback pointer to the Tx Buffer Abort Callback function
01248   * @retval HAL status
01249   */
01250 HAL_StatusTypeDef HAL_FDCAN_RegisterTxBufferAbortCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_TxBufferAbortCallbackTypeDef pCallback)
01251 {
01252   HAL_StatusTypeDef status = HAL_OK;
01253 
01254   if (pCallback == NULL)
01255   {
01256     /* Update the error code */
01257     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01258     return HAL_ERROR;
01259   }
01260 
01261   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01262   {
01263     hfdcan->TxBufferAbortCallback = pCallback;
01264   }
01265   else
01266   {
01267     /* Update the error code */
01268     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01269 
01270     /* Return error status */
01271     status =  HAL_ERROR;
01272   }
01273 
01274   return status;
01275 }
01276 
01277 /**
01278   * @brief  UnRegister the Tx Buffer Abort FDCAN Callback
01279   *         Tx Buffer Abort FDCAN Callback is redirected to the weak HAL_FDCAN_TxBufferAbortCallback() predefined callback
01280   * @param  hfdcan FDCAN handle
01281   * @retval HAL status
01282   */
01283 HAL_StatusTypeDef HAL_FDCAN_UnRegisterTxBufferAbortCallback(FDCAN_HandleTypeDef *hfdcan)
01284 {
01285   HAL_StatusTypeDef status = HAL_OK;
01286 
01287   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01288   {
01289     hfdcan->TxBufferAbortCallback = HAL_FDCAN_TxBufferAbortCallback; /* Legacy weak TxBufferAbortCallback  */
01290   }
01291   else
01292   {
01293     /* Update the error code */
01294     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01295 
01296     /* Return error status */
01297     status =  HAL_ERROR;
01298   }
01299 
01300   return status;
01301 }
01302 
01303 /**
01304   * @brief  Register Error Status FDCAN Callback
01305   *         To be used instead of the weak HAL_FDCAN_ErrorStatusCallback() predefined callback
01306   * @param  hfdcan FDCAN handle
01307   * @param  pCallback pointer to the Error Status Callback function
01308   * @retval HAL status
01309   */
01310 HAL_StatusTypeDef HAL_FDCAN_RegisterErrorStatusCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_ErrorStatusCallbackTypeDef pCallback)
01311 {
01312   HAL_StatusTypeDef status = HAL_OK;
01313 
01314   if (pCallback == NULL)
01315   {
01316     /* Update the error code */
01317     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01318     return HAL_ERROR;
01319   }
01320 
01321   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01322   {
01323     hfdcan->ErrorStatusCallback = pCallback;
01324   }
01325   else
01326   {
01327     /* Update the error code */
01328     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01329 
01330     /* Return error status */
01331     status =  HAL_ERROR;
01332   }
01333 
01334   return status;
01335 }
01336 
01337 /**
01338   * @brief  UnRegister the Error Status FDCAN Callback
01339   *         Error Status FDCAN Callback is redirected to the weak HAL_FDCAN_ErrorStatusCallback() predefined callback
01340   * @param  hfdcan FDCAN handle
01341   * @retval HAL status
01342   */
01343 HAL_StatusTypeDef HAL_FDCAN_UnRegisterErrorStatusCallback(FDCAN_HandleTypeDef *hfdcan)
01344 {
01345   HAL_StatusTypeDef status = HAL_OK;
01346 
01347   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01348   {
01349     hfdcan->ErrorStatusCallback = HAL_FDCAN_ErrorStatusCallback; /* Legacy weak ErrorStatusCallback  */
01350   }
01351   else
01352   {
01353     /* Update the error code */
01354     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01355 
01356     /* Return error status */
01357     status =  HAL_ERROR;
01358   }
01359 
01360   return status;
01361 }
01362 
01363 /**
01364   * @brief  Register TT Schedule Synchronization FDCAN Callback
01365   *         To be used instead of the weak HAL_FDCAN_TT_ScheduleSyncCallback() predefined callback
01366   * @param  hfdcan FDCAN handle
01367   * @param  pCallback pointer to the TT Schedule Synchronization Callback function
01368   * @retval HAL status
01369   */
01370 HAL_StatusTypeDef HAL_FDCAN_RegisterTTScheduleSyncCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_TT_ScheduleSyncCallbackTypeDef pCallback)
01371 {
01372   HAL_StatusTypeDef status = HAL_OK;
01373 
01374   if (pCallback == NULL)
01375   {
01376     /* Update the error code */
01377     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01378     return HAL_ERROR;
01379   }
01380 
01381   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01382   {
01383     hfdcan->TT_ScheduleSyncCallback = pCallback;
01384   }
01385   else
01386   {
01387     /* Update the error code */
01388     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01389 
01390     /* Return error status */
01391     status =  HAL_ERROR;
01392   }
01393 
01394   return status;
01395 }
01396 
01397 /**
01398   * @brief  UnRegister the TT Schedule Synchronization FDCAN Callback
01399   *         TT Schedule Synchronization Callback is redirected to the weak HAL_FDCAN_TT_ScheduleSyncCallback() predefined callback
01400   * @param  hfdcan FDCAN handle
01401   * @retval HAL status
01402   */
01403 HAL_StatusTypeDef HAL_FDCAN_UnRegisterTTScheduleSyncCallback(FDCAN_HandleTypeDef *hfdcan)
01404 {
01405   HAL_StatusTypeDef status = HAL_OK;
01406 
01407   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01408   {
01409     hfdcan->TT_ScheduleSyncCallback = HAL_FDCAN_TT_ScheduleSyncCallback; /* Legacy weak TT_ScheduleSyncCallback  */
01410   }
01411   else
01412   {
01413     /* Update the error code */
01414     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01415 
01416     /* Return error status */
01417     status =  HAL_ERROR;
01418   }
01419 
01420   return status;
01421 }
01422 
01423 /**
01424   * @brief  Register TT Time Mark FDCAN Callback
01425   *         To be used instead of the weak HAL_FDCAN_TT_TimeMarkCallback() predefined callback
01426   * @param  hfdcan FDCAN handle
01427   * @param  pCallback pointer to the TT Time Mark Callback function
01428   * @retval HAL status
01429   */
01430 HAL_StatusTypeDef HAL_FDCAN_RegisterTTTimeMarkCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_TT_TimeMarkCallbackTypeDef pCallback)
01431 {
01432   HAL_StatusTypeDef status = HAL_OK;
01433 
01434   if (pCallback == NULL)
01435   {
01436     /* Update the error code */
01437     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01438     return HAL_ERROR;
01439   }
01440 
01441   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01442   {
01443     hfdcan->TT_TimeMarkCallback = pCallback;
01444   }
01445   else
01446   {
01447     /* Update the error code */
01448     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01449 
01450     /* Return error status */
01451     status =  HAL_ERROR;
01452   }
01453 
01454   return status;
01455 }
01456 
01457 /**
01458   * @brief  UnRegister the TT Time Mark FDCAN Callback
01459   *         TT Time Mark Callback is redirected to the weak HAL_FDCAN_TT_TimeMarkCallback() predefined callback
01460   * @param  hfdcan FDCAN handle
01461   * @retval HAL status
01462   */
01463 HAL_StatusTypeDef HAL_FDCAN_UnRegisterTTTimeMarkCallback(FDCAN_HandleTypeDef *hfdcan)
01464 {
01465   HAL_StatusTypeDef status = HAL_OK;
01466 
01467   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01468   {
01469     hfdcan->TT_TimeMarkCallback = HAL_FDCAN_TT_TimeMarkCallback; /* Legacy weak TT_TimeMarkCallback  */
01470   }
01471   else
01472   {
01473     /* Update the error code */
01474     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01475 
01476     /* Return error status */
01477     status =  HAL_ERROR;
01478   }
01479 
01480   return status;
01481 }
01482 
01483 /**
01484   * @brief  Register TT Stop Watch FDCAN Callback
01485   *         To be used instead of the weak HAL_FDCAN_TT_StopWatchCallback() predefined callback
01486   * @param  hfdcan FDCAN handle
01487   * @param  pCallback pointer to the TT Stop Watch Callback function
01488   * @retval HAL status
01489   */
01490 HAL_StatusTypeDef HAL_FDCAN_RegisterTTStopWatchCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_TT_StopWatchCallbackTypeDef pCallback)
01491 {
01492   HAL_StatusTypeDef status = HAL_OK;
01493 
01494   if (pCallback == NULL)
01495   {
01496     /* Update the error code */
01497     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01498     return HAL_ERROR;
01499   }
01500 
01501   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01502   {
01503     hfdcan->TT_StopWatchCallback = pCallback;
01504   }
01505   else
01506   {
01507     /* Update the error code */
01508     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01509 
01510     /* Return error status */
01511     status =  HAL_ERROR;
01512   }
01513 
01514   return status;
01515 }
01516 
01517 /**
01518   * @brief  UnRegister the TT Stop Watch FDCAN Callback
01519   *         TT Stop Watch Callback is redirected to the weak HAL_FDCAN_TT_StopWatchCallback() predefined callback
01520   * @param  hfdcan FDCAN handle
01521   * @retval HAL status
01522   */
01523 HAL_StatusTypeDef HAL_FDCAN_UnRegisterTTStopWatchCallback(FDCAN_HandleTypeDef *hfdcan)
01524 {
01525   HAL_StatusTypeDef status = HAL_OK;
01526 
01527   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01528   {
01529     hfdcan->TT_StopWatchCallback = HAL_FDCAN_TT_StopWatchCallback; /* Legacy weak TT_StopWatchCallback  */
01530   }
01531   else
01532   {
01533     /* Update the error code */
01534     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01535 
01536     /* Return error status */
01537     status =  HAL_ERROR;
01538   }
01539 
01540   return status;
01541 }
01542 
01543 /**
01544   * @brief  Register TT Global Time FDCAN Callback
01545   *         To be used instead of the weak HAL_FDCAN_TT_GlobalTimeCallback() predefined callback
01546   * @param  hfdcan FDCAN handle
01547   * @param  pCallback pointer to the TT Global Time Callback function
01548   * @retval HAL status
01549   */
01550 HAL_StatusTypeDef HAL_FDCAN_RegisterTTGlobalTimeCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_TT_GlobalTimeCallbackTypeDef pCallback)
01551 {
01552   HAL_StatusTypeDef status = HAL_OK;
01553 
01554   if (pCallback == NULL)
01555   {
01556     /* Update the error code */
01557     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01558     return HAL_ERROR;
01559   }
01560 
01561   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01562   {
01563     hfdcan->TT_GlobalTimeCallback = pCallback;
01564   }
01565   else
01566   {
01567     /* Update the error code */
01568     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01569 
01570     /* Return error status */
01571     status =  HAL_ERROR;
01572   }
01573 
01574   return status;
01575 }
01576 
01577 /**
01578   * @brief  UnRegister the TT Global Time FDCAN Callback
01579   *         TT Global Time Callback is redirected to the weak HAL_FDCAN_TT_GlobalTimeCallback() predefined callback
01580   * @param  hfdcan FDCAN handle
01581   * @retval HAL status
01582   */
01583 HAL_StatusTypeDef HAL_FDCAN_UnRegisterTTGlobalTimeCallback(FDCAN_HandleTypeDef *hfdcan)
01584 {
01585   HAL_StatusTypeDef status = HAL_OK;
01586 
01587   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01588   {
01589     hfdcan->TT_GlobalTimeCallback = HAL_FDCAN_TT_GlobalTimeCallback; /* Legacy weak TT_GlobalTimeCallback  */
01590   }
01591   else
01592   {
01593     /* Update the error code */
01594     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
01595 
01596     /* Return error status */
01597     status =  HAL_ERROR;
01598   }
01599 
01600   return status;
01601 }
01602 
01603 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
01604 
01605 /**
01606   * @}
01607   */
01608 
01609 /** @defgroup FDCAN_Exported_Functions_Group2 Configuration functions
01610  *  @brief    FDCAN Configuration functions.
01611  *
01612 @verbatim
01613   ==============================================================================
01614               ##### Configuration functions #####
01615   ==============================================================================
01616     [..]  This section provides functions allowing to:
01617       (+) HAL_FDCAN_ConfigClockCalibration        : Configure the FDCAN clock calibration unit
01618         (+) HAL_FDCAN_GetClockCalibrationState      : Get the clock calibration state
01619         (+) HAL_FDCAN_ResetClockCalibrationState    : Reset the clock calibration state
01620         (+) HAL_FDCAN_GetClockCalibrationCounter    : Get the clock calibration counters values
01621       (+) HAL_FDCAN_ConfigFilter                  : Configure the FDCAN reception filters
01622       (+) HAL_FDCAN_ConfigGlobalFilter            : Configure the FDCAN global filter
01623       (+) HAL_FDCAN_ConfigExtendedIdMask          : Configure the extended ID mask
01624       (+) HAL_FDCAN_ConfigRxFifoOverwrite         : Configure the Rx FIFO operation mode
01625       (+) HAL_FDCAN_ConfigFifoWatermark           : Configure the FIFO watermark
01626       (+) HAL_FDCAN_ConfigRamWatchdog             : Configure the RAM watchdog
01627       (+) HAL_FDCAN_ConfigTimestampCounter        : Configure the timestamp counter
01628         (+) HAL_FDCAN_EnableTimestampCounter        : Enable the timestamp counter
01629         (+) HAL_FDCAN_DisableTimestampCounter       : Disable the timestamp counter
01630         (+) HAL_FDCAN_GetTimestampCounter           : Get the timestamp counter value
01631         (+) HAL_FDCAN_ResetTimestampCounter         : Reset the timestamp counter to zero
01632       (+) HAL_FDCAN_ConfigTimeoutCounter          : Configure the timeout counter
01633         (+) HAL_FDCAN_EnableTimeoutCounter          : Enable the timeout counter
01634         (+) HAL_FDCAN_DisableTimeoutCounter         : Disable the timeout counter
01635         (+) HAL_FDCAN_GetTimeoutCounter             : Get the timeout counter value
01636         (+) HAL_FDCAN_ResetTimeoutCounter           : Reset the timeout counter to its start value
01637       (+) HAL_FDCAN_ConfigTxDelayCompensation     : Configure the transmitter delay compensation
01638         (+) HAL_FDCAN_EnableTxDelayCompensation     : Enable the transmitter delay compensation
01639         (+) HAL_FDCAN_DisableTxDelayCompensation    : Disable the transmitter delay compensation
01640       (+) HAL_FDCAN_EnableISOMode                 : Enable ISO 11898-1 protocol mode
01641       (+) HAL_FDCAN_DisableISOMode                : Disable ISO 11898-1 protocol mode
01642       (+) HAL_FDCAN_EnableEdgeFiltering           : Enable edge filtering during bus integration
01643       (+) HAL_FDCAN_DisableEdgeFiltering          : Disable edge filtering during bus integration
01644 
01645 @endverbatim
01646   * @{
01647   */
01648 
01649 /**
01650   * @brief  Configure the FDCAN clock calibration unit according to the specified
01651   *         parameters in the FDCAN_ClkCalUnitTypeDef structure.
01652   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
01653   *         the configuration information for the specified FDCAN.
01654   * @param  sCcuConfig pointer to an FDCAN_ClkCalUnitTypeDef structure that
01655   *         contains the clock calibration information
01656   * @retval HAL status
01657   */
01658 HAL_StatusTypeDef HAL_FDCAN_ConfigClockCalibration(FDCAN_HandleTypeDef *hfdcan, FDCAN_ClkCalUnitTypeDef *sCcuConfig)
01659 {
01660   /* Check function parameters */
01661   assert_param(IS_FDCAN_CLOCK_CALIBRATION(sCcuConfig->ClockCalibration));
01662   if (sCcuConfig->ClockCalibration == FDCAN_CLOCK_CALIBRATION_DISABLE)
01663   {
01664     assert_param(IS_FDCAN_CKDIV(sCcuConfig->ClockDivider));
01665   }
01666   else
01667   {
01668     assert_param(IS_FDCAN_MAX_VALUE(sCcuConfig->MinOscClkPeriods, 0xFFU));
01669     assert_param(IS_FDCAN_CALIBRATION_FIELD_LENGTH(sCcuConfig->CalFieldLength));
01670     assert_param(IS_FDCAN_MIN_VALUE(sCcuConfig->TimeQuantaPerBitTime, 4U));
01671     assert_param(IS_FDCAN_MAX_VALUE(sCcuConfig->TimeQuantaPerBitTime, 0x25U));
01672     assert_param(IS_FDCAN_MAX_VALUE(sCcuConfig->WatchdogStartValue, 0xFFFFU));
01673   }
01674 
01675   /* FDCAN1 should be initialized in order to use clock calibration */
01676   if (hfdcan->Instance != FDCAN1)
01677   {
01678     /* Update error code */
01679     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
01680 
01681     return HAL_ERROR;
01682   }
01683 
01684   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01685   {
01686     if (sCcuConfig->ClockCalibration == FDCAN_CLOCK_CALIBRATION_DISABLE)
01687     {
01688       /* Bypass clock calibration */
01689       SET_BIT(FDCAN_CCU->CCFG, FDCANCCU_CCFG_BCC);
01690 
01691       /* Configure clock divider */
01692       MODIFY_REG(FDCAN_CCU->CCFG, FDCANCCU_CCFG_CDIV, sCcuConfig->ClockDivider);
01693     }
01694     else /* sCcuConfig->ClockCalibration == ENABLE */
01695     {
01696       /* Clock calibration unit generates time quanta clock */
01697       CLEAR_BIT(FDCAN_CCU->CCFG, FDCANCCU_CCFG_BCC);
01698 
01699       /* Configure clock calibration unit */
01700       MODIFY_REG(FDCAN_CCU->CCFG,
01701                  (FDCANCCU_CCFG_TQBT | FDCANCCU_CCFG_CFL | FDCANCCU_CCFG_OCPM),
01702                  ((sCcuConfig->TimeQuantaPerBitTime << FDCANCCU_CCFG_TQBT_Pos) | sCcuConfig->CalFieldLength | (sCcuConfig->MinOscClkPeriods << FDCANCCU_CCFG_OCPM_Pos)));
01703 
01704       /* Configure the start value of the calibration watchdog counter */
01705       MODIFY_REG(FDCAN_CCU->CWD, FDCANCCU_CWD_WDC, sCcuConfig->WatchdogStartValue);
01706     }
01707 
01708     /* Return function status */
01709     return HAL_OK;
01710   }
01711   else
01712   {
01713     /* Update error code */
01714     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
01715 
01716     return HAL_ERROR;
01717   }
01718 }
01719 
01720 /**
01721   * @brief  Get the clock calibration state.
01722   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
01723   *         the configuration information for the specified FDCAN.
01724   * @retval State clock calibration state (can be a value of @arg FDCAN_calibration_state)
01725   */
01726 uint32_t HAL_FDCAN_GetClockCalibrationState(FDCAN_HandleTypeDef *hfdcan)
01727 {
01728   /* Prevent unused argument(s) compilation warning */
01729   UNUSED(hfdcan);
01730 
01731   return (FDCAN_CCU->CSTAT & FDCANCCU_CSTAT_CALS);
01732 }
01733 
01734 /**
01735   * @brief  Reset the clock calibration state.
01736   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
01737   *         the configuration information for the specified FDCAN.
01738   * @retval HAL status
01739   */
01740 HAL_StatusTypeDef HAL_FDCAN_ResetClockCalibrationState(FDCAN_HandleTypeDef *hfdcan)
01741 {
01742   /* FDCAN1 should be initialized in order to use clock calibration */
01743   if (hfdcan->Instance != FDCAN1)
01744   {
01745     /* Update error code */
01746     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
01747 
01748     return HAL_ERROR;
01749   }
01750 
01751   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01752   {
01753     /* Calibration software reset */
01754     SET_BIT(FDCAN_CCU->CCFG, FDCANCCU_CCFG_SWR);
01755 
01756     /* Return function status */
01757     return HAL_OK;
01758   }
01759   else
01760   {
01761     /* Update error code */
01762     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
01763 
01764     return HAL_ERROR;
01765   }
01766 }
01767 
01768 /**
01769   * @brief  Get the clock calibration counter value.
01770   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
01771   *         the configuration information for the specified FDCAN.
01772   * @param  Counter clock calibration counter.
01773   *         This parameter can be a value of @arg FDCAN_calibration_counter.
01774   * @retval Value clock calibration counter value
01775   */
01776 uint32_t HAL_FDCAN_GetClockCalibrationCounter(FDCAN_HandleTypeDef *hfdcan, uint32_t Counter)
01777 {
01778   /* Prevent unused argument(s) compilation warning */
01779   UNUSED(hfdcan);
01780 
01781   /* Check function parameters */
01782   assert_param(IS_FDCAN_CALIBRATION_COUNTER(Counter));
01783 
01784   if (Counter == FDCAN_CALIB_TIME_QUANTA_COUNTER)
01785   {
01786     return ((FDCAN_CCU->CSTAT & FDCANCCU_CSTAT_TQC) >> FDCANCCU_CSTAT_TQC_Pos);
01787   }
01788   else if (Counter == FDCAN_CALIB_CLOCK_PERIOD_COUNTER)
01789   {
01790     return (FDCAN_CCU->CSTAT & FDCANCCU_CSTAT_OCPC);
01791   }
01792   else /* Counter == FDCAN_CALIB_WATCHDOG_COUNTER */
01793   {
01794     return ((FDCAN_CCU->CWD & FDCANCCU_CWD_WDV) >> FDCANCCU_CWD_WDV_Pos);
01795   }
01796 }
01797 
01798 /**
01799   * @brief  Configure the FDCAN reception filter according to the specified
01800   *         parameters in the FDCAN_FilterTypeDef structure.
01801   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
01802   *         the configuration information for the specified FDCAN.
01803   * @param  sFilterConfig pointer to an FDCAN_FilterTypeDef structure that
01804   *         contains the filter configuration information
01805   * @retval HAL status
01806   */
01807 HAL_StatusTypeDef HAL_FDCAN_ConfigFilter(FDCAN_HandleTypeDef *hfdcan, FDCAN_FilterTypeDef *sFilterConfig)
01808 {
01809   uint32_t FilterElementW1;
01810   uint32_t FilterElementW2;
01811   uint32_t *FilterAddress;
01812   HAL_FDCAN_StateTypeDef state = hfdcan->State;
01813 
01814   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
01815   {
01816     /* Check function parameters */
01817     assert_param(IS_FDCAN_ID_TYPE(sFilterConfig->IdType));
01818     assert_param(IS_FDCAN_FILTER_CFG(sFilterConfig->FilterConfig));
01819     if (sFilterConfig->FilterConfig == FDCAN_FILTER_TO_RXBUFFER)
01820     {
01821       assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->RxBufferIndex, 63U));
01822       assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->IsCalibrationMsg, 1U));
01823     }
01824 
01825     if (sFilterConfig->IdType == FDCAN_STANDARD_ID)
01826     {
01827       /* Check function parameters */
01828       assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterIndex, (hfdcan->Init.StdFiltersNbr - 1U)));
01829       assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterID1, 0x7FFU));
01830       if (sFilterConfig->FilterConfig != FDCAN_FILTER_TO_RXBUFFER)
01831       {
01832         assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterID2, 0x7FFU));
01833         assert_param(IS_FDCAN_STD_FILTER_TYPE(sFilterConfig->FilterType));
01834       }
01835 
01836       /* Build filter element */
01837       if (sFilterConfig->FilterConfig == FDCAN_FILTER_TO_RXBUFFER)
01838       {
01839         FilterElementW1 = ((FDCAN_FILTER_TO_RXBUFFER << 27U)       |
01840                            (sFilterConfig->FilterID1 << 16U)       |
01841                            (sFilterConfig->IsCalibrationMsg << 8U) |
01842                            sFilterConfig->RxBufferIndex);
01843       }
01844       else
01845       {
01846         FilterElementW1 = ((sFilterConfig->FilterType << 30U)   |
01847                            (sFilterConfig->FilterConfig << 27U) |
01848                            (sFilterConfig->FilterID1 << 16U)    |
01849                            sFilterConfig->FilterID2);
01850       }
01851 
01852       /* Calculate filter address */
01853       FilterAddress = (uint32_t *)(hfdcan->msgRam.StandardFilterSA + (sFilterConfig->FilterIndex * 4U));
01854 
01855       /* Write filter element to the message RAM */
01856       *FilterAddress = FilterElementW1;
01857     }
01858     else /* sFilterConfig->IdType == FDCAN_EXTENDED_ID */
01859     {
01860       /* Check function parameters */
01861       assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterIndex, (hfdcan->Init.ExtFiltersNbr - 1U)));
01862       assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterID1, 0x1FFFFFFFU));
01863       if (sFilterConfig->FilterConfig != FDCAN_FILTER_TO_RXBUFFER)
01864       {
01865         assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterID2, 0x1FFFFFFFU));
01866         assert_param(IS_FDCAN_EXT_FILTER_TYPE(sFilterConfig->FilterType));
01867       }
01868 
01869       /* Build first word of filter element */
01870       FilterElementW1 = ((sFilterConfig->FilterConfig << 29U) | sFilterConfig->FilterID1);
01871 
01872       /* Build second word of filter element */
01873       if (sFilterConfig->FilterConfig == FDCAN_FILTER_TO_RXBUFFER)
01874       {
01875         FilterElementW2 = sFilterConfig->RxBufferIndex;
01876       }
01877       else
01878       {
01879         FilterElementW2 = ((sFilterConfig->FilterType << 30U) | sFilterConfig->FilterID2);
01880       }
01881 
01882       /* Calculate filter address */
01883       FilterAddress = (uint32_t *)(hfdcan->msgRam.ExtendedFilterSA + (sFilterConfig->FilterIndex * 4U * 2U));
01884 
01885       /* Write filter element to the message RAM */
01886       *FilterAddress = FilterElementW1;
01887       FilterAddress++;
01888       *FilterAddress = FilterElementW2;
01889     }
01890 
01891     /* Return function status */
01892     return HAL_OK;
01893   }
01894   else
01895   {
01896     /* Update error code */
01897     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
01898 
01899     return HAL_ERROR;
01900   }
01901 }
01902 
01903 /**
01904   * @brief  Configure the FDCAN global filter.
01905   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
01906   *         the configuration information for the specified FDCAN.
01907   * @param  NonMatchingStd Defines how received messages with 11-bit IDs that
01908   *         do not match any element of the filter list are treated.
01909   *         This parameter can be a value of @arg FDCAN_Non_Matching_Frames.
01910   * @param  NonMatchingExt Defines how received messages with 29-bit IDs that
01911   *         do not match any element of the filter list are treated.
01912   *         This parameter can be a value of @arg FDCAN_Non_Matching_Frames.
01913   * @param  RejectRemoteStd Filter or reject all the remote 11-bit IDs frames.
01914   *         This parameter can be a value of @arg FDCAN_Reject_Remote_Frames.
01915   * @param  RejectRemoteExt Filter or reject all the remote 29-bit IDs frames.
01916   *         This parameter can be a value of @arg FDCAN_Reject_Remote_Frames.
01917   * @retval HAL status
01918   */
01919 HAL_StatusTypeDef HAL_FDCAN_ConfigGlobalFilter(FDCAN_HandleTypeDef *hfdcan,
01920                                                uint32_t NonMatchingStd,
01921                                                uint32_t NonMatchingExt,
01922                                                uint32_t RejectRemoteStd,
01923                                                uint32_t RejectRemoteExt)
01924 {
01925   /* Check function parameters */
01926   assert_param(IS_FDCAN_NON_MATCHING(NonMatchingStd));
01927   assert_param(IS_FDCAN_NON_MATCHING(NonMatchingExt));
01928   assert_param(IS_FDCAN_REJECT_REMOTE(RejectRemoteStd));
01929   assert_param(IS_FDCAN_REJECT_REMOTE(RejectRemoteExt));
01930 
01931   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01932   {
01933     /* Configure global filter */
01934     hfdcan->Instance->GFC = ((NonMatchingStd << FDCAN_GFC_ANFS_Pos)  |
01935                              (NonMatchingExt << FDCAN_GFC_ANFE_Pos)  |
01936                              (RejectRemoteStd << FDCAN_GFC_RRFS_Pos) |
01937                              (RejectRemoteExt << FDCAN_GFC_RRFE_Pos));
01938 
01939     /* Return function status */
01940     return HAL_OK;
01941   }
01942   else
01943   {
01944     /* Update error code */
01945     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
01946 
01947     return HAL_ERROR;
01948   }
01949 }
01950 
01951 /**
01952   * @brief  Configure the extended ID mask.
01953   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
01954   *         the configuration information for the specified FDCAN.
01955   * @param  Mask Extended ID Mask.
01956   *         This parameter must be a number between 0 and 0x1FFFFFFF
01957   * @retval HAL status
01958   */
01959 HAL_StatusTypeDef HAL_FDCAN_ConfigExtendedIdMask(FDCAN_HandleTypeDef *hfdcan, uint32_t Mask)
01960 {
01961   /* Check function parameters */
01962   assert_param(IS_FDCAN_MAX_VALUE(Mask, 0x1FFFFFFFU));
01963 
01964   if (hfdcan->State == HAL_FDCAN_STATE_READY)
01965   {
01966     /* Configure the extended ID mask */
01967     hfdcan->Instance->XIDAM = Mask;
01968 
01969     /* Return function status */
01970     return HAL_OK;
01971   }
01972   else
01973   {
01974     /* Update error code */
01975     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
01976 
01977     return HAL_ERROR;
01978   }
01979 }
01980 
01981 /**
01982   * @brief  Configure the Rx FIFO operation mode.
01983   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
01984   *         the configuration information for the specified FDCAN.
01985   * @param  RxFifo Rx FIFO.
01986   *         This parameter can be one of the following values:
01987   *           @arg FDCAN_RX_FIFO0: Rx FIFO 0
01988   *           @arg FDCAN_RX_FIFO1: Rx FIFO 1
01989   * @param  OperationMode operation mode.
01990   *         This parameter can be a value of @arg FDCAN_Rx_FIFO_operation_mode.
01991   * @retval HAL status
01992   */
01993 HAL_StatusTypeDef HAL_FDCAN_ConfigRxFifoOverwrite(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo, uint32_t OperationMode)
01994 {
01995   /* Check function parameters */
01996   assert_param(IS_FDCAN_RX_FIFO(RxFifo));
01997   assert_param(IS_FDCAN_RX_FIFO_MODE(OperationMode));
01998 
01999   if (hfdcan->State == HAL_FDCAN_STATE_READY)
02000   {
02001     if (RxFifo == FDCAN_RX_FIFO0)
02002     {
02003       /* Select FIFO 0 Operation Mode */
02004       MODIFY_REG(hfdcan->Instance->RXF0C, FDCAN_RXF0C_F0OM, OperationMode);
02005     }
02006     else /* RxFifo == FDCAN_RX_FIFO1 */
02007     {
02008       /* Select FIFO 1 Operation Mode */
02009       MODIFY_REG(hfdcan->Instance->RXF1C, FDCAN_RXF1C_F1OM, OperationMode);
02010     }
02011 
02012     /* Return function status */
02013     return HAL_OK;
02014   }
02015   else
02016   {
02017     /* Update error code */
02018     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
02019 
02020     return HAL_ERROR;
02021   }
02022 }
02023 
02024 /**
02025   * @brief  Configure the FIFO watermark.
02026   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02027   *         the configuration information for the specified FDCAN.
02028   * @param  FIFO select the FIFO to be configured.
02029   *         This parameter can be a value of @arg FDCAN_FIFO_watermark.
02030   * @param  Watermark level for FIFO watermark interrupt.
02031   *         This parameter must be a number between:
02032   *           - 0 and 32, if FIFO is FDCAN_CFG_TX_EVENT_FIFO
02033   *           - 0 and 64, if FIFO is FDCAN_CFG_RX_FIFO0 or FDCAN_CFG_RX_FIFO1
02034   * @retval HAL status
02035   */
02036 HAL_StatusTypeDef HAL_FDCAN_ConfigFifoWatermark(FDCAN_HandleTypeDef *hfdcan, uint32_t FIFO, uint32_t Watermark)
02037 {
02038   /* Check function parameters */
02039   assert_param(IS_FDCAN_FIFO_WATERMARK(FIFO));
02040   if (FIFO == FDCAN_CFG_TX_EVENT_FIFO)
02041   {
02042     assert_param(IS_FDCAN_MAX_VALUE(Watermark, 32U));
02043   }
02044   else /* (FIFO == FDCAN_CFG_RX_FIFO0) || (FIFO == FDCAN_CFG_RX_FIFO1) */
02045   {
02046     assert_param(IS_FDCAN_MAX_VALUE(Watermark, 64U));
02047   }
02048 
02049   if (hfdcan->State == HAL_FDCAN_STATE_READY)
02050   {
02051     /* Set the level for FIFO watermark interrupt */
02052     if (FIFO == FDCAN_CFG_TX_EVENT_FIFO)
02053     {
02054       MODIFY_REG(hfdcan->Instance->TXEFC, FDCAN_TXEFC_EFWM, (Watermark << FDCAN_TXEFC_EFWM_Pos));
02055     }
02056     else if (FIFO == FDCAN_CFG_RX_FIFO0)
02057     {
02058       MODIFY_REG(hfdcan->Instance->RXF0C, FDCAN_RXF0C_F0WM, (Watermark << FDCAN_RXF0C_F0WM_Pos));
02059     }
02060     else /* FIFO == FDCAN_CFG_RX_FIFO1 */
02061     {
02062       MODIFY_REG(hfdcan->Instance->RXF1C, FDCAN_RXF1C_F1WM, (Watermark << FDCAN_RXF1C_F1WM_Pos));
02063     }
02064 
02065     /* Return function status */
02066     return HAL_OK;
02067   }
02068   else
02069   {
02070     /* Update error code */
02071     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
02072 
02073     return HAL_ERROR;
02074   }
02075 }
02076 
02077 /**
02078   * @brief  Configure the RAM watchdog.
02079   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02080   *         the configuration information for the specified FDCAN.
02081   * @param  CounterStartValue Start value of the Message RAM Watchdog Counter,
02082   *         This parameter must be a number between 0x00 and 0xFF,
02083   *         with the reset value of 0x00 the counter is disabled.
02084   * @retval HAL status
02085   */
02086 HAL_StatusTypeDef HAL_FDCAN_ConfigRamWatchdog(FDCAN_HandleTypeDef *hfdcan, uint32_t CounterStartValue)
02087 {
02088   /* Check function parameters */
02089   assert_param(IS_FDCAN_MAX_VALUE(CounterStartValue, 0xFFU));
02090 
02091   if (hfdcan->State == HAL_FDCAN_STATE_READY)
02092   {
02093     /* Configure the RAM watchdog counter start value */
02094     MODIFY_REG(hfdcan->Instance->RWD, FDCAN_RWD_WDC, CounterStartValue);
02095 
02096     /* Return function status */
02097     return HAL_OK;
02098   }
02099   else
02100   {
02101     /* Update error code */
02102     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
02103 
02104     return HAL_ERROR;
02105   }
02106 }
02107 
02108 /**
02109   * @brief  Configure the timestamp counter.
02110   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02111   *         the configuration information for the specified FDCAN.
02112   * @param  TimestampPrescaler Timestamp Counter Prescaler.
02113   *         This parameter can be a value of @arg FDCAN_Timestamp_Prescaler.
02114   * @retval HAL status
02115   */
02116 HAL_StatusTypeDef HAL_FDCAN_ConfigTimestampCounter(FDCAN_HandleTypeDef *hfdcan, uint32_t TimestampPrescaler)
02117 {
02118   /* Check function parameters */
02119   assert_param(IS_FDCAN_TIMESTAMP_PRESCALER(TimestampPrescaler));
02120 
02121   if (hfdcan->State == HAL_FDCAN_STATE_READY)
02122   {
02123     /* Configure prescaler */
02124     MODIFY_REG(hfdcan->Instance->TSCC, FDCAN_TSCC_TCP, TimestampPrescaler);
02125 
02126     /* Return function status */
02127     return HAL_OK;
02128   }
02129   else
02130   {
02131     /* Update error code */
02132     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
02133 
02134     return HAL_ERROR;
02135   }
02136 }
02137 
02138 /**
02139   * @brief  Enable the timestamp counter.
02140   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02141   *         the configuration information for the specified FDCAN.
02142   * @param  TimestampOperation Timestamp counter operation.
02143   *         This parameter can be a value of @arg FDCAN_Timestamp.
02144   * @retval HAL status
02145   */
02146 HAL_StatusTypeDef HAL_FDCAN_EnableTimestampCounter(FDCAN_HandleTypeDef *hfdcan, uint32_t TimestampOperation)
02147 {
02148   /* Check function parameters */
02149   assert_param(IS_FDCAN_TIMESTAMP(TimestampOperation));
02150 
02151   if (hfdcan->State == HAL_FDCAN_STATE_READY)
02152   {
02153     /* Enable timestamp counter */
02154     MODIFY_REG(hfdcan->Instance->TSCC, FDCAN_TSCC_TSS, TimestampOperation);
02155 
02156     /* Return function status */
02157     return HAL_OK;
02158   }
02159   else
02160   {
02161     /* Update error code */
02162     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
02163 
02164     return HAL_ERROR;
02165   }
02166 }
02167 
02168 /**
02169   * @brief  Disable the timestamp counter.
02170   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02171   *         the configuration information for the specified FDCAN.
02172   * @retval HAL status
02173   */
02174 HAL_StatusTypeDef HAL_FDCAN_DisableTimestampCounter(FDCAN_HandleTypeDef *hfdcan)
02175 {
02176   if (hfdcan->State == HAL_FDCAN_STATE_READY)
02177   {
02178     /* Disable timestamp counter */
02179     CLEAR_BIT(hfdcan->Instance->TSCC, FDCAN_TSCC_TSS);
02180 
02181     /* Return function status */
02182     return HAL_OK;
02183   }
02184   else
02185   {
02186     /* Update error code */
02187     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
02188 
02189     return HAL_ERROR;
02190   }
02191 }
02192 
02193 /**
02194   * @brief  Get the timestamp counter value.
02195   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02196   *         the configuration information for the specified FDCAN.
02197   * @retval Value Timestamp counter value
02198   */
02199 uint16_t HAL_FDCAN_GetTimestampCounter(FDCAN_HandleTypeDef *hfdcan)
02200 {
02201   return (uint16_t)(hfdcan->Instance->TSCV);
02202 }
02203 
02204 /**
02205   * @brief  Reset the timestamp counter to zero.
02206   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02207   *         the configuration information for the specified FDCAN.
02208   * @retval HAL status
02209   */
02210 HAL_StatusTypeDef HAL_FDCAN_ResetTimestampCounter(FDCAN_HandleTypeDef *hfdcan)
02211 {
02212   if ((hfdcan->Instance->TSCC & FDCAN_TSCC_TSS) != FDCAN_TIMESTAMP_EXTERNAL)
02213   {
02214     /* Reset timestamp counter.
02215        Actually any write operation to TSCV clears the counter */
02216     CLEAR_REG(hfdcan->Instance->TSCV);
02217   }
02218   else
02219   {
02220     /* Update error code.
02221        Unable to reset external counter */
02222     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
02223 
02224     return HAL_ERROR;
02225   }
02226 
02227   /* Return function status */
02228   return HAL_OK;
02229 }
02230 
02231 /**
02232   * @brief  Configure the timeout counter.
02233   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02234   *         the configuration information for the specified FDCAN.
02235   * @param  TimeoutOperation Timeout counter operation.
02236   *         This parameter can be a value of @arg FDCAN_Timeout_Operation.
02237   * @param  TimeoutPeriod Start value of the timeout down-counter.
02238   *         This parameter must be a number between 0x0000 and 0xFFFF
02239   * @retval HAL status
02240   */
02241 HAL_StatusTypeDef HAL_FDCAN_ConfigTimeoutCounter(FDCAN_HandleTypeDef *hfdcan, uint32_t TimeoutOperation, uint32_t TimeoutPeriod)
02242 {
02243   /* Check function parameters */
02244   assert_param(IS_FDCAN_TIMEOUT(TimeoutOperation));
02245   assert_param(IS_FDCAN_MAX_VALUE(TimeoutPeriod, 0xFFFFU));
02246 
02247   if (hfdcan->State == HAL_FDCAN_STATE_READY)
02248   {
02249     /* Select timeout operation and configure period */
02250     MODIFY_REG(hfdcan->Instance->TOCC, (FDCAN_TOCC_TOS | FDCAN_TOCC_TOP), (TimeoutOperation | (TimeoutPeriod << FDCAN_TOCC_TOP_Pos)));
02251 
02252     /* Return function status */
02253     return HAL_OK;
02254   }
02255   else
02256   {
02257     /* Update error code */
02258     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
02259 
02260     return HAL_ERROR;
02261   }
02262 }
02263 
02264 /**
02265   * @brief  Enable the timeout counter.
02266   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02267   *         the configuration information for the specified FDCAN.
02268   * @retval HAL status
02269   */
02270 HAL_StatusTypeDef HAL_FDCAN_EnableTimeoutCounter(FDCAN_HandleTypeDef *hfdcan)
02271 {
02272   if (hfdcan->State == HAL_FDCAN_STATE_READY)
02273   {
02274     /* Enable timeout counter */
02275     SET_BIT(hfdcan->Instance->TOCC, FDCAN_TOCC_ETOC);
02276 
02277     /* Return function status */
02278     return HAL_OK;
02279   }
02280   else
02281   {
02282     /* Update error code */
02283     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
02284 
02285     return HAL_ERROR;
02286   }
02287 }
02288 
02289 /**
02290   * @brief  Disable the timeout counter.
02291   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02292   *         the configuration information for the specified FDCAN.
02293   * @retval HAL status
02294   */
02295 HAL_StatusTypeDef HAL_FDCAN_DisableTimeoutCounter(FDCAN_HandleTypeDef *hfdcan)
02296 {
02297   if (hfdcan->State == HAL_FDCAN_STATE_READY)
02298   {
02299     /* Disable timeout counter */
02300     CLEAR_BIT(hfdcan->Instance->TOCC, FDCAN_TOCC_ETOC);
02301 
02302     /* Return function status */
02303     return HAL_OK;
02304   }
02305   else
02306   {
02307     /* Update error code */
02308     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
02309 
02310     return HAL_ERROR;
02311   }
02312 }
02313 
02314 /**
02315   * @brief  Get the timeout counter value.
02316   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02317   *         the configuration information for the specified FDCAN.
02318   * @retval Value Timeout counter value
02319   */
02320 uint16_t HAL_FDCAN_GetTimeoutCounter(FDCAN_HandleTypeDef *hfdcan)
02321 {
02322   return (uint16_t)(hfdcan->Instance->TOCV);
02323 }
02324 
02325 /**
02326   * @brief  Reset the timeout counter to its start value.
02327   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02328   *         the configuration information for the specified FDCAN.
02329   * @retval HAL status
02330   */
02331 HAL_StatusTypeDef HAL_FDCAN_ResetTimeoutCounter(FDCAN_HandleTypeDef *hfdcan)
02332 {
02333   if ((hfdcan->Instance->TOCC & FDCAN_TOCC_TOS) == FDCAN_TIMEOUT_CONTINUOUS)
02334   {
02335     /* Reset timeout counter to start value */
02336     CLEAR_REG(hfdcan->Instance->TOCV);
02337 
02338     /* Return function status */
02339     return HAL_OK;
02340   }
02341   else
02342   {
02343     /* Update error code.
02344        Unable to reset counter: controlled only by FIFO empty state */
02345     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
02346 
02347     return HAL_ERROR;
02348   }
02349 }
02350 
02351 /**
02352   * @brief  Configure the transmitter delay compensation.
02353   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02354   *         the configuration information for the specified FDCAN.
02355   * @param  TdcOffset Transmitter Delay Compensation Offset.
02356   *         This parameter must be a number between 0x00 and 0x7F.
02357   * @param  TdcFilter Transmitter Delay Compensation Filter Window Length.
02358   *         This parameter must be a number between 0x00 and 0x7F.
02359   * @retval HAL status
02360   */
02361 HAL_StatusTypeDef HAL_FDCAN_ConfigTxDelayCompensation(FDCAN_HandleTypeDef *hfdcan, uint32_t TdcOffset, uint32_t TdcFilter)
02362 {
02363   /* Check function parameters */
02364   assert_param(IS_FDCAN_MAX_VALUE(TdcOffset, 0x7FU));
02365   assert_param(IS_FDCAN_MAX_VALUE(TdcFilter, 0x7FU));
02366 
02367   if (hfdcan->State == HAL_FDCAN_STATE_READY)
02368   {
02369     /* Configure TDC offset and filter window */
02370     hfdcan->Instance->TDCR = ((TdcFilter << FDCAN_TDCR_TDCF_Pos) | (TdcOffset << FDCAN_TDCR_TDCO_Pos));
02371 
02372     /* Return function status */
02373     return HAL_OK;
02374   }
02375   else
02376   {
02377     /* Update error code */
02378     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
02379 
02380     return HAL_ERROR;
02381   }
02382 }
02383 
02384 /**
02385   * @brief  Enable the transmitter delay compensation.
02386   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02387   *         the configuration information for the specified FDCAN.
02388   * @retval HAL status
02389   */
02390 HAL_StatusTypeDef HAL_FDCAN_EnableTxDelayCompensation(FDCAN_HandleTypeDef *hfdcan)
02391 {
02392   if (hfdcan->State == HAL_FDCAN_STATE_READY)
02393   {
02394     /* Enable transmitter delay compensation */
02395     SET_BIT(hfdcan->Instance->DBTP, FDCAN_DBTP_TDC);
02396 
02397     /* Return function status */
02398     return HAL_OK;
02399   }
02400   else
02401   {
02402     /* Update error code */
02403     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
02404 
02405     return HAL_ERROR;
02406   }
02407 }
02408 
02409 /**
02410   * @brief  Disable the transmitter delay compensation.
02411   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02412   *         the configuration information for the specified FDCAN.
02413   * @retval HAL status
02414   */
02415 HAL_StatusTypeDef HAL_FDCAN_DisableTxDelayCompensation(FDCAN_HandleTypeDef *hfdcan)
02416 {
02417   if (hfdcan->State == HAL_FDCAN_STATE_READY)
02418   {
02419     /* Disable transmitter delay compensation */
02420     CLEAR_BIT(hfdcan->Instance->DBTP, FDCAN_DBTP_TDC);
02421 
02422     /* Return function status */
02423     return HAL_OK;
02424   }
02425   else
02426   {
02427     /* Update error code */
02428     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
02429 
02430     return HAL_ERROR;
02431   }
02432 }
02433 
02434 /**
02435   * @brief  Enable ISO 11898-1 protocol mode.
02436   *         CAN FD frame format is according to ISO 11898-1 standard.
02437   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02438   *         the configuration information for the specified FDCAN.
02439   * @retval HAL status
02440   */
02441 HAL_StatusTypeDef HAL_FDCAN_EnableISOMode(FDCAN_HandleTypeDef *hfdcan)
02442 {
02443   if (hfdcan->State == HAL_FDCAN_STATE_READY)
02444   {
02445     /* Disable Non ISO protocol mode */
02446     CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_NISO);
02447 
02448     /* Return function status */
02449     return HAL_OK;
02450   }
02451   else
02452   {
02453     /* Update error code */
02454     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
02455 
02456     return HAL_ERROR;
02457   }
02458 }
02459 
02460 /**
02461   * @brief  Disable ISO 11898-1 protocol mode.
02462   *         CAN FD frame format is according to Bosch CAN FD specification V1.0.
02463   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02464   *         the configuration information for the specified FDCAN.
02465   * @retval HAL status
02466   */
02467 HAL_StatusTypeDef HAL_FDCAN_DisableISOMode(FDCAN_HandleTypeDef *hfdcan)
02468 {
02469   if (hfdcan->State == HAL_FDCAN_STATE_READY)
02470   {
02471     /* Enable Non ISO protocol mode */
02472     SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_NISO);
02473 
02474     /* Return function status */
02475     return HAL_OK;
02476   }
02477   else
02478   {
02479     /* Update error code */
02480     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
02481 
02482     return HAL_ERROR;
02483   }
02484 }
02485 
02486 /**
02487   * @brief  Enable edge filtering during bus integration.
02488   *         Two consecutive dominant tq are required to detect an edge for hard synchronization.
02489   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02490   *         the configuration information for the specified FDCAN.
02491   * @retval HAL status
02492   */
02493 HAL_StatusTypeDef HAL_FDCAN_EnableEdgeFiltering(FDCAN_HandleTypeDef *hfdcan)
02494 {
02495   if (hfdcan->State == HAL_FDCAN_STATE_READY)
02496   {
02497     /* Enable edge filtering */
02498     SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_EFBI);
02499 
02500     /* Return function status */
02501     return HAL_OK;
02502   }
02503   else
02504   {
02505     /* Update error code */
02506     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
02507 
02508     return HAL_ERROR;
02509   }
02510 }
02511 
02512 /**
02513   * @brief  Disable edge filtering during bus integration.
02514   *         One dominant tq is required to detect an edge for hard synchronization.
02515   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02516   *         the configuration information for the specified FDCAN.
02517   * @retval HAL status
02518   */
02519 HAL_StatusTypeDef HAL_FDCAN_DisableEdgeFiltering(FDCAN_HandleTypeDef *hfdcan)
02520 {
02521   if (hfdcan->State == HAL_FDCAN_STATE_READY)
02522   {
02523     /* Disable edge filtering */
02524     CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_EFBI);
02525 
02526     /* Return function status */
02527     return HAL_OK;
02528   }
02529   else
02530   {
02531     /* Update error code */
02532     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
02533 
02534     return HAL_ERROR;
02535   }
02536 }
02537 
02538 /**
02539   * @}
02540   */
02541 
02542 /** @defgroup FDCAN_Exported_Functions_Group3 Control functions
02543  *  @brief    Control functions
02544  *
02545 @verbatim
02546   ==============================================================================
02547                           ##### Control functions #####
02548   ==============================================================================
02549     [..]  This section provides functions allowing to:
02550       (+) HAL_FDCAN_Start                         : Start the FDCAN module
02551       (+) HAL_FDCAN_Stop                          : Stop the FDCAN module and enable access to configuration registers
02552       (+) HAL_FDCAN_AddMessageToTxFifoQ           : Add a message to the Tx FIFO/Queue and activate the corresponding transmission request
02553       (+) HAL_FDCAN_AddMessageToTxBuffer          : Add a message to a dedicated Tx buffer
02554       (+) HAL_FDCAN_EnableTxBufferRequest         : Enable transmission request
02555       (+) HAL_FDCAN_GetLatestTxFifoQRequestBuffer : Get Tx buffer index of latest Tx FIFO/Queue request
02556       (+) HAL_FDCAN_AbortTxRequest                : Abort transmission request
02557       (+) HAL_FDCAN_GetRxMessage                  : Get an FDCAN frame from the Rx Buffer/FIFO zone into the message RAM
02558       (+) HAL_FDCAN_GetTxEvent                    : Get an FDCAN Tx event from the Tx Event FIFO zone into the message RAM
02559       (+) HAL_FDCAN_GetHighPriorityMessageStatus  : Get high priority message status
02560       (+) HAL_FDCAN_GetProtocolStatus             : Get protocol status
02561       (+) HAL_FDCAN_GetErrorCounters              : Get error counter values
02562       (+) HAL_FDCAN_IsRxBufferMessageAvailable    : Check if a new message is received in the selected Rx buffer
02563       (+) HAL_FDCAN_IsTxBufferMessagePending      : Check if a transmission request is pending on the selected Tx buffer
02564       (+) HAL_FDCAN_GetRxFifoFillLevel            : Return Rx FIFO fill level
02565       (+) HAL_FDCAN_GetTxFifoFreeLevel            : Return Tx FIFO free level
02566       (+) HAL_FDCAN_IsRestrictedOperationMode     : Check if the FDCAN peripheral entered Restricted Operation Mode
02567       (+) HAL_FDCAN_ExitRestrictedOperationMode   : Exit Restricted Operation Mode
02568 
02569 @endverbatim
02570   * @{
02571   */
02572 
02573 /**
02574   * @brief  Start the FDCAN module.
02575   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02576   *         the configuration information for the specified FDCAN.
02577   * @retval HAL status
02578   */
02579 HAL_StatusTypeDef HAL_FDCAN_Start(FDCAN_HandleTypeDef *hfdcan)
02580 {
02581   if (hfdcan->State == HAL_FDCAN_STATE_READY)
02582   {
02583     /* Change FDCAN peripheral state */
02584     hfdcan->State = HAL_FDCAN_STATE_BUSY;
02585 
02586     /* Request leave initialisation */
02587     CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT);
02588 
02589     /* Reset the FDCAN ErrorCode */
02590     hfdcan->ErrorCode = HAL_FDCAN_ERROR_NONE;
02591 
02592     /* Return function status */
02593     return HAL_OK;
02594   }
02595   else
02596   {
02597     /* Update error code */
02598     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
02599 
02600     return HAL_ERROR;
02601   }
02602 }
02603 
02604 /**
02605   * @brief  Stop the FDCAN module and enable access to configuration registers.
02606   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02607   *         the configuration information for the specified FDCAN.
02608   * @retval HAL status
02609   */
02610 HAL_StatusTypeDef HAL_FDCAN_Stop(FDCAN_HandleTypeDef *hfdcan)
02611 {
02612   uint32_t Counter = 0U;
02613 
02614   if (hfdcan->State == HAL_FDCAN_STATE_BUSY)
02615   {
02616     /* Request initialisation */
02617     SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT);
02618 
02619     /* Wait until the INIT bit into CCCR register is set */
02620     while ((hfdcan->Instance->CCCR & FDCAN_CCCR_INIT) == 0U)
02621     {
02622       /* Check for the Timeout */
02623       if (Counter > FDCAN_TIMEOUT_COUNT)
02624       {
02625         /* Update error code */
02626         hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
02627 
02628         /* Change FDCAN state */
02629         hfdcan->State = HAL_FDCAN_STATE_ERROR;
02630 
02631         return HAL_ERROR;
02632       }
02633 
02634       /* Increment counter */
02635       Counter++;
02636     }
02637 
02638     /* Reset counter */
02639     Counter = 0U;
02640 
02641     /* Exit from Sleep mode */
02642     CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CSR);
02643 
02644     /* Wait until FDCAN exits sleep mode */
02645     while ((hfdcan->Instance->CCCR & FDCAN_CCCR_CSA) == FDCAN_CCCR_CSA)
02646     {
02647       /* Check for the Timeout */
02648       if (Counter > FDCAN_TIMEOUT_COUNT)
02649       {
02650         /* Update error code */
02651         hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
02652 
02653         /* Change FDCAN state */
02654         hfdcan->State = HAL_FDCAN_STATE_ERROR;
02655 
02656         return HAL_ERROR;
02657       }
02658 
02659       /* Increment counter */
02660       Counter++;
02661     }
02662 
02663     /* Enable configuration change */
02664     SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CCE);
02665 
02666     /* Reset Latest Tx FIFO/Queue Request Buffer Index */
02667     hfdcan->LatestTxFifoQRequest = 0U;
02668 
02669     /* Change FDCAN peripheral state */
02670     hfdcan->State = HAL_FDCAN_STATE_READY;
02671 
02672     /* Return function status */
02673     return HAL_OK;
02674   }
02675   else
02676   {
02677     /* Update error code */
02678     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
02679 
02680     return HAL_ERROR;
02681   }
02682 }
02683 
02684 /**
02685   * @brief  Add a message to the Tx FIFO/Queue and activate the corresponding transmission request
02686   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02687   *         the configuration information for the specified FDCAN.
02688   * @param  pTxHeader pointer to a FDCAN_TxHeaderTypeDef structure.
02689   * @param  pTxData pointer to a buffer containing the payload of the Tx frame.
02690   * @retval HAL status
02691   */
02692 HAL_StatusTypeDef HAL_FDCAN_AddMessageToTxFifoQ(FDCAN_HandleTypeDef *hfdcan, FDCAN_TxHeaderTypeDef *pTxHeader, uint8_t *pTxData)
02693 {
02694   uint32_t PutIndex;
02695 
02696   /* Check function parameters */
02697   assert_param(IS_FDCAN_ID_TYPE(pTxHeader->IdType));
02698   if (pTxHeader->IdType == FDCAN_STANDARD_ID)
02699   {
02700     assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->Identifier, 0x7FFU));
02701   }
02702   else /* pTxHeader->IdType == FDCAN_EXTENDED_ID */
02703   {
02704     assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->Identifier, 0x1FFFFFFFU));
02705   }
02706   assert_param(IS_FDCAN_FRAME_TYPE(pTxHeader->TxFrameType));
02707   assert_param(IS_FDCAN_DLC(pTxHeader->DataLength));
02708   assert_param(IS_FDCAN_ESI(pTxHeader->ErrorStateIndicator));
02709   assert_param(IS_FDCAN_BRS(pTxHeader->BitRateSwitch));
02710   assert_param(IS_FDCAN_FDF(pTxHeader->FDFormat));
02711   assert_param(IS_FDCAN_EFC(pTxHeader->TxEventFifoControl));
02712   assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->MessageMarker, 0xFFU));
02713 
02714   if (hfdcan->State == HAL_FDCAN_STATE_BUSY)
02715   {
02716     /* Check that the Tx FIFO/Queue has an allocated area into the RAM */
02717     if ((hfdcan->Instance->TXBC & FDCAN_TXBC_TFQS) == 0U)
02718     {
02719       /* Update error code */
02720       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
02721 
02722       return HAL_ERROR;
02723     }
02724 
02725     /* Check that the Tx FIFO/Queue is not full */
02726     if ((hfdcan->Instance->TXFQS & FDCAN_TXFQS_TFQF) != 0U)
02727     {
02728       /* Update error code */
02729       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_FIFO_FULL;
02730 
02731       return HAL_ERROR;
02732     }
02733     else
02734     {
02735       /* Retrieve the Tx FIFO PutIndex */
02736       PutIndex = ((hfdcan->Instance->TXFQS & FDCAN_TXFQS_TFQPI) >> FDCAN_TXFQS_TFQPI_Pos);
02737 
02738       /* Add the message to the Tx FIFO/Queue */
02739       FDCAN_CopyMessageToRAM(hfdcan, pTxHeader, pTxData, PutIndex);
02740 
02741       /* Activate the corresponding transmission request */
02742       hfdcan->Instance->TXBAR = ((uint32_t)1 << PutIndex);
02743 
02744       /* Store the Latest Tx FIFO/Queue Request Buffer Index */
02745       hfdcan->LatestTxFifoQRequest = ((uint32_t)1 << PutIndex);
02746     }
02747 
02748     /* Return function status */
02749     return HAL_OK;
02750   }
02751   else
02752   {
02753     /* Update error code */
02754     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
02755 
02756     return HAL_ERROR;
02757   }
02758 }
02759 
02760 /**
02761   * @brief  Add a message to a dedicated Tx buffer
02762   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02763   *         the configuration information for the specified FDCAN.
02764   * @param  pTxHeader pointer to a FDCAN_TxHeaderTypeDef structure.
02765   * @param  pTxData pointer to a buffer containing the payload of the Tx frame.
02766   * @param  BufferIndex index of the buffer to be configured.
02767   *         This parameter can be a value of @arg FDCAN_Tx_location.
02768   * @retval HAL status
02769   */
02770 HAL_StatusTypeDef HAL_FDCAN_AddMessageToTxBuffer(FDCAN_HandleTypeDef *hfdcan, FDCAN_TxHeaderTypeDef *pTxHeader, uint8_t *pTxData, uint32_t BufferIndex)
02771 {
02772   HAL_FDCAN_StateTypeDef state = hfdcan->State;
02773 
02774   /* Check function parameters */
02775   assert_param(IS_FDCAN_ID_TYPE(pTxHeader->IdType));
02776   if (pTxHeader->IdType == FDCAN_STANDARD_ID)
02777   {
02778     assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->Identifier, 0x7FFU));
02779   }
02780   else /* pTxHeader->IdType == FDCAN_EXTENDED_ID */
02781   {
02782     assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->Identifier, 0x1FFFFFFFU));
02783   }
02784   assert_param(IS_FDCAN_FRAME_TYPE(pTxHeader->TxFrameType));
02785   assert_param(IS_FDCAN_DLC(pTxHeader->DataLength));
02786   assert_param(IS_FDCAN_ESI(pTxHeader->ErrorStateIndicator));
02787   assert_param(IS_FDCAN_BRS(pTxHeader->BitRateSwitch));
02788   assert_param(IS_FDCAN_FDF(pTxHeader->FDFormat));
02789   assert_param(IS_FDCAN_EFC(pTxHeader->TxEventFifoControl));
02790   assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->MessageMarker, 0xFFU));
02791   assert_param(IS_FDCAN_TX_LOCATION(BufferIndex));
02792 
02793   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
02794   {
02795     /* Check that the selected buffer has an allocated area into the RAM */
02796     if (POSITION_VAL(BufferIndex) >= ((hfdcan->Instance->TXBC & FDCAN_TXBC_NDTB) >> FDCAN_TXBC_NDTB_Pos))
02797     {
02798       /* Update error code */
02799       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
02800 
02801       return HAL_ERROR;
02802     }
02803 
02804     /* Check that there is no transmission request pending for the selected buffer */
02805     if ((hfdcan->Instance->TXBRP & BufferIndex) != 0U)
02806     {
02807       /* Update error code */
02808       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PENDING;
02809 
02810       return HAL_ERROR;
02811     }
02812     else
02813     {
02814       /* Add the message to the Tx buffer */
02815       FDCAN_CopyMessageToRAM(hfdcan, pTxHeader, pTxData, POSITION_VAL(BufferIndex));
02816     }
02817 
02818     /* Return function status */
02819     return HAL_OK;
02820   }
02821   else
02822   {
02823     /* Update error code */
02824     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
02825 
02826     return HAL_ERROR;
02827   }
02828 }
02829 
02830 /**
02831   * @brief  Enable transmission request.
02832   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02833   *         the configuration information for the specified FDCAN.
02834   * @param  BufferIndex buffer index.
02835   *         This parameter can be any combination of @arg FDCAN_Tx_location.
02836   * @retval HAL status
02837   */
02838 HAL_StatusTypeDef HAL_FDCAN_EnableTxBufferRequest(FDCAN_HandleTypeDef *hfdcan, uint32_t BufferIndex)
02839 {
02840   if (hfdcan->State == HAL_FDCAN_STATE_BUSY)
02841   {
02842     /* Add transmission request */
02843     hfdcan->Instance->TXBAR = BufferIndex;
02844 
02845     /* Return function status */
02846     return HAL_OK;
02847   }
02848   else
02849   {
02850     /* Update error code */
02851     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
02852 
02853     return HAL_ERROR;
02854   }
02855 }
02856 
02857 /**
02858   * @brief  Get Tx buffer index of latest Tx FIFO/Queue request
02859   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02860   *         the configuration information for the specified FDCAN.
02861   * @retval Tx buffer index of last Tx FIFO/Queue request
02862   *          - Any value of @arg FDCAN_Tx_location if Tx request has been submitted.
02863   *          - 0 if no Tx FIFO/Queue request have been submitted.
02864   */
02865 uint32_t HAL_FDCAN_GetLatestTxFifoQRequestBuffer(FDCAN_HandleTypeDef *hfdcan)
02866 {
02867   /* Return Last Tx FIFO/Queue Request Buffer */
02868   return hfdcan->LatestTxFifoQRequest;
02869 }
02870 
02871 /**
02872   * @brief  Abort transmission request
02873   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02874   *         the configuration information for the specified FDCAN.
02875   * @param  BufferIndex buffer index.
02876   *         This parameter can be any combination of @arg FDCAN_Tx_location.
02877   * @retval HAL status
02878   */
02879 HAL_StatusTypeDef HAL_FDCAN_AbortTxRequest(FDCAN_HandleTypeDef *hfdcan, uint32_t BufferIndex)
02880 {
02881   if (hfdcan->State == HAL_FDCAN_STATE_BUSY)
02882   {
02883     /* Add cancellation request */
02884     hfdcan->Instance->TXBCR = BufferIndex;
02885 
02886     /* Return function status */
02887     return HAL_OK;
02888   }
02889   else
02890   {
02891     /* Update error code */
02892     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
02893 
02894     return HAL_ERROR;
02895   }
02896 }
02897 
02898 /**
02899   * @brief  Get an FDCAN frame from the Rx Buffer/FIFO zone into the message RAM.
02900   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
02901   *         the configuration information for the specified FDCAN.
02902   * @param  RxLocation Location of the received message to be read.
02903   *         This parameter can be a value of @arg FDCAN_Rx_location.
02904   * @param  pRxHeader pointer to a FDCAN_RxHeaderTypeDef structure.
02905   * @param  pRxData pointer to a buffer where the payload of the Rx frame will be stored.
02906   * @retval HAL status
02907   */
02908 HAL_StatusTypeDef HAL_FDCAN_GetRxMessage(FDCAN_HandleTypeDef *hfdcan, uint32_t RxLocation, FDCAN_RxHeaderTypeDef *pRxHeader, uint8_t *pRxData)
02909 {
02910   uint32_t *RxAddress;
02911   uint8_t  *pData;
02912   uint32_t ByteCounter;
02913   uint32_t GetIndex = 0;
02914   HAL_FDCAN_StateTypeDef state = hfdcan->State;
02915 
02916   if (state == HAL_FDCAN_STATE_BUSY)
02917   {
02918     if (RxLocation == FDCAN_RX_FIFO0) /* Rx element is assigned to the Rx FIFO 0 */
02919     {
02920       /* Check that the Rx FIFO 0 has an allocated area into the RAM */
02921       if ((hfdcan->Instance->RXF0C & FDCAN_RXF0C_F0S) == 0U)
02922       {
02923         /* Update error code */
02924         hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
02925 
02926         return HAL_ERROR;
02927       }
02928 
02929       /* Check that the Rx FIFO 0 is not empty */
02930       if ((hfdcan->Instance->RXF0S & FDCAN_RXF0S_F0FL) == 0U)
02931       {
02932         /* Update error code */
02933         hfdcan->ErrorCode |= HAL_FDCAN_ERROR_FIFO_EMPTY;
02934 
02935         return HAL_ERROR;
02936       }
02937       else
02938       {
02939         /* Check that the Rx FIFO 0 is full & overwrite mode is on*/
02940         if(((hfdcan->Instance->RXF0S & FDCAN_RXF0S_F0F) >> FDCAN_RXF0S_F0F_Pos) == 1U)
02941         {
02942           if(((hfdcan->Instance->RXF0C & FDCAN_RXF0C_F0OM) >> FDCAN_RXF0C_F0OM_Pos) == FDCAN_RX_FIFO_OVERWRITE)
02943           {
02944             /* When overwrite status is on discard first message in FIFO */
02945             GetIndex = 1U;
02946           }
02947         }
02948 
02949         /* Calculate Rx FIFO 0 element index*/
02950         GetIndex += ((hfdcan->Instance->RXF0S & FDCAN_RXF0S_F0GI) >> FDCAN_RXF0S_F0GI_Pos);
02951 
02952         /* Calculate Rx FIFO 0 element address */
02953         RxAddress = (uint32_t *)(hfdcan->msgRam.RxFIFO0SA + (GetIndex * hfdcan->Init.RxFifo0ElmtSize * 4U));
02954       }
02955     }
02956     else if (RxLocation == FDCAN_RX_FIFO1) /* Rx element is assigned to the Rx FIFO 1 */
02957     {
02958       /* Check that the Rx FIFO 1 has an allocated area into the RAM */
02959       if ((hfdcan->Instance->RXF1C & FDCAN_RXF1C_F1S) == 0U)
02960       {
02961         /* Update error code */
02962         hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
02963 
02964         return HAL_ERROR;
02965       }
02966 
02967       /* Check that the Rx FIFO 0 is not empty */
02968       if ((hfdcan->Instance->RXF1S & FDCAN_RXF1S_F1FL) == 0U)
02969       {
02970         /* Update error code */
02971         hfdcan->ErrorCode |= HAL_FDCAN_ERROR_FIFO_EMPTY;
02972 
02973         return HAL_ERROR;
02974       }
02975       else
02976       {
02977         /* Check that the Rx FIFO 1 is full & overwrite mode is on*/
02978         if(((hfdcan->Instance->RXF1S & FDCAN_RXF1S_F1F) >> FDCAN_RXF1S_F1F_Pos) == 1U)
02979         {
02980           if(((hfdcan->Instance->RXF1C & FDCAN_RXF1C_F1OM) >> FDCAN_RXF1C_F1OM_Pos) == FDCAN_RX_FIFO_OVERWRITE)
02981           {
02982             /* When overwrite status is on discard first message in FIFO */
02983             GetIndex = 1U;
02984           }
02985         }
02986 
02987         /* Calculate Rx FIFO 1 element index*/
02988         GetIndex += ((hfdcan->Instance->RXF1S & FDCAN_RXF1S_F1GI) >> FDCAN_RXF1S_F1GI_Pos);
02989 
02990         /* Calculate Rx FIFO 1 element address */
02991         RxAddress = (uint32_t *)(hfdcan->msgRam.RxFIFO1SA + (GetIndex * hfdcan->Init.RxFifo1ElmtSize * 4U));
02992       }
02993     }
02994     else /* Rx element is assigned to a dedicated Rx buffer */
02995     {
02996       /* Check that the selected buffer has an allocated area into the RAM */
02997       if (RxLocation >= hfdcan->Init.RxBuffersNbr)
02998       {
02999         /* Update error code */
03000         hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
03001 
03002         return HAL_ERROR;
03003       }
03004       else
03005       {
03006         /* Calculate Rx buffer address */
03007         RxAddress = (uint32_t *)(hfdcan->msgRam.RxBufferSA + (RxLocation * hfdcan->Init.RxBufferSize * 4U));
03008       }
03009     }
03010 
03011     /* Retrieve IdType */
03012     pRxHeader->IdType = *RxAddress & FDCAN_ELEMENT_MASK_XTD;
03013 
03014     /* Retrieve Identifier */
03015     if (pRxHeader->IdType == FDCAN_STANDARD_ID) /* Standard ID element */
03016     {
03017       pRxHeader->Identifier = ((*RxAddress & FDCAN_ELEMENT_MASK_STDID) >> 18);
03018     }
03019     else /* Extended ID element */
03020     {
03021       pRxHeader->Identifier = (*RxAddress & FDCAN_ELEMENT_MASK_EXTID);
03022     }
03023 
03024     /* Retrieve RxFrameType */
03025     pRxHeader->RxFrameType = (*RxAddress & FDCAN_ELEMENT_MASK_RTR);
03026 
03027     /* Retrieve ErrorStateIndicator */
03028     pRxHeader->ErrorStateIndicator = (*RxAddress & FDCAN_ELEMENT_MASK_ESI);
03029 
03030     /* Increment RxAddress pointer to second word of Rx FIFO element */
03031     RxAddress++;
03032 
03033     /* Retrieve RxTimestamp */
03034     pRxHeader->RxTimestamp = (*RxAddress & FDCAN_ELEMENT_MASK_TS);
03035 
03036     /* Retrieve DataLength */
03037     pRxHeader->DataLength = (*RxAddress & FDCAN_ELEMENT_MASK_DLC);
03038 
03039     /* Retrieve BitRateSwitch */
03040     pRxHeader->BitRateSwitch = (*RxAddress & FDCAN_ELEMENT_MASK_BRS);
03041 
03042     /* Retrieve FDFormat */
03043     pRxHeader->FDFormat = (*RxAddress & FDCAN_ELEMENT_MASK_FDF);
03044 
03045     /* Retrieve FilterIndex */
03046     pRxHeader->FilterIndex = ((*RxAddress & FDCAN_ELEMENT_MASK_FIDX) >> 24);
03047 
03048     /* Retrieve NonMatchingFrame */
03049     pRxHeader->IsFilterMatchingFrame = ((*RxAddress & FDCAN_ELEMENT_MASK_ANMF) >> 31);
03050 
03051     /* Increment RxAddress pointer to payload of Rx FIFO element */
03052     RxAddress++;
03053 
03054     /* Retrieve Rx payload */
03055     pData = (uint8_t *)RxAddress;
03056     for (ByteCounter = 0; ByteCounter < DLCtoBytes[pRxHeader->DataLength >> 16]; ByteCounter++)
03057     {
03058       pRxData[ByteCounter] = pData[ByteCounter];
03059     }
03060 
03061     if (RxLocation == FDCAN_RX_FIFO0) /* Rx element is assigned to the Rx FIFO 0 */
03062     {
03063       /* Acknowledge the Rx FIFO 0 that the oldest element is read so that it increments the GetIndex */
03064       hfdcan->Instance->RXF0A = GetIndex;
03065     }
03066     else if (RxLocation == FDCAN_RX_FIFO1) /* Rx element is assigned to the Rx FIFO 1 */
03067     {
03068       /* Acknowledge the Rx FIFO 1 that the oldest element is read so that it increments the GetIndex */
03069       hfdcan->Instance->RXF1A = GetIndex;
03070     }
03071     else /* Rx element is assigned to a dedicated Rx buffer */
03072     {
03073       /* Clear the New Data flag of the current Rx buffer */
03074       if (RxLocation < FDCAN_RX_BUFFER32)
03075       {
03076         hfdcan->Instance->NDAT1 = ((uint32_t)1 << RxLocation);
03077       }
03078       else /* FDCAN_RX_BUFFER32 <= RxLocation <= FDCAN_RX_BUFFER63 */
03079       {
03080         hfdcan->Instance->NDAT2 = ((uint32_t)1 << (RxLocation & 0x1FU));
03081       }
03082     }
03083 
03084     /* Return function status */
03085     return HAL_OK;
03086   }
03087   else
03088   {
03089     /* Update error code */
03090     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
03091 
03092     return HAL_ERROR;
03093   }
03094 }
03095 
03096 /**
03097   * @brief  Get an FDCAN Tx event from the Tx Event FIFO zone into the message RAM.
03098   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
03099   *         the configuration information for the specified FDCAN.
03100   * @param  pTxEvent pointer to a FDCAN_TxEventFifoTypeDef structure.
03101   * @retval HAL status
03102   */
03103 HAL_StatusTypeDef HAL_FDCAN_GetTxEvent(FDCAN_HandleTypeDef *hfdcan, FDCAN_TxEventFifoTypeDef *pTxEvent)
03104 {
03105   uint32_t *TxEventAddress;
03106   uint32_t GetIndex;
03107   HAL_FDCAN_StateTypeDef state = hfdcan->State;
03108 
03109   /* Check function parameters */
03110   assert_param(IS_FDCAN_MIN_VALUE(hfdcan->Init.TxEventsNbr, 1U));
03111 
03112   if (state == HAL_FDCAN_STATE_BUSY)
03113   {
03114     /* Check that the Tx Event FIFO has an allocated area into the RAM */
03115     if ((hfdcan->Instance->TXEFC & FDCAN_TXEFC_EFS) == 0U)
03116     {
03117       /* Update error code */
03118       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
03119 
03120       return HAL_ERROR;
03121     }
03122 
03123     /* Check that the Tx event FIFO is not empty */
03124     if ((hfdcan->Instance->TXEFS & FDCAN_TXEFS_EFFL) == 0U)
03125     {
03126       /* Update error code */
03127       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_FIFO_EMPTY;
03128 
03129       return HAL_ERROR;
03130     }
03131 
03132     /* Calculate Tx event FIFO element address */
03133     GetIndex = ((hfdcan->Instance->TXEFS & FDCAN_TXEFS_EFGI) >> FDCAN_TXEFS_EFGI_Pos);
03134     TxEventAddress = (uint32_t *)(hfdcan->msgRam.TxEventFIFOSA + (GetIndex * 2U * 4U));
03135 
03136     /* Retrieve IdType */
03137     pTxEvent->IdType = *TxEventAddress & FDCAN_ELEMENT_MASK_XTD;
03138 
03139     /* Retrieve Identifier */
03140     if (pTxEvent->IdType == FDCAN_STANDARD_ID) /* Standard ID element */
03141     {
03142       pTxEvent->Identifier = ((*TxEventAddress & FDCAN_ELEMENT_MASK_STDID) >> 18U);
03143     }
03144     else /* Extended ID element */
03145     {
03146       pTxEvent->Identifier = (*TxEventAddress & FDCAN_ELEMENT_MASK_EXTID);
03147     }
03148 
03149     /* Retrieve TxFrameType */
03150     pTxEvent->TxFrameType = (*TxEventAddress & FDCAN_ELEMENT_MASK_RTR);
03151 
03152     /* Retrieve ErrorStateIndicator */
03153     pTxEvent->ErrorStateIndicator = (*TxEventAddress & FDCAN_ELEMENT_MASK_ESI);
03154 
03155     /* Increment TxEventAddress pointer to second word of Tx Event FIFO element */
03156     TxEventAddress++;
03157 
03158     /* Retrieve TxTimestamp */
03159     pTxEvent->TxTimestamp = (*TxEventAddress & FDCAN_ELEMENT_MASK_TS);
03160 
03161     /* Retrieve DataLength */
03162     pTxEvent->DataLength = (*TxEventAddress & FDCAN_ELEMENT_MASK_DLC);
03163 
03164     /* Retrieve BitRateSwitch */
03165     pTxEvent->BitRateSwitch = (*TxEventAddress & FDCAN_ELEMENT_MASK_BRS);
03166 
03167     /* Retrieve FDFormat */
03168     pTxEvent->FDFormat = (*TxEventAddress & FDCAN_ELEMENT_MASK_FDF);
03169 
03170     /* Retrieve EventType */
03171     pTxEvent->EventType = (*TxEventAddress & FDCAN_ELEMENT_MASK_ET);
03172 
03173     /* Retrieve MessageMarker */
03174     pTxEvent->MessageMarker = ((*TxEventAddress & FDCAN_ELEMENT_MASK_MM) >> 24);
03175 
03176     /* Acknowledge the Tx Event FIFO that the oldest element is read so that it increments the GetIndex */
03177     hfdcan->Instance->TXEFA = GetIndex;
03178 
03179     /* Return function status */
03180     return HAL_OK;
03181   }
03182   else
03183   {
03184     /* Update error code */
03185     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
03186 
03187     return HAL_ERROR;
03188   }
03189 }
03190 
03191 /**
03192   * @brief  Get high priority message status.
03193   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
03194   *         the configuration information for the specified FDCAN.
03195   * @param  HpMsgStatus pointer to an FDCAN_HpMsgStatusTypeDef structure.
03196   * @retval HAL status
03197   */
03198 HAL_StatusTypeDef HAL_FDCAN_GetHighPriorityMessageStatus(FDCAN_HandleTypeDef *hfdcan, FDCAN_HpMsgStatusTypeDef *HpMsgStatus)
03199 {
03200   HpMsgStatus->FilterList = ((hfdcan->Instance->HPMS & FDCAN_HPMS_FLST) >> FDCAN_HPMS_FLST_Pos);
03201   HpMsgStatus->FilterIndex = ((hfdcan->Instance->HPMS & FDCAN_HPMS_FIDX) >> FDCAN_HPMS_FIDX_Pos);
03202   HpMsgStatus->MessageStorage = (hfdcan->Instance->HPMS & FDCAN_HPMS_MSI);
03203   HpMsgStatus->MessageIndex = (hfdcan->Instance->HPMS & FDCAN_HPMS_BIDX);
03204 
03205   /* Return function status */
03206   return HAL_OK;
03207 }
03208 
03209 /**
03210   * @brief  Get protocol status.
03211   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
03212   *         the configuration information for the specified FDCAN.
03213   * @param  ProtocolStatus pointer to an FDCAN_ProtocolStatusTypeDef structure.
03214   * @retval HAL status
03215   */
03216 HAL_StatusTypeDef HAL_FDCAN_GetProtocolStatus(FDCAN_HandleTypeDef *hfdcan, FDCAN_ProtocolStatusTypeDef *ProtocolStatus)
03217 {
03218   uint32_t StatusReg;
03219 
03220   /* Read the protocol status register */
03221   StatusReg = READ_REG(hfdcan->Instance->PSR);
03222 
03223   /* Fill the protocol status structure */
03224   ProtocolStatus->LastErrorCode = (StatusReg & FDCAN_PSR_LEC);
03225   ProtocolStatus->DataLastErrorCode = ((StatusReg & FDCAN_PSR_DLEC) >> FDCAN_PSR_DLEC_Pos);
03226   ProtocolStatus->Activity = (StatusReg & FDCAN_PSR_ACT);
03227   ProtocolStatus->ErrorPassive = ((StatusReg & FDCAN_PSR_EP) >> FDCAN_PSR_EP_Pos);
03228   ProtocolStatus->Warning = ((StatusReg & FDCAN_PSR_EW) >> FDCAN_PSR_EW_Pos);
03229   ProtocolStatus->BusOff = ((StatusReg & FDCAN_PSR_BO) >> FDCAN_PSR_BO_Pos);
03230   ProtocolStatus->RxESIflag = ((StatusReg & FDCAN_PSR_RESI) >> FDCAN_PSR_RESI_Pos);
03231   ProtocolStatus->RxBRSflag = ((StatusReg & FDCAN_PSR_RBRS) >> FDCAN_PSR_RBRS_Pos);
03232   ProtocolStatus->RxFDFflag = ((StatusReg & FDCAN_PSR_REDL) >> FDCAN_PSR_REDL_Pos);
03233   ProtocolStatus->ProtocolException = ((StatusReg & FDCAN_PSR_PXE) >> FDCAN_PSR_PXE_Pos);
03234   ProtocolStatus->TDCvalue = ((StatusReg & FDCAN_PSR_TDCV) >> FDCAN_PSR_TDCV_Pos);
03235 
03236   /* Return function status */
03237   return HAL_OK;
03238 }
03239 
03240 /**
03241   * @brief  Get error counter values.
03242   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
03243   *         the configuration information for the specified FDCAN.
03244   * @param  ErrorCounters pointer to an FDCAN_ErrorCountersTypeDef structure.
03245   * @retval HAL status
03246   */
03247 HAL_StatusTypeDef HAL_FDCAN_GetErrorCounters(FDCAN_HandleTypeDef *hfdcan, FDCAN_ErrorCountersTypeDef *ErrorCounters)
03248 {
03249   uint32_t CountersReg;
03250 
03251   /* Read the error counters register */
03252   CountersReg = READ_REG(hfdcan->Instance->ECR);
03253 
03254   /* Fill the error counters structure */
03255   ErrorCounters->TxErrorCnt = ((CountersReg & FDCAN_ECR_TEC) >> FDCAN_ECR_TEC_Pos);
03256   ErrorCounters->RxErrorCnt = ((CountersReg & FDCAN_ECR_REC) >> FDCAN_ECR_REC_Pos);
03257   ErrorCounters->RxErrorPassive = ((CountersReg & FDCAN_ECR_RP) >> FDCAN_ECR_RP_Pos);
03258   ErrorCounters->ErrorLogging = ((CountersReg & FDCAN_ECR_CEL) >> FDCAN_ECR_CEL_Pos);
03259 
03260   /* Return function status */
03261   return HAL_OK;
03262 }
03263 
03264 /**
03265   * @brief  Check if a new message is received in the selected Rx buffer.
03266   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
03267   *         the configuration information for the specified FDCAN.
03268   * @param  RxBufferIndex Rx buffer index.
03269   *         This parameter must be a number between 0 and 63.
03270   * @retval Status
03271   *          - 0 : No new message on RxBufferIndex.
03272   *          - 1 : New message received on RxBufferIndex.
03273   */
03274 uint32_t HAL_FDCAN_IsRxBufferMessageAvailable(FDCAN_HandleTypeDef *hfdcan, uint32_t RxBufferIndex)
03275 {
03276   /* Check function parameters */
03277   assert_param(IS_FDCAN_MAX_VALUE(RxBufferIndex, 63U));
03278   uint32_t NewData1 = hfdcan->Instance->NDAT1;
03279   uint32_t NewData2 = hfdcan->Instance->NDAT2;
03280 
03281   /* Check new message reception on the selected buffer */
03282   if (((RxBufferIndex < 32U) && ((NewData1 & (uint32_t)((uint32_t)1 << RxBufferIndex)) == 0U)) ||
03283       ((RxBufferIndex >= 32U) && ((NewData2 & (uint32_t)((uint32_t)1 << (RxBufferIndex & 0x1FU))) == 0U)))
03284   {
03285     return 0;
03286   }
03287 
03288   /* Clear the New Data flag of the current Rx buffer */
03289   if (RxBufferIndex < 32U)
03290   {
03291     hfdcan->Instance->NDAT1 = ((uint32_t)1 << RxBufferIndex);
03292   }
03293   else /* 32 <= RxBufferIndex <= 63 */
03294   {
03295     hfdcan->Instance->NDAT2 = ((uint32_t)1 << (RxBufferIndex & 0x1FU));
03296   }
03297 
03298   return 1;
03299 }
03300 
03301 /**
03302   * @brief  Check if a transmission request is pending on the selected Tx buffer.
03303   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
03304   *         the configuration information for the specified FDCAN.
03305   * @param  TxBufferIndex Tx buffer index.
03306   *         This parameter can be any combination of @arg FDCAN_Tx_location.
03307   * @retval Status
03308   *          - 0 : No pending transmission request on TxBufferIndex.
03309   *          - 1 : Pending transmission request on TxBufferIndex.
03310   */
03311 uint32_t HAL_FDCAN_IsTxBufferMessagePending(FDCAN_HandleTypeDef *hfdcan, uint32_t TxBufferIndex)
03312 {
03313   /* Check pending transmission request on the selected buffer */
03314   if ((hfdcan->Instance->TXBRP & TxBufferIndex) == 0U)
03315   {
03316     return 0;
03317   }
03318   return 1;
03319 }
03320 
03321 /**
03322   * @brief  Return Rx FIFO fill level.
03323   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
03324   *         the configuration information for the specified FDCAN.
03325   * @param  RxFifo Rx FIFO.
03326   *         This parameter can be one of the following values:
03327   *           @arg FDCAN_RX_FIFO0: Rx FIFO 0
03328   *           @arg FDCAN_RX_FIFO1: Rx FIFO 1
03329   * @retval Level Rx FIFO fill level.
03330   */
03331 uint32_t HAL_FDCAN_GetRxFifoFillLevel(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo)
03332 {
03333   uint32_t FillLevel;
03334 
03335   /* Check function parameters */
03336   assert_param(IS_FDCAN_RX_FIFO(RxFifo));
03337 
03338   if (RxFifo == FDCAN_RX_FIFO0)
03339   {
03340     FillLevel = hfdcan->Instance->RXF0S & FDCAN_RXF0S_F0FL;
03341   }
03342   else /* RxFifo == FDCAN_RX_FIFO1 */
03343   {
03344     FillLevel = hfdcan->Instance->RXF1S & FDCAN_RXF1S_F1FL;
03345   }
03346 
03347   /* Return Rx FIFO fill level */
03348   return FillLevel;
03349 }
03350 
03351 /**
03352   * @brief  Return Tx FIFO free level: number of consecutive free Tx FIFO
03353   *         elements starting from Tx FIFO GetIndex.
03354   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
03355   *         the configuration information for the specified FDCAN.
03356   * @retval Level Tx FIFO free level.
03357   */
03358 uint32_t HAL_FDCAN_GetTxFifoFreeLevel(FDCAN_HandleTypeDef *hfdcan)
03359 {
03360   uint32_t FreeLevel;
03361 
03362   FreeLevel = hfdcan->Instance->TXFQS & FDCAN_TXFQS_TFFL;
03363 
03364   /* Return Tx FIFO free level */
03365   return FreeLevel;
03366 }
03367 
03368 /**
03369   * @brief  Check if the FDCAN peripheral entered Restricted Operation Mode.
03370   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
03371   *         the configuration information for the specified FDCAN.
03372   * @retval Status
03373   *          - 0 : Normal FDCAN operation.
03374   *          - 1 : Restricted Operation Mode active.
03375   */
03376 uint32_t HAL_FDCAN_IsRestrictedOperationMode(FDCAN_HandleTypeDef *hfdcan)
03377 {
03378   uint32_t OperationMode;
03379 
03380   /* Get Operation Mode */
03381   OperationMode = ((hfdcan->Instance->CCCR & FDCAN_CCCR_ASM) >> FDCAN_CCCR_ASM_Pos);
03382 
03383   return OperationMode;
03384 }
03385 
03386 /**
03387   * @brief  Exit Restricted Operation Mode.
03388   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
03389   *         the configuration information for the specified FDCAN.
03390   * @retval HAL status
03391   */
03392 HAL_StatusTypeDef HAL_FDCAN_ExitRestrictedOperationMode(FDCAN_HandleTypeDef *hfdcan)
03393 {
03394   HAL_FDCAN_StateTypeDef state = hfdcan->State;
03395 
03396   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
03397   {
03398     /* Exit Restricted Operation mode */
03399     CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_ASM);
03400 
03401     /* Return function status */
03402     return HAL_OK;
03403   }
03404   else
03405   {
03406     /* Update error code */
03407     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
03408 
03409     return HAL_ERROR;
03410   }
03411 }
03412 
03413 /**
03414   * @}
03415   */
03416 
03417 /** @defgroup FDCAN_Exported_Functions_Group4 TT Configuration and control functions
03418  *  @brief    TT Configuration and control functions
03419  *
03420 @verbatim
03421   ==============================================================================
03422               ##### TT Configuration and control functions #####
03423   ==============================================================================
03424     [..]  This section provides functions allowing to:
03425       (+) HAL_FDCAN_TT_ConfigOperation                  : Initialize TT operation parameters
03426       (+) HAL_FDCAN_TT_ConfigReferenceMessage           : Configure the reference message
03427       (+) HAL_FDCAN_TT_ConfigTrigger                    : Configure the FDCAN trigger
03428       (+) HAL_FDCAN_TT_SetGlobalTime                    : Schedule global time adjustment
03429       (+) HAL_FDCAN_TT_SetClockSynchronization          : Schedule TUR numerator update
03430       (+) HAL_FDCAN_TT_ConfigStopWatch                  : Configure stop watch source and polarity
03431       (+) HAL_FDCAN_TT_ConfigRegisterTimeMark           : Configure register time mark pulse generation
03432         (+) HAL_FDCAN_TT_EnableRegisterTimeMarkPulse      : Enable register time mark pulse generation
03433         (+) HAL_FDCAN_TT_DisableRegisterTimeMarkPulse     : Disable register time mark pulse generation
03434       (+) HAL_FDCAN_TT_EnableTriggerTimeMarkPulse       : Enable trigger time mark pulse generation
03435       (+) HAL_FDCAN_TT_DisableTriggerTimeMarkPulse      : Disable trigger time mark pulse generation
03436       (+) HAL_FDCAN_TT_EnableHardwareGapControl         : Enable gap control by input pin fdcan1_evt
03437       (+) HAL_FDCAN_TT_DisableHardwareGapControl        : Disable gap control by input pin fdcan1_evt
03438       (+) HAL_FDCAN_TT_EnableTimeMarkGapControl         : Enable gap control (finish only) by register time mark interrupt
03439       (+) HAL_FDCAN_TT_DisableTimeMarkGapControl        : Disable gap control by register time mark interrupt
03440       (+) HAL_FDCAN_TT_SetNextIsGap                     : Transmit next reference message with Next_is_Gap = "1"
03441       (+) HAL_FDCAN_TT_SetEndOfGap                      : Finish a Gap by requesting start of reference message
03442       (+) HAL_FDCAN_TT_ConfigExternalSyncPhase          : Configure target phase used for external synchronization
03443         (+) HAL_FDCAN_TT_EnableExternalSynchronization    : Synchronize the phase of the FDCAN schedule to an external schedule
03444         (+) HAL_FDCAN_TT_DisableExternalSynchronization   : Disable external schedule synchronization
03445       (+) HAL_FDCAN_TT_GetOperationStatus               : Get TT operation status
03446 
03447 @endverbatim
03448   * @{
03449   */
03450 
03451 /**
03452   * @brief  Initialize TT operation parameters.
03453   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
03454   *         the configuration information for the specified FDCAN.
03455   * @param  pTTParams pointer to a FDCAN_TT_ConfigTypeDef structure.
03456   * @retval HAL status
03457   */
03458 HAL_StatusTypeDef HAL_FDCAN_TT_ConfigOperation(FDCAN_HandleTypeDef *hfdcan, FDCAN_TT_ConfigTypeDef *pTTParams)
03459 {
03460   uint32_t tickstart;
03461   uint32_t RAMcounter;
03462   uint32_t StartAddress;
03463 
03464   /* Check function parameters */
03465   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
03466   assert_param(IS_FDCAN_TT_TUR_NUMERATOR(pTTParams->TURNumerator));
03467   assert_param(IS_FDCAN_TT_TUR_DENOMINATOR(pTTParams->TURDenominator));
03468   assert_param(IS_FDCAN_TT_TIME_MASTER(pTTParams->TimeMaster));
03469   assert_param(IS_FDCAN_MAX_VALUE(pTTParams->SyncDevLimit, 7U));
03470   assert_param(IS_FDCAN_MAX_VALUE(pTTParams->InitRefTrigOffset, 127U));
03471   assert_param(IS_FDCAN_MAX_VALUE(pTTParams->TriggerMemoryNbr, 64U));
03472   assert_param(IS_FDCAN_TT_CYCLE_START_SYNC(pTTParams->CycleStartSync));
03473   assert_param(IS_FDCAN_TT_STOP_WATCH_TRIGGER(pTTParams->StopWatchTrigSel));
03474   assert_param(IS_FDCAN_TT_EVENT_TRIGGER(pTTParams->EventTrigSel));
03475   if (pTTParams->TimeMaster == FDCAN_TT_POTENTIAL_MASTER)
03476   {
03477     assert_param(IS_FDCAN_TT_BASIC_CYCLES_NUMBER(pTTParams->BasicCyclesNbr));
03478   }
03479   if (pTTParams->OperationMode != FDCAN_TT_COMMUNICATION_LEVEL0)
03480   {
03481     assert_param(IS_FDCAN_TT_OPERATION(pTTParams->GapEnable));
03482     assert_param(IS_FDCAN_MAX_VALUE(pTTParams->AppWdgLimit, 255U));
03483     assert_param(IS_FDCAN_TT_EVENT_TRIGGER_POLARITY(pTTParams->EvtTrigPolarity));
03484     assert_param(IS_FDCAN_TT_TX_ENABLE_WINDOW(pTTParams->TxEnableWindow));
03485     assert_param(IS_FDCAN_MAX_VALUE(pTTParams->ExpTxTrigNbr, 4095U));
03486   }
03487   if (pTTParams->OperationMode != FDCAN_TT_COMMUNICATION_LEVEL1)
03488   {
03489     assert_param(IS_FDCAN_TT_TUR_LEVEL_0_2(pTTParams->TURNumerator, pTTParams->TURDenominator));
03490     assert_param(IS_FDCAN_TT_EXTERNAL_CLK_SYNC(pTTParams->ExternalClkSync));
03491     assert_param(IS_FDCAN_TT_GLOBAL_TIME_FILTERING(pTTParams->GlobalTimeFilter));
03492     assert_param(IS_FDCAN_TT_AUTO_CLK_CALIBRATION(pTTParams->ClockCalibration));
03493   }
03494   else
03495   {
03496     assert_param(IS_FDCAN_TT_TUR_LEVEL_1(pTTParams->TURNumerator, pTTParams->TURDenominator));
03497   }
03498 
03499   if (hfdcan->State == HAL_FDCAN_STATE_READY)
03500   {
03501     /* Stop local time in order to enable write access to the other bits of TURCF register */
03502     CLEAR_BIT(hfdcan->ttcan->TURCF, FDCAN_TURCF_ELT);
03503 
03504     /* Get tick */
03505     tickstart = HAL_GetTick();
03506 
03507     /* Wait until the ELT bit into TURCF register is reset */
03508     while ((hfdcan->ttcan->TURCF & FDCAN_TURCF_ELT) != 0U)
03509     {
03510       /* Check for the Timeout */
03511       if ((HAL_GetTick() - tickstart) > FDCAN_TIMEOUT_VALUE)
03512       {
03513         /* Update error code */
03514         hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
03515 
03516         /* Change FDCAN state */
03517         hfdcan->State = HAL_FDCAN_STATE_ERROR;
03518 
03519         return HAL_ERROR;
03520       }
03521     }
03522 
03523     /* Configure TUR (Time Unit Ratio) */
03524     MODIFY_REG(hfdcan->ttcan->TURCF,
03525                (FDCAN_TURCF_NCL | FDCAN_TURCF_DC),
03526                (((pTTParams->TURNumerator - 0x10000U) << FDCAN_TURCF_NCL_Pos) | (pTTParams->TURDenominator << FDCAN_TURCF_DC_Pos)));
03527 
03528     /* Enable local time */
03529     SET_BIT(hfdcan->ttcan->TURCF, FDCAN_TURCF_ELT);
03530 
03531     /* Configure TT operation */
03532     MODIFY_REG(hfdcan->ttcan->TTOCF,
03533                (FDCAN_TTOCF_OM | FDCAN_TTOCF_TM | FDCAN_TTOCF_LDSDL | FDCAN_TTOCF_IRTO),
03534                (pTTParams->OperationMode                           | \
03535                 pTTParams->TimeMaster                              | \
03536                 (pTTParams->SyncDevLimit << FDCAN_TTOCF_LDSDL_Pos) | \
03537                 (pTTParams->InitRefTrigOffset << FDCAN_TTOCF_IRTO_Pos)));
03538     if (pTTParams->OperationMode != FDCAN_TT_COMMUNICATION_LEVEL0)
03539     {
03540       MODIFY_REG(hfdcan->ttcan->TTOCF,
03541                  (FDCAN_TTOCF_GEN | FDCAN_TTOCF_AWL | FDCAN_TTOCF_EVTP),
03542                  (pTTParams->GapEnable                            | \
03543                   (pTTParams->AppWdgLimit << FDCAN_TTOCF_AWL_Pos) | \
03544                   pTTParams->EvtTrigPolarity));
03545     }
03546     if (pTTParams->OperationMode != FDCAN_TT_COMMUNICATION_LEVEL1)
03547     {
03548       MODIFY_REG(hfdcan->ttcan->TTOCF,
03549                  (FDCAN_TTOCF_EECS | FDCAN_TTOCF_EGTF | FDCAN_TTOCF_ECC),
03550                  (pTTParams->ExternalClkSync  | \
03551                   pTTParams->GlobalTimeFilter | \
03552                   pTTParams->ClockCalibration));
03553     }
03554 
03555     /* Configure system matrix limits */
03556     MODIFY_REG(hfdcan->ttcan->TTMLM, FDCAN_TTMLM_CSS, pTTParams->CycleStartSync);
03557     if (pTTParams->OperationMode != FDCAN_TT_COMMUNICATION_LEVEL0)
03558     {
03559       MODIFY_REG(hfdcan->ttcan->TTMLM,
03560                  (FDCAN_TTMLM_TXEW | FDCAN_TTMLM_ENTT),
03561                  (((pTTParams->TxEnableWindow - 1U) << FDCAN_TTMLM_TXEW_Pos) | (pTTParams->ExpTxTrigNbr << FDCAN_TTMLM_ENTT_Pos)));
03562     }
03563     if (pTTParams->TimeMaster == FDCAN_TT_POTENTIAL_MASTER)
03564     {
03565       MODIFY_REG(hfdcan->ttcan->TTMLM, FDCAN_TTMLM_CCM, pTTParams->BasicCyclesNbr);
03566     }
03567 
03568     /* Configure input triggers: Stop watch and Event */
03569     MODIFY_REG(hfdcan->ttcan->TTTS,
03570                (FDCAN_TTTS_SWTSEL | FDCAN_TTTS_EVTSEL),
03571                (pTTParams->StopWatchTrigSel | pTTParams->EventTrigSel));
03572 
03573     /* Configure trigger memory start address */
03574     StartAddress = (hfdcan->msgRam.EndAddress - SRAMCAN_BASE) / 4U;
03575     MODIFY_REG(hfdcan->ttcan->TTTMC, FDCAN_TTTMC_TMSA, (StartAddress << FDCAN_TTTMC_TMSA_Pos));
03576 
03577     /* Trigger memory elements number */
03578     MODIFY_REG(hfdcan->ttcan->TTTMC, FDCAN_TTTMC_TME, (pTTParams->TriggerMemoryNbr << FDCAN_TTTMC_TME_Pos));
03579 
03580     /* Recalculate End Address */
03581     hfdcan->msgRam.TTMemorySA = hfdcan->msgRam.EndAddress;
03582     hfdcan->msgRam.EndAddress = hfdcan->msgRam.TTMemorySA + (pTTParams->TriggerMemoryNbr * 2U * 4U);
03583 
03584     if (hfdcan->msgRam.EndAddress > FDCAN_MESSAGE_RAM_END_ADDRESS) /* Last address of the Message RAM */
03585     {
03586       /* Update error code.
03587          Message RAM overflow */
03588       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
03589 
03590       return HAL_ERROR;
03591     }
03592     else
03593     {
03594       /* Flush the allocated Message RAM area */
03595       for (RAMcounter = hfdcan->msgRam.TTMemorySA; RAMcounter < hfdcan->msgRam.EndAddress; RAMcounter += 4U)
03596       {
03597         *(uint32_t *)(RAMcounter) = 0x00000000;
03598       }
03599     }
03600 
03601     /* Return function status */
03602     return HAL_OK;
03603   }
03604   else
03605   {
03606     /* Update error code */
03607     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
03608 
03609     return HAL_ERROR;
03610   }
03611 }
03612 
03613 /**
03614   * @brief  Configure the reference message.
03615   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
03616   *         the configuration information for the specified FDCAN.
03617   * @param  IdType Identifier Type.
03618   *         This parameter can be a value of @arg FDCAN_id_type.
03619   * @param  Identifier Reference Identifier.
03620   *         This parameter must be a number between:
03621   *           - 0 and 0x7FF, if IdType is FDCAN_STANDARD_ID
03622   *           - 0 and 0x1FFFFFFF, if IdType is FDCAN_EXTENDED_ID
03623   * @param  Payload Enable or disable the additional payload.
03624   *         This parameter can be a value of @arg FDCAN_TT_Reference_Message_Payload.
03625   *         This parameter is ignored in case of time slaves.
03626   *         If this parameter is set to FDCAN_TT_REF_MESSAGE_ADD_PAYLOAD, the
03627   *         following elements are taken from Tx Buffer 0:
03628   *          - MessageMarker
03629   *          - TxEventFifoControl
03630   *          - DataLength
03631   *          - Data Bytes (payload):
03632   *             - bytes 2-8, for Level 1
03633   *             - bytes 5-8, for Level 0 and Level 2
03634   * @retval HAL status
03635   */
03636 HAL_StatusTypeDef HAL_FDCAN_TT_ConfigReferenceMessage(FDCAN_HandleTypeDef *hfdcan, uint32_t IdType, uint32_t Identifier, uint32_t Payload)
03637 {
03638   /* Check function parameters */
03639   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
03640   assert_param(IS_FDCAN_ID_TYPE(IdType));
03641   if (IdType == FDCAN_STANDARD_ID)
03642   {
03643     assert_param(IS_FDCAN_MAX_VALUE(Identifier, 0x7FFU));
03644   }
03645   else /* IdType == FDCAN_EXTENDED_ID */
03646   {
03647     assert_param(IS_FDCAN_MAX_VALUE(Identifier, 0x1FFFFFFFU));
03648   }
03649   assert_param(IS_FDCAN_TT_REFERENCE_MESSAGE_PAYLOAD(Payload));
03650 
03651   if (hfdcan->State == HAL_FDCAN_STATE_READY)
03652   {
03653     /* Configure reference message identifier type, identifier and payload */
03654     if (IdType == FDCAN_EXTENDED_ID)
03655     {
03656       MODIFY_REG(hfdcan->ttcan->TTRMC, (FDCAN_TTRMC_RID | FDCAN_TTRMC_XTD | FDCAN_TTRMC_RMPS), (Payload | IdType | Identifier));
03657     }
03658     else /* IdType == FDCAN_STANDARD_ID */
03659     {
03660       MODIFY_REG(hfdcan->ttcan->TTRMC, (FDCAN_TTRMC_RID | FDCAN_TTRMC_XTD | FDCAN_TTRMC_RMPS), (Payload | IdType | (Identifier << 18)));
03661     }
03662 
03663     /* Return function status */
03664     return HAL_OK;
03665   }
03666   else
03667   {
03668     /* Update error code */
03669     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
03670 
03671     return HAL_ERROR;
03672   }
03673 }
03674 
03675 /**
03676   * @brief  Configure the FDCAN trigger according to the specified
03677   *         parameters in the FDCAN_TriggerTypeDef structure.
03678   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
03679   *         the configuration information for the specified FDCAN.
03680   * @param  sTriggerConfig pointer to an FDCAN_TriggerTypeDef structure that
03681   *         contains the trigger configuration information
03682   * @retval HAL status
03683   */
03684 HAL_StatusTypeDef HAL_FDCAN_TT_ConfigTrigger(FDCAN_HandleTypeDef *hfdcan, FDCAN_TriggerTypeDef *sTriggerConfig)
03685 {
03686   uint32_t CycleCode;
03687   uint32_t MessageNumber;
03688   uint32_t TriggerElementW1;
03689   uint32_t TriggerElementW2;
03690   uint32_t *TriggerAddress;
03691 
03692   /* Check function parameters */
03693   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
03694   assert_param(IS_FDCAN_MAX_VALUE(sTriggerConfig->TriggerIndex, 63U));
03695   assert_param(IS_FDCAN_MAX_VALUE(sTriggerConfig->TimeMark, 0xFFFFU));
03696   assert_param(IS_FDCAN_TT_REPEAT_FACTOR(sTriggerConfig->RepeatFactor));
03697   if (sTriggerConfig->RepeatFactor != FDCAN_TT_REPEAT_EVERY_CYCLE)
03698   {
03699     assert_param(IS_FDCAN_MAX_VALUE(sTriggerConfig->StartCycle, (sTriggerConfig->RepeatFactor - 1U)));
03700   }
03701   assert_param(IS_FDCAN_TT_TM_EVENT_INTERNAL(sTriggerConfig->TmEventInt));
03702   assert_param(IS_FDCAN_TT_TM_EVENT_EXTERNAL(sTriggerConfig->TmEventExt));
03703   assert_param(IS_FDCAN_TT_TRIGGER_TYPE(sTriggerConfig->TriggerType));
03704   assert_param(IS_FDCAN_ID_TYPE(sTriggerConfig->FilterType));
03705   if ((sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_SINGLE) ||
03706       (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_CONTINUOUS) ||
03707       (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_ARBITRATION) ||
03708       (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_MERGED))
03709   {
03710     assert_param(IS_FDCAN_TX_LOCATION(sTriggerConfig->TxBufferIndex));
03711   }
03712   if (sTriggerConfig->TriggerType == FDCAN_TT_RX_TRIGGER)
03713   {
03714     if (sTriggerConfig->FilterType == FDCAN_STANDARD_ID)
03715     {
03716       assert_param(IS_FDCAN_MAX_VALUE(sTriggerConfig->FilterIndex, 63U));
03717     }
03718     else /* sTriggerConfig->FilterType == FDCAN_EXTENDED_ID */
03719     {
03720       assert_param(IS_FDCAN_MAX_VALUE(sTriggerConfig->FilterIndex, 127U));
03721     }
03722   }
03723 
03724   if (hfdcan->State == HAL_FDCAN_STATE_READY)
03725   {
03726     /* Calculate cycle code */
03727     if (sTriggerConfig->RepeatFactor == FDCAN_TT_REPEAT_EVERY_CYCLE)
03728     {
03729       CycleCode = FDCAN_TT_REPEAT_EVERY_CYCLE;
03730     }
03731     else /* sTriggerConfig->RepeatFactor != FDCAN_TT_REPEAT_EVERY_CYCLE */
03732     {
03733       CycleCode = sTriggerConfig->RepeatFactor + sTriggerConfig->StartCycle;
03734     }
03735 
03736     /* Build first word of trigger element */
03737     TriggerElementW1 = ((sTriggerConfig->TimeMark << 16) | \
03738                         (CycleCode << 8)                 | \
03739                         sTriggerConfig->TmEventInt       | \
03740                         sTriggerConfig->TmEventExt       | \
03741                         sTriggerConfig->TriggerType);
03742 
03743     /* Select message number depending on trigger type (transmission or reception) */
03744     if (sTriggerConfig->TriggerType == FDCAN_TT_RX_TRIGGER)
03745     {
03746       MessageNumber = sTriggerConfig->FilterIndex;
03747     }
03748     else if ((sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_SINGLE) ||
03749              (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_CONTINUOUS) ||
03750              (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_ARBITRATION) ||
03751              (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_MERGED))
03752     {
03753       MessageNumber = POSITION_VAL(sTriggerConfig->TxBufferIndex);
03754     }
03755     else
03756     {
03757       MessageNumber = 0U;
03758     }
03759 
03760     /* Build second word of trigger element */
03761     TriggerElementW2 = ((sTriggerConfig->FilterType >> 7) | (MessageNumber << 16));
03762 
03763     /* Calculate trigger address */
03764     TriggerAddress = (uint32_t *)(hfdcan->msgRam.TTMemorySA + (sTriggerConfig->TriggerIndex * 4U * 2U));
03765 
03766     /* Write trigger element to the message RAM */
03767     *TriggerAddress = TriggerElementW1;
03768     TriggerAddress++;
03769     *TriggerAddress = TriggerElementW2;
03770 
03771     /* Return function status */
03772     return HAL_OK;
03773   }
03774   else
03775   {
03776     /* Update error code */
03777     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
03778 
03779     return HAL_ERROR;
03780   }
03781 }
03782 
03783 /**
03784   * @brief  Schedule global time adjustment for the next reference message.
03785   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
03786   *         the configuration information for the specified FDCAN.
03787   * @param  TimePreset time preset value.
03788   *         This parameter must be a number between:
03789   *           - 0x0000 and 0x7FFF, Next_Master_Ref_Mark = Current_Master_Ref_Mark + TimePreset
03790   *           or
03791   *           - 0x8001 and 0xFFFF, Next_Master_Ref_Mark = Current_Master_Ref_Mark - (0x10000 - TimePreset)
03792   * @retval HAL status
03793   */
03794 HAL_StatusTypeDef HAL_FDCAN_TT_SetGlobalTime(FDCAN_HandleTypeDef *hfdcan, uint32_t TimePreset)
03795 {
03796   uint32_t Counter = 0U;
03797   HAL_FDCAN_StateTypeDef state = hfdcan->State;
03798 
03799   /* Check function parameters */
03800   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
03801   assert_param(IS_FDCAN_TT_TIME_PRESET(TimePreset));
03802 
03803   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
03804   {
03805     /* Check that the external clock synchronization is enabled */
03806     if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_EECS) != FDCAN_TTOCF_EECS)
03807     {
03808       /* Update error code */
03809       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
03810 
03811       return HAL_ERROR;
03812     }
03813 
03814     /* Check that no global time preset is pending */
03815     if ((hfdcan->ttcan->TTOST & FDCAN_TTOST_WGTD) == FDCAN_TTOST_WGTD)
03816     {
03817       /* Update error code */
03818       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PENDING;
03819 
03820       return HAL_ERROR;
03821     }
03822 
03823     /* Configure time preset */
03824     MODIFY_REG(hfdcan->ttcan->TTGTP, FDCAN_TTGTP_TP, (TimePreset << FDCAN_TTGTP_TP_Pos));
03825 
03826     /* Wait until the LCKC bit into TTOCN register is reset */
03827     while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
03828     {
03829       /* Check for the Timeout */
03830       if (Counter > FDCAN_TIMEOUT_COUNT)
03831       {
03832         /* Update error code */
03833         hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
03834 
03835         /* Change FDCAN state */
03836         hfdcan->State = HAL_FDCAN_STATE_ERROR;
03837 
03838         return HAL_ERROR;
03839       }
03840 
03841       /* Increment counter */
03842       Counter++;
03843     }
03844 
03845     /* Schedule time preset to take effect by the next reference message */
03846     SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_SGT);
03847 
03848     /* Return function status */
03849     return HAL_OK;
03850   }
03851   else
03852   {
03853     /* Update error code */
03854     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
03855 
03856     return HAL_ERROR;
03857   }
03858 }
03859 
03860 /**
03861   * @brief  Schedule TUR numerator update for the next reference message.
03862   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
03863   *         the configuration information for the specified FDCAN.
03864   * @param  NewTURNumerator new value of the TUR numerator.
03865   *         This parameter must be a number between 0x10000 and 0x1FFFF.
03866   * @retval HAL status
03867   */
03868 HAL_StatusTypeDef HAL_FDCAN_TT_SetClockSynchronization(FDCAN_HandleTypeDef *hfdcan, uint32_t NewTURNumerator)
03869 {
03870   uint32_t Counter = 0U;
03871   HAL_FDCAN_StateTypeDef state = hfdcan->State;
03872 
03873   /* Check function parameters */
03874   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
03875   assert_param(IS_FDCAN_TT_TUR_NUMERATOR(NewTURNumerator));
03876 
03877   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
03878   {
03879     /* Check that the external clock synchronization is enabled */
03880     if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_EECS) != FDCAN_TTOCF_EECS)
03881     {
03882       /* Update error code */
03883       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
03884 
03885       return HAL_ERROR;
03886     }
03887 
03888     /* Check that no external clock synchronization is pending */
03889     if ((hfdcan->ttcan->TTOST & FDCAN_TTOST_WECS) == FDCAN_TTOST_WECS)
03890     {
03891       /* Update error code */
03892       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PENDING;
03893 
03894       return HAL_ERROR;
03895     }
03896 
03897     /* Configure new TUR numerator */
03898     MODIFY_REG(hfdcan->ttcan->TURCF, FDCAN_TURCF_NCL, (NewTURNumerator - 0x10000U));
03899 
03900     /* Wait until the LCKC bit into TTOCN register is reset */
03901     while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
03902     {
03903       /* Check for the Timeout */
03904       if (Counter > FDCAN_TIMEOUT_COUNT)
03905       {
03906         /* Update error code */
03907         hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
03908 
03909         /* Change FDCAN state */
03910         hfdcan->State = HAL_FDCAN_STATE_ERROR;
03911 
03912         return HAL_ERROR;
03913       }
03914 
03915       /* Increment counter */
03916       Counter++;
03917     }
03918 
03919     /* Schedule TUR numerator update by the next reference message */
03920     SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_ECS);
03921 
03922     /* Return function status */
03923     return HAL_OK;
03924   }
03925   else
03926   {
03927     /* Update error code */
03928     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
03929 
03930     return HAL_ERROR;
03931   }
03932 }
03933 
03934 /**
03935   * @brief  Configure stop watch source and polarity.
03936   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
03937   *         the configuration information for the specified FDCAN.
03938   * @param  Source stop watch source.
03939   *         This parameter can be a value of @arg FDCAN_TT_stop_watch_source.
03940   * @param  Polarity stop watch polarity.
03941   *         This parameter can be a value of @arg FDCAN_TT_stop_watch_polarity.
03942   * @retval HAL status
03943   */
03944 HAL_StatusTypeDef HAL_FDCAN_TT_ConfigStopWatch(FDCAN_HandleTypeDef *hfdcan, uint32_t Source, uint32_t Polarity)
03945 {
03946   uint32_t Counter = 0U;
03947   HAL_FDCAN_StateTypeDef state = hfdcan->State;
03948 
03949   /* Check function parameters */
03950   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
03951   assert_param(IS_FDCAN_TT_STOP_WATCH_SOURCE(Source));
03952   assert_param(IS_FDCAN_TT_STOP_WATCH_POLARITY(Polarity));
03953 
03954   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
03955   {
03956     /* Wait until the LCKC bit into TTOCN register is reset */
03957     while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
03958     {
03959       /* Check for the Timeout */
03960       if (Counter > FDCAN_TIMEOUT_COUNT)
03961       {
03962         /* Update error code */
03963         hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
03964 
03965         /* Change FDCAN state */
03966         hfdcan->State = HAL_FDCAN_STATE_ERROR;
03967 
03968         return HAL_ERROR;
03969       }
03970 
03971       /* Increment counter */
03972       Counter++;
03973     }
03974 
03975     /* Select stop watch source and polarity */
03976     MODIFY_REG(hfdcan->ttcan->TTOCN, (FDCAN_TTOCN_SWS | FDCAN_TTOCN_SWP), (Source | Polarity));
03977 
03978     /* Return function status */
03979     return HAL_OK;
03980   }
03981   else
03982   {
03983     /* Update error code */
03984     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
03985 
03986     return HAL_ERROR;
03987   }
03988 }
03989 
03990 /**
03991   * @brief  Configure register time mark pulse generation.
03992   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
03993   *         the configuration information for the specified FDCAN.
03994   * @param  TimeMarkSource time mark source.
03995   *         This parameter can be a value of @arg FDCAN_TT_time_mark_source.
03996   * @param  TimeMarkValue time mark value (reference).
03997   *         This parameter must be a number between 0 and 0xFFFF.
03998   * @param  RepeatFactor repeat factor of the cycle for which the time mark is valid.
03999   *         This parameter can be a value of @arg FDCAN_TT_Repeat_Factor.
04000   * @param  StartCycle index of the first cycle in which the time mark becomes valid.
04001   *         This parameter is ignored if RepeatFactor is set to FDCAN_TT_REPEAT_EVERY_CYCLE.
04002   *         This parameter must be a number between 0 and RepeatFactor.
04003   * @retval HAL status
04004   */
04005 HAL_StatusTypeDef HAL_FDCAN_TT_ConfigRegisterTimeMark(FDCAN_HandleTypeDef *hfdcan,
04006                                                       uint32_t TimeMarkSource, uint32_t TimeMarkValue,
04007                                                       uint32_t RepeatFactor, uint32_t StartCycle)
04008 {
04009   uint32_t Counter = 0U;
04010   uint32_t CycleCode;
04011   HAL_FDCAN_StateTypeDef state = hfdcan->State;
04012 
04013   /* Check function parameters */
04014   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
04015   assert_param(IS_FDCAN_TT_REGISTER_TIME_MARK_SOURCE(TimeMarkSource));
04016   assert_param(IS_FDCAN_MAX_VALUE(TimeMarkValue, 0xFFFFU));
04017   assert_param(IS_FDCAN_TT_REPEAT_FACTOR(RepeatFactor));
04018   if (RepeatFactor != FDCAN_TT_REPEAT_EVERY_CYCLE)
04019   {
04020     assert_param(IS_FDCAN_MAX_VALUE(StartCycle, (RepeatFactor - 1U)));
04021   }
04022 
04023   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
04024   {
04025     /* Wait until the LCKC bit into TTOCN register is reset */
04026     while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
04027     {
04028       /* Check for the Timeout */
04029       if (Counter > FDCAN_TIMEOUT_COUNT)
04030       {
04031         /* Update error code */
04032         hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
04033 
04034         /* Change FDCAN state */
04035         hfdcan->State = HAL_FDCAN_STATE_ERROR;
04036 
04037         return HAL_ERROR;
04038       }
04039 
04040       /* Increment counter */
04041       Counter++;
04042     }
04043 
04044     /* Disable the time mark compare function */
04045     CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TMC);
04046 
04047     if (TimeMarkSource != FDCAN_TT_REG_TIMEMARK_DIABLED)
04048     {
04049       /* Calculate cycle code */
04050       if (RepeatFactor == FDCAN_TT_REPEAT_EVERY_CYCLE)
04051       {
04052         CycleCode = FDCAN_TT_REPEAT_EVERY_CYCLE;
04053       }
04054       else /* RepeatFactor != FDCAN_TT_REPEAT_EVERY_CYCLE */
04055       {
04056         CycleCode = RepeatFactor + StartCycle;
04057       }
04058 
04059       Counter = 0U;
04060 
04061       /* Wait until the LCKM bit into TTTMK register is reset */
04062       while ((hfdcan->ttcan->TTTMK & FDCAN_TTTMK_LCKM) != 0U)
04063       {
04064         /* Check for the Timeout */
04065         if (Counter > FDCAN_TIMEOUT_COUNT)
04066         {
04067           /* Update error code */
04068           hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
04069 
04070           /* Change FDCAN state */
04071           hfdcan->State = HAL_FDCAN_STATE_ERROR;
04072 
04073           return HAL_ERROR;
04074         }
04075 
04076         /* Increment counter */
04077         Counter++;
04078       }
04079 
04080       /* Configure time mark value and cycle code */
04081       hfdcan->ttcan->TTTMK = ((TimeMarkValue << FDCAN_TTTMK_TM_Pos) | (CycleCode << FDCAN_TTTMK_TICC_Pos));
04082 
04083       Counter = 0U;
04084 
04085       /* Wait until the LCKC bit into TTOCN register is reset */
04086       while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
04087       {
04088         /* Check for the Timeout */
04089         if (Counter > FDCAN_TIMEOUT_COUNT)
04090         {
04091           /* Update error code */
04092           hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
04093 
04094           /* Change FDCAN state */
04095           hfdcan->State = HAL_FDCAN_STATE_ERROR;
04096 
04097           return HAL_ERROR;
04098         }
04099 
04100         /* Increment counter */
04101         Counter++;
04102       }
04103 
04104       /* Update the register time mark compare source */
04105       MODIFY_REG(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TMC, TimeMarkSource);
04106     }
04107 
04108     /* Return function status */
04109     return HAL_OK;
04110   }
04111   else
04112   {
04113     /* Update error code */
04114     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
04115 
04116     return HAL_ERROR;
04117   }
04118 }
04119 
04120 /**
04121   * @brief  Enable register time mark pulse generation.
04122   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
04123   *         the configuration information for the specified FDCAN.
04124   * @retval HAL status
04125   */
04126 HAL_StatusTypeDef HAL_FDCAN_TT_EnableRegisterTimeMarkPulse(FDCAN_HandleTypeDef *hfdcan)
04127 {
04128   uint32_t Counter = 0U;
04129   HAL_FDCAN_StateTypeDef state = hfdcan->State;
04130 
04131   /* Check function parameters */
04132   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
04133 
04134   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
04135   {
04136     /* Wait until the LCKC bit into TTOCN register is reset */
04137     while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
04138     {
04139       /* Check for the Timeout */
04140       if (Counter > FDCAN_TIMEOUT_COUNT)
04141       {
04142         /* Update error code */
04143         hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
04144 
04145         /* Change FDCAN state */
04146         hfdcan->State = HAL_FDCAN_STATE_ERROR;
04147 
04148         return HAL_ERROR;
04149       }
04150 
04151       /* Increment counter */
04152       Counter++;
04153     }
04154 
04155     /* Enable Register Time Mark Interrupt output on fdcan1_rtp */
04156     SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_RTIE);
04157 
04158     /* Return function status */
04159     return HAL_OK;
04160   }
04161   else
04162   {
04163     /* Update error code */
04164     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
04165 
04166     return HAL_ERROR;
04167   }
04168 }
04169 
04170 /**
04171   * @brief  Disable register time mark pulse generation.
04172   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
04173   *         the configuration information for the specified FDCAN.
04174   * @retval HAL status
04175   */
04176 HAL_StatusTypeDef HAL_FDCAN_TT_DisableRegisterTimeMarkPulse(FDCAN_HandleTypeDef *hfdcan)
04177 {
04178   uint32_t Counter = 0U;
04179   HAL_FDCAN_StateTypeDef state = hfdcan->State;
04180 
04181   /* Check function parameters */
04182   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
04183 
04184   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
04185   {
04186     /* Wait until the LCKC bit into TTOCN register is reset */
04187     while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
04188     {
04189       /* Check for the Timeout */
04190       if (Counter > FDCAN_TIMEOUT_COUNT)
04191       {
04192         /* Update error code */
04193         hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
04194 
04195         /* Change FDCAN state */
04196         hfdcan->State = HAL_FDCAN_STATE_ERROR;
04197 
04198         return HAL_ERROR;
04199       }
04200 
04201       /* Increment counter */
04202       Counter++;
04203     }
04204 
04205     /* Disable Register Time Mark Interrupt output on fdcan1_rtp */
04206     CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_RTIE);
04207 
04208     /* Return function status */
04209     return HAL_OK;
04210   }
04211   else
04212   {
04213     /* Update error code */
04214     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
04215 
04216     return HAL_ERROR;
04217   }
04218 }
04219 
04220 /**
04221   * @brief  Enable trigger time mark pulse generation.
04222   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
04223   *         the configuration information for the specified FDCAN.
04224   * @retval HAL status
04225   */
04226 HAL_StatusTypeDef HAL_FDCAN_TT_EnableTriggerTimeMarkPulse(FDCAN_HandleTypeDef *hfdcan)
04227 {
04228   uint32_t Counter = 0U;
04229   HAL_FDCAN_StateTypeDef state = hfdcan->State;
04230 
04231   /* Check function parameters */
04232   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
04233 
04234   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
04235   {
04236     if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
04237     {
04238       /* Wait until the LCKC bit into TTOCN register is reset */
04239       while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
04240       {
04241         /* Check for the Timeout */
04242         if (Counter > FDCAN_TIMEOUT_COUNT)
04243         {
04244           /* Update error code */
04245           hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
04246 
04247           /* Change FDCAN state */
04248           hfdcan->State = HAL_FDCAN_STATE_ERROR;
04249 
04250           return HAL_ERROR;
04251         }
04252 
04253         /* Increment counter */
04254         Counter++;
04255       }
04256 
04257       /* Enable Trigger Time Mark Interrupt output on fdcan1_tmp */
04258       SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TTIE);
04259 
04260       /* Return function status */
04261       return HAL_OK;
04262     }
04263     else
04264     {
04265       /* Update error code.
04266          Feature not supported for TT Level 0 */
04267       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
04268 
04269       return HAL_ERROR;
04270     }
04271   }
04272   else
04273   {
04274     /* Update error code */
04275     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
04276 
04277     return HAL_ERROR;
04278   }
04279 }
04280 
04281 /**
04282   * @brief  Disable trigger time mark pulse generation.
04283   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
04284   *         the configuration information for the specified FDCAN.
04285   * @retval HAL status
04286   */
04287 HAL_StatusTypeDef HAL_FDCAN_TT_DisableTriggerTimeMarkPulse(FDCAN_HandleTypeDef *hfdcan)
04288 {
04289   uint32_t Counter = 0U;
04290   HAL_FDCAN_StateTypeDef state = hfdcan->State;
04291 
04292   /* Check function parameters */
04293   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
04294 
04295   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
04296   {
04297     if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
04298     {
04299       /* Wait until the LCKC bit into TTOCN register is reset */
04300       while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
04301       {
04302         /* Check for the Timeout */
04303         if (Counter > FDCAN_TIMEOUT_COUNT)
04304         {
04305           /* Update error code */
04306           hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
04307 
04308           /* Change FDCAN state */
04309           hfdcan->State = HAL_FDCAN_STATE_ERROR;
04310 
04311           return HAL_ERROR;
04312         }
04313 
04314         /* Increment counter */
04315         Counter++;
04316       }
04317 
04318       /* Disable Trigger Time Mark Interrupt output on fdcan1_rtp */
04319       CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TTIE);
04320 
04321       /* Return function status */
04322       return HAL_OK;
04323     }
04324     else
04325     {
04326       /* Update error code.
04327          Feature not supported for TT Level 0 */
04328       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
04329 
04330       return HAL_ERROR;
04331     }
04332   }
04333   else
04334   {
04335     /* Update error code */
04336     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
04337 
04338     return HAL_ERROR;
04339   }
04340 }
04341 
04342 /**
04343   * @brief  Enable gap control by input pin fdcan1_evt.
04344   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
04345   *         the configuration information for the specified FDCAN.
04346   * @retval HAL status
04347   */
04348 HAL_StatusTypeDef HAL_FDCAN_TT_EnableHardwareGapControl(FDCAN_HandleTypeDef *hfdcan)
04349 {
04350   uint32_t Counter = 0U;
04351   HAL_FDCAN_StateTypeDef state = hfdcan->State;
04352 
04353   /* Check function parameters */
04354   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
04355 
04356   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
04357   {
04358     if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
04359     {
04360       /* Wait until the LCKC bit into TTOCN register is reset */
04361       while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
04362       {
04363         /* Check for the Timeout */
04364         if (Counter > FDCAN_TIMEOUT_COUNT)
04365         {
04366           /* Update error code */
04367           hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
04368 
04369           /* Change FDCAN state */
04370           hfdcan->State = HAL_FDCAN_STATE_ERROR;
04371 
04372           return HAL_ERROR;
04373         }
04374 
04375         /* Increment counter */
04376         Counter++;
04377       }
04378 
04379       /* Enable gap control by pin fdcan1_evt */
04380       SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_GCS);
04381 
04382       /* Return function status */
04383       return HAL_OK;
04384     }
04385     else
04386     {
04387       /* Update error code.
04388          Feature not supported for TT Level 0 */
04389       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
04390 
04391       return HAL_ERROR;
04392     }
04393   }
04394   else
04395   {
04396     /* Update error code */
04397     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
04398 
04399     return HAL_ERROR;
04400   }
04401 }
04402 
04403 /**
04404   * @brief  Disable gap control by input pin fdcan1_evt.
04405   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
04406   *         the configuration information for the specified FDCAN.
04407   * @retval HAL status
04408   */
04409 HAL_StatusTypeDef HAL_FDCAN_TT_DisableHardwareGapControl(FDCAN_HandleTypeDef *hfdcan)
04410 {
04411   uint32_t Counter = 0U;
04412   HAL_FDCAN_StateTypeDef state = hfdcan->State;
04413 
04414   /* Check function parameters */
04415   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
04416 
04417   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
04418   {
04419     if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
04420     {
04421       /* Wait until the LCKC bit into TTOCN register is reset */
04422       while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
04423       {
04424         /* Check for the Timeout */
04425         if (Counter > FDCAN_TIMEOUT_COUNT)
04426         {
04427           /* Update error code */
04428           hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
04429 
04430           /* Change FDCAN state */
04431           hfdcan->State = HAL_FDCAN_STATE_ERROR;
04432 
04433           return HAL_ERROR;
04434         }
04435 
04436         /* Increment counter */
04437         Counter++;
04438       }
04439 
04440       /* Disable gap control by pin fdcan1_evt */
04441       CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_GCS);
04442 
04443       /* Return function status */
04444       return HAL_OK;
04445     }
04446     else
04447     {
04448       /* Update error code.
04449          Feature not supported for TT Level 0 */
04450       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
04451 
04452       return HAL_ERROR;
04453     }
04454   }
04455   else
04456   {
04457     /* Update error code */
04458     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
04459 
04460     return HAL_ERROR;
04461   }
04462 }
04463 
04464 /**
04465   * @brief  Enable gap control (finish only) by register time mark interrupt.
04466   *         The next register time mark interrupt (TTIR.RTMI = "1") will finish
04467   *         the Gap and start the reference message.
04468   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
04469   *         the configuration information for the specified FDCAN.
04470   * @retval HAL status
04471   */
04472 HAL_StatusTypeDef HAL_FDCAN_TT_EnableTimeMarkGapControl(FDCAN_HandleTypeDef *hfdcan)
04473 {
04474   uint32_t Counter = 0U;
04475   HAL_FDCAN_StateTypeDef state = hfdcan->State;
04476 
04477   /* Check function parameters */
04478   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
04479 
04480   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
04481   {
04482     if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
04483     {
04484       /* Wait until the LCKC bit into TTOCN register is reset */
04485       while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
04486       {
04487         /* Check for the Timeout */
04488         if (Counter > FDCAN_TIMEOUT_COUNT)
04489         {
04490           /* Update error code */
04491           hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
04492 
04493           /* Change FDCAN state */
04494           hfdcan->State = HAL_FDCAN_STATE_ERROR;
04495 
04496           return HAL_ERROR;
04497         }
04498 
04499         /* Increment counter */
04500         Counter++;
04501       }
04502 
04503       /* Enable gap control by register time mark interrupt */
04504       SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TMG);
04505 
04506       /* Return function status */
04507       return HAL_OK;
04508     }
04509     else
04510     {
04511       /* Update error code.
04512          Feature not supported for TT Level 0 */
04513       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
04514 
04515       return HAL_ERROR;
04516     }
04517   }
04518   else
04519   {
04520     /* Update error code */
04521     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
04522 
04523     return HAL_ERROR;
04524   }
04525 }
04526 
04527 /**
04528   * @brief  Disable gap control by register time mark interrupt.
04529   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
04530   *         the configuration information for the specified FDCAN.
04531   * @retval HAL status
04532   */
04533 HAL_StatusTypeDef HAL_FDCAN_TT_DisableTimeMarkGapControl(FDCAN_HandleTypeDef *hfdcan)
04534 {
04535   uint32_t Counter = 0U;
04536   HAL_FDCAN_StateTypeDef state = hfdcan->State;
04537 
04538   /* Check function parameters */
04539   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
04540 
04541   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
04542   {
04543     if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
04544     {
04545       /* Wait until the LCKC bit into TTOCN register is reset */
04546       while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
04547       {
04548         /* Check for the Timeout */
04549         if (Counter > FDCAN_TIMEOUT_COUNT)
04550         {
04551           /* Update error code */
04552           hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
04553 
04554           /* Change FDCAN state */
04555           hfdcan->State = HAL_FDCAN_STATE_ERROR;
04556 
04557           return HAL_ERROR;
04558         }
04559 
04560         /* Increment counter */
04561         Counter++;
04562       }
04563 
04564       /* Disable gap control by register time mark interrupt */
04565       CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TMG);
04566 
04567       /* Return function status */
04568       return HAL_OK;
04569     }
04570     else
04571     {
04572       /* Update error code.
04573          Feature not supported for TT Level 0 */
04574       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
04575 
04576       return HAL_ERROR;
04577     }
04578   }
04579   else
04580   {
04581     /* Update error code */
04582     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
04583 
04584     return HAL_ERROR;
04585   }
04586 }
04587 
04588 /**
04589   * @brief  Transmit next reference message with Next_is_Gap = "1".
04590   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
04591   *         the configuration information for the specified FDCAN.
04592   * @retval HAL status
04593   */
04594 HAL_StatusTypeDef HAL_FDCAN_TT_SetNextIsGap(FDCAN_HandleTypeDef *hfdcan)
04595 {
04596   uint32_t Counter = 0U;
04597   HAL_FDCAN_StateTypeDef state = hfdcan->State;
04598 
04599   /* Check function parameters */
04600   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
04601 
04602   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
04603   {
04604     /* Check that the node is configured for external event-synchronized TT operation */
04605     if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_GEN) != FDCAN_TTOCF_GEN)
04606     {
04607       /* Update error code */
04608       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
04609 
04610       return HAL_ERROR;
04611     }
04612 
04613     if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
04614     {
04615       /* Wait until the LCKC bit into TTOCN register is reset */
04616       while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
04617       {
04618         /* Check for the Timeout */
04619         if (Counter > FDCAN_TIMEOUT_COUNT)
04620         {
04621           /* Update error code */
04622           hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
04623 
04624           /* Change FDCAN state */
04625           hfdcan->State = HAL_FDCAN_STATE_ERROR;
04626 
04627           return HAL_ERROR;
04628         }
04629 
04630         /* Increment counter */
04631         Counter++;
04632       }
04633 
04634       /* Set Next is Gap */
04635       SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_NIG);
04636 
04637       /* Return function status */
04638       return HAL_OK;
04639     }
04640     else
04641     {
04642       /* Update error code.
04643          Feature not supported for TT Level 0 */
04644       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
04645 
04646       return HAL_ERROR;
04647     }
04648   }
04649   else
04650   {
04651     /* Update error code */
04652     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
04653 
04654     return HAL_ERROR;
04655   }
04656 }
04657 
04658 /**
04659   * @brief  Finish a Gap by requesting start of reference message.
04660   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
04661   *         the configuration information for the specified FDCAN.
04662   * @retval HAL status
04663   */
04664 HAL_StatusTypeDef HAL_FDCAN_TT_SetEndOfGap(FDCAN_HandleTypeDef *hfdcan)
04665 {
04666   uint32_t Counter = 0U;
04667   HAL_FDCAN_StateTypeDef state = hfdcan->State;
04668 
04669   /* Check function parameters */
04670   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
04671 
04672   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
04673   {
04674     /* Check that the node is configured for external event-synchronized TT operation */
04675     if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_GEN) != FDCAN_TTOCF_GEN)
04676     {
04677       /* Update error code */
04678       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
04679 
04680       return HAL_ERROR;
04681     }
04682 
04683     if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
04684     {
04685       /* Wait until the LCKC bit into TTOCN register is reset */
04686       while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
04687       {
04688         /* Check for the Timeout */
04689         if (Counter > FDCAN_TIMEOUT_COUNT)
04690         {
04691           /* Update error code */
04692           hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
04693 
04694           /* Change FDCAN state */
04695           hfdcan->State = HAL_FDCAN_STATE_ERROR;
04696 
04697           return HAL_ERROR;
04698         }
04699 
04700         /* Increment counter */
04701         Counter++;
04702       }
04703 
04704       /* Set Finish Gap */
04705       SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_FGP);
04706 
04707       /* Return function status */
04708       return HAL_OK;
04709     }
04710     else
04711     {
04712       /* Update error code.
04713          Feature not supported for TT Level 0 */
04714       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
04715 
04716       return HAL_ERROR;
04717     }
04718   }
04719   else
04720   {
04721     /* Update error code */
04722     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
04723 
04724     return HAL_ERROR;
04725   }
04726 }
04727 
04728 /**
04729   * @brief  Configure target phase used for external synchronization by event
04730   *         trigger input pin fdcan1_evt.
04731   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
04732   *         the configuration information for the specified FDCAN.
04733   * @param  TargetPhase defines target value of cycle time when a rising edge
04734   *         of fdcan1_evt is expected.
04735   *         This parameter must be a number between 0 and 0xFFFF.
04736   * @retval HAL status
04737   */
04738 HAL_StatusTypeDef HAL_FDCAN_TT_ConfigExternalSyncPhase(FDCAN_HandleTypeDef *hfdcan, uint32_t TargetPhase)
04739 {
04740   HAL_FDCAN_StateTypeDef state = hfdcan->State;
04741 
04742   /* Check function parameters */
04743   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
04744   assert_param(IS_FDCAN_MAX_VALUE(TargetPhase, 0xFFFFU));
04745 
04746   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
04747   {
04748     /* Check that no external schedule synchronization is pending */
04749     if ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_ESCN) == FDCAN_TTOCN_ESCN)
04750     {
04751       /* Update error code */
04752       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PENDING;
04753 
04754       return HAL_ERROR;
04755     }
04756 
04757     /* Configure cycle time target phase */
04758     MODIFY_REG(hfdcan->ttcan->TTGTP, FDCAN_TTGTP_CTP, (TargetPhase << FDCAN_TTGTP_CTP_Pos));
04759 
04760     /* Return function status */
04761     return HAL_OK;
04762   }
04763   else
04764   {
04765     /* Update error code */
04766     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
04767 
04768     return HAL_ERROR;
04769   }
04770 }
04771 
04772 /**
04773   * @brief  Synchronize the phase of the FDCAN schedule to an external schedule
04774   *         using event trigger input pin fdcan1_evt.
04775   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
04776   *         the configuration information for the specified FDCAN.
04777   * @retval HAL status
04778   */
04779 HAL_StatusTypeDef HAL_FDCAN_TT_EnableExternalSynchronization(FDCAN_HandleTypeDef *hfdcan)
04780 {
04781   uint32_t Counter = 0U;
04782   HAL_FDCAN_StateTypeDef state = hfdcan->State;
04783 
04784   /* Check function parameters */
04785   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
04786 
04787   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
04788   {
04789     /* Wait until the LCKC bit into TTOCN register is reset */
04790     while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
04791     {
04792       /* Check for the Timeout */
04793       if (Counter > FDCAN_TIMEOUT_COUNT)
04794       {
04795         /* Update error code */
04796         hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
04797 
04798         /* Change FDCAN state */
04799         hfdcan->State = HAL_FDCAN_STATE_ERROR;
04800 
04801         return HAL_ERROR;
04802       }
04803 
04804       /* Increment counter */
04805       Counter++;
04806     }
04807 
04808     /* Enable external synchronization */
04809     SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_ESCN);
04810 
04811     /* Return function status */
04812     return HAL_OK;
04813   }
04814   else
04815   {
04816     /* Update error code */
04817     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
04818 
04819     return HAL_ERROR;
04820   }
04821 }
04822 
04823 /**
04824   * @brief  Disable external schedule synchronization.
04825   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
04826   *         the configuration information for the specified FDCAN.
04827   * @retval HAL status
04828   */
04829 HAL_StatusTypeDef HAL_FDCAN_TT_DisableExternalSynchronization(FDCAN_HandleTypeDef *hfdcan)
04830 {
04831   uint32_t Counter = 0U;
04832   HAL_FDCAN_StateTypeDef state = hfdcan->State;
04833 
04834   /* Check function parameters */
04835   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
04836 
04837   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
04838   {
04839     /* Wait until the LCKC bit into TTOCN register is reset */
04840     while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
04841     {
04842       /* Check for the Timeout */
04843       if (Counter > FDCAN_TIMEOUT_COUNT)
04844       {
04845         /* Update error code */
04846         hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
04847 
04848         /* Change FDCAN state */
04849         hfdcan->State = HAL_FDCAN_STATE_ERROR;
04850 
04851         return HAL_ERROR;
04852       }
04853 
04854       /* Increment counter */
04855       Counter++;
04856     }
04857 
04858     /* Disable external synchronization */
04859     CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_ESCN);
04860 
04861     /* Return function status */
04862     return HAL_OK;
04863   }
04864   else
04865   {
04866     /* Update error code */
04867     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
04868 
04869     return HAL_ERROR;
04870   }
04871 }
04872 
04873 /**
04874   * @brief  Get TT operation status.
04875   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
04876   *         the configuration information for the specified FDCAN.
04877   * @param  TTOpStatus pointer to an FDCAN_TTOperationStatusTypeDef structure.
04878   * @retval HAL status
04879   */
04880 HAL_StatusTypeDef HAL_FDCAN_TT_GetOperationStatus(FDCAN_HandleTypeDef *hfdcan, FDCAN_TTOperationStatusTypeDef *TTOpStatus)
04881 {
04882   uint32_t TTStatusReg;
04883 
04884   /* Check function parameters */
04885   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
04886 
04887   /* Read the TT operation status register */
04888   TTStatusReg = READ_REG(hfdcan->ttcan->TTOST);
04889 
04890   /* Fill the TT operation status structure */
04891   TTOpStatus->ErrorLevel = (TTStatusReg & FDCAN_TTOST_EL);
04892   TTOpStatus->MasterState = (TTStatusReg & FDCAN_TTOST_MS);
04893   TTOpStatus->SyncState = (TTStatusReg & FDCAN_TTOST_SYS);
04894   TTOpStatus->GTimeQuality = ((TTStatusReg & FDCAN_TTOST_QGTP) >> FDCAN_TTOST_QGTP_Pos);
04895   TTOpStatus->ClockQuality = ((TTStatusReg & FDCAN_TTOST_QCS) >> FDCAN_TTOST_QCS_Pos);
04896   TTOpStatus->RefTrigOffset = ((TTStatusReg & FDCAN_TTOST_RTO) >> FDCAN_TTOST_RTO_Pos);
04897   TTOpStatus->GTimeDiscPending = ((TTStatusReg & FDCAN_TTOST_WGTD) >> FDCAN_TTOST_WGTD_Pos);
04898   TTOpStatus->GapFinished = ((TTStatusReg & FDCAN_TTOST_GFI) >> FDCAN_TTOST_GFI_Pos);
04899   TTOpStatus->MasterPriority = ((TTStatusReg & FDCAN_TTOST_TMP) >> FDCAN_TTOST_TMP_Pos);
04900   TTOpStatus->GapStarted = ((TTStatusReg & FDCAN_TTOST_GSI) >> FDCAN_TTOST_GSI_Pos);
04901   TTOpStatus->WaitForEvt = ((TTStatusReg & FDCAN_TTOST_WFE) >> FDCAN_TTOST_WFE_Pos);
04902   TTOpStatus->AppWdgEvt = ((TTStatusReg & FDCAN_TTOST_AWE) >> FDCAN_TTOST_AWE_Pos);
04903   TTOpStatus->ECSPending = ((TTStatusReg & FDCAN_TTOST_WECS) >> FDCAN_TTOST_WECS_Pos);
04904   TTOpStatus->PhaseLock = ((TTStatusReg & FDCAN_TTOST_SPL) >> FDCAN_TTOST_SPL_Pos);
04905 
04906   /* Return function status */
04907   return HAL_OK;
04908 }
04909 
04910 /**
04911   * @}
04912   */
04913 
04914 /** @defgroup FDCAN_Exported_Functions_Group5 Interrupts management
04915  *  @brief    Interrupts management
04916  *
04917 @verbatim
04918   ==============================================================================
04919                        ##### Interrupts management #####
04920   ==============================================================================
04921     [..]  This section provides functions allowing to:
04922       (+) HAL_FDCAN_ConfigInterruptLines      : Assign interrupts to either Interrupt line 0 or 1
04923       (+) HAL_FDCAN_TT_ConfigInterruptLines   : Assign TT interrupts to either Interrupt line 0 or 1
04924       (+) HAL_FDCAN_ActivateNotification      : Enable interrupts
04925       (+) HAL_FDCAN_DeactivateNotification    : Disable interrupts
04926       (+) HAL_FDCAN_TT_ActivateNotification   : Enable TT interrupts
04927       (+) HAL_FDCAN_TT_DeactivateNotification : Disable TT interrupts
04928       (+) HAL_FDCAN_IRQHandler                : Handles FDCAN interrupt request
04929 
04930 @endverbatim
04931   * @{
04932   */
04933 
04934 /**
04935   * @brief  Assign interrupts to either Interrupt line 0 or 1.
04936   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
04937   *         the configuration information for the specified FDCAN.
04938   * @param  ITList indicates which interrupts will be assigned to the selected interrupt line.
04939   *         This parameter can be any combination of @arg FDCAN_Interrupts.
04940   * @param  InterruptLine Interrupt line.
04941   *         This parameter can be a value of @arg FDCAN_Interrupt_Line.
04942   * @retval HAL status
04943   */
04944 HAL_StatusTypeDef HAL_FDCAN_ConfigInterruptLines(FDCAN_HandleTypeDef *hfdcan, uint32_t ITList, uint32_t InterruptLine)
04945 {
04946   HAL_FDCAN_StateTypeDef state = hfdcan->State;
04947 
04948   /* Check function parameters */
04949   assert_param(IS_FDCAN_IT(ITList));
04950   assert_param(IS_FDCAN_IT_LINE(InterruptLine));
04951 
04952   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
04953   {
04954     /* Assign list of interrupts to the selected line */
04955     if (InterruptLine == FDCAN_INTERRUPT_LINE0)
04956     {
04957       CLEAR_BIT(hfdcan->Instance->ILS, ITList);
04958     }
04959     else /* InterruptLine == FDCAN_INTERRUPT_LINE1 */
04960     {
04961       SET_BIT(hfdcan->Instance->ILS, ITList);
04962     }
04963 
04964     /* Return function status */
04965     return HAL_OK;
04966   }
04967   else
04968   {
04969     /* Update error code */
04970     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
04971 
04972     return HAL_ERROR;
04973   }
04974 }
04975 
04976 /**
04977   * @brief  Assign TT interrupts to either Interrupt line 0 or 1.
04978   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
04979   *         the configuration information for the specified FDCAN.
04980   * @param  TTITList indicates which interrupts will be assigned to the selected interrupt line.
04981   *         This parameter can be any combination of @arg FDCAN_TTInterrupts.
04982   * @param  InterruptLine Interrupt line.
04983   *         This parameter can be a value of @arg FDCAN_Interrupt_Line.
04984   * @retval HAL status
04985   */
04986 HAL_StatusTypeDef HAL_FDCAN_TT_ConfigInterruptLines(FDCAN_HandleTypeDef *hfdcan, uint32_t TTITList, uint32_t InterruptLine)
04987 {
04988   HAL_FDCAN_StateTypeDef state = hfdcan->State;
04989 
04990   /* Check function parameters */
04991   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
04992   assert_param(IS_FDCAN_TT_IT(TTITList));
04993   assert_param(IS_FDCAN_IT_LINE(InterruptLine));
04994 
04995   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
04996   {
04997     /* Assign list of interrupts to the selected line */
04998     if (InterruptLine == FDCAN_INTERRUPT_LINE0)
04999     {
05000       CLEAR_BIT(hfdcan->ttcan->TTILS, TTITList);
05001     }
05002     else /* InterruptLine == FDCAN_INTERRUPT_LINE1 */
05003     {
05004       SET_BIT(hfdcan->ttcan->TTILS, TTITList);
05005     }
05006 
05007     /* Return function status */
05008     return HAL_OK;
05009   }
05010   else
05011   {
05012     /* Update error code */
05013     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
05014 
05015     return HAL_ERROR;
05016   }
05017 }
05018 
05019 /**
05020   * @brief  Enable interrupts.
05021   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05022   *         the configuration information for the specified FDCAN.
05023   * @param  ActiveITs indicates which interrupts will be enabled.
05024   *         This parameter can be any combination of @arg FDCAN_Interrupts.
05025   * @param  BufferIndexes Tx Buffer Indexes.
05026   *         This parameter can be any combination of @arg FDCAN_Tx_location.
05027   *         This parameter is ignored if ActiveITs does not include one of the following:
05028   *           - FDCAN_IT_TX_COMPLETE
05029   *           - FDCAN_IT_TX_ABORT_COMPLETE
05030   * @retval HAL status
05031   */
05032 HAL_StatusTypeDef HAL_FDCAN_ActivateNotification(FDCAN_HandleTypeDef *hfdcan, uint32_t ActiveITs, uint32_t BufferIndexes)
05033 {
05034   HAL_FDCAN_StateTypeDef state = hfdcan->State;
05035 
05036   /* Check function parameters */
05037   assert_param(IS_FDCAN_IT(ActiveITs));
05038 
05039   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
05040   {
05041     /* Enable Interrupt lines */
05042     if ((ActiveITs & hfdcan->Instance->ILS) == 0U)
05043     {
05044       /* Enable Interrupt line 0 */
05045       SET_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE0);
05046     }
05047     else if ((ActiveITs & hfdcan->Instance->ILS) == ActiveITs)
05048     {
05049       /* Enable Interrupt line 1 */
05050       SET_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE1);
05051     }
05052     else
05053     {
05054       /* Enable Interrupt lines 0 and 1 */
05055       hfdcan->Instance->ILE = (FDCAN_INTERRUPT_LINE0 | FDCAN_INTERRUPT_LINE1);
05056     }
05057 
05058     if ((ActiveITs & FDCAN_IT_TX_COMPLETE) != 0U)
05059     {
05060       /* Enable Tx Buffer Transmission Interrupt to set TC flag in IR register,
05061          but interrupt will only occur if TC is enabled in IE register */
05062       SET_BIT(hfdcan->Instance->TXBTIE, BufferIndexes);
05063     }
05064 
05065     if ((ActiveITs & FDCAN_IT_TX_ABORT_COMPLETE) != 0U)
05066     {
05067       /* Enable Tx Buffer Cancellation Finished Interrupt to set TCF flag in IR register,
05068          but interrupt will only occur if TCF is enabled in IE register */
05069       SET_BIT(hfdcan->Instance->TXBCIE, BufferIndexes);
05070     }
05071 
05072     /* Enable the selected interrupts */
05073     __HAL_FDCAN_ENABLE_IT(hfdcan, ActiveITs);
05074 
05075     /* Return function status */
05076     return HAL_OK;
05077   }
05078   else
05079   {
05080     /* Update error code */
05081     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
05082 
05083     return HAL_ERROR;
05084   }
05085 }
05086 
05087 /**
05088   * @brief  Disable interrupts.
05089   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05090   *         the configuration information for the specified FDCAN.
05091   * @param  InactiveITs indicates which interrupts will be disabled.
05092   *         This parameter can be any combination of @arg FDCAN_Interrupts.
05093   * @retval HAL status
05094   */
05095 HAL_StatusTypeDef HAL_FDCAN_DeactivateNotification(FDCAN_HandleTypeDef *hfdcan, uint32_t InactiveITs)
05096 {
05097   uint32_t ITLineSelection;
05098   HAL_FDCAN_StateTypeDef state = hfdcan->State;
05099 
05100   /* Check function parameters */
05101   assert_param(IS_FDCAN_IT(InactiveITs));
05102 
05103   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
05104   {
05105     /* Disable the selected interrupts */
05106     __HAL_FDCAN_DISABLE_IT(hfdcan, InactiveITs);
05107 
05108     if ((InactiveITs & FDCAN_IT_TX_COMPLETE) != 0U)
05109     {
05110       /* Disable Tx Buffer Transmission Interrupts */
05111       CLEAR_REG(hfdcan->Instance->TXBTIE);
05112     }
05113 
05114     if ((InactiveITs & FDCAN_IT_TX_ABORT_COMPLETE) != 0U)
05115     {
05116       /* Disable Tx Buffer Cancellation Finished Interrupt */
05117       CLEAR_REG(hfdcan->Instance->TXBCIE);
05118     }
05119 
05120     ITLineSelection = hfdcan->Instance->ILS;
05121 
05122     if ((hfdcan->Instance->IE | ITLineSelection) == ITLineSelection)
05123     {
05124       /* Disable Interrupt line 0 */
05125       CLEAR_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE0);
05126     }
05127 
05128     if ((hfdcan->Instance->IE & ITLineSelection) == 0U)
05129     {
05130       /* Disable Interrupt line 1 */
05131       CLEAR_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE1);
05132     }
05133 
05134     /* Return function status */
05135     return HAL_OK;
05136   }
05137   else
05138   {
05139     /* Update error code */
05140     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
05141 
05142     return HAL_ERROR;
05143   }
05144 }
05145 
05146 /**
05147   * @brief  Enable TT interrupts.
05148   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05149   *         the configuration information for the specified FDCAN.
05150   * @param  ActiveTTITs indicates which TT interrupts will be enabled.
05151   *         This parameter can be any combination of @arg FDCAN_TTInterrupts.
05152   * @retval HAL status
05153   */
05154 HAL_StatusTypeDef HAL_FDCAN_TT_ActivateNotification(FDCAN_HandleTypeDef *hfdcan, uint32_t ActiveTTITs)
05155 {
05156   HAL_FDCAN_StateTypeDef state = hfdcan->State;
05157 
05158   /* Check function parameters */
05159   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
05160   assert_param(IS_FDCAN_TT_IT(ActiveTTITs));
05161 
05162   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
05163   {
05164     /* Enable Interrupt lines */
05165     if ((ActiveTTITs & hfdcan->ttcan->TTILS) == 0U)
05166     {
05167       /* Enable Interrupt line 0 */
05168       SET_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE0);
05169     }
05170     else if ((ActiveTTITs & hfdcan->ttcan->TTILS) == ActiveTTITs)
05171     {
05172       /* Enable Interrupt line 1 */
05173       SET_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE1);
05174     }
05175     else
05176     {
05177       /* Enable Interrupt lines 0 and 1 */
05178       hfdcan->Instance->ILE = (FDCAN_INTERRUPT_LINE0 | FDCAN_INTERRUPT_LINE1);
05179     }
05180 
05181     /* Enable the selected TT interrupts */
05182     __HAL_FDCAN_TT_ENABLE_IT(hfdcan, ActiveTTITs);
05183 
05184     /* Return function status */
05185     return HAL_OK;
05186   }
05187   else
05188   {
05189     /* Update error code */
05190     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
05191 
05192     return HAL_ERROR;
05193   }
05194 }
05195 
05196 /**
05197   * @brief  Disable TT interrupts.
05198   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05199   *         the configuration information for the specified FDCAN.
05200   * @param  InactiveTTITs indicates which TT interrupts will be disabled.
05201   *         This parameter can be any combination of @arg FDCAN_TTInterrupts.
05202   * @retval HAL status
05203   */
05204 HAL_StatusTypeDef HAL_FDCAN_TT_DeactivateNotification(FDCAN_HandleTypeDef *hfdcan, uint32_t InactiveTTITs)
05205 {
05206   uint32_t ITLineSelection;
05207   HAL_FDCAN_StateTypeDef state = hfdcan->State;
05208 
05209   /* Check function parameters */
05210   assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
05211   assert_param(IS_FDCAN_TT_IT(InactiveTTITs));
05212 
05213   if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
05214   {
05215     /* Disable the selected TT interrupts */
05216     __HAL_FDCAN_TT_DISABLE_IT(hfdcan, InactiveTTITs);
05217 
05218     ITLineSelection = hfdcan->ttcan->TTILS;
05219 
05220     if ((hfdcan->ttcan->TTIE | ITLineSelection) == ITLineSelection)
05221     {
05222       /* Disable Interrupt line 0 */
05223       CLEAR_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE0);
05224     }
05225 
05226     if ((hfdcan->ttcan->TTIE & ITLineSelection) == 0U)
05227     {
05228       /* Disable Interrupt line 1 */
05229       CLEAR_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE1);
05230     }
05231 
05232     /* Return function status */
05233     return HAL_OK;
05234   }
05235   else
05236   {
05237     /* Update error code */
05238     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
05239 
05240     return HAL_ERROR;
05241   }
05242 }
05243 
05244 /**
05245   * @brief  Handles FDCAN interrupt request.
05246   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05247   *         the configuration information for the specified FDCAN.
05248   * @retval HAL status
05249   */
05250 void HAL_FDCAN_IRQHandler(FDCAN_HandleTypeDef *hfdcan)
05251 {
05252   uint32_t ClkCalibrationITs;
05253   uint32_t TxEventFifoITs;
05254   uint32_t RxFifo0ITs;
05255   uint32_t RxFifo1ITs;
05256   uint32_t Errors;
05257   uint32_t ErrorStatusITs;
05258   uint32_t TransmittedBuffers;
05259   uint32_t AbortedBuffers;
05260   uint32_t TTSchedSyncITs;
05261   uint32_t TTTimeMarkITs;
05262   uint32_t TTGlobTimeITs;
05263   uint32_t TTDistErrors;
05264   uint32_t TTFatalErrors;
05265   uint32_t SWTime;
05266   uint32_t SWCycleCount;
05267 
05268   ClkCalibrationITs = (FDCAN_CCU->IR << 30);
05269   ClkCalibrationITs &= (FDCAN_CCU->IE << 30);
05270   TxEventFifoITs = hfdcan->Instance->IR & FDCAN_TX_EVENT_FIFO_MASK;
05271   TxEventFifoITs &= hfdcan->Instance->IE;
05272   RxFifo0ITs = hfdcan->Instance->IR & FDCAN_RX_FIFO0_MASK;
05273   RxFifo0ITs &= hfdcan->Instance->IE;
05274   RxFifo1ITs = hfdcan->Instance->IR & FDCAN_RX_FIFO1_MASK;
05275   RxFifo1ITs &= hfdcan->Instance->IE;
05276   Errors = hfdcan->Instance->IR & FDCAN_ERROR_MASK;
05277   Errors &= hfdcan->Instance->IE;
05278   ErrorStatusITs = hfdcan->Instance->IR & FDCAN_ERROR_STATUS_MASK;
05279   ErrorStatusITs &= hfdcan->Instance->IE;
05280 
05281   /* High Priority Message interrupt management *******************************/
05282   if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_RX_HIGH_PRIORITY_MSG) != 0U)
05283   {
05284     if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_RX_HIGH_PRIORITY_MSG) != 0U)
05285     {
05286       /* Clear the High Priority Message flag */
05287       __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_RX_HIGH_PRIORITY_MSG);
05288 
05289 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
05290       /* Call registered callback*/
05291       hfdcan->HighPriorityMessageCallback(hfdcan);
05292 #else
05293       /* High Priority Message Callback */
05294       HAL_FDCAN_HighPriorityMessageCallback(hfdcan);
05295 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
05296     }
05297   }
05298 
05299   /* Transmission Abort interrupt management **********************************/
05300   if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_TX_ABORT_COMPLETE) != 0U)
05301   {
05302     if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_TX_ABORT_COMPLETE) != 0U)
05303     {
05304       /* List of aborted monitored buffers */
05305       AbortedBuffers = hfdcan->Instance->TXBCF;
05306       AbortedBuffers &= hfdcan->Instance->TXBCIE;
05307 
05308       /* Clear the Transmission Cancellation flag */
05309       __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_TX_ABORT_COMPLETE);
05310 
05311 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
05312       /* Call registered callback*/
05313       hfdcan->TxBufferAbortCallback(hfdcan, AbortedBuffers);
05314 #else
05315       /* Transmission Cancellation Callback */
05316       HAL_FDCAN_TxBufferAbortCallback(hfdcan, AbortedBuffers);
05317 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
05318     }
05319   }
05320 
05321   /* Clock calibration unit interrupts management *****************************/
05322   if (ClkCalibrationITs != 0U)
05323   {
05324     /* Clear the Clock Calibration flags */
05325     __HAL_FDCAN_CLEAR_FLAG(hfdcan, ClkCalibrationITs);
05326 
05327 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
05328     /* Call registered callback*/
05329     hfdcan->ClockCalibrationCallback(hfdcan, ClkCalibrationITs);
05330 #else
05331     /* Clock Calibration Callback */
05332     HAL_FDCAN_ClockCalibrationCallback(hfdcan, ClkCalibrationITs);
05333 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
05334   }
05335 
05336   /* Tx event FIFO interrupts management **************************************/
05337   if (TxEventFifoITs != 0U)
05338   {
05339     /* Clear the Tx Event FIFO flags */
05340     __HAL_FDCAN_CLEAR_FLAG(hfdcan, TxEventFifoITs);
05341 
05342 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
05343     /* Call registered callback*/
05344     hfdcan->TxEventFifoCallback(hfdcan, TxEventFifoITs);
05345 #else
05346     /* Tx Event FIFO Callback */
05347     HAL_FDCAN_TxEventFifoCallback(hfdcan, TxEventFifoITs);
05348 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
05349   }
05350 
05351   /* Rx FIFO 0 interrupts management ******************************************/
05352   if (RxFifo0ITs != 0U)
05353   {
05354     /* Clear the Rx FIFO 0 flags */
05355     __HAL_FDCAN_CLEAR_FLAG(hfdcan, RxFifo0ITs);
05356 
05357 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
05358     /* Call registered callback*/
05359     hfdcan->RxFifo0Callback(hfdcan, RxFifo0ITs);
05360 #else
05361     /* Rx FIFO 0 Callback */
05362     HAL_FDCAN_RxFifo0Callback(hfdcan, RxFifo0ITs);
05363 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
05364   }
05365 
05366   /* Rx FIFO 1 interrupts management ******************************************/
05367   if (RxFifo1ITs != 0U)
05368   {
05369     /* Clear the Rx FIFO 1 flags */
05370     __HAL_FDCAN_CLEAR_FLAG(hfdcan, RxFifo1ITs);
05371 
05372 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
05373     /* Call registered callback*/
05374     hfdcan->RxFifo1Callback(hfdcan, RxFifo1ITs);
05375 #else
05376     /* Rx FIFO 1 Callback */
05377     HAL_FDCAN_RxFifo1Callback(hfdcan, RxFifo1ITs);
05378 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
05379   }
05380 
05381   /* Tx FIFO empty interrupt management ***************************************/
05382   if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_TX_FIFO_EMPTY) != 0U)
05383   {
05384     if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_TX_FIFO_EMPTY) != 0U)
05385     {
05386       /* Clear the Tx FIFO empty flag */
05387       __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_TX_FIFO_EMPTY);
05388 
05389 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
05390       /* Call registered callback*/
05391       hfdcan->TxFifoEmptyCallback(hfdcan);
05392 #else
05393       /* Tx FIFO empty Callback */
05394       HAL_FDCAN_TxFifoEmptyCallback(hfdcan);
05395 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
05396     }
05397   }
05398 
05399   /* Transmission Complete interrupt management *******************************/
05400   if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_TX_COMPLETE) != 0U)
05401   {
05402     if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_TX_COMPLETE) != 0U)
05403     {
05404       /* List of transmitted monitored buffers */
05405       TransmittedBuffers = hfdcan->Instance->TXBTO;
05406       TransmittedBuffers &= hfdcan->Instance->TXBTIE;
05407 
05408       /* Clear the Transmission Complete flag */
05409       __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_TX_COMPLETE);
05410 
05411 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
05412       /* Call registered callback*/
05413       hfdcan->TxBufferCompleteCallback(hfdcan, TransmittedBuffers);
05414 #else
05415       /* Transmission Complete Callback */
05416       HAL_FDCAN_TxBufferCompleteCallback(hfdcan, TransmittedBuffers);
05417 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
05418     }
05419   }
05420 
05421   /* Rx Buffer New Message interrupt management *******************************/
05422   if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_RX_BUFFER_NEW_MESSAGE) != 0U)
05423   {
05424     if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_RX_BUFFER_NEW_MESSAGE) != 0U)
05425     {
05426       /* Clear the Rx Buffer New Message flag */
05427       __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_RX_BUFFER_NEW_MESSAGE);
05428 
05429 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
05430       /* Call registered callback*/
05431       hfdcan->RxBufferNewMessageCallback(hfdcan);
05432 #else
05433       /* Rx Buffer New Message Callback */
05434       HAL_FDCAN_RxBufferNewMessageCallback(hfdcan);
05435 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
05436     }
05437   }
05438 
05439   /* Timestamp Wraparound interrupt management ********************************/
05440   if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_TIMESTAMP_WRAPAROUND) != 0U)
05441   {
05442     if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_TIMESTAMP_WRAPAROUND) != 0U)
05443     {
05444       /* Clear the Timestamp Wraparound flag */
05445       __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_TIMESTAMP_WRAPAROUND);
05446 
05447 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
05448       /* Call registered callback*/
05449       hfdcan->TimestampWraparoundCallback(hfdcan);
05450 #else
05451       /* Timestamp Wraparound Callback */
05452       HAL_FDCAN_TimestampWraparoundCallback(hfdcan);
05453 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
05454     }
05455   }
05456 
05457   /* Timeout Occurred interrupt management ************************************/
05458   if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_TIMEOUT_OCCURRED) != 0U)
05459   {
05460     if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_TIMEOUT_OCCURRED) != 0U)
05461     {
05462       /* Clear the Timeout Occurred flag */
05463       __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_TIMEOUT_OCCURRED);
05464 
05465 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
05466       /* Call registered callback*/
05467       hfdcan->TimeoutOccurredCallback(hfdcan);
05468 #else
05469       /* Timeout Occurred Callback */
05470       HAL_FDCAN_TimeoutOccurredCallback(hfdcan);
05471 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
05472     }
05473   }
05474 
05475   /* Message RAM access failure interrupt management **************************/
05476   if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_RAM_ACCESS_FAILURE) != 0U)
05477   {
05478     if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_RAM_ACCESS_FAILURE) != 0U)
05479     {
05480       /* Clear the Message RAM access failure flag */
05481       __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_RAM_ACCESS_FAILURE);
05482 
05483       /* Update error code */
05484       hfdcan->ErrorCode |= HAL_FDCAN_ERROR_RAM_ACCESS;
05485     }
05486   }
05487 
05488   /* Error Status interrupts management ***************************************/
05489   if (ErrorStatusITs != 0U)
05490   {
05491     /* Clear the Error flags */
05492     __HAL_FDCAN_CLEAR_FLAG(hfdcan, ErrorStatusITs);
05493 
05494 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
05495     /* Call registered callback*/
05496     hfdcan->ErrorStatusCallback(hfdcan, ErrorStatusITs);
05497 #else
05498     /* Error Status Callback */
05499     HAL_FDCAN_ErrorStatusCallback(hfdcan, ErrorStatusITs);
05500 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
05501   }
05502 
05503   /* Error interrupts management **********************************************/
05504   if (Errors != 0U)
05505   {
05506     /* Clear the Error flags */
05507     __HAL_FDCAN_CLEAR_FLAG(hfdcan, Errors);
05508 
05509     /* Update error code */
05510     hfdcan->ErrorCode |= Errors;
05511   }
05512 
05513   if (hfdcan->Instance == FDCAN1)
05514   {
05515     if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != 0U)
05516     {
05517       TTSchedSyncITs = hfdcan->ttcan->TTIR & FDCAN_TT_SCHEDULE_SYNC_MASK;
05518       TTSchedSyncITs &= hfdcan->ttcan->TTIE;
05519       TTTimeMarkITs = hfdcan->ttcan->TTIR & FDCAN_TT_TIME_MARK_MASK;
05520       TTTimeMarkITs &= hfdcan->ttcan->TTIE;
05521       TTGlobTimeITs = hfdcan->ttcan->TTIR & FDCAN_TT_GLOBAL_TIME_MASK;
05522       TTGlobTimeITs &= hfdcan->ttcan->TTIE;
05523       TTDistErrors = hfdcan->ttcan->TTIR & FDCAN_TT_DISTURBING_ERROR_MASK;
05524       TTDistErrors &= hfdcan->ttcan->TTIE;
05525       TTFatalErrors = hfdcan->ttcan->TTIR & FDCAN_TT_FATAL_ERROR_MASK;
05526       TTFatalErrors &= hfdcan->ttcan->TTIE;
05527 
05528       /* TT Schedule Synchronization interrupts management **********************/
05529       if (TTSchedSyncITs != 0U)
05530       {
05531         /* Clear the TT Schedule Synchronization flags */
05532         __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, TTSchedSyncITs);
05533 
05534 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
05535         /* Call registered callback*/
05536         hfdcan->TT_ScheduleSyncCallback(hfdcan, TTSchedSyncITs);
05537 #else
05538         /* TT Schedule Synchronization Callback */
05539         HAL_FDCAN_TT_ScheduleSyncCallback(hfdcan, TTSchedSyncITs);
05540 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
05541       }
05542 
05543       /* TT Time Mark interrupts management *************************************/
05544       if (TTTimeMarkITs != 0U)
05545       {
05546         /* Clear the TT Time Mark flags */
05547         __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, TTTimeMarkITs);
05548 
05549 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
05550         /* Call registered callback*/
05551         hfdcan->TT_TimeMarkCallback(hfdcan, TTTimeMarkITs);
05552 #else
05553         /* TT Time Mark Callback */
05554         HAL_FDCAN_TT_TimeMarkCallback(hfdcan, TTTimeMarkITs);
05555 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
05556       }
05557 
05558       /* TT Stop Watch interrupt management *************************************/
05559       if (__HAL_FDCAN_TT_GET_IT_SOURCE(hfdcan, FDCAN_TT_IT_STOP_WATCH) != 0U)
05560       {
05561         if (__HAL_FDCAN_TT_GET_FLAG(hfdcan, FDCAN_TT_FLAG_STOP_WATCH) != 0U)
05562         {
05563           /* Retrieve Stop watch Time and Cycle count */
05564           SWTime = ((hfdcan->ttcan->TTCPT & FDCAN_TTCPT_SWV) >> FDCAN_TTCPT_SWV_Pos);
05565           SWCycleCount = ((hfdcan->ttcan->TTCPT & FDCAN_TTCPT_CCV) >> FDCAN_TTCPT_CCV_Pos);
05566 
05567           /* Clear the TT Stop Watch flag */
05568           __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, FDCAN_TT_FLAG_STOP_WATCH);
05569 
05570 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
05571           /* Call registered callback*/
05572           hfdcan->TT_StopWatchCallback(hfdcan, SWTime, SWCycleCount);
05573 #else
05574           /* TT Stop Watch Callback */
05575           HAL_FDCAN_TT_StopWatchCallback(hfdcan, SWTime, SWCycleCount);
05576 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
05577         }
05578       }
05579 
05580       /* TT Global Time interrupts management ***********************************/
05581       if (TTGlobTimeITs != 0U)
05582       {
05583         /* Clear the TT Global Time flags */
05584         __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, TTGlobTimeITs);
05585 
05586 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
05587         /* Call registered callback*/
05588         hfdcan->TT_GlobalTimeCallback(hfdcan, TTGlobTimeITs);
05589 #else
05590         /* TT Global Time Callback */
05591         HAL_FDCAN_TT_GlobalTimeCallback(hfdcan, TTGlobTimeITs);
05592 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
05593       }
05594 
05595       /* TT Disturbing Error interrupts management ******************************/
05596       if (TTDistErrors != 0U)
05597       {
05598         /* Clear the TT Disturbing Error flags */
05599         __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, TTDistErrors);
05600 
05601         /* Update error code */
05602         hfdcan->ErrorCode |= TTDistErrors;
05603       }
05604 
05605       /* TT Fatal Error interrupts management ***********************************/
05606       if (TTFatalErrors != 0U)
05607       {
05608         /* Clear the TT Fatal Error flags */
05609         __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, TTFatalErrors);
05610 
05611         /* Update error code */
05612         hfdcan->ErrorCode |= TTFatalErrors;
05613       }
05614     }
05615   }
05616 
05617   if (hfdcan->ErrorCode != HAL_FDCAN_ERROR_NONE)
05618   {
05619 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
05620     /* Call registered callback*/
05621     hfdcan->ErrorCallback(hfdcan);
05622 #else
05623     /* Error Callback */
05624     HAL_FDCAN_ErrorCallback(hfdcan);
05625 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
05626   }
05627 }
05628 
05629 /**
05630   * @}
05631   */
05632 
05633 /** @defgroup FDCAN_Exported_Functions_Group6 Callback functions
05634  *  @brief   FDCAN Callback functions
05635  *
05636 @verbatim
05637   ==============================================================================
05638                           ##### Callback functions #####
05639   ==============================================================================
05640     [..]
05641     This subsection provides the following callback functions:
05642       (+) HAL_FDCAN_ClockCalibrationCallback
05643       (+) HAL_FDCAN_TxEventFifoCallback
05644       (+) HAL_FDCAN_RxFifo0Callback
05645       (+) HAL_FDCAN_RxFifo1Callback
05646       (+) HAL_FDCAN_TxFifoEmptyCallback
05647       (+) HAL_FDCAN_TxBufferCompleteCallback
05648       (+) HAL_FDCAN_TxBufferAbortCallback
05649       (+) HAL_FDCAN_RxBufferNewMessageCallback
05650       (+) HAL_FDCAN_HighPriorityMessageCallback
05651       (+) HAL_FDCAN_TimestampWraparoundCallback
05652       (+) HAL_FDCAN_TimeoutOccurredCallback
05653       (+) HAL_FDCAN_ErrorCallback
05654       (+) HAL_FDCAN_ErrorStatusCallback
05655       (+) HAL_FDCAN_TT_ScheduleSyncCallback
05656       (+) HAL_FDCAN_TT_TimeMarkCallback
05657       (+) HAL_FDCAN_TT_StopWatchCallback
05658       (+) HAL_FDCAN_TT_GlobalTimeCallback
05659 
05660 @endverbatim
05661   * @{
05662   */
05663 
05664 /**
05665   * @brief  Clock Calibration callback.
05666   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05667   *         the configuration information for the specified FDCAN.
05668   * @param  ClkCalibrationITs indicates which Clock Calibration interrupts are signaled.
05669   *         This parameter can be any combination of @arg FDCAN_Clock_Calibration_Interrupts.
05670   * @retval None
05671   */
05672 __weak void HAL_FDCAN_ClockCalibrationCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t ClkCalibrationITs)
05673 {
05674   /* Prevent unused argument(s) compilation warning */
05675   UNUSED(hfdcan);
05676   UNUSED(ClkCalibrationITs);
05677 
05678   /* NOTE : This function Should not be modified, when the callback is needed,
05679             the HAL_FDCAN_ClockCalibrationCallback could be implemented in the user file
05680    */
05681 }
05682 
05683 /**
05684   * @brief  Tx Event callback.
05685   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05686   *         the configuration information for the specified FDCAN.
05687   * @param  TxEventFifoITs indicates which Tx Event FIFO interrupts are signaled.
05688   *         This parameter can be any combination of @arg FDCAN_Tx_Event_Fifo_Interrupts.
05689   * @retval None
05690   */
05691 __weak void HAL_FDCAN_TxEventFifoCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t TxEventFifoITs)
05692 {
05693   /* Prevent unused argument(s) compilation warning */
05694   UNUSED(hfdcan);
05695   UNUSED(TxEventFifoITs);
05696 
05697   /* NOTE : This function Should not be modified, when the callback is needed,
05698             the HAL_FDCAN_TxEventFifoCallback could be implemented in the user file
05699    */
05700 }
05701 
05702 /**
05703   * @brief  Rx FIFO 0 callback.
05704   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05705   *         the configuration information for the specified FDCAN.
05706   * @param  RxFifo0ITs indicates which Rx FIFO 0 interrupts are signaled.
05707   *         This parameter can be any combination of @arg FDCAN_Rx_Fifo0_Interrupts.
05708   * @retval None
05709   */
05710 __weak void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
05711 {
05712   /* Prevent unused argument(s) compilation warning */
05713   UNUSED(hfdcan);
05714   UNUSED(RxFifo0ITs);
05715 
05716   /* NOTE : This function Should not be modified, when the callback is needed,
05717             the HAL_FDCAN_RxFifo0Callback could be implemented in the user file
05718    */
05719 }
05720 
05721 /**
05722   * @brief  Rx FIFO 1 callback.
05723   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05724   *         the configuration information for the specified FDCAN.
05725   * @param  RxFifo1ITs indicates which Rx FIFO 1 interrupts are signaled.
05726   *         This parameter can be any combination of @arg FDCAN_Rx_Fifo1_Interrupts.
05727   * @retval None
05728   */
05729 __weak void HAL_FDCAN_RxFifo1Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo1ITs)
05730 {
05731   /* Prevent unused argument(s) compilation warning */
05732   UNUSED(hfdcan);
05733   UNUSED(RxFifo1ITs);
05734 
05735   /* NOTE : This function Should not be modified, when the callback is needed,
05736             the HAL_FDCAN_RxFifo1Callback could be implemented in the user file
05737    */
05738 }
05739 
05740 /**
05741   * @brief  Tx FIFO Empty callback.
05742   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05743   *         the configuration information for the specified FDCAN.
05744   * @retval None
05745   */
05746 __weak void HAL_FDCAN_TxFifoEmptyCallback(FDCAN_HandleTypeDef *hfdcan)
05747 {
05748   /* Prevent unused argument(s) compilation warning */
05749   UNUSED(hfdcan);
05750 
05751   /* NOTE : This function Should not be modified, when the callback is needed,
05752             the HAL_FDCAN_TxFifoEmptyCallback could be implemented in the user file
05753    */
05754 }
05755 
05756 /**
05757   * @brief  Transmission Complete callback.
05758   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05759   *         the configuration information for the specified FDCAN.
05760   * @param  BufferIndexes Indexes of the transmitted buffers.
05761   *         This parameter can be any combination of @arg FDCAN_Tx_location.
05762   * @retval None
05763   */
05764 __weak void HAL_FDCAN_TxBufferCompleteCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t BufferIndexes)
05765 {
05766   /* Prevent unused argument(s) compilation warning */
05767   UNUSED(hfdcan);
05768   UNUSED(BufferIndexes);
05769 
05770   /* NOTE : This function Should not be modified, when the callback is needed,
05771             the HAL_FDCAN_TxBufferCompleteCallback could be implemented in the user file
05772    */
05773 }
05774 
05775 /**
05776   * @brief  Transmission Cancellation callback.
05777   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05778   *         the configuration information for the specified FDCAN.
05779   * @param  BufferIndexes Indexes of the aborted buffers.
05780   *         This parameter can be any combination of @arg FDCAN_Tx_location.
05781   * @retval None
05782   */
05783 __weak void HAL_FDCAN_TxBufferAbortCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t BufferIndexes)
05784 {
05785   /* Prevent unused argument(s) compilation warning */
05786   UNUSED(hfdcan);
05787   UNUSED(BufferIndexes);
05788 
05789   /* NOTE : This function Should not be modified, when the callback is needed,
05790             the HAL_FDCAN_TxBufferAbortCallback could be implemented in the user file
05791    */
05792 }
05793 
05794 /**
05795   * @brief  Rx Buffer New Message callback.
05796   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05797   *         the configuration information for the specified FDCAN.
05798   * @retval None
05799   */
05800 __weak void HAL_FDCAN_RxBufferNewMessageCallback(FDCAN_HandleTypeDef *hfdcan)
05801 {
05802   /* Prevent unused argument(s) compilation warning */
05803   UNUSED(hfdcan);
05804 
05805   /* NOTE : This function Should not be modified, when the callback is needed,
05806             the HAL_FDCAN_RxBufferNewMessageCallback could be implemented in the user file
05807    */
05808 }
05809 
05810 /**
05811   * @brief  Timestamp Wraparound callback.
05812   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05813   *         the configuration information for the specified FDCAN.
05814   * @retval None
05815   */
05816 __weak void HAL_FDCAN_TimestampWraparoundCallback(FDCAN_HandleTypeDef *hfdcan)
05817 {
05818   /* Prevent unused argument(s) compilation warning */
05819   UNUSED(hfdcan);
05820 
05821   /* NOTE : This function Should not be modified, when the callback is needed,
05822             the HAL_FDCAN_TimestampWraparoundCallback could be implemented in the user file
05823    */
05824 }
05825 
05826 /**
05827   * @brief  Timeout Occurred callback.
05828   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05829   *         the configuration information for the specified FDCAN.
05830   * @retval None
05831   */
05832 __weak void HAL_FDCAN_TimeoutOccurredCallback(FDCAN_HandleTypeDef *hfdcan)
05833 {
05834   /* Prevent unused argument(s) compilation warning */
05835   UNUSED(hfdcan);
05836 
05837   /* NOTE : This function Should not be modified, when the callback is needed,
05838             the HAL_FDCAN_TimeoutOccurredCallback could be implemented in the user file
05839    */
05840 }
05841 
05842 /**
05843   * @brief  High Priority Message callback.
05844   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05845   *         the configuration information for the specified FDCAN.
05846   * @retval None
05847   */
05848 __weak void HAL_FDCAN_HighPriorityMessageCallback(FDCAN_HandleTypeDef *hfdcan)
05849 {
05850   /* Prevent unused argument(s) compilation warning */
05851   UNUSED(hfdcan);
05852 
05853   /* NOTE : This function Should not be modified, when the callback is needed,
05854             the HAL_FDCAN_HighPriorityMessageCallback could be implemented in the user file
05855    */
05856 }
05857 
05858 /**
05859   * @brief  Error callback.
05860   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05861   *         the configuration information for the specified FDCAN.
05862   * @retval None
05863   */
05864 __weak void HAL_FDCAN_ErrorCallback(FDCAN_HandleTypeDef *hfdcan)
05865 {
05866   /* Prevent unused argument(s) compilation warning */
05867   UNUSED(hfdcan);
05868 
05869   /* NOTE : This function Should not be modified, when the callback is needed,
05870             the HAL_FDCAN_ErrorCallback could be implemented in the user file
05871    */
05872 }
05873 
05874 /**
05875   * @brief  Error status callback.
05876   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05877   *         the configuration information for the specified FDCAN.
05878   * @param  ErrorStatusITs indicates which Error Status interrupts are signaled.
05879   *         This parameter can be any combination of @arg FDCAN_Error_Status_Interrupts.
05880   * @retval None
05881   */
05882 __weak void HAL_FDCAN_ErrorStatusCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t ErrorStatusITs)
05883 {
05884   /* Prevent unused argument(s) compilation warning */
05885   UNUSED(hfdcan);
05886   UNUSED(ErrorStatusITs);
05887 
05888   /* NOTE : This function Should not be modified, when the callback is needed,
05889             the HAL_FDCAN_ErrorStatusCallback could be implemented in the user file
05890    */
05891 }
05892 
05893 /**
05894   * @brief  TT Schedule Synchronization callback.
05895   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05896   *         the configuration information for the specified FDCAN.
05897   * @param  TTSchedSyncITs indicates which TT Schedule Synchronization interrupts are signaled.
05898   *         This parameter can be any combination of @arg FDCAN_TTScheduleSynchronization_Interrupts.
05899   * @retval None
05900   */
05901 __weak void HAL_FDCAN_TT_ScheduleSyncCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t TTSchedSyncITs)
05902 {
05903   /* Prevent unused argument(s) compilation warning */
05904   UNUSED(hfdcan);
05905   UNUSED(TTSchedSyncITs);
05906 
05907   /* NOTE : This function Should not be modified, when the callback is needed,
05908             the HAL_FDCAN_TT_ScheduleSyncCallback could be implemented in the user file
05909    */
05910 }
05911 
05912 /**
05913   * @brief  TT Time Mark callback.
05914   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05915   *         the configuration information for the specified FDCAN.
05916   * @param  TTTimeMarkITs indicates which TT Schedule Synchronization interrupts are signaled.
05917   *         This parameter can be any combination of @arg FDCAN_TTTimeMark_Interrupts.
05918   * @retval None
05919   */
05920 __weak void HAL_FDCAN_TT_TimeMarkCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t TTTimeMarkITs)
05921 {
05922   /* Prevent unused argument(s) compilation warning */
05923   UNUSED(hfdcan);
05924   UNUSED(TTTimeMarkITs);
05925 
05926   /* NOTE : This function Should not be modified, when the callback is needed,
05927             the HAL_FDCAN_TT_TimeMarkCallback could be implemented in the user file
05928    */
05929 }
05930 
05931 /**
05932   * @brief  TT Stop Watch callback.
05933   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05934   *         the configuration information for the specified FDCAN.
05935   * @param  SWTime Time Value captured at the Stop Watch Trigger pin (fdcan1_swt) falling/rising
05936   *         edge (as configured via HAL_FDCAN_TTConfigStopWatch).
05937   *         This parameter is a number between 0 and 0xFFFF.
05938   * @param  SWCycleCount Cycle count value captured together with SWTime.
05939   *         This parameter is a number between 0 and 0x3F.
05940   * @retval None
05941   */
05942 __weak void HAL_FDCAN_TT_StopWatchCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t SWTime, uint32_t SWCycleCount)
05943 {
05944   /* Prevent unused argument(s) compilation warning */
05945   UNUSED(hfdcan);
05946   UNUSED(SWTime);
05947   UNUSED(SWCycleCount);
05948 
05949   /* NOTE : This function Should not be modified, when the callback is needed,
05950             the HAL_FDCAN_TT_StopWatchCallback could be implemented in the user file
05951    */
05952 }
05953 
05954 /**
05955   * @brief  TT Global Time callback.
05956   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05957   *         the configuration information for the specified FDCAN.
05958   * @param  TTGlobTimeITs indicates which TT Global Time interrupts are signaled.
05959   *         This parameter can be any combination of @arg FDCAN_TTGlobalTime_Interrupts.
05960   * @retval None
05961   */
05962 __weak void HAL_FDCAN_TT_GlobalTimeCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t TTGlobTimeITs)
05963 {
05964   /* Prevent unused argument(s) compilation warning */
05965   UNUSED(hfdcan);
05966   UNUSED(TTGlobTimeITs);
05967 
05968   /* NOTE : This function Should not be modified, when the callback is needed,
05969             the HAL_FDCAN_TT_GlobalTimeCallback could be implemented in the user file
05970    */
05971 }
05972 
05973 /**
05974   * @}
05975   */
05976 
05977 /** @defgroup FDCAN_Exported_Functions_Group7 Peripheral State functions
05978  *  @brief   FDCAN Peripheral State functions
05979  *
05980 @verbatim
05981   ==============================================================================
05982                       ##### Peripheral State functions #####
05983   ==============================================================================
05984     [..]
05985     This subsection provides functions allowing to :
05986       (+) HAL_FDCAN_GetState()  : Return the FDCAN state.
05987       (+) HAL_FDCAN_GetError()  : Return the FDCAN error code if any.
05988 
05989 @endverbatim
05990   * @{
05991   */
05992 /**
05993   * @brief  Return the FDCAN state
05994   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
05995   *         the configuration information for the specified FDCAN.
05996   * @retval HAL state
05997   */
05998 HAL_FDCAN_StateTypeDef HAL_FDCAN_GetState(FDCAN_HandleTypeDef *hfdcan)
05999 {
06000   /* Return FDCAN state */
06001   return hfdcan->State;
06002 }
06003 
06004 /**
06005   * @brief  Return the FDCAN error code
06006   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
06007   *         the configuration information for the specified FDCAN.
06008   * @retval FDCAN Error Code
06009   */
06010 uint32_t HAL_FDCAN_GetError(FDCAN_HandleTypeDef *hfdcan)
06011 {
06012   /* Return FDCAN error code */
06013   return hfdcan->ErrorCode;
06014 }
06015 
06016 /**
06017   * @}
06018   */
06019 
06020 /**
06021   * @}
06022   */
06023 
06024 /** @addtogroup FDCAN_Private_Functions
06025   * @{
06026   */
06027 
06028 /**
06029   * @brief  Calculate each RAM block start address and size
06030   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
06031   *         the configuration information for the specified FDCAN.
06032   * @retval HAL status
06033  */
06034 static HAL_StatusTypeDef FDCAN_CalcultateRamBlockAddresses(FDCAN_HandleTypeDef *hfdcan)
06035 {
06036   uint32_t RAMcounter;
06037   uint32_t StartAddress;
06038 
06039   StartAddress = hfdcan->Init.MessageRAMOffset;
06040 
06041   /* Standard filter list start address */
06042   MODIFY_REG(hfdcan->Instance->SIDFC, FDCAN_SIDFC_FLSSA, (StartAddress << FDCAN_SIDFC_FLSSA_Pos));
06043 
06044   /* Standard filter elements number */
06045   MODIFY_REG(hfdcan->Instance->SIDFC, FDCAN_SIDFC_LSS, (hfdcan->Init.StdFiltersNbr << FDCAN_SIDFC_LSS_Pos));
06046 
06047   /* Extended filter list start address */
06048   StartAddress += hfdcan->Init.StdFiltersNbr;
06049   MODIFY_REG(hfdcan->Instance->XIDFC, FDCAN_XIDFC_FLESA, (StartAddress << FDCAN_XIDFC_FLESA_Pos));
06050 
06051   /* Extended filter elements number */
06052   MODIFY_REG(hfdcan->Instance->XIDFC, FDCAN_XIDFC_LSE, (hfdcan->Init.ExtFiltersNbr << FDCAN_XIDFC_LSE_Pos));
06053 
06054   /* Rx FIFO 0 start address */
06055   StartAddress += (hfdcan->Init.ExtFiltersNbr * 2U);
06056   MODIFY_REG(hfdcan->Instance->RXF0C, FDCAN_RXF0C_F0SA, (StartAddress << FDCAN_RXF0C_F0SA_Pos));
06057 
06058   /* Rx FIFO 0 elements number */
06059   MODIFY_REG(hfdcan->Instance->RXF0C, FDCAN_RXF0C_F0S, (hfdcan->Init.RxFifo0ElmtsNbr << FDCAN_RXF0C_F0S_Pos));
06060 
06061   /* Rx FIFO 1 start address */
06062   StartAddress += (hfdcan->Init.RxFifo0ElmtsNbr * hfdcan->Init.RxFifo0ElmtSize);
06063   MODIFY_REG(hfdcan->Instance->RXF1C, FDCAN_RXF1C_F1SA, (StartAddress << FDCAN_RXF1C_F1SA_Pos));
06064 
06065   /* Rx FIFO 1 elements number */
06066   MODIFY_REG(hfdcan->Instance->RXF1C, FDCAN_RXF1C_F1S, (hfdcan->Init.RxFifo1ElmtsNbr << FDCAN_RXF1C_F1S_Pos));
06067 
06068   /* Rx buffer list start address */
06069   StartAddress += (hfdcan->Init.RxFifo1ElmtsNbr * hfdcan->Init.RxFifo1ElmtSize);
06070   MODIFY_REG(hfdcan->Instance->RXBC, FDCAN_RXBC_RBSA, (StartAddress << FDCAN_RXBC_RBSA_Pos));
06071 
06072   /* Tx event FIFO start address */
06073   StartAddress += (hfdcan->Init.RxBuffersNbr * hfdcan->Init.RxBufferSize);
06074   MODIFY_REG(hfdcan->Instance->TXEFC, FDCAN_TXEFC_EFSA, (StartAddress << FDCAN_TXEFC_EFSA_Pos));
06075 
06076   /* Tx event FIFO elements number */
06077   MODIFY_REG(hfdcan->Instance->TXEFC, FDCAN_TXEFC_EFS, (hfdcan->Init.TxEventsNbr << FDCAN_TXEFC_EFS_Pos));
06078 
06079   /* Tx buffer list start address */
06080   StartAddress += (hfdcan->Init.TxEventsNbr * 2U);
06081   MODIFY_REG(hfdcan->Instance->TXBC, FDCAN_TXBC_TBSA, (StartAddress << FDCAN_TXBC_TBSA_Pos));
06082 
06083   /* Dedicated Tx buffers number */
06084   MODIFY_REG(hfdcan->Instance->TXBC, FDCAN_TXBC_NDTB, (hfdcan->Init.TxBuffersNbr << FDCAN_TXBC_NDTB_Pos));
06085 
06086   /* Tx FIFO/queue elements number */
06087   MODIFY_REG(hfdcan->Instance->TXBC, FDCAN_TXBC_TFQS, (hfdcan->Init.TxFifoQueueElmtsNbr << FDCAN_TXBC_TFQS_Pos));
06088 
06089   hfdcan->msgRam.StandardFilterSA = SRAMCAN_BASE + (hfdcan->Init.MessageRAMOffset * 4U);
06090   hfdcan->msgRam.ExtendedFilterSA = hfdcan->msgRam.StandardFilterSA + (hfdcan->Init.StdFiltersNbr * 4U);
06091   hfdcan->msgRam.RxFIFO0SA = hfdcan->msgRam.ExtendedFilterSA + (hfdcan->Init.ExtFiltersNbr * 2U * 4U);
06092   hfdcan->msgRam.RxFIFO1SA = hfdcan->msgRam.RxFIFO0SA + (hfdcan->Init.RxFifo0ElmtsNbr * hfdcan->Init.RxFifo0ElmtSize * 4U);
06093   hfdcan->msgRam.RxBufferSA = hfdcan->msgRam.RxFIFO1SA + (hfdcan->Init.RxFifo1ElmtsNbr * hfdcan->Init.RxFifo1ElmtSize * 4U);
06094   hfdcan->msgRam.TxEventFIFOSA = hfdcan->msgRam.RxBufferSA + (hfdcan->Init.RxBuffersNbr * hfdcan->Init.RxBufferSize * 4U);
06095   hfdcan->msgRam.TxBufferSA = hfdcan->msgRam.TxEventFIFOSA + (hfdcan->Init.TxEventsNbr * 2U * 4U);
06096   hfdcan->msgRam.TxFIFOQSA = hfdcan->msgRam.TxBufferSA + (hfdcan->Init.TxBuffersNbr * hfdcan->Init.TxElmtSize * 4U);
06097 
06098   hfdcan->msgRam.EndAddress = hfdcan->msgRam.TxFIFOQSA + (hfdcan->Init.TxFifoQueueElmtsNbr * hfdcan->Init.TxElmtSize * 4U);
06099 
06100   if (hfdcan->msgRam.EndAddress > FDCAN_MESSAGE_RAM_END_ADDRESS) /* Last address of the Message RAM */
06101   {
06102     /* Update error code.
06103        Message RAM overflow */
06104     hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
06105 
06106     /* Change FDCAN state */
06107     hfdcan->State = HAL_FDCAN_STATE_ERROR;
06108 
06109     return HAL_ERROR;
06110   }
06111   else
06112   {
06113     /* Flush the allocated Message RAM area */
06114     for (RAMcounter = hfdcan->msgRam.StandardFilterSA; RAMcounter < hfdcan->msgRam.EndAddress; RAMcounter += 4U)
06115     {
06116       *(uint32_t *)(RAMcounter) = 0x00000000;
06117     }
06118   }
06119 
06120   /* Return function status */
06121   return HAL_OK;
06122 }
06123 
06124 /**
06125   * @brief  Copy Tx message to the message RAM.
06126   * @param  hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
06127   *         the configuration information for the specified FDCAN.
06128   * @param  pTxHeader pointer to a FDCAN_TxHeaderTypeDef structure.
06129   * @param  pTxData pointer to a buffer containing the payload of the Tx frame.
06130   * @param  BufferIndex index of the buffer to be configured.
06131   * @retval HAL status
06132  */
06133 static void FDCAN_CopyMessageToRAM(FDCAN_HandleTypeDef *hfdcan, FDCAN_TxHeaderTypeDef *pTxHeader, uint8_t *pTxData, uint32_t BufferIndex)
06134 {
06135   uint32_t TxElementW1;
06136   uint32_t TxElementW2;
06137   uint32_t *TxAddress;
06138   uint32_t ByteCounter;
06139 
06140   /* Build first word of Tx header element */
06141   if (pTxHeader->IdType == FDCAN_STANDARD_ID)
06142   {
06143     TxElementW1 = (pTxHeader->ErrorStateIndicator |
06144                    FDCAN_STANDARD_ID |
06145                    pTxHeader->TxFrameType |
06146                    (pTxHeader->Identifier << 18));
06147   }
06148   else /* pTxHeader->IdType == FDCAN_EXTENDED_ID */
06149   {
06150     TxElementW1 = (pTxHeader->ErrorStateIndicator |
06151                    FDCAN_EXTENDED_ID |
06152                    pTxHeader->TxFrameType |
06153                    pTxHeader->Identifier);
06154   }
06155 
06156   /* Build second word of Tx header element */
06157   TxElementW2 = ((pTxHeader->MessageMarker << 24) |
06158                  pTxHeader->TxEventFifoControl |
06159                  pTxHeader->FDFormat |
06160                  pTxHeader->BitRateSwitch |
06161                  pTxHeader->DataLength);
06162 
06163   /* Calculate Tx element address */
06164   TxAddress = (uint32_t *)(hfdcan->msgRam.TxBufferSA + (BufferIndex * hfdcan->Init.TxElmtSize * 4U));
06165 
06166   /* Write Tx element header to the message RAM */
06167   *TxAddress = TxElementW1;
06168   TxAddress++;
06169   *TxAddress = TxElementW2;
06170   TxAddress++;
06171 
06172   /* Write Tx payload to the message RAM */
06173   for (ByteCounter = 0; ByteCounter < DLCtoBytes[pTxHeader->DataLength >> 16]; ByteCounter += 4U)
06174   {
06175     *TxAddress = (((uint32_t)pTxData[ByteCounter + 3U] << 24) |
06176                   ((uint32_t)pTxData[ByteCounter + 2U] << 16) |
06177                   ((uint32_t)pTxData[ByteCounter + 1U] << 8) |
06178                   (uint32_t)pTxData[ByteCounter]);
06179     TxAddress++;
06180   }
06181 }
06182 
06183 /**
06184   * @}
06185   */
06186 #endif /* HAL_FDCAN_MODULE_ENABLED */
06187 /**
06188   * @}
06189   */
06190 
06191 /**
06192   * @}
06193   */
06194 
06195 #endif /* FDCAN1 */
06196