Skip to content

Commit a5e69cd

Browse files
committed
update(demo): wait done in linkoutput_fn for rndis & ecm, retransmission in lwip costs too much time
Signed-off-by: sakumisu <[email protected]>
1 parent 6516a47 commit a5e69cd

File tree

2 files changed

+78
-40
lines changed

2 files changed

+78
-40
lines changed

demo/cdc_ecm_template.c

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
#endif
1818

1919
/*!< endpoint address */
20-
#define CDC_IN_EP 0x81
21-
#define CDC_OUT_EP 0x02
22-
#define CDC_INT_EP 0x83
20+
#define CDC_IN_EP 0x81
21+
#define CDC_OUT_EP 0x02
22+
#define CDC_INT_EP 0x83
2323

2424
#define USBD_VID 0xFFFF
2525
#define USBD_PID 0xFFFF
2626
#define USBD_MAX_POWER 100
2727
#define USBD_LANGID_STRING 1033
2828

2929
/*!< config descriptor size */
30-
#define USB_CONFIG_SIZE (9 + CDC_ECM_DESCRIPTOR_LEN)
30+
#define USB_CONFIG_SIZE (9 + CDC_ECM_DESCRIPTOR_LEN)
3131

3232
#ifdef CONFIG_USB_HS
3333
#define CDC_MAX_MPS 512
@@ -38,7 +38,7 @@
3838
#define CDC_ECM_ETH_STATISTICS_BITMAP 0x00000000
3939

4040
/* str idx = 4 is for mac address: aa:bb:cc:dd:ee:ff*/
41-
#define CDC_ECM_MAC_STRING_INDEX 4
41+
#define CDC_ECM_MAC_STRING_INDEX 4
4242

4343
#ifdef CONFIG_USBDEV_ADVANCE_DESC
4444
static const uint8_t device_descriptor[] = {
@@ -228,7 +228,7 @@ const ip_addr_t ipaddr = IPADDR4_INIT_BYTES(IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADD
228228
const ip_addr_t netmask = IPADDR4_INIT_BYTES(NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
229229
const ip_addr_t gateway = IPADDR4_INIT_BYTES(GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
230230

231-
#define NUM_DHCP_ENTRY 3
231+
#define NUM_DHCP_ENTRY 3
232232

233233
static dhcp_entry_t entries[NUM_DHCP_ENTRY] = {
234234
/* mac ip address subnet mask lease time */
@@ -248,27 +248,41 @@ static dhcp_config_t dhcp_config = {
248248

249249
static bool dns_query_proc(const char *name, ip_addr_t *addr)
250250
{
251-
if (strcmp(name, "rndis.cherry") == 0 || strcmp(name, "www.rndis.cherry") == 0) {
251+
if (strcmp(name, "cdc_ecm.cherry") == 0 || strcmp(name, "www.cdc_ecm.cherry") == 0) {
252252
addr->addr = *(uint32_t *)ipaddr;
253253
return true;
254254
}
255255
return false;
256256
}
257257

258+
volatile bool cdc_ecm_tx_done = false;
259+
260+
void usbd_cdc_ecm_data_send_done(uint32_t len)
261+
{
262+
cdc_ecm_tx_done = true; // suggest you to use semaphore in os
263+
}
264+
265+
void usbd_cdc_ecm_data_recv_done(uint32_t len)
266+
{
267+
}
268+
258269
static struct netif cdc_ecm_netif; //network interface
259270

260271
/* Network interface name */
261272
#define IFNAME0 'E'
262273
#define IFNAME1 'X'
263274

264-
static err_t linkoutput_fn(struct netif *netif, struct pbuf *p)
275+
err_t linkoutput_fn(struct netif *netif, struct pbuf *p)
265276
{
266-
static int ret;
277+
int ret;
267278

279+
cdc_ecm_tx_done = false;
268280
ret = usbd_cdc_ecm_eth_tx(p);
269-
if (ret == 0)
281+
if (ret == 0) {
282+
while (!cdc_ecm_tx_done) {
283+
}
270284
return ERR_OK;
271-
else
285+
} else
272286
return ERR_BUF;
273287
}
274288

@@ -288,8 +302,8 @@ err_t cdc_ecm_if_init(struct netif *netif)
288302

289303
err_t cdc_ecm_if_input(struct netif *netif)
290304
{
291-
static err_t err;
292-
static struct pbuf *p;
305+
err_t err;
306+
struct pbuf *p;
293307

294308
p = usbd_cdc_ecm_eth_rx();
295309
if (p != NULL) {
@@ -318,13 +332,11 @@ void cdc_ecm_lwip_init(void)
318332
while (!netif_is_up(netif)) {
319333
}
320334

321-
while (dhserv_init(&dhcp_config)) {}
322-
323-
while (dnserv_init(IP_ADDR_ANY, 53, dns_query_proc)) {}
324-
}
335+
while (dhserv_init(&dhcp_config)) {
336+
}
325337

326-
void usbd_cdc_ecm_data_recv_done(uint32_t len)
327-
{
338+
while (dnserv_init(IP_ADDR_ANY, 53, dns_query_proc)) {
339+
}
328340
}
329341

330342
void cdc_ecm_input_poll(void)

demo/cdc_rndis_template.c

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ const ip_addr_t ipaddr = IPADDR4_INIT_BYTES(IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADD
200200
const ip_addr_t netmask = IPADDR4_INIT_BYTES(NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
201201
const ip_addr_t gateway = IPADDR4_INIT_BYTES(GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
202202

203-
#define NUM_DHCP_ENTRY 3
203+
#define NUM_DHCP_ENTRY 3
204204

205205
static dhcp_entry_t entries[NUM_DHCP_ENTRY] = {
206206
/* mac ip address subnet mask lease time */
@@ -227,6 +227,20 @@ static bool dns_query_proc(const char *name, ip_addr_t *addr)
227227
return false;
228228
}
229229

230+
volatile bool rndis_tx_done = false;
231+
232+
void usbd_rndis_data_send_done(uint32_t len)
233+
{
234+
rndis_tx_done = true; // suggest you to use semaphore in os
235+
}
236+
237+
void usbd_rndis_data_recv_done(uint32_t len)
238+
{
239+
#ifdef RT_USING_LWIP
240+
eth_device_ready(&rndis_dev);
241+
#endif
242+
}
243+
230244
#ifdef RT_USING_LWIP
231245
#include <rtthread.h>
232246
#include <rtdevice.h>
@@ -240,13 +254,11 @@ static rt_err_t rt_usbd_rndis_control(rt_device_t dev, int cmd, void *args)
240254
case NIOCTL_GADDR:
241255

242256
/* get mac address */
243-
if (args)
244-
{
257+
if (args) {
245258
uint8_t *mac_dev = (uint8_t *)args;
246259
rt_memcpy(mac_dev, mac, 6);
247260
mac_dev[5] = ~mac_dev[5]; /* device mac can't same as host. */
248-
}
249-
else
261+
} else
250262
return -RT_ERROR;
251263

252264
break;
@@ -265,12 +277,16 @@ struct pbuf *rt_usbd_rndis_eth_rx(rt_device_t dev)
265277

266278
rt_err_t rt_usbd_rndis_eth_tx(rt_device_t dev, struct pbuf *p)
267279
{
268-
return usbd_rndis_eth_tx(p);
269-
}
280+
int ret;
270281

271-
void usbd_rndis_data_recv_done(uint32_t len)
272-
{
273-
eth_device_ready(&rndis_dev);
282+
rndis_tx_done = false;
283+
ret = usbd_rndis_eth_tx(p);
284+
if (ret == 0) {
285+
while (!rndis_tx_done) {
286+
}
287+
return RT_EOK;
288+
} else
289+
return -RT_ERROR;
274290
}
275291

276292
void rndis_lwip_init(void)
@@ -282,6 +298,15 @@ void rndis_lwip_init(void)
282298
eth_device_init(&rndis_dev, "u0");
283299

284300
eth_device_linkchange(&rndis_dev, RT_FALSE);
301+
302+
while (!netif_is_up(rndis_dev.netif)) {
303+
}
304+
305+
while (dhserv_init(&dhcp_config)) {
306+
}
307+
308+
while (dnserv_init(IP_ADDR_ANY, 53, dns_query_proc)) {
309+
}
285310
}
286311
#else
287312
#include "netif/etharp.h"
@@ -297,12 +322,15 @@ static struct netif rndis_netif; //network interface
297322

298323
err_t linkoutput_fn(struct netif *netif, struct pbuf *p)
299324
{
300-
static int ret;
325+
int ret;
301326

327+
rndis_tx_done = false;
302328
ret = usbd_rndis_eth_tx(p);
303-
if (ret == 0)
329+
if (ret == 0) {
330+
while (!rndis_tx_done) {
331+
}
304332
return ERR_OK;
305-
else
333+
} else
306334
return ERR_BUF;
307335
}
308336

@@ -322,8 +350,8 @@ err_t rndisif_init(struct netif *netif)
322350

323351
err_t rndisif_input(struct netif *netif)
324352
{
325-
static err_t err;
326-
static struct pbuf *p;
353+
err_t err;
354+
struct pbuf *p;
327355

328356
p = usbd_rndis_eth_rx();
329357
if (p != NULL) {
@@ -352,13 +380,11 @@ void rndis_lwip_init(void)
352380
while (!netif_is_up(netif)) {
353381
}
354382

355-
while (dhserv_init(&dhcp_config)) {}
356-
357-
while (dnserv_init(IP_ADDR_ANY, 53, dns_query_proc)) {}
358-
}
383+
while (dhserv_init(&dhcp_config)) {
384+
}
359385

360-
void usbd_rndis_data_recv_done(uint32_t len)
361-
{
386+
while (dnserv_init(IP_ADDR_ANY, 53, dns_query_proc)) {
387+
}
362388
}
363389

364390
void rndis_input_poll(void)

0 commit comments

Comments
 (0)