PXX synchro using Hearbeat (#6482)

* [PXX] Latency using heartbeat sync optimized for X7 (stable @ 12ms)
* [PXX] Latency using heartbeat sync optimized for XLite Pro (stable @ 9ms)
This commit is contained in:
Bertrand Songis
2019-06-08 10:44:31 +02:00
committed by GitHub
parent 56a31f20d3
commit aff6c3fd1d
37 changed files with 383 additions and 189 deletions
@@ -17,6 +17,7 @@ option(MULTIMODULE "DIY Multiprotocol TX Module (https://github.com/pascallanger
option(MULTI_SPORT "SPORT telemetry support" OFF)
option(SUPPORT_D16_EU_ONLY "XJT module only supports D16-EU and LR12-EU" OFF) # TODO rename to XJT_EU_ONLY
option(DEBUG_INTERRUPTS "Count interrupts" OFF)
option(DEBUG_LATENCY "Debug latency" OFF)
option(DEBUG_USB_INTERRUPTS "Count individual USB interrupts" OFF)
option(DEBUG_TASKS "Task switching statistics" OFF)
option(DEBUG_TIMERS "Time critical parts of the code" OFF)
@@ -71,6 +72,17 @@ if(DEBUG_TIMERS)
set(DEBUG ON)
endif()
if(DEBUG_LATENCY STREQUAL MIXER_RF)
add_definitions(-DDEBUG_LATENCY)
add_definitions(-DDEBUG_LATENCY_MIXER_RF)
endif()
if(DEBUG_LATENCY STREQUAL RF_ONLY)
add_definitions(-DDEBUG_LATENCY)
add_definitions(-DDEBUG_LATENCY_RF_ONLY)
endif()
if(CLI)
add_definitions(-DCLI)
set(FIRMWARE_SRC ${FIRMWARE_SRC} cli.cpp)
@@ -1,60 +0,0 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "opentx.h"
volatile uint32_t HearbeatCapture = 0;
void init_xjt_heartbeat()
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = HEARTBEAT_GPIO_PIN;
GPIO_Init(HEARTBEAT_GPIO, &GPIO_InitStructure);
SYSCFG_EXTILineConfig(HEARTBEAT_EXTI_PortSource, HEARTBEAT_EXTI_PinSource);
EXTI_InitTypeDef EXTI_InitStructure;
EXTI_StructInit(&EXTI_InitStructure);
EXTI_InitStructure.EXTI_Line = HEARTBEAT_EXTI_LINE;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_SetPriority(HEARTBEAT_EXTI_IRQn, 0); // Highest priority interrupt
NVIC_EnableIRQ(HEARTBEAT_EXTI_IRQn);
}
void stop_xjt_heartbeat()
{
NVIC_DisableIRQ(HEARTBEAT_EXTI_IRQn);
}
extern "C" void HEARTBEAT_EXTI_IRQHandler()
{
if (EXTI_GetITStatus(HEARTBEAT_EXTI_LINE) != RESET) {
HearbeatCapture = TIMER_2MHz_TIMER->CNT;
EXTI_ClearITPendingBit(HEARTBEAT_EXTI_LINE);
}
}
@@ -0,0 +1,83 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "opentx.h"
volatile HeartbeatCapture heartbeatCapture;
#if defined(INTMODULE_HEARTBEAT_GPIO)
void init_intmodule_heartbeat()
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = INTMODULE_HEARTBEAT_GPIO_PIN;
GPIO_Init(INTMODULE_HEARTBEAT_GPIO, &GPIO_InitStructure);
SYSCFG_EXTILineConfig(INTMODULE_HEARTBEAT_EXTI_PortSource, INTMODULE_HEARTBEAT_EXTI_PinSource);
EXTI_InitTypeDef EXTI_InitStructure;
EXTI_StructInit(&EXTI_InitStructure);
EXTI_InitStructure.EXTI_Line = INTMODULE_HEARTBEAT_EXTI_LINE;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_SetPriority(INTMODULE_HEARTBEAT_EXTI_IRQn, 0); // Highest priority interrupt
NVIC_EnableIRQ(INTMODULE_HEARTBEAT_EXTI_IRQn);
heartbeatCapture.valid = true;
}
void stop_intmodule_heartbeat()
{
heartbeatCapture.valid = false;
#if !defined(INTMODULE_HEARTBEAT_REUSE_INTERRUPT_ROTARY_ENCODER)
NVIC_DisableIRQ(INTMODULE_HEARTBEAT_EXTI_IRQn);
#endif
EXTI_InitTypeDef EXTI_InitStructure;
EXTI_StructInit(&EXTI_InitStructure);
EXTI_InitStructure.EXTI_Line = INTMODULE_HEARTBEAT_EXTI_LINE;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = INTMODULE_HEARTBEAT_TRIGGER;
EXTI_InitStructure.EXTI_LineCmd = DISABLE;
EXTI_Init(&EXTI_InitStructure);
}
void check_xjt_heartbeat()
{
if (EXTI_GetITStatus(INTMODULE_HEARTBEAT_EXTI_LINE) != RESET) {
heartbeatCapture.timestamp = TIMER_2MHz_TIMER->CNT;
heartbeatCapture.count++;
EXTI_ClearITPendingBit(INTMODULE_HEARTBEAT_EXTI_LINE);
}
}
#endif
#if defined(INTMDULE_HEARTBEAT) && !defined(INTMODULE_HEARTBEAT_REUSE_INTERRUPT_ROTARY_ENCODER)
extern "C" void INTMODULE_HEARTBEAT_EXTI_IRQHandler()
{
check_xjt_heartbeat();
}
#endif
@@ -90,6 +90,10 @@ extern "C" void ROTARY_ENCODER_EXTI_IRQHandler1(void)
EXTI_ClearITPendingBit(ROTARY_ENCODER_EXTI_LINE2);
}
#endif
#if !defined(BOOT) && defined(INTMODULE_HEARTBEAT_REUSE_INTERRUPT_ROTARY_ENCODER)
check_xjt_heartbeat();
#endif
}
#if defined(ROTARY_ENCODER_EXTI_IRQn2)