51 lines
1.7 KiB
Markdown
51 lines
1.7 KiB
Markdown
# lwIP Ethernet Driver for CH32V208
|
|
|
|
This is a simple ethernetif.c driver to get lwIP working on the WCH CH32V208 MCU using the ch32fun lib.
|
|
It uses the chip's internal 10Mbps Ethernet MAC. The MAC address is pulled from the chip's 6-byte unique ID.
|
|
|
|
The provided main.c is an example that starts up, gets an IP address via DHCP, and runs a small HTTP server.
|
|
|
|
## Usage
|
|
|
|
1. Initialize lwIP and add the network interface.
|
|
2. Poll the driver and service lwIP's timers in your main loop.
|
|
|
|
```c
|
|
netif_add(&g_netif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, ðernet_input);
|
|
netif_set_default(&g_netif);
|
|
netif_set_up(&g_netif);
|
|
dhcp_start(&g_netif);
|
|
|
|
while (1) {
|
|
// poll for incoming packets
|
|
ethernetif_input(&g_netif);
|
|
|
|
// handle lwIP timers (for TCP, DHCP, etc.)
|
|
sys_check_timeouts();
|
|
|
|
// poll link for link up/down cb
|
|
ethernetif_link_poll(&g_netif);
|
|
}
|
|
```
|
|
|
|
seems okayish
|
|
|
|
```sh
|
|
$ wrk -t12 -c500 -d10s http://192.168.102.119
|
|
Running 10s test @ http://192.168.102.119
|
|
12 threads and 500 connections
|
|
Thread Stats Avg Stdev Max +/- Stdev
|
|
Latency 1.87ms 6.98ms 613.62ms 99.63%
|
|
Req/Sec 334.20 201.29 0.88k 74.58%
|
|
8197 requests in 10.10s, 5.30MB read
|
|
Requests/sec: 811.63
|
|
Transfer/sec: 537.39KB
|
|
```
|
|
|
|
## Impl note
|
|
|
|
This driver is kinda functional but not optimized
|
|
|
|
- **Packet RX:** ~~This is done by polling~~ RXIF works now. You must call `ethernetif_input()` continuously in your main loop to check for and process incoming packets
|
|
- **Packet TX:** TX isn't exactly typical DMA? The CPU has to copy the packet into a single transmit buffer and then manually start the transmission. An ISR will signal when the buffer is free to send the next packet
|