circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

November 2004, Issue 172

TCP/IP Stack Solution
A Detailed Look at the CMX-MicroNet


by Fred Eady


CMX-MicroNet & W/PIC18

The Easy Ethernet W/PIC18 is shown in Photo 1a. The “W” is short for Whacker because the Easy Ethernet W/PIC18’s Ethernet hardware is based on the classic Packet Whacker NIC shown in Photo 1b. The Packet Whacker consists of an RTL8019AS Ethernet engine, a 20-MHz crystal, a Bothhand LF1S022-34 integrated magnetics package, and a complement of supporting power supply bypass capacitors. The Packet Whacker is designed to interface to almost any microcontroller that can supply it with a minimal set of address and data I/O lines.

(Click here to enlarge)

Photo 1a—The EDTP Electronics Easy Ethernet W/PIC18 is actually a product of convenience. It’s basically a Packet Whacker with all of the supporting circuitry on a single PCB. b—The Packet Whacker is a minimal implementation of the RTL8019AS Ethernet engine IC.  Despite its simplicity, the Packet Whacker is in service in every free country of the world.

The Easy Ethernet W/PIC18 takes the basic design of the Packet Whacker and adds a PIC18F452 microcontroller running at 20 MHz, a regulated 5-V power supply, a programming/debugging interface, a data latch (74HCT573 transparent octal latch), and a regulation RS-232 port. The inclusion of the programming/debugging interface allows the Easy Ethernet W/PIC18 to be programmed using the new Microchip PM3 programmer or debugged and programmed using the hockey puck and the MPLAB IDE. The Easy Ethernet W/PIC18’s hardware layout is depicted in Figure 1.

(Click here to enlarge)

Figure 1—The Sipex SP233ACT-based RS-232 port is a luxury option. Only the PIC and the RTL8019AS with their associated support components are needed to put the Easy Ethernet W/PIC18 on a LAN or the Internet. However, the RS-232 port comes in handy when the Easy Ethernet W/PIC18 is used as a serial-to-Ethernet converter.

Before you can load any CMX-MicroNet firmware into the Easy Ethernet W/PIC18’s microcontroller, you must first define your desired TCP/IP operating environment and set up the hardware. This is easily done by modifying the contents of a couple of CMX-MicroNet network component files and setting some microcontroller fuses within the MPLAB IDE. 

The hardware setup is straightforward. Using the Configure pull-down menu in the MPLAB IDE, I set up the microcontroller clock for high-speed operation and turned off the watchdog timer, brownout detect, low-voltage programming, and anything that has to do with code or memory area protection. At MPLAB IDE startup, the hockey puck sensed the PIC18F452 microcontroller and informed the MPLAB IDE that it had found a valid PIC18F452 at the other end of its interface cable. Because the CMX-MicroNet contains its own RTL8019AS driver, I also needed to make sure that the Easy Ethernet W/PIC18 I/O pin definitions matched the CMX-MicroNet driver’s I/O pin definitions. The mapping of the RTL8019AS drive to the hardware I/O structure is found in the rtlregs.h file in the C:\MICRONET\netlib directory. The code snippet that defines the I/O structure that is used with the PICC-18 C compiler and the Easy Ethernet W/PIC18 is shown in Listing 1.

The CMX-MicroNet network file source code components are found in the C:\MICRONET\netlib directory. The driver for the Realtek RTL8019AS Ethernet engine IC also can be found in the netlib directory. Each network source code file is compiled and archived into the netlib.lib library file depending on the protocols selected in the mnconfig.h file, which is also located in the C:\MICRONET\netlib directory.

Refer to the Circuit Cellar ftp site for the code snippet taken from mnconfig.h. I selected the TCP and UDP protocols, which kick in TCP and UDP sockets, and requested to use Ethernet with a checksummed UDP protocol. That pulls tcp.c, udp.c, and mn_csum.c from the C:\MICRONET\netlib directory into the netlib.lib compilation and archival process. I elected to allow the Easy Ethernet W/PIC18 to be pinged. Notice that I also turned on the HTTP server, SMTP, ARP, DHCP, and the CMX-MicroNet virtual file system. That results in including arp.c, http.c, smtp.c, and so forth.

There are also other elements that are automatically included that are common to all of the protocols, such as ip.c and socket.c. The RTL8019AS driver is represented by rtl8019.c. Judging from my list of protocols, it looked like the PIC18F452 was going to be packed as tight as a tube of deli bologna.

The next step in the configuration process was to identify and specify the IP addresses of the network players. This is done to nail down hard-coded IP addresses if DHCP is not being used. My network includes a Windows 2000-based PC loaded with packet-sniffing software, a home-brewed Internet test panel, and a web browser. The gateway device (192.168.0.1) is a Netgear wireless router, which incorporates a four-port 10/100 wired switch and DHCP server capabilities. 

I pinged my ISP’s mail server to get the mail server’s IP address (65.32.5.130) and plugged that into the SMTP IP address definition. All of my IP ducks were in a row at that point. However, the CMX-MicroNet installation set-up documentation suggests ensuring that the required PICC-18 libraries, which are included in the path statement, are built, and gives instructions on how to make that happen. Otherwise, the initial build of the CMX-MicroNet netlib.lib, which is a mandatory step in the CMX-MicroNet stack generation process, will not happen.

The library file netlib.lib must be built before any CMX-MicroNet stack services can be called and used. Two batch files are included with the CMX-MicroNet to facilitate the construction of a netlib.lib file: one supports the RTL8019AS, and one doesn’t include the RTL8019AS driver. The netlib.lib compilation and archival process using PICC-18 compiler and the CMX-MicroNet network library files was performed without incident. Note that the CMX-MicroNet installation process had already correctly modified the path statements.

Everything up to this point pointed to “go” for a test compile and load of the example code included in the CMX-MicroNet package. The PICC-18 C compiler installed without trouble. It successfully registered and attached itself to the MPLAB IDE.

I decided to start with the CMX-MicroNet UDP example code in Client mode because I could instantly test the operation of the code and hardware using my trusty Internet test panel, which enables a UDP echo port on the PC at 192.168.0.2 on the Florida room’s CMX-MicroNet LAN. Server mode or Client mode for UDP and TCP sockets is available by simply completing the #define SERVER_MODE statement in the example code with a 0 for Client mode and a 1 for Server mode. 

I performed a final check on the PIC’s fuse settings and kicked off the compile session. I could hear a TV game show’s “loser” buzzer go off loudly as the error-filled contents rolled through the MPLAB IDE output window. (Refer to the Circuit Cellar ftp site for the code snippet.) I fired off a quick note to the CMX-MicroNet support folks describing my dilemma. The verdict: Stupid Fred was out of PIC18F452 program and data memory. So, I had to pull some of that bologna out of the tube. 

I turned off TCP, HTTP, DHCP, SMTP, and the virtual file system by modifying mnconfig.h. I kept the maximum number of sockets at two, and I didn’t touch the default receive and transmit buffer sizes. I also kept Ethernet support and ping capability enabled. The ping selection doesn’t add any additional code to the final stack.

Turning the knobs and throwing switches within the mnconfig.h file requires a rebuild of the netlib.lib file. Rebuilding the netlib.lib file is as simple as making the changes in mnconfig.h, saving the changes, and executing the CMX-MicroNet’s mkphpice.bat batch file. If Ethernet support is not required, the mkphtpic.bat file can be used to generate the new netlib.lib file. I compiled the UDP example code again. This time I was rewarded with a “BUILD SUCCEEDED” message and the statistics you see in Figure 2a.

Photo 2 is a composite shot of the Internet test panel talking UDP with the Easy Ethernet W/PIC18 and the Netgear router’s view of its attached devices. Notice that because DHCP is turned off, the Easy Ethernet W/PIC18’s IP address is the IP address I hard-coded into the CALLBACK.c network file in the snippet posted on the Circuit Cellar ftp site.

(Click here to enlarge)

Photo 2—The EDTP Electronics Internet test panel is a Visual Basic application that implements a simple UDP echo function on well-known port 7. The test panel can also function as a UDP client that interacts with an Easy Ethernet W/PIC18 acting as a UDP server. You can test drive the Internet test panel by checking out the EDTP web cam.

I also hard-coded the PC destination address in the CMX-MicroNet example code with the following statement:

byte my_dest_addr[IP_ADDR_LEN] = {192,168,0,2};

In addition to bouncing UDP packets off the Internet test panel, I was also able to ping the Easy Ethernet W/PIC18-CMX-MicroNet pair from the PC using the Easy Ethernet W/PIC18’s hard-coded IP address of 192.168.0.150.

The next logical step was to turn on TCP in Server mode and try to get to the Easy Ethernet W/PIC18 using a Telnet session and the CMX-MicroNet TCP example code. A look at Figure 2b shows that I was getting close to filling up that tube of bologna. There’s nothing exciting about looking at a drab Telnet window. So, I’ll just say that the Telnet session worked. The characters were echoed to the PC’s Telnet window from the Easy Ethernet W/PIC18-CMX-MicroNet combination as designed.

Now that I had the Easy Ethernet W/PIC18 jumping through hoops, I added some fire in the form of DHCP. There went that loser buzzer again. Check this out:

Error[000] //Can’t find 0x2C words (0x2C with total) for psect bss in segment RAM

Error[000] //Can’t find 0x18 words (0x18 with total) for psect bss in segment RAM

It looked like I was out of gas in the PIC’s RAM area. I turned off TCP to see if I could regain some ground. However, even with TCP turned off, the RAM utilization was just above 97%. That means you can run a TCP-based or UDP-based Easy Ethernet W/PIC18 with DHCP, but you wouldn’t have much trunk space. So, if you’re going to soar with the Internet eagles, it’s time to switch your LAN locomotion.