This commit is contained in:
Tony Kuker 2022-09-10 20:48:09 +00:00
parent 4bf0416ab4
commit 0134b81061
6 changed files with 63 additions and 89 deletions

View File

@ -131,10 +131,10 @@ bool GPIOBUS::Init(mode_e mode)
pads = (DWORD *)map;
pads += PADS_OFFSET / sizeof(DWORD);
// System timer
SysTimer::Init(
(DWORD *)map + SYST_OFFSET / sizeof(DWORD),
(DWORD *)map + ARMT_OFFSET / sizeof(DWORD));
// // System timer
// SysTimer::Init(
// (DWORD *)map + SYST_OFFSET / sizeof(DWORD),
// (DWORD *)map + ARMT_OFFSET / sizeof(DWORD));
// Interrupt controller
irpctl = (DWORD *)map;
@ -705,7 +705,7 @@ int GPIOBUS::CommandHandShake(BYTE *buf)
bool ret = WaitSignal(PIN_ACK, TRUE);
// Wait until the signal line stabilizes
SysTimer::instance.SleepNsec(SCSI_DELAY_BUS_SETTLE_DELAY_NS);
SysTimer::instance().SleepNsec(SCSI_DELAY_BUS_SETTLE_DELAY_NS);
// Get data
*buf = GetDAT();
@ -742,7 +742,7 @@ int GPIOBUS::CommandHandShake(BYTE *buf)
ret = WaitSignal(PIN_ACK, TRUE);
SysTimer::instance.SleepNsec(SCSI_DELAY_BUS_SETTLE_DELAY_NS);
SysTimer::instance().SleepNsec(SCSI_DELAY_BUS_SETTLE_DELAY_NS);
// Get the actual SCSI command
*buf = GetDAT();
@ -776,7 +776,7 @@ int GPIOBUS::CommandHandShake(BYTE *buf)
ret = WaitSignal(PIN_ACK, TRUE);
// Wait until the signal line stabilizes
SysTimer::instance.SleepNsec(SCSI_DELAY_BUS_SETTLE_DELAY_NS);
SysTimer::instance().SleepNsec(SCSI_DELAY_BUS_SETTLE_DELAY_NS);
// Get data
*buf = GetDAT();
@ -827,7 +827,7 @@ int GPIOBUS::ReceiveHandShake(BYTE *buf, int count)
bool ret = WaitSignal(PIN_ACK, TRUE);
// Wait until the signal line stabilizes
SysTimer::instance.SleepNsec(SCSI_DELAY_BUS_SETTLE_DELAY_NS);
SysTimer::instance().SleepNsec(SCSI_DELAY_BUS_SETTLE_DELAY_NS);
// Get data
*buf = GetDAT();
@ -870,7 +870,7 @@ int GPIOBUS::ReceiveHandShake(BYTE *buf, int count)
}
// Wait until the signal line stabilizes
SysTimer::instance.SleepNsec(SCSI_DELAY_BUS_SETTLE_DELAY_NS);
SysTimer::instance()->SleepNsec(SCSI_DELAY_BUS_SETTLE_DELAY_NS);
// Get data
*buf = GetDAT();
@ -922,7 +922,7 @@ int GPIOBUS::SendHandShake(BYTE *buf, int count, int delay_after_bytes)
for (i = 0; i < count; i++) {
if(i==delay_after_bytes){
LOGTRACE("%s DELAYING for %dus after %d bytes", __PRETTY_FUNCTION__, SCSI_DELAY_SEND_DATA_DAYNAPORT_US, (int)delay_after_bytes)
SysTimer::instance.SleepUsec(SCSI_DELAY_SEND_DATA_DAYNAPORT_US);
SysTimer::instance()->SleepUsec(SCSI_DELAY_SEND_DATA_DAYNAPORT_US);
}
// Set the DATA signals
@ -965,7 +965,7 @@ int GPIOBUS::SendHandShake(BYTE *buf, int count, int delay_after_bytes)
for (i = 0; i < count; i++) {
if(i==delay_after_bytes){
LOGTRACE("%s DELAYING for %dus after %d bytes", __PRETTY_FUNCTION__, SCSI_DELAY_SEND_DATA_DAYNAPORT_US, (int)delay_after_bytes)
SysTimer::instance.SleepUsec(SCSI_DELAY_SEND_DATA_DAYNAPORT_US);
SysTimer::instance()->SleepUsec(SCSI_DELAY_SEND_DATA_DAYNAPORT_US);
}
// Set the DATA signals
@ -1252,7 +1252,7 @@ void GPIOBUS::SetSignal(int pin, bool ast)
bool GPIOBUS::WaitSignal(int pin, BOOL ast)
{
// Get current time
DWORD now = SysTimer::GetTimerLow();
DWORD now = SysTimer::instance()->GetTimerLow();
// Calculate timeout (3000ms)
DWORD timeout = 3000 * 1000;
@ -1269,7 +1269,7 @@ bool GPIOBUS::WaitSignal(int pin, BOOL ast)
if (((signals >> pin) ^ ~ast) & 1) {
return true;
}
} while ((SysTimer::GetTimerLow() - now) < timeout);
} while ((SysTimer::instance()->GetTimerLow() - now) < timeout);
// We timed out waiting for the signal
return false;

View File

@ -98,7 +98,7 @@ void SBC_Version::Init(){
str_buffer << input_stream.rdbuf();
device_tree_model = str_buffer.str();
for (const auto& [key, value] : m_device_model_map) {
for (const auto& [key, value] : m_proc_device_tree_mapping) {
if(device_tree_model.rfind(key,0) == 0){
m_sbc_version = value;
LOGINFO("Detected device %s", GetString()->c_str());

View File

@ -11,7 +11,7 @@
//
//---------------------------------------------------------------------------
#include "hal/systimer.h"
#include "hal/systimer_allwinner.h"
#include <sys/mman.h>
#include "os.h"
@ -20,58 +20,41 @@
#include "config.h"
#include "log.h"
ControllerManager& ControllerManager::instance()
{
// If we haven't set up the private instance yet, do that now
if(private_instance == nullptr){
if(SBC_Version::IsRaspberryPi()){
private_instance = std::make_shared<SysTimer_Raspberry>();
private_instance->Init();
}
else if(SBC_Version::IsBananaPi()){
private_instance = std::make_shared<SysTimer_AllWinner>();
private_instance->Init();
}
}
return private_instance;
}
//---------------------------------------------------------------------------
//
// Initialize the system timer
//
//---------------------------------------------------------------------------
void SysTimer::Init(DWORD *syst, DWORD *armt)
void SysTimer_AllWinner::Init()
{
// RPI Mailbox property interface
// Get max clock rate
// Tag: 0x00030004
//
// Request: Length: 4
// Value: u32: clock id
// Response: Length: 8
// Value: u32: clock id, u32: rate (in Hz)
//
// Clock id
// 0x000000004: CORE
DWORD maxclock[32] = { 32, 0, 0x00030004, 8, 0, 4, 0, 0 };
// //
// // Request: Length: 4
// // Value: u32: clock id
// // Response: Length: 8
// // Value: u32: clock id, u32: rate (in Hz)
// //
// // Clock id
// // 0x000000004: CORE
// DWORD maxclock[32] = { 32, 0, 0x00030004, 8, 0, 4, 0, 0 };
// Save the base address
systaddr = syst;
armtaddr = armt;
// // Save the base address
// systaddr = syst;
// armtaddr = armt;
// Change the ARM timer to free run mode
armtaddr[ARMT_CTRL] = 0x00000282;
// // Change the ARM timer to free run mode
// armtaddr[ARMT_CTRL] = 0x00000282;
// Get the core frequency
corefreq = 0;
int fd = open("/dev/vcio", O_RDONLY);
if (fd >= 0) {
ioctl(fd, _IOWR(100, 0, char *), maxclock);
corefreq = maxclock[6] / 1000000;
}
close(fd);
// // Get the core frequency
// corefreq = 0;
// int fd = open("/dev/vcio", O_RDONLY);
// if (fd >= 0) {
// ioctl(fd, _IOWR(100, 0, char *), maxclock);
// corefreq = maxclock[6] / 1000000;
// }
// close(fd);
}
//---------------------------------------------------------------------------
@ -79,7 +62,7 @@ void SysTimer::Init(DWORD *syst, DWORD *armt)
// Get system timer low byte
//
//---------------------------------------------------------------------------
DWORD SysTimer::GetTimerLow() {
DWORD SysTimer_AllWinner::GetTimerLow() {
return systaddr[SYST_CLO];
}
@ -88,7 +71,7 @@ DWORD SysTimer::GetTimerLow() {
// Get system timer high byte
//
//---------------------------------------------------------------------------
DWORD SysTimer::GetTimerHigh() {
DWORD SysTimer_AllWinner::GetTimerHigh() {
return systaddr[SYST_CHI];
}
@ -97,7 +80,7 @@ DWORD SysTimer::GetTimerHigh() {
// Sleep in nanoseconds
//
//---------------------------------------------------------------------------
void SysTimer::instance.SleepNsec(DWORD nsec)
void SysTimer_AllWinner::SleepNsec(DWORD nsec)
{
// If time is 0, don't do anything
if (nsec == 0) {
@ -124,7 +107,7 @@ void SysTimer::instance.SleepNsec(DWORD nsec)
// Sleep in microseconds
//
//---------------------------------------------------------------------------
void SysTimer::instance.SleepUsec(DWORD usec)
void SysTimer_AllWinner::SleepUsec(DWORD usec)
{
// If time is 0, don't do anything
if (usec == 0) {

View File

@ -21,15 +21,15 @@
class SysTimer_AllWinner : SysTimer
{
public:
override void Init(uint32_t *syst, uint32_t *armt);
void Init();
// Initialization
override uint32_t GetTimerLow();
uint32_t GetTimerLow();
// Get system timer low byte
override uint32_t GetTimerHigh();
uint32_t GetTimerHigh();
// Get system timer high byte
override void SleepNsec(uint32_t nsec);
void SleepNsec(uint32_t nsec);
// Sleep for N nanoseconds
override void SleepUsec(uint32_t usec);
void SleepUsec(uint32_t usec);
// Sleep for N microseconds
private:

View File

@ -11,31 +11,22 @@
//
//---------------------------------------------------------------------------
#include "hal/systimer.h"
#include "hal/systimer_raspberry.h"
#include <sys/mman.h>
#include <memory>
#include "os.h"
#include "hal/gpiobus.h"
#include "hal/sbc_version.h"
#include "config.h"
#include "log.h"
ControllerManager& ControllerManager::instance()
{
// If we haven't set up the private instance yet, do that now
if(private_instance == nullptr){
if(SBC_Version::IsRaspberryPi()){
private_instance = std::make_shared<SysTimer_Raspberry>();
private_instance->Init();
}
else if(SBC_Version::IsBananaPi()){
private_instance = std::make_shared<SysTimer_AllWinner>();
private_instance->Init();
}
}
return private_instance;
}
static volatile uint32_t *systaddr = 0;
// System timer address
static volatile uint32_t *armtaddr = 0;
// ARM timer address
static volatile uint32_t corefreq = 0;
//---------------------------------------------------------------------------
//
@ -56,7 +47,7 @@ void SysTimer_Raspberry::Init()
}
// Map peripheral region memory
map = mmap(NULL, 0x1000100, PROT_READ | PROT_WRITE, MAP_SHARED, fd, baseaddr);
void *map = mmap(NULL, 0x1000100, PROT_READ | PROT_WRITE, MAP_SHARED, fd, baseaddr);
if (map == MAP_FAILED) {
LOGERROR("Error: Unable to map memory")
close(fd);
@ -78,7 +69,7 @@ void SysTimer_Raspberry::Init()
// Save the base address
systaddr = (DWORD *)map + SYST_OFFSET / sizeof(DWORD);
armtaddr = (DWORD *)map + ARMT_OFFSET / sizeof(DWORD));
armtaddr = (DWORD *)map + ARMT_OFFSET / sizeof(DWORD);
// Change the ARM timer to free run mode
armtaddr[ARMT_CTRL] = 0x00000282;

View File

@ -24,15 +24,15 @@
class SysTimer_Raspberry : SysTimer
{
public:
override void Init(uint32_t *syst, uint32_t *armt);
void Init();
// Initialization
override uint32_t GetTimerLow();
uint32_t GetTimerLow();
// Get system timer low byte
override uint32_t GetTimerHigh();
uint32_t GetTimerHigh();
// Get system timer high byte
override void SleepNsec(uint32_t nsec);
void SleepNsec(uint32_t nsec);
// Sleep for N nanoseconds
override void SleepUsec(uint32_t usec);
void SleepUsec(uint32_t usec);
// Sleep for N microseconds
private:
@ -40,6 +40,6 @@ private:
// System timer address
static volatile uint32_t *armtaddr;
// ARM timer address
static volatile uint32_t corefreq = 0;
static volatile uint32_t corefreq;
// Core frequency
};