📄 main.lst
字号:
226 2 else
227 2 printf("Read network configuration from I2C error! \n");
228 2 }
229 1
230 1
231 1 IAP_pageread(FLASH_MAC_START_ADDR, mac, MACLEN);
232 1 IAP_pageread(FLASH_IP_START_ADDR, &tempip[0], 4);
233 1 IAP_pageread(FLASH_TFTP_SERVER_ADDR, &temptftp[0], 4);
234 1
235 1 //printf("mac[0] : %bx IP[0]: %bx tftp[0]:%bx \n", mac[0], tempip[0], temptftp[0]);
236 1
237 1
238 1 if(((mac[0]&0x01) == 0) && (tempip[0]<248) && (temptftp[0]<248))
239 1 {
240 2 ipfromwhere = 2; /*from flash*/
C51 COMPILER V7.50 MAIN 10/12/2006 15:31:38 PAGE 5
241 2 printf("Read network configuration from flash \n");
242 2 return 1;
243 2 }
244 1 else
245 1 {
246 2 ipfromwhere = 3;
247 2 printf("Read network configuration from flash error! \n");
248 2 printf("Read network configuration from config.c \n");
249 2 }
250 1 return 1;
251 1 }
252
253 /************************************************************************
254 /* Function Name : netconfig *
255 /* *
256 /* Arguments : *
257 /* NODE *np:Point to NODE to return settings. *
258 /* char from_eeprom_flag:Set to read setting from EEPROM. *
259 /* *
260 /* Return : None. *
261 /* *
262 /* *
263 /* Comment : *
264 /* This function get the: IP address, netmask, and Gateway for *
265 /* the local node.Attempts to read network parameters from *
266 /* serial eeprom if the from_eeprom_flag is set, otherwise *
267 /* defaults to config.c. *
268 /* *
269 /************************************************************************/
270 void netconfig (NODE *np,char net_from_flag)
271 {
272 1
273 1 unsigned char tempip[6];
274 1 unsigned char tempmask[6];
275 1 unsigned char tempgate[6];
276 1
277 1 /* MAC address. */
278 1 memcpy(np->mac,my_mac_addr,MACLEN);
279 1
280 1
281 1 /* Read the network configuration from the serial EEPROM. */
282 1 if (net_from_flag == 1)
283 1 {
284 2 c256_pageread(I2C_IP_START_ADDR,&tempip[0],4);
285 2 c256_pageread(I2C_NET_MASK_START_ADDR,&tempmask[0],4);
286 2 c256_pageread(I2C_GATEWAY_START_ADDR,&tempgate[0],4);
287 2
288 2 np->gate=((LWORD)tempgate[0]<<24)+((LWORD)tempgate[1]<<16)+((LWORD)tempgate[2]<<8)+tempgate[3];
289 2 np->ip=((LWORD)tempip[0]<<24)+((LWORD)tempip[1]<<16)+((LWORD)tempip[2]<<8)+tempip[3];
290 2 np->mask=((LWORD)tempmask[0]<<24)+((LWORD)tempmask[1]<<16)+((LWORD)tempmask[2]<<8)+tempmask[3];
291 2
292 2 }
293 1 else if(net_from_flag == 2)
294 1 {
295 2 IAP_pageread(FLASH_IP_START_ADDR, &tempip[0], 4);
296 2 IAP_pageread(FLASH_NET_MASK_START_ADDR, &tempmask[0], 4);
297 2 IAP_pageread(FLASH_GATEWAY_START_ADDR, &tempgate[0], 4);
298 2
299 2 np->gate=((LWORD)tempgate[0]<<24)+((LWORD)tempgate[1]<<16)+((LWORD)tempgate[2]<<8)+tempgate[3];
300 2 np->ip=((LWORD)tempip[0]<<24)+((LWORD)tempip[1]<<16)+((LWORD)tempip[2]<<8)+tempip[3];
301 2 np->mask=((LWORD)tempmask[0]<<24)+((LWORD)tempmask[1]<<16)+((LWORD)tempmask[2]<<8)+tempmask[3];
302 2
C51 COMPILER V7.50 MAIN 10/12/2006 15:31:38 PAGE 6
303 2 }
304 1 else
305 1 {
306 2 np->ip = atoip (my_ip_addr);
307 2 np->gate=atoip (my_gateway_addr);
308 2 np->mask = atoip (my_ip_mask);
309 2 }
310 1
311 1 }
312
313 /************************************************************************
314 /* Function Name : CS620X_init *
315 /* *
316 /* Arguments : *
317 /* None. *
318 /* Return : *
319 /* None. *
320 /* *
321 /* Comment : *
322 /* This function sets up the clocking and RS232 intrface. *
323 /* *
324 /************************************************************************/
325 void CS620X_init(void)
326 {
327 1 PCON = PCON | 0x80;
328 1 /*
329 1 The following code cannot run when using the Keil in-system debugger.
330 1 Undefine mon51 when burning code into FLASH memory.
331 1 */
332 1 #ifndef mon51
333 1 SCON = 0x5A;
334 1 TMOD = 0x22;
335 1 TCON = 0x40;
336 1 TH1 = 0xF9; /* Baud Rate = 38400Kbs. */
337 1 TL1 = 0xFF;
338 1 IE = 0xA0;
339 1 /* Use the "stretch MOVX select bits" to make MOVX 2 machine cycles. */
340 1 CKCON = CKCON & 0xFB;
341 1 #endif
342 1
343 1 XBYTE[NIC_TCR] = XBYTE[NIC_TCR] | 0x80; //fullduplex = 1
344 1
345 1 TI = 1;
346 1
347 1 }
348
349 /************************************************************************
350 /* Function Name : do_receive *
351 /* *
352 /* Arguments : *
353 /* GENFRAME *gfp:Point to GENFRAME. *
354 /* Return : *
355 /* None. *
356 /* *
357 /* Comment : *
358 /* This function check for TCP/IP socket and send data if *
359 /* required. *
360 /* *
361 /************************************************************************/
362 void do_poll(GENFRAME *gfp)
363 {
364 1 tcp_poll(tsocks, NSOCKS, gfp);
C51 COMPILER V7.50 MAIN 10/12/2006 15:31:38 PAGE 7
365 1 }
366 /************************************************************************
367 /* Function Name : do_receive *
368 /* *
369 /* Arguments : *
370 /* GENFRAME *gfp:Point to GENFRAME. *
371 /* Return : *
372 /* None. *
373 /* *
374 /* Comment : *
375 /* This function check for incoming packets, send response if *
376 /* required. *
377 /* *
378 /************************************************************************/
379 void do_receive(GENFRAME *gfp)
380 {
381 1 NODE node;
382 1 ARPKT *arp;
383 1 IPKT *ip;
384 1 ICMPKT *icmp;
385 1 int rxlen, txlen, len;
386 1
387 1 /* Any incoming frames? */
388 1 if ((rxlen=get_frame(gfp)) > 0)
389 1 {
390 2 ip = getframe_datap(gfp);
391 2
392 2 /* Check for ARP. */
393 2 if (is_arp(gfp, rxlen))
394 2 {
395 3 /* ARP request? */
396 3 arp = getframe_datap(gfp);
397 3 if (arp->op==ARPREQ && arp->dip==locnode.ip)
398 3 {
399 4 /* Make ARP response. */
400 4 node.ip = arp->sip;
401 4 memcpy(node.mac, arp->smac, MACLEN);
402 4 txlen = make_arp(gfp, &locnode, &node, ARPRESP);
403 4 /* Send out the packet. */
404 4 put_frame(gfp, txlen);
405 4 }
406 3
407 3 /* Check for ARP response? */
408 3 if (arp->op==ARPRESP && arp->dip==locnode.ip)
409 3 {
410 4 arp_receive(tsocks, NSOCKS, gfp);
411 4 }
412 3 }
413 2 /* IP datagram? */
414 2 else if ((rxlen=is_ip(gfp, rxlen))!=0 &&
415 2 ip->i.dip==locnode.ip || ip->i.dip==BCASTIP)
416 2 {
417 3 getip_srce(gfp, &node);
418 3
419 3 /* ICMP protocol? */
420 3 if ((len=is_icmp(ip, rxlen))!=0)
421 3 {
422 4 /* ECHO request? */
423 4 icmp = (ICMPKT *)ip;
424 4 if (icmp->c.type==ICREQ)
425 4 {
426 5 /* Create ICMP response packet. */
C51 COMPILER V7.50 MAIN 10/12/2006 15:31:38 PAGE 8
427 5 len = (WORD)maxi(len, 0);
428 5 txlen = make_icmp(gfp, &locnode, &node, ICREP,
429 5 icmp->c.i_code, (WORD)len);
430 5
431 5 /* Send out the packet. */
432 5 put_frame(gfp, txlen);
433 5 }
434 4 }
435 3 /* TCP datagram? */
436 3 else if ((len=is_tcp(ip, rxlen))!=0)
437 3 {
438 4 tcp_receive(tsocks, NSOCKS, gfp, len);
439 4 }
440 3 }
441 2 }
442 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 2008 ----
CONSTANT SIZE = 271 ----
XDATA SIZE = 1 96
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -