📄 d12.lst
字号:
C51 COMPILER V7.01 D12 02/17/2006 15:09:23 PAGE 1
C51 COMPILER V7.01, COMPILATION OF MODULE D12
OBJECT MODULE PLACED IN D12.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE D12.C BROWSE MODP2 DEBUG OBJECTEXTEND
stmt level source
1
2 #include "InsUsb.h"
3
4 //
5 //*************************************************************************
6 // Parameter:
7 // In : bAddress : The USB address that PDIUSBD12 will be set
8 // bEnable : If 1, new USB address will be enabled,vice visa
9 // Out: None
10 // Function:
11 // PDIUSBD12 Register: 0xD0H
12 // Set USB address of PDIUSBD12,and if bEanble is 1,the address will
13 // be valid immediately.
14 void D12SetAddressEnable(unsigned char bAddress, BOOL bEnable)
15 {
16 1 D12_COMMAND_ADDRESS = 0xD0;
17 1
18 1 if(bEnable)
19 1 bAddress |= 0x80;
20 1 else
21 1 bAddress &= 0x7F;
22 1
23 1 D12_DATA_ADDRESS = bAddress;
24 1 }
25
26 //
27 //*************************************************************************
28 // Parameter:
29 // In : bEndpointEnable: Only the last bit is meaningful,if it is 1,
30 // the select endpont will be enabled
31 // Out: None
32 // Function:
33 // PDIUSBD12 Register: 0xD8H
34 // The function is to set generic/isochronous endpoint enabled or disabled
35 // 0 disable endpoint1 and endpoint2,1 enable
36 void D12SetEndpointEnable(unsigned char bEndpointEnable)
37 {
38 1 D12_COMMAND_ADDRESS = 0xD8;
39 1 D12_DATA_ADDRESS = bEndpointEnable;
40 1 }
41
42 //
43 //*************************************************************************
44 // Parameter:
45 // In : bConfiguration : The first byte
46 // bClockkDivision: The second byte
47 // Out: None
48 // Function:
49 // PDIUSBD12 Register: 0xF3H
50 // The function set PDIUSBD12 work mode
51 void D12SetMode(unsigned char bConfiguration, unsigned char bClockkDivision)
52 {
53 1 D12_COMMAND_ADDRESS = 0xF3;
54 1 D12_DATA_ADDRESS = bConfiguration;
55 1 D12_DATA_ADDRESS = bClockkDivision;
C51 COMPILER V7.01 D12 02/17/2006 15:09:23 PAGE 2
56 1 }
57
58 //
59 //*************************************************************************
60 // Parameter:
61 // In :
62 // Out:
63 // Function:
64
65 void D12SetDMA(unsigned char bValue)
66 {
67 1 D12_COMMAND_ADDRESS = 0xFB;
68 1 D12_DATA_ADDRESS = bValue;
69 1 }
70
71
72 //
73 //*************************************************************************
74 // Parameter:
75 // In : None
76 // Out: One byte
77 // Function:
78 // PDIUSBD12 Register: 0xF4H
79 // Read interrupt register of PDIUSBD12,and will read two bytes,but the
80 // second byte is only one bit is meaningful and relative only to DMA,
81 // since PDIUSBD12 Develop Board doesn't implementate DMA,so the second
82 // byte has no use and will not return in this function.
83 unsigned char D12ReadInterruptRegister(void)
84 {
85 1 unsigned char bUsbIntByte1;
86 1 unsigned char bUsbIntByte2;
87 1
88 1 D12_COMMAND_ADDRESS = 0xF4;
89 1 bUsbIntByte1 = D12_DATA_ADDRESS ; //read the first byte
90 1 bUsbIntByte2 = D12_DATA_ADDRESS ; //read the second byte
91 1 return (bUsbIntByte1);
92 1 }
93
94 //
95 //*************************************************************************
96 // Parameter:
97 // In :bEndpointIndex:
98 // Out:One byte
99 // Function:
100 // PDIUSBD12 Register: 0x00H-0x05H
101 // Select Endpoint command will initialezes an internal pointer to the
102 // start of the selected buffer.The last two bits of returned byte mans
103 // whether the buffer is full/empty and whether the selected endpoint is
104 // in stall status
105 unsigned char D12SelectEndpoint(unsigned char bEndpointIndex)
106 {
107 1 unsigned char data bEndpointStatus;
108 1 D12_COMMAND_ADDRESS = bEndpointIndex;
109 1 bEndpointStatus = D12_DATA_ADDRESS ;
110 1
111 1 return bEndpointStatus;
112 1
113 1 }
114
115
116 //
117 //*************************************************************************
C51 COMPILER V7.01 D12 02/17/2006 15:09:23 PAGE 3
118 // Parameter:
119 // In : bEndpointAddress : select this endpoint to read last transaction status
120 // Out: One byte,Last transaction status
121 // Function:
122 // PDIUSBD12 Register: 0x40H-0x45H
123 // Select Endpoint and read last transaction status
124
125 unsigned char D12ReadLastTransactionStatus(unsigned char bEndpointIndex)
126 {
127 1 unsigned char data bLastTransactionStatus;
128 1 D12_COMMAND_ADDRESS = bEndpointIndex;
129 1 bLastTransactionStatus = D12_DATA_ADDRESS ;
130 1 return bLastTransactionStatus;
131 1 }
132
133 //
134 //*************************************************************************
135 // Parameter:
136 // In : bEndpointIndex : the endpont index of PDIUSBD12
137 // bExpectedLength: length want to read
138 // pBuffer : pointer,the start address of buffer which received
139 // data will be write to
140 // Out: One byte : the byte count of receive buffer ,
141 // if bExpectedLength is less than length that the buffer
142 // actually received,return 0xFF as an error flag.
143 // Function:
144 // PDIUSBD12 Register: 0xF0H
145 // Read buffer of PDIUSBD12.
146 unsigned char D12ReadBuffer(unsigned char bEndpointIndex, unsigned int bExpectedLength,unsigned char * pBu
-ffer)
147 {
148 1 unsigned char data i, bByteCount=0;
149 1 unsigned char data bEndpointBufferFullEmpty;
150 1
151 1 D12_COMMAND_ADDRESS = bEndpointIndex; //select endpoint,the optional read one byte is not read
152 1
153 1 bEndpointBufferFullEmpty = D12_DATA_ADDRESS; //probe: whether this buffer has valid data packet
154 1
155 1 if (bEndpointBufferFullEmpty & D12_BUFFER_FULL_EMPTY_MASK)
156 1 {
157 2 //if buffer is full
158 2 D12_COMMAND_ADDRESS = D12_READ_BUFFER_SELECTED_ENDPOINT;
159 2 bByteCount = D12_DATA_ADDRESS ; //the first byte has no meaning
160 2 bByteCount = D12_DATA_ADDRESS ; //the data byte count
161 2
162 2
163 2
164 2
165 2 if ((unsigned int)(bByteCount) <= bExpectedLength)
166 2 {
167 3 #ifndef _INT_MODE_
#ifdef _Debug_
printf("Receive buffer:");
#endif
#endif
172 3 for(i=0; i<bByteCount; i++)
173 3 {
174 4 *pBuffer = D12_DATA_ADDRESS ;
175 4 #ifndef _INT_MODE_
#ifdef _Debug_
printf("%x,",(unsigned int)(*pBuffer));
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -