STM32H735xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32h7xx_hal_cordic.c 00004 * @author MCD Application Team 00005 * @brief CORDIC HAL module driver. 00006 * This file provides firmware functions to manage the following 00007 * functionalities of the CORDIC peripheral: 00008 * + Initialization and de-initialization functions 00009 * + Peripheral Control functions 00010 * + Callback functions 00011 * + IRQ handler management 00012 * + Peripheral State 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 The CORDIC HAL driver can be used as follows: 00031 00032 (#) Initialize the CORDIC low level resources by implementing the HAL_CORDIC_MspInit(): 00033 (++) Enable the CORDIC interface clock using __HAL_RCC_CORDIC_CLK_ENABLE() 00034 (++) In case of using interrupts (e.g. HAL_CORDIC_Calculate_IT()) 00035 (+++) Configure the CORDIC interrupt priority using HAL_NVIC_SetPriority() 00036 (+++) Enable the CORDIC IRQ handler using HAL_NVIC_EnableIRQ() 00037 (+++) In CORDIC IRQ handler, call HAL_CORDIC_IRQHandler() 00038 (++) In case of using DMA to control data transfer (e.g. HAL_CORDIC_Calculate_DMA()) 00039 (+++) Enable the DMA2 interface clock using 00040 __HAL_RCC_DMA2_CLK_ENABLE() 00041 (+++) Configure and enable two DMA channels one for managing data transfer from 00042 memory to peripheral (input channel) and another channel for managing data 00043 transfer from peripheral to memory (output channel) 00044 (+++) Associate the initialized DMA handle to the CORDIC DMA handle 00045 using __HAL_LINKDMA() 00046 (+++) Configure the priority and enable the NVIC for the transfer complete 00047 interrupt on the two DMA channels. 00048 Resort to HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ() 00049 00050 (#) Initialize the CORDIC HAL using HAL_CORDIC_Init(). This function 00051 (++) resorts to HAL_CORDIC_MspInit() for low-level initialization, 00052 00053 (#) Configure CORDIC processing (calculation) using HAL_CORDIC_Configure(). 00054 This function configures: 00055 (++) Processing functions: Cosine, Sine, Phase, Modulus, Arctangent, 00056 Hyperbolic cosine, Hyperbolic sine, Hyperbolic arctangent, 00057 Natural log, Square root 00058 (++) Scaling factor: 1 to 2exp(-7) 00059 (++) Width of input data: 32 bits input data size (Q1.31 format) or 16 bits 00060 input data size (Q1.15 format) 00061 (++) Width of output data: 32 bits output data size (Q1.31 format) or 16 bits 00062 output data size (Q1.15 format) 00063 (++) Number of 32-bit write expected for one calculation: One 32-bits write 00064 or Two 32-bit write 00065 (++) Number of 32-bit read expected after one calculation: One 32-bits read 00066 or Two 32-bit read 00067 (++) Precision: 1 to 15 cycles for calculation (the more cycles, the better precision) 00068 00069 (#) Four processing (calculation) functions are available: 00070 (++) Polling mode: processing API is blocking function 00071 i.e. it processes the data and wait till the processing is finished 00072 API is HAL_CORDIC_Calculate 00073 (++) Polling Zero-overhead mode: processing API is blocking function 00074 i.e. it processes the data and wait till the processing is finished 00075 A bit faster than standard polling mode, but blocking also AHB bus 00076 API is HAL_CORDIC_CalculateZO 00077 (++) Interrupt mode: processing API is not blocking functions 00078 i.e. it processes the data under interrupt 00079 API is HAL_CORDIC_Calculate_IT 00080 (++) DMA mode: processing API is not blocking functions and the CPU is 00081 not used for data transfer, 00082 i.e. the data transfer is ensured by DMA 00083 API is HAL_CORDIC_Calculate_DMA 00084 00085 (#) Call HAL_CORDIC_DeInit() to de-initialize the CORDIC peripheral. This function 00086 (++) resorts to HAL_CORDIC_MspDeInit() for low-level de-initialization, 00087 00088 *** Callback registration *** 00089 ============================================= 00090 00091 The compilation define USE_HAL_CORDIC_REGISTER_CALLBACKS when set to 1 00092 allows the user to configure dynamically the driver callbacks. 00093 Use Function HAL_CORDIC_RegisterCallback() to register an interrupt callback. 00094 00095 Function HAL_CORDIC_RegisterCallback() allows to register following callbacks: 00096 (+) ErrorCallback : Error Callback. 00097 (+) CalculateCpltCallback : Calculate complete Callback. 00098 (+) MspInitCallback : CORDIC MspInit. 00099 (+) MspDeInitCallback : CORDIC MspDeInit. 00100 This function takes as parameters the HAL peripheral handle, the Callback ID 00101 and a pointer to the user callback function. 00102 00103 Use function HAL_CORDIC_UnRegisterCallback() to reset a callback to the default 00104 weak function. 00105 HAL_CORDIC_UnRegisterCallback takes as parameters the HAL peripheral handle, 00106 and the Callback ID. 00107 This function allows to reset following callbacks: 00108 (+) ErrorCallback : Error Callback. 00109 (+) CalculateCpltCallback : Calculate complete Callback. 00110 (+) MspInitCallback : CORDIC MspInit. 00111 (+) MspDeInitCallback : CORDIC MspDeInit. 00112 00113 By default, after the HAL_CORDIC_Init() and when the state is HAL_CORDIC_STATE_RESET, 00114 all callbacks are set to the corresponding weak functions: 00115 examples HAL_CORDIC_ErrorCallback(), HAL_CORDIC_CalculateCpltCallback(). 00116 Exception done for MspInit and MspDeInit functions that are 00117 reset to the legacy weak function in the HAL_CORDIC_Init()/ HAL_CORDIC_DeInit() only when 00118 these callbacks are null (not registered beforehand). 00119 if not, MspInit or MspDeInit are not null, the HAL_CORDIC_Init()/ HAL_CORDIC_DeInit() 00120 keep and use the user MspInit/MspDeInit callbacks (registered beforehand) 00121 00122 Callbacks can be registered/unregistered in HAL_CORDIC_STATE_READY state only. 00123 Exception done MspInit/MspDeInit that can be registered/unregistered 00124 in HAL_CORDIC_STATE_READY or HAL_CORDIC_STATE_RESET state, 00125 thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit. 00126 In that case first register the MspInit/MspDeInit user callbacks 00127 using HAL_CORDIC_RegisterCallback() before calling HAL_CORDIC_DeInit() 00128 or HAL_CORDIC_Init() function. 00129 00130 When The compilation define USE_HAL_CORDIC_REGISTER_CALLBACKS is set to 0 or 00131 not defined, the callback registration feature is not available and all callbacks 00132 are set to the corresponding weak functions. 00133 00134 @endverbatim 00135 ****************************************************************************** 00136 */ 00137 00138 /* Includes ------------------------------------------------------------------*/ 00139 #include "stm32h7xx_hal.h" 00140 00141 #if defined(CORDIC) 00142 #ifdef HAL_CORDIC_MODULE_ENABLED 00143 00144 /** @addtogroup STM32H7xx_HAL_Driver 00145 * @{ 00146 */ 00147 00148 /** @defgroup CORDIC CORDIC 00149 * @brief CORDIC HAL driver modules. 00150 * @{ 00151 */ 00152 00153 /* Private typedef -----------------------------------------------------------*/ 00154 /* Private define ------------------------------------------------------------*/ 00155 /* Private macro -------------------------------------------------------------*/ 00156 /* Private variables ---------------------------------------------------------*/ 00157 /* Private function prototypes -----------------------------------------------*/ 00158 00159 /** @defgroup CORDIC_Private_Functions CORDIC Private Functions 00160 * @{ 00161 */ 00162 static void CORDIC_WriteInDataIncrementPtr(CORDIC_HandleTypeDef *hcordic, int32_t **ppInBuff); 00163 static void CORDIC_ReadOutDataIncrementPtr(CORDIC_HandleTypeDef *hcordic, int32_t **ppOutBuff); 00164 static void CORDIC_DMAInCplt(DMA_HandleTypeDef *hdma); 00165 static void CORDIC_DMAOutCplt(DMA_HandleTypeDef *hdma); 00166 static void CORDIC_DMAError(DMA_HandleTypeDef *hdma); 00167 /** 00168 * @} 00169 */ 00170 00171 /* Exported functions --------------------------------------------------------*/ 00172 00173 /** @defgroup CORDIC_Exported_Functions CORDIC Exported Functions 00174 * @{ 00175 */ 00176 00177 /** @defgroup CORDIC_Exported_Functions_Group1 Initialization and de-initialization functions 00178 * @brief Initialization and Configuration functions. 00179 * 00180 @verbatim 00181 ============================================================================== 00182 ##### Initialization and de-initialization functions ##### 00183 ============================================================================== 00184 [..] This section provides functions allowing to: 00185 (+) Initialize the CORDIC peripheral and the associated handle 00186 (+) DeInitialize the CORDIC peripheral 00187 (+) Initialize the CORDIC MSP (MCU Specific Package) 00188 (+) De-Initialize the CORDIC MSP 00189 00190 [..] 00191 00192 @endverbatim 00193 * @{ 00194 */ 00195 00196 /** 00197 * @brief Initialize the CORDIC peripheral and the associated handle. 00198 * @param hcordic pointer to a CORDIC_HandleTypeDef structure. 00199 * @retval HAL status 00200 */ 00201 HAL_StatusTypeDef HAL_CORDIC_Init(CORDIC_HandleTypeDef *hcordic) 00202 { 00203 /* Check the CORDIC handle allocation */ 00204 if (hcordic == NULL) 00205 { 00206 /* Return error status */ 00207 return HAL_ERROR; 00208 } 00209 00210 /* Check the instance */ 00211 assert_param(IS_CORDIC_ALL_INSTANCE(hcordic->Instance)); 00212 00213 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1 00214 if (hcordic->State == HAL_CORDIC_STATE_RESET) 00215 { 00216 /* Allocate lock resource and initialize it */ 00217 hcordic->Lock = HAL_UNLOCKED; 00218 00219 /* Reset callbacks to legacy functions */ 00220 hcordic->ErrorCallback = HAL_CORDIC_ErrorCallback; /* Legacy weak ErrorCallback */ 00221 hcordic->CalculateCpltCallback = HAL_CORDIC_CalculateCpltCallback; /* Legacy weak CalculateCpltCallback */ 00222 00223 if (hcordic->MspInitCallback == NULL) 00224 { 00225 hcordic->MspInitCallback = HAL_CORDIC_MspInit; /* Legacy weak MspInit */ 00226 } 00227 00228 /* Initialize the low level hardware */ 00229 hcordic->MspInitCallback(hcordic); 00230 } 00231 #else 00232 if (hcordic->State == HAL_CORDIC_STATE_RESET) 00233 { 00234 /* Allocate lock resource and initialize it */ 00235 hcordic->Lock = HAL_UNLOCKED; 00236 00237 /* Initialize the low level hardware */ 00238 HAL_CORDIC_MspInit(hcordic); 00239 } 00240 #endif /* (USE_HAL_CORDIC_REGISTER_CALLBACKS) */ 00241 00242 /* Set CORDIC error code to none */ 00243 hcordic->ErrorCode = HAL_CORDIC_ERROR_NONE; 00244 00245 /* Reset pInBuff and pOutBuff */ 00246 hcordic->pInBuff = NULL; 00247 hcordic->pOutBuff = NULL; 00248 00249 /* Reset NbCalcToOrder and NbCalcToGet */ 00250 hcordic->NbCalcToOrder = 0U; 00251 hcordic->NbCalcToGet = 0U; 00252 00253 /* Reset DMADirection */ 00254 hcordic->DMADirection = CORDIC_DMA_DIR_NONE; 00255 00256 /* Change CORDIC peripheral state */ 00257 hcordic->State = HAL_CORDIC_STATE_READY; 00258 00259 /* Return function status */ 00260 return HAL_OK; 00261 } 00262 00263 /** 00264 * @brief DeInitialize the CORDIC peripheral. 00265 * @param hcordic pointer to a CORDIC_HandleTypeDef structure. 00266 * @retval HAL status 00267 */ 00268 HAL_StatusTypeDef HAL_CORDIC_DeInit(CORDIC_HandleTypeDef *hcordic) 00269 { 00270 /* Check the CORDIC handle allocation */ 00271 if (hcordic == NULL) 00272 { 00273 /* Return error status */ 00274 return HAL_ERROR; 00275 } 00276 00277 /* Check the parameters */ 00278 assert_param(IS_CORDIC_ALL_INSTANCE(hcordic->Instance)); 00279 00280 /* Change CORDIC peripheral state */ 00281 hcordic->State = HAL_CORDIC_STATE_BUSY; 00282 00283 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1 00284 if (hcordic->MspDeInitCallback == NULL) 00285 { 00286 hcordic->MspDeInitCallback = HAL_CORDIC_MspDeInit; 00287 } 00288 00289 /* De-Initialize the low level hardware */ 00290 hcordic->MspDeInitCallback(hcordic); 00291 #else 00292 /* De-Initialize the low level hardware: CLOCK, NVIC, DMA */ 00293 HAL_CORDIC_MspDeInit(hcordic); 00294 #endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */ 00295 00296 /* Set CORDIC error code to none */ 00297 hcordic->ErrorCode = HAL_CORDIC_ERROR_NONE; 00298 00299 /* Reset pInBuff and pOutBuff */ 00300 hcordic->pInBuff = NULL; 00301 hcordic->pOutBuff = NULL; 00302 00303 /* Reset NbCalcToOrder and NbCalcToGet */ 00304 hcordic->NbCalcToOrder = 0U; 00305 hcordic->NbCalcToGet = 0U; 00306 00307 /* Reset DMADirection */ 00308 hcordic->DMADirection = CORDIC_DMA_DIR_NONE; 00309 00310 /* Change CORDIC peripheral state */ 00311 hcordic->State = HAL_CORDIC_STATE_RESET; 00312 00313 /* Reset Lock */ 00314 hcordic->Lock = HAL_UNLOCKED; 00315 00316 /* Return function status */ 00317 return HAL_OK; 00318 } 00319 00320 /** 00321 * @brief Initialize the CORDIC MSP. 00322 * @param hcordic CORDIC handle 00323 * @retval None 00324 */ 00325 __weak void HAL_CORDIC_MspInit(CORDIC_HandleTypeDef *hcordic) 00326 { 00327 /* Prevent unused argument(s) compilation warning */ 00328 UNUSED(hcordic); 00329 00330 /* NOTE : This function should not be modified, when the callback is needed, 00331 the HAL_CORDIC_MspInit can be implemented in the user file 00332 */ 00333 } 00334 00335 /** 00336 * @brief DeInitialize the CORDIC MSP. 00337 * @param hcordic CORDIC handle 00338 * @retval None 00339 */ 00340 __weak void HAL_CORDIC_MspDeInit(CORDIC_HandleTypeDef *hcordic) 00341 { 00342 /* Prevent unused argument(s) compilation warning */ 00343 UNUSED(hcordic); 00344 00345 /* NOTE : This function should not be modified, when the callback is needed, 00346 the HAL_CORDIC_MspDeInit can be implemented in the user file 00347 */ 00348 } 00349 00350 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1 00351 /** 00352 * @brief Register a CORDIC CallBack. 00353 * To be used instead of the weak predefined callback. 00354 * @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains 00355 * the configuration information for CORDIC module 00356 * @param CallbackID ID of the callback to be registered 00357 * This parameter can be one of the following values: 00358 * @arg @ref HAL_CORDIC_ERROR_CB_ID error Callback ID 00359 * @arg @ref HAL_CORDIC_CALCULATE_CPLT_CB_ID calculate complete Callback ID 00360 * @arg @ref HAL_CORDIC_MSPINIT_CB_ID MspInit callback ID 00361 * @arg @ref HAL_CORDIC_MSPDEINIT_CB_ID MspDeInit callback ID 00362 * @param pCallback pointer to the Callback function 00363 * @retval HAL status 00364 */ 00365 HAL_StatusTypeDef HAL_CORDIC_RegisterCallback(CORDIC_HandleTypeDef *hcordic, HAL_CORDIC_CallbackIDTypeDef CallbackID, 00366 void (* pCallback)(CORDIC_HandleTypeDef *_hcordic)) 00367 { 00368 HAL_StatusTypeDef status = HAL_OK; 00369 00370 if (pCallback == NULL) 00371 { 00372 /* Update the error code */ 00373 hcordic->ErrorCode |= HAL_CORDIC_ERROR_INVALID_CALLBACK; 00374 00375 /* Return error status */ 00376 return HAL_ERROR; 00377 } 00378 00379 if (hcordic->State == HAL_CORDIC_STATE_READY) 00380 { 00381 switch (CallbackID) 00382 { 00383 case HAL_CORDIC_ERROR_CB_ID : 00384 hcordic->ErrorCallback = pCallback; 00385 break; 00386 00387 case HAL_CORDIC_CALCULATE_CPLT_CB_ID : 00388 hcordic->CalculateCpltCallback = pCallback; 00389 break; 00390 00391 case HAL_CORDIC_MSPINIT_CB_ID : 00392 hcordic->MspInitCallback = pCallback; 00393 break; 00394 00395 case HAL_CORDIC_MSPDEINIT_CB_ID : 00396 hcordic->MspDeInitCallback = pCallback; 00397 break; 00398 00399 default : 00400 /* Update the error code */ 00401 hcordic->ErrorCode |= HAL_CORDIC_ERROR_INVALID_CALLBACK; 00402 00403 /* Return error status */ 00404 status = HAL_ERROR; 00405 break; 00406 } 00407 } 00408 else if (hcordic->State == HAL_CORDIC_STATE_RESET) 00409 { 00410 switch (CallbackID) 00411 { 00412 case HAL_CORDIC_MSPINIT_CB_ID : 00413 hcordic->MspInitCallback = pCallback; 00414 break; 00415 00416 case HAL_CORDIC_MSPDEINIT_CB_ID : 00417 hcordic->MspDeInitCallback = pCallback; 00418 break; 00419 00420 default : 00421 /* Update the error code */ 00422 hcordic->ErrorCode |= HAL_CORDIC_ERROR_INVALID_CALLBACK; 00423 00424 /* Return error status */ 00425 status = HAL_ERROR; 00426 break; 00427 } 00428 } 00429 else 00430 { 00431 /* Update the error code */ 00432 hcordic->ErrorCode |= HAL_CORDIC_ERROR_INVALID_CALLBACK; 00433 00434 /* Return error status */ 00435 status = HAL_ERROR; 00436 } 00437 00438 return status; 00439 } 00440 #endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */ 00441 00442 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1 00443 /** 00444 * @brief Unregister a CORDIC CallBack. 00445 * CORDIC callback is redirected to the weak predefined callback. 00446 * @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains 00447 * the configuration information for CORDIC module 00448 * @param CallbackID ID of the callback to be unregistered 00449 * This parameter can be one of the following values: 00450 * @arg @ref HAL_CORDIC_ERROR_CB_ID error Callback ID 00451 * @arg @ref HAL_CORDIC_CALCULATE_CPLT_CB_ID calculate complete Callback ID 00452 * @arg @ref HAL_CORDIC_MSPINIT_CB_ID MspInit callback ID 00453 * @arg @ref HAL_CORDIC_MSPDEINIT_CB_ID MspDeInit callback ID 00454 * @retval HAL status 00455 */ 00456 HAL_StatusTypeDef HAL_CORDIC_UnRegisterCallback(CORDIC_HandleTypeDef *hcordic, HAL_CORDIC_CallbackIDTypeDef CallbackID) 00457 { 00458 HAL_StatusTypeDef status = HAL_OK; 00459 00460 if (hcordic->State == HAL_CORDIC_STATE_READY) 00461 { 00462 switch (CallbackID) 00463 { 00464 case HAL_CORDIC_ERROR_CB_ID : 00465 hcordic->ErrorCallback = HAL_CORDIC_ErrorCallback; 00466 break; 00467 00468 case HAL_CORDIC_CALCULATE_CPLT_CB_ID : 00469 hcordic->CalculateCpltCallback = HAL_CORDIC_CalculateCpltCallback; 00470 break; 00471 00472 case HAL_CORDIC_MSPINIT_CB_ID : 00473 hcordic->MspInitCallback = HAL_CORDIC_MspInit; 00474 break; 00475 00476 case HAL_CORDIC_MSPDEINIT_CB_ID : 00477 hcordic->MspDeInitCallback = HAL_CORDIC_MspDeInit; 00478 break; 00479 00480 default : 00481 /* Update the error code */ 00482 hcordic->ErrorCode |= HAL_CORDIC_ERROR_INVALID_CALLBACK; 00483 00484 /* Return error status */ 00485 status = HAL_ERROR; 00486 break; 00487 } 00488 } 00489 else if (hcordic->State == HAL_CORDIC_STATE_RESET) 00490 { 00491 switch (CallbackID) 00492 { 00493 case HAL_CORDIC_MSPINIT_CB_ID : 00494 hcordic->MspInitCallback = HAL_CORDIC_MspInit; 00495 break; 00496 00497 case HAL_CORDIC_MSPDEINIT_CB_ID : 00498 hcordic->MspDeInitCallback = HAL_CORDIC_MspDeInit; 00499 break; 00500 00501 default : 00502 /* Update the error code */ 00503 hcordic->ErrorCode |= HAL_CORDIC_ERROR_INVALID_CALLBACK; 00504 00505 /* Return error status */ 00506 status = HAL_ERROR; 00507 break; 00508 } 00509 } 00510 else 00511 { 00512 /* Update the error code */ 00513 hcordic->ErrorCode |= HAL_CORDIC_ERROR_INVALID_CALLBACK; 00514 00515 /* Return error status */ 00516 status = HAL_ERROR; 00517 } 00518 00519 return status; 00520 } 00521 #endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */ 00522 00523 /** 00524 * @} 00525 */ 00526 00527 /** @defgroup CORDIC_Exported_Functions_Group2 Peripheral Control functions 00528 * @brief Control functions. 00529 * 00530 @verbatim 00531 ============================================================================== 00532 ##### Peripheral Control functions ##### 00533 ============================================================================== 00534 [..] This section provides functions allowing to: 00535 (+) Configure the CORDIC peripheral: function, precision, scaling factor, 00536 number of input data and output data, size of input data and output data. 00537 (+) Calculate output data of CORDIC processing on input date, using the 00538 existing CORDIC configuration 00539 [..] Four processing functions are available for calculation: 00540 (+) Polling mode 00541 (+) Polling mode, with Zero-Overhead register access 00542 (+) Interrupt mode 00543 (+) DMA mode 00544 00545 @endverbatim 00546 * @{ 00547 */ 00548 00549 /** 00550 * @brief Configure the CORDIC processing according to the specified 00551 parameters in the CORDIC_ConfigTypeDef structure. 00552 * @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains 00553 * the configuration information for CORDIC module 00554 * @param sConfig pointer to a CORDIC_ConfigTypeDef structure that 00555 * contains the CORDIC configuration information. 00556 * @retval HAL status 00557 */ 00558 HAL_StatusTypeDef HAL_CORDIC_Configure(CORDIC_HandleTypeDef *hcordic, CORDIC_ConfigTypeDef *sConfig) 00559 { 00560 HAL_StatusTypeDef status = HAL_OK; 00561 00562 /* Check the parameters */ 00563 assert_param(IS_CORDIC_FUNCTION(sConfig->Function)); 00564 assert_param(IS_CORDIC_PRECISION(sConfig->Precision)); 00565 assert_param(IS_CORDIC_SCALE(sConfig->Scale)); 00566 assert_param(IS_CORDIC_NBWRITE(sConfig->NbWrite)); 00567 assert_param(IS_CORDIC_NBREAD(sConfig->NbRead)); 00568 assert_param(IS_CORDIC_INSIZE(sConfig->InSize)); 00569 assert_param(IS_CORDIC_OUTSIZE(sConfig->OutSize)); 00570 00571 /* Check handle state is ready */ 00572 if (hcordic->State == HAL_CORDIC_STATE_READY) 00573 { 00574 /* Apply all configuration parameters in CORDIC control register */ 00575 MODIFY_REG(hcordic->Instance->CSR, \ 00576 (CORDIC_CSR_FUNC | CORDIC_CSR_PRECISION | CORDIC_CSR_SCALE | \ 00577 CORDIC_CSR_NARGS | CORDIC_CSR_NRES | CORDIC_CSR_ARGSIZE | CORDIC_CSR_RESSIZE), \ 00578 (sConfig->Function | sConfig->Precision | sConfig->Scale | \ 00579 sConfig->NbWrite | sConfig->NbRead | sConfig->InSize | sConfig->OutSize)); 00580 } 00581 else 00582 { 00583 /* Set CORDIC error code */ 00584 hcordic->ErrorCode |= HAL_CORDIC_ERROR_NOT_READY; 00585 00586 /* Return error status */ 00587 status = HAL_ERROR; 00588 } 00589 00590 /* Return function status */ 00591 return status; 00592 } 00593 00594 /** 00595 * @brief Carry out data of CORDIC processing in polling mode, 00596 * according to the existing CORDIC configuration. 00597 * @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains 00598 * the configuration information for CORDIC module. 00599 * @param pInBuff Pointer to buffer containing input data for CORDIC processing. 00600 * @param pOutBuff Pointer to buffer where output data of CORDIC processing will be stored. 00601 * @param NbCalc Number of CORDIC calculation to process. 00602 * @param Timeout Specify Timeout value 00603 * @retval HAL status 00604 */ 00605 HAL_StatusTypeDef HAL_CORDIC_Calculate(CORDIC_HandleTypeDef *hcordic, int32_t *pInBuff, int32_t *pOutBuff, 00606 uint32_t NbCalc, uint32_t Timeout) 00607 { 00608 uint32_t tickstart; 00609 uint32_t index; 00610 int32_t *p_tmp_in_buff = pInBuff; 00611 int32_t *p_tmp_out_buff = pOutBuff; 00612 00613 /* Check parameters setting */ 00614 if ((pInBuff == NULL) || (pOutBuff == NULL) || (NbCalc == 0U)) 00615 { 00616 /* Update the error code */ 00617 hcordic->ErrorCode |= HAL_CORDIC_ERROR_PARAM; 00618 00619 /* Return error status */ 00620 return HAL_ERROR; 00621 } 00622 00623 /* Check handle state is ready */ 00624 if (hcordic->State == HAL_CORDIC_STATE_READY) 00625 { 00626 /* Reset CORDIC error code */ 00627 hcordic->ErrorCode = HAL_CORDIC_ERROR_NONE; 00628 00629 /* Change the CORDIC state */ 00630 hcordic->State = HAL_CORDIC_STATE_BUSY; 00631 00632 /* Get tick */ 00633 tickstart = HAL_GetTick(); 00634 00635 /* Write of input data in Write Data register, and increment input buffer pointer */ 00636 CORDIC_WriteInDataIncrementPtr(hcordic, &p_tmp_in_buff); 00637 00638 /* Calculation is started. 00639 Provide next set of input data, until number of calculation is achieved */ 00640 for (index = (NbCalc - 1U); index > 0U; index--) 00641 { 00642 /* Write of input data in Write Data register, and increment input buffer pointer */ 00643 CORDIC_WriteInDataIncrementPtr(hcordic, &p_tmp_in_buff); 00644 00645 /* Wait for RRDY flag to be raised */ 00646 do 00647 { 00648 /* Check for the Timeout */ 00649 if (Timeout != HAL_MAX_DELAY) 00650 { 00651 if ((HAL_GetTick() - tickstart) > Timeout) 00652 { 00653 /* Set CORDIC error code */ 00654 hcordic->ErrorCode = HAL_CORDIC_ERROR_TIMEOUT; 00655 00656 /* Change the CORDIC state */ 00657 hcordic->State = HAL_CORDIC_STATE_READY; 00658 00659 /* Return function status */ 00660 return HAL_ERROR; 00661 } 00662 } 00663 } while (HAL_IS_BIT_CLR(hcordic->Instance->CSR, CORDIC_CSR_RRDY)); 00664 00665 /* Read output data from Read Data register, and increment output buffer pointer */ 00666 CORDIC_ReadOutDataIncrementPtr(hcordic, &p_tmp_out_buff); 00667 } 00668 00669 /* Read output data from Read Data register, and increment output buffer pointer */ 00670 CORDIC_ReadOutDataIncrementPtr(hcordic, &p_tmp_out_buff); 00671 00672 /* Change the CORDIC state */ 00673 hcordic->State = HAL_CORDIC_STATE_READY; 00674 00675 /* Return function status */ 00676 return HAL_OK; 00677 } 00678 else 00679 { 00680 /* Set CORDIC error code */ 00681 hcordic->ErrorCode |= HAL_CORDIC_ERROR_NOT_READY; 00682 00683 /* Return function status */ 00684 return HAL_ERROR; 00685 } 00686 } 00687 00688 /** 00689 * @brief Carry out data of CORDIC processing in Zero-Overhead mode (output data being read 00690 * soon as input data are written), according to the existing CORDIC configuration. 00691 * @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains 00692 * the configuration information for CORDIC module. 00693 * @param pInBuff Pointer to buffer containing input data for CORDIC processing. 00694 * @param pOutBuff Pointer to buffer where output data of CORDIC processing will be stored. 00695 * @param NbCalc Number of CORDIC calculation to process. 00696 * @param Timeout Specify Timeout value 00697 * @retval HAL status 00698 */ 00699 HAL_StatusTypeDef HAL_CORDIC_CalculateZO(CORDIC_HandleTypeDef *hcordic, int32_t *pInBuff, int32_t *pOutBuff, 00700 uint32_t NbCalc, uint32_t Timeout) 00701 { 00702 uint32_t tickstart; 00703 uint32_t index; 00704 int32_t *p_tmp_in_buff = pInBuff; 00705 int32_t *p_tmp_out_buff = pOutBuff; 00706 00707 /* Check parameters setting */ 00708 if ((pInBuff == NULL) || (pOutBuff == NULL) || (NbCalc == 0U)) 00709 { 00710 /* Update the error code */ 00711 hcordic->ErrorCode |= HAL_CORDIC_ERROR_PARAM; 00712 00713 /* Return error status */ 00714 return HAL_ERROR; 00715 } 00716 00717 /* Check handle state is ready */ 00718 if (hcordic->State == HAL_CORDIC_STATE_READY) 00719 { 00720 /* Reset CORDIC error code */ 00721 hcordic->ErrorCode = HAL_CORDIC_ERROR_NONE; 00722 00723 /* Change the CORDIC state */ 00724 hcordic->State = HAL_CORDIC_STATE_BUSY; 00725 00726 /* Get tick */ 00727 tickstart = HAL_GetTick(); 00728 00729 /* Write of input data in Write Data register, and increment input buffer pointer */ 00730 CORDIC_WriteInDataIncrementPtr(hcordic, &p_tmp_in_buff); 00731 00732 /* Calculation is started. 00733 Provide next set of input data, until number of calculation is achieved */ 00734 for (index = (NbCalc - 1U); index > 0U; index--) 00735 { 00736 /* Write of input data in Write Data register, and increment input buffer pointer */ 00737 CORDIC_WriteInDataIncrementPtr(hcordic, &p_tmp_in_buff); 00738 00739 /* Read output data from Read Data register, and increment output buffer pointer 00740 The reading is performed in Zero-Overhead mode: 00741 reading is ordered immediately without waiting result ready flag */ 00742 CORDIC_ReadOutDataIncrementPtr(hcordic, &p_tmp_out_buff); 00743 00744 /* Check for the Timeout */ 00745 if (Timeout != HAL_MAX_DELAY) 00746 { 00747 if ((HAL_GetTick() - tickstart) > Timeout) 00748 { 00749 /* Set CORDIC error code */ 00750 hcordic->ErrorCode = HAL_CORDIC_ERROR_TIMEOUT; 00751 00752 /* Change the CORDIC state */ 00753 hcordic->State = HAL_CORDIC_STATE_READY; 00754 00755 /* Return function status */ 00756 return HAL_ERROR; 00757 } 00758 } 00759 } 00760 00761 /* Read output data from Read Data register, and increment output buffer pointer 00762 The reading is performed in Zero-Overhead mode: 00763 reading is ordered immediately without waiting result ready flag */ 00764 CORDIC_ReadOutDataIncrementPtr(hcordic, &p_tmp_out_buff); 00765 00766 /* Change the CORDIC state */ 00767 hcordic->State = HAL_CORDIC_STATE_READY; 00768 00769 /* Return function status */ 00770 return HAL_OK; 00771 } 00772 else 00773 { 00774 /* Set CORDIC error code */ 00775 hcordic->ErrorCode |= HAL_CORDIC_ERROR_NOT_READY; 00776 00777 /* Return function status */ 00778 return HAL_ERROR; 00779 } 00780 } 00781 00782 /** 00783 * @brief Carry out data of CORDIC processing in interrupt mode, 00784 * according to the existing CORDIC configuration. 00785 * @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains 00786 * the configuration information for CORDIC module. 00787 * @param pInBuff Pointer to buffer containing input data for CORDIC processing. 00788 * @param pOutBuff Pointer to buffer where output data of CORDIC processing will be stored. 00789 * @param NbCalc Number of CORDIC calculation to process. 00790 * @retval HAL status 00791 */ 00792 HAL_StatusTypeDef HAL_CORDIC_Calculate_IT(CORDIC_HandleTypeDef *hcordic, int32_t *pInBuff, int32_t *pOutBuff, 00793 uint32_t NbCalc) 00794 { 00795 int32_t *tmp_pInBuff = pInBuff; 00796 00797 /* Check parameters setting */ 00798 if ((pInBuff == NULL) || (pOutBuff == NULL) || (NbCalc == 0U)) 00799 { 00800 /* Update the error code */ 00801 hcordic->ErrorCode |= HAL_CORDIC_ERROR_PARAM; 00802 00803 /* Return error status */ 00804 return HAL_ERROR; 00805 } 00806 00807 /* Check handle state is ready */ 00808 if (hcordic->State == HAL_CORDIC_STATE_READY) 00809 { 00810 /* Reset CORDIC error code */ 00811 hcordic->ErrorCode = HAL_CORDIC_ERROR_NONE; 00812 00813 /* Change the CORDIC state */ 00814 hcordic->State = HAL_CORDIC_STATE_BUSY; 00815 00816 /* Store the buffers addresses and number of calculations in handle, 00817 provisioning initial write of input data that will be done */ 00818 if (HAL_IS_BIT_SET(hcordic->Instance->CSR, CORDIC_CSR_NARGS)) 00819 { 00820 /* Two writes of input data are expected */ 00821 tmp_pInBuff++; 00822 tmp_pInBuff++; 00823 } 00824 else 00825 { 00826 /* One write of input data is expected */ 00827 tmp_pInBuff++; 00828 } 00829 hcordic->pInBuff = tmp_pInBuff; 00830 hcordic->pOutBuff = pOutBuff; 00831 hcordic->NbCalcToOrder = NbCalc - 1U; 00832 hcordic->NbCalcToGet = NbCalc; 00833 00834 /* Enable Result Ready Interrupt */ 00835 __HAL_CORDIC_ENABLE_IT(hcordic, CORDIC_IT_IEN); 00836 00837 /* Set back pointer to start of input data buffer */ 00838 tmp_pInBuff = pInBuff; 00839 00840 /* Initiate the processing by providing input data 00841 in the Write Data register */ 00842 WRITE_REG(hcordic->Instance->WDATA, (uint32_t)*tmp_pInBuff); 00843 00844 /* Check if second write of input data is expected */ 00845 if (HAL_IS_BIT_SET(hcordic->Instance->CSR, CORDIC_CSR_NARGS)) 00846 { 00847 /* Increment pointer to input data */ 00848 tmp_pInBuff++; 00849 00850 /* Perform second write of input data */ 00851 WRITE_REG(hcordic->Instance->WDATA, (uint32_t)*tmp_pInBuff); 00852 } 00853 00854 /* Return function status */ 00855 return HAL_OK; 00856 } 00857 else 00858 { 00859 /* Set CORDIC error code */ 00860 hcordic->ErrorCode |= HAL_CORDIC_ERROR_NOT_READY; 00861 00862 /* Return function status */ 00863 return HAL_ERROR; 00864 } 00865 } 00866 00867 /** 00868 * @brief Carry out input and/or output data of CORDIC processing in DMA mode, 00869 * according to the existing CORDIC configuration. 00870 * @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains 00871 * the configuration information for CORDIC module. 00872 * @param pInBuff Pointer to buffer containing input data for CORDIC processing. 00873 * @param pOutBuff Pointer to buffer where output data of CORDIC processing will be stored. 00874 * @param NbCalc Number of CORDIC calculation to process. 00875 * @param DMADirection Direction of DMA transfers. 00876 * This parameter can be one of the following values: 00877 * @arg @ref CORDIC_DMA_Direction CORDIC DMA direction 00878 * @note pInBuff or pOutBuff is unused in case of unique DMADirection transfer, and can 00879 * be set to NULL value in this case. 00880 * @note pInBuff and pOutBuff buffers must be 32-bit aligned to ensure a correct 00881 * DMA transfer to and from the Peripheral. 00882 * @retval HAL status 00883 */ 00884 HAL_StatusTypeDef HAL_CORDIC_Calculate_DMA(CORDIC_HandleTypeDef *hcordic, int32_t *pInBuff, int32_t *pOutBuff, 00885 uint32_t NbCalc, uint32_t DMADirection) 00886 { 00887 uint32_t sizeinbuff; 00888 uint32_t sizeoutbuff; 00889 uint32_t inputaddr; 00890 uint32_t outputaddr; 00891 00892 /* Check the parameters */ 00893 assert_param(IS_CORDIC_DMA_DIRECTION(DMADirection)); 00894 00895 /* Check parameters setting */ 00896 if (NbCalc == 0U) 00897 { 00898 /* Update the error code */ 00899 hcordic->ErrorCode |= HAL_CORDIC_ERROR_PARAM; 00900 00901 /* Return error status */ 00902 return HAL_ERROR; 00903 } 00904 00905 /* Check if CORDIC DMA direction "Out" is requested */ 00906 if ((DMADirection == CORDIC_DMA_DIR_OUT) || (DMADirection == CORDIC_DMA_DIR_IN_OUT)) 00907 { 00908 /* Check parameters setting */ 00909 if (pOutBuff == NULL) 00910 { 00911 /* Update the error code */ 00912 hcordic->ErrorCode |= HAL_CORDIC_ERROR_PARAM; 00913 00914 /* Return error status */ 00915 return HAL_ERROR; 00916 } 00917 } 00918 00919 /* Check if CORDIC DMA direction "In" is requested */ 00920 if ((DMADirection == CORDIC_DMA_DIR_IN) || (DMADirection == CORDIC_DMA_DIR_IN_OUT)) 00921 { 00922 /* Check parameters setting */ 00923 if (pInBuff == NULL) 00924 { 00925 /* Update the error code */ 00926 hcordic->ErrorCode |= HAL_CORDIC_ERROR_PARAM; 00927 00928 /* Return error status */ 00929 return HAL_ERROR; 00930 } 00931 } 00932 00933 if (hcordic->State == HAL_CORDIC_STATE_READY) 00934 { 00935 /* Reset CORDIC error code */ 00936 hcordic->ErrorCode = HAL_CORDIC_ERROR_NONE; 00937 00938 /* Change the CORDIC state */ 00939 hcordic->State = HAL_CORDIC_STATE_BUSY; 00940 00941 /* Get DMA direction */ 00942 hcordic->DMADirection = DMADirection; 00943 00944 /* Check if CORDIC DMA direction "Out" is requested */ 00945 if ((DMADirection == CORDIC_DMA_DIR_OUT) || (DMADirection == CORDIC_DMA_DIR_IN_OUT)) 00946 { 00947 /* Set the CORDIC DMA transfer complete callback */ 00948 hcordic->hdmaOut->XferCpltCallback = CORDIC_DMAOutCplt; 00949 /* Set the DMA error callback */ 00950 hcordic->hdmaOut->XferErrorCallback = CORDIC_DMAError; 00951 00952 /* Check number of output data at each calculation, 00953 to retrieve the size of output data buffer */ 00954 if (HAL_IS_BIT_SET(hcordic->Instance->CSR, CORDIC_CSR_NRES)) 00955 { 00956 sizeoutbuff = 2U * NbCalc; 00957 } 00958 else 00959 { 00960 sizeoutbuff = NbCalc; 00961 } 00962 00963 outputaddr = (uint32_t)pOutBuff; 00964 00965 /* Enable the DMA stream managing CORDIC output data read */ 00966 if (HAL_DMA_Start_IT(hcordic->hdmaOut, (uint32_t)&hcordic->Instance->RDATA, outputaddr, sizeoutbuff) != HAL_OK) 00967 { 00968 /* Update the error code */ 00969 hcordic->ErrorCode |= HAL_CORDIC_ERROR_DMA; 00970 00971 /* Return error status */ 00972 return HAL_ERROR; 00973 } 00974 00975 /* Enable output data Read DMA requests */ 00976 SET_BIT(hcordic->Instance->CSR, CORDIC_DMA_REN); 00977 } 00978 00979 /* Check if CORDIC DMA direction "In" is requested */ 00980 if ((DMADirection == CORDIC_DMA_DIR_IN) || (DMADirection == CORDIC_DMA_DIR_IN_OUT)) 00981 { 00982 /* Set the CORDIC DMA transfer complete callback */ 00983 hcordic->hdmaIn->XferCpltCallback = CORDIC_DMAInCplt; 00984 /* Set the DMA error callback */ 00985 hcordic->hdmaIn->XferErrorCallback = CORDIC_DMAError; 00986 00987 /* Check number of input data expected for each calculation, 00988 to retrieve the size of input data buffer */ 00989 if (HAL_IS_BIT_SET(hcordic->Instance->CSR, CORDIC_CSR_NARGS)) 00990 { 00991 sizeinbuff = 2U * NbCalc; 00992 } 00993 else 00994 { 00995 sizeinbuff = NbCalc; 00996 } 00997 00998 inputaddr = (uint32_t)pInBuff; 00999 01000 /* Enable the DMA stream managing CORDIC input data write */ 01001 if (HAL_DMA_Start_IT(hcordic->hdmaIn, inputaddr, (uint32_t)&hcordic->Instance->WDATA, sizeinbuff) != HAL_OK) 01002 { 01003 /* Update the error code */ 01004 hcordic->ErrorCode |= HAL_CORDIC_ERROR_DMA; 01005 01006 /* Return error status */ 01007 return HAL_ERROR; 01008 } 01009 01010 /* Enable input data Write DMA request */ 01011 SET_BIT(hcordic->Instance->CSR, CORDIC_DMA_WEN); 01012 } 01013 01014 /* Return function status */ 01015 return HAL_OK; 01016 } 01017 else 01018 { 01019 /* Set CORDIC error code */ 01020 hcordic->ErrorCode |= HAL_CORDIC_ERROR_NOT_READY; 01021 01022 /* Return function status */ 01023 return HAL_ERROR; 01024 } 01025 } 01026 01027 /** 01028 * @} 01029 */ 01030 01031 /** @defgroup CORDIC_Exported_Functions_Group3 Callback functions 01032 * @brief Callback functions. 01033 * 01034 @verbatim 01035 ============================================================================== 01036 ##### Callback functions ##### 01037 ============================================================================== 01038 [..] This section provides Interruption and DMA callback functions: 01039 (+) DMA or Interrupt calculate complete 01040 (+) DMA or Interrupt error 01041 01042 @endverbatim 01043 * @{ 01044 */ 01045 01046 /** 01047 * @brief CORDIC error callback. 01048 * @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains 01049 * the configuration information for CORDIC module 01050 * @retval None 01051 */ 01052 __weak void HAL_CORDIC_ErrorCallback(CORDIC_HandleTypeDef *hcordic) 01053 { 01054 /* Prevent unused argument(s) compilation warning */ 01055 UNUSED(hcordic); 01056 01057 /* NOTE : This function should not be modified; when the callback is needed, 01058 the HAL_CORDIC_ErrorCallback can be implemented in the user file 01059 */ 01060 } 01061 01062 /** 01063 * @brief CORDIC calculate complete callback. 01064 * @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains 01065 * the configuration information for CORDIC module 01066 * @retval None 01067 */ 01068 __weak void HAL_CORDIC_CalculateCpltCallback(CORDIC_HandleTypeDef *hcordic) 01069 { 01070 /* Prevent unused argument(s) compilation warning */ 01071 UNUSED(hcordic); 01072 01073 /* NOTE : This function should not be modified; when the callback is needed, 01074 the HAL_CORDIC_CalculateCpltCallback can be implemented in the user file 01075 */ 01076 } 01077 01078 /** 01079 * @} 01080 */ 01081 01082 /** @defgroup CORDIC_Exported_Functions_Group4 IRQ handler management 01083 * @brief IRQ handler. 01084 * 01085 @verbatim 01086 ============================================================================== 01087 ##### IRQ handler management ##### 01088 ============================================================================== 01089 [..] This section provides IRQ handler function. 01090 01091 @endverbatim 01092 * @{ 01093 */ 01094 01095 /** 01096 * @brief Handle CORDIC interrupt request. 01097 * @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains 01098 * the configuration information for CORDIC module 01099 * @retval None 01100 */ 01101 void HAL_CORDIC_IRQHandler(CORDIC_HandleTypeDef *hcordic) 01102 { 01103 /* Check if calculation complete interrupt is enabled and if result ready 01104 flag is raised */ 01105 if (__HAL_CORDIC_GET_IT_SOURCE(hcordic, CORDIC_IT_IEN) != 0U) 01106 { 01107 if (__HAL_CORDIC_GET_FLAG(hcordic, CORDIC_FLAG_RRDY) != 0U) 01108 { 01109 /* Decrement number of calculations to get */ 01110 hcordic->NbCalcToGet--; 01111 01112 /* Read output data from Read Data register, and increment output buffer pointer */ 01113 CORDIC_ReadOutDataIncrementPtr(hcordic, &(hcordic->pOutBuff)); 01114 01115 /* Check if calculations are still to be ordered */ 01116 if (hcordic->NbCalcToOrder > 0U) 01117 { 01118 /* Decrement number of calculations to order */ 01119 hcordic->NbCalcToOrder--; 01120 01121 /* Continue the processing by providing another write of input data 01122 in the Write Data register, and increment input buffer pointer */ 01123 CORDIC_WriteInDataIncrementPtr(hcordic, &(hcordic->pInBuff)); 01124 } 01125 01126 /* Check if all calculations results are got */ 01127 if (hcordic->NbCalcToGet == 0U) 01128 { 01129 /* Disable Result Ready Interrupt */ 01130 __HAL_CORDIC_DISABLE_IT(hcordic, CORDIC_IT_IEN); 01131 01132 /* Change the CORDIC state */ 01133 hcordic->State = HAL_CORDIC_STATE_READY; 01134 01135 /* Call calculation complete callback */ 01136 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1 01137 /*Call registered callback*/ 01138 hcordic->CalculateCpltCallback(hcordic); 01139 #else 01140 /*Call legacy weak (surcharged) callback*/ 01141 HAL_CORDIC_CalculateCpltCallback(hcordic); 01142 #endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */ 01143 } 01144 } 01145 } 01146 } 01147 01148 /** 01149 * @} 01150 */ 01151 01152 /** @defgroup CORDIC_Exported_Functions_Group5 Peripheral State functions 01153 * @brief Peripheral State functions. 01154 * 01155 @verbatim 01156 ============================================================================== 01157 ##### Peripheral State functions ##### 01158 ============================================================================== 01159 [..] 01160 This subsection permits to get in run-time the status of the peripheral. 01161 01162 @endverbatim 01163 * @{ 01164 */ 01165 01166 /** 01167 * @brief Return the CORDIC handle state. 01168 * @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains 01169 * the configuration information for CORDIC module 01170 * @retval HAL state 01171 */ 01172 HAL_CORDIC_StateTypeDef HAL_CORDIC_GetState(CORDIC_HandleTypeDef *hcordic) 01173 { 01174 /* Return CORDIC handle state */ 01175 return hcordic->State; 01176 } 01177 01178 /** 01179 * @brief Return the CORDIC peripheral error. 01180 * @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains 01181 * the configuration information for CORDIC module 01182 * @note The returned error is a bit-map combination of possible errors 01183 * @retval Error bit-map 01184 */ 01185 uint32_t HAL_CORDIC_GetError(CORDIC_HandleTypeDef *hcordic) 01186 { 01187 /* Return CORDIC error code */ 01188 return hcordic->ErrorCode; 01189 } 01190 01191 /** 01192 * @} 01193 */ 01194 01195 /** 01196 * @} 01197 */ 01198 01199 /** @addtogroup CORDIC_Private_Functions 01200 * @{ 01201 */ 01202 01203 /** 01204 * @brief Write input data for CORDIC processing, and increment input buffer pointer. 01205 * @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains 01206 * the configuration information for CORDIC module. 01207 * @param ppInBuff Pointer to pointer to input buffer. 01208 * @retval none 01209 */ 01210 static void CORDIC_WriteInDataIncrementPtr(CORDIC_HandleTypeDef *hcordic, int32_t **ppInBuff) 01211 { 01212 /* First write of input data in the Write Data register */ 01213 WRITE_REG(hcordic->Instance->WDATA, (uint32_t) **ppInBuff); 01214 01215 /* Increment input data pointer */ 01216 (*ppInBuff)++; 01217 01218 /* Check if second write of input data is expected */ 01219 if (HAL_IS_BIT_SET(hcordic->Instance->CSR, CORDIC_CSR_NARGS)) 01220 { 01221 /* Second write of input data in the Write Data register */ 01222 WRITE_REG(hcordic->Instance->WDATA, (uint32_t) **ppInBuff); 01223 01224 /* Increment input data pointer */ 01225 (*ppInBuff)++; 01226 } 01227 } 01228 01229 /** 01230 * @brief Read output data of CORDIC processing, and increment output buffer pointer. 01231 * @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains 01232 * the configuration information for CORDIC module. 01233 * @param ppOutBuff Pointer to pointer to output buffer. 01234 * @retval none 01235 */ 01236 static void CORDIC_ReadOutDataIncrementPtr(CORDIC_HandleTypeDef *hcordic, int32_t **ppOutBuff) 01237 { 01238 /* First read of output data from the Read Data register */ 01239 **ppOutBuff = (int32_t)READ_REG(hcordic->Instance->RDATA); 01240 01241 /* Increment output data pointer */ 01242 (*ppOutBuff)++; 01243 01244 /* Check if second read of output data is expected */ 01245 if (HAL_IS_BIT_SET(hcordic->Instance->CSR, CORDIC_CSR_NRES)) 01246 { 01247 /* Second read of output data from the Read Data register */ 01248 **ppOutBuff = (int32_t)READ_REG(hcordic->Instance->RDATA); 01249 01250 /* Increment output data pointer */ 01251 (*ppOutBuff)++; 01252 } 01253 } 01254 01255 /** 01256 * @brief DMA CORDIC Input Data process complete callback. 01257 * @param hdma DMA handle. 01258 * @retval None 01259 */ 01260 static void CORDIC_DMAInCplt(DMA_HandleTypeDef *hdma) 01261 { 01262 CORDIC_HandleTypeDef *hcordic = (CORDIC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; 01263 01264 /* Disable the DMA transfer for input request */ 01265 CLEAR_BIT(hcordic->Instance->CSR, CORDIC_DMA_WEN); 01266 01267 /* Check if DMA direction is CORDIC Input only (no DMA for CORDIC Output) */ 01268 if (hcordic->DMADirection == CORDIC_DMA_DIR_IN) 01269 { 01270 /* Change the CORDIC DMA direction to none */ 01271 hcordic->DMADirection = CORDIC_DMA_DIR_NONE; 01272 01273 /* Change the CORDIC state to ready */ 01274 hcordic->State = HAL_CORDIC_STATE_READY; 01275 01276 /* Call calculation complete callback */ 01277 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1 01278 /*Call registered callback*/ 01279 hcordic->CalculateCpltCallback(hcordic); 01280 #else 01281 /*Call legacy weak (surcharged) callback*/ 01282 HAL_CORDIC_CalculateCpltCallback(hcordic); 01283 #endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */ 01284 } 01285 } 01286 01287 /** 01288 * @brief DMA CORDIC Output Data process complete callback. 01289 * @param hdma DMA handle. 01290 * @retval None 01291 */ 01292 static void CORDIC_DMAOutCplt(DMA_HandleTypeDef *hdma) 01293 { 01294 CORDIC_HandleTypeDef *hcordic = (CORDIC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; 01295 01296 /* Disable the DMA transfer for output request */ 01297 CLEAR_BIT(hcordic->Instance->CSR, CORDIC_DMA_REN); 01298 01299 /* Change the CORDIC DMA direction to none */ 01300 hcordic->DMADirection = CORDIC_DMA_DIR_NONE; 01301 01302 /* Change the CORDIC state to ready */ 01303 hcordic->State = HAL_CORDIC_STATE_READY; 01304 01305 /* Call calculation complete callback */ 01306 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1 01307 /*Call registered callback*/ 01308 hcordic->CalculateCpltCallback(hcordic); 01309 #else 01310 /*Call legacy weak (surcharged) callback*/ 01311 HAL_CORDIC_CalculateCpltCallback(hcordic); 01312 #endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */ 01313 } 01314 01315 /** 01316 * @brief DMA CORDIC communication error callback. 01317 * @param hdma DMA handle. 01318 * @retval None 01319 */ 01320 static void CORDIC_DMAError(DMA_HandleTypeDef *hdma) 01321 { 01322 CORDIC_HandleTypeDef *hcordic = (CORDIC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; 01323 01324 /* Set CORDIC handle state to error */ 01325 hcordic->State = HAL_CORDIC_STATE_READY; 01326 01327 /* Set CORDIC handle error code to DMA error */ 01328 hcordic->ErrorCode |= HAL_CORDIC_ERROR_DMA; 01329 01330 /* Call user callback */ 01331 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1 01332 /*Call registered callback*/ 01333 hcordic->ErrorCallback(hcordic); 01334 #else 01335 /*Call legacy weak (surcharged) callback*/ 01336 HAL_CORDIC_ErrorCallback(hcordic); 01337 #endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */ 01338 } 01339 01340 /** 01341 * @} 01342 */ 01343 01344 /** 01345 * @} 01346 */ 01347 01348 /** 01349 * @} 01350 */ 01351 01352 #endif /* HAL_CORDIC_MODULE_ENABLED */ 01353 #endif /* CORDIC */