Shop OBEX P1 Docs P2 Docs Learn Events
Is there any buffer overflow prevention on FullDuplexSerial? — Parallax Forums

Is there any buffer overflow prevention on FullDuplexSerial?

Sniper KingSniper King Posts: 221
edited 2013-07-30 14:57 in Propeller 1
I started this thread as a sister to my other thread because this could affect everybody.· I haven't started learning the Spin Assembly so I can't check this.· But I am narrowing my problem down to this.·

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··


Michael King
Application Engineer
R&D

Check out Project: PSAV Persistent Sailing Autonomous Vehicle

Comments

  • Ken PetersonKen Peterson Posts: 806
    edited 2008-09-22 18:04
    Not sure what you mean by overflow prevention.· I believe FDS simply ignores incoming characters if the buffer is full.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"I have always wished that my computer would be as easy to use as my telephone.· My wish has come true.· I no longer know how to use my telephone."

    - Bjarne Stroustrup
  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2008-09-22 18:10
    There is no flow control built it.

    You could implement software flow control in your code that uses FDS. Getting hardware flow control would require more pins (and hardware modification depending on what board you are using).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out the Propeller Wiki·and contribute if you can.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-22 18:56
    There is a 4 channel full duplex serial driver recently posted to the Object Exchange. I believe it has hardware flow control as a selectable option.

    The standard FullDuplexSerial object discards the oldest character in the receive buffer if it receives a new character and the buffer is full.
    The buffer size is easily increased to any power of two by changing a couple of lines of code. The version of FullDuplexSerial used in BoeBotBasic has been modified to be able to set the buffer size with a constant definition in one place.
  • StefanL38StefanL38 Posts: 2,292
    edited 2008-09-22 19:39
    Hello Michael,

    if you changeover from FullDuplexSerial to SerialMirror from the obex you can increase the buffer to several kB
    as serialmirror does not use COG-RAM for the buffer but HUB-RAM where you have 32kB minus "your SPIN-tokens" as memory

    best regards

    Stefan
  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2008-09-22 19:45
    FullDuplexSerial also uses hub memory for the send and receive buffers.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out the Propeller Wiki·and contribute if you can.
  • dbpagedbpage Posts: 217
    edited 2008-09-24 13:36
    I have found that the compiler imposes a limit of $1FF for FullDuplexSerial buffer size.

    It appears to me that the head/tail buffer pointers wrap around on overflow and ignore previously received characters.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dennis B. Page, Page Radio Company
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-24 14:36
    The FDS source uses an immediate value for the bit mask used to handle wraparound for the buffer pointers.
    There is a limit of $1FF for any immediate value. You would need to change the few instructions that use these
    bit masks to use a direct value (not immediate) and define the transmit and receive wraparound bit masks as
    32-bit constants. That would allow larger buffer sizes to be used.

    Yes, the head/tail buffer pointers wrap around. If the buffer is full and a new character is received, the oldest
    character in the buffer is overstored. There's no provision for reporting that an overrun condition occurred.
    It's possible for you or someone else to add this feature and it's possible to change the behavior of the driver
    when an overrun occurs, but this is not a "full service" UART simulator. Most programs don't check for receive
    overrun. There is a modified FDS in the Object Exchange that has an option for hardware flow control.
  • dbpagedbpage Posts: 217
    edited 2008-09-24 16:51
    Thank you for the helpful advice.

    It appears to me that if the buffer is full and a new character is received, and the oldest character in the buffer is overstored, FDS returns only the new character and none of the older characters, effectively losing the older characters.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dennis B. Page, Page Radio Company
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-24 17:28
    Yes, that's true, because the head pointer (pointing to where the next character goes) passes the tail pointer (pointing to where the next character is to remove from the buffer).
  • dbpagedbpage Posts: 217
    edited 2008-09-24 19:11
    So, the correct explanation is that if the buffer is full and a character is received, the buffer is discarded and replaced with the new character. With a few more code changes, an internal overflow detector could permit all characters to be returned, except for those that have been overwritten, and still not report the overflow.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dennis B. Page, Page Radio Company
  • coryco2coryco2 Posts: 107
    edited 2013-07-30 14:39
    Mike Green wrote: »
    The FDS source uses an immediate value for the bit mask used to handle wraparound for the buffer pointers.
    There is a limit of $1FF for any immediate value. You would need to change the few instructions that use these
    bit masks to use a direct value (not immediate) and define the transmit and receive wraparound bit masks as
    32-bit constants. That would allow larger buffer sizes to be used.

    Could you please explain this in a bit more neophyte language? I would like to increase the size of the FDS buffer, but I'm not understanding what changes need to be made. Thanks!
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-07-30 14:57
    It's relatively easy to change the buffer size in PST. IIRC FDS has several locations where numbers need to be changed (both in Spin code and PASM code). Tracy Allen's four port driver is also easy to change and the buffers don't need to be powers of two.

    I post #2 of my index, one of the projects listed was to expand the buffers in Tim Moore's driver (here's a link). There is some discussion in the thread about what is required to increase buffer sizes.
Sign In or Register to comment.