2009年10月2日 星期五

PING 8051 with DM9000 Ethernet

http://class.ruten.com.tw/user/index00.php?s=indiana_jones
I like to share with you how to ping 8051 by ethernet protocol,
It's basic ethernet protocol implementation, and it's not necessory to spend much money to practice it.
If you know How it works in ethernet and ping and TCP/IP protocol, then it 's much helpful to implement
others Internet protocol like UDP , TCP , telent, FTP and http ..
1. Base on my previous article, you should know how to move out from DM9000 a packet , and move in 
   a packt to DM9000 and transmimt it.
   FIFO move in/output is basic function.

2. We can know is IP or ARP from Ethernet header protocol, Then we can implement two function two
   branch this two different protocol.

3. We can easy to use Windows Commander, and type pin 192.168.0.200, then PC will send a broadcast command to etherent , our 8051 will get this packet from DM9000, then know PC is ask DM9000 MAC address. So DM9000 will reply and MAC address to PC.

4. PC will use new MAC address , and send ICMP packet to 8051.

5. When 8051 get new packet from DM9000, and know is IP packet not ARP packet.

6. 8051 will check the IP packet protocol, is ICMP or UDP or TCP and pass to ICMP protocol..

7. 8051 will know hte packe the ICMP request. then prepare another packet to transmit.

8. 8051 well prepare ICMP packet , then Pass back the IP layer .

9. 8051 will prepare IP header and add in front of ICMP Packet , then pass back to Ethernet layer.

10. 8051 move all of IP + ICMP packet and add ethernet header , then move into DM9000, and transmit.

11. PC will get this packet and show delay time.

You can see this, We using DOS windows ping command, to send ICMP packet to 8051+DM9000, Due to 8051 have eto calcute checksum, so it took some times delay ..


We show the meeasge in debug window when 8051+dm9000 got packet or send packet.


you also be able to use wireshark to capture packet, to know your transmit packet are correct or not .

http://class.ruten.com.tw/user/index00.php?s=indiana_jones
if you intersting this toy , you can buy it from this , or contact with me.
jones.hsu@gmail.com ..

2009年10月1日 星期四

PING 8051 Step 0 ( Keil Compiler Bug )

Sometimes you will never think about the bug is there , and hard to image that.
Yester I want to Implement PING function to 8051+DM9000B solution.
I can get a  packet from Ethernet with Broadcast command, but I can't get ICMP packet
Then I started to debug , why  ????

I try to look at the packet read pointer of DM9000, When I got first ARP packet and reply RARP to
Sender, and Sender re-send ICMP packet to me, but I will lost this packet.and there is two possibility:
1. The packet is not correct.
2. my MAC address has problem ..
3. Buffer overflow.

So I try to list down all of input buffer reader pointer, the packet pointer is work fine..
then I try to print it the value of My MAC address, and I found the problem is from My wrong
MAC address..

This is MAC address wirte function, it looks no any problem , is it ?

void dm9k_hash_table(void)
{
UC i;
        for(i = 0; i < 6; i++)
                 iow(DM9000_PAR + i, DEF_MAC_ADDR[i]);

        for(i = 0; i < 8; i++)
                  iow(DM9000_MAR + i, 0x00);
         iow(DM9000_MAR + 7, 0x80);
}

But I try to look at and assemeby CODE, then I got this :

; FUNCTION dm9k_hash_table (BEGIN)

; SOURCE LINE # 81
; SOURCE LINE # 82
; SOURCE LINE # 85

0000 E4              CLR A
0001 F500 R      MOV i,A
0003 ?C0016:
0003 E500 R      MOV A,i
0005 C3             CLR C
0006 9406          SUBB A,#06H
0008 500C         JNC ?C0017

; SOURCE LINE # 86

000A E500 R     MOV A,i
000C 2410         ADD A,#010H
000E 908000     MOV DPTR,#DM9000_Index
0011 F0             MOVX @DPTR,A
0012 0500 R      INC i
0014 80ED         SJMP ?C0016
0016 ?C0017:
0016 7400 R      MOV A,#LOW DEF_MAC_ADDR
0018 2500 R      ADD A,i
001A F8             MOV R0,A
001B E6             MOV A,@R0
001C 908001     MOV DPTR,#DM9000_Data
001F F0             MOVX @DPTR,A

now you should see the problem , Keil C optimize the function, and let separate two block
and only write a data .
So I modify the code as it ..

void dm9k_hash_table(void)

{
UC i;
      for(i = 0; i < 6; i++)
     {
           iow(DM9000_PAR + i, DEF_MAC_ADDR[i]);
      }
      for(i = 0; i < 8; i++)
    {
           iow(DM9000_MAR + i, 0x00);
     }
     iow(DM9000_MAR + 7, 0x80);
}

and I got assemebly as below :

; FUNCTION dm9k_hash_table (BEGIN)

; SOURCE LINE # 81
; SOURCE LINE # 82
; SOURCE LINE # 85
0000 E4              CLR A
0001 F500 R       MOV i,A
0003 ?C0016:
0003 E500 R       MOV A,i
0005 C3              CLR C
0006 9406           SUBB A,#06H
0008 5014           JNC ?C0017
; SOURCE LINE # 86
; SOURCE LINE # 87
000A E500 R      MOV A,i
000C 2410          ADD A,#010H
000E 908000      MOV DPTR,#DM9000_Index
0011 F0              MOVX @DPTR,A
0012 7400 R       MOV A,#LOW DEF_MAC_ADDR
0014 2500 R       ADD A,i
0016 F8              MOV R0,A
0017 E6              MOV A,@R0
0018 A3             INC DPTR
0019 F0             MOVX @DPTR,A

; SOURCE LINE # 88
001A 0500 R      INC i
001C 80E5        SJMP ?C0016

So be careful for coding ...

BR,Jones  joens.hsu@gmail.com