SHDesigns: Embedded Systems Design, Consulting and Developer Resources Page hits:

Softools WinIDE Tips

Getting the TCP/IP stack to work:

1. tcp_tick() can be called from a timer function. Hower, if you enable it with the timer, it must not be called before sock_init.

2. sock_init may require the timer to be active.

Both the above can be solved with:

... in main()
  WDT_DISAABLE();      // this is needed ot the baord will reset
  ipset0();            // enable interrupts
  usingAll();          // select the driver for all boards
  startTimer(10,0,1);  // start the timer so MS_TIMER counts
  sock_init();    // init net

That will initialize the interface, see item #6 for additional steps needed.

void near MyTimerFunc(void)
{
    tcp_tick(NULL)
}
 // after sock_init()
  timerSetHandler( MyTimerFunc ); // automatically call tcp_tick

The above way will allow the sock_init to use timers and then enable the automatic polling of tcp_tick(). This seems to work for some applications, but multiple calls to tcp_tick() may cause problems.

It is usually better to incude tcp_tick() in your main() loop and not use it in your timer handler.

3. TCP/IP parameters

Many of the defines used by the ZW compiler have been replaced with const variables. I.e the settings for buffers and sockets are as follows:

const char MAX_UDP_SOCKET_BUFFERS = 4; (this is 0 in lib versions > 1.58)
const char MAX_TCP_SOCKET_BUFFERS = 4;
const unsigned UDP_BUF_SIZE= 4096;
const unsigned TCP_BUF_SIZE= 4096;

The above are the defaults. This will use over 32k of xmem for the buffers (4, 4k TCP buffers and 4, 4k UDP buffers. They can normally be reduced and will allow debugging on 128k boards.

The libs have default variables set for these variables. If you need to change them, define them in your source, this will get linked in before the lib and the lib values will then not ne used.

Here are most of the of the other settings:

const char SAUTH_MAXUSERS = 10;
const unsigned TCP_TWTIMEOUT = 2000;
const char KEEPALIVE_NUMRETRYS = 4;
const char KEEPALIVE_WAITTIME = 60;
const char MAX_RESERVEPORTS = 5;
const unsigned TCP_BUF_SIZE = 4096;
const char cookie_name[] = "DCRABBIT";
const int HTTP_DIGEST_NONCE_TIMEOUT = 0;
const int HTTP_MAX_NONCES = 5;
const int VSERIAL_NUM_GATEWAYS = 1;
const char MY_IP_ADDRESS[] = "";
const char MY_NETMASK[] = "";
const char MY_GATEWAY[] = "";
const char MY_NAMESERVER[] = "";
const char MAX_TCP_SOCKET_BUFFERS = 4;
const char MAX_UDP_SOCKET_BUFFERS = 0;
const int TIMEZONE = -8;
const char HTTP_TIMEOUT = 16;
const unsigned HTTP_PORT = 80;
const int FORM_ERROR_BUF = 1;
const char SSPEC_MAXSPEC = 10;
const char DHCP_CLASS_ID[] = "Rabbit2000-TCPIP:Z-World:Test:1.0.0";

const char HTTP_MAXSERVERS = 1;

Note: HTTP_MAXSERVERS also needs the following added to you code if set to any number other than 1:

HttpState http_servers[n]; // n must be equal to the HTTP_MAXSERVERS value

Read the refresh.c example, Softools uses a different syntax for the mime and web page list, the reffresh.c is a good sample.

4. Cstart and stack

Under the cstart options define STACK_SIZE=2048 or higher. I use 4096 to be safe. DHCP will require 3072 or more.

5. PORTA_AUX__IO

The TCP/IP stack as of 5/30/2004 now includes this support. The stack will automatically adjust to the bus mode. However, the bus must be set up before sock_init. There are two macros to set up aux_io:

enableI0bus()
disableIObus()


The stack will read the SPCR and configure the LAN driver to use the current bus mode.

6. Add the required calls to bring up the interface.

DHCP has changed in later versions of the stack. This is due to changes in the ZW code. To enable DHCP, use the following steps:

1. Add the appropriate usingXXX() call:

usingAll(); // load drivers for all interfaces

usingAll() will allow code to run on any ZW board. Other options are usingRealtek(), usingSMSC() and usingASIX();

The call does very little at run time, but it will cause the linker to load the right drivers.

2. Call sock_init()

3a.Enable DHCP

 ifconfig(IF_ETH0,IFS_DHCP,1,IFS_UP,IFS_END);

3b. If DHCP is not used, you will still need to bring up the interface and set the IP address.

 ifconfig(IF_ETH0,IFS_DHCP,0,...,IFS_UP,IFS_END); // when using stcpio-dhcp.lib

 ifconfig(IF_ETH0,...,IFS_UP,IFS_END); // whan not using stcpip-dhcp.lib

replace '...' with the parameters to set IP, Mask and Gateway.

4. Wait for the interface to come up and DHCP to finish before opening sockets:

 while (ifpending(IF_ETH0) == 1)
   tcp_tick(NULL);

You might also want to set the fallback addresses with ifconfig().

7. XMEM

The stack will use xmem for socket transmit and receive buffers.Make sure the end address for STACK set in the linker settings allows enough room for buffers. XMEM is from this address to the end of RAM.

It will need at least:

4k + MAX_TCP_SOCKET_BUFFERS * TCP_BUF_SIZE + MAX_UDP_SOCKET_BUFFERS * UDP_BUF_SIZE.



Additional Information: Rabbit Libraries Home Page - SHDesigns Home Page