hk32f0xx_divsqrt.h 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. ******************************************************************************
  3. * @file hk32f0xx_divsqrt.h
  4. * @brief hk32f0xx divsqrt file.
  5. * The file is the unique include file that the application programmer
  6. * is using in the C source code.it is a patch file
  7. ******************************************************************************
  8. **/
  9. /* Define to prevent recursive inclusion -------------------------------------*/
  10. #ifndef __HK32F0xx_DIVSQRT_H
  11. #define __HK32F0xx_DIVSQRT_H
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. /* Includes ------------------------------------------------------------------*/
  16. #include "hk32f0xx.h"
  17. #define DVSQ_BUSY_WAIT_EN 1 /* 为1的话在读取DVSQ运算结果寄存器前都会判断并等待DVSQ空闲 */
  18. // DVSQ寄存器访问指针
  19. #define DVSQ DIVSQRT
  20. // DVSQ外设时钟操作
  21. #define RCC_AHBPeriph_DVSQ ((uint32_t)0x00000001)
  22. #define RCC_AHBPeriph_DVSQ_CLK_Enable() RCC->AHBENR2 |= RCC_AHBPeriph_DVSQ /* 使能DVSQ外设时钟 */
  23. #define RCC_AHBPeriph_DVSQ_CLK_Disable() RCC->AHBENR2 &= ~RCC_AHBPeriph_DVSQ /* 关闭DVSQ外设时钟 */
  24. /* DVSQ工作状态定义 */
  25. #define DVSQ_IDLE_NO_OPERATION ((uint32_t)0x00000000) /* 加速器处于空闲状态,并且尚未进行过开方或除法运算 */
  26. #define DVSQ_IDLE_SQRT ((uint32_t)0x20000000) /* 加速器处于空闲状态,并且完成的上一个操作是开方运算 */
  27. #define DVSQ_IDLE_DIV ((uint32_t)0x40000000) /* 加速器处于空闲状诚,并且完成的上一个操作为除法运算 */
  28. #define DVSQ_BUSY_SQRT ((uint32_t)0xA0000000) /* 加速器处于忙状态,并且正在进行开方运算 */
  29. #define DVSQ_BUSY_DIV ((uint32_t)0xC0000000) /* 加速器处于忙状态,并且正在进行除法运算 */
  30. /* 配置DVSQ除法运算的启动方式 */
  31. #define DVSQ_EnableDivFastStart() DVSQ->CSR &= ~DIVSQRT_CSR_DFS /* 使能快速启动除法运算功能 */
  32. #define DVSQ_DisableDivFastStart() DVSQ->CSR |= DIVSQRT_CSR_DFS /* 关闭快速启动除法运算功能 */
  33. /* 配置DVSQ除法是否带符号 */
  34. #define DVSQ_ConfigDivUnsigned() DVSQ->CSR |= DIVSQRT_CSR_UNSIGN_DIV /* 将DVSQ配置为执行无符号除法模式 */
  35. #define DVSQ_ConfigDivSigned() DVSQ->CSR &= ~DIVSQRT_CSR_UNSIGN_DIV /* 将DVSQ配置为执行带符号除法模式 */
  36. /* 配置DVSQ开方运算精度 */
  37. #define DVSQ_ConfigSqrtPresHigh() DVSQ->CSR |= DIVSQRT_CSR_HPRESQRT /* 配置DVSQ为高精度开方运算模式 */
  38. #define DVSQ_ConfigSqrtPresNormal() DVSQ->CSR &= ~DIVSQRT_CSR_HPRESQRT /* 配置DVSQ为普通精度开方运算模式 */
  39. /* 当DVSQ的CSR中DVSQ_CSR_DFS为1时,必须由软件启动除法运算,当该位为0时,往除数寄存器中写入值后硬件自动启动除法运算 */
  40. #define DVSQ_StartDivCalc() DVSQ->CSR |= DIVSQRT_CSR_DIV_SRT /* 开始除法运算 */
  41. /* DVSQ忙状态查询 */
  42. #define DVSQ_IsBusy() ((DVSQ->CSR & DIVSQRT_CSR_BUSY)? 1:0) /* 返回'1'表示忙; 返回'0'表示空闲 */
  43. /* DVSQ等待空闲 */
  44. #if (DVSQ_BUSY_WAIT_EN == 1)
  45. #define DVSQ_Wait() while(DVSQ_IsBusy())
  46. #else
  47. #define DVSQ_Wait()
  48. #endif
  49. /*DIVSQRT的API函数接口*/
  50. void HK_Dvsq_Init(void);
  51. uint32_t HK_Dvsq_Sqrt(uint32_t u32Radicand, FlagStatus eIsHighPres);
  52. uint32_t HK_Dvsq_Divsion(uint32_t u32Dividend, uint32_t u32Divisor, uint32_t *u32pRemainder, FlagStatus eIsUnsigned, FlagStatus eIsFastStart);
  53. #ifdef __cplusplus
  54. }
  55. #endif
  56. #endif