xous-core/services/shellchat
bunnie 25bccd9446 THE BALDEST YAK: keyboard injection now working
I wrote in a commit yesterday how there was no ROI on doing this
yet somehow I kept on doing it. I blame poor impulse control.

Turns out there was a series of race conditions and bugs that
caused this thing to "mostly work" on the first go at it but
really hard to debug and get very right.

1. Litex UART has a weird undocumented API. You advance the Rx
FIFO by writing `1` to the PENDING bit, and no other way. However,
you determine if there are any more characters to receive by
reading the EMPTY bit and seeing if it is 1. The previous method
wrote `1` to the PENDING bit and then used the PENDING bit to
see if a character was available, under the theory that the
PENDING bit would be set again if there was still a character.
This is somewhat true, except that the PENDING bit is set only
some amount of time later which is about comparable to a few
CPU instructions, so if you had a fast loop path the PENDING
bit would show as cleared and you'd exit, which would cause
no further interrupts to fire because the interrupt was
effecitvely not acknowledged.

This isn't written up anywhere but I figured this out by
just reading the source code for Litex UART and BIOS:
e8be391504/litex/soc/cores/uart.py (L264-L279)
ccd3ab17be/litex/soc/software/libbase/uart.c (L38-L44)

2. I had the Key Injector IP block in the `sys` domain, which
would have its clock cut when the CPU went to sleep, which would
cause input characters to disappear when the CPU went into power
saving. moving this to "always on" domain fixes that.

3. I had the UART PHY in the always on block (so you could
send or receive exactly one character), but not the
separate UART block (which contained the FIFOs).
The UART block would also go into power
savings, and this would cause FIFO entries to go missing.

4. Escape sequences get sent as a burst of characters. The Key Injector
originally did not have a FIFO of its own, so it would only
remember the *last* key of the sequence that was written, causing
some keys to be dropped occassionally. Adding a 16-deep FIFO
to the injector fixes this.

5. The code I had to read out the injector's results was designed with
the "strobe" bit (to indicate that the FIFO had characters) in the
same regsiter as the character itself. Thus the loop that 1. checked
if the fifo was empty then 2. read and forwarded the character
would actually perform two reads from the FIFO. However, this "mostly worked"
I think because the FIFO retains the last value that was written
even when it was empty, so if only one character was read at a time
everything was fine. It only didn't work when you stuffed two characters
in there, as you'd drop the first one. Reading the FIFO once and
then interpreting the code with a bitmask fixes this.

6. The escape sequences, in their full glory with no dropped characters,
required a refactored parsing routine, which I have now added.

7. backspace->delete mappings, the bane of computer engineers since 1960.

OK. very bald yak. Here I lay down the shears next to several
mooshi pillows stuffed with the finest Yak hair.
2022-01-28 15:17:47 +08:00
..
src THE BALDEST YAK: keyboard injection now working 2022-01-28 15:17:47 +08:00
Cargo.toml update wlan status to a binary version with more detailed output 2022-01-14 02:23:57 +08:00
README.md add docs and screenshots 2022-01-25 03:11:50 +08:00
shellchat_screen1.png fix errant dot from screenshot tool 2021-03-11 23:07:05 +08:00

Shell Chat

shellchat is the basic command line environment for Precursor. It houses most of the system maintenanence and test commands.

If you'd like to make your own REPL-type app, check out apps/repl/ for a pared-down version of shellchat which is a better starting point.