?? eth.lst
字號:
176 1 reg07=0xff;
177 1 reg00=0x3e; //to sendpacket;
178 1 free(outbuf);
179 1 }
C51 COMPILER V7.06 ETH 07/29/2006 13:15:57 PAGE 4
180
181 //------------------------------------------------------------------------
182 // This functions checks the 8019 receive event status
183 // word to see if an ethernet frame has arrived. If so,
184 // set EVENT_ETH_ARRIVED bit in global event_word
185 //------------------------------------------------------------------------
186 void query_8019(void)
187 {
188 1 char bnry,curr;
189 1 page(0);
190 1 bnry=reg03; //bnry page have read 讀頁指針
191 1 page(1);
192 1 curr=reg07; //curr writepoint 8019寫頁指針
193 1 page(0);
194 1 if ((curr==0)) return;
195 1 bnry=bnry++;
196 1 if (bnry>0x7f) bnry=0x4c;
197 1 if (bnry!=curr) //此時(shí)表示有新的數(shù)據(jù)包在緩沖區(qū)里
198 1 {
199 2 EA = 0;
200 2 event_word |= EVENT_ETH_ARRIVED;
201 2 EA = 1;
202 2 }
203 1 reg0b=0x00; reg0a=0x00; reg00=0x22;//complete dma page 0
204 1 }
205
206 //------------------------------------------------------------------------
207 // This function gets an incoming Ethernet frame from the 8019.
208 // There may be more than 1 waiting but just allocate memory for
209 // one and read one in. Use the 8019 to queue incoming packets.
210 //------------------------------------------------------------------------
211 UCHAR xdata * rcve_frame(void)//如果收到一個(gè)有效的數(shù)據(jù)包,返回收到的數(shù)據(jù),否則返回NULL
212 {
213 1 UCHAR bnry,curr,next_page;
214 1
215 1 UINT len, ii;
216 1 UCHAR temp;
217 1 UCHAR xdata * buf;
218 1
219 1 page(0);
220 1 bnry=reg03; //bnry page have read 讀頁指針
221 1 page(1);
222 1 curr=reg07; //curr writepoint 8019寫頁指針
223 1 page(0);
224 1 if ((curr==0)) return NULL; //讀的過程出錯(cuò)
225 1 next_page=bnry;
226 1 bnry=bnry++;
227 1 if (bnry>0x7f) bnry=0x4c;
228 1 if (bnry!=curr) //此時(shí)表示有新的數(shù)據(jù)包在緩沖區(qū)里
229 1 {
230 2 //讀取一包的前4個(gè)字節(jié):4字節(jié)的8019頭部
231 2 page(0);
232 2 reg09=bnry; //read page address high
233 2 reg08=0x00; //read page address low
234 2 reg0b=0x00; //read count high
235 2 reg0a=4; //read count low;
236 2 reg00=0x0a; //read dma
237 2
238 2 temp = reg10; temp = reg10;
239 2 next_page = temp-1; //next page start-1
240 2 len = reg10; temp = reg10;
241 2 len += temp<<8;
C51 COMPILER V7.06 ETH 07/29/2006 13:15:57 PAGE 5
242 2 reg0b=0x00; reg0a=0x00; reg00=0x22;//complete dma page 0
243 2
244 2 // Allocate enough memory to hold the incoming frame
245 2 buf = (UCHAR xdata *)malloc(len);
246 2 if (buf == NULL)
247 2 {
248 3 // out of RAM
249 3 // Tell 8019 to skip the frame
250 3 page(1);
251 3 curr=reg07; //page1
252 3 page(0); //切換回page0
253 3 bnry = curr -1;
254 3 if (bnry < 0x4c) bnry =0x7f;
255 3 reg03=bnry; //write to bnry
256 3 reg07=0xff; //清除中斷狀態(tài)可以不用
257 3 return NULL;
258 3 }
259 2 // This flag keeps track of allocated rcve memory
260 2 rcve_buf_allocated = TRUE;
261 2 // Call the assembler function to get the incoming frame
262 2 reg09=bnry; //read page address high
263 2 reg08=4; //read page address low
264 2 reg0b=len>>8; //read count high
265 2 reg0a=len&0xff; //read count low;
266 2 reg00=0x0a; //read dma
267 2 for(ii=0;ii<len;ii++)
268 2 {
269 3 buf[ii]=reg10;
270 3 }
271 2 reg0b=0x00; reg0a=0x00; reg00=0x22; //dma complete page0
272 2 // Return pointer to start of buffer
273 2 bnry=next_page;
274 2 if (bnry<0x4c) bnry=0x7f;
275 2 reg03=bnry; //write to bnry
276 2 reg07=0xff;
277 2 return (buf);
278 2 }
279 1 return NULL;
280 1 }
281
282
283
284
285
286
287 void eth_send(UCHAR xdata * outbuf, UCHAR * hwaddr, UINT ptype, UINT len)
288 {
289 1 ETH_HEADER xdata * eth;
290 1
291 1 eth = (ETH_HEADER xdata *)outbuf;
292 1
293 1 // Add 14 byte Ethernet header
294 1 memcpy(eth->dest_hwaddr, hwaddr, 6);
295 1 memcpy(eth->source_hwaddr, my_hwaddr, 6);
296 1 eth->frame_type = ptype;
297 1
298 1 // We just added 14 bytes to length
299 1 send_frame(outbuf, len + 14);
300 1 }
301
302 //------------------------------------------------------------------------
303 // This is the handler for incoming Ethernet frames
C51 COMPILER V7.06 ETH 07/29/2006 13:15:57 PAGE 6
304 // This is designed to handle standard Ethernet (RFC 893) frames
305 // See "TCP/IP Illustrated, Volume 1" Sect 2.2
306 //------------------------------------------------------------------------
307 void eth_rcve(UCHAR xdata * inbuf)
308 {
309 1 ETH_HEADER xdata * eth;
310 1
311 1 eth = (ETH_HEADER xdata *)inbuf;
312 1
313 1 // Reject frames in IEEE 802 format where Eth type field
314 1 // is used for length. Todo: Make it handle this format
315 1 if (eth->frame_type < 1520)
316 1 {
317 2 if (debug) serial_send("ETH: IEEE 802 pkt rejected\r");
318 2 return;
319 2 }
320 1
321 1 // Figure out what type of frame it is from Eth header
322 1 // Call appropriate handler and supply address of buffer
323 1 switch (eth->frame_type)
324 1 {
325 2 case ARP_PACKET:
326 2 arp_rcve(inbuf);
327 2 break;
328 2
329 2 case IP_PACKET:
330 2 ip_rcve(inbuf);
331 2 break;
332 2
333 2 default:
334 2 if (debug) serial_send("Error: Unknown pkt rcvd\r");
335 2 break;
336 2 }
337 1 }
338
339
340
341
342
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1048 ----
CONSTANT SIZE = 53 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 26
IDATA SIZE = ---- ----
BIT SIZE = 1 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -