mirror of
https://github.com/akuker/RASCSI.git
synced 2024-11-29 16:49:55 +00:00
updates
This commit is contained in:
parent
4bf0416ab4
commit
0134b81061
@ -131,10 +131,10 @@ bool GPIOBUS::Init(mode_e mode)
|
|||||||
pads = (DWORD *)map;
|
pads = (DWORD *)map;
|
||||||
pads += PADS_OFFSET / sizeof(DWORD);
|
pads += PADS_OFFSET / sizeof(DWORD);
|
||||||
|
|
||||||
// System timer
|
// // System timer
|
||||||
SysTimer::Init(
|
// SysTimer::Init(
|
||||||
(DWORD *)map + SYST_OFFSET / sizeof(DWORD),
|
// (DWORD *)map + SYST_OFFSET / sizeof(DWORD),
|
||||||
(DWORD *)map + ARMT_OFFSET / sizeof(DWORD));
|
// (DWORD *)map + ARMT_OFFSET / sizeof(DWORD));
|
||||||
|
|
||||||
// Interrupt controller
|
// Interrupt controller
|
||||||
irpctl = (DWORD *)map;
|
irpctl = (DWORD *)map;
|
||||||
@ -705,7 +705,7 @@ int GPIOBUS::CommandHandShake(BYTE *buf)
|
|||||||
bool ret = WaitSignal(PIN_ACK, TRUE);
|
bool ret = WaitSignal(PIN_ACK, TRUE);
|
||||||
|
|
||||||
// Wait until the signal line stabilizes
|
// 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
|
// Get data
|
||||||
*buf = GetDAT();
|
*buf = GetDAT();
|
||||||
@ -742,7 +742,7 @@ int GPIOBUS::CommandHandShake(BYTE *buf)
|
|||||||
|
|
||||||
ret = WaitSignal(PIN_ACK, TRUE);
|
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
|
// Get the actual SCSI command
|
||||||
*buf = GetDAT();
|
*buf = GetDAT();
|
||||||
@ -776,7 +776,7 @@ int GPIOBUS::CommandHandShake(BYTE *buf)
|
|||||||
ret = WaitSignal(PIN_ACK, TRUE);
|
ret = WaitSignal(PIN_ACK, TRUE);
|
||||||
|
|
||||||
// Wait until the signal line stabilizes
|
// 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
|
// Get data
|
||||||
*buf = GetDAT();
|
*buf = GetDAT();
|
||||||
@ -827,7 +827,7 @@ int GPIOBUS::ReceiveHandShake(BYTE *buf, int count)
|
|||||||
bool ret = WaitSignal(PIN_ACK, TRUE);
|
bool ret = WaitSignal(PIN_ACK, TRUE);
|
||||||
|
|
||||||
// Wait until the signal line stabilizes
|
// 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
|
// Get data
|
||||||
*buf = GetDAT();
|
*buf = GetDAT();
|
||||||
@ -870,7 +870,7 @@ int GPIOBUS::ReceiveHandShake(BYTE *buf, int count)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wait until the signal line stabilizes
|
// 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
|
// Get data
|
||||||
*buf = GetDAT();
|
*buf = GetDAT();
|
||||||
@ -922,7 +922,7 @@ int GPIOBUS::SendHandShake(BYTE *buf, int count, int delay_after_bytes)
|
|||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
if(i==delay_after_bytes){
|
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)
|
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
|
// 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++) {
|
for (i = 0; i < count; i++) {
|
||||||
if(i==delay_after_bytes){
|
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)
|
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
|
// Set the DATA signals
|
||||||
@ -1252,7 +1252,7 @@ void GPIOBUS::SetSignal(int pin, bool ast)
|
|||||||
bool GPIOBUS::WaitSignal(int pin, BOOL ast)
|
bool GPIOBUS::WaitSignal(int pin, BOOL ast)
|
||||||
{
|
{
|
||||||
// Get current time
|
// Get current time
|
||||||
DWORD now = SysTimer::GetTimerLow();
|
DWORD now = SysTimer::instance()->GetTimerLow();
|
||||||
|
|
||||||
// Calculate timeout (3000ms)
|
// Calculate timeout (3000ms)
|
||||||
DWORD timeout = 3000 * 1000;
|
DWORD timeout = 3000 * 1000;
|
||||||
@ -1269,7 +1269,7 @@ bool GPIOBUS::WaitSignal(int pin, BOOL ast)
|
|||||||
if (((signals >> pin) ^ ~ast) & 1) {
|
if (((signals >> pin) ^ ~ast) & 1) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} while ((SysTimer::GetTimerLow() - now) < timeout);
|
} while ((SysTimer::instance()->GetTimerLow() - now) < timeout);
|
||||||
|
|
||||||
// We timed out waiting for the signal
|
// We timed out waiting for the signal
|
||||||
return false;
|
return false;
|
||||||
|
@ -98,7 +98,7 @@ void SBC_Version::Init(){
|
|||||||
str_buffer << input_stream.rdbuf();
|
str_buffer << input_stream.rdbuf();
|
||||||
device_tree_model = str_buffer.str();
|
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){
|
if(device_tree_model.rfind(key,0) == 0){
|
||||||
m_sbc_version = value;
|
m_sbc_version = value;
|
||||||
LOGINFO("Detected device %s", GetString()->c_str());
|
LOGINFO("Detected device %s", GetString()->c_str());
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
//
|
//
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "hal/systimer.h"
|
#include "hal/systimer_allwinner.h"
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
@ -20,58 +20,41 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "log.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
|
// Initialize the system timer
|
||||||
//
|
//
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
void SysTimer::Init(DWORD *syst, DWORD *armt)
|
void SysTimer_AllWinner::Init()
|
||||||
{
|
{
|
||||||
// RPI Mailbox property interface
|
// RPI Mailbox property interface
|
||||||
// Get max clock rate
|
// Get max clock rate
|
||||||
// Tag: 0x00030004
|
// Tag: 0x00030004
|
||||||
//
|
// //
|
||||||
// Request: Length: 4
|
// // Request: Length: 4
|
||||||
// Value: u32: clock id
|
// // Value: u32: clock id
|
||||||
// Response: Length: 8
|
// // Response: Length: 8
|
||||||
// Value: u32: clock id, u32: rate (in Hz)
|
// // Value: u32: clock id, u32: rate (in Hz)
|
||||||
//
|
// //
|
||||||
// Clock id
|
// // Clock id
|
||||||
// 0x000000004: CORE
|
// // 0x000000004: CORE
|
||||||
DWORD maxclock[32] = { 32, 0, 0x00030004, 8, 0, 4, 0, 0 };
|
// DWORD maxclock[32] = { 32, 0, 0x00030004, 8, 0, 4, 0, 0 };
|
||||||
|
|
||||||
// Save the base address
|
// // Save the base address
|
||||||
systaddr = syst;
|
// systaddr = syst;
|
||||||
armtaddr = armt;
|
// armtaddr = armt;
|
||||||
|
|
||||||
// Change the ARM timer to free run mode
|
// // Change the ARM timer to free run mode
|
||||||
armtaddr[ARMT_CTRL] = 0x00000282;
|
// armtaddr[ARMT_CTRL] = 0x00000282;
|
||||||
|
|
||||||
// Get the core frequency
|
// // Get the core frequency
|
||||||
corefreq = 0;
|
// corefreq = 0;
|
||||||
int fd = open("/dev/vcio", O_RDONLY);
|
// int fd = open("/dev/vcio", O_RDONLY);
|
||||||
if (fd >= 0) {
|
// if (fd >= 0) {
|
||||||
ioctl(fd, _IOWR(100, 0, char *), maxclock);
|
// ioctl(fd, _IOWR(100, 0, char *), maxclock);
|
||||||
corefreq = maxclock[6] / 1000000;
|
// corefreq = maxclock[6] / 1000000;
|
||||||
}
|
// }
|
||||||
close(fd);
|
// close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@ -79,7 +62,7 @@ void SysTimer::Init(DWORD *syst, DWORD *armt)
|
|||||||
// Get system timer low byte
|
// Get system timer low byte
|
||||||
//
|
//
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
DWORD SysTimer::GetTimerLow() {
|
DWORD SysTimer_AllWinner::GetTimerLow() {
|
||||||
return systaddr[SYST_CLO];
|
return systaddr[SYST_CLO];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +71,7 @@ DWORD SysTimer::GetTimerLow() {
|
|||||||
// Get system timer high byte
|
// Get system timer high byte
|
||||||
//
|
//
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
DWORD SysTimer::GetTimerHigh() {
|
DWORD SysTimer_AllWinner::GetTimerHigh() {
|
||||||
return systaddr[SYST_CHI];
|
return systaddr[SYST_CHI];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +80,7 @@ DWORD SysTimer::GetTimerHigh() {
|
|||||||
// Sleep in nanoseconds
|
// Sleep in nanoseconds
|
||||||
//
|
//
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
void SysTimer::instance.SleepNsec(DWORD nsec)
|
void SysTimer_AllWinner::SleepNsec(DWORD nsec)
|
||||||
{
|
{
|
||||||
// If time is 0, don't do anything
|
// If time is 0, don't do anything
|
||||||
if (nsec == 0) {
|
if (nsec == 0) {
|
||||||
@ -124,7 +107,7 @@ void SysTimer::instance.SleepNsec(DWORD nsec)
|
|||||||
// Sleep in microseconds
|
// Sleep in microseconds
|
||||||
//
|
//
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
void SysTimer::instance.SleepUsec(DWORD usec)
|
void SysTimer_AllWinner::SleepUsec(DWORD usec)
|
||||||
{
|
{
|
||||||
// If time is 0, don't do anything
|
// If time is 0, don't do anything
|
||||||
if (usec == 0) {
|
if (usec == 0) {
|
||||||
|
@ -21,15 +21,15 @@
|
|||||||
class SysTimer_AllWinner : SysTimer
|
class SysTimer_AllWinner : SysTimer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
override void Init(uint32_t *syst, uint32_t *armt);
|
void Init();
|
||||||
// Initialization
|
// Initialization
|
||||||
override uint32_t GetTimerLow();
|
uint32_t GetTimerLow();
|
||||||
// Get system timer low byte
|
// Get system timer low byte
|
||||||
override uint32_t GetTimerHigh();
|
uint32_t GetTimerHigh();
|
||||||
// Get system timer high byte
|
// Get system timer high byte
|
||||||
override void SleepNsec(uint32_t nsec);
|
void SleepNsec(uint32_t nsec);
|
||||||
// Sleep for N nanoseconds
|
// Sleep for N nanoseconds
|
||||||
override void SleepUsec(uint32_t usec);
|
void SleepUsec(uint32_t usec);
|
||||||
// Sleep for N microseconds
|
// Sleep for N microseconds
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -11,31 +11,22 @@
|
|||||||
//
|
//
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "hal/systimer.h"
|
#include "hal/systimer_raspberry.h"
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "hal/gpiobus.h"
|
#include "hal/gpiobus.h"
|
||||||
|
#include "hal/sbc_version.h"
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
static volatile uint32_t *systaddr = 0;
|
||||||
ControllerManager& ControllerManager::instance()
|
// System timer address
|
||||||
{
|
static volatile uint32_t *armtaddr = 0;
|
||||||
// If we haven't set up the private instance yet, do that now
|
// ARM timer address
|
||||||
if(private_instance == nullptr){
|
static volatile uint32_t corefreq = 0;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
@ -56,7 +47,7 @@ void SysTimer_Raspberry::Init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Map peripheral region memory
|
// 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) {
|
if (map == MAP_FAILED) {
|
||||||
LOGERROR("Error: Unable to map memory")
|
LOGERROR("Error: Unable to map memory")
|
||||||
close(fd);
|
close(fd);
|
||||||
@ -78,7 +69,7 @@ void SysTimer_Raspberry::Init()
|
|||||||
|
|
||||||
// Save the base address
|
// Save the base address
|
||||||
systaddr = (DWORD *)map + SYST_OFFSET / sizeof(DWORD);
|
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
|
// Change the ARM timer to free run mode
|
||||||
armtaddr[ARMT_CTRL] = 0x00000282;
|
armtaddr[ARMT_CTRL] = 0x00000282;
|
||||||
|
@ -24,15 +24,15 @@
|
|||||||
class SysTimer_Raspberry : SysTimer
|
class SysTimer_Raspberry : SysTimer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
override void Init(uint32_t *syst, uint32_t *armt);
|
void Init();
|
||||||
// Initialization
|
// Initialization
|
||||||
override uint32_t GetTimerLow();
|
uint32_t GetTimerLow();
|
||||||
// Get system timer low byte
|
// Get system timer low byte
|
||||||
override uint32_t GetTimerHigh();
|
uint32_t GetTimerHigh();
|
||||||
// Get system timer high byte
|
// Get system timer high byte
|
||||||
override void SleepNsec(uint32_t nsec);
|
void SleepNsec(uint32_t nsec);
|
||||||
// Sleep for N nanoseconds
|
// Sleep for N nanoseconds
|
||||||
override void SleepUsec(uint32_t usec);
|
void SleepUsec(uint32_t usec);
|
||||||
// Sleep for N microseconds
|
// Sleep for N microseconds
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -40,6 +40,6 @@ private:
|
|||||||
// System timer address
|
// System timer address
|
||||||
static volatile uint32_t *armtaddr;
|
static volatile uint32_t *armtaddr;
|
||||||
// ARM timer address
|
// ARM timer address
|
||||||
static volatile uint32_t corefreq = 0;
|
static volatile uint32_t corefreq;
|
||||||
// Core frequency
|
// Core frequency
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user