TI 28xx 系列c/c++编辑主程序代码注意事项
[复制链接]
编辑主程序代码主程序代码示例: #define APP_MAIN_GLOBALS #i nclude "Sources_DSP\DSP2833x_Device.h" // Device Headerfile and Examples Include File #i nclude "Sources_DSP\DSP2833x_Examples.h" void main(void) { // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example is found in the DSP2833x_SysCtrl.c file. InitSysCtrl(); // Step 2. Initalize GPIO: InitGpio(); InitXintf(); // Step 3. Clear all interrupts and initialize PIE vector table: // Disable CPU interrupts DINT; MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart); InitFlash(); //必须在RAM内完成该操作 // Initialize the PIE control registers to their default state. InitPieCtrl(); // Disable CPU interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0000; InitPieVectTable(); EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.TINT0 = (PINT)&s_Timer0ISR;//定时器0中断 EDIS; PieCtrlRegs.PIEIER1.bit.INTx7 = 1; //定时器0中断使能 IER = M_INT1|M_INT8|M_INT9; EINT; s_InitMAX3100_IRQ(); s_InitMAX3100(0xe40b); //进入应用程序 //s_App(); for(;;); } 对于主程序笔者发现了以下几个问题: 注1:头文件包含要正确地指出相对路径,否则编译器找不到该头文件 #i nclude "Sources_DSP\DSP2833x_Device.h" // Device Headerfile and Examples Include File #i nclude "Sources_DSP\DSP2833x_Examples.h" 注2:如果要初始化FLASH MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart); InitFlash(); //初始化FLASH必须在RAM内完成该操作 可以在“DSP2833x_MemCopy.cpp”文件头上补充:#i nclude "DSP2833x_Examples.h" 因为MemCopy函数是在DSP2833x_Examples.h文件里声明的所以要包含它。否则编译器会报 “_MemCopy( ) is undefined symbo”。不过还有很多其他解决方法。 注3:如果使用外部接口 InitGpio(); InitXintf(); 顺序不能对调了,因为28335的外部接口可以配置为通用I/O,函数InitGpio()就是把它配置为通用IO,如果没有调用InitXintf(),你会发现访问不了外部SRAM!! 如果先调用InitXintf();再调用InitGpio();仍然是把外部接口配置为通用I/O,所以顺序不能对调,也不能不调用InitXintf()。 注4:如果C ++编写代码笔者曾遇到以下几个问题: 1.函数 void InitPieVectTable(void)实体内有一条语句是: Uint32 *Source = (void *) &PieVectTableInit; Uint32 *Dest = (void *) &PieVectTable; 要改为: Uint32 *Source = (Uint32*) &PieVectTableInit; Uint32 *Dest = (Uint32*) &PieVectTable; C允许把任意类型的指针赋值给void值针,也可以把void值针赋值给任意类型的指针,因为C++语法更严谨,不允许这种操作。 2.分配中断向量时要注意: PieVectTable.TINT0 = (PINT)&s_Timer0ISR;//定时器0中断(这是刘刚发现的) 要把中断服务子程序入口地址强制转换成 PINT 型,究其原因和上一个问题是一样的。 3.一个工程里不允许出现既有 “.c”又有“.cpp”,这样会出现诡异的编译报错,编译器会按照c语言来编译,凡是不符合c语法的编译器都会认为是错误的,如果不注意这点,看到一堆error会让人摸不着头。 4.要用Inline 函数时 不是在函数声明前面加关键字Inline,而是在函数实体前面加关键字Inline。例如: inline void s_SysRealySetUp(void) { INT16U i; INT8U uch_RelayBordNum; for(i=0;i { guch_RelayComTransBuf[15+i] = e_guch_RelaySet; } }
|