BetaFlight模块设计之二十四:transponder任务分析

Posted lida2003

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BetaFlight模块设计之二十四:transponder任务分析相关的知识,希望对你有一定的参考价值。

BetaFlight模块设计之二十四:transponder任务分析

基于BetaFlight开源代码框架简介的框架设计,逐步分析内部模块功能设计。

transponder任务

描述:主要是通过一个红外发射固定的一个红外编码。竞赛时,不同FC都有唯一编码,红外接收机通过识别唯一编码,给FC机型计时和打卡。

 ├──> 初始化
 │   ├──> [v]硬件初始化transponderInit(transponderIrInit/transponderIrInitArcitimer/transponderIrInitIlap/transponderIrInitERLT/transponderIrHardwareInit)
 │   └──> [x]业务初始化
 ├──> 任务
 │   ├──> [x]实时任务
 │   ├──> [x]事件任务
 │   └──> [v]时间任务[TASK_TRANSPONDER] = DEFINE_TASK("TRANSPONDER", NULL, NULL, transponderUpdate, TASK_PERIOD_HZ(250), TASK_PRIORITY_LOW),
 ├──> 驱动
 │   ├──> [x]查询
 │   └──> [x]中断
 └──> 接口
     ├──> 支持MSP修改唯一标识码及应答机类型(ILAP/ARCITIMER/ERLT)
     ├──> void transponderStartRepeating(void)
     └──> void transponderStopRepeating(void)

配置情况

硬件配置

Kakute F7从默认配置角度并不支持这个功能。

注:如果想要有这个功能,需要配置并整理出一个IO来做硬件驱动IR LED发射编码使用。

以下是默认配置支持transponder功能的机型。

./src/main/target/OMNIBUS/target.h:142:#define USE_TRANSPONDER
./src/main/target/NUCLEOH743/target.h:249:#define USE_TRANSPONDER
./src/main/target/NOX/target.h:115:#define USE_TRANSPONDER
./src/main/target/BEEBRAIN_V2F/target.h:106:#define USE_TRANSPONDER
./src/main/target/SPRACINGF4EVO/target.h:185:#define USE_TRANSPONDER
./src/main/target/OMNINXT/target.h:178:#define USE_TRANSPONDER
./src/main/target/ELINF722/target.h:118:#define USE_TRANSPONDER
./src/main/target/AG3X/target.h:154:#define USE_TRANSPONDER
./src/main/target/OMNIBUSF4/target.h:277:#define USE_TRANSPONDER
./src/main/target/NUCLEOH723ZG/target.h:235:#define USE_TRANSPONDER
./src/main/target/SPRACINGF3NEO/target.h:138:#define USE_TRANSPONDER
./src/main/target/BEEROTORF4/target.h:138:#define USE_TRANSPONDER
./src/main/target/NUCLEOF103RG/target.h:29:#undef USE_TRANSPONDER
./src/main/target/NUCLEOH7A3ZI/target.h:235:#define USE_TRANSPONDER
./src/main/target/SPRACINGF3EVO/target.h:160:#define USE_TRANSPONDER
./src/main/target/CLRACINGF4/target.h:127:#define USE_TRANSPONDER
./src/main/target/SPRACINGH7NANO/target.h:188:#define USE_TRANSPONDER
./src/main/target/REVO/target.h:335:#define USE_TRANSPONDER
./src/main/target/SPRACINGF7DUAL/target.h:185:#define USE_TRANSPONDER
./src/main/target/SPRACINGF4NEO/target.h:181:#define USE_TRANSPONDER
./src/main/target/STM32_UNIFIED/target.h:339:#define USE_TRANSPONDER
./src/main/target/NUCLEOH725ZG/target.h:244:#define USE_TRANSPONDER
./src/main/target/RG_SSD_F3/target.h:119:#define USE_TRANSPONDER
./src/main/target/SPRACINGH7EXTREME/target.h:173:#define USE_TRANSPONDER
./src/main/target/PYRODRONEF4/target.h:103:#define USE_TRANSPONDER
./src/main/target/FF_PIKOBLX/target.h:105:#define USE_TRANSPONDER
./src/main/target/SPRACINGF3MINI/target.h:171:#define USE_TRANSPONDER
./src/main/target/NUCLEOF303RE/target.h:139:#define USE_TRANSPONDER
./src/main/target/OMNIBUSF4FW/target.h:196:#define USE_TRANSPONDER
./src/main/target/EXF722DUAL/target.h:145:#define USE_TRANSPONDER
./src/main/target/FRSKYF3/target.h:117:#define USE_TRANSPONDER
./src/main/target/SPRACINGH7ZERO/target.h:191:#define USE_TRANSPONDER
./src/main/target/REVOLT/target.h:44:#define USE_TRANSPONDER

驱动配置

不同MCU对应的驱动有一些变化,这里给出了当前F3/F4/F7/H7/G4主控对应的驱动代码。

./make/source.mk:317:            drivers/transponder_ir_io_hal.c \\
./make/mcu/STM32F7.mk:181:            drivers/transponder_ir_io_hal.c \\
./make/mcu/STM32H7.mk:320:            drivers/transponder_ir_io_hal.c \\
./make/mcu/STM32G4.mk:177:            drivers/transponder_ir_io_hal.c \\
./make/source.mk:318:            drivers/transponder_ir_io_stdperiph.c \\
./make/mcu/STM32F4.mk:183:            drivers/transponder_ir_io_stdperiph.c \\
./make/mcu/STM32F3.mk:87:            drivers/transponder_ir_io_stdperiph.c \\

业务配置

初始化

\\src\\main\\io\\transponder_ir.c
void pgResetFn_transponderConfig(transponderConfig_t *transponderConfig)

    RESET_CONFIG_2(transponderConfig_t, transponderConfig,
        .provider = TRANSPONDER_ILAP,
        .reserved = 0,
        .data =  0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0x0, 0x0, 0x0 , // Note, this is NOT a valid transponder code, it's just for testing production hardware
        .ioTag = IO_TAG_NONE
    );
    transponderConfig->ioTag = timerioTagGetByUsage(TIM_USE_TRANSPONDER, 0);

MSP协议

\\src\\main\\msp\\msp_protocol.h
#define MSP_TRANSPONDER_CONFIG          82 //out message         Get transponder settings
#define MSP_SET_TRANSPONDER_CONFIG      83 //in message          Set transponder settings

三种IR transponder type类型

\\src\\main\\io\\transponder_ir.c
const transponderRequirement_t transponderRequirements[TRANSPONDER_PROVIDER_COUNT] = 
    TRANSPONDER_ILAP, TRANSPONDER_DATA_LENGTH_ILAP, TRANSPONDER_TRANSMIT_DELAY_ILAP, TRANSPONDER_TRANSMIT_JITTER_ILAP,
    TRANSPONDER_ARCITIMER, TRANSPONDER_DATA_LENGTH_ARCITIMER, TRANSPONDER_TRANSMIT_DELAY_ARCITIMER, TRANSPONDER_TRANSMIT_JITTER_ARCITIMER,
    TRANSPONDER_ERLT, TRANSPONDER_DATA_LENGTH_ERLT, TRANSPONDER_TRANSMIT_DELAY_ERLT, TRANSPONDER_TRANSMIT_JITTER_ERLT
;

主要函数

采用DMA方式进行IO电平变换,发送唯一红外编码。DMA控制器可以很好的确保不占用CPU资源,确保资源的有效利用。

transponderUpdate
 ├──> <!(transponderInitialised && transponderRepeat && isTransponderIrReady())>
 │   └──> return  //硬件初始化(transponderInitialised),业务逻辑初始化(transponderRepeat),DMA忙状态(isTransponderIrReady)
 ├──> <!(updateNow = (timeDelta_t)(currentTimeUs - nextUpdateAtUs) >= 0L)>
 │   └──> return  //未到下次更新时间
 ├──> 更新Jitter时间,避开某些同步传输的问题
 ├──> nextUpdateAtUs = currentTimeUs + transponderRequirements[provider - 1].transmitDelay + jitter; //规划下次执行transponder时间
 ├──> <REDUCE_TRANSPONDER_CURRENT_DRAW_WHEN_USB_CABLE_PRESENT><usbCableIsInserted()>
 │   └──> nextUpdateAtUs = currentTimeUs + (1000 * 1000) / 10; // 10 hz.USB连接FC时,传输周期定义为10Hz
 └──> transponderIrTransmit //触发传输

以上是关于BetaFlight模块设计之二十四:transponder任务分析的主要内容,如果未能解决你的问题,请参考以下文章

BetaFlight模块设计之二十六:接收机任务分析

BetaFlight模块设计之二十八:MainPidLoop任务分析

BetaFlight模块设计之二十二:地面测距任务分析

BetaFlight模块设计之二十一:dashboard任务分析

BetaFlight模块设计之二十九:滤波模块分析

BetaFlight模块设计之二十五:dispatch任务分析