2020-09-17 15:53:52 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include "Protocol.hpp"
|
2020-11-07 07:50:59 +08:00
|
|
|
#include "FPGA/FPGA.hpp"
|
2020-11-18 06:03:13 +08:00
|
|
|
#include "AmplitudeCal.hpp"
|
2020-11-19 02:19:29 +08:00
|
|
|
#include "max2871.hpp"
|
|
|
|
#include "Si5351C.hpp"
|
2020-09-17 15:53:52 +08:00
|
|
|
|
2020-10-04 03:56:09 +08:00
|
|
|
#define USE_DEBUG_PINS
|
|
|
|
|
|
|
|
#ifdef USE_DEBUG_PINS
|
|
|
|
#define DEBUG1_GPIO GPIOA
|
|
|
|
#define DEBUG1_PIN GPIO_PIN_13
|
|
|
|
#define DEBUG2_GPIO GPIOA
|
|
|
|
#define DEBUG2_PIN GPIO_PIN_14
|
|
|
|
|
|
|
|
#define DEBUG1_LOW() do {DEBUG1_GPIO->BSRR = DEBUG1_PIN<<16; }while(0)
|
|
|
|
#define DEBUG1_HIGH() do {DEBUG1_GPIO->BSRR = DEBUG1_PIN; }while(0)
|
|
|
|
#define DEBUG2_LOW() do {DEBUG2_GPIO->BSRR = DEBUG2_PIN<<16; }while(0)
|
|
|
|
#define DEBUG2_HIGH() do {DEBUG2_GPIO->BSRR = DEBUG2_PIN; }while(0)
|
|
|
|
#else
|
|
|
|
#define DEBUG1_LOW()
|
|
|
|
#define DEBUG1_HIGH()
|
|
|
|
#define DEBUG2_LOW()
|
|
|
|
#define DEBUG2_HIGH()
|
|
|
|
#endif
|
|
|
|
|
2020-09-17 15:53:52 +08:00
|
|
|
namespace HW {
|
|
|
|
|
2020-09-27 05:34:31 +08:00
|
|
|
static constexpr uint32_t ADCSamplerate = 800000;
|
2020-09-30 05:03:20 +08:00
|
|
|
static constexpr uint32_t IF1 = 62000000;
|
2020-09-17 21:51:20 +08:00
|
|
|
static constexpr uint32_t IF2 = 250000;
|
2020-09-20 16:13:06 +08:00
|
|
|
static constexpr uint32_t LO1_minFreq = 25000000;
|
|
|
|
static constexpr uint32_t MaxSamples = 130944;
|
2020-09-27 05:34:31 +08:00
|
|
|
static constexpr uint32_t MinSamples = 16;
|
2020-09-20 16:13:06 +08:00
|
|
|
static constexpr uint32_t PLLRef = 100000000;
|
2020-11-19 02:19:29 +08:00
|
|
|
static constexpr uint32_t BandSwitchFrequency = 25000000;
|
2020-09-27 05:34:31 +08:00
|
|
|
|
2020-11-07 07:50:59 +08:00
|
|
|
static constexpr uint8_t ADCprescaler = FPGA::Clockrate / ADCSamplerate;
|
|
|
|
static_assert(ADCprescaler * ADCSamplerate == FPGA::Clockrate, "ADCSamplerate can not be reached exactly");
|
2020-10-31 02:23:34 +08:00
|
|
|
static constexpr uint16_t DFTphaseInc = 4096 * IF2 / ADCSamplerate;
|
|
|
|
static_assert(DFTphaseInc * ADCSamplerate == 4096 * IF2, "DFT can not be computed for 2.IF");
|
|
|
|
|
2020-11-18 06:03:13 +08:00
|
|
|
// approximate output power at low frequencies with different source strength settings (attenuator = 0) in cdbm
|
|
|
|
static constexpr int16_t LowBandMinPower = -1350;
|
|
|
|
static constexpr int16_t LowBandMaxPower = -190;
|
|
|
|
static constexpr int16_t HighBandMinPower = -1060;
|
|
|
|
static constexpr int16_t HighBandMaxPower = -160;
|
|
|
|
|
2020-11-07 20:22:10 +08:00
|
|
|
static constexpr Protocol::DeviceInfo Info = {
|
|
|
|
.ProtocolVersion = Protocol::Version,
|
|
|
|
.FW_major = FW_MAJOR,
|
|
|
|
.FW_minor = FW_MINOR,
|
|
|
|
.FW_patch = FW_PATCH,
|
|
|
|
.HW_Revision = HW_REVISION,
|
|
|
|
.extRefAvailable = 0,
|
|
|
|
.extRefInUse = 0,
|
|
|
|
.FPGA_configured = 0,
|
|
|
|
.source_locked = 0,
|
|
|
|
.LO1_locked = 0,
|
|
|
|
.ADC_overload = 0,
|
2021-02-12 05:49:47 +08:00
|
|
|
.unlevel = 0,
|
2020-11-07 20:22:10 +08:00
|
|
|
.temp_source = 0,
|
|
|
|
.temp_LO1 = 0,
|
|
|
|
.temp_MCU = 0,
|
|
|
|
.limits_minFreq = 0,
|
|
|
|
.limits_maxFreq = 6000000000,
|
|
|
|
.limits_minIFBW = ADCSamplerate / MaxSamples,
|
|
|
|
.limits_maxIFBW = ADCSamplerate / MinSamples,
|
|
|
|
.limits_maxPoints = FPGA::MaxPoints,
|
|
|
|
.limits_cdbm_min = -4000,
|
|
|
|
.limits_cdbm_max = 0,
|
|
|
|
.limits_minRBW = (uint32_t) (ADCSamplerate * 2.23f / MaxSamples),
|
|
|
|
.limits_maxRBW = (uint32_t) (ADCSamplerate * 2.23f / MinSamples),
|
2020-11-18 06:03:13 +08:00
|
|
|
.limits_maxAmplitudePoints = AmplitudeCal::maxPoints,
|
2020-12-18 22:03:01 +08:00
|
|
|
.limits_maxFreqHarmonic = 18000000000,
|
2020-09-27 05:34:31 +08:00
|
|
|
};
|
2020-09-17 21:51:20 +08:00
|
|
|
|
2020-09-17 15:53:52 +08:00
|
|
|
enum class Mode {
|
|
|
|
Idle,
|
|
|
|
Manual,
|
|
|
|
VNA,
|
|
|
|
SA,
|
|
|
|
};
|
|
|
|
|
2020-09-27 17:49:30 +08:00
|
|
|
bool Init();
|
2020-09-17 15:53:52 +08:00
|
|
|
void SetMode(Mode mode);
|
|
|
|
void SetIdle();
|
2020-09-17 21:51:20 +08:00
|
|
|
void Work();
|
2020-12-16 01:03:29 +08:00
|
|
|
bool TimedOut();
|
2020-09-17 15:53:52 +08:00
|
|
|
|
2021-02-12 05:49:47 +08:00
|
|
|
void SetOutputUnlevel(bool unlev);
|
|
|
|
|
2020-11-19 02:19:29 +08:00
|
|
|
using AmplitudeSettings = struct _amplitudeSettings {
|
|
|
|
uint8_t attenuator;
|
|
|
|
union {
|
|
|
|
MAX2871::Power highBandPower;
|
|
|
|
Si5351C::DriveStrength lowBandPower;
|
|
|
|
};
|
|
|
|
bool unlevel;
|
|
|
|
};
|
|
|
|
AmplitudeSettings GetAmplitudeSettings(int16_t cdbm, uint64_t freq = 0, bool applyCorrections = false, bool port2 = false);
|
|
|
|
|
2020-09-17 15:53:52 +08:00
|
|
|
bool GetTemps(uint8_t *source, uint8_t *lo);
|
2020-11-07 20:22:10 +08:00
|
|
|
void fillDeviceInfo(Protocol::DeviceInfo *info, bool updateEvenWhenBusy = false);
|
2020-09-17 15:53:52 +08:00
|
|
|
namespace Ref {
|
|
|
|
bool available();
|
|
|
|
// reference won't change until update is called
|
|
|
|
void set(Protocol::ReferenceSettings s);
|
|
|
|
void update();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|