Sub-1G: PLHD¶
重要
此例程仅存在于特殊版本的SDK中,如有需要请联系Panchip。
1 功能概述¶
plhd演示了Sub-1G的接收提前中断功能。此功能会在收到配置的数据长度后就提前产生一个中断,不需要等到全部收完才产生中断。在一些应用中我们可以使用这个功能去做一些头部信息检查,来过滤掉一些非预期包,提高接收效率。
2 环境准备¶
- PAN3730 EVB两块 
- Type-C USB线两条(用于供电和查看串口打印Log) 
- 硬件接线: - 使用USB线,将PC USB与EVB Type-C USB(USB->UART)相连 
- 使用杜邦线或者跳线帽将EVB上的: - TX0 与 P00相连 
- RX0 与 P01相连 
 
 
- PC软件: 串口调试助手(UartAssist)或终端工具(SecureCRT),波特率921600 
- 码表或者其他ANT接收设备,手机(nrf connect) 
3 编译和烧录¶
例程位置:zephyr\samples_panchip\sub_1G\plhd
编译时Board选择pan3730_evb,Config选择prj.conf
使用 ZAL 工具可以对其进行编译、烧录、打开 VS Code 调试等操作。关于 ZAL 工具的详细介绍请参考:Zephyr APP Launcher 工具介绍。
4 演示说明¶
例程上电初始化会打印如下日志:
*** Booting Zephyr OS build zephyr-v2.7.0-999-gc2c0b41086a9  ***
[00:00:00.000,000] <dbg> sub1g.main: Sub-1G PLHD sample start!
因为PLHD例程是一个RX例程,所以需要一个TX端做配合进行测试,这里我们可以复用trx_sample这个例程。首先我们把trx_sample例程进行一点微调,因为提前中断功能需要设置确定从第几个字节开始检查,以及检查多少个字节的数据。而检查字节数有8字节和16字节可选,所以发送端必须发送超过8字节的数据才可以使用该功能。这里把light_command_send这个函数修改为如下内容:
uint8_t data[20];
if (device_attr.device_type != DEVICE_TYPE_SEND) {
    LOG_WRN("The current device is a receiving device and cannot send commands\n");
    return -1;
}
for(uint8_t i = 0; i < 20; i++){
    data[i] = i + 1;
}
return sub_oneg_send(&cfg, data, 20);
修改后,配置成发送设备,就可以用key2键发送数据了。每次发送就可以在RX端看到提前中断的日志:
[00:02:46.818,000] <dbg> sub1g.sub_oneg_main_thread: PLHD len: 8
[00:02:46.819,000] <dbg> sub1g: PLHD data: 
                                01 02 03 04 05 06 07 08                          |........         
[00:02:46.833,000] <dbg> sub1g.sub_oneg_main_thread: Data len: 20
[00:02:46.833,000] <dbg> sub1g: Data data: 
                                01 02 03 04 05 06 07 08  09 0a 0b 0c 0d 0e 0f 10 |........ ........
                                11 12 13 14                                      |.... 
5 开发者说明¶
- 启用ANT模块,需要在 - prj.conf文件中添加”CONFIG_SUB_ONEG=y”和”CONFIG_NEWLIB_LIBC=y”- CONFIG_SUB_ONEG=y CONFIG_NEWLIB_LIBC=y 
- Sub-1G初始化 - /** * @brief Configure the sub-1G module. * * @param cfg Pointer to the sub-1G config struct. * * @retval 0 If successful. * @retval -errno Negative errno code on failure. */ int sub_oneg_configure(sub_oneg_cfg *cfg); 
- 使能提前中断功能 - /** * @brief The phld function was enabled. * * @param start_address Match the number of start bytes. * @param length Matches the length of bytes. You can just choose 8 or 16 bytes. * SUB_ONEG_PLHD_LEN8 8 bytes * SUB_ONEG_PLHD_LEN16 16 bytes * @param on_off Enable or disable this function. */ void sub_oneg_plhd_switch(uint8_t start_address, uint8_t length, uint8_t on_off); 
- Sub-1G接收启动 - /** * @brief Start receive mode. * * @param cfg Pointer to the sub-1G config struct. * @param mode Set continue rx mode or single rx mode. * CONTINUE_RX_MODE: After the rx is finished, * it will not exit the rx mode and will remain in the rx mode. * SINGLE_RX_MODE: When rx is finished, it exits rx mode * @param timeout Set rx timeout(ms), 0 indicates no timeout until data is received. * * @retval 0 If successful. * @retval -errno Negative errno code on failure. */ int sub_oneg_receive_start(sub_oneg_cfg *cfg, sub_oneg_rx_mode_t mode, uint32_t timeout); 
更多有关sub-1G的介绍请参考 Sub-1G使用指南文档。
6 RAM/Flash资源使用情况¶
Memory region         Used Size  Region Size  %age Used
FLASH:      43628 B       256 KB     16.64%
SRAM:        9064 B        64 KB     13.83%