📄 cp220x_eth.lst
字号:
C51 COMPILER V7.09 CP220X_ETH 07/27/2007 15:11:24 PAGE 1
C51 COMPILER V7.09, COMPILATION OF MODULE CP220X_ETH
OBJECT MODULE PLACED IN CP220x_ETH.OBJ
COMPILER INVOKED BY: F:\Keil\C51\BIN\C51.EXE CP220x_ETH.c LARGE BROWSE DEBUG OBJECTEXTEND
line level source
1 //-----------------------------------------------------------------------------
2 // CP220x_ETH.c
3 //-----------------------------------------------------------------------------
4 // Copyright 2006 Silicon Laboratories, Inc.
5 // http://www.silabs.com
6 //
7 // Program Description:
8 //
9 // This file contains basic send and receive functions for the CP220x.
10 //
11 // FID:
12 // Target: Multiple
13 // Tool chain: Keil C51 7.20 / Keil EVAL C51
14 // Silicon Laboratories IDE version 2.72
15 // Command Line: See Readme.txt
16 // Project Name: CP220x_Ethernet_Routines
17 //
18 //
19 //
20 // Release 1.1
21 // - Configures C8051F120 SYSCLK to 98 MHz
22 //
23 // Release 1.0
24 // -Initial Release (FB)
25 // -30 MAY 2006
26 //
27
28 //-----------------------------------------------------------------------------
29 // Includes
30 //-----------------------------------------------------------------------------
31 #include "global.h"
32
33 //-----------------------------------------------------------------------------
34 // Function Prototypes
35 //-----------------------------------------------------------------------------
36 void CP220x_Send( MACADDRESS* pDestAddr, unsigned char* buffer,
37 unsigned int buffer_length, unsigned int packet_type);
38
39 void CP220x_SendD( unsigned char* buffer, unsigned int buffer_length);
40
41 unsigned int CP220x_Receive(unsigned char* buffer, unsigned int buffer_length);
42
43 void CP220x_SendD( unsigned char* buffer, unsigned int buffer_length)
44 {
45 1 int i;
46 1 unsigned int ramaddr;
47 1
48 1 // Define Macro to increment the RAM address Pointer
49 1 #define INC_RAMADDR ramaddr++; \
50 1 RAMADDRH = (ramaddr >> 8);\
51 1 RAMADDRL = (ramaddr & 0x00FF);
52 1
53 1
54 1 // Step 1: Poll TXBUSY until it becomes 0x00
55 1 while(TXBUSY);
C51 COMPILER V7.09 CP220X_ETH 07/27/2007 15:11:24 PAGE 2
56 1
57 1 // Step 2: Set the TXSTARTH:TXSTARTL address to 0x0000
58 1 TXSTARTH = 0x00;
59 1 TXSTARTL = 0x00;
60 1
61 1
62 1 // Step 3: Load data into transmit buffer
63 1 // When the random access method is used, we do not need to check for
64 1 // aborted packets. This method will be slightly slower than the Autowrite
65 1 // method, however, it reduces code space requirements.
66 1
67 1 // Setup RAM Address Pointer To 0x0000
68 1 RAMADDRH = 0x00;
69 1 RAMADDRL = 0x00;
70 1 ramaddr = 0x0000;
71 1
72 1 // Step 3a: Load the destination address
73 1 for(i = 0; i < buffer_length; i++)
74 1 {
75 2 RAMTXDATA = buffer[i];
76 2 INC_RAMADDR
77 2 }
78 1 // Step 3e: Pad short packets
79 1 while(ramaddr < 64){
80 2 RAMTXDATA = 0;
81 2 INC_RAMADDR
82 2 }
83 1
84 1 // Set the TXENDH:TXENDL address to <ramaddr - 1>
85 1 ramaddr--;
86 1 TXENDH = (ramaddr >> 8);
87 1 TXENDL = (ramaddr & 0x00FF);
88 1
89 1
90 1 // Step 4: Set the TXSTARTH:TXSTARTL address back to 0x0000
91 1 TXSTARTH = 0x00;
92 1 TXSTARTL = 0x00;
93 1
94 1 // Step 5: Write '1' to TXGO to begin transmission
95 1 TXCN = 0x01;
96 1 }
97
98 //-----------------------------------------------------------------------------
99 // CP220x_Send
100 //-----------------------------------------------------------------------------
101 //
102 // Return Value : None
103 // Parameters :
104 // 1) MACADDRESS* pDestAddr - destination MAC address.
105 // 2) unsigned char* buffer - address of payload.
106 // 3) unsigned int buffer_length - length of payload.
107 // 4) unsigned int packet_type - contents of Ethertype field.
108 //
109 // This function sends an IEEE 802.3 Ethernet packet using the CP220x.
110 // Upon entry, there should be valid data in array <buffer>.
111 //
112 // (8 bytes) 48-bit 48-bit 16-bit 0-1500 bytes
113 // ----------------------------------------------------------------------
114 // | Preamble| SFD | Dest |Source| Type/Length |Data Field | Pad | FCS |
115 // | | | Addr | Addr | Field | | | (CRC) |
116 // ----------------------------------------------------------------------
117 // supplied by | supplied by the MCU | supplied
C51 COMPILER V7.09 CP220X_ETH 07/27/2007 15:11:24 PAGE 3
118 // CP220x | (minimum 64 bytes) | by CP220x
119 //
120 //
121 //-----------------------------------------------------------------------------
122 void CP220x_Send( MACADDRESS* pDestAddr, unsigned char* buffer,
123 unsigned int buffer_length, unsigned int packet_type)
124 {
125 1
126 1 int i;
127 1 unsigned int ramaddr;
128 1
129 1 // Define Macro to increment the RAM address Pointer
130 1 #define INC_RAMADDR ramaddr++; \
131 1 RAMADDRH = (ramaddr >> 8);\
132 1 RAMADDRL = (ramaddr & 0x00FF);
133 1
134 1
135 1 // Step 1: Poll TXBUSY until it becomes 0x00
136 1 while(TXBUSY);
137 1
138 1 // Step 2: Set the TXSTARTH:TXSTARTL address to 0x0000
139 1 TXSTARTH = 0x00;
140 1 TXSTARTL = 0x00;
141 1
142 1
143 1 // Step 3: Load data into transmit buffer
144 1 // When the random access method is used, we do not need to check for
145 1 // aborted packets. This method will be slightly slower than the Autowrite
146 1 // method, however, it reduces code space requirements.
147 1
148 1 // Setup RAM Address Pointer To 0x0000
149 1 RAMADDRH = 0x00;
150 1 RAMADDRL = 0x00;
151 1 ramaddr = 0x0000;
152 1
153 1 // Step 3a: Load the destination address
154 1 for(i = 0; i < 6; i++){
155 2
156 2 RAMTXDATA = pDestAddr->Char[i];
157 2 INC_RAMADDR
158 2
159 2 }
160 1
161 1 // Step 3b: Load the source address
162 1 for(i = 0; i < 6; i++){
163 2 RAMTXDATA = MYMAC.Char[i];
164 2 INC_RAMADDR
165 2 }
166 1
167 1 // Step 3c: Load the Type/Length Field
168 1 RAMTXDATA = (packet_type >> 8);
169 1 INC_RAMADDR
170 1
171 1 RAMTXDATA = (packet_type & 0xFF);
172 1 INC_RAMADDR
173 1
174 1
175 1 // Step 3d: Load the packet payload
176 1 for(i = 0; i < buffer_length; i++){
177 2 RAMTXDATA = buffer[i];
178 2 INC_RAMADDR
179 2 }
C51 COMPILER V7.09 CP220X_ETH 07/27/2007 15:11:24 PAGE 4
180 1
181 1 // Step 3e: Pad short packets
182 1 while(ramaddr < 64){
183 2 RAMTXDATA = 0;
184 2 INC_RAMADDR
185 2 }
186 1
187 1 // Set the TXENDH:TXENDL address to <ramaddr - 1>
188 1 ramaddr--;
189 1 TXENDH = (ramaddr >> 8);
190 1 TXENDL = (ramaddr & 0x00FF);
191 1
192 1
193 1 // Step 4: Set the TXSTARTH:TXSTARTL address back to 0x0000
194 1 TXSTARTH = 0x00;
195 1 TXSTARTL = 0x00;
196 1
197 1 // Step 5: Write '1' to TXGO to begin transmission
198 1 TXCN = 0x01;
199 1
200 1 }
201
202
203 //-----------------------------------------------------------------------------
204 // CP220x_Receive
205 //-----------------------------------------------------------------------------
206 //
207 // This function reads the current packet from the CP220x receive buffer and
208 // copies it to the passed buffer. The data copied to the buffer includes the
209 // 14-byte Ethernet Header and the Data Field.
210 //
211 // Returns the number of bytes added to the buffer.
212 //
213 // (8 bytes) 48-bit 48-bit 16-bit 0-1500 bytes
214 // --------------------------------------------------------------------------
215 // | Preamble | SFD | Dest | Source | Type/Length | Data Field | Pad | FCS |
216 // | | | Addr | Addr | Field | | | (CRC) |
217 // --------------------------------------------------------------------------
218 // supplied by | supplied by the MCU | supplied by
219 // CP220x | | CP220x
220 //-----------------------------------------------------------------------------
221 unsigned int CP220x_Receive(unsigned char* buffer, unsigned int buffer_length)
222 {
223 1 bit rx_ok;
224 1 bit skip = 0;
225 1 UINT cplen;
226 1 unsigned int i;
227 1
228 1 // Step 1: Check the RXOK bit to see if packet was received correctly
229 1 rx_ok = (CPINFOL & RXOK) && (CPINFOH & RXVALID);//检查是否接收正确
230 1
231 1 // Step 2: If packet received correctly, read the length, otherwise, skip packet.
232 1 if(rx_ok){
233 2
234 2 // Read the packet length读出包的长度
235 2 cplen.Char[0] = CPLENH;
236 2 cplen.Char[1] = CPLENL;
237 2
238 2 } else {
239 2
240 2 // Set packet length to zero
241 2 cplen.Int = 0;
C51 COMPILER V7.09 CP220X_ETH 07/27/2007 15:11:24 PAGE 5
242 2
243 2 // Skip packet
244 2 skip = 1;
245 2 }
246 1
247 1 // Step 3: Read the entire packet from the buffer
248 1
249 1 // If packet will fit in the buffer读出事个包的数据
250 1 if(buffer_length >= cplen.Int){
251 2
252 2 // Copy entire packet
253 2 for(i = 0; i < cplen.Int; i++){
254 3 *buffer++ = RXAUTORD;
255 3 }
256 2
257 2 } else {
258 2
259 2 // Set packet length to zero
260 2 cplen.Int = 0;
261 2
262 2 // Skip packet
263 2 skip = 1;
264 2 }
265 1
266 1 // Step 4: Skip the packet, or clear the valid bit if the entire packet
267 1 // has been unloaded from the buffer.
268 1
269 1 if(skip)
270 1 {
271 2 RXCN |= 0x02; // Skip the packet
272 2 }
273 1
274 1 else
275 1 {
276 2 RXCN |= 0x04; // Clear the valid bit only清空标志,表示已经接收了包
277 2 }
278 1
279 1 // If there are no more packets in the receive buffer, enable reception
280 1 if(TLBVALID == 0x00)//如果还有其它的包,经纬接收
281 1 {
282 2 RXCN = 0x00;
283 2 }
284 1
285 1 // Return the number of bytes added to the buffer
286 1 return cplen.Int;
287 1 }
288
289
290 //-----------------------------------------------------------------------------
291 // End Of File
292 //-----------------------------------------------------------------------------
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 712 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- 24
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- 2
END OF MODULE INFORMATION.
C51 COMPILER V7.09 CP220X_ETH 07/27/2007 15:11:24 PAGE 6
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -