整理代码
This commit is contained in:
@@ -108,16 +108,16 @@ static const dhcp_config_t dhcp_config = {
|
||||
|
||||
|
||||
|
||||
static void tud_output_fn(void *t){
|
||||
static int tud_output_fn(void *t){
|
||||
struct pbuf *p = t;
|
||||
rt_kprintf("arrive %s:%d\n", __FILE__, __LINE__);
|
||||
// rt_kprintf("arrive %s:%d\n", __FILE__, __LINE__);
|
||||
/* if the network driver can accept another packet, we make it happen */
|
||||
if (tud_network_can_xmit(p->tot_len)) {
|
||||
tud_network_xmit(p, 0 /* unused for this example */);
|
||||
rt_kprintf("send %d bytes\n", p->tot_len);
|
||||
// return ERR_OK;
|
||||
// rt_kprintf("send %d bytes\n", p->tot_len);
|
||||
return ERR_OK;
|
||||
}
|
||||
// return ERR_USE;
|
||||
return ERR_USE;
|
||||
}
|
||||
|
||||
|
||||
@@ -130,14 +130,9 @@ static err_t linkoutput_fn(struct netif *netif, struct pbuf *p) {
|
||||
/* if TinyUSB isn't ready, we must signal back to lwip that there is nothing we can do */
|
||||
if (!tud_ready())
|
||||
return ERR_USE;
|
||||
/*rc this packet will be sent in usbd task */
|
||||
rt_kprintf("arrive %s:%d\n", __FILE__, __LINE__);
|
||||
usbd_defer_func(tud_output_fn, p, false);
|
||||
return ERR_OK;
|
||||
// return usbd_defer_func_wait(tud_output_fn, p);
|
||||
/* transfer execution to TinyUSB in the hopes that it will finish transmitting the prior packet */
|
||||
/*rc: if use rtos, this function still will be called? */
|
||||
// tud_task();
|
||||
// rt_kprintf("arrive %s:%d\n", __FILE__, __LINE__);
|
||||
// <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ȴ<EFBFBD>usb<73>̴߳<DFB3><CCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD>lwip<69><70><EFBFBD>ͷ<EFBFBD>p
|
||||
return usbd_defer_func_wait(tud_output_fn, p);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,10 +223,7 @@ bool tud_network_recv_cb(const uint8_t *src, uint16_t size) {
|
||||
/* Copy buf to pbuf */
|
||||
pbuf_take(p, src, size);
|
||||
|
||||
// Surrender ownership of our pbuf unless there was an error
|
||||
// Only call pbuf_free if not Ok else it will panic with "pbuf_free: p->ref > 0"
|
||||
// or steal it from whatever took ownership of it with undefined consequences.
|
||||
// See: https://savannah.nongnu.org/patch/index.php?10121
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><EFBFBD><EFBFBD>lwip<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>usb<EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD><EFBFBD><EFBFBD>tcpip<EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD><EFBFBD>ͣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD>ȴ<EFBFBD>lwip<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (err=netif->input(p, netif),err != ERR_OK) {
|
||||
rt_kprintf("ERROR: netif input failed, err=%d\n", err);
|
||||
pbuf_free(p);
|
||||
@@ -358,9 +350,9 @@ int init_tinyusb(void) {
|
||||
while (dhserv_init(&dhcp_config) != ERR_OK){
|
||||
rt_thread_mdelay(10);
|
||||
}
|
||||
// while (dnserv_init(IP_ADDR_ANY, 53, dns_query_proc) != ERR_OK){
|
||||
// rt_thread_mdelay(10);
|
||||
// }
|
||||
while (dnserv_init(IP_ADDR_ANY, 53, dns_query_proc) != ERR_OK){
|
||||
rt_thread_mdelay(10);
|
||||
}
|
||||
httpd_init();
|
||||
|
||||
#ifdef INCLUDE_IPERF
|
||||
@@ -393,26 +385,8 @@ int init_tinyusb(void) {
|
||||
}
|
||||
|
||||
rt_thread_startup(tid);
|
||||
// while (1) {
|
||||
// tud_task();
|
||||
// // sys_check_timeouts(); // service lwip
|
||||
// // handle_link_state_switch();
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
||||
extern_init(tinyusb, init_tinyusb);
|
||||
|
||||
/* lwip has provision for using a mutex, when applicable */
|
||||
/* This implementation is for single-threaded use only */
|
||||
// sys_prot_t sys_arch_protect(void) {
|
||||
// return 0;
|
||||
// }
|
||||
// void sys_arch_unprotect(sys_prot_t pval) {
|
||||
// (void) pval;
|
||||
// }
|
||||
|
||||
// /* lwip needs a millisecond time source, and the TinyUSB board support code has one available */
|
||||
// uint32_t sys_now(void) {
|
||||
// return board_millis();
|
||||
// }
|
||||
|
@@ -139,7 +139,7 @@ static void udp_recv_proc(void *arg, struct udp_pcb *upcb, struct pbuf *p, const
|
||||
ip4_addr_t host_addr;
|
||||
dns_answer_t *answer;
|
||||
|
||||
rt_kprintf("DNS query\n");
|
||||
// rt_kprintf("DNS query\n");
|
||||
(void)arg;
|
||||
|
||||
if (p->len <= sizeof(dns_header_t)) goto error;
|
||||
|
Reference in New Issue
Block a user