請問#pragma DATA_ALIGN有什么作用?
比如:
int abc;
#pragma DATA_ALIGN(abc, 128)
那么編譯時一定會把abc變量的地址安排在128字節對齊的位置上,也即abc地址的低7位一定為0,
又比如
char efd;
#prgma DATA_ALIGN(efd, 8)
那么編譯時一定會把efd變量的地址安排在8字節對齊的位置上,也即efd地址的低3位一定為0。
pragma DATA_ALIGN是非常有用的,也經常使用的。
(一)#pragma DATA_SECTION 利用CCS進行DSP編程時,如果不指定變量的存儲位置,那么編譯器會自動給變量分配存儲位置,但是,有些時候,需要將某個變量存放到某個特定的位置,這個時候就可以利用#pragma DATA_SECTION指令了。
第一步,利用#pragma DATA_SECTION指令將變量xxxCmdBuf關聯到SECTIONS“ramdata”;
#pragma DATA_SECTION(xxxCmdBuf,"ramdata"); uint16_t xxxCmdBuf[4];12
第二步,修改CMD文件使得“ramdata”映射到指定的地址空間。
MEMORY { PAGE 0 : /* Program Memory */ ......
PAGE 1 : /* Data Memory */ ...... RAML_XXXCMD : origin = 0x00BFF0, length = 0x000004 } ......
SECTIONS { ...... ramdata : > RAML_XXXCMD, PAGE = 1 ...... }1234567891011121314151617
只需完成上述簡單的兩步就可以將某個變量指定到特定的位置,一些博文指出采用這種方法時,需要先利用#pragma DATA_SECTION開辟一個空間,然后在定義該空間的大小,即第一步中的兩行代碼是有先后順序的。
TI 的技術文檔《Programming TMS320x28xx and 28xxx Peripherals in C/C++》(SPRAA85D–November 2005–Revised January 2013)對該方法也有相應的描述,如下所示。
(二)#pragma CODE_SECTION 利用#pragma CODE_SECTION指令可以將程序從Flash搬到RAM中運行,從而提高程序執行速率,該方法需要完成以下四步。
第一步,利用#pragma CODE_SECTION指令關聯程序和SECTIONS;
#pragma CODE_SECTION(mainISR,"ramfuncs");1
第二步,為鏈接創建相關變量;
// Used for running BackGround in flash, and ISR in RAM extern uint16_t *RamfuncsLoadStart, *RamfuncsLoadEnd, *RamfuncsRunStart;12
第三步,復制時間關鍵代碼以及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);1234
第四步,修改CMD文件。
SECTIONS { /* Allocate program areas: */ ...... ramfuncs : LOAD = FLASHD, RUN = RAML0_1, LOAD_START(_RamfuncsLoadStart), LOAD_END(_RamfuncsLoadEnd), RUN_START(_RamfuncsRunStart), PAGE = 0 1234567891011
上面代碼中, LOAD = FLASHD, //指定了要加載程序在Flash里的地址段 RUN = RAML0_1, //指定了在RAM里運行程序的RAM地址段 LOAD_START(_RamfuncsLoadStart), // 所要加載程序在Flash里的初始地址 LOAD_END(_RamfuncsLoadEnd), // 所要加載程序在Flash里的結束地址 RUN_START(_RamfuncsRunStart), // 程序運行的起始地址 --------------------- 作者:Ronnie_Hu 來源:CSDN 原文:https://blog.csdn.net/Ronnie_Hu/article/details/74075090 版權聲明:本文為博主原創文章,轉載請附上博文鏈接!