Move mip/ -> src/tcpip/, rename mip_ -> mg_tcpip_

This commit is contained in:
cpq committed 2023-02-07 21:35:37 +00:00
1 parent efc54375dd
commit 2c62e58dbd
64 files changed
+515 -516

No files matched your search

+1 -1
View File
@@ -9,7 +9,7 @@ pico_sdk_init()
add_compile_definitions(
MIP_DEBUG=1
MG_ENABLE_PACKED_FS=1
MG_ENABLE_MIP=1
MG_ENABLE_TCPIP=1
)
add_executable(firmware
+17 -17
View File
@@ -29,7 +29,7 @@ static dma_channel_config dmacfg_tx;
static uint8_t s_rxbuf[2][ETH_PKT_SIZE]; // ping-pong buffer
static uint8_t s_txbuf[ETH_PKT_SIZE];
static struct mip_if *s_ifp; // MIP interface
static struct mg_tcpip_if *s_ifp; // MIP interface
#define rmii_tx_wrap_target 0
#define rmii_tx_wrap 8
@@ -251,9 +251,9 @@ static uint16_t eth_read_phy(uint addr, uint reg, uint8_t gpio) {
static void rx_irq(void);
static bool mip_driver_rp2040_rmii_init(struct mip_if *ifp) {
struct mip_driver_rp2040_rmii_data *d =
(struct mip_driver_rp2040_rmii_data *) ifp->driver_data;
static bool mg_tcpip_driver_rp2040_rmii_init(struct mg_tcpip_if *ifp) {
struct mg_tcpip_driver_rp2040_rmii_data *d =
(struct mg_tcpip_driver_rp2040_rmii_data *) ifp->driver_data;
uint rx_sm_addr, tx_sm_addr;
s_ifp = ifp;
if (ifp->queue.len == 0) ifp->queue.len = 8192;
@@ -299,8 +299,8 @@ static bool mip_driver_rp2040_rmii_init(struct mip_if *ifp) {
return true;
}
static size_t mip_driver_rp2040_rmii_tx(const void *buf, size_t len,
struct mip_if *ifp) {
static size_t mg_tcpip_driver_rp2040_rmii_tx(const void *buf, size_t len,
struct mg_tcpip_if *ifp) {
dma_channel_wait_for_finish_blocking(dma_tx);
memset(s_txbuf, 0, 60); // pre-pad
memcpy(s_txbuf, buf, len);
@@ -333,12 +333,12 @@ static void rx_irq(void) {
// time we can linger here is what it takes for the other buffer to fill
// (<8us) and that includes irq chaining
if (len >= 64 && len <= ETH_PKT_SIZE)
mip_qwrite(s_rxbuf[s_rxno], len, s_ifp);
mg_tcpip_qwrite(s_rxbuf[s_rxno], len, s_ifp);
s_rxno = rxno;
}
static size_t mip_driver_rp2040_rmii_rx(void *buf, size_t buflen, struct mip_if *ifp) {
size_t len = mip_qread(buf, ifp);
static size_t mg_tcpip_driver_rp2040_rmii_rx(void *buf, size_t buflen, struct mg_tcpip_if *ifp) {
size_t len = mg_tcpip_qread(buf, ifp);
if (len == 0) return 0;
len -= 4; // exclude CRC from frame length
uint32_t crc = crc_calc(buf, len); // calculate CRC and compare
@@ -350,17 +350,17 @@ static size_t mip_driver_rp2040_rmii_rx(void *buf, size_t buflen, struct mip_if
return len;
}
static bool mip_driver_rp2040_rmii_up(struct mip_if *ifp) {
struct mip_driver_rp2040_rmii_data *d =
(struct mip_driver_rp2040_rmii_data *) ifp->driver_data;
static bool mg_tcpip_driver_rp2040_rmii_up(struct mg_tcpip_if *ifp) {
struct mg_tcpip_driver_rp2040_rmii_data *d =
(struct mg_tcpip_driver_rp2040_rmii_data *) ifp->driver_data;
uint32_t bsr =
eth_read_phy(d->phy_addr, 1, d->mdio); // Basic Status Register
return (bsr & (1 << 2)) ? 1 : 0; // check Link Status flag
}
struct mip_driver mip_driver_rp2040_rmii = {
mip_driver_rp2040_rmii_init,
mip_driver_rp2040_rmii_tx,
mip_driver_rp2040_rmii_rx,
mip_driver_rp2040_rmii_up,
struct mg_tcpip_driver mg_tcpip_driver_rp2040_rmii = {
mg_tcpip_driver_rp2040_rmii_init,
mg_tcpip_driver_rp2040_rmii_tx,
mg_tcpip_driver_rp2040_rmii_rx,
mg_tcpip_driver_rp2040_rmii_up,
};
@@ -1,10 +1,10 @@
#pragma once
struct mip_driver_rp2040_rmii_data {
struct mg_tcpip_driver_rp2040_rmii_data {
uint8_t rx0; // RX0, RX1, CRS_DV; consecutive GPIO pins
uint8_t tx0; // TX0, TX1, TX-EN; consecutive GPIO pins
uint8_t mdio; // MDIO, MDC; consecutive GPIO pins
uint8_t phy_addr; // PHY address
};
extern struct mip_driver mip_driver_rp2040_rmii;
extern struct mg_tcpip_driver mg_tcpip_driver_rp2040_rmii;
+4 -4
View File
@@ -30,7 +30,7 @@ int main(void) {
MG_INFO(("Init MIP"));
// Initialise Mongoose network stack and specific driver
// Set consecutive GPIOs for RMII (tx and rx) and SMI function groups
struct mip_driver_rp2040_rmii_data driver_data = {
struct mg_tcpip_driver_rp2040_rmii_data driver_data = {
// see driver_rp2040_rmii.h
.rx0 = 6, // 6, 7, 8 : RX0, RX1, CRS_DV
.tx0 = 10, // 10, 11, 12 : TX0, TX1, TX-EN
@@ -39,13 +39,13 @@ int main(void) {
};
// Specify MAC address, either set use_dhcp or enter a static config.
// For static configuration, specify IP/mask/GW in network byte order
struct mip_if mif = {
struct mg_tcpip_if mif = {
.mac = {2, 0, 1, 2, 3, 5},
.ip = 0,
.driver = &mip_driver_rp2040_rmii,
.driver = &mg_tcpip_driver_rp2040_rmii,
.driver_data = &driver_data,
};
mip_init(&mgr, &mif);
mg_tcpip_init(&mgr, &mif);
mg_http_listen(&mgr, "http://0.0.0.0", fn, NULL); // HTTP listener
MG_INFO(("Init done, starting main loop"));
@@ -24,7 +24,7 @@ pico_enable_stdio_usb(firmware 0) # Route stdio
pico_enable_stdio_uart(firmware 1) # to the UART
# Mongoose build flags
add_definitions(-DMG_ENABLE_MIP=1)
add_definitions(-DMG_ENABLE_TCPIP=1)
add_definitions(-DMG_ENABLE_PACKED_FS=1)
add_definitions(-DMG_ENABLE_FILE=0)
add_definitions(-DDISABLE_ROUTING=1)
+7 -7
View File
@@ -5,7 +5,7 @@
#include "pico/stdlib.h"
#include "tusb.h"
static struct mip_if *s_ifp;
static struct mg_tcpip_if *s_ifp;
const uint8_t tud_network_mac_address[6] = {2, 2, 0x84, 0x6A, 0x96, 0};
@@ -15,7 +15,7 @@ static void blink_cb(void *arg) { // Blink periodically
}
bool tud_network_recv_cb(const uint8_t *buf, uint16_t len) {
mip_qwrite((void *) buf, len, s_ifp);
mg_tcpip_qwrite((void *) buf, len, s_ifp);
// MG_INFO(("RECV %hu", len));
// mg_hexdump(buf, len);
tud_network_recv_renew();
@@ -30,7 +30,7 @@ uint16_t tud_network_xmit_cb(uint8_t *dst, void *ref, uint16_t arg) {
return arg;
}
static size_t usb_tx(const void *buf, size_t len, struct mip_if *ifp) {
static size_t usb_tx(const void *buf, size_t len, struct mg_tcpip_if *ifp) {
if (!tud_ready()) return 0;
while (!tud_network_can_xmit(len)) tud_task();
tud_network_xmit((void *) buf, len);
@@ -38,7 +38,7 @@ static size_t usb_tx(const void *buf, size_t len, struct mip_if *ifp) {
return len;
}
static bool usb_up(struct mip_if *ifp) {
static bool usb_up(struct mg_tcpip_if *ifp) {
(void) ifp;
return tud_inited() && tud_ready() && tud_connected();
}
@@ -56,15 +56,15 @@ int main(void) {
mg_mgr_init(&mgr); // and attach it to the MIP interface
mg_timer_add(&mgr, 500, MG_TIMER_REPEAT, blink_cb, &mgr);
struct mip_driver driver = {.tx = usb_tx, .rx = mip_driver_rx, .up = usb_up};
struct mip_if mif = {.mac = {2, 0, 1, 2, 3, 0x77},
struct mg_tcpip_driver driver = {.tx = usb_tx, .rx = mg_tcpip_driver_rx, .up = usb_up};
struct mg_tcpip_if mif = {.mac = {2, 0, 1, 2, 3, 0x77},
.ip = mg_htonl(MG_U32(192, 168, 3, 1)),
.mask = mg_htonl(MG_U32(255, 255, 255, 0)),
.enable_dhcp_server = true,
.driver = &driver,
.queue.len = 4096};
s_ifp = &mif;
mip_init(&mgr, &mif);
mg_tcpip_init(&mgr, &mif);
tusb_init();
MG_INFO(("Initialising application..."));
+1 -1
View File
@@ -21,7 +21,7 @@ pico_enable_stdio_usb(firmware 0)
pico_enable_stdio_uart(firmware 1)
# Mongoose build flags
add_definitions(-DMG_ENABLE_MIP=1)
add_definitions(-DMG_ENABLE_TCPIP=1)
add_definitions(-DMG_ENABLE_PACKED_FS=1)
add_definitions(-DMG_ENABLE_FILE=0)
+5 -5
View File
@@ -21,7 +21,7 @@ static uint8_t spi_txn(void *spi, uint8_t byte) {
static void timer_cb(void *arg) {
gpio_put(PICO_DEFAULT_LED_PIN, !gpio_get_out_level(PICO_DEFAULT_LED_PIN));
bool up = ((struct mip_if *) arg)->state == MIP_STATE_READY;
bool up = ((struct mg_tcpip_if *) arg)->state == MIP_STATE_READY;
MG_INFO(("Ethernet: %s", up ? "up" : "down")); // Show network status
}
@@ -43,14 +43,14 @@ int main(void) {
gpio_put(SPI_CS, 1); // And drive CS high (inactive)
// Init Mongoose
struct mip_spi spi = {NULL, spi_begin, spi_end, spi_txn};
struct mip_if mif = {.mac = {2, 0, 1, 2, 3, 5},
.driver = &mip_driver_w5500,
struct mg_tcpip_spi spi = {NULL, spi_begin, spi_end, spi_txn};
struct mg_tcpip_if mif = {.mac = {2, 0, 1, 2, 3, 5},
.driver = &mg_tcpip_driver_w5500,
.driver_data = &spi};
struct mg_mgr mgr; // Declare event manager
mg_mgr_init(&mgr); // Init event manager
mg_log_set(MG_LL_DEBUG); // Set DEBUG log level
mip_init(&mgr, &mif); // Init TCP/IP stack
mg_tcpip_init(&mgr, &mif); // Init TCP/IP stack
mg_timer_add(&mgr, BLINK_PERIOD_MS, MG_TIMER_REPEAT, timer_cb, &mif);
MG_INFO(("Waiting until network is up..."));