TCP/IP Stack Library

TCP/IP Stack Library

Overview

The TCP/IP stack is entirely written in mikroPascal and supports TCP/IP server and client communication. This library supports both the ENC28J60 and ENC48J600 ethernet controllers to give you a full embedded web and Internet server from a PIC microcontroller.

By default the library supports

  • ARP requests
  • ICMP requests
  • IPv4 Protocol
  • UDP client and server
  • TCP client and server (Fully stack driven)
  • DHCP client

The library is written in such a way that socket modules can be "pluged" into the stack to extend its functionality. The modules that comes with this stack is

  • HTTP server - used for a webserver
  • HTTP SD card server - Same as the HTTP server, but files are served from a SD card
  • UART server - a transparent UART to TCP link

Hardware Setup

The source code was developed making use of  MikroElectronika's LV24-33A Development board and a ENC28J60 Ethernet breakout board. It is however fairly easy to port the application to any other development environment that supports Mikrochip's PIC24F range since only 6 wires (4 for SPI and 2 for power) are necessary to drive the ENC28J60 module.

Library interface

Here is a small example of how to implement the TCP/IP stack. This example will configure a HTTP server running on port 80, that will automatically span client sockets and serve webpages, as well as setup TCP port 4001 to listen for incoming connections to create a transaprent link between the TCP/IP port and the USART port on the PIC

begin
  // Init ENC28J60 controller with TCP/IP stack
  ENC28J60_Init(PortF, 0, 1);
  // Static IP address
  // TCPIP_Init('192.168.1.200', '255.255.255.0', '192.168.1.254', '192.168.1.225');

  // DHCP IP address
  TCPIP_Init('0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0');

  // Init HTTP server for the TCP/IP stack
  HTTPServer_Init();
  UARTServer_Init();

  // Setup socket 1 
  // Port 80
  // Multiple connections allowed
  // Don't keep alive
  // HTTP server callbacks
  Socket1 := TCPIP_Bind(TCP, HTTPPort);
  TCPIP_SetCallback(Socket1, HTTPServer);
  TCPIP_Listen(Socket1, true, false);

  // Setup socket 2
  // Port 4001
  // Single connection
  // Keep alive
  // UART server callbacks
  Socket2 := TCPIP_Bind(TCP, UARTPort1);
  TCPIP_SetCallback(Socket2, UARTServer);
  TCPIP_Listen(Socket2, false, true);

  while true do
  begin
    // Do this in an endless loop to process the incoming ethernet packets
    // and TCP/IP stack
    TCPIP_DoPacket();
    TCPIP_DoStack();
  end;
end.

Downloads

Attachments

File name File version File size
mikroPascal for dsPIC source 10 August 2011 1.34 MB

 
Shopping Cart
0 items
 
Riecktron Electronics © 2012