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