FullDuplexSerial and clone objects GOTCHA: Use caution when changing buffer siz
Chuck Rice
Posts: 210
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.
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:
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!
.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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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
BTW: I type as I'm thinking, so please don't take any offence at my writing style
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!