Microchip TCP/IP Stack v3.75.5 (beta)

Contents
Download zip file (866KB)



Configuration

There are at least three files that you will need to edit and modify to reflect your particular hardware configuration and code options, the config.h file, the particular hardware configuration file for your board and if necessary the main application source code.

Once you have the files "tailored" for your project or application you must select the correct processor on MPLAB IDE and if necessary the language toolset that will be used to compile the code.

Remember that some microcontrollers such as the PIC18F452 or PIC18F4520 have limited amount of program memory space to fit all stack modules and leave available space for your application.

A recommended pin compatible device with more memory both program and RAM, and more advanced peripherals is the PIC18F4620 or its 28-pin version the PIC18F2620.

The main configuration file and other parts of the code use a special macro that define which is the hardware profile to be included for building the stack, you need to add this macro the project build options on MPLAB IDE.

For example if you are planning to build the code for the Microchip PICDEM.net board, on the Projects->Build Options->Project menu and MPLAB C18 tab you must add the macro PICDEMNET .


The config.h file

The config.h file is included throughout the code to select particular pieces of code and initialization values based on the particular hardware configuration (more about it later) and TCP/IP stack configuration and options.

The config.h is located in the src/include subdirectory.

The file is organized in different sections. Below is an explanation of each section and some of the configuration options/macros.

The first section defines a string with the current version of the code, this string will be displayed on the LCD if present and available as a variable for the HTTP server in case like the HTTP documents examples you want to show the version on a HTML page.
#define VERSION   "3.75.5b"        // Firmware version
        
The following group of conditional macros selects which hardware configuration file to include based on a macro that must be defined in the projects options. The software distribution includes several MPLAB IDE project files that have the correct macro defined for each project. Notice that this macro value will be used in other parts of the code such as the main application code to set the appropriate processor configuration bits.

Also each project may have some variants based on the particular hardware configuration, for example if you want to compile the code for the PICNet 1 Board without the SPI LCD drivers you must comment the line that includes the picnet1_spilcd.h file and uncomment the one that includes the picnet1.h.
//*****************************************************************************
// Define or include your hardware configuration
//
#if defined(PIC10T)
    #include "include/pic10t.h"
#elif defined(MINIPIC10T)
    #include "include/minipic10t.h"
#elif defined(PICNET1)
//    #include "include/picnet1.h"
    #include "include/picnet1_spilcd.h"
#elif defined(EIP10)
//    #include "include/eip10.h"
    #include "include/eip10_lcd.h"
//    #include "include/eip10_spilcd.h"
#elif defined(PICDEM2)
    #include "include/picdem2.h"
#elif defined(PICDEMNET)
    #include "include/picdemnet.h"
#elif defined(EXP16_DSPIC33)
    #include "include/exp16_dspic33.h"
#elif defined(EXP16_PIC24H)
    #include "include/exp16_pic24h.h"
#elif defined(EXP16_PIC24F)
    #include "include/exp16_pic24F.h"
#else
    #error: CFG001: No hardware configuration defined
#endif
        
The following group of macros set the default MAC Address and IP configuration. Observe that for the MAC and IP addresses the values are separated by commas.
//*****************************************************************************
// TCP/IP Config
//
#define DEFAULT_MAC_ADDRESS { 0x00, 0x04, 0xa3, 0x00, 0x02, 0x00 }
#define DEFAULT_IP_ADDRESS  { 192, 168, 1, 201 }
#define DEFAULT_NETMASK     { 255, 255, 255, 255 }
#define DEFAULT_GATEWAY     { 192, 168, 1, 1 }
#define DEFAULT_NS1         { 192, 168, 1, 1 }

#if defined(PICDEM2)
    #define DEFAULT_NETBIOS_NAME  "PICDEM2"
#elif defined(PIC10T) || defined(MINIPIC10T)
    #define DEFAULT_NETBIOS_NAME  "PIC10T"
#elif defined(EIP10)
    #define DEFAULT_NETBIOS_NAME  "EIP10"
#elif defined(PICNET1)
    #define DEFAULT_NETBIOS_NAME  "PICNET1"
#else
    #define DEFAULT_NETBIOS_NAME  "MCHPBOARD"
#endif
        
The following group of macros select which modules of the TCP/IP stack will be included, there is no need to include the UDP and TCP modules since they will be automatically include based on the requirements of each of the modules listed below.

To include a particular module just uncomment the corresponding line. Be aware that some modules like the TCP Client Example will automatically include the DNS module regardless if the line in this section is commented or not.
//*****************************************************************************
// Stack Modules
//
#define STACK_USE_ICMP               // ICMP reply (ping) module
#define STACK_USE_HTTP_SERVER        // HTTP server
//#define STACK_USE_IP_GLEANING      // Obtain IP address via IP Gleaning 
//#define STACK_USE_DHCP             // DHCP client
#define STACK_USE_FTP_SERVER         // FTP server
//#define STACK_USE_TCP_EXAMPLE1     // HTTP client example in tcp_client_ex1.c
#define STACK_USE_ANNOUNCE           // Ethernet Device Discoverer server/client
//#define STACK_USE_DNS              // DNS client
#define STACK_USE_NBNS               // NetBIOS Name Service Server
//#define STACK_USE_UDPTEST          // Enable UDP Test code
        
The next group of macros defines various options and parameters for the TCP/IP stack and main application, each of the macros include a descriptive comment of its use and accepted values.
//*****************************************************************************
// Miscellaneous Stack Options
//

// Define Ticks per second for the tick manager and timer prescale value
// TICKS_PER_SECOND must be in the 10-255 range and TICK_PRESCALE_VALUE
// must be a power of 2, ie 2, 4, 8, 16 ... 256
//
#define TICKS_PER_SECOND     (100)   // 10ms
#define TICK_PRESCALE_VALUE  (256)

// Define the Baud Rate for the RS-232 Serial Interface
#define BAUD_RATE (19200)            // bps

// Include the code for the configuration menu via the RS-232 serial interface
//
#define ENABLE_BUTTON0_CONFIG

// Include User process code in main.c
//
//#define ENABLE_USER_PROCESS

// Define Username and Password for the FTP Server
//
#define FTP_USERNAME "ftp"
#define FTP_PASSWORD "microchip"
#define FTP_USER_NAME_LEN (10)

// Enable Hardware assisted IP checksum calculation
// Some Ethernet controllers such as the ENC28J60 include a feature that 
// permits to use the DMA module in checksum mode to assist in the calculation
// of checksum values. The current silicon revisions of the ENC28J60 (B1-B5)
// have a bug that may produce incoming packet loss if this option is enabled
// and a packet is received when the DMA module is in checksum mode.
// If this option is commented the code will set the STACK_USE_SW_CKSUM and
// include the appropriate code to calculate the checksums by software.
//
//#define STACK_USE_HW_CKSUM

// Uncomment following line if this stack will be used in client mode.
// In client mode, some functions specific to client operation are enabled.
// This option will be enabled by default if you include any stack modules
// in the "Stack Modules" section above that require the stack to operate in
// this particular mode.
//
//#define STACK_CLIENT_MODE

// Comment following line if TCP state machine should wait for acknowledgement
// from the remote host before transmitting another packet.
// Commenting following line may reduce throughput.
//
//#define TCP_NO_WAIT_FOR_ACK

// This macro is specific to the Microchip Ethernet controllers.  
// If a different Ethernet controller is used, this define is not used.
// If a Microchip controller is used and a self memory test should be done 
// when the MACInit() function is called, uncomment this line.
// The test requires ~512 bytes of program memory.
//
//#define MAC_POWER_ON_TEST

// This macro is specific to the Microchip Ethernet controllers.  
// If a different Ethernet controller is used, this define is not used.
// Ideally, when MAC_FILTER_BROADCASTS is defined, all broadcast packets that
// are received would be discarded by the hardware, except for ARP requests for
// our IP address. This could be accomplished by filtering all broadcasts, but
// allowing the ARPs using the pattern match filter.
// The code for this feature has been partially implemented, but it is not
// complete nor tested, so this option should remain unused in this stack 
// version.
//
//#define MAC_FILTER_BROADCASTS

// Maximum number of TCP sockets allowed
// Note that each TCP socket consumes 38 bytes of RAM.
//
#define MAX_SOCKETS          (6u)

// Maximum number of TCP sockets allowed
//
#define MAX_UDP_SOCKETS      (4u)

// Maximum numbers of simultaneous HTTP connections allowed.
// Each connection consumes 10 bytes of RAM.
//
#define MAX_HTTP_CONNECTIONS (3u)
	    
The TCP/IP stack includes a simple HTTP server for which the documents must be stored either in an external memory or included as part of the code in program memory.
Uncomment the appropriate line based on your hardware configuration.
//*****************************************************************************
// Storage options
//
#define MPFS_USE_EEPROM            // Use external serial EEPROM
//#define MPFS_USE_PGRM            // Use Program Memory
		
The last section of the config.h file includes a large list of conditional macros that will validate the configuration files and set specific parameters based on the hardware configuration and previously selected options, such as for example the speed and page size for the serial EEPROM, etc.

Normally you should not need to change anything below the following comment lines.
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///       UNLESS NECESSARY AND YOU REALLY KNOW WHAT YOU ARE DOING YOU       ///
///           SHOULD NOT NEED TO CHANGE ANY OF THE LINES BELOW              ///
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
		



   
    ©2006-2008, Jorge Amodio, All rights reserved

Last Update: June 7, 2007