• 6678 DATA_SECTION 函数 #pragma CODE_SECTION


    (一)#pragma DATA_SECTION
    利用CCS进行DSP编程时,如果不指定变量的存储位置,那么编译器会自动给变量分配存储位置,但是,有些时候,需要将某个变量存放到某个特定的位置,这个时候就可以利用#pragma DATA_SECTION指令了。

    第一步,利用#pragma DATA_SECTION指令将变量xxxCmdBuf关联到SECTIONS“ramdata”;

    #pragma DATA_SECTION(xxxCmdBuf,"ramdata");
    uint16_t xxxCmdBuf[4];

    第二步,修改CMD文件使得“ramdata”映射到指定的地址空间。

    MEMORY
    {
    PAGE 0 :   /* Program Memory */
    ......
    
    PAGE 1 :   /* Data Memory */
    ......
    RAML_XXXCMD     : origin = 0x00BFF0, length = 0x000004     
    }
    ......
    
    SECTIONS
    {
    ......
    ramdata         : > RAML_XXXCMD,   PAGE = 1
    ......
    }

    只需完成上述简单的两步就可以将某个变量指定到特定的位置,一些博文指出采用这种方法时,需要先利用#pragma DATA_SECTION开辟一个空间,然后在定义该空间的大小,即第一步中的两行代码是有先后顺序的。

    TI 的技术文档《Programming TMS320x28xx and 28xxx Peripherals in C/C++》(SPRAA85D–November 2005–Revised January 2013)对该方法也有相应的描述,如下所示。

    The syntax for the DATA_SECTION pragma in C is:
    #pragma DATA_SECTION (symbol,"section name")
    The syntax for the DATA_SECTION pragma in C++ is:
    #pragma DATA_SECTION ("section name")

    Example 5. Assigning Variables to Data Sections

    /********************************************************************
    * Assign variables to data sections using the #pragma compiler statement
    * C and C++ use different forms of the #pragma statement
    * When compiling a C++ program, the compiler will define __cplusplus automatically
    ********************************************************************/
    //----------------------------------------
    #ifdef __cplusplus
    #pragma DATA_SECTION("SciaRegsFile")
    #else
    #pragma DATA_SECTION(SciaRegs,"SciaRegsFile");
    #endif
    volatile struct SCI_REGS SciaRegs;
    //----------------------------------------
    #ifdef __cplusplus
    #pragma DATA_SECTION("ScibRegsFile")
    #else
    #pragma DATA_SECTION(ScibRegs,"ScibRegsFile");
    #endif
    volatile struct SCI_REGS ScibRegs;

    Example 6. Mapping Data Sections to Register Memory Locations

    /********************************************************************
    * Memory linker .cmd file
    * Assign the SCI register-file structures to the corresponding memory
    ********************************************************************/
    MEMORY
    {
    ...
    PAGE 1:
    SCIA : origin = 0x007050, length = 0x000010 /* SCI-A registers */
    SCIB : origin = 0x007750, length = 0x000010 /* SCI-B registers */
    ...
    }
    SECTIONS
    {
    ...
    SciaRegsFile : > SCIA, PAGE = 1
    ScibRegsFile : > SCIB, PAGE = 1
    ...
    }

    利用#pragma CODE_SECTION指令可以将程序从Flash搬到RAM中运行,从而提高程序执行速率,该方法需要完成以下四步。

    第一步,利用#pragma CODE_SECTION指令关联程序和SECTIONS;

    #pragma CODE_SECTION(mainISR,"ramfuncs");

    第二步,为链接创建相关变量;

    // Used for running BackGround in flash, and ISR in RAM
    extern uint16_t *RamfuncsLoadStart, *RamfuncsLoadEnd, *RamfuncsRunStart;

    第三步,复制时间关键代码以及Flash设置代码到RAM;

    // Copy time critical code and Flash setup code to RAM
    // The RamfuncsLoadStart, RamfuncsLoadEnd, and 
    // RamfuncsRunStart symbols are created by the linker. // Refer to the linker files.
    memCopy((uint16_t *)&RamfuncsLoadStart,(uint16_t *)&RamfuncsLoadEnd,(uint16_t *)&RamfuncsRunStart);

    第四步,修改CMD文件。

    SECTIONS
    {
    /* Allocate program areas: */
    ......
    ramfuncs       : LOAD = FLASHD, 
                     RUN = RAML0_1,                                    
                     LOAD_START(_RamfuncsLoadStart),
                     LOAD_END(_RamfuncsLoadEnd),
                     RUN_START(_RamfuncsRunStart),
                     PAGE = 0

    上面代码中,

    LOAD = FLASHD, //指定了要加载程序在Flash里的地址段
    RUN = RAML0_1, //指定了在RAM里运行程序的RAM地址段
    LOAD_START(_RamfuncsLoadStart), // 所要加载程序在Flash里的初始地址
    LOAD_END(_RamfuncsLoadEnd), // 所要加载程序在Flash里的结束地址
    RUN_START(_RamfuncsRunStart), // 程序运行的起始地址



  • 相关阅读:
    sprinboot测试类报错问题(Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...))
    实体类的命名细分
    zuul服务网关
    解决aplication.yml没有图标问题
    用户动态权限菜单管理简单实现方式
    servlet+ajax完成select二级联动/动态传值/查询分页功能
    servlet+jsp实现分页功能
    python——Django之admin的使用
    python-Django连接mysql实现可视化会出现的问题
    python——迭代器、列表解析、三元表达式
  • 原文地址:https://www.cnblogs.com/sdb1942/p/13208810.html
Copyright © 2020-2023  润新知