mirror of
https://github.com/akuker/RASCSI.git
synced 2025-07-25 05:24:17 +00:00
Initial merge of (incomplete) Banana Pi updates (#993)
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// SCSI Target Emulator RaSCSI Reloaded
|
||||
// for Raspberry Pi
|
||||
//
|
||||
// Copyright (C) 2020-2021 akuker
|
||||
//
|
||||
// [ SCSI Bus Monitor ]
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include "shared/scsi.h"
|
||||
#include "data_sample.h"
|
||||
|
||||
const char *GetPhaseStr(const data_capture *sample)
|
||||
{
|
||||
return BUS::GetPhaseStrRaw(GetPhase(sample));
|
||||
}
|
||||
|
||||
BUS::phase_t GetPhase(const data_capture *sample)
|
||||
{
|
||||
// Selection Phase
|
||||
if (GetSel(sample))
|
||||
{
|
||||
return BUS::phase_t::selection;
|
||||
}
|
||||
|
||||
// Bus busy phase
|
||||
if (!GetBsy(sample))
|
||||
{
|
||||
return BUS::phase_t::busfree;
|
||||
}
|
||||
|
||||
// Get target phase from bus signal line
|
||||
uint32_t mci = GetMsg(sample) ? 0x04 : 0x00;
|
||||
mci |= GetCd(sample) ? 0x02 : 0x00;
|
||||
mci |= GetIo(sample) ? 0x01 : 0x00;
|
||||
return BUS::GetPhase(mci);
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// SCSI Target Emulator RaSCSI Reloaded
|
||||
// for Raspberry Pi
|
||||
//
|
||||
// Copyright (C) 2020-2021 akuker
|
||||
//
|
||||
// [ SCSI Bus Monitor ]
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "shared/scsi.h"
|
||||
#include "hal/gpiobus.h"
|
||||
|
||||
using data_capture_t = struct data_capture
|
||||
{
|
||||
uint32_t data;
|
||||
uint64_t timestamp;
|
||||
};
|
||||
|
||||
#define GET_PIN(SAMPLE, PIN) ((bool)((SAMPLE->data >> PIN) & 1))
|
||||
|
||||
inline bool GetBsy(const data_capture *sample) { return BUS::GetPinRaw(sample->data, PIN_BSY); }
|
||||
inline bool GetSel(const data_capture *sample) { return BUS::GetPinRaw(sample->data, PIN_SEL); }
|
||||
inline bool GetAtn(const data_capture *sample) { return BUS::GetPinRaw(sample->data, PIN_ATN); }
|
||||
inline bool GetAck(const data_capture *sample) { return BUS::GetPinRaw(sample->data, PIN_ACK); }
|
||||
inline bool GetRst(const data_capture *sample) { return BUS::GetPinRaw(sample->data, PIN_RST); }
|
||||
inline bool GetMsg(const data_capture *sample) { return BUS::GetPinRaw(sample->data, PIN_MSG); }
|
||||
inline bool GetCd(const data_capture *sample) { return BUS::GetPinRaw(sample->data, PIN_CD); }
|
||||
inline bool GetIo(const data_capture *sample) { return BUS::GetPinRaw(sample->data, PIN_IO); }
|
||||
inline bool GetReq(const data_capture *sample) { return BUS::GetPinRaw(sample->data, PIN_REQ); }
|
||||
inline bool GetDp(const data_capture *sample) { return BUS::GetPinRaw(sample->data, PIN_DP); }
|
||||
inline uint8_t GetData(const data_capture *sample)
|
||||
{
|
||||
uint32_t data = sample->data;
|
||||
return (uint8_t)((data >> (PIN_DT0 - 0)) & (1 << 0)) |
|
||||
((data >> (PIN_DT1 - 1)) & (1 << 1)) |
|
||||
((data >> (PIN_DT2 - 2)) & (1 << 2)) |
|
||||
((data >> (PIN_DT3 - 3)) & (1 << 3)) |
|
||||
((data >> (PIN_DT4 - 4)) & (1 << 4)) |
|
||||
((data >> (PIN_DT5 - 5)) & (1 << 5)) |
|
||||
((data >> (PIN_DT6 - 6)) & (1 << 6)) |
|
||||
((data >> (PIN_DT7 - 7)) & (1 << 7));
|
||||
}
|
||||
|
||||
const char *GetPhaseStr(const data_capture *sample);
|
||||
BUS::phase_t GetPhase(const data_capture *sample);
|
@@ -5,23 +5,24 @@
|
||||
//
|
||||
// Powered by XM6 TypeG Technology.
|
||||
// Copyright (C) 2016-2020 GIMONS
|
||||
// Copyright (C) 2021-2022 akuker
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include "shared/log.h"
|
||||
#include "shared/rasutil.h"
|
||||
#include "shared/rascsi_version.h"
|
||||
#include "hal/gpiobus_factory.h"
|
||||
#include "hal/gpiobus.h"
|
||||
#include "monitor/sm_reports.h"
|
||||
#include "monitor/sm_core.h"
|
||||
#include "monitor/data_sample.h"
|
||||
#include <sys/time.h>
|
||||
#include "hal/data_sample.h"
|
||||
#include "hal/gpiobus.h"
|
||||
#include "hal/gpiobus_factory.h"
|
||||
#include "monitor/sm_reports.h"
|
||||
#include "shared/log.h"
|
||||
#include "shared/rascsi_version.h"
|
||||
#include "shared/rasutil.h"
|
||||
#include <climits>
|
||||
#include <csignal>
|
||||
#include <iostream>
|
||||
#include <getopt.h>
|
||||
#include <iostream>
|
||||
#include <sched.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace ras_util;
|
||||
@@ -31,7 +32,7 @@ void ScsiMon::KillHandler(int)
|
||||
running = false;
|
||||
}
|
||||
|
||||
void ScsiMon::ParseArguments(const vector<char *>& args)
|
||||
void ScsiMon::ParseArguments(const vector<char *> &args)
|
||||
{
|
||||
int opt;
|
||||
|
||||
@@ -46,11 +47,11 @@ void ScsiMon::ParseArguments(const vector<char *>& args)
|
||||
buff_size = atoi(optarg);
|
||||
break;
|
||||
case 'i':
|
||||
input_file_name = optarg;
|
||||
import_data = true;
|
||||
input_file_name = optarg;
|
||||
import_data = true;
|
||||
break;
|
||||
case 1:
|
||||
file_base_name = optarg;
|
||||
file_base_name = optarg;
|
||||
break;
|
||||
default:
|
||||
cout << "default: " << optarg << endl;
|
||||
@@ -60,8 +61,10 @@ void ScsiMon::ParseArguments(const vector<char *>& args)
|
||||
|
||||
/* Process any remaining command line arguments (not options). */
|
||||
if (optind < static_cast<int>(args.size())) {
|
||||
while (optind < static_cast<int>(args.size()))
|
||||
file_base_name = args[optind++];
|
||||
while (optind < static_cast<int>(args.size())) {
|
||||
file_base_name = args[optind];
|
||||
optind++;
|
||||
}
|
||||
}
|
||||
|
||||
vcd_file_name = file_base_name;
|
||||
@@ -72,7 +75,7 @@ void ScsiMon::ParseArguments(const vector<char *>& args)
|
||||
html_file_name += ".html";
|
||||
}
|
||||
|
||||
void ScsiMon::PrintHelpText(const vector<char *>& args) const
|
||||
void ScsiMon::PrintHelpText(const vector<char *> &args) const
|
||||
{
|
||||
LOGINFO("%s -i [input file json] -b [buffer size] [output file]", args[0])
|
||||
LOGINFO(" -i [input file json] - scsimon will parse the json file instead of capturing new data")
|
||||
@@ -86,8 +89,7 @@ void ScsiMon::Banner() const
|
||||
{
|
||||
if (import_data) {
|
||||
LOGINFO("Reading input file: %s", input_file_name.c_str())
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
LOGINFO("Reading live data from the GPIO pins")
|
||||
LOGINFO(" Connection type : %s", CONNECT_DESC.c_str())
|
||||
}
|
||||
@@ -112,7 +114,7 @@ bool ScsiMon::Init()
|
||||
return false;
|
||||
}
|
||||
|
||||
bus = GPIOBUS_Factory::Create(BUS::mode_e::TARGET);
|
||||
bus = GPIOBUS_Factory::Create(BUS::mode_e::TARGET);
|
||||
if (bus == nullptr) {
|
||||
LOGERROR("Unable to intiailize the GPIO bus. Exiting....")
|
||||
return false;
|
||||
@@ -130,11 +132,11 @@ void ScsiMon::Cleanup() const
|
||||
}
|
||||
LOGINFO(" ")
|
||||
LOGINFO("Generating %s...", vcd_file_name.c_str())
|
||||
scsimon_generate_value_change_dump(vcd_file_name.c_str(), data_buffer, data_idx);
|
||||
scsimon_generate_value_change_dump(vcd_file_name, data_buffer);
|
||||
LOGINFO("Generating %s...", json_file_name.c_str())
|
||||
scsimon_generate_json(json_file_name.c_str(), data_buffer, data_idx);
|
||||
scsimon_generate_json(json_file_name, data_buffer);
|
||||
LOGINFO("Generating %s...", html_file_name.c_str())
|
||||
scsimon_generate_html(html_file_name.c_str(), data_buffer, data_idx);
|
||||
scsimon_generate_html(html_file_name, data_buffer);
|
||||
|
||||
bus->Cleanup();
|
||||
}
|
||||
@@ -144,12 +146,7 @@ void ScsiMon::Reset() const
|
||||
bus->Reset();
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
static uint32_t high_bits = 0x0;
|
||||
static uint32_t low_bits = 0xFFFFFFFF;
|
||||
#endif
|
||||
|
||||
int ScsiMon::run(const vector<char *>& args)
|
||||
int ScsiMon::run(const vector<char *> &args)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
spdlog::set_level(spdlog::level::trace);
|
||||
@@ -162,12 +159,8 @@ int ScsiMon::run(const vector<char *>& args)
|
||||
|
||||
ParseArguments(args);
|
||||
|
||||
#ifdef DEBUG
|
||||
uint32_t prev_high = high_bits;
|
||||
uint32_t prev_low = low_bits;
|
||||
#endif
|
||||
uint32_t prev_sample = 0xFFFFFFFF;
|
||||
uint32_t this_sample = 0;
|
||||
shared_ptr<DataSample> prev_sample = nullptr;
|
||||
shared_ptr<DataSample> this_sample = nullptr;
|
||||
timeval start_time;
|
||||
timeval stop_time;
|
||||
uint64_t loop_count = 0;
|
||||
@@ -181,12 +174,11 @@ int ScsiMon::run(const vector<char *>& args)
|
||||
|
||||
Banner();
|
||||
|
||||
data_buffer = (data_capture *)calloc(buff_size, sizeof(data_capture_t));
|
||||
data_buffer.reserve(buff_size);
|
||||
|
||||
if (import_data) {
|
||||
data_idx = scsimon_read_json(input_file_name.c_str(), data_buffer, buff_size);
|
||||
if (data_idx > 0)
|
||||
{
|
||||
data_idx = scsimon_read_json(input_file_name, data_buffer);
|
||||
if (data_idx > 0) {
|
||||
LOGDEBUG("Read %d samples from %s", data_idx, input_file_name.c_str())
|
||||
Cleanup();
|
||||
}
|
||||
@@ -223,12 +215,8 @@ int ScsiMon::run(const vector<char *>& args)
|
||||
|
||||
(void)gettimeofday(&start_time, nullptr);
|
||||
|
||||
LOGDEBUG("ALL_SCSI_PINS %08X\n", ALL_SCSI_PINS)
|
||||
|
||||
// Main Loop
|
||||
while (running) {
|
||||
// Work initialization
|
||||
this_sample = (bus->Acquire() & ALL_SCSI_PINS);
|
||||
loop_count++;
|
||||
if (loop_count > LLONG_MAX - 1) {
|
||||
LOGINFO("Maximum amount of time has elapsed. SCSIMON is terminating.")
|
||||
@@ -240,23 +228,9 @@ int ScsiMon::run(const vector<char *>& args)
|
||||
running = false;
|
||||
}
|
||||
|
||||
if (this_sample != prev_sample) {
|
||||
#ifdef DEBUG
|
||||
// This is intended to be a debug check to see if every pin is set
|
||||
// high and low at some point.
|
||||
high_bits |= this_sample;
|
||||
low_bits &= this_sample;
|
||||
if ((high_bits != prev_high) || (low_bits != prev_low)) {
|
||||
LOGDEBUG(" %08X %08X\n", high_bits, low_bits)
|
||||
}
|
||||
prev_high = high_bits;
|
||||
prev_low = low_bits;
|
||||
if ((data_idx % 1000) == 0) {
|
||||
LOGDEBUG("%s", ("Collected " + to_string(data_idx) + " samples...").c_str())
|
||||
}
|
||||
#endif
|
||||
data_buffer[data_idx].data = this_sample;
|
||||
data_buffer[data_idx].timestamp = loop_count;
|
||||
this_sample = bus->GetSample(loop_count);
|
||||
if ((prev_sample == nullptr) || (this_sample->GetRawCapture() != prev_sample->GetRawCapture())) {
|
||||
data_buffer.push_back(this_sample);
|
||||
data_idx++;
|
||||
prev_sample = this_sample;
|
||||
}
|
||||
@@ -266,8 +240,7 @@ int ScsiMon::run(const vector<char *>& args)
|
||||
|
||||
// Collect one last sample, otherwise it looks like the end of the data was cut off
|
||||
if (data_idx < buff_size) {
|
||||
data_buffer[data_idx].data = this_sample;
|
||||
data_buffer[data_idx].timestamp = loop_count;
|
||||
data_buffer.push_back(bus->GetSample(loop_count));
|
||||
data_idx++;
|
||||
}
|
||||
|
||||
@@ -276,13 +249,15 @@ int ScsiMon::run(const vector<char *>& args)
|
||||
timersub(&stop_time, &start_time, &time_diff);
|
||||
|
||||
elapsed_us = ((time_diff.tv_sec * 1000000) + time_diff.tv_usec);
|
||||
LOGINFO("%s", ("Elapsed time: " + to_string(elapsed_us) + " microseconds (" + to_string(elapsed_us / 1000000)
|
||||
+ " seconds").c_str())
|
||||
LOGINFO("%s", ("Elapsed time: " + to_string(elapsed_us) + " microseconds (" + to_string(elapsed_us / 1000000) +
|
||||
" seconds")
|
||||
.c_str())
|
||||
LOGINFO("%s", ("Collected " + to_string(data_idx) + " changes").c_str())
|
||||
|
||||
ns_per_loop = (double)(elapsed_us * 1000) / (double)loop_count;
|
||||
LOGINFO("%s", ("Read the SCSI bus " + to_string(loop_count) + " times with an average of "
|
||||
+ to_string(ns_per_loop) + " ns for each read").c_str())
|
||||
LOGINFO("%s", ("Read the SCSI bus " + to_string(loop_count) + " times with an average of " +
|
||||
to_string(ns_per_loop) + " ns for each read")
|
||||
.c_str())
|
||||
|
||||
Cleanup();
|
||||
|
||||
|
@@ -10,52 +10,50 @@
|
||||
#pragma once
|
||||
|
||||
#include "hal/bus.h"
|
||||
#include "monitor/data_sample.h"
|
||||
#include <vector>
|
||||
#include "hal/data_sample.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
// TODO Make static fields/methods non-static
|
||||
class ScsiMon
|
||||
{
|
||||
public:
|
||||
public:
|
||||
ScsiMon() = default;
|
||||
~ScsiMon() = default;
|
||||
|
||||
ScsiMon() = default;
|
||||
~ScsiMon() = default;
|
||||
int run(const vector<char *> &);
|
||||
|
||||
int run(const vector<char *>&);
|
||||
inline static double ns_per_loop;
|
||||
|
||||
inline static double ns_per_loop;
|
||||
private:
|
||||
void ParseArguments(const vector<char *> &);
|
||||
void PrintHelpText(const vector<char *> &) const;
|
||||
void Banner() const;
|
||||
bool Init();
|
||||
void Cleanup() const;
|
||||
void Reset() const;
|
||||
|
||||
private:
|
||||
static void KillHandler(int);
|
||||
|
||||
void ParseArguments(const vector<char *>&);
|
||||
void PrintHelpText(const vector<char *>&) const;
|
||||
void Banner() const;
|
||||
bool Init();
|
||||
void Cleanup() const;
|
||||
void Reset() const;
|
||||
static inline volatile bool running;
|
||||
|
||||
static void KillHandler(int);
|
||||
shared_ptr<BUS> bus;
|
||||
|
||||
static inline volatile bool running;
|
||||
uint32_t buff_size = 1000000;
|
||||
|
||||
unique_ptr<BUS> bus;
|
||||
vector<shared_ptr<DataSample>> data_buffer;
|
||||
|
||||
uint32_t buff_size = 1000000;
|
||||
uint32_t data_idx = 0;
|
||||
|
||||
data_capture *data_buffer = nullptr;
|
||||
bool print_help = false;
|
||||
|
||||
uint32_t data_idx = 0;
|
||||
bool import_data = false;
|
||||
|
||||
bool print_help = false;
|
||||
|
||||
bool import_data = false;
|
||||
|
||||
string file_base_name = "log";
|
||||
string vcd_file_name;
|
||||
string json_file_name;
|
||||
string html_file_name;
|
||||
string input_file_name;
|
||||
string file_base_name = "log";
|
||||
string vcd_file_name;
|
||||
string json_file_name;
|
||||
string html_file_name;
|
||||
string input_file_name;
|
||||
};
|
||||
|
@@ -5,6 +5,7 @@
|
||||
//
|
||||
// Powered by XM6 TypeG Technology.
|
||||
// Copyright (C) 2016-2020 GIMONS
|
||||
// Copyright (C) 2021-2022 akuker
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -96,13 +97,13 @@ for (i = 0; i < coll.length; i++) {
|
||||
)";
|
||||
|
||||
|
||||
static void print_html_data(ofstream& html_fp, const data_capture *data_capture_array, uint32_t capture_count)
|
||||
static void print_html_data(ofstream& html_fp, const vector<shared_ptr<DataSample>> &data_capture_array)
|
||||
{
|
||||
const data_capture *data;
|
||||
shared_ptr<DataSample> data;
|
||||
bool prev_data_valid = false;
|
||||
bool curr_data_valid;
|
||||
uint32_t selected_id = 0;
|
||||
BUS::phase_t prev_phase = BUS::phase_t::busfree;
|
||||
phase_t prev_phase = phase_t::busfree;
|
||||
bool close_row = false;
|
||||
int data_space_count = 0;
|
||||
bool collapsible_div_active = false;
|
||||
@@ -110,12 +111,11 @@ static void print_html_data(ofstream& html_fp, const data_capture *data_capture_
|
||||
|
||||
html_fp << "<table>" << endl;
|
||||
|
||||
for (uint32_t idx = 0; idx < capture_count; idx++) {
|
||||
data = &data_capture_array[idx];
|
||||
curr_data_valid = GetAck(data) && GetReq(data);
|
||||
BUS::phase_t phase = GetPhase(data);
|
||||
if (phase == BUS::phase_t::selection && !GetBsy(data)) {
|
||||
selected_id = GetData(data);
|
||||
for (auto data: data_capture_array) {
|
||||
curr_data_valid = data->GetACK() && data->GetREQ();
|
||||
phase_t phase = data->GetPhase();
|
||||
if (phase == phase_t::selection && !data->GetBSY()) {
|
||||
selected_id = data->GetDAT();
|
||||
}
|
||||
if (prev_phase != phase) {
|
||||
if (close_row) {
|
||||
@@ -137,8 +137,8 @@ static void print_html_data(ofstream& html_fp, const data_capture *data_capture_
|
||||
}
|
||||
html_fp << "<tr>";
|
||||
close_row = true; // Close the row the next time around
|
||||
html_fp << "<td>" << (double)data->timestamp / 100000 << "</td>";
|
||||
html_fp << "<td>" << GetPhaseStr(data) << "</td>";
|
||||
html_fp << "<td>" << (double)data->GetTimestamp() / 100000 << "</td>";
|
||||
html_fp << "<td>" << data->GetPhaseStr() << "</td>";
|
||||
html_fp << "<td>" << std::hex << selected_id << "</td>";
|
||||
html_fp << "<td>";
|
||||
}
|
||||
@@ -151,7 +151,7 @@ static void print_html_data(ofstream& html_fp, const data_capture *data_capture_
|
||||
html_fp << std::hex << data_space_count << ": ";
|
||||
}
|
||||
|
||||
html_fp << fmt::format("{0:02X}", GetData(data));
|
||||
html_fp << fmt::format("{0:02X}", data->GetDAT());
|
||||
|
||||
data_space_count++;
|
||||
if ((data_space_count % 4) == 0) {
|
||||
@@ -171,17 +171,17 @@ static void print_html_data(ofstream& html_fp, const data_capture *data_capture_
|
||||
}
|
||||
}
|
||||
|
||||
void scsimon_generate_html(const char *filename, const data_capture *data_capture_array, uint32_t capture_count)
|
||||
void scsimon_generate_html(const string &filename, const vector<shared_ptr<DataSample>> &data_capture_array)
|
||||
{
|
||||
LOGINFO("Creating HTML report file (%s)", filename)
|
||||
LOGINFO("Creating HTML report file (%s)", filename.c_str())
|
||||
|
||||
ofstream html_ofstream;
|
||||
|
||||
html_ofstream.open(filename, ios::out);
|
||||
html_ofstream.open(filename.c_str(), ios::out);
|
||||
|
||||
html_ofstream << html_header;
|
||||
print_copyright_info(html_ofstream);
|
||||
print_html_data(html_ofstream, data_capture_array, capture_count);
|
||||
print_html_data(html_ofstream, data_capture_array);
|
||||
|
||||
html_ofstream << html_footer;
|
||||
|
||||
|
@@ -5,60 +5,59 @@
|
||||
//
|
||||
// Powered by XM6 TypeG Technology.
|
||||
// Copyright (C) 2016-2020 GIMONS
|
||||
// Copyright (C) 2021-2022 akuker
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include "hal/data_sample_raspberry.h"
|
||||
#include "shared/log.h"
|
||||
#include "sm_reports.h"
|
||||
#include "string.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const char timestamp_label[] = "\"timestamp\":\"0x";
|
||||
const char data_label[] = "\"data\":\"0x";
|
||||
const string timestamp_label = "\"timestamp\":\"0x";
|
||||
const string data_label = "\"data\":\"0x";
|
||||
|
||||
uint32_t scsimon_read_json(const char *json_filename, data_capture *data_capture_array, uint32_t max_sz)
|
||||
uint32_t scsimon_read_json(const string &json_filename, vector<shared_ptr<DataSample>> &data_capture_array)
|
||||
{
|
||||
char str_buf[1024];
|
||||
FILE *fp = fopen(json_filename, "r");
|
||||
std::ifstream json_file(json_filename);
|
||||
uint32_t sample_count = 0;
|
||||
|
||||
while (fgets(str_buf, sizeof(str_buf), fp)) {
|
||||
char timestamp[1024];
|
||||
char data[1024];
|
||||
while (json_file) {
|
||||
string str_buf;
|
||||
std::getline(json_file, str_buf);
|
||||
string timestamp;
|
||||
string data;
|
||||
uint64_t timestamp_uint;
|
||||
uint32_t data_uint;
|
||||
char *ptr;
|
||||
|
||||
const char *timestamp_str = strstr(str_buf, timestamp_label);
|
||||
if (!timestamp_str)
|
||||
size_t timestamp_pos = str_buf.find(timestamp_label);
|
||||
if (timestamp_pos == string::npos)
|
||||
continue;
|
||||
strncpy(timestamp, ×tamp_str[strlen(timestamp_label)], 16);
|
||||
timestamp[16] = '\0';
|
||||
timestamp_uint = strtoull(timestamp, &ptr, 16);
|
||||
timestamp = str_buf.substr(timestamp_pos + timestamp_label.length(), 16);
|
||||
timestamp_uint = strtoull(timestamp.c_str(), &ptr, 16);
|
||||
|
||||
const char *data_str = strstr(str_buf, data_label);
|
||||
if (!data_str)
|
||||
size_t data_pos = str_buf.find(data_label);
|
||||
if (data_pos == string::npos)
|
||||
continue;
|
||||
strncpy(data, &data_str[strlen(data_label)], 8);
|
||||
data[8] = '\0';
|
||||
data_uint = static_cast<uint32_t>(strtoul(data, &ptr, 16));
|
||||
data = str_buf.substr(data_pos + data_label.length(), 8);
|
||||
data_uint = static_cast<uint32_t>(strtoul(data.c_str(), &ptr, 16));
|
||||
|
||||
// For reading in JSON files, we'll just assume raspberry pi data types
|
||||
data_capture_array.push_back(make_unique<DataSample_Raspberry>(data_uint, timestamp_uint));
|
||||
|
||||
data_capture_array[sample_count].timestamp = timestamp_uint;
|
||||
data_capture_array[sample_count].data = data_uint;
|
||||
sample_count++;
|
||||
if (sample_count >= max_sz) {
|
||||
LOGWARN("File exceeds maximum buffer size. Some data may be missing.")
|
||||
LOGWARN("Try re-running the tool with a larger buffer size")
|
||||
if (sample_count == UINT32_MAX) {
|
||||
LOGWARN("Maximum number of samples read. Some data may not be included.")
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fp != nullptr) {
|
||||
fclose(fp);
|
||||
}
|
||||
json_file.close();
|
||||
|
||||
return sample_count;
|
||||
}
|
||||
@@ -68,20 +67,21 @@ uint32_t scsimon_read_json(const char *json_filename, data_capture *data_capture
|
||||
// Generate JSON Output File
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
void scsimon_generate_json(const char *filename, const data_capture *data_capture_array, uint32_t capture_count)
|
||||
void scsimon_generate_json(const string &filename, const vector<shared_ptr<DataSample>> &data_capture_array)
|
||||
{
|
||||
LOGTRACE("Creating JSON file (%s)", filename)
|
||||
LOGTRACE("Creating JSON file (%s)", filename.c_str())
|
||||
ofstream json_ofstream;
|
||||
json_ofstream.open(filename, ios::out);
|
||||
json_ofstream.open(filename.c_str(), ios::out);
|
||||
|
||||
json_ofstream << "[" << endl;
|
||||
|
||||
uint32_t i = 0;
|
||||
while (i < capture_count) {
|
||||
json_ofstream << fmt::format("{{\"id\": \"{0:d}\", \"timestamp\":\"{1:#016x}\", \"data\":\"{2:#08x}\"}}", i, data_capture_array[i].timestamp, data_capture_array[i].data);
|
||||
size_t i = 0;
|
||||
size_t capture_count = data_capture_array.size();
|
||||
for (auto data : data_capture_array) {
|
||||
json_ofstream << fmt::format("{{\"id\": \"{0:d}\", \"timestamp\":\"{1:#016x}\", \"data\":\"{2:#08x}\"}}", i,
|
||||
data->GetTimestamp(), data->GetRawCapture());
|
||||
|
||||
if (i != (capture_count - 1))
|
||||
{
|
||||
if (i != (capture_count - 1)) {
|
||||
json_ofstream << ",";
|
||||
}
|
||||
json_ofstream << endl;
|
||||
@@ -89,5 +89,4 @@ void scsimon_generate_json(const char *filename, const data_capture *data_captur
|
||||
}
|
||||
json_ofstream << "]" << endl;
|
||||
json_ofstream.close();
|
||||
|
||||
}
|
||||
|
@@ -9,10 +9,11 @@
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include "data_sample.h"
|
||||
#include "hal/data_sample.h"
|
||||
#include <memory>
|
||||
|
||||
uint32_t scsimon_read_json(const char *json_filename, data_capture *data_capture_array, uint32_t max_sz);
|
||||
uint32_t scsimon_read_json(const string &json_filename, vector<shared_ptr<DataSample>> &data_capture_array);
|
||||
|
||||
void scsimon_generate_html(const char *filename, const data_capture *data_capture_array, uint32_t capture_count);
|
||||
void scsimon_generate_json(const char *filename, const data_capture *data_capture_array, uint32_t capture_count);
|
||||
void scsimon_generate_value_change_dump(const char *filename, const data_capture *data_capture_array, uint32_t capture_count);
|
||||
void scsimon_generate_html(const string &filename, const vector<shared_ptr<DataSample>> &data_capture_array);
|
||||
void scsimon_generate_json(const string &filename, const vector<shared_ptr<DataSample>> &data_capture_array);
|
||||
void scsimon_generate_value_change_dump(const string &filename, const vector<shared_ptr<DataSample>> &data_capture_array);
|
||||
|
@@ -9,14 +9,14 @@
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include "shared/log.h"
|
||||
#include "hal/data_sample.h"
|
||||
#include "hal/gpiobus.h"
|
||||
#include "data_sample.h"
|
||||
#include "shared/log.h"
|
||||
#include "sm_core.h"
|
||||
#include "sm_reports.h"
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -29,16 +29,16 @@ using namespace std;
|
||||
// Symbol definition for the VCD file
|
||||
// These are just arbitrary symbols. They can be anything allowed by the VCD file format,
|
||||
// as long as they're consistently used.
|
||||
const char SYMBOL_PIN_DAT = '#';
|
||||
const char SYMBOL_PIN_ATN = '+';
|
||||
const char SYMBOL_PIN_RST = '$';
|
||||
const char SYMBOL_PIN_ACK = '%';
|
||||
const char SYMBOL_PIN_REQ = '^';
|
||||
const char SYMBOL_PIN_MSG = '&';
|
||||
const char SYMBOL_PIN_CD = '*';
|
||||
const char SYMBOL_PIN_IO = '(';
|
||||
const char SYMBOL_PIN_BSY = ')';
|
||||
const char SYMBOL_PIN_SEL = '-';
|
||||
const char SYMBOL_PIN_DAT = '#';
|
||||
const char SYMBOL_PIN_ATN = '+';
|
||||
const char SYMBOL_PIN_RST = '$';
|
||||
const char SYMBOL_PIN_ACK = '%';
|
||||
const char SYMBOL_PIN_REQ = '^';
|
||||
const char SYMBOL_PIN_MSG = '&';
|
||||
const char SYMBOL_PIN_CD = '*';
|
||||
const char SYMBOL_PIN_IO = '(';
|
||||
const char SYMBOL_PIN_BSY = ')';
|
||||
const char SYMBOL_PIN_SEL = '-';
|
||||
const char SYMBOL_PIN_PHASE = '=';
|
||||
|
||||
// We'll use position 0 in the prev_value array to store the previous phase
|
||||
@@ -49,133 +49,99 @@ const int PIN_PHASE = 0;
|
||||
// Variable declarations
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
static uint8_t prev_value[32] = {0xFF};
|
||||
static array<uint8_t,32> prev_value = {0xFF};
|
||||
|
||||
static uint8_t get_pin_value(uint32_t data, int pin)
|
||||
static void vcd_output_if_changed_phase(ofstream &fp, phase_t data, int pin, char symbol)
|
||||
{
|
||||
return (data >> pin) & 1;
|
||||
}
|
||||
|
||||
static uint8_t get_data_field(uint32_t data)
|
||||
{
|
||||
const uint32_t data_out =
|
||||
((data >> (PIN_DT0 - 0)) & (1 << 7)) |
|
||||
((data >> (PIN_DT1 - 1)) & (1 << 6)) |
|
||||
((data >> (PIN_DT2 - 2)) & (1 << 5)) |
|
||||
((data >> (PIN_DT3 - 3)) & (1 << 4)) |
|
||||
((data >> (PIN_DT4 - 4)) & (1 << 3)) |
|
||||
((data >> (PIN_DT5 - 5)) & (1 << 2)) |
|
||||
((data >> (PIN_DT6 - 6)) & (1 << 1)) |
|
||||
((data >> (PIN_DT7 - 7)) & (1 << 0));
|
||||
|
||||
return (uint8_t)data_out;
|
||||
}
|
||||
|
||||
static void vcd_output_if_changed_phase(ofstream& fp, uint32_t data, int pin, char symbol)
|
||||
{
|
||||
const BUS::phase_t new_value = GPIOBUS::GetPhaseRaw(data);
|
||||
if (prev_value[pin] != static_cast<uint8_t>(new_value)) {
|
||||
prev_value[pin] = static_cast<uint8_t>(new_value);
|
||||
fp << "s" << GPIOBUS::GetPhaseStrRaw(new_value) << " " << symbol << endl;
|
||||
if (prev_value[pin] != static_cast<uint8_t>(data)) {
|
||||
prev_value[pin] = static_cast<uint8_t>(data);
|
||||
fp << "s" << BUS::GetPhaseStrRaw(data) << " " << symbol << endl;
|
||||
}
|
||||
}
|
||||
|
||||
static void vcd_output_if_changed_bool(ofstream& fp, uint32_t data, int pin, char symbol)
|
||||
static void vcd_output_if_changed_bool(ofstream &fp, bool data, int pin, char symbol)
|
||||
{
|
||||
const uint8_t new_value = get_pin_value(data, pin);
|
||||
if (prev_value[pin] != new_value) {
|
||||
prev_value[pin] = new_value;
|
||||
fp << new_value << symbol << endl;
|
||||
if (prev_value[pin] != data) {
|
||||
prev_value[pin] = data;
|
||||
fp << data << symbol << endl;
|
||||
}
|
||||
}
|
||||
|
||||
static void vcd_output_if_changed_byte(ofstream& fp, uint32_t data, int pin, char symbol)
|
||||
static void vcd_output_if_changed_byte(ofstream &fp, uint8_t data, int pin, char symbol)
|
||||
{
|
||||
const uint8_t new_value = get_data_field(data);
|
||||
if (prev_value[pin] != new_value) {
|
||||
prev_value[pin] = new_value;
|
||||
fp << "b"
|
||||
<< fmt::format("{0:b}", get_pin_value(data, PIN_DT7))
|
||||
<< fmt::format("{0:b}", get_pin_value(data, PIN_DT6))
|
||||
<< fmt::format("{0:b}", get_pin_value(data, PIN_DT5))
|
||||
<< fmt::format("{0:b}", get_pin_value(data, PIN_DT4))
|
||||
<< fmt::format("{0:b}", get_pin_value(data, PIN_DT3))
|
||||
<< fmt::format("{0:b}", get_pin_value(data, PIN_DT2))
|
||||
<< fmt::format("{0:b}", get_pin_value(data, PIN_DT1))
|
||||
<< fmt::format("{0:b}", get_pin_value(data, PIN_DT0))
|
||||
<< " " << symbol << endl;
|
||||
if (prev_value[pin] != data) {
|
||||
prev_value[pin] = data;
|
||||
fp << "b" << fmt::format("{0:8b}", data) << " " << symbol << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void scsimon_generate_value_change_dump(const char *filename, const data_capture *data_capture_array, uint32_t capture_count)
|
||||
void scsimon_generate_value_change_dump(const string &filename, const vector<shared_ptr<DataSample>> &data_capture_array)
|
||||
{
|
||||
LOGTRACE("Creating Value Change Dump file (%s)", filename)
|
||||
LOGTRACE("Creating Value Change Dump file (%s)", filename.c_str())
|
||||
ofstream vcd_ofstream;
|
||||
vcd_ofstream.open(filename, ios::out);
|
||||
vcd_ofstream.open(filename.c_str(), ios::out);
|
||||
|
||||
// Get the current time
|
||||
time_t rawtime;
|
||||
time(&rawtime);
|
||||
const struct tm *timeinfo = localtime(&rawtime);
|
||||
char timestamp[256];
|
||||
strftime(timestamp, sizeof(timestamp), "%d-%m-%Y %H-%M-%S", timeinfo);
|
||||
struct tm timeinfo;
|
||||
localtime_r(&rawtime, &timeinfo);
|
||||
string timestamp;
|
||||
timestamp.resize(256);
|
||||
strftime(×tamp[0], timestamp.size(), "%d-%m-%Y %H-%M-%S", &timeinfo);
|
||||
|
||||
vcd_ofstream
|
||||
<< "$date" << endl
|
||||
<< timestamp << endl
|
||||
<< "$end" << endl
|
||||
<< "$version" << endl
|
||||
<< " VCD generator tool version info text." << endl
|
||||
<< "$end" << endl
|
||||
<< "$comment" << endl
|
||||
<< " Tool build date:" << __TIMESTAMP__ << endl
|
||||
<< "$end" << endl
|
||||
<< "$timescale 1 ns $end" << endl
|
||||
<< "$scope module logic $end" << endl
|
||||
<< "$var wire 1 " << SYMBOL_PIN_BSY << " BSY $end" << endl
|
||||
<< "$var wire 1 " << SYMBOL_PIN_SEL << " SEL $end" << endl
|
||||
<< "$var wire 1 " << SYMBOL_PIN_CD << " CD $end" << endl
|
||||
<< "$var wire 1 " << SYMBOL_PIN_IO << " IO $end"<< endl
|
||||
<< "$var wire 1 " << SYMBOL_PIN_MSG << " MSG $end"<< endl
|
||||
<< "$var wire 1 " << SYMBOL_PIN_REQ << " REQ $end" << endl
|
||||
<< "$var wire 1 " << SYMBOL_PIN_ACK << " ACK $end" << endl
|
||||
<< "$var wire 1 " << SYMBOL_PIN_ATN << " ATN $end" << endl
|
||||
<< "$var wire 1 " << SYMBOL_PIN_RST << " RST $end" << endl
|
||||
<< "$var wire 8 " << SYMBOL_PIN_DAT << " data $end" << endl
|
||||
<< "$var string 1 " << SYMBOL_PIN_PHASE << " phase $end" << endl
|
||||
<< "$upscope $end" << endl
|
||||
<< "$enddefinitions $end" << endl;
|
||||
vcd_ofstream << "$date" << endl
|
||||
<< timestamp << endl
|
||||
<< "$end" << endl
|
||||
<< "$version" << endl
|
||||
<< " VCD generator tool version info text." << endl
|
||||
<< "$end" << endl
|
||||
<< "$comment" << endl
|
||||
<< " Tool build date:" << __TIMESTAMP__ << endl
|
||||
<< "$end" << endl
|
||||
<< "$timescale 1 ns $end" << endl
|
||||
<< "$scope module logic $end" << endl
|
||||
<< "$var wire 1 " << SYMBOL_PIN_BSY << " BSY $end" << endl
|
||||
<< "$var wire 1 " << SYMBOL_PIN_SEL << " SEL $end" << endl
|
||||
<< "$var wire 1 " << SYMBOL_PIN_CD << " CD $end" << endl
|
||||
<< "$var wire 1 " << SYMBOL_PIN_IO << " IO $end" << endl
|
||||
<< "$var wire 1 " << SYMBOL_PIN_MSG << " MSG $end" << endl
|
||||
<< "$var wire 1 " << SYMBOL_PIN_REQ << " REQ $end" << endl
|
||||
<< "$var wire 1 " << SYMBOL_PIN_ACK << " ACK $end" << endl
|
||||
<< "$var wire 1 " << SYMBOL_PIN_ATN << " ATN $end" << endl
|
||||
<< "$var wire 1 " << SYMBOL_PIN_RST << " RST $end" << endl
|
||||
<< "$var wire 8 " << SYMBOL_PIN_DAT << " data $end" << endl
|
||||
<< "$var string 1 " << SYMBOL_PIN_PHASE << " phase $end" << endl
|
||||
<< "$upscope $end" << endl
|
||||
<< "$enddefinitions $end" << endl;
|
||||
|
||||
// Initial values - default to zeros
|
||||
vcd_ofstream
|
||||
<< "$dumpvars" << endl
|
||||
<< "0" << SYMBOL_PIN_BSY << endl
|
||||
<< "0" << SYMBOL_PIN_SEL << endl
|
||||
<< "0" << SYMBOL_PIN_CD << endl
|
||||
<< "0" << SYMBOL_PIN_IO << endl
|
||||
<< "0" << SYMBOL_PIN_MSG << endl
|
||||
<< "0" << SYMBOL_PIN_REQ << endl
|
||||
<< "0" << SYMBOL_PIN_ACK << endl
|
||||
<< "0" << SYMBOL_PIN_ATN << endl
|
||||
<< "0" << SYMBOL_PIN_RST << endl
|
||||
<< "b00000000 " << SYMBOL_PIN_DAT << endl
|
||||
<< "$end" << endl;
|
||||
vcd_ofstream << "$dumpvars" << endl
|
||||
<< "0" << SYMBOL_PIN_BSY << endl
|
||||
<< "0" << SYMBOL_PIN_SEL << endl
|
||||
<< "0" << SYMBOL_PIN_CD << endl
|
||||
<< "0" << SYMBOL_PIN_IO << endl
|
||||
<< "0" << SYMBOL_PIN_MSG << endl
|
||||
<< "0" << SYMBOL_PIN_REQ << endl
|
||||
<< "0" << SYMBOL_PIN_ACK << endl
|
||||
<< "0" << SYMBOL_PIN_ATN << endl
|
||||
<< "0" << SYMBOL_PIN_RST << endl
|
||||
<< "b00000000 " << SYMBOL_PIN_DAT << endl
|
||||
<< "$end" << endl;
|
||||
|
||||
uint32_t i = 0;
|
||||
while (i < capture_count) {
|
||||
vcd_ofstream << "#" << (uint64_t)((double)data_capture_array[i].timestamp * ScsiMon::ns_per_loop) << endl;
|
||||
vcd_output_if_changed_bool(vcd_ofstream, data_capture_array[i].data, PIN_BSY, SYMBOL_PIN_BSY);
|
||||
vcd_output_if_changed_bool(vcd_ofstream, data_capture_array[i].data, PIN_SEL, SYMBOL_PIN_SEL);
|
||||
vcd_output_if_changed_bool(vcd_ofstream, data_capture_array[i].data, PIN_CD, SYMBOL_PIN_CD);
|
||||
vcd_output_if_changed_bool(vcd_ofstream, data_capture_array[i].data, PIN_IO, SYMBOL_PIN_IO);
|
||||
vcd_output_if_changed_bool(vcd_ofstream, data_capture_array[i].data, PIN_MSG, SYMBOL_PIN_MSG);
|
||||
vcd_output_if_changed_bool(vcd_ofstream, data_capture_array[i].data, PIN_REQ, SYMBOL_PIN_REQ);
|
||||
vcd_output_if_changed_bool(vcd_ofstream, data_capture_array[i].data, PIN_ACK, SYMBOL_PIN_ACK);
|
||||
vcd_output_if_changed_bool(vcd_ofstream, data_capture_array[i].data, PIN_ATN, SYMBOL_PIN_ATN);
|
||||
vcd_output_if_changed_bool(vcd_ofstream, data_capture_array[i].data, PIN_RST, SYMBOL_PIN_RST);
|
||||
vcd_output_if_changed_byte(vcd_ofstream, data_capture_array[i].data, PIN_DT0, SYMBOL_PIN_DAT);
|
||||
vcd_output_if_changed_phase(vcd_ofstream, data_capture_array[i].data, PIN_PHASE, SYMBOL_PIN_PHASE);
|
||||
i++;
|
||||
for (shared_ptr<DataSample> cur_sample : data_capture_array) {
|
||||
vcd_ofstream << "#" << (double)cur_sample->GetTimestamp() * ScsiMon::ns_per_loop << endl;
|
||||
vcd_output_if_changed_bool(vcd_ofstream, cur_sample->GetBSY(), PIN_BSY, SYMBOL_PIN_BSY);
|
||||
vcd_output_if_changed_bool(vcd_ofstream, cur_sample->GetSEL(), PIN_SEL, SYMBOL_PIN_SEL);
|
||||
vcd_output_if_changed_bool(vcd_ofstream, cur_sample->GetCD(), PIN_CD, SYMBOL_PIN_CD);
|
||||
vcd_output_if_changed_bool(vcd_ofstream, cur_sample->GetIO(), PIN_IO, SYMBOL_PIN_IO);
|
||||
vcd_output_if_changed_bool(vcd_ofstream, cur_sample->GetMSG(), PIN_MSG, SYMBOL_PIN_MSG);
|
||||
vcd_output_if_changed_bool(vcd_ofstream, cur_sample->GetREQ(), PIN_REQ, SYMBOL_PIN_REQ);
|
||||
vcd_output_if_changed_bool(vcd_ofstream, cur_sample->GetACK(), PIN_ACK, SYMBOL_PIN_ACK);
|
||||
vcd_output_if_changed_bool(vcd_ofstream, cur_sample->GetATN(), PIN_ATN, SYMBOL_PIN_ATN);
|
||||
vcd_output_if_changed_bool(vcd_ofstream, cur_sample->GetRST(), PIN_RST, SYMBOL_PIN_RST);
|
||||
vcd_output_if_changed_byte(vcd_ofstream, cur_sample->GetDAT(), PIN_DT0, SYMBOL_PIN_DAT);
|
||||
vcd_output_if_changed_phase(vcd_ofstream, cur_sample->GetPhase(), PIN_PHASE, SYMBOL_PIN_PHASE);
|
||||
}
|
||||
vcd_ofstream.close();
|
||||
}
|
||||
|
Reference in New Issue
Block a user