########################################################################

#	

#	5307 Stop instruction Verification

#

#	This code was written to test the Stop instruction execution on 

# 	the 5307 lab eval board.  

#	  

#	What does this code do?

#		The processor is initialized to handle an interrupt of 

# 	level 1.  Once this is done D3 is set to 0 and then the stop 

#	instruction is executed.  After this instruction, the processor 

# 	is halted and is waiting for IRQ1.  To issue the interrupt, simply

#	ground the IRQ1 pin which is located at pin 3 of P5 on the 5307

#	evaluation board.

#

#	If the routine is working properly, the interrupt will be taken by 

#	the processor, and the exception handler for IRQ1 will be called.  

#	The exception will increment D3 so that, after the return from 

#	exception (RTE), D3 != 0.  Thus the loop at first will only 

# 	increment D4 once, and the break point will be incountered.

#

#	If the routine is not working properly, the interrupt will not be 

#	taken, and D4 will be incremented infinitely.



MBAR 	equ	0x10000000

VBR	equ	0x00000000



AVCR	equ	MBAR + 0x4B

IMR	equ	MBAR + 0x44

IPR	equ	MBAR + 0x40



	XDEF	_main

_main:

	NOP

	NOP

	NOP

	MOVE.L	#VBR,A6

	MOVEC	A6,VBR

	MOVE.L 	#exception_handler,d0	;Exception Vector Assignment for

	MOVE.L	d0,VBR+0x64		; IRQ1 is at 0x64		

	

	MOVE.B	#0x2,d0

	MOVE.B	d0,AVCR			;autovector external interrupt 1	



	MOVE.L	#0xFFFFFFFC,d0		;set IMR to enable IRQ1

	MOVE.L 	d0,IMR



	MOVE.L	#0x80,D0			;PLLCR mask to enable low power mode

	MOVE.B	D0,MBAR+0x008		;any interrupt wakes system/clock tree



	MOVE.W	#0x2000,SR		;Processor in supervisor state

	MOVE.W	#0x2000,SR		;Processor in supervisor state

					; set interrupt priority to 0

	CLR.L     	D3		;set D3 equal to zero

	STOP      	#0x2000		;stop processor until IRQ1 recieved

					; level 1

first:

	nop

	nop

	nop

	ADDQ.L	#0x01,D4	;increment D4

	TST.L  	D3		;check (D3 == 0)

	BEQ	first		;if (D3 != 0), branch back

second:

	nop

	nop

	nop

	bra	second

exception_handler:

	MOVE.W	IPR,D1		;read IPR

	ADDQ.L	#0x01,D3	;increment D3

	RTE			;return from exception

