2022-01-07 18:17:44 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-12-05 17:58:23 +00:00
|
|
|
// SCSI Target Emulator PiSCSI
|
2022-08-26 01:01:39 +00:00
|
|
|
// for Raspberry Pi
|
2022-01-07 18:17:44 +00:00
|
|
|
//
|
|
|
|
// Copyright (C) 2020-2021 akuker
|
|
|
|
//
|
|
|
|
// [ SCSI Bus Monitor ]
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2022-12-03 04:20:27 +00:00
|
|
|
#include "hal/data_sample.h"
|
2022-11-10 06:44:06 +00:00
|
|
|
#include "hal/gpiobus.h"
|
2023-10-15 06:38:15 +00:00
|
|
|
#include "hal/log.h"
|
2022-11-11 20:08:48 +00:00
|
|
|
#include "sm_core.h"
|
2022-11-10 06:44:06 +00:00
|
|
|
#include "sm_reports.h"
|
2022-01-07 18:17:44 +00:00
|
|
|
#include <fstream>
|
2022-12-03 04:20:27 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
2022-01-07 18:17:44 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Constant declarations
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// 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.
|
2022-12-03 04:20:27 +00:00
|
|
|
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 = '-';
|
2022-09-07 14:38:42 +00:00
|
|
|
const char SYMBOL_PIN_PHASE = '=';
|
2022-01-07 18:17:44 +00:00
|
|
|
|
|
|
|
// We'll use position 0 in the prev_value array to store the previous phase
|
2022-09-07 14:38:42 +00:00
|
|
|
const int PIN_PHASE = 0;
|
2022-01-07 18:17:44 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Variable declarations
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2022-12-03 04:20:27 +00:00
|
|
|
static array<uint8_t,32> prev_value = {0xFF};
|
2022-01-07 18:17:44 +00:00
|
|
|
|
2022-12-03 04:20:27 +00:00
|
|
|
static void vcd_output_if_changed_phase(ofstream &fp, phase_t data, int pin, char symbol)
|
2022-01-07 18:17:44 +00:00
|
|
|
{
|
2022-12-03 04:20:27 +00:00
|
|
|
if (prev_value[pin] != static_cast<uint8_t>(data)) {
|
|
|
|
prev_value[pin] = static_cast<uint8_t>(data);
|
|
|
|
fp << "s" << BUS::GetPhaseStrRaw(data) << " " << symbol << endl;
|
2022-01-07 18:17:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-03 04:20:27 +00:00
|
|
|
static void vcd_output_if_changed_bool(ofstream &fp, bool data, int pin, char symbol)
|
2022-01-07 18:17:44 +00:00
|
|
|
{
|
2022-12-03 04:20:27 +00:00
|
|
|
if (prev_value[pin] != data) {
|
|
|
|
prev_value[pin] = data;
|
|
|
|
fp << data << symbol << endl;
|
2022-01-07 18:17:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-03 04:20:27 +00:00
|
|
|
static void vcd_output_if_changed_byte(ofstream &fp, uint8_t data, int pin, char symbol)
|
2022-01-07 18:17:44 +00:00
|
|
|
{
|
2022-12-03 04:20:27 +00:00
|
|
|
if (prev_value[pin] != data) {
|
|
|
|
prev_value[pin] = data;
|
|
|
|
fp << "b" << fmt::format("{0:8b}", data) << " " << symbol << endl;
|
2022-01-07 18:17:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-03 04:20:27 +00:00
|
|
|
void scsimon_generate_value_change_dump(const string &filename, const vector<shared_ptr<DataSample>> &data_capture_array)
|
2022-01-07 18:17:44 +00:00
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
spdlog::trace("Creating Value Change Dump file (" + filename + ")");
|
2022-01-07 18:17:44 +00:00
|
|
|
ofstream vcd_ofstream;
|
2022-12-03 04:20:27 +00:00
|
|
|
vcd_ofstream.open(filename.c_str(), ios::out);
|
2022-01-07 18:17:44 +00:00
|
|
|
|
|
|
|
// Get the current time
|
|
|
|
time_t rawtime;
|
|
|
|
time(&rawtime);
|
2022-12-03 04:20:27 +00:00
|
|
|
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;
|
2022-01-07 18:17:44 +00:00
|
|
|
|
|
|
|
// Initial values - default to zeros
|
2022-12-03 04:20:27 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
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);
|
2022-01-07 18:17:44 +00:00
|
|
|
}
|
|
|
|
vcd_ofstream.close();
|
|
|
|
}
|