diff --git a/src/raspberrypi/Makefile b/src/raspberrypi/Makefile index 20b5f27a..13925961 100644 --- a/src/raspberrypi/Makefile +++ b/src/raspberrypi/Makefile @@ -189,13 +189,6 @@ $(BINDIR)/$(SCSIMON): $(OBJ_SCSIMON) | $(BINDIR) clean: rm -rf $(OBJDIR) $(BINDIR) $(GEN_PROTOBUF) -## run : Launches RaSCSI using some pre-defined drive -## images. Useful for debugging when you're building -## and re-launching over and over. -.PHONY: run -run: - sudo $(BINDIR)/$(RASCSI) -ID1 /home/pi/HARDDISK2.hda -ID6 /home/pi/marathon.iso - ## install : Copies all of the man pages to the correct location ## Copies the binaries to a global install location ## Configures the Systemd and RSyslog services to auto-run RaSCSI diff --git a/src/raspberrypi/controllers/scsidev_ctrl.cpp b/src/raspberrypi/controllers/scsidev_ctrl.cpp index c07d35b6..799214d4 100644 --- a/src/raspberrypi/controllers/scsidev_ctrl.cpp +++ b/src/raspberrypi/controllers/scsidev_ctrl.cpp @@ -25,11 +25,6 @@ // //=========================================================================== -//--------------------------------------------------------------------------- -// -// Constructor -// -//--------------------------------------------------------------------------- SCSIDEV::SCSIDEV() : SASIDEV() { // Synchronous transfer work initialization @@ -45,11 +40,6 @@ SCSIDEV::~SCSIDEV() { } -//--------------------------------------------------------------------------- -// -// Device reset -// -//--------------------------------------------------------------------------- void SCSIDEV::Reset() { // Work initialization @@ -61,11 +51,6 @@ void SCSIDEV::Reset() SASIDEV::Reset(); } -//--------------------------------------------------------------------------- -// -// Process -// -//--------------------------------------------------------------------------- BUS::phase_t SCSIDEV::Process() { // Do nothing if not connected @@ -130,9 +115,8 @@ BUS::phase_t SCSIDEV::Process() MsgIn(); break; - // Other default: - ASSERT(FALSE); + assert(false); break; } @@ -319,7 +303,6 @@ void SCSIDEV::MsgOut() return; } - // Receive Receive(); } @@ -473,9 +456,8 @@ void SCSIDEV::Send() MsgIn(); break; - // Other (impossible) default: - ASSERT(FALSE); + assert(false); break; } } @@ -599,14 +581,14 @@ void SCSIDEV::Receive() // ABORT if (data == 0x06) { - LOGTRACE("Message code ABORT $%02X", (int)data); + LOGTRACE("Message code ABORT $%02X", data); BusFree(); return; } // BUS DEVICE RESET if (data == 0x0C) { - LOGTRACE("Message code BUS DEVICE RESET $%02X", (int)data); + LOGTRACE("Message code BUS DEVICE RESET $%02X", data); scsi.syncoffset = 0; BusFree(); return; @@ -620,7 +602,7 @@ void SCSIDEV::Receive() // Extended Message if (data == 0x01) { - LOGTRACE("Message code EXTENDED MESSAGE $%02X", (int)data); + LOGTRACE("Message code EXTENDED MESSAGE $%02X", data); // Check only when synchronous transfer is possible if (!scsi.syncenable || scsi.msb[i + 2] != 0x01) { @@ -669,16 +651,14 @@ void SCSIDEV::Receive() // Data out phase case BUS::dataout: - // Flush unit FlushUnit(); // status phase Status(); break; - // Other (impossible) default: - ASSERT(FALSE); + assert(false); break; } } diff --git a/src/raspberrypi/devices/cfilesystem.cpp b/src/raspberrypi/devices/cfilesystem.cpp index c1b3e06a..7ed12297 100644 --- a/src/raspberrypi/devices/cfilesystem.cpp +++ b/src/raspberrypi/devices/cfilesystem.cpp @@ -280,7 +280,7 @@ void CHostDrv::Init(const TCHAR* szBase, DWORD nFlag) } else { pClear = NULL; } - if ((0x80 <= c && c <= 0x9F) || 0xE0 <= c) { // To be precise: 0x81~0x9F 0xE0~0xEF + if (((TCHAR)0x80 <= c && c <= (TCHAR)0x9F) || (TCHAR)0xE0 <= c) { // To be precise: 0x81~0x9F 0xE0~0xEF p++; if (*p == _T('\0')) break; diff --git a/src/raspberrypi/devices/disk.cpp b/src/raspberrypi/devices/disk.cpp index 7a94f250..9763056e 100644 --- a/src/raspberrypi/devices/disk.cpp +++ b/src/raspberrypi/devices/disk.cpp @@ -366,9 +366,8 @@ void Disk::Verify16(SASIDEV *controller) void Disk::Inquiry(SASIDEV *controller) { - ScsiPrimaryCommands *device = NULL; int lun = controller->GetEffectiveLun(); - device = ctrl->unit[lun]; + const ScsiPrimaryCommands *device = ctrl->unit[lun]; // Find a valid unit // TODO The code below is probably wrong. It results in the same INQUIRY data being @@ -507,8 +506,6 @@ void Disk::SynchronizeCache16(SASIDEV *controller) void Disk::ReadDefectData10(SASIDEV *controller) { ctrl->length = ReadDefectData10(ctrl->cmd, ctrl->buffer); - ASSERT(ctrl->length >= 0); - if (ctrl->length <= 4) { controller->Error(); return; @@ -517,11 +514,6 @@ void Disk::ReadDefectData10(SASIDEV *controller) controller->DataIn(); } -//--------------------------------------------------------------------------- -// -// Eject -// -//--------------------------------------------------------------------------- bool Disk::Eject(bool force) { bool status = Device::Eject(force); @@ -541,11 +533,6 @@ bool Disk::Eject(bool force) return status; } -//--------------------------------------------------------------------------- -// -// Check Ready -// -//--------------------------------------------------------------------------- bool Disk::CheckReady() { // Not ready if reset @@ -651,11 +638,6 @@ int Disk::ModeSelectCheck10(const DWORD *cdb) return ModeSelectCheck(cdb, length); } -//--------------------------------------------------------------------------- -// -// MODE SELECT -// -//--------------------------------------------------------------------------- bool Disk::ModeSelect(const DWORD* /*cdb*/, const BYTE *buf, int length) { ASSERT(buf); @@ -667,16 +649,8 @@ bool Disk::ModeSelect(const DWORD* /*cdb*/, const BYTE *buf, int length) return false; } -//--------------------------------------------------------------------------- -// -// MODE SENSE(6) -// -//--------------------------------------------------------------------------- int Disk::ModeSense6(const DWORD *cdb, BYTE *buf) { - ASSERT(cdb); - ASSERT(buf); - // Get length, clear buffer int length = (int)cdb[4]; ASSERT((length >= 0) && (length < 0x100)); @@ -802,16 +776,8 @@ int Disk::ModeSense6(const DWORD *cdb, BYTE *buf) return length; } -//--------------------------------------------------------------------------- -// -// MODE SENSE(10) -// -//--------------------------------------------------------------------------- int Disk::ModeSense10(const DWORD *cdb, BYTE *buf) { - ASSERT(cdb); - ASSERT(buf); - // Get length, clear buffer int length = cdb[7]; length <<= 8; @@ -972,8 +938,6 @@ int Disk::ModeSense10(const DWORD *cdb, BYTE *buf) int Disk::AddErrorPage(bool change, BYTE *buf) { - ASSERT(buf); - // Set the message length buf[0] = 0x01; buf[1] = 0x0a; @@ -984,8 +948,6 @@ int Disk::AddErrorPage(bool change, BYTE *buf) int Disk::AddFormatPage(bool change, BYTE *buf) { - ASSERT(buf); - // Set the message length buf[0] = 0x80 | 0x03; buf[1] = 0x16; @@ -1022,8 +984,6 @@ int Disk::AddFormatPage(bool change, BYTE *buf) int Disk::AddDrivePage(bool change, BYTE *buf) { - ASSERT(buf); - // Set the message length buf[0] = 0x04; buf[1] = 0x16; @@ -1052,8 +1012,6 @@ int Disk::AddDrivePage(bool change, BYTE *buf) int Disk::AddOptionPage(bool change, BYTE *buf) { - ASSERT(buf); - // Set the message length buf[0] = 0x06; buf[1] = 0x02; @@ -1064,8 +1022,6 @@ int Disk::AddOptionPage(bool change, BYTE *buf) int Disk::AddCachePage(bool change, BYTE *buf) { - ASSERT(buf); - // Set the message length buf[0] = 0x08; buf[1] = 0x0a; @@ -1076,8 +1032,6 @@ int Disk::AddCachePage(bool change, BYTE *buf) int Disk::AddCDROMPage(bool change, BYTE *buf) { - ASSERT(buf); - // Set the message length buf[0] = 0x0d; buf[1] = 0x06; @@ -1099,8 +1053,6 @@ int Disk::AddCDROMPage(bool change, BYTE *buf) int Disk::AddCDDAPage(bool change, BYTE *buf) { - ASSERT(buf); - // Set the message length buf[0] = 0x0e; buf[1] = 0x0e; @@ -1197,7 +1149,7 @@ int Disk::Read(const DWORD *cdb, BYTE *buf, uint64_t block) } // leave it to the cache - if (!disk.dcache->Read(buf, block)) { + if (!disk.dcache->ReadSector(buf, block)) { SetStatusCode(STATUS_READFAULT); return 0; } @@ -1267,7 +1219,7 @@ bool Disk::Write(const DWORD *cdb, const BYTE *buf, DWORD block) } // Leave it to the cache - if (!disk.dcache->Write(buf, block)) { + if (!disk.dcache->WriteSector(buf, block)) { SetStatusCode(STATUS_WRITEFAULT); return false; } @@ -1296,25 +1248,13 @@ void Disk::Seek6(SASIDEV *controller) Seek(controller); } -//--------------------------------------------------------------------------- -// -// SEEK(10) -// -//--------------------------------------------------------------------------- void Disk::Seek10(SASIDEV *controller) { Seek(controller); } -//--------------------------------------------------------------------------- -// -// START STOP UNIT -// -//--------------------------------------------------------------------------- bool Disk::StartStop(const DWORD *cdb) { - ASSERT(cdb); - bool start = cdb[4] & 0x01; bool load = cdb[4] & 0x02; @@ -1342,15 +1282,8 @@ bool Disk::StartStop(const DWORD *cdb) return true; } -//--------------------------------------------------------------------------- -// -// SEND DIAGNOSTIC -// -//--------------------------------------------------------------------------- bool Disk::SendDiag(const DWORD *cdb) { - ASSERT(cdb); - // Do not support PF bit if (cdb[1] & 0x10) { SetStatusCode(STATUS_INVALIDCDB); @@ -1366,17 +1299,10 @@ bool Disk::SendDiag(const DWORD *cdb) return true; } -//--------------------------------------------------------------------------- -// -// READ CAPACITY -// -//--------------------------------------------------------------------------- void Disk::ReadCapacity10(SASIDEV *controller) { BYTE *buf = ctrl->buffer; - ASSERT(buf); - memset(buf, 0, 8); if (!CheckReady()) { @@ -1416,8 +1342,6 @@ void Disk::ReadCapacity16(SASIDEV *controller) { BYTE *buf = ctrl->buffer; - ASSERT(buf); - memset(buf, 0, 14); if (!CheckReady() || disk.blocks <= 0) { @@ -1452,17 +1376,10 @@ void Disk::ReadCapacity16(SASIDEV *controller) controller->DataIn(); } -//--------------------------------------------------------------------------- -// -// REPORT LUNS -// -//--------------------------------------------------------------------------- void Disk::ReportLuns(SASIDEV *controller) { BYTE *buf = ctrl->buffer; - ASSERT(buf); - if (!CheckReady()) { controller->Error(); return; diff --git a/src/raspberrypi/devices/disk_track_cache.cpp b/src/raspberrypi/devices/disk_track_cache.cpp index 9b5befd1..bc4aba37 100644 --- a/src/raspberrypi/devices/disk_track_cache.cpp +++ b/src/raspberrypi/devices/disk_track_cache.cpp @@ -57,11 +57,6 @@ DiskTrack::~DiskTrack() } } -//--------------------------------------------------------------------------- -// -// Initialization -// -//--------------------------------------------------------------------------- void DiskTrack::Init(int track, int size, int sectors, BOOL raw, off_t imgoff) { ASSERT(track >= 0); @@ -84,15 +79,8 @@ void DiskTrack::Init(int track, int size, int sectors, BOOL raw, off_t imgoff) dt.imgoffset = imgoff; } -//--------------------------------------------------------------------------- -// -// Load -// -//--------------------------------------------------------------------------- bool DiskTrack::Load(const Filepath& path) { - Fileio fio; - // Not needed if already loaded if (dt.init) { ASSERT(dt.buffer); @@ -160,6 +148,7 @@ bool DiskTrack::Load(const Filepath& path) memset(dt.changemap, 0x00, dt.sectors * sizeof(BOOL)); // Read from File + Fileio fio; if (!fio.OpenDIO(path, Fileio::ReadOnly)) { return false; } @@ -200,11 +189,6 @@ bool DiskTrack::Load(const Filepath& path) return true; } -//--------------------------------------------------------------------------- -// -// Save -// -//--------------------------------------------------------------------------- bool DiskTrack::Save(const Filepath& path) { // Not needed if not initialized @@ -290,12 +274,7 @@ bool DiskTrack::Save(const Filepath& path) return true; } -//--------------------------------------------------------------------------- -// -// Read Sector -// -//--------------------------------------------------------------------------- -bool DiskTrack::Read(BYTE *buf, int sec) const +bool DiskTrack::ReadSector(BYTE *buf, int sec) const { ASSERT(buf); ASSERT((sec >= 0) & (sec < 0x100)); @@ -320,12 +299,7 @@ bool DiskTrack::Read(BYTE *buf, int sec) const return true; } -//--------------------------------------------------------------------------- -// -// Write Sector -// -//--------------------------------------------------------------------------- -bool DiskTrack::Write(const BYTE *buf, int sec) +bool DiskTrack::WriteSector(const BYTE *buf, int sec) { ASSERT(buf); ASSERT((sec >= 0) & (sec < 0x100)); @@ -368,11 +342,6 @@ bool DiskTrack::Write(const BYTE *buf, int sec) // //=========================================================================== -//--------------------------------------------------------------------------- -// -// Constructor -// -//--------------------------------------------------------------------------- DiskCache::DiskCache(const Filepath& path, int size, uint32_t blocks, off_t imgoff) { ASSERT(blocks > 0); @@ -393,33 +362,18 @@ DiskCache::DiskCache(const Filepath& path, int size, uint32_t blocks, off_t imgo imgoffset = imgoff; } -//--------------------------------------------------------------------------- -// -// Destructor -// -//--------------------------------------------------------------------------- DiskCache::~DiskCache() { // Clear the track Clear(); } -//--------------------------------------------------------------------------- -// -// RAW Mode Setting -// -//--------------------------------------------------------------------------- void DiskCache::SetRawMode(BOOL raw) { // Configuration cd_raw = raw; } -//--------------------------------------------------------------------------- -// -// Save -// -//--------------------------------------------------------------------------- bool DiskCache::Save() { // Save track @@ -457,11 +411,6 @@ bool DiskCache::GetCache(int index, int& track, DWORD& aserial) const return true; } -//--------------------------------------------------------------------------- -// -// Clear -// -//--------------------------------------------------------------------------- void DiskCache::Clear() { // Free the cache @@ -473,17 +422,12 @@ void DiskCache::Clear() } } -//--------------------------------------------------------------------------- -// -// Sector Read -// -//--------------------------------------------------------------------------- -bool DiskCache::Read(BYTE *buf, int block) +bool DiskCache::ReadSector(BYTE *buf, int block) { ASSERT(sec_size != 0); // Update first - Update(); + UpdateSerialNumber(); // Calculate track (fixed to 256 sectors/track) int track = block >> 8; @@ -495,20 +439,15 @@ bool DiskCache::Read(BYTE *buf, int block) } // Read the track data to the cache - return disktrk->Read(buf, (BYTE)block); + return disktrk->ReadSector(buf, block & 0xff); } -//--------------------------------------------------------------------------- -// -// Sector write -// -//--------------------------------------------------------------------------- -bool DiskCache::Write(const BYTE *buf, int block) +bool DiskCache::WriteSector(const BYTE *buf, int block) { ASSERT(sec_size != 0); // Update first - Update(); + UpdateSerialNumber(); // Calculate track (fixed to 256 sectors/track) int track = block >> 8; @@ -520,7 +459,7 @@ bool DiskCache::Write(const BYTE *buf, int block) } // Write the data to the cache - return disktrk->Write(buf, (BYTE)block); + return disktrk->WriteSector(buf, block & 0xff); } //--------------------------------------------------------------------------- @@ -585,7 +524,6 @@ DiskTrack* DiskCache::Assign(int track) DiskTrack *disktrk = cache[c].disktrk; cache[c].disktrk = NULL; - // Load if (Load(c, track, disktrk)) { // Successful loading cache[c].serial = serial; @@ -635,12 +573,7 @@ bool DiskCache::Load(int index, int track, DiskTrack *disktrk) return true; } -//--------------------------------------------------------------------------- -// -// Update serial number -// -//--------------------------------------------------------------------------- -void DiskCache::Update() +void DiskCache::UpdateSerialNumber() { // Update and do nothing except 0 serial++; diff --git a/src/raspberrypi/devices/disk_track_cache.h b/src/raspberrypi/devices/disk_track_cache.h index e79aaae5..2c1244e0 100644 --- a/src/raspberrypi/devices/disk_track_cache.h +++ b/src/raspberrypi/devices/disk_track_cache.h @@ -49,8 +49,8 @@ public: bool Save(const Filepath& path); // Read / Write - bool Read(BYTE *buf, int sec) const; // Sector Read - bool Write(const BYTE *buf, int sec); // Sector Write + bool ReadSector(BYTE *buf, int sec) const; // Sector Read + bool WriteSector(const BYTE *buf, int sec); // Sector Write int GetTrack() const { return dt.track; } // Get track }; @@ -72,8 +72,8 @@ public: // Access bool Save(); // Save and release all - bool Read(BYTE *buf, int block); // Sector Read - bool Write(const BYTE *buf, int block); // Sector Write + bool ReadSector(BYTE *buf, int block); // Sector Read + bool WriteSector(const BYTE *buf, int block); // Sector Write bool GetCache(int index, int& track, DWORD& serial) const; // Get cache information private: @@ -81,7 +81,7 @@ private: void Clear(); // Clear all tracks DiskTrack* Assign(int track); // Load track bool Load(int index, int track, DiskTrack *disktrk = NULL); // Load track - void Update(); // Update serial number + void UpdateSerialNumber(); // Update serial number // Internal data cache_t cache[CacheMax]; // Cache management diff --git a/src/raspberrypi/devices/scsi_daynaport.cpp b/src/raspberrypi/devices/scsi_daynaport.cpp index 6a1707e3..b95b656e 100644 --- a/src/raspberrypi/devices/scsi_daynaport.cpp +++ b/src/raspberrypi/devices/scsi_daynaport.cpp @@ -212,10 +212,6 @@ int SCSIDaynaPort::Read(const DWORD *cdb, BYTE *buf, uint64_t block) s << __PRETTY_FUNCTION__ << " reading DaynaPort block " << block; LOGTRACE("%s", s.str().c_str()); - if (cdb[0] != 0x08) { - LOGERROR("Received unexpected cdb command: %02X. Expected 0x08", cdb[0]); - } - int requested_length = cdb[4]; LOGTRACE("%s Read maximum length %d, (%04X)", __PRETTY_FUNCTION__, requested_length, requested_length); diff --git a/src/raspberrypi/gpiobus.cpp b/src/raspberrypi/gpiobus.cpp index fc24ef16..5ea9ba84 100644 --- a/src/raspberrypi/gpiobus.cpp +++ b/src/raspberrypi/gpiobus.cpp @@ -27,14 +27,11 @@ //--------------------------------------------------------------------------- static DWORD get_dt_ranges(const char *filename, DWORD offset) { - DWORD address; - FILE *fp; - BYTE buf[4]; - - address = ~0; - fp = fopen(filename, "rb"); + DWORD address = ~0; + FILE *fp = fopen(filename, "rb"); if (fp) { fseek(fp, offset, SEEK_SET); + BYTE buf[4]; if (fread(buf, 1, sizeof buf, fp) == sizeof buf) { address = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3] << 0; @@ -46,9 +43,7 @@ static DWORD get_dt_ranges(const char *filename, DWORD offset) DWORD bcm_host_get_peripheral_address(void) { - DWORD address; - - address = get_dt_ranges("/proc/device-tree/soc/ranges", 4); + DWORD address = get_dt_ranges("/proc/device-tree/soc/ranges", 4); if (address == 0) { address = get_dt_ranges("/proc/device-tree/soc/ranges", 8); } @@ -429,7 +424,7 @@ void GPIOBUS::Reset() SetMode(PIN_ACK, OUT); SetMode(PIN_RST, OUT); - // Set the data bus signals to outpu + // Set the data bus signals to output SetControl(PIN_DTD, DTD_OUT); SetMode(PIN_DT0, OUT); SetMode(PIN_DT1, OUT); @@ -659,8 +654,7 @@ void GPIOBUS::SetCD(BOOL ast) //--------------------------------------------------------------------------- BOOL GPIOBUS::GetIO() { - BOOL ast; - ast = GetSignal(PIN_IO); + BOOL ast = GetSignal(PIN_IO); if (actmode == INITIATOR) { // Change the data input/output direction by IO signal @@ -757,9 +751,7 @@ void GPIOBUS::SetREQ(BOOL ast) //--------------------------------------------------------------------------- BYTE GPIOBUS::GetDAT() { - DWORD data; - - data = Aquire(); + DWORD data = Aquire(); data = ((data >> (PIN_DT0 - 0)) & (1 << 0)) | ((data >> (PIN_DT1 - 1)) & (1 << 1)) | @@ -782,9 +774,7 @@ void GPIOBUS::SetDAT(BYTE dat) { // Write to port #if SIGNAL_CONTROL_MODE == 0 - DWORD fsel; - - fsel = gpfsel[0]; + DWORD fsel = gpfsel[0]; fsel &= tblDatMsk[0][dat]; fsel |= tblDatSet[0][dat]; if (fsel != gpfsel[0]) { @@ -830,8 +820,6 @@ BOOL GPIOBUS::GetDP() //--------------------------------------------------------------------------- int GPIOBUS::CommandHandShake(BYTE *buf) { - int i; - BOOL ret; int count; // Only works in TARGET mode @@ -843,13 +831,13 @@ int GPIOBUS::CommandHandShake(BYTE *buf) DisableIRQ(); // Get the first command byte - i = 0; + int i = 0; // Assert REQ signal SetSignal(PIN_REQ, ON); // Wait for ACK signal - ret = WaitSignal(PIN_ACK, TRUE); + BOOL ret = WaitSignal(PIN_ACK, TRUE); // Wait until the signal line stabilizes SysTimer::SleepNsec(GPIO_DATA_SETTLING); @@ -1029,8 +1017,6 @@ int GPIOBUS::ReceiveHandShake(BYTE *buf, int count) int GPIOBUS::SendHandShake(BYTE *buf, int count, int delay_after_bytes) { int i; - BOOL ret; - DWORD phase; // Disable IRQs DisableIRQ(); @@ -1046,7 +1032,7 @@ int GPIOBUS::SendHandShake(BYTE *buf, int count, int delay_after_bytes) SetDAT(*buf); // Wait for ACK to clear - ret = WaitSignal(PIN_ACK, FALSE); + BOOL ret = WaitSignal(PIN_ACK, FALSE); // Check for timeout waiting for ACK to clear if (!ret) { @@ -1077,7 +1063,7 @@ int GPIOBUS::SendHandShake(BYTE *buf, int count, int delay_after_bytes) WaitSignal(PIN_ACK, FALSE); } else { // Get Phase - phase = Aquire() & GPIO_MCI; + DWORD phase = Aquire() & GPIO_MCI; for (i = 0; i < count; i++) { if(i==delay_after_bytes){ @@ -1089,7 +1075,7 @@ int GPIOBUS::SendHandShake(BYTE *buf, int count, int delay_after_bytes) SetDAT(*buf); // Wait for REQ to be asserted - ret = WaitSignal(PIN_REQ, TRUE); + BOOL ret = WaitSignal(PIN_REQ, TRUE); // Check for timeout waiting for REQ to be asserted if (!ret) { @@ -1198,8 +1184,6 @@ void GPIOBUS::MakeTable(void) int i; int j; BOOL tblParity[256]; - DWORD bits; - DWORD parity; #if SIGNAL_CONTROL_MODE == 0 int index; int shift; @@ -1210,8 +1194,8 @@ void GPIOBUS::MakeTable(void) // Create parity table for (i = 0; i < 0x100; i++) { - bits = (DWORD)i; - parity = 0; + DWORD bits = (DWORD)i; + DWORD parity = 0; for (j = 0; j < 8; j++) { parity ^= bits & 1; bits >>= 1; @@ -1226,7 +1210,7 @@ void GPIOBUS::MakeTable(void) memset(tblDatSet, 0x00, sizeof(tblDatSet)); for (i = 0; i < 0x100; i++) { // Bit string for inspection - bits = (DWORD)i; + DWORD bits = (DWORD)i; // Get parity if (tblParity[i]) { @@ -1256,7 +1240,7 @@ void GPIOBUS::MakeTable(void) memset(tblDatSet, 0x00, sizeof(tblDatSet)); for (i = 0; i < 0x100; i++) { // bit string for inspection - bits = (DWORD)i; + DWORD bits = (DWORD)i; // get parity if (tblParity[i]) { @@ -1303,19 +1287,15 @@ void GPIOBUS::SetControl(int pin, BOOL ast) //--------------------------------------------------------------------------- void GPIOBUS::SetMode(int pin, int mode) { - int index; - int shift; - DWORD data; - #if SIGNAL_CONTROL_MODE == 0 if (mode == OUT) { return; } #endif // SIGNAL_CONTROL_MODE - index = pin / 10; - shift = (pin % 10) * 3; - data = gpfsel[index]; + int index = pin / 10; + int shift = (pin % 10) * 3; + DWORD data = gpfsel[index]; data &= ~(0x7 << shift); if (mode == OUT) { data |= (1 << shift); @@ -1331,7 +1311,7 @@ void GPIOBUS::SetMode(int pin, int mode) //--------------------------------------------------------------------------- BOOL GPIOBUS::GetSignal(int pin) { - return (signals >> pin) & 1; + return (signals >> pin) & 1; } //--------------------------------------------------------------------------- @@ -1342,13 +1322,9 @@ BOOL GPIOBUS::GetSignal(int pin) void GPIOBUS::SetSignal(int pin, BOOL ast) { #if SIGNAL_CONTROL_MODE == 0 - int index; - int shift; - DWORD data; - - index = pin / 10; - shift = (pin % 10) * 3; - data = gpfsel[index]; + int index = pin / 10; + int shift = (pin % 10) * 3; + DWORD data = gpfsel[index]; if (ast) { data |= (1 << shift); } else { @@ -1378,14 +1354,11 @@ void GPIOBUS::SetSignal(int pin, BOOL ast) //--------------------------------------------------------------------------- BOOL GPIOBUS::WaitSignal(int pin, BOOL ast) { - DWORD now; - DWORD timeout; - // Get current time - now = SysTimer::GetTimerLow(); + DWORD now = SysTimer::GetTimerLow(); // Calculate timeout (3000ms) - timeout = 3000 * 1000; + DWORD timeout = 3000 * 1000; // end immediately if the signal has changed do { @@ -1454,16 +1427,13 @@ void GPIOBUS::EnableIRQ() //--------------------------------------------------------------------------- void GPIOBUS::PinConfig(int pin, int mode) { - int index; - DWORD mask; - // Check for invalid pin if (pin < 0) { return; } - index = pin / 10; - mask = ~(0x7 << ((pin % 10) * 3)); + int index = pin / 10; + DWORD mask = ~(0x7 << ((pin % 10) * 3)); gpio[index] = (gpio[index] & mask) | ((mode & 0x7) << ((pin % 10) * 3)); } @@ -1474,8 +1444,6 @@ void GPIOBUS::PinConfig(int pin, int mode) //--------------------------------------------------------------------------- void GPIOBUS::PullConfig(int pin, int mode) { - int shift; - DWORD bits; DWORD pull; // Check for invalid pin @@ -1499,8 +1467,8 @@ void GPIOBUS::PullConfig(int pin, int mode) } pin &= 0x1f; - shift = (pin & 0xf) << 1; - bits = gpio[GPIO_PUPPDN0 + (pin >> 4)]; + int shift = (pin & 0xf) << 1; + DWORD bits = gpio[GPIO_PUPPDN0 + (pin >> 4)]; bits &= ~(3 << shift); bits |= (pull << shift); gpio[GPIO_PUPPDN0 + (pin >> 4)] = bits; @@ -1541,9 +1509,7 @@ void GPIOBUS::PinSetSignal(int pin, BOOL ast) //--------------------------------------------------------------------------- void GPIOBUS::DrvConfig(DWORD drive) { - DWORD data; - - data = pads[PAD_0_27]; + DWORD data = pads[PAD_0_27]; pads[PAD_0_27] = (0xFFFFFFF8 & data) | drive | 0x5a000000; } @@ -1555,8 +1521,6 @@ void GPIOBUS::DrvConfig(DWORD drive) //--------------------------------------------------------------------------- BUS::phase_t GPIOBUS::GetPhaseRaw(DWORD raw_data) { - DWORD mci; - // Selection Phase if (GetPinRaw(raw_data, PIN_SEL)) { @@ -1573,7 +1537,7 @@ BUS::phase_t GPIOBUS::GetPhaseRaw(DWORD raw_data) } // Get target phase from bus signal line - mci = GetPinRaw(raw_data, PIN_MSG) ? 0x04 : 0x00; + DWORD mci = GetPinRaw(raw_data, PIN_MSG) ? 0x04 : 0x00; mci |= GetPinRaw(raw_data, PIN_CD) ? 0x02 : 0x00; mci |= GetPinRaw(raw_data, PIN_IO) ? 0x01 : 0x00; return GetPhase(mci); @@ -1640,7 +1604,6 @@ void SysTimer::Init(DWORD *syst, DWORD *armt) // Clock id // 0x000000004: CORE DWORD maxclock[32] = { 32, 0, 0x00030004, 8, 0, 4, 0, 0 }; - int fd; // Save the base address systaddr = syst; @@ -1651,7 +1614,7 @@ void SysTimer::Init(DWORD *syst, DWORD *armt) // Get the core frequency corefreq = 0; - fd = open("/dev/vcio", O_RDONLY); + int fd = open("/dev/vcio", O_RDONLY); if (fd >= 0) { ioctl(fd, _IOWR(100, 0, char *), maxclock); corefreq = maxclock[6] / 1000000; @@ -1684,16 +1647,13 @@ DWORD SysTimer::GetTimerHigh() { //--------------------------------------------------------------------------- void SysTimer::SleepNsec(DWORD nsec) { - DWORD diff; - DWORD start; - // If time is 0, don't do anything if (nsec == 0) { return; } // Calculate the timer difference - diff = corefreq * nsec / 1000; + DWORD diff = corefreq * nsec / 1000; // Return if the difference in time is too small if (diff == 0) { @@ -1701,7 +1661,7 @@ void SysTimer::SleepNsec(DWORD nsec) } // Start - start = armtaddr[ARMT_FREERUN]; + DWORD start = armtaddr[ARMT_FREERUN]; // Loop until timer has elapsed while ((armtaddr[ARMT_FREERUN] - start) < diff); @@ -1714,13 +1674,11 @@ void SysTimer::SleepNsec(DWORD nsec) //--------------------------------------------------------------------------- void SysTimer::SleepUsec(DWORD usec) { - DWORD now; - // If time is 0, don't do anything if (usec == 0) { return; } - now = GetTimerLow(); + DWORD now = GetTimerLow(); while ((GetTimerLow() - now) < usec); } diff --git a/src/raspberrypi/rascsi.cpp b/src/raspberrypi/rascsi.cpp index 047cab32..058dce7c 100644 --- a/src/raspberrypi/rascsi.cpp +++ b/src/raspberrypi/rascsi.cpp @@ -12,15 +12,11 @@ #include "rascsi.h" #include "os.h" -#include "filepath.h" -#include "fileio.h" #include "controllers/scsidev_ctrl.h" #include "controllers/sasidev_ctrl.h" #include "devices/device_factory.h" #include "devices/device.h" #include "devices/disk.h" -#include "devices/scsi_host_bridge.h" -#include "devices/scsi_daynaport.h" #include "devices/file_support.h" #include "gpiobus.h" #include "exceptions.h" @@ -32,16 +28,12 @@ #include "rascsi_interface.pb.h" #include "spdlog/spdlog.h" #include "spdlog/sinks/stdout_color_sinks.h" -#include -#include -#include #include #include #include #include #include #include -#include using namespace std; using namespace spdlog; @@ -607,7 +599,7 @@ bool Attach(int fd, const PbDeviceDefinition& pb_device, Device *map[], bool dry } } - // File check (type is HD, for removable media drives, CD and MO the medium (=file) may be inserted later) + // File check (type is HD, for removable media drives, CD and MO the medium (=file) may be inserted later if (file_support && !device->IsRemovable() && filename.empty()) { delete device; diff --git a/src/raspberrypi/rascsi_response.cpp b/src/raspberrypi/rascsi_response.cpp index e16e7520..7636447f 100644 --- a/src/raspberrypi/rascsi_response.cpp +++ b/src/raspberrypi/rascsi_response.cpp @@ -25,14 +25,6 @@ RascsiResponse::RascsiResponse(DeviceFactory *device_factory, const RascsiImage { this->device_factory = device_factory; this->rascsi_image = rascsi_image; - - log_levels.push_back("trace"); - log_levels.push_back("debug"); - log_levels.push_back("info"); - log_levels.push_back("warn"); - log_levels.push_back("err"); - log_levels.push_back("critical"); - log_levels.push_back("off"); } PbDeviceProperties *RascsiResponse::GetDeviceProperties(const Device *device) diff --git a/src/raspberrypi/rascsi_response.h b/src/raspberrypi/rascsi_response.h index 12f4ea44..a4c7893a 100644 --- a/src/raspberrypi/rascsi_response.h +++ b/src/raspberrypi/rascsi_response.h @@ -45,7 +45,7 @@ private: DeviceFactory *device_factory; const RascsiImage *rascsi_image; - vector log_levels; + vector log_levels { "trace", "debug", "info", "warn", "err", "critical", "off" }; PbDeviceProperties *GetDeviceProperties(const Device *); void GetDevice(const Device *, PbDevice *); diff --git a/src/raspberrypi/rascsi_version.cpp b/src/raspberrypi/rascsi_version.cpp index c9630bb8..7bf1393c 100644 --- a/src/raspberrypi/rascsi_version.cpp +++ b/src/raspberrypi/rascsi_version.cpp @@ -9,8 +9,7 @@ //--------------------------------------------------------------------------- #include "rascsi_version.h" -#include -#include +#include // The following should be updated for each release const int rascsi_major_version = 21; // Last two digits of year diff --git a/src/raspberrypi/rasctl.cpp b/src/raspberrypi/rasctl.cpp index f811cc0c..f49c0061 100644 --- a/src/raspberrypi/rasctl.cpp +++ b/src/raspberrypi/rasctl.cpp @@ -65,30 +65,30 @@ PbDeviceType ParseType(const char *optarg) if (PbDeviceType_Parse(t, &type)) { return type; } - else { - // Parse convenience device types (shortcuts) - switch (tolower(optarg[0])) { - case 'c': - return SCCD; - case 'b': - return SCBR; + // Parse convenience device types (shortcuts) + switch (tolower(optarg[0])) { + case 'c': + return SCCD; - case 'd': - return SCDP; + case 'b': + return SCBR; - case 'h': - return SCHD; + case 'd': + return SCDP; - case 'm': - return SCMO; + case 'h': + return SCHD; - case 'r': - return SCRM; - } + case 'm': + return SCMO; + + case 'r': + return SCRM; + + default: + return UNDEFINED; } - - return UNDEFINED; } int main(int argc, char* argv[]) diff --git a/src/raspberrypi/rasctl_display.cpp b/src/raspberrypi/rasctl_display.cpp index d9e6036c..6d3e2da3 100644 --- a/src/raspberrypi/rasctl_display.cpp +++ b/src/raspberrypi/rasctl_display.cpp @@ -118,10 +118,10 @@ void RasctlDisplay::DisplayLogLevelInfo(const PbLogLevelInfo& log_level_info) void RasctlDisplay::DisplayDeviceTypesInfo(const PbDeviceTypesInfo& device_types_info) { cout << "Supported device types and their properties:" << endl; - for (auto it = device_types_info.properties().begin(); it != device_types_info.properties().end(); ++it) { - cout << " " << PbDeviceType_Name(it->type()); + for (const auto& device_type_info : device_types_info.properties()) { + cout << " " << PbDeviceType_Name(device_type_info.type()); - const PbDeviceProperties& properties = it->properties(); + const PbDeviceProperties& properties = device_type_info.properties(); cout << " Supported LUN numbers: 0"; if (properties.luns() > 1) { @@ -163,6 +163,7 @@ void RasctlDisplay::DisplayDeviceTypesInfo(const PbDeviceTypesInfo& device_types } if (properties.supports_params() && properties.default_params_size()) { + // Creates a sorted map map params = { properties.default_params().begin(), properties.default_params().end() }; cout << " Default parameters: "; @@ -180,6 +181,7 @@ void RasctlDisplay::DisplayDeviceTypesInfo(const PbDeviceTypesInfo& device_types } if (properties.block_sizes_size()) { + // Creates a sorted set set block_sizes = { properties.block_sizes().begin(), properties.block_sizes().end() }; cout << " Configurable block sizes in bytes: "; @@ -227,27 +229,26 @@ void RasctlDisplay::DisplayImageFile(const PbImageFile& image_file_info) void RasctlDisplay::DisplayImageFiles(const PbImageFilesInfo& image_files_info) { - const list image_files = { image_files_info.image_files().begin(), image_files_info.image_files().end() }; - cout << "Default image file folder: " << image_files_info.default_image_folder() << endl; - if (image_files.empty()) { + if (image_files_info.image_files().empty()) { cout << " No image files available" << endl; } else { - list files = { image_files.begin(), image_files.end() }; - files.sort([](const auto& a, const auto& b) { return a.name() < b.name(); }); + list image_files = { image_files_info.image_files().begin(), image_files_info.image_files().end() }; + image_files.sort([](const auto& a, const auto& b) { return a.name() < b.name(); }); cout << "Available image files:" << endl; - for (const auto& file : files) { + for (const auto& image_file : image_files) { cout << " "; - DisplayImageFile(file); + DisplayImageFile(image_file); } } } void RasctlDisplay::DisplayNetworkInterfaces(const PbNetworkInterfacesInfo& network_interfaces_info) { + // Creates a sorted list const list interfaces = { network_interfaces_info.name().begin(), network_interfaces_info.name().end() }; cout << "Available (up) network interfaces:" << endl; @@ -264,6 +265,7 @@ void RasctlDisplay::DisplayNetworkInterfaces(const PbNetworkInterfacesInfo& netw void RasctlDisplay::DisplayMappingInfo(const PbMappingInfo& mapping_info) { + // Creates a sorted map const map mappings = { mapping_info.mapping().begin(), mapping_info.mapping().end() }; cout << "Supported image file extension to device type mappings:" << endl; diff --git a/src/raspberrypi/rasdump.cpp b/src/raspberrypi/rasdump.cpp index f5dcb0e7..0a92351f 100644 --- a/src/raspberrypi/rasdump.cpp +++ b/src/raspberrypi/rasdump.cpp @@ -9,7 +9,7 @@ // //--------------------------------------------------------------------------- -#include +#include #include "os.h" #include "fileio.h" #include "filepath.h" diff --git a/src/raspberrypi/sasidump.cpp b/src/raspberrypi/sasidump.cpp index 847945a4..c0d3ac0f 100644 --- a/src/raspberrypi/sasidump.cpp +++ b/src/raspberrypi/sasidump.cpp @@ -18,7 +18,7 @@ // //--------------------------------------------------------------------------- -#include +#include #include "os.h" #include "fileio.h" #include "filepath.h" diff --git a/src/raspberrypi/scsimon.cpp b/src/raspberrypi/scsimon.cpp index 06dc79b3..96c0c496 100644 --- a/src/raspberrypi/scsimon.cpp +++ b/src/raspberrypi/scsimon.cpp @@ -5,14 +5,12 @@ // // Powered by XM6 TypeG Technology. // Copyright (C) 2016-2020 GIMONS -// [ RaSCSI main ] // //--------------------------------------------------------------------------- #include "os.h" #include "filepath.h" #include "fileio.h" -#include "devices/disk.h" #include "log.h" #include "gpiobus.h" #include "rascsi_version.h" @@ -20,8 +18,11 @@ #include #include #include +#include #include "rascsi.h" +using namespace std; + //--------------------------------------------------------------------------- // // Constant declarations @@ -117,7 +118,7 @@ void Banner(int argc, char* argv[]) // Initialization // //--------------------------------------------------------------------------- -BOOL Init() +bool Init() { // Interrupt handler settings if (signal(SIGINT, KillHandler) == SIG_ERR) { @@ -130,13 +131,11 @@ BOOL Init() return FALSE; } - // GPIOBUS creation - bus = new GPIOBUS(); - // GPIO Initialization + bus = new GPIOBUS(); if (!bus->Init()) { LOGERROR("Unable to intiailize the GPIO bus. Exiting...."); - return FALSE; + return false; } // Bus Reset @@ -145,18 +144,17 @@ BOOL Init() // Other running = false; - return TRUE; + return true; } BOOL get_pin_value(DWORD data, int pin) { - return (data >> pin) & 1; + return (data >> pin) & 1; } BYTE get_data_field(DWORD data) { - DWORD data_out; - data_out = + DWORD data_out = ((data >> (PIN_DT0 - 0)) & (1 << 7)) | ((data >> (PIN_DT1 - 1)) & (1 << 6)) | ((data >> (PIN_DT2 - 2)) & (1 << 5)) | @@ -172,7 +170,7 @@ BYTE get_data_field(DWORD data) void vcd_output_if_changed_phase(FILE *fp, DWORD data, int pin, char symbol) { BUS::phase_t new_value = GPIOBUS::GetPhaseRaw(data); - if(prev_value[pin] != new_value) + if (prev_value[pin] != new_value) { prev_value[pin] = new_value; fprintf(fp, "s%s %c\n", GPIOBUS::GetPhaseStrRaw(new_value), symbol); @@ -182,7 +180,7 @@ void vcd_output_if_changed_phase(FILE *fp, DWORD data, int pin, char symbol) void vcd_output_if_changed_bool(FILE *fp, DWORD data, int pin, char symbol) { BOOL new_value = get_pin_value(data,pin); - if(prev_value[pin] != new_value) + if (prev_value[pin] != new_value) { prev_value[pin] = new_value; fprintf(fp, "%d%c\n", new_value, symbol); @@ -207,21 +205,16 @@ void vcd_output_if_changed_byte(FILE *fp, DWORD data, int pin, char symbol) } } - - void create_value_change_dump() { - time_t rawtime; - struct tm * timeinfo; - DWORD i = 0; - char timestamp[256]; - FILE *fp; LOGINFO("Creating Value Change Dump file (%s)", log_file_name); - fp = fopen(log_file_name,"w"); + FILE *fp = fopen(log_file_name,"w"); // Get the current time - time (&rawtime); - timeinfo = localtime(&rawtime); + time_t rawtime; + time(&rawtime); + struct tm *timeinfo = localtime(&rawtime); + char timestamp[256]; strftime (timestamp,sizeof(timestamp),"%d-%m-%Y %H-%M-%S",timeinfo); fprintf(fp, "$date\n"); @@ -263,7 +256,8 @@ void create_value_change_dump() fprintf(fp, "b00000000 %c\n", SYMBOL_PIN_DAT); fprintf(fp, "$end\n"); - while(i < data_idx) + DWORD i = 0; + while (i < data_idx) { ostringstream s; s << (uint64_t)(data_buffer[i].timestamp*ns_per_loop); @@ -284,32 +278,17 @@ void create_value_change_dump() fclose(fp); } - - -//--------------------------------------------------------------------------- -// -// Cleanup -// -//--------------------------------------------------------------------------- void Cleanup() { - LOGINFO("Stopping data collection...."); create_value_change_dump(); // Cleanup the Bus bus->Cleanup(); - // Discard the GPIOBUS object delete bus; - } -//--------------------------------------------------------------------------- -// -// Reset -// -//--------------------------------------------------------------------------- void Reset() { // Reset the bus @@ -323,13 +302,11 @@ void Reset() //--------------------------------------------------------------------------- void FixCpu(int cpu) { - cpu_set_t cpuset; - int cpus; - // Get the number of CPUs + cpu_set_t cpuset; CPU_ZERO(&cpuset); sched_getaffinity(0, sizeof(cpu_set_t), &cpuset); - cpus = CPU_COUNT(&cpuset); + int cpus = CPU_COUNT(&cpuset); // Set the thread affinity if (cpu < cpus) { @@ -359,7 +336,6 @@ int main(int argc, char* argv[]) #endif DWORD prev_sample = 0xFFFFFFFF; DWORD this_sample = 0; - int ret; struct sched_param schparam; timeval start_time, stop_time; uint64_t loop_count = 0; @@ -395,7 +371,7 @@ int main(int argc, char* argv[]) memset(data_buffer,0,sizeof(data_buffer)); // Initialize - ret = 0; + int ret = 0; if (!Init()) { ret = EPERM; goto init_exit; @@ -424,18 +400,18 @@ int main(int argc, char* argv[]) // Work initialization this_sample = (bus->Aquire() & ALL_SCSI_PINS); loop_count++; - if(loop_count > LLONG_MAX -1) + if (loop_count > LLONG_MAX -1) { LOGINFO("Maximum amount of time has elapsed. SCSIMON is terminating."); running=false; } - if(data_idx >= (MAX_BUFF_SIZE-2)) + if (data_idx >= (MAX_BUFF_SIZE-2)) { LOGINFO("Internal data buffer is full. SCSIMON is terminating."); running=false; } - if(this_sample != prev_sample) + if (this_sample != prev_sample) { #ifdef DEBUG @@ -465,7 +441,7 @@ int main(int argc, char* argv[]) } // Collect one last sample, otherwise it looks like the end of the data was cut off - if(data_idx < MAX_BUFF_SIZE) + if (data_idx < MAX_BUFF_SIZE) { data_buffer[data_idx].data = this_sample; data_buffer[data_idx].timestamp = loop_count; @@ -490,7 +466,6 @@ int main(int argc, char* argv[]) s << "Read the SCSI bus " << loop_count << " times with an average of " << ns_per_loop << " ns for each read"; LOGINFO("%s", s.str().c_str()); - // Cleanup Cleanup(); init_exit: