Speed improvements

This commit is contained in:
Jan Käberich 2020-10-03 21:56:09 +02:00
parent 5e00b2a7f8
commit 6bc6b1d202
18 changed files with 130 additions and 108 deletions

View File

@ -8,7 +8,7 @@ using namespace std;
Calibration::Calibration() Calibration::Calibration()
{ {
// Creator vectors for measurements // Create vectors for measurements
measurements[Measurement::Port1Open].datapoints = vector<Protocol::Datapoint>(); measurements[Measurement::Port1Open].datapoints = vector<Protocol::Datapoint>();
measurements[Measurement::Port1Short].datapoints = vector<Protocol::Datapoint>(); measurements[Measurement::Port1Short].datapoints = vector<Protocol::Datapoint>();
measurements[Measurement::Port1Load].datapoints = vector<Protocol::Datapoint>(); measurements[Measurement::Port1Load].datapoints = vector<Protocol::Datapoint>();
@ -80,7 +80,6 @@ void Calibration::construct12TermPoints()
requiredMeasurements.push_back(Measurement::Isolation); requiredMeasurements.push_back(Measurement::Isolation);
bool isolation_measured = SanityCheckSamples(requiredMeasurements); bool isolation_measured = SanityCheckSamples(requiredMeasurements);
// If we get here the calibration measurements are all okay
points.clear(); points.clear();
for(unsigned int i = 0;i<measurements[Measurement::Port1Open].datapoints.size();i++) { for(unsigned int i = 0;i<measurements[Measurement::Port1Open].datapoints.size();i++) {
Point p; Point p;
@ -334,7 +333,6 @@ void Calibration::constructTRL()
auto c = a / a_over_c; auto c = a / a_over_c;
auto Box_A = Tparam<complex<double>>(r22 * a, r22 * b, r22 * c, r22); auto Box_A = Tparam<complex<double>>(r22 * a, r22 * b, r22 * c, r22);
auto Box_B = Tparam<complex<double>>(rho22 * alpha, rho22 * beta, rho22 * gamma, rho22); auto Box_B = Tparam<complex<double>>(rho22 * alpha, rho22 * beta, rho22 * gamma, rho22);
// e00 is S11_A, S11 = T12/T22 = r22*a/r22
complex<double> dummy1, dummy2; complex<double> dummy1, dummy2;
Box_A.toSparam(p.fe00, dummy1, p.fe10e01, p.fe11); Box_A.toSparam(p.fe00, dummy1, p.fe10e01, p.fe11);
Box_B.toSparam(p.fe22, p.fe10e32, dummy1, dummy2); Box_B.toSparam(p.fe22, p.fe10e32, dummy1, dummy2);

View File

@ -29,7 +29,7 @@
<storageModule moduleId="cdtBuildSystem" version="4.0.0"> <storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactExtension="elf" artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" id="fr.ac6.managedbuild.config.gnu.cross.exe.debug.1502405410" name="Debug" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=" parent="fr.ac6.managedbuild.config.gnu.cross.exe.debug" postannouncebuildStep="Generating hex and Printing size information:" postbuildStep="arm-none-eabi-objcopy -O binary &quot;${BuildArtifactFileBaseName}.elf&quot; &quot;${BuildArtifactFileBaseName}.bin&quot; &amp;&amp; arm-none-eabi-objcopy -O ihex &quot;${BuildArtifactFileBaseName}.elf&quot; &quot;${BuildArtifactFileBaseName}.hex&quot; &amp;&amp; arm-none-eabi-size &quot;${BuildArtifactFileName}&quot;"> <configuration artifactExtension="elf" artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" errorParsers="org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GCCErrorParser" id="fr.ac6.managedbuild.config.gnu.cross.exe.debug.1502405410" name="Debug" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.enablement=null,org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.image=null,org.eclipse.cdt.docker.launcher.containerbuild.property.connection=null" parent="fr.ac6.managedbuild.config.gnu.cross.exe.debug" postannouncebuildStep="Generating hex and Printing size information:" postbuildStep="arm-none-eabi-objcopy -O binary &quot;${BuildArtifactFileBaseName}.elf&quot; &quot;${BuildArtifactFileBaseName}.bin&quot; &amp;&amp; arm-none-eabi-objcopy -O ihex &quot;${BuildArtifactFileBaseName}.elf&quot; &quot;${BuildArtifactFileBaseName}.hex&quot; &amp;&amp; arm-none-eabi-size &quot;${BuildArtifactFileName}&quot;">
<folderInfo id="fr.ac6.managedbuild.config.gnu.cross.exe.debug.1502405410." name="/" resourcePath=""> <folderInfo id="fr.ac6.managedbuild.config.gnu.cross.exe.debug.1502405410." name="/" resourcePath="">

View File

@ -25,7 +25,7 @@
static Protocol::Datapoint result; static Protocol::Datapoint result;
static Protocol::SweepSettings settings; static Protocol::SweepSettings settings;
static Protocol::PacketInfo packet; static Protocol::PacketInfo recv_packet, transmit_packet;
static TaskHandle_t handle; static TaskHandle_t handle;
#if HW_REVISION >= 'B' #if HW_REVISION >= 'B'
@ -41,14 +41,17 @@ extern ADC_HandleTypeDef hadc1;
#define FLAG_USB_PACKET 0x01 #define FLAG_USB_PACKET 0x01
#define FLAG_DATAPOINT 0x02 #define FLAG_DATAPOINT 0x02
static void VNACallback(Protocol::Datapoint res) { static void VNACallback(const Protocol::Datapoint &res) {
result = res; DEBUG2_HIGH();
transmit_packet.type = Protocol::PacketType::Datapoint;
transmit_packet.datapoint = res;
BaseType_t woken = false; BaseType_t woken = false;
xTaskNotifyFromISR(handle, FLAG_DATAPOINT, eSetBits, &woken); xTaskNotifyFromISR(handle, FLAG_DATAPOINT, eSetBits, &woken);
portYIELD_FROM_ISR(woken); portYIELD_FROM_ISR(woken);
DEBUG2_LOW();
} }
static void USBPacketReceived(Protocol::PacketInfo p) { static void USBPacketReceived(const Protocol::PacketInfo &p) {
packet = p; recv_packet = p;
BaseType_t woken = false; BaseType_t woken = false;
xTaskNotifyFromISR(handle, FLAG_USB_PACKET, eSetBits, &woken); xTaskNotifyFromISR(handle, FLAG_USB_PACKET, eSetBits, &woken);
portYIELD_FROM_ISR(woken); portYIELD_FROM_ISR(woken);
@ -114,28 +117,25 @@ void App_Start() {
if(xTaskNotifyWait(0x00, UINT32_MAX, &notification, 100) == pdPASS) { if(xTaskNotifyWait(0x00, UINT32_MAX, &notification, 100) == pdPASS) {
// something happened // something happened
if(notification & FLAG_DATAPOINT) { if(notification & FLAG_DATAPOINT) {
Protocol::PacketInfo packet; Communication::Send(transmit_packet);
packet.type = Protocol::PacketType::Datapoint;
packet.datapoint = result;
Communication::Send(packet);
lastNewPoint = HAL_GetTick(); lastNewPoint = HAL_GetTick();
} }
if(notification & FLAG_USB_PACKET) { if(notification & FLAG_USB_PACKET) {
switch(packet.type) { switch(recv_packet.type) {
case Protocol::PacketType::SweepSettings: case Protocol::PacketType::SweepSettings:
LOG_INFO("New settings received"); LOG_INFO("New settings received");
settings = packet.settings; settings = recv_packet.settings;
sweepActive = VNA::Setup(settings, VNACallback); sweepActive = VNA::Setup(settings, VNACallback);
lastNewPoint = HAL_GetTick(); lastNewPoint = HAL_GetTick();
Communication::SendWithoutPayload(Protocol::PacketType::Ack); Communication::SendWithoutPayload(Protocol::PacketType::Ack);
break; break;
case Protocol::PacketType::ManualControl: case Protocol::PacketType::ManualControl:
sweepActive = false; sweepActive = false;
Manual::Setup(packet.manual); Manual::Setup(recv_packet.manual);
Communication::SendWithoutPayload(Protocol::PacketType::Ack); Communication::SendWithoutPayload(Protocol::PacketType::Ack);
break; break;
case Protocol::PacketType::Reference: case Protocol::PacketType::Reference:
HW::Ref::set(packet.reference); HW::Ref::set(recv_packet.reference);
if(!sweepActive) { if(!sweepActive) {
// can update right now // can update right now
HW::Ref::update(); HW::Ref::update();
@ -145,13 +145,13 @@ void App_Start() {
case Protocol::PacketType::Generator: case Protocol::PacketType::Generator:
sweepActive = false; sweepActive = false;
LOG_INFO("Updating generator setting"); LOG_INFO("Updating generator setting");
Generator::Setup(packet.generator); Generator::Setup(recv_packet.generator);
Communication::SendWithoutPayload(Protocol::PacketType::Ack); Communication::SendWithoutPayload(Protocol::PacketType::Ack);
break; break;
case Protocol::PacketType::SpectrumAnalyzerSettings: case Protocol::PacketType::SpectrumAnalyzerSettings:
sweepActive = false; sweepActive = false;
LOG_INFO("Updating spectrum analyzer settings"); LOG_INFO("Updating spectrum analyzer settings");
SA::Setup(packet.spectrumSettings); SA::Setup(recv_packet.spectrumSettings);
Communication::SendWithoutPayload(Protocol::PacketType::Ack); Communication::SendWithoutPayload(Protocol::PacketType::Ack);
break; break;
case Protocol::PacketType::RequestDeviceLimits: case Protocol::PacketType::RequestDeviceLimits:
@ -174,8 +174,8 @@ void App_Start() {
} }
break; break;
case Protocol::PacketType::FirmwarePacket: case Protocol::PacketType::FirmwarePacket:
LOG_INFO("Writing firmware packet at address %u", packet.firmware.address); LOG_INFO("Writing firmware packet at address %u", recv_packet.firmware.address);
if(flash.write(packet.firmware.address, sizeof(packet.firmware.data), packet.firmware.data)) { if(flash.write(recv_packet.firmware.address, sizeof(recv_packet.firmware.data), recv_packet.firmware.data)) {
Communication::SendWithoutPayload(Protocol::PacketType::Ack); Communication::SendWithoutPayload(Protocol::PacketType::Ack);
} else { } else {
LOG_ERR("Failed to write FLASH"); LOG_ERR("Failed to write FLASH");

View File

@ -42,10 +42,12 @@ void Communication::Input(const uint8_t *buf, uint16_t len) {
} }
} while (handled_len > 0); } while (handled_len > 0);
} }
#include "Hardware.hpp"
bool Communication::Send(Protocol::PacketInfo packet) { bool Communication::Send(const Protocol::PacketInfo &packet) {
// DEBUG1_HIGH();
uint16_t len = Protocol::EncodePacket(packet, outputBuffer, uint16_t len = Protocol::EncodePacket(packet, outputBuffer,
sizeof(outputBuffer)); sizeof(outputBuffer));
// DEBUG1_LOW();
return usb_transmit(outputBuffer, len); return usb_transmit(outputBuffer, len);
// if (hUsbDeviceFS.dev_state == USBD_STATE_CONFIGURED) { // if (hUsbDeviceFS.dev_state == USBD_STATE_CONFIGURED) {
// uint16_t len = Protocol::EncodePacket(packet, outputBuffer, // uint16_t len = Protocol::EncodePacket(packet, outputBuffer,

View File

@ -8,11 +8,11 @@
namespace Communication { namespace Communication {
using Callback = void(*)(Protocol::PacketInfo); using Callback = void(*)(const Protocol::PacketInfo&);
void SetCallback(Callback cb); void SetCallback(Callback cb);
void Input(const uint8_t *buf, uint16_t len); void Input(const uint8_t *buf, uint16_t len);
bool Send(Protocol::PacketInfo packet); bool Send(const Protocol::PacketInfo &packet);
bool SendWithoutPayload(Protocol::PacketType type); bool SendWithoutPayload(Protocol::PacketType type);
} }

View File

@ -152,18 +152,26 @@ static Protocol::Datapoint DecodeDatapoint(uint8_t *buf) {
} }
static int16_t EncodeDatapoint(Protocol::Datapoint d, uint8_t *buf, static int16_t EncodeDatapoint(Protocol::Datapoint d, uint8_t *buf,
uint16_t bufSize) { uint16_t bufSize) {
Encoder e(buf, bufSize); // Special case, bypassing the encoder for speed optimizations.
e.add<float>(d.real_S11); // The datapoint is only ever encoded on the device and the
e.add<float>(d.imag_S11); // Protocol::Datapoint struct is setup without any padding between
e.add<float>(d.real_S21); // the variables. In this case it is allowed to simply copy its
e.add<float>(d.imag_S21); // content into the buffer. Compared to using the encoder, this
e.add<float>(d.real_S12); // saves approximately 40us for each datapoint
e.add<float>(d.imag_S12); memcpy(buf, &d, sizeof(d));
e.add<float>(d.real_S22); return sizeof(d);
e.add<float>(d.imag_S22); // Encoder e(buf, bufSize);
e.add<uint64_t>(d.frequency); // e.add<float>(d.real_S11);
e.add<uint16_t>(d.pointNum); // e.add<float>(d.imag_S11);
return e.getSize(); // e.add<float>(d.real_S21);
// e.add<float>(d.imag_S21);
// e.add<float>(d.real_S12);
// e.add<float>(d.imag_S12);
// e.add<float>(d.real_S22);
// e.add<float>(d.imag_S22);
// e.add<uint64_t>(d.frequency);
// e.add<uint16_t>(d.pointNum);
// return e.getSize();
} }
static Protocol::SweepSettings DecodeSweepSettings(uint8_t *buf) { static Protocol::SweepSettings DecodeSweepSettings(uint8_t *buf) {
@ -484,15 +492,25 @@ uint16_t Protocol::DecodeBuffer(uint8_t *buf, uint16_t len, PacketInfo *info) {
return data - buf; return data - buf;
} }
/* The complete frame has been received, check checksum */ // /* The complete frame has been received, check checksum */
uint32_t crc = *(uint32_t*) &data[length - 4]; // auto type = (PacketType) data[3];
uint32_t compare = CRC32(0, data, length - 4); // uint32_t crc = *(uint32_t*) &data[length - 4];
if(crc != compare) { // if(type != PacketType::Datapoint) {
// CRC mismatch, remove header // uint32_t compare = CRC32(0, data, length - 4);
data += 1; // if(crc != compare) {
info->type = PacketType::None; // // CRC mismatch, remove header
return data - buf; // data += 1;
} // info->type = PacketType::None;
// return data - buf;
// }
// } else {
// // Datapoint has the CRC set to zero
// if(crc != 0x00000000) {
// data += 1;
// info->type = PacketType::None;
// return data - buf;
// }
// }
// Valid packet, extract packet info // Valid packet, extract packet info
info->type = (PacketType) data[3]; info->type = (PacketType) data[3];
@ -544,7 +562,7 @@ uint16_t Protocol::DecodeBuffer(uint8_t *buf, uint16_t len, PacketInfo *info) {
return data - buf + length; return data - buf + length;
} }
uint16_t Protocol::EncodePacket(PacketInfo packet, uint8_t *dest, uint16_t destsize) { uint16_t Protocol::EncodePacket(const PacketInfo &packet, uint8_t *dest, uint16_t destsize) {
int16_t payload_size = 0; int16_t payload_size = 0;
switch (packet.type) { switch (packet.type) {
case PacketType::Datapoint: case PacketType::Datapoint:
@ -600,7 +618,14 @@ uint16_t Protocol::EncodePacket(PacketInfo packet, uint8_t *dest, uint16_t dests
memcpy(&dest[1], &overall_size, 2); memcpy(&dest[1], &overall_size, 2);
dest[3] = (int) packet.type; dest[3] = (int) packet.type;
// Calculate checksum // Calculate checksum
uint32_t crc = CRC32(0, dest, overall_size - 4); uint32_t crc = 0x00000000;
if(packet.type == PacketType::Datapoint) {
// CRC calculation takes about 18us which is the bulk of the time required to encode and transmit a datapoint.
// Skip CRC for data points to optimize throughput
crc = 0x00000000;
} else {
crc = CRC32(0, dest, overall_size - 4);
}
memcpy(&dest[overall_size - 4], &crc, 4); memcpy(&dest[overall_size - 4], &crc, 4);
return overall_size; return overall_size;
} }

View File

@ -173,6 +173,6 @@ using PacketInfo = struct _packetinfo {
uint32_t CRC32(uint32_t crc, const void *data, uint32_t len); uint32_t CRC32(uint32_t crc, const void *data, uint32_t len);
uint16_t DecodeBuffer(uint8_t *buf, uint16_t len, PacketInfo *info); uint16_t DecodeBuffer(uint8_t *buf, uint16_t len, PacketInfo *info);
uint16_t EncodePacket(PacketInfo packet, uint8_t *dest, uint16_t destsize); uint16_t EncodePacket(const PacketInfo &packet, uint8_t *dest, uint16_t destsize);
} }

View File

@ -237,9 +237,7 @@ static inline int64_t sign_extend_64(int64_t x, uint16_t bits) {
} }
static FPGA::ReadCallback callback; static FPGA::ReadCallback callback;
static uint8_t raw[36]; static uint8_t raw[38];
static bool halted;
static bool new_sample;
static FPGA::SamplingResult result; static FPGA::SamplingResult result;
static bool busy_reading = false; static bool busy_reading = false;
@ -249,38 +247,11 @@ bool FPGA::InitiateSampleRead(ReadCallback cb) {
return false; return false;
} }
callback = cb; callback = cb;
uint8_t cmd[2] = {0xC0, 0x00}; uint8_t cmd[38] = {0xC0, 0x00};
uint16_t status;
Low(CS);
HAL_SPI_TransmitReceive(&FPGA_SPI, cmd, (uint8_t*) &status, 2, 100);
SwitchBytes(status);
if (status & 0x0010) {
halted = true;
} else {
halted = false;
}
if (!(status & 0x0004)) {
// no new data available yet
High(CS);
if (halted) {
if (halted && halted_cb) {
halted_cb();
halted = false;
}
} else {
LOG_WARN("ISR without new data, status: 0x%04x", status);
}
return false;
}
// Start data read // Start data read
Low(CS);
busy_reading = true; busy_reading = true;
HAL_SPI_Receive_DMA(&FPGA_SPI, raw, 36); HAL_SPI_TransmitReceive_DMA(&FPGA_SPI, cmd, raw, 38);
return true; return true;
} }
@ -292,24 +263,22 @@ static int64_t assembleSampleResultValue(uint8_t *raw) {
} }
extern "C" { extern "C" {
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi) { void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) {
uint16_t status = (uint16_t) raw[0] << 8 | raw[1];
// Assemble data from words // Assemble data from words
result.P1I = assembleSampleResultValue(&raw[30]); result.P1I = assembleSampleResultValue(&raw[32]);
result.P1Q = assembleSampleResultValue(&raw[24]); result.P1Q = assembleSampleResultValue(&raw[26]);
result.P2I = assembleSampleResultValue(&raw[18]); result.P2I = assembleSampleResultValue(&raw[20]);
result.P2Q = assembleSampleResultValue(&raw[12]); result.P2Q = assembleSampleResultValue(&raw[14]);
result.RefI = assembleSampleResultValue(&raw[6]); result.RefI = assembleSampleResultValue(&raw[8]);
result.RefQ = assembleSampleResultValue(&raw[0]); result.RefQ = assembleSampleResultValue(&raw[2]);
High(CS); High(CS);
busy_reading = false; busy_reading = false;
new_sample = true; if ((status & 0x0004) && callback) {
if (new_sample && callback) {
callback(result); callback(result);
new_sample = false;
} }
if (halted && halted_cb) { if ((status & 0x0010) && halted_cb) {
halted_cb(); halted_cb();
halted = false;
} }
} }
} }

View File

@ -110,7 +110,7 @@ void DisableInterrupt(Interrupt i);
void WriteMAX2871Default(uint32_t *DefaultRegs); void WriteMAX2871Default(uint32_t *DefaultRegs);
void WriteSweepConfig(uint16_t pointnum, bool lowband, uint32_t *SourceRegs, uint32_t *LORegs, void WriteSweepConfig(uint16_t pointnum, bool lowband, uint32_t *SourceRegs, uint32_t *LORegs,
uint8_t attenuation, uint64_t frequency, SettlingTime settling, Samples samples, bool halt = false, LowpassFilter filter = LowpassFilter::Auto); uint8_t attenuation, uint64_t frequency, SettlingTime settling, Samples samples, bool halt = false, LowpassFilter filter = LowpassFilter::Auto);
using ReadCallback = void(*)(SamplingResult result); using ReadCallback = void(*)(const SamplingResult &result);
bool InitiateSampleRead(ReadCallback cb); bool InitiateSampleRead(ReadCallback cb);
ADCLimits GetADCLimits(); ADCLimits GetADCLimits();
void ResetADCLimits(); void ResetADCLimits();

View File

@ -19,7 +19,7 @@ static uint8_t *USBD_Class_GetDeviceQualifierDescriptor (uint16_t *length);
static usbd_recv_callback_t cb; static usbd_recv_callback_t cb;
static uint8_t usb_receive_buffer[1024]; static uint8_t usb_receive_buffer[1024];
static uint8_t usb_transmit_fifo[4096]; static uint8_t usb_transmit_fifo[4092];
static uint16_t usb_transmit_read_index = 0; static uint16_t usb_transmit_read_index = 0;
static uint16_t usb_transmit_fifo_level = 0; static uint16_t usb_transmit_fifo_level = 0;
static bool data_transmission_active = false; static bool data_transmission_active = false;
@ -218,10 +218,9 @@ void usb_init(usbd_recv_callback_t receive_callback) {
USBD_Start(&hUsbDeviceFS); USBD_Start(&hUsbDeviceFS);
HAL_NVIC_SetPriority(USB_HP_IRQn, 0, 0); HAL_NVIC_SetPriority(USB_HP_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USB_HP_IRQn); HAL_NVIC_EnableIRQ(USB_HP_IRQn);
HAL_NVIC_SetPriority(USB_LP_IRQn, 7, 0); HAL_NVIC_SetPriority(USB_LP_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(USB_LP_IRQn); HAL_NVIC_EnableIRQ(USB_LP_IRQn);
} }
bool usb_transmit(const uint8_t *data, uint16_t length) { bool usb_transmit(const uint8_t *data, uint16_t length) {
// attempt to add data to fifo // attempt to add data to fifo
if(usb_transmit_fifo_level + length > sizeof(usb_transmit_fifo)) { if(usb_transmit_fifo_level + length > sizeof(usb_transmit_fifo)) {

View File

@ -30,7 +30,7 @@ static void HaltedCallback() {
} }
} }
static void ReadComplete(FPGA::SamplingResult result) { static void ReadComplete(const FPGA::SamplingResult &result) {
bool needs_work = false; bool needs_work = false;
switch(activeMode) { switch(activeMode) {
case HW::Mode::VNA: case HW::Mode::VNA:
@ -71,6 +71,16 @@ void HW::Work() {
} }
bool HW::Init() { bool HW::Init() {
#ifdef USE_DEBUG_PINS
// initialize debug pins
GPIO_InitTypeDef gpio;
gpio.Pin = DEBUG1_PIN;
gpio.Mode = GPIO_MODE_OUTPUT_PP;
gpio.Speed = GPIO_SPEED_HIGH;
HAL_GPIO_Init(DEBUG1_GPIO, &gpio);
gpio.Pin = DEBUG2_PIN;
HAL_GPIO_Init(DEBUG2_GPIO, &gpio);
#endif
LOG_DEBUG("Initializing..."); LOG_DEBUG("Initializing...");
activeMode = Mode::Idle; activeMode = Mode::Idle;

View File

@ -3,6 +3,25 @@
#include <cstdint> #include <cstdint>
#include "Protocol.hpp" #include "Protocol.hpp"
#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
namespace HW { namespace HW {
static constexpr uint32_t ADCSamplerate = 800000; static constexpr uint32_t ADCSamplerate = 800000;

View File

@ -77,7 +77,7 @@ void Manual::Setup(Protocol::ManualControl m) {
FPGA::StartSweep(); FPGA::StartSweep();
} }
bool Manual::MeasurementDone(FPGA::SamplingResult result) { bool Manual::MeasurementDone(const FPGA::SamplingResult &result) {
if(!active) { if(!active) {
return false; return false;
} }

View File

@ -6,7 +6,7 @@
namespace Manual { namespace Manual {
void Setup(Protocol::ManualControl m); void Setup(Protocol::ManualControl m);
bool MeasurementDone(FPGA::SamplingResult result); bool MeasurementDone(const FPGA::SamplingResult &result);
void Work(); void Work();
void Stop(); void Stop();

View File

@ -149,7 +149,7 @@ void SA::Setup(Protocol::SpectrumAnalyzerSettings settings) {
StartNextSample(); StartNextSample();
} }
bool SA::MeasurementDone(FPGA::SamplingResult result) { bool SA::MeasurementDone(const FPGA::SamplingResult &result) {
if(!active) { if(!active) {
return false; return false;
} }

View File

@ -14,7 +14,7 @@ enum class Detector {
}; };
void Setup(Protocol::SpectrumAnalyzerSettings settings); void Setup(Protocol::SpectrumAnalyzerSettings settings);
bool MeasurementDone(FPGA::SamplingResult result); bool MeasurementDone(const FPGA::SamplingResult &result);
void Work(); void Work();
void Stop(); void Stop();

View File

@ -190,7 +190,7 @@ static void PassOnData() {
} }
} }
bool VNA::MeasurementDone(FPGA::SamplingResult result) { bool VNA::MeasurementDone(const FPGA::SamplingResult &result) {
if(!active) { if(!active) {
return false; return false;
} }

View File

@ -6,10 +6,10 @@
namespace VNA { namespace VNA {
using SweepCallback = void(*)(Protocol::Datapoint); using SweepCallback = void(*)(const Protocol::Datapoint&);
bool Setup(Protocol::SweepSettings s, SweepCallback cb); bool Setup(Protocol::SweepSettings s, SweepCallback cb);
bool MeasurementDone(FPGA::SamplingResult result); bool MeasurementDone(const FPGA::SamplingResult &result);
void Work(); void Work();
void SweepHalted(); void SweepHalted();
void Stop(); void Stop();