19.08.2013 Views

AN2120: Connecting an M68HC08 Family Microcontroller to an ...

AN2120: Connecting an M68HC08 Family Microcontroller to an ...

AN2120: Connecting an M68HC08 Family Microcontroller to an ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

*/<br />

#include "IP.h"<br />

#include "ICMP.h"<br />

/***********************************************************************<br />

Function : ICMPPing<br />

Parameters : IP Address <strong>to</strong> ping<br />

Date : September 2000<br />

Desc : Sends a ICMP ECHO message <strong>to</strong> a remote host<br />

***********************************************************************/<br />

void IcmpPing (BYTE Ip[]) {<br />

WORD Value;<br />

static BYTE Seq = 0xAB;<br />

}<br />

<strong>AN2120</strong><br />

Application Note<br />

Code Implementation<br />

ip_out->SourceAddress [0] = IPAddress [0];// Ping will have our source address<br />

ip_out->SourceAddress [1] = IPAddress [1];<br />

ip_out->SourceAddress [2] = IPAddress [2];<br />

ip_out->SourceAddress [3] = IPAddress [3];<br />

ip_out->DestAddress [0] = Ip[0]; // Set destination IP address<br />

ip_out->DestAddress [1] = Ip[1];<br />

ip_out->DestAddress [2] = Ip[2];<br />

ip_out->DestAddress [3] = Ip[3];<br />

ip_out->Payload [0] = ECHO; // ICMP message type set <strong>to</strong> ECHO<br />

ip_out->Payload [1] = 0; // ICMP code must by set <strong>to</strong> zero<br />

ip_out->Payload [2] = 0; // reset checksum<br />

ip_out->Payload [3] = 0;<br />

ip_out->Payload [4] = 1; // set ID of ICMP message<br />

ip_out->Payload [5] = 0;<br />

Seq++;<br />

ip_out->Payload [6] = (Seq >> 8) & 0xFF; // set sequence number of ICMP Msg<br />

ip_out->Payload [7] = Seq & 0xFF;<br />

ip_out->Pro<strong>to</strong>col = ICMP; // IP datagram will carry ICMP data<br />

ip_out->Length = 28; // ECHO message doesn't include data<br />

Value = IPCheckSum ((BYTE *)&ip_out->Payload[0], (ip_out->Length - 20) >> 1);<br />

ip_out->Payload [2] = (Value >> 8); // obtain ICMP checksum<br />

ip_out->Payload [3] = (Value & 0xFF);<br />

IPNetSend (ip_out); // Net send <strong>to</strong> IP layer<br />

MOTOROLA 85

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!