main() is now complete until before the main loop.

This commit is contained in:
Dual Tachyon 2023-08-14 22:26:27 +01:00
parent ed06b4aed9
commit 21e2bba583
9 changed files with 255 additions and 3 deletions

View File

@ -693,3 +693,36 @@ void BK4819_TransmitTone(bool bLocalLoopback, uint32_t Frequency)
BK4819_ExitTxMute();
}
void BK4819_GenTail(uint8_t Tail)
{
switch(Tail) {
case 0: // CTC134
BK4819_WriteRegister(BK4819_REG_52, 0x828F);
break;
case 1: // CTC120
BK4819_WriteRegister(BK4819_REG_52, 0xA28F);
break;
case 2: // CTC180
BK4819_WriteRegister(BK4819_REG_52, 0xC28F);
break;
case 3: // CTC240
BK4819_WriteRegister(BK4819_REG_52, 0xE28F);
break;
case 4: // CTC55
BK4819_WriteRegister(BK4819_REG_07, 0x046f);
break;
}
}
void BK4819_EnableCDCSS(void)
{
BK4819_GenTail(0); // CTC134
BK4819_WriteRegister(BK4819_REG_51, 0x804A);
}
void BK4819_EnableCTCSS(void)
{
BK4819_GenTail(4); // CTC55
BK4819_WriteRegister(BK4819_REG_51, 0x904A);
}

View File

@ -96,5 +96,9 @@ void BK4819_PlayDTMFString(char *pString, bool bDelayFirst, uint16_t FirstCodePe
void BK4819_TransmitTone(bool bLocalLoopback, uint32_t Frequency);
void BK4819_GenTail(uint8_t Tail);
void BK4819_EnableCDCSS(void);
void BK4819_EnableCTCSS(void);
#endif

View File

@ -15,6 +15,8 @@
*/
#include "frequencies.h"
#include "misc.h"
#include "settings.h"
const uint32_t LowerLimitFrequencyBandTable[7] = {
5000000,
@ -119,3 +121,73 @@ uint32_t FREQUENCY_FloorToStep(uint32_t Frequency, uint32_t Step, uint32_t Base)
return Base + (Step * Index);
}
int FREQUENCY_Check(RADIO_Info_t *pInfo)
{
uint32_t Frequency;
if (pInfo->CHANNEL_SAVE >= 207) {
return -1;
}
Frequency = pInfo->pDCS_Reverse->Frequency;
if (gSetting_F_LOCK == F_LOCK_FCC) {
if ((Frequency + 14400000) < 399991) {
return 0;
}
if (2999990 < (Frequency - 42000000)) {
return -1;
}
return 0;
}
if (gSetting_F_LOCK == F_LOCK_CE) {
if ((Frequency - 14400000) < 199991) {
return 0;
}
}
if (gSetting_F_LOCK != F_LOCK_GB) {
if (gSetting_F_LOCK != F_LOCK_430) {
if (gSetting_F_LOCK == F_LOCK_438) {
if ((Frequency - 13600000) < 3799991) {
return 0;
}
if ((Frequency - 40000000) < 3799991) {
return 0;
}
return -1;
}
if ((Frequency - 13600000) < 3799991) {
return 0;
}
if (((Frequency - 35000000) < 4999991 && gSetting_350TX && gSetting_350EN)) {
return 0;
}
if ((Frequency - 40000000) < 6999991) {
return 0;
}
if ((Frequency - 17400000) < 17599991 && gSetting_200TX) {
return 0;
}
if ((Frequency - 47000000) < 13000001 && gSetting_500TX) {
return 0;
}
return -1;
}
if ((Frequency - 13600000) < 3799991) {
return 0;
}
if (2999990 < (Frequency - 40000000)) {
return -1;
}
}
if ((Frequency - 14400000) < 399991) {
return 0;
}
if (999990 < (Frequency - 43000000)) {
return -1;
}
return 0;
}

View File

@ -18,6 +18,7 @@
#define FREQUENCIES_H
#include <stdint.h>
#include "radio.h"
enum FREQUENCY_Band_t {
BAND1_50MHz = 0,
@ -40,6 +41,7 @@ extern const uint16_t StepFrequencyTable[6];
FREQUENCY_Band_t FREQUENCY_GetBand(uint32_t Frequency);
uint32_t FREQUENCY_CalculateOutputPower(uint8_t TxpLow, uint8_t TxpMid, uint8_t TxpHigh, uint32_t LowerLimit, uint32_t Middle, uint32_t UpperLimit, uint32_t Frequency);
uint32_t FREQUENCY_FloorToStep(uint32_t Frequency, uint32_t Step, uint32_t Base);
int FREQUENCY_Check(RADIO_Info_t *pInfo);
#endif

View File

@ -87,13 +87,12 @@ void FUNCTION_Select(uint8_t Function)
if (Function == FUNCTION_0) {
if (g_200003BE != 0) {
// TODO
//FUN_00002014();
RADIO_Something();
}
if (PreviousFunction == FUNCTION_TRANSMIT) {
g_20000378 = 0;
g_20000379 = 0;
} else if (PreviousFunction != 0x04) {
} else if (PreviousFunction != FUNCTION_TRANSMIT) {
g_2000032E = 1000;
gSystickFlag5 = 0;
return;
@ -236,3 +235,4 @@ Skip:
gSystickFlag5 = 0;
g_2000038E = 0;
}

12
misc.c
View File

@ -25,6 +25,7 @@ bool gSetting_KILLED;
bool gSetting_200TX;
bool gSetting_500TX;
bool gSetting_350EN;
uint8_t gSetting_F_LOCK;
bool gSetting_ScrambleEnable;
uint8_t gSetting_F_LOCK;
@ -48,12 +49,17 @@ uint8_t gEEPROM_1F8E;
uint8_t gMR_ChannelParameters[207];
uint16_t g_2000032E;
uint16_t g_2000033A;
uint16_t g_2000033E = 1000;
uint8_t g_20000342;
uint8_t g_20000356;
uint8_t g_2000036B;
uint8_t g_2000036D;
uint8_t g_2000036E;
uint8_t g_2000036F;
uint8_t g_20000370;
uint8_t g_20000371[2];
uint8_t g_20000373;
uint8_t g_20000375;
uint8_t g_20000376;
uint8_t g_20000377;
@ -72,8 +78,12 @@ uint8_t g_200003AF;
uint8_t g_200003B0;
uint16_t g_200003B6;
uint8_t g_200003BC;
uint8_t g_200003BD;
uint8_t g_200003BE;
uint8_t g_200003C3;
uint8_t g_200003FD;
uint8_t g_20000400;
uint8_t g_2000041F;
uint8_t g_20000420;
uint8_t g_2000042F;
uint8_t g_20000438;
@ -104,9 +114,11 @@ uint8_t gShowChPrefix;
uint8_t gSystickCountdown2;
uint8_t gSystickCountdown3;
uint8_t gSystickCountdown4;
uint8_t gSystickFlag0;
uint8_t gSystickFlag10;
uint8_t gSystickFlag5;
uint8_t gSystickFlag6;
uint8_t gSystickFlag7;
uint8_t gSystickFlag8;
// --------

12
misc.h
View File

@ -28,6 +28,7 @@ extern bool gSetting_KILLED;
extern bool gSetting_200TX;
extern bool gSetting_500TX;
extern bool gSetting_350EN;
extern uint8_t gSetting_F_LOCK;
extern bool gSetting_ScrambleEnable;
extern uint8_t gSetting_F_LOCK;
@ -51,12 +52,17 @@ extern uint8_t gEEPROM_1F8E;
extern uint8_t gMR_ChannelParameters[207];
extern uint16_t g_2000032E;
extern uint16_t g_2000033A;
extern uint16_t g_2000033E;
extern uint8_t g_20000342;
extern uint8_t g_20000356;
extern uint8_t g_2000036B;
extern uint8_t g_2000036D;
extern uint8_t g_2000036E;
extern uint8_t g_2000036F;
extern uint8_t g_20000370;
extern uint8_t g_20000371[2];
extern uint8_t g_20000373;
extern uint8_t g_20000375;
extern uint8_t g_20000376;
extern uint8_t g_20000377;
@ -75,8 +81,12 @@ extern uint8_t g_200003AF;
extern uint8_t g_200003B0;
extern uint16_t g_200003B6;
extern uint8_t g_200003BC;
extern uint8_t g_200003BD;
extern uint8_t g_200003BE;
extern uint8_t g_200003C3;
extern uint8_t g_200003FD;
extern uint8_t g_20000400;
extern uint8_t g_2000041F;
extern uint8_t g_20000420;
extern uint8_t g_2000042F;
extern uint8_t g_20000438;
@ -107,9 +117,11 @@ extern uint8_t gShowChPrefix;
extern uint8_t gSystickCountdown2;
extern uint8_t gSystickCountdown3;
extern uint8_t gSystickCountdown4;
extern uint8_t gSystickFlag0;
extern uint8_t gSystickFlag10;
extern uint8_t gSystickFlag5;
extern uint8_t gSystickFlag6;
extern uint8_t gSystickFlag7;
extern uint8_t gSystickFlag8;
// --------

108
radio.c
View File

@ -15,6 +15,8 @@
*/
#include <string.h>
#include "audio.h"
#include "battery.h"
#include "bsp/dp32g030/gpio.h"
#include "dcs.h"
#include "driver/bk4819.h"
@ -646,3 +648,109 @@ void RADIO_PrepareTransmit(void)
BK4819_SetCTCSSBaudRate(CTCSS_Options[gCrossTxRadioInfo->pDCS_Reverse->RX_TX_Code + 1]);
}
void RADIO_SomethingElse(uint8_t Arg)
{
if (Arg == 0) {
g_20000371[0] = 0;
g_20000371[1] = 0;
g_20000373 = 0;
} else {
if (Arg == 6) {
g_20000371[0] = 6;
g_20000371[1] = 3;
} else {
uint8_t Channel;
Channel = gEeprom.RX_CHANNEL;
if (gEeprom.CROSS_BAND_RX_TX != 0) {
Channel = gEeprom.TX_CHANNEL;
}
g_20000371[Channel] = Arg;
}
g_20000373 = 5;
}
gUpdateDisplay = true;
}
void RADIO_SomethingWithTransmit(void)
{
if (gEeprom.DUAL_WATCH != 0) {
g_2000033A = 360;
gSystickFlag7 = 0;
if (g_2000041F == 0) {
gEeprom.RX_CHANNEL = gEeprom.TX_CHANNEL;
gInfoCHAN_A = gEeprom.RadioInfo + gEeprom.TX_CHANNEL;
}
g_2000041F = 1;
}
RADIO_ConfigureCrossTX();
if (g_20000383 == 0 || g_20000383 == 3 || (g_20000383 == 1 && gEeprom.ALARM_MODE == 1)) {
uint8_t Value;
if (!FREQUENCY_Check(gCrossTxRadioInfo)) {
if (gCrossTxRadioInfo->BUSY_CHANNEL_LOCK == true && gCurrentFunction == FUNCTION_4) {
Value = 1;
} else if (gBatteryDisplayLevel == 0) {
Value = 2;
} else {
// TODO: Fix this goto, a bit painful to disentangle
if (gBatteryDisplayLevel != 6) {
goto LAB_00007c20;
}
Value = 6;
}
} else {
Value = 3;
}
RADIO_SomethingElse(Value);
g_20000383 = 0;
AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL);
} else {
LAB_00007c20:
if (g_200003BE == 1) {
if (g_20000438 == 2) {
g_200003BD = 1;
g_200003BC = 0;
g_200003C3 = 6;
}
else {
g_200003BC = 1;
g_200003BD = 0;
}
}
FUNCTION_Select(FUNCTION_TRANSMIT);
if (g_20000383 == 0) {
g_2000033E = gEeprom.TX_TIMEOUT_TIMER * 120;
} else {
g_2000033E = 0;
}
gSystickFlag0 = 0;
g_200003FD = 0;
g_2000036D = 0;
}
g_200003BE = 0;
}
void RADIO_EnableCxCSS(void)
{
switch (gCrossTxRadioInfo->pDCS_Reverse->CodeType) {
case CODE_TYPE_DIGITAL:
case CODE_TYPE_REVERSE_DIGITAL:
BK4819_EnableCDCSS();
break;
default:
BK4819_EnableCTCSS();
break;
}
SYSTEM_DelayMs(200);
}
void RADIO_Something(void)
{
RADIO_SomethingWithTransmit();
SYSTEM_DelayMs(200);
RADIO_EnableCxCSS();
RADIO_SetupRegisters(true);
}

View File

@ -26,6 +26,15 @@ enum {
POWER_ON_DISPLAY_MODE_VOLTAGE = 2U,
};
enum {
F_LOCK_OFF = 0U,
F_LOCK_FCC = 1U,
F_LOCK_CE = 2U,
F_LOCK_GB = 3U,
F_LOCK_430 = 4U,
F_LOCK_438 = 5U,
};
typedef struct {
uint8_t EEPROM_0E80_0E83[2];
uint8_t EEPROM_0E82_0E85[2];