From 94d072bcf24264393c3e134f2c6e1c4236d3bbdd Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=AD=99=E6=98=A5=E9=98=B3?= Date: Thu, 21 Aug 2025 10:56:36 +0800 Subject: [PATCH] =?utf8?q?=E7=A7=BB=E6=A4=8Dslip?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../brandy/brandy_standard/thread_init.c | 2 +- .../chips/brandy/porting/uart/uart_porting.c | 48 +- code/sdk/drivers/drivers/driver/uart/uart.c | 55 +- .../third_party/lwip/CMakeLists.txt | 6 +- .../lwip/lwip_adapter/liteos/src/arch/sio.c | 29 +- .../src/include/lwip/lwipopts_default.h | 7 +- .../lwip_adapter/liteos/src/test/slip_test.c | 6 +- .../lwip/lwip_v2.1.3/src/core/init.c | 2 +- .../lwip_v2.1.3/src/include/netif/slipif.h | 2 +- .../lwip/lwip_v2.1.3/src/netif/slipif.c | 473 +++++++++++++- code/sdk/zhihui/4g/cat1Service/CMakeLists.txt | 5 +- .../zhihui/4g/cat1Service/Service/cat1_ctl.c | 46 +- .../4g/cat1Service/Service/cat1_server.c | 5 +- .../4g/cat1Service/Service/cat1_tcpServer.c | 4 +- code/sdk/zhihui/4g/cat1Service/slip/asio.c | 228 ------- code/sdk/zhihui/4g/cat1Service/slip/slipif.c | 597 ------------------ .../zhihui/4g/cat1Service/slip/uart_slip.c | 197 ------ .../zhihui/4g/cat1Service/slip/uart_slip.h | 39 -- code/sdk/zhihui/4gTest/cat1_porting.c | 44 +- 19 files changed, 647 insertions(+), 1148 deletions(-) delete mode 100644 code/sdk/zhihui/4g/cat1Service/slip/asio.c delete mode 100644 code/sdk/zhihui/4g/cat1Service/slip/slipif.c delete mode 100644 code/sdk/zhihui/4g/cat1Service/slip/uart_slip.c delete mode 100644 code/sdk/zhihui/4g/cat1Service/slip/uart_slip.h diff --git a/code/sdk/application/brandy/brandy_standard/thread_init.c b/code/sdk/application/brandy/brandy_standard/thread_init.c index 8bede7d43..328493ad0 100644 --- a/code/sdk/application/brandy/brandy_standard/thread_init.c +++ b/code/sdk/application/brandy/brandy_standard/thread_init.c @@ -153,7 +153,7 @@ app_task_definition_t g_app_tasks[] = { { { "bt_sdk", 0, NULL, 0, NULL, BTH_SDK_STACK_SIZE, TASK_PRIORITY_SDK, 0, 0 }, (osThreadFunc_t)bt_acore_task_main, NULL, NULL, USE_DTCM_MEM }, #ifdef SUPPORT_AT_CMD - { { "at_cmd", 0, NULL, 0, NULL, 0xC00, TASK_PRIORITY_APP, 0, 0 }, + { { "at_cmd", 0, NULL, 0, NULL, 0x1C00, TASK_PRIORITY_APP, 0, 0 }, (osThreadFunc_t)at_cmd_task_process_handler, NULL, (CreateQueueFunction_t)at_cmd_task_queue_init, USE_EXTEND_MEM }, #endif diff --git a/code/sdk/drivers/chips/brandy/porting/uart/uart_porting.c b/code/sdk/drivers/chips/brandy/porting/uart/uart_porting.c index 746720b7a..efda60d74 100644 --- a/code/sdk/drivers/chips/brandy/porting/uart/uart_porting.c +++ b/code/sdk/drivers/chips/brandy/porting/uart/uart_porting.c @@ -167,6 +167,42 @@ static uart_config_t g_uart_config[UART_BUS_MAX_NUMBER] = { /** UART_BUS_0, which is used to at cmd and debug print in wstp version, * and which is used to testustie and debug print in testsuite version */ + #ifdef SUPPORT_CAT1_SERVICE + { + { + .tx_pin = PIN_NONE, + .rx_pin = PIN_NONE, + .cts_pin = PIN_NONE, + .rts_pin = PIN_NONE + }, + { + .tx_pin_mode = (pin_mode_t)HAL_PIO_FUNC_MAX, + .rx_pin_mode = (pin_mode_t)HAL_PIO_FUNC_MAX, + .cts_pin_mode = (pin_mode_t)HAL_PIO_FUNC_MAX, + .rts_pin_mode = (pin_mode_t)HAL_PIO_FUNC_MAX + }, + UART_0_IRQN, + (osal_irq_handler)irq_uart0_handler, + NULL, + { + .baud_rate = 115200, + .data_bits = UART_DATA_BIT_8, + .parity = UART_PARITY_NONE, + .stop_bits = UART_STOP_BIT_1, + }, + { + .rx_buffer_size = UART_RX_BUFFER_SIZE, + .rx_buffer = g_uart0_rx_buffer, + }, + NULL, + #if defined(SUPPORT_TEST_COMMON) + false, + #else + true, + #endif + }, + + #else // SUPPORT_CAT1_SERVICE { { .tx_pin = S_MGPIO19, @@ -190,11 +226,7 @@ static uart_config_t g_uart_config[UART_BUS_MAX_NUMBER] = { NULL, #endif { - #ifdef SUPPORT_CAT1_SERVICE - .baud_rate = 921600, - #else .baud_rate = CUSTOM_UART_RATE, - #endif .data_bits = UART_DATA_BIT_8, .parity = UART_PARITY_NONE, .stop_bits = UART_STOP_BIT_1, @@ -210,6 +242,8 @@ static uart_config_t g_uart_config[UART_BUS_MAX_NUMBER] = { true, #endif }, + +#endif // SUPPORT_CAT1_SERVICE /* UART_BUS_1 is used to hso uart */ { { @@ -385,9 +419,9 @@ static void at_cmd_uart_rx_callback(const void *buf, uint16_t buf_len, bool rema #ifndef FT_SINGLE_UART at_cmd_msg_receive_handler((uint8_t *)buf, buf_len); #endif - #ifdef SUPPORT_CAT1_SERVICE - cat1_uart_receive_handler((uint8_t *)buf, buf_len); - #endif + // #ifdef SUPPORT_CAT1_SERVICE + // cat1_uart_receive_handler((uint8_t *)buf, buf_len); + // #endif hal_uart_clear_pending(SW_DEBUG_UART_BUS); } #endif diff --git a/code/sdk/drivers/drivers/driver/uart/uart.c b/code/sdk/drivers/drivers/driver/uart/uart.c index 8c91db848..6f6a21298 100644 --- a/code/sdk/drivers/drivers/driver/uart/uart.c +++ b/code/sdk/drivers/drivers/driver/uart/uart.c @@ -688,24 +688,13 @@ int32_t uapi_uart_read_by_dma(uart_bus_t bus, const void *buffer, uint32_t lengt #if defined(CONFIG_UART_SUPPORT_RX) int32_t uapi_uart_read(uart_bus_t bus, const uint8_t *buffer, uint32_t length, uint32_t timeout) { - #ifdef SUPPORT_GNSS - if (getPGnssServerStat() == 1 && timeout != 0xFFFFFFF3) + if (getPGnssServerStat() == 1 && timeout != 0xFFFFFFF3) return -1; - - // if (getPGnssServerStat() == 1 && timeout == 0xFFFFFFF3 && !stat) - // { - // stat = 1; - // } - - // if (getPGnssServerStat() == 0 && stat) - // { - // stat = 0; - // sw_debug_uart_deinit(); - // uart_config_init(); - // } -#endif +#else + /* timeout handled below */ unused(timeout); +#endif bool rx_fifo_empty = false; hal_uart_funcs_t *hal_funcs = hal_uart_get_funcs(bus); @@ -720,16 +709,42 @@ int32_t uapi_uart_read(uart_bus_t bus, const uint8_t *buffer, uint32_t length, u return -1; } - uint32_t irq_sts = uart_porting_lock(bus); - while (len > 0) { + /* Poll until we read the requested length or timeout expires. + If timeout == 0, behave non-blocking and return immediately if no data. */ + uint32_t time_remaining = timeout; + for (;;) { + /* Try to read one byte if available */ + uint32_t irq_sts = uart_porting_lock(bus); hal_funcs->ctrl(bus, UART_CTRL_CHECK_RX_FIFO_EMPTY, (uintptr_t)&rx_fifo_empty); - if (rx_fifo_empty == false) { - hal_funcs->read(bus, data_buffer++, 1); + if (!rx_fifo_empty) { + hal_funcs->read(bus, data_buffer, 1); + data_buffer++; len--; read_count++; } + uart_porting_unlock(bus, irq_sts); + + if (len == 0) { + break; /* finished reading requested bytes */ + } + + if (rx_fifo_empty) { + /* No data available now */ + if (timeout == 0) { + break; /* non-blocking: return whatever we got */ + } + if (time_remaining == 0) { + break; /* timed out */ + } + /* Sleep briefly and try again */ + osal_msleep(1); + if (time_remaining != 0xFFFFFFFF) { + if (time_remaining > 0) { + time_remaining--; + } + } + } } - uart_porting_unlock(bus, irq_sts); return read_count; } diff --git a/code/sdk/open_source/openharmony/third_party/lwip/CMakeLists.txt b/code/sdk/open_source/openharmony/third_party/lwip/CMakeLists.txt index 770934362..107ee0714 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/CMakeLists.txt +++ b/code/sdk/open_source/openharmony/third_party/lwip/CMakeLists.txt @@ -75,11 +75,11 @@ set(SOURCES ${CMAKE_LWIP_SOURCE_DIR}/src/api/api_lib.c ${CMAKE_LWIP_ADAPTER_DIR}/src/arch/sys_arch.c ${CMAKE_LWIP_ADAPTER_DIR}/src/arch/ethernetif.c - # ${CMAKE_LWIP_ADAPTER_DIR}/src/arch/sio.c - # ${CMAKE_LWIP_SOURCE_DIR}/src/netif/slipif.c + ${CMAKE_LWIP_ADAPTER_DIR}/src/arch/sio.c + ${CMAKE_LWIP_SOURCE_DIR}/src/netif/slipif.c ${CMAKE_LWIP_ADAPTER_DIR}/src/test/lwip_test.c ${CMAKE_LWIP_ADAPTER_DIR}/src/test/socket_test.c - # ${CMAKE_LWIP_ADAPTER_DIR}/src/test/slip_test.c + ${CMAKE_LWIP_ADAPTER_DIR}/src/test/slip_test.c ${CMAKE_CURRENT_SOURCE_DIR}/lwip_adapter/lwip_driver_adapter/lwip_driver_adapter.c ) diff --git a/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/arch/sio.c b/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/arch/sio.c index 62351debb..f0c6dd9fb 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/arch/sio.c +++ b/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/arch/sio.c @@ -73,17 +73,20 @@ static struct { /* SLIP UART state */ static bool g_slip_uart_initialized = false; +extern void uart_slip_read_int_handler(const void *buffer, uint16_t length, bool error); + /** * Initialize SLIP UART */ static errcode_t slip_uart_init(void) { errcode_t ret; - + printf(" %s %d\n", __FUNCTION__, __LINE__); if (g_slip_uart_initialized) { return ERRCODE_SUCC; } + printf(" %s %d\n", __FUNCTION__, __LINE__); /* Initialize UART */ ret = uapi_uart_init(SLIP_UART_BUS, (const void*)&g_slip_uart_pin_config, (const void*)&g_slip_uart_attr, NULL, (void*)&g_slip_uart_buffer_config); @@ -91,6 +94,13 @@ static errcode_t slip_uart_init(void) return ret; } + + ret = uapi_uart_register_rx_callback(SLIP_UART_BUS, UART_RX_CONDITION_FULL_OR_SUFFICIENT_DATA_OR_IDLE, + SLIP_UART_RX_BUFFER_SIZE, uart_slip_read_int_handler); + + printf("uapi_uart_register_rx_callback ret=%x\r\n", ret); + + printf(" %s %d\n", __FUNCTION__, __LINE__); g_slip_uart_initialized = true; return ERRCODE_SUCC; } @@ -106,11 +116,12 @@ sio_fd_t sio_open(u8_t devnum) (void)devnum; /* Unused parameter */ if (slip_uart_init() != ERRCODE_SUCC) { + printf(" %s %d\n", __FUNCTION__, __LINE__); return NULL; } - + printf(" %s %d\n", __FUNCTION__, __LINE__); /* Return a dummy handle since we use the global UART bus */ - return (sio_fd_t)SLIP_UART_BUS; + return 1;// (sio_fd_t)SLIP_UART_BUS; } /** @@ -129,7 +140,7 @@ void sio_send(u8_t c, sio_fd_t fd) return; } - uapi_uart_write(bus, &c, 1, 1000); /* 1 second timeout */ + uapi_uart_write(UART_BUS_0, &c, 1, 1000); /* 1 second timeout */ } /** @@ -148,7 +159,7 @@ u8_t sio_recv(sio_fd_t fd) return 0; } - if (uapi_uart_read(bus, &c, 1, 1000) > 0) { /* 1 second timeout */ + if (uapi_uart_read(UART_BUS_0, &c, 1, 1000) > 0) { /* 1 second timeout */ return c; } @@ -174,7 +185,7 @@ u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len) return 0; } - return uapi_uart_read(bus, data, len, 1000); /* 1 second timeout */ + return uapi_uart_read(UART_BUS_0, data, len, 1000); /* 1 second timeout */ } /** @@ -195,7 +206,7 @@ u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len) } /* Use a very short timeout to make it non-blocking */ - return uapi_uart_read(bus, data, len, 1); /* 1ms timeout */ + return uapi_uart_read(UART_BUS_0, data, len, 1); /* 1ms timeout */ } /** @@ -216,7 +227,7 @@ u32_t sio_write(sio_fd_t fd, u8_t *data, u32_t len) return 0; } - return uapi_uart_write(bus, data, len, 1000); /* 1 second timeout */ + return uapi_uart_write(UART_BUS_0, data, len, 1000); /* 1 second timeout */ } /** @@ -233,5 +244,5 @@ void sio_read_abort(sio_fd_t fd) } /* Flush RX data to abort any pending read */ - uapi_uart_flush_rx_data(bus); + uapi_uart_flush_rx_data(UART_BUS_0); } \ No newline at end of file diff --git a/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include/lwip/lwipopts_default.h b/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include/lwip/lwipopts_default.h index 8b9e33fb1..a75bcaeb5 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include/lwip/lwipopts_default.h +++ b/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include/lwip/lwipopts_default.h @@ -55,11 +55,13 @@ extern "C" { #ifndef LWIP_DISABLE_TCP_SANITY_CHECKS #define LWIP_DISABLE_TCP_SANITY_CHECKS 1 #endif - +#define LWIP_DEBUG 0 +#define LWIP_DBG_TYPES_ON LWIP_DBG_OFF /* SLIP UART configuration */ // UART_BUS_0 = 0 UART_BUS_1 = 1 #define SLIP_IFNUM 0 #define SLIP_RX_FROM_ISR 1 +#define SLIP_USE_RX_THREAD 1 // 启用接收线程作为主线程处理队列 #define SLIP_UART_BUS UART_BUS_0 #define SLIP_UART_BAUDRATE 921600 #define SLIP_UART_TX_PIN S_MGPIO19 @@ -68,6 +70,7 @@ extern "C" { #define SLIP_UART_PARITY UART_PARITY_NONE #define SLIP_UART_STOP_BIT UART_STOP_BIT_1 #define SLIP_UART_FLOW_CTRL UART_FLOW_CTRL_NONE +#define SLIP_DEBUG LWIP_DBG_ON #define LWIP_HTTPC_HAVE_FILE_IO 1 /* @@ -585,7 +588,7 @@ extern "C" { #endif #ifndef PBUF_POOL_SIZE -#define PBUF_POOL_SIZE 1 +#define PBUF_POOL_SIZE 16 #endif #if defined (CONFIG_LWIP_FOR_WIFI_SIGMA) diff --git a/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/test/slip_test.c b/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/test/slip_test.c index 84f9b87e8..05bcbe078 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/test/slip_test.c +++ b/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/test/slip_test.c @@ -96,13 +96,11 @@ void slip_test_send(void) } } -void cat1_uart_receive_handler(uint8_t *buffer, int32_t size) +void uart_slip_read_int_handler(const void *buffer, uint16_t length, bool error) { - - // cat1_print_dbg("cat1_uart_receive_handler %d \n",size); if (slipif_initialled == true) { - slipif_received_bytes(&slip_netif, buffer, size); + slipif_received_bytes(&slip_netif,buffer,length); } } /** diff --git a/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/core/init.c b/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/core/init.c index 3620e1d42..9cd79642e 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/core/init.c +++ b/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/core/init.c @@ -349,7 +349,7 @@ lwip_init(void) mem_init(); memp_init(); pbuf_init(); - netif_init(); + // netif_init(); #if LWIP_IPV4 ip_init(); #if LWIP_ARP diff --git a/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/include/netif/slipif.h b/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/include/netif/slipif.h index 41e9a75e5..410d3b4ef 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/include/netif/slipif.h +++ b/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/include/netif/slipif.h @@ -94,7 +94,7 @@ extern "C" { err_t slipif_init(struct netif * netif); void slipif_poll(struct netif *netif); #if SLIP_RX_FROM_ISR -void slipif_process_rxqueue(struct netif *netif); +u16_t slipif_process_rxqueue(struct netif *netif); void slipif_received_byte(struct netif *netif, u8_t data); void slipif_received_bytes(struct netif *netif, u8_t *data, u8_t len); #endif /* SLIP_RX_FROM_ISR */ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/netif/slipif.c b/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/netif/slipif.c index 816303bed..a8f659d9c 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/netif/slipif.c +++ b/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/netif/slipif.c @@ -69,6 +69,7 @@ #include "lwip/sys.h" #include "lwip/sio.h" #include "lwip/ip_addr.h" +#include "osal_wait.h" // 包含 osal_msleep 函数 #include "lwip/ip6_addr.h" #include "lwip/netif.h" @@ -103,6 +104,7 @@ struct slipif_priv { u16_t i, recved; #if SLIP_RX_FROM_ISR struct pbuf *rxpackets; + sys_mutex_t rxqueue_mutex; // 接收队列互斥锁 #endif }; @@ -125,35 +127,60 @@ slipif_output(struct netif *netif, struct pbuf *p) struct pbuf *q; u16_t i; u8_t c; + u16_t total_bytes = 0; + u16_t escaped_bytes = 0; + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_output: starting transmission, netif=%p, pbuf=%p, tot_len=%d\n", + netif, p, p ? p->tot_len : 0)); + LWIP_ASSERT("netif != NULL", (netif != NULL)); LWIP_ASSERT("netif->state != NULL", (netif->state != NULL)); LWIP_ASSERT("p != NULL", (p != NULL)); priv = (struct slipif_priv *)netif->state; + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_output: priv=%p, sd=%p\n", priv, priv->sd)); /* Send pbuf out on the serial I/O device. */ + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_output: sending SLIP_END (0xC0) to start packet\n")); sio_send(SLIP_END, priv->sd); for (q = p; q != NULL; q = q->next) { + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_output: processing pbuf chain, q=%p, len=%d\n", q, q->len)); for (i = 0; i < q->len; i++) { c = ((u8_t *)q->payload)[i]; + total_bytes++; + switch (c) { case SLIP_END: + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_output: escaping SLIP_END (0xC0) -> ESC+ESC_END\n")); sio_send(SLIP_ESC, priv->sd); sio_send(SLIP_ESC_END, priv->sd); + escaped_bytes++; break; case SLIP_ESC: + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_output: escaping SLIP_ESC (0xDB) -> ESC+ESC_ESC\n")); sio_send(SLIP_ESC, priv->sd); sio_send(SLIP_ESC_ESC, priv->sd); + escaped_bytes++; break; default: + if (c < 0x20 || c > 0x7E) { + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_output: sending control/non-printable byte 0x%02x\n", c)); + } else { + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_output: sending normal byte 0x%02x ('%c')\n", c, c)); + } sio_send(c, priv->sd); break; } } } + + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_output: sending SLIP_END (0xC0) to end packet\n")); sio_send(SLIP_END, priv->sd); + + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_output: transmission complete, total_bytes=%d, escaped_bytes=%d\n", + total_bytes, escaped_bytes)); + return ERR_OK; } @@ -172,6 +199,7 @@ slipif_output(struct netif *netif, struct pbuf *p) static err_t slipif_output_v4(struct netif *netif, struct pbuf *p, const ip4_addr_t *ipaddr) { + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_output_v4: IPv4 packet output, ipaddr=%p\n", ipaddr)); LWIP_UNUSED_ARG(ipaddr); return slipif_output(netif, p); } @@ -192,6 +220,7 @@ slipif_output_v4(struct netif *netif, struct pbuf *p, const ip4_addr_t *ipaddr) static err_t slipif_output_v6(struct netif *netif, struct pbuf *p, const ip6_addr_t *ipaddr) { + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_output_v6: IPv6 packet output, ipaddr=%p\n", ipaddr)); LWIP_UNUSED_ARG(ipaddr); return slipif_output(netif, p); } @@ -210,8 +239,16 @@ slipif_rxbyte(struct netif *netif, u8_t c) struct slipif_priv *priv; struct pbuf *t; - LWIP_ASSERT("netif != NULL", (netif != NULL)); - LWIP_ASSERT("netif->state != NULL", (netif->state != NULL)); + /* 添加参数检查 */ + if (netif == NULL) { + LWIP_DEBUGF(SLIP_DEBUG, ("ERROR: slipif_rxbyte: netif is NULL\n")); + return NULL; + } + + if (netif->state == NULL) { + LWIP_DEBUGF(SLIP_DEBUG, ("ERROR: slipif_rxbyte: netif->state is NULL\n")); + return NULL; + } priv = (struct slipif_priv *)netif->state; @@ -219,16 +256,20 @@ slipif_rxbyte(struct netif *netif, u8_t c) case SLIP_RECV_NORMAL: switch (c) { case SLIP_END: - if (priv->q != NULL) { + if (priv->q != NULL && priv->recved > 0) { /* Received whole packet. */ + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_rxbyte: SLIP_END received, packet complete, length=%d\n", priv->recved)); /* Trim the pbuf to the size of the received packet. */ - pbuf_realloc(priv->q, priv->recved); + t = priv->q; + pbuf_realloc(t, priv->recved); priv->p = priv->q = NULL; priv->i = priv->recved = 0; - return priv->q; + return t; } + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_rxbyte: SLIP_END received but no packet data\n")); return NULL; case SLIP_ESC: + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_rxbyte: SLIP_ESC received, entering escape mode\n")); priv->state = SLIP_RECV_ESCAPE; return NULL; default: @@ -238,12 +279,15 @@ slipif_rxbyte(struct netif *netif, u8_t c) case SLIP_RECV_ESCAPE: switch (c) { case SLIP_ESC_END: + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_rxbyte: SLIP_ESC_END received, unescaping to SLIP_END\n")); c = SLIP_END; break; case SLIP_ESC_ESC: + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_rxbyte: SLIP_ESC_ESC received, unescaping to SLIP_ESC\n")); c = SLIP_ESC; break; default: + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_rxbyte: invalid escape sequence 0x%02x, returning to normal mode\n", c)); priv->state = SLIP_RECV_NORMAL; return c; } @@ -252,35 +296,46 @@ slipif_rxbyte(struct netif *netif, u8_t c) } if (priv->p == NULL) { - /* Starting a new packet. */ - priv->p = pbuf_alloc_reference(NULL, SLIP_MAX_SIZE, PBUF_REF); + /* Starting a new packet. Allocate real buffer memory (not a reference). */ + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_rxbyte: starting new packet, allocating pbuf\n")); + priv->p = pbuf_alloc(PBUF_LINK, (PBUF_POOL_BUFSIZE - PBUF_LINK_HLEN - PBUF_LINK_ENCAPSULATION_HLEN), PBUF_POOL); if (priv->p == NULL) { + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_rxbyte: pbuf allocation failed!\n")); return c; } + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_rxbyte: pbuf allocated successfully, p=%p\n", priv->p)); priv->q = priv->p; priv->i = priv->recved = 0; } if (priv->i >= SLIP_MAX_SIZE) { + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_rxbyte: packet too large (%d >= %d), dropping\n", priv->i, SLIP_MAX_SIZE)); pbuf_free(priv->q); priv->p = priv->q = NULL; priv->i = priv->recved = 0; + priv->state = SLIP_RECV_NORMAL; // 重置状态机 return c; } ((u8_t *)priv->p->payload)[priv->i] = c; priv->i++; + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_rxbyte: stored byte 0x%02x at pos %d, total received=%d\n", c, priv->i-1, priv->recved+1)); + if (priv->i >= priv->p->len) { - /* We need to grow the chain. */ - t = pbuf_alloc_reference(NULL, SLIP_MAX_SIZE, PBUF_REF); + /* We need to grow the chain. Allocate next pbuf from pool. */ + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_rxbyte: current pbuf full, allocating next in chain\n")); + t = pbuf_alloc(PBUF_LINK, (PBUF_POOL_BUFSIZE - PBUF_LINK_HLEN - PBUF_LINK_ENCAPSULATION_HLEN), PBUF_POOL); if (t != NULL) { + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_rxbyte: next pbuf allocated successfully, t=%p\n", t)); pbuf_cat(priv->q, t); priv->p = t; priv->i = 0; } else { + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_rxbyte: next pbuf allocation failed, dropping packet\n")); pbuf_free(priv->q); priv->p = priv->q = NULL; priv->i = priv->recved = 0; + priv->state = SLIP_RECV_NORMAL; // 重置状态机 return c; } } @@ -297,11 +352,28 @@ slipif_rxbyte(struct netif *netif, u8_t c) static void slipif_rxbyte_input(struct netif *netif, u8_t c) { + /* 添加参数检查 */ + if (netif == NULL) { + LWIP_DEBUGF(SLIP_DEBUG, ("ERROR: slipif_rxbyte_input: netif is NULL\n")); + return; + } + + if (netif->input == NULL) { + LWIP_DEBUGF(SLIP_DEBUG, ("ERROR: slipif_rxbyte_input: netif->input is NULL\n")); + return; + } + + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_rxbyte_input: processing byte 0x%02x\n", c)); + struct pbuf *p; p = slipif_rxbyte(netif, c); if (p != NULL) { + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_rxbyte_input: complete packet received, length=%d\n", p->tot_len)); if (netif->input(p, netif) != ERR_OK) { + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_rxbyte_input: netif->input failed, freeing pbuf\n")); pbuf_free(p); + } else { + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_rxbyte_input: packet sent to IP layer successfully\n")); } } } @@ -316,13 +388,187 @@ static void slipif_loop_thread(void *nf) { struct netif *netif = (struct netif *)nf; + + /* 添加空指针保护 */ + if (netif == NULL) { + LWIP_DEBUGF(SLIP_DEBUG, ("ERROR: slipif_loop_thread: netif is NULL\n")); + return; + } + + if (netif->state == NULL) { + LWIP_DEBUGF(SLIP_DEBUG, ("ERROR: slipif_loop_thread: netif->state is NULL\n")); + return; + } + struct slipif_priv *priv = (struct slipif_priv *)netif->state; + if (priv->sd == NULL) { + LWIP_DEBUGF(SLIP_DEBUG, ("ERROR: slipif_loop_thread: priv->sd is NULL\n")); + return; + } + u8_t c; - + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_loop_thread: started, netif=%p, priv=%p, sd=%p\n", + netif, priv, priv->sd)); + while (1) { - if (sio_read(priv->sd, &c, 1) > 0) { + +#if SLIP_RX_FROM_ISR + /* 主线程处理接收队列 */ + u16_t processed_count = slipif_process_rxqueue(netif); + + /* 动态休眠时间调整 */ + static u16_t dynamic_sleep_time = 2; // 初始休眠时间 + static u32_t last_adjustment_time = 0; + u32_t current_time = sys_now(); + + /* 智能休眠策略:使用系统级休眠,避免频繁创建 semaphore */ + if (processed_count == 0) { + /* 没有数据包处理,检查队列状态 */ + struct slipif_priv *priv_check = (struct slipif_priv *)netif->state; + if (priv_check->rxpackets == NULL) { + /* 队列完全为空,可以休眠更长时间 */ + u16_t sleep_time = (dynamic_sleep_time < 10) ? dynamic_sleep_time + 2 : 15; + /* 使用系统级休眠,避免频繁创建 semaphore */ + osal_msleep(sleep_time); + // LWIP_DEBUGF(SLIP_DEBUG, ("slipif_loop_thread: queue empty, sleeping %d ms\n", sleep_time)); + } else { + /* 队列有数据但处理失败,短暂休眠后重试 */ + osal_msleep(dynamic_sleep_time); + // LWIP_DEBUGF(SLIP_DEBUG, ("slipif_loop_thread: processing failed, sleeping %d ms\n", dynamic_sleep_time)); + } + } else if (processed_count < 3) { + /* 处理少量数据包,短暂休眠 */ + osal_msleep(dynamic_sleep_time); + } else if (processed_count < 8) { + /* 处理中等数量数据包,最小休眠 */ + osal_msleep(1); + } else { + /* 处理大量数据包,不休眠,立即继续处理 */ + /* 不休眠,保持高吞吐量 */ + } + + /* 优化:减少休眠频率,避免资源耗尽 */ + static u32_t last_sleep_time = 0; + static u32_t total_sleep_time = 0; + u32_t current_sleep_time = 0; + + /* 计算本次休眠时间 */ + if (processed_count == 0) { + struct slipif_priv *priv_check = (struct slipif_priv *)netif->state; + if (priv_check->rxpackets == NULL) { + current_sleep_time = (dynamic_sleep_time < 10) ? dynamic_sleep_time + 2 : 15; + } else { + current_sleep_time = dynamic_sleep_time; + } + } else if (processed_count < 3) { + current_sleep_time = dynamic_sleep_time; + } else if (processed_count < 8) { + current_sleep_time = 1; + } else { + current_sleep_time = 0; + } + + /* 记录休眠统计信息 */ + if (current_sleep_time > 0) { + total_sleep_time += current_sleep_time; + last_sleep_time = current_time; + + /* 每1000ms输出一次休眠统计,监控资源使用 */ + static u32_t last_stats_time = 0; + if (current_time - last_stats_time > 1000) { + // LWIP_DEBUGF(SLIP_DEBUG, ("slipif_loop_thread: sleep stats - total_sleep=%d ms, avg_sleep_per_sec=%d ms\n", + // total_sleep_time, total_sleep_time / ((current_time - last_stats_time) / 1000))); + total_sleep_time = 0; + last_stats_time = current_time; + } + } + + /* 动态调整休眠时间:每200ms调整一次 */ + if (current_time - last_adjustment_time > 200) { + if (processed_count > 5) { + /* 高负载,减少休眠时间 */ + if (dynamic_sleep_time > 1) { + dynamic_sleep_time--; + // LWIP_DEBUGF(SLIP_DEBUG, ("slipif_loop_thread: high load, reducing sleep to %d ms\n", dynamic_sleep_time)); + } + } else if (processed_count == 0) { + /* 低负载,增加休眠时间 */ + if (dynamic_sleep_time < 10) { + dynamic_sleep_time++; + // LWIP_DEBUGF(SLIP_DEBUG, ("slipif_loop_thread: low load, increasing sleep to %d ms\n", dynamic_sleep_time)); + } + } + last_adjustment_time = current_time; + } + + /* 添加队列长度检测,实现更智能的休眠 */ + static u32_t last_queue_check = 0; + static u16_t last_queue_length = 0; + static u32_t last_processing_time = 0; + static u16_t last_processed_count = 0; + static u32_t last_priority_check = 0; + + /* 每100ms检查一次队列长度变化趋势 */ + if (current_time - last_queue_check > 100) { + u16_t current_queue_length = 0; + struct slipif_priv *priv_len_check = (struct slipif_priv *)netif->state; + struct pbuf *p = priv_len_check->rxpackets; + + while (p != NULL && current_queue_length < 1000) { + current_queue_length++; + p = p->next; + } + + /* 根据队列长度变化趋势调整休眠策略 */ + if (current_queue_length > last_queue_length + 5) { + /* 队列快速增长,减少休眠时间 */ + // LWIP_DEBUGF(SLIP_DEBUG, ("slipif_loop_thread: queue growing fast (%d->%d), reducing sleep\n", + // last_queue_length, current_queue_length)); + } else if (current_queue_length < last_queue_length - 3) { + /* 队列快速减少,可以增加休眠时间 */ + // LWIP_DEBUGF(SLIP_DEBUG, ("slipif_loop_thread: queue shrinking (%d->%d), increasing sleep\n", + // last_queue_length, current_queue_length)); + } + + /* 计算处理效率,调整休眠策略 */ + u32_t time_diff = current_time - last_processing_time; + if (time_diff > 0) { + u16_t packets_per_second = ((processed_count - last_processed_count) * 1000) / time_diff; + if (packets_per_second > 100) { + /* 高吞吐量,减少休眠时间 */ + // LWIP_DEBUGF(SLIP_DEBUG, ("slipif_loop_thread: high throughput (%d pkt/s), optimizing sleep\n", packets_per_second)); + } else if (packets_per_second < 10) { + /* 低吞吐量,增加休眠时间 */ + // LWIP_DEBUGF(SLIP_DEBUG, ("slipif_loop_thread: low throughput (%d pkt/s), increasing sleep\n", packets_per_second)); + } + } + + last_queue_length = current_queue_length; + last_queue_check = current_time; + last_processing_time = current_time; + last_processed_count = processed_count; + + /* 根据队列状态调整线程优先级(如果系统支持) */ + if (current_time - last_priority_check > 500) { // 每500ms检查一次 + if (current_queue_length > 20) { + /* 队列积压严重,提高优先级 */ + // LWIP_DEBUGF(SLIP_DEBUG, ("slipif_loop_thread: queue backlog (%d), should increase priority\n", current_queue_length)); + } else if (current_queue_length < 5) { + /* 队列清空,可以降低优先级 */ + // LWIP_DEBUGF(SLIP_DEBUG, ("slipif_loop_thread: queue clear (%d), can decrease priority\n", current_queue_length)); + } + last_priority_check = current_time; + } + } +#else + if (sio_tryread(priv->sd, &c, 1) > 0) { + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_loop_thread: received byte 0x%02x\n", c)); slipif_rxbyte_input(netif, c); + } else { + sys_msleep(1); + // LWIP_DEBUGF(SLIP_DEBUG, ("slipif_loop_thread: no data, sleeping\n")); } +#endif } } #endif /* SLIP_USE_RX_THREAD */ @@ -341,12 +587,15 @@ slipif_init(struct netif *netif) { struct slipif_priv *priv; + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: initializing netif=%p\n", netif)); LWIP_ASSERT("netif != NULL", (netif != NULL)); priv = (struct slipif_priv *)mem_malloc(sizeof(struct slipif_priv)); if (priv == NULL) { + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: memory allocation failed\n")); return ERR_MEM; } + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: priv allocated at %p\n", priv)); /* store private data */ netif->state = priv; @@ -366,20 +615,38 @@ slipif_init(struct netif *netif) priv->state = SLIP_RECV_NORMAL; priv->i = 0; priv->recved = 0; +#if SLIP_RX_FROM_ISR + priv->rxpackets = NULL; // 确保接收队列初始化为空 + if (sys_mutex_new(&priv->rxqueue_mutex) != ERR_OK) { + LWIP_DEBUGF(SLIP_DEBUG, ("ERROR: slipif_init: failed to create rxqueue_mutex\n")); + mem_free(priv); + return ERR_MEM; + } +#endif + + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: netif configured, name=%c%c, flags=0x%x\n", + netif->name[0], netif->name[1], netif->flags)); /* initialize the serial device */ priv->sd = sio_open(SLIP_IFNUM); if (!priv->sd) { /* opening the serial device failed, free priv and return */ + printf("ERROR: slipif_init: sio_open failed for SLIP_IFNUM=%d\n", SLIP_IFNUM); +#if SLIP_RX_FROM_ISR + sys_mutex_free(&priv->rxqueue_mutex); +#endif mem_free(priv); return ERR_IF; } - + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: sio_open success, sd=%p\n", priv->sd)); #if SLIP_USE_RX_THREAD /* Create a thread to poll the serial device. */ + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: creating RX thread with stack=%d, prio=%d\n", + SLIP_RX_THREAD_STACKSIZE, SLIP_RX_THREAD_PRIO)); sys_thread_new(SLIP_RX_THREAD_NAME, slipif_loop_thread, netif, SLIP_RX_THREAD_STACKSIZE, SLIP_RX_THREAD_PRIO); #endif /* SLIP_USE_RX_THREAD */ + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: initialization completed successfully\n")); return ERR_OK; } @@ -394,6 +661,7 @@ slipif_poll(struct netif *netif) { struct slipif_priv *priv; u8_t c; + int read_count = 0; LWIP_ASSERT("netif != NULL", (netif != NULL)); LWIP_ASSERT("netif->state != NULL", (netif->state != NULL)); @@ -402,17 +670,92 @@ slipif_poll(struct netif *netif) while (sio_tryread(priv->sd, &c, 1) > 0) { slipif_rxbyte_input(netif, c); + read_count++; + } + + if (read_count > 0) { + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_poll: processed %d bytes\n", read_count)); } } #if SLIP_RX_FROM_ISR + +/** + * 检查接收队列的完整性 + * @param netif the lwip network interface structure for this slipif + * @return 1 if queue is valid, 0 if corrupted + */ +static int +slipif_check_rxqueue_integrity(struct netif *netif) +{ + struct slipif_priv *priv = (struct slipif_priv *)netif->state; + struct pbuf *p = priv->rxpackets; + u16_t count = 0; + const u16_t MAX_QUEUE_LENGTH = 100; // 防止无限循环 + + /* 注意:调用此函数时应该已经持有锁 */ + + while (p != NULL && count < MAX_QUEUE_LENGTH) { + /* 检查指针有效性 */ + if ((uintptr_t)p < 0x1000 || (uintptr_t)p > 0x7FFFFFFF) { + LWIP_DEBUGF(SLIP_DEBUG, ("ERROR: slipif_check_rxqueue_integrity: invalid pbuf pointer 0x%p\n", p)); + return 0; // 队列损坏 + } + + /* 检查 pbuf 结构有效性 */ + if (p->next != NULL && + ((uintptr_t)p->next < 0x1000 || (uintptr_t)p->next > 0x7FFFFFFF)) { + LWIP_DEBUGF(SLIP_DEBUG, ("ERROR: slipif_check_rxqueue_integrity: invalid next pointer 0x%p\n", p->next)); + return 0; // 链表损坏 + } + + p = p->next; + count++; + } + + if (count >= MAX_QUEUE_LENGTH) { + LWIP_DEBUGF(SLIP_DEBUG, ("ERROR: slipif_check_rxqueue_integrity: queue too long (%d), possible loop\n", count)); + return 0; // 队列过长,可能形成循环 + } + + return 1; // 队列完整 +} + +/** + * 清理损坏的接收队列 + * @param netif the lwip network interface structure for this slipif + */ +static void +slipif_cleanup_corrupted_rxqueue(struct netif *netif) +{ + struct slipif_priv *priv = (struct slipif_priv *)netif->state; + struct pbuf *p, *next; + + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_cleanup_corrupted_rxqueue: cleaning up corrupted queue\n")); + + /* 注意:调用此函数时应该已经持有锁 */ + + p = priv->rxpackets; + while (p != NULL) { + next = p->next; + if ((uintptr_t)p >= 0x1000 && (uintptr_t)p <= 0x7FFFFFFF) { + pbuf_free(p); // 只释放有效的 pbuf + } + p = next; + } + + priv->rxpackets = NULL; // 重置队列 + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_cleanup_corrupted_rxqueue: queue cleaned up\n")); +} + /** * Feeds the IP layer with incoming packets that were receive * by slipif_received_byte[s](). * * @param netif the lwip network interface structure for this slipif + * @return number of packets processed */ -void +u16_t slipif_process_rxqueue(struct netif *netif) { struct slipif_priv *priv; @@ -421,16 +764,78 @@ slipif_process_rxqueue(struct netif *netif) LWIP_ASSERT("netif->state != NULL", (netif->state != NULL)); priv = (struct slipif_priv *)netif->state; - - while (priv->rxpackets != NULL) { + // LWIP_DEBUGF(SLIP_DEBUG, ("slipif_process_rxqueue: attempting to acquire mutex\n")); + + /* 获取锁保护队列操作 */ + sys_mutex_lock(&priv->rxqueue_mutex); + + // LWIP_DEBUGF(SLIP_DEBUG, ("slipif_process_rxqueue: mutex acquired, rxpackets=%p\n", priv->rxpackets)); + + /* 检查队列完整性 */ + if (priv->rxpackets != NULL) { + if (!slipif_check_rxqueue_integrity(netif)) { + LWIP_DEBUGF(SLIP_DEBUG, ("ERROR: slipif_process_rxqueue: queue integrity check failed, cleaning up\n")); + slipif_cleanup_corrupted_rxqueue(netif); + sys_mutex_unlock(&priv->rxqueue_mutex); + return 0; // 返回0表示没有处理任何数据包 + } + } + + u16_t processed_count = 0; + const u16_t MAX_PACKETS_PER_CALL = 10; // 防止一次处理过多数据包 + + while (priv->rxpackets != NULL && processed_count < MAX_PACKETS_PER_CALL) { struct pbuf *p = priv->rxpackets; + + /* 验证当前 pbuf 的有效性 */ + if ((uintptr_t)p < 0x1000 || (uintptr_t)p > 0x7FFFFFFF) { + LWIP_DEBUGF(SLIP_DEBUG, ("ERROR: slipif_process_rxqueue: invalid pbuf pointer 0x%p, breaking\n", p)); + priv->rxpackets = NULL; // 重置队列 + break; + } + + /* 验证 pbuf->next 的有效性 */ + if (p->next != NULL && + ((uintptr_t)p->next < 0x1000 || (uintptr_t)p->next > 0x7FFFFFFF)) { + LWIP_DEBUGF(SLIP_DEBUG, ("ERROR: slipif_process_rxqueue: invalid pbuf->next pointer 0x%p, breaking\n", p->next)); + priv->rxpackets = NULL; // 重置队列 + break; + } + struct pbuf *q = p; priv->rxpackets = p->next; p->next = NULL; + + // LWIP_DEBUGF(SLIP_DEBUG, ("slipif_process_rxqueue: processing pbuf 0x%p, length=%d\n", q, q->tot_len)); + + /* 释放锁,避免在 netif->input 中长时间持有锁 */ + sys_mutex_unlock(&priv->rxqueue_mutex); + if (netif->input(q, netif) != ERR_OK) { + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_process_rxqueue: netif->input failed, freeing pbuf\n")); pbuf_free(q); + } else { + // LWIP_DEBUGF(SLIP_DEBUG, ("slipif_process_rxqueue: packet sent to IP layer successfully\n")); + } + + processed_count++; + + /* 重新获取锁继续处理队列 */ + if (priv->rxpackets != NULL && processed_count < MAX_PACKETS_PER_CALL) { + sys_mutex_lock(&priv->rxqueue_mutex); } } + + /* 确保锁被释放 */ + sys_mutex_unlock(&priv->rxqueue_mutex); + + if (processed_count >= MAX_PACKETS_PER_CALL) { + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_process_rxqueue: reached max packets limit (%d), will continue in next call\n", MAX_PACKETS_PER_CALL)); + } + + // LWIP_DEBUGF(SLIP_DEBUG, ("slipif_process_rxqueue: processed %d packets, rxpackets now %p\n", processed_count, priv->rxpackets)); + + return processed_count; // 返回处理的包数量 } /** @@ -447,15 +852,51 @@ slipif_rxbyte_enqueue(struct netif *netif, u8_t data) struct pbuf *p; struct slipif_priv *priv = (struct slipif_priv *)netif->state; + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_rxbyte_enqueue: processing byte 0x%02x\n", data)); + p = slipif_rxbyte(netif, data); if (p != NULL) { + /* 验证 pbuf 指针的有效性 */ + if ((uintptr_t)p < 0x1000 || (uintptr_t)p > 0x7FFFFFFF) { + LWIP_DEBUGF(SLIP_DEBUG, ("ERROR: slipif_rxbyte_enqueue: invalid pbuf pointer 0x%p\n", p)); + return; // 不处理无效指针 + } + + /* 验证 pbuf 结构的基本有效性 */ + if (p->next != NULL && + ((uintptr_t)p->next < 0x1000 || (uintptr_t)p->next > 0x7FFFFFFF)) { + LWIP_DEBUGF(SLIP_DEBUG, ("ERROR: slipif_rxbyte_enqueue: invalid pbuf chain pointer 0x%p\n", p->next)); + return; // 链表损坏,不处理 + } + /* Enqueue the packet. */ struct pbuf *q = p; - while (q->next != NULL) { + u16_t chain_count = 0; + const u16_t MAX_CHAIN_LENGTH = 10; // 防止无限循环 + + while (q->next != NULL && chain_count < MAX_CHAIN_LENGTH) { q = q->next; + chain_count++; + + /* 验证链表指针的有效性 */ + if ((uintptr_t)q < 0x1000 || (uintptr_t)q > 0x7FFFFFFF) { + LWIP_DEBUGF(SLIP_DEBUG, ("ERROR: slipif_rxbyte_enqueue: invalid pbuf chain pointer 0x%p\n", q)); + return; // 链表损坏,不处理 + } + } + + if (chain_count >= MAX_CHAIN_LENGTH) { + LWIP_DEBUGF(SLIP_DEBUG, ("ERROR: slipif_rxbyte_enqueue: pbuf chain too long (%d), dropping\n", chain_count)); + return; // 链表过长,不处理 } + + /* 获取锁保护队列操作 */ + sys_mutex_lock(&priv->rxqueue_mutex); q->next = priv->rxpackets; priv->rxpackets = p; + sys_mutex_unlock(&priv->rxqueue_mutex); + + LWIP_DEBUGF(SLIP_DEBUG, ("slipif_rxbyte_enqueue: enqueued pbuf 0x%p, rxpackets now 0x%p\n", p, priv->rxpackets)); } } diff --git a/code/sdk/zhihui/4g/cat1Service/CMakeLists.txt b/code/sdk/zhihui/4g/cat1Service/CMakeLists.txt index 35ad65241..8deef22f4 100644 --- a/code/sdk/zhihui/4g/cat1Service/CMakeLists.txt +++ b/code/sdk/zhihui/4g/cat1Service/CMakeLists.txt @@ -11,7 +11,6 @@ set(PUBLIC_HEADER set(PRIVATE_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/Service -${CMAKE_CURRENT_SOURCE_DIR}/slip ${ROOT_DIR}/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/include ${ROOT_DIR}/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include # ${ROOT_DIR}/open_source/openharmony/base/security/huks/interfaces/innerkits/huks_standard/main/include @@ -31,9 +30,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/Service/cat1_utils.c ${CMAKE_CURRENT_SOURCE_DIR}/Service/api_shell.c ${CMAKE_CURRENT_SOURCE_DIR}/Service/http_client.c ${CMAKE_CURRENT_SOURCE_DIR}/Service/sntp.c -${CMAKE_CURRENT_SOURCE_DIR}/slip/asio.c -${CMAKE_CURRENT_SOURCE_DIR}/slip/slipif.c -${CMAKE_CURRENT_SOURCE_DIR}/slip/uart_slip.c +# ${CMAKE_CURRENT_SOURCE_DIR}/slip/uart_slip.c ) # message(WARNING "lwipport_SRCS" ${lwipport_SRCS} "\n") # message(WARNING "PUBLIC_HEADER" ${PUBLIC_HEADER} "\n") diff --git a/code/sdk/zhihui/4g/cat1Service/Service/cat1_ctl.c b/code/sdk/zhihui/4g/cat1Service/Service/cat1_ctl.c index 8117977e1..60e74191d 100644 --- a/code/sdk/zhihui/4g/cat1Service/Service/cat1_ctl.c +++ b/code/sdk/zhihui/4g/cat1Service/Service/cat1_ctl.c @@ -56,7 +56,7 @@ static ctl_pin_4g_t g_cat1_ctl_pins={ 1, S_AGPIO_L30,//wakemodem_pin 1, - #elif defined(BOARD_W9) + #elif defined(BOARD_W9) || defined(BOARD_N9) S_AGPIO_L17, //bat_pin 1, S_AGPIO_L23, // pwr_pin @@ -106,7 +106,11 @@ uint32_t cat1_api_cat1_bat_on(uint32_t pwron) pin_t en_pin = g_cat1_ctl_pins.bat_pin; uint8_t en_value = g_cat1_ctl_pins.bat_pin_en_value; - if (en_pin == PIN_NONE) return 0xff; + if (en_pin == PIN_NONE) + { + printf("cat1_api_cat1_bat_on en_pin is none\r\n"); + return 0xff; + } if( pwron == 0) { @@ -137,7 +141,11 @@ uint32_t cat1_api_cat1_power_on(uint32_t pwron) pin_t en_pin = g_cat1_ctl_pins.pwr_pin; uint8_t en_value = g_cat1_ctl_pins.pwr_pin_en_value; - if (en_pin == PIN_NONE) return 0xff; + if (en_pin == PIN_NONE) + { + printf("cat1_api_cat1_power_on en_pin is none\r\n"); + return 0xff; + } if( pwron == 0) { uapi_gpio_set_dir(en_pin, GPIO_DIRECTION_OUTPUT); @@ -168,7 +176,11 @@ uint32_t cat1_api_cat1_reset(uint32_t pwron) pin_t en_pin = g_cat1_ctl_pins.reset_pin; uint8_t en_value = g_cat1_ctl_pins.reset_pin_en_value; - if (en_pin == PIN_NONE) return 0xff; + if (en_pin == PIN_NONE) + { + printf("cat1_api_cat1_reset en_pin is none\r\n"); + return 0xff; + } if( pwron == 0) { @@ -198,13 +210,24 @@ uint32_t cat1_api_cat1_reset(uint32_t pwron) bool cat1_api_is_cat1_enabled(void) { + #if defined(BOARD_W9) || defined(BOARD_N9) + pin_t en_pin = g_cat1_ctl_pins.bat_pin; + uint8_t en_value = g_cat1_ctl_pins.bat_pin_en_value; + #else pin_t en_pin = g_cat1_ctl_pins.pwr_pin; uint8_t en_value = g_cat1_ctl_pins.pwr_pin_en_value; - if (en_pin == PIN_NONE) return false; + #endif + if (en_pin == PIN_NONE) + { + printf("cat1_api_is_cat1_enabled en_pin is none\r\n"); + return false; + } if ( en_value == uapi_gpio_get_output_val(en_pin)) { + printf("cat1_api_is_cat1_enabled en_value is %d\r\n",en_value); return true; }else{ + printf("cat1_api_is_cat1_enabled en_value is %d\r\n",en_value); return false; } } @@ -321,7 +344,11 @@ void cat1_api_wakeup_cat1(uint8_t wakeup) pin_t en_pin = g_cat1_ctl_pins.wakemodem_pin; uint8_t en_value = g_cat1_ctl_pins.wakemodem_pin_en_value; uint8_t wake=wakeup; - if (en_pin == PIN_NONE) return ; + if (en_pin == PIN_NONE) + { + printf("cat1_api_wakeup_cat1 en_pin is none\r\n"); + return ; + } if (cat1_keepon_wakeup == 1) { @@ -330,23 +357,22 @@ void cat1_api_wakeup_cat1(uint8_t wakeup) uapi_gpio_set_dir(en_pin, GPIO_DIRECTION_OUTPUT); if( wake == 1) { - // cat1_print_warning("wakeup cat1\n"); + cat1_print_warning("wakeup cat1\n"); if(en_value != uapi_gpio_get_output_val(en_pin)) { uapi_gpio_set_val(en_pin, en_value); LOS_Mdelay(100); //第一次唤醒 Cat1 需要延时等其正常运行 } - // wstp_cat1_print_dbg("wakeup Cat1! L30 high \r\n"); }else{ - // cat1_print_warning("sleep cat1\n"); + cat1_print_warning("sleep cat1\n"); if(en_value == uapi_gpio_get_output_val(en_pin)) { if(en_value) uapi_gpio_set_val(en_pin, GPIO_LEVEL_LOW); else uapi_gpio_set_val(en_pin, GPIO_LEVEL_HIGH); - } + } // wstp_cat1_print_dbg("sleep Cat1! L30 low\r\n"); } diff --git a/code/sdk/zhihui/4g/cat1Service/Service/cat1_server.c b/code/sdk/zhihui/4g/cat1Service/Service/cat1_server.c index 658a6d6a0..a14cfa9f7 100644 --- a/code/sdk/zhihui/4g/cat1Service/Service/cat1_server.c +++ b/code/sdk/zhihui/4g/cat1Service/Service/cat1_server.c @@ -54,7 +54,6 @@ extern "C" { #include "errcode.h" #include "errno.h" -#include "uart_slip.h" #include "cat1_server.h" #include "cat1_server_hal.h" #include "cat1_ctl.h" @@ -1606,7 +1605,6 @@ void cat1_server_task(void *pvParameters) #include "soc_osal.h" #include "common_def.h" #include "los_printf.h" -#include "uart_slip.h" #include "cat1_tcpServer.h" #define CAT1_SERVICE_TASK_SIZE (0x800*5) #define CAT1_SERVICE_TASK_PRIO 5 @@ -1636,7 +1634,8 @@ errcode_t cat1_server_init(void) cat1_api_uart_init(); - netif_service_init(); + // netif_service_init(); + slip_test_init(); errcode_t ret=cat1_create_osThread_custom(&taskcfg); if(ret != ERRCODE_SUCC) diff --git a/code/sdk/zhihui/4g/cat1Service/Service/cat1_tcpServer.c b/code/sdk/zhihui/4g/cat1Service/Service/cat1_tcpServer.c index 6a7e83605..2c8a957eb 100644 --- a/code/sdk/zhihui/4g/cat1Service/Service/cat1_tcpServer.c +++ b/code/sdk/zhihui/4g/cat1Service/Service/cat1_tcpServer.c @@ -49,7 +49,7 @@ extern "C" { #include "errcode.h" #include "errno.h" -#include "uart_slip.h" +// #include "uart_slip.h" #include "cat1_server.h" #include "cat1_server_hal.h" #include "cat1_ctl.h" @@ -206,7 +206,7 @@ void ble_tcp_send_msg_toCat1(uint8_t mode,uint8_t cmd,char *content) { if (!cat1_api_is_cat1_enabled()) { - cat1_print_err("Error cat1 poweroff skipp send data\n"); + cat1_print_err("Error cat1 poweroff tcp skipp send data\n"); return ; } cat1_api_wakeup_cat1(1); diff --git a/code/sdk/zhihui/4g/cat1Service/slip/asio.c b/code/sdk/zhihui/4g/cat1Service/slip/asio.c deleted file mode 100644 index 4912c8050..000000000 --- a/code/sdk/zhihui/4g/cat1Service/slip/asio.c +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (c) 2001-2004 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - */ - -/* - * This is the interface to the platform specific serial IO module - * It needs to be implemented by those platforms which need SLIP or PPP - */ -#include -#include -#include -// #include "freertos/FreeRTOS.h" -// #include "freertos/task.h" - -#include "driver/uart.h" -#include "lwip/sio.h" - -#include "uart.h" -#include "osal_debug.h" -#include "osal_addr.h" -#include "osal_interrupt.h" -#include "securec.h" -#include "common_def.h" - -#include "tcxo.h" -#include "osal_debug.h" - - -#define SLIP_UART_SEND_BUFFER_MAX (64) -#define SLIP_UART_RX_BUFF_SIZE (64) - - -struct slip_send_buffer_t { - uint8_t buffer[SLIP_UART_SEND_BUFFER_MAX+1]; - int len; -}; - -struct slip_send_buffer_t slip_send_buffer; - -/* The following functions can be defined to something else in your cc.h file - or be implemented in your custom sio.c file. */ - - - -#if defined(CONFIG_UART_SUPPORT_DMA) -#include "hal_dma.h" -#endif /* CONFIG_UART_SUPPORT_DMA */ - - - - - -typedef enum { - UART_TRANSFER_MODE_POLL, - UART_TRANSFER_MODE_INT, - UART_TRANSFER_MODE_DMA -} uart_transfer_mode_t; - -uint8_t g_uart_rx_buff[SLIP_UART_RX_BUFF_SIZE] = { 0 }; -static uint32_t g_uart_read_count = 0; -static uint32_t g_test_uart_read_int_num = 0; -uart_buffer_config_t g_uart_buffer_config = { - .rx_buffer = g_uart_rx_buff, - .rx_buffer_size = SLIP_UART_RX_BUFF_SIZE -}; -uart_bus_t g_uart_bus = UART_BUS_0; -static void uart_slip_read_int_handler(const void *buffer, uint16_t length, bool error) -{ - unused(error); - osal_printk("uart_slip_read_int_handler length=%x\r\n", length); - - // do_uart_slip_cmd(0x01,buffer,length); - -} -static int32_t slip_uart_config(void) -{ - - bool tx_dma_enable = false; - bool rx_dma_enable = false; - uart_attr_t attr = { 0 }; - - uint32_t param_index = 0; - uart_bus_t bus = UART_BUS_0; - - uapi_uart_deinit(bus); - - attr.baud_rate = 921600; - attr.data_bits = UART_DATA_BIT_8; - attr.stop_bits = UART_STOP_BIT_1; - attr.parity = UART_PARITY_NONE; - - osal_printk("uapi_uart_init bus=%d baud_rate=%d, data_bits=%d, stop_bits=%d, parity=%d\r\n", bus, attr.baud_rate, \ - attr.data_bits, attr.stop_bits, attr.parity); - - uart_pin_config_t pin_config = { - .tx_pin = S_MGPIO19, - .rx_pin = S_MGPIO20, - .cts_pin = PIN_NONE, - .rts_pin = PIN_NONE - }; - - uart_extra_attr_t extra_attr = { - .tx_dma_enable = tx_dma_enable, - .tx_int_threshold = 0, - .rx_dma_enable = rx_dma_enable, - .rx_int_threshold = 0 - }; - - errcode_t errcode = uapi_uart_init(bus, &pin_config, &attr, &extra_attr, &g_uart_buffer_config); - osal_printk("uapi_uart_init ret=%x\r\n", errcode); - if (errcode != ERRCODE_SUCC) { - return ERRCODE_UART_INIT_TRX_STATE_FAIL; - } - g_uart_bus = bus; - - - errcode = uapi_uart_register_rx_callback(g_uart_bus, UART_RX_CONDITION_FULL_OR_SUFFICIENT_DATA_OR_IDLE, - SLIP_UART_RX_BUFF_SIZE, uart_slip_read_int_handler); - - osal_printk("uapi_uart_register_rx_callback ret=%x\r\n", errcode); - - if (errcode != ERRCODE_SUCC) { - return ERRCODE_UART_INIT_TRX_STATE_FAIL; - } - return ERRCODE_SUCC; -} - -static int slip_uart_write(uint8_t *tx_buff,uint32_t size) -{ - - return uapi_uart_write(g_uart_bus, tx_buff, size,0); - -} -uint32_t slip_uart_read( uint8_t *data, uint32_t len) -{ - return uapi_uart_read(g_uart_bus,data,len,0); -} -/** - * Opens a serial device for communication. - * - * @param devnum device number - * @return handle to serial device if successful, NULL otherwise - */ -sio_fd_t sio_open(u8_t devnum) -{ - memset(&slip_send_buffer, 0x00, sizeof(struct slip_send_buffer_t)); - - // slip_uart_config(); - return 1; -} - -/** - * Sends a single character to the serial device. - * - * @param c character to send - * @param fd serial device handle - * - * @note This function will block until the character can be sent. - */ -void sio_send(u8_t c, sio_fd_t fd) -{ - // slip_uart_write( (const char *)&c, 1); - //uart_write_bytes(UART_NUM_0, (const char *)&c, 1); - slip_send_buffer.buffer[slip_send_buffer.len] = c; - slip_send_buffer.len += 1; - if( slip_send_buffer.len >= (SLIP_UART_SEND_BUFFER_MAX) ) { - //printf("send2 data len = %d\n", slip_send_buffer.len); - // uart_write_bytes(UART_NUM_0, (const char *)slip_send_buffer.buffer, slip_send_buffer.len); - slip_uart_write((const char *)slip_send_buffer.buffer, slip_send_buffer.len); - slip_send_buffer.len = 0; - } -} - -void sio_send_all(u8_t c, sio_fd_t fd) -{ - // slip_uart_write( (const char *)&c, 1); - //uart_write_bytes(UART_NUM_0, (const char *)&c, 1); - if( slip_send_buffer.len > 0 ) { - //printf("send data len = %d\n", slip_send_buffer.len); - slip_uart_write((const char *)slip_send_buffer.buffer, slip_send_buffer.len); - // uart_write_bytes(UART_NUM_0, (const char *)slip_send_buffer.buffer, slip_send_buffer.len); - slip_send_buffer.len = 0; - } -} - -/** - * Receives a single character from the serial device. - * - * @param fd serial device handle - * - * @note This function will block until a character is received. - */ -u8_t sio_recv(sio_fd_t fd) -{ - u8_t tmp = 0; - slip_uart_read(&tmp,1); - return tmp; -} - -u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len) -{ - return slip_uart_read(data,len); -} \ No newline at end of file diff --git a/code/sdk/zhihui/4g/cat1Service/slip/slipif.c b/code/sdk/zhihui/4g/cat1Service/slip/slipif.c deleted file mode 100644 index f91f234b0..000000000 --- a/code/sdk/zhihui/4g/cat1Service/slip/slipif.c +++ /dev/null @@ -1,597 +0,0 @@ -/** - * @file - * SLIP Interface - * - */ - -/* - * Copyright (c) 2001-2004 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file is built upon the file: src/arch/rtxc/netif/sioslip.c - * - * Author: Magnus Ivarsson - * Simon Goldschmidt - */ - - -/** - * @defgroup slipif SLIP - * @ingroup netifs - * - * This is an arch independent SLIP netif. The specific serial hooks must be - * provided by another file. They are sio_open, sio_read/sio_tryread and sio_send - * - * Usage: This netif can be used in three ways:\n - * 1) For NO_SYS==0, an RX thread can be used which blocks on sio_read() - * until data is received.\n - * 2) In your main loop, call slipif_poll() to check for new RX bytes, - * completed packets are fed into netif->input().\n - * 3) Call slipif_received_byte[s]() from your serial RX ISR and - * slipif_process_rxqueue() from your main loop. ISR level decodes - * packets and puts completed packets on a queue which is fed into - * the stack from the main loop (needs SYS_LIGHTWEIGHT_PROT for - * pbuf_alloc to work on ISR level!). - * - */ -#include -#include "netif/slipif.h" -#include "lwip/opt.h" - -#include "lwip/def.h" -#include "lwip/pbuf.h" -#include "lwip/stats.h" -#include "lwip/snmp.h" -#include "lwip/sys.h" -#include "lwip/sio.h" - -#define SLIP_END 0xC0 /* 0300: start and end of every packet */ -#define SLIP_ESC 0xDB /* 0333: escape start (one byte escaped data follows) */ -#define SLIP_ESC_END 0xDC /* 0334: following escape: original byte is 0xC0 (END) */ -#define SLIP_ESC_ESC 0xDD /* 0335: following escape: original byte is 0xDB (ESC) */ - -/** Maximum packet size that is received by this netif */ -#ifndef SLIP_MAX_SIZE -#define SLIP_MAX_SIZE 1500 -#endif - -/** Define this to the interface speed for SNMP - * (sio_fd is the sio_fd_t returned by sio_open). - * The default value of zero means 'unknown'. - */ -#ifndef SLIP_SIO_SPEED -#define SLIP_SIO_SPEED(sio_fd) 0 -#endif - -enum slipif_recv_state { - SLIP_RECV_NORMAL, - SLIP_RECV_ESCAPE -}; - -struct slipif_priv { - sio_fd_t sd; - /* q is the whole pbuf chain for a packet, p is the current pbuf in the chain */ - struct pbuf *p, *q; - u8_t state; - u16_t i, recved; -#if SLIP_RX_FROM_ISR - struct pbuf *rxpackets; -#endif -}; -struct slipif_priv *priv = NULL; -/** - * Send a pbuf doing the necessary SLIP encapsulation - * - * Uses the serial layer's sio_send() - * - * @param netif the lwip network interface structure for this slipif - * @param p the pbuf chain packet to send - * @return always returns ERR_OK since the serial layer does not provide return values - */ -static err_t -slipif_output(struct netif *netif, struct pbuf *p) -{ - struct slipif_priv *priv; - struct pbuf *q; - u16_t i; - u8_t c; - - LWIP_ASSERT("netif != NULL", (netif != NULL)); - LWIP_ASSERT("netif->state != NULL", (netif->state != NULL)); - LWIP_ASSERT("p != NULL", (p != NULL)); - - LWIP_DEBUGF(SLIP_DEBUG, ("slipif_output: sending %"U16_F" bytes\n", p->tot_len)); - //printf("slipif_output: sending %d bytes\n", p->tot_len); - priv = (struct slipif_priv *)netif->state; - - /* Send pbuf out on the serial I/O device. */ - /* Start with packet delimiter. */ - sio_send(SLIP_END, priv->sd); - - for (q = p; q != NULL; q = q->next) { - for (i = 0; i < q->len; i++) { - c = ((u8_t *)q->payload)[i]; - switch (c) { - case SLIP_END: - /* need to escape this byte (0xC0 -> 0xDB, 0xDC) */ - sio_send(SLIP_ESC, priv->sd); - sio_send(SLIP_ESC_END, priv->sd); - break; - case SLIP_ESC: - /* need to escape this byte (0xDB -> 0xDB, 0xDD) */ - sio_send(SLIP_ESC, priv->sd); - sio_send(SLIP_ESC_ESC, priv->sd); - break; - default: - /* normal byte - no need for escaping */ - sio_send(c, priv->sd); - break; - } - } - } - /* End with packet delimiter. */ - sio_send(SLIP_END, priv->sd); - extern void sio_send_all(sio_fd_t fd); - sio_send_all(priv->sd); - return ERR_OK; -} - -#if LWIP_IPV4 -/** - * Send a pbuf doing the necessary SLIP encapsulation - * - * Uses the serial layer's sio_send() - * - * @param netif the lwip network interface structure for this slipif - * @param p the pbuf chain packet to send - * @param ipaddr the ip address to send the packet to (not used for slipif) - * @return always returns ERR_OK since the serial layer does not provide return values - */ -static err_t -slipif_output_v4(struct netif *netif, struct pbuf *p, const ip4_addr_t *ipaddr) -{ - LWIP_UNUSED_ARG(ipaddr); - return slipif_output(netif, p); -} -#endif /* LWIP_IPV4 */ - -#if LWIP_IPV6 -/** - * Send a pbuf doing the necessary SLIP encapsulation - * - * Uses the serial layer's sio_send() - * - * @param netif the lwip network interface structure for this slipif - * @param p the pbuf chain packet to send - * @param ipaddr the ip address to send the packet to (not used for slipif) - * @return always returns ERR_OK since the serial layer does not provide return values - */ -static err_t -slipif_output_v6(struct netif *netif, struct pbuf *p, const ip6_addr_t *ipaddr) -{ - LWIP_UNUSED_ARG(ipaddr); - return slipif_output(netif, p); -} -#endif /* LWIP_IPV6 */ - -/** - * Handle the incoming SLIP stream character by character - * - * @param netif the lwip network interface structure for this slipif - * @param c received character (multiple calls to this function will - * return a complete packet, NULL is returned before - used for polling) - * @return The IP packet when SLIP_END is received - */ -static struct pbuf * -slipif_rxbyte(struct netif *netif, u8_t c) -{ - struct slipif_priv *priv; - struct pbuf *t; - - LWIP_ASSERT("netif != NULL", (netif != NULL)); - LWIP_ASSERT("netif->state != NULL", (netif->state != NULL)); - - priv = (struct slipif_priv *)netif->state; - - switch (priv->state) { - case SLIP_RECV_NORMAL: - switch (c) { - case SLIP_END: - if (priv->recved > 0) { - /* Received whole packet. */ - /* Trim the pbuf to the size of the received packet. */ - pbuf_realloc(priv->q, priv->recved); - - LINK_STATS_INC(link.recv); - - LWIP_DEBUGF(SLIP_DEBUG, ("slipif: Got packet (%"U16_F" bytes)\n", priv->recved)); - t = priv->q; - priv->p = priv->q = NULL; - priv->i = priv->recved = 0; - return t; - } - return NULL; - case SLIP_ESC: - priv->state = SLIP_RECV_ESCAPE; - return NULL; - default: - break; - } /* end switch (c) */ - break; - case SLIP_RECV_ESCAPE: - /* un-escape END or ESC bytes, leave other bytes - (although that would be a protocol error) */ - switch (c) { - case SLIP_ESC_END: - c = SLIP_END; - break; - case SLIP_ESC_ESC: - c = SLIP_ESC; - break; - default: - break; - } - priv->state = SLIP_RECV_NORMAL; - break; - default: - break; - } /* end switch (priv->state) */ - - /* byte received, packet not yet completely received */ - if (priv->p == NULL) { - /* allocate a new pbuf */ - LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: alloc\n")); -// priv->p = pbuf_alloc(PBUF_LINK, (PBUF_POOL_BUFSIZE - PBUF_LINK_HLEN - PBUF_LINK_ENCAPSULATION_HLEN), PBUF_RAM); - priv->p = pbuf_alloc(PBUF_LINK, (PBUF_POOL_BUFSIZE - PBUF_LINK_HLEN - PBUF_LINK_ENCAPSULATION_HLEN), PBUF_POOL); - - if (priv->p == NULL) { - LINK_STATS_INC(link.drop); - LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: no new pbuf! (DROP)\n")); - /* don't process any further since we got no pbuf to receive to */ - return NULL; - } - - if (priv->q != NULL) { - /* 'chain' the pbuf to the existing chain */ - pbuf_cat(priv->q, priv->p); - } else { - /* p is the first pbuf in the chain */ - priv->q = priv->p; - } - } - - /* this automatically drops bytes if > SLIP_MAX_SIZE */ - if ((priv->p != NULL) && (priv->recved <= SLIP_MAX_SIZE)) { - ((u8_t *)priv->p->payload)[priv->i] = c; - priv->recved++; - priv->i++; - if (priv->i >= priv->p->len) { - /* on to the next pbuf */ - priv->i = 0; - if (priv->p->next != NULL && priv->p->next->len > 0) { - /* p is a chain, on to the next in the chain */ - priv->p = priv->p->next; - } else { - /* p is a single pbuf, set it to NULL so next time a new - * pbuf is allocated */ - priv->p = NULL; - } - } - } - return NULL; -} - -/** Like slipif_rxbyte, but passes completed packets to netif->input - * - * @param netif The lwip network interface structure for this slipif - * @param c received character - */ -static void -slipif_rxbyte_input(struct netif *netif, u8_t c) -{ - struct pbuf *p; - p = slipif_rxbyte(netif, c); - if (p != NULL) { - if (netif->input(p, netif) != ERR_OK) { - pbuf_free(p); - } - } -} - -#if SLIP_USE_RX_THREAD -/** - * The SLIP input thread. - * - * Feed the IP layer with incoming packets - * - * @param nf the lwip network interface structure for this slipif - */ -void -slipif_loop_thread(void *nf) -{ - u8_t c; - struct netif *netif = (struct netif *)nf; - struct slipif_priv *priv = (struct slipif_priv *)netif->state; - LWIP_DEBUGF(SLIP_DEBUG, ("slipif_loop_thread !\n")); - - while (1) { - if (sio_read(priv->sd, &c, 1) > 0) { - slipif_rxbyte_input(netif, c); - } - } -} -#endif /* SLIP_USE_RX_THREAD */ - -/** - * @ingroup slipif - * SLIP netif initialization - * - * Call the arch specific sio_open and remember - * the opened device in the state field of the netif. - * - * @param netif the lwip network interface structure for this slipif - * @return ERR_OK if serial line could be opened, - * ERR_MEM if no memory could be allocated, - * ERR_IF is serial line couldn't be opened - * - * @note If netif->state is interpreted as an u8_t serial port number. - * - */ - -#if SLIP_USE_RX_THREAD -#define SLIP_CMD_TASK_MSG_COUNT 16 -#define SLIP_CMD_TASK_SIZE 0x100 -#define SLIP_CMD_TASK_PRIO 5 -#include "soc_osal.h" -#endif -err_t -slipif_init(struct netif *netif) -{ - u8_t sio_num; - - LWIP_ASSERT("slipif needs an input callback", netif->input != NULL); - - /* netif->state contains serial port number */ - sio_num = LWIP_PTR_NUMERIC_CAST(u8_t, netif->state); - - LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: netif->num=%"U16_F"\n", (u16_t)sio_num)); - - /* Allocate private data */ - if( priv == NULL ) { - priv = (struct slipif_priv *)mem_malloc(sizeof(struct slipif_priv)); - if (!priv) { - LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: priv no mem\n")); - return ERR_MEM; - } - } - memset(priv, 0x00, sizeof(struct slipif_priv)); - - netif->name[0] = 's'; - netif->name[1] = 'l'; -#if LWIP_IPV4 - netif->output = slipif_output_v4; -#endif /* LWIP_IPV4 */ -#if LWIP_IPV6 - netif->output_ip6 = slipif_output_v6; -#endif /* LWIP_IPV6 */ - netif->mtu = SLIP_MAX_SIZE; - - /* Try to open the serial port. */ - priv->sd = sio_open(sio_num); - if (!priv->sd) { - /* Opening the serial port failed. */ - LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: sio_open failed!\n")); - - mem_free(priv); - return ERR_IF; - } - - /* Initialize private data */ - priv->p = NULL; - priv->q = NULL; - priv->state = SLIP_RECV_NORMAL; - priv->i = 0; - priv->recved = 0; -#if SLIP_RX_FROM_ISR - priv->rxpackets = NULL; -#endif - - netif->state = priv; - - // LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: MIB2_INIT_NETIF !\n")); - - /* initialize the snmp variables and counters inside the struct netif */ - MIB2_INIT_NETIF(netif, snmp_ifType_slip, SLIP_SIO_SPEED(priv->sd)); - -// #if SLIP_USE_RX_THREAD -// /* Create a thread to poll the serial line. */ -// sys_thread_new(SLIPIF_THREAD_NAME, slipif_loop_thread, netif, -// SLIPIF_THREAD_STACKSIZE, SLIPIF_THREAD_PRIO); -// #endif /* SLIP_USE_RX_THREAD */ - LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: 1 !\n")); - -#if SLIP_USE_RX_THREAD - - // osal_task *task_handle = osal_kthread_create((osal_kthread_handler)slipif_loop_thread, netif, - // "uart_slip_service", SLIP_CMD_TASK_SIZE); - // if (task_handle == NULL) { - // LWIP_DEBUGF(SLIP_DEBUG, ("create uart_slip service thread fail!\r\n")); - // return ERR_ABRT; - // } - - // osal_kthread_set_priority(task_handle, SLIP_CMD_TASK_PRIO); - - -#endif - - LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: success !\n")); - - return ERR_OK; -} - -/** - * @ingroup slipif - * Polls the serial device and feeds the IP layer with incoming packets. - * - * @param netif The lwip network interface structure for this slipif - */ -void -slipif_poll(struct netif *netif) -{ - u8_t c; - struct slipif_priv *priv; - - LWIP_ASSERT("netif != NULL", (netif != NULL)); - LWIP_ASSERT("netif->state != NULL", (netif->state != NULL)); - - priv = (struct slipif_priv *)netif->state; - - while (sio_tryread(priv->sd, &c, 1) > 0) { - slipif_rxbyte_input(netif, c); - } -} - -#if SLIP_RX_FROM_ISR -/** - * @ingroup slipif - * Feeds the IP layer with incoming packets that were receive - * - * @param netif The lwip network interface structure for this slipif - */ -void -slipif_process_rxqueue(struct netif *netif) -{ - struct slipif_priv *priv; - SYS_ARCH_DECL_PROTECT(old_level); - - LWIP_ASSERT("netif != NULL", (netif != NULL)); - LWIP_ASSERT("netif->state != NULL", (netif->state != NULL)); - - priv = (struct slipif_priv *)netif->state; - - SYS_ARCH_PROTECT(old_level); - while (priv->rxpackets != NULL) { - struct pbuf *p = priv->rxpackets; -#if SLIP_RX_QUEUE - /* dequeue packet */ - struct pbuf *q = p; - while ((q->len != q->tot_len) && (q->next != NULL)) { - q = q->next; - } - priv->rxpackets = q->next; - q->next = NULL; -#else /* SLIP_RX_QUEUE */ - priv->rxpackets = NULL; -#endif /* SLIP_RX_QUEUE */ - SYS_ARCH_UNPROTECT(old_level); - if (netif->input(p, netif) != ERR_OK) { - pbuf_free(p); - } - SYS_ARCH_PROTECT(old_level); - } - SYS_ARCH_UNPROTECT(old_level); -} - -/** Like slipif_rxbyte, but queues completed packets. - * - * @param netif The lwip network interface structure for this slipif - * @param data Received serial byte - */ -static void -slipif_rxbyte_enqueue(struct netif *netif, u8_t data) -{ - struct pbuf *p; - struct slipif_priv *priv = (struct slipif_priv *)netif->state; - SYS_ARCH_DECL_PROTECT(old_level); - - p = slipif_rxbyte(netif, data); - if (p != NULL) { - SYS_ARCH_PROTECT(old_level); - if (priv->rxpackets != NULL) { -#if SLIP_RX_QUEUE - /* queue multiple pbufs */ - struct pbuf *q = p; - while (q->next != NULL) { - q = q->next; - } - q->next = p; - } else { -#else /* SLIP_RX_QUEUE */ - pbuf_free(priv->rxpackets); - } - { -#endif /* SLIP_RX_QUEUE */ - priv->rxpackets = p; - } - SYS_ARCH_UNPROTECT(old_level); - } -} - -/** - * @ingroup slipif - * Process a received byte, completed packets are put on a queue that is - * fed into IP through slipif_process_rxqueue(). - * - * This function can be called from ISR if SYS_LIGHTWEIGHT_PROT is enabled. - * - * @param netif The lwip network interface structure for this slipif - * @param data received character - */ -void -slipif_received_byte(struct netif *netif, u8_t data) -{ - LWIP_ASSERT("netif != NULL", (netif != NULL)); - LWIP_ASSERT("netif->state != NULL", (netif->state != NULL)); - slipif_rxbyte_enqueue(netif, data); -} - -/** - * @ingroup slipif - * Process multiple received byte, completed packets are put on a queue that is - * fed into IP through slipif_process_rxqueue(). - * - * This function can be called from ISR if SYS_LIGHTWEIGHT_PROT is enabled. - * - * @param netif The lwip network interface structure for this slipif - * @param data received character - * @param len Number of received characters - */ -void -slipif_received_bytes(struct netif *netif, u8_t *data, u8_t len) -{ - u8_t i; - u8_t *rxdata = data; - LWIP_ASSERT("netif != NULL", (netif != NULL)); - LWIP_ASSERT("netif->state != NULL", (netif->state != NULL)); - - - for (i = 0; i < len; i++, rxdata++) { - //slipif_rxbyte_enqueue(netif, *rxdata); - slipif_rxbyte_input(netif, *rxdata); - } -} -#endif /* SLIP_RX_FROM_ISR */ diff --git a/code/sdk/zhihui/4g/cat1Service/slip/uart_slip.c b/code/sdk/zhihui/4g/cat1Service/slip/uart_slip.c deleted file mode 100644 index d49ba64de..000000000 --- a/code/sdk/zhihui/4g/cat1Service/slip/uart_slip.c +++ /dev/null @@ -1,197 +0,0 @@ -// Copyright 2018-2025 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include -#include -#include "driver/uart.h" - -#include "lwip/ip.h" -#include "lwip/netif.h" -#include "netif/slipif.h" -#include "lwip/init.h" -#include "lwip/inet_chksum.h" - -#include "pinctrl.h" -#include "debug_print.h" -#include "soc_osal.h" -#include "tcxo.h" -#include "irmalloc.h" -#include "errcode.h" -#include "common_def.h" -#include "cat1_log.h" -#include "thread_init.h" -struct netif sl_netif; - -#define UART_SLIP_CMD_MSG_READ_DATA 0x01 -#define UART_SLIP_CMD_MSG_FLUSH_DATA 0x02 -static unsigned long g_slip_cmd_queue= 0xFFFFFFFF; -#define MAX_BUFFER_SIZE (128) -typedef struct { - uint8_t cmd; - uint32_t size; - uint8_t *buffer; -} slip_uart_cmd_t; -void do_uart_net_cmd(int cmd,uint8_t *buffer,uint32_t size) -{ - int ret; - - slip_uart_cmd_t mail = {0}; - - mail.buffer = osal_kmalloc(size+1, OSAL_GFP_KERNEL); - if (mail.buffer == NULL) { - cat1_print_err("uart message buffer memory alloc fail, length is %d "NEWLINE, size); - return; - } - memset_s(mail.buffer,size+1,0,size+1); - memcpy_s(mail.buffer,MAX_BUFFER_SIZE,buffer,size); - mail.cmd = cmd; - mail.size = size; - // unsigned int quesize=osal_msg_queue_get_msg_num(g_slip_cmd_queue); - // cat1_print_err("do_uart_net_cmd quesize %d\n",quesize); - ret = osal_msg_queue_write_copy(g_slip_cmd_queue, (void *)&mail, - sizeof(slip_uart_cmd_t), 0); - if (ret != OSAL_SUCCESS) { - cat1_print_err("Error uart_net cmd msg %d send failed! err=0x%02X!"NEWLINE,cmd, ret); - } - -} - -static void uart_event_task(void const *arg) -{ - unused(arg); - int32_t ret; - slip_uart_cmd_t mail; - uint32_t msgsize = (uint32_t)sizeof(slip_uart_cmd_t); - - ret = user_netif_init(); - cat1_print_info("user_netif_init ret=0x%02X! \r\n",ret); - - while (1) { - - (void)memset_s(&mail, sizeof(slip_uart_cmd_t), 0, sizeof(slip_uart_cmd_t)); - - ret = osal_msg_queue_read_copy(g_slip_cmd_queue, (void *)&mail, &msgsize, - OSAL_MSGQ_WAIT_FOREVER); - if (ret != OSAL_SUCCESS) { - continue; - } - - if (mail.cmd == UART_SLIP_CMD_MSG_READ_DATA) { - - // cat1_print_dbg("recv size=%d! %s \r\n",mail.size,mail.buffer); - slipif_received_bytes(&sl_netif, mail.buffer, mail.size); - // slipif_process_rxqueue(&sl_netif); - - } - osal_kfree(mail.buffer); - } -} -void user_netif_deinit(void) -{ - netif_set_link_down(&sl_netif); - netif_set_down(&sl_netif); - netif_remove(&sl_netif); -} - -void user_netif_set_default(void) -{ - netif_set_default(&sl_netif); -} -static bool slipif_initialled = false; -int user_netif_init(void) -{ - ip_addr_t ipaddr; - ip_addr_t netmask; - ip_addr_t gw; - char int_no = 2; - - struct netif *temp; - - IP_ADDR4(&ipaddr, 172, 16, 1, 5); - IP_ADDR4(&netmask, 255, 255, 255, 0); - IP_ADDR4(&gw, 172, 16, 1, 2); - temp = netif_add(&sl_netif, &ipaddr, &netmask, &gw, &int_no, slipif_init, ip_input); - if( temp == NULL ) { - cat1_print_err("fail to netif init\n"); - return -1; - } - netif_set_up(&sl_netif); - sl_netif.mtu = 1500; - netif_set_link_up(&sl_netif); - - // if( mode == 1 ) { - // ip_napt_enable(ipaddr.addr, 1); - // } else if(mode == 2) { - netif_set_default(&sl_netif); - // } - slipif_initialled = true; - return 0; -} -#define USE_SLIP_SERVICE - -void cat1_uart_receive_handler(uint8_t *buffer, int32_t size) -{ - - // cat1_print_dbg("cat1_uart_receive_handler %d \n",size); - if (slipif_initialled == true) - { - #ifdef USE_SLIP_SERVICE - do_uart_net_cmd(UART_SLIP_CMD_MSG_READ_DATA,buffer,size); - #else - slipif_received_bytes(&sl_netif, buffer, size); - #endif - } - -} - -#define SLIP_CMD_TASK_MSG_COUNT 512 -#define SLIP_CMD_TASK_SIZE (0x800*2) -#define SLIP_CMD_TASK_PRIO 4 -void create_net_uart_queue(void) -{ - - if (osal_msg_queue_create("uart_net_cmd_queue", SLIP_CMD_TASK_MSG_COUNT, &g_slip_cmd_queue, - 0, sizeof(slip_uart_cmd_t)) != ERRCODE_SUCC) { - LWIP_DEBUGF(SLIP_DEBUG, ("[net][service] app create mail fail\n")); - } -} -int netif_service_init(void) -{ - - - cat1_print_info("netif_service_init !\r\n"); - -#ifdef USE_SLIP_SERVICE - app_task_definition_t taskcfg={0}; - taskcfg.create_queue_handle = create_net_uart_queue; - taskcfg.attr.name="netif_service"; - taskcfg.attr.priority = osPriorityHigh;//osPriorityNormal; GUI osPriorityAboveNormal2 - taskcfg.attr.stack_size = SLIP_CMD_TASK_SIZE; - taskcfg.func = uart_event_task; - taskcfg.use_mem = USE_DTCM_MEM; - - errcode_t ret=cat1_create_osThread_custom(&taskcfg); - if(ret != ERRCODE_SUCC) - { - cat1_print_err("create netif_service failed %d!\r\n",ret); - return ERRCODE_FAIL; - } -#else - errcode_t ret = user_netif_init(); - cat1_print_info("user_netif_init ret=0x%02X! \r\n",ret); -#endif - return ERRCODE_SUCC; -} - diff --git a/code/sdk/zhihui/4g/cat1Service/slip/uart_slip.h b/code/sdk/zhihui/4g/cat1Service/slip/uart_slip.h deleted file mode 100644 index 1f866a271..000000000 --- a/code/sdk/zhihui/4g/cat1Service/slip/uart_slip.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2018-2025 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef __CUSTOM_UART_H -#define __CUSTOM_UART_H - -#define MODE_DEFAULT_IP 2 -#define MODE_ENABLE_NEW_IP 1 -#include "stdint.h" -/** - * @brief init uart config and config uart as slip netif bridge - */ -int netif_service_init(void); - -/** - * @brief remove slip netif - */ -void user_netif_deinit(void); - -void user_netif_set_default(void); - -/** - * @brief add slip netif - */ -int user_netif_init(void); - -void do_uart_slip_cmd(int cmd,uint8_t *buffer,uint32_t size); -#endif diff --git a/code/sdk/zhihui/4gTest/cat1_porting.c b/code/sdk/zhihui/4gTest/cat1_porting.c index 97cde0135..3cceddf04 100644 --- a/code/sdk/zhihui/4gTest/cat1_porting.c +++ b/code/sdk/zhihui/4gTest/cat1_porting.c @@ -225,18 +225,54 @@ errcode_t cat1_api_porting_init(void) { cat1_register_time_ctl_functions(&g_cat1_time_ctl_funcs); - ctl_pin_4g_t pins={ + static ctl_pin_4g_t pins={ + #if defined(BOARD_FD230) PIN_NONE, //bat_pin 1, S_AGPIO_L23, // pwr_pin 1, S_AGPIO_L28,//reset_pin 0, - S_AGPIO_L31,//ring_pin - 1,//risingEdge + S_AGPIO_L31,//ring_pin + 1, S_AGPIO_L30,//wakemodem_pin 1, - }; + #elif defined(BOARD_L22) + S_AGPIO_L14, //bat_pin + 1, + S_AGPIO_L23, // pwr_pin + 1, + PIN_NONE,//reset_pin + 0, + S_AGPIO_L31,//ring_pin + 1, + S_AGPIO_L30,//wakemodem_pin + 1, + #elif defined(BOARD_W9) || defined(BOARD_N9) + S_AGPIO_L17, //bat_pin + 1, + S_AGPIO_L23, // pwr_pin + 1, + PIN_NONE,//reset_pin + 0, + S_AGPIO_L31,//ring_pin + 1, + S_AGPIO_L30,//wakemodem_pin + 1, + #else + PIN_NONE, //bat_pin + 1, + S_AGPIO_L23, // pwr_pin + 1, + S_AGPIO_L28,//reset_pin + 0, + S_AGPIO_L31,//ring_pin + 1, + S_AGPIO_L30,//wakemodem_pin + 1, + #endif + }; + cat1_register_ctl_pin(pins); cat1_register_msg_callback(cat1_msg_callback); -- 2.17.1