⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 upsd_usb.src

📁 DK3200 USB DEMO for KEIL C
💻 SRC
📖 第 1 页 / 共 4 页
字号:

	RSEG  ?PR?STALL_EP0?UPSD_USB
STALL_EP0:
			; SOURCE LINE # 192
; /******************************************************************************
;  Function   : void STALL_EP0()
;  Parameters : none
;  Description: Stalls EP0.
;      This endpoint is halted or a control pipe request is not supported.
;      Endpoint can be unstalled by the next SETUP packet.
;      STALL is returned by a function in response to an IN token
;      or after the data phase of an OUT transaction.
;      It indicates that a function is unable to transmit or receive data,
;      or that a control pipe request is not supported.
;  ******************************************************************************/
;  {
			; SOURCE LINE # 204
;   #pragma asm
;               anl    UCON0,#uTSEQ0+uRX0E+uSTALL0+uTX0E                   ;mask
	  anl    UCON0,#0x80+0x10+0x40+0x20                   ;mask
;               orl    UCON0,#uSTALL0                 ;clear TSEQ bit, STALL EP0
	  orl    UCON0,#0x40                 ;clear TSEQ bit, STALL EP0
;   #pragma endasm
;  }
			; SOURCE LINE # 209
	RET  	
; END OF STALL_EP0

; 
; 
; 
; 
; 
; 
; static BOOL TransmitBufferEP0()

	RSEG  ?PR?TransmitBufferEP0?UPSD_USB
TransmitBufferEP0:
	USING	0
			; SOURCE LINE # 216
; /******************************************************************************
;  Function   : static BOOL TransmitBufferEP0()
;  Parameters : none
;  Description: Transmits next segment of descriptor buffer (pTransmitBufferEP0).
;      This routine prepates 0..8 bytes  of data from TransmitBufferEP0
;      at endpoint0. If no data is available in buffer, the endpoint is disabled.
;      According to USB standard, zero length packet is trasmitted at then end.
;  ******************************************************************************/
;  {
			; SOURCE LINE # 225
;   data int i;
;   data int nBytes;
; 
;   if (pTransmitBufferEP0)                    // If there is data going out...
			; SOURCE LINE # 229
	MOV  	DPTR,#pTransmitBufferEP0
	MOVX 	A,@DPTR
	MOV  	R3,A
	INC  	DPTR
	MOVX 	A,@DPTR
	MOV  	R2,A
	INC  	DPTR
	MOVX 	A,@DPTR
	MOV  	R1,A
	MOV  	A,R2
	ORL  	A,R1
	ORL  	A,R3
	JNZ  	$ + 5H
	LJMP 	?C0004
;    {
			; SOURCE LINE # 230
;     #pragma asm                              // send zero length packet
;               xrl    UCON0,#uTSEQ0                            ;toggle TSEQ bit
	  xrl    UCON0,#0x80                            ;toggle TSEQ bit
;               anl    UCON0,#uTSEQ0+uRX0E              ;mask
	  anl    UCON0,#0x80+0x10              ;mask
;     #pragma endasm
;     if (!bytesToTransmitEP0)                 // If data has already been sent...
			; SOURCE LINE # 235
	MOV  	DPTR,#bytesToTransmitEP0
	MOVX 	A,@DPTR
	MOV  	R6,A
	INC  	DPTR
	MOVX 	A,@DPTR
	MOV  	R7,A
	ORL  	A,R6
	JNZ  	?C0005
;      {
			; SOURCE LINE # 236
;       #pragma asm                            // send zero length packet
;               orl    UCON0,#uTX0E                             ;enable transmit
	  orl    UCON0,#0x20                             ;enable transmit
;       #pragma endasm
;       pTransmitBufferEP0 = NULL;             // If data has already been sent...
			; SOURCE LINE # 240
	MOV  	DPTR,#pTransmitBufferEP0
	CLR  	A
	MOVX 	@DPTR,A
	INC  	DPTR
	MOVX 	@DPTR,A
	INC  	DPTR
	MOVX 	@DPTR,A
;      }
			; SOURCE LINE # 241
	LJMP 	?C0006
?C0005:
;     else
;      {
			; SOURCE LINE # 243
;       nBytes = bytesToTransmitEP0;           // Transmit next chunk of data
			; SOURCE LINE # 244
	MOV  	nBytes?341,R6
	MOV  	nBytes?341+01H,R7
;       if (nBytes > 8)
			; SOURCE LINE # 245
	SETB 	C
	MOV  	A,nBytes?341+01H
	SUBB 	A,#08H
	MOV  	A,nBytes?341
	XRL  	A,#080H
	SUBB 	A,#080H
	JC   	?C0007
;        {
			; SOURCE LINE # 246
;         nBytes = 8;
			; SOURCE LINE # 247
	MOV  	nBytes?341,#00H
	MOV  	nBytes?341+01H,#08H
;        }
			; SOURCE LINE # 248
?C0007:
;       UCON0 |= nBytes;                       // set FIFO size
			; SOURCE LINE # 249
	MOV  	A,nBytes?341+01H
	ORL  	UCON0,A
; 
;       for (i = 0; i < nBytes; i++)           // Load data into FIFO
			; SOURCE LINE # 251
	CLR  	A
	MOV  	i?340,A
	MOV  	i?340+01H,A
?C0008:
	CLR  	C
	MOV  	A,i?340+01H
	SUBB 	A,nBytes?341+01H
	MOV  	A,nBytes?341
	XRL  	A,#080H
	MOV  	R0,A
	MOV  	A,i?340
	XRL  	A,#080H
	SUBB 	A,R0
	JNC  	?C0009
;        {
			; SOURCE LINE # 252
;         UDT0 = *pTransmitBufferEP0++;
			; SOURCE LINE # 253
	MOV  	DPTR,#pTransmitBufferEP0
	MOVX 	A,@DPTR
	MOV  	R3,A
	INC  	DPTR
	CLR  	A
	MOV  	B,#01H
	LCALL	?C?ILDIX
	MOV  	R1,B
	MOV  	R2,A
	LCALL	?C?CLDPTR
	MOV  	UDT0,A
;        }
			; SOURCE LINE # 254
	INC  	i?340+01H
	MOV  	A,i?340+01H
	JNZ  	?C0008
	INC  	i?340
?C0107:
	SJMP 	?C0008
?C0009:
; 
;       if ((bytesToTransmitEP0 -= nBytes) == 0)
			; SOURCE LINE # 256
	CLR  	C
	MOV  	DPTR,#bytesToTransmitEP0+01H
	MOVX 	A,@DPTR
	SUBB 	A,nBytes?341+01H
	MOV  	R7,A
	MOV  	DPTR,#bytesToTransmitEP0
	MOVX 	A,@DPTR
	SUBB 	A,nBytes?341
	MOV  	R6,A
	MOVX 	@DPTR,A
	INC  	DPTR
	MOV  	A,R7
	MOVX 	@DPTR,A
	ORL  	A,R6
	JNZ  	?C0011
;        {
			; SOURCE LINE # 257
;                   // For short transfers, we need to send a zero length terminator
;         if (!shortTransfer || (nBytes < 8))
			; SOURCE LINE # 259
	MOV  	DPTR,#shortTransfer
	MOVX 	A,@DPTR
	JZ   	?C0013
	CLR  	C
	MOV  	A,nBytes?341+01H
	SUBB 	A,#08H
	MOV  	A,nBytes?341
	XRL  	A,#080H
	SUBB 	A,#080H
	JNC  	?C0011
?C0013:
;          {
			; SOURCE LINE # 260
;           pTransmitBufferEP0 = NULL;         // it will be sent the next cycle
			; SOURCE LINE # 261
	MOV  	DPTR,#pTransmitBufferEP0
	CLR  	A
	MOVX 	@DPTR,A
	INC  	DPTR
	MOVX 	@DPTR,A
	INC  	DPTR
	MOVX 	@DPTR,A
;          }
			; SOURCE LINE # 262
;        }
			; SOURCE LINE # 263
?C0011:
;       #pragma asm
;               orl    UCON0,#uTX0E                            ; enable transmit
	  orl    UCON0,#0x20                            ; enable transmit
;       #pragma endasm
;      }
			; SOURCE LINE # 267
?C0006:
;     return TRUE;
			; SOURCE LINE # 268
	MOV  	R7,#01H
	RET  	
;    }
			; SOURCE LINE # 269
?C0004:
; 
;   #pragma asm                            // No data going out, so disable endpoint
;               anl    UCON0,#uRX0E                                        ;mask
	  anl    UCON0,#0x10                                        ;mask
;               orl    UCON0,#uTSEQ0                               ;set TSEQ bit
	  orl    UCON0,#0x80                               ;set TSEQ bit
;   #pragma endasm
; 
;   return FALSE;
			; SOURCE LINE # 276
	MOV  	R7,#00H
;  }
			; SOURCE LINE # 277
?C0014:
	RET  	
; END OF TransmitBufferEP0

; 
; 
; 
; 
; 
; 
; 
; 
; void TransmitDataEP0(uchar* pData, int nBytes)

	RSEG  ?PR?_TransmitDataEP0?UPSD_USB
_TransmitDataEP0:
	USING	0
			; SOURCE LINE # 286
	MOV  	DPTR,#pData?442
	MOV  	A,R3
	MOVX 	@DPTR,A
	INC  	DPTR
	MOV  	A,R2
	MOVX 	@DPTR,A
	INC  	DPTR
	MOV  	A,R1
	MOVX 	@DPTR,A
;---- Variable 'nBytes?443' assigned to Register 'R4/R5' ----
; /******************************************************************************
;  Function   : void TransmitDataEP0()
;  Parameters : (uchar* pData, int nBytes)
;  Description: Load and arm EP0 to transmit data.
;      This routine prepates 0..8 bytes of data at endpoint0 to be trasmitted.
;      Caller must then clear FIFO status flag (uTXD0F) to arm the endpoint.
;  ******************************************************************************/
;  {
			; SOURCE LINE # 294
;   data unsigned char xBytes;
; 
;   if (nBytes > EP0_SIZE) xBytes = EP0_SIZE; else xBytes = nBytes;
			; SOURCE LINE # 297
	SETB 	C
	MOV  	A,R5
	SUBB 	A,#08H
	MOV  	A,R4
	XRL  	A,#080H
	SUBB 	A,#080H
	JC   	?C0015
	MOV  	xBytes?444,#08H
	SJMP 	?C0016
?C0015:
	MOV  	xBytes?444,R5
?C0016:
; 
;                        // Disable endpoint, set DATA0/1 sequence bit and FIFO size
;   #pragma asm
;               xrl    UCON0,#uTSEQ0                            ;toggle TSEQ bit
	  xrl    UCON0,#0x80                            ;toggle TSEQ bit
;               anl    UCON0,#(uTSEQ0+uRX0E)
	  anl    UCON0,#(0x80+0x10)
;   #pragma endasm
;   UCON0 |=xBytes;                            // set FIFO size
			; SOURCE LINE # 304
	MOV  	A,xBytes?444
	ORL  	UCON0,A
?C0017:
; 
;   while (xBytes--)
			; SOURCE LINE # 306
	MOV  	R7,xBytes?444
	DEC  	xBytes?444
	MOV  	A,R7
	JZ   	?C0018
;    {
			; SOURCE LINE # 307
;     UDT0 = *pData++;                         // Load data into FIFO
			; SOURCE LINE # 308
	MOV  	DPTR,#pData?442
	MOVX 	A,@DPTR
	MOV  	R3,A
	INC  	DPTR
	CLR  	A
	MOV  	B,#01H
	LCALL	?C?ILDIX
	MOV  	R1,B
	MOV  	R2,A
	LCALL	?C?CLDPTR
	MOV  	UDT0,A
;    }
			; SOURCE LINE # 309
	SJMP 	?C0017
?C0018:
;   UCON0 |= uTX0E;                            // Enable endpoint
			; SOURCE LINE # 310
	ORL  	UCON0,#020H
;  }
			; SOURCE LINE # 311
	RET  	
; END OF _TransmitDataEP0

; 
; 
; 
; 
; 
; 
; 
; void TransmitDataEPx(int x, uchar* pData, int nBytes)

	RSEG  ?PR?_TransmitDataEPx?UPSD_USB
_TransmitDataEPx:
	USING	0
			; SOURCE LINE # 319
	MOV  	DPTR,#pData?546
	MOV  	A,R3
	MOVX 	@DPTR,A
	INC  	DPTR
	MOV  	A,R2
	MOVX 	@DPTR,A
	INC  	DPTR
	MOV  	A,R1
	MOVX 	@DPTR,A
;---- Variable 'x?545' assigned to Register 'R6/R7' ----
; /******************************************************************************
;  Function   : void TransmitDataEPx()
;  Parameters : (int x, uchar* pData, int nBytes)
;  Description: Loads EP1 or EP2 transmit FIFO.
;               Caller must then clear FIFO status flag (uTXD1F) to arm endpoint.
;  ******************************************************************************/
;  {
			; SOURCE LINE # 326
; 
;   data unsigned char xBytes;
; 
;   if (nBytes > 8)  xBytes = 8; else xBytes = nBytes;
			; SOURCE LINE # 330
	SETB 	C
	MOV  	DPTR,#nBytes?547+01H
	MOVX 	A,@DPTR
	SUBB 	A,#08H
	MOV  	DPTR,#nBytes?547
	MOVX 	A,@DPTR
	XRL  	A,#080H
	SUBB 	A,#080H
	JC   	?C0020
	MOV  	xBytes?548,#08H
	SJMP 	?C0021
?C0020:
	MOV  	DPTR,#nBytes?547+01H
	MOVX 	A,@DPTR
	MOV  	xBytes?548,A
?C0021:
;   // Disable endpoint, set DATA0/1 sequence bit, endpoint selection, and FIFO size
;   UCON1 &= ~uEP12SEL;                        //mask
			; SOURCE LINE # 332
	ANL  	UCON1,#0BFH
;   UCON1 |= ((x == 2) ? uEP12SEL : 0);        //set endpoint
			; SOURCE LINE # 333
	MOV  	A,R7
	XRL  	A,#02H
	ORL  	A,R6
	JNZ  	?C0022
	MOV  	R7,#040H
	SJMP 	?C0023
?C0022:
	MOV  	R7,#00H
?C0023:
	MOV  	A,R7
	ORL  	UCON1,A
;   UCON1 &= uTSEQ1+uEP12SEL;                  //mask
			; SOURCE LINE # 334
	ANL  	UCON1,#0C0H
;   UCON1 ^= uTSEQ1;                           //toggle DATAx bit
			; SOURCE LINE # 335
	XRL  	UCON1,#080H
;   UCON1 |= xBytes;                           //set FIFO size
			; SOURCE LINE # 336
	MOV  	A,xBytes?548
	ORL  	UCON1,A
?C0024:
;   while (nBytes--)
			; SOURCE LINE # 337
	MOV  	DPTR,#nBytes?547
	MOV  	A,#0FFH
	MOV  	B,A
	LCALL	?C?ILDIX
	ORL  	A,B
	JZ   	?C0025
;    {
			; SOURCE LINE # 338
;     UDT1 = *pData++;                         // Load data into FIFO
			; SOURCE LINE # 339
	MOV  	DPTR,#pData?546
	MOVX 	A,@DPTR
	MOV  	R3,A
	INC  	DPTR
	CLR  	A
	MOV  	B,#01H
	LCALL	?C?ILDIX
	MOV  	R1,B
	MOV  	R2,A
	LCALL	?C?CLDPTR
	MOV  	UDT1,A
;    }
			; SOURCE LINE # 340
	SJMP 	?C0024
?C0025:
;   UCON1 |= uTX1E;                            // Enable endpoint
			; SOURCE LINE # 341
	ORL  	UCON1,#020H
;   UIEN  |= uTXD1IE;                          // enable INT
			; SOURCE LINE # 342
	ORL  	UIEN,#04H
;  }
			; SOURCE LINE # 343
	RET  	
; END OF _TransmitDataEPx

; 
; 
; 
; 
; 
; 
; 
; 
; 
; 
; 
; 
; 
; 
; 
; 
; 
; 
; 
; 
; //the following function changed on April 30, 2004
; 
; static void OnGetStatus()

	RSEG  ?PR?OnGetStatus?UPSD_USB
OnGetStatus:
	USING	0
			; SOURCE LINE # 366
; /******************************************************************************
;  Function   : static void OnGetStatus()
;  Parameters : none
;  Description: Handler for GET_STATUS control requests.
;  ******************************************************************************/
;  {
			; SOURCE LINE # 372
;   #pragma asm                                // send zero length packet
;               orl    UCON0,#uTSEQ0                               ;set TSEQ bit
	  orl    UCON0,#0x80                               ;set TSEQ bit
;               anl    UCON0,#uTSEQ0+uRX0E                   ;mask, keep RX flag
	  anl    UCON0,#0x80+0x10                   ;mask, keep RX flag
;               orl    UCON0,#2                                   ;set FIFO size
	  orl    UCON0,#2                                   ;set FIFO size
;   #pragma endasm
;   
;   if((setupPacket.wIndex.lo == 0x00) & (setupPacket.wIndex.hi == 0x00)){//device
			; SOURCE LINE # 379
	MOV  	DPTR,#setupPacket+05H
	MOVX 	A,@DPTR
	MOV  	R7,A
	JNZ  	?C0028
	MOV  	R6,#01H
	SJMP 	?C0029
?C0028:
	MOV  	R6,#00H
?C0029:
	MOV  	DPTR,#setupPacket+04H
	MOVX 	A,@DPTR
	MOV  	R5,A
	JNZ  	?C0030
	MOV  	R4,#01H
	SJMP 	?C0031
?C0030:
	MOV  	R4,#00H
?C0031:
	MOV  	A,R4
	ANL  	A,R6
	JZ   	?C0027
; 	UDT0 = 1;
			; SOURCE LINE # 380
	MOV  	UDT0,#01H
; 	UDT0 = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -