mirror of
https://github.com/sakumisu/CherryUSB.git
synced 2025-05-09 00:21:44 +08:00
update(demo): wait done in linkoutput_fn for rndis & ecm, retransmission in lwip costs too much time
Signed-off-by: sakumisu <1203593632@qq.com>
This commit is contained in:
parent
6516a470c8
commit
a5e69cd8b5
@ -17,9 +17,9 @@
|
||||
#endif
|
||||
|
||||
/*!< endpoint address */
|
||||
#define CDC_IN_EP 0x81
|
||||
#define CDC_OUT_EP 0x02
|
||||
#define CDC_INT_EP 0x83
|
||||
#define CDC_IN_EP 0x81
|
||||
#define CDC_OUT_EP 0x02
|
||||
#define CDC_INT_EP 0x83
|
||||
|
||||
#define USBD_VID 0xFFFF
|
||||
#define USBD_PID 0xFFFF
|
||||
@ -27,7 +27,7 @@
|
||||
#define USBD_LANGID_STRING 1033
|
||||
|
||||
/*!< config descriptor size */
|
||||
#define USB_CONFIG_SIZE (9 + CDC_ECM_DESCRIPTOR_LEN)
|
||||
#define USB_CONFIG_SIZE (9 + CDC_ECM_DESCRIPTOR_LEN)
|
||||
|
||||
#ifdef CONFIG_USB_HS
|
||||
#define CDC_MAX_MPS 512
|
||||
@ -38,7 +38,7 @@
|
||||
#define CDC_ECM_ETH_STATISTICS_BITMAP 0x00000000
|
||||
|
||||
/* str idx = 4 is for mac address: aa:bb:cc:dd:ee:ff*/
|
||||
#define CDC_ECM_MAC_STRING_INDEX 4
|
||||
#define CDC_ECM_MAC_STRING_INDEX 4
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
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
|
||||
const ip_addr_t netmask = IPADDR4_INIT_BYTES(NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
|
||||
const ip_addr_t gateway = IPADDR4_INIT_BYTES(GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
|
||||
|
||||
#define NUM_DHCP_ENTRY 3
|
||||
#define NUM_DHCP_ENTRY 3
|
||||
|
||||
static dhcp_entry_t entries[NUM_DHCP_ENTRY] = {
|
||||
/* mac ip address subnet mask lease time */
|
||||
@ -248,27 +248,41 @@ static dhcp_config_t dhcp_config = {
|
||||
|
||||
static bool dns_query_proc(const char *name, ip_addr_t *addr)
|
||||
{
|
||||
if (strcmp(name, "rndis.cherry") == 0 || strcmp(name, "www.rndis.cherry") == 0) {
|
||||
if (strcmp(name, "cdc_ecm.cherry") == 0 || strcmp(name, "www.cdc_ecm.cherry") == 0) {
|
||||
addr->addr = *(uint32_t *)ipaddr;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
volatile bool cdc_ecm_tx_done = false;
|
||||
|
||||
void usbd_cdc_ecm_data_send_done(uint32_t len)
|
||||
{
|
||||
cdc_ecm_tx_done = true; // suggest you to use semaphore in os
|
||||
}
|
||||
|
||||
void usbd_cdc_ecm_data_recv_done(uint32_t len)
|
||||
{
|
||||
}
|
||||
|
||||
static struct netif cdc_ecm_netif; //network interface
|
||||
|
||||
/* Network interface name */
|
||||
#define IFNAME0 'E'
|
||||
#define IFNAME1 'X'
|
||||
|
||||
static err_t linkoutput_fn(struct netif *netif, struct pbuf *p)
|
||||
err_t linkoutput_fn(struct netif *netif, struct pbuf *p)
|
||||
{
|
||||
static int ret;
|
||||
int ret;
|
||||
|
||||
cdc_ecm_tx_done = false;
|
||||
ret = usbd_cdc_ecm_eth_tx(p);
|
||||
if (ret == 0)
|
||||
if (ret == 0) {
|
||||
while (!cdc_ecm_tx_done) {
|
||||
}
|
||||
return ERR_OK;
|
||||
else
|
||||
} else
|
||||
return ERR_BUF;
|
||||
}
|
||||
|
||||
@ -288,8 +302,8 @@ err_t cdc_ecm_if_init(struct netif *netif)
|
||||
|
||||
err_t cdc_ecm_if_input(struct netif *netif)
|
||||
{
|
||||
static err_t err;
|
||||
static struct pbuf *p;
|
||||
err_t err;
|
||||
struct pbuf *p;
|
||||
|
||||
p = usbd_cdc_ecm_eth_rx();
|
||||
if (p != NULL) {
|
||||
@ -318,13 +332,11 @@ void cdc_ecm_lwip_init(void)
|
||||
while (!netif_is_up(netif)) {
|
||||
}
|
||||
|
||||
while (dhserv_init(&dhcp_config)) {}
|
||||
while (dhserv_init(&dhcp_config)) {
|
||||
}
|
||||
|
||||
while (dnserv_init(IP_ADDR_ANY, 53, dns_query_proc)) {}
|
||||
}
|
||||
|
||||
void usbd_cdc_ecm_data_recv_done(uint32_t len)
|
||||
{
|
||||
while (dnserv_init(IP_ADDR_ANY, 53, dns_query_proc)) {
|
||||
}
|
||||
}
|
||||
|
||||
void cdc_ecm_input_poll(void)
|
||||
|
@ -200,7 +200,7 @@ const ip_addr_t ipaddr = IPADDR4_INIT_BYTES(IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADD
|
||||
const ip_addr_t netmask = IPADDR4_INIT_BYTES(NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
|
||||
const ip_addr_t gateway = IPADDR4_INIT_BYTES(GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
|
||||
|
||||
#define NUM_DHCP_ENTRY 3
|
||||
#define NUM_DHCP_ENTRY 3
|
||||
|
||||
static dhcp_entry_t entries[NUM_DHCP_ENTRY] = {
|
||||
/* mac ip address subnet mask lease time */
|
||||
@ -227,6 +227,20 @@ static bool dns_query_proc(const char *name, ip_addr_t *addr)
|
||||
return false;
|
||||
}
|
||||
|
||||
volatile bool rndis_tx_done = false;
|
||||
|
||||
void usbd_rndis_data_send_done(uint32_t len)
|
||||
{
|
||||
rndis_tx_done = true; // suggest you to use semaphore in os
|
||||
}
|
||||
|
||||
void usbd_rndis_data_recv_done(uint32_t len)
|
||||
{
|
||||
#ifdef RT_USING_LWIP
|
||||
eth_device_ready(&rndis_dev);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef RT_USING_LWIP
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
@ -240,13 +254,11 @@ static rt_err_t rt_usbd_rndis_control(rt_device_t dev, int cmd, void *args)
|
||||
case NIOCTL_GADDR:
|
||||
|
||||
/* get mac address */
|
||||
if (args)
|
||||
{
|
||||
if (args) {
|
||||
uint8_t *mac_dev = (uint8_t *)args;
|
||||
rt_memcpy(mac_dev, mac, 6);
|
||||
mac_dev[5] = ~mac_dev[5]; /* device mac can't same as host. */
|
||||
}
|
||||
else
|
||||
} else
|
||||
return -RT_ERROR;
|
||||
|
||||
break;
|
||||
@ -265,12 +277,16 @@ struct pbuf *rt_usbd_rndis_eth_rx(rt_device_t dev)
|
||||
|
||||
rt_err_t rt_usbd_rndis_eth_tx(rt_device_t dev, struct pbuf *p)
|
||||
{
|
||||
return usbd_rndis_eth_tx(p);
|
||||
}
|
||||
int ret;
|
||||
|
||||
void usbd_rndis_data_recv_done(uint32_t len)
|
||||
{
|
||||
eth_device_ready(&rndis_dev);
|
||||
rndis_tx_done = false;
|
||||
ret = usbd_rndis_eth_tx(p);
|
||||
if (ret == 0) {
|
||||
while (!rndis_tx_done) {
|
||||
}
|
||||
return RT_EOK;
|
||||
} else
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
void rndis_lwip_init(void)
|
||||
@ -282,6 +298,15 @@ void rndis_lwip_init(void)
|
||||
eth_device_init(&rndis_dev, "u0");
|
||||
|
||||
eth_device_linkchange(&rndis_dev, RT_FALSE);
|
||||
|
||||
while (!netif_is_up(rndis_dev.netif)) {
|
||||
}
|
||||
|
||||
while (dhserv_init(&dhcp_config)) {
|
||||
}
|
||||
|
||||
while (dnserv_init(IP_ADDR_ANY, 53, dns_query_proc)) {
|
||||
}
|
||||
}
|
||||
#else
|
||||
#include "netif/etharp.h"
|
||||
@ -297,12 +322,15 @@ static struct netif rndis_netif; //network interface
|
||||
|
||||
err_t linkoutput_fn(struct netif *netif, struct pbuf *p)
|
||||
{
|
||||
static int ret;
|
||||
int ret;
|
||||
|
||||
rndis_tx_done = false;
|
||||
ret = usbd_rndis_eth_tx(p);
|
||||
if (ret == 0)
|
||||
if (ret == 0) {
|
||||
while (!rndis_tx_done) {
|
||||
}
|
||||
return ERR_OK;
|
||||
else
|
||||
} else
|
||||
return ERR_BUF;
|
||||
}
|
||||
|
||||
@ -322,8 +350,8 @@ err_t rndisif_init(struct netif *netif)
|
||||
|
||||
err_t rndisif_input(struct netif *netif)
|
||||
{
|
||||
static err_t err;
|
||||
static struct pbuf *p;
|
||||
err_t err;
|
||||
struct pbuf *p;
|
||||
|
||||
p = usbd_rndis_eth_rx();
|
||||
if (p != NULL) {
|
||||
@ -352,13 +380,11 @@ void rndis_lwip_init(void)
|
||||
while (!netif_is_up(netif)) {
|
||||
}
|
||||
|
||||
while (dhserv_init(&dhcp_config)) {}
|
||||
while (dhserv_init(&dhcp_config)) {
|
||||
}
|
||||
|
||||
while (dnserv_init(IP_ADDR_ANY, 53, dns_query_proc)) {}
|
||||
}
|
||||
|
||||
void usbd_rndis_data_recv_done(uint32_t len)
|
||||
{
|
||||
while (dnserv_init(IP_ADDR_ANY, 53, dns_query_proc)) {
|
||||
}
|
||||
}
|
||||
|
||||
void rndis_input_poll(void)
|
||||
|
Loading…
x
Reference in New Issue
Block a user