4.4. Ethernet Module
4.4.1. Module Files
4.4.1.1. Driver
src/app/application/ethernet/ethernet.csrc/app/application/ethernet/ethernet.h
4.4.1.1.1. FreeRTOS
src/app/application/ethernet/ethernet_freertos.c
4.4.1.2. Configuration
src/app/application/config/ethernet_cfg.csrc/app/application/config/ethernet_cfg.h
4.4.1.3. Unit Test
tests/unit/app/application/config/test_ethernet_cfg.ctests/unit/app/application/ethernet/test_ethernet.ctests/unit/app/application/ethernet/test_ethernet_freertos.c
4.4.2. Detailed Description
The ethernet module contains the high level application code for the ethernet communication. It also provides the external function implementations required by the FreeRTOS-Plus-TCP Library.
4.4.2.1. Initialization
During the initialization tree things happen:
A struct that holds the driver for the network interface (EMAC + PHY) is filled. The TCP/IP stack accesses the relevant functions via this struct.
The necessary needed network parameters are stored and made available for the TCP/IP stack.
The TCP/IP stack is initialised and the tasks that use the network are created in the function
vApplicationIPNetworkEventHook()
This is sufficient to respond to ICMP ping requests. How this works is explained in How to Test TCP/IP.
4.4.2.2. Echo Server
As an application example, a tcp Echo Server is implemented in
ethernet.c.
To implement the echo server, a two-stepped approach was chosen.
The Echo Server consists of two IP Application Tasks that are integrated in
the task scheme as described in Operating System Configuration.
Fig. 4.3 shows this communication in a simplified way.
Fig. 4.3 Echo Server Sequence Diagram
The task ETH_ListenForConnection is created in the IP Event Hook.
This task creates a socket that listens for incoming connections.
If a TCP handshake completes successfully, a new connection socket is created
and the actual server task ETH_EchoServerInstance is started.
The server task first performs some basic configuration and then waits for incoming messages. When a message is received, the data is simply echoed back. If the receive timeout is reached, the socket is closed and the task is deleted. The usage is explained in detail in How to Test TCP/IP.
4.4.2.3. Random Numbers
The externalized functions ulApplicationGetNextSequenceNumber() and xApplicationGetRandomNumber() return just a simple random number.
Warning
The random number generator is presently implemented in a simple approach. It does not apply to any security recommendations. It is not suitable for security-relevant use (e.g., exposed to untrusted networks).
4.4.2.4. IP Event Hook
The vApplicationIPNetworkEventHook_Multi() is called by the FreeRTOS-Plus-TCP Library when the network connects or disconnects. This can be used to implement server tasks that depend on network connectivity.
4.4.2.5. DNS (Domain Name System resolution)
FreeRTOS provides the function prototype xApplicationDNSQueryHook()
to implement a DNS resolution.
This function is called by the TCP/IP stack to check whether the name
received is the same as the one device is looking for.