uv-k5-firmware/scheduler.c

131 lines
3.2 KiB
C
Raw Normal View History

2023-08-15 06:38:59 +08:00
/* Copyright 2023 Dual Tachyon
* https://github.com/DualTachyon
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2023-09-03 03:18:53 +08:00
#include "app/scanner.h"
2023-08-15 06:38:59 +08:00
#include "audio.h"
#include "functions.h"
#include "helper/battery.h"
2023-08-15 06:38:59 +08:00
#include "misc.h"
#include "settings.h"
2023-08-15 18:14:43 +08:00
static volatile uint32_t gGlobalSysTickCounter;
2023-08-15 06:38:59 +08:00
void SystickHandler(void);
2023-08-15 06:38:59 +08:00
void SystickHandler(void)
{
2023-08-15 18:14:43 +08:00
gGlobalSysTickCounter++;
gNextTimeslice = true;
2023-08-15 06:38:59 +08:00
if ((gGlobalSysTickCounter % 50) == 0) {
2023-08-16 05:39:26 +08:00
gNextTimeslice500ms = true;
2023-08-30 07:47:34 +08:00
if (gTxTimerCountdown) {
2023-08-16 05:39:26 +08:00
gTxTimerCountdown--;
if (gTxTimerCountdown == 0) {
2023-08-29 20:26:13 +08:00
gTxTimeoutReached = true;
2023-08-15 06:38:59 +08:00
}
}
}
if ((gGlobalSysTickCounter & 3) == 0) {
2023-08-16 05:39:26 +08:00
gNextTimeslice40ms = true;
2023-08-15 06:38:59 +08:00
}
2023-08-30 07:47:34 +08:00
if (gSystickCountdown2) {
2023-08-15 06:38:59 +08:00
gSystickCountdown2--;
}
2023-08-30 20:21:07 +08:00
if (gFoundCDCSSCountdown) {
gFoundCDCSSCountdown--;
2023-08-15 06:38:59 +08:00
}
2023-08-30 20:21:07 +08:00
if (gFoundCTCSSCountdown) {
gFoundCTCSSCountdown--;
2023-08-15 06:38:59 +08:00
}
2023-08-30 07:47:34 +08:00
if (gCurrentFunction == FUNCTION_0 && gBatterySaveCountdown) {
2023-08-29 20:26:13 +08:00
gBatterySaveCountdown--;
if (gBatterySaveCountdown == 0) {
gSchedulePowerSave = true;
2023-08-15 06:38:59 +08:00
}
}
2023-08-30 07:47:34 +08:00
if (gCurrentFunction == FUNCTION_POWER_SAVE && gBatterySave) {
2023-08-15 06:38:59 +08:00
gBatterySave--;
if (gBatterySave == 0) {
2023-08-15 18:14:43 +08:00
gBatterySaveCountdownExpired = true;
2023-08-15 06:38:59 +08:00
}
}
2023-08-27 19:32:21 +08:00
if (gStepDirection == 0 && g_20000381 == 0 && gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) {
if (gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT) {
2023-08-30 19:14:01 +08:00
if (gCurrentFunction != FUNCTION_RECEIVE) {
2023-09-03 01:11:04 +08:00
if (gDualWatchCountdown) {
gDualWatchCountdown--;
if (!gDualWatchCountdown) {
gScheduleDualWatch = true;
2023-08-15 06:38:59 +08:00
}
}
}
}
}
2023-08-27 19:32:21 +08:00
if (gStepDirection == 0 && g_20000381 == 0 && gEeprom.DUAL_WATCH == DUAL_WATCH_OFF) {
if (gIsNoaaMode && gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT) {
2023-08-30 19:14:01 +08:00
if (gCurrentFunction != FUNCTION_RECEIVE) {
2023-08-31 23:04:49 +08:00
if (gNOAA_Countdown) {
gNOAA_Countdown--;
if (gNOAA_Countdown == 0) {
gScheduleNOAA = true;
2023-08-15 06:38:59 +08:00
}
}
}
}
}
2023-08-30 07:47:34 +08:00
if (gStepDirection || g_20000381 == 1) {
if (gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT) {
2023-08-30 07:47:34 +08:00
if (ScanPauseDelayIn10msec) {
2023-08-15 06:38:59 +08:00
ScanPauseDelayIn10msec--;
if (ScanPauseDelayIn10msec == 0) {
2023-09-03 01:25:05 +08:00
gScheduleScanListen = true;
2023-08-15 06:38:59 +08:00
}
}
}
}
2023-08-30 07:47:34 +08:00
if (g_20000342) {
2023-08-15 06:38:59 +08:00
g_20000342--;
if (g_20000342 == 0) {
2023-08-15 18:14:43 +08:00
gSystickFlag10 = true;
2023-08-15 06:38:59 +08:00
}
}
2023-08-30 07:47:34 +08:00
if (gCountdownToPlayNextVoice) {
2023-08-15 06:38:59 +08:00
gCountdownToPlayNextVoice--;
if (gCountdownToPlayNextVoice == 0) {
gFlagPlayQueuedVoice = true;
}
}
2023-08-30 07:47:34 +08:00
if (gFM_Step && gCurrentFunction != FUNCTION_MONITOR) {
2023-08-30 19:14:01 +08:00
if (gCurrentFunction != FUNCTION_TRANSMIT && gCurrentFunction != FUNCTION_RECEIVE) {
2023-08-30 07:47:34 +08:00
if (gFmPlayCountdown) {
2023-08-29 20:26:13 +08:00
gFmPlayCountdown--;
if (gFmPlayCountdown == 0) {
gScheduleFM = true;
2023-08-15 06:38:59 +08:00
}
}
}
}
2023-08-30 07:47:34 +08:00
if (gSystickCountdown11) {
2023-08-15 06:38:59 +08:00
gSystickCountdown11--;
}
}