diff --git a/mongoose.c b/mongoose.c index a87b21f3..fcf0a1b9 100644 --- a/mongoose.c +++ b/mongoose.c @@ -4054,8 +4054,8 @@ void mg_mgr_init(struct mg_mgr *mgr) { // Ignore SIGPIPE signal, so if client cancels the request, it // won't kill the whole process. signal(SIGPIPE, SIG_IGN); -#elif MG_ENABLE_TCPIP && MG_ENABLE_TCPIP_DRIVER_INIT - mg_tcpip_auto_init(mgr); +#elif MG_ENABLE_TCPIP_DRIVER_INIT && defined(MG_TCPIP_DRIVER_INIT) + MG_TCPIP_DRIVER_INIT(mgr); #endif mgr->pipe = MG_INVALID_SOCKET; mgr->dnstimeout = 3000; @@ -4976,11 +4976,11 @@ static void mg_tcpip_poll(struct mg_tcpip_if *ifp, uint64_t now) { ======= const char *names[] = {"down", "up", "req", "ready"}; <<<<<<< HEAD +<<<<<<< HEAD >>>>>>> 60cce282 (Add driver init to mg_mgr_init()) - MG_INFO(("Status: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u", ======= - MG_INFO(("Ethernet: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u", ->>>>>>> a0834330 (Add driver init to mg_mgr_init()) +>>>>>>> f74ae90c (update version) + MG_INFO(("Status: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u", names[ifp->state], mg_print_ip4, &ifp->ip, ifp->nrecv, ifp->nsent, ifp->ndrop, ifp->nerr)); } diff --git a/mongoose.h b/mongoose.h index 3d286127..d10e7572 100644 --- a/mongoose.h +++ b/mongoose.h @@ -876,19 +876,21 @@ struct timeval { #define MG_ENABLE_TCPIP_DRIVER_INIT 1 // enabled built-in driver for #endif // Mongoose built-in network stack -#ifndef MG_TCPIP_IP // e.g. MG_IPV4(192, 168, 0, 223) -#define MG_TCPIP_IP MG_IPV4(0, 0, 0, 0) // or leave as 0 for DHCP +#ifndef MG_TCPIP_IP // e.g. MG_IPV4(192, 168, 0, 223) +#define MG_TCPIP_IP MG_IPV4(0, 0, 0, 0) // Default is 0.0.0.0 (DHCP) #endif #ifndef MG_TCPIP_MASK -#define MG_TCPIP_MASK MG_IPV4(255, 255, 255, 0) +#define MG_TCPIP_MASK MG_IPV4(0, 0, 0, 0) // Default is 0.0.0.0 (DHCP) #endif #ifndef MG_TCPIP_GW -#define MG_TCPIP_GW MG_IPV4(0, 0, 0, 1) +#define MG_TCPIP_GW MG_IPV4(0, 0, 0, 0) // Default is 0.0.0.0 (DHCP) #endif -#define MG_MAC_ADDRESS_RANDOM { 0, 0, 0, 0, 0, 0 } +#ifndef MG_SET_MAC_ADDRESS +#define MG_SET_MAC_ADDRESS(mac) +#endif #ifndef MG_ENABLE_TCPIP_PRINT_DEBUG_STATS #define MG_ENABLE_TCPIP_PRINT_DEBUG_STATS 0 @@ -2885,8 +2887,6 @@ struct mg_profitem { #endif -#if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_IMXRT) && MG_ENABLE_DRIVER_IMXRT - #if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_IMXRT) && MG_ENABLE_DRIVER_IMXRT struct mg_tcpip_driver_imxrt_data { @@ -2906,10 +2906,6 @@ struct mg_tcpip_driver_imxrt_data { uint8_t phy_addr; // PHY address }; -#ifndef MG_MAC_ADDRESS -#define MG_MAC_ADDRESS MG_MAC_ADDRESS_RANDOM -#endif - #ifndef MG_TCPIP_PHY_ADDR #define MG_TCPIP_PHY_ADDR 2 #endif @@ -2918,14 +2914,55 @@ struct mg_tcpip_driver_imxrt_data { #define MG_DRIVER_MDC_CR 24 #endif -#define MG_TCPIP_DRIVER_DATA \ - static struct mg_tcpip_driver_imxrt_data driver_data = { \ - .mdc_cr = MG_DRIVER_MDC_CR, \ - .phy_addr = MG_TCPIP_PHY_ADDR, \ - }; +#define MG_TCPIP_DRIVER_INIT(mgr) \ + do { \ + static struct mg_tcpip_driver_imxrt_data driver_data_; \ + static struct mg_tcpip_if mif_; \ + driver_data_.mdc_cr = MG_DRIVER_MDC_CR; \ + driver_data_.phy_addr = MG_TCPIP_PHY_ADDR; \ + mif_.ip = MG_TCPIP_IP; \ + mif_.mask = MG_TCPIP_MASK; \ + mif_.gw = MG_TCPIP_GW; \ + mif_.driver = &mg_tcpip_driver_imxrt; \ + mif_.driver_data = &driver_data_; \ + MG_SET_MAC_ADDRESS(mif_.mac); \ + mg_tcpip_init(mgr, &mif_); \ + MG_INFO(("Driver: imxrt, MAC: %M", mg_print_mac, mif_.mac)); \ + } while (0) -#define MG_TCPIP_DRIVER_CODE &mg_tcpip_driver_imxrt -#define MG_TCPIP_DRIVER_NAME "imxrt" +#endif + + + + +struct mg_phy { + uint16_t (*read_reg)(uint8_t addr, uint8_t reg); + void (*write_reg)(uint8_t addr, uint8_t reg, uint16_t value); +}; + +// PHY configuration settings, bitmask +enum { + MG_PHY_LEDS_ACTIVE_HIGH = + (1 << 0), // Set if PHY LEDs are connected to ground + MG_PHY_CLOCKS_MAC = + (1 << 1) // Set when PHY clocks MAC. Otherwise, MAC clocks PHY +}; + +enum { MG_PHY_SPEED_10M, MG_PHY_SPEED_100M, MG_PHY_SPEED_1000M }; + +void mg_phy_init(struct mg_phy *, uint8_t addr, uint8_t config); +bool mg_phy_up(struct mg_phy *, uint8_t addr, bool *full_duplex, + uint8_t *speed); + + +#if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_RA) && MG_ENABLE_DRIVER_RA + +struct mg_tcpip_driver_ra_data { + // MDC clock "divider". MDC clock is software generated, + uint32_t clock; // core clock frequency in Hz + uint16_t irqno; // IRQn, R_ICU->IELSR[irqno] + uint8_t phy_addr; // PHY address +}; #endif @@ -2936,22 +2973,10 @@ struct mg_tcpip_driver_same54_data { int mdc_cr; }; -#ifndef MG_MAC_ADDRESS -#define MG_MAC_ADDRESS MG_MAC_ADDRESS_RANDOM -#endif - #ifndef MG_DRIVER_MDC_CR #define MG_DRIVER_MDC_CR 5 #endif -#define MG_TCPIP_DRIVER_DATA \ - static struct mg_tcpip_driver_same54_data driver_data = { \ - .mdc_cr = MG_DRIVER_MDC_CR, \ - }; - -#define MG_TCPIP_DRIVER_CODE &mg_tcpip_driver_same54 -#define MG_TCPIP_DRIVER_NAME "same54" - #endif @@ -2975,10 +3000,6 @@ struct mg_tcpip_driver_stm32f_data { uint8_t phy_addr; // PHY address }; -#ifndef MG_MAC_ADDRESS -#define MG_MAC_ADDRESS MG_MAC_ADDRESS_RANDOM -#endif - #ifndef MG_TCPIP_PHY_ADDR #define MG_TCPIP_PHY_ADDR 0 #endif @@ -2987,14 +3008,21 @@ struct mg_tcpip_driver_stm32f_data { #define MG_DRIVER_MDC_CR 4 #endif -#define MG_TCPIP_DRIVER_DATA \ - static struct mg_tcpip_driver_stm32f_data driver_data = { \ - .mdc_cr = MG_DRIVER_MDC_CR, \ - .phy_addr = MG_TCPIP_PHY_ADDR, \ - }; - -#define MG_TCPIP_DRIVER_CODE &mg_tcpip_driver_stm32f -#define MG_TCPIP_DRIVER_NAME "stm32f" +#define MG_TCPIP_DRIVER_INIT(mgr) \ + do { \ + static struct mg_tcpip_driver_stm32f_data driver_data_; \ + static struct mg_tcpip_if mif_; \ + driver_data_.mdc_cr = MG_DRIVER_MDC_CR; \ + driver_data_.phy_addr = MG_TCPIP_PHY_ADDR; \ + mif_.ip = MG_TCPIP_IP; \ + mif_.mask = MG_TCPIP_MASK; \ + mif_.gw = MG_TCPIP_GW; \ + mif_.driver = &mg_tcpip_driver_stm32f; \ + mif_.driver_data = &driver_data_; \ + MG_SET_MAC_ADDRESS(mif_.mac); \ + mg_tcpip_init(mgr, &mif_); \ + MG_INFO(("Driver: stm32f, MAC: %M", mg_print_mac, mif_.mac)); \ + } while (0) #endif @@ -3027,6 +3055,7 @@ struct mg_tcpip_driver_stm32h_data { uint8_t phy_conf; // PHY config }; +<<<<<<< HEAD <<<<<<< HEAD #ifndef MG_TCPIP_PHY_CONF #define MG_TCPIP_PHY_CONF MG_PHY_CLOCKS_MAC @@ -3035,19 +3064,16 @@ struct mg_tcpip_driver_stm32h_data { ======= <<<<<<< HEAD >>>>>>> 60cce282 (Add driver init to mg_mgr_init()) +======= +>>>>>>> f74ae90c (update version) #ifndef MG_TCPIP_PHY_ADDR #define MG_TCPIP_PHY_ADDR 0 -======= -#ifndef MG_MAC_ADDRESS -#define MG_MAC_ADDRESS MG_MAC_ADDRESS_RANDOM ->>>>>>> a0834330 (Add driver init to mg_mgr_init()) #endif #ifndef MG_DRIVER_MDC_CR #define MG_DRIVER_MDC_CR 4 #endif -<<<<<<< HEAD #define MG_TCPIP_DRIVER_INIT(mgr) \ do { \ static struct mg_tcpip_driver_stm32h_data driver_data_; \ @@ -3064,15 +3090,6 @@ struct mg_tcpip_driver_stm32h_data { mg_tcpip_init(mgr, &mif_); \ MG_INFO(("Driver: stm32h, MAC: %M", mg_print_mac, mif_.mac)); \ } while (0) -======= -#define MG_TCPIP_DRIVER_DATA \ - static struct mg_tcpip_driver_stm32h_data driver_data = { \ - .mdc_cr = MG_DRIVER_MDC_CR, \ - }; - -#define MG_TCPIP_DRIVER_CODE &mg_tcpip_driver_stm32h -#define MG_TCPIP_DRIVER_NAME "stm32h" ->>>>>>> a0834330 (Add driver init to mg_mgr_init()) #endif #endif @@ -3093,17 +3110,11 @@ struct mg_tcpip_driver_tm4c_data { int mdc_cr; // Valid values: -1, 0, 1, 2, 3 }; -<<<<<<< HEAD -======= -#ifndef MG_MAC_ADDRESS -#define MG_MAC_ADDRESS MG_MAC_ADDRESS_RANDOM -#endif - ->>>>>>> a0834330 (Add driver init to mg_mgr_init()) #ifndef MG_DRIVER_MDC_CR #define MG_DRIVER_MDC_CR 1 #endif +<<<<<<< HEAD <<<<<<< HEAD #define MG_TCPIP_DRIVER_INIT(mgr) \ do { \ @@ -3134,6 +3145,8 @@ struct mg_tcpip_driver_tm4c_data { >>>>>>> a0834330 (Add driver init to mg_mgr_init()) >>>>>>> 60cce282 (Add driver init to mg_mgr_init()) +======= +>>>>>>> f74ae90c (update version) #endif @@ -3174,7 +3187,6 @@ struct mg_tcpip_driver_tms570_data { #endif -<<<<<<< HEAD #if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_XMC7) && MG_ENABLE_DRIVER_XMC7 @@ -3257,8 +3269,6 @@ struct mg_tcpip_driver_xmc_data { #endif -======= ->>>>>>> a0834330 (Add driver init to mg_mgr_init()) #ifdef __cplusplus } #endif