Additional updates

This commit is contained in:
akuker
2020-08-28 17:33:40 -05:00
parent eb36bb67b9
commit 612e7c2e51
6 changed files with 126 additions and 31 deletions

View File

@@ -5,7 +5,7 @@
"type": "shell", "type": "shell",
"label": "g++ build active file", "label": "g++ build active file",
"command": "make", "command": "make",
"args": ["all", "DEBUG=1"], "args": ["all", "DEBUG=1", "ARCH=", "CROSS_COMPILE="],
"options": { "options": {
"cwd": "${workspaceFolder}/" "cwd": "${workspaceFolder}/"
}, },

View File

@@ -21,17 +21,27 @@
#include "os.h" #include "os.h"
#include "rasctl_command.h" #include "rasctl_command.h"
#include "sasihd.h" #include "devices/sasihd.h"
#include "scsihd.h" #include "devices/scsihd.h"
#include "scsihd_nec.h" #include "devices/scsihd_nec.h"
#include "scsihd_apple.h" #include "devices/scsihd_apple.h"
#include "scsicd.h" #include "devices/scsicd.h"
#include "scsimo.h" #include "devices/scsimo.h"
#include "scsi_host_bridge.h" #include "devices/scsi_host_bridge.h"
int Command_Thread::m_monsocket = -1; // Monitor Socket int Command_Thread::m_monsocket = -1; // Monitor Socket
pthread_t Command_Thread::m_monthread; // Monitor Thread pthread_t Command_Thread::m_monthread; // Monitor Thread
// These objects are currently in rascsi.cpp. They should eventually be
// broken out.
extern volatile BOOL running; // Running flag
extern volatile BOOL active; // Processing flag
void ListDevice(FILE *fp);
Disk* GetDevice(FILE *fp, int id, int un);
BOOL AttachDevice(FILE *fp, Disk *pUnit, int id, int un);
BOOL DetachDevice(FILE *fp, int id, int un);
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// Initialization // Initialization
@@ -304,7 +314,7 @@ void *Command_Thread::MonThread(void *param)
// Setup the monitor socket to receive commands // Setup the monitor socket to receive commands
listen(m_monsocket, 1); listen(m_monsocket, 1);
while (Rascsi_Manager::IsRunning()) { while (running) {
// Wait for connection // Wait for connection
memset(&client, 0, sizeof(client)); memset(&client, 0, sizeof(client));
len = sizeof(client); len = sizeof(client);
@@ -319,14 +329,14 @@ void *Command_Thread::MonThread(void *param)
// If we received a command.... // If we received a command....
if (p) { if (p) {
// Decode the received buffer into a Command object
new_command = Rasctl_Command::DeSerialize(p,BUFSIZ); new_command = Rasctl_Command::DeSerialize(p,BUFSIZ);
// If the command was successfully parsed
if(new_command != nullptr){ if(new_command != nullptr){
// Execute the command // Execute the command
ExecuteCommand(fp, new_command); ExecuteCommand(fp, new_command);
} }
} }
// Release the connection // Release the connection
@@ -380,12 +390,12 @@ BOOL Command_Thread::ExecuteCommand(FILE *fp, Rasctl_Command *incoming_command)
BOOL Command_Thread::DoShutdown(FILE *fp, Rasctl_Command *incoming_command){ BOOL Command_Thread::DoShutdown(FILE *fp, Rasctl_Command *incoming_command){
fprintf(fp, "Stopping the RaSCSI application\n"); fprintf(fp, "Stopping the RaSCSI application\n");
Rascsi_Manager::Stop(); running = FALSE;
return TRUE; return TRUE;
} }
BOOL Command_Thread::DoList(FILE *fp, Rasctl_Command *incoming_command){ BOOL Command_Thread::DoList(FILE *fp, Rasctl_Command *incoming_command){
Rascsi_Manager::ListDevice(fp); ListDevice(fp);
return TRUE; return TRUE;
} }
@@ -453,17 +463,17 @@ BOOL Command_Thread::DoAttach(FILE *fp, Rasctl_Command *incoming_command){
pUnit->SetCacheWB(FALSE); pUnit->SetCacheWB(FALSE);
// Map the controller // Map the controller
return Rascsi_Manager::AttachDevice(fp, pUnit, incoming_command->id, incoming_command->un); return AttachDevice(fp, pUnit, incoming_command->id, incoming_command->un);
} }
BOOL Command_Thread::DoDetach(FILE *fp, Rasctl_Command *incoming_command){ BOOL Command_Thread::DoDetach(FILE *fp, Rasctl_Command *incoming_command){
return Rascsi_Manager::DetachDevice(fp, incoming_command->id, incoming_command->un); return DetachDevice(fp, incoming_command->id, incoming_command->un);
} }
BOOL Command_Thread::DoInsert(FILE *fp, Rasctl_Command *incoming_command){ BOOL Command_Thread::DoInsert(FILE *fp, Rasctl_Command *incoming_command){
Filepath filepath; Filepath filepath;
Disk *pUnit = Rascsi_Manager::GetDevice(fp, incoming_command->id, incoming_command->un); Disk *pUnit = GetDevice(fp, incoming_command->id, incoming_command->un);
// Does the device exist? // Does the device exist?
@@ -491,7 +501,7 @@ BOOL Command_Thread::DoInsert(FILE *fp, Rasctl_Command *incoming_command){
return TRUE; return TRUE;
} }
BOOL Command_Thread::DoEject(FILE *fp, Rasctl_Command *incoming_command){ BOOL Command_Thread::DoEject(FILE *fp, Rasctl_Command *incoming_command){
Disk *pUnit = Rascsi_Manager::GetDevice(fp, incoming_command->id, incoming_command->un); Disk *pUnit = GetDevice(fp, incoming_command->id, incoming_command->un);
// Does the device exist? // Does the device exist?
if (pUnit == nullptr) { if (pUnit == nullptr) {
@@ -511,7 +521,7 @@ BOOL Command_Thread::DoEject(FILE *fp, Rasctl_Command *incoming_command){
BOOL Command_Thread::DoProtect(FILE *fp, Rasctl_Command *incoming_command){ BOOL Command_Thread::DoProtect(FILE *fp, Rasctl_Command *incoming_command){
Disk *pUnit = Rascsi_Manager::GetDevice(fp, incoming_command->id, incoming_command->un); Disk *pUnit = GetDevice(fp, incoming_command->id, incoming_command->un);
// Does the device exist? // Does the device exist?
if (pUnit == nullptr) { if (pUnit == nullptr) {

View File

@@ -117,6 +117,12 @@
#define ARRAY_SIZE(x) (sizeof(x)/(sizeof(x[0]))) #define ARRAY_SIZE(x) (sizeof(x)/(sizeof(x[0])))
#ifdef BAREMETAL
#define FPRT(fp, ...) printf( __VA_ARGS__ )
#else
#define FPRT(fp, ...) fprintf(fp, __VA_ARGS__ )
#endif // BAREMETAL
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// Basic Type Definitions // Basic Type Definitions

View File

@@ -33,19 +33,17 @@
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#define CtrlMax 8 // Maximum number of SCSI controllers #define CtrlMax 8 // Maximum number of SCSI controllers
#define UnitNum 2 // Number of units around controller #define UnitNum 2 // Number of units around controller
#ifdef BAREMETAL
#define FPRT(fp, ...) printf( __VA_ARGS__ )
#else
#define FPRT(fp, ...) fprintf(fp, __VA_ARGS__ )
#endif // BAREMETAL
#ifndef CONNECT_DESC
#define CONNECT_DESC "Unknown"
#endif
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// Variable declarations // Variable declarations
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
static volatile BOOL running; // Running flag volatile BOOL running; // Running flag
static volatile BOOL active; // Processing flag volatile BOOL active; // Processing flag
SASIDEV *ctrl[CtrlMax]; // Controller SASIDEV *ctrl[CtrlMax]; // Controller
Disk *disk[CtrlMax * UnitNum]; // Disk Disk *disk[CtrlMax * UnitNum]; // Disk
GPIOBUS *bus; // GPIO Bus GPIOBUS *bus; // GPIO Bus
@@ -297,6 +295,9 @@ void ListDevice(FILE *fp)
FPRT(fp, "+----+----+------+-------------------------------------\n"); FPRT(fp, "+----+----+------+-------------------------------------\n");
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// Controller Mapping // Controller Mapping
@@ -412,6 +413,80 @@ void MapControler(FILE *fp, Disk **map)
} }
} }
Disk* GetDevice(FILE *fp, int id, int un){
// Check the Controller Number
if (id < 0 || id >= CtrlMax) {
FPRT(fp, "Error : Invalid ID\n");
return FALSE;
}
// Check the Unit Number
if (un < 0 || un >= UnitNum) {
FPRT(fp, "Error : Invalid unit number\n");
return FALSE;
}
// Replace with the newly created unit
return disk[id * UnitNum + un];
}
BOOL AttachDevice(FILE *fp, Disk *pUnit, int id, int un){
Disk *map[CtrlMax * UnitNum];
Filepath filepath;
// Copy the Unit List
memcpy(map, disk, sizeof(disk));
// Check the Controller Number
if (id < 0 || id >= CtrlMax) {
FPRT(fp, "Error : Invalid ID\n");
return FALSE;
}
// Check the Unit Number
if (un < 0 || un >= UnitNum) {
FPRT(fp, "Error : Invalid unit number\n");
return FALSE;
}
// Replace with the newly created unit
map[id * UnitNum + un] = pUnit;
// Re-map the controller
MapControler(fp, map);
return TRUE;
}
BOOL DetachDevice(FILE *fp, int id, int un){
Disk *map[CtrlMax * UnitNum];
Filepath filepath;
// Copy the Unit List
memcpy(map, disk, sizeof(disk));
// Check the Controller Number
if (id < 0 || id >= CtrlMax) {
FPRT(fp, "Error : Invalid ID\n");
return FALSE;
}
// Check the Unit Number
if (un < 0 || un >= UnitNum) {
FPRT(fp, "Error : Invalid unit number\n");
return FALSE;
}
// Free the existing unit
map[id * UnitNum + un] = NULL;
// Re-map the controller
MapControler(fp, map);
return TRUE;
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// Main processing // Main processing

View File

@@ -1,5 +1,4 @@
#include "rasctl_command.h" #include "rasctl_command.h"
#include "rascsi_mgr.h"
#include <string.h> #include <string.h>
// In the serialized string from rasctl // In the serialized string from rasctl
@@ -100,7 +99,6 @@ BOOL Rasctl_Command::rasctl_dev_is_hd(rasctl_dev_type type)
BOOL Rasctl_Command::IsValid(FILE *fp){ BOOL Rasctl_Command::IsValid(FILE *fp){
struct stat stat_buffer; struct stat stat_buffer;
rasctl_dev_type expected_type = rasctl_dev_invalid;
// If the command is "invalid" we can just return FALSE // If the command is "invalid" we can just return FALSE
if(cmd == rasctl_cmd_invalid){ if(cmd == rasctl_cmd_invalid){
@@ -113,14 +111,14 @@ BOOL Rasctl_Command::IsValid(FILE *fp){
} }
// Check that the ID is in range // Check that the ID is in range
if((id < 0) || (id >= Rascsi_Manager::CtrlMax)){ if((id < 0) || (id >= CtrlMax)){
FPRT(fp, "Invalid ID. Must be between 0 and %d",Rascsi_Manager::CtrlMax-1); FPRT(fp, "Invalid ID. Must be between 0 and %d",CtrlMax-1);
return FALSE; return FALSE;
} }
// Check that unit number is in range // Check that unit number is in range
if((un < 0) || (un >= Rascsi_Manager::UnitNum)){ if((un < 0) || (un >= UnitNum)){
FPRT(fp, "Invalid unit number. Must be between 0 and %d",Rascsi_Manager::UnitNum-1); FPRT(fp, "Invalid unit number. Must be between 0 and %d",UnitNum-1);
return FALSE; return FALSE;
} }

View File

@@ -14,6 +14,12 @@
#include "os.h" #include "os.h"
// Todo - this is a clone of the declaration in rascsi.cpp. This is sloppy!!! Fix this!!
#ifndef CtrlMax
#define CtrlMax 8 // Maximum number of SCSI controllers
#define UnitNum 2 // Number of units around controller
#endif
enum rasctl_command : int { enum rasctl_command : int {
rasctl_cmd_invalid = -1, rasctl_cmd_invalid = -1,
rasctl_cmd_attach = 0, rasctl_cmd_attach = 0,