mirror of
https://github.com/opentx/opentx.git
synced 2025-07-23 16:25:16 +03:00
[ARM] Mixers calculated just-in-time
This commit is contained in:
parent
ce0b17744c
commit
29325ad54f
5 changed files with 45 additions and 3 deletions
|
@ -223,6 +223,8 @@ const char * debugTimerNames[DEBUG_TIMERS_COUNT] = {
|
||||||
,"ADC read " // debugTimerAdcRead,
|
,"ADC read " // debugTimerAdcRead,
|
||||||
,"ADC loop " // debugTimerAdcLoop,
|
,"ADC loop " // debugTimerAdcLoop,
|
||||||
,"ADC wait " // debugTimerAdcWait,
|
,"ADC wait " // debugTimerAdcWait,
|
||||||
|
,"mix-pulses " // debugTimerMixerCalcToUsage
|
||||||
|
,"mix-int. " // debugTimerMixerIterval
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -324,6 +324,9 @@ enum DebugTimers {
|
||||||
debugTimerAdcLoop,
|
debugTimerAdcLoop,
|
||||||
debugTimerAdcWait,
|
debugTimerAdcWait,
|
||||||
|
|
||||||
|
debugTimerMixerCalcToUsage,
|
||||||
|
debugTimerMixerIterval,
|
||||||
|
|
||||||
DEBUG_TIMERS_COUNT
|
DEBUG_TIMERS_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -717,6 +717,7 @@ extern uint8_t flightModeTransitionLast;
|
||||||
void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms);
|
void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms);
|
||||||
void evalMixes(uint8_t tick10ms);
|
void evalMixes(uint8_t tick10ms);
|
||||||
void doMixerCalculations();
|
void doMixerCalculations();
|
||||||
|
void scheduleNextMixerCalculation(uint8_t module, uint16_t delay);
|
||||||
|
|
||||||
#if defined(CPUARM)
|
#if defined(CPUARM)
|
||||||
void checkTrims();
|
void checkTrims();
|
||||||
|
|
|
@ -179,12 +179,14 @@ void setupPulses(unsigned int port)
|
||||||
switch (required_protocol) {
|
switch (required_protocol) {
|
||||||
case PROTO_PXX:
|
case PROTO_PXX:
|
||||||
setupPulsesPXX(port);
|
setupPulsesPXX(port);
|
||||||
|
scheduleNextMixerCalculation(port, 9);
|
||||||
break;
|
break;
|
||||||
#if defined(DSM2)
|
#if defined(DSM2)
|
||||||
case PROTO_DSM2_LP45:
|
case PROTO_DSM2_LP45:
|
||||||
case PROTO_DSM2_DSM2:
|
case PROTO_DSM2_DSM2:
|
||||||
case PROTO_DSM2_DSMX:
|
case PROTO_DSM2_DSMX:
|
||||||
setupPulsesDSM2(port);
|
setupPulsesDSM2(port);
|
||||||
|
scheduleNextMixerCalculation(port, 11);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(CROSSFIRE)
|
#if defined(CROSSFIRE)
|
||||||
|
@ -194,6 +196,7 @@ void setupPulses(unsigned int port)
|
||||||
uint8_t * crossfire = modulePulsesData[port].crossfire.pulses;
|
uint8_t * crossfire = modulePulsesData[port].crossfire.pulses;
|
||||||
createCrossfireFrame(crossfire, &channelOutputs[g_model.moduleData[port].channelsStart]);
|
createCrossfireFrame(crossfire, &channelOutputs[g_model.moduleData[port].channelsStart]);
|
||||||
sportSendBuffer(crossfire, CROSSFIRE_FRAME_LEN);
|
sportSendBuffer(crossfire, CROSSFIRE_FRAME_LEN);
|
||||||
|
// TODO scheduleNextMixerCalculation()
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -205,6 +208,7 @@ void setupPulses(unsigned int port)
|
||||||
#endif
|
#endif
|
||||||
case PROTO_PPM:
|
case PROTO_PPM:
|
||||||
setupPulsesPPM(port);
|
setupPulsesPPM(port);
|
||||||
|
scheduleNextMixerCalculation(port, (45+g_model.moduleData[port].ppm.frameLength)/2);
|
||||||
break ;
|
break ;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -91,8 +91,11 @@ uint16_t stackAvailable()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
uint32_t nextMixerTime[NUM_MODULES];
|
||||||
|
|
||||||
void mixerTask(void * pdata)
|
void mixerTask(void * pdata)
|
||||||
{
|
{
|
||||||
|
static uint32_t lastRunTime;
|
||||||
s_pulses_paused = true;
|
s_pulses_paused = true;
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
|
@ -102,12 +105,35 @@ void mixerTask(void * pdata)
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
CoTickDelay(1);
|
||||||
|
|
||||||
|
uint32_t now = CoGetOSTime();
|
||||||
|
bool run = false;
|
||||||
|
if ((now - lastRunTime) > 10) { // run at least every 20ms
|
||||||
|
run = true;
|
||||||
|
}
|
||||||
|
else if (now == nextMixerTime[0]) {
|
||||||
|
run = true;
|
||||||
|
}
|
||||||
|
#if NUM_MODULES >= 2
|
||||||
|
else if (now == nextMixerTime[1]) {
|
||||||
|
run = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (!run) {
|
||||||
|
continue; // go back to sleep
|
||||||
|
}
|
||||||
|
|
||||||
|
lastRunTime = now;
|
||||||
|
|
||||||
if (!s_pulses_paused) {
|
if (!s_pulses_paused) {
|
||||||
uint16_t t0 = getTmr2MHz();
|
uint16_t t0 = getTmr2MHz();
|
||||||
|
|
||||||
DEBUG_TIMER_START(debugTimerMixer);
|
DEBUG_TIMER_START(debugTimerMixer);
|
||||||
CoEnterMutexSection(mixerMutex);
|
CoEnterMutexSection(mixerMutex);
|
||||||
doMixerCalculations();
|
doMixerCalculations();
|
||||||
|
DEBUG_TIMER_START(debugTimerMixerCalcToUsage);
|
||||||
|
DEBUG_TIMER_SAMPLE(debugTimerMixerIterval);
|
||||||
CoLeaveMutexSection(mixerMutex);
|
CoLeaveMutexSection(mixerMutex);
|
||||||
DEBUG_TIMER_STOP(debugTimerMixer);
|
DEBUG_TIMER_STOP(debugTimerMixer);
|
||||||
|
|
||||||
|
@ -125,12 +151,18 @@ void mixerTask(void * pdata)
|
||||||
t0 = getTmr2MHz() - t0;
|
t0 = getTmr2MHz() - t0;
|
||||||
if (t0 > maxMixerDuration) maxMixerDuration = t0 ;
|
if (t0 > maxMixerDuration) maxMixerDuration = t0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
CoTickDelay(1); // 2ms for now
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MENU_TASK_PERIOD_TICKS 10 // 20ms
|
void scheduleNextMixerCalculation(uint8_t module, uint16_t delay)
|
||||||
|
{
|
||||||
|
// Schedule next mixer calculation time,
|
||||||
|
// for now assume mixer calculation takes 2 ms.
|
||||||
|
nextMixerTime[module] = (uint32_t)CoGetOSTime() + (delay)/2 - 1/*2ms*/;
|
||||||
|
DEBUG_TIMER_STOP(debugTimerMixerCalcToUsage);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define MENU_TASK_PERIOD_TICKS 25 // 50ms
|
||||||
|
|
||||||
void menusTask(void * pdata)
|
void menusTask(void * pdata)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue