Files
edgetx-gx12/radio/src/targets/common/arm/stm32/mixer_scheduler_driver.cpp
T
Raphael CoefficandRaphael Coeffic 916651033c Fixed mixer scheduler timer overflow
The max period is now 50ms, so that it overflows the 16bit timer when set to the max period.
Many thanks to @marianomd for finding the issue and the proposed fix!
2021-11-21 21:53:11 +01:00

86 lines
2.4 KiB
C++

/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* 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)
#include "FreeRTOSConfig.h"
// 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 / 1000000 - 1; // 1uS (1Mhz)
MIXER_SCHEDULER_TIMER->CCER = 0;
MIXER_SCHEDULER_TIMER->CCMR1 = 0;
MIXER_SCHEDULER_TIMER->ARR = getMixerSchedulerPeriod() - 1;
MIXER_SCHEDULER_TIMER->EGR = TIM_EGR_UG; // reset timer
NVIC_EnableIRQ(MIXER_SCHEDULER_TIMER_IRQn);
NVIC_SetPriority(MIXER_SCHEDULER_TIMER_IRQn,
configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
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 = getMixerSchedulerPeriod() - 1;
// trigger mixer start
mixerSchedulerISRTrigger();
}
#endif