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