Shop OBEX P1 Docs P2 Docs Learn Events
FullDuplexSerial and clone objects GOTCHA: Use caution when changing buffer siz — Parallax Forums

FullDuplexSerial and clone objects GOTCHA: Use caution when changing buffer siz

Chuck RiceChuck Rice Posts: 210
edited 2009-04-18 15:03 in Propeller 1
I ran into this a long time ago, but I just noticed that many of the FullDuplexSerial clones people are using still suffer from this problem. I think that Mike Green pointed me to the problem and the fix long ago, but I still run into it all the time. The code says that you can increase the buffer size by changing the BUFFER_LENGTH constant. Sounds good, but if you do, you will see strange and mysterious behavior. This is because only part of the code uses the constant. Other places hard code the 16 ($10) in, so if you change the 16, the operations will be mismatched. The following show the problem and the patches that need to be made to fix whatever variant you are using.

.CON
.
.  '' Default BUFFER_LENGTH is 16, adjust the BUFFER_LENGTH constant
.  '' in the object for larger buffer sizes.
.  BUFFER_LENGTH = 16
.





As long as you leave the BUFFER_LENGTH set to 16, everything is ok, but if you change it to say, 128, the code fails in mysterious ways. You need to make the following changes:

.--------------------------------------------------------------------
.Change:
.  '' Default BUFFER_LENGTH is 16, adjust the BUFFER_LENGTH constant
.  '' in the object for larger buffer sizes.
.  BUFFER_LENGTH = 16
.
.To:
.  buffer_length = 128          'can be 2, 4, 8, 16, 32, 64, 128, 256
.  buffer_mask   = buffer_length - 1
.
.--------------------------------------------------------------------
.Change:
.    rx_tail := (rx_tail + 1) & $F
.
.To:
.    rx_tail := (rx_tail + 1) & buffer_mask
.
.--------------------------------------------------------------------
.Change:
.  '' Sends byte (may wait for room in buffer)
.
.  repeat until (tx_tail <> (tx_head + 1) & $F)
.  tx_buffer[noparse][[/noparse]tx_head] := txbyte
.  tx_head := (tx_head + 1) & $F
.
.
.To:
.  'Wait till there's space in the Tx buffer
.  repeat until (tx_tail <> ((tx_head + 1) & buffer_mask))
.  tx_buffer[noparse][[/noparse]tx_head] := txbyte
.  tx_head := (tx_head + 1) & buffer_mask
.
.
.--------------------------------------------------------------------
.Change:
.                        add     txbuff,#16
.
.To:
.                        add     txbuff,#buffer_length
.
.--------------------------------------------------------------------
.Change:
.                        and     t2,#$0F
.
.To:
.                        and     t2,#buffer_mask
.
.--------------------------------------------------------------------
.Change:
.                        and     t3,#$0F
.
.To:
.                        and     t3,#buffer_mask
.
.--------------------------------------------------------------------
.
.




Note: Ignore the dots at the start of each line. I put them in to keep the forum software from screwing up the formating.

FullDuplexSerial is a pretty important object, so help stamp out this GOTCHA!

Comments

  • simonlsimonl Posts: 866
    edited 2009-04-17 22:54
    Thanks for the heads-up Chuck - I've not hit this problem yet, but am currently messing with several of these objects, so you've probably just saved the last bit of hair on my head - LOL

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,
    Simon

    www.norfolkhelicopterclub.com

    You'll always have as many take-offs as landings, the trick is to be sure you can take-off again wink.gif
    BTW: I type as I'm thinking, so please don't take any offence at my writing style smile.gif
  • Tom CTom C Posts: 461
    edited 2009-04-18 15:03
    Chuck,

    Good work!

    Steve Norris also documented this issue some time back when he was working with the FullDuplexSerial object and needed to increase the buffer size for a robot project.

    Regards,

    TCIII


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    If you are going to send·a Robot·to save the world, you·better make sure it likes it the way it is!
Sign In or Register to comment.