DSP中CMD空间分配

在DSP的CMD文件中,分配的空间大小计算:如RAMGS2: origin = 0x00E000, length = 0x000E00;他对应的函数意义是,初始地址为0x00E000,大小为0x000E00=14*16*16=3,584,这么大空间。如果长度为0x001000=1*16*16*16=4K。

此外,对于PAGE 0,和PAGE 1中如果有同样名称的变量,不使用的要注释掉,不然CSS Memory allocation的显示会异常,内存不够用报错了,CSS上显示的是使用空间占比为0%

在CMD文件中,PAGE0代表程序空间,PAGE1代表数据空间

PAGE 0 :  /* Program Memory */
          /* Memory (RAM/FLASH) blocks can be moved to PAGE1 for data allocation */
          /* BEGIN is used for the "boot to Flash" bootloader mode   */
    RAMGS2           : origin = 0x00E000, length = 0x000E00           /* reserved for C28 flash to GSRAM*/
    FLASHD           : origin = 0x086000, length = 0x000800	/* on-chip Flash */
PAGE 1 : /* Data Memory */
         /* Memory (RAM/FLASH) blocks can be moved to PAGE0 for program allocation */

在开发DSP时,平时都是在调试程序,是把程序下载到RAM中,而当开发完成后,需要烧写到flash中,但是当程序烧写到flash中后,运行速度要慢,大概降到原来的RAM中的70%~80%。如果对时间敏感的可以复制到RAM中运行,程序如下:

SECTIONS
{
    ramfuncs          : LOAD = FLASHD,

                        RUN = RAMGS2,
                        LOAD_START(_RamfuncsLoadStart),
                        LOAD_SIZE(_RamfuncsLoadSize),
                        LOAD_END(_RamfuncsLoadEnd),
                        RUN_START(_RamfuncsRunStart),
                        RUN_SIZE(_RamfuncsRunSize),
                        RUN_END(_RamfuncsRunEnd),
                        PAGE = 0, ALIGN(4)
}

在其他C文件中,定义函数时,能够声明该函数运行的位置

#pragma CODE_SECTION(DABCtrlFun_PI, "ramfuncs");
void DABCtrlFun_PI(DAB_PI_CTRL_COEFFS *coeffs,DAB_PI_CTRL_VARS *vars)
{
    vars->Err = vars->Ref - vars->Fdb;
    vars->Out0 = vars->Out1 + vars->Err * coeffs->Ki * vars->AntiSat;
    vars->Out1 = vars->Out0;
    vars->Out0 = vars->Out0 + vars->Err * coeffs->Kp;
    if(vars->Out0 > coeffs->OutMax)
    {
        vars->Out0 = coeffs->OutMax;
        if(vars->Err > 0)
        {
            vars->AntiSat = 0;
        }
        else
        {
            vars->AntiSat = 1;
        }
    }
    else if(vars->Out0 <= coeffs->OutMin)  //todo
    {
        vars->Out0 = coeffs->OutMin;
        if(vars->Err < 0)
        {
            vars->AntiSat = 0;
        }
        else
        {
            vars->AntiSat = 1;
        }
    }
    else
    {
        vars->AntiSat = 1;
    }
}