;*********************************************************************
; Functin Library
; Author : Ansonku
; EMail : ansonku@holtek.com.tw
; Date : 2005/01/11
;*********************************************************************
#include ht82a832r.inc
#include const.inc
;=====================================================================
; Descriptor Label
;=====================================================================
;2005/11/01 ClearFeature_Endpoint add Send_Hand_Shake
;
;
;
;
;
;
;
;
extern control_read_table:NEAR
extern device_desc_table:NEAR
extern config_desc_table:NEAR
extern end_config_desc_table:NEAR
extern hid_report_desc_table:NEAR
extern end_hid_report_desc_table:NEAR
extern USBStringLanguageDescription:NEAR
extern USBStringDescription1:NEAR
extern USBStringDescription2:NEAR
extern USBStringDescription3:NEAR
extern HID_Desc:NEAR
extern config_desc_length:NEAR
extern hid_desc_length:NEAR
extern report_desc_length:NEAR
extern USB_EP0_ISR_END:NEAR
;=====================================================================
; External Variable
;=====================================================================
;modify 2006-09-22
extern FIFO_SIZE:byte
;-----------------------------
extern FIFO_SendLen:byte
extern FIFO_Type:byte
extern FIFO_Request:byte
extern FIFO_wValueL:byte
extern FIFO_wValueH:byte
extern FIFO_wIndexL:byte
extern FIFO_wIndexH:byte
extern FIFO_wLengthL:byte
extern FIFO_wLengthH:byte
extern FIFO_Out1:byte
extern FIFO_Out2:byte
extern FIFO_Out3:byte
extern FIFO_Out4:byte
extern FIFO_Out5:byte
extern FIFO_Out6:byte
extern FIFO_Out7:byte
extern FIFO_Out8:byte
extern USB_Interface:byte
extern USB_Interface_Alt:byte
extern USB_Configuration:byte
extern FIFO_ADDR:byte
extern Loop_Counter:byte
extern Data_Count:byte
extern Data_Start:byte
extern nCmdIndex1:byte
extern nCmdIndex2:byte
extern nCmdIndex3:byte
extern VolumeH_Save:byte
extern VolumeL_Save:byte
extern bFlag_Audio_Mute:bit
;modify 2006-09-28
extern bFlag_Mic_Mute:bit
;=====================================================================
; FIFO Status
;=====================================================================
;FIFO
extern FIFO_TEMP:byte
extern bFlag_Real_Cmd:bit
extern bFlag_FIFO_Ready:bit
extern bFlag_FIFO_LEN0:bit
extern bFlag_RD_HTable:bit
extern bFlag_wait_control_out:bit
extern bFlag_SET_ADDRESS:bit
extern bFlag_SCMD:bit
extern bFlag_Enum_Ready:bit
extern bFlag_SetConfiguration_Ready:bit
extern bFlag_SetInterface_Ready:bit
extern StageOne:NEAR
extern USB_ISR_END:NEAR
;********************************************************************
; USB LIB
; 1.CHECK FIFOX RD READEY? bFlag_FIFO_Ready = 1:bFlag_FIFO_Ready = 0
;********************************************************************
FIFO0_RD_CHECK:
MOV A,UCC
OR A,00000111b
AND A,11111000b
MOV UCC,A
MOV A,00000000b
JMP FIFO_CHECK
FIFO1_RD_CHECK:
MOV A,UCC
OR A,00000111b
AND A,11111001b
MOV UCC,A
MOV A,00000000b
JMP FIFO_CHECK
FIFO2_RD_CHECK:
MOV A,UCC
OR A,00000111b
AND A,11111010b
MOV UCC,A
MOV A,00000000b
JMP FIFO_CHECK
FIFO3_RD_CHECK:
MOV A,UCC
OR A,00000111b
AND A,11111011b
MOV UCC,A
MOV A,00000000b
JMP FIFO_CHECK
FIFO4_RD_CHECK:
MOV A,UCC
OR A,00000111b
AND A,11111100b
MOV UCC,A
MOV A,00000000b
JMP FIFO_CHECK
FIFO5_RD_CHECK:
MOV A,UCC
OR A,00000111b
AND A,11111101b
MOV UCC,A
MOV A,00000000b
JMP FIFO_CHECK
;********************************************************************
; USB LIB
; 1.CHECK FIFOX WR READEY ? bFlag_FIFO_Ready = 1:bFlag_FIFO_Ready = 0
;********************************************************************
;LEN0 ready to write??
LEN0_WR_CHECK:
;CHECK FIFOX ready to write?
FIFO0_WR_CHECK:
MOV A,UCC
OR A,00000111b
AND A,11111000b
MOV UCC,A
MOV A,00000010b
JMP FIFO_CHECK
FIFO1_WR_CHECK:
MOV A,UCC
OR A,00000111b
AND A,11111001b
MOV UCC,A
MOV A,00000010b
JMP FIFO_CHECK
FIFO2_WR_CHECK:
MOV A,UCC
OR A,00000111b
AND A,11111010b
MOV UCC,A
MOV A,00000010b
JMP FIFO_CHECK
FIFO3_WR_CHECK:
MOV A,UCC
OR A,00000111b
AND A,11111011b
MOV UCC,A
MOV A,00000010b
JMP FIFO_CHECK
FIFO4_WR_CHECK:
MOV A,UCC
OR A,00000111b
AND A,11111100b
MOV UCC,A
MOV A,00000010b
JMP FIFO_CHECK
FIFO5_WR_CHECK:
MOV A,UCC
OR A,00000111b
AND A,11111101b
MOV UCC,A
MOV A,00000010b
JMP FIFO_CHECK
FIFO_CHECK:
clr wdt
MOV FIFO_TEMP,A
MOV A,USB_MISC
MOV MP1,A
MOV A,R1
AND A,11111000b
OR A,FIFO_TEMP
MOV R1,A
CALL Delay_3us
SET R1.@MISC_REQ ;set request
CALL Delay_28us
SET bFlag_FIFO_Ready
SNZ R1.@MISC_Ready
CLR bFlag_FIFO_Ready ;if MISC.Ready = 1 -> bFlag_FIFO_Ready = 1
SET bFlag_FIFO_LEN0
SNZ R1.@MISC_LEN0
CLR bFlag_FIFO_LEN0
;;SZ bFlag_FIFO_Ready
clr MISC.@MISC_REQ
clr wdt
RET
;modify 2006-09-22
ReadLen0:
MOV A,USB_FIFO0
MOV MP1,A
MOV A,R1
NOP
JMP Read_FIFO_END
Read_FIFO0:
MOV A,USB_FIFO0_SIZE
MOV FIFO_SIZE,A
MOV A,USB_FIFO0
JMP Read_FIFO
Read_FIFO1:
MOV A,USB_FIFO1_SIZE
MOV FIFO_SIZE,A
MOV A,USB_FIFO1
JMP Read_FIFO
Read_FIFO2:
MOV A,USB_FIFO2_SIZE
MOV FIFO_SIZE,A
MOV A,USB_FIFO2
JMP Read_FIFO
Read_FIFO3:
MOV A,USB_FIFO3_SIZE
MOV FIFO_SIZE,A
MOV A,USB_FIFO3
JMP Read_FIFO
Read_FIFO4:
MOV A,USB_FIFO4_SIZE
MOV FIFO_SIZE,A
MOV A,USB_FIFO4
JMP Read_FIFO
Read_FIFO5:
MOV A,USB_FIFO5_SIZE
MOV FIFO_SIZE,A
MOV A,USB_FIFO5
JMP Read_FIFO
Read_FIFO:
SET MISC.@MISC_REQ
MOV FIFO_TEMP,A ;FIFO_TEMP SAVE FIFOX ADDRESS
CLR FIFO_SendLen
MOV A,OFFSET FIFO_Type
MOV MP0,A
Read_FIFO_Loop:
MOV A,FIFO_TEMP
MOV MP1,A
MOV A,R1
MOV R0,A
INC FIFO_SendLen
INC MP0
MOV A,FIFO_SIZE
XOR A,FIFO_SendLen
SZ Z ;1=FIFO_SIZE=FIFO_SendLen
JMP Read_FIFO_End
MOV A,USB_MISC
MOV MP1,A
CALL Delay_28us
SZ R1.@MISC_Ready
JMP Read_FIFO_LOOP
JMP Read_FIFO_End
Send_Hand_Shake:
Send_Hand_Shake_wait:
; protect die loop
call Check_Real_Cmd
sz bFlag_Real_Cmd
;jmp USB_EP0_ISR_END
ret ;modify by 2006-02-16
CALL FIFO0_WR_CHECK
SNZ bFlag_FIFO_Ready
JMP Send_Hand_Shake_wait
set MISC.@MISC_REQ
WriteLen0:
Write_FIFO_OK:
Read_FIFO_End:
MOV A,USB_MISC
MOV MP1,A
MOV A,(01H SHL @MISC_TX) ;Change TX State
;CLR INTC0.0
XORM A,R1
CALL Delay_3us
CLR R1.@MISC_REQ
;SET INTC0.0
RET
;============================================================
;Function:Write FIFOx from FIFO_OUTx
;============================================================
Write_FIFO0:
MOV A,USB_FIFO0
JMP Write_FIFO
Write_FIFO1:
MOV A,USB_FIFO1
JMP Write_FIFO
Write_FIFO2:
MOV A,USB_FIFO2
JMP Write_FIFO
Write_FIFO3:
MOV A,USB_FIFO3
JMP Write_FIFO
Write_FIFO4:
MOV A,USB_FIFO4
JMP Write_FIFO
Write_FIFO5:
MOV A,USB_FIFO5
JMP Write_FIFO
Write_FIFO:
clr wdt
SET MISC.@MISC_REQ
MOV FIFO_TEMP,A ;FIFO NO Address
MOV A,OFFSET FIFO_OUT1
MOV MP0,A
Write_FIFO_Loop:
clr wdt
MOV A,FIFO_SendLen
XOR A,00H
SZ Z
JMP Write_FIFO_End
MOV A,FIFO_TEMP
MOV MP1,A
MOV A,R0
MOV R1,A
DEC FIFO_SendLen
MOV A,FIFO_SendLen
XOR A,00H
SZ Z
JMP Write_FIFO_End ;FIFO_SendLen=0