More refactoring

Lots of things removed but compiles again
This commit is contained in:
2025-06-25 11:18:44 -05:00
parent 0556b06cab
commit 2ff7291c63
31 changed files with 1247 additions and 2569 deletions

View File

@@ -14,9 +14,8 @@
#include <stdbool.h>
#include <stdint.h>
#include "arm_math.h"
#include "arm_math.h"
#include "ports.h"
#include "frq.h"
#include "spi.h"
#include "display.h"
#include "utils.h"
@@ -32,6 +31,7 @@
#include "System/system.h"
#include "usbComms.h"
#include "driver.h"
#include "broadcast.h"
uint16_t Port_timer;
uint16_t Taps_adjust_timer;
@@ -49,87 +49,18 @@ extern SYSTEM_DATA_t sys;
uint8_t whatever;
static uint8_t Bcast_LF_Value[5] = {0,5,10,15,20};
static uint8_t Bcast_HF_Value[5] = {0,12,25,37,50};
static int handleBroadcast(ACCESSORY_t *accy)
bool ACCY_timedOut(ACCESSORY_t *accy)
{
switch (accy->state)
{
case PORT_STATE_INIT:
{
if (accy->initState)
{
// use the current frequency if it is valid, otherwise, set to the lowest valid for broadcast
sys.frequency = 3140;
return (sys.systemTime >= accy->stateTimer);
}
if(sys.frequency <= 8010)
BC_Duty_Cycle = Bcast_LF_Value[0];
else
BC_Duty_Cycle = Bcast_HF_Value[0];
PWM_Setup(sys.frequency, BC_Duty_Cycle);//freqArray[frequency].frequency1
driver_broadcastOn(true);
accy->stateTimer = sys.systemTime + 500;
}
if (sys.systemTime >= accy->stateTimer)
{
accy->state = PORT_STATE_RUNNING;
}
break;
}
case PORT_STATE_DEINIT:
{
if (accy->initState)
{
//USB_SendString("Broadcast deinitializing...");
// turn off the amp and antenna
driver_broadcastOn(false);
delayms(50);
// turn off PWM
driver_setDuty(0);
// set PSU to minimum
driver_setPSUVoltage(V_24V);
accy->stateTimer = sys.systemTime + 500;
}
if (sys.systemTime >= accy->stateTimer)
{
accy->state = PORT_STATE_STANDBY;
//USB_SendString("Broadcast in standby!");
}
break;
}
case PORT_STATE_RUNNING:
{
if (accy->initState)
{
//USB_SendString("Broadcast running!");
}
break;
}
default:
return -1;
}
return 0;
void ACCY_setTimeout(ACCESSORY_t *accy, uint32_t msec)
{
accy->stateTimer = sys.systemTime + msec;
}
static int handleClamp(ACCESSORY_t *accy)
{
switch (accy->state)
{
case PORT_STATE_INIT:
@@ -388,7 +319,7 @@ bool ACCY_Connect(ACCESSORY_t *accy, ACCY_ID_t id)
case ID_BROADCAST:
{
accy->channels[CHANNEL_A].connected = true;
accy->handler = handleBroadcast;
accy->handler = broadcast_service;
break;
}
@@ -497,23 +428,7 @@ bool ACCY_isKnown(ACCY_ID_t id)
}
ACCY_ID_t ACCY_GetConnectedAccessory(uint8_t port)
{
return ID_NONE;
}
ACCY_ID_t ACCY_GetActive(void)
{
if(Cur_Mode == PORT1_A)
{
return ACCY_GetConnectedAccessory(1);
}
else
{
return ACCY_GetConnectedAccessory(2);
}
}
void Read_Tx_Ports(void) // check for whats plugged in at the ports every 100mS.
@@ -530,241 +445,4 @@ void Read_Tx_Ports(void) // check for whats plugged in at the ports every 100mS.
void Select_Output_Port(void) // which DC Out port, to switch on
{
Port_State[MID_SR] &= OUT_RELAY_OFF_MASK;
if (Cur_Mode != BROADCAST)
{
Delay_Ticks(DELAY_100MS);
if(Compare_Voltage(sys.adc.V_CHK, MAX_BYPASS_VOLTS))
{
sys.status[OVERVOLTAGE] = true;
Select_Bypass(OFF); // Force into blocked state.
Delay_Ticks(20);
}
// HACK
Select_Estop(CONNECTED); // Ensure output is not ISOLATED from connections
switch (Cur_Mode)
{
case PORT1_A:
Port_State[MID_SR] |= PORT1A_ON;
break;
case PORT1_B:
Port_State[MID_SR] |= PORT1B_ON;
break;
case PORT2_A:
Port_State[MID_SR] |= PORT2A_ON;
break;
case PORT2_B:
Port_State[MID_SR] |= PORT2B_ON;
break;
default:
Port_State[MID_SR] |= PORT2B_ON; // TODO Later disconnect??
break;
}
Disable_BC();
Reset_Power_Gain();
Port_changed_flag = false;
SPI0_SendBytes(Port_State, 3, EXPANDER);
}
else
{ // Assumes broadcast mode has just been selected
Disable_DC(); // Shut down Direct connect circuitry
Select_Estop(ISOLATED); // Ensure output is ISOLATED from connections
Tx_ConfigureFrequency(); // Select correct frequency
Enable_BC(); // Enable BCAST circuitry using either Minimum or previously selected freq
Port_changed_flag = false;
}
}
void Reset_Power_Gain(void)
{
Power_Level = 0;
Bcast_Pwr_Level = 0;
// if( (ACCY_GetConnectedAccessory(1) != ID_CLAMP) && (ACCY_GetConnectedAccessory(2) != ID_CLAMP))
if(!Check_For_Clamp())
{
if (freqArray[frequency].frequency1 <= MAX_DTYPE)
Dds_Pot_Val[1] = Pot_Value[Power_Level]; // data
else
Dds_Pot_Val[1] = Pot_Value_AB[Power_Level]; // data
}
else
Get_Clamp_Value();
Dds_Pot_Val[0] = 0; // address
SPI0_SendBytes(Dds_Pot_Val, 2, AMPLITUDE);
Delay_Ticks(30); // Set power out level 1 3/20/24
// Power_Level = 1;
// if(Init_Done)
// {
// Delay_Ticks(10); // Set power out level 1 3/20/24
// Power_Level++;
// inc_pwr();
Init_Done = false;
// }
}
void Tx_ConfigureFrequency(void)
{
uint32_t tmp_frq;
if (freqArray[frequency].bc_enabled == false && Cur_Mode == BROADCAST) // if (freq < min freq) ToDo
{
tmp_frq = Search_BC_Frequency(); // select minimum frequency for BCAST
if (tmp_frq < FREQ_MAX_NUM)
frequency = tmp_frq;
//endif
}
}
uint32_t Search_BC_Frequency(void)
{
uint32_t idx;
idx = 0;
while (freqArray[idx].bc_enabled == false && idx < FREQ_MAX_NUM)
idx++;
if (idx >= FREQ_MAX_NUM)
idx = FREQ_MAX_NUM;
return(idx);
}
uint32_t Search_Frequency(uint32_t pattern)
{
uint32_t idx;
idx = 0;
while (freqArray[idx].frequency1 != pattern && idx < FREQ_MAX_NUM)
idx++;
if (idx >= FREQ_MAX_NUM)
idx = FREQ_MAX_NUM;
return(idx);
}
void Disable_DC(void)
{
All_Amps_Off(); // shut down Amplifiers DC connections
// Shut off all amplifier enables
// Reset_DDS(); // Stop all DDS chips
// Set_PSU_Voltage(V_18V); //MID_POINT_PSU 18,24,27,30,36, 55
// Set PSU to MIN.
}
void Enable_BC(void)
{
// if((freqArray[old_freq].frequency1 >8010 ) && (freqArray[frequency].frequency1 < 8010))
// Cycled_Freq_Change_BC(LF);
// else
// {
// if((freqArray[old_freq].frequency1 < 8010 ) && (freqArray[frequency].frequency1 > 8010))
// Cycled_Freq_Change_BC(HF);
// }
if(freqArray[frequency].frequency1 <= 8010)
BC_Duty_Cycle = Bcast_LF_Value[Bcast_Pwr_Level];
else
BC_Duty_Cycle = Bcast_HF_Value[Bcast_Pwr_Level];
PWM_Setup(freqArray[frequency].frequency1, BC_Duty_Cycle);//freqArray[frequency].frequency1
Port_State[MID_SR] |=ANT_AMP_EN; // Enable Antenna amp
// Port_State[BOTTOM_SR] |= ANT_AMP_PWR; // Enable PWR Switch
Port_State[TOP_SR] |= ANT_AMP_SW;
SPI0_SendBytes(Port_State, 3, EXPANDER); // Update shift register
Delay_Ticks(5);
Set_PSU_Voltage(V_27V); // Set PSU to MAX
Port_State[BOTTOM_SR] &= AMP_PSU_ON; // switch AMP PSU on
SPI0_SendBytes(Port_State, 3, EXPANDER); // Update shift register
}
void Cycled_Freq_Change_BC(uint8_t value)
{
if(value == LF)
{
if(Bcast_Pwr_Level == MAX_BCAST_PWR)
Bcast_Pwr_Level--;
BC_Duty_Cycle = 10;
BC_Duty_Cycle = BC_Duty_Cycle + Bcast_Pwr_Level*5;
}
else
{
BC_Duty_Cycle = 10;
BC_Duty_Cycle = BC_Duty_Cycle + Bcast_Pwr_Level*10;
}
}
void Enable_DC(void)
{
// Switch on correct amplifier enables
// Switch on correct power switches
// Enable correct DDS chips
// Set PSU to Medium.
}
void Disable_BC(void)
{
Port_State[MID_SR] &=~ANT_AMP_EN; // disable Antenna amp
// Port_State[BOTTOM_SR] |=ANT_AMP_PWR; // Enable PWR Switch
Port_State[TOP_SR] &= ~ANT_AMP_SW;
SPI0_SendBytes(Port_State, 3, EXPANDER); // Update shift register
// Change the SCT clock back here
PWM_Setup(15890, 0); // switches off PWM // Set duty cycle to zero
Delay_Ticks(5);
Set_PSU_Voltage(V_24V); // Set PSU to MIN
// Init_PWM_CLKS(DC_CLK); // Return timer clock to internal
}
bool Is_Clamp_Detected(void)
{
if((ACCY_GetConnectedAccessory(1) == ID_CLAMP) || (ACCY_GetConnectedAccessory(2) == ID_CLAMP) || (ACCY_GetConnectedAccessory(1) == ID_CLAMP2) || (ACCY_GetConnectedAccessory(2) == ID_CLAMP2))
return(true);
else
return(false);
}