BetaFlight模块设计之十八:图传模块同步任务分析
Posted lida2003
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BetaFlight模块设计之十八:图传模块同步任务分析相关的知识,希望对你有一定的参考价值。
BetaFlight模块设计之十八:图传模块同步任务分析
基于BetaFlight开源代码框架简介的框架设计,逐步分析内部模块功能设计。
图传模块同步任务
描述:主要用于图传数据的同步处理,目前主要支持SPI硬件集成RTC6705无线图传芯片和串行总线SmartAudio & Tramp Telemetry协议的图传外接模块。
├──> 初始化
│ ├──> [v]硬件初始化vtxRTC6705Init/pgResetFn_vtxIOConfig/vtxSmartAudioInit/vtxTrampInit
│ └──> [v]业务初始化vtxTableInit/vtxControlInit/vtxCommonInit
├──> 任务
│ ├──> [x]实时任务
│ ├──> [x]事件任务
│ └──> [v]时间任务[TASK_VTXCTRL] = DEFINE_TASK("VTXCTRL", NULL, NULL, vtxUpdate, TASK_PERIOD_HZ(5), TASK_PRIORITY_LOWEST),
├──> 驱动
│ ├──> [x]查询
│ └──> [x]中断
└──> 接口
├──> void vtxCommonSetDevice(vtxDevice_t *pDevice)
├──> 支持SPI硬件集成RTC6705无线图传芯片
└──> 支持串行总线SmartAudio & Tramp Telemetry协议
硬件及功能配置
板级集成RTC6705芯片方案
./src/main/target/BEEBRAIN_V2F/target.h:92:#define USE_VTX_RTC6705
./src/main/target/SPRACINGF4EVO/target.h:135:#define USE_VTX_RTC6705
./src/main/target/SPRACINGF3NEO/target.h:101:#define USE_VTX_RTC6705
./src/main/target/SINGULARITY/target.h:78:#define USE_VTX_RTC6705
./src/main/target/SPRACINGF7DUAL/target.h:146:#define USE_VTX_RTC6705
./src/main/target/SPRACINGF4NEO/target.h:143:#define USE_VTX_RTC6705
./src/main/target/STM32_UNIFIED/target.h:336:#define USE_VTX_RTC6705
./src/main/target/FISHDRONEF4/target.h:116:#define USE_VTX_RTC6705
./src/main/target/SPRACINGH7EXTREME/target.h:178:#define USE_VTX_RTC6705
./src/main/target/MOTOLABF4/target.h:101:#define USE_VTX_RTC6705
./src/main/target/SIRINFPV/target.h:111:#define USE_VTX_RTC6705
通用外接模块方案
\\src\\main\\target\\common_pre.h
#if ((TARGET_FLASH_SIZE > 256) || (FEATURE_CUT_LEVEL < 11))
#define USE_VTX_COMMON
#define USE_VTX_CONTROL
#define USE_VTX_SMARTAUDIO
#define USE_VTX_TRAMP
#endif
VTX模块接口
RTC6705芯片方案接口
\\src\\main\\io\\vtx_rtc6705.c
static vtxVTable_t rtc6705VTable =
.process = vtxRTC6705Process,
.getDeviceType = vtxRTC6705GetDeviceType,
.isReady = vtxRTC6705IsReady,
.setBandAndChannel = vtxRTC6705SetBandAndChannel,
.setPowerByIndex = vtxRTC6705SetPowerByIndex,
.setPitMode = vtxRTC6705SetPitMode,
.setFrequency = vtxRTC6705SetFrequency,
.getBandAndChannel = vtxRTC6705GetBandAndChannel,
.getPowerIndex = vtxRTC6705GetPowerIndex,
.getFrequency = vtxRTC6705GetFreq,
.getStatus = vtxRTC6705GetStatus,
.getPowerLevels = vtxRTC6705GetPowerLevels,
.serializeCustomDeviceStatus = NULL,
;
Tramp Telemetry协议接口
Tramp Telemetry is a protocol created by ImmersionRC for the Tramp HV video transmitter. Nowadays both protocols are used in several other video transmitters.
\\src\\main\\io\\vtx_tramp.c
static const vtxVTable_t trampVTable =
.process = vtxTrampProcess,
.getDeviceType = vtxTrampGetDeviceType,
.isReady = vtxTrampIsReady,
.setBandAndChannel = vtxTrampSetBandAndChannel,
.setPowerByIndex = vtxTrampSetPowerByIndex,
.setPitMode = vtxTrampSetPitMode,
.setFrequency = vtxTrampSetFreq,
.getBandAndChannel = vtxTrampGetBandAndChannel,
.getPowerIndex = vtxTrampGetPowerIndex,
.getFrequency = vtxTrampGetFreq,
.getStatus = vtxTrampGetStatus,
.getPowerLevels = vtxTrampGetPowerLevels,
.serializeCustomDeviceStatus = NULL,
;
SmartAudio协议接口
SmartAudio is a protocol created by TBS (Team Blacksheep) for it’s brand video transmitters.
\\src\\main\\io\\vtx_smartaudio.c
static const vtxVTable_t saVTable =
.process = vtxSAProcess,
.getDeviceType = vtxSAGetDeviceType,
.isReady = vtxSAIsReady,
.setBandAndChannel = vtxSASetBandAndChannel,
.setPowerByIndex = vtxSASetPowerByIndex,
.setPitMode = vtxSASetPitMode,
.setFrequency = vtxSASetFreq,
.getBandAndChannel = vtxSAGetBandAndChannel,
.getPowerIndex = vtxSAGetPowerIndex,
.getFrequency = vtxSAGetFreq,
.getStatus = vtxSAGetStatus,
.getPowerLevels = vtxSAGetPowerLevels,
.serializeCustomDeviceStatus = vtxSASerializeCustomDeviceStatus,
;
注:关于协议方面的详细版本,详见链接.
函数分析
vtxUpdate
主要同步功率、频道、频点(频率)等图传模块配置信息。
vtxUpdate
├──> <cliMode>
│ └──> return //命令行模式下,直接返回
├──> <!vtxDevice>
│ └──> return //vtx设备无效,直接返回
├──> vtxControlInputPoll
├──> do //状态机切换currentSchedule,并记录startingSchedule = currentSchedule;
│ ├──> <VTX_PARAM_POWER>
│ │ └──> vtxUpdatePending = vtxProcessPower(vtxDevice);
│ ├──> <VTX_PARAM_BANDCHAN>
│ │ ├──> <vtxGetSettings().band>
│ │ │ └──> vtxUpdatePending = vtxProcessBandAndChannel(vtxDevice);
│ │ └──> <!vtxGetSettings().band><VTX_SETTINGS_FREQCMD>
│ │ └──> vtxUpdatePending = vtxProcessFrequency(vtxDevice);
│ ├──> <VTX_PARAM_PITMODE>
│ │ └──> vtxUpdatePending = vtxProcessPitMode(vtxDevice);
│ ├──> <VTX_PARAM_CONFIRM>
│ │ └──> vtxUpdatePending = vtxProcessStateUpdate(vtxDevice);
│ ├──> currentSchedule = (currentSchedule + 1) % VTX_PARAM_COUNT;
│ └──> <!vtxUpdatePending && currentSchedule != startingSchedule> //满足条件循环do,否则退出循环
└──> <!ARMING_FLAG(ARMED) || vtxUpdatePending>
└──> vtxCommonProcess(vtxDevice, currentTimeUs);
vtxControlInputPoll
配置参数更新
vtxControlInputPoll
└──> <USE_SPEKTRUM_VTX_CONTROL>
└──> spektrumVtxControl
vtxProcessPower
功率参数同步
vtxProcessPower
└──> <vtxCommonGetPowerIndex(vtxDevice, &vtxPower)>
├──> const vtxSettingsConfig_t settings = vtxGetSettings();
└──> <vtxPower != settings.power>
└──> vtxCommonSetPowerByIndex(vtxDevice, settings.power);
vtxProcessBandAndChannel
频点,通道参数同步
vtxProcessBandAndChannel
└──> <!ARMING_FLAG(ARMED)><vtxCommonGetBandAndChannel(vtxDevice, &vtxBand, &vtxChan)>
├──> const vtxSettingsConfig_t settings = vtxGetSettings();
└──> <vtxBand != settings.band || vtxChan != settings.channel>
└──> vtxCommonSetBandAndChannel(vtxDevice, settings.band, settings.channel);
vtxProcessFrequency
频率参数同步
vtxProcessFrequency
└──> <!ARMING_FLAG(ARMED)><vtxCommonGetFrequency(vtxDevice, &vtxFreq)>
├──> const vtxSettingsConfig_t settings = vtxGetSettings();
└──> <vtxFreq != settings.freq>
└──> vtxCommonSetFrequency(vtxDevice, settings.freq);
vtxProcessPitMode
PitMode(维修站模式)设置同步
vtxProcessPitMode
├──> <!ARMING_FLAG(ARMED) && vtxCommonGetStatus(vtxDevice, &vtxStatus)>
│ ├──> bool currPmSwitchState = IS_RC_MODE_ACTIVE(BOXVTXPITMODE);
│ └──> <currPmSwitchState != prevPmSwitchState>
│ └──> <currPmSwitchState>
│ ├──> <VTX_SETTINGS_FREQCMD><vtxSettingsConfig()->pitModeFreq>
│ │ └──> return false
│ ├──> <!(vtxStatus & VTX_STATUS_PIT_MODE)>
│ │ ├──> vtxCommonSetPitMode(vtxDevice, true);
│ │ └──> return true
│ └──> <!currPmSwitchState><vtxStatus & VTX_STATUS_PIT_MODE>
│ ├──> vtxCommonSetPitMode(vtxDevice, false);
│ └──> return false
└──> return false
vtxProcessStateUpdate
频段,通道参数同步
vtxProcessStateUpdate
├──> <vtxSettingsState.band>
│ └──> vtxCommonGetBandAndChannel(vtxDevice, &vtxState.band, &vtxState.channel);
├──> <!vtxSettingsState.band><VTX_SETTINGS_FREQCMD>
│ └──> vtxCommonGetFrequency(vtxDevice, &vtxState.freq);
└──> vtxCommonGetPowerIndex(vtxDevice, &vtxState.power);
vtxCommonProcess
通信操作,确认通信操作事务完成情况,并根据异常进行处理。
vtxCommonProcess
└──> <vtxDevice>
└──> vtxDevice->vTable->process(vtxDevice, currentTimeUs);
以上是关于BetaFlight模块设计之十八:图传模块同步任务分析的主要内容,如果未能解决你的问题,请参考以下文章