Cluso's Serial Driver (pasm standalone COG, incorporates most of ROM Monitor/Debugger)
Cluso99
Posts: 18,069
Cluso's Serial Driver - standalone PASM Cog
Here is my latest Serial Driver which currently implements a number of the ROM Monitor/Debugger functions...
v1.62
Current commands supported/tested...
The interface is via a simple 4 long hub mailbox, which is passed when starting the serial driver with coginit.
For each command, simply set the optional values in the mailbox "data", "addr1" & "addr2" and then set the desired command in the mailbox "cmd", and wait for the "cmd" to be cleared. This method is easily supported from pasm and spin, and hopefully will be supported from the other languages too.
Here is my latest Serial Driver which currently implements a number of the ROM Monitor/Debugger functions...
v1.62
Current commands supported/tested...
TxChar send 1-4 characters, options to reverse byte order TxStr send $0 terminated string TxHex send long in hex, options to reverse byte order, add space in pairs, 1-8 digits TxList send/dump line(s) of hex & ascii from hub (cog/lut not relevant), option to display longs, give address range TxBin send binary, 1-32 digits TxDec send decimal, signed/unsigned RxChar (not tested) receive a char, options to send prompt 1-4 chars first, echo, strip <lf>, wait or return $1FF in not-avail RxStr (not tested) receive string, options to send prompt 1-4 chars first, echo, strip <lf>, supply new hub buffer address. Can edit with <bs> Monitor call Monitor/Debugger (as in P2 ROM). Returns with Q<cr>
The interface is via a simple 4 long hub mailbox, which is passed when starting the serial driver with coginit.
For each command, simply set the optional values in the mailbox "data", "addr1" & "addr2" and then set the desired command in the mailbox "cmd", and wait for the "cmd" to be cleared. This method is easily supported from pasm and spin, and hopefully will be supported from the other languages too.
'' +-------------------------------------------------------------------------------------------------------------------+ '' | HUB Mailbox Interface: | '' +-------------------------------------------------------------------------------------------------------------------+ '' | +0: ptr_cmd long command | '' | +4: ptr_data long data | '' | +8: ptr_addr1 long address | '' | +12: ptr_addr2 long address2 | '' +-------------------------------------------------------------------------------------------------------------------+ '' | command | 8 7 6 5 | 4 3 2 1 0 | comment | '' |------------|---------|-----------|--------------------------------------------------------------------------------| '' | idle | 0 0 0 0 | 0 0 0 0 0 | waiting for command | '' | | |-----------|--------------------------------------------------------------------------------| '' | initialise | 0 0 0 0 | 1 0 0 0 0 | initialise serial... | '' | | | | reg_x = bitper (calc from baud) | '' | | | | reg_p = bufad in hub (for Rx buf) | '' | | | | reg_p2 = rxpin<<8 + txpin | '' | | |-----------|--------------------------------------------------------------------------------| '' | monitor | 0 0 0 0 | 1 1 1 1 1 | call the Monitor/Debugger (return with Q<cr>) | '' |------------|---------|-----------|--------------------------------------------------------------------------------| '' | TxChar | 0 0 0 1 | 0 . . . . | display 1-4 chars (in reg_x) | '' | | | 0 1 . . . | reverse byte order | '' | | | 0 . 1 . . | | '' | | | 0 . . 1 . | | '' | | | 0 . . . 1 | | '' | | |-----------|--------------------------------------------------------------------------------| '' | TxString | 0 0 0 1 | 1 . . . . | display nul-terminated string (from @reg_p) | '' | | | 1 1 . . . | | '' | | | 1 . 1 . . | | '' | | | 1 . . 1 . | | '' | | | 1 . . . 1 | | '' |------------|---------|-----------|--------------------------------------------------------------------------------| '' | TxHex | 0 0 1 0 | . . . . . | display in hex (in reg_x) | '' | | | 1 . . . . | space between hex pairs | '' | | | . 1 . . . | reverse byte order | '' | | | . . n n n | nnn = digits 1-7, 0 = 8 digits | '' |------------|---------|-----------|--------------------------------------------------------------------------------| '' | TxList | 0 0 1 1 | . . . . . | display line(s) 16 hex bytes plus ascii (from @reg_p to @reg_p2) | '' | | | 1 . . . . | | '' | | | . 1 . . . | | '' | | | . . 1 . . | | '' | | | . . . 1 . | display as longs | '' | | | . . . . 1 | address range (from @reg_p to @reg_p2 else @reg_p[16]) | '' |------------|---------|-----------|--------------------------------------------------------------------------------| '' | TxBinary | 0 1 0 0 | . . . . . | display in binary (in reg_x) | '' | | | n n n n n | nnnnn = no.of digits 1-31, 0 = 32 digits | '' |------------|---------|-----------|--------------------------------------------------------------------------------| '' | TxDecimal | 0 1 0 1 | 0 . . . . | display in decimal (in reg_x) | '' | | | 0 1 . . . | | '' | | | 0 . 1 . . | | '' | | | 0 . . 1 . | | '' | | | 0 . . . 1 | signed (else unsigned) | '' | | |-----------|--------------------------------------------------------------------------------| '' | ? | 0 1 0 1 | 1 . . . . | ? | '' |------------|---------|-----------|--------------------------------------------------------------------------------| '' | ? | 0 1 1 0 | . . . . . | ? | '' |------------|---------|-----------|--------------------------------------------------------------------------------| '' | RxChar | 0 0 0 1 | 0 . . . . | receive 1 char (into reg_x) | '' | | | 0 1 . . . | echo | '' | | | 0 . 1 . . | prompt (display prompt char(s) in reg_x first) | '' | | | 0 . . 1 . | ?tbd? strip <lf> | '' | | | 0 . . . 1 | ?tbd? return $1FF if no char avail | '' | | |-----------|--------------------------------------------------------------------------------| '' | RxString | 0 0 0 1 | 1 . . . . | receive string (into @reg_p), <cr> terminates, adds <nul>, supports <bs> edit | '' | | | 1 1 . . . | echo | '' | | | 1 . 1 . . | prompt (display prompt char(s) in reg_x first) | '' | | | 1 . . 1 . | strip <lf> | '' | | | 1 . . . 1 | address for input (in @reg_p) else use equ._bufad | '' +-------------------------------------------------------------------------------------------------------------------+
Comments
I have left the majority of that code intact. This isn't the most efficient, but it works.
Note the command call bits (defined in ClusoSerial_Equ.spin2) have changed from the ROM code. Provided you use the defined names rather than hardcoding you will be fine.
forums.parallax.com/discussion/170638/p2-rom-monitor-debugger-rev-1-rev-2-silicon
Of special note is the Monitor call. This allows your program to call the monitor where you can display and/or modify the hub memory. It is a powerful tool for debugging your code, and once done you can return to your code to continue.
The Monitor mode works the same as the ROM version. So you can call the monitor from you pasm code, which then allows you to examine, and modify hub memory (while cog/lut still work there is little point as this code resides in it's own cog so you're only going to see it's own cog/lut memory). As usual, return to your user code by entering "Q" followed by "<enter>" or "<cr>".
Initialise now passes the serial pins, so it's possible to use pins other than 63 & 62.
The mailbox consists of 4 longs (command, data, address1 address2) followed by an 80 byte buffer for use by the serial receive character/string routine. This address can be changed in the receive string call. The receive string call supports backspacing to correct typos before entering the string. The string will be terminated by the <cr> followed by a $0. Therefore, and 80 character buffer only supports 78 characters.
Currently I have only provided a PASM Demo program which I assembled with fastspin 4.2.5. It is also possible to use the Serial Driver from spin2 since the interface is a hub mailbox of 4 longs. The address of the mailbox is passed to the serial driver via PTRA using SETQ before the COGINIT call.
BTW I am aiming for this to have, either within or separate, a vga/hdmi and usb/ps2 keyboard alternative.
see top post for code
Adds TxBinary(digits) and TxDecimal(signed/unsigned)
I'm having a compile error with your PasmDemo.spin2. See attached photo. I'm using FlexGUI 4.2.5.
I believe the compile error in ClusoSerial.spin2 line 112 is from the first compile error.
I'm not understanding the compile problem - it must be with my setup because no one else apparently has this problem...
Thanks,
Kevin
Have you tried v1.62 (presume it will give the same error)?
This is my windoze compile command where %1 is substituted with "pasmdemo"