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