Ethernet Device Driver Implementation
All device drivers must declare an instance of the appropriate device driver API structure as a global variable within the source code. The API structure is an ordered list of function pointers utilized by µC/TCP-IP when device hardware services are required.
A sample Ethernet interface API structure is shown below.
Listing 7-3 Ethernet interface API
Note: It is the device driver developers’ responsibility to ensure that all of the functions listed within the API are properly implemented and that the order of the functions within the API structure is correct.
L7-3(1) Device initialization/add function pointer
L7-3(2) Device start function pointer
L7-3(3) Device stop function pointer
L7-3(4) Device Receive function pointer
L7-3(5) Device transmit function pointer
L7-3(6) Device multicast address add function pointer
L7-3(7) Device multicast address remove function pointer
L7-3(8) Device interrupt service routine (ISR) handler function pointer
L7-3(9) Device I/O control function pointer
L7-3(10) Physical layer (PHY) register read function pointer
L7-3(11) Physical layer (PHY) register write function pointer
Note: µC/TCP-IP device driver API function names may not be unique. Name clashes between device drivers are avoided by never globally prototyping device driver functions and ensuring that all references to functions within the driver are obtained by pointers within the API structure. The developer may arbitrarily name the functions within the source file so long as the API structure is properly declared. The user application should never need to call API functions by name. Unless special care is taken, calling device driver functions by name may lead to unpredictable results due to reentrancy.
The following figure describes the call path from the application layer through the Core, Interface and Controller layers.
...
- Initializing a Network Device
- Starting a Network Device
- Stopping a Network Device
- Receiving Packets on a Network Device
- Transmitting Packets on a Network Device
- Adding an Address to the Multicast Address Filter of a Network Device
- Removing an Address from the Multicast Address Filter of a Network Device
- Setting the MAC Link, Duplex and Speed Settings
- Reading PHY Registers
- Writing to PHY Registers