b_util_uart

数据结构

//串口接收空闲的回调
typedef int (*pbUartIdleCallback_t)(uint8_t *pbuf, uint16_t len, void *arg);

typedef struct UtilUart
{
    uint8_t             *pbuf;
    uint16_t             buf_size;
    volatile uint16_t    index;
    uint32_t             idle_thd_ms;
    pbUartIdleCallback_t callback;
    void                *cb_arg;
    uint32_t             l_tick;
    uint32_t             l_index;
    struct UtilUart     *next;
    struct UtilUart     *prev;
} bUitlUart_t;

typedef bUitlUart_t bUitlUartInstance_t;

//用于创建串口接收实例
#define bUTIL_UART_INSTANCE(name, buf_len, idle_ms, cb, arg) \
    static uint8_t      Buf##name[buf_len];                  \
    bUitlUartInstance_t name = {                             \
        .pbuf        = Buf##name,                            \
        .buf_size    = buf_len,                              \
        .idle_thd_ms = idle_ms,                              \
        .callback    = cb,                                   \
        .cb_arg      = arg,                                  \
        .index       = 0,                                    \
        .l_tick      = 0,                                    \
        .l_index     = 0,                                    \
        .prev        = NULL,                                 \
        .next        = NULL,                                 \
    }

接口介绍

//    初始化用户定义的bUitlUartInstance_t(没有使用bUTIL_UART_INSTANCE去定义实例的情况)
void bUtilUartInitStruct(bUitlUartInstance_t *pinstance, uint8_t *pbuf, uint16_t size,
                         uint32_t idle_ms, pbUartIdleCallback_t cb, void *arg);

//    将串口号绑定到已有实例,绑定后可以用 bUtilUartRxHandler2和bUtilUartReceivedSize2
void bUtilUartBind(uint8_t uart_no, bUitlUartInstance_t *pinstance);

//    bUtilUartRxHandler 和 bUtilUartRxHandler2 效果是一样
//    但是,只有通过bUtilUartBind绑定串口号,才能调用bUtilUartRxHandler2
void bUtilUartRxHandler(bUitlUartInstance_t *pinstance, uint8_t dat);
void bUtilUartRxHandler2(uint8_t uart_no, uint8_t dat);

//    获取当前BUF中已经收到的数据长度
uint16_t bUtilUartReceivedSize(bUitlUartInstance_t *pinstance);
uint16_t bUtilUartReceivedSize2(uint8_t uart_no);