This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2530: 在iar平台测试32位的移位、加、减、乘、除运算都非常耗时,请问正常吗?

Part Number: CC2530
Other Parts Discussed in Thread: CC2652R

如题所述,我在IAR EW8051 9.10.1上新建一个项目,用示波器测量引脚波长来测量32位数据(unsigned long)的相关运算耗时,发现有相当严重的耗时问题,比如:
31位的左右移位操作耗时60us,除法耗时123us,等等。请问是什么问题呢?

代码如下:

////////////////////////////////////////////////////////////////////////////////
/*
功能:
测试32位数据运算耗时。
*/ 
////////////////////////////////////////////////////////////////////////////////
#include <ioCC2530.h>

#define LED1    P0_0
#define LED2    P0_1
#define LED3    P0_4
#define LED4    P0_5
#define LED5    P0_6
#define LED6    P0_7

#define SetRegBitValue(Reg, BitNum, State) \
((State) ? ((Reg) |= (((unsigned char)1) << BitNum)) : ((Reg) &= ~(((unsigned char)1) << (BitNum))))

#define SetRegValue(Reg, Bit7, Bit6, Bit5, Bit4, Bit3, Bit2, Bit1, Bit0) \
(Reg = (unsigned char)(Bit0) + (unsigned char)((Bit1)<<1) + (unsigned char)((Bit2)<<2) + (unsigned char)((Bit3)<<3) \
     + (unsigned char)((Bit4)<<4) + (unsigned char)((Bit5)<<5) + (unsigned char)((Bit6)<<6) + (unsigned char)((Bit7)<<7) )

#define BinValue(Bit7, Bit6, Bit5, Bit4, Bit3, Bit2, Bit1, Bit0) \
((unsigned char)(Bit0) + (unsigned char)((Bit1)<<1) + (unsigned char)((Bit2)<<2) + (unsigned char)((Bit3)<<3) \
  + (unsigned char)((Bit4)<<4) + (unsigned char)((Bit5)<<5) + (unsigned char)((Bit6)<<6) + (unsigned char)((Bit7)<<7))

//typedef signed   char   int8;
//typedef unsigned char   uint8;
//
//typedef signed   short  int16;
//typedef unsigned short  uint16;
//
//typedef signed   long   int32;
//typedef unsigned long   uint32;

////////////////////////////////////////////////////////////////////////////////
int main( void )
{
    //--------------------------------------------------------------------------
    //先稳定外部晶振,再设定当前时钟为32MHz。
    //[7][OSC32K]1(1,R/W), 设置高频时钟为32kHz RCOSC。
    //[6][OSC]0(1,R/W), 设置高频时钟为32MHz XOSC。
    //[5:3][TICKSPD]101(001,R/W),设置Timer Ticks为1MHz。
    //[2:0][CLKSPD]000(001,R/W),设置内部系统主时钟为32MHz。
    SetRegValue(CLKCONCMD, 1, 0, 1,0,1, 0,0,0);
    while(CLKCONSTA != BinValue(1, 0, 1,0,1, 0,0,0));
    
    //--------------------------------------------------------------------------
    EA = 0; //关闭全局中断。
  
    //初始化引脚。
    SetRegBitValue(P0SEL, 0, 0); //0,选择通用I/O功能。
    SetRegBitValue(P0DIR, 0, 1); //1,输出方向。
    
    SetRegBitValue(P0SEL, 1, 0); //0,选择通用I/O功能。
    SetRegBitValue(P0DIR, 1, 1); //1,输出方向。
    
    SetRegBitValue(P0SEL, 4, 0); //0,选择通用I/O功能。
    SetRegBitValue(P0DIR, 4, 1); //1,输出方向。
    
    SetRegBitValue(P0SEL, 5, 0); //0,选择通用I/O功能。
    SetRegBitValue(P0DIR, 5, 1); //1,输出方向。
    
    SetRegBitValue(P0SEL, 6, 0); //0,选择通用I/O功能。
    SetRegBitValue(P0DIR, 6, 1); //1,输出方向。
    
    SetRegBitValue(P0SEL, 7, 0); //0,选择通用I/O功能。
    SetRegBitValue(P0DIR, 7, 1); //1,输出方向。
    
    //--------------------------------------------------------------------------
    while(1)
    {
        unsigned long A = 0xF32E9AD0; 
        unsigned long B = 0xE9A3D02E; 
        
        LED1 = 1;
        /*
        1位,7.5us。 5位,14.6us。  10位,23.6us。  13位,29.0us。  16位,34.4us。
        19位,39.6us。  24位,48.8us。  29位,57.6us。  31位,61.2us。     */
        unsigned long C = A << 31; 
        LED1 = 0;
        
        LED2 = 1;
        /*
        1位,7.6us。  5位,15us。  10位,24.4us。  13位,29.8us。  16位,35.4us。
        19位,41.2us。  24位,50.4us。  29位,59.6us。   31位,63.2us。    */
        unsigned long D = A >> 31;
        LED2 = 0;
        
        LED3 = 1;
        unsigned long E = A + B; //【8.3us】
        LED3 = 0;
        
        LED4 = 1;
        unsigned long F = A - B; //【8.9us】
        LED4 = 0;
        
        LED5 = 1;
        unsigned long H = A * B; //【18.6us】
        LED5 = 0;
        
        LED6 = 1;
        unsigned long I = A / B; //【123us】
        LED6 = 0;
    }
    //--------------------------------------------------------------------------
    return 0;
}

////////////////////////////////////////////////////////////////////////////////

一些环境配置如下: