Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
TiferKing committed Jan 2, 2023
0 parents commit 079506d
Show file tree
Hide file tree
Showing 35 changed files with 2,723 additions and 0 deletions.
64 changes: 64 additions & 0 deletions AnalyzerSDK/inc/Analyzer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#ifndef ANALYZER
#define ANALYZER

#include "LogicPublicTypes.h"
#include "AnalyzerTypes.h"
#include "SimulationChannelDescriptor.h"
#include "AnalyzerSettings.h"

class AnalyzerChannelData;
class DeviceCollection;
class ConditionManager;
class ProgressManager;
class AnalyzerResults;
struct AnalyzerData;

class LOGICAPI Analyzer
{
public:
Analyzer();
virtual ~Analyzer() = 0;
virtual void WorkerThread() = 0;

//sample_rate: if there are multiple devices attached, and one is faster than the other,
//we can sample at the speed of the faster one; and pretend the slower one is the same speed.
virtual U32 GenerateSimulationData(U64 newest_sample_requested, U32 sample_rate, SimulationChannelDescriptor **simulation_channels) = 0;
virtual U32 GetMinimumSampleRateHz() = 0; //provide the sample rate required to generate good simulation data
virtual const char *GetAnalyzerVersion() const; //don't override
virtual const char *GetAnalyzerName() const = 0;
virtual bool NeedsRerun() = 0;
virtual void SetupResults();

//use, but don't override:
void SetAnalyzerSettings(AnalyzerSettings *settings);
void KillThread();
AnalyzerChannelData *GetAnalyzerChannelData(Channel &channel); //don't delete this pointer
void ReportProgress(U64 sample_number);
void SetAnalyzerResults(AnalyzerResults *results);
U32 GetSimulationSampleRate();
U32 GetSampleRate();
U64 GetTriggerSample();

//don't override, don't use:
void Init(DeviceCollection *device_collection, ConditionManager *condition_manager, ProgressManager *progress_manager);
void StartProcessing();
void StopWorkerThread();
AnalyzerSettings *GetAnalyzerSettings();
bool DoesAnalyzerUseDevice(U64 device_id);
bool IsValid(Channel *channel_array, U32 count);
void InitialWorkerThread();
bool GetAnalyzerResults(AnalyzerResults **analyzer_results);

//functions added after initial release -- added at the bottom for binary compatibilty
void CheckIfThreadShouldExit();
double GetAnalyzerProgress();
void SetThreadMustExit();
void StartProcessing(U64 starting_sample);

protected:
struct AnalyzerData *mData;
};

typedef Analyzer Analyzer2; //provide compatibility definitions

#endif //ANALYZER
40 changes: 40 additions & 0 deletions AnalyzerSDK/inc/AnalyzerChannelData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef ANALYZERCHANNELDATA
#define ANALYZERCHANNELDATA

#include "LogicPublicTypes.h"

struct AnalyzerChannelDataData;
class ChannelData;

class LOGICAPI AnalyzerChannelData
{
public:
AnalyzerChannelData(ChannelData *channel_data);
~AnalyzerChannelData();

//State
U64 GetSampleNumber();
BitState GetBitState();

//Basic:
U32 Advance(U32 num_samples); //move forward the specified number of samples. Returns the number of times the bit changed state during the move.
U32 AdvanceToAbsPosition(U64 sample_number); //move forward to the specified sample number. Returns the number of times the bit changed state during the move.
void AdvanceToNextEdge(); //move forward until the bit state changes from what it is now.

//Fancier
U64 GetSampleOfNextEdge(); //without moving, get the sample of the next transition.
bool WouldAdvancingCauseTransition(U32 num_samples); //if we advanced, would we encounter any transitions?
bool WouldAdvancingToAbsPositionCauseTransition(U64 sample_number); //if we advanced, would we encounter any transitions?

//minimum pulse tracking. The serial analyzer uses this for auto-baud
void TrackMinimumPulseWidth(); //normally this is not enabled.
U64 GetMinimumPulseWidthSoFar();

//Fancier, part II
bool DoMoreTransitionsExistInCurrentData(); //use this when you have a situation where you have multiple lines, and you need to handle the case where one or the other of them may never change again, and you don't know which.

protected:
AnalyzerChannelDataData *mData;
};

#endif //ANALYZERCHANNELDATA
108 changes: 108 additions & 0 deletions AnalyzerSDK/inc/AnalyzerHelpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#ifndef ANALYZER_HELPERS_H
#define ANALYZER_HELPERS_H

#include "Analyzer.h"

class LOGICAPI AnalyzerHelpers
{
public:
static bool IsEven(U64 value);
static bool IsOdd(U64 value);
static U32 GetOnesCount(U64 value);
static U32 Diff32(U32 a, U32 b);

static void GetNumberString(U64 number, DisplayBase display_base, U32 num_data_bits, char *result_string, U32 result_string_max_length);
static void GetTimeString(U64 sample, U64 trigger_sample, U32 sample_rate_hz, char *result_string, U32 result_string_max_length);

static void Assert(const char *message);
static U64 AdjustSimulationTargetSample(U64 target_sample, U32 sample_rate, U32 simulation_sample_rate);

static bool DoChannelsOverlap(const Channel *channel_array, U32 num_channels);
static void SaveFile(const char *file_name, const U8 *data, U32 data_length, bool is_binary = false);

static S64 ConvertToSignedNumber(U64 number, U32 num_bits);

//These save functions should not be used with SaveFile, above. They are a better way to export data (don't waste memory), and should be used from now on.
static void *StartFile(const char *file_name, bool is_binary = false);
static void AppendToFile(const U8 *data, U32 data_length, void *file);
static void EndFile(void *file);
};


struct ClockGeneratorData;
class LOGICAPI ClockGenerator
{
public:
ClockGenerator();
~ClockGenerator();
void Init(double target_frequency, U32 sample_rate_hz);
U32 AdvanceByHalfPeriod(double multiple = 1.0);
U32 AdvanceByTimeS(double time_s);

protected:
struct ClockGeneratorData *mData;
};


struct BitExtractorData;
class LOGICAPI BitExtractor
{
public:
BitExtractor(U64 data, AnalyzerEnums::ShiftOrder shift_order, U32 num_bits);
~BitExtractor();

BitState GetNextBit();

protected:
struct BitExtractorData *mData;
};


struct DataBuilderData;
class LOGICAPI DataBuilder
{
public:
DataBuilder();
~DataBuilder();

void Reset(U64 *data, AnalyzerEnums::ShiftOrder shift_order, U32 num_bits);
void AddBit(BitState bit);

protected:
struct DataBuilderData *mData;
};


struct SimpleArchiveData;
class LOGICAPI SimpleArchive
{
public:
SimpleArchive();
~SimpleArchive();

void SetString(const char *archive_string);
const char *GetString();

bool operator<<(U64 data);
bool operator<<(U32 data);
bool operator<<(S64 data);
bool operator<<(S32 data);
bool operator<<(double data);
bool operator<<(bool data);
bool operator<<(const char *data);
bool operator<<(Channel &data);

bool operator>>(U64 &data);
bool operator>>(U32 &data);
bool operator>>(S64 &data);
bool operator>>(S32 &data);
bool operator>>(double &data);
bool operator>>(bool &data);
bool operator>>(char const **data);
bool operator>>(Channel &data);

protected:
struct SimpleArchiveData *mData;
};

#endif //ANALYZER_HELPERS_H
99 changes: 99 additions & 0 deletions AnalyzerSDK/inc/AnalyzerResults.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#ifndef ANALYZER_RESULTS
#define ANALYZER_RESULTS

#include "LogicPublicTypes.h"
#include <string>

#define DISPLAY_AS_ERROR_FLAG (1 << 7)
#define DISPLAY_AS_WARNING_FLAG (1 << 6)

class LOGICAPI Frame
{
public:
Frame();
Frame(const Frame &frame);
~Frame();

S64 mStartingSampleInclusive;
S64 mEndingSampleInclusive;
U64 mData1;
U64 mData2;
U8 mType;
U8 mFlags;

bool HasFlag(U8 flag);
};

#define INVALID_RESULT_INDEX 0xFFFFFFFFFFFFFFFFull

struct AnalyzerResultsData;
class LOGICAPI AnalyzerResults
{
public:
enum MarkerType { Dot, ErrorDot, Square, ErrorSquare, UpArrow, DownArrow, X, ErrorX, Start, Stop, One, Zero };
AnalyzerResults(); //you must call the base class contructor in your constructor
virtual ~AnalyzerResults();

//override:
virtual void GenerateBubbleText(U64 frame_index, Channel &channel, DisplayBase display_base) = 0;
virtual void GenerateExportFile(const char *file, DisplayBase display_base, U32 export_type_user_id) = 0;
virtual void GenerateFrameTabularText(U64 frame_index, DisplayBase display_base) = 0;
virtual void GeneratePacketTabularText(U64 packet_id, DisplayBase display_base) = 0;
virtual void GenerateTransactionTabularText(U64 transaction_id, DisplayBase display_base) = 0;

public: //adding/setting data
void AddMarker(U64 sample_number, MarkerType marker_type, Channel &channel);

U64 AddFrame(const Frame &frame);
U64 CommitPacketAndStartNewPacket();
void CancelPacketAndStartNewPacket();
void AddPacketToTransaction(U64 transaction_id, U64 packet_id);
void AddChannelBubblesWillAppearOn(const Channel &channel);

void CommitResults();

public: //data access
U64 GetNumFrames();
U64 GetNumPackets();
Frame GetFrame(U64 frame_id);

U64 GetPacketContainingFrame(U64 frame_id);
U64 GetPacketContainingFrameSequential(U64 frame_id);
void GetFramesContainedInPacket(U64 packet_id, U64 *first_frame_id, U64 *last_frame_id);

U32 GetTransactionContainingPacket(U64 packet_id);
void GetPacketsContainedInTransaction(U64 transaction_id, U64 **packet_id_array, U64 *packet_id_count);

public: //text results setting and access:
void ClearResultStrings();
void AddResultString(const char *str1, const char *str2 = NULL, const char *str3 = NULL, const char *str4 = NULL, const char *str5 = NULL, const char *str6 = NULL); //multiple strings will be concatinated
void GetResultStrings(char const ***result_string_array, U32 *num_strings);

protected: //use these when exporting data.
bool UpdateExportProgressAndCheckForCancel(U64 completed_frames, U64 total_frames);

public: //don't use
bool DoBubblesAppearOnChannel(Channel &channel);
bool DoMarkersAppearOnChannel(Channel &channel);
bool GetFramesInRange(S64 starting_sample_inclusive, S64 ending_sample_inclusive, U64 *first_frame_index, U64 *last_frame_index);
bool GetMarkersInRange(Channel &channel, S64 starting_sample_inclusive, S64 ending_sample_inclusive, U64 *first_marker_index, U64 *last_marker_index);
void GetMarker(Channel &channel, U64 marker_index, MarkerType *marker_type, U64 *marker_sample);
U64 GetNumMarkers(Channel &channel);

void CancelExport();
double GetProgress();
void StartExportThread(const char *file, DisplayBase display_base, U32 export_type_user_id);

protected:
struct AnalyzerResultsData *mData;

public:
void ClearTabularText();
const char *BuildSearchData(U64 FrameID, DisplayBase disp_base, int channel_list_index, char *result);

std::string GetStringForDisplayBase(U64 frame_id, Channel channel, DisplayBase disp_base);
void AddTabularText(const char *str1, const char *str2 = NULL, const char *str3 = NULL, const char *str4 = NULL, const char *str5 = NULL, const char *str6 = NULL);
std::string GetTabularTextString();
};

#endif //ANALYZER_RESULTS
Loading

0 comments on commit 079506d

Please sign in to comment.