Final instructions for Laboratory 2 using the 68K simulator

Now that you have seen that the virtual COFFEEPOT actually works, you now need to develop the code to control it yourself.

linker -f absmap.spc test.o vstart.o cofdev.o -o test.out

You should experience no difficulty in linking the files, but is you do, follow the link for solving certain linker errors.

Basic animation sequence

Controlling the COFFEEPOT device

You are going to make the coffeepot device perform the follow task.

	Place_COFFEEPOT_on_DATA_BUS
	INIT_COFFEEPOT

	while (temperature < BOILING) 
		Apply_Heat 
	end_while 

	Signal_Water_Boiled 

	while (time < TOO_LONG) 
		Apply_Low_Heat 
	end_while 

	Signal_Coffee_Ready

You will need to make use of the data sheets on the COFFEEPOT device. I am only going to provide some general examples on accessing the device registers. The control of the loops is your responsiblity. You'll have to use the examples in HVZ to guide you, together with the information provided about for and while loops.


Limitations of the COFFEEPOT device

The virtual device operation is handled by introducing some complex operations during an interrupt service routine. This interrupt service routine was not straight forward to develop to work with a real processor on an evaluation board. It was doubly difficult on the SDS simulator as that does not completely support all the different types of interrupts available on a true PowerPC processor.

The reason that you had to specify the "-V 68020" option when assembling is that every single member of the 68K family handles interrupts in a different manner. I implemented the interrupt handling for the 68020 processor in the "COFFEEPOT" device.

Rather than developing 128K of code, and really slowing down the simulation, I decided to only allow certain operations on the virtual devices. These were the typical operations you would perform -- moving values to and from the device.

In actual fact, you'll find that the "68K virtual device" will support more than just these operations, but these are the only "official" ones that work for both READ and WRITE operations on the device when using the SDS demo kit.


Controlling the COFFEEPOT device

You must first install the COFFEEPOT device on the 68K processor buses using the InitCoffeePot() subroutine. This places the device so that its BASEADDRESS is at memory location 0x20000. If you read the COFFEEPOT data sheets you will see that, for example, that the C_CONTROL register is described as having an offset of 0x20. This offset is relative to the base address of the device. Thus the COFFEEPOT C_CONTROL register will respond when the processor places the value 0x20020 (0x20000 + register offset 0c20) on its address bus. The other registers will respond in a similar way.

If a second COFFEEPOT is installed on the 68K processor buses (possible with the COFFEEPOT device from the "Full Companion") with a baseaddress of 0x40000, then that COFFEEPOT device would have a C_CONTROL register that would respond to address 0x40020.

After you have installed the COFFEEPOT device on the 68K data bus (InitCoffeePot()) and sent a RESET signal to the device's control register (C_CONTROL), you will find that you can

The following code shows how to activate the water valves and read the water temperature, all necessary tasks in controlling a typical device.

#include "cof020.i"
COFFEEPOT_BASEADDRESS 	EQU 0x20000

	MOVEA.L #COFFEEPOT_BASEADDRESS, A0	; Set the address pointer

	MOVE.L #START_WATER, D0			; Set the value
	MOVE.L D0, C_WATER(A0)			; Activate the device

	MOVE.L C_TEMPERATURE(A0), D0		; Read the temperature

Note I have used A0 as the address register and D0 as the data register when accessing the device. The virtual device is more flexible than this, but using these registers works the most reliably. The file cof020.i can be included directly into your source code file. It contains all the register offsets and constants needed to control the device.

You now have enough information to control the COFFEEPOT device so that you can "boil the water" and "perk the coffee" to your taste.

For the rest of Laboratory 2, you are on your own. PLEASANT PERKING


Sending Messages to the Screen

You can also send messages to the "device screen" when you are running your code as follows.

"C" pseudo code

void mycode(void) {
	AddToScreen(1, "Hello World!");
}

"assembler code"

	section code
mycode:
	EXTERN _AddToScreen
	SUB.L #8, SP

	MOVE.L 1, 0(SP)
	MOVE.L #HELLO, 4(SP)
	JSR _AddToScreen	; AddToScreen(1, "Hello World!");

	ADD.L #8, SP
	RTS

	section string
HELLO:	DC.B 'HELLO WORLD\0'
	.align

WARNING:- If you make use of the "AddToScreen()" routine inside a loop, make sure that there is nothing important stored in registers D0, D1, A0 and A1. Calling conventions state that these registers are volatile meaning that the subroutine called can use these registers without saving them. The other registers (D2 -- D7 and A2 -- A6) are non-volatile. This means that the subroutine can make use of these registers, but must restore their original values before returning to the calling routine.

If you want more information about the handling of subroutines see Laboratory 3 which covers the basics of subroutines using the SDS assembler and compiler. Alternately read up the information in HVZ.



Last modified: July 22, 1996 01:18 PM by M. Smith.
Copyright -- M. R. Smith