Merge branch 'sdk650pathc0423' of codeup.aliyun.com:64191456b9581d62e8f81ac0/FD230...
author孙春阳 <snickersun@163.com>
Thu, 11 Sep 2025 08:50:25 +0000 (16:50 +0800)
committer孙春阳 <snickersun@163.com>
Thu, 11 Sep 2025 08:50:25 +0000 (16:50 +0800)
1  2 
code/sdk/zhihui/ppp/include/ppp_serial.h
code/sdk/zhihui/ppp/src/ppp_serial.c

@@@ -8,6 -8,6 +8,7 @@@ extern "C" 
  #include <stdint.h>
  #include <stdbool.h>
  #include "ppp_types.h"
++#include "lwip/sio.h"
  
  /* 串口接收回调函数类型 */
  typedef void (*ppp_serial_rx_callback_t)(const uint8_t *data, uint16_t length, void *arg);
@@@ -94,13 -94,6 +95,12 @@@ ppp_error_t ppp_serial_set_baudrate(uin
   */
  void ppp_serial_get_stats(ppp_serial_stats_t *stats);
  
- #include "lwip/sio.h"
 +/**
 + * @brief 获取PPP模块SIO句柄
 + * @return SIO句柄,如果未初始化则返回NULL
 + */
 +sio_fd_t ppp_get_sio_fd(void);
 +
  #ifdef __cplusplus
  }
  #endif
@@@ -84,41 -102,112 +84,6 @@@ ppp_error_t ppp_serial_init(const ppp_s
      g_serial_ctx.rx_callback = config->rx_callback;
      g_serial_ctx.rx_callback_arg = config->rx_callback_arg;
  
 -    /* 配置串口引脚 */
 -    g_serial_ctx.pin_config.tx_pin = config->tx_pin;
 -    g_serial_ctx.pin_config.rx_pin = config->rx_pin;
 -    g_serial_ctx.pin_config.cts_pin = PIN_NONE;
 -    g_serial_ctx.pin_config.rts_pin = PIN_NONE;
 -
 -    /* 配置串口属性 */
 -    g_serial_ctx.uart_attr.baud_rate = config->baudrate;
 -    g_serial_ctx.uart_attr.data_bits = UART_DATA_BIT_8;
 -    g_serial_ctx.uart_attr.parity = UART_PARITY_NONE;
 -    g_serial_ctx.uart_attr.stop_bits = UART_STOP_BIT_1;
 -
 -    /* 配置串口缓冲区 */
 -    g_serial_ctx.buffer_config.rx_buffer_size = 256; // 硬件缓冲区
 -    g_serial_ctx.buffer_config.rx_buffer = (uint8_t *)osal_kmalloc(256, OSAL_GFP_KERNEL);
 -    if (!g_serial_ctx.buffer_config.rx_buffer) {
 -        PPP_DEBUG_ERROR("Failed to allocate UART RX buffer");
 -        osal_sem_destroy(g_serial_ctx.rx_semaphore);
 -        osal_mutex_destroy(g_serial_ctx.rx_mutex);
 -        osal_kfree(g_serial_ctx.rx_buffer);
 -        osal_kfree(g_serial_ctx.tx_buffer);
 -        return PPP_ERR_MEMORY;
 -    }
 -
 -    /* 初始化串口 */
 -    errcode_t ret = uapi_uart_init(g_serial_ctx.uart_bus, 
 -                                   &g_serial_ctx.pin_config,
 -                                   &g_serial_ctx.uart_attr,
 -                                   NULL,
 -                                   &g_serial_ctx.buffer_config);
 -    if (ret != ERRCODE_SUCC) {
 -        PPP_DEBUG_ERROR("Failed to initialize UART: %d", ret);
 -        osal_kfree(g_serial_ctx.buffer_config.rx_buffer);
 -        osal_sem_destroy(g_serial_ctx.rx_semaphore);
 -        osal_mutex_destroy(g_serial_ctx.rx_mutex);
 -        osal_kfree(g_serial_ctx.rx_buffer);
 -        osal_kfree(g_serial_ctx.tx_buffer);
 -        return PPP_ERR_UART;
 -    }
 -
 -    /* 注册接收回调 */
 -    ret = uapi_uart_register_rx_callback(g_serial_ctx.uart_bus,
 -                                         UART_RX_CONDITION_FULL_OR_SUFFICIENT_DATA_OR_IDLE,
 -                                         1, // 接收到1个字节就触发回调
 -                                         ppp_serial_rx_callback);
 -    if (ret != ERRCODE_SUCC) {
 -        PPP_DEBUG_ERROR("Failed to register UART RX callback: %d", ret);
 -        uapi_uart_deinit(g_serial_ctx.uart_bus);
 -        osal_kfree(g_serial_ctx.buffer_config.rx_buffer);
 -        osal_sem_destroy(g_serial_ctx.rx_semaphore);
 -        osal_mutex_destroy(g_serial_ctx.rx_mutex);
 -        osal_kfree(g_serial_ctx.rx_buffer);
 -        osal_kfree(g_serial_ctx.tx_buffer);
 -        return PPP_ERR_UART;
 -    }
 -
--    /* 初始化缓冲区状态 */
--    g_serial_ctx.rx_head = 0;
--    g_serial_ctx.rx_tail = 0;
--    g_serial_ctx.rx_count = 0;
--
--    /* 清零统计信息 */
--    g_serial_ctx.tx_bytes = 0;
--    g_serial_ctx.rx_bytes = 0;
--    g_serial_ctx.tx_errors = 0;
--    g_serial_ctx.rx_errors = 0;
--
--    g_serial_ctx.initialized = true;
--    PPP_DEBUG_INFO("PPP serial initialized successfully");
--
--    return PPP_ERR_OK;
- }
- void uart_read_data_int_handler(const void *buffer, uint16_t length, bool error)
- {
-     ppp_serial_rx_callback(buffer, length,error);
--}
 -
--/**
-- * @brief 反初始化PPP串口
-- */
--void ppp_serial_deinit(void)
--{
--    if (!g_serial_ctx.initialized) {
--        return;
--    }
--
--    PPP_DEBUG_INFO("Deinitializing PPP serial");
--
-     /* 关闭SIO接口 */
-     if (g_serial_ctx.sio_fd != NULL) {
-         sio_close(g_serial_ctx.sio_fd);
-         g_serial_ctx.sio_fd = NULL;
 -    /* 反初始化串口 */
 -    uapi_uart_deinit(g_serial_ctx.uart_bus);
 -
 -    /* 释放资源 */
 -    if (g_serial_ctx.buffer_config.rx_buffer) {
 -        osal_kfree(g_serial_ctx.buffer_config.rx_buffer);
 -    }
 -    
 -    if (g_serial_ctx.rx_semaphore) {
 -        osal_sem_destroy(g_serial_ctx.rx_semaphore);
 -    }
 -    
 -    if (g_serial_ctx.rx_mutex) {
 -        osal_mutex_destroy(g_serial_ctx.rx_mutex);
 -    }
 -    
 -    if (g_serial_ctx.rx_buffer) {
 -        osal_kfree(g_serial_ctx.rx_buffer);
 -    }
 -    
 -    if (g_serial_ctx.tx_buffer) {
 -        osal_kfree(g_serial_ctx.tx_buffer);
      }
  
      memset_s(&g_serial_ctx, sizeof(g_serial_ctx), 0, sizeof(g_serial_ctx));