; This module supports an external USB connection using an I2C-connected ; PDIUSBD11 (from Philips). ; The hardware is shown in Figure 6-17 with the following correction: ; The 12MHz crystal is connected to the PDIUSBD11. The EZ-USB is ; clocked from CLKOUT of the PDIUSBD11. (This saved a divide by ; two on the 24MHz CLKOUT of the EZ-USB). ; The interrupt from the PDIUSBD11 is fed to INT4 of the EZ-USB ; ; This module contains all of the interrupt vector declarations and ; the first level interrupt servicing of the PDIUSBD11: read Interrupt ; Status Register, Check for Valid Transaction etc) ; ; 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 ; 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 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. ; 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: Timer0_ISR: INT1_ISR: Timer1_ISR: UART0_ISR: Timer2_ISR: UART1_ISR: I2C_ISR: INT5_ISR: INT6_ISR: Not_Used: ; Should not get any of these RETI ClearINT4: ; Tell the hardware that we're done MOV A, EXIF CLR ACC.4 ; Clear the Interrupt 2 bit MOV EXIF, A RET INT4_ISR: ; The PDIUSBD11 needs attention MOV A, #0F4H ; Read it's Interrupt Register CALL ReadI2CByte ANL A, #00000100b ; In this example only the EP0 Control is enabled JZ Done MOV A, #42H ; Read the Last Transaction Status CALL ReadI2CByte JB ACC.0, Done ; Ignore transaction if there are errors JNB ACC.5, Done ; We're waiting for a SETUP packet Wait4F: MOV A, #82H ; Read status of EP0 Control OUT Call ReadI2CByte JNB ACC.5, Wait4F ; Wait til all of the token has been received ; MOV A, #3 ; Select Endpoint(3) = EP0 Control IN CALL SendI2Ccommand MOV A, #0F1H ; Acknowledge that the SETUP token has been received CALL SendI2Ccommand MOV A, #0F2H ; Clear the EP0 OUT buffer ready to receive data CALL SendI2Ccommand MOV A, #2 ; Select Endpoint(2) = EP0 Control OUT CALL SendI2Ccommand MOV A, #0F1H ; Acknowledge that the SETUP token has been received CALL SendI2Ccommand ; This will allow the SETUP data to be received MOV A, #10 CALL ReadI2CBytes ; Read 10 bytes [Reserved, Count, SetupData(8)] ; Returns with Count in ACC CJNE A, #8, Stall ; Need 8 bytes for a valid SETUP packet ; ; We have just received a SETUP packet, interpret and respond to it's contents CALL ServiceSetupPacket ; Note that SETUPDAT, SUDPTR, In0ByteCount and EP0Control are redeclared in this ; module so that fewer changes are required in ExtINT (was USB_INT) ; ; This routine returns with ACC.1 = HSNAK and ACC.0 = EP0STALL 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 ExitISR:MOV DPTR, #USBIRQ MOVX @DPTR, A POP DPH ; Restore Registers POP DPL POP ACC POP PSW RETI SOF_ISR: ; A Start-Of-Frame packet has been received PUSH PSW ; Save Registers before the service routine PUSH ACC PUSH DPL PUSH DPH CALL ServiceTimerRoutine CALL ClearINT2 ; Clear the source of the interrupt MOV A, #00000010b JMP ExitISR