📄 host_811.lst
字号:
C51 COMPILER V7.06 HOST_811 07/30/2008 08:56:14 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE HOST_811
OBJECT MODULE PLACED IN host_811.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE host_811.c LARGE BROWSE DEBUG OBJECTEXTEND
stmt level source
1 //////////////////////////////////////////////////////////////////////////////
2 //author:dragon;www.8dragon.com
3 //2004年完成于桃龙源
4 //
5 ///////////////////////////////////////////////////////////////////////////
6 #include "AT89X52.H"
7 #include "host_811.h"
8 #include "fw.h"
9 xdata BYTE SL811H_ADDR _at_ 0x8000; //A0=0
10 xdata BYTE SL811H_DATA _at_ 0x8100; //A0=1
11 //////////////////////////////////////////////////////////////////////////
12 BYTE bBUF[256]; // at 0x2000 for general descriptors data
13 USBDEV idata uDev; // Multiple USB devices attributes, Max 5 devices
14 //////////////////////////////////////////////////////////////////////////
15 Control bdata USB_Control; //全局命令控制变量
16 BYTE bData1; //乒乓操作标志
17 BYTE d1,d2;
18 //*****************************************************************************************
19 // Byte Read from SL811H
20 // a = register address
21 // return = data in register
22 //*****************************************************************************************
23 BYTE SL811Read(BYTE idata a)
24 {
25 1 SL811H_ADDR = a;
26 1 return (SL811H_DATA);
27 1 }
28 //*****************************************************************************************
29 // Byte Write to SL811H
30 // a = register address
31 // d = data to be written to this register address
32 //*****************************************************************************************
33 void SL811Write(BYTE idata a, BYTE idata d)
34 {
35 1 SL811H_ADDR = a;
36 1 SL811H_DATA = d;
37 1 }
38 //*****************************************************************************************
39 // Buffer Read from SL811H
40 // addr = buffer start address
41 // s = return buffer address where data are to be save/read
42 // c = buffer data length
43 //*****************************************************************************************
44 void SL811BufRead(BYTE addr, BYTE *s, BYTE c)
45 {
46 1 BYTE idata i;
47 1 ////////////////////////////////////////////////////////////////////////
48 1 i=c;
49 1 SL811H_ADDR = addr;
50 1 while (i--)
51 1 *s++ = SL811H_DATA;
52 1 }
53
54 //*****************************************************************************************
55 // Buffer Write to SL811H
C51 COMPILER V7.06 HOST_811 07/30/2008 08:56:14 PAGE 2
56 // addr = buffer start address
57 // s = buffer address where data are to be written
58 // c = buffer data length
59 //*****************************************************************************************
60 void SL811BufWrite(BYTE addr, BYTE *s, BYTE c)
61 {
62 1 SL811H_ADDR = addr;
63 1 while (c--)
64 1 SL811H_DATA = *s++;
65 1 }
66 void DelayMs(BYTE nFactor)
67 {
68 1 BYTE i;
69 1 BYTE j;
70 1 ////////////////////////////////////////////////////////////////////////
71 1 for(i=0; i<nFactor; i++)
72 1 {
73 2 for(j=0;j<240;j++)
74 2 j=j;
75 2 }
76 1 }
77 //*****************************************************************************************
78 // Swap high and low byte
79 //*****************************************************************************************
80 WORD WordSwap(WORD input)
81 {
82 1 return(((input&0x00FF)<<8)|((input&0xFF00)>>8));
83 1 }
84 DWORD DWordSwap(DWORD dData)
85 {
86 1 dData = (dData&0xff)<<24|(dData&0xff00)<<8|(dData&0xff000000)>>24|(dData&0xff0000)>>8;
87 1 return dData;
88 1 }
89 //*****************************************************************************************
90 // UsbReset during enumeration of device attached directly to SL811HS
91 //*****************************************************************************************
92 void USBReset()
93 {
94 1 BYTE temp;
95 1 BYTE i;
96 1 ////////////////////////////////////////////////////////////////////////
97 1 /* SL811Write(cSOFcnt,0xae);
98 1 SL811Write(CtrlReg,0x48);
99 1 DelayMs(10);
100 1 SL811Write(CtrlReg,0x00);
101 1 DelayMs(10);*/
102 1 i=SL811Read(IntStatus);
103 1 if(i&0x80)
104 1 {
105 2 SL811Write(cDATASet,0xe0);
106 2 SL811Write(cSOFcnt,0xae);
107 2 SL811Write(CtrlReg,0x05);
108 2 }
109 1 SL811Write(EP0Status,0x50);
110 1 SL811Write(EP0Counter,0x00);
111 1 SL811Write(EP0Control,0x01);
112 1 DelayMs(150);
113 1 temp=SL811Read(CtrlReg);
114 1 SL811Write(CtrlReg,temp|0x08);
115 1 DelayMs(15);
116 1 SL811Write(CtrlReg,temp | 0x18);
117 1 DelayMs(15);//Delay(200);
C51 COMPILER V7.06 HOST_811 07/30/2008 08:56:14 PAGE 3
118 1 SL811Write(CtrlReg,temp | 0x08);
119 1 DelayMs(15);//Delay(200);
120 1 SL811Write(CtrlReg,temp);
121 1 DelayMs(150);
122 1 //DelayMs(400);//Delay(2000);
123 1 }
124
125 //*****************************************************************************************
126 // usbXfer:
127 // successful transfer = return TRUE
128 // fail transfer = return FALSE
129 //*****************************************************************************************
130 BYTE usbXfer(BYTE usbaddr, BYTE endpoint, BYTE pid,WORD wPayload, WORD wLen, BYTE *buffer)
131 {
132 1 BYTE cmd, result, timeout, intr;
133 1 BYTE xferLen, bufLen, data0, data1, dataX, addr,remainder;
134 1 ////////////////////////////////////////////////////////////////////////
135 1 //------------------------------------------------
136 1 // Default setting for usb trasnfer
137 1 //------------------------------------------------
138 1 bufLen = dataX = timeout = 0; //reset all
139 1 data0 = EP0_Buf; // DATA0 buffer address
140 1 data1 = data0 + (BYTE)wPayload; // DATA1 buffer address
141 1 USB_Control.DATA_STOP = USB_Control.TIMEOUT_ERR = FALSE; // set default conditions
142 1 //------------------------------------------------
143 1 // Define data transfer payload
144 1 //------------------------------------------------
145 1 if (wLen >= wPayload) // select proper data payload
146 1 xferLen = wPayload; // limit to wPayload size
147 1 else // else take < payload len
148 1 xferLen = wLen; //
149 1
150 1 //------------------------------------------------
151 1 // For IN token
152 1 //------------------------------------------------
153 1 if (pid==PID_IN) // for current IN tokens
154 1 {
155 2 cmd=sDATA0_RD;
156 2 }
157 1 //------------------------------------------------
158 1 // For OUT token
159 1 //------------------------------------------------
160 1 else if(pid==PID_OUT) // for OUT tokens
161 1 {
162 2 if(xferLen) // only when there are
163 2 SL811BufWrite(data0,buffer,xferLen); // data to transfer on USB
164 2 cmd=sDATA0_WR;
165 2 bData1 = uDev.bData1[endpoint];
166 2 uDev.bData1[endpoint] = (uDev.bData1[endpoint] ? 0 : 1); // DataToggle
167 2 if(bData1)
168 2 cmd |= 0x40; // Set Data1 bit in command
169 2 }
170 1 //------------------------------------------------
171 1 // For SETUP/OUT token
172 1 //------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -