Ethernet TCP/IP Source Code Driver Project
Section 03. Sample NIC Drivers and Sample Projects

03. Sample NIC Drivers and Sample Projects

a) Overview

Sample nic.c & nic.h network interface controller files are included for several nic’s. If using one of these nic’s they can be used directly or if using a different nic IC they can be used as a basis for your new device. See later in this manual for details on creating your own version for a new nic. To use them copy all of the files in the chosen nic IC directory into the same directory as the main driver files.

Sample projects are included with the driver for specific devices and compilers. The example schematics at the end of this manual detail the circuit each sample project is designed to work with. You may use the sample projects with the circuit shown or if desired use them as a starting block for your own project with a different device or compiler. To use them copy all of the files in the chosen sample project directory into the same directory as the driver files and then open and run using the development environment / compiler the project was designed with.

b) Sample NIC Drivers Included

Sample nic files are included for each of the following nic’s:-

NXP LPC2000 series 32bit ARM microcontroller

Dual speed 10/100Mps

Built in Ethernet interface with external KSZ8001 PHY IC

Microchip PIC32 series 32bit MIPS microcontroller

Dual speed 10/100Mps

Built in Ethernet interface with external KSZ8001 PHY IC

SMSC LAN91C111

Dual speed 10/100Mps

Parallel 8 or 16 bit interface

Realtek RTL8019AS

Single speed 10Mps

Parallel 8 bit interface

Microchip ENC28J60

Single speed 10Mps

Serial SPI interface

See later in this manual for details on creating your own version for a new nic model.

c) Sample Projects Included

Rowley CrossWorks 2 Compiler

Compiler:

Rowley Associates CrossWorks 2 C Compiler for ARM

Device:

NXP LPC2365

NIC:

Built in. Uses external KSZ8001 PHY IC.

Microchip C18 Compiler using PICDEM.net 2 Development Board

Compiler:

Microchip C18 MPLAB C Compiler for PIC18 family of 8 bit microcontrollers

Device:

PIC18F97J60

NIC:

Microchip ENC28J60

Notes:

JP5 Link centre to RD2

JP9 Link

Connect Ethernet to J2

Microchip C30 Compiler using Explorer 16 Development Board & Ethernet PICtail+

Compiler:

Microchip C30 MPLAB C Compiler for PIC24 family of 16 bit microcontrollers and dsPIC digital signal controllers

Device:

PIC24FJ128GA010

NIC:

Microchip ENC28J60

Microchip C32 Compiler using Explorer 16 Development Board & Ethernet PICtail+

Compiler:

Microchip C32 MPLAB C Compiler for PIC32 family of 32 bit microcontrollers

Device:

PIC32MX360F512L

NIC:

Microchip ENC28J60

d) Sample Project Functions

If you haven’t already it’s a good idea to read the Network Protocol Analyzer Utilities and PC Ethernet Ports sections of this manual now so that you can setup Wireshark to monitor your computers Ethernet port and see activity on the network as it happens. Without this it’s hard to see with your own eyes what the stack is actually doing!

The sample project, which is all provided in ap-main.c and ap-main.h, is configured with DHCP enabled. If you wish to manually set an IP address, for instance if your network does not have a DHCP server or if you are directly connecting your device to your computer, alter the initialise() function.

Compile and run the project on your hardware. If the Network Interface Controller IC (nic) is connected to a network (connected to a hub, switch or directly to another Ethernet device) LED A will light. LED B will light when the driver has an IP address. If you are using manual IP settings then this will be immediate but if you are using DHCP this will be once the DHCP server has been found and the IP settings obtained.

To view the sample web page:

enter the following in your browsers address bar:

“http://embedded-device/”, or just “embedded-device”

This is the name the sample project sets as the drivers NetBIOS name. If your browser doesn’t display the sample web page shown above and doesn’t display a ‘not found’ error page then its likely that your DNS service is stopping your computer trying the NetBIOS service, so instead enter the IP address of the device in the browsers address bar. If you are using DHCP you can find what IP address the DHCP server assigned by looking at your Wireshark log or by using your debugger to view the value of the variable our_ip_address.

The sample page shown demonstrates the serving of a single web page and an image, the inclusion of dynamic data in each of the form fields, and the three different types of form input methods you may use.

If you have a POP3 or SMTP account to use the web page allows you to trigger the sending or receiving of email. The sample functions that is passed each received email doesn’t do anything with the data but can be made to by adding your own code. The sample functions that is called to provide the email contents when triggering an email send will generate a simple email with a text file attached. Triggering a send or receive of email can also be monitored using Wireshark so you can see POP3 and SMTP driver in action.

You can also test the uploading of a file using the third form. Again the sample functions don’t do anything with the received file data but can be made to if you add your own code to them.

The 2 switch inputs provide the following functions:-

Switch A Press to trigger the following:

Requests time from SNTP server

Opens a client UDP socket, sends a broadcast UDP packet to port 6452 containing the text “Hello World” and the waits for a response, timing out and resetting if none is received

Switch B Press to trigger the following:

Attempts to opens a client TCP socket connected to a remote device with IP address 192.168.0.20 (alter as required) using port 4102. If the connection is accepted by the remote device it will then sends a TCP packet containing the text “Hello World” and the wait for a response. If a response is received or if it times out it will then request the socket to be closed.

The sample project also implements a constantly running UDP server socket and TCP server socket which provide the following functions:

If you setup another device to send a UDP packet to port 6451 the sample socket will automatically respond with a broadcast packet containing the text “Hello World”.

If you setup another device to connect using TCP to 4101 the driver will accept the connection and wait for a single packet. It will automatically respond with a packet containing the text “Hello World”. The TCP server will remain connected until the remote client disconnects.

The sample projects may be used as a starting point to write a new application or just as a reference for including the driver in your own project.