The Target Link Monitor is a small, 712 byte, program that allows the communication with the Host PC and implements multitasking. This small program is however self contained. It requires no further code to allow full modification and inspection of all the AVRs resources.
This is all carried out by the word SERVER which is defined as follows:
: SERVER (S - ) BEGIN ADDR@ EXECUTE $A5 CHAR-OUT AGAIN ;
We must thank the University of Rostock, in what was East Germany, for this deceptively simple idea. The words ADDR@ waits for the Host to send two bytes of data, LSB first, to the Target stack. This 16 bit value must be a valid CFA, Code Field Address, of an existing Target definition. The word EXECUTE performs a IJMP to this address. The $A5 CHAR-OUT is used as an acknowledgement for the communications.
The basic TLM words are:
ADDR@, C@, C!, EXECUTE, PAUSE, @, !, SERVER, SP0, STOP, WORD>
With only these it is possible for SERVER to interrogate the AVR internals.
For example, if we wish to look at the current value of the SREG register, we need to perform a C@ on file address $3F and send the result to the Host for display. This is what happens:
I/O SREG C@ H. <cr>
Host sends CFA of ADDR@, EXECUTE runs it.
Host sends $3F (SREG adds) which ADDR@ puts on Target stack.
Host sends CFA of C@, EXECUTE runs it and C@ fetches the value.
Host sends CFA of WORD>, EXECUTE runs it and sends result to Host.
Host displays the 8 bit value in Hex.
SP@ puts the value of the stack pointer, DP ,on the stack so using WORD> and C@ the Host may display the current Target stack contents. When in the Remote mode, .S does this function.
With C! the Host may modify AVR resources. This allows you to write Host programs that require no further Target code but that will exercise hardware external to the AVR. This is very useful in development and production, to do initial testing