Hi Jon,

Jon Hallsten schrieb:
> Or does interaction with this buffer not require this protection?

If you need "more than byte-wise" access (for interpreting a command)
to the buffer you need some protection.
By handshake/protocol/timing/disabling_IRQ or whatever.
I would not recommend this.

Instead I would use byte-wise access to the buffer using a head
and a tail pointer only. This allows reading/writing from/to
the buffer *without* disabling IRQ.

You could take the function to_buffer() in manual section 3.12
as a starting point:

* You'd "buf [head++] = SBUF;" instead of setting from "c" there,

* add the corresponding function from_buffer(). You may
  also call it getchar();

* add some %32, %=32, or &=32-1 or &(32-1) for pointer wrapping

* add a "buffer empty" or "char available" functionality
  which checks for "head == tail"

* make some tests with buf residing in different memory spaces.
  In increasing order of convenience for the 8051:
  xdata, xdata __at(0xYY00), pdata, idata

Ideally you'd implement a putchar() function too and post
your c-code here.

Even more ideally someone (hey, there are 666 subscribers to this
list!) picks it up and converts it to inline assembler and posts
the optimized code.

Other places to look at are the files in device/lib :
ser_ir.c, serial.c, _ser.c, ser_ir_cts_rts.c

or "The SDCC Open Knowledge Resource" at:
http://sdccokr.dl9sec.de/resources.htm "Code for 8051 series UART"

Actually I like the code there most although one might want to adapt:
make pointers static, remove volatile for rx_tail and tx_head (as
hinted to in the code), rename to getchar() and to putchar(),
remove the using directive for the IRQ (nowadays SDCC doesn't
save the complete register bank for IRQ any more), change
memory space from data to idata or pdata space, use modulo
instead of if directive to wrap the pointers, allow for
different receive/send buffer sizes, remove init_ser()
and the test code in main() and add some hooks for
RS485, half-duplex and hardware handshake...

Greetings,

Frieder

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to