New analyzer

This commit is contained in:
Thomas Roth
2023-10-12 00:21:47 +02:00
parent c05378e34b
commit 665cfdee89
8 changed files with 160 additions and 205 deletions

View File

@@ -1,70 +1,77 @@
#include "SimpleSerialAnalyzer.h" #include "LPCClocklessAnalyzer.h"
#include "SimpleSerialAnalyzerSettings.h" #include "LPCClocklessAnalyzerSettings.h"
#include <AnalyzerChannelData.h> #include <AnalyzerChannelData.h>
#include <iostream>
SimpleSerialAnalyzer::SimpleSerialAnalyzer() LPCClocklessAnalyzer::LPCClocklessAnalyzer()
: Analyzer2(), : Analyzer2(),
mSettings( new SimpleSerialAnalyzerSettings() ), mSettings( new LPCClocklessAnalyzerSettings() )
mSimulationInitilized( false ) // mSimulationInitilized( false )
{ {
SetAnalyzerSettings( mSettings.get() ); SetAnalyzerSettings( mSettings.get() );
} }
SimpleSerialAnalyzer::~SimpleSerialAnalyzer() LPCClocklessAnalyzer::~LPCClocklessAnalyzer()
{ {
KillThread(); KillThread();
} }
void SimpleSerialAnalyzer::SetupResults() void LPCClocklessAnalyzer::SetupResults()
{ {
mResults.reset( new SimpleSerialAnalyzerResults( this, mSettings.get() ) ); mResults.reset( new LPCClocklessAnalyzerResults( this, mSettings.get() ) );
SetAnalyzerResults( mResults.get() ); SetAnalyzerResults( mResults.get() );
mResults->AddChannelBubblesWillAppearOn( mSettings->mInputChannel ); mResults->AddChannelBubblesWillAppearOn( mSettings->mFrameChannel );
// mResults->AddChannelBubblesWillAppearOn( mSettings->mInputChannel );
} }
void SimpleSerialAnalyzer::WorkerThread() void LPCClocklessAnalyzer::WorkerThread()
{ {
mSampleRateHz = GetSampleRate(); mSampleRateHz = GetSampleRate();
mFrame = GetAnalyzerChannelData( mSettings->mFrameChannel );
// mSerial = GetAnalyzerChannelData( mSettings->mInputChannel );
mSerial = GetAnalyzerChannelData( mSettings->mInputChannel ); if( mFrame->GetBitState() == BIT_HIGH )
mFrame->AdvanceToNextEdge();
if( mSerial->GetBitState() == BIT_LOW )
mSerial->AdvanceToNextEdge();
U32 samples_per_bit = mSampleRateHz / mSettings->mBitRate;
U32 samples_to_first_center_of_first_data_bit = U32( 1.5 * double( mSampleRateHz ) / double( mSettings->mBitRate ) ); U32 samples_per_bit = mSampleRateHz / 33000000;
std::cout << "Samples per bit: " << samples_per_bit << std::endl;
// U32 samples_to_first_center_of_first_data_bit = U32( 1.5 * double( mSampleRateHz ) / double( mSettings->mBitRate ) );
for( ; ; ) for( ; ; )
{ {
U8 data = 0; U8 data = 0;
U8 mask = 1 << 7; U8 mask = 1 << 7;
// std::cout << "Advancing..." << mFrame->GetSampleNumber() << std::endl;
mSerial->AdvanceToNextEdge(); //falling edge -- beginning of the start bit mFrame->Advance(samples_per_bit/2);
U64 starting_sample = mSerial->GetSampleNumber(); // mSerial->AdvanceToNextEdge(); //falling edge -- beginning of the start bit
mSerial->Advance( samples_to_first_center_of_first_data_bit ); U64 starting_sample = mFrame->GetSampleNumber();
// mSerial->Advance( samples_to_first_center_of_first_data_bit );
for( U32 i=0; i<8; i++ ) for( U32 i=0; i<8; i++ )
{ {
//let's put a dot exactly where we sample this bit: //let's put a dot exactly where we sample this bit:
mResults->AddMarker( mSerial->GetSampleNumber(), AnalyzerResults::Dot, mSettings->mInputChannel ); mResults->AddMarker( mFrame->GetSampleNumber(), AnalyzerResults::Dot, mSettings->mFrameChannel );
if( mSerial->GetBitState() == BIT_HIGH ) // if( mSerial->GetBitState() == BIT_HIGH )
data |= mask; // data |= mask;
mSerial->Advance( samples_per_bit ); mFrame->Advance( samples_per_bit );
mask = mask >> 1; // mask = mask >> 1;
} }
//we have a byte to save. //we have a byte to save.
Frame frame; Frame frame;
frame.mData1 = data; // frame.mData1 = data;
frame.mFlags = 0; frame.mFlags = 0;
frame.mStartingSampleInclusive = starting_sample; frame.mStartingSampleInclusive = starting_sample;
frame.mEndingSampleInclusive = mSerial->GetSampleNumber(); frame.mEndingSampleInclusive = mFrame->GetSampleNumber();
mResults->AddFrame( frame ); mResults->AddFrame( frame );
mResults->CommitResults(); mResults->CommitResults();
@@ -72,40 +79,42 @@ void SimpleSerialAnalyzer::WorkerThread()
} }
} }
bool SimpleSerialAnalyzer::NeedsRerun() bool LPCClocklessAnalyzer::NeedsRerun()
{ {
return false; return false;
} }
U32 SimpleSerialAnalyzer::GenerateSimulationData( U64 minimum_sample_index, U32 device_sample_rate, SimulationChannelDescriptor** simulation_channels ) U32 LPCClocklessAnalyzer::GenerateSimulationData( U64 minimum_sample_index, U32 device_sample_rate, SimulationChannelDescriptor** simulation_channels )
{ {
if( mSimulationInitilized == false ) return 0;
{
mSimulationDataGenerator.Initialize( GetSimulationSampleRate(), mSettings.get() );
mSimulationInitilized = true;
}
return mSimulationDataGenerator.GenerateSimulationData( minimum_sample_index, device_sample_rate, simulation_channels );
} }
// if( mSimulationInitilized == false )
// {
// mSimulationDataGenerator.Initialize( GetSimulationSampleRate(), mSettings.get() );
// mSimulationInitilized = true;
// }
U32 SimpleSerialAnalyzer::GetMinimumSampleRateHz() // return mSimulationDataGenerator.GenerateSimulationData( minimum_sample_index, device_sample_rate, simulation_channels );
// }
U32 LPCClocklessAnalyzer::GetMinimumSampleRateHz()
{ {
return mSettings->mBitRate * 4; return mSettings->mBitRate * 4;
} }
const char* SimpleSerialAnalyzer::GetAnalyzerName() const const char* LPCClocklessAnalyzer::GetAnalyzerName() const
{ {
return "Simple Serial"; return "LPC Clockless";
} }
const char* GetAnalyzerName() const char* GetAnalyzerName()
{ {
return "Simple Serial"; return "LPC Clockless";
} }
Analyzer* CreateAnalyzer() Analyzer* CreateAnalyzer()
{ {
return new SimpleSerialAnalyzer(); return new LPCClocklessAnalyzer();
} }
void DestroyAnalyzer( Analyzer* analyzer ) void DestroyAnalyzer( Analyzer* analyzer )

View File

@@ -1,16 +1,16 @@
#ifndef SIMPLESERIAL_ANALYZER_H #ifndef LPCCLOCKLESS_ANALYZER_H
#define SIMPLESERIAL_ANALYZER_H #define LPCCLOCKLESS_ANALYZER_H
#include <Analyzer.h> #include <Analyzer.h>
#include "SimpleSerialAnalyzerResults.h" #include "LPCClocklessAnalyzerResults.h"
#include "SimpleSerialSimulationDataGenerator.h" #include "LPCClocklessSimulationDataGenerator.h"
class SimpleSerialAnalyzerSettings; class LPCClocklessAnalyzerSettings;
class ANALYZER_EXPORT SimpleSerialAnalyzer : public Analyzer2 class ANALYZER_EXPORT LPCClocklessAnalyzer : public Analyzer2
{ {
public: public:
SimpleSerialAnalyzer(); LPCClocklessAnalyzer();
virtual ~SimpleSerialAnalyzer(); virtual ~LPCClocklessAnalyzer();
virtual void SetupResults(); virtual void SetupResults();
virtual void WorkerThread(); virtual void WorkerThread();
@@ -22,12 +22,14 @@ public:
virtual bool NeedsRerun(); virtual bool NeedsRerun();
protected: //vars protected: //vars
std::auto_ptr< SimpleSerialAnalyzerSettings > mSettings; std::unique_ptr< LPCClocklessAnalyzerSettings > mSettings;
std::auto_ptr< SimpleSerialAnalyzerResults > mResults; std::unique_ptr< LPCClocklessAnalyzerResults > mResults;
AnalyzerChannelData* mSerial; // AnalyzerChannelData* mSerial;
AnalyzerChannelData *mFrame;
AnalyzerChannelData *mLadd[4];
SimpleSerialSimulationDataGenerator mSimulationDataGenerator; // LPCClocklessSimulationDataGenerator mSimulationDataGenerator;
bool mSimulationInitilized; // bool mSimulationInitilized;
//Serial analysis vars: //Serial analysis vars:
U32 mSampleRateHz; U32 mSampleRateHz;
@@ -39,4 +41,4 @@ extern "C" ANALYZER_EXPORT const char* __cdecl GetAnalyzerName();
extern "C" ANALYZER_EXPORT Analyzer* __cdecl CreateAnalyzer( ); extern "C" ANALYZER_EXPORT Analyzer* __cdecl CreateAnalyzer( );
extern "C" ANALYZER_EXPORT void __cdecl DestroyAnalyzer( Analyzer* analyzer ); extern "C" ANALYZER_EXPORT void __cdecl DestroyAnalyzer( Analyzer* analyzer );
#endif //SIMPLESERIAL_ANALYZER_H #endif //LPCCLOCKLESS_ANALYZER_H

View File

@@ -1,22 +1,22 @@
#include "SimpleSerialAnalyzerResults.h" #include "LPCClocklessAnalyzerResults.h"
#include <AnalyzerHelpers.h> #include <AnalyzerHelpers.h>
#include "SimpleSerialAnalyzer.h" #include "LPCClocklessAnalyzer.h"
#include "SimpleSerialAnalyzerSettings.h" #include "LPCClocklessAnalyzerSettings.h"
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
SimpleSerialAnalyzerResults::SimpleSerialAnalyzerResults( SimpleSerialAnalyzer* analyzer, SimpleSerialAnalyzerSettings* settings ) LPCClocklessAnalyzerResults::LPCClocklessAnalyzerResults( LPCClocklessAnalyzer* analyzer, LPCClocklessAnalyzerSettings* settings )
: AnalyzerResults(), : AnalyzerResults(),
mSettings( settings ), mSettings( settings ),
mAnalyzer( analyzer ) mAnalyzer( analyzer )
{ {
} }
SimpleSerialAnalyzerResults::~SimpleSerialAnalyzerResults() LPCClocklessAnalyzerResults::~LPCClocklessAnalyzerResults()
{ {
} }
void SimpleSerialAnalyzerResults::GenerateBubbleText( U64 frame_index, Channel& channel, DisplayBase display_base ) void LPCClocklessAnalyzerResults::GenerateBubbleText( U64 frame_index, Channel& channel, DisplayBase display_base )
{ {
ClearResultStrings(); ClearResultStrings();
Frame frame = GetFrame( frame_index ); Frame frame = GetFrame( frame_index );
@@ -26,7 +26,7 @@ void SimpleSerialAnalyzerResults::GenerateBubbleText( U64 frame_index, Channel&
AddResultString( number_str ); AddResultString( number_str );
} }
void SimpleSerialAnalyzerResults::GenerateExportFile( const char* file, DisplayBase display_base, U32 export_type_user_id ) void LPCClocklessAnalyzerResults::GenerateExportFile( const char* file, DisplayBase display_base, U32 export_type_user_id )
{ {
std::ofstream file_stream( file, std::ios::out ); std::ofstream file_stream( file, std::ios::out );
@@ -58,7 +58,7 @@ void SimpleSerialAnalyzerResults::GenerateExportFile( const char* file, DisplayB
file_stream.close(); file_stream.close();
} }
void SimpleSerialAnalyzerResults::GenerateFrameTabularText( U64 frame_index, DisplayBase display_base ) void LPCClocklessAnalyzerResults::GenerateFrameTabularText( U64 frame_index, DisplayBase display_base )
{ {
#ifdef SUPPORTS_PROTOCOL_SEARCH #ifdef SUPPORTS_PROTOCOL_SEARCH
Frame frame = GetFrame( frame_index ); Frame frame = GetFrame( frame_index );
@@ -70,13 +70,13 @@ void SimpleSerialAnalyzerResults::GenerateFrameTabularText( U64 frame_index, Dis
#endif #endif
} }
void SimpleSerialAnalyzerResults::GeneratePacketTabularText( U64 packet_id, DisplayBase display_base ) void LPCClocklessAnalyzerResults::GeneratePacketTabularText( U64 packet_id, DisplayBase display_base )
{ {
//not supported //not supported
} }
void SimpleSerialAnalyzerResults::GenerateTransactionTabularText( U64 transaction_id, DisplayBase display_base ) void LPCClocklessAnalyzerResults::GenerateTransactionTabularText( U64 transaction_id, DisplayBase display_base )
{ {
//not supported //not supported
} }

View File

@@ -1,16 +1,16 @@
#ifndef SIMPLESERIAL_ANALYZER_RESULTS #ifndef LPCCLOCKLESS_ANALYZER_RESULTS
#define SIMPLESERIAL_ANALYZER_RESULTS #define LPCCLOCKLESS_ANALYZER_RESULTS
#include <AnalyzerResults.h> #include <AnalyzerResults.h>
class SimpleSerialAnalyzer; class LPCClocklessAnalyzer;
class SimpleSerialAnalyzerSettings; class LPCClocklessAnalyzerSettings;
class SimpleSerialAnalyzerResults : public AnalyzerResults class LPCClocklessAnalyzerResults : public AnalyzerResults
{ {
public: public:
SimpleSerialAnalyzerResults( SimpleSerialAnalyzer* analyzer, SimpleSerialAnalyzerSettings* settings ); LPCClocklessAnalyzerResults( LPCClocklessAnalyzer* analyzer, LPCClocklessAnalyzerSettings* settings );
virtual ~SimpleSerialAnalyzerResults(); virtual ~LPCClocklessAnalyzerResults();
virtual void GenerateBubbleText( U64 frame_index, Channel& channel, DisplayBase display_base ); virtual void GenerateBubbleText( U64 frame_index, Channel& channel, DisplayBase display_base );
virtual void GenerateExportFile( const char* file, DisplayBase display_base, U32 export_type_user_id ); virtual void GenerateExportFile( const char* file, DisplayBase display_base, U32 export_type_user_id );
@@ -22,8 +22,8 @@ public:
protected: //functions protected: //functions
protected: //vars protected: //vars
SimpleSerialAnalyzerSettings* mSettings; LPCClocklessAnalyzerSettings* mSettings;
SimpleSerialAnalyzer* mAnalyzer; LPCClocklessAnalyzer* mAnalyzer;
}; };
#endif //SIMPLESERIAL_ANALYZER_RESULTS #endif //LPCCLOCKLESS_ANALYZER_RESULTS

View File

@@ -1,14 +1,31 @@
#include "SimpleSerialAnalyzerSettings.h" #include "LPCClocklessAnalyzerSettings.h"
#include <AnalyzerHelpers.h> #include <AnalyzerHelpers.h>
SimpleSerialAnalyzerSettings::SimpleSerialAnalyzerSettings() LPCClocklessAnalyzerSettings::LPCClocklessAnalyzerSettings() :
: mInputChannel( UNDEFINED_CHANNEL ), // : mInputChannel( UNDEFINED_CHANNEL ),
mFrameChannel( UNDEFINED_CHANNEL ),
mBitRate( 9600 ) mBitRate( 9600 )
{ {
mInputChannelInterface.reset( new AnalyzerSettingInterfaceChannel() ); ClearChannels();
mInputChannelInterface->SetTitleAndTooltip( "Serial", "Standard Simple Serial" ); for(int i=0; i < 4; i++) {
mInputChannelInterface->SetChannel( mInputChannel ); mLaddChannel[i] = Channel(UNDEFINED_CHANNEL);
// }
mLaddChannelInterface[i].reset( new AnalyzerSettingInterfaceChannel() );
// const char *name = std::string("Ladd" + std::to_string(i)).c_str();
mLaddChannelInterface[i]->SetTitleAndTooltip(std::string("Ladd" + std::to_string(i)).c_str(), "Signal.");
mLaddChannelInterface[i]->SetChannel( mLaddChannel[i] );
AddInterface( mLaddChannelInterface[i].get() );
AddChannel( mLaddChannel[i], std::string("Ladd" + std::to_string(i)).c_str(), false );
}
mFrameChannelInterface.reset( new AnalyzerSettingInterfaceChannel() );
mFrameChannelInterface->SetTitleAndTooltip( "Frame", "Frame signal" );
mFrameChannelInterface->SetChannel( mFrameChannel );
AddInterface(mFrameChannelInterface.get());
// mInputChannelInterface.reset( new AnalyzerSettingInterfaceChannel() );
// mInputChannelInterface->SetTitleAndTooltip( "Serial", "Standard LPC Clockless" );
// mInputChannelInterface->SetChannel( mInputChannel );
mBitRateInterface.reset( new AnalyzerSettingInterfaceInteger() ); mBitRateInterface.reset( new AnalyzerSettingInterfaceInteger() );
mBitRateInterface->SetTitleAndTooltip( "Bit Rate (Bits/S)", "Specify the bit rate in bits per second." ); mBitRateInterface->SetTitleAndTooltip( "Bit Rate (Bits/S)", "Specify the bit rate in bits per second." );
@@ -16,57 +33,80 @@ SimpleSerialAnalyzerSettings::SimpleSerialAnalyzerSettings()
mBitRateInterface->SetMin( 1 ); mBitRateInterface->SetMin( 1 );
mBitRateInterface->SetInteger( mBitRate ); mBitRateInterface->SetInteger( mBitRate );
AddInterface( mInputChannelInterface.get() ); // AddInterface( mInputChannelInterface.get() );
AddInterface( mBitRateInterface.get() ); AddInterface( mBitRateInterface.get() );
AddExportOption( 0, "Export as text/csv file" ); AddExportOption( 0, "Export as text/csv file" );
AddExportExtension( 0, "text", "txt" ); AddExportExtension( 0, "text", "txt" );
AddExportExtension( 0, "csv", "csv" ); AddExportExtension( 0, "csv", "csv" );
ClearChannels(); // ClearChannels();
AddChannel( mInputChannel, "Serial", false ); AddChannel( mFrameChannel, "Frame", false );
} }
SimpleSerialAnalyzerSettings::~SimpleSerialAnalyzerSettings() LPCClocklessAnalyzerSettings::~LPCClocklessAnalyzerSettings()
{ {
} }
bool SimpleSerialAnalyzerSettings::SetSettingsFromInterfaces() bool LPCClocklessAnalyzerSettings::SetSettingsFromInterfaces()
{ {
mInputChannel = mInputChannelInterface->GetChannel(); // mInputChannel = mInputChannelInterface->GetChannel();
mFrameChannel = mFrameChannelInterface->GetChannel();
for(int i=0; i < 4; i++) {
mLaddChannel[i] = mLaddChannelInterface[i]->GetChannel();
}
mBitRate = mBitRateInterface->GetInteger(); mBitRate = mBitRateInterface->GetInteger();
ClearChannels(); ClearChannels();
AddChannel( mInputChannel, "Simple Serial", true ); for(int i=0; i < 4; i++) {
AddChannel( mLaddChannel[i], std::string("Ladd" + std::to_string(i)).c_str(), true);
}
// AddChannel( mInputChannel, "LPC Clockless", true );
AddChannel( mFrameChannel, "Frame", true );
return true; return true;
} }
void SimpleSerialAnalyzerSettings::UpdateInterfacesFromSettings() void LPCClocklessAnalyzerSettings::UpdateInterfacesFromSettings()
{ {
mInputChannelInterface->SetChannel( mInputChannel ); for(int i=0; i < 4; i++) {
mLaddChannelInterface[i]->SetChannel( mLaddChannel[i] );
}
mFrameChannelInterface->SetChannel( mFrameChannel );
// mInputChannelInterface->SetChannel( mInputChannel );
mBitRateInterface->SetInteger( mBitRate ); mBitRateInterface->SetInteger( mBitRate );
} }
void SimpleSerialAnalyzerSettings::LoadSettings( const char* settings ) void LPCClocklessAnalyzerSettings::LoadSettings( const char* settings )
{ {
SimpleArchive text_archive; SimpleArchive text_archive;
text_archive.SetString( settings ); text_archive.SetString( settings );
for(int i=0; i < 4; i++) {
text_archive >> mInputChannel; text_archive >> mLaddChannel[i];
}
text_archive >> mFrameChannel;
text_archive >> mBitRate; text_archive >> mBitRate;
ClearChannels(); ClearChannels();
AddChannel( mInputChannel, "Simple Serial", true ); for(int i=0; i < 4; i++) {
AddChannel( mLaddChannel[i], std::string("Ladd" + std::to_string(i)).c_str(), true);
}
// AddChannel( mInputChannel, "LPC Clockless", true );
AddChannel( mFrameChannel, "Frame", true );
// AddChannel( mInputChannel, "LPC Clockless", true );
UpdateInterfacesFromSettings(); UpdateInterfacesFromSettings();
} }
const char* SimpleSerialAnalyzerSettings::SaveSettings() const char* LPCClocklessAnalyzerSettings::SaveSettings()
{ {
SimpleArchive text_archive; SimpleArchive text_archive;
text_archive << mInputChannel; for(int i=0; i < 4; i++) {
text_archive << mLaddChannel[i];
}
text_archive << mFrameChannel;
// text_archive << mInputChannel;
text_archive << mBitRate; text_archive << mBitRate;
return SetReturnString( text_archive.GetString() ); return SetReturnString( text_archive.GetString() );

View File

@@ -1,14 +1,14 @@
#ifndef SIMPLESERIAL_ANALYZER_SETTINGS #ifndef LPCCLOCKLESS_ANALYZER_SETTINGS
#define SIMPLESERIAL_ANALYZER_SETTINGS #define LPCCLOCKLESS_ANALYZER_SETTINGS
#include <AnalyzerSettings.h> #include <AnalyzerSettings.h>
#include <AnalyzerTypes.h> #include <AnalyzerTypes.h>
class SimpleSerialAnalyzerSettings : public AnalyzerSettings class LPCClocklessAnalyzerSettings : public AnalyzerSettings
{ {
public: public:
SimpleSerialAnalyzerSettings(); LPCClocklessAnalyzerSettings();
virtual ~SimpleSerialAnalyzerSettings(); virtual ~LPCClocklessAnalyzerSettings();
virtual bool SetSettingsFromInterfaces(); virtual bool SetSettingsFromInterfaces();
void UpdateInterfacesFromSettings(); void UpdateInterfacesFromSettings();
@@ -16,12 +16,16 @@ public:
virtual const char* SaveSettings(); virtual const char* SaveSettings();
Channel mInputChannel; // Channel mInputChannel;
Channel mLaddChannel[4];
Channel mFrameChannel;
U32 mBitRate; U32 mBitRate;
protected: protected:
std::auto_ptr< AnalyzerSettingInterfaceChannel > mInputChannelInterface; // std::unique_ptr< AnalyzerSettingInterfaceChannel > mInputChannelInterface;
std::auto_ptr< AnalyzerSettingInterfaceInteger > mBitRateInterface; std::unique_ptr< AnalyzerSettingInterfaceChannel > mLaddChannelInterface[4];
std::unique_ptr< AnalyzerSettingInterfaceChannel > mFrameChannelInterface;
std::unique_ptr< AnalyzerSettingInterfaceInteger > mBitRateInterface;
}; };
#endif //SIMPLESERIAL_ANALYZER_SETTINGS #endif //LPCCLOCKLESS_ANALYZER_SETTINGS

View File

@@ -1,71 +0,0 @@
#include "SimpleSerialSimulationDataGenerator.h"
#include "SimpleSerialAnalyzerSettings.h"
#include <AnalyzerHelpers.h>
SimpleSerialSimulationDataGenerator::SimpleSerialSimulationDataGenerator()
: mSerialText( "My first analyzer, woo hoo!" ),
mStringIndex( 0 )
{
}
SimpleSerialSimulationDataGenerator::~SimpleSerialSimulationDataGenerator()
{
}
void SimpleSerialSimulationDataGenerator::Initialize( U32 simulation_sample_rate, SimpleSerialAnalyzerSettings* settings )
{
mSimulationSampleRateHz = simulation_sample_rate;
mSettings = settings;
mSerialSimulationData.SetChannel( mSettings->mInputChannel );
mSerialSimulationData.SetSampleRate( simulation_sample_rate );
mSerialSimulationData.SetInitialBitState( BIT_HIGH );
}
U32 SimpleSerialSimulationDataGenerator::GenerateSimulationData( U64 largest_sample_requested, U32 sample_rate, SimulationChannelDescriptor** simulation_channel )
{
U64 adjusted_largest_sample_requested = AnalyzerHelpers::AdjustSimulationTargetSample( largest_sample_requested, sample_rate, mSimulationSampleRateHz );
while( mSerialSimulationData.GetCurrentSampleNumber() < adjusted_largest_sample_requested )
{
CreateSerialByte();
}
*simulation_channel = &mSerialSimulationData;
return 1;
}
void SimpleSerialSimulationDataGenerator::CreateSerialByte()
{
U32 samples_per_bit = mSimulationSampleRateHz / mSettings->mBitRate;
U8 byte = mSerialText[ mStringIndex ];
mStringIndex++;
if( mStringIndex == mSerialText.size() )
mStringIndex = 0;
//we're currenty high
//let's move forward a little
mSerialSimulationData.Advance( samples_per_bit * 10 );
mSerialSimulationData.Transition(); //low-going edge for start bit
mSerialSimulationData.Advance( samples_per_bit ); //add start bit time
U8 mask = 0x1 << 7;
for( U32 i=0; i<8; i++ )
{
if( ( byte & mask ) != 0 )
mSerialSimulationData.TransitionIfNeeded( BIT_HIGH );
else
mSerialSimulationData.TransitionIfNeeded( BIT_LOW );
mSerialSimulationData.Advance( samples_per_bit );
mask = mask >> 1;
}
mSerialSimulationData.TransitionIfNeeded( BIT_HIGH ); //we need to end high
//lets pad the end a bit for the stop bit:
mSerialSimulationData.Advance( samples_per_bit );
}

View File

@@ -1,29 +0,0 @@
#ifndef SIMPLESERIAL_SIMULATION_DATA_GENERATOR
#define SIMPLESERIAL_SIMULATION_DATA_GENERATOR
#include <SimulationChannelDescriptor.h>
#include <string>
class SimpleSerialAnalyzerSettings;
class SimpleSerialSimulationDataGenerator
{
public:
SimpleSerialSimulationDataGenerator();
~SimpleSerialSimulationDataGenerator();
void Initialize( U32 simulation_sample_rate, SimpleSerialAnalyzerSettings* settings );
U32 GenerateSimulationData( U64 newest_sample_requested, U32 sample_rate, SimulationChannelDescriptor** simulation_channel );
protected:
SimpleSerialAnalyzerSettings* mSettings;
U32 mSimulationSampleRateHz;
protected:
void CreateSerialByte();
std::string mSerialText;
U32 mStringIndex;
SimulationChannelDescriptor mSerialSimulationData;
};
#endif //SIMPLESERIAL_SIMULATION_DATA_GENERATOR