找回密码
 注册
关于网站域名变更的通知
查看: 904|回复: 2
打印 上一主题 下一主题

【TI C2000的使用经验】CMD文件解读&从flash里搬运RAM函数

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2016-6-28 15:07 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

EDA365欢迎您登录!

您需要 登录 才可以下载或查看,没有帐号?注册

x
首先每个数据段的存放位置,以及运行位置都是在cmd文件里面存放控制的。例如下面一段:% c! H, v$ S# J) A2 e0 \
   .cinit                        :        LOAD = FLASHC,        PAGE = 0        /* Load section to Flash */ 9 b/ l3 U) V/ z/ O; t
             RUN = RAML6,             PAGE = 1    /* Run section from RAM */
; G. h& W$ [- j7 }' J+ R             LOAD_START(_cinit_loadstart),
4 C5 T; ?5 i" y$ s             RUN_START(_cinit_runstart),: E: A" [7 O1 o! f$ E6 ~
             SIZE(_cinit_size)
6 M! i6 G2 u) ~6 D复制代码7 h5 L6 }5 x4 F  `( i. _6 c0 ~
我们就可以看到.cinit这个段。存放在flashC段里。运行的会把函数拷贝到RAML6段里来运行。后面的三行表示存储的起始位置,运行的起始位置,以及该函数的长度。- x( j$ N# z9 [# N! d5 g
有了这些就够了。如果不能保证DSP在下载程序后不会掉电,那么程序就要烧写在flash里。运行的时候呢。要么就拷贝到RAM里,要么就直接在flash里面跑。拷贝到RAM里又要看你程序会不会比较大,可以只拷贝一部分还是全部都拷进去。% J" t" t' Q% z
那么本文后半部分就讲全部拷贝的方法。6 I7 o. I2 d) P" O3 A
首先我们来看F2806x_CodeStartBranch.asm这个文件。
8 F% {2 H- V' h. H1 _***********************************************************************
2 N2 O* N7 g2 i/ N* Function: codestart section
5 I, }8 S/ Z6 V3 u& a- C7 h3 Z** q! I+ ]; o& @0 |9 E2 O( [
* Description: Branch to code starting point
. ~5 D( `& p. R* g***********************************************************************, m- O3 h* W0 V' t

4 t. C4 U% y9 X* A3 x) w  n+ m    .sect "codestart") X. \( ?1 k( ]3 y( m
, ^/ A; i2 q! z+ _: Z/ [# ~) E! Y
code_start:; @2 E& C- J5 t; S1 t8 d. q- k: z
    .if WD_DISABLE == 1" }6 ?4 h2 X' ]1 e5 L
        LB wd_disable       ;Branch to watchdog disable code0 i# z9 ]( t2 n4 d( o/ s" U0 |0 f* f
    .else
5 i! S6 i6 V# ]) t        LB _c_int00         ;Branch to start of boot.asm in RTS library
$ ]8 l6 z9 N. ]; v* ]: i5 ?    .endif
5 U& t+ M2 I! a' f- N6 v, b2 M6 ?" N- R+ Y! @
;end codestart section
* P# v6 a. Y$ |5 K9 G5 L复制代码
- A4 `( L4 |/ d" Y! EcontrolSUITE默认的文件呢是这个样子的。先关看门狗,然后在跳转到c_int00开始执行。当然这些都是在main执行之前做的事。9 x4 l) m% A2 |% i( W6 c( G; R3 q
0 ?- i5 U( d( W$ q4 }& N/ I
那么我们就把这句话改掉。让他跳转到另一个地方去。( L- ^& H' r4 D- U3 Y7 T* j
    .sect "codestart"
) v* F% L# @! x. ?+ S1 n6 D+ R0 v2 q) n" R% m8 O# [) h6 h
code_start:
9 {' N* U3 Q1 ?/ t% G4 |# }- i    .if WD_DISABLE == 1
9 c9 p! \% k, V/ f2 H1 E2 w0 S        LB wd_disable       ;Branch to watchdog disable code* P3 c1 l* r; s2 O# Y
    .else
6 L4 T0 ]5 Q4 ]        LB copy_sections    ;Branch to copy_sections9 H! s/ z6 N; X8 W0 s
    .endif
& X! H/ U( p7 |2 A- t复制代码
9 d/ P- \) _2 o7 t. C+ U跳转到哪里去呢?我们就需要另一个文件给我们指示F2806x_SectionCopy_nonBIOS.asm4 h' M: r- D( C: S8 S: S! F
;############################################################################
4 G; h% m( o0 B2 K/ A6 c;
3 @- _- t; Z8 f4 y; FILE:   DSP28xxx_SectionCopy_nonBIOS.asm- u2 A& q) r, F! [. t5 `
;
! l# ^; y8 ^1 T: x0 f; DESCRIPTION:  Provides functionality for copying intialized sections from , u& K! G4 R: A7 Y2 J
;                                flash to ram at runtime before entering the _c_int00 startup
/ [: U( H' Z# P  r;                                routine
/ P6 P4 d5 K' b; |: w3 a+ v) A: u$ w;############################################################################8 z; B# g6 ^+ D4 |1 U8 W- r
; Author: Tim Love2 L. X9 H7 N6 y  \8 C
; Release Date: March 2008        9 E4 s% ?3 O# e) i; g& V
;############################################################################7 U3 Z1 S8 @* e7 W* R
/ Y1 M9 L7 ^- S; m* G

# O+ L: [- s8 ?, p8 l        .ref _c_int00
4 V' c. `6 v! R! g        .global copy_sections  d$ V( N. N6 w3 V7 d) F3 w
        .global _cinit_loadstart, _cinit_runstart, _cinit_size! [! `/ B- K7 e0 T) N% Y0 H
        .global _const_loadstart, _const_runstart, _const_size
$ L" I" Y* K+ }$ n        .global _econst_loadstart, _econst_runstart, _econst_size
, a9 Z( p5 j! r2 E2 b7 r5 m0 G& k        .global _pinit_loadstart, _pinit_runstart, _pinit_size
' d4 W' m. w# R, X+ H; a        .global _switch_loadstart, _switch_runstart, _switch_size3 G5 R( b2 M- m3 q
        .global _text_loadstart, _text_runstart, _text_size
% i4 E+ _  w* h0 L4 w        .global _cla_loadstart, _cla_runstart, _cla_size
( n: y5 l9 d* S        
& D3 E' ]& z9 t***********************************************************************
' Z4 \( q/ N  X. W* Function: copy_sections
4 O: x- v! y* \# n' ^2 y*
% C! g8 P# g! z* Description: Copies initialized sections from flash to ram0 T% o2 k- W$ j9 [/ f3 R
***********************************************************************
9 Z, K  r& S6 O, W/ {, ^4 c+ @/ Z( R2 p6 ]/ C! r
        .sect "copysections"
+ p, i8 j1 p0 L) q
9 t* I, }& v' S6 h, x0 G" gcopy_sections:
7 R+ _2 S- n! i4 n# J; r! s
1 [2 {/ Z8 J+ l0 C        MOVL XAR5,#_const_size                                ; Store Section Size in XAR5' R& S! E- y2 y; W
        MOVL ACC,@XAR5                                                ; Move Section Size to ACC
8 V; u* v3 z$ _4 E2 L        MOVL XAR6,#_const_loadstart                        ; Store Load Starting Address in XAR6
) o* b% H3 Z: h$ M% ]    MOVL XAR7,#_const_runstart                        ; Store Run Address in XAR7
2 D/ D. y2 _. M& s) M- ?, q3 v6 Y    LCR  copy                                                        ; Branch to Copy+ P: d) ~6 W8 x4 d% j- O7 K1 V
    $ }( T( ], e" M, @& u3 G0 Y6 m( s
        MOVL XAR5,#_econst_size                                ; Store Section Size in XAR5
8 a$ [9 ]# I* i8 J3 Q2 ?        MOVL ACC,@XAR5                                                ; Move Section Size to ACC
7 D) |1 x- f: K8 K; C' _+ Z8 F# U        MOVL XAR6,#_econst_loadstart                ; Store Load Starting Address in XAR65 V4 V4 V. K9 w* A. O
    MOVL XAR7,#_econst_runstart                        ; Store Run Address in XAR7, H1 A7 \1 V% N+ @% T& @
    LCR  copy                                                        ; Branch to Copy
8 _3 ^) y1 `, j, y. |" H% g3 x% A) t* |5 k6 }
        MOVL XAR5,#_pinit_size                                ; Store Section Size in XAR59 h% V  L4 {6 l+ N. K$ f. h
        MOVL ACC,@XAR5                                                ; Move Section Size to ACC7 {3 r7 k4 ~/ r, L
        MOVL XAR6,#_pinit_loadstart                        ; Store Load Starting Address in XAR6) h# J8 j% ?/ `& A& w
    MOVL XAR7,#_pinit_runstart                        ; Store Run Address in XAR7
; w+ C9 Z. t" [6 S    LCR  copy                                                        ; Branch to Copy
+ M9 |6 U  y! {- V
9 c' ]* z. `, z* T) u' P        MOVL XAR5,#_switch_size                                ; Store Section Size in XAR5: e# @+ b/ S9 u
        MOVL ACC,@XAR5                                                ; Move Section Size to ACC
# g( o- x3 u% d7 M! |( @; v7 C5 Z& g6 C' T        MOVL XAR6,#_switch_loadstart                ; Store Load Starting Address in XAR6. @) \7 ?: v2 q7 x( \, r7 s
    MOVL XAR7,#_switch_runstart                        ; Store Run Address in XAR7
) W1 d- C. Z& p& a    LCR  copy                                                        ; Branch to Copy' x) S$ o4 r/ ]& t( |. t

3 l2 o. s4 u% N& f# u1 j2 y; L- J        MOVL XAR5,#_text_size                                ; Store Section Size in XAR5% t# j2 d, O# O3 t
        MOVL ACC,@XAR5                                                ; Move Section Size to ACC
: t, _9 N- i. c        MOVL XAR6,#_text_loadstart                        ; Store Load Starting Address in XAR6# U8 I+ X/ f0 f
    MOVL XAR7,#_text_runstart                        ; Store Run Address in XAR7& }2 U/ L3 x$ E
    LCR  copy                                                        ; Branch to Copy
2 D( e+ v6 P( \. _! G0 e    # @2 C9 T3 N  _, N' F9 o
           MOVL XAR5,#_cinit_size                                ; Store Section Size in XAR5
4 F) x( l( B: r2 K        MOVL ACC,@XAR5                                                ; Move Section Size to ACC5 t# B' N& u- o- c- M
        MOVL XAR6,#_cinit_loadstart                        ; Store Load Starting Address in XAR6/ u- P1 O3 D5 W4 ?2 D' B) {0 D
    MOVL XAR7,#_cinit_runstart                        ; Store Run Address in XAR7$ [5 t9 B' O  L9 c
    LCR  copy                                                        ; Branch to Copy
! v9 A. R* K; d) v2 B) G$ G3 u
- S" V6 V/ {2 p( Z; y$ C$ u6 Y# Q    MOVL XAR5,#_cla_size                                ; Store Section Size in XAR5
2 v. Y7 ]+ t  J        MOVL ACC,@XAR5                                                ; Move Section Size to ACC- |1 j4 e6 w# t- H. E- S0 Z1 ]- [
        MOVL XAR6,#_cla_loadstart                ; Store Load Starting Address in XAR6$ ?5 _5 r. W2 N5 Q. x: Y
    MOVL XAR7,#_cla_runstart                        ; Store Run Address in XAR78 l2 ]$ _1 z6 ]: }& T7 q$ C. y
    LCR  copy                                                        ; Branch to Copy9 A  R, C6 q# j6 Y" w4 c
" w  }3 _4 j/ k# g4 J/ B
    LB _c_int00                                                         ; Branch to start of boot.asm in RTS library
" G4 I7 z+ @4 x" Z" n. Y' m  U5 ~( g4 r/ N6 _. D% P5 W3 z0 q
copy:        
" F5 Y9 f- e; }: N& S) ?* ?: s        B return,EQ                                                        ; Return if ACC is Zero (No section to copy)6 H! S) o# A" H  B
1 a' m# A- o7 v. T  M
    RPT AL                                                                ; Copy Section From Load Address to8 Y5 h: Z5 i9 ?. ~* J% y/ t
    || PWRITE  *XAR7, *XAR6++                        ; Run Address+ d" {/ Q( s+ M! i

. `. r  X, f/ A; i+ z. {; Zreturn:
4 d# H  I3 P8 q7 [' z        LRETR                                                                ; Return9 s1 `& z- z4 \  p' `" v

9 W" v' m% V, w+ z$ n5 b& b        .end$ t8 c+ e1 K$ U/ Y! i0 P2 ^
        
" U# V2 y8 C' B# K9 |;//===========================================================================
- G" ?/ W) A5 j! k- Z;// End of file.
1 {% l8 u8 C/ V- l;//===========================================================================  \# v' H: W( ]! g; O( G
复制代码
/ w2 T) D1 y0 w- t# ]4 _
- g" ~; r' `" B$ k( C' |% ~6 K3 K看到这个文件比较长,但其实是一直在重复。每段里是先把某一个程序段的长度给ACC,然后把存储起始地址,运行起始地址给XAR6,XAR7。然后就是拷贝。, C; @; c& ]1 R
然后所有的数据段都拷贝完了,在跳转会c_int00继续执行。0 B& @! z4 l0 i1 }6 a* `; }
这样就完成啦。是不是很简单。+ |$ n6 A% d& g. p. P5 G: A

该用户从未签到

2#
 楼主| 发表于 2016-6-28 15:08 | 只看该作者
看贴学心得,回贴是美德7 W$ ?( X6 b) d' ]

该用户从未签到

3#
发表于 2016-6-29 10:36 | 只看该作者
好人啊 感恩感恩
; O& W; ~4 w4 x. j! {+ j, [% O
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

推荐内容上一条 /1 下一条

EDA365公众号

关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

GMT+8, 2025-7-19 16:36 , Processed in 0.125000 second(s), 23 queries , Gzip On.

深圳市墨知创新科技有限公司

地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

快速回复 返回顶部 返回列表