> 文章列表 > BT8918D---huart模块分析

BT8918D---huart模块分析

BT8918D---huart模块分析

1 huart模块

huart模块从名字可以看出,用于串口UART通讯,H的含义,目前还不知道,待了解。该模块源码未公开,已经编译成库文件,供开发者使用。

2 huart模块分析

2.1 特性

默认特性

  • Baud rate :1500000(可调
  • Protocol :8N18 bits data, Non-polality, 1 stop bit;不可调,固定

2.2 所在静态库

通过app/projects/standard/output/bin/map.txt文件可知:

 .sbss          0x000000000001522c       0x10 ..\\..\\platform\\libs\\libplatform.a(huart.o)
                0x0000000000015234                huart_rx_buf_len
                0x0000000000015238                huart_rx_buf

  • 所在静态库为:app/platform/libs/libplatform.a
  • 所在模块为:huart
  • 头文件:app/platform/libs/api_uart.h

3 流程分析 

3.1 bsp_uart模块

该模块(bsp_uart)用于与huart模块沟通的桥梁。

3.1.1 bsp_huart_init

该函数,会进行波特率设置,并且将应用场景的串口接收buffer的地址和大小传入到huart模块

特点:

  • 接口由bsp_sys模块中的bsp_sys_init接口调用;

3.1.2 huart_rx_done

该接口在库文件libplatform.a中被调用,如下图所示:

 调用该接口时,会根据huart_rx_buff中的内容进行判断,看是否满足相关模块通讯协议。如调用bsp_eq模块中的bsp_eq_rx_done进行判断。

#if EQ_DBG_IN_UART
    if(bsp_eq_rx_done(huart_rx_buf)){
        return;
    }
#endif

3.1.3 huart_get_rxbuf

u8* huart_get_rxbuf(u16 *len)
{
    *len  = EQ_BUFFER_LEN;
    return eq_rx_buf;
}

该接口被huart模块调用,如下图所示:

 

 

3.2 bsp_eq模块 

3.2.1 bsp_eq_rx_done

 AT(.com_huart.text)
u8 bsp_eq_rx_done(u8* rx_buf)
{
    if (memcmp(rx_buf, tbl_anc_header, 3) == 0) {
        msg_enqueue(EVT_ONLINE_SET_ANC);
        eq_dbg_cb.rx_type = 1;
    } else if((rx_buf[0]=='E')&&(rx_buf[1]=='Q')){
        msg_enqueue(EVT_ONLINE_SET_EQ);
        eq_dbg_cb.rx_type = 1;
    }
    return eq_dbg_cb.rx_type;

如果符合EQ调试,那么就会给系统发送一个消息,EVT_ONLINE_SET_EQ。 该消息最后在func模块中被处理。

#if EQ_DBG_IN_UART || EQ_DBG_IN_SPP
        case EVT_ONLINE_SET_EQ:
            bsp_eq_parse_cmd();
            break;
#endif

最后调用bsp_eq_parse_cmd进行解析处理。

3.2.2 bsp_eq_parse_cmd