2022年DSP的C语言编程 .pdf





《2022年DSP的C语言编程 .pdf》由会员分享,可在线阅读,更多相关《2022年DSP的C语言编程 .pdf(17页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、DSP的 C语言开发一、流程步骤:Resetvectors.asmc_int00(位于rts.lib 中)_args_main()(位于 rts.lib 中)调用 main()1、配置 CPU相关寄存器2、初始化时钟和PLL3、配置相关外设寄存器4、设置中断(一关二设三开)main() 开始主要程序返回 c_int00下面是 vectors.asm函数,该文件在每个DSP的 project 中(需手工加入),其中有对_c_int00的调用, 而_c_int00在 rts.lib 中, 在开发时要手工加入。在 reset后, rom 等外存中的程序已经转移到了L2 cache中, 并且程序从 0
2、 x0000 0000处开始执行,而 0 x0000 0000处的程序正是 vectors.asm,以下就开始层层调用,进入 main 函数。= vectors.asm = 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 17 页 - - - - - - - - - ; Plug in the entry point at RESET in the interrupt vector table ; ; ; = unused = ; plug inifinite loop
3、- with nested branches to ; disable interrupts - for all undefined vectors ; unused .macro id .global unused:id: unused:id: b unused:id: ; nested branches to block interrupts nop 4 b unused:id: nop nop nop nop nop .endm .sect .vectors .ref _c_int00 ; C entry point .align 32*8*4 ; must be aligned on
4、256 word boundary RESET: ; reset vector mvkl _c_int00,b0 ; load destination function address to b0 mvkh _c_int00,b0 b b0 ; start branch to destination function mvc PCE1,b0 ; address of interrupt vectors mvc b0,ISTP ; set table to point here nop 3 ; fill delay slot nop nop ; ; plug unused interrupts
5、with infinite loops to ; catch stray interrupts ; unused 1 unused 2 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 17 页 - - - - - - - - - unused 3 unused 4 unused 5 unused 6 unused 7 unused 8 unused 9 unused 10 unused 11 unused 12 unused 13 unused 14 unused 15
6、Rts6000.lib来自于 rts6000.src, 该原文件是由多个 .c和.cpp以及.asm组成的,其中关于int _args_main()的函数:这个函数就是void _interrupt c_int00()在初始化完成后调用的函数,int _args_main()函数中调用了main(argc, argv)从而正式转入main 函数。args_main.c/ 1162235705 0 0 0 1930 /*/ /* The ARGS data structure is defined according to a convention with linker. */ /* */ /
7、* 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 */
8、 /* 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. */ /* */ /*
9、 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 *argv1; ARGS; extern ARGS _c_args_; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - -
10、- - - - - 名师精心整理 - - - - - - - 第 3 页,共 17 页 - - - - - - - - - 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); 以下是 boot
11、.c 文件:其中有extern void _interrupt c_int00()进行 C环境的初始化,比如堆栈的建立等,以及对main 函数的调用。boot.c/ 1162235706 0 0 0 3018 /*/ /* BOOT.C v6.0.8 - Initialize the C60 C runtime environment */ /* Copyright (c) 1993-2006 Texas Instruments Incorporated */ /*/ #include #define CINIT (void*)&_cinit_) extern far int _cinit_;
12、 extern far int _args_main(); extern far void exit(int status); extern far void _auto_init(const void *cinit); /*-*/ /* ALLOCATE THE MEMORY FOR THE SYSTEM STACK. THIS SECTION WILL BE SIZED */ /* BY THE LINKER. */ /*-*/ _asm(t.global _STACK_SIZE); #pragma DATA_ALIGN (_stack, 8); #pragma DATA_SECTION
13、(_stack, .stack); char _stack8; /*/ /* C_INT00() - C ENVIRONMENT ENTRY POINT */ /*/ 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 17 页 - - - - - - - - - extern void _interrupt c_int00() /*-*/ /* SET UP THE STACK POINTER IN B15. */ /* THE STACK POINTER POINTS 1
14、 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 MVKLtt _stack + _STACK_SIZE - 4, SP); _asm(t MVKHtt _stack + _STACK_SIZE - 4, SP); _asm(t ANDtt 7,SP,SP); /*-*/ /* SET UP THE GLOBAL PAGE POINTER IN B14. */ /*-*/
15、 _asm(t MVKLtt $bss,DP); _asm(t MVKHtt $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); 通过以上步骤就完成了C语言环境的初
16、始化,并且自动进入到 main函数中,当然,main 函数执行结束后,又会返回到void _interrupt c_int00()中,参看上面黄色标记部分。二、需要文件:这里是不使用 BIOS和 csl库时的方法。1)gel文件: CCS调试时使用,因为不用reset,主要是 startup 程序。/* 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 17 页 - - - - - - - - - * This GEL file (init6x0 x.gel) is loa
17、ded on the command line * of Code Composer. It provides example code on how to * reset the C6x DSP and initialize the External Memory Interface. * * You may have to edit settings in emif_init() to your own * specifications as the example is applicable to the C6x EVM. * */ /* * The StartUp() function
18、 is called every time you start * Code Composer. You can customize this function to * initialize wait states in the EMIF or to perform * other initialization. */ StartUp() /* C6201 map1 specific memory mapping */ GEL_MapOn(); GEL_MapReset(); GEL_MapAdd(0 x00000000, 0, 0 x00010000, 1, 1); /* Internal
19、 Program RAM */ GEL_MapAdd(0 x00400000, 0, 0 x00c00000, 1, 1); /* External Memory Interface CE0 */ GEL_MapAdd(0 x01000000, 0, 0 x00400000, 1, 1); /* External Memory Interface CE0 */ GEL_MapAdd(0 x01400000, 0, 0 x00010000, 1, 1); /* External Memory Interface CE1 */ GEL_MapAdd(0 x01410000, 0, 0 x003f0
20、000, 1, 1); /* External Memory Interface CE1 */ GEL_MapAdd(0 x01800000, 0, 0 x00000024, 1, 1); /* Internal Peripheral Bus EMIF Registers */ GEL_MapAdd(0 x01840000, 0, 0 x00000074, 1, 1); /* Internal Peripheral Bus DMA Controller Registers */ GEL_MapAdd(0 x018c0000, 0, 0 x00000028, 1, 1); /* Internal
21、 Peripheral Bus McBSP0 Registers */ GEL_MapAdd(0 x01900000, 0, 0 x00000028, 1, 1); /* Internal Peripheral Bus McBSP1 Registers */ GEL_MapAdd(0 x01940000, 0, 0 x0000000c, 1, 1); /* Internal Peripheral Bus Timer0 Registers */ GEL_MapAdd(0 x01980000, 0, 0 x0000000c, 1, 1); /* Internal Peripheral Bus Ti
22、mer1 Registers */ GEL_MapAdd(0 x019c0000, 0, 0 x0000000c, 1, 1); /* Internal Peripheral Bus Interrupt Selector Registers */ GEL_MapAdd(0 x02000000, 0, 0 x01000000, 1, 1); /* External Memory Interface CE2 */ GEL_MapAdd(0 x03000000, 0, 0 x01000000, 1, 1); /* External Memory Interface CE3 */ GEL_MapAdd
23、(0 x80000000, 0, 0 x00010000, 1, 1); /* Internal Data RAM */ OnTargetConnect() 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 17 页 - - - - - - - - - /* initialize the EMIF registers on the C6x when Code Composer starts up */ emif_init(); /* OnReset callback fun
24、ction called after the target processor has been reset */ OnReset(int nErrorCode) if (nErrorCode) GEL_TextOut(An error occured while resetting -%d-n,nErrorCode); else emif_init(); /* * Menuitem creates a selection available beneath the GEL * menu selection in Code Composer Studio. */ menuitem Resets
25、; hotmenu Reset_and_EMIF_Setup() GEL_Reset(); emif_init(); hotmenu Reset_EMIFset_and_ClearBreakPts() GEL_Reset(); emif_init(); GEL_BreakPtReset(); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 17 页 - - - - - - - - - /*/ emif_init() /*-*/ /* EMIF REGISTER VALUE
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年DSP的C语言编程 2022 DSP 语言 编程

限制150内