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"));