Emulated UART Demo using a periodic timer to clock logic.

wikipedia on UART

Consider the diagram below, a stream of characters is sent from one computer to another. Flags are used to control the flow

CPU TX: -- UART--serial--UART -- CPU RX:

This demo uses JavaScript. process1() is run every 200ms, to simulate the CPU clock of microprocessors.

  window.setInterval("process1()",200);

CPU TX: and CPU RX: are run in their own asychronous timeslice randomly picked in process1(); UART uses shared memory, uartFlag is set by TX: and reset by RX:

TX: - - - UARTs - - - RX:

This demo combines TX:'s UART, the serial and RX:'s UART into one UART and considers the handshaking, using a flag.

If TX: has text waiting and the UART buffer is empty, remove the first byte of TX: and write it into the UART and set uartFlag.

Another process polls the UART, uartFlag indicates if a byte is available. If uartFlag is set, read UART and append RX. Reset uartFlag.

This process also polls RX: to see if there are any multi byte words e.g. "OK","START","STOP","GO"

If a key word is seen turn on LED. flash LEDs when TX: and RX: are run.

UART - CPU -> HOST :

TX: run

CPU tx -> rx HOST:

RX: run - When Space is seen copy RX: to last word and empty.

lastWord Keywords:

received Text:

TX: communicates RX: using the UART.

This is summarised as a TX and RX register and two flags TxEmpty and RxFull.

Emulated CPU - UART:-

  A write to TX resets TxEmpty.
  A read from RX resets RxFull.

UART - Host:-

  A read from TX sets TxEmpty.
  A write to RX sets RxFull.

If you have a FIFO then there need to be changes.

 TxEmpty may need to be TxSpaceAvailable 
 RxFull becomes RxAvailable
wikipedia on UART

Automated Typing demo - InterConnected Terminals.

Two automated terminals type at each other. They can see the text the other end is typing.

Try and get each to type at each other. If the other one is typing, do not type at the same time.

This is not supposed to do AI on the text, use simple rules.

[ A ] - - - - [ B ]

Send one character each tick.

The other end receives it and buffers it.

A UART has a TX buffer, and TX buffer and flags.

Flags:
	TXbuffer
	TXempty
	RXfull
	RXbuffer

[ A ] analyses the buffered text.
if last text was GA\n reduce holdoff typing.
if last text was space hold off typing until timeout.

if holdoff times out resume typing.
if [A]'s next char is a space, you need a rule.