RASCSI/cpp/hal/gpiobus_raspberry.h

133 lines
4.3 KiB
C
Raw Normal View History

//---------------------------------------------------------------------------
//
// SCSI Target Emulator RaSCSI Reloaded
// for Raspberry Pi
//
// Powered by XM6 TypeG Technology.
// Copyright (C) 2016-2020 GIMONS
// [ GPIO-SCSI bus ]
//
//---------------------------------------------------------------------------
#pragma once
#include <map>
#include "config.h"
#include "hal/gpiobus.h"
#include "hal/board_type.h"
#include "log.h"
2022-10-22 22:30:28 +00:00
#include "scsi.h"
//---------------------------------------------------------------------------
//
// Class definition
//
//---------------------------------------------------------------------------
class GPIOBUS_Raspberry final : public GPIOBUS
{
2022-10-22 22:30:28 +00:00
public:
2022-10-22 21:34:22 +00:00
// Basic Functions
2022-10-22 22:30:28 +00:00
GPIOBUS_Raspberry() = default;
2022-10-23 21:47:42 +00:00
~GPIOBUS_Raspberry() override = default;
2022-10-22 21:34:22 +00:00
// Destructor
bool Init(mode_e mode = mode_e::TARGET, board_type::rascsi_board_type_e
rascsi_type = board_type::rascsi_board_type_e::BOARD_TYPE_FULLSPEC) override;
// // Initialization
// void Reset() override;
2022-10-22 21:34:22 +00:00
// Reset
void Cleanup() override;
// Cleanup
//---------------------------------------------------------------------------
//
// Bus signal acquisition
//
//---------------------------------------------------------------------------
uint32_t Acquire() override;
uint8_t GetDAT() override;
2022-10-22 21:34:22 +00:00
// Get DAT signal
void SetDAT(uint8_t dat) override;
2022-10-22 21:34:22 +00:00
// Set DAT signal
// TODO: Restore this back to private
// private:
2022-10-22 21:34:22 +00:00
// SCSI I/O signal control
2022-10-23 17:36:07 +00:00
void MakeTable() override;
2022-10-22 21:34:22 +00:00
// Create work data
2022-10-28 02:10:36 +00:00
void SetControl(board_type::pi_physical_pin_e pin, board_type::gpio_high_low_e ast) override;
2022-10-22 21:34:22 +00:00
// Set Control Signal
2022-10-28 02:10:36 +00:00
void SetMode(board_type::pi_physical_pin_e pin, board_type::gpio_direction_e mode) override;
2022-10-22 21:34:22 +00:00
// Set SCSI I/O mode
bool GetSignal(board_type::pi_physical_pin_e pin) const override;
2022-10-22 21:34:22 +00:00
// Get SCSI input signal value
2022-10-28 02:10:36 +00:00
void SetSignal(board_type::pi_physical_pin_e pin, board_type::gpio_high_low_e ast) override;
2022-10-22 21:34:22 +00:00
// Set SCSI output signal value
2022-10-28 02:10:36 +00:00
bool WaitSignal(board_type::pi_physical_pin_e pin, board_type::gpio_high_low_e ast) override;
2022-10-22 21:34:22 +00:00
// Wait for a signal to change
// Interrupt control
void DisableIRQ() override;
// IRQ Disabled
void EnableIRQ() override;
// IRQ Enabled
// GPIO pin functionality settings
2022-10-28 02:10:36 +00:00
void PinConfig(board_type::pi_physical_pin_e pin, board_type::gpio_direction_e mode) override;
2022-10-22 21:34:22 +00:00
// GPIO pin direction setting
2022-10-28 02:10:36 +00:00
void PullConfig(board_type::pi_physical_pin_e pin, board_type::gpio_pull_up_down_e mode) override;
2022-10-22 21:34:22 +00:00
// GPIO pin pull up/down resistor setting
2022-10-28 02:10:36 +00:00
void PinSetSignal(board_type::pi_physical_pin_e pin, board_type::gpio_high_low_e ast) override;
2022-10-22 21:34:22 +00:00
// Set GPIO output signal
2022-10-23 17:40:42 +00:00
void DrvConfig(uint32_t drive) override;
2022-10-22 21:34:22 +00:00
// Set GPIO drive strength
// Map the physical pin number to the logical GPIO number
const static std::map<board_type::pi_physical_pin_e, int> phys_to_gpio_map;
#if !defined(__x86_64__) && !defined(__X86__)
2022-10-22 21:34:22 +00:00
uint32_t baseaddr = 0; // Base address
#endif
2022-10-22 21:34:22 +00:00
int rpitype = 0; // Type of Raspberry Pi
2022-10-22 21:34:22 +00:00
volatile uint32_t *gpio = nullptr; // GPIO register
2022-10-22 21:34:22 +00:00
volatile uint32_t *pads = nullptr; // PADS register
#if !defined(__x86_64__) && !defined(__X86__)
2022-10-22 21:34:22 +00:00
volatile uint32_t *level = nullptr; // GPIO input level
#endif
2022-10-22 21:34:22 +00:00
volatile uint32_t *irpctl = nullptr; // Interrupt control register
2022-10-22 21:34:22 +00:00
volatile uint32_t irptenb; // Interrupt enabled state
2022-10-22 21:34:22 +00:00
volatile uint32_t *qa7regs = nullptr; // QA7 register
2022-10-22 21:34:22 +00:00
volatile int tintcore; // Interupt control target CPU.
2022-10-22 21:34:22 +00:00
volatile uint32_t tintctl; // Interupt control
2022-10-22 21:34:22 +00:00
volatile uint32_t giccpmr; // GICC priority setting
#if !defined(__x86_64__) && !defined(__X86__)
2022-10-22 21:34:22 +00:00
volatile uint32_t *gicd = nullptr; // GIC Interrupt distributor register
#endif
2022-10-22 21:34:22 +00:00
volatile uint32_t *gicc = nullptr; // GIC CPU interface register
2022-10-22 21:34:22 +00:00
array<uint32_t, 4> gpfsel; // GPFSEL0-4 backup values
2022-10-22 21:34:22 +00:00
uint32_t signals = 0; // All bus signals
#if SIGNAL_CONTROL_MODE == 0
2022-10-22 21:34:22 +00:00
array<array<uint32_t, 256>, 3> tblDatMsk; // Data mask table
2022-10-22 21:34:22 +00:00
array<array<uint32_t, 256>, 3> tblDatSet; // Data setting table
#else
2022-10-22 21:34:22 +00:00
array<uint32_t, 256> tblDatMsk = {}; // Data mask table
2022-10-22 21:34:22 +00:00
array<uint32_t, 256> tblDatSet = {}; // Table setting table
#endif
};