Click here to Skip to main content
15,885,244 members
Articles / Mobile Apps

TCP/IP Stack, FAT16 System on a Microcontroller

Rate me:
Please Sign up or sign in to vote.
4.53/5 (10 votes)
31 Jul 2011GPL35 min read 43.4K   2.1K   36  
TCP/IP Stack, FAT16 System on a Microcontroller
/*
 * tcpstack.c
 *
 *  Created on: 4/07/2011
 *      Author: lyl
 */

#include "string.h"
#include <stdio.h>
#include "tcpipconfig.h"
#include "helper.h"
#include "macb.h"

/*! initial sequence number for ICMP request and reply */

/*! sequence number for ICMP request and reply */
unsigned short seqnum = SEQ_NUM_START;

const unsigned char my_ip[4] = {ETHERNET_CONF_IPADDR0,ETHERNET_CONF_IPADDR1,ETHERNET_CONF_IPADDR2,ETHERNET_CONF_IPADDR3};

/*! define the ARP global frame */
const unsigned char ARP_FRAME[42] = {
	0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	ETHERNET_CONF_ETHADDR0,ETHERNET_CONF_ETHADDR1,ETHERNET_CONF_ETHADDR2,ETHERNET_CONF_ETHADDR3,ETHERNET_CONF_ETHADDR4,ETHERNET_CONF_ETHADDR5,
	0x08,0x06,0x00,0x01,0x08,0x00,0x06,0x04,0x00,0x01,
	ETHERNET_CONF_ETHADDR0,ETHERNET_CONF_ETHADDR1,ETHERNET_CONF_ETHADDR2,ETHERNET_CONF_ETHADDR3,ETHERNET_CONF_ETHADDR4,ETHERNET_CONF_ETHADDR5,
	ETHERNET_CONF_IPADDR0,ETHERNET_CONF_IPADDR1,ETHERNET_CONF_IPADDR2,ETHERNET_CONF_IPADDR3,
	0x00,0x00,0x00,0x00,0x00,0x00,
	ETHERNET_CONF_GATEWAY_ADDR0,ETHERNET_CONF_GATEWAY_ADDR1,ETHERNET_CONF_GATEWAY_ADDR2,ETHERNET_CONF_GATEWAY_ADDR3
};

APP_CONFIG myConfig;
unsigned char hwaddr[6] = { ETHERNET_CONF_ETHADDR0,ETHERNET_CONF_ETHADDR1,ETHERNET_CONF_ETHADDR2,ETHERNET_CONF_ETHADDR3,ETHERNET_CONF_ETHADDR4,ETHERNET_CONF_ETHADDR5 };

/*! buffer for sending packets */

void print_our_ip(void)
{
	char debug[30];
	sprintf(debug,"My IP=%03d.%03d.%03d.%03d\r\n",myConfig.MyIPAddr.v[0],
			myConfig.MyIPAddr.v[1],myConfig.MyIPAddr.v[2],myConfig.MyIPAddr.v[3]);
	LW_ASSERT(TRUE,debug);
}

void tcp_ip_core_start(void)
{
	myConfig.IPDecided=FALSE;
	memset(myConfig.MyIPAddr.v,0xff,4);
	#ifndef STACK_USE_DHCP
		memcpy(myConfig.MyIPAddr.v,my_ip,4);
		myConfig.IPDecided=TRUE;
	#endif
	
	memcpy(myConfig.MyMACAddr.v,hwaddr,6);
	vMACBSetMACAddress(hwaddr);

	print_our_ip();

	TCPInit();
	UDPInit();
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions