硬件除法器初始化配置如下:
RCC_AHBPeriphclockCmd(RCC_AHBPeriph_HWDIV, ENABLE); //使能除法器时钟
HWDIV->DIVCON |= (DIV_UNSIGN ); //无符号除法,不使能除零中断
为了验证硬件除法器的效率,在主函数中分别使用硬件除法器和软件除法器进行16次除法运算,不使用while是为了避免多余的指令占用时间。
主函数如下:
- u32 DVD_data[32] = {
- 0x12345678,0x9876554 ,0x9822346 ,0x98734662,
- 0x000001 ,0xFFFFFFFF,0x11111111,0x22222222,
- 0x33333333,0x78645323,0x4399039 ,0x4367464 ,
- 0x42345678,0x9873554 ,0x9822346 ,0x98734662,
- 0x100001 ,0x1FFFFFFF,0x11511111,0x22422222,
- 0x53333333,0x78645323,0x4399039 ,0x4367464 ,
- 0x140001 ,0x11FFFFFF,0x12111111,0x29422222,
- 0x53333333,0x78644323,0x4369039 ,0x4767464 ,
- };
- u32 DVS_data[32] = {
- 0x11,0x22,0x33,0x44,
- 0x55,0x66,0x77,0x88,
- 0x99,0xaa,0xbb,0xcc,
- 0xdd,0xee,0xff,0xee,
- 0xdd,0xcc,0xbb,0xaa,
- 0x99,0x88,0x77,0x66,
- 0x55,0x44,0x33,0x22,
- 0x11,0x22,0x33,0x44,
- };//除数数组
- u32 result[32];
- int main (void)
- {
- u32 i ;
- IO_Init();
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_HWDIV, ENABLE);
- HWDivider_UnsignInit();
- while(1)
- {
- GPIOB->ODR ^= 1<<5;
- GPIOB->ODR ^= 1<<5;
- //硬件除法器运算
- SET_HWDivider(DVD_data[0],DVS_data[0]);
- result[0] = GET_HWDivider;
- SET_HWDivider(DVD_data[1],DVS_data[1]);
- result[1] = GET_HWDivider;
- SET_HWDivider(DVD_data[2],DVS_data[2]); result[2] = GET_HWDivider;
- SET_HWDivider(DVD_data[3],DVS_data[3]);
- result[3] = GET_HWDivider;
- SET_HWDivider(DVD_data[4],DVS_data[4]);
- result[4] = GET_HWDivider;
- SET_HWDivider(DVD_data[5],DVS_data[5]);
- result[5] = GET_HWDivider;
- SET_HWDivider(DVD_data[6],DVS_data[6]);
- result[6] = GET_HWDivider;
- SET_HWDivider(DVD_data[7],DVS_data[7]);
- result[7] = GET_HWDivider;
- SET_HWDivider(DVD_data[8],DVS_data[8]);
- result[8] = GET_HWDivider;
- SET_HWDivider(DVD_data[9],DVS_data[9]);
- result[9] = GET_HWDivider;
- SET_HWDivider(DVD_data[10],DVS_data[10]);
- result[10] = GET_HWDivider;
- SET_HWDivider(DVD_data[11],DVS_data[11]);
- result[11] = GET_HWDivider;
- SET_HWDivider(DVD_data[12],DVS_data[12]);
- result[12] = GET_HWDivider;
- SET_HWDivider(DVD_data[13],DVS_data[13]);
- result[13] = GET_HWDivider;
- SET_HWDivider(DVD_data[14],DVS_data[14]);
- result[14] = GET_HWDivider;
- SET_HWDivider(DVD_data[15],DVS_data[15]);
- result[15] = GET_HWDivider;
- GPIOB->ODR ^= 1<<5;
- GPIOB->ODR ^= 1<<5;
- i = 1000;while(i--);
- GPIOB->ODR ^= 1<<5;
- GPIOB->ODR ^= 1<<5;
- //软件除法器运算
- result[0] = DVD_data[0]/DVS_data[0];
- result[1] = DVD_data[1]/DVS_data[1];
- result[2] = DVD_data[2]/DVS_data[2];
- result[3] = DVD_data[3]/DVS_data[3];
- result[4] = DVD_data[4]/DVS_data[4];
- result[5] = DVD_data[5]/DVS_data[5];
- result[6] = DVD_data[6]/DVS_data[6];
- result[7] = DVD_data[7]/DVS_data[7];
- result[8] = DVD_data[8]/DVS_data[8];
- result[9] = DVD_data[9]/DVS_data[9];
- result[10] = DVD_data[10]/DVS_data[10];
- result[11] = DVD_data[11]/DVS_data[11];
- result[12] = DVD_data[12]/DVS_data[12];
- result[13] = DVD_data[13]/DVS_data[13];
- result[14] = DVD_data[14]/DVS_data[14];
- result[15] = DVD_data[15]/DVS_data[15];
- GPIOB->ODR ^= 1<<5;
- GPIOB->ODR ^= 1<<5;
- i = 1000;while(i--);
- }
- }
复制代码
|