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-14 05:55:14 +08:00
|
|
|
#if defined(ENABLE_FMRADIO)
|
2023-09-04 22:26:28 +08:00
|
|
|
#include "app/fm.h"
|
2023-09-14 05:55:14 +08:00
|
|
|
#endif
|
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"
|
2023-08-29 03:13:33 +08:00
|
|
|
#include "helper/battery.h"
|
2023-08-15 06:38:59 +08:00
|
|
|
#include "misc.h"
|
|
|
|
#include "settings.h"
|
|
|
|
|
2023-09-04 22:00:55 +08:00
|
|
|
#define DECREMENT_AND_TRIGGER(cnt, flag) \
|
|
|
|
do { \
|
|
|
|
if (cnt) { \
|
|
|
|
if (--cnt == 0) { \
|
|
|
|
flag = true; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
2023-08-15 18:14:43 +08:00
|
|
|
static volatile uint32_t gGlobalSysTickCounter;
|
2023-08-15 06:38:59 +08:00
|
|
|
|
2023-08-16 17:04:06 +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-09-04 22:00:55 +08:00
|
|
|
DECREMENT_AND_TRIGGER(gTxTimerCountdown, gTxTimeoutReached);
|
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-09-05 05:26:57 +08:00
|
|
|
if (gCurrentFunction == FUNCTION_FOREGROUND) {
|
2023-09-04 22:00:55 +08:00
|
|
|
DECREMENT_AND_TRIGGER(gBatterySaveCountdown, gSchedulePowerSave);
|
2023-08-15 06:38:59 +08:00
|
|
|
}
|
2023-09-04 22:00:55 +08:00
|
|
|
if (gCurrentFunction == FUNCTION_POWER_SAVE) {
|
|
|
|
DECREMENT_AND_TRIGGER(gBatterySave, gBatterySaveCountdownExpired);
|
2023-08-15 06:38:59 +08:00
|
|
|
}
|
2023-09-04 22:00:55 +08:00
|
|
|
|
2023-09-04 22:26:28 +08:00
|
|
|
if (gScanState == SCAN_OFF && gCssScanMode == CSS_SCAN_MODE_OFF && gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) {
|
2023-08-29 07:37:06 +08:00
|
|
|
if (gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT) {
|
2023-08-30 19:14:01 +08:00
|
|
|
if (gCurrentFunction != FUNCTION_RECEIVE) {
|
2023-09-04 22:00:55 +08:00
|
|
|
DECREMENT_AND_TRIGGER(gDualWatchCountdown, gScheduleDualWatch);
|
2023-08-15 06:38:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-14 18:30:08 +08:00
|
|
|
#if defined(ENABLE_NOAA)
|
2023-09-04 22:26:28 +08:00
|
|
|
if (gScanState == SCAN_OFF && gCssScanMode == CSS_SCAN_MODE_OFF && gEeprom.DUAL_WATCH == DUAL_WATCH_OFF) {
|
2023-08-29 07:37:06 +08:00
|
|
|
if (gIsNoaaMode && gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT) {
|
2023-08-30 19:14:01 +08:00
|
|
|
if (gCurrentFunction != FUNCTION_RECEIVE) {
|
2023-09-04 22:00:55 +08:00
|
|
|
DECREMENT_AND_TRIGGER(gNOAA_Countdown, gScheduleNOAA);
|
2023-08-15 06:38:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-09-14 18:30:08 +08:00
|
|
|
#endif
|
2023-08-15 06:38:59 +08:00
|
|
|
|
2023-09-04 22:26:28 +08:00
|
|
|
if (gScanState != SCAN_OFF || gCssScanMode == CSS_SCAN_MODE_SCANNING) {
|
2023-08-29 07:37:06 +08:00
|
|
|
if (gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT) {
|
2023-09-04 22:00:55 +08:00
|
|
|
DECREMENT_AND_TRIGGER(ScanPauseDelayIn10msec, gScheduleScanListen);
|
2023-08-15 06:38:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-07 20:30:52 +08:00
|
|
|
DECREMENT_AND_TRIGGER(gTailNoteEliminationCountdown, gFlagTteComplete);
|
2023-08-15 06:38:59 +08:00
|
|
|
|
2023-09-04 22:00:55 +08:00
|
|
|
DECREMENT_AND_TRIGGER(gCountdownToPlayNextVoice, gFlagPlayQueuedVoice);
|
2023-08-15 06:38:59 +08:00
|
|
|
|
2023-09-14 05:55:14 +08:00
|
|
|
#if defined(ENABLE_FMRADIO)
|
2023-09-04 22:26:28 +08:00
|
|
|
if (gFM_ScanState != FM_SCAN_OFF && gCurrentFunction != FUNCTION_MONITOR) {
|
2023-08-30 19:14:01 +08:00
|
|
|
if (gCurrentFunction != FUNCTION_TRANSMIT && gCurrentFunction != FUNCTION_RECEIVE) {
|
2023-09-04 22:00:55 +08:00
|
|
|
DECREMENT_AND_TRIGGER(gFmPlayCountdown, gScheduleFM);
|
2023-08-15 06:38:59 +08:00
|
|
|
}
|
|
|
|
}
|
2023-09-14 05:55:14 +08:00
|
|
|
#endif
|
2023-09-03 18:47:36 +08:00
|
|
|
if (gVoxStopCountdown) {
|
|
|
|
gVoxStopCountdown--;
|
2023-08-15 06:38:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|