mirror of
https://github.com/akuker/RASCSI.git
synced 2025-08-05 01:27:46 +00:00
Code cleanup, especially casts, lambdas, data types, encapsulation (#952)
* Unit test updates * Lambda syntax cleanup * Use new-style casts * Use std::none_of when saving the cache * Use to_integer instead of casts * Use accessors for getting CDB data * Made ctrl_t private * Improved encapsulation * Replaced pointers by references * Removed all remaining occurrences of DWORD and BYTE, making os.h obsolete
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
#include "hal/sbc_version.h"
|
||||
#include "hal/systimer.h"
|
||||
#include "log.h"
|
||||
#include "os.h"
|
||||
#include <array>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
@@ -432,7 +431,7 @@ bool GPIOBUS::GetDP() const
|
||||
// Receive command handshake
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
int GPIOBUS::CommandHandShake(BYTE *buf)
|
||||
int GPIOBUS::CommandHandShake(uint8_t *buf)
|
||||
{
|
||||
GPIO_FUNCTION_TRACE
|
||||
// Only works in TARGET mode
|
||||
@@ -555,7 +554,7 @@ int GPIOBUS::CommandHandShake(BYTE *buf)
|
||||
// Data reception handshake
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
int GPIOBUS::ReceiveHandShake(BYTE *buf, int count)
|
||||
int GPIOBUS::ReceiveHandShake(uint8_t *buf, int count)
|
||||
{
|
||||
GPIO_FUNCTION_TRACE
|
||||
|
||||
@@ -657,7 +656,7 @@ int GPIOBUS::ReceiveHandShake(BYTE *buf, int count)
|
||||
// Data transmission handshake
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
int GPIOBUS::SendHandShake(BYTE *buf, int count, int delay_after_bytes)
|
||||
int GPIOBUS::SendHandShake(uint8_t *buf, int count, int delay_after_bytes)
|
||||
{
|
||||
GPIO_FUNCTION_TRACE
|
||||
|
||||
@@ -973,7 +972,7 @@ BUS::phase_t GPIOBUS::GetPhaseRaw(uint32_t raw_data)
|
||||
// Get the number of bytes for a command
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
int GPIOBUS::GetCommandByteCount(BYTE opcode)
|
||||
int GPIOBUS::GetCommandByteCount(uint8_t opcode)
|
||||
{
|
||||
GPIO_FUNCTION_TRACE
|
||||
|
||||
|
@@ -332,17 +332,17 @@ class GPIOBUS : public BUS
|
||||
// Set REQ signal
|
||||
bool GetDP() const override;
|
||||
// Get Data parity signal
|
||||
int CommandHandShake(BYTE *buf) override;
|
||||
int CommandHandShake(uint8_t *buf) override;
|
||||
// Command receive handshake
|
||||
int ReceiveHandShake(BYTE *buf, int count) override;
|
||||
int ReceiveHandShake(uint8_t *buf, int count) override;
|
||||
// Data receive handshake
|
||||
int SendHandShake(BYTE *buf, int count, int delay_after_bytes) override;
|
||||
int SendHandShake(uint8_t *buf, int count, int delay_after_bytes) override;
|
||||
// Data transmission handshake
|
||||
|
||||
static BUS::phase_t GetPhaseRaw(uint32_t raw_data);
|
||||
// Get the phase based on raw data
|
||||
|
||||
static int GetCommandByteCount(BYTE opcode);
|
||||
static int GetCommandByteCount(uint8_t opcode);
|
||||
|
||||
#ifdef USE_SEL_EVENT_ENABLE
|
||||
// SEL signal interrupt
|
||||
|
@@ -34,13 +34,13 @@ void GPIOBUS_Allwinner::Cleanup()
|
||||
|
||||
void GPIOBUS_Allwinner::Reset(){LOGWARN("%s NOT IMPLEMENTED", __PRETTY_FUNCTION__)}
|
||||
|
||||
BYTE GPIOBUS_Allwinner::GetDAT()
|
||||
uint8_t GPIOBUS_Allwinner::GetDAT()
|
||||
{
|
||||
LOGWARN("%s NOT IMPLEMENTED", __PRETTY_FUNCTION__)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GPIOBUS_Allwinner::SetDAT(BYTE dat)
|
||||
void GPIOBUS_Allwinner::SetDAT(uint8_t dat)
|
||||
{
|
||||
LOGWARN("%s NOT IMPLEMENTED", __PRETTY_FUNCTION__)
|
||||
}
|
||||
@@ -103,7 +103,7 @@ void GPIOBUS_Allwinner::PinSetSignal(int pin, bool ast)
|
||||
LOGWARN("%s NOT IMPLEMENTED", __PRETTY_FUNCTION__)
|
||||
}
|
||||
|
||||
void GPIOBUS_Allwinner::DrvConfig(DWORD drive)
|
||||
void GPIOBUS_Allwinner::DrvConfig(uint32_t drive)
|
||||
{
|
||||
(void)drive;
|
||||
LOGERROR("%s not implemented!!", __PRETTY_FUNCTION__)
|
||||
|
@@ -42,9 +42,9 @@ class GPIOBUS_Allwinner : public GPIOBUS
|
||||
//---------------------------------------------------------------------------
|
||||
uint32_t Acquire() override;
|
||||
|
||||
BYTE GetDAT() override;
|
||||
uint8_t GetDAT() override;
|
||||
// Get DAT signal
|
||||
void SetDAT(BYTE dat) override;
|
||||
void SetDAT(uint8_t dat) override;
|
||||
// Set DAT signal
|
||||
protected:
|
||||
// SCSI I/O signal control
|
||||
@@ -73,7 +73,7 @@ class GPIOBUS_Allwinner : public GPIOBUS
|
||||
// GPIO pin pull up/down resistor setting
|
||||
void PinSetSignal(int pin, bool ast) override;
|
||||
// Set GPIO output signal
|
||||
void DrvConfig(DWORD drive) override;
|
||||
void DrvConfig(uint32_t drive) override;
|
||||
// Set GPIO drive strength
|
||||
|
||||
#if !defined(__x86_64__) && !defined(__X86__)
|
||||
|
@@ -17,7 +17,6 @@
|
||||
#include "hal/gpiobus_raspberry.h"
|
||||
#include "hal/systimer.h"
|
||||
#include "log.h"
|
||||
#include "os.h"
|
||||
#include <string.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/ioctl.h>
|
||||
@@ -36,7 +35,7 @@ static uint32_t get_dt_ranges(const char *filename, uint32_t offset)
|
||||
uint32_t address = ~0;
|
||||
if (FILE *fp = fopen(filename, "rb"); fp) {
|
||||
fseek(fp, offset, SEEK_SET);
|
||||
if (array<BYTE, 4> buf; fread(buf.data(), 1, buf.size(), fp) == buf.size()) {
|
||||
if (array<uint8_t, 4> buf; fread(buf.data(), 1, buf.size(), fp) == buf.size()) {
|
||||
address = (int)buf[0] << 24 | (int)buf[1] << 16 | (int)buf[2] << 8 | (int)buf[3] << 0;
|
||||
}
|
||||
fclose(fp);
|
||||
@@ -453,7 +452,7 @@ void GPIOBUS_Raspberry::Reset()
|
||||
// Get data signals
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
BYTE GPIOBUS_Raspberry::GetDAT()
|
||||
uint8_t GPIOBUS_Raspberry::GetDAT()
|
||||
{
|
||||
GPIO_FUNCTION_TRACE
|
||||
uint32_t data = Acquire();
|
||||
@@ -461,7 +460,7 @@ BYTE GPIOBUS_Raspberry::GetDAT()
|
||||
((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));
|
||||
return (BYTE)data;
|
||||
return (uint8_t)data;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -469,7 +468,7 @@ BYTE GPIOBUS_Raspberry::GetDAT()
|
||||
// Set data signals
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
void GPIOBUS_Raspberry::SetDAT(BYTE dat)
|
||||
void GPIOBUS_Raspberry::SetDAT(uint8_t dat)
|
||||
{
|
||||
GPIO_FUNCTION_TRACE
|
||||
// Write to port
|
||||
|
@@ -42,9 +42,9 @@ class GPIOBUS_Raspberry final : public GPIOBUS
|
||||
//---------------------------------------------------------------------------
|
||||
uint32_t Acquire() override;
|
||||
|
||||
BYTE GetDAT() override;
|
||||
uint8_t GetDAT() override;
|
||||
// Get DAT signal
|
||||
void SetDAT(BYTE dat) override;
|
||||
void SetDAT(uint8_t dat) override;
|
||||
// Set DAT signal
|
||||
private:
|
||||
// SCSI I/O signal control
|
||||
|
@@ -161,13 +161,13 @@ bool SBC_Version::IsBananaPi()
|
||||
|
||||
// The following functions are only used on the Raspberry Pi
|
||||
// (imported from bcm_host.c)
|
||||
DWORD SBC_Version::GetDeviceTreeRanges(const char *filename, DWORD offset)
|
||||
uint32_t SBC_Version::GetDeviceTreeRanges(const char *filename, uint32_t offset)
|
||||
{
|
||||
LOGTRACE("%s", __PRETTY_FUNCTION__)
|
||||
DWORD address = ~0;
|
||||
uint32_t address = ~0;
|
||||
if (FILE *fp = fopen(filename, "rb"); fp) {
|
||||
fseek(fp, offset, SEEK_SET);
|
||||
if (std::array<BYTE, 4> buf; fread(buf.data(), 1, buf.size(), fp) == buf.size()) {
|
||||
if (std::array<uint8_t, 4> buf; fread(buf.data(), 1, buf.size(), fp) == buf.size()) {
|
||||
address = (int)buf[0] << 24 | (int)buf[1] << 16 | (int)buf[2] << 8 | (int)buf[3] << 0;
|
||||
}
|
||||
fclose(fp);
|
||||
@@ -176,25 +176,25 @@ DWORD SBC_Version::GetDeviceTreeRanges(const char *filename, DWORD offset)
|
||||
}
|
||||
|
||||
#if defined __linux__
|
||||
DWORD SBC_Version::GetPeripheralAddress(void)
|
||||
uint32_t SBC_Version::GetPeripheralAddress(void)
|
||||
{
|
||||
LOGTRACE("%s", __PRETTY_FUNCTION__)
|
||||
DWORD address = GetDeviceTreeRanges("/proc/device-tree/soc/ranges", 4);
|
||||
uint32_t address = GetDeviceTreeRanges("/proc/device-tree/soc/ranges", 4);
|
||||
if (address == 0) {
|
||||
address = GetDeviceTreeRanges("/proc/device-tree/soc/ranges", 8);
|
||||
}
|
||||
address = (address == (DWORD)~0) ? 0x20000000 : address;
|
||||
address = (address == (uint32_t)~0) ? 0x20000000 : address;
|
||||
|
||||
LOGDEBUG("Peripheral address : 0x%8x\n", address)
|
||||
|
||||
return address;
|
||||
}
|
||||
#elif defined __NetBSD__
|
||||
DWORD SBC_Version::GetPeripheralAddress(void)
|
||||
uint32_t SBC_Version::GetPeripheralAddress(void)
|
||||
{
|
||||
char buf[1024];
|
||||
size_t len = sizeof(buf);
|
||||
DWORD address;
|
||||
uint32_t address;
|
||||
|
||||
if (sysctlbyname("hw.model", buf, &len, NULL, 0) || strstr(buf, "ARM1176JZ-S") != buf) {
|
||||
// Failed to get CPU model || Not BCM2835
|
||||
@@ -208,7 +208,7 @@ DWORD SBC_Version::GetPeripheralAddress(void)
|
||||
return address;
|
||||
}
|
||||
#else
|
||||
DWORD SBC_Version::GetPeripheralAddress(void)
|
||||
uint32_t SBC_Version::GetPeripheralAddress(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
#include "os.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
@@ -47,7 +47,7 @@ class SBC_Version
|
||||
|
||||
static const std::string *GetString();
|
||||
|
||||
static DWORD GetPeripheralAddress();
|
||||
static uint32_t GetPeripheralAddress();
|
||||
|
||||
private:
|
||||
static sbc_version_type m_sbc_version;
|
||||
@@ -66,5 +66,5 @@ class SBC_Version
|
||||
|
||||
static const std::string m_device_tree_model_path;
|
||||
|
||||
static DWORD GetDeviceTreeRanges(const char *filename, DWORD offset);
|
||||
};
|
||||
static uint32_t GetDeviceTreeRanges(const char *filename, uint32_t offset);
|
||||
};
|
||||
|
@@ -18,7 +18,6 @@
|
||||
|
||||
#include "hal/gpiobus.h"
|
||||
#include "hal/sbc_version.h"
|
||||
#include "os.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
|
@@ -13,7 +13,6 @@
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "hal/gpiobus.h"
|
||||
#include "os.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
@@ -99,14 +98,14 @@ void SysTimer_AllWinner::disable_hs_timer()
|
||||
sysbus_regs->bus_soft_rst_reg0)
|
||||
}
|
||||
|
||||
DWORD SysTimer_AllWinner::GetTimerLow()
|
||||
uint32_t SysTimer_AllWinner::GetTimerLow()
|
||||
{
|
||||
// RaSCSI expects the timer to count UP, but the Allwinner HS timer counts
|
||||
// down. So, we subtract the current timer value from UINT32_MAX
|
||||
return UINT32_MAX - (hsitimer_regs->hs_tmr_curnt_lo_reg / 200);
|
||||
}
|
||||
|
||||
DWORD SysTimer_AllWinner::GetTimerHigh()
|
||||
uint32_t SysTimer_AllWinner::GetTimerHigh()
|
||||
{
|
||||
return (uint32_t)0;
|
||||
}
|
||||
@@ -116,7 +115,7 @@ DWORD SysTimer_AllWinner::GetTimerHigh()
|
||||
// Sleep in nanoseconds
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
void SysTimer_AllWinner::SleepNsec(DWORD nsec)
|
||||
void SysTimer_AllWinner::SleepNsec(uint32_t nsec)
|
||||
{
|
||||
// If time is less than one HS timer clock tick, don't do anything
|
||||
if (nsec < 20) {
|
||||
@@ -127,7 +126,7 @@ void SysTimer_AllWinner::SleepNsec(DWORD nsec)
|
||||
// one clock tick every 5 ns.
|
||||
auto clockticks = (uint32_t)std::ceil(nsec / 5);
|
||||
|
||||
DWORD enter_time = hsitimer_regs->hs_tmr_curnt_lo_reg;
|
||||
uint32_t enter_time = hsitimer_regs->hs_tmr_curnt_lo_reg;
|
||||
|
||||
LOGTRACE("%s entertime: %08X ns: %d clockticks: %d", __PRETTY_FUNCTION__, enter_time, nsec, clockticks)
|
||||
while ((enter_time - hsitimer_regs->hs_tmr_curnt_lo_reg) < clockticks)
|
||||
@@ -141,7 +140,7 @@ void SysTimer_AllWinner::SleepNsec(DWORD nsec)
|
||||
// Sleep in microseconds
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
void SysTimer_AllWinner::SleepUsec(DWORD usec)
|
||||
void SysTimer_AllWinner::SleepUsec(uint32_t usec)
|
||||
{
|
||||
LOGTRACE("%s", __PRETTY_FUNCTION__)
|
||||
|
||||
@@ -150,7 +149,7 @@ void SysTimer_AllWinner::SleepUsec(DWORD usec)
|
||||
return;
|
||||
}
|
||||
|
||||
DWORD enter_time = GetTimerLow();
|
||||
uint32_t enter_time = GetTimerLow();
|
||||
while ((GetTimerLow() - enter_time) < usec)
|
||||
;
|
||||
}
|
||||
|
@@ -18,7 +18,6 @@
|
||||
|
||||
#include "hal/gpiobus.h"
|
||||
#include "hal/sbc_version.h"
|
||||
#include "os.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
@@ -69,8 +68,8 @@ void SysTimer_Raspberry::Init()
|
||||
std::array<uint32_t, 32> maxclock = {32, 0, 0x00030004, 8, 0, 4, 0, 0};
|
||||
|
||||
// Save the base address
|
||||
systaddr = (DWORD *)map + SYST_OFFSET / sizeof(DWORD);
|
||||
armtaddr = (DWORD *)map + ARMT_OFFSET / sizeof(DWORD);
|
||||
systaddr = (uint32_t *)map + SYST_OFFSET / sizeof(uint32_t);
|
||||
armtaddr = (uint32_t *)map + ARMT_OFFSET / sizeof(uint32_t);
|
||||
|
||||
// Change the ARM timer to free run mode
|
||||
armtaddr[ARMT_CTRL] = 0x00000282;
|
||||
@@ -88,7 +87,7 @@ void SysTimer_Raspberry::Init()
|
||||
// Get system timer low byte
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
DWORD SysTimer_Raspberry::GetTimerLow()
|
||||
uint32_t SysTimer_Raspberry::GetTimerLow()
|
||||
{
|
||||
return systaddr[SYST_CLO];
|
||||
}
|
||||
@@ -98,7 +97,7 @@ DWORD SysTimer_Raspberry::GetTimerLow()
|
||||
// Get system timer high byte
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
DWORD SysTimer_Raspberry::GetTimerHigh()
|
||||
uint32_t SysTimer_Raspberry::GetTimerHigh()
|
||||
{
|
||||
return systaddr[SYST_CHI];
|
||||
}
|
||||
@@ -108,7 +107,7 @@ DWORD SysTimer_Raspberry::GetTimerHigh()
|
||||
// Sleep in nanoseconds
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
void SysTimer_Raspberry::SleepNsec(DWORD nsec)
|
||||
void SysTimer_Raspberry::SleepNsec(uint32_t nsec)
|
||||
{
|
||||
// If time is 0, don't do anything
|
||||
if (nsec == 0) {
|
||||
@@ -116,7 +115,7 @@ void SysTimer_Raspberry::SleepNsec(DWORD nsec)
|
||||
}
|
||||
|
||||
// Calculate the timer difference
|
||||
DWORD diff = corefreq * nsec / 1000;
|
||||
uint32_t diff = corefreq * nsec / 1000;
|
||||
|
||||
// Return if the difference in time is too small
|
||||
if (diff == 0) {
|
||||
@@ -124,7 +123,7 @@ void SysTimer_Raspberry::SleepNsec(DWORD nsec)
|
||||
}
|
||||
|
||||
// Start
|
||||
DWORD start = armtaddr[ARMT_FREERUN];
|
||||
uint32_t start = armtaddr[ARMT_FREERUN];
|
||||
|
||||
// Loop until timer has elapsed
|
||||
while ((armtaddr[ARMT_FREERUN] - start) < diff)
|
||||
@@ -136,14 +135,14 @@ void SysTimer_Raspberry::SleepNsec(DWORD nsec)
|
||||
// Sleep in microseconds
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
void SysTimer_Raspberry::SleepUsec(DWORD usec)
|
||||
void SysTimer_Raspberry::SleepUsec(uint32_t usec)
|
||||
{
|
||||
// If time is 0, don't do anything
|
||||
if (usec == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
DWORD now = GetTimerLow();
|
||||
uint32_t now = GetTimerLow();
|
||||
while ((GetTimerLow() - now) < usec)
|
||||
;
|
||||
}
|
||||
|
Reference in New Issue
Block a user