@@ -4509,11 +4509,24 @@ void mg_tcpip_arp_request(struct mg_tcpip_if *ifp, uint32_t ip, uint8_t *mac) {
45094509 ether_output(ifp, PDIFF(eth, arp + 1));
45104510}
45114511
4512+ static void mg_tcpip_set_local_addr(struct mg_connection *c) {
4513+ #if MG_ENABLE_IPV6
4514+ if (c->loc.is_ip6) {
4515+ c->loc.ip6[0] = c->mgr->ifp->ip6[0], c->loc.ip6[1] = c->mgr->ifp->ip6[1];
4516+ } else
4517+ #endif
4518+ c->loc.ip4 = c->mgr->ifp->ip;
4519+ }
4520+
45124521static void onstatechange(struct mg_tcpip_if *ifp) {
45134522 if (ifp->state == MG_TCPIP_STATE_READY) {
4523+ struct mg_connection *c;
45144524 MG_INFO(("READY, IP: %M", mg_print_ip4, &ifp->ip));
45154525 MG_INFO((" GW: %M", mg_print_ip4, &ifp->gw));
45164526 MG_INFO((" MAC: %M", mg_print_mac, &ifp->mac));
4527+ for (c = ifp->mgr->conns; c != NULL; c = c->next) {
4528+ mg_tcpip_set_local_addr(c);
4529+ }
45174530 } else if (ifp->state == MG_TCPIP_STATE_IP) {
45184531 mg_tcpip_arp_request(ifp, ifp->gw, NULL); // unsolicited GW ARP request
45194532 } else if (ifp->state == MG_TCPIP_STATE_UP) {
@@ -6117,12 +6130,8 @@ bool mg_open_listener(struct mg_connection *c, const char *url) {
61176130 if (!mg_aton(mg_url_host(url), &c->loc)) {
61186131 MG_ERROR(("invalid listening URL: %s", url));
61196132 return false;
6120- #if MG_ENABLE_IPV6
6121- } else if (c->loc.is_ip6) {
6122- c->loc.ip6[0] = c->mgr->ifp->ip6[0], c->loc.ip6[1] = c->mgr->ifp->ip6[1];
6123- #endif
61246133 } else {
6125- c->loc.ip4 = c->mgr->ifp->ip ;
6134+ mg_tcpip_set_local_addr(c) ;
61266135 }
61276136 return true;
61286137}
@@ -25213,15 +25222,11 @@ enum {
2521325222 EPHYSTS = 16
2521425223}; // PHY constants
2521525224
25216- static inline void tm4cspin(volatile uint32_t count) {
25217- while (count--) (void) 0;
25218- }
25219-
2522025225static uint32_t emac_read_phy(uint8_t addr, uint8_t reg) {
2522125226 EMAC->EMACMIIADDR &= (0xf << 2);
2522225227 EMAC->EMACMIIADDR |= ((uint32_t) addr << 11) | ((uint32_t) reg << 6);
2522325228 EMAC->EMACMIIADDR |= MG_BIT(0);
25224- while (EMAC->EMACMIIADDR & MG_BIT(0)) tm4cspin(1) ;
25229+ while (EMAC->EMACMIIADDR & MG_BIT(0)) (void) 0 ;
2522525230 return EMAC->EMACMIIDATA;
2522625231}
2522725232
@@ -25231,7 +25236,7 @@ static void emac_write_phy(uint8_t addr, uint8_t reg, uint32_t val) {
2523125236 EMAC->EMACMIIADDR |=
2523225237 ((uint32_t) addr << 11) | ((uint32_t) reg << 6) | MG_BIT(1);
2523325238 EMAC->EMACMIIADDR |= MG_BIT(0);
25234- while (EMAC->EMACMIIADDR & MG_BIT(0)) tm4cspin(1) ;
25239+ while (EMAC->EMACMIIADDR & MG_BIT(0)) (void) 0 ;
2523525240}
2523625241
2523725242static uint32_t get_sysclk(void) {
@@ -25323,9 +25328,8 @@ static bool mg_tcpip_driver_tm4c_init(struct mg_tcpip_if *ifp) {
2532325328 (uint32_t) (uintptr_t) s_txdesc[(i + 1) % ETH_DESC_CNT]; // Chain
2532425329 }
2532525330
25326- EMAC->EMACDMABUSMOD |= MG_BIT(0); // Software reset
25327- while ((EMAC->EMACDMABUSMOD & MG_BIT(0)) != 0)
25328- tm4cspin(1); // Wait until done
25331+ EMAC->EMACDMABUSMOD |= MG_BIT(0); // Software reset
25332+ while ((EMAC->EMACDMABUSMOD & MG_BIT(0)) != 0) (void) 0; // Wait until done
2532925333
2533025334 // Set MDC clock divider. If user told us the value, use it. Otherwise, guess
2533125335 int cr = (d == NULL || d->mdc_cr < 0) ? guess_mdc_cr() : d->mdc_cr;
0 commit comments