Command and control as ASCII bytes

A project log for Discrete YASEP

a 16-bits YASEP computer (mostly) made of DIP/SOIC chips like in the 70s and 80s... with 2010's twists!

Yann Guidon / YGDES 10/22/2015 at 21:070 Comments

Guys, this post is going to be fun. Like, a lot of fun.

If you have read the past logs you know that I include a UART interface for input-output with a host computer. This host can contain software to assemble or disassemble code, and whatever fancy softwary stuff you dare program.

But what if (what if ?) you could actually directly send commands to the board without a fancy software package that runs a GUI in your browser ? Who has the time to develop a GUI these days anyway ?

The word for the magic feature is "console".

Let's look at the setup:

Now it becomes easy to control the board with a few keystrokes, just type "cat > /dev/ttyS0" !

But what keystrokes ?

ASCII codes for letter 0 to 9 map to 0x30-0x39 so we can directly extract the lower nibble but the letters A to F map to something totally different ! Why don't I code in octal, why ?

From here, I see where this could be going to : write software. But wait! If you got POSIX, you got tr !

[yg@localhost]$ man tr
       tr - translate or delete characters

       tr [OPTION]... SET1 [SET2]

       Translate, squeeze, and/or delete characters from standard input, writing to standard output.
Why write a program when you can use an existing filter ?
[yg@localhost]$ tr a-z A-z

The rest is pretty easy!

[yg@localhost]$ tr A-Fa-f '\072\073\074\075\076\077\072\073\074\075\076\077' |od -w1 -t x1
0000000 30
0000001 31
0000002 32
0000003 33
0000010 38
0000011 39
0000012 3a
0000013 3b
0000014 3c
0000015 3d
0000016 3e
0000017 3f   <-- yay !
0000020 0a  <-- new line
0000021 30
0000022 31
0000031 38
0000032 39
0000033 3a <-- yay again !
0000034 3b
0000035 3c
0000036 3d
0000037 3e
0000040 3f
0000041 0a
This can be saved as a script that you can invoke to send data to the board.
[yg@localhost]$ > /dev/ttyS0
This sends the value 0x1234 to the register R4. This supposes that


Unrecognised characters are discarded or ignored by the board. This is important because the terminal buffers lines, so you have to press the ENTER key to send the line over to the serial port.

Then you can save all these commands, copy, paste, translate, sed, hawk, python, perl, and maybe, at a higher level, interface with GDB ?...

This also removes the need to record keystrokes directly on the board for the purpose of replaying them later.