From: kishor on
Thanks for reply,

> 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.
>
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.

From: David Brown on
On 01/06/2010 10:17, kishor wrote:
> Thanks for reply,
>
>> 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.
>>
> 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?
>

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.