mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-05 22:45:23 +00:00
Halt sweep when USB buffer full
This commit is contained in:
parent
0f758584bf
commit
51806b936c
3 changed files with 36 additions and 2 deletions
|
|
@ -12,6 +12,7 @@
|
|||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "Util.hpp"
|
||||
#include "usb.h"
|
||||
|
||||
#define LOG_LEVEL LOG_LEVEL_INFO
|
||||
#define LOG_MODULE "VNA"
|
||||
|
|
@ -44,6 +45,10 @@ static_assert(alternativePrescaler * alternativeSamplerate == 102400000UL, "alte
|
|||
static constexpr uint16_t alternativePhaseInc = 4096 * HW::IF2 / alternativeSamplerate;
|
||||
static_assert(alternativePhaseInc * alternativeSamplerate == 4096 * HW::IF2, "DFT can not be computed for 2.IF when using alternative samplerate");
|
||||
|
||||
// Constants for USB buffer overflow prevention
|
||||
static constexpr uint16_t maxPointsBetweenHalts = 40;
|
||||
static constexpr uint32_t reservedUSBbuffer = maxPointsBetweenHalts * (sizeof(Protocol::Datapoint) + 8 /*USB packet overhead*/);
|
||||
|
||||
using namespace HWHAL;
|
||||
|
||||
bool VNA::Setup(Protocol::SweepSettings s) {
|
||||
|
|
@ -106,6 +111,8 @@ bool VNA::Setup(Protocol::SweepSettings s) {
|
|||
// invalidate first entry of IFTable, preventing switing of 2.LO in halted callback
|
||||
IFTable[0].pointCnt = 0xFFFF;
|
||||
|
||||
uint16_t pointsWithoutHalt = 0;
|
||||
|
||||
// Transfer PLL configuration to FPGA
|
||||
for (uint16_t i = 0; i < points; i++) {
|
||||
bool harmonic_mixing = false;
|
||||
|
|
@ -187,6 +194,17 @@ bool VNA::Setup(Protocol::SweepSettings s) {
|
|||
IFdeviation, (uint32_t ) (freq / 1000000), (uint32_t ) (freq % 1000000));
|
||||
}
|
||||
|
||||
// halt on regular intervals to prevent USB buffer overflow
|
||||
if(!needs_halt) {
|
||||
pointsWithoutHalt++;
|
||||
if(pointsWithoutHalt > maxPointsBetweenHalts) {
|
||||
needs_halt = true;
|
||||
}
|
||||
}
|
||||
if(needs_halt) {
|
||||
pointsWithoutHalt = 0;
|
||||
}
|
||||
|
||||
FPGA::WriteSweepConfig(i, lowband, Source.GetRegisters(),
|
||||
LO1.GetRegisters(), attenuator, freq, FPGA::SettlingTime::us20,
|
||||
FPGA::Samples::SPPRegister, needs_halt);
|
||||
|
|
@ -350,7 +368,18 @@ void VNA::SweepHalted() {
|
|||
adcShifted = false;
|
||||
}
|
||||
|
||||
FPGA::ResumeHaltedSweep();
|
||||
if(usb_available_buffer() >= reservedUSBbuffer) {
|
||||
// enough space available, can resume immediately
|
||||
FPGA::ResumeHaltedSweep();
|
||||
} else {
|
||||
// USB buffer could potentially overflow before next halted point, wait until more space is available.
|
||||
// This function is called from a low level interrupt, need to dispatch to lower priority to allow USB
|
||||
// handling to continue
|
||||
STM::DispatchToInterrupt([](){
|
||||
while(usb_available_buffer() < reservedUSBbuffer);
|
||||
FPGA::ResumeHaltedSweep();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void VNA::Stop() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue