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

@@ -342,6 +342,9 @@
</tool>
</toolChain>
</folderInfo>
<fileInfo id="com.crt.advproject.config.exe.debug.1065441720.598071465" name="psu_ctrl.h" rcbsApplicability="disable" resourcePath="source/psu_ctrl.h" toolsToInvoke=""/>
<fileInfo id="com.crt.advproject.config.exe.debug.1065441720.1193857386" name="pro_key.h" rcbsApplicability="disable" resourcePath="source/pro_key.h" toolsToInvoke=""/>
<fileInfo id="com.crt.advproject.config.exe.debug.1065441720.1336799103" name="safety_key.h" rcbsApplicability="disable" resourcePath="source/safety_key.h" toolsToInvoke=""/>
<sourceEntries>
<entry flags="LOCAL|VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="CMSIS"/>
<entry flags="LOCAL|VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="LPC54114"/>
@@ -349,7 +352,7 @@
<entry flags="LOCAL|VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="component"/>
<entry flags="LOCAL|VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="device"/>
<entry flags="LOCAL|VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="drivers"/>
<entry flags="LOCAL|VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="source"/>
<entry excluding="psu_ctrl.h|pro_key.h|safety_key.h|sys_chk.c|taps.c|testMenu.c|safety_key.c|pwr_level.c|psu_ctrl.c|pro_key.c|mode.c|init.c|amps.c" flags="LOCAL|VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="source"/>
<entry flags="LOCAL|VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="startup"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="usb"/>
<entry flags="LOCAL|VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="utilities"/>

View File

@@ -88,7 +88,7 @@ void system_init(void)
sys.activeAccessory = NULL;
sys.nextAccessory = NULL;
sys.maxPowerLimit = POWER_LIMIT_ALKALINE; // default until battery type determined.
sys.driver = driver_getDriver();
char *ver = SW_VERSION;

View File

@@ -99,9 +99,7 @@ typedef struct
int h100HzTimer;
char tmpString[64];
// TODO: change to FREQUENCY_t*
uint32_t frequency;
TxDriver_t *driver;
} SYSTEM_DATA_t;

View File

@@ -29,7 +29,7 @@
#include "bootloader.h"
#include "eeprom.h"
#include "System/system.h"
#include "frq.h"
//#include "frq.h"
#include "hwFixes.h"
#include "usbComms.h"
@@ -278,8 +278,8 @@ void USB_ProcessSystemCommand(void)
{
//Save settings data
EE_SaveData();
frq_update_flag = false;
Change_To_Next_BC_Freq();
//frq_update_flag = false;
//Change_To_Next_BC_Freq();
USB_SendString(ACK);
}
@@ -346,16 +346,17 @@ void USB_ProcessFrequencyCommand(void)
p = strtok(null, ","); //inMenu
uint32_t inMenu = atoi(p);
FREQ_AddFrequency(frequency, enabled, inMenu, type);
fgen_addFrequency(frequency, enabled, inMenu, type);
USB_SendString(ACK);
}
else if (USB_CommandCompare("fClear"))
{
//Clear the frequency list
frq_update_flag = true;
//frq_update_flag = true;
FREQ_ClearFrequencies();
fgen_clearFrequencies();
USB_SendString(ACK);
}
else if (USB_CommandCompare("fSave"))
@@ -366,7 +367,7 @@ void USB_ProcessFrequencyCommand(void)
}
else if (USB_CommandCompare("fGetNum")) //Get number of frequencies in the receiver
{
sprintf(usbTempString, "%d", FREQ_GetNumFrequencies());
sprintf(usbTempString, "%d", fgen_getNumFrequencies());
USB_SendString(usbTempString);
}
else if (USB_CommandPrefixCompare("fGet,")) //Get string representing a single frequency
@@ -376,8 +377,8 @@ void USB_ProcessFrequencyCommand(void)
p = strtok(null, ","); //index
uint32_t index = atoi(p);
FREQUENCY_t frq = FREQ_GetFreqByIndex(index);
sprintf(usbTempString, "%d,%d,%d,%d", frq.frequency1, 0, frq.enabled, 1); //FREQ_TYPE-t always 0, inMenu always 1
//FREQUENCY_t frq = FREQ_GetFreqByIndex(index);
//sprintf(usbTempString, "%d,%d,%d,%d", frq.frequency1, 0, frq.enabled, 1); //FREQ_TYPE-t always 0, inMenu always 1
USB_SendString(usbTempString);

View File

@@ -20,11 +20,12 @@
//Application includes
#include "timer.h"
#include "adc.h"
#include "frq.h"
//#include "frq.h"
#include "ports.h"
#include "utils.h"
#include "hwFixes.h"
#include "System/system.h"
#include "driver.h"
/*******************************************************************************
* Definitions
@@ -348,7 +349,8 @@ static float32_t ScaleLowGainCurrent(float32_t input)
uint32_t numEntries = sizeof(currentTableLowGain) / sizeof(float32_t) / 2;
//Get target frequency
float32_t targetFreq = FREQ_GetFreqByIndex(frequency).frequency1;
//float32_t targetFreq = FREQ_GetFreqByIndex(frequency).frequency1;
float32_t targetFreq = sys.driver->frequency->frequency;
#if 0 //TESTING - Use a specific frequency
targetFreq = 384;
@@ -404,7 +406,8 @@ static float32_t ScaleHighGainCurrent(float32_t input)
uint32_t numEntries = sizeof(currentTableHighGain) / sizeof(float32_t) / 2;
//Get target frequency
float32_t targetFreq = FREQ_GetFreqByIndex(frequency).frequency1;
//float32_t targetFreq = FREQ_GetFreqByIndex(frequency).frequency1;
float32_t targetFreq = sys.driver->frequency->frequency;
#if 0 //TESTING - Use a specific frequency
targetFreq = 384;
@@ -460,7 +463,8 @@ static float32_t ScaleLowGainVoltage(float32_t input)
uint32_t numEntries = sizeof(voltageTableLowGain) / sizeof(float32_t) / 2;
//Get target frequency
float32_t targetFreq = FREQ_GetFreqByIndex(frequency).frequency1;
//float32_t targetFreq = FREQ_GetFreqByIndex(frequency).frequency1;
float32_t targetFreq = sys.driver->frequency->frequency;
#if 0 //TESTING - Use a specific frequency
targetFreq = 384;
@@ -517,7 +521,8 @@ static float32_t ScaleLowGainCurrent208023(float32_t input)
uint32_t numEntries = sizeof(currentTableLowGain208023) / sizeof(float32_t) / 2;
//Get target frequency
float32_t targetFreq = FREQ_GetFreqByIndex(frequency).frequency1;
//float32_t targetFreq = FREQ_GetFreqByIndex(frequency).frequency1;
float32_t targetFreq = sys.driver->frequency->frequency;
#if 0 //TESTING - Use a specific frequency
targetFreq = 384;
@@ -573,7 +578,8 @@ static float32_t ScaleHighGainCurrent208023(float32_t input)
uint32_t numEntries = sizeof(currentTableHighGain208023) / sizeof(float32_t) / 2;
//Get target frequency
float32_t targetFreq = FREQ_GetFreqByIndex(frequency).frequency1;
//float32_t targetFreq = FREQ_GetFreqByIndex(frequency).frequency1;
float32_t targetFreq = sys.driver->frequency->frequency;
#if 0 //TESTING - Use a specific frequency
targetFreq = 384;
@@ -629,7 +635,8 @@ static float32_t ScaleLowGainVoltage208023(float32_t input)
uint32_t numEntries = sizeof(voltageTableLowGain208023) / sizeof(float32_t) / 2;
//Get target frequency
float32_t targetFreq = FREQ_GetFreqByIndex(frequency).frequency1;
//float32_t targetFreq = FREQ_GetFreqByIndex(frequency).frequency1;
float32_t targetFreq = sys.driver->frequency->frequency;
#if 0 //TESTING - Use a specific frequency
targetFreq = 384;
@@ -687,7 +694,8 @@ static float32_t ScaleLowGainCurrent208025(float32_t input)
uint32_t numEntries = sizeof(currentTableLowGain208025) / sizeof(float32_t) / 3;
//Get target frequency
float32_t targetFreq = FREQ_GetFreqByIndex(frequency).frequency1;
//float32_t targetFreq = FREQ_GetFreqByIndex(frequency).frequency1;
float32_t targetFreq = sys.driver->frequency->frequency;
#if 0 //TESTING - Use a specific frequency
targetFreq = 384;
@@ -754,7 +762,8 @@ static float32_t ScaleHighGainCurrent208025(float32_t input)
uint32_t numEntries = sizeof(currentTableHighGain208025) / sizeof(float32_t) / 3;
//Get target frequency
float32_t targetFreq = FREQ_GetFreqByIndex(frequency).frequency1;
//float32_t targetFreq = FREQ_GetFreqByIndex(frequency).frequency1;
float32_t targetFreq = sys.driver->frequency->frequency;
#if 1 //TESTING - Use a specific frequency
targetFreq = 5666;

View File

@@ -12,7 +12,7 @@
#include "psu_ctrl.h"
#include "timer.h"
#include "ports.h"
#include "frq.h"
//#include "frq.h"
#include "taps.h"
extern uint8_t frequency, Power_Level,old_freq, psu_failed;

View File

@@ -98,7 +98,7 @@ float32_t Bat_Mid_Point;
while(1)
{
safe_key();
//safe_key();
Display_Update();
Delay_Ticks(10);
}

140
source/broadcast.c Normal file
View File

@@ -0,0 +1,140 @@
#include "driver.h"
#include "ports.h"
#include "fgen.h"
#include "utils.h"
#include "System/system.h"
#define MIN_BROADCAST_FREQ 3140
#define MAX_BROADCAST_FREQ 210000
static uint8_t Bcast_LF_Value[5] = {0,5,10,15,20};
static uint8_t Bcast_HF_Value[5] = {0,12,25,37,50};
extern SYSTEM_DATA_t sys;
static FREQUENCY_t * setFrequency(ACCESSORY_t *accy, FREQUENCY_t *freq)
{
// use the current frequency if it is valid, otherwise, set to the lowest valid for broadcast
bool findFreq = false;
if (freq != NULL)
{
if (freq->frequency < MIN_BROADCAST_FREQ || freq->frequency > MAX_BROADCAST_FREQ)
{
findFreq = true;
}
}
else
{
findFreq = true;
}
if (findFreq)
{
freq = fgen_findNearest(MIN_BROADCAST_FREQ);
if (freq == NULL)
{
accy->state = PORT_STATE_ERROR;
return NULL;
}
}
accy->setPower(accy, sys.driver->powerLevel);
return freq;
}
static int setPower(ACCESSORY_t *accy, PowerLevel_t power)
{
FREQUENCY_t *f = driver_getFrequency();
uint8_t duty = 0;
if(f->frequency <= 8010)
duty = Bcast_LF_Value[power];
else
duty = Bcast_HF_Value[power];
driver_setDuty(duty);
return 0;
}
static void _stateInit(ACCESSORY_t *accy)
{
FREQUENCY_t *freq = driver_getFrequency();
if (accy->initState)
{
accy->setFrequency = setFrequency;
accy->setPower = setPower;
driver_setFrequency(freq);
driver_broadcastOn(true);
ACCY_setTimeout(accy, 500);
}
if (ACCY_timedOut(accy))
{
accy->state = PORT_STATE_RUNNING;
}
}
int broadcast_service(ACCESSORY_t *accy)
{
switch (accy->state)
{
case PORT_STATE_INIT:
{
_stateInit(accy);
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;
}

8
source/broadcast.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef _BROADCAST_H
#define _BROADCAST_H
#include "ports.h"
int broadcast_service(ACCESSORY_t *accy);
#endif

91
source/dds.c Normal file
View File

@@ -0,0 +1,91 @@
#include "dds.h"
#include "io.h"
static void sendCommand(dds_t *dds, uint16_t reg, uint8_t *data, uint16_t len)
{
uint8_t tmp[2];
tmp[0] = (uint8_t)(reg >> 8); // Reset bit held
tmp[1] = (uint8_t)(reg & 0x00ff);
SPI0_SendBytes(tmp, 2, dds->mode);
if (data != NULL)
{
SPI0_SendBytes(data, len, dds->mode);
}
}
static uint32_t calculateDDSValue(uint32_t frequency) // Calculate frequency word for DDS
{
// FREG = (Frequency * 2^28)/fclk = 12MHz normally
return (uint32_t)((frequency * 268435456.0) / DDS_CLK + 0.5);
}
void dds_setFrequency(dds_t *dds, uint32_t frequency)
{
uint16_t freq_hi = FREQ0_REG;
uint16_t freq_lo = FREQ0_REG;
dds->frequency = frequency;
uint8_t data[4];
// set signal DDS
if (frequency > 0)
{
uint32_t freqValue = calculateDDSValue(dds->frequency);
freq_hi = FREQ0_REG;
freq_lo = FREQ0_REG;
freq_lo |= (freqValue & 0x3fff);
freqValue >>= 14;
freq_hi |= (freqValue & 0x3fff);
data[0] = (uint8_t)(freq_lo >> 8); //LS 16-bit word, MSB
data[1] = (uint8_t)(freq_lo & 0x00ff); //LS 16-bit word, LSB
data[2] = (uint8_t)(freq_hi >> 8);
data[3] = (uint8_t)(freq_hi & 0x00ff);
// send Control word to hold setup
sendCommand(dds, FRQ_CTRL_WORD1, data, sizeof(data));
// send Control word to release setup
sendCommand(dds, FRQ_CTRL_WORD2, NULL, 0);
}
else
{
dds_sleep(dds, true, false);
}
}
void dds_init(dds_t *dds, SPI_MODE_t mode, gpio_pin_t resetPin)
{
dds->mode = mode;
dds->resetPin = resetPin;
dds_reset(dds, true);
}
void dds_reset(dds_t *dds, bool reset)
{
GPIO_PinWrite(GPIO, dds->resetPin.port, dds->resetPin.pin, (reset ? 1 : 0) );
}
void dds_sleep(dds_t *dds, bool sleep, bool disableDAC)
{
if (sleep)
{
if (disableDAC)
{
sendCommand(dds, SLP_CTRL_WRD2, NULL, 0);
}
else
{
sendCommand(dds, SLP_CTRL_WRD, NULL, 0);
}
}
}

62
source/dds.h Normal file
View File

@@ -0,0 +1,62 @@
#ifndef _DDS_H
#define _DDS_H
#include "spi.h"
#include "io.h"
#define TX_SYS_CLK 12000000 // 12MHZ
#define DDS_CLK TX_SYS_CLK
#define RAMP_300KHZ 6710886
#define FREQ_MAX_NUM 50 //Max number of frequencies allowed
#define FREQ_MIN 0
#define FREQ0_REG 0x4000 // Address of internal 9838 register
#define FRQ_CTRL_WORD1 0x2100 // Control register with Reset bit active
#define FRQ_CTRL_WORD2 0x2000 // Exit Reset Control Word
#define PHASE_RESET 0xC000 // PHASE Register 0 = 0;
#define RAMP_CTRL_WORD1 0x2102
#define RAMP_CTRL_WORD2 0x2002
#define RAMP_CTRL_WORD3 0x2002 // TODO Places wavegen in sleep mode
#define SLP_CTRL_WRD 0x2180 // Power down unused DDS
#define SLP_CTRL_WRD2 0x21C0
#define BCAST_MIN 3140
#define BCAST_MAX 200000
#define DUMMY_FRQ 250
#define MIN_BLOCK_FREQ 20000
#define MASK_15 0b00000000
#define MASK_58 0b00001000
#define MASK_144 0b00011000
#define CLK_MASK_BITS 0b11100111
#define MAX_LD_FREQ 10000
//FREQUENCY PACKING - from RX so it has extra fields
#define FREQ_PACK_MASK_FREQ 0x0007ffff //target frequency bits 0 - 18
#define FREQ_PACK_MASK_TYPE 0x00380000 //3-bit field for FREQ_TYPE_t. bits 19 - 21
#define FREQ_PACK_SHIFT_TYPE 19 //Frequency type shift
#define FREQ_PACK_MASK_ENABLED 0x80000000 //enabled mask
#define FREQ_PACK_SHIFT_ENABLED 31 //enabled shift bit 31
#define FREQ_PACK_MASK_INMENU 0x40000000 //inMenu mask
#define FREQ_PACK_SHIFT_INMENU 30 //inMenu shift bit 30
//Locate direction (LD)
#define FREQ_LD_MAX_FREQUENCY 10000 //LD runs at or below this frequency
#define FREQ_LD_SWITCH_POINT 1500 //At or below this freq, f2 is f1 * 2. above this f2 = f1 / 2
typedef struct
{
SPI_MODE_t mode;
uint32_t frequency;
// reset pin
gpio_pin_t resetPin;
} dds_t;
void dds_init(dds_t *dds, SPI_MODE_t mode, gpio_pin_t resetPin);
void dds_reset(dds_t *dds, bool reset);
void dds_sleep(dds_t *dds, bool sleep, bool disableDAC);
#endif

View File

@@ -17,7 +17,7 @@
#include "spi.h"
#include "lcd.h"
#include "display.h"
#include "frq.h"
//#include "frq.h"
#include "battery.h"
#include "utils.h"
#include "Graphics/splash.h"
@@ -544,6 +544,7 @@ void Display_High_Voltage(void)
void Display_Frequency(uint8_t frequency)
{
#if 0
// if (freqArray[frequency].frequency2 > 0)
// Display_CD_Symbol(); // place a CD symbol in front in correct position
@@ -568,27 +569,23 @@ void Display_Frequency(uint8_t frequency)
// }
FL_DrawString( tempString, LCD_X_MAX+6, LCD_Y_MAX - 22, font18Bold, LCD_DRAW_SET, FL_ALIGN_RIGHT);
#endif
}
void Display_CD_Symbol(void)
{
// uint16_t ldy = LCD_Y_MAX - GL_GetMonoBitmapHeight(ld2)+3;
#if 0
if (freqArray[frequency].frequency1 < 1000)
GL_DrawMonoBitmap(ld, LCD_X_MAX - 90, LCD_Y_MAX - 16, LCD_DRAW_SET);
else
GL_DrawMonoBitmap(ld, LCD_X_MAX - 106, LCD_Y_MAX - 16, LCD_DRAW_SET);
#endif
}
void Test_Frequency(void)
{
if(freqArray[frequency].enabled)
Display_Frequency(frequency);
frequency = Next_Frequency(frequency);
}
void Display_Bye_Bye()
{
@@ -656,7 +653,7 @@ void Display_Normal(void)
else
Display_Level(Power_Level); // Display bars
Display_Frequency(frequency);
//Display_Frequency(frequency);
if(Test_Mode)
FL_DrawString("BETA", LCD_X_MIN, LCD_Y_MIN-3, font16Bold, LCD_DRAW_XOR, FL_ALIGN_LEFT);
@@ -730,56 +727,6 @@ uint8_t Display_Taps(void)
}
void Display_Currently_Selected(void)
{
switch (Cur_Mode)
{
case BROADCAST:
break;
case PORT1_A:
if(ACCY_GetConnectedAccessory(1) == ID_CLAMP || ACCY_GetConnectedAccessory(1) == ID_CLAMP2)
//Display_Clamp_Volts();
Display_Clamp_Power();
else
Display_Line_Measurements();
break;
case PORT1_B:
if(ACCY_GetConnectedAccessory(1) == ID_CLAMP || ACCY_GetConnectedAccessory(1) == ID_CLAMP2)
//Display_Clamp_Volts();
Display_Clamp_Power();
else
Display_Line_Measurements();
break;
case PORT2_A:
if(ACCY_GetConnectedAccessory(2) == ID_CLAMP || ACCY_GetConnectedAccessory(2) == ID_CLAMP2)
//Display_Clamp_Volts();
Display_Clamp_Power();
else
Display_Line_Measurements();
break;
case PORT2_B:
if(ACCY_GetConnectedAccessory(2) == ID_CLAMP || ACCY_GetConnectedAccessory(2) == ID_CLAMP2)
//Display_Clamp_Volts();
Display_Clamp_Power();
else
Display_Line_Measurements();
break;
}
}
void Display_Line_Measurements(void)
{
Display_Line_Voltage();
@@ -790,39 +737,6 @@ void Display_Line_Measurements(void)
}
void Display_Tx_Status(void)
{
switch(Task)
{
case SAFETY_TASK:
Display_Danger_Menu();
break;
case FATAL_ERROR_TASK:
Display_Fatal_Error();
break;
case ESTOP_TASK:
Display_Estop();
break;
case LOW_BATTERY_TASK:
Display_Flash_Bat();
break;
case BAT_INSERTION_ERROR:
LCD_Clear(); //clear the frameBuffer
Display_Bat_Error();
break;
default:
Display_Normal();
}
}
void Display_USB_Status(void)
{

View File

@@ -93,7 +93,6 @@ void Display_Fatal_Error(void);
void Display_OnScreen_Diagnostics(void);
void Display_Over_Voltage_Status(void);
void Display_USB_Status(void);
void Display_Tx_Status(void);
void Draw_Battery(uint8_t stacks);
uint8_t Read_Model_type();
void Display_EXT_DC(void);

207
source/driver.c Normal file
View File

@@ -0,0 +1,207 @@
#include "driver.h"
#include "io.h"
#include "System/system.h"
#include "spi.h"
#include "pwm.h"
#include "utils.h"
static SYSTEM_DATA_t *_sys = NULL;
static TxDriver_t _driver;
TxDriver_t * driver_getDriver(void)
{
return &_driver;
}
void driver_setPSUVoltage(uint8_t value)
{
uint8_t data[2];
data[0] = 0x0;
data[1] = value;
SPI0_SendBytes(data, 2, PSU_VCTRL); // Update the Pot
}
void driver_setAmplitude(uint8_t value)
{
uint8_t data[2];
data[0] = 0x0;
data[1] = value;
SPI0_SendBytes(data, 2, AMPLITUDE); // Update the Pot
}
void driver_isolateOutput(bool isolate)
{
if (_sys != NULL)
{
_sys->status[ESTOP] = isolate;
}
if (isolate)
{
GPIO_WRITE(PIN_ESTOP, LOW); // Isolated
}
else
{
GPIO_WRITE(PIN_ESTOP, HIGH); // Not Isolated
}
}
void driver_enablePower(bool enable)
{
if (enable)
{
GPIO_WRITE(PIN_POWER_CTL, HIGH); // Switch or keep power on
}
else
{
GPIO_WRITE(PIN_POWER_CTL, LOW); // Switch power off
}
}
void driver_init(void)
{
_sys = system_getSys();
// isolate output
driver_isolateOutput(true);
_driver.state = DRIVER_STATE_INIT;
_driver.initState = true;
// initialize amplitude pot
driver_setAmplitude(0);
// initialize PSU
_driver.psuValueMax = MAX_AB_PSU;
driver_setPSUVoltage(_driver.psuValueMax);
driver_enablePower(true);
}
void driver_broadcastOn(bool on)
{
// turn off all amplifiers
io_broadcastOn(false, NO_UPDATE);
io_connectAmpAB(false, NO_UPDATE);
io_ampDOn(false, NO_UPDATE);
// update values at the same time
io_update();
delayms(10);
driver_setPSUVoltage(V_27V);
// turn on broadcast amp
io_broadcastOn(true, UPDATE);
delayms(5);
// turn on the amplifier power supply
io_ampPsuOn(true, UPDATE);
}
void driver_setDuty(uint32_t duty)
{
uint32_t frequency;
if (duty == 0)
{
frequency = DEFAULT_PWM_FREQ;
}
else
{
frequency = _driver.frequency->frequency;
}
PWM_Setup(frequency, duty);
}
void driver_setFrequency(FREQUENCY_t *freq)
{
if (_sys->activeAccessory != NULL)
{
freq = _sys->activeAccessory->setFrequency(_sys->activeAccessory, freq);
if (freq != NULL)
{
// TODO: accessory may select a different frequency
_driver.frequency = freq;
driver_setPower(_driver.powerLevel);
}
}
}
void driver_setPower(PowerLevel_t powerLevel)
{
if (_sys->activeAccessory != NULL)
{
if (powerLevel > POWER_LEVEL_4)
{
powerLevel = POWER_LEVEL_4;
}
if (0 == _sys->activeAccessory->setPower(_sys->activeAccessory, powerLevel))
{
_driver.powerLevel = powerLevel;
}
}
}
void driver_setSafe(bool safe)
{
_sys->safeMode = safe;
//Select_Estop((safe ? ISOLATED : CONNECTED));
driver_isolateOutput(true);
if (safe)
{
//clear shift registers to known state
io_expanderSetSafe();
delayms(10);
dds_t *dds = fgen_getDDS(DDS_SIGNAL);
dds_sleep(dds, true, true);
}
}
FREQUENCY_t *driver_getFrequency(void)
{
return _driver.frequency;
}
// safety monitor run from interrupt
void driver_monitor(void)
{
}
void driver_service(void)
{
switch (_driver.state)
{
case DRIVER_STATE_INIT:
{
break;
}
case DRIVER_STATE_WAIT_PSU:
{
break;
}
case DRIVER_STATE_SWITCH_FREQUENCY:
{
break;
}
}
}

70
source/driver.h Normal file
View File

@@ -0,0 +1,70 @@
#ifndef _DRIVER_H
#define _DRIVER_H
#include <stdint.h>
#include <stdbool.h>
#include "fgen.h"
#define MAIN_PSU_ENBL 0b00000100 // Active Low U13 D2
#define V_18V 0
#define V_21V 88
#define V_24V 118
#define V_27V 148
#define V_30V 171
#define V_36V 218
#define V_42V 250
#define V_55V 255
#define MAX_AB_PSU V_24V //TODO
#define MAX_D_PSU V_36V
#define MAX_CLAMP_PSU 255
typedef enum
{
POWER_LEVEL_0 = 0,
POWER_LEVEL_1,
POWER_LEVEL_2,
POWER_LEVEL_3,
POWER_LEVEL_4,
} PowerLevel_t;
typedef enum
{
DRIVER_STATE_INIT = 0,
DRIVER_STATE_WAIT_PSU,
DRIVER_STATE_SWITCH_FREQUENCY,
} DriverState_t;
typedef struct
{
DriverState_t state;
bool initState;
uint32_t stateTimer;
uint8_t psuValue;
uint8_t psuValueMax;
FREQUENCY_t *frequency;
PowerLevel_t powerLevel;
} TxDriver_t;
TxDriver_t * driver_getDriver(void);
void driver_setPSUVoltage(uint8_t value);
void driver_setAmplitude(uint8_t value);
void driver_isolateOutput(bool isolate);
void driver_enablePower(bool enable);
void driver_init(void);
void driver_monitor(void);
void driver_service(void);
void driver_setDuty(uint32_t duty);
void driver_broadcastOn(bool on);
void driver_setFrequency(FREQUENCY_t *freq);
void driver_setPower(PowerLevel_t powerLevel);
FREQUENCY_t *driver_getFrequency(void);
void driver_setSafe(bool safe);
#endif

View File

@@ -17,8 +17,9 @@
#include "timer.h"
#include "System/system.h"
#include "bootloader.h"
#include "frq.h"
//#include "frq.h"
#include "eeprom.h"
#include "fgen.h"
#include "Fonts/translate.h"
/*******************************************************************************
@@ -56,6 +57,37 @@ static bool EE_Busy(void)
* Public Functions
******************************************************************************/
/*
* Pack frequency data and return
* Packed data is used for saving to FLASH
*/
uint32_t EE_GetPackedFrequency(uint32_t index)
{
FREQUENCY_t *freq = fgen_getByIndex(index);
uint32_t packed = freq->frequency;
//packed |= freqArray[index].type << FREQ_PACK_SHIFT_TYPE;
packed |= (uint32_t)freq->enabled << FREQ_PACK_SHIFT_ENABLED;
//packed |= (uint32_t)freqArray[index].inMenu << FREQ_PACK_SHIFT_INMENU;
return packed;
}
/*
* Add a frequency to the list from packed data
* Packed data is used for saving to FLASH
*/
void EE_AddPackedFrequency(uint32_t packedFreq)
{
uint32_t frequency = packedFreq & FREQ_PACK_MASK_FREQ;
//FREQ_TYPE_t type = (packedFreq & FREQ_PACK_MASK_TYPE) >> FREQ_PACK_SHIFT_TYPE;
bool enabled = packedFreq & FREQ_PACK_MASK_ENABLED;
//bool inMenu = packedFreq & FREQ_PACK_MASK_INMENU;
fgen_addFrequency(frequency, enabled, 1, FT_ACTIVE); //inMenu always 1, all FT_ACTIVE
}
/*
* Load data from EEPROM
*/
@@ -109,7 +141,7 @@ bool EE_LoadFrequencies(void)
for(uint32_t i = 0; i < tempNumFreqs; i++)
{
uint32_t packedFreq = EE_ReadUINT32(EE_FREQ_START + EE_BYTES_PER_WORD * i);
FREQ_AddPackedFrequency(packedFreq);
EE_AddPackedFrequency(packedFreq);
}
}
@@ -134,11 +166,12 @@ void EE_SaveData(void)
EE_WriteBytes(EE_DATA_TIMER, &tmr.autoShutdown, 1); // Save Power down timer status
//Save Frequencies
uint32_t numFreqs = FREQ_GetNumFrequencies();
uint32_t numFreqs = fgen_getNumFrequencies();
EE_WriteUINT32(EE_FREQ_NUM, numFreqs);
for(uint32_t i = 0; i < numFreqs; i++)
{
EE_WriteUINT32(EE_FREQ_START + EE_BYTES_PER_WORD * i, FREQ_GetPackedFrequency(i));
EE_WriteUINT32(EE_FREQ_START + EE_BYTES_PER_WORD * i, EE_GetPackedFrequency(i));
}
}

407
source/fgen.c Normal file
View File

@@ -0,0 +1,407 @@
#include <stdio.h>
#include "fgen.h"
#include "dds.h"
#include "io.h"
#include "spi.h"
#include "eeprom.h"
#include "arm_math.h"
#include "soft_timer.h"
static fgen_t _fgen;
enum
{
FREQ_512 = 512,
FREQ_3K14 = 3140,
FREQ_8K = 8192,
};
static float V_coeff_lo_Chk(uint32_t f1)
{
float a;
switch(f1)
{
case 1 ... 940:
a= 0.876923;
break;
case 941 ... 1170:
a = 0.911538;
break;
case 1171 ... 6000:
a = 0.97083;
break;
case 6001 ... 8009:
a = 1.025;
break;
case 8010 ... 9820:
a = 1.025;
break;
case 9821 ... 29430:
a = 0.81;
break;
case 29431 ... 32768:
a = 0.81;//1.009;
break;
case 32769 ... 44100:
a = 1.035;
break;
case 44101 ... 65536:
a = 1.0;
break;
case 65537 ... 80000:
a = 1.1;
break;
case 80001 ... 199999:
a = 1.36;
break;
case 200000 ... 480000:
a = 4.5;
break;
default:
a = 0.53;
}
return(a);
}
static float V_coeff_hi_Chk(uint32_t f1)
{
return(0);
}
static float I_coeff_lo_Chk(uint32_t f1)
{
float a;
// a = freqArray[Search_for_frq(f1)].i_coeff_lo;
switch(f1)
{
case 1 ... 500:
a = 1;
break;
case 501 ... 870:
a= 0.8396;
break;
case 871 ... 1170:
a = 0.8105;
break;
case 1171 ... 3139:
a = 0.8634;
break;
case 3140 ... 6000:
a = 0.8634;
break;
case 6001 ... 8009:
a = 0.8634;
break;
case 8010 ... 9820:
a = 0.8976;
break;
case 9821 ... 29430:
a = 0.8976;
break;
case 29431 ... 32768:
a = 0.8976;
break;
case 32769 ... 44100:
a = 0.91;
break;
case 44101 ... 65536:
a = 1.015;
break;
case 65537 ... 199999:
a = 1.255;
break;
case 200000 ... 480000:
a = 3.111;
break;
default:
a = 0.8976;
}
return(a);
}
static float I_coeff_hi_Chk(uint32_t f1)
{
float a;
switch(f1)
{
case 1 ... 940:
a= 0.47;
break;
case 941 ... 1170:
a = 0.49;
break;
case 1171 ... 6000:
a = 0.482;
break;
case 6001 ... 8009:
a = 0.53;
break;
case 8010 ... 9820:
a = 0.53;
break;
case 9821 ... 29430:
a = 0.69;
break;
case 29431 ... 32768:
a = 0.71333;
break;
case 32769 ... 44100:
a = 1.035;
break;
case 44101 ... 65536:
a = 1.35;
break;
case 65537 ... 200000:
a = 1.36;
break;
case 200001 ... 480000:
a = 2.111;
break;
default:
a = 0.53;
}
return(a);
}
dds_t* fgen_getDDS(dds_type_t dds)
{
return &_fgen.dds[dds];
}
void fgen_enableDDS(dds_type_t dds, bool enable)
{
}
void fgen_clearFrequencies(void)
{
for(uint32_t i = 0; i < _fgen.numFrequencies; i++)
{
_fgen.frequencies[i].frequency = 0;
_fgen.frequencies[i].enabled = 0;
}
_fgen.numFrequencies = 0;
}
void fgen_addFrequency(uint32_t frequency, uint8_t enabled, uint8_t inMenu, FREQ_TYPE_t type)
{
if(!inMenu)
{
return; //ignore freqs that are not in menu
}
if((type != FT_ACTIVE) && (type != FT_LD_ACTIVE))
{
return; //ignore RX frequency types
}
FREQUENCY_t *freq = &_fgen.frequencies[_fgen.numFrequencies];
freq->ldFrequency = 0;
if(type == FT_LD_ACTIVE)
{
if(frequency <= FREQ_LD_SWITCH_POINT)
{
freq->ldFrequency = frequency * 2;
}
else if(frequency <= FREQ_LD_MAX_FREQUENCY)
{
freq->ldFrequency = frequency / 2; //TODO: This will break for odd frequencies since it's an integer. Need to rework freqs...
}
}
float32_t v_coeff_lo = V_coeff_lo_Chk(frequency);
float32_t i_coeff_hi = I_coeff_hi_Chk(frequency);
float32_t i_coeff_lo = I_coeff_lo_Chk(frequency);
float32_t v_coeff_hi = V_coeff_hi_Chk(frequency); //always 0
freq->frequency = frequency;
freq->enabled = enabled;
freq->v_coeff_hi = v_coeff_hi;
freq->v_coeff_lo = v_coeff_lo;
freq->i_coeff_hi = i_coeff_hi;
freq->i_coeff_lo = i_coeff_lo;
_fgen.numFrequencies++;
}
FREQUENCY_t *fgen_getByIndex(int index)
{
if (index >= _fgen.numFrequencies)
{
return NULL;
}
return &_fgen.frequencies[index];
}
// find the nearest enabled frequency higher than freq
FREQUENCY_t* fgen_findNearest(uint32_t freq)
{
for (int i=0; i < _fgen.numFrequencies; ++i)
{
FREQUENCY_t *f = &_fgen.frequencies[i];
if (f->frequency >= freq)
{
return f;
}
}
return NULL;
}
uint32_t fgen_getNumFrequencies(void)
{
return _fgen.numFrequencies;
}
/* Generate name for the frequency at the specified index
* @param index index in the frequency list
* @param *string pointer to the storage location for the name string
*/
void fgen_getFrequencyName(FREQUENCY_t *freq, uint8_t *string)
{
//Generate frequency name
// < 1000Hz: "xxxHz"
// < 10kHz: "x.xxkHz"
// < 100kHz: "xx.xkHz"
// >=100kHz: "xxxkHz"
uint32_t freqTemp = freq->frequency; //the numeric freqTemp
if(freq->ldFrequency != 0)
{
if(freqTemp < 1000)
{
sprintf(string, "LD %dHz", freqTemp);
}
else if(freqTemp < 10000)
{
sprintf(string, "LD %.2fkHz", (float32_t)freqTemp / 1000.0);
}
else
{
sprintf(string, "ERROR");
}
}
else
{
if(freqTemp < 1000)
{
sprintf(string, "%dHz", freqTemp);
}
else if(freqTemp < 10000)
{
sprintf(string, "%.2fkHz", (float32_t)freqTemp / 1000.0);
}
else if(freqTemp < 100000)
{
sprintf(string, "%.1fkHz", (float32_t)freqTemp / 1000.0);
}
else if(freqTemp < 500000)
{
sprintf(string, "%.0fkHz", (float32_t)freqTemp / 1000.0);
}
else
{
sprintf(string, "ERROR");
}
}
}
static void loadDefaults(void)
{
//These are the FACTORY TEST Frequencies
fgen_clearFrequencies();
fgen_addFrequency(512, 1, 1, FT_ACTIVE);
fgen_addFrequency(3140, 1, 1, FT_ACTIVE);
fgen_addFrequency(8192, 1, 1, FT_ACTIVE);
fgen_addFrequency(29433, 1, 1, FT_ACTIVE);
fgen_addFrequency(32770, 1, 1, FT_ACTIVE);
fgen_addFrequency(65055, 1, 1, FT_ACTIVE);
fgen_addFrequency(88779, 1, 1, FT_ACTIVE);
}
static bool loadFrequencies(void)
{
bool success = true;
//Load frequencies
uint32_t tempNumFreqs = EE_ReadUINT32(EE_FREQ_NUM);
if((tempNumFreqs > FREQ_MAX_NUM) || (tempNumFreqs == 0)) //Error check numFreqs
{
loadDefaults();
}
else
{
for(uint32_t i = 0; i < tempNumFreqs; i++)
{
uint32_t packedFreq = EE_ReadUINT32(EE_FREQ_START + EE_BYTES_PER_WORD * i);
uint32_t frequency = packedFreq & FREQ_PACK_MASK_FREQ;
bool enabled = packedFreq & FREQ_PACK_MASK_ENABLED;
fgen_addFrequency(frequency, enabled, 1, FT_ACTIVE); //inMenu always 1, all FT_ACTIVE
}
}
return success;
}
void fgen_init(void)
{
uint32_t tmp;
gpio_pin_t resetPin;
// init sets reset
resetPin.port = PORT(PIN_SIG_RESET);
resetPin.pin = PIN (PIN_SIG_RESET);
dds_init(&_fgen.dds[DDS_SIGNAL], SIGNAL, resetPin);
resetPin.port = PORT(PIN_SD_RESET);
resetPin.pin = PIN (PIN_SD_RESET);
dds_init(&_fgen.dds[DDS_DIRECTION], SDSIGNAL, resetPin);
resetPin.port = PORT(PIN_RAMP_RST);
resetPin.pin = PIN (PIN_RAMP_RST);
dds_init(&_fgen.dds[DDS_RAMP], RAMP, resetPin);
stimer_delay(10);
// clear reset after delay
for (int i=0; i<NUM_DDS; ++i)
{
dds_reset(&_fgen.dds[i], false);
}
_fgen.numFrequencies = 0;
loadFrequencies();
dds_sleep(&_fgen.dds[DDS_DIRECTION], true, false);
}

65
source/fgen.h Normal file
View File

@@ -0,0 +1,65 @@
#ifndef _FGEN_H
#define _FGEN_H
#include "dds.h"
typedef enum
{
DDS_SIGNAL = 0,
DDS_DIRECTION,
DDS_RAMP,
NUM_DDS
} dds_type_t;
//Locate direction (LD)
#define FREQ_LD_MAX_FREQUENCY 10000 //LD runs at or below this frequency
#define FREQ_LD_SWITCH_POINT 1500 //At or below this freq, f2 is f1 * 2. above this f2 = f1 / 2
typedef enum
{
FT_ACTIVE, //active
FT_LD_ACTIVE, //active w/ Locate Direction
FT_POWER, //RX ONLY individual power
FT_GROUPED_POWER, //RX ONLY Radio style grouped power
FT_CATHODIC, //RX ONLY cathodic protection - Identical to individual power except naming in frequency menu
FT_SONDE, //RX ONLY
FT_RADIO, //RX ONLY
FT_FAULT_FIND, //RX ONLY fault finder - Has it's own dedicated frequency set. frequencies are NOT user definable
} FREQ_TYPE_t;
//Data for individual frequencies
typedef struct
{
FREQ_TYPE_t type;
uint32_t frequency; //frequency in Hz
uint32_t ldFrequency;
uint8_t enabled;
float i_coeff_lo;
float i_coeff_hi;
float v_coeff_lo;
float v_coeff_hi;
} FREQUENCY_t;
typedef struct
{
// list of frequencies...
FREQUENCY_t frequencies[FREQ_MAX_NUM];
uint32_t numFrequencies; //number of frequencies in array
dds_t dds[NUM_DDS];
} fgen_t;
void fgen_init(void);
FREQUENCY_t* fgen_findNearest(uint32_t freq);
FREQUENCY_t *fgen_getByIndex(int index);
void fgen_getFrequencyName(FREQUENCY_t *freq, uint8_t *string);
uint32_t fgen_getNumFrequencies(void);
void fgen_addFrequency(uint32_t frequency, uint8_t enabled, uint8_t inMenu, FREQ_TYPE_t type);
void fgen_clearFrequencies(void);
void fgen_enableDDS(dds_type_t dds, bool enable);
dds_t* fgen_getDDS(dds_type_t dds);
#endif

View File

@@ -1,917 +0,0 @@
/*
* frq.c
*
* Created on: Jun 8, 2022
* Author: Keith.Lloyd
*/
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "arm_math.h"
#include "spi.h"
#include "fsl_gpio.h"
#include "frq.h"
#include "LPC54114_cm4.h"
#include "display.h"
#include "utils.h"
#include "init.h"
#include "amps.h"
#include "ports.h"
#include "timer.h"
#include "mode.h"
#include "stdbool.h"
#include "eeprom.h"
#include "pwr_level.h"
#include "System/system.h"
extern uint8_t Test_Mode, catch_up_flag;
extern uint8_t Taps_Flag;
extern uint32_t new_freq;
extern uint8_t frequency,Cur_Mode,LD_Flag;
extern uint8_t Dds_Pot_Val[2];
uint8_t Tx_mode, frq_chg_tmr,old_freq;
FREQDATA_t freq;
FREQUENCY_t freqArray[FREQ_MAX_NUM];
uint8_t foo[4]; //stuff the 2 16-bit values into an array of 4 uint8_t
uint8_t frq_update_flag;
extern uint8_t Power_Level;
extern ClampData_t clampData;
extern uint32_t systemTime;
uint32_t Calc_Freq(uint32_t fout) // Calculate frequency word for DDS
{
float Freg;
uint32_t Frq_result;
Freg = fout * 268435456.0; // FREG = (Frequency * 2^28)/fclk = 12MHz normally
Frq_result = Freg/DDS_CLK + 0.5;
return(Frq_result);
}
void Load_Ramp(uint32_t ramp_freq) // Sets up RAMP DDS for PWM AMP
{
uint16_t ramp_hi = FREQ0_REG; //top 2 bits 0x01 for Freq0 register address
uint16_t ramp_lo = FREQ0_REG;
if (ramp_freq > 0)
{
Send_Ctrl_Word(RAMP_CTRL_WORD1,RAMP); // send Control word to hold setup
ramp_lo |= (ramp_freq & 0x3fff);
ramp_freq >>= 14;
ramp_hi |= (ramp_freq & 0x3fff);
//ramp_hi |= (ramp_freq & 0xc000) >> 14; // Preserve upper 2 bits
foo[0] = (uint8_t)(ramp_lo >> 8); //LS 16-bit word, MSB
foo[1] = (uint8_t)(ramp_lo & 0x00ff); //LS 16-bit word, LSB
foo[2] = (uint8_t)(ramp_hi >> 8);
foo[3] = (uint8_t)(ramp_hi & 0x00ff);
SPI0_SendBytes(foo, 4, RAMP);
Send_Ctrl_Word(RAMP_CTRL_WORD2,RAMP); // send Control word to release setup
}
else
{
Send_Ctrl_Word(RAMP_CTRL_WORD3,RAMP); // Control word to hold setup and put part to sleep
GPIO_PinWrite(GPIO, RAMP_PORT, RAMP_RST_GPIO_PIN, HI); //Hold RST HI
while(1); //stop
}
}
void Load_Frq_Gen(FRQ_OUT_SELECT_t Freq_Mode, int32_t f1, int32_t f2)
{
uint8_t x=0;
uint16_t freq_hi = FREQ0_REG;
uint16_t freq_lo = FREQ0_REG;
if (Freq_Mode == NULL_FREQ)
x = 1; // Switch both DDS chips OFF
if (Freq_Mode == SINGLE)
{
x = 2; // Switch the primary DDS ON
Send_Ctrl_Word(FRQ_CTRL_WORD1,SIGNAL); // send Control word to hold setup
freq_lo |= (f1 & 0x3fff);
f1 >>= 14;
freq_hi |= (f1 & 0x3fff);
foo[0] = (uint8_t)(freq_lo >> 8); //LS 16-bit word, MSB
foo[1] = (uint8_t)(freq_lo & 0x00ff); //LS 16-bit word, LSB
foo[2] = (uint8_t)(freq_hi >> 8);
foo[3] = (uint8_t)(freq_hi & 0x00ff);
// freq_hi |= (f1 & 0xc000) >> 14; // Preserve upper 2 bits
// freq_lo |= (f1 & 0x3fff);
// foo[0] = (uint8_t)(freq_lo >> 8);
// foo[1] = (uint8_t)(freq_lo & 0x00ff);
// foo[2] = (uint8_t)(freq_hi >> 8);
// foo[3] = (uint8_t)(freq_hi & 0x00ff);
SPI0_SendBytes(foo, 4, SIGNAL);
Send_Ctrl_Word(FRQ_CTRL_WORD2,SIGNAL); // send Control word to release setup
}
if (Freq_Mode == DUAL)
{ // ############---Switch both DDS chips ON SYNCHRONOUSLY--######
// Set RESET to hold
// Load F1
Send_Ctrl_Word(FRQ_CTRL_WORD1,SIGNAL); // send Control word to hold setup
freq_lo |= (f1 & 0x3fff);
f1 >>= 14;
freq_hi |= (f1 & 0x3fff);
foo[0] = (uint8_t)(freq_lo >> 8); //LS 16-bit word, MSB
foo[1] = (uint8_t)(freq_lo & 0x00ff); //LS 16-bit word, LSB
foo[2] = (uint8_t)(freq_hi >> 8);
foo[3] = (uint8_t)(freq_hi & 0x00ff);
SPI0_SendBytes(foo, 4, SIGNAL);
Send_Ctrl_Word(FRQ_CTRL_WORD2,SIGNAL); // send Control word to release setup
// Load F2
freq_hi = FREQ0_REG;
freq_lo = FREQ0_REG;
Send_Ctrl_Word(FRQ_CTRL_WORD1,SDSIGNAL); // send Control word to hold setup
freq_lo |= (f2 & 0x3fff);
f2 >>= 14;
freq_hi |= (f2 & 0x3fff);
foo[0] = (uint8_t)(freq_lo >> 8); //LS 16-bit word, MSB
foo[1] = (uint8_t)(freq_lo & 0x00ff); //LS 16-bit word, LSB
foo[2] = (uint8_t)(freq_hi >> 8);
foo[3] = (uint8_t)(freq_hi & 0x00ff);
SPI0_SendBytes(foo, 4, SDSIGNAL);
Send_Ctrl_Word(FRQ_CTRL_WORD2,SDSIGNAL); // send Control word to release setup
// Send_Ctrl_Word(SLP_CTRL_WRD,SIGNAL); // TEST ONLY REMOVE Put unused DDS to sleep
// Send_Ctrl_Word(PHASE_RESET,SIGNAL); // // Set Phase F1 to 0
// Send_Ctrl_Word(PHASE_RESET,SDSIGNAL); // Set Phase F2 to 0
// Send_Ctrl_Word(FRQ_CTRL_WORD2,BOTH_SIGNAL); // Send release code word simultaneously
// End#.
// GPIO_PinWrite(GPIO, 1, 13, 1);
// Set high SD_RST
// Set high SIG_RST
// Set up both Sine Wave generators
// set low SD_RST
// set low SIG_RST.
}
}
void Send_Ctrl_Word(uint16_t Control_Reg, SPI_MODE_t mode)
{
//Set the control register Send MS Byte first then LSByte
foo[0] = (uint8_t)(Control_Reg >> 8); // Reset bit held
foo[1] = (uint8_t)(Control_Reg & 0x00ff);
SPI0_SendBytes(foo, 2, mode);
}
void AddFrequency(uint32_t frequency1,uint32_t frequency2, uint8_t enabled, uint8_t bc_enabled,uint8_t bc_mask,uint8_t pot,float i_lo,float i_hi,float v_lo,float v_hi)
{
uint32_t i = freq.numFrequencies;
freqArray[i].frequency1 = frequency1;
freqArray[i].frequency2 = frequency2;
freqArray[i].enabled = enabled;
freqArray[i].bc_enabled = bc_enabled;
freqArray[i].bc_Mask = bc_mask;
freqArray[i].max_pot = pot;
// freqArray[i].v_coeff_lo = 0.876923;
freqArray[i].v_coeff_lo = v_lo;
freqArray[i].i_coeff_hi = i_hi;
freqArray[i].i_coeff_lo = i_lo;
freq.numFrequencies++;
}
void ClearFreqArray(void)
{
for(uint32_t i = 0; i < FREQ_MAX_NUM; i++)
{
freqArray[i].frequency1 = 0;
freqArray[i].frequency2 = 0;
freqArray[i].enabled = 0;
freqArray[i].bc_enabled = 0;
}
}
void FREQ_Init(void)
{
uint32_t tmp;
GPIO_PinWrite(GPIO, SIGNAL_PORT, SIG_RST_GPIO_PIN, 1); // Set all RESET signals to RESET
GPIO_PinWrite(GPIO, SIGNAL_PORT, SD_RST_GPIO_PIN, 1);
GPIO_PinWrite(GPIO, SIGNAL_PORT, RAMP_RST_GPIO_PIN, 1);
Delay_Ticks(1);
GPIO_PinWrite(GPIO, SIGNAL_PORT, RAMP_RST_GPIO_PIN, 0);
GPIO_PinWrite(GPIO, SIGNAL_PORT, SIG_RST_GPIO_PIN, 0); // Set all RESET signals to RESET
GPIO_PinWrite(GPIO, SIGNAL_PORT, SD_RST_GPIO_PIN, 0); // 8/26/24
freq.numFrequencies = 0;
if(!EE_LoadFrequencies())
{
FREQ_LoadFactoryDefaults();
}
Send_Ctrl_Word(SLP_CTRL_WRD,SDSIGNAL); // Put unused DDS to sleep
Load_Ramp(6710886); // 300KHz ramp waveform
}
void FREQ_LoadFactoryDefaults(void)
{
//These are the FACTORY TEST Frequencies
FREQ_ClearFrequencies();
FREQ_AddFrequency(512, 1, 1, FT_ACTIVE);
FREQ_AddFrequency(3140, 1, 1, FT_ACTIVE);
FREQ_AddFrequency(8192, 1, 1, FT_ACTIVE);
FREQ_AddFrequency(29433, 1, 1, FT_ACTIVE);
FREQ_AddFrequency(32770, 1, 1, FT_ACTIVE);
FREQ_AddFrequency(65055, 1, 1, FT_ACTIVE);
FREQ_AddFrequency(88779, 1, 1, FT_ACTIVE);
}
/*
* Pack frequency data and return
* Packed data is used for saving to FLASH
*/
uint32_t FREQ_GetPackedFrequency(uint32_t index)
{
uint32_t packed = freqArray[index].frequency1;
//packed |= freqArray[index].type << FREQ_PACK_SHIFT_TYPE;
packed |= (uint32_t)freqArray[index].enabled << FREQ_PACK_SHIFT_ENABLED;
//packed |= (uint32_t)freqArray[index].inMenu << FREQ_PACK_SHIFT_INMENU;
return packed;
}
/*
* Add a frequency to the list from packed data
* Packed data is used for saving to FLASH
*/
void FREQ_AddPackedFrequency(uint32_t packedFreq)
{
uint32_t frequency = packedFreq & FREQ_PACK_MASK_FREQ;
//FREQ_TYPE_t type = (packedFreq & FREQ_PACK_MASK_TYPE) >> FREQ_PACK_SHIFT_TYPE;
bool enabled = packedFreq & FREQ_PACK_MASK_ENABLED;
//bool inMenu = packedFreq & FREQ_PACK_MASK_INMENU;
FREQ_AddFrequency(frequency, enabled, 1, FT_ACTIVE); //inMenu always 1, all FT_ACTIVE
}
/*
* Clear the frequency list
* Zero out all data and set freq.numFrequencies to zero
*/
void FREQ_ClearFrequencies(void)
{
// frq_update_flag = true;
for(uint32_t i = 0; i < freq.numFrequencies; i++)
{
freqArray[i].frequency1 = 0;
freqArray[i].enabled = 0;
}
freq.numFrequencies = 0;
frequency = 0;
}
/*
* Add a Frequency from UM Setup
*/
void FREQ_AddFrequency(uint32_t f1, uint8_t enabledTemp, uint8_t inMenu, FREQ_TYPE_t type)
{
if(!inMenu)
{
return; //ignore freqs that are not in menu
}
if((type != FT_ACTIVE) && (type != FT_LD_ACTIVE))
{
return; //ignore RX frequency types
}
//TODO: Calculate other things in Keith's freqArray[] here
//frequency2 for LD needs a function to determine 2nd frequency
//Doesn't matter yet since RX doesn't support LD
//scale factors
//other crap
//f2
uint32_t f2 = 0;
if(type == FT_LD_ACTIVE)
{
if(f1 <= FREQ_LD_SWITCH_POINT)
{
f2 = f1 * 2;
}
else if(f1 <= FREQ_LD_MAX_FREQUENCY)
{
f2 = f1 / 2; //TODO: This will break for odd frequencies since it's an integer. Need to rework freqs...
}
else
{
f2 = 0;
}
}
//TODO: Generate values for these!!!!!!!!!!
uint32_t bc_enabledTemp = BC_Enable_Chk(f1);
uint32_t bc_maskTemp = BC_Mask_Chk(f1); //Todo remove as unused
uint32_t max_pot = Max_Pot_Chk(f1);
float32_t v_coeff_lo = V_coeff_lo_Chk(f1);
float32_t i_coeff_hi = I_coeff_hi_Chk(f1);
float32_t i_coeff_lo = I_coeff_lo_Chk(f1);
float32_t v_coeff_hi = V_coeff_hi_Chk(f1); //always 0
AddFrequency(f1, f2, enabledTemp, bc_enabledTemp, bc_maskTemp, max_pot, i_coeff_lo, i_coeff_hi, v_coeff_lo, v_coeff_hi);
}
uint8_t BC_Enable_Chk(uint32_t f1)
{
if((f1 >= BCAST_MIN) && (f1 < BCAST_MAX+1))
return(1);
else
return(0);
}
uint8_t BC_Mask_Chk(uint32_t f1)
{
if((f1 >= BCAST_MIN) && (f1 < 9820)|| (f1 >= 200000) && (f1 <=480000))
return(MASK_144);
else if(f1 == 29430 || f1==32768 || f1==65536 || f1==131072)
return(MASK_58);
else if(f1 == 44624 || f1== 83078)
return(MASK_15);
else
{
return 99;
}
}
uint8_t Max_Pot_Chk(uint32_t f1)
{
if(f1 < 440)
return(180);//165
if((f1 >= 440) && (f1 < 12000)) // 29430
return(235);
if((f1 >= 12000) && (f1 < 29430))
return(245);
if((f1 >= 29430)&& (f1 <= 44500))
return(250);
if((f1 > 44624) && (f1 < 200000))
return(200);
if(f1 == 200000)
return(140);
else
return(140);
//TODO set up default value
}
float V_coeff_lo_Chk(uint32_t f1)
{
float a;
switch(f1)
{
case 1 ... 940:
a= 0.876923;
break;
case 941 ... 1170:
a = 0.911538;
break;
case 1171 ... 6000:
a = 0.97083;
break;
case 6001 ... 8009:
a = 1.025;
break;
case 8010 ... 9820:
a = 1.025;
break;
case 9821 ... 29430:
a = 0.81;
break;
case 29431 ... 32768:
a = 0.81;//1.009;
break;
case 32769 ... 44100:
a = 1.035;
break;
case 44101 ... 65536:
a = 1.0;
break;
case 65537 ... 80000:
a = 1.1;
break;
case 80001 ... 199999:
a = 1.36;
break;
case 200000 ... 480000:
a = 4.5;
break;
default:
a = 0.53;
}
return(a);
}
float V_coeff_hi_Chk(uint32_t f1)
{
return(0);
}
float I_coeff_lo_Chk(uint32_t f1)
{
float a;
// a = freqArray[Search_for_frq(f1)].i_coeff_lo;
switch(f1)
{
case 1 ... 500:
a = 1;
break;
case 501 ... 870:
a= 0.8396;
break;
case 871 ... 1170:
a = 0.8105;
break;
case 1171 ... 3139:
a = 0.8634;
break;
case 3140 ... 6000:
a = 0.8634;
break;
case 6001 ... 8009:
a = 0.8634;
break;
case 8010 ... 9820:
a = 0.8976;
break;
case 9821 ... 29430:
a = 0.8976;
break;
case 29431 ... 32768:
a = 0.8976;
break;
case 32769 ... 44100:
a = 0.91;
break;
case 44101 ... 65536:
a = 1.015;
break;
case 65537 ... 199999:
a = 1.255;
break;
case 200000 ... 480000:
a = 3.111;
break;
default:
a = 0.8976;
}
return(a);
}
float I_coeff_hi_Chk(uint32_t f1)
{
float a;
a = freqArray[Search_for_frq(f1)].i_coeff_hi;
switch(f1)
{
case 1 ... 940:
a= 0.47;
break;
case 941 ... 1170:
a = 0.49;
break;
case 1171 ... 6000:
a = 0.482;
break;
case 6001 ... 8009:
a = 0.53;
break;
case 8010 ... 9820:
a = 0.53;
break;
case 9821 ... 29430:
a = 0.69;
break;
case 29431 ... 32768:
a = 0.71333;
break;
case 32769 ... 44100:
a = 1.035;
break;
case 44101 ... 65536:
a = 1.35;
break;
case 65537 ... 200000:
a = 1.36;
break;
case 200001 ... 480000:
a = 2.111;
break;
default:
a = 0.53;
}
return(a);
}
uint8_t Search_for_frq(uint32_t f1)
{
uint8_t i =0;
for(i=0; i < FREQ_MAX_NUM - 1; i++)
{
if((f1 == freqArray[i].frequency1)) //(freqArray[frq_tmp].enabled > 0)
break;
}
return(i);
}
void FREQ_ToggleEnable(uint32_t selected) //selected is same as frequency index
{
freqArray[selected].enabled ^= 1;
}
FREQUENCY_t FREQ_GetFreqByIndex(uint32_t index)
{
return freqArray[index];
}
FREQUENCY_t* FREQ_GetFreqPointerByIndex(uint32_t index)
{
return &freqArray[index];
}
uint32_t FREQ_GetNumFrequencies(void)
{
return freq.numFrequencies;
}
uint8_t Next_Frequency(uint8_t frq_tmp) // increments frequency
{
uint8_t found = false;
uint8_t i;
frq_tmp = frequency;
if (frq_tmp < FREQ_MAX_NUM - 1)
frq_tmp++;
else
frq_tmp = 0;
for(i=0; i < FREQ_MAX_NUM - 1; i++)
{
if(Check_freq_enabled(frq_tmp)) //(freqArray[frq_tmp].enabled > 0)
{
found = 1;
break;
}
if (frq_tmp < FREQ_MAX_NUM - 1)
frq_tmp++;
else
frq_tmp= 0;
}
return(frq_tmp);
}
bool Check_freq_enabled(uint8_t frq_tmp)
{
bool x;
x = false;
if(Cur_Mode != BROADCAST && (freqArray[frq_tmp].enabled > 0))
x= true;
else
if ((Cur_Mode == BROADCAST) && (freqArray[frq_tmp].bc_enabled > 0) && (freqArray[frq_tmp].enabled > 0))
x = true;
return(x);
}
/* Generate name for the frequency at the specified index
* @param index index in the frequency list
* @param *string pointer to the storage location for the name string
*/
void FREQ_GetFrequencyName(uint32_t index, uint8_t *string)
{
//Generate frequency name
// < 1000Hz: "xxxHz"
// < 10kHz: "x.xxkHz"
// < 100kHz: "xx.xkHz"
// >=100kHz: "xxxkHz"
uint32_t freqTemp = freqArray[index].frequency1; //the numeric freqTemp
if(freqArray[index].frequency2 != 0)
{
if(freqTemp < 1000)
{
sprintf(string, "LD %dHz", freqTemp);
}
else if(freqTemp < 10000)
{
sprintf(string, "LD %.2fkHz", (float32_t)freqTemp / 1000.0);
}
else
{
sprintf(string, "ERROR");
}
}
else
{
if(freqTemp < 1000)
{
sprintf(string, "%dHz", freqTemp);
}
else if(freqTemp < 10000)
{
sprintf(string, "%.2fkHz", (float32_t)freqTemp / 1000.0);
}
else if(freqTemp < 100000)
{
sprintf(string, "%.1fkHz", (float32_t)freqTemp / 1000.0);
}
else if(freqTemp < 500000)
{
sprintf(string, "%.0fkHz", (float32_t)freqTemp / 1000.0);
}
else
{
sprintf(string, "ERROR");
}
}
}
/*while(!found && frq_tmp < FREQ_MAX_NUM)
{
frq_tmp++;
if(freqArray[frq_tmp].enabled > 0)
found = true;
if(frq_tmp >= FREQ_MAX_NUM)
frq_tmp = FREQ_MIN;
} */
void Update_Min_Frequency(void)
{
}
void Update_Frequency()
{
uint32_t tmp;
if (Cur_Mode != BROADCAST) // IF - ! Broadcast
{
Enable_Amplifier(); // Select correct amplifier
Select_Transformer(); // Select correct transformer
// tmp = Calc_Freq(freqArray[frequency].frequency1);
// Load_Frq_Gen(SINGLE,tmp,0); // # update the frequency generators
Set_Selected_Freq();
Taps_Flag = false;
if((ACCY_GetConnectedAccessory(1) == ID_CLAMP) || (ACCY_GetConnectedAccessory(2) == ID_CLAMP))
{
Get_Clamp_Value(); // Ensure correct table for Clamp amplitude
SPI0_SendBytes(Dds_Pot_Val, 2, AMPLITUDE);
}
else
if ((ACCY_GetConnectedAccessory(1) == ID_CLAMP2) || (ACCY_GetConnectedAccessory(2) == ID_CLAMP2))
{
clampData.regulate = true;
if (freqArray[frequency].frequency1 < 800)
{
clampData.maxPower = MAX_POWER_TARGET_VLF;
}
else
if (freqArray[frequency].frequency1 < 45000)
{
clampData.maxPower = MAX_POWER_TARGET_LF;
}
else
{
clampData.maxPower = MAX_POWER_TARGET_HF;
}
Get_Clamp_Value();
clampData.timeout = systemTime + CLAMP_REGULATE_DELAY;
if (Power_Level > 0)
{
clampData.prevPowerLevel = 0;
setTestPot();
}
}
// Select_Output_Port(ONE); // Switch in the correct pathway
}
else // else
{
All_Amps_Off(); // shut down Amplifiers DC connections
Disable_DC();
Enable_BC(); // Enable BCAST circuitry using either Minimum or previously selected freq
LD_Flag = false;
// Init_PWM(); // update PWM generators
}
old_freq = frequency; // Indicate done
}
void Set_Selected_Freq(void)
{
uint32_t frq1;
uint32_t frq2;
if(LD_Flag && freqArray[frequency].frequency1 <= MAX_LD_FREQ)
{
frq1 = Calc_Freq(freqArray[frequency].frequency1);
frq2 = freqArray[frequency].frequency1;
frq2 = frq2 * 2.0;
// frq2 = 9100; // test only
frq2 = Calc_Freq(frq2);
Load_Frq_Gen(DUAL,frq1,frq2); // # update the frequency generators
}
else
{
frq1 = Calc_Freq(freqArray[frequency].frequency1);
frq2 = 0;
Load_Frq_Gen(SINGLE,frq1,frq2); // # update the frequency generators
Send_Ctrl_Word(SLP_CTRL_WRD,SDSIGNAL); // Put unused DDS to sleep
}
}
void Reset_DDS(void)
{
GPIO_PinWrite(GPIO, SIGNAL_PORT, SIG_RST_GPIO_PIN, 1); // Set all RESET signals to RESET
GPIO_PinWrite(GPIO, SIGNAL_PORT, SD_RST_GPIO_PIN, 1);
GPIO_PinWrite(GPIO, SIGNAL_PORT, RAMP_RST_GPIO_PIN, 1);
Delay_Ticks(1);
GPIO_PinWrite(GPIO, SIGNAL_PORT, RAMP_RST_GPIO_PIN, 0);
GPIO_PinWrite(GPIO, SIGNAL_PORT, SIG_RST_GPIO_PIN, 0); // Set all RESET signals to RESET
}
void Change_to_next_dc_frq(void)
{
uint32_t tmp_frqx;
uint8_t count;
if((ACCY_GetConnectedAccessory(1) == ID_CLAMP) || (ACCY_GetConnectedAccessory(2) == ID_CLAMP))
{
frequency = Next_Frequency(frequency); // increment the frequency
new_freq = freqArray[frequency].frequency1;
if(freqArray[frequency].frequency1 <= MIN_CTYPE)// is frequecny > min
{
count = 0;
while(freqArray[frequency].frequency1 < MIN_CTYPE && count < FREQ_MAX_NUM)
{
frequency = Next_Frequency(frequency); // increment the frequency
new_freq = freqArray[frequency].frequency1;
count++;
}
// tmp_frqx = Search_Frequency(256); // select minimum frequency for DC Clamp operation
// if (tmp_frqx < FREQ_MAX_NUM) // set up new min freq
// {
// frequency = tmp_frqx;
// new_freq = freqArray[frequency].frequency1;
// }
}
else
{
// frequency = Next_Frequency(frequency); // increment the frequency
new_freq = freqArray[frequency].frequency1;
}
}
else
{
frequency = Next_Frequency(frequency); // increment the frequency
new_freq = freqArray[frequency].frequency1;
//Sys_Chk_tmr= DELAY_500MS; // Allow system settling before checking measurements
// catch_up_flag = true;
}
}
void Change_To_Next_BC_Freq(void)
{
uint32_t tmp_frqx;
if(Cur_Mode == BROADCAST) // Special case only if BC mode already selected
{
if (freqArray[frequency].frequency1 < BCAST_MIN) // if (freq < min freq) ToDo
tmp_frqx = Search_Frequency(3140); // select minimum frequency for BCAST
if (tmp_frqx < FREQ_MAX_NUM)
{
frequency = tmp_frqx;
new_freq = freqArray[frequency].frequency1;
}
}
}

View File

@@ -1,145 +0,0 @@
/*
* frq.h
*
* Created on: Jun 8, 2022
* Author: Keith.Lloyd
*/
#ifndef FRQ_H_
#define FRQ_H_
#include "spi.h"
typedef enum {
NULL_FREQ,
SINGLE,
DUAL
}FRQ_OUT_SELECT_t;
#define TX_SYS_CLK 12000000 // 12MHZ
#define DDS_CLK TX_SYS_CLK
#define FREQ_MAX_NUM 50 //Max number of frequencies allowed
#define FREQ_MIN 0
#define FREQ0_REG 0x4000 // Address of internal 9838 register
#define FRQ_CTRL_WORD1 0x2100 // Control register with Reset bit active
#define FRQ_CTRL_WORD2 0x2000 // Exit Reset Control Word
//#define FRQ_CTRL_WORD2 0x2038 // Exit Reset Control Word for PLL Test
#define PHASE_RESET 0xC000 // PHASE Register 0 = 0;
#define RAMP_CTRL_WORD1 0x2102
#define RAMP_CTRL_WORD2 0x2002
#define RAMP_CTRL_WORD3 0x2002 // TODO Places wavegen in sleep mode
#define SLP_CTRL_WRD 0x2180 // Power down unused DDS
#define SLP_CTRL_WRD2 0x21C0
#define RAMP_PORT 1
//#define RAMP_RST_GPIO_PIN 14
#define HI 1
#define BCAST_MIN 3140
#define BCAST_MAX 200000
#define DUMMY_FRQ 250
#define MIN_BLOCK_FREQ 20000
#define MASK_15 0b00000000
#define MASK_58 0b00001000
#define MASK_144 0b00011000
#define CLK_MASK_BITS 0b11100111
#define MAX_LD_FREQ 10000
//FREQUENCY PACKING - from RX so it has extra fields
#define FREQ_PACK_MASK_FREQ 0x0007ffff //target frequency bits 0 - 18
#define FREQ_PACK_MASK_TYPE 0x00380000 //3-bit field for FREQ_TYPE_t. bits 19 - 21
#define FREQ_PACK_SHIFT_TYPE 19 //Frequency type shift
#define FREQ_PACK_MASK_ENABLED 0x80000000 //enabled mask
#define FREQ_PACK_SHIFT_ENABLED 31 //enabled shift bit 31
#define FREQ_PACK_MASK_INMENU 0x40000000 //inMenu mask
#define FREQ_PACK_SHIFT_INMENU 30 //inMenu shift bit 30
//Locate direction (LD)
#define FREQ_LD_MAX_FREQUENCY 10000 //LD runs at or below this frequency
#define FREQ_LD_SWITCH_POINT 1500 //At or below this freq, f2 is f1 * 2. above this f2 = f1 / 2
#define MIN_CTYPE 263 // Minimum clamp frequency.
typedef enum {
FT_ACTIVE, //active
FT_LD_ACTIVE, //active w/ Locate Direction
FT_POWER, //RX ONLY individual power
FT_GROUPED_POWER, //RX ONLY Radio style grouped power
FT_CATHODIC, //RX ONLY cathodic protection - Identical to individual power except naming in frequency menu
FT_SONDE, //RX ONLY
FT_RADIO, //RX ONLY
FT_FAULT_FIND, //RX ONLY fault finder - Has it's own dedicated frequency set. frequencies are NOT user definable
}FREQ_TYPE_t;
//Data for individual frequencies
typedef struct {
uint32_t frequency1; //frequency in Hz
uint32_t frequency2;
uint8_t enabled; //
uint8_t bc_enabled;
uint8_t bc_Mask;
uint8_t max_pot;
float i_coeff_lo;
float i_coeff_hi;
float v_coeff_lo;
float v_coeff_hi;
}FREQUENCY_t;
//General data for frequencies module
typedef struct {
uint32_t numFrequencies; //number of frequencies in freqArray
}FREQDATA_t;
void FREQ_Init(void);
void FREQ_LoadFactoryDefaults(void);
uint32_t FREQ_GetPackedFrequency(uint32_t index);
void FREQ_AddPackedFrequency(uint32_t packedFreq);
void FREQ_ClearFrequencies(void);
void FREQ_AddFrequency(uint32_t f1, uint8_t enabledTemp, uint8_t inMenu, FREQ_TYPE_t type);
void Load_Ramp(uint32_t ramp_freq);
void Load_Frq_Gen(FRQ_OUT_SELECT_t, int32_t, int32_t); // NONE,either or both plus two data words
//void AddFrequency(uint32_t frequency, uint32_t frequency2, uint8_t enabled, uint8_t bc_enabled, uint8_t bc_mask);
uint8_t Next_Frequency(uint8_t frequency);
void FREQ_ToggleEnable(uint32_t selected);
FREQUENCY_t FREQ_GetFreqByIndex(uint32_t index);
FREQUENCY_t* FREQ_GetFreqPointerByIndex(uint32_t index);
uint32_t FREQ_GetNumFrequencies(void);
void FREQ_GetFrequencyName(uint32_t index, uint8_t *string);
void Send_Ctrl_Word(uint16_t Control_Reg, SPI_MODE_t mode);
uint32_t Calc_Freq(uint32_t fout); // Calculate frequency word for DDS
void Update_Min_Frequency(void);
void Update_Frequency();
void Reset_DDS(void);
void AddFrequency(uint32_t frequency1,uint32_t frequency2, uint8_t enabled, uint8_t bc_enabled,uint8_t bc_mask,uint8_t pot,float i_lo,float i_hi,float v_lo,float v_hi);
bool Check_freq_enabled(uint8_t frq_tmp);
uint8_t BC_Enable_Chk(uint32_t f1);
uint8_t BC_Mask_Chk(uint32_t f1);
uint8_t Max_Pot_Chk(uint32_t f1);
float V_coeff_lo_Chk(uint32_t f1);
float V_coeff_hi_Chk(uint32_t f1);
float I_coeff_lo_Chk(uint32_t f1);
float I_coeff_hi_Chk(uint32_t f1);
uint8_t Search_for_frq(uint32_t f1);
void Change_to_next_dc_frq(void);
void Change_To_Next_BC_Freq(void);
void Set_Selected_Freq(void);
extern FREQUENCY_t freqArray[];
#endif /* FRQ_H_ */

View File

@@ -31,13 +31,30 @@ void io_update(void)
void io_expanderSetSafe(void)
{
_expanderState[BOT_SR] = 0;
_expanderState[MID_SR] = 0;
_expanderState[TOP_SR] = 0;
io_expanderClearAll(NO_UPDATE);
io_connectAmpAB(false, NO_UPDATE);
io_backlightOn(true, NO_UPDATE);
io_ampPsuOn(false, NO_UPDATE);
io_update();
}
void io_connectAmpAB(bool connect, bool update)
{
if (connect)
{
EXPANDER_CLEAR(DISCONNECT_AB, NO_UPDATE);
}
else
{
EXPANDER_SET(DISCONNECT_AB, NO_UPDATE);
}
if (update) io_update();
}
void io_expanderClearAll(bool update)
{
_expanderState[BOT_SR] = 0;
@@ -51,36 +68,29 @@ void io_backlightOn(bool on, bool update)
{
if (on)
{
EXPANDER_SET(BACKLIGHT_ON, update);
EXPANDER_SET(BACKLIGHT_ON, NO_UPDATE);
}
else
{
EXPANDER_CLEAR(BACKLIGHT_ON, update);
EXPANDER_CLEAR(BACKLIGHT_ON, NO_UPDATE);
}
if (update) io_update();
}
void io_ampABOn(bool on, bool update)
{
if (on)
{
EXPANDER_SET(AMP_AB_ON, update);
}
else
{
EXPANDER_CLEAR(AMP_AB_ON, update);
}
}
void io_ampDOn(bool on, bool update)
{
if (on)
{
EXPANDER_SET(AMP_D_EN, update);
EXPANDER_SET(AMP_D_EN, NO_UPDATE);
}
else
{
EXPANDER_CLEAR(AMP_D_EN, update);
EXPANDER_CLEAR(AMP_D_EN, NO_UPDATE);
}
if (update) io_update();
}
void io_broadcastOn(bool on, bool update)
@@ -112,4 +122,4 @@ void io_ampPsuOn(bool on, bool update)
}
if (update) io_update();
}
}

View File

@@ -90,10 +90,11 @@ void io_update(void);
#define BYPASS_ON (MID_SR , LF_BYPASS)
#define BACKLIGHT_ON (BOT_SR, BKLITE_ON)
#define AMP_AB_ON (TOP_SR, MUX_AB_AMP)
#define DISCONNECT_AB (TOP_SR, MUX_AB_AMP)
#define BROADCAST_AMP_EN (MID_SR, ANT_AMP_EN)
#define BROADCAST_AMP_PWR (TOP_SR, ANT_AMP_SW)
#define AMP_D_EN (MID_SR, DAMP_EN)
#define _AMP_PSU_ON (BOT_SR, AMP_PSU)
@@ -112,9 +113,11 @@ typedef struct
void io_expanderClearAll(bool update);
void io_backlightOn(bool on, bool update);
void io_ampABOn(bool on, bool update);
void io_ampDOn(bool on, bool update);
void io_broadcastOn(bool on, bool update);
void io_ampPsuOn(bool on, bool update);
void io_connectAmpAB(bool connect, bool update);
void io_expanderSetSafe(void);
#endif

View File

@@ -204,18 +204,7 @@ void Display_Update(void)
LCD_Clear(); //clear the frameBuffer
Display_USB_Status();
if((!Check_For_Clamp_New()) && Display_warning_tmr == 0)
Display_Over_Voltage_Status();
Display_Tx_Status();
//Display_OnScreen_Diagnostics(); // temporary for debug
#if 0 //info
if(Diag_Flag)
Display_OnScreen_Diagnostics();
#endif
LCD_Update();
}

View File

@@ -19,7 +19,6 @@
#include "spi.h"
#include "lcd.h"
#include "main.h"
#include "frq.h"
#include "pro_key.h"
#include "menu1.h"
#include "mode.h"
@@ -77,23 +76,7 @@ extern SYSTEM_DATA_t sys;
ClampData_t clampData;
void setSafeMode(bool safe)
{
sys.safeMode = safe;
//Select_Estop((safe ? ISOLATED : CONNECTED));
driver_isolateOutput(true);
if (safe)
{
//clear shift registers to known state
Port_State[MID_SR] = USB_STATE_MID; //
Port_State[BOTTOM_SR] = USB_STATE_BOT; //
Port_State[TOP_SR] = USB_STATE_TOP;
SPI0_SendBytes(Port_State, 3, EXPANDER); // Update shift register
Delay_Ticks(1);
Send_Ctrl_Word(SLP_CTRL_WRD2, SIGNAL); // Switch signal off
}
}
bool isUsbConnected(void)
{
@@ -141,7 +124,7 @@ static void init(void)
io_expanderClearAll(false);
io_backlightOn(true, NO_UPDATE);
io_ampABOn(true, NO_UPDATE);
io_connectAmpAB(true, NO_UPDATE);
io_update();
BL_ReadInfo();
@@ -199,7 +182,8 @@ int main(void)
// USB connected
if (!prevUsbConnected)
{
setSafeMode(true);
driver_setSafe(true);
//setSafeMode(true);
}
Display_USB();
@@ -214,7 +198,8 @@ int main(void)
//init();
// check that things are safe before exiting safe mode
setSafeMode(false);
//setSafeMode(false);
driver_setSafe(false);
prevUsbConnected = false;
}
}
@@ -332,80 +317,9 @@ int main(void)
Display_Update();
}
#if 0
switch (Task)
{
case PRIMARY_TASK:
pro_key(pressed); // process primary keys front 6 first menu
break;
case BAT_INSERTION_ERROR:
if(Shut_down_tmr == 0); //Display_Bat_Error();
Power_Down(); // Stores last settings and powers off
break;
case LOW_BATTERY_TASK:
if(Low_Bat_timer == 0)
Task = PWR_OFF_TASK;
break;
}
#endif
#if 0
if(old_freq != frequency && frq_chg_tmr == 0 && (!frq_update_flag))
{
Update_Frequency();
//Port_changed_flag = true;
}
if(Bat_Type == BAT_ERROR)
Task = BAT_INSERTION_ERROR;
if (Port_timer == 0)
Read_Tx_Ports(); // check for whats plugged in at the ports every 100mS.
if(Port_changed_flag)
{
Select_Output_Port();
Update_Frequency();
Init_Pwr_Level_One(); // Set power out level 1
}
if((!Check_For_Clamp_New()))
{
Check_For_Open_Circuit(); // DC mode only
}
else
{
EXPANDER_SET(BYPASS_ON, true);
//Port_State[MID_SR] |= BYPASS_ON; // Set relay to By Pass protection cap
//SPI0_SendBytes(Port_State, 3, EXPANDER); // Send_Update_Port();
}
if (Check_For_Clamp())
{
doClampPower();
}
//Send_Wireless_Data(); // Send system update to Receiver.
if (Taps_adjust_timer == 0)
Check_Taps(); // Check for optimum Taps
#endif
}

View File

@@ -22,7 +22,6 @@
#include "lcd.h"
#include "keys.h"
#include "timer.h"
#include "frq.h"
#include "Graphics\icons.h"
#include "System\system.h"
#include "mode.h"
@@ -96,21 +95,11 @@ static int handleSystemInfoMenu(Menu_t *menu);
static int handleAutoShutdown(Menu_t *menu);
static int handleFrequencies(Menu_t *menu);
static void ClearMenuItems(MenuItem_t items[], uint32_t num);
static void DrawMenuScrollBar(uint32_t displayIndex, uint32_t numItems);
static void DisplaySystemInfo(void);
static void DisplayDiagnostics(void);
static void DisplayDiagnostics2(void);
static void LinkRadioMenu(void);
static void DisplayLinkRadioMenu(uint32_t selected);
static void FrequenciesMenu(void);
static void DisplayFrequenciesMenu(uint32_t selected);
static void LanguageMenu(void);
static void DisplayLanguageMenu(uint32_t selected);
static void DisplayRegulatoryInfo(void);
@@ -339,15 +328,15 @@ static int handleFrequencies(Menu_t *menu)
int itemCount = 0;
menu->items = &_menuItems[_menuItemsIndex];
MenuItem_t *item;
int numFreq = FREQ_GetNumFrequencies();
int numFreq = fgen_getNumFrequencies();
for (int i=0; i<numFreq; ++i)
{
item = &menu->items[itemCount++];
item->id = MENU_ID_FREQUENCY;
item->handler = NULL;
FREQ_GetFrequencyName(i, item->text);
item->data = (void*)FREQ_GetFreqPointerByIndex(i);
item->data = (void*)fgen_getByIndex(i);
fgen_getFrequencyName(item->data, item->text);
}
_menuItemsIndex += itemCount;
@@ -386,7 +375,7 @@ static int handleFrequencies(Menu_t *menu)
FL_DrawString(item->text, MENU_MAIN_TEXT_X, MENU_MAIN_TEXT_Y_START + (i - menu->displayIndex)*MENU_LINE_HEIGHT, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
//checkBoxes
if(FREQ_GetFreqByIndex(i).enabled)
if (fgen_getByIndex(i)->enabled)
{
GL_DrawMonoBitmap(box_checked, MENU_MAIN_STATUS_X, MENU_MAIN_TEXT_Y_START +2+ (i - menu->displayIndex)*MENU_LINE_HEIGHT, LCD_DRAW_SET);
}
@@ -559,17 +548,6 @@ static int handleMainMenu(Menu_t *menu)
//Clear an array of MENU_ITEM_t
static void ClearMenuItems(MenuItem_t items[], uint32_t num)
{
for(uint32_t i = 0; i < num; i++)
{
items[i].pMonoIcon = NULL; //Init mono icon pointer to null
items[i].text[0] = '\0'; //Init first char to null
}
}
//Draw menu scroll bar on right side
static void DrawMenuScrollBar(uint32_t displayIndex, uint32_t numItems)
@@ -603,714 +581,6 @@ static void DrawMenuScrollBar(uint32_t displayIndex, uint32_t numItems)
}
static void SystemInfoMenu(void)
{
uint32_t selected = 0;
uint32_t menuExit = 0;
while(1)
{
if(KEY_IsKeyPressed(KEY_ALL))
{
//use keys to change selected
uint32_t pressed = KEY_WaitForKeyPress(KEY_ALL);
switch(pressed) //This won't work if multiple keys pressed, but it'll clear them
{
case KEY_UP:
if(--selected > MENU_SYS_INFO_NUM)
{
selected = 0;
}
break;
case KEY_DOWN:
if(++selected >= MENU_SYS_INFO_NUM)
{
selected = MENU_SYS_INFO_NUM - 1;
}
break;
case KEY_BACK:
menuExit = true;
break;
case ON_OFF_KEY:
menu.exitToMainScreen = true;
break;
case KEY_POWER: //Look for test menu key sequence: HOLD POWER,
if(selected == 1) //Must be in Diagnostics to enter test menu
{
uint32_t mode = 0;
uint32_t up = 0;
uint32_t down = 0;
while(KEY_GetPowerKeyHeld())
{
if(KEY_GetModeKeyHeld())
{
mode++;
while(KEY_GetModeKeyHeld());
}
if(KEY_GetUpKeyHeld())
{
up++;
while(KEY_GetUpKeyHeld());
}
if(KEY_GetDownKeyHeld())
{
down++;
while(KEY_GetDownKeyHeld());
}
delayms(100);
}
if((mode == 2) && (up == 2) && (down == 1))
{
TM_TestMenu();
}
}
}
}
#if 1 //Update info for diagnostics screens.
//ACCEL_Update();
//RTC_Update();
#endif
//Display selected screen
switch(selected)
{
case 0:
DisplaySystemInfo();
break;
case 1:
DisplayDiagnostics();
break;
case 2:
DisplayDiagnostics2();
break;
default:
break;
}
if(menuExit || menu.exitToMainScreen)
{
return;
}
Delay_Ticks(10); //100mS delay for screen display
}
}
static void DisplaySystemInfo(void)
{
uint32_t xCol1 = 0;
uint32_t xCol2 = 145;
uint32_t yStart = 17;//22;
uint32_t yPos = yStart;
uint32_t yInc = 18;//7;
LCD_Clear();
//Title
FL_DrawTranslatedString("SYSTEM INFO", LCD_X_MID, 0, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_CENTER);
//Column 1
yPos = yStart;
if(Read_Model_type() != LEICA)
FL_DrawTranslatedString(sys.manufacturer, xCol1, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
else
{
// tempstr2[10] = " 1005573";
// sprintf(sys.manufacturer, "%s%s",sys.manufacturer,tempstr2);
FL_DrawTranslatedString(sys.manufacturer, xCol1, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
FL_DrawTranslatedString(" 1005573", xCol1 + 64, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
}
yPos += yInc;
FL_DrawTranslatedString("Model Name", xCol1, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
yPos += yInc;
FL_DrawTranslatedString("Serial Number", xCol1, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
yPos += yInc;
FL_DrawTranslatedString("Loader Version", xCol1, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
yPos += yInc;
FL_DrawTranslatedString("Software Version", xCol1, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
yPos += yInc;
FL_DrawTranslatedString("Manufacture Date", xCol1, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
yPos += yInc;
//Column 2
yPos = yStart;
if(strncmp(sys.manufacturer, "Underground", 10) == 0 || strncmp(sys.manufacturer, "Goldenland", 9) == 0) //If MFG is "Underground...", move modelNumber to the right
{
FL_DrawString(sys.modelNumber, LCD_X_MAX, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_RIGHT);
yPos += yInc;
}
else
{
FL_DrawString(sys.modelNumber, xCol2, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
yPos += yInc;
}
if(Read_Model_type() == UMAG)
FL_DrawString("10W", xCol2, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
else
FL_DrawString(sys.modelName, xCol2, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
yPos += yInc;
FL_DrawString(sys.serialNumber, xCol2, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
yPos += yInc;
sprintf(tempString, "%d", sys.bootloaderVersion);
FL_DrawString(tempString, xCol2, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
yPos += yInc;
FL_DrawString(SW_VERSION, xCol2, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
yPos += yInc;
FL_DrawString(sys.mfgDate, xCol2, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
yPos += yInc;
LCD_Update();
}
static void DisplayDiagnostics(void)
{
uint32_t xCol1 = 2;
uint32_t xCol2 = 100;
uint32_t yStart = 25;
uint32_t yPos = yStart;
uint32_t yInc = 16;
LCD_Clear();
//Title
FL_DrawString("DIAGNOSTICS 1", LCD_X_MID, 0, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_CENTER);
//Show Main PCBA PN top right
sprintf(tempString, "%d", hwf.mainPcbaPN);
FL_DrawString(tempString, LCD_X_MAX, yStart, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_RIGHT);
//Column 1: Headings
yPos = yStart;
FL_DrawString("Output", xCol1, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
yPos += yInc;
FL_DrawString("Frequency", xCol1, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
yPos += yInc;
#if 0
FL_DrawString("Voltage", xCol1, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
yPos += yInc;
FL_DrawString("Current", xCol1, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
yPos += yInc;
FL_DrawString("Power", xCol1, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
yPos += yInc;
#endif
yPos += yInc;
yPos += yInc;
FL_DrawString("Ios", xCol1, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT); //current offset
yPos += yInc;
FL_DrawString("Vos", xCol1, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT); //voltage offset
yPos += yInc;
//Column 2: values
yPos = yStart;
switch(Cur_Mode) //Show text for MODE
{
case BROADCAST:
sprintf(tempString, "INDUCTION");
break;
case PORT1_A:
sprintf(tempString, "PORT 1A");
break;
case PORT1_B:
sprintf(tempString, "PORT 1B");
break;
case PORT2_A:
sprintf(tempString, "PORT 2A");
break;
case PORT2_B:
sprintf(tempString, "PORT 1B");
break;
default:
sprintf(tempString, "Taco");
break;
}
FL_DrawString(tempString, xCol2, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
yPos += yInc;
FREQ_GetFrequencyName(frequency, tempString);
FL_DrawString(tempString, xCol2, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT); //Frequency
yPos += yInc;
#if 0
FL_DrawString(tempString, xCol2, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT); //voltage
yPos += yInc;
FL_DrawString(tempString, xCol2, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT); //current
yPos += yInc;
FL_DrawString(tempString, xCol2, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT); //power
yPos += yInc;
#endif
sprintf(tempString, "POT %d", Dds_Pot_Val[1]);
FL_DrawString(tempString, xCol1, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
if(psu_failed)
{
sprintf(tempString, "PSU Error1");
FL_DrawString(tempString, xCol2, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
}
yPos += yInc;
if((Port_State[MID_SR] & 0x40) > 0)
sprintf(tempString, "Gain HI");
else
sprintf(tempString, "Gain LO");
FL_DrawString(tempString, xCol1, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
yPos += yInc;
// yPos += yInc;
sprintf(tempString, "%d", sys.adc.V_OffsetAdc);
FL_DrawString(tempString, xCol2, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT); //voltage offset
if(!sys.adc.vosOK)
{
FL_DrawString("ERR", xCol1 + 30, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
}
yPos += yInc;
sprintf(tempString, "%d", sys.adc.I_OffsetAdc);
FL_DrawString(tempString, xCol2, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT); //current offset
if(!sys.adc.iosOK)
{
FL_DrawString("ERR", xCol1 + 30, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
}
yPos += yInc;
LCD_Update();
}
static void DisplayDiagnostics2(void)
{
uint32_t xCol1 = 2;
uint32_t xCol2 = 100;
uint32_t yStart = 25;
uint32_t yPos = yStart;
uint32_t yInc = 16;
LCD_Clear();
//Title
FL_DrawString("DIAGNOSTICS 2", LCD_X_MID, 0, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_CENTER);
#if 0
//Column 1: Headings
yPos = yStart;
FL_DrawString("Output", xCol1, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
yPos += yInc;
//Column 2: values
yPos = yStart;
switch(Cur_Mode) //Show text for MODE
{
case BROADCAST:
sprintf(tempString, "INDUCTION");
break;
case PORT1_A:
sprintf(tempString, "PORT 1A");
break;
case PORT1_B:
sprintf(tempString, "PORT 1B");
break;
case PORT2_A:
sprintf(tempString, "PORT 2A");
break;
case PORT2_B:
sprintf(tempString, "PORT 1B");
break;
default:
sprintf(tempString, "Taco");
break;
}
FL_DrawString(tempString, xCol2, yPos, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
yPos += yInc;
#endif
LCD_Update();
}
static void LinkRadioMenu(void)
{
}
static void DisplayLinkRadioMenu(uint32_t selected)
{
}
static void FrequenciesMenu(void)
{
static uint32_t selected = 0; //static = menu selection persists - Is this a good thing?
uint32_t menuExit = 0;
uint32_t numFrequencies = FREQ_GetNumFrequencies();
//Draw screen first time
DisplayFrequenciesMenu(selected);
while(1)
{
//use keys to change selected
uint32_t pressed = KEY_WaitForKeyPress(KEY_ALL);
switch(pressed) //This won't work if multiple keys pressed, but it'll clear them
{
case KEY_BACK:
menuExit = true;
break;
case ON_OFF_KEY:
menu.exitToMainScreen = true;
break;
case KEY_UP:
if(--selected > numFrequencies)
{
selected = 0;
}
DisplayFrequenciesMenu(selected);
break;
case (KEY_UP << KEY_LONG_PRESS):
do
{
if(--selected > numFrequencies)
{
selected = 0;
}
DisplayFrequenciesMenu(selected);
Delay_Ticks(MENU_KEY_HOLD_SCROLL_DELAY);
}
while(KEY_GetUpKeyHeld());
break;
case KEY_DOWN:
if(++selected >= numFrequencies)
{
selected = numFrequencies - 1;
}
DisplayFrequenciesMenu(selected);
break;
case (KEY_DOWN << KEY_LONG_PRESS):
do
{
if(++selected >= numFrequencies)
{
selected = numFrequencies - 1;
}
DisplayFrequenciesMenu(selected);
Delay_Ticks(MENU_KEY_HOLD_SCROLL_DELAY);
}
while(KEY_GetDownKeyHeld());
break;
case KEY_ENTER:
//Toggle enable on selected frequency
FREQ_ToggleEnable(selected); //selected is same as frequency index
DisplayFrequenciesMenu(selected); //Redraw menu after any changes
break;
}
if(menuExit || menu.exitToMainScreen)
{
return;
}
}
}
static void DisplayFrequenciesMenu(uint32_t selected)
{
#if 1
uint32_t numFrequencies = FREQ_GetNumFrequencies();
static char displayIndex = 0; //index of first menu line to draw
LCD_Clear();
//Title
//FL_DrawString("FREQUENCIES", LCD_X_MID, 0, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_CENTER);
//Update displayIndex
if(selected >= (displayIndex + MENU_MAX_LINES_DISPLAYED))
{
displayIndex++;
}
else if(selected < displayIndex)
{
displayIndex--;
}
//Draw menu items
for(uint32_t i = displayIndex; i < displayIndex + numFrequencies; i++) //this could draw lots of frequencies off the screen but we don't care
{
//Frequency name
FREQ_GetFrequencyName(i, tempString);
FL_DrawString(tempString, MENU_MAIN_TEXT_X, MENU_MAIN_TEXT_Y_START + (i - displayIndex)*MENU_LINE_HEIGHT, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
//checkBoxes
if(FREQ_GetFreqByIndex(i).enabled)
{
GL_DrawMonoBitmap(box_checked, MENU_MAIN_STATUS_X, MENU_MAIN_TEXT_Y_START +2+ (i - displayIndex)*MENU_LINE_HEIGHT, LCD_DRAW_SET);
}
else
{
GL_DrawMonoBitmap(box_unchecked, MENU_MAIN_STATUS_X, MENU_MAIN_TEXT_Y_START +2+ (i - displayIndex)*MENU_LINE_HEIGHT, LCD_DRAW_SET);
}
}
//Draw selection bar
uint32_t selRectY0 = MENU_MAIN_TEXT_Y_START + (selected - displayIndex)*MENU_LINE_HEIGHT;
//GL_DrawFilledRoundedRectangle(MENU_SEL_RECT_X0, selRectY0, MENU_SEL_RECT_X1, selRectY0 + MENU_LINE_HEIGHT, MENU_SEL_RECT_RADIUS, LCD_DRAW_XOR);
GL_DrawFilledRectangle(MENU_SEL_RECT_X0, selRectY0, MENU_SEL_RECT_X1A, selRectY0 + MENU_LINE_HEIGHT, LCD_DRAW_XOR);
//Draw menu icons
//Use DrawMenuBitmap(mainMenu[i], x, y)
DrawMenuScrollBar(displayIndex, numFrequencies);
LCD_Update();
#endif
}
static void LanguageMenu(void)
{
static uint32_t selected = 0; //static = start language menu where we left off
uint32_t menuExit = 0;
//Draw screen first time
DisplayLanguageMenu(selected);
KEY_ClearAll();
while(1)
{
//use keys to changes selected
uint32_t pressed = KEY_WaitForKeyPress(KEY_ALL);
switch(pressed) //This won't work if multiple keys pressed, but it'll clear them
{
case KEY_BACK:
menuExit = true;
break;
case ON_OFF_KEY:
menu.exitToMainScreen = true;
break;
case KEY_UP:
selected--;
if(selected > LANG_NUM)
{
selected = 0;
}
DisplayLanguageMenu(selected);
break;
case (KEY_UP << KEY_LONG_PRESS):
do
{
if(--selected > LANG_NUM)
{
selected = 0;
}
DisplayLanguageMenu(selected);
Delay_Ticks(MENU_KEY_HOLD_SCROLL_DELAY);
}
while(KEY_GetUpKeyHeld());
break;
case KEY_DOWN:
selected++;
if(selected >= LANG_NUM)
{
selected = LANG_NUM - 1;
}
DisplayLanguageMenu(selected);
break;
case (KEY_DOWN << KEY_LONG_PRESS):
do
{
if(++selected >= LANG_NUM)
{
selected = LANG_NUM - 1;
}
DisplayLanguageMenu(selected);
Delay_Ticks(MENU_KEY_HOLD_SCROLL_DELAY);
}
while(KEY_GetDownKeyHeld()); // Bug fixed KL 6/26/24
break;
case KEY_ENTER:
sys.language = selected; //Change language
DisplayLanguageMenu(selected);
break;
}
if(menuExit || menu.exitToMainScreen)
{
return;
}
}
}
static void DisplayLanguageMenu(uint32_t selected)
{
static char displayIndex = 0; //index of first menu line to draw
LCD_Clear();
//Title
//FL_DrawString("LANGUAGE MENU", 240, 0, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_CENTER);
if(selected >= (displayIndex + MENU_MAX_LINES_DISPLAYED))
{
displayIndex++;
}
else if(selected < displayIndex)
{
displayIndex--;
}
//Draw menu strings
uint32_t lastIndex = displayIndex + MENU_MAX_LINES_DISPLAYED;
for(uint32_t i = displayIndex; i < lastIndex; i++)
{
//Language name
if(i == LANG_CHINESE || i == LANG_KOREAN) //Simsun for Chinese and Korean
{
FL_DrawTranslatedString(languageNames[i], MENU_MAIN_TEXT_X, MENU_MAIN_TEXT_Y_START + (i - displayIndex)*MENU_LINE_HEIGHT, fontSimsun, LCD_DRAW_SET, FL_ALIGN_LEFT);
}
else
{
FL_DrawTranslatedString(languageNames[i], MENU_MAIN_TEXT_X, MENU_MAIN_TEXT_Y_START + (i - displayIndex)*MENU_LINE_HEIGHT, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
}
//checkBoxes
if(SYS_GetLanguage() == i) //language enum matches index
{
GL_DrawMonoBitmap(box_checked, MENU_MAIN_STATUS_X, MENU_MAIN_TEXT_Y_START +2+ (i - displayIndex)*MENU_LINE_HEIGHT, LCD_DRAW_SET);
}
else
{
GL_DrawMonoBitmap(box_unchecked, MENU_MAIN_STATUS_X, MENU_MAIN_TEXT_Y_START +2+ (i - displayIndex)*MENU_LINE_HEIGHT, LCD_DRAW_SET);
}
}
//Draw selection bar
uint32_t selRectY0 = MENU_MAIN_TEXT_Y_START + (selected - displayIndex)*MENU_LINE_HEIGHT;
GL_DrawFilledRectangle(MENU_SEL_RECT_X0, selRectY0, MENU_SEL_RECT_X1A, selRectY0 + MENU_LINE_HEIGHT, LCD_DRAW_XOR);
DrawMenuScrollBar(displayIndex, LANG_MENU_NUM);
LCD_Update();
}
static void DisplayRegulatoryInfo(void)
{
uint32_t caretX = 35;
uint32_t menuX = 50;
uint32_t menuYStart = 30;
uint32_t yInc = 30;
LCD_Clear();
//Title
FL_DrawTranslatedString("REGULATORY INFO", 240, 0, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_CENTER);
//TODO: Display radio info here (Tx25 ONLY)
LCD_Update();
while(1)
{
//use keys to changes selected
uint32_t pressed = KEY_WaitForKeyPress(KEY_ALL);
if((pressed) == KEY_BACK || ON_OFF_KEY)
{
if(pressed == ON_OFF_KEY)
{
menu.exitToMainScreen = true;
}
return;
}
}
}
/*******************************************************************************
* Public Functions
******************************************************************************/
@@ -1384,180 +654,6 @@ void MENU_Init(void)
}
void MENU_Main(void)
{
static uint32_t selected = 0; //static = menu selection persists - Is this a good thing?
uint32_t menuNum = MAIN_MENU_NUM_TX10;
uint32_t menuExit = 0;
//Draw screen first time
MENU_DisplayMain(selected);
while(1)
{
//use keys to changes selected
uint32_t pressed = KEY_WaitForKeyPress(KEY_ALL);
switch(pressed) //This won't work if multiple keys pressed, but it'll clear them
{
case KEY_BACK:
menuExit = true;
break;
case ON_OFF_KEY:
menu.exitToMainScreen = true;
break;
case KEY_UP:
if(--selected > menuNum)
{
selected = 0;
}
MENU_DisplayMain(selected);
break;
case (KEY_UP << KEY_LONG_PRESS):
do
{
if(--selected > menuNum)
{
selected = 0;
}
MENU_DisplayMain(selected);
Delay_Ticks(MENU_KEY_HOLD_SCROLL_DELAY);
}
while(KEY_GetUpKeyHeld());
break;
case KEY_DOWN:
if(++selected >= menuNum)
{
selected = menuNum - 1;
}
MENU_DisplayMain(selected);
break;
case (KEY_DOWN << KEY_LONG_PRESS):
do
{
if(++selected >= menuNum)
{
selected = menuNum - 1;
}
MENU_DisplayMain(selected);
Delay_Ticks(MENU_KEY_HOLD_SCROLL_DELAY);
}
while(KEY_GetDownKeyHeld());
break;
case KEY_ENTER:
switch(selected)
{
case(0): //System Info Menu
SystemInfoMenu();
break;
case(1): //Frequency menu
FrequenciesMenu();
break;
case(2): //Auto shut down
tmr_ChangeAutoSDTimer();
break;
case(3): //Language menu
LanguageMenu();
break;
case(4): //Link Radio
//LinkRadioMenu();
break;
case(5): //Regulatory
DisplayRegulatoryInfo();
break;
default:
break;
}
if(!menu.exitToMainScreen)
{
MENU_DisplayMain(selected); //Redraw menu after any changes
}
break;
}
if(menuExit || menu.exitToMainScreen)
{
menu.exitToMainScreen = false;
//SYS_SaveSettings();
return;
}
}
}
void MENU_DisplayMain(uint32_t selected)
{
char displayIndex = 0; //index of first menu line to draw
uint32_t menuNum = MAIN_MENU_NUM_TX10;
LCD_Clear();
//Title
//'FL_DrawString("MAIN MENU", 240, 0, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_CENTER);
//Update displayIndex
if(selected >= (displayIndex + MENU_MAX_LINES_DISPLAYED))
{
displayIndex++;
}
else if(selected < displayIndex)
{
displayIndex--;
}
//Draw menu items
for(uint32_t i = displayIndex; i < displayIndex + menuNum; i++) //this can draw extra lines off the screen but we don't care
{
//Menu strings
FL_DrawTranslatedString(mainMenu[i].text, MENU_MAIN_TEXT_X, MENU_MAIN_TEXT_Y_START + (i-displayIndex)*MENU_LINE_HEIGHT, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
//Draw item status
switch(i)
{
case(0): //System Info screen
GL_DrawMonoBitmap(menuMore, MENU_MAIN_STATUS_X, MENU_MAIN_TEXT_Y_START + (i-displayIndex)*MENU_LINE_HEIGHT + MENU_MAIN_STATUS_Y_OFF, LCD_DRAW_SET);
break;
case(1): //Frequency
GL_DrawMonoBitmap(menuMore, MENU_MAIN_STATUS_X, MENU_MAIN_TEXT_Y_START + (i-displayIndex)*MENU_LINE_HEIGHT + MENU_MAIN_STATUS_Y_OFF, LCD_DRAW_SET);
break;
case(2): //Auto Shutdown
FL_DrawTranslatedString(tmr_GetAutoSDTimerString(), MENU_MAIN_STATUS_X, MENU_MAIN_TEXT_Y_START + (i - displayIndex)*MENU_LINE_HEIGHT, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
break;
case(3): //Language
GL_DrawMonoBitmap(menuMore, MENU_MAIN_STATUS_X, MENU_MAIN_TEXT_Y_START + (i-displayIndex)*MENU_LINE_HEIGHT + MENU_MAIN_STATUS_Y_OFF, LCD_DRAW_SET);
break;
case(4): //Link radio
GL_DrawMonoBitmap(menuMore, MENU_MAIN_STATUS_X, MENU_MAIN_TEXT_Y_START + (i-displayIndex)*MENU_LINE_HEIGHT + MENU_MAIN_STATUS_Y_OFF, LCD_DRAW_SET);
break;
case(5): //Regulatory
break;
case(6): //Not used
break;
default:
break;
}
}
//Draw selection bar
uint32_t selRectY0 = MENU_MAIN_TEXT_Y_START + (selected - displayIndex)*MENU_LINE_HEIGHT;
//GL_DrawFilledRoundedRectangle(MENU_SEL_RECT_X0, selRectY0, MENU_SEL_RECT_X1, selRectY0 + MENU_LINE_HEIGHT, MENU_SEL_RECT_RADIUS, LCD_DRAW_XOR);
GL_DrawFilledRectangle(MENU_SEL_RECT_X0, selRectY0, MENU_SEL_RECT_X1, selRectY0 + MENU_LINE_HEIGHT, LCD_DRAW_XOR);
//Draw menu icons
//Use DrawMenuBitmap(mainMenu[i], x, y)
DrawMenuScrollBar(displayIndex, menuNum);
LCD_Update();
}
void Menu_init(void)
{

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);
}

View File

@@ -8,8 +8,15 @@
#ifndef PORTS_H_
#define PORTS_H_
#include "fgen.h"
#include "driver.h"
typedef struct ACCESSORY_s ACCESSORY_t;
typedef int (*AccessoryHandler_t)(ACCESSORY_t *accy);
typedef int (*AccessoryService_t)(ACCESSORY_t *accy);
typedef FREQUENCY_t* (*AccessorySetFrequency_t)(ACCESSORY_t *accy, FREQUENCY_t *freq);
typedef int (*AccessorySetPower_t)(ACCESSORY_t *accy, PowerLevel_t powerLevel);
typedef enum {
ID_BROADCAST = -1,
@@ -30,10 +37,12 @@ typedef enum {
typedef enum
{
PORT_STATE_DEINIT = -1,
PORT_STATE_ERROR = -1,
PORT_STATE_INIT = 0,
PORT_STATE_STANDBY = 1,
PORT_STATE_RUNNING = 2,
PORT_STATE_DEINIT,
PORT_STATE_STANDBY,
PORT_STATE_RUNNING,
} PortState_t;
typedef enum
@@ -57,24 +66,30 @@ typedef struct
bool connected;
} AccessoryChannel_t;
struct ACCESSORY_s {
struct ACCESSORY_s
{
bool isConnected; //Accessory is connected
ACCY_ID_t connected; //Currently connected accessory
ACCY_ID_t lastDetected; //accessory detected last scan
uint32_t consecutiveScans; //number of consecutive scans of same accessory
float *idVoltage;
float *idVoltage;
PortState_t state;
bool initState;
AccessoryHandler_t handler;
AccessoryService_t handler;
AccessoryChannel_t channels[NUM_CHANNELS];
AccyChannelId_t activeChannel;
uint32_t stateTimer;
AccessoryPortId_t portId;
AccessorySetFrequency_t setFrequency;
AccessorySetPower_t setPower;
uint8_t powerLevel;
};
#define DELAY_100MS 10
@@ -111,7 +126,6 @@ void ACCY_Connect1(ACCY_ID_t id);
void ACCY_Connect2(ACCY_ID_t id);
bool ACCY_IsConnected(uint8_t port);
ACCY_ID_t ACCY_GetConnectedAccessory(uint8_t port);
ACCY_ID_t ACCY_GetActive(void);
void Select_Output_Port(void); // Mutually exclusive output port selector
void Enable_BC(void);
void Disable_DC(void);
@@ -129,4 +143,8 @@ void ACCY_service(void);
bool ACCY_Connect(ACCESSORY_t *accy, ACCY_ID_t id);
void ACCY_setActive(ACCESSORY_t *accy, AccyChannelId_t channel);
void ACCY_next(void);
bool ACCY_timedOut(ACCESSORY_t *accy);
void ACCY_setTimeout(ACCESSORY_t *accy, uint32_t msec);
#endif /* PORTS_H_ */

View File

@@ -12,7 +12,6 @@
#include <stdbool.h>
#include <stdint.h>
#include "frq.h"
#include "pwm.h"
#include "ports.h"
#include "arm_math.h"

View File

@@ -40,6 +40,7 @@ uint16_t Power_tmr, Display_warning_tmr;
void System_Check()
{
#if 0
if(freqArray[frequency].frequency1 <= MAX_DTYPE)
{
@@ -89,6 +90,8 @@ void System_Check()
// Update_Amp_Pot();
}
#endif
#endif
}
void Safety_Check(void)
@@ -101,7 +104,7 @@ void Safety_Check(void)
while(1)
{
safe_key();
//safe_key();
Display_Update();
Delay_Ticks(10);
}

View File

@@ -96,8 +96,6 @@ void ctimer_match0_callback(uint32_t flags) // ISR every 1mS
if (Sys_Timer > 0)
Sys_Timer--;
if (frq_chg_tmr > 0)
frq_chg_tmr--;
if (Low_Bat_timer > 0)
Low_Bat_timer--;
@@ -127,8 +125,7 @@ void ctimer_match0_callback(uint32_t flags) // ISR every 1mS
if(ByPass_tmr > 0)
ByPass_tmr--;
if(Display_warning_tmr > 0)
Display_warning_tmr--;
if(sys.adc.measure)

View File

@@ -13,7 +13,6 @@
#include "eeprom.h"
#include "display.h"
#include "utils.h"
#include "frq.h"
#include "psu_ctrl.h"
#include "amps.h"
#include "main.h"
@@ -62,6 +61,7 @@ extern ClampData_t clampData;
uint8_t Error, Suspend_Step_Chk;
uint8_t Check_Output_Status(char Connector)
{
uint32_t x = 1;
@@ -114,6 +114,7 @@ GPIO_PinWrite(GPIO, 0, PORT_LE, 1); // De-select CS
void Select_Bypass(RELAY_SELECT_t bypass) // Bypass allows transmitting w/o full protection
{
#if 0
sys.status[BYPASS] = bypass;
if (bypass)
@@ -127,7 +128,7 @@ void Select_Bypass(RELAY_SELECT_t bypass) // Bypass allows transmitting w/o full
{
EXPANDER_CLEAR(BYPASS_ON, true);
}
#endif
}
@@ -152,7 +153,7 @@ void Select_Estop(ESTOP_SELECT_t stop)
}
void Select_Transformer()
{
#if 0
if (freqArray[frequency].frequency1 > MAX_LOW_FRQ)//ie. > 80K Was MAX_DTYPE
{
Port_State[MID_SR] |= SLCT_XFMR; // Switch to High freq xfrmr Taps O/P
@@ -179,6 +180,7 @@ void Select_Transformer()
// or not
SPI0_SendBytes(Port_State, 3, EXPANDER);
#endif
}
void Select_Amp_Xfrmr_Rly(AMP_XFRMR_SLCT_t Amp2xfrmr) // Allows any combination of Amp and transformer
@@ -219,6 +221,7 @@ void Power_ON_OFF(RELAY_SELECT_t Power)
void Check_Clamp_OverVoltage(void)
{
#if 0
if (Cur_Mode != BROADCAST)
{
@@ -231,6 +234,7 @@ void Check_Clamp_OverVoltage(void)
}
}
}
#endif
}
void Check_Live_Voltage()
{
@@ -276,6 +280,7 @@ bool Compare_Voltage(float32_t source, float32_t limit)
void Check_Over_Current()
{
#if 0
float x;
x = Get_Max_Current();
@@ -291,18 +296,22 @@ float x;
}
}
#endif
}
float Get_Max_Current(void)
{
#if 0
if (freqArray[frequency].frequency1 <= MAX_DTYPE)
return (MAX_CURRENT);
else
return (MAX_HF_CURRENT);
#endif
}
void Check_Over_Power(void)
{
#if 0
//uint8_t New_Pot_Val;
if (Cur_Mode != BROADCAST)
{
@@ -315,20 +324,23 @@ void Check_Over_Power(void)
}
}
// Delay_Ticks(100);
#endif
}
float32_t Get_Power_Limit(void)
{
#if 0
if (freqArray[frequency].frequency1 < MAX_DTYPE)
return(sys.maxPowerLimit);
else
return(1.0);
#endif
}
// if over power, scale amplitude
void Adjust_Output_Power(float32_t New_Power_Limit)
{
#if 0
if (Watts_Filt > New_Power_Limit)
{
uint8_t New_Pot_Val;
@@ -345,6 +357,7 @@ void Adjust_Output_Power(float32_t New_Power_Limit)
}
else
Suspend_Step_Chk = false;
#endif
}
@@ -468,6 +481,7 @@ void Count_Down_PWR_OFF(void) //Display_Bat_Error();
void Adjust_Clamp_Volts(void) // Set clamp output voltages to PL1
{
#if 0
if (freqArray[frequency].frequency1 <= MAX_DTYPE)
{
Dds_Pot_Val[1] = Pot_Value_CLAMP1[1]; // data
@@ -481,10 +495,12 @@ void Adjust_Clamp_Volts(void) // Set clamp output voltages to PL1
Dds_Pot_Val[0] = 0; // address
SPI0_SendBytes(Dds_Pot_Val, 2, AMPLITUDE);
#endif
}
void Check_Over_Voltage(void) // Check Direct Connect Over voltage
{
#if 0
uint8_t New_Pot_Val;
uint8_t test1;
if (Over_Voltage_tmr == 0)
@@ -513,10 +529,12 @@ void Check_Over_Voltage(void) // Check Direct Connect Over voltage
}
}
}
#endif
}
void Controlled_Pwr_Dwn()
{
#if 0
uint8_t count;
uint8_t avalue; // for debugging only
@@ -549,10 +567,12 @@ void Controlled_Pwr_Dwn()
Set_PSU_Voltage(V_18V); // switch off main psu down
Delay_Ticks(DELAY_250MS);
#endif
}
void Update_Amp_Pot(void)
{
#if 0
uint8_t avalue; // for debugging only
Dds_Pot_Val[0] = 0; // address
@@ -563,11 +583,12 @@ void Update_Amp_Pot(void)
avalue = Dds_Pot_Val[1];
SPI0_SendBytes(Dds_Pot_Val, 2, AMPLITUDE);
#endif
}
void Check_For_Clamp_On_Pwr_Up(void)
{
#if 0
uint32_t idNumber1 = (uint32_t) ((sys.adc.V_ID2 * 3.3333) + 0.5);//multiply by 3.3333 and round to nearest integer
uint32_t idNumber2 = (uint32_t) ((sys.adc.V_ID1 * 3.3333) + 0.5);//multiply by 3.3333 and round to nearest integer
@@ -590,6 +611,7 @@ void Check_For_Clamp_On_Pwr_Up(void)
}
}
}
#endif
}
bool Check_For_Clamp_New()
@@ -701,6 +723,7 @@ bool Check_For_Clamp(void) // Assumes BROADCAST already checked for
void freq_key_process(void)
{
#if 0
uint32_t tmp_frqx;
LD_Flag = false;
@@ -738,10 +761,12 @@ void freq_key_process(void)
}
}
}
#endif
}
void LD_key_process(void)
{
#if 0
if(freqArray[frequency].frequency1 <= MAX_LD_FREQ && Cur_Mode != BROADCAST)
{
LD_Flag ^= 1;
@@ -751,6 +776,7 @@ void LD_key_process(void)
else
Init_LD_Sync(); // clear the second freq
}
#endif
}
@@ -806,4 +832,4 @@ void Umag_Patch(void)
void delayms(uint32_t msec)
{
stimer_delay(msec);
}
}