; This module is specific to the Lighting Control Panel (since it uses Timer 0)

;

; It contains all of the interrupt vector declarations and

; the first level interrupt servicing (register save, call subroutine,

; clear interrupt source, restore registers, return)

; Suspend and Resume are handled totally in this module

;

; A Reset sends us to Program space location 0

	CSEG AT	0		; Code space

	USING 0			; Reset forces Register Bank 0

	LJMP	Reset

;

; The interrupt vector table is also located here

; EZ-USB has two levels of USB interrupts:

; 1-the main level is described in this table (at ORG 43H)

; 2-there are 21 sources of USB interrupts and these are described in USB_ISR

; This means that two levels of acknowledgement and clearing will be required	

;	LJMP	INT0_ISR	; Features not used are commented out

	ORG	0BH

	LJMP	Timer0_ISR

;	ORG	13H

;	LJMP	INT1_ISR

;	ORG	1BH

;	LJMP	Timer1_ISR

;	ORG	23H

;	LJMP	UART0_ISR

;	ORG	2BH

;	LJMP	Timer2_ISR

;	ORG	33H

;	LJMP	WakeUp_ISR

;	ORG	3BH

;	LJMP	UART1_ISR

	ORG	43H

	LJMP	USB_ISR		; Auto Vector will replace byte 45H

;	ORG	4BH

;	LJMP	I2C_ISR

;	ORG	53H

;	LJMP	INT4_ISR

;	ORG	5BH

;	LJMP	INT5_ISR

;	ORG	63H

;	LJMP	INT6_ISR



	ORG	0E0H		; Keep out of the way of dScope monitor

				; If you are not using dScope then this memory hole

				; may be used for useful routines.

	ORG	100H	

USB_ISR:LJMP	SUDAV_ISR

      	DB	0		; Pad entries to 4 bytes

	LJMP	SOF_ISR

	DB	0

	LJMP	SUTOK_ISR

	DB	0

	LJMP	Suspend_ISR

	DB	0

	LJMP	USBReset_ISR

	DB	0

	LJMP	Reserved

	DB	0

;	LJMP	EP0In_ISR	; Endpoint Interrupts are not used in these examples

;	DB	0               ; Comment out features not used

;	LJMP	EP0Out_ISR

;	DB	0

;	LJMP	EP1In_ISR

;	DB	0

;	LJMP	EP1Out_ISR

;	DB	0

;	LJMP	EP2In_ISR

;	DB	0

;	LJMP	EP2Out_ISR

;	DB	0

;	LJMP	EP3In_ISR

;	DB	0

;	LJMP	EP3Out_ISR

;	DB	0

;	LJMP	EP4In_ISR

;	DB	0

;	LJMP	EP4Out_ISR

;	DB	0

;	LJMP	EP5In_ISR

;	DB	0

;	LJMP	EP5Out_ISR

;	DB	0

;	LJMP	EP6In_ISR

;	DB	0

;	LJMP	EP6Out_ISR

;	DB	0

;	LJMP	EP7In_ISR

;	DB	0

;	LJMP	EP7Out_ISR		

; End of Interrupt Vector tables



; When a feature is used insert the required interrupt processing here

; The example use only used Endpoints 0 and 1 and also SOF for timing

Reserved:

INT0_ISR:

INT1_ISR:

Timer1_ISR:

UART0_ISR:

Timer2_ISR:

UART1_ISR:

I2C_ISR:

INT4_ISR:

INT5_ISR:

INT6_ISR:

SOF_ISR:

SUTOK_ISR:

EP0In_ISR:

EP0Out_ISR:

EP1In_ISR:

EP1Out_ISR:

EP2In_ISR:

EP2Out_ISR:

EP3In_ISR:

EP3Out_ISR:

EP4In_ISR:

EP4Out_ISR:

EP5In_ISR:

EP5Out_ISR:

EP6In_ISR:

EP6Out_ISR:

EP7In_ISR :

EP7Out_ISR:

Not_Used:			; Should not get any of these

	RETI



ClearINT2:			; Tell the hardware that we're done

	MOV	A, EXIF

	CLR	ACC.4		; Clear the Interrupt 2 bit

	MOV	EXIF, A

	RET



USBReset_ISR:			; Bus has been Reset, move to DEFAULT state

	PUSH	ACC

	CLR	Configured

        CALL	ClearINT2

				; No need to clear source of interrupt

	POP	ACC

	RETI



Suspend_ISR:			; SIE detected an Idle bus

	PUSH	ACC

	MOV	A, PCON

	ORL	A, #1

	MOV	PCON, A		; Go to sleep!

	NOP

	NOP			; Wake up here due to a USBResume

	NOP

	CALL	ClearINT2

	POP	ACC

	RETI

 	

WakeUp_ISR:			; Not using external WAKEUP in these examples

				; So this must be due to a USBResume

	CLR	EICON.4		; Clear the wakeup interrupt source

	RETI



SUDAV_ISR:			; A Setup packet has been received

	PUSH	PSW		; Save Registers before the service routine

	PUSH	ACC

	PUSH	DPL

	PUSH	DPH

	CALL	ServiceSetupPacket

	CALL	ClearINT2				

	                        ; Clear the source of the interrupt

	MOV	A, #00000001b

	MOV	DPTR, #USBIRQ

	MOVX	@DPTR, A

ExitISR:POP	DPH		; Restore Registers

	POP	DPL

        POP	ACC

        POP	PSW

	RETI



Timer0_ISR:

	PUSH	PSW		; Save Registers before the service routine

	PUSH	ACC

	PUSH	DPL

	PUSH	DPH

	CALL	ServiceTimerRoutine

	                        ; Source of the interrupt claered automatically

	JMP	ExitISR