Timeout handling in FPGA communication (better recovery from missing reference)
This commit is contained in:
parent
f0c5962878
commit
00f0de43f2
@ -266,8 +266,7 @@ bool Device::SetManual(Protocol::ManualControl manual)
|
|||||||
|
|
||||||
bool Device::SetIdle()
|
bool Device::SetIdle()
|
||||||
{
|
{
|
||||||
Protocol::SweepSettings s = {};
|
return SendCommandWithoutPayload(Protocol::PacketType::SetIdle);
|
||||||
return Configure(s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::SendFirmwareChunk(Protocol::FirmwarePacket &fw)
|
bool Device::SendFirmwareChunk(Protocol::FirmwarePacket &fw)
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
|
||||||
static Protocol::PacketInfo recv_packet;
|
static Protocol::PacketInfo recv_packet;
|
||||||
|
static Protocol::PacketInfo last_measure_packet; // contains the command that started the last measured (replay in case of timeout)
|
||||||
static TaskHandle_t handle;
|
static TaskHandle_t handle;
|
||||||
|
|
||||||
#if HW_REVISION >= 'B'
|
#if HW_REVISION >= 'B'
|
||||||
@ -108,11 +109,13 @@ void App_Start() {
|
|||||||
switch(recv_packet.type) {
|
switch(recv_packet.type) {
|
||||||
case Protocol::PacketType::SweepSettings:
|
case Protocol::PacketType::SweepSettings:
|
||||||
LOG_INFO("New settings received");
|
LOG_INFO("New settings received");
|
||||||
|
last_measure_packet = recv_packet;
|
||||||
sweepActive = VNA::Setup(recv_packet.settings);
|
sweepActive = VNA::Setup(recv_packet.settings);
|
||||||
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
|
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
|
||||||
break;
|
break;
|
||||||
case Protocol::PacketType::ManualControl:
|
case Protocol::PacketType::ManualControl:
|
||||||
sweepActive = false;
|
sweepActive = false;
|
||||||
|
last_measure_packet = recv_packet;
|
||||||
Manual::Setup(recv_packet.manual);
|
Manual::Setup(recv_packet.manual);
|
||||||
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
|
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
|
||||||
break;
|
break;
|
||||||
@ -125,13 +128,15 @@ void App_Start() {
|
|||||||
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
|
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
|
||||||
break;
|
break;
|
||||||
case Protocol::PacketType::Generator:
|
case Protocol::PacketType::Generator:
|
||||||
sweepActive = false;
|
sweepActive = true;
|
||||||
|
last_measure_packet = recv_packet;
|
||||||
LOG_INFO("Updating generator setting");
|
LOG_INFO("Updating generator setting");
|
||||||
Generator::Setup(recv_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 = true;
|
||||||
|
last_measure_packet = recv_packet;
|
||||||
LOG_INFO("Updating spectrum analyzer settings");
|
LOG_INFO("Updating spectrum analyzer settings");
|
||||||
SA::Setup(recv_packet.spectrumSettings);
|
SA::Setup(recv_packet.spectrumSettings);
|
||||||
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
|
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
|
||||||
@ -142,6 +147,11 @@ void App_Start() {
|
|||||||
HW::fillDeviceInfo(&p.info);
|
HW::fillDeviceInfo(&p.info);
|
||||||
Communication::Send(p);
|
Communication::Send(p);
|
||||||
break;
|
break;
|
||||||
|
case Protocol::PacketType::SetIdle:
|
||||||
|
HW::SetMode(HW::Mode::Idle);
|
||||||
|
sweepActive = false;
|
||||||
|
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
|
||||||
|
break;
|
||||||
#ifdef HAS_FLASH
|
#ifdef HAS_FLASH
|
||||||
case Protocol::PacketType::ClearFlash:
|
case Protocol::PacketType::ClearFlash:
|
||||||
HW::SetMode(HW::Mode::Idle);
|
HW::SetMode(HW::Mode::Idle);
|
||||||
@ -197,5 +207,10 @@ void App_Start() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(HW::TimedOut()) {
|
||||||
|
HW::SetMode(HW::Mode::Idle);
|
||||||
|
// insert the last received packet (restarts the timed out operation)
|
||||||
|
USBPacketReceived(last_measure_packet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -590,6 +590,7 @@ uint16_t Protocol::DecodeBuffer(uint8_t *buf, uint16_t len, PacketInfo *info) {
|
|||||||
case PacketType::RequestDeviceInfo:
|
case PacketType::RequestDeviceInfo:
|
||||||
case PacketType::RequestReceiverCal:
|
case PacketType::RequestReceiverCal:
|
||||||
case PacketType::RequestSourceCal:
|
case PacketType::RequestSourceCal:
|
||||||
|
case PacketType::SetIdle:
|
||||||
// no payload, nothing to do
|
// no payload, nothing to do
|
||||||
break;
|
break;
|
||||||
case PacketType::None:
|
case PacketType::None:
|
||||||
@ -643,6 +644,7 @@ uint16_t Protocol::EncodePacket(const PacketInfo &packet, uint8_t *dest, uint16_
|
|||||||
case PacketType::RequestDeviceInfo:
|
case PacketType::RequestDeviceInfo:
|
||||||
case PacketType::RequestSourceCal:
|
case PacketType::RequestSourceCal:
|
||||||
case PacketType::RequestReceiverCal:
|
case PacketType::RequestReceiverCal:
|
||||||
|
case PacketType::SetIdle:
|
||||||
// no payload, nothing to do
|
// no payload, nothing to do
|
||||||
break;
|
break;
|
||||||
case PacketType::None:
|
case PacketType::None:
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
namespace Protocol {
|
namespace Protocol {
|
||||||
|
|
||||||
static constexpr uint16_t Version = 2;
|
static constexpr uint16_t Version = 3;
|
||||||
|
|
||||||
// When changing/adding/removing variables from these structs also adjust the decode/encode functions in Protocol.cpp
|
// When changing/adding/removing variables from these structs also adjust the decode/encode functions in Protocol.cpp
|
||||||
|
|
||||||
@ -171,6 +171,7 @@ enum class PacketType : uint8_t {
|
|||||||
RequestReceiverCal = 17,
|
RequestReceiverCal = 17,
|
||||||
SourceCalPoint = 18,
|
SourceCalPoint = 18,
|
||||||
ReceiverCalPoint = 19,
|
ReceiverCalPoint = 19,
|
||||||
|
SetIdle = 20,
|
||||||
};
|
};
|
||||||
|
|
||||||
using PacketInfo = struct _packetinfo {
|
using PacketInfo = struct _packetinfo {
|
||||||
|
@ -18,6 +18,7 @@ static bool extRefInUse = false;
|
|||||||
HW::Mode activeMode;
|
HW::Mode activeMode;
|
||||||
|
|
||||||
static Protocol::ReferenceSettings ref;
|
static Protocol::ReferenceSettings ref;
|
||||||
|
static uint32_t lastISR;
|
||||||
|
|
||||||
using namespace HWHAL;
|
using namespace HWHAL;
|
||||||
|
|
||||||
@ -53,6 +54,7 @@ static void ReadComplete(const FPGA::SamplingResult &result) {
|
|||||||
|
|
||||||
static void FPGA_Interrupt(void*) {
|
static void FPGA_Interrupt(void*) {
|
||||||
FPGA::InitiateSampleRead(ReadComplete);
|
FPGA::InitiateSampleRead(ReadComplete);
|
||||||
|
lastISR = HAL_GetTick();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HW::Work() {
|
void HW::Work() {
|
||||||
@ -174,6 +176,8 @@ bool HW::Init() {
|
|||||||
|
|
||||||
LOG_INFO("Initialized");
|
LOG_INFO("Initialized");
|
||||||
FPGA::Enable(FPGA::Periphery::ReadyLED);
|
FPGA::Enable(FPGA::Periphery::ReadyLED);
|
||||||
|
|
||||||
|
Ref::update();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,6 +199,7 @@ void HW::SetMode(Mode mode) {
|
|||||||
if(mode != Mode::Idle) {
|
if(mode != Mode::Idle) {
|
||||||
// do a full initialization when switching directly between modes
|
// do a full initialization when switching directly between modes
|
||||||
HW::Init();
|
HW::Init();
|
||||||
|
lastISR = HAL_GetTick();
|
||||||
}
|
}
|
||||||
SetIdle();
|
SetIdle();
|
||||||
activeMode = mode;
|
activeMode = mode;
|
||||||
@ -269,6 +274,15 @@ HW::AmplitudeSettings HW::GetAmplitudeSettings(int16_t cdbm, uint64_t freq, bool
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool HW::TimedOut() {
|
||||||
|
constexpr uint32_t timeout = 1000;
|
||||||
|
if(activeMode != Mode::Idle && HAL_GetTick() - lastISR > timeout) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void HW::fillDeviceInfo(Protocol::DeviceInfo *info, bool updateEvenWhenBusy) {
|
void HW::fillDeviceInfo(Protocol::DeviceInfo *info, bool updateEvenWhenBusy) {
|
||||||
// copy constant default values
|
// copy constant default values
|
||||||
memcpy(info, &HW::Info, sizeof(HW::Info));
|
memcpy(info, &HW::Info, sizeof(HW::Info));
|
||||||
|
@ -86,6 +86,7 @@ bool Init();
|
|||||||
void SetMode(Mode mode);
|
void SetMode(Mode mode);
|
||||||
void SetIdle();
|
void SetIdle();
|
||||||
void Work();
|
void Work();
|
||||||
|
bool TimedOut();
|
||||||
|
|
||||||
using AmplitudeSettings = struct _amplitudeSettings {
|
using AmplitudeSettings = struct _amplitudeSettings {
|
||||||
uint8_t attenuator;
|
uint8_t attenuator;
|
||||||
|
@ -123,6 +123,19 @@ void Manual::Work() {
|
|||||||
p.status.refmax = limits.Rmax;
|
p.status.refmax = limits.Rmax;
|
||||||
HW::GetTemps(&p.status.temp_source, &p.status.temp_LO);
|
HW::GetTemps(&p.status.temp_source, &p.status.temp_LO);
|
||||||
Communication::Send(p);
|
Communication::Send(p);
|
||||||
|
HW::Ref::update();
|
||||||
|
Protocol::PacketInfo packet;
|
||||||
|
packet.type = Protocol::PacketType::DeviceInfo;
|
||||||
|
// Enable PLL chips for temperature reading
|
||||||
|
bool srcEn = FPGA::IsEnabled(FPGA::Periphery::SourceChip);
|
||||||
|
bool LOEn = FPGA::IsEnabled(FPGA::Periphery::LO1Chip);
|
||||||
|
FPGA::Enable(FPGA::Periphery::SourceChip);
|
||||||
|
FPGA::Enable(FPGA::Periphery::LO1Chip);
|
||||||
|
HW::fillDeviceInfo(&packet.info, true);
|
||||||
|
// restore PLL state
|
||||||
|
FPGA::Enable(FPGA::Periphery::SourceChip, srcEn);
|
||||||
|
FPGA::Enable(FPGA::Periphery::LO1Chip, LOEn);
|
||||||
|
Communication::Send(packet);
|
||||||
// Trigger next status update
|
// Trigger next status update
|
||||||
FPGA::StartSweep();
|
FPGA::StartSweep();
|
||||||
}
|
}
|
||||||
|
@ -373,11 +373,19 @@ void SA::Work() {
|
|||||||
pointCnt += DFTpoints;
|
pointCnt += DFTpoints;
|
||||||
} else {
|
} else {
|
||||||
pointCnt = 0;
|
pointCnt = 0;
|
||||||
|
// sweep finished, extract device info
|
||||||
|
FPGA::Enable(FPGA::Periphery::SourceChip); // needs to enable the chip to get a valid temperature reading
|
||||||
|
Protocol::PacketInfo packet;
|
||||||
|
packet.type = Protocol::PacketType::DeviceInfo;
|
||||||
|
HW::fillDeviceInfo(&packet.info, true);
|
||||||
|
FPGA::Disable(FPGA::Periphery::SourceChip);
|
||||||
|
Communication::Send(packet);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// more measurements required for signal ID
|
// more measurements required for signal ID
|
||||||
signalIDstep++;
|
signalIDstep++;
|
||||||
}
|
}
|
||||||
|
HW::Ref::update();
|
||||||
StartNextSample();
|
StartNextSample();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,10 +259,6 @@ void VNA::Work() {
|
|||||||
// Compile info packet
|
// Compile info packet
|
||||||
Protocol::PacketInfo packet;
|
Protocol::PacketInfo packet;
|
||||||
packet.type = Protocol::PacketType::DeviceInfo;
|
packet.type = Protocol::PacketType::DeviceInfo;
|
||||||
packet.info.FPGA_configured = 1;
|
|
||||||
packet.info.FW_major = FW_MAJOR;
|
|
||||||
packet.info.FW_minor = FW_MINOR;
|
|
||||||
packet.info.HW_Revision = HW_REVISION;
|
|
||||||
HW::fillDeviceInfo(&packet.info, true);
|
HW::fillDeviceInfo(&packet.info, true);
|
||||||
Communication::Send(packet);
|
Communication::Send(packet);
|
||||||
// Start next sweep
|
// Start next sweep
|
||||||
|
Loading…
Reference in New Issue
Block a user