Skip to content

Commit

Permalink
Breakup GPIOBUS (#843)
Browse files Browse the repository at this point in the history
* moved gpiobus

* moved gpiobus and systimer into hardware abstraction layer

* split up gpiobus by connection type

* merge develop changes

* revert compiler setting change

* registers working

* updates

* updates

* Revert "updates"

This reverts commit 0134b81.

* Revert "updates"

This reverts commit 4bf0416.

* Revert "registers working"

This reverts commit f5ee073.

* Address comment in #843. Restore -Wextra

Co-authored-by: Tony Kuker <akuker@gmail.com>
  • Loading branch information
akuker and Tony Kuker authored Sep 10, 2022
1 parent f0c36fb commit e64c2f7
Show file tree
Hide file tree
Showing 15 changed files with 434 additions and 341 deletions.
11 changes: 5 additions & 6 deletions src/raspberrypi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ SRC_PROTOBUF = \

SRC_RASCSI_CORE = \
scsi.cpp \
gpiobus.cpp \
filepath.cpp \
fileio.cpp \
rascsi_version.cpp \
Expand All @@ -98,16 +97,17 @@ SRC_RASCSI_CORE = \
localizer.cpp
SRC_RASCSI_CORE += $(shell find ./controllers -name '*.cpp')
SRC_RASCSI_CORE += $(shell find ./devices -name '*.cpp')
SRC_RASCSI_CORE += $(shell find ./hal -name '*.cpp')
SRC_RASCSI_CORE += $(SRC_PROTOBUF)

SRC_RASCSI = rascsi.cpp

SRC_SCSIMON = \
scsimon.cpp \
scsi.cpp \
gpiobus.cpp \
rascsi_version.cpp
SRC_SCSIMON += $(shell find ./monitor -name '*.cpp')
SRC_SCSIMON += $(shell find ./hal -name '*.cpp')

SRC_RASCTL = \
rasctl.cpp\
Expand All @@ -122,17 +122,16 @@ SRC_RASCTL += $(SRC_PROTOBUF)
SRC_RASDUMP = \
rasdump.cpp \
scsi.cpp \
gpiobus.cpp \
filepath.cpp \
fileio.cpp \
rascsi_version.cpp

SRC_RASDUMP += $(shell find ./hal -name '*.cpp')

SRC_RASCSI_TEST = $(shell find ./test -name '*.cpp')


vpath %.h ./ ./controllers ./devices ./monitor
vpath %.cpp ./ ./controllers ./devices ./monitor ./test
vpath %.h ./ ./controllers ./devices ./monitor ./hal
vpath %.cpp ./ ./controllers ./devices ./monitor ./test ./hal
vpath %.o ./$(OBJDIR)
vpath ./$(BINDIR)

Expand Down
3 changes: 2 additions & 1 deletion src/raspberrypi/controllers/scsi_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
//---------------------------------------------------------------------------

#include "log.h"
#include "gpiobus.h"
#include "hal/gpiobus.h"
#include "hal/systimer.h"
#include "rascsi_exceptions.h"
#include "devices/scsi_host_bridge.h"
#include "devices/scsi_daynaport.h"
Expand Down
121 changes: 2 additions & 119 deletions src/raspberrypi/gpiobus.cpp → src/raspberrypi/hal/gpiobus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#include <sys/mman.h>

#include "os.h"
#include "gpiobus.h"
#include "hal/gpiobus.h"
#include "hal/systimer.h"

#include "config.h"
#include "log.h"
Expand Down Expand Up @@ -1452,121 +1453,3 @@ int GPIOBUS::GetCommandByteCount(BYTE opcode) {
}
}

//---------------------------------------------------------------------------
//
// System timer address
//
//---------------------------------------------------------------------------
volatile DWORD* SysTimer::systaddr;

//---------------------------------------------------------------------------
//
// ARM timer address
//
//---------------------------------------------------------------------------
volatile DWORD* SysTimer::armtaddr;

//---------------------------------------------------------------------------
//
// Core frequency
//
//---------------------------------------------------------------------------
volatile DWORD SysTimer::corefreq;

//---------------------------------------------------------------------------
//
// Initialize the system timer
//
//---------------------------------------------------------------------------
void SysTimer::Init(DWORD *syst, DWORD *armt)
{
// 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 };

// Save the base address
systaddr = syst;
armtaddr = armt;

// 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 system timer low byte
//
//---------------------------------------------------------------------------
DWORD SysTimer::GetTimerLow() {
return systaddr[SYST_CLO];
}

//---------------------------------------------------------------------------
//
// Get system timer high byte
//
//---------------------------------------------------------------------------
DWORD SysTimer::GetTimerHigh() {
return systaddr[SYST_CHI];
}

//---------------------------------------------------------------------------
//
// Sleep in nanoseconds
//
//---------------------------------------------------------------------------
void SysTimer::SleepNsec(DWORD nsec)
{
// If time is 0, don't do anything
if (nsec == 0) {
return;
}

// Calculate the timer difference
DWORD diff = corefreq * nsec / 1000;

// Return if the difference in time is too small
if (diff == 0) {
return;
}

// Start
DWORD start = armtaddr[ARMT_FREERUN];

// Loop until timer has elapsed
while ((armtaddr[ARMT_FREERUN] - start) < diff);
}

//---------------------------------------------------------------------------
//
// Sleep in microseconds
//
//---------------------------------------------------------------------------
void SysTimer::SleepUsec(DWORD usec)
{
// If time is 0, don't do anything
if (usec == 0) {
return;
}

DWORD now = GetTimerLow();
while ((GetTimerLow() - now) < usec);
}
Loading

0 comments on commit e64c2f7

Please sign in to comment.