Porting LWIP Based on S3C2440 and dm9000 (1)
Finally, I started my first note. This is the migration of Ethernet.
I have been using mini2440 for some time. Such as bare-metal led, keyboard switch, and so on have also been tested, UCOS, WinCE is also a simple taste. Now I think of Ethernet.
Because the mini2440 board integrates a dm9000 Nic, And the CE system successfully uses Ethernet to connect to the PC. As a result, I naturally wondered if I could implement Ethernet interfaces under UCOS?
I don't know anything at first, so I am looking for some information. Here I would like to thank Jiao Haibo for his book on Embedded Network System Design. During the transplantation process, many materials come from this book. The second is the mikenoodle microcontroller-driven dm9000 Nic, which details how to drive dm9000 Nic on bare metal 2440.
First, what do we need to do? To implement the LWIP protocol under UCOS. Of course, we need an LWIP protocol file, which can be downloaded from the LWIP official website. The latest version is 1.3.0. To facilitate the first migration, I used the LWIP version 1.2.0 used by Jiao Haibo. The second is the dm9000 NIC driver, and the second is the 2440-based UCOS system. To sum up, we need to do the following:
1. LWIP
2. UCOS for 2440
3. Driver for dm9000
4. LWIP-> driver for dm9000
The last one is the link program of the LWIP and dm9000 drivers, which is what we usually call the protocol and hardware interfaces.
LWIP can be downloaded from the official website. You only need to modify it to 2440. UCOS for 2440 is easy to use. The remaining two items are the implementation of the following two items.
I have been searching for the dm9000 driver for a long time. I finally found a 2440 bare metal driver, but I'm not sure if it meets my needs. Therefore, I decided to first implement the driver under UCOS, that is, porting the driver under bare metal to UCOS without going through the LWIP protocol and directly testing its availability.
The dm9000 driver is mainly used to complete two tasks. One is to assign values to each register of the dm9000 according to the technical requirements of the dm9000 Nic to initialize the dm9000, and the other is to implement the data sending and receiving function of the dm9000. Regarding the initialization of dm9000, The mikenoodle blog explains the following steps:
1. Activate gpio0 and set it as input. It is a channel for communication between dm9000 and internal Phy.
2. Check the ID of the dm9000. The purpose of this step is to determine whether the chip used is dm9000.
3. Check the dm9000 type. This step is to determine the network card type.
4. Set the register of the phy, that is, initialize the parameters of the physical layer.
5. Set the MAC address of the NIC. You can set this step manually or using eepram.
6. Activate dm9000, mainly to set the interrupt and receive registers.
7. Wait for the link to be established and complete initialization.
It should be noted that the value assignment to the dm9000 register usually writes the Register address before writing data. The only difference between the write address and data to dm9000 is that the write address parameter address is the base address + 300, and the write address is the base address + 300 + 4, from the perspective of the circuit model, that is, the high and low levels of the CMD pin. The high level indicates that the data is written, and the low level indicates that the address is written. In addition, when assigning values to the eepram and PHY registers, you must first select the eepram or phy, and then assign values to the registers that read and write eepram/Phy.
After initialization, the next task is to write the transceiver driver. The implementation of sending and receiving is actually the process of writing the data to be sent to the sending register of dm9000 and reading the data to be received from the receiving register, which is similar to the general serial port sending and receiving process. It is worth noting that the process of reading and writing registers also needs to write the Register address first and perform the next operation on the register.
It should be noted that there are two registers for receiving and sending dm9000. One is the receiving (sending) incremental register. After reading (sending) One data bit each time, its address pointer will automatically increment one bit, and the other is the receiving (sending) Non-incrementing register, after reading (sending) One data bit each time, the address pointer does not increase progressively.
The above is what the dm9000 driver needs to implement.
LWIP implementation based on S3C2440 and dm9000 (2)
After completing the dm9000 driver, the next step is to link the driver with the LWIP protocol and place it in the UCOS system. According to Mr. Jiao Haibo's introduction to embedded network system design, this process mainly involves three parts.
1. The association between LWIP initialization and nic initialization.
2. The association between LWIP receiving and nic receiving driver.
3. The association between LWIP sending and nic sending driver.
The general idea is as follows:
First, let's start with initialization. In the UCOS system, we create a task to initialize network interfaces. This task program first calls the initialization program in LWIP to initialize the mailbox, queue, semaphore, stack, and other parameters used by LWIP. Then, it sets the network address in the dm9000 driver, package the address parameters required by the MAC address, gateway, and other piv4 protocols into the data (struct) for managing these addresses in the LWIP protocol. Then, it calls the NIC initialization program to initialize dm9000. At this time, the dm9000 and external network channels are connected.
However, at this time, it cannot communicate with other computers in the external network, because even if the network is connected, the data transmitted over the network must comply with the Ethernet protocol before it can be identified, so we still need to do the following two steps. It is to associate the receiving (sending) program that processes various network protocols in the LWIP protocol with the receiving (sending) program in the dm9000 driver. This association has two methods. One is to use the interrupt method association, that is, to set an external interrupt in 2440, read the interrupt Status Register ISR of dm9000 In the interrupt program, and determine whether the interrupt is received or sent, then, use the mailbox or semaphore function to guide the execution of the corresponding program. The other is to use the UCOS task function to create two tasks, one for receiving, the other for sending, and the query for execution.
Don't forget, after completing this step, we also need to call the receiving or sending programs in the dm9000 driver in the LWIP Input Program and output program to complete the link between them.
So far, LWIP can be put into use on 2440.