re-entrant function in Keil-4 RVMDK

Hi friends,

I am new to keil-4 RVMDK & luminary micro lm3s6965. I want to use some functions as re-entrant.

In keil C51, they provide keyword "reentrant", But in RVMDK I didn't find any clue.

Thanks & Regards, Kishore

Reply to
kishor
Loading thread data ...

In message , kishor writes

Have you asked Keil tech support?

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills  Staffs  England     /\/\/\/\/
 Click to see the full signature
Reply to
Chris H

You make a function re-entrant by writing appropriate C code - avoid using shared storage (such as global variables or function-scope statics), avoid calling non-re-entrant functions, etc.

It's only on non-standard compilers for seriously limited processors - such as Keil's C51 compiler - that you will see a "reentrant" keyword. For processors that can efficiently access data on a stack, or with compilers that are smart enough to figure out these things automatically and thus generate good code while following C standards (I don't know if such a compiler exists for the 8051), there is no such thing as a "reentrant" keyword.

Reply to
David Brown

Keil is no more "non-standard" than most other compilers.... GCC for example.

The only sensible compiler for the 8051 is the Keil which has about 80% of the market.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills  Staffs  England     /\/\/\/\/
 Click to see the full signature
Reply to
Chris H

I was wondering if you could resist...

Of course, all embedded compilers have non-standard features - there are things that an embedded C programmer wants to be able to express that cannot be expressed in C (such as interrupt functions, embedded assembly, data in flash or other specific memory areas, etc.).

Additionally, many compilers (embedded or otherwise) have extensions or extra features to help you write smaller, faster, or otherwise better code. They also often allow you to mix features from different standards, such as allowing // comments or inline functions in ANSI C. gcc has plenty of such extensions if you want to use them, as do many (all?) other compilers. But as these are optional, they are not non-standard.

Where Keil's 8051 compiler differs here is that it requires non-standard extension keywords to write code that can be expressed correctly in standard C. Re-entrant functions are not a special embedded feature, but part of the language. If you cannot write a re-entrant (or recursive) function in plain standard C, then the compiler is non-standard in a much more serious way than most other embedded compilers. Of course, it could be that there are command-line switches for Keil that allow any functions to be re-entrant, thus making the compiler more standards compliant (but perhaps generating horrible code).

I have never had to use the 8051, so I don't know the tools in detail. But the little I've seen of code written for either Keil or SDCC for the

8051 has had a mishmash of extra keywords saying whether data is to be placed in registers, internal ram, xdata, or whatever. That's not standard C.

That does not mean there is anything wrong with it, of course - the compiler is a tool to let you write code to run on the target. If it has to be non-standard to let you generate good object code, then that's fair enough.

Reply to
David Brown

Thanks for reply,

I have written some "Ring buffer" operation related function.

Byte FIFO_Write (ST_RING_BUFF * lpstBuff, Byte lbData); Byte Read_Buff (ST_RING_BUFF * lpstBuff);

In above functions I am passing pointer to ring buffer structure, passing or receiving data Byte.

I have two ring buffers for two serial ports.

In following case, If FIFO_Write function is writing data to first Buffer. At the same time if Second serial port ISR interrupts the function. And if it calls the FIFO_Write function, to write data to second buffer.

Is it safe to use these 'common' functions for both the serial port buffer?

Regards, Kishore.

Reply to
kishor

Yes, of course it is safe. This is basic C knowledge. I think perhaps you have been corrupted by working with a hideous compiler* for a hideous chip that can't work with proper C. You may have to read a book on C programming, and you will certainly have to /think/ a bit about what you are writing, how it works, and how it is implemented. Some trial and error, test code, and studying generated assembly code would also help.

  • Keil may be the best compiler available for the 8051, but it is hideous nonetheless.
Reply to
David Brown

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.