www.pudn.com > windows2000XP_WDM_DeviceDriverDevelopment_WuAnHe_C > COUNTER.LST


CYASM Version 1.75
(C) 1997 Cypress Semiconductor Corp.

0000 ; Port Usage
0000 ; P1.0 -
0000 ; .1 -
0000 ; .2 - Button (0=pushed) (input)
0000 ; .3 - LED (0=on) (output)
0000 ;
0000 ;*******************************************************************************
0000
0000 ;//$PAGE
0000 ; Directives
0000 FillROM 0
0000
0000 ; Microprocessor definitions
0000 ;;******************************************************************************
0000 ;; C7C63x0x.h - Cypress Semiconductor Cy7C63x0x micrprocessor definitions
0000 ;; Copyright (c) Slade Systems, Inc, 1997
0000 ;;
0000 ;; Cypress Semiconductor Corp.
0000 ;; 12032 113th Ave NE, Kirkland, WA 98034
0000 ;; 206-821-9202 - 206-820-8959(f)
0000 ;;
0000 ;;******************************************************************************
0000
0000
0000 ;*******************************************************************************
0000 ;
0000 ; M8 - 8bit microprocessor
0000 ; registers: accumulator 'acc'
0000 ; index 'x'
0000 ; stack pointer 'dsp'
0000 ; program SP 'psp'
0000 ; program counter 'pc' 16 bits (14 bit addressing)
0000 ; PC low 'pcl'
0000 ; PC high 'pch'
0000 ; When PC is pushed on stack
0000 ; carry flag is stored in bit 14
0000 ; zero flag is stored in bit 15
0000 ;
0000 ; Program ROM 4096 bytes in 256 byte pages
0000 ; Program RAM 128 bytes
0000 ; Processor PORTs contain 16k-ohm resistor (pull-up and slew control)
0000 ;
0000 ; After reset:
0000 ; Port 0 and Port 1 are set high
0000 ;
0000 ;
0000 ;*******************************************************************************
0000
0000 ;*************************************************
0000 ;
0000 ; I/O ports defined
0000 SysPort0 :equ 00h ; GPIO data port 0 (P00-P07)
0000 SysPort1 :equ 01h ; GPIO data port 1 (P10-P13)
0000 SysPort0IntEnable :equ 04h ; Port0 Interrupt Enable
0000 SysPort1IntEnable :equ 05h ; Port1 Interrupt Enable
0000 SysPort0PullUp :equ 08h ; Port0 PullUp Resistor Enable (0=active)
0000 SysPort1PullUp :equ 09h ; Port1 PullUp Resistor Enable (0=active)
0000
0000 ; General
0000 SysStatus :equ FFh ;
0000 SysStatusRun :equ 01h ;
0000 SysStatusReserved2 :equ 02h ; nul
0000 SysStatusReserved3 :equ 04h ; nul
0000 SysStatusSuspend :equ 08h ; write only (restart =256us)
0000 SysStatusPowerOn :equ 10h ;
0000 SysStatusUSBReset :equ 20h ;
0000 SysStatusWDReset :equ 40h ;
0000 SysStatusReserved7 :equ 80h ; nul
0000 SysWatchDog :equ 21h ; WatchDog controller
0000 SysTimerExternal :equ 22h ; Timer also ???
0000 SysTimer :equ 23h ; Timer (read only) {6MHZ=1us resolution}
0000 SysInterrupt :equ 20h ; Global interrupt
0000 SysIntReserved0 :equ 01h ;
0000 SysIntTimer128us :equ 02h ;
0000 SysIntTimer1024us :equ 04h ;
0000 SysIntUSBEndP0 :equ 08h ;
0000 SysIntUSBEndP1 :equ 10h ;
0000 SysIntReserved5 :equ 20h ;
0000 SysIntGPIO :equ 40h ;
0000 SysIntWakeUp :equ 80h ;
0000
0000 ; Ouput ISink ???
0000 SysPort0ISinkPin0 :equ 30h ;
0000 SysPort0ISinkPin1 :equ 31h ;
0000 SysPort0ISinkPin2 :equ 32h ;
0000 SysPort0ISinkPin3 :equ 33h ;
0000 SysPort0ISinkPin4 :equ 34h ;
0000 SysPort0ISinkPin5 :equ 35h ;
0000 SysPort0ISinkPin6 :equ 36h ;
0000 SysPort0ISinkPin7 :equ 37h ;
0000 SysPort1ISinkPin0 :equ 38h ;
0000 SysPort1ISinkPin1 :equ 39h ;
0000 SysPort1ISinkPin2 :equ 3Ah ;
0000 SysPort1ISinkPin3 :equ 3Bh ;
0000
0000 ; USB FIFOs
0000 USBEndP0FIFO :equ 70h
0000 USBEndP0FIFO_0 :equ 70h ; Will contain CRC if (rx count <8)
0000 USBEndP0FIFO_1 :equ 71h
0000 USBEndP0FIFO_2 :equ 72h
0000 USBEndP0FIFO_3 :equ 73h
0000 USBEndP0FIFO_4 :equ 74h
0000 USBEndP0FIFO_5 :equ 75h
0000 USBEndP0FIFO_6 :equ 76h
0000 USBEndP0FIFO_7 :equ 77h
0000 ;
0000 USBEndP1FIFO :equ 78h
0000 USBEndP1FIFO_0 :equ 78h
0000 USBEndP1FIFO_1 :equ 79h
0000 USBEndP1FIFO_2 :equ 7Ah
0000 USBEndP1FIFO_3 :equ 7Bh
0000 USBEndP1FIFO_4 :equ 7Ch
0000 USBEndP1FIFO_5 :equ 7Dh
0000 USBEndP1FIFO_6 :equ 7Eh
0000 USBEndP1FIFO_7 :equ 7Fh
0000
0000 ;*************************************************
0000 ;
0000 USBDeviceAddress :equ 12h ; Assigned device address
0000
0000 ; USB port control
0000 USBControl :equ 13h ; Status/Control register
0000 USBControlBusActive :equ 01h ; 1=active, write 0 and watch if bus dies
0000 USBControlResume :equ 02h ; set transmitter to k state sending resume to host ???
0000 USBControlReserve2 :equ 04h
0000 USBControlAckStatusData :equ 08h ; Auto ACK Data1 SETUP OUT data packets
0000 USBControlAckOutData :equ 10h ; Auto ACK Data1 OUT data packets
0000 USBControlReserve5 :equ 20h
0000 USBControlReserve6 :equ 40h
0000 USBControlReserve7 :equ 80h
0000
0000 USBEndP0RxStatus :equ 14h ; Port0 receive status
0000 USBEndP0RxSetup :equ 01h ; 1=setup token received (must be cleared to write FIFOs ???)
0000 USBEndP0RxOut :equ 02h ; 1=out token received
0000 USBEndP0RxIn :equ 04h ; 1=in token received
0000 USBEndP0RxDataFlag :equ 08h
0000 USBEndP0RxCount0 :equ 10h ; size =count -2 (two bytes of CRC)
0000 USBEndP0RxCount1 :equ 20h
0000 USBEndP0RxCount2 :equ 40h
0000 USBEndP0RxCount3 :equ 80h
0000
0000 USBEndP0TxConfig :equ 10h ; Transmit configuration
0000 USBEndP0TxCount0 :equ 01h
0000 USBEndP0TxCount1 :equ 02h
0000 USBEndP0TxCount2 :equ 04h
0000 USBEndP0TxCount3 :equ 08h
0000 USBEndP0TxRxErr :equ 10h ; read and write
0000 USBEndP0TxStall :equ 20h ;
0000 USBEndP0TxSequence :equ 40h ;
0000 USBEndP0TxRespond :equ 80h ;
0000
0000 USBEndP1TxConfig :equ 11h ;
0000 USBEndP1TxCount0 :equ 01h
0000 USBEndP1TxCount1 :equ 02h
0000 USBEndP1TxCount2 :equ 04h
0000 USBEndP1TxCount3 :equ 08h
0000 USBEndP1TxEnable :equ 10h ;
0000 USBEndP1TxStall :equ 20h ;
0000 USBEndP1TxSequence :equ 40h ;
0000 USBEndP1TxRespond :equ 80h
0000
0000 ;*************************************************
0000 ; USB Protocol
0000 ;union USBRqst
0000 ;{ struct
0000 ; { BYTE bReceipient :5; // 0=Device,1=Interface,2=Endpoint,3=Other,4..31=Reserved
0000 ; BYTE bType :2; // 1=Standard,1=Class,2=Vendor,3=Reserved
0000 ; BYTE bDirection :1; // 0=Host to Device,1=Device to Host
0000 ; BYTE bRqst; //
0000 ; // 0x00,0x01,0x02 =Clear Feature
0000 ; // 0x00,0x01,0x02 =Set Feature
0000 ; // 0x80,0x81,0x82 =Get Status
0000 ; // 0x00 =Set Address
0000 ; // 0x80 =Get Descriptor
0000 ; // 0x00 =Set Descriptor
0000 ; // 0x80 =Get Configuration
0000 ; // 0x81 =Get Interface
0000 ; // 0x01 =Set Interface
0000 ; // 0x82 =Synch Frame
0000 ; WORD wValue; //
0000 ; WORD wIndex; //
0000 ; WORD wLength; //
0000 ; }
0000 ;}
0000
0000 ;*************************************************
0000 ; USB Protocol
0000 USBRqstType :equ USBEndP0FIFO_0 ;
0000 USBRqstTypeDirection :equ 80h ; 1=Device to Host,0=Host to Device
0000
0000 USBRqstTypeMask :equ 60h
0000 USBRqstTypeStandard :equ 00h
0000 USBRqstTypeClass :equ 20h
0000 USBRqstTypeVendor :equ 40h
0000 USBRqstTypeReserved :equ 60h
0000
0000 USBRqstTargetDevice :equ 00h
0000 USBRqstTargetInterface :equ 01h
0000 USBRqstTargetEndPoint :equ 02h
0000 USBRqstTargetOther :equ 03h
0000
0000 USBRqstMessage :equ USBEndP0FIFO_1 ;
0000 USBRqstGetStatus :equ 00h ; bit field: 0x01 =Self powered,0x02 =Remote wakeup
0000 USBRqstClearFeature :equ 01h
0000 USBRqstReserved02 :equ 02h
0000 USBRqstSetFeature :equ 03h
0000 USBRqstReserved04 :equ 04h
0000 USBRqstSetAddress :equ 05h
0000 USBRqstGetDescriptor :equ 06h
0000 USBRqstSetDescriptor :equ 07h
0000 USBRqstGetConfiguration :equ 08h
0000 USBRqstSetConfiguration :equ 09h
0000 USBRqstGetInterface :equ 0Ah
0000 USBRqstSetInterface :equ 0Bh
0000 USBRqstSynchFrame :equ 0Ch
0000 USBRqstReserved0D :equ 0Dh
0000
0000 USBRqstWordValueLo :equ USBEndP0FIFO_2 ;
0000 USBRqstWordValueHi :equ USBEndP0FIFO_3 ;
0000
0000 ;*************************************************
0000 ;
0000 USBDescriptorTypeDevice :equ 01h
0000 USBDescriptorTypeConfig :equ 02h
0000 USBDescriptorTypeString :equ 03h
0000 USBDescriptorTypeInterface :equ 04h
0000 USBDescriptorTypeEndPoint :equ 05h
0000 USBDescriptorTypeReserved06 :equ 06h
0000
0000 ;*************************************************
0000 ;
0000 USBRawProtocolSetup :equ B4h
0000 USBRawProtocolIn :equ 96h
0000 USBRawProtocolOut :equ 87h
0000 USBRawProtocolPort0 :equ C3h
0000 USBRawProtocolPort1 :equ D2h
0000 USBRawProtocolACK :equ 4Bh
0000 USBRawProtocolNAK :equ 5Ah
0000
0000
0000 ;*************************************************
0000 ; Data Segment (RAM)
0000 ;*************************************************
0000
0000 ; Program Stack
0000 gbSysProgramStack :equ 00h ; [00h-1Fh] Stack 0x20h
0000 gbSysDataStack :equ 50h ; [50h-6Fh] Stack 0x70h
0000 gbSysFIFO :equ 70h ; [70h-7Fh] EP0 and EP1 FIFO's
0000
0000 ; Global Interrupt
0000 gbSysInterruptMask :equ 20h ; Holds the current interrupt mask
0000
0000 ; USB management data
0000 gbUSBSendSequence :equ 28h ; Buffer send data 0/1 line
0000 gbUSBSendBytes :equ 29h ; Buffer bytes left to send
0000 gbUSBSendBuffer :equ 2Ah ; Offset into current buffer
0000
0000 gbSuspendCount :equ 2Bh ; # of msec bus has been IDLE
0000
0000 ; Button management
0000 gbButtonDebounce :equ 2Ch ; Debounce count down value
0000 gbButtonClicks :equ 2Dh ; Button count value
0000
0000 Button_Pin :equ 04h ; Pin the switch is on, P12
0000 LED_ON :equ 08h ; P13 is used to indicate Enumeration
0000
0000 ;//$PAGE
0000 ;*************************************************
0000 ; Code Segment (ROM)
0000 ;*************************************************
0000
0000 ; Vector Table
0000 org 00h
0000 80 15 [05] jmp main ; Reset of some type
0002 80 10 [05] jmp SysUnUsed ; 128us timer (not used)
0004 80 48 [05] jmp SysTimer1024usEvent ; 1024us timer
0006 80 AD [05] jmp USBEndPoint0Event ; EP0
0008 80 A2 [05] jmp USBEndPoint1Event ; EP1 (not used)
000A 80 10 [05] jmp SysUnUsed ; Reserved
000C 80 99 [05] jmp SysGPIOEvent ; Button
000E 80 10 [05] jmp SysUnUsed ; CExt (not used)
0010
0010 ;*************************************************
0010 ; Unused event
0010 ; Do nothing, restore machine to prior state
0010 ;*************************************************
0010 SysUnUsed:
0010 2D [05] push a
0011 1A 20 [06] mov a,[gbSysInterruptMask]
0013 1E 20 [13] ipret SysInterrupt
0015
0015 ;//$PAGE
0015 ;*******************************************************************************
0015 ; main()
0015 ; @func Entry point after PowerOn, WatchDog timeout or WakeUp from sleeping.
0015 ; @comm Never returns
0015 ;*******************************************************************************
0015 main:
0015 ; This portion of Main is only executed after a RESET (Power-On or USB)
0015 ; Setup data stack in high order RAM, just below EP0 FIFO
0015 ; It will grow down from here
0015 19 70 [04] mov a,70h ; USBEndP0FIFO
0017 30 [05] swap a,dsp
0018
0018 ; Initialize both Ports high
0018 19 FF [04] mov a,FFh
001A 2A 00 [05] iowr SysPort0 ; Port 0 Data reg
001C 2A 01 [05] iowr SysPort1 ; Port 1 Data reg
001E ; 1 on P13 is needed to make sure enumerate LED is off
001E ; 1 on any port that needs to be an input
001E ; Enable Pullups (0=enable)
001E 19 00 [04] mov a,0
0020 2A 08 [05] iowr SysPort0PullUp
0022 19 04 [04] mov a,Button_Pin
0024 2A 09 [05] iowr SysPort1PullUp ; 1 on P12 is needed to make sure GPIO interrupt
0026 ; occurs on LOW to HIGH transistion. This
0026 ; disables it's pull up
0026
0026 ; Enable or disable interrupts on appropriate pins
0026 19 00 [04] mov a,0
0028 2A 04 [05] iowr SysPort0IntEnable ; All pins irq's are disabled on Port 0
002A 19 04 [04] mov a,Button_Pin
002C 2A 05 [05] iowr SysPort1IntEnable ; Enable P12, the button pin.
002E ; No interrupts will occur until the device
002E ; is enumerated. Then GPIO's will be enabled and
002E ; we will allow P12 to generate interrupts
002E
002E ; Initialize USB variables
002E 19 00 [04] mov a,0
0030 31 28 [05] mov [gbUSBSendSequence],a ; Start with a 0
0032
0032 ; Initialize Counter
0032 19 00 [04] mov a,0
0034 31 2D [05] mov [gbButtonClicks],a ; Initial state of 0, no button pushed
0036
0036 ; Initialize variables
0036 19 00 [04] mov a,0
0038 31 29 [05] mov [gbUSBSendBytes],a ; No bytes to send in FIFO buffers
003A 31 2B [05] mov [gbSuspendCount],a ; Reset bus activity to 0
003C 31 2C [05] mov [gbButtonDebounce],a ; We are not debouncing
003E
003E ; Set interrupt mask
003E 19 0C [04] mov a,SysIntTimer1024us | SysIntUSBEndP0
0040 31 20 [05] mov [gbSysInterruptMask],a
0042
0042 ;*********************************************
0042 MainLoop:
0042 ; Enable interrupts to current mask
0042 1A 20 [06] mov a,[gbSysInterruptMask]
0044 2A 20 [05] iowr SysInterrupt
0046
0046 ; Loop
0046 80 42 [05] jmp MainLoop
0048
0048 ;********************************************************
0048 ; SysTimer1024usEvent()
0048 ; @func Timer interrupt event ocurring every 1.024 mSec
0048 ; using 6Mhz crystal.
0048 ;********************************************************
0048 SysTimer1024usEvent:
0048
0048 ; Save accumulator
0048 2D [05] push a
0049
0049 ; Clear watchdog timer
0049 ; Clearing it here effectively disables the timer
0049 2A 21 [05] iowr SysWatchDog
004B
004B ; Keep track of length of any IDLE conditions (No bus activity)
004B 29 13 [05] iord USBControl ; Read the USB Status and Control Reg
004D 10 01 [04] and a,01h ; Check bit 0
004F 16 00 [04] cmp a,0h
0051 A0 5F [05] jz Inc_Counter ; Hmm! No activity. Branch and keep track of it.
0053 29 13 [05] iord USBControl ; Ah! There was activity,
0055 ; clear the bus activity bit
0055 10 FE [04] and a,0feh
0057 2A 13 [05] iowr USBControl
0059 19 00 [04] mov a,0 ; Clear the suspend counter
005B 31 2B [05] mov [gbSuspendCount],a
005D 80 72 [05] jmp Suspend_End
005F
005F Inc_Counter: ; Monitor the IDLE count
005F 1A 2B [06] mov a,[gbSuspendCount] ; Get # of mSec we have been IDLE
0061 21 [04] inc a ; Increment the count
0062 31 2B [05] mov [gbSuspendCount],a
0064 16 03 [04] cmp a,03h ; Has it been 3msec yet?
0066 B0 72 [05] jnz Suspend_End ; Not yet, branch
0068 19 00 [04] mov a,0h ; Yes, clear the suspend counter
006A 31 2B [05] mov [gbSuspendCount],a
006C 29 FF [05] iord SysStatus
006E 0D 08 [04] or a,08h ; Set the suspend bit to cause a suspend
0070 2A FF [05] iowr SysStatus ; We will enter the suspend state during
0072 ; the next instruction.
0072
0072 Suspend_End:
0072 ; Are we counting down a button debounce
0072 19 00 [04] mov a,0
0074 17 2C [06] cmp a,[gbButtonDebounce]
0076 A0 95 [05] jz STimerNoDebounce ; Not debouncing, branch
0078
0078 ; Yes, we're debouncing. Let's see if we are timed out.
0078 27 2C [07] dec [gbButtonDebounce]
007A 19 00 [04] mov a,0
007C 17 2C [06] cmp a,[gbButtonDebounce]
007E
007E ; has debounce timed out?
007E B0 95 [05] jnz STimerNoDebounce ; No, still debouncing, branch.
0080
0080 ; The debounce timer has timed out
0080 ; check if the button pin is at a 1. If not, the button is either still
0080 ; bouncing or still pushed
0080 29 01 [05] iord SysPort1 ; check the port the button is on
0082 10 04 [04] and a,Button_Pin ; check the pin
0084 A0 95 [05] jz STimerNoDebounce ; branch if it is not pushed
0086
0086 ; Reset debounce since the button is not yet released or is bouncing
0086 1A 2D [06] mov a,[gbButtonClicks]
0088 21 [04] inc a;
0089 31 2D [05] mov [gbButtonClicks],a
008B 31 78 [05] mov [USBEndP1FIFO_0],a
008D
008D 29 11 [05] iord USBEndP1TxConfig
008F 10 40 [04] and a,40h
0091 0D 91 [04] or a,91h
0093 2A 11 [05] iowr USBEndP1TxConfig
0095
0095 ; Debounce must be over
0095 STimerNoDebounce:
0095 ; Enable interrupts and return
0095 1A 20 [06] mov a,[gbSysInterruptMask]
0097 1E 20 [13] ipret SysInterrupt
0099
0099 ;//$PAGE
0099 ;********************************************************
0099 ; SysGPIOEvent()
0099 ; @func General purpose port event
0099 ; @comm Which pin?
0099 ;********************************************************
0099 SysGPIOEvent:
0099
0099 ; Save accumulator
0099 2D [05] push a
009A
009A ; Reset debounce any time we are here
009A 19 32 [04] mov a,50
009C 31 2C [05] mov [gbButtonDebounce],a
009E
009E SysGPIOButtonDebouncing:
009E ; Enable interrupts and return
009E 1A 20 [06] mov a,[gbSysInterruptMask]
00A0 1E 20 [13] ipret SysInterrupt
00A2
00A2 USBEndPoint1Event:
00A2
00A2 ; Save accumulator
00A2 2D [05] push a
00A3
00A3 29 11 [05] iord USBEndP1TxConfig
00A5 13 40 [04] xor a,40h
00A7 2A 11 [05] iowr USBEndP1TxConfig
00A9
00A9 ; Enable interrupts and return
00A9 1A 20 [06] mov a,[gbSysInterruptMask]
00AB 1E 20 [13] ipret SysInterrupt
00AD
00AD ;*******************************************************************************
00AD ;
00AD ; This section of code responds to activity on End Point 0 and determines
00AD ; what needs to be done.
00AD ;
00AD ;*******************************************************************************
00AD
00AD ;//$PAGE
00AD ;********************************************************
00AD ; USBEndPoint0Event()
00AD ; @func End Point zero USB event.
00AD ; @comm Default end point.
00AD ;********************************************************
00AD USBEndPoint0Event:
00AD
00AD ; This code checks to see what type of packet was received
00AD ; (Setup, Out, or In) and jumps to the correct routine to decode the
00AD ; specifics. After the code to which the jump points is through, it jumps
00AD ; back to USBEventEP0End.
00AD
00AD ; Save accumulator
00AD 2D [05] push a
00AE
00AE ; Is this a SETUP packet?
00AE 29 14 [05] iord USBEndP0RxStatus
00B0 10 01 [04] and a,USBEndP0RxSetup ; Check the setup bit
00B2 B0 C0 [05] jnz USBEventEP0_SETUP ; Yes it's a setup, branch
00B4
00B4 USBEventEP0End:
00B4 ; OK. We're done with the packet.
00B4 ; Let's enable interrupts and return
00B4 1A 20 [06] mov a,[gbSysInterruptMask]
00B6 1E 20 [13] ipret SysInterrupt ; done with EP0 irq service routine
00B8
00B8 USBEventEP0Stall:
00B8 ; Stall any subsequent IN's or OUT's until the
00B8 ; stall bit (bit 5) is cleard by an I/O write to
00B8 ; the USB End Point 0 TX Configuration Register (0x10)
00B8 ; or any SETUP is received.
00B8 29 10 [05] iord USBEndP0TxConfig
00BA 0D 20 [04] or a,USBEndP0TxStall
00BC 2A 10 [05] iowr USBEndP0TxConfig
00BE
00BE ; OK. We've set the stall condition for Endpoint 0.
00BE ; Now let's complete the routine.
00BE 80 B4 [05] jmp USBEventEP0End
00C0
00C0 ;*******************************************************************************
00C0 ;
00C0 ; We know we have received a Setup token. Now we need to parse it to
00C0 ; determine what command it is.
00C0 ;
00C0 ;*******************************************************************************
00C0
00C0 ;//$PAGE
00C0 ;*******************************************************************************
00C0 ; USBEventEP0_SETUP()
00C0 ; @func End point event SETUP packet handler.
00C0 ; @devnote Runs in interrupt enabled context.
00C0 ;********************************************************
00C0 USBEventEP0_SETUP:
00C0 ; Well, we have a SETUP packet. Let's find out what to do.
00C0 1A 20 [06] mov A,[gbSysInterruptMask]
00C2 2A 20 [05] iowr SysInterrupt
00C4
00C4 ; If we are here and are and we are processing a previous Setup,
00C4 ; we need to abort the processing of the previous Setup
00C4 19 00 [04] mov a,0 ; Clear any indication that we have bytes left to transfer
00C6 31 29 [05] mov [gbUSBSendBytes],a
00C8
00C8 ; Clear EP0 RxReg (including the Setup flag)
00C8 ; The Data toggle bit remains unchanged, however.
00C8 19 00 [04] mov a,0
00CA 2A 14 [05] iowr USBEndP0RxStatus
00CC
00CC ;*********************************************
00CC ; Setup Event
00CC ;*********************************************
00CC
00CC ; Check the request type and branch to the correct location to handle it.
00CC 1A 70 [06] mov a,[USBEndP0FIFO_0]
00CE
00CE USBEventEP0SetupTargetDeviceOUT:
00CE ; Target Device?
00CE 16 00 [04] cmp a,USBRqstTargetDevice
00D0 A0 F0 [05] jz USBEventEP0SetupIsSetAddress ; Yes
00D2
00D2 USBEventEP0SetupTargetInterfaceOUT:
00D2 16 01 [04] cmp a,USBRqstTargetInterface
00D4 A0 B8 [05] jz USBEventEP0Stall ; Yes. Oops! We don't have an interface.
00D6
00D6 USBEventEP0SetupTargetEndpointOUT:
00D6 16 02 [04] cmp a,USBRqstTargetEndPoint
00D8 A0 B8 [05] jz USBEventEP0Stall ; Yes
00DA
00DA USBEventEP0SetupTargetDeviceIN:
00DA 16 80 [04] cmp a,USBRqstTargetDevice | USBRqstTypeDirection
00DC A1 18 [05] jz USBEventEP0SetupGetDescriptor ; Yes
00DE
00DE USBEventEP0SetupTargetInterfaceIN:
00DE 16 81 [04] cmp a,USBRqstTargetInterface | USBRqstTypeDirection
00E0 A0 B8 [05] jz USBEventEP0Stall ; Yes Oops! We don't have an interface.
00E2
00E2 USBEventEP0SetupTargetEndpointIN:
00E2 16 82 [04] cmp a,USBRqstTargetEndPoint | USBRqstTypeDirection
00E4 A0 B8 [05] jz USBEventEP0Stall ; Yes
00E6
00E6 ; Vendor specific commands
00E6 USBEventEP0SetupTargetVendorIN_OUT:
00E6 ; Check request (IN packet OK, OUT packet ERR)
00E6 1A 70 [06] mov a,[USBEndP0FIFO_0]
00E8 10 C2 [04] and a,USBRqstTypeVendor | USBRqstTargetEndPoint | USBRqstTypeDirection
00EA 16 C2 [04] cmp a,USBRqstTypeVendor | USBRqstTargetEndPoint | USBRqstTypeDirection
00EC A2 3C [05] jz USBEventEP0VendorRqst
00EE
00EE ; Unsupported request !!!
00EE 80 B8 [05] jmp USBEventEP0Stall ; Oops! We don't support whatever
00F0 ; request was made.
00F0
00F0 ;//$PAGE
00F0 ;********************************************************
00F0 ; USBEventEP0SetupIsSet()
00F0 ; @func End point event SETUP to set address.
00F0 ; @devnote Runs in interrupt enabled context.
00F0 ;********************************************************
00F0 USBEventEP0SetupIsSetAddress:
00F0
00F0 ; Set device address?
00F0 1A 71 [06] mov a,[USBRqstMessage]
00F2 16 05 [04] cmp a,USBRqstSetAddress
00F4 A0 FE [05] jz USBEventEP0SetupSetAddress ; Yes
00F6
00F6 ; Set device configuration?
00F6 1A 71 [06] mov a,[USBRqstMessage]
00F8 16 09 [04] cmp a,USBRqstSetConfiguration
00FA A1 08 [05] jz USBEventEP0SetupSetConfig ; Yes
00FC
00FC ; Unsupported set request !!!
00FC 80 B8 [05] jmp USBEventEP0Stall ; No. Stall
00FE
00FE ;********************************************************
00FE ; USBEventEP0SetupSetAddress()
00FE ; @func End point zero event SETUP to set address.
00FE ; @devnote Runs in interrupt enabled context.
00FE ; @comm
00FE ; The status token of the SetAddress is an IN. So, we send status manually.
00FE ;********************************************************
00FE USBEventEP0SetupSetAddress:
00FE
00FE ; Send ACK
00FE 20 [04] NOP
00FF 1F [04] XPAGE
0100 92 23 [10] call USBSendACK
0102 ; Now that we have been acknowleged, we actually set the address.
0102 ; This is different from all other commands which execute first
0102 ; and then acknowlege (_________________)
0102
0102 ; Set Address
0102 1A 72 [06] mov a,[USBRqstWordValueLo]
0104 2A 12 [05] iowr USBDeviceAddress
0106
0106 ; Done
0106 80 B4 [05] jmp USBEventEP0End
0108
0108 ;********************************************************
0108 ; USBEventEP0SetupSetConfig()
0108 ; @func End point zero event SETUP to Set Configuration.
0108 ; @devnote Runs in interrupt enabled context.
0108 ; 1
0108 ; set enumerated (gbSysEnumerated) state,
0108 ; enable GPIO (and EP1, if appropriate)
0108 ; Enable P0 and P1
0108 ; 0
0108 ; Reset enumerated (gbSysEnumerated) state,
0108 ; Turn off LED
0108 ; Reset variables
0108 ; Disable GPIO and EP1
0108 ; Disable dallas chip and P0 and P1
0108 ;********************************************************
0108 USBEventEP0SetupSetConfig:
0108
0108 ; Enumerated !
0108 ; Write a 0 to the LED on P13 to turn it on
0108 19 F7 [04] mov a,~(LED_ON)
010A 2A 01 [05] iowr SysPort1
010C
010C 19 10 [04] mov a,10h
010E 2A 11 [05] iowr USBEndP1TxConfig;NAK
0110
0110 ; enable all appropriate irq's
0110 19 5C [04] mov a,SysIntTimer1024us | SysIntGPIO | SysIntUSBEndP0 | SysIntUSBEndP1
0112 31 20 [05] mov [gbSysInterruptMask],a
0114
0114 ; Send ACK
0114 92 23 [10] call USBSendACK
0116 80 B4 [05] jmp USBEventEP0End
0118
0118 ;//$PAGE
0118 ;********************************************************
0118 ; USBEventEP0SetupGetDescriptor()
0118 ; @func End point zero event SETUP to Get Descriptor.
0118 ; @devnote Runs in interrupt enabled context.
0118 ;********************************************************
0118 USBEventEP0SetupGetDescriptor:
0118
0118 ; Get descriptor type
0118 1A 73 [06] mov a,[USBRqstWordValueHi]
011A
011A USBEventEP0SetupGetDescriptorDevice:
011A ; Device Descriptor?
011A 16 01 [04] cmp a,USBDescriptorTypeDevice
011C B1 2C [05] jnz USBEventEP0SetupGetDescriptorConfig ; No
011E
011E ;*********************************************
011E ; Get Device Descriptor Event
011E ;*********************************************
011E ; Descriptor pointer
011E 19 00 [04] mov a,(USBDeviceDescription -USBSendROMBufferBase)
0120 31 2A [05] mov [gbUSBSendBuffer],a
0122
0122 ; Descriptor size
0122 19 12 [04] mov a,12h ;[USBDeviceDescription]
0124 31 29 [05] mov [gbUSBSendBytes],a
0126
0126 ; Check request size field
0126 91 B6 [10] call USBSendDescriptorCheckLength
0128
0128 ; Send buffer
0128 91 C7 [10] call USBSendROMBuffer
012A 80 B4 [05] jmp USBEventEP0End
012C
012C USBEventEP0SetupGetDescriptorConfig:
012C ; Configuration Descriptor?
012C 16 02 [04] cmp a,USBDescriptorTypeConfig
012E B1 42 [05] jnz USBEventEP0SetupGetDescriptorString ; No
0130
0130 ;*********************************************
0130 ; Get Configuration Descriptor Event
0130 ;*********************************************
0130 ; Descriptor pointer
0130 19 12 [04] mov a,(USBConfigurationDescription -USBSendROMBufferBase)
0132 31 2A [05] mov [gbUSBSendBuffer],a
0134
0134 ; Descriptor size
0134 19 09 [04] mov a,09h ;[USBConfigurationDescription]
0136 01 09 [04] add a,09h ;[USBInterfaceDescription]
0138 01 07 [04] add a,07h ;[USBEndPointDescriptionInt]
013A 31 29 [05] mov [gbUSBSendBytes],a
013C
013C ; Check request size field
013C 91 B6 [10] call USBSendDescriptorCheckLength
013E
013E ; Send buffer
013E 91 C7 [10] call USBSendROMBuffer
0140 80 B4 [05] jmp USBEventEP0End
0142
0142 USBEventEP0SetupGetDescriptorString:
0142 ; Get String Descriptor?
0142 16 03 [04] cmp a,USBDescriptorTypeString
0144 B1 B4 [05] jnz USBEventEP0SetupGetDescriptorEnd ; No
0146
0146 ;*********************************************
0146 ; Get String Descriptor Event
0146 ;*********************************************
0146
0146 ; Get string descriptor index
0146 1A 72 [06] mov a,[USBRqstWordValueLo]
0148
0148 USBEventEP0SetupGetDescriptorString0:
0148 16 00 [04] cmp a,0h
014A B1 5A [05] jnz USBEventEP0SetupGetDescriptorString1 ; No
014C
014C ;*********************************************
014C ; Get String Language(s) Descriptor Event
014C ;*********************************************
014C ; Descriptor pointer
014C 19 2B [04] mov a,(USBStringLanguageDescription -USBSendROMBufferBase)
014E 31 2A [05] mov [gbUSBSendBuffer],a
0150
0150 ; Descriptor size
0150 19 04 [04] mov a,4h ;[USBStringLanguageDescription]
0152 31 29 [05] mov [gbUSBSendBytes],a
0154
0154 ; Check request size field
0154 91 B6 [10] call USBSendDescriptorCheckLength
0156
0156 ; Send buffer
0156 91 C7 [10] call USBSendROMBuffer
0158 80 B4 [05] jmp USBEventEP0End
015A
015A USBEventEP0SetupGetDescriptorString1:
015A 16 01 [04] cmp a,1
015C B1 6C [05] jnz USBEventEP0SetupGetDescriptorString2 ; No
015E
015E ;*********************************************
015E ; Get String 1 Descriptor Event
015E ;*********************************************
015E ; Descriptor pointer
015E 19 2F [04] mov a,(USBStringDescription1 -USBSendROMBufferBase)
0160 31 2A [05] mov [gbUSBSendBuffer],a
0162
0162 ; Descriptor size
0162 19 10 [04] mov a,10h ;[USBStringDescription1]
0164 31 29 [05] mov [gbUSBSendBytes],a
0166
0166 ; Check request size field
0166 91 B6 [10] call USBSendDescriptorCheckLength
0168
0168 ; Send buffer
0168 91 C7 [10] call USBSendROMBuffer
016A 80 B4 [05] jmp USBEventEP0End
016C
016C USBEventEP0SetupGetDescriptorString2:
016C 16 02 [04] cmp a,2
016E B1 7E [05] jnz USBEventEP0SetupGetDescriptorString3 ; No
0170
0170 ;*********************************************
0170 ; Get String 2 Descriptor Event
0170 ;*********************************************
0170 ; Descriptor pointer
0170 19 3F [04] mov a,(USBStringDescription2 -USBSendROMBufferBase)
0172 31 2A [05] mov [gbUSBSendBuffer],a
0174
0174 ; Descriptor size
0174 19 10 [04] mov a,10h ;[USBStringDescription2]
0176 31 29 [05] mov [gbUSBSendBytes],a
0178
0178 ; Check request size field
0178 91 B6 [10] call USBSendDescriptorCheckLength
017A
017A ; Send buffer
017A 91 C7 [10] call USBSendROMBuffer
017C 80 B4 [05] jmp USBEventEP0End
017E
017E USBEventEP0SetupGetDescriptorString3:
017E 16 03 [04] cmp a,3
0180 B1 90 [05] jnz USBEventEP0SetupGetDescriptorString4 ; No
0182
0182 ;*********************************************
0182 ; Get String 3 Descriptor Event
0182 ;*********************************************
0182 ; Descriptor pointer
0182 19 4F [04] mov a,(USBStringDescription3 -USBSendROMBufferBase)
0184 31 2A [05] mov [gbUSBSendBuffer],a
0186
0186 ; Descriptor size
0186 19 0A [04] mov a,0Ah ;[USBStringDescription3]
0188 31 29 [05] mov [gbUSBSendBytes],a
018A
018A ; Check request size field
018A 91 B6 [10] call USBSendDescriptorCheckLength
018C
018C ; Send buffer
018C 91 C7 [10] call USBSendROMBuffer
018E 80 B4 [05] jmp USBEventEP0End
0190
0190 USBEventEP0SetupGetDescriptorString4:
0190 16 04 [04] cmp a,4
0192 B1 A2 [05] jnz USBEventEP0SetupGetDescriptorString5 ; No
0194
0194 ;*********************************************
0194 ; Get String 4 Descriptor Event
0194 ;*********************************************
0194 ; Descriptor pointer
0194 19 59 [04] mov a,(USBStringDescription4 -USBSendROMBufferBase)
0196 31 2A [05] mov [gbUSBSendBuffer],a
0198
0198 ; Descriptor size
0198 19 28 [04] mov a,28h ;[USBStringDescription4]
019A 31 29 [05] mov [gbUSBSendBytes],a
019C
019C ; Check request size field
019C 91 B6 [10] call USBSendDescriptorCheckLength
019E
019E ; Send buffer
019E 91 C7 [10] call USBSendROMBuffer
01A0 80 B4 [05] jmp USBEventEP0End
01A2
01A2 USBEventEP0SetupGetDescriptorString5:
01A2 16 05 [04] cmp a,5
01A4 B1 B4 [05] jnz USBEventEP0SetupGetDescriptorEnd ; No
01A6
01A6 ;*********************************************
01A6 ; Get String 5 Descriptor Event
01A6 ;*********************************************
01A6 ; Descriptor pointer
01A6 19 81 [04] mov a,(USBStringDescription5 -USBSendROMBufferBase)
01A8 31 2A [05] mov [gbUSBSendBuffer],a
01AA
01AA ; Descriptor size
01AA 19 3E [04] mov a,3Eh ;[USBStringDescription5]
01AC 31 29 [05] mov [gbUSBSendBytes],a
01AE
01AE ; Check request size field
01AE 91 B6 [10] call USBSendDescriptorCheckLength
01B0
01B0 ; Send buffer
01B0 91 C7 [10] call USBSendROMBuffer
01B2 80 B4 [05] jmp USBEventEP0End
01B4
01B4 USBEventEP0SetupGetDescriptorEnd:
01B4 ; Unsupported Get request !!!
01B4 80 B8 [05] jmp USBEventEP0Stall
01B6
01B6 ;//$PAGE
01B6 ;********************************************************
01B6 ; USBSendDescriptorCheckLength()
01B6 ; @func Check and update send length for Get Descriptor
01B6 ; requests on end point 0.
01B6 ; @parm BYTE | gbUSBSendBytes | Number of bytes to send.
01B6 ;********************************************************
01B6 USBSendDescriptorCheckLength:
01B6
01B6 ; High byte set? (Assume <255 bytes)
01B6 1A 77 [06] mov a,[USBEndP0FIFO_7]
01B8 16 00 [04] cmp a,0
01BA B1 C6 [05] jnz USBSendDescriptorCheckLengthEnd ; Yes
01BC
01BC ; Check size
01BC 1A 76 [06] mov a,[USBEndP0FIFO_6]
01BE 17 29 [06] cmp a,[gbUSBSendBytes]
01C0 A1 C6 [05] jz USBSendDescriptorCheckLengthEnd ; equal
01C2 D1 C6 [05] jnc USBSendDescriptorCheckLengthEnd ; greater than
01C4
01C4 ; New size
01C4 31 29 [05] mov [gbUSBSendBytes],a
01C6
01C6 USBSendDescriptorCheckLengthEnd:
01C6 3F [08] ret
01C7
01C7 ;//$PAGE
01C7 ;********************************************************
01C7 ; USBSendROMBuffer()
01C7 ; @func Send a number of ROM bytes on end point 0.
01C7 ; @parm BYTE | gbUSBSendBytes | Number of bytes to send.
01C7 ; @parm BYTE | gbUSBSendBuffer | Offset from ROM base
01C7 ; of data to send.
01C7 ; @comm assumes IN packets are ignored in the interrupt routine
01C7 ; @devnote Enables interrupts
01C7 ;********************************************************
01C7 USBSendROMBuffer:
01C7
01C7 ; Clear flag
01C7 19 00 [04] mov a,0h
01C9 2A 14 [05] iowr USBEndP0RxStatus
01CB
01CB ; Enable interrupts
01CB 1A 20 [06] mov a,[gbSysInterruptMask]
01CD 10 F7 [04] and a,~SysIntUSBEndP0
01CF 2A 20 [05] iowr SysInterrupt
01D1
01D1 ; Auto ACK OUT packet (This would be a Status Out)
01D1 19 08 [04] mov a,USBControlAckStatusData
01D3 2A 13 [05] iowr USBControl
01D5
01D5 ; Initialize sequence
01D5 19 00 [04] mov a,0h
01D7 31 28 [05] mov [gbUSBSendSequence],a
01D9
01D9 ; Send count
01D9 1A 29 [06] mov a,[gbUSBSendBytes]
01DB
01DB USendROMBufferLoop:
01DB ; One 8-byte chunk or less left?
01DB 16 08 [04] cmp a,08h
01DD A1 F5 [05] jz USendROMBufferLoopDone ; exactly 8 bytes left, branch
01DF C1 F5 [05] jc USendROMBufferLoopDone ; less than 8 bytes left, branch
01E1
01E1 ; more than 8 bytes left, fall through and loop
01E1 ; until there are 8 bytes or less.
01E1 ; Save count
01E1 2D [05] push a
01E2
01E2 ; Send 8 byte chunk
01E2 19 08 [04] mov a,08h
01E4 31 29 [05] mov [gbUSBSendBytes],a
01E6 91 F8 [10] call _USBSendROMBuffer
01E8
01E8 ; Check for OUT packet cancelling send
01E8 29 14 [05] iord USBEndP0RxStatus
01EA 10 02 [04] and a,USBEndP0RxOut
01EC
01EC ; Restore count
01EC 2B [04] pop a
01ED
01ED ; Handle exception: OUT packet cancel send
01ED B1 F7 [05] jnz USendROMBufferLoopExit ; Cancelled
01EF
01EF ; Save bytes left
01EF 07 08 [04] sub a,08h
01F1 31 29 [05] mov [gbUSBSendBytes],a
01F3 81 DB [05] jmp USendROMBufferLoop
01F5
01F5 USendROMBufferLoopDone:
01F5 ; Send last 8 or less bytes
01F5 91 F8 [10] call _USBSendROMBuffer
01F7
01F7 USendROMBufferLoopExit:
01F7 3F [08] ret
01F8
01F8 ;//$PAGE
01F8 ;********************************************************
01F8 ; _USBSendROMBuffer()
01F8 ; @func Buffer and inialize USB send of up
01F8 ; to 8 bytes of ROM data on end point 0.
01F8 ; @comm affects gbUSBSendBytes &amt; gbUSBSendBuffer
01F8 ;********************************************************
01F8 _USBSendROMBuffer:
01F8
01F8 ; Save x
01F8 2E [05] push x
01F9
01F9 ; Initialize
01F9 1C 00 [04] mov x,0h
01FB
01FB _USendROMBufferLoop:
01FB ; Any more?
01FB 19 00 [04] mov a,0h
01FD 17 29 [06] cmp a,[gbUSBSendBytes]
01FF 1F [04] XPAGE
0200 A2 0F [05] jz _USendROMBufferLoopDone ; No more
0202 27 29 [07] dec [gbUSBSendBytes]
0204
0204 ; Move bytes to FIFO
0204 1A 2A [06] mov a,[gbUSBSendBuffer]
0206 F2 64 [14] index USBSendROMBufferBase
0208 32 70 [06] mov [x +USBEndP0FIFO],a
020A 22 [04] inc x
020B
020B ; Next byte
020B 23 2A [07] inc [gbUSBSendBuffer]
020D 81 FB [05] jmp _USendROMBufferLoop
020F
020F _USendROMBufferLoopDone:
020F ; Re-enable reception
020F 19 00 [04] mov a,0h
0211 2A 14 [05] iowr USBEndP0RxStatus
0213
0213 ; Toggle sequence
0213 19 40 [04] mov a,USBEndP0TxSequence
0215 37 28 [07] xor [gbUSBSendSequence],a
0217
0217 ; Send bytes
0217 2E [05] push x
0218 2B [04] pop a
0219 0E 28 [06] or a,[gbUSBSendSequence]
021B 0D 80 [04] or a,USBEndP0TxRespond
021D 2A 10 [05] iowr USBEndP0TxConfig
021F
021F ; The FIFO is loaded, go and wait untill it's read
021F 92 2D [10] call USBSendWaitForComplete
0221
0221 _USendROMBufferEnd:
0221 ; Restore and exit
0221 2C [04] pop x
0222 3F [08] ret
0223
0223 ;//$PAGE
0223 ;********************************************************
0223 ; USBSendACK()
0223 ; func Respond to a "USB Status In" with a zero byte buffer with
0223 ; Sequence field set) on end point 0.
0223 ; Called by SetAddress and SetConfig commands
0223 ;********************************************************
0223 USBSendACK:
0223
0223 ; Status response to Status In is to send a zero byte packet
0223 19 C0 [04] mov a,USBEndP0TxRespond | USBEndP0TxSequence
0225 2A 10 [05] iowr USBEndP0TxConfig
0227
0227 ; Enable interrupts
0227 1A 20 [06] mov a,[gbSysInterruptMask]
0229 2A 20 [05] iowr SysInterrupt
022B
022B ; Wait for send complete
022B 82 2D [05] jmp USBSendWaitForComplete
022D
022D ;********************************************************
022D ; USBSendWaitForComplete()
022D ; @func Wait for send to complete on end point 0.
022D ;********************************************************
022D
022D ; At some point, either the 0 data will be ACK'd or a SETUP
022D ; will come in.
022D ; Either event will cause the "Enable Respond
022D ; to In Packets" to be reset, and we will fall out of the loop.
022D ; In either case, an EP0 IRQ will be generated (5.9.2.2 in Cyp
022D ; device spec) if EP0 irq is enabled.
022D
022D USBSendWaitForComplete:
022D
022D ; Poll the send complete bit
022D ; This will be reset when the data has been sent to the host
022D ; and the host has ACK's, or the host has sent another SETUP
022D ; which should terminate this activity in any case.
022D 29 10 [05] iord USBEndP0TxConfig
022F 10 80 [04] and a,USBEndP0TxRespond
0231 A2 3B [05] jz USBSendWaitComplete
0233
0233 ; Check for OUT packet cancelling send. A STATUS OUT should
0233 ; terminate any pending IN's. A Setup could also set the Out bit.
0233 29 14 [05] iord USBEndP0RxStatus
0235 10 02 [04] and a,USBEndP0RxOut
0237 B2 3B [05] jnz USBSendWaitComplete ; Cancelled
0239
0239 ; Keep waiting
0239 82 2D [05] jmp USBSendWaitForComplete
023B
023B USBSendWaitComplete:
023B 3F [08] ret
023C
023C ;********************************************************
023C ; USBEventEP0VendorRqst()
023C ; @func Vendor request on end point zero.
023C ; @devnote Runs in interrupt disabled context.
023C ;********************************************************
023C USBEventEP0VendorRqst:
023C
023C ; Save it
023C 2E [05] push x
023D
023D ; Check Protocol
023D 1A 71 [06] mov a,[USBEndP0FIFO_1]
023F 16 00 [04] cmp a,0h
0241 B0 B8 [05] jnz USBEventEP0Stall ; No
0243
0243 ;*********************************************
0243 ; Reset Counter Event
0243 ;*********************************************
0243 ; Initialize Counter
0243 19 00 [04] mov a,0
0245 31 2D [05] mov [gbButtonClicks],a ; Initial state of 0, no button pushed
0247 31 78 [05] mov [USBEndP1FIFO_0],a
0249
0249 29 11 [05] iord USBEndP1TxConfig
024B 10 40 [04] and a,40h
024D 0D 91 [04] or a,91h
024F 2A 11 [05] iowr USBEndP1TxConfig
0251
0251 ;USBEventEP0VendorRqstFinish:
0251
0251 ; Protocol ACK
0251 19 42 [04] mov a,42h
0253 31 70 [05] mov [USBEndP0FIFO_0],a
0255
0255 ; Auto ACK OUT packet
0255 19 08 [04] mov a,USBControlAckStatusData
0257 2A 13 [05] iowr USBControl
0259
0259 ; Send bytes as Data1
0259 19 08 [04] mov a,8
025B 0D 40 [04] or a,USBEndP0TxSequence
025D 0D 80 [04] or a,USBEndP0TxRespond
025F 2A 10 [05] iowr USBEndP0TxConfig
0261
0261 ;call USBSendWaitForComplete
0261
0261 ; Restore it
0261 2C [04] pop x
0262
0262 ; Return
0262 80 B4 [05] jmp USBEventEP0End
0264
0264 ;********************************************************
0264 ; Data Segment (ROM)
0264 ;********************************************************
0264 USBSendROMBufferBase:
0264 USBDeviceDescription:
0264 12 [00] db 12h ; Length
0265 01 [00] db 01h ; Type (1=device)
0266 10 [00] db 10h,01h ; Complies to USB Spec. v1.10
0267 01 [00]
0268 00 [00] db 00h ; Class code (0=??)
0269 00 [00] db 00h ; SubClass code (0=??)
026A 00 [00] db 00h ; Protocol (0=none)(9.6.1)
026B 08 [00] db 08h ; Max. packet size for port0
026C 34 [00] db 34h,12h ; Vendor ID: (0x1234=WahBook)
026D 12 [00]
026E 78 [00] db 78h,56h ; Product ID (0x01=USB Counter)
026F 56 [00]
0270 00 [00] db 00h,01h ; Device release v1.00
0271 01 [00]
0272 01 [00] db 01h ; Manufacturer string descriptor index (0=none)
0273 02 [00] db 02h ; Product string descriptor index (0=none)
0274 03 [00] db 03h ; Serial number string descriptor index (0=none)
0275 01 [00] db 01h ; Number of possible configurations
0276 USBDeviceDescriptionEnd:
0276
0276 ;*************************************************
0276 ;
0276 USBConfigurationDescription:
0276 09 [00] db 09h ; Length
0277 02 [00] db 02h ; Type (2=config)
0278 19 [00] db 19h,00h ; Total data length (1 config,1 interface,1 endpoints)
0279 00 [00]
027A 01 [00] db 01h ; Interface supported (1=???)
027B 01 [00] db 01h ; Configuration value (1=???)
027C 04 [00] db 04h ; Confituration string descriptor index (0=none)
027D 80 [00] db 80h ; Configuration (bus powered)
027E 32 [00] db 32h ; Maximum power consumption in 2mA units
027F USBConfigurationDescriptionEnd:
027F
027F ;*************************************************
027F ;
027F USBInterfaceDescription:
027F 09 [00] db 09h ; Length
0280 04 [00] db 04h ; Type (4=interface)
0281 00 [00] db 00h ; Number of interfaces (0 based)
0282 00 [00] db 00h ; Alternate settings
0283 01 [00] db 01h ; Number of endpoints (1 based) (9.6.3)
0284 00 [00] db 00h ; Class code (0=non-specified,1=kb,2=mouse,3=joystick ???)
0285 00 [00] db 00h ; Subclass code (0=???)
0286 00 [00] db 00h ; Protocol code (0=non-specified)
0287 05 [00] db 05h ; Interface string index (0=non-specified, 1,2,3,...)
0288 USBInterfaceDescriptionEnd:
0288
0288 ;*************************************************
0288 ; Never used for EP0
0288 USBEndPointDescriptionInt:
0288 07 [00] db 07h ; Length
0289 05 [00] db 05h ; Type (5=endpoint)
028A 81 [00] db 81h ; Address (EP#=1 | [0x80=IN, 0=OUT])
028B 03 [00] db 03h ; Attribute (0=control,1=isochronous,2=bulk,3=interrupt)
028C 08 [00] db 08h,00h ; Max packet size
028D 00 [00]
028E B8 [00] db B8h ; Interval (200 ms)
028F USBEndPointDescriptionIntEnd:
028F
028F ;*************************************************
028F ;
028F USBStringLanguageDescription:
028F 04 [00] db 04h ; Length
0290 03 [00] db 03h ; Type (3=string)
0291 09 [00] db 09h ; Language: English
0292 01 [00] db 01h ; Sub-language: US
0293
0293 USBStringDescription1:
0293 10 [00] db 10h ; Length
0294 03 [00] db 03h ; Type (3=string)
0295 57 00 ... dsu "WAHBOOK"
41 00 48 00 42 00 4F 00 4F 00 4B 00
02A3
02A3 USBStringDescription2:
02A3 10 [00] db 10h ; Length
02A4 03 [00] db 03h ; Type (3=string)
02A5 43 00 ... dsu "Counter"
6F 00 75 00 6E 00 74 00 65 00 72 00
02B3
02B3 USBStringDescription3:
02B3 0A [00] db 0Ah ; Length
02B4 03 [00] db 03h ; Type (3=string)
02B5 30 00 ... dsu "0001"
30 00 30 00 31 00
02BD
02BD USBStringDescription4:
02BD 28 [00] db 28h ; Length
02BE 03 [00] db 03h ; Type (3=string)
02BF 43 00 ... dsu "Count Button Clicks"
6F 00 75 00 6E 00 74 00 20 00 42 00 75 00 74 00 74 00 6F 00 6E 00 20 00 43 00
6C 00 69 00 63 00 6B 00 73 00
02E5
02E5 USBStringDescription5:
02E5 3E [00] db 3Eh ; Length
02E6 03 [00] db 03h ; Type (3=string)
02E7 45 00 ... dsu "EndPoint1 200ms Interrupt Pipe"
6E 00 64 00 50 00 6F 00 69 00 6E 00 74 00 31 00 20 00 32 00 30 00 30 00 6D 00
73 00 20 00 49 00 6E 00 74 00 65 00 72 00 72 00 75 00 70 00 74 00 20 00 50 00
69 00 70 00 65 00

CheckSum = C186
Warnings = 0
Errors = 0

Product: CPU=63, RAM=128 bytes, ROM=4096K bytes

************ SYMBOLIC REFERENCE TABLE ************

Value Label # Uses
----- -------------------- ------
4 = Button_Pin 3
5f Inc_Counter 1
8 = LED_ON 1
42 MainLoop 1
95 STimerNoDebounce 3
72 Suspend_End 2
9e SysGPIOButtonDebouncing 0
99 SysGPIOEvent 1
40 = SysIntGPIO 1
1 = SysIntReserved0 0
20 = SysIntReserved5 0
4 = SysIntTimer1024us 2
2 = SysIntTimer128us 0
8 = SysIntUSBEndP0 3
10 = SysIntUSBEndP1 1
80 = SysIntWakeUp 0
20 = SysInterrupt 9
0 = SysPort0 1
30 = SysPort0ISinkPin0 0
31 = SysPort0ISinkPin1 0
32 = SysPort0ISinkPin2 0
33 = SysPort0ISinkPin3 0
34 = SysPort0ISinkPin4 0
35 = SysPort0ISinkPin5 0
36 = SysPort0ISinkPin6 0
37 = SysPort0ISinkPin7 0
4 = SysPort0IntEnable 1
8 = SysPort0PullUp 1
1 = SysPort1 3
38 = SysPort1ISinkPin0 0
39 = SysPort1ISinkPin1 0
3a = SysPort1ISinkPin2 0
3b = SysPort1ISinkPin3 0
5 = SysPort1IntEnable 1
9 = SysPort1PullUp 1
ff = SysStatus 2
10 = SysStatusPowerOn 0
2 = SysStatusReserved2 0
4 = SysStatusReserved3 0
80 = SysStatusReserved7 0
1 = SysStatusRun 0
8 = SysStatusSuspend 0
20 = SysStatusUSBReset 0
40 = SysStatusWDReset 0
23 = SysTimer 0
48 SysTimer1024usEvent 1
22 = SysTimerExternal 0
10 SysUnUsed 3
21 = SysWatchDog 1
276 USBConfigurationDescription 1
27f USBConfigurationDescriptionEnd 0
13 = USBControl 5
10 = USBControlAckOutData 0
8 = USBControlAckStatusData 2
1 = USBControlBusActive 0
4 = USBControlReserve2 0
20 = USBControlReserve5 0
40 = USBControlReserve6 0
80 = USBControlReserve7 0
2 = USBControlResume 0
2 = USBDescriptorTypeConfig 1
1 = USBDescriptorTypeDevice 1
5 = USBDescriptorTypeEndPoint 0
4 = USBDescriptorTypeInterface 0
6 = USBDescriptorTypeReserved06 0
3 = USBDescriptorTypeString 1
12 = USBDeviceAddress 1
264 USBDeviceDescription 1
276 USBDeviceDescriptionEnd 0
70 = USBEndP0FIFO 1
70 = USBEndP0FIFO_0 4
71 = USBEndP0FIFO_1 2
72 = USBEndP0FIFO_2 1
73 = USBEndP0FIFO_3 1
74 = USBEndP0FIFO_4 0
75 = USBEndP0FIFO_5 0
76 = USBEndP0FIFO_6 1
77 = USBEndP0FIFO_7 1
10 = USBEndP0RxCount0 0
20 = USBEndP0RxCount1 0
40 = USBEndP0RxCount2 0
80 = USBEndP0RxCount3 0
8 = USBEndP0RxDataFlag 0
4 = USBEndP0RxIn 0
2 = USBEndP0RxOut 2
1 = USBEndP0RxSetup 1
14 = USBEndP0RxStatus 6
10 = USBEndP0TxConfig 6
1 = USBEndP0TxCount0 0
2 = USBEndP0TxCount1 0
4 = USBEndP0TxCount2 0
8 = USBEndP0TxCount3 0
80 = USBEndP0TxRespond 4
10 = USBEndP0TxRxErr 0
40 = USBEndP0TxSequence 3
20 = USBEndP0TxStall 1
78 = USBEndP1FIFO 0
78 = USBEndP1FIFO_0 2
79 = USBEndP1FIFO_1 0
7a = USBEndP1FIFO_2 0
7b = USBEndP1FIFO_3 0
7c = USBEndP1FIFO_4 0
7d = USBEndP1FIFO_5 0
7e = USBEndP1FIFO_6 0
7f = USBEndP1FIFO_7 0
11 = USBEndP1TxConfig 7
1 = USBEndP1TxCount0 0
2 = USBEndP1TxCount1 0
4 = USBEndP1TxCount2 0
8 = USBEndP1TxCount3 0
10 = USBEndP1TxEnable 0
80 = USBEndP1TxRespond 0
40 = USBEndP1TxSequence 0
20 = USBEndP1TxStall 0
ad USBEndPoint0Event 1
a2 USBEndPoint1Event 1
288 USBEndPointDescriptionInt 0
28f USBEndPointDescriptionIntEnd 0
b4 USBEventEP0End 12
118 USBEventEP0SetupGetDescriptor 1
12c USBEventEP0SetupGetDescriptorConfig 1
11a USBEventEP0SetupGetDescriptorDevice 0
1b4 USBEventEP0SetupGetDescriptorEnd 2
142 USBEventEP0SetupGetDescriptorString 1
148 USBEventEP0SetupGetDescriptorString0 0
15a USBEventEP0SetupGetDescriptorString1 1
16c USBEventEP0SetupGetDescriptorString2 1
17e USBEventEP0SetupGetDescriptorString3 1
190 USBEventEP0SetupGetDescriptorString4 1
1a2 USBEventEP0SetupGetDescriptorString5 1
f0 USBEventEP0SetupIsSetAddress 1
fe USBEventEP0SetupSetAddress 1
108 USBEventEP0SetupSetConfig 1
da USBEventEP0SetupTargetDeviceIN 0
ce USBEventEP0SetupTargetDeviceOUT 0
e2 USBEventEP0SetupTargetEndpointIN 0
d6 USBEventEP0SetupTargetEndpointOUT 0
de USBEventEP0SetupTargetInterfaceIN 0
d2 USBEventEP0SetupTargetInterfaceOUT 0
e6 USBEventEP0SetupTargetVendorIN_OUT 0
b8 USBEventEP0Stall 8
23c USBEventEP0VendorRqst 1
c0 USBEventEP0_SETUP 1
27f USBInterfaceDescription 0
288 USBInterfaceDescriptionEnd 0
4b = USBRawProtocolACK 0
96 = USBRawProtocolIn 0
5a = USBRawProtocolNAK 0
87 = USBRawProtocolOut 0
c3 = USBRawProtocolPort0 0
d2 = USBRawProtocolPort1 0
b4 = USBRawProtocolSetup 0
1 = USBRqstClearFeature 0
8 = USBRqstGetConfiguration 0
6 = USBRqstGetDescriptor 0
a = USBRqstGetInterface 0
0 = USBRqstGetStatus 0
71 = USBRqstMessage 2
2 = USBRqstReserved02 0
4 = USBRqstReserved04 0
d = USBRqstReserved0D 0
5 = USBRqstSetAddress 1
9 = USBRqstSetConfiguration 1
7 = USBRqstSetDescriptor 0
3 = USBRqstSetFeature 0
b = USBRqstSetInterface 0
c = USBRqstSynchFrame 0
0 = USBRqstTargetDevice 2
2 = USBRqstTargetEndPoint 4
1 = USBRqstTargetInterface 2
3 = USBRqstTargetOther 0
70 = USBRqstType 0
20 = USBRqstTypeClass 0
80 = USBRqstTypeDirection 5
60 = USBRqstTypeMask 0
60 = USBRqstTypeReserved 0
0 = USBRqstTypeStandard 0
40 = USBRqstTypeVendor 2
73 = USBRqstWordValueHi 1
72 = USBRqstWordValueLo 2
223 USBSendACK 2
1b6 USBSendDescriptorCheckLength 8
1c6 USBSendDescriptorCheckLengthEnd 3
1c7 USBSendROMBuffer 8
264 USBSendROMBufferBase 9
23b USBSendWaitComplete 2
22d USBSendWaitForComplete 3
293 USBStringDescription1 1
2a3 USBStringDescription2 1
2b3 USBStringDescription3 1
2bd USBStringDescription4 1
2e5 USBStringDescription5 1
28f USBStringLanguageDescription 1
1db USendROMBufferLoop 1
1f5 USendROMBufferLoopDone 2
1f7 USendROMBufferLoopExit 1
1f8 _USBSendROMBuffer 2
221 _USendROMBufferEnd 0
1fb _USendROMBufferLoop 1
20f _USendROMBufferLoopDone 1
2d = gbButtonClicks 4
2c = gbButtonDebounce 5
2b = gbSuspendCount 5
50 = gbSysDataStack 0
70 = gbSysFIFO 0
20 = gbSysInterruptMask 11
0 = gbSysProgramStack 0
2a = gbUSBSendBuffer 10
29 = gbUSBSendBytes 17
28 = gbUSBSendSequence 4
15 main 1