Shop OBEX P1 Docs P2 Docs Learn Events
Cluso's Serial Driver (based on JonnyMacs jm_fullduplexserial plus extensions) — Parallax Forums

Cluso's Serial Driver (based on JonnyMacs jm_fullduplexserial plus extensions)

@JonnyMac 's serial driver (jm_fullduplexserial.spin) has some great features :)

But I am used to some extras, especially dumping hub memory and reading strings.

So, I've taken Jon's serial and used this as a base to add my extras. This is a list of them
''    tx(chr)                               ' *** modified to call txChar(chr) - backward compatible
''    txChar(chr)                           ' sends chr (optionally strip <lf>) 
''    txOut(chr)                            ' sends chr (do not strip <lf>) 
''    txStr(stringptr)                      ' equivalent to fstr0(stringptr)
''    txStrCRstringptr)                     ' sends string followed by <cr><lf>
''    txCR()                                ' sends <cr><lf>
''    txASCII(chr)                          ' sends chr (converts chrs $00-$1F & >$7E to ".")
''    txDump(stringptr1,stringptr2)         ' sends hub as lines of 4 longs + ASCII
''    rxStr(stringptr)                      ' returns 0 terminated string (<cr> terminates entry)
''    rxPeek()                              ' returns -1 (True) if no chars available, else 0 (False)

The demo code attached is not finished because I want to decouple the Cog PASM Driver and pass both the spin driver and the pasm driver the buffer addresses. This will permit multiple cogs being able to drive the one serial port, and it will provide the ultimate desire of making the pasm cog resident which is necessary for my P2 OS. Also, by decoupling the pasm from the spin, the pasm can be substituted with a VGA / Keyboard driver or any other as desired.

There's one other thing that isn't complete. In my P1 OS, I have an option to strip <lf> from the output using an OS flag. I've coded this but it's disabled at present. This requires one change to Jon's tx(b) routine which I have replaced with a new tx(b) which immediately calls txChar(chr) where the strip <lf> code is present. You can use the txOut(chr) if you want to bypass the optional <lf> stripping.

I've currently implemented most changes to Jon's routines by adding in my routines using an #INCLUDE "jmrr_extras.spin2". Beware, #INCLUDE only works with Eric's FlexSpin compiler so if you want to use pnut or PropTool you will need to past the code from jmrr_extras.spin2 into the main code jmrr_fullduplexserial.spin2.

txStr(stringptr) , txStrCRstringptr) and txCR() are faily self-explanitory.

txDump(stringptr1,stringptr2) dumps a block of hub ram in hex and ascii, and uses txASCII(chr).
FC000: 00 08 80 FF  3F 00 0C FC  32 C8 06 F6  1F 04 DC FC  '....?...2.......'
FC010: 40 7E 74 FD  01 CA A6 F0  1F CA 26 F4  00 CA 62 FD  '@~t.......&...b.'

rxStr(stringptr) reads input from serial (via the head/tail buffer) waiting for a <cr>. Currently the <cr> is stripped from the buffer and then the string is terminated with a "0" (ie usual string termination). I am unsure whether I need the <cr> and potentially <lf> inserted into the buffer before the terminating 0, so this may change.

rxPeek() is a different way of testing if there is/are character(s) waiting in the buffer (eg Available() and rxcheck() ).

Enjoy :sunglasses:
Sign In or Register to comment.