BetaFlight模块设计之六:Beeper任务分析

Posted lida2003

tags:

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

BetaFlight模块设计之六:Beeper任务分析

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

beeper任务

描述:主要用于蜂鸣提示系统状态。

 ├──> 初始化
 │   ├──> [v]硬件初始化:无过多硬件初始化,直接IO操作BUZ-
 │   └──> [x]业务初始化
 ├──> 任务
 │   ├──> [x]实时任务
 │   ├──> [x]事件任务
 │   └──> [v]时间任务[TASK_BEEPER] = DEFINE_TASK("BEEPER", NULL, NULL, beeperUpdate, TASK_PERIOD_HZ(100), TASK_PRIORITY_LOW),
 ├──> 驱动
 │   ├──> [x]查询
 │   └──> [x]中断
 └──> 接口
     ├──> bool isBeeperOn(void)
	 ├──> int beeperTableEntryCount(void)
	 ├──> const char *beeperNameForTableIndex(int idx)
	 ├──> uint32_t beeperModeMaskForTableIndex(int idx)
	 ├──> beeperMode_e beeperModeForTableIndex(int idx)
	 ├──> uint32_t getArmingBeepTimeMicros(void)
	 ├──> void beeperSilence(void)
	 ├──> void beeperWarningBeeps(uint8_t beepCount)
	 ├──> void beeperConfirmationBeeps(uint8_t beepCount)
	 ├──> 支持命令行蜂鸣测试
     └──> 支持多场景蜂鸣模式

注:硬件配置\\src\\main\\target\\KAKUTEF7\\target.h

#define USE_BEEPER
#define BEEPER_PIN              PD15
#define BEEPER_INVERTED

beeperUpdate函数分析

beeperUpdate
 ├──> <IS_RC_MODE_ACTIVE(BOXBEEPERON)>
 │   └──> beeper(BEEPER_RX_SET);
 ├──> <featureIsEnabled(FEATURE_GPS) && IS_RC_MODE_ACTIVE(BOXBEEPGPSCOUNT)>
 │   └──> beeperGpsStatus();
 ├──> <currentBeeperEntry == NULL>
 │   └──> return //there aren't any sounds ongoing
 ├──> <beeperNextToggleTime > currentTimeUs>
 │   ├──> schedulerIgnoreTaskExecTime
 │   └──> return 
 ├──> <蜂鸣没有开>
 │   ├──> <USE_DSHOT>
 │   │   ├──> <电机未运行,且遥控器设置或者遥控器信号丢失>
 │   │   └──> dshotCommandWrite  //ESC指令蜂鸣
 │   └──> <sequence[beeperPos] != 0> //蜂鸣配置参数定义需要蜂鸣, 1st, 3rd, 5th.. are the delays how long the beeper is on
 │       ├──> <检查模式是否允许蜂鸣报警>
 │       │   ├──> BEEP_ON
 │       │   └──> beeperIsOn = true;
 │       ├──> warningLedEnable
 │       ├──> warningLedRefresh
 │       └──> <arming beep>
 │           └──> armingBeepTimeMicros = micros(); // 未黑匣子标记时间
 ├──> <蜂鸣已打开>
 │   └──> <sequence[beeperPos] != 0> //蜂鸣配置参数定义需要蜂鸣, 2nd, 4th, 6th.. are the delays how long beeper is off
 │       ├──> BEEP_OFF;
 │       ├──> beeperIsOn = false;
 │       ├──> warningLedDisable
 │       └──> warningLedRefresh
 ├──> <USE_OSD>
 │   ├──> <beeperIsOn && !beeperWasOn> //蜂鸣 且之前没有蜂鸣
 │   └──> osdSetVisualBeeperState(true);
 └──> beeperProcessCommand
     ├──> <BEEPER_COMMAND_REPEAT>
	 │   └──> beeperPos = 0;
     ├──> <BEEPER_COMMAND_STOP>
	 │   └──> beeperSilence
     └──> <calculate next toggle time>
	     ├──> beeperNextToggleTime = currentTimeUs + 1000 * 10 * currentBeeperEntry->sequence[beeperPos];
	     └──> beeperPos++;

beep场景对应表

// IMPORTANT: these are in priority order, 0 = Highest
static const beeperTableEntry_t beeperTable[] = 
     BEEPER_ENTRY(BEEPER_GYRO_CALIBRATED,       0, beep_gyroCalibrated,   "GYRO_CALIBRATED") ,
     BEEPER_ENTRY(BEEPER_RX_LOST,               1, beep_txLostBeep,       "RX_LOST") ,
     BEEPER_ENTRY(BEEPER_RX_LOST_LANDING,       2, beep_sos,              "RX_LOST_LANDING") ,
     BEEPER_ENTRY(BEEPER_DISARMING,             3, beep_disarmBeep,       "DISARMING") ,
     BEEPER_ENTRY(BEEPER_ARMING,                4, beep_armingBeep,       "ARMING")  ,
     BEEPER_ENTRY(BEEPER_ARMING_GPS_FIX,        5, beep_armingGpsFix,     "ARMING_GPS_FIX") ,
     BEEPER_ENTRY(BEEPER_ARMING_GPS_NO_FIX,     6, beep_armingGpsNoFix,   "ARMING_GPS_NO_FIX") ,
     BEEPER_ENTRY(BEEPER_BAT_CRIT_LOW,          7, beep_critBatteryBeep,  "BAT_CRIT_LOW") ,
     BEEPER_ENTRY(BEEPER_BAT_LOW,               8, beep_lowBatteryBeep,   "BAT_LOW") ,
     BEEPER_ENTRY(BEEPER_GPS_STATUS,            9, beep_multiBeeps,       "GPS_STATUS") ,
     BEEPER_ENTRY(BEEPER_RX_SET,                10, beep_shortBeep,       "RX_SET") ,
     BEEPER_ENTRY(BEEPER_ACC_CALIBRATION,       11, beep_2shortBeeps,     "ACC_CALIBRATION") ,
     BEEPER_ENTRY(BEEPER_ACC_CALIBRATION_FAIL,  12, beep_2longerBeeps,    "ACC_CALIBRATION_FAIL") ,
     BEEPER_ENTRY(BEEPER_READY_BEEP,            13, beep_readyBeep,       "READY_BEEP") ,
     BEEPER_ENTRY(BEEPER_MULTI_BEEPS,           14, beep_multiBeeps,      "MULTI_BEEPS") , // FIXME having this listed makes no sense since the beep array will not be initialised.
     BEEPER_ENTRY(BEEPER_DISARM_REPEAT,         15, beep_disarmRepeatBeep, "DISARM_REPEAT") ,
     BEEPER_ENTRY(BEEPER_ARMED,                 16, beep_armedBeep,       "ARMED") ,
     BEEPER_ENTRY(BEEPER_SYSTEM_INIT,           17, NULL,                 "SYSTEM_INIT") ,
     BEEPER_ENTRY(BEEPER_USB,                   18, NULL,                 "ON_USB") ,
     BEEPER_ENTRY(BEEPER_BLACKBOX_ERASE,        19, beep_2shortBeeps,     "BLACKBOX_ERASE") ,
     BEEPER_ENTRY(BEEPER_CRASH_FLIP_MODE,       20, beep_2longerBeeps,    "CRASH_FLIP") ,
     BEEPER_ENTRY(BEEPER_CAM_CONNECTION_OPEN,   21, beep_camOpenBeep,     "CAM_CONNECTION_OPEN") ,
     BEEPER_ENTRY(BEEPER_CAM_CONNECTION_CLOSE,  22, beep_camCloseBeep,    "CAM_CONNECTION_CLOSE") ,
     BEEPER_ENTRY(BEEPER_RC_SMOOTHING_INIT_FAIL,23, beep_rcSmoothingInitFail, "RC_SMOOTHING_INIT_FAIL") ,
     BEEPER_ENTRY(BEEPER_ALL,                   24, NULL,                 "ALL") ,
;

beep场景音调参数表

/* Beeper Sound Sequences: (Square wave generation)
 * Sequence must end with 0xFF or 0xFE. 0xFE repeats the sequence from
 * start when 0xFF stops the sound when it's completed.
 *
 * "Sound" Sequences are made so that 1st, 3rd, 5th.. are the delays how
 * long the beeper is on and 2nd, 4th, 6th.. are the delays how long beeper
 * is off. Delays are in milliseconds/10 (i.e., 5 => 50ms).
 */
// short fast beep
static const uint8_t beep_shortBeep[] = 
    10, 10, BEEPER_COMMAND_STOP
;
// arming beep
static const uint8_t beep_armingBeep[] = 
    30, 5, 5, 5, BEEPER_COMMAND_STOP
;
// Arming when GPS is fixed
static const uint8_t beep_armingGpsFix[] = 
    5, 5, 15, 5, 5, 5, 15, 30, BEEPER_COMMAND_STOP
;
// Arming when GPS is not fixed
static const uint8_t beep_armingGpsNoFix[] = 
    30, 5, 30, 5, 30, 5, BEEPER_COMMAND_STOP
;
// armed beep (first pause, then short beep)
static const uint8_t beep_armedBeep[] = 
    0, 245, 10, 5, BEEPER_COMMAND_STOP
;
// disarming beeps
static const uint8_t beep_disarmBeep[] = 
    15, 5, 15, 5, BEEPER_COMMAND_STOP
;
// beeps while stick held in disarm position (after pause)
static const uint8_t beep_disarmRepeatBeep[] = 
    0, 100, 10, BEEPER_COMMAND_STOP
;
// Long beep and pause after that
static const uint8_t beep_lowBatteryBeep[] = 
    25, 50, BEEPER_COMMAND_STOP
;
// critical battery beep
static const uint8_t beep_critBatteryBeep[] = 
    50, 2, BEEPER_COMMAND_STOP
;

// transmitter-signal-lost tone
static const uint8_t beep_txLostBeep[] = 
    50, 50, BEEPER_COMMAND_STOP
;
// SOS morse code:
static const uint8_t beep_sos[] = 
    10, 10, 10, 10, 10, 40, 40, 10, 40, 10, 40, 40, 10, 10, 10, 10, 10, 70, BEEPER_COMMAND_STOP
;
// Ready beeps. When gps has fix and copter is ready to fly.
static const uint8_t beep_readyBeep[] = 
    4, 5, 4, 5, 8, 5, 15, 5, 8, 5, 4, 5, 4, 5, BEEPER_COMMAND_STOP
;
// 2 fast short beeps
static const uint8_t beep_2shortBeeps[] = 
    5, 5, 5, 5, BEEPER_COMMAND_STOP
;
// 2 longer beeps
static const uint8_t beep_2longerBeeps[] = 
    20, 15, 35, 5, BEEPER_COMMAND_STOP
;
// 3 beeps
static const uint8_t beep_gyroCalibrated[] = 
    20, 10, 20, 10, 20, 10, BEEPER_COMMAND_STOP
;

// Cam connection opened
static const uint8_t beep_camOpenBeep[] = 
    5, 15, 10, 15, 20, BEEPER_COMMAND_STOP
;

// Cam connection close
static const uint8_t beep_camCloseBeep[] = 
    10, 8, 5, BEEPER_COMMAND_STOP
;

// RC Smoothing filter not initialized - 3 short + 1 long
static const uint8_t beep_rcSmoothingInitFail[] = 
    10, 10, 10, 10, 10, 10, 50, 25, BEEPER_COMMAND_STOP
;

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

BetaFlight模块设计之一:系统任务模块分析

BetaFlight模块设计之二:SERIAL任务分析

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

BetaFlight模块设计之二十七:姿态更新任务分析

BetaFlight模块设计之十二:电传任务分析

BetaFlight模块设计之四:ESC传感任务分析