mixer scheduler
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include "mixer_scheduler.h"
|
||||
|
||||
#if defined(INTMODULE_HEARTBEAT_GPIO)
|
||||
volatile HeartbeatCapture heartbeatCapture;
|
||||
@@ -77,6 +78,8 @@ void check_intmodule_heartbeat()
|
||||
heartbeatCapture.count++;
|
||||
#endif
|
||||
EXTI_ClearITPendingBit(INTMODULE_HEARTBEAT_EXTI_LINE);
|
||||
|
||||
mixerSchedulerISRTrigger();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -45,12 +45,6 @@ void intmoduleStop()
|
||||
USART_DeInit(INTMODULE_USART);
|
||||
|
||||
GPIO_ResetBits(INTMODULE_GPIO, INTMODULE_TX_GPIO_PIN | INTMODULE_RX_GPIO_PIN);
|
||||
|
||||
#if defined(INTERNAL_MODULE_MULTI)
|
||||
// stop pulses timer
|
||||
INTMODULE_TIMER->DIER &= ~TIM_DIER_CC2IE;
|
||||
INTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN;
|
||||
#endif
|
||||
}
|
||||
|
||||
void intmodulePxx1SerialStart()
|
||||
@@ -103,28 +97,6 @@ void intmoduleSerialStart(uint32_t baudrate, uint8_t rxEnable, uint16_t parity,
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(INTERNAL_MODULE_MULTI)
|
||||
void intmoduleTimerStart(uint32_t periodMs)
|
||||
{
|
||||
// Timer
|
||||
INTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN;
|
||||
INTMODULE_TIMER->PSC = INTMODULE_TIMER_FREQ / 2000000 - 1; // 0.5uS (2Mhz)
|
||||
INTMODULE_TIMER->ARR = periodMs * 2000;
|
||||
INTMODULE_TIMER->CCR2 = (periodMs - 1) * 2000;
|
||||
INTMODULE_TIMER->CCER = TIM_CCER_CC3E;
|
||||
INTMODULE_TIMER->CCMR2 = 0;
|
||||
INTMODULE_TIMER->EGR = 1; // Restart
|
||||
|
||||
INTMODULE_TIMER->CCMR2 = TIM_CCMR2_OC3M_1 | TIM_CCMR2_OC3M_0; // Toggle CC1 o/p
|
||||
INTMODULE_TIMER->SR &= ~TIM_SR_CC2IF; // Clear flag
|
||||
INTMODULE_TIMER->DIER |= TIM_DIER_CC2IE; // Enable this interrupt
|
||||
INTMODULE_TIMER->CR1 |= TIM_CR1_CEN;
|
||||
|
||||
NVIC_EnableIRQ(INTMODULE_TIMER_IRQn);
|
||||
NVIC_SetPriority(INTMODULE_TIMER_IRQn, 7);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE)
|
||||
extern "C" void INTMODULE_USART_IRQHandler(void)
|
||||
{
|
||||
@@ -217,12 +189,3 @@ void intmoduleSendNextFrame()
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(INTERNAL_MODULE_MULTI)
|
||||
extern "C" void INTMODULE_TIMER_IRQHandler()
|
||||
{
|
||||
INTMODULE_TIMER->SR &= ~TIM_SR_CC2IF; // clear flag
|
||||
setupPulsesInternalModule();
|
||||
intmoduleSendNextFrame();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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"
|
||||
#include "mixer_scheduler.h"
|
||||
|
||||
#if !defined(SIMU)
|
||||
|
||||
// Start scheduler with default period
|
||||
void mixerSchedulerStart()
|
||||
{
|
||||
MIXER_SCHEDULER_TIMER->CR1 &= ~TIM_CR1_CEN;
|
||||
|
||||
MIXER_SCHEDULER_TIMER->CR1 = TIM_CR1_URS; // do not generate interrupt on soft update
|
||||
MIXER_SCHEDULER_TIMER->PSC = MIXER_SCHEDULER_TIMER_FREQ / 2000000 - 1; // 0.5uS (2Mhz)
|
||||
MIXER_SCHEDULER_TIMER->CCER = 0;
|
||||
MIXER_SCHEDULER_TIMER->CCMR1 = 0;
|
||||
MIXER_SCHEDULER_TIMER->ARR = 2 * getMixerSchedulerPeriod() - 1;
|
||||
MIXER_SCHEDULER_TIMER->EGR = TIM_EGR_UG; // reset timer
|
||||
|
||||
NVIC_EnableIRQ(MIXER_SCHEDULER_TIMER_IRQn);
|
||||
NVIC_SetPriority(MIXER_SCHEDULER_TIMER_IRQn, 8);
|
||||
|
||||
MIXER_SCHEDULER_TIMER->SR &= TIM_SR_UIF; // clear interrupt flag
|
||||
MIXER_SCHEDULER_TIMER->DIER |= TIM_DIER_UIE; // enable interrupt
|
||||
MIXER_SCHEDULER_TIMER->CR1 |= TIM_CR1_CEN;
|
||||
}
|
||||
|
||||
void mixerSchedulerStop()
|
||||
{
|
||||
MIXER_SCHEDULER_TIMER->CR1 &= ~TIM_CR1_CEN;
|
||||
NVIC_DisableIRQ(MIXER_SCHEDULER_TIMER_IRQn);
|
||||
}
|
||||
|
||||
void mixerSchedulerResetTimer()
|
||||
{
|
||||
mixerSchedulerDisableTrigger();
|
||||
MIXER_SCHEDULER_TIMER->CNT = 0;
|
||||
mixerSchedulerEnableTrigger();
|
||||
}
|
||||
|
||||
void mixerSchedulerEnableTrigger()
|
||||
{
|
||||
MIXER_SCHEDULER_TIMER->DIER |= TIM_DIER_UIE; // enable interrupt
|
||||
}
|
||||
|
||||
void mixerSchedulerDisableTrigger()
|
||||
{
|
||||
MIXER_SCHEDULER_TIMER->DIER &= ~TIM_DIER_UIE; // disable interrupt
|
||||
}
|
||||
|
||||
extern "C" void MIXER_SCHEDULER_TIMER_IRQHandler(void)
|
||||
{
|
||||
MIXER_SCHEDULER_TIMER->SR &= ~TIM_SR_UIF; // clear flag
|
||||
mixerSchedulerDisableTrigger();
|
||||
|
||||
// set next period
|
||||
MIXER_SCHEDULER_TIMER->ARR = 2 * getMixerSchedulerPeriod() - 1;
|
||||
|
||||
// trigger mixer start
|
||||
mixerSchedulerISRTrigger();
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user