DSPRelated.com
Forums

Initializations of Processor variables, registers in C or assembly ?? why ?

Started by techie March 12, 2007
Hello all

Im new to the world of embedded systems. I had a basic query.

Im working on a project that requires me to migrate the code for a 16-
bit DSP Processor ( TMS320C50 ) to a 32-bit DSP Processor
( TMS320F2812 ).

All the initializations of the processor peripherals, registers have
been written in Assembly. My predicament is whether i should re-write
all these assembly routines in C for my new 32-bit processor of just
re-write them in assembly ???

Is there a thumb rule that initializations should be done only in
assembly ??? Please give me your opinions ...

regards

techie

>Hello all > >Im new to the world of embedded systems. I had a basic query. > >Im working on a project that requires me to migrate the code for a 16- >bit DSP Processor ( TMS320C50 ) to a 32-bit DSP Processor >( TMS320F2812 ). > >All the initializations of the processor peripherals, registers have >been written in Assembly. My predicament is whether i should re-write >all these assembly routines in C for my new 32-bit processor of just >re-write them in assembly ??? > >Is there a thumb rule that initializations should be done only in >assembly ??? Please give me your opinions ... > >regards > >techie > >
>Is there a thumb rule that initializations should be done only in >assembly ??? Please give me your opinions ...
Without question, you should always initialize you're data, regardless of the language in which you are coding and regardless of your target platform. Most (but not all) compilers will initalize static and global data to a value of zero unless you specify otherwise. That may not be what you want. Stack variables (if you have a stack) will contain "random" junk. Whether you should recode functions in assembly or "C" is another matter. Regards, Mikial
>Hello all > >Im new to the world of embedded systems. I had a basic query. > >Im working on a project that requires me to migrate the code for a 16- >bit DSP Processor ( TMS320C50 ) to a 32-bit DSP Processor >( TMS320F2812 ). > >All the initializations of the processor peripherals, registers have >been written in Assembly. My predicament is whether i should re-write >all these assembly routines in C for my new 32-bit processor of just >re-write them in assembly ??? > >Is there a thumb rule that initializations should be done only in >assembly ??? Please give me your opinions ... > >regards > >techie > >
Techie, Re-reading your post, I originally took it to mean 'do I only have to initialize my data if I am coding in assembly' but you probably meant, 'given that I need to initialize my data should I do it in assembly or 'C''. My advice is this. Generally, if you are recoding in 'C' then initialize in 'C'. If selected functions are to be coded in assembly and their data can be encapsulated then initialize them in assembly. Is your initialization something that can be done at compile time such as assigning values to a table rather than performing some lengthy calculation? If so, there's no performance penalty for using 'C' and the result will look the same in object code. On the other hand if your CPU permits things like hardware supported circular buffers you may have to implement them in assembly -- consult your compiler manual. Keep in mind also that you'll have to be a bit more careful with everything in assembly than in 'C' including alignment of data. Finally ask yourself this, if you ever change CPUs again, will you want to recode things in assembly one more time? Mikial
hello mikial
> > > Re-reading your post, I originally took it to mean 'do I only have to > initialize my data if I am coding in assembly' but you probably meant, > 'given that I need to initialize my data should I do it in assembly or > 'C''.
Bingo, that was what I was asking....
> Finally ask yourself this, if you > ever change CPUs again, will you want to recode things in assembly one more > time? >
Definitely not.. Considering there are no major performance overheads, I wud rather go with C, atleast it makes the code more readable, if someone tries to migrate it down the lane.... Are there any routines that must be in assembly though ??? say for example interrupts and timers etc ... regards techie
How so i set the Data page pointer to a certain memory location in
C ???

i.e, how would i re-write the following assembly instruction in
'C' ???
asm("	ldp	#80h");

Hope to hear from someone soon..

regards

techie

techie wrote:
> Hello all > > Im new to the world of embedded systems. I had a basic query. > > Im working on a project that requires me to migrate the code for a 16- > bit DSP Processor ( TMS320C50 ) to a 32-bit DSP Processor > ( TMS320F2812 ). > > All the initializations of the processor peripherals, registers have > been written in Assembly. My predicament is whether i should re-write > all these assembly routines in C for my new 32-bit processor of just > re-write them in assembly ??? > > Is there a thumb rule that initializations should be done only in > assembly ??? Please give me your opinions ...
High-level languages -- languages, not their compilers -- know nothing of registers or condition flags. Many compilers, especially those intended to produce programs for embedded work, have extensions that do. Even if you can write initialization code that your compiler deals with, it won't be portable ANSI C. It may port across a class of processors. Please yourself. Jerry -- Engineering is the art of making what you want from things you can get. ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
techie wrote:
> How so i set the Data page pointer to a certain memory location in > C ??? > > i.e, how would i re-write the following assembly instruction in > 'C' ??? > asm(" ldp #80h"); > > Hope to hear from someone soon..
Read the compiler manual for your particular processor. If it has pragmas or other constructs that allow you to deal directly with registers, you'll know what they are when you read about them. If not, it's assembly all the way and, for my part, not much loss. Peripheral initialization is all "magic numbers" anyway (Document them well!) and will be different if you ever migrate again. Moreover, even if your present compiler can load constants to control registers, the next one may not. Sometimes, control registers have memory addresses and you can have access to them that way. The still doesn't make the code portable, because some other processor will have different addresses for the registers and they'll need different constants loaded. Jerry -- Engineering is the art of making what you want from things you can get. ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
On Mar 12, 5:14 am, "techie" <techie.embed...@gmail.com> wrote:
> How so i set the Data page pointer to a certain memory location in > C ??? > > i.e, how would i re-write the following assembly instruction in > 'C' ??? > asm(" ldp #80h"); > > Hope to hear from someone soon.. > > regards > > techie
As of several years ago TI provided a set of .h files that defined registers and read/write macros for each peripheral device. Look in your Code Composer source tree for a set of .h files called something like "mcbsp54x.h","dma54x.h", etc (the 54X part will reflect your processor). John
On 12 Mar 2007 02:14:25 -0700, "techie" <techie.embedded@gmail.com>
wrote in comp.dsp:

> How so i set the Data page pointer to a certain memory location in > C ??? > > i.e, how would i re-write the following assembly instruction in > 'C' ??? > asm(" ldp #80h");
No, no, NO!!! Don't do that. The TI 2818, like all the members of he 28xx family, has a mode for running 27xx 16-bit code, BUT DON'T USE IT. Especially not if you're programming in C. Build your code for native 16/32 bit 28xx mode. Use the sample source files TI supplies, see http://focus.ti.com/docs/prod/folders/print/tms320f2812.html if you don't have them already. There are app notes and sample source code for all of the peripherals, you can just customize their source as needed for your application. And you will never need to set the data page pointer, the compiler takes care of it. The C compiler for the 28xx family is really quite good. We have several high-speed real time applications on the 2812 and none of them have move than a few dozen lines of assembly language in the early start up functions.
> Hope to hear from someone soon.. > > regards
-- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://c-faq.com/ comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
On Mar 12, 7:50 am, Jerry Avins <j...@ieee.org> wrote:

> Read the compiler manual for your particular processor. If it has > pragmas or other constructs that allow you to deal directly with > registers, you'll know what they are when you read about them. If not, > it's assembly all the way and, for my part, not much loss. Peripheral > initialization is all "magic numbers" anyway (Document them well!) and > will be different if you ever migrate again. Moreover, even if your > present compiler can load constants to control registers, the next one > may not. > > Sometimes, control registers have memory addresses and you can have > access to them that way. The still doesn't make the code portable, > because some other processor will have different addresses for the > registers and they'll need different constants loaded.
U have made a lot of sense with regards to worries of portability and stuff... Thanks a lot.. U have made a lot of sense. cheers techie