修改net设备为支持操作系统
Some checks failed
Build / set-matrix (push) Has been cancelled
Build / make-os (macos-latest) (push) Has been cancelled
Build / make-os (windows-latest) (push) Has been cancelled
Build / zephyr (push) Has been cancelled
Build / hil-hfp (push) Has been cancelled
pre-commit / pre-commit (push) Has been cancelled
Build / cmake (aarch64-gcc) (push) Has been cancelled
Build / cmake (arm-gcc) (push) Has been cancelled
Build / cmake (esp-idf) (push) Has been cancelled
Build / cmake (msp430-gcc) (push) Has been cancelled
Build / cmake (riscv-gcc) (push) Has been cancelled
Build / make (aarch64-gcc) (push) Has been cancelled
Build / make (arm-gcc) (push) Has been cancelled
Build / make (msp430-gcc) (push) Has been cancelled
Build / make (riscv-gcc) (push) Has been cancelled
Build / make (rx-gcc) (push) Has been cancelled
Build / arm-iar (make) (push) Has been cancelled
Build / hil-build (arm-gcc) (push) Has been cancelled
Build / hil-build (esp-idf) (push) Has been cancelled
Build / hil-tinyusb (push) Has been cancelled

This commit is contained in:
2025-10-10 12:12:51 +08:00
parent bbda99171d
commit 8a9a778375
5 changed files with 49 additions and 26 deletions

View File

@@ -3,6 +3,16 @@
#include <rtconfig.h> #include <rtconfig.h>
#define LWIP_MULTICAST_PING 1
#define LWIP_BROADCAST_PING 1
#define LWIP_IP_ACCEPT_UDP_PORT(p) ((p) == PP_NTOHS(67))
#define ETHARP_SUPPORT_STATIC_ENTRIES 1
#define LWIP_SINGLE_NETIF 1
#define LWIP_NETIF_LINK_CALLBACK 1
#define PBUF_POOL_SIZE 4
#define LWIP_CHECKSUM_ON_COPY 1
#define ERRNO 1 #define ERRNO 1
#define LWIP_SOCKET_SELECT 1 #define LWIP_SOCKET_SELECT 1
@@ -346,7 +356,7 @@
#ifdef RT_LWIP_TCP_SND_BUF #ifdef RT_LWIP_TCP_SND_BUF
#define TCP_SND_BUF RT_LWIP_TCP_SND_BUF #define TCP_SND_BUF RT_LWIP_TCP_SND_BUF
#else #else
#define TCP_SND_BUF (TCP_MSS * 2) #define TCP_SND_BUF (TCP_MSS * 4)
#endif #endif
/* TCP sender buffer space (pbufs). This must be at least = 2 * /* TCP sender buffer space (pbufs). This must be at least = 2 *
@@ -363,7 +373,7 @@
#ifdef RT_LWIP_TCP_WND #ifdef RT_LWIP_TCP_WND
#define TCP_WND RT_LWIP_TCP_WND #define TCP_WND RT_LWIP_TCP_WND
#else #else
#define TCP_WND (TCP_MSS * 2) #define TCP_WND (TCP_MSS * 4)
#endif #endif
/* Maximum number of retransmissions of data segments. */ /* Maximum number of retransmissions of data segments. */
@@ -379,8 +389,8 @@
#define TCPIP_THREAD_STACKSIZE RT_LWIP_TCPTHREAD_STACKSIZE #define TCPIP_THREAD_STACKSIZE RT_LWIP_TCPTHREAD_STACKSIZE
#else #else
#define TCPIP_MBOX_SIZE 8 #define TCPIP_MBOX_SIZE 8
#define TCPIP_THREAD_PRIO 7 #define TCPIP_THREAD_PRIO 5
#define TCPIP_THREAD_STACKSIZE 4096 #define TCPIP_THREAD_STACKSIZE 4096*2
#endif #endif
#define TCPIP_THREAD_NAME "tcpip" #define TCPIP_THREAD_NAME "tcpip"
#define DEFAULT_TCP_RECVMBOX_SIZE 10 #define DEFAULT_TCP_RECVMBOX_SIZE 10
@@ -435,7 +445,7 @@
#define LWIP_UDP 0 #define LWIP_UDP 0
#endif #endif
#define LWIP_UDPLITE 0 #define LWIP_UDPLITE 1
#define UDP_TTL 255 #define UDP_TTL 255
#define DEFAULT_UDP_RECVMBOX_SIZE 1 #define DEFAULT_UDP_RECVMBOX_SIZE 1

View File

@@ -85,7 +85,7 @@ uint8_t tud_network_mac_address[6] = {0x02, 0x02, 0x84, 0x6A, 0x96, 0x00};
/* network parameters of this MCU */ /* network parameters of this MCU */
static const ip4_addr_t ipaddr = INIT_IP4(192, 168, 7, 1); static const ip4_addr_t ipaddr = INIT_IP4(192, 168, 7, 1);
static const ip4_addr_t netmask = INIT_IP4(255, 255, 255, 0); static const ip4_addr_t netmask = INIT_IP4(255, 255, 255, 0);
static const ip4_addr_t gateway = INIT_IP4(0, 0, 0, 0); static const ip4_addr_t gateway = INIT_IP4(192, 168, 7, 1);
/* database IP addresses that can be offered to the host; this must be in RAM to store assigned MAC addresses */ /* database IP addresses that can be offered to the host; this must be in RAM to store assigned MAC addresses */
static dhcp_entry_t entries[] = { static dhcp_entry_t entries[] = {
@@ -96,7 +96,7 @@ static dhcp_entry_t entries[] = {
}; };
static const dhcp_config_t dhcp_config = { static const dhcp_config_t dhcp_config = {
.router = INIT_IP4(0, 0, 0, 0), /* router address (if any) */ .router = INIT_IP4(192, 168, 7, 1), /* router address (if any) */
.port = 67, /* listen port */ .port = 67, /* listen port */
.dns = INIT_IP4(192, 168, 7, 1), /* dns server (if any) */ .dns = INIT_IP4(192, 168, 7, 1), /* dns server (if any) */
"usb", /* dns suffix */ "usb", /* dns suffix */
@@ -108,14 +108,16 @@ static const dhcp_config_t dhcp_config = {
static int tud_output_fn(void *t){ static void tud_output_fn(void *t){
struct pbuf *p = t; struct pbuf *p = t;
/* if the network driver can accept another packet, we make it happen */ 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)) { if (tud_network_can_xmit(p->tot_len)) {
tud_network_xmit(p, 0 /* unused for this example */); tud_network_xmit(p, 0 /* unused for this example */);
return ERR_OK; rt_kprintf("send %d bytes\n", p->tot_len);
// return ERR_OK;
} }
return ERR_USE; // return ERR_USE;
} }
@@ -129,7 +131,10 @@ static err_t linkoutput_fn(struct netif *netif, struct pbuf *p) {
if (!tud_ready()) if (!tud_ready())
return ERR_USE; return ERR_USE;
/*rc this packet will be sent in usbd task */ /*rc this packet will be sent in usbd task */
return usbd_defer_func_wait(tud_output_fn, p); 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 */ /* 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? */ /*rc: if use rtos, this function still will be called? */
// tud_task(); // tud_task();
@@ -216,7 +221,7 @@ bool tud_network_recv_cb(const uint8_t *src, uint16_t size) {
struct pbuf *p = pbuf_alloc(PBUF_RAW, size, PBUF_POOL); struct pbuf *p = pbuf_alloc(PBUF_RAW, size, PBUF_POOL);
if (p == NULL) { if (p == NULL) {
TU_LOG(2,"ERROR: Failed to allocate pbuf of size %d\n", size); rt_kprintf("ERROR: Failed to allocate pbuf of size %d\n", size);
return false; return false;
} }
@@ -305,7 +310,7 @@ void usb_irq_enable(){
static void tusb_thread_entry(void *parameter) static void tusb_thread_entry(void *parameter)
{ {
TU_LOG(2, "TinyUSB task started\n"); rt_kprintf( "TinyUSB task started\n");
(void) parameter; (void) parameter;
while (1) { while (1) {
#if CFG_TUH_ENABLED #if CFG_TUH_ENABLED
@@ -353,9 +358,9 @@ int init_tinyusb(void) {
while (dhserv_init(&dhcp_config) != ERR_OK){ while (dhserv_init(&dhcp_config) != ERR_OK){
rt_thread_mdelay(10); rt_thread_mdelay(10);
} }
while (dnserv_init(IP_ADDR_ANY, 53, dns_query_proc) != ERR_OK){ // while (dnserv_init(IP_ADDR_ANY, 53, dns_query_proc) != ERR_OK){
rt_thread_mdelay(10); // rt_thread_mdelay(10);
} // }
httpd_init(); httpd_init();
#ifdef INCLUDE_IPERF #ifdef INCLUDE_IPERF
@@ -371,8 +376,8 @@ int init_tinyusb(void) {
#ifdef RT_USING_HEAP #ifdef RT_USING_HEAP
tid = rt_thread_create("tusb", tusb_thread_entry, RT_NULL, tid = rt_thread_create("tusb", tusb_thread_entry, RT_NULL,
2048, 4096,
1, 10); 7, 10);
if (tid == RT_NULL) if (tid == RT_NULL)
#else #else
rt_err_t result; rt_err_t result;

View File

@@ -62,7 +62,7 @@ extern "C" {
#endif #endif
#ifndef CFG_TUSB_DEBUG #ifndef CFG_TUSB_DEBUG
#define CFG_TUSB_DEBUG 3 #define CFG_TUSB_DEBUG 0
#endif #endif
#ifdef CFG_TUSB_DEBUG #ifdef CFG_TUSB_DEBUG
#define CFG_TUSB_DEBUG_PRINTF rt_kprintf #define CFG_TUSB_DEBUG_PRINTF rt_kprintf

View File

@@ -139,7 +139,8 @@ static void udp_recv_proc(void *arg, struct udp_pcb *upcb, struct pbuf *p, const
ip4_addr_t host_addr; ip4_addr_t host_addr;
dns_answer_t *answer; dns_answer_t *answer;
(void)arg; rt_kprintf("DNS query\n");
(void)arg;
if (p->len <= sizeof(dns_header_t)) goto error; if (p->len <= sizeof(dns_header_t)) goto error;
header = (dns_header_t *)p->payload; header = (dns_header_t *)p->payload;

View File

@@ -134,12 +134,13 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_unlock(osal_mutex_t mutex_hd
// role device/host is used by OS NONE for mutex (disable usb isr) only // role device/host is used by OS NONE for mutex (disable usb isr) only
#define OSAL_QUEUE_DEF(_int_set, _name, _depth, _type) \ #define OSAL_QUEUE_DEF(_int_set, _name, _depth, _type) \
static _type _name##_##buf[_depth]; \ static uint32_t _name##_##buf[((sizeof(_type)+sizeof(void *))*_depth+3)/4]; \
osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf }; osal_queue_def_t _name = { .item_sz = sizeof(_type), \
.pool_size=sizeof(_name##_##buf), .buf = _name##_##buf };
typedef struct { typedef struct {
uint16_t depth;
uint16_t item_sz; uint16_t item_sz;
uint16_t pool_size;
void *buf; void *buf;
struct rt_messagequeue sq; struct rt_messagequeue sq;
@@ -149,7 +150,7 @@ typedef rt_mq_t osal_queue_t;
TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create(osal_queue_def_t *qdef) { TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create(osal_queue_def_t *qdef) {
rt_mq_init(&(qdef->sq), "tusb", qdef->buf, qdef->item_sz, rt_mq_init(&(qdef->sq), "tusb", qdef->buf, qdef->item_sz,
qdef->item_sz * qdef->depth, RT_IPC_FLAG_PRIO); qdef->pool_size, RT_IPC_FLAG_FIFO);
return &(qdef->sq); return &(qdef->sq);
} }
@@ -162,7 +163,13 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, v
#if RT_VERSION_MAJOR >= 5 #if RT_VERSION_MAJOR >= 5
return rt_mq_recv(qhdl, data, qhdl->msg_size, tick) > 0; return rt_mq_recv(qhdl, data, qhdl->msg_size, tick) > 0;
#else #else
return rt_mq_recv(qhdl, data, qhdl->msg_size, tick) == RT_EOK; rt_err_t ret = rt_mq_recv(qhdl, data, qhdl->msg_size, tick);
if (ret == RT_EOK){
return true;
}else{
rt_kprintf("osal_queue_receive failed ret=%d\n", ret);
return false;
}
#endif /* RT_VERSION_MAJOR >= 5 */ #endif /* RT_VERSION_MAJOR >= 5 */
} }