Skip to content

Commit b907094

Browse files
committed
Fixes for tm4c
1 parent cac4b3e commit b907094

File tree

3 files changed

+36
-28
lines changed

3 files changed

+36
-28
lines changed

mongoose.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
45124521
static 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-
2522025225
static 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

2523725242
static 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;

src/drivers/tm4c.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,11 @@ enum {
4040
EPHYSTS = 16
4141
}; // PHY constants
4242

43-
static inline void tm4cspin(volatile uint32_t count) {
44-
while (count--) (void) 0;
45-
}
46-
4743
static uint32_t emac_read_phy(uint8_t addr, uint8_t reg) {
4844
EMAC->EMACMIIADDR &= (0xf << 2);
4945
EMAC->EMACMIIADDR |= ((uint32_t) addr << 11) | ((uint32_t) reg << 6);
5046
EMAC->EMACMIIADDR |= MG_BIT(0);
51-
while (EMAC->EMACMIIADDR & MG_BIT(0)) tm4cspin(1);
47+
while (EMAC->EMACMIIADDR & MG_BIT(0)) (void) 0;
5248
return EMAC->EMACMIIDATA;
5349
}
5450

@@ -58,7 +54,7 @@ static void emac_write_phy(uint8_t addr, uint8_t reg, uint32_t val) {
5854
EMAC->EMACMIIADDR |=
5955
((uint32_t) addr << 11) | ((uint32_t) reg << 6) | MG_BIT(1);
6056
EMAC->EMACMIIADDR |= MG_BIT(0);
61-
while (EMAC->EMACMIIADDR & MG_BIT(0)) tm4cspin(1);
57+
while (EMAC->EMACMIIADDR & MG_BIT(0)) (void) 0;
6258
}
6359

6460
static uint32_t get_sysclk(void) {
@@ -150,9 +146,8 @@ static bool mg_tcpip_driver_tm4c_init(struct mg_tcpip_if *ifp) {
150146
(uint32_t) (uintptr_t) s_txdesc[(i + 1) % ETH_DESC_CNT]; // Chain
151147
}
152148

153-
EMAC->EMACDMABUSMOD |= MG_BIT(0); // Software reset
154-
while ((EMAC->EMACDMABUSMOD & MG_BIT(0)) != 0)
155-
tm4cspin(1); // Wait until done
149+
EMAC->EMACDMABUSMOD |= MG_BIT(0); // Software reset
150+
while ((EMAC->EMACDMABUSMOD & MG_BIT(0)) != 0) (void) 0; // Wait until done
156151

157152
// Set MDC clock divider. If user told us the value, use it. Otherwise, guess
158153
int cr = (d == NULL || d->mdc_cr < 0) ? guess_mdc_cr() : d->mdc_cr;

src/net_builtin.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,24 @@ void mg_tcpip_arp_request(struct mg_tcpip_if *ifp, uint32_t ip, uint8_t *mac) {
303303
ether_output(ifp, PDIFF(eth, arp + 1));
304304
}
305305

306+
static void mg_tcpip_set_local_addr(struct mg_connection *c) {
307+
#if MG_ENABLE_IPV6
308+
if (c->loc.is_ip6) {
309+
c->loc.ip6[0] = c->mgr->ifp->ip6[0], c->loc.ip6[1] = c->mgr->ifp->ip6[1];
310+
} else
311+
#endif
312+
c->loc.ip4 = c->mgr->ifp->ip;
313+
}
314+
306315
static void onstatechange(struct mg_tcpip_if *ifp) {
307316
if (ifp->state == MG_TCPIP_STATE_READY) {
317+
struct mg_connection *c;
308318
MG_INFO(("READY, IP: %M", mg_print_ip4, &ifp->ip));
309319
MG_INFO((" GW: %M", mg_print_ip4, &ifp->gw));
310320
MG_INFO((" MAC: %M", mg_print_mac, &ifp->mac));
321+
for (c = ifp->mgr->conns; c != NULL; c = c->next) {
322+
mg_tcpip_set_local_addr(c);
323+
}
311324
} else if (ifp->state == MG_TCPIP_STATE_IP) {
312325
mg_tcpip_arp_request(ifp, ifp->gw, NULL); // unsolicited GW ARP request
313326
} else if (ifp->state == MG_TCPIP_STATE_UP) {
@@ -1911,12 +1924,8 @@ bool mg_open_listener(struct mg_connection *c, const char *url) {
19111924
if (!mg_aton(mg_url_host(url), &c->loc)) {
19121925
MG_ERROR(("invalid listening URL: %s", url));
19131926
return false;
1914-
#if MG_ENABLE_IPV6
1915-
} else if (c->loc.is_ip6) {
1916-
c->loc.ip6[0] = c->mgr->ifp->ip6[0], c->loc.ip6[1] = c->mgr->ifp->ip6[1];
1917-
#endif
19181927
} else {
1919-
c->loc.ip4 = c->mgr->ifp->ip;
1928+
mg_tcpip_set_local_addr(c);
19201929
}
19211930
return true;
19221931
}

0 commit comments

Comments
 (0)