Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scopehal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ set(SCOPEHAL_SOURCES
SParameterFilter.cpp

TestWaveformSource.cpp
TestDigitalWaveformSource.cpp

ComputePipeline.cpp
FilterGraphExecutor.cpp
Expand Down
173 changes: 171 additions & 2 deletions scopehal/DemoOscilloscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ DemoOscilloscope::DemoOscilloscope(SCPITransport* transport)
m_source[i] = new TestWaveformSource(*m_rng[i]);
}

m_digitalSource = new TestDigitalWaveformSource();

m_model = "Oscilloscope Simulator";
m_vendor = "Antikernel Labs";
m_serial = "12345";
Expand Down Expand Up @@ -93,6 +95,22 @@ DemoOscilloscope::DemoOscilloscope(SCPITransport* transport)
m_channelModes[i] = CHANNEL_MODE_NOISE_LPF;
}

char chn[32];
for(size_t i=0; i<16; i++)
{
snprintf(chn, sizeof(chn), "D%zu", i);
auto chan = new OscilloscopeChannel(
this,
chn,
GetDefaultChannelColor(m_channels.size()),
Unit(Unit::UNIT_FS),
Unit(Unit::UNIT_COUNTS),
Stream::STREAM_TYPE_DIGITAL,
m_channels.size());
m_channels.push_back(chan);
m_digitalChannels.push_back(chan);
}

m_sweepFreq = 1e9;

//Default sampling configuration
Expand All @@ -104,6 +122,24 @@ DemoOscilloscope::DemoOscilloscope(SCPITransport* transport)
m_channels[2]->SetDisplayName("PRBS31");
m_channels[3]->SetDisplayName("8B10B");

m_channels[4]->SetDisplayName("SPI-CS");
m_channels[5]->SetDisplayName("SPI-SCLK");
m_channels[6]->SetDisplayName("SPI-MOSI");
m_channels[7]->SetDisplayName("UART-0");
m_channels[8]->SetDisplayName("UART-0-Clk");
m_channels[9]->SetDisplayName("UART-1");
m_channels[10]->SetDisplayName("UART-1-Clk");
m_channels[11]->SetDisplayName("Parallel-Clk");

m_channels[12]->SetDisplayName("Parallel-0");
m_channels[13]->SetDisplayName("Parallel-1");
m_channels[14]->SetDisplayName("Parallel-2");
m_channels[15]->SetDisplayName("Parallel-3");
m_channels[16]->SetDisplayName("Parallel-4");
m_channels[17]->SetDisplayName("Parallel-5");
m_channels[18]->SetDisplayName("Parallel-6");
m_channels[19]->SetDisplayName("Parallel-7");

//Create Vulkan objects for the waveform conversion
for(int i=0; i<4; i++)
{
Expand Down Expand Up @@ -137,6 +173,24 @@ DemoOscilloscope::DemoOscilloscope(SCPITransport* transport)
}
}

vector<Oscilloscope::DigitalBank> DemoOscilloscope::GetDigitalBanks()
{
vector<DigitalBank> banks;

for(size_t n = 0; n < 2; n++)
{
DigitalBank bank;

for(size_t i = 0; i < 8; i++)
bank.push_back(m_digitalChannels[i + n * 8]);

banks.push_back(bank);
}

return banks;
}


DemoOscilloscope::~DemoOscilloscope()
{
LogTrace("Shutting down demo scope\n");
Expand All @@ -146,6 +200,7 @@ DemoOscilloscope::~DemoOscilloscope()
delete m_source[i];
delete m_rng[i];
}
delete m_digitalSource;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -538,7 +593,7 @@ bool DemoOscilloscope::AcquireData()

auto depth = GetSampleDepth();
int64_t sampleperiod = FS_PER_SECOND / m_rate;
WaveformBase* waveforms[4] = {nullptr};
WaveformBase* waveforms[4+16] = {nullptr};
for(int i=0; i<4; i++)
{
if(!m_channelsEnabled[i])
Expand Down Expand Up @@ -591,8 +646,122 @@ bool DemoOscilloscope::AcquireData()
ChannelsDownloadStatusUpdate(i, InstrumentChannel::DownloadState::DOWNLOAD_FINISHED, 1.0);
}

bool spiEnabled = m_channelsEnabled[4]||m_channelsEnabled[5]||m_channelsEnabled[6];
bool parallelEnabled = false;
for(int i=11; i<=19; i++)
{
if(m_channelsEnabled[i])
{
parallelEnabled = true;
break;
}
}


// Prepare SPI data
SparseDigitalWaveform* cs = nullptr;
SparseDigitalWaveform* sclk = nullptr;
SparseDigitalWaveform* mosi = nullptr;
if(spiEnabled)
{
cs = AllocateDigitalWaveform("CS");
sclk = AllocateDigitalWaveform("SCLK");
mosi = AllocateDigitalWaveform("MOSI");
m_digitalSource->GenerateSPI(cs,sclk,mosi,sampleperiod, depth);
}

std::vector<SparseDigitalWaveform*> parallelWfms;
if(parallelEnabled)
{ // Prepare Parallel bus data
auto wfClk = AllocateDigitalWaveform("Parallel-Clk");
parallelWfms.push_back(wfClk);
// Parallel lines waveforms
for(int i = 0 ; i < 8 ; i++)
{
auto wf = AllocateDigitalWaveform("Parallel-"+to_string(i));
parallelWfms.push_back(wf);
}
m_digitalSource->GenerateParallel(parallelWfms,sampleperiod,depth);
}

for(int i=4; i<(4+16); i++)
{
if(!m_channelsEnabled[i])
{
switch(i)
{
case 4:
if(spiEnabled) delete cs;
break;
case 5:
if(spiEnabled) delete sclk;
break;
case 6:
if(spiEnabled) delete mosi;
break;
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
// Paralle bus
if(parallelEnabled) delete parallelWfms[i-11];
break;
}

continue;
}

// Lambda passed to generate waveform methods to update "download" percentage
ChannelsDownloadStatusUpdate(i, InstrumentChannel::DownloadState::DOWNLOAD_IN_PROGRESS, 0.0);
switch(i)
{
case 4:
waveforms[i] = cs;
break;
case 5:
waveforms[i] = sclk;
break;
case 6:
waveforms[i] = mosi;
break;
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
// Paralle bus
waveforms[i] = parallelWfms[i-11];
break;
default:
if(i%2 == 1)
{
auto wfm = AllocateDigitalWaveform("UART");
waveforms[i] = wfm;
m_digitalSource->GenerateUART(wfm, sampleperiod, depth);
}
else
{
auto wfm = AllocateDigitalWaveform("UART-Clk");
waveforms[i] = wfm;
m_digitalSource->GenerateUARTClock(wfm, sampleperiod, depth);
}
break;
}

ChannelsDownloadStatusUpdate(i, InstrumentChannel::DownloadState::DOWNLOAD_FINISHED, 1.0);
}

SequenceSet s;
for(int i=0; i<4; i++)
for(int i=0; i<(4+16); i++)
{
s[GetOscilloscopeChannel(i)] = waveforms[i];
}
Expand Down
10 changes: 10 additions & 0 deletions scopehal/DemoOscilloscope.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#define DemoOscilloscope_h

#include "TestWaveformSource.h"
#include "TestDigitalWaveformSource.h"
#include <random>

/**
Expand Down Expand Up @@ -119,6 +120,9 @@ class DemoOscilloscope : public virtual SCPIOscilloscope
virtual unsigned int GetInstrumentTypes() const override;
virtual void LoadConfiguration(int version, const YAML::Node& node, IDTable& idmap) override;

virtual std::vector<DigitalBank> GetDigitalBanks() override;


protected:

///@brief External trigger
Expand All @@ -145,6 +149,10 @@ class DemoOscilloscope : public virtual SCPIOscilloscope
///@brief Map of channel ID to ADC mode
std::map<size_t, size_t> m_channelModes;

///@brief Digital channels
std::vector<OscilloscopeChannel*> m_digitalChannels;


///@brief ADC mode selectors (used to select the simulated channel)
enum ChannelModes
{
Expand Down Expand Up @@ -186,6 +194,8 @@ class DemoOscilloscope : public virtual SCPIOscilloscope
*/
TestWaveformSource* m_source[4];

TestDigitalWaveformSource* m_digitalSource;

///@brief Vulkan queue for ISI channel
std::shared_ptr<QueueHandle> m_queue[4];

Expand Down
Loading