您的位置:首页 > 其它

为C6713建立一个简单的工程

2013-08-03 16:36 375 查看
今天下载了CCS的最新版本5.4,建立了一个乘加的c工程。CCS5.4只需添加一个main.c就可以编译生成out文件了,很方便。

int main(void) {
int a[]={1,2,3,4,5};
int x[]={5,4,3,2,1};

int i=0;
int sum = 0;
for(i = 0; i < 5; i++)
{
sum += a[i]*x[i];
}

;
return 0;
}


好久不用CCS3.3,今天用它建立一个基于C6713的c工程,因为时间有点久了,居然费了不好周折。看来还是得总结出来,不然容易忘。

除了main.c,还需要cmd文件,asm文件和rts lib文件,否则会报错。



由此产生一个问题,_c_int00的作用是什么?(一下网上收集)

在DSP启动后,系统会进入复位中断,此时复位中断服务函数为c_init00,此函数用于建立C环境,为进入main()函数进行系统初始化,主要工作是建立堆栈,初始化全局变量等。

全局变量的初始化:如果程序在链接时采用-c选项,则编译链接后的可执行程序会将全局变量的初始化放在c_init00()函数中进行,在此函数中会调用_auto_init(CINIT)函数,将.cinit段的内容拷入.bss中相应的变量中,此过程是在系统上电后进入main()函数之前执行的。

如果程序在链接时采用-cr选项,则编译后的可执行程序中全局变量需要使用loader进行初始化,这种方法一般用于在JTAG调试时,CCS即为loader。

一下是c_int00的代码,来自rts.src

/*****************************************************************************/
/* C_INT00() - C ENVIRONMENT ENTRY POINT                                     */
/*****************************************************************************/
extern void __interrupt c_int00()
{

/*------------------------------------------------------------------------*/
/* SET UP THE STACK POINTER IN B15.                                       */
/* THE STACK POINTER POINTS 1 WORD PAST THE TOP OF THE STACK, SO SUBTRACT */
/* 1 WORD FROM THE SIZE. ALSO THE SP MUST BE ALIGNED ON AN 8-BYTE BOUNDARY*/
/*------------------------------------------------------------------------*/
__asm("\t   MVKL\t\t   __stack + __STACK_SIZE - 4, SP");
__asm("\t   MVKH\t\t   __stack + __STACK_SIZE - 4, SP");
__asm("\t   AND\t\t   ~7,SP,SP");

/*------------------------------------------------------------------------*/
/* SET UP THE GLOBAL PAGE POINTER IN B14.                                 */
/*------------------------------------------------------------------------*/
__asm("\t   MVKL\t\t   $bss,DP");
__asm("\t   MVKH\t\t   $bss,DP");

/*------------------------------------------------------------------------*/
/* SET UP FLOATING POINT REGISTERS FOR C6700                              */
/*------------------------------------------------------------------------*/
#ifdef _TMS320C6700
FADCR = 0; FMCR  = 0;
#endif

/*------------------------------------------------------------------------*/
/* CALL THE AUTOINITIALIZATION ROUTINE.                                   */
/*------------------------------------------------------------------------*/
_auto_init(CINIT);

_args_main();

/*------------------------------------------------------------------------*/
/* CALL EXIT.                                                             */
/*------------------------------------------------------------------------*/
exit(1);
}


args_main.c/    1162235705  0     0     0       1930      `
/******************************************************************************/
/* The ARGS data structure is defined according to a convention with linker.  */
/*                                                                            */
/* If the user want to pass arguments to loader, "--args=###" option has to   */
/* be used in linking to generate executable. With this option, the linker    */
/* will allocate a section starting with __c_args__, and with this "###" many */
/* bytes. The loader when parses the arguments, will dump the number of       */
/* arguments, argc as the 1st arguments at address __c_args__, all the actual */
/* arguments will be dumped after that. The total space for these arguments   */
/* will not exceed "###" bytes.                                               */
/*                                                                            */
/* if "--args="###" is not used as a linker option, linker will put -1 at     */
/* __c_args__ location.                                                       */
/*                                                                            */
/* Based on the above convention, the following code implements the access to */
/* these arguments when main is called.                                       */
/*                                                                            */
/* This function is called from boot.asm or boot.c.                           */
/******************************************************************************/

typedef struct { int argc; char *argv[1]; } ARGS;
extern ARGS __c_args__;

extern far int main(int argc, char *argv[]);

int _args_main()
{
register ARGS *pargs = &__c_args__;
register int    argc = 0;
register char **argv = 0;

if (pargs != (ARGS *)-1)
{ argc = pargs->argc; argv = pargs->argv; }

return main(argc, argv);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: