Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:06

0001 /**
0002   ******************************************************************************
0003   * @file    stm32h7xx_hal_cordic.c
0004   * @author  MCD Application Team
0005   * @brief   CORDIC HAL module driver.
0006   *          This file provides firmware functions to manage the following
0007   *          functionalities of the CORDIC peripheral:
0008   *           + Initialization and de-initialization functions
0009   *           + Peripheral Control functions
0010   *           + Callback functions
0011   *           + IRQ handler management
0012   *           + Peripheral State functions
0013   *
0014   ******************************************************************************
0015   * @attention
0016   *
0017   * Copyright (c) 2017 STMicroelectronics.
0018   * All rights reserved.
0019   *
0020   * This software is licensed under terms that can be found in the LICENSE file
0021   * in the root directory of this software component.
0022   * If no LICENSE file comes with this software, it is provided AS-IS.
0023   *
0024   ******************************************************************************
0025   @verbatim
0026   ================================================================================
0027             ##### How to use this driver #####
0028   ================================================================================
0029     [..]
0030       The CORDIC HAL driver can be used as follows:
0031 
0032       (#) Initialize the CORDIC low level resources by implementing the HAL_CORDIC_MspInit():
0033          (++) Enable the CORDIC interface clock using __HAL_RCC_CORDIC_CLK_ENABLE()
0034          (++) In case of using interrupts (e.g. HAL_CORDIC_Calculate_IT())
0035              (+++) Configure the CORDIC interrupt priority using HAL_NVIC_SetPriority()
0036              (+++) Enable the CORDIC IRQ handler using HAL_NVIC_EnableIRQ()
0037              (+++) In CORDIC IRQ handler, call HAL_CORDIC_IRQHandler()
0038          (++) In case of using DMA to control data transfer (e.g. HAL_CORDIC_Calculate_DMA())
0039              (+++) Enable the DMA2 interface clock using
0040                  __HAL_RCC_DMA2_CLK_ENABLE()
0041              (+++) Configure and enable two DMA channels one for managing data transfer from
0042                  memory to peripheral (input channel) and another channel for managing data
0043                  transfer from peripheral to memory (output channel)
0044              (+++) Associate the initialized DMA handle to the CORDIC DMA handle
0045                  using __HAL_LINKDMA()
0046              (+++) Configure the priority and enable the NVIC for the transfer complete
0047                  interrupt on the two DMA channels.
0048                  Resort to HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ()
0049 
0050       (#) Initialize the CORDIC HAL using HAL_CORDIC_Init(). This function
0051          (++) resorts to HAL_CORDIC_MspInit() for low-level initialization,
0052 
0053       (#) Configure CORDIC processing (calculation) using HAL_CORDIC_Configure().
0054           This function configures:
0055          (++) Processing functions: Cosine, Sine, Phase, Modulus, Arctangent,
0056               Hyperbolic cosine, Hyperbolic sine, Hyperbolic arctangent,
0057               Natural log, Square root
0058          (++) Scaling factor: 1 to 2exp(-7)
0059          (++) Width of input data: 32 bits input data size (Q1.31 format) or 16 bits
0060               input data size (Q1.15 format)
0061          (++) Width of output data: 32 bits output data size (Q1.31 format) or 16 bits
0062               output data size (Q1.15 format)
0063          (++) Number of 32-bit write expected for one calculation: One 32-bits write
0064               or Two 32-bit write
0065          (++) Number of 32-bit read expected after one calculation: One 32-bits read
0066               or Two 32-bit read
0067          (++) Precision: 1 to 15 cycles for calculation (the more cycles, the better precision)
0068 
0069       (#) Four processing (calculation) functions are available:
0070          (++) Polling mode: processing API is blocking function
0071               i.e. it processes the data and wait till the processing is finished
0072               API is HAL_CORDIC_Calculate
0073          (++) Polling Zero-overhead mode: processing API is blocking function
0074               i.e. it processes the data and wait till the processing is finished
0075               A bit faster than standard polling mode, but blocking also AHB bus
0076               API is HAL_CORDIC_CalculateZO
0077          (++) Interrupt mode: processing API is not blocking functions
0078               i.e. it processes the data under interrupt
0079               API is HAL_CORDIC_Calculate_IT
0080          (++) DMA mode: processing API is not blocking functions and the CPU is
0081               not used for data transfer,
0082               i.e. the data transfer is ensured by DMA
0083               API is HAL_CORDIC_Calculate_DMA
0084 
0085       (#) Call HAL_CORDIC_DeInit() to de-initialize the CORDIC peripheral. This function
0086          (++) resorts to HAL_CORDIC_MspDeInit() for low-level de-initialization,
0087 
0088   *** Callback registration ***
0089   =============================================
0090 
0091   The compilation define  USE_HAL_CORDIC_REGISTER_CALLBACKS when set to 1
0092   allows the user to configure dynamically the driver callbacks.
0093   Use Function HAL_CORDIC_RegisterCallback() to register an interrupt callback.
0094 
0095   Function HAL_CORDIC_RegisterCallback() allows to register following callbacks:
0096     (+) ErrorCallback             : Error Callback.
0097     (+) CalculateCpltCallback     : Calculate complete Callback.
0098     (+) MspInitCallback           : CORDIC MspInit.
0099     (+) MspDeInitCallback         : CORDIC MspDeInit.
0100   This function takes as parameters the HAL peripheral handle, the Callback ID
0101   and a pointer to the user callback function.
0102 
0103   Use function HAL_CORDIC_UnRegisterCallback() to reset a callback to the default
0104   weak function.
0105   HAL_CORDIC_UnRegisterCallback takes as parameters the HAL peripheral handle,
0106   and the Callback ID.
0107   This function allows to reset following callbacks:
0108     (+) ErrorCallback             : Error Callback.
0109     (+) CalculateCpltCallback     : Calculate complete Callback.
0110     (+) MspInitCallback           : CORDIC MspInit.
0111     (+) MspDeInitCallback         : CORDIC MspDeInit.
0112 
0113   By default, after the HAL_CORDIC_Init() and when the state is HAL_CORDIC_STATE_RESET,
0114   all callbacks are set to the corresponding weak functions:
0115   examples HAL_CORDIC_ErrorCallback(), HAL_CORDIC_CalculateCpltCallback().
0116   Exception done for MspInit and MspDeInit functions that are
0117   reset to the legacy weak function in the HAL_CORDIC_Init()/ HAL_CORDIC_DeInit() only when
0118   these callbacks are null (not registered beforehand).
0119   if not, MspInit or MspDeInit are not null, the HAL_CORDIC_Init()/ HAL_CORDIC_DeInit()
0120   keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
0121 
0122   Callbacks can be registered/unregistered in HAL_CORDIC_STATE_READY state only.
0123   Exception done MspInit/MspDeInit that can be registered/unregistered
0124   in HAL_CORDIC_STATE_READY or HAL_CORDIC_STATE_RESET state,
0125   thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
0126   In that case first register the MspInit/MspDeInit user callbacks
0127   using HAL_CORDIC_RegisterCallback() before calling HAL_CORDIC_DeInit()
0128   or HAL_CORDIC_Init() function.
0129 
0130   When The compilation define USE_HAL_CORDIC_REGISTER_CALLBACKS is set to 0 or
0131   not defined, the callback registration feature is not available and all callbacks
0132   are set to the corresponding weak functions.
0133 
0134   @endverbatim
0135   ******************************************************************************
0136   */
0137 
0138 /* Includes ------------------------------------------------------------------*/
0139 #include "stm32h7xx_hal.h"
0140 
0141 #if defined(CORDIC)
0142 #ifdef HAL_CORDIC_MODULE_ENABLED
0143 
0144 /** @addtogroup STM32H7xx_HAL_Driver
0145   * @{
0146   */
0147 
0148 /** @defgroup CORDIC CORDIC
0149   * @ingroup RTEMSBSPsARMSTM32H7
0150   * @brief CORDIC HAL driver modules.
0151   * @{
0152   */
0153 
0154 /* Private typedef -----------------------------------------------------------*/
0155 /* Private define ------------------------------------------------------------*/
0156 /* Private macro -------------------------------------------------------------*/
0157 /* Private variables ---------------------------------------------------------*/
0158 /* Private function prototypes -----------------------------------------------*/
0159 
0160 /** @defgroup CORDIC_Private_Functions CORDIC Private Functions
0161   * @ingroup RTEMSBSPsARMSTM32H7
0162   * @{
0163   */
0164 static void CORDIC_WriteInDataIncrementPtr(const CORDIC_HandleTypeDef *hcordic, const int32_t **ppInBuff);
0165 static void CORDIC_ReadOutDataIncrementPtr(const CORDIC_HandleTypeDef *hcordic, int32_t **ppOutBuff);
0166 static void CORDIC_DMAInCplt(DMA_HandleTypeDef *hdma);
0167 static void CORDIC_DMAOutCplt(DMA_HandleTypeDef *hdma);
0168 static void CORDIC_DMAError(DMA_HandleTypeDef *hdma);
0169 /**
0170   * @}
0171   */
0172 
0173 /* Exported functions --------------------------------------------------------*/
0174 
0175 /** @defgroup CORDIC_Exported_Functions CORDIC Exported Functions
0176   * @ingroup RTEMSBSPsARMSTM32H7
0177   * @{
0178   */
0179 
0180 /** @defgroup CORDIC_Exported_Functions_Group1 Initialization and de-initialization functions
0181   * @ingroup RTEMSBSPsARMSTM32H7
0182   *  @brief    Initialization and Configuration functions.
0183   *
0184 @verbatim
0185   ==============================================================================
0186               ##### Initialization and de-initialization functions #####
0187   ==============================================================================
0188     [..]  This section provides functions allowing to:
0189       (+) Initialize the CORDIC peripheral and the associated handle
0190       (+) DeInitialize the CORDIC peripheral
0191       (+) Initialize the CORDIC MSP (MCU Specific Package)
0192       (+) De-Initialize the CORDIC MSP
0193 
0194     [..]
0195 
0196 @endverbatim
0197   * @{
0198   */
0199 
0200 /**
0201   * @brief  Initialize the CORDIC peripheral and the associated handle.
0202   * @param  hcordic pointer to a CORDIC_HandleTypeDef structure.
0203   * @retval HAL status
0204   */
0205 HAL_StatusTypeDef HAL_CORDIC_Init(CORDIC_HandleTypeDef *hcordic)
0206 {
0207   /* Check the CORDIC handle allocation */
0208   if (hcordic == NULL)
0209   {
0210     /* Return error status */
0211     return HAL_ERROR;
0212   }
0213 
0214   /* Check the instance */
0215   assert_param(IS_CORDIC_ALL_INSTANCE(hcordic->Instance));
0216 
0217 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
0218   if (hcordic->State == HAL_CORDIC_STATE_RESET)
0219   {
0220     /* Allocate lock resource and initialize it */
0221     hcordic->Lock = HAL_UNLOCKED;
0222 
0223     /* Reset callbacks to legacy functions */
0224     hcordic->ErrorCallback         = HAL_CORDIC_ErrorCallback;         /* Legacy weak ErrorCallback */
0225     hcordic->CalculateCpltCallback = HAL_CORDIC_CalculateCpltCallback; /* Legacy weak CalculateCpltCallback */
0226 
0227     if (hcordic->MspInitCallback == NULL)
0228     {
0229       hcordic->MspInitCallback = HAL_CORDIC_MspInit;                   /* Legacy weak MspInit */
0230     }
0231 
0232     /* Initialize the low level hardware */
0233     hcordic->MspInitCallback(hcordic);
0234   }
0235 #else
0236   if (hcordic->State == HAL_CORDIC_STATE_RESET)
0237   {
0238     /* Allocate lock resource and initialize it */
0239     hcordic->Lock = HAL_UNLOCKED;
0240 
0241     /* Initialize the low level hardware */
0242     HAL_CORDIC_MspInit(hcordic);
0243   }
0244 #endif /* (USE_HAL_CORDIC_REGISTER_CALLBACKS) */
0245 
0246   /* Set CORDIC error code to none */
0247   hcordic->ErrorCode = HAL_CORDIC_ERROR_NONE;
0248 
0249   /* Reset pInBuff and pOutBuff */
0250   hcordic->pInBuff = NULL;
0251   hcordic->pOutBuff = NULL;
0252 
0253   /* Reset NbCalcToOrder and NbCalcToGet */
0254   hcordic->NbCalcToOrder = 0U;
0255   hcordic->NbCalcToGet = 0U;
0256 
0257   /* Reset DMADirection */
0258   hcordic->DMADirection = CORDIC_DMA_DIR_NONE;
0259 
0260   /* Change CORDIC peripheral state */
0261   hcordic->State = HAL_CORDIC_STATE_READY;
0262 
0263   /* Return function status */
0264   return HAL_OK;
0265 }
0266 
0267 /**
0268   * @brief  DeInitialize the CORDIC peripheral.
0269   * @param  hcordic pointer to a CORDIC_HandleTypeDef structure.
0270   * @retval HAL status
0271   */
0272 HAL_StatusTypeDef HAL_CORDIC_DeInit(CORDIC_HandleTypeDef *hcordic)
0273 {
0274   /* Check the CORDIC handle allocation */
0275   if (hcordic == NULL)
0276   {
0277     /* Return error status */
0278     return HAL_ERROR;
0279   }
0280 
0281   /* Check the parameters */
0282   assert_param(IS_CORDIC_ALL_INSTANCE(hcordic->Instance));
0283 
0284   /* Change CORDIC peripheral state */
0285   hcordic->State = HAL_CORDIC_STATE_BUSY;
0286 
0287 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
0288   if (hcordic->MspDeInitCallback == NULL)
0289   {
0290     hcordic->MspDeInitCallback = HAL_CORDIC_MspDeInit;
0291   }
0292 
0293   /* De-Initialize the low level hardware */
0294   hcordic->MspDeInitCallback(hcordic);
0295 #else
0296   /* De-Initialize the low level hardware: CLOCK, NVIC, DMA */
0297   HAL_CORDIC_MspDeInit(hcordic);
0298 #endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */
0299 
0300   /* Set CORDIC error code to none */
0301   hcordic->ErrorCode = HAL_CORDIC_ERROR_NONE;
0302 
0303   /* Reset pInBuff and pOutBuff */
0304   hcordic->pInBuff = NULL;
0305   hcordic->pOutBuff = NULL;
0306 
0307   /* Reset NbCalcToOrder and NbCalcToGet */
0308   hcordic->NbCalcToOrder = 0U;
0309   hcordic->NbCalcToGet = 0U;
0310 
0311   /* Reset DMADirection */
0312   hcordic->DMADirection = CORDIC_DMA_DIR_NONE;
0313 
0314   /* Change CORDIC peripheral state */
0315   hcordic->State = HAL_CORDIC_STATE_RESET;
0316 
0317   /* Reset Lock */
0318   hcordic->Lock = HAL_UNLOCKED;
0319 
0320   /* Return function status */
0321   return HAL_OK;
0322 }
0323 
0324 /**
0325   * @brief  Initialize the CORDIC MSP.
0326   * @param  hcordic CORDIC handle
0327   * @retval None
0328   */
0329 __weak void HAL_CORDIC_MspInit(CORDIC_HandleTypeDef *hcordic)
0330 {
0331   /* Prevent unused argument(s) compilation warning */
0332   UNUSED(hcordic);
0333 
0334   /* NOTE : This function should not be modified, when the callback is needed,
0335             the HAL_CORDIC_MspInit can be implemented in the user file
0336    */
0337 }
0338 
0339 /**
0340   * @brief  DeInitialize the CORDIC MSP.
0341   * @param  hcordic CORDIC handle
0342   * @retval None
0343   */
0344 __weak void HAL_CORDIC_MspDeInit(CORDIC_HandleTypeDef *hcordic)
0345 {
0346   /* Prevent unused argument(s) compilation warning */
0347   UNUSED(hcordic);
0348 
0349   /* NOTE : This function should not be modified, when the callback is needed,
0350             the HAL_CORDIC_MspDeInit can be implemented in the user file
0351    */
0352 }
0353 
0354 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
0355 /**
0356   * @brief  Register a CORDIC CallBack.
0357   *         To be used instead of the weak predefined callback.
0358   * @param  hcordic pointer to a CORDIC_HandleTypeDef structure that contains
0359   *         the configuration information for CORDIC module
0360   * @param  CallbackID ID of the callback to be registered
0361   *         This parameter can be one of the following values:
0362   *           @arg @ref HAL_CORDIC_ERROR_CB_ID error Callback ID
0363   *           @arg @ref HAL_CORDIC_CALCULATE_CPLT_CB_ID calculate complete Callback ID
0364   *           @arg @ref HAL_CORDIC_MSPINIT_CB_ID MspInit callback ID
0365   *           @arg @ref HAL_CORDIC_MSPDEINIT_CB_ID MspDeInit callback ID
0366   * @param  pCallback pointer to the Callback function
0367   * @retval HAL status
0368   */
0369 HAL_StatusTypeDef HAL_CORDIC_RegisterCallback(CORDIC_HandleTypeDef *hcordic, HAL_CORDIC_CallbackIDTypeDef CallbackID,
0370                                               void (* pCallback)(CORDIC_HandleTypeDef *_hcordic))
0371 {
0372   HAL_StatusTypeDef status = HAL_OK;
0373 
0374   if (pCallback == NULL)
0375   {
0376     /* Update the error code */
0377     hcordic->ErrorCode |= HAL_CORDIC_ERROR_INVALID_CALLBACK;
0378 
0379     /* Return error status */
0380     return HAL_ERROR;
0381   }
0382 
0383   if (hcordic->State == HAL_CORDIC_STATE_READY)
0384   {
0385     switch (CallbackID)
0386     {
0387       case HAL_CORDIC_ERROR_CB_ID :
0388         hcordic->ErrorCallback = pCallback;
0389         break;
0390 
0391       case HAL_CORDIC_CALCULATE_CPLT_CB_ID :
0392         hcordic->CalculateCpltCallback = pCallback;
0393         break;
0394 
0395       case HAL_CORDIC_MSPINIT_CB_ID :
0396         hcordic->MspInitCallback = pCallback;
0397         break;
0398 
0399       case HAL_CORDIC_MSPDEINIT_CB_ID :
0400         hcordic->MspDeInitCallback = pCallback;
0401         break;
0402 
0403       default :
0404         /* Update the error code */
0405         hcordic->ErrorCode |= HAL_CORDIC_ERROR_INVALID_CALLBACK;
0406 
0407         /* Return error status */
0408         status = HAL_ERROR;
0409         break;
0410     }
0411   }
0412   else if (hcordic->State == HAL_CORDIC_STATE_RESET)
0413   {
0414     switch (CallbackID)
0415     {
0416       case HAL_CORDIC_MSPINIT_CB_ID :
0417         hcordic->MspInitCallback = pCallback;
0418         break;
0419 
0420       case HAL_CORDIC_MSPDEINIT_CB_ID :
0421         hcordic->MspDeInitCallback = pCallback;
0422         break;
0423 
0424       default :
0425         /* Update the error code */
0426         hcordic->ErrorCode |= HAL_CORDIC_ERROR_INVALID_CALLBACK;
0427 
0428         /* Return error status */
0429         status = HAL_ERROR;
0430         break;
0431     }
0432   }
0433   else
0434   {
0435     /* Update the error code */
0436     hcordic->ErrorCode |= HAL_CORDIC_ERROR_INVALID_CALLBACK;
0437 
0438     /* Return error status */
0439     status = HAL_ERROR;
0440   }
0441 
0442   return status;
0443 }
0444 #endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */
0445 
0446 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
0447 /**
0448   * @brief  Unregister a CORDIC CallBack.
0449   *         CORDIC callback is redirected to the weak predefined callback.
0450   * @param  hcordic pointer to a CORDIC_HandleTypeDef structure that contains
0451   *         the configuration information for CORDIC module
0452   * @param  CallbackID ID of the callback to be unregistered
0453   *         This parameter can be one of the following values:
0454   *           @arg @ref HAL_CORDIC_ERROR_CB_ID error Callback ID
0455   *           @arg @ref HAL_CORDIC_CALCULATE_CPLT_CB_ID calculate complete Callback ID
0456   *           @arg @ref HAL_CORDIC_MSPINIT_CB_ID MspInit callback ID
0457   *           @arg @ref HAL_CORDIC_MSPDEINIT_CB_ID MspDeInit callback ID
0458   * @retval HAL status
0459   */
0460 HAL_StatusTypeDef HAL_CORDIC_UnRegisterCallback(CORDIC_HandleTypeDef *hcordic, HAL_CORDIC_CallbackIDTypeDef CallbackID)
0461 {
0462   HAL_StatusTypeDef status = HAL_OK;
0463 
0464   if (hcordic->State == HAL_CORDIC_STATE_READY)
0465   {
0466     switch (CallbackID)
0467     {
0468       case HAL_CORDIC_ERROR_CB_ID :
0469         hcordic->ErrorCallback = HAL_CORDIC_ErrorCallback;
0470         break;
0471 
0472       case HAL_CORDIC_CALCULATE_CPLT_CB_ID :
0473         hcordic->CalculateCpltCallback = HAL_CORDIC_CalculateCpltCallback;
0474         break;
0475 
0476       case HAL_CORDIC_MSPINIT_CB_ID :
0477         hcordic->MspInitCallback = HAL_CORDIC_MspInit;
0478         break;
0479 
0480       case HAL_CORDIC_MSPDEINIT_CB_ID :
0481         hcordic->MspDeInitCallback = HAL_CORDIC_MspDeInit;
0482         break;
0483 
0484       default :
0485         /* Update the error code */
0486         hcordic->ErrorCode |= HAL_CORDIC_ERROR_INVALID_CALLBACK;
0487 
0488         /* Return error status */
0489         status = HAL_ERROR;
0490         break;
0491     }
0492   }
0493   else if (hcordic->State == HAL_CORDIC_STATE_RESET)
0494   {
0495     switch (CallbackID)
0496     {
0497       case HAL_CORDIC_MSPINIT_CB_ID :
0498         hcordic->MspInitCallback = HAL_CORDIC_MspInit;
0499         break;
0500 
0501       case HAL_CORDIC_MSPDEINIT_CB_ID :
0502         hcordic->MspDeInitCallback = HAL_CORDIC_MspDeInit;
0503         break;
0504 
0505       default :
0506         /* Update the error code */
0507         hcordic->ErrorCode |= HAL_CORDIC_ERROR_INVALID_CALLBACK;
0508 
0509         /* Return error status */
0510         status = HAL_ERROR;
0511         break;
0512     }
0513   }
0514   else
0515   {
0516     /* Update the error code */
0517     hcordic->ErrorCode |= HAL_CORDIC_ERROR_INVALID_CALLBACK;
0518 
0519     /* Return error status */
0520     status = HAL_ERROR;
0521   }
0522 
0523   return status;
0524 }
0525 #endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */
0526 
0527 /**
0528   * @}
0529   */
0530 
0531 /** @defgroup CORDIC_Exported_Functions_Group2 Peripheral Control functions
0532   * @ingroup RTEMSBSPsARMSTM32H7
0533   *  @brief    Control functions.
0534   *
0535 @verbatim
0536   ==============================================================================
0537                       ##### Peripheral Control functions #####
0538   ==============================================================================
0539     [..]  This section provides functions allowing to:
0540       (+) Configure the CORDIC peripheral: function, precision, scaling factor,
0541           number of input data and output data, size of input data and output data.
0542       (+) Calculate output data of CORDIC processing on input date, using the
0543           existing CORDIC configuration
0544     [..]  Four processing functions are available for calculation:
0545       (+) Polling mode
0546       (+) Polling mode, with Zero-Overhead register access
0547       (+) Interrupt mode
0548       (+) DMA mode
0549 
0550 @endverbatim
0551   * @{
0552   */
0553 
0554 /**
0555   * @brief  Configure the CORDIC processing according to the specified
0556             parameters in the CORDIC_ConfigTypeDef structure.
0557   * @param  hcordic pointer to a CORDIC_HandleTypeDef structure that contains
0558   *         the configuration information for CORDIC module
0559   * @param  sConfig pointer to a CORDIC_ConfigTypeDef structure that
0560   *         contains the CORDIC configuration information.
0561   * @retval HAL status
0562   */
0563 HAL_StatusTypeDef HAL_CORDIC_Configure(CORDIC_HandleTypeDef *hcordic, const CORDIC_ConfigTypeDef *sConfig)
0564 {
0565   HAL_StatusTypeDef status = HAL_OK;
0566 
0567   /* Check the parameters */
0568   assert_param(IS_CORDIC_FUNCTION(sConfig->Function));
0569   assert_param(IS_CORDIC_PRECISION(sConfig->Precision));
0570   assert_param(IS_CORDIC_SCALE(sConfig->Scale));
0571   assert_param(IS_CORDIC_NBWRITE(sConfig->NbWrite));
0572   assert_param(IS_CORDIC_NBREAD(sConfig->NbRead));
0573   assert_param(IS_CORDIC_INSIZE(sConfig->InSize));
0574   assert_param(IS_CORDIC_OUTSIZE(sConfig->OutSize));
0575 
0576   /* Check handle state is ready */
0577   if (hcordic->State == HAL_CORDIC_STATE_READY)
0578   {
0579     /* Apply all configuration parameters in CORDIC control register */
0580     MODIFY_REG(hcordic->Instance->CSR,                                                         \
0581                (CORDIC_CSR_FUNC | CORDIC_CSR_PRECISION | CORDIC_CSR_SCALE |                    \
0582                 CORDIC_CSR_NARGS | CORDIC_CSR_NRES | CORDIC_CSR_ARGSIZE | CORDIC_CSR_RESSIZE), \
0583                (sConfig->Function | sConfig->Precision | sConfig->Scale |                      \
0584                 sConfig->NbWrite | sConfig->NbRead | sConfig->InSize | sConfig->OutSize));
0585   }
0586   else
0587   {
0588     /* Set CORDIC error code */
0589     hcordic->ErrorCode |= HAL_CORDIC_ERROR_NOT_READY;
0590 
0591     /* Return error status */
0592     status = HAL_ERROR;
0593   }
0594 
0595   /* Return function status */
0596   return status;
0597 }
0598 
0599 /**
0600   * @brief  Carry out data of CORDIC processing in polling mode,
0601   *         according to the existing CORDIC configuration.
0602   * @param  hcordic pointer to a CORDIC_HandleTypeDef structure that contains
0603   *         the configuration information for CORDIC module.
0604   * @param  pInBuff Pointer to buffer containing input data for CORDIC processing.
0605   * @param  pOutBuff Pointer to buffer where output data of CORDIC processing will be stored.
0606   * @param  NbCalc Number of CORDIC calculation to process.
0607   * @param  Timeout Specify Timeout value
0608   * @retval HAL status
0609   */
0610 HAL_StatusTypeDef HAL_CORDIC_Calculate(CORDIC_HandleTypeDef *hcordic, const int32_t *pInBuff, int32_t *pOutBuff,
0611                                        uint32_t NbCalc, uint32_t Timeout)
0612 {
0613   uint32_t tickstart;
0614   uint32_t index;
0615   const int32_t *p_tmp_in_buff = pInBuff;
0616   int32_t *p_tmp_out_buff = pOutBuff;
0617 
0618   /* Check parameters setting */
0619   if ((pInBuff == NULL) || (pOutBuff == NULL) || (NbCalc == 0U))
0620   {
0621     /* Update the error code */
0622     hcordic->ErrorCode |= HAL_CORDIC_ERROR_PARAM;
0623 
0624     /* Return error status */
0625     return HAL_ERROR;
0626   }
0627 
0628   /* Check handle state is ready */
0629   if (hcordic->State == HAL_CORDIC_STATE_READY)
0630   {
0631     /* Reset CORDIC error code */
0632     hcordic->ErrorCode = HAL_CORDIC_ERROR_NONE;
0633 
0634     /* Change the CORDIC state */
0635     hcordic->State = HAL_CORDIC_STATE_BUSY;
0636 
0637     /* Get tick */
0638     tickstart = HAL_GetTick();
0639 
0640     /* Write of input data in Write Data register, and increment input buffer pointer */
0641     CORDIC_WriteInDataIncrementPtr(hcordic, &p_tmp_in_buff);
0642 
0643     /* Calculation is started.
0644        Provide next set of input data, until number of calculation is achieved */
0645     for (index = (NbCalc - 1U); index > 0U; index--)
0646     {
0647       /* Write of input data in Write Data register, and increment input buffer pointer */
0648       CORDIC_WriteInDataIncrementPtr(hcordic, &p_tmp_in_buff);
0649 
0650       /* Wait for RRDY flag to be raised */
0651       do
0652       {
0653         /* Check for the Timeout */
0654         if (Timeout != HAL_MAX_DELAY)
0655         {
0656           if ((HAL_GetTick() - tickstart) > Timeout)
0657           {
0658             /* Set CORDIC error code */
0659             hcordic->ErrorCode = HAL_CORDIC_ERROR_TIMEOUT;
0660 
0661             /* Change the CORDIC state */
0662             hcordic->State = HAL_CORDIC_STATE_READY;
0663 
0664             /* Return function status */
0665             return HAL_ERROR;
0666           }
0667         }
0668       } while (HAL_IS_BIT_CLR(hcordic->Instance->CSR, CORDIC_CSR_RRDY));
0669 
0670       /* Read output data from Read Data register, and increment output buffer pointer */
0671       CORDIC_ReadOutDataIncrementPtr(hcordic, &p_tmp_out_buff);
0672     }
0673 
0674     /* Read output data from Read Data register, and increment output buffer pointer */
0675     CORDIC_ReadOutDataIncrementPtr(hcordic, &p_tmp_out_buff);
0676 
0677     /* Change the CORDIC state */
0678     hcordic->State = HAL_CORDIC_STATE_READY;
0679 
0680     /* Return function status */
0681     return HAL_OK;
0682   }
0683   else
0684   {
0685     /* Set CORDIC error code */
0686     hcordic->ErrorCode |= HAL_CORDIC_ERROR_NOT_READY;
0687 
0688     /* Return function status */
0689     return HAL_ERROR;
0690   }
0691 }
0692 
0693 /**
0694   * @brief  Carry out data of CORDIC processing in Zero-Overhead mode (output data being read
0695   *         soon as input data are written), according to the existing CORDIC configuration.
0696   * @param  hcordic pointer to a CORDIC_HandleTypeDef structure that contains
0697   *         the configuration information for CORDIC module.
0698   * @param  pInBuff Pointer to buffer containing input data for CORDIC processing.
0699   * @param  pOutBuff Pointer to buffer where output data of CORDIC processing will be stored.
0700   * @param  NbCalc Number of CORDIC calculation to process.
0701   * @param  Timeout Specify Timeout value
0702   * @retval HAL status
0703   */
0704 HAL_StatusTypeDef HAL_CORDIC_CalculateZO(CORDIC_HandleTypeDef *hcordic, const int32_t *pInBuff, int32_t *pOutBuff,
0705                                          uint32_t NbCalc, uint32_t Timeout)
0706 {
0707   uint32_t tickstart;
0708   uint32_t index;
0709   const int32_t *p_tmp_in_buff = pInBuff;
0710   int32_t *p_tmp_out_buff = pOutBuff;
0711 
0712   /* Check parameters setting */
0713   if ((pInBuff == NULL) || (pOutBuff == NULL) || (NbCalc == 0U))
0714   {
0715     /* Update the error code */
0716     hcordic->ErrorCode |= HAL_CORDIC_ERROR_PARAM;
0717 
0718     /* Return error status */
0719     return HAL_ERROR;
0720   }
0721 
0722   /* Check handle state is ready */
0723   if (hcordic->State == HAL_CORDIC_STATE_READY)
0724   {
0725     /* Reset CORDIC error code */
0726     hcordic->ErrorCode = HAL_CORDIC_ERROR_NONE;
0727 
0728     /* Change the CORDIC state */
0729     hcordic->State = HAL_CORDIC_STATE_BUSY;
0730 
0731     /* Get tick */
0732     tickstart = HAL_GetTick();
0733 
0734     /* Write of input data in Write Data register, and increment input buffer pointer */
0735     CORDIC_WriteInDataIncrementPtr(hcordic, &p_tmp_in_buff);
0736 
0737     /* Calculation is started.
0738        Provide next set of input data, until number of calculation is achieved */
0739     for (index = (NbCalc - 1U); index > 0U; index--)
0740     {
0741       /* Write of input data in Write Data register, and increment input buffer pointer */
0742       CORDIC_WriteInDataIncrementPtr(hcordic, &p_tmp_in_buff);
0743 
0744       /* Read output data from Read Data register, and increment output buffer pointer
0745          The reading is performed in Zero-Overhead mode:
0746          reading is ordered immediately without waiting result ready flag */
0747       CORDIC_ReadOutDataIncrementPtr(hcordic, &p_tmp_out_buff);
0748 
0749       /* Check for the Timeout */
0750       if (Timeout != HAL_MAX_DELAY)
0751       {
0752         if ((HAL_GetTick() - tickstart) > Timeout)
0753         {
0754           /* Set CORDIC error code */
0755           hcordic->ErrorCode = HAL_CORDIC_ERROR_TIMEOUT;
0756 
0757           /* Change the CORDIC state */
0758           hcordic->State = HAL_CORDIC_STATE_READY;
0759 
0760           /* Return function status */
0761           return HAL_ERROR;
0762         }
0763       }
0764     }
0765 
0766     /* Read output data from Read Data register, and increment output buffer pointer
0767        The reading is performed in Zero-Overhead mode:
0768        reading is ordered immediately without waiting result ready flag */
0769     CORDIC_ReadOutDataIncrementPtr(hcordic, &p_tmp_out_buff);
0770 
0771     /* Change the CORDIC state */
0772     hcordic->State = HAL_CORDIC_STATE_READY;
0773 
0774     /* Return function status */
0775     return HAL_OK;
0776   }
0777   else
0778   {
0779     /* Set CORDIC error code */
0780     hcordic->ErrorCode |= HAL_CORDIC_ERROR_NOT_READY;
0781 
0782     /* Return function status */
0783     return HAL_ERROR;
0784   }
0785 }
0786 
0787 /**
0788   * @brief  Carry out data of CORDIC processing in interrupt mode,
0789   *         according to the existing CORDIC configuration.
0790   * @param  hcordic pointer to a CORDIC_HandleTypeDef structure that contains
0791   *         the configuration information for CORDIC module.
0792   * @param  pInBuff Pointer to buffer containing input data for CORDIC processing.
0793   * @param  pOutBuff Pointer to buffer where output data of CORDIC processing will be stored.
0794   * @param  NbCalc Number of CORDIC calculation to process.
0795   * @retval HAL status
0796   */
0797 HAL_StatusTypeDef HAL_CORDIC_Calculate_IT(CORDIC_HandleTypeDef *hcordic, const int32_t *pInBuff, int32_t *pOutBuff,
0798                                           uint32_t NbCalc)
0799 {
0800   const int32_t *tmp_pInBuff = pInBuff;
0801 
0802   /* Check parameters setting */
0803   if ((pInBuff == NULL) || (pOutBuff == NULL) || (NbCalc == 0U))
0804   {
0805     /* Update the error code */
0806     hcordic->ErrorCode |= HAL_CORDIC_ERROR_PARAM;
0807 
0808     /* Return error status */
0809     return HAL_ERROR;
0810   }
0811 
0812   /* Check handle state is ready */
0813   if (hcordic->State == HAL_CORDIC_STATE_READY)
0814   {
0815     /* Reset CORDIC error code */
0816     hcordic->ErrorCode = HAL_CORDIC_ERROR_NONE;
0817 
0818     /* Change the CORDIC state */
0819     hcordic->State = HAL_CORDIC_STATE_BUSY;
0820 
0821     /* Store the buffers addresses and number of calculations in handle,
0822        provisioning initial write of input data that will be done */
0823     if (HAL_IS_BIT_SET(hcordic->Instance->CSR, CORDIC_CSR_NARGS))
0824     {
0825       /* Two writes of input data are expected */
0826       tmp_pInBuff++;
0827       tmp_pInBuff++;
0828     }
0829     else
0830     {
0831       /* One write of input data is expected */
0832       tmp_pInBuff++;
0833     }
0834     hcordic->pInBuff = tmp_pInBuff;
0835     hcordic->pOutBuff = pOutBuff;
0836     hcordic->NbCalcToOrder = NbCalc - 1U;
0837     hcordic->NbCalcToGet = NbCalc;
0838 
0839     /* Enable Result Ready Interrupt */
0840     __HAL_CORDIC_ENABLE_IT(hcordic, CORDIC_IT_IEN);
0841 
0842     /* Set back pointer to start of input data buffer */
0843     tmp_pInBuff = pInBuff;
0844 
0845     /* Initiate the processing by providing input data
0846        in the Write Data register */
0847     WRITE_REG(hcordic->Instance->WDATA, (uint32_t)*tmp_pInBuff);
0848 
0849     /* Check if second write of input data is expected */
0850     if (HAL_IS_BIT_SET(hcordic->Instance->CSR, CORDIC_CSR_NARGS))
0851     {
0852       /* Increment pointer to input data */
0853       tmp_pInBuff++;
0854 
0855       /* Perform second write of input data */
0856       WRITE_REG(hcordic->Instance->WDATA, (uint32_t)*tmp_pInBuff);
0857     }
0858 
0859     /* Return function status */
0860     return HAL_OK;
0861   }
0862   else
0863   {
0864     /* Set CORDIC error code */
0865     hcordic->ErrorCode |= HAL_CORDIC_ERROR_NOT_READY;
0866 
0867     /* Return function status */
0868     return HAL_ERROR;
0869   }
0870 }
0871 
0872 /**
0873   * @brief  Carry out input and/or output data of CORDIC processing in DMA mode,
0874   *         according to the existing CORDIC configuration.
0875   * @param  hcordic pointer to a CORDIC_HandleTypeDef structure that contains
0876   *         the configuration information for CORDIC module.
0877   * @param  pInBuff Pointer to buffer containing input data for CORDIC processing.
0878   * @param  pOutBuff Pointer to buffer where output data of CORDIC processing will be stored.
0879   * @param  NbCalc Number of CORDIC calculation to process.
0880   * @param  DMADirection Direction of DMA transfers.
0881   *         This parameter can be one of the following values:
0882   *            @arg @ref CORDIC_DMA_Direction CORDIC DMA direction
0883   * @note   pInBuff or pOutBuff is unused in case of unique DMADirection transfer, and can
0884   *         be set to NULL value in this case.
0885   * @note   pInBuff and pOutBuff buffers must be 32-bit aligned to ensure a correct
0886   *         DMA transfer to and from the Peripheral.
0887   * @retval HAL status
0888   */
0889 HAL_StatusTypeDef HAL_CORDIC_Calculate_DMA(CORDIC_HandleTypeDef *hcordic, const int32_t *pInBuff, int32_t *pOutBuff,
0890                                            uint32_t NbCalc, uint32_t DMADirection)
0891 {
0892   uint32_t sizeinbuff;
0893   uint32_t sizeoutbuff;
0894 
0895   /* Check the parameters */
0896   assert_param(IS_CORDIC_DMA_DIRECTION(DMADirection));
0897 
0898   /* Check parameters setting */
0899   if (NbCalc == 0U)
0900   {
0901     /* Update the error code */
0902     hcordic->ErrorCode |= HAL_CORDIC_ERROR_PARAM;
0903 
0904     /* Return error status */
0905     return HAL_ERROR;
0906   }
0907 
0908   /* Check if CORDIC DMA direction "Out" is requested */
0909   if ((DMADirection == CORDIC_DMA_DIR_OUT) || (DMADirection == CORDIC_DMA_DIR_IN_OUT))
0910   {
0911     /* Check parameters setting */
0912     if (pOutBuff == NULL)
0913     {
0914       /* Update the error code */
0915       hcordic->ErrorCode |= HAL_CORDIC_ERROR_PARAM;
0916 
0917       /* Return error status */
0918       return HAL_ERROR;
0919     }
0920   }
0921 
0922   /* Check if CORDIC DMA direction "In" is requested */
0923   if ((DMADirection == CORDIC_DMA_DIR_IN) || (DMADirection == CORDIC_DMA_DIR_IN_OUT))
0924   {
0925     /* Check parameters setting */
0926     if (pInBuff == NULL)
0927     {
0928       /* Update the error code */
0929       hcordic->ErrorCode |= HAL_CORDIC_ERROR_PARAM;
0930 
0931       /* Return error status */
0932       return HAL_ERROR;
0933     }
0934   }
0935 
0936   if (hcordic->State == HAL_CORDIC_STATE_READY)
0937   {
0938     /* Reset CORDIC error code */
0939     hcordic->ErrorCode = HAL_CORDIC_ERROR_NONE;
0940 
0941     /* Change the CORDIC state */
0942     hcordic->State = HAL_CORDIC_STATE_BUSY;
0943 
0944     /* Get DMA direction */
0945     hcordic->DMADirection = DMADirection;
0946 
0947     /* Check if CORDIC DMA direction "Out" is requested */
0948     if ((DMADirection == CORDIC_DMA_DIR_OUT) || (DMADirection == CORDIC_DMA_DIR_IN_OUT))
0949     {
0950       /* Set the CORDIC DMA transfer complete callback */
0951       hcordic->hdmaOut->XferCpltCallback = CORDIC_DMAOutCplt;
0952       /* Set the DMA error callback */
0953       hcordic->hdmaOut->XferErrorCallback = CORDIC_DMAError;
0954 
0955       /* Check number of output data at each calculation,
0956          to retrieve the size of output data buffer */
0957       if (HAL_IS_BIT_SET(hcordic->Instance->CSR, CORDIC_CSR_NRES))
0958       {
0959         sizeoutbuff = 2U * NbCalc;
0960       }
0961       else
0962       {
0963         sizeoutbuff = NbCalc;
0964       }
0965 
0966       /* Enable the DMA stream managing CORDIC output data read */
0967       if (HAL_DMA_Start_IT(hcordic->hdmaOut, (uint32_t)&hcordic->Instance->RDATA, (uint32_t) pOutBuff, sizeoutbuff)
0968           != HAL_OK)
0969       {
0970         /* Update the error code */
0971         hcordic->ErrorCode |= HAL_CORDIC_ERROR_DMA;
0972 
0973         /* Return error status */
0974         return HAL_ERROR;
0975       }
0976 
0977       /* Enable output data Read DMA requests */
0978       SET_BIT(hcordic->Instance->CSR, CORDIC_DMA_REN);
0979     }
0980 
0981     /* Check if CORDIC DMA direction "In" is requested */
0982     if ((DMADirection == CORDIC_DMA_DIR_IN) || (DMADirection == CORDIC_DMA_DIR_IN_OUT))
0983     {
0984       /* Set the CORDIC DMA transfer complete callback */
0985       hcordic->hdmaIn->XferCpltCallback = CORDIC_DMAInCplt;
0986       /* Set the DMA error callback */
0987       hcordic->hdmaIn->XferErrorCallback = CORDIC_DMAError;
0988 
0989       /* Check number of input data expected for each calculation,
0990          to retrieve the size of input data buffer */
0991       if (HAL_IS_BIT_SET(hcordic->Instance->CSR, CORDIC_CSR_NARGS))
0992       {
0993         sizeinbuff = 2U * NbCalc;
0994       }
0995       else
0996       {
0997         sizeinbuff = NbCalc;
0998       }
0999 
1000       /* Enable the DMA stream managing CORDIC input data write */
1001       if (HAL_DMA_Start_IT(hcordic->hdmaIn, (uint32_t) pInBuff, (uint32_t)&hcordic->Instance->WDATA, sizeinbuff)
1002           != HAL_OK)
1003       {
1004         /* Update the error code */
1005         hcordic->ErrorCode |= HAL_CORDIC_ERROR_DMA;
1006 
1007         /* Return error status */
1008         return HAL_ERROR;
1009       }
1010 
1011       /* Enable input data Write DMA request */
1012       SET_BIT(hcordic->Instance->CSR, CORDIC_DMA_WEN);
1013     }
1014 
1015     /* Return function status */
1016     return HAL_OK;
1017   }
1018   else
1019   {
1020     /* Set CORDIC error code */
1021     hcordic->ErrorCode |= HAL_CORDIC_ERROR_NOT_READY;
1022 
1023     /* Return function status */
1024     return HAL_ERROR;
1025   }
1026 }
1027 
1028 /**
1029   * @}
1030   */
1031 
1032 /** @defgroup CORDIC_Exported_Functions_Group3 Callback functions
1033   * @ingroup RTEMSBSPsARMSTM32H7
1034   *  @brief    Callback functions.
1035   *
1036 @verbatim
1037   ==============================================================================
1038                       ##### Callback functions  #####
1039   ==============================================================================
1040     [..]  This section provides Interruption and DMA callback functions:
1041       (+) DMA or Interrupt calculate complete
1042       (+) DMA or Interrupt error
1043 
1044 @endverbatim
1045   * @{
1046   */
1047 
1048 /**
1049   * @brief  CORDIC error callback.
1050   * @param  hcordic pointer to a CORDIC_HandleTypeDef structure that contains
1051   *         the configuration information for CORDIC module
1052   * @retval None
1053   */
1054 __weak void HAL_CORDIC_ErrorCallback(CORDIC_HandleTypeDef *hcordic)
1055 {
1056   /* Prevent unused argument(s) compilation warning */
1057   UNUSED(hcordic);
1058 
1059   /* NOTE : This function should not be modified; when the callback is needed,
1060             the HAL_CORDIC_ErrorCallback can be implemented in the user file
1061    */
1062 }
1063 
1064 /**
1065   * @brief  CORDIC calculate complete callback.
1066   * @param  hcordic pointer to a CORDIC_HandleTypeDef structure that contains
1067   *         the configuration information for CORDIC module
1068   * @retval None
1069   */
1070 __weak void HAL_CORDIC_CalculateCpltCallback(CORDIC_HandleTypeDef *hcordic)
1071 {
1072   /* Prevent unused argument(s) compilation warning */
1073   UNUSED(hcordic);
1074 
1075   /* NOTE : This function should not be modified; when the callback is needed,
1076             the HAL_CORDIC_CalculateCpltCallback can be implemented in the user file
1077    */
1078 }
1079 
1080 /**
1081   * @}
1082   */
1083 
1084 /** @defgroup CORDIC_Exported_Functions_Group4 IRQ handler management
1085   * @ingroup RTEMSBSPsARMSTM32H7
1086   *  @brief    IRQ handler.
1087   *
1088 @verbatim
1089   ==============================================================================
1090                 ##### IRQ handler management #####
1091   ==============================================================================
1092 [..]  This section provides IRQ handler function.
1093 
1094 @endverbatim
1095   * @{
1096   */
1097 
1098 /**
1099   * @brief  Handle CORDIC interrupt request.
1100   * @param  hcordic pointer to a CORDIC_HandleTypeDef structure that contains
1101   *         the configuration information for CORDIC module
1102   * @retval None
1103   */
1104 void HAL_CORDIC_IRQHandler(CORDIC_HandleTypeDef *hcordic)
1105 {
1106   /* Check if calculation complete interrupt is enabled and if result ready
1107      flag is raised */
1108   if (__HAL_CORDIC_GET_IT_SOURCE(hcordic, CORDIC_IT_IEN) != 0U)
1109   {
1110     if (__HAL_CORDIC_GET_FLAG(hcordic, CORDIC_FLAG_RRDY) != 0U)
1111     {
1112       /* Decrement number of calculations to get */
1113       hcordic->NbCalcToGet--;
1114 
1115       /* Read output data from Read Data register, and increment output buffer pointer */
1116       CORDIC_ReadOutDataIncrementPtr(hcordic, &(hcordic->pOutBuff));
1117 
1118       /* Check if calculations are still to be ordered */
1119       if (hcordic->NbCalcToOrder > 0U)
1120       {
1121         /* Decrement number of calculations to order */
1122         hcordic->NbCalcToOrder--;
1123 
1124         /* Continue the processing by providing another write of input data
1125            in the Write Data register, and increment input buffer pointer */
1126         CORDIC_WriteInDataIncrementPtr(hcordic, &(hcordic->pInBuff));
1127       }
1128 
1129       /* Check if all calculations results are got */
1130       if (hcordic->NbCalcToGet == 0U)
1131       {
1132         /* Disable Result Ready Interrupt */
1133         __HAL_CORDIC_DISABLE_IT(hcordic, CORDIC_IT_IEN);
1134 
1135         /* Change the CORDIC state */
1136         hcordic->State = HAL_CORDIC_STATE_READY;
1137 
1138         /* Call calculation complete callback */
1139 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
1140         /*Call registered callback*/
1141         hcordic->CalculateCpltCallback(hcordic);
1142 #else
1143         /*Call legacy weak callback*/
1144         HAL_CORDIC_CalculateCpltCallback(hcordic);
1145 #endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */
1146       }
1147     }
1148   }
1149 }
1150 
1151 /**
1152   * @}
1153   */
1154 
1155 /** @defgroup CORDIC_Exported_Functions_Group5 Peripheral State functions
1156   * @ingroup RTEMSBSPsARMSTM32H7
1157   *  @brief   Peripheral State functions.
1158   *
1159 @verbatim
1160   ==============================================================================
1161                       ##### Peripheral State functions #####
1162   ==============================================================================
1163     [..]
1164     This subsection permits to get in run-time the status of the peripheral.
1165 
1166 @endverbatim
1167   * @{
1168   */
1169 
1170 /**
1171   * @brief  Return the CORDIC handle state.
1172   * @param  hcordic pointer to a CORDIC_HandleTypeDef structure that contains
1173   *         the configuration information for CORDIC module
1174   * @retval HAL state
1175   */
1176 HAL_CORDIC_StateTypeDef HAL_CORDIC_GetState(const CORDIC_HandleTypeDef *hcordic)
1177 {
1178   /* Return CORDIC handle state */
1179   return hcordic->State;
1180 }
1181 
1182 /**
1183   * @brief  Return the CORDIC peripheral error.
1184   * @param  hcordic pointer to a CORDIC_HandleTypeDef structure that contains
1185   *         the configuration information for CORDIC module
1186   * @note   The returned error is a bit-map combination of possible errors
1187   * @retval Error bit-map
1188   */
1189 uint32_t HAL_CORDIC_GetError(const CORDIC_HandleTypeDef *hcordic)
1190 {
1191   /* Return CORDIC error code */
1192   return hcordic->ErrorCode;
1193 }
1194 
1195 /**
1196   * @}
1197   */
1198 
1199 /**
1200   * @}
1201   */
1202 
1203 /** @addtogroup CORDIC_Private_Functions
1204   * @{
1205   */
1206 
1207 /**
1208   * @brief  Write input data for CORDIC processing, and increment input buffer pointer.
1209   * @param  hcordic pointer to a CORDIC_HandleTypeDef structure that contains
1210   *         the configuration information for CORDIC module.
1211   * @param  ppInBuff Pointer to pointer to input buffer.
1212   * @retval none
1213   */
1214 static void CORDIC_WriteInDataIncrementPtr(const CORDIC_HandleTypeDef *hcordic, const int32_t **ppInBuff)
1215 {
1216   /* First write of input data in the Write Data register */
1217   WRITE_REG(hcordic->Instance->WDATA, (uint32_t) **ppInBuff);
1218 
1219   /* Increment input data pointer */
1220   (*ppInBuff)++;
1221 
1222   /* Check if second write of input data is expected */
1223   if (HAL_IS_BIT_SET(hcordic->Instance->CSR, CORDIC_CSR_NARGS))
1224   {
1225     /* Second write of input data in the Write Data register */
1226     WRITE_REG(hcordic->Instance->WDATA, (uint32_t) **ppInBuff);
1227 
1228     /* Increment input data pointer */
1229     (*ppInBuff)++;
1230   }
1231 }
1232 
1233 /**
1234   * @brief  Read output data of CORDIC processing, and increment output buffer pointer.
1235   * @param  hcordic pointer to a CORDIC_HandleTypeDef structure that contains
1236   *         the configuration information for CORDIC module.
1237   * @param  ppOutBuff Pointer to pointer to output buffer.
1238   * @retval none
1239   */
1240 static void CORDIC_ReadOutDataIncrementPtr(const CORDIC_HandleTypeDef *hcordic, int32_t **ppOutBuff)
1241 {
1242   /* First read of output data from the Read Data register */
1243   **ppOutBuff = (int32_t)READ_REG(hcordic->Instance->RDATA);
1244 
1245   /* Increment output data pointer */
1246   (*ppOutBuff)++;
1247 
1248   /* Check if second read of output data is expected */
1249   if (HAL_IS_BIT_SET(hcordic->Instance->CSR, CORDIC_CSR_NRES))
1250   {
1251     /* Second read of output data from the Read Data register */
1252     **ppOutBuff = (int32_t)READ_REG(hcordic->Instance->RDATA);
1253 
1254     /* Increment output data pointer */
1255     (*ppOutBuff)++;
1256   }
1257 }
1258 
1259 /**
1260   * @brief  DMA CORDIC Input Data process complete callback.
1261   * @param  hdma DMA handle.
1262   * @retval None
1263   */
1264 static void CORDIC_DMAInCplt(DMA_HandleTypeDef *hdma)
1265 {
1266   CORDIC_HandleTypeDef *hcordic = (CORDIC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
1267 
1268   /* Disable the DMA transfer for input request */
1269   CLEAR_BIT(hcordic->Instance->CSR, CORDIC_DMA_WEN);
1270 
1271   /* Check if DMA direction is CORDIC Input only (no DMA for CORDIC Output) */
1272   if (hcordic->DMADirection == CORDIC_DMA_DIR_IN)
1273   {
1274     /* Change the CORDIC DMA direction to none */
1275     hcordic->DMADirection = CORDIC_DMA_DIR_NONE;
1276 
1277     /* Change the CORDIC state to ready */
1278     hcordic->State = HAL_CORDIC_STATE_READY;
1279 
1280     /* Call calculation complete callback */
1281 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
1282     /*Call registered callback*/
1283     hcordic->CalculateCpltCallback(hcordic);
1284 #else
1285     /*Call legacy weak callback*/
1286     HAL_CORDIC_CalculateCpltCallback(hcordic);
1287 #endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */
1288   }
1289 }
1290 
1291 /**
1292   * @brief  DMA CORDIC Output Data process complete callback.
1293   * @param  hdma DMA handle.
1294   * @retval None
1295   */
1296 static void CORDIC_DMAOutCplt(DMA_HandleTypeDef *hdma)
1297 {
1298   CORDIC_HandleTypeDef *hcordic = (CORDIC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
1299 
1300   /* Disable the DMA transfer for output request */
1301   CLEAR_BIT(hcordic->Instance->CSR, CORDIC_DMA_REN);
1302 
1303   /* Change the CORDIC DMA direction to none */
1304   hcordic->DMADirection = CORDIC_DMA_DIR_NONE;
1305 
1306   /* Change the CORDIC state to ready */
1307   hcordic->State = HAL_CORDIC_STATE_READY;
1308 
1309   /* Call calculation complete callback */
1310 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
1311   /*Call registered callback*/
1312   hcordic->CalculateCpltCallback(hcordic);
1313 #else
1314   /*Call legacy weak callback*/
1315   HAL_CORDIC_CalculateCpltCallback(hcordic);
1316 #endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */
1317 }
1318 
1319 /**
1320   * @brief  DMA CORDIC communication error callback.
1321   * @param  hdma DMA handle.
1322   * @retval None
1323   */
1324 static void CORDIC_DMAError(DMA_HandleTypeDef *hdma)
1325 {
1326   CORDIC_HandleTypeDef *hcordic = (CORDIC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
1327 
1328   /* Set CORDIC handle state to error */
1329   hcordic->State = HAL_CORDIC_STATE_READY;
1330 
1331   /* Set CORDIC handle error code to DMA error */
1332   hcordic->ErrorCode |= HAL_CORDIC_ERROR_DMA;
1333 
1334   /* Call user callback */
1335 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
1336   /*Call registered callback*/
1337   hcordic->ErrorCallback(hcordic);
1338 #else
1339   /*Call legacy weak callback*/
1340   HAL_CORDIC_ErrorCallback(hcordic);
1341 #endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */
1342 }
1343 
1344 /**
1345   * @}
1346   */
1347 
1348 /**
1349   * @}
1350   */
1351 
1352 /**
1353   * @}
1354   */
1355 
1356 #endif /* HAL_CORDIC_MODULE_ENABLED */
1357 #endif /* CORDIC */