|
@@ -60,15 +60,16 @@
|
|
#include <SdFat.h>
|
|
#include <SdFat.h>
|
|
#include "sdios.h"
|
|
#include "sdios.h"
|
|
#include "blacksasi.h"
|
|
#include "blacksasi.h"
|
|
|
|
+
|
|
#ifdef USE_STM32_DMA
|
|
#ifdef USE_STM32_DMA
|
|
#warning "warning USE_STM32_DMA"
|
|
#warning "warning USE_STM32_DMA"
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-
|
|
|
|
// SDFAT
|
|
// SDFAT
|
|
SdFs SD;
|
|
SdFs SD;
|
|
|
|
|
|
-
|
|
|
|
|
|
+// Logfile
|
|
|
|
+FsFile LOG_FILE;
|
|
|
|
|
|
static const uint32_t scsiDbOutputRegOr = 0x55150011;
|
|
static const uint32_t scsiDbOutputRegOr = 0x55150011;
|
|
static const uint32_t scsiDbInputOutputAnd = 0x00C0FFCC;
|
|
static const uint32_t scsiDbInputOutputAnd = 0x00C0FFCC;
|
|
@@ -85,20 +86,11 @@ static const uint32_t scsiDbInputOutputAnd = 0x00C0FFCC;
|
|
// BSY,REQ,MSG,CD,IO Turn off output, BSY is the last input
|
|
// BSY,REQ,MSG,CD,IO Turn off output, BSY is the last input
|
|
#define SCSI_TARGET_INACTIVE() { SCSI_OUT(vREQ,inactive); SCSI_OUT(vMSG,inactive); SCSI_OUT(vCD,inactive); SCSI_OUT(vIO,inactive); SCSI_OUT(vBSY,inactive); pinMode(BOARD_SCSI_BSY, INPUT); }
|
|
#define SCSI_TARGET_INACTIVE() { SCSI_OUT(vREQ,inactive); SCSI_OUT(vMSG,inactive); SCSI_OUT(vCD,inactive); SCSI_OUT(vIO,inactive); SCSI_OUT(vBSY,inactive); pinMode(BOARD_SCSI_BSY, INPUT); }
|
|
|
|
|
|
-// HDDiamge file
|
|
|
|
-#define HDIMG_ID_POS 2 // Position to embed ID number
|
|
|
|
-#define HDIMG_LUN_POS 3 // Position to embed LUN numbers
|
|
|
|
-#define HDIMG_BLK_POS 5 // Position to embed block size numbers
|
|
|
|
-#define MAX_FILE_PATH 32 // Maximum file name length
|
|
|
|
|
|
+
|
|
static ArduinoOutStream cout(Serial);
|
|
static ArduinoOutStream cout(Serial);
|
|
// HDD image
|
|
// HDD image
|
|
uint16_t imageSelect = 0;
|
|
uint16_t imageSelect = 0;
|
|
-typedef struct hddimg_struct
|
|
|
|
-{
|
|
|
|
- FsFile m_file; // File object
|
|
|
|
- uint64_t m_fileSize; // File size
|
|
|
|
- size_t m_blocksize; // SCSI BLOCK size
|
|
|
|
-}HDDIMG;
|
|
|
|
|
|
+
|
|
HDDIMG img[NUM_SCSIID][NUM_SCSILUN]; // Maximum number
|
|
HDDIMG img[NUM_SCSIID][NUM_SCSILUN]; // Maximum number
|
|
|
|
|
|
uint8_t m_senseKey = 0; // Sense key
|
|
uint8_t m_senseKey = 0; // Sense key
|
|
@@ -203,7 +195,7 @@ static const byte db2scsiid[256]={
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
|
|
-FsFile LOG_FILE;
|
|
|
|
|
|
+
|
|
|
|
|
|
// SCSI Drive Vendor information
|
|
// SCSI Drive Vendor information
|
|
byte SCSI_INFO_BUF[36] = {
|
|
byte SCSI_INFO_BUF[36] = {
|
|
@@ -219,40 +211,7 @@ byte SCSI_INFO_BUF[36] = {
|
|
'1', '.', '0', ' ' // version 4
|
|
'1', '.', '0', ' ' // version 4
|
|
};
|
|
};
|
|
|
|
|
|
-void onFalseInit(void);
|
|
|
|
-void noSDCardFound(void);
|
|
|
|
-void onBusReset(void);
|
|
|
|
-void sdCardInsert(void);
|
|
|
|
-void switchImage(void);
|
|
|
|
-void initFileLog(void);
|
|
|
|
-void finalizeFileLog(void);
|
|
|
|
-//------------------------------------------------------------------------------
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-void errorPrint() {
|
|
|
|
- if (SD.sdErrorCode()) {
|
|
|
|
- cout << F("SD errorCode: ") << hex << showbase;
|
|
|
|
- printSdErrorSymbol(&Serial, SD.sdErrorCode());
|
|
|
|
- cout << F(" = ") << int(SD.sdErrorCode()) << endl;
|
|
|
|
- cout << F("SD errorData = ") << int(SD.sdErrorData()) << endl;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-//------------------------------------------------------------------------------
|
|
|
|
-void dmpVol() {
|
|
|
|
- cout << F("\nScanning FAT, please wait.\n");
|
|
|
|
- uint32_t freeClusterCount = SD.freeClusterCount();
|
|
|
|
- if (SD.fatType() <= 32) {
|
|
|
|
- cout << F("\nVolume is FAT") << int(SD.fatType()) << endl;
|
|
|
|
- } else {
|
|
|
|
- cout << F("\nVolume is exFAT\n");
|
|
|
|
- }
|
|
|
|
- cout << F("sectorsPerCluster: ") << SD.sectorsPerCluster() << endl;
|
|
|
|
- cout << F("clusterCount: ") << SD.clusterCount() << endl;
|
|
|
|
- cout << F("freeClusterCount: ") << freeClusterCount << endl;
|
|
|
|
- cout << F("fatStartSector: ") << SD.fatStartSector() << endl;
|
|
|
|
- cout << F("dataStartSector: ") << SD.dataStartSector() << endl;
|
|
|
|
|
|
|
|
-}
|
|
|
|
/*
|
|
/*
|
|
* IO read.
|
|
* IO read.
|
|
*/
|
|
*/
|
|
@@ -270,96 +229,8 @@ inline byte readIO(void)
|
|
return bret;
|
|
return bret;
|
|
}
|
|
}
|
|
|
|
|
|
-// If config file exists, read the first three lines and copy the contents.
|
|
|
|
-// File must be well formed or you will get junk in the SCSI Vendor fields.
|
|
|
|
-void readSCSIDeviceConfig() {
|
|
|
|
- FsFile config_file = SD.open("scsi-config.txt", O_RDONLY);
|
|
|
|
- if (!config_file.isOpen()) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- char vendor[9];
|
|
|
|
- memset(vendor, 0, sizeof(vendor));
|
|
|
|
- config_file.readBytes(vendor, sizeof(vendor));
|
|
|
|
- LOG_FILE.print("SCSI VENDOR: ");
|
|
|
|
- LOG_FILE.println(vendor);
|
|
|
|
- memcpy(&(SCSI_INFO_BUF[8]), vendor, 8);
|
|
|
|
-
|
|
|
|
- char product[17];
|
|
|
|
- memset(product, 0, sizeof(product));
|
|
|
|
- config_file.readBytes(product, sizeof(product));
|
|
|
|
- LOG_FILE.print("SCSI PRODUCT: ");
|
|
|
|
- LOG_FILE.println(product);
|
|
|
|
- memcpy(&(SCSI_INFO_BUF[16]), product, 16);
|
|
|
|
-
|
|
|
|
- char version[5];
|
|
|
|
- memset(version, 0, sizeof(version));
|
|
|
|
- config_file.readBytes(version, sizeof(version));
|
|
|
|
- LOG_FILE.print("SCSI VERSION: ");
|
|
|
|
- LOG_FILE.println(version);
|
|
|
|
- memcpy(&(SCSI_INFO_BUF[32]), version, 4);
|
|
|
|
- config_file.close();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// read SD information and print to logfile
|
|
|
|
-void readSDCardInfo()
|
|
|
|
-{
|
|
|
|
- cid_t sd_cid;
|
|
|
|
|
|
|
|
- if(SD.card()->readCID(&sd_cid))
|
|
|
|
- {
|
|
|
|
- Serial.print("Sd MID:");
|
|
|
|
- Serial.print(sd_cid.mid, 16);
|
|
|
|
- Serial.print(" OID:");
|
|
|
|
- Serial.print(sd_cid.oid[0]);
|
|
|
|
- Serial.println(sd_cid.oid[1]);
|
|
|
|
-
|
|
|
|
- Serial.print("Sd Name:");
|
|
|
|
- Serial.print(sd_cid.pnm[0]);
|
|
|
|
- Serial.print(sd_cid.pnm[1]);
|
|
|
|
- Serial.print(sd_cid.pnm[2]);
|
|
|
|
- Serial.print(sd_cid.pnm[3]);
|
|
|
|
- Serial.println(sd_cid.pnm[4]);
|
|
|
|
-
|
|
|
|
- Serial.print("Sd Date:");
|
|
|
|
- Serial.print(sd_cid.mdt_month);
|
|
|
|
- Serial.print("/20"); // CID year is 2000 + high/low
|
|
|
|
- Serial.print(sd_cid.mdt_year_high);
|
|
|
|
- Serial.println(sd_cid.mdt_year_low);
|
|
|
|
-
|
|
|
|
- Serial.print("Sd Serial:");
|
|
|
|
- Serial.println(sd_cid.psn);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-void readSDCardInfo2()
|
|
|
|
-{
|
|
|
|
- cid_t sd_cid;
|
|
|
|
|
|
|
|
- if(SD.card()->readCID(&sd_cid))
|
|
|
|
- {
|
|
|
|
- LOG_FILE.print("Sd MID:");
|
|
|
|
- LOG_FILE.print(sd_cid.mid, 16);
|
|
|
|
- LOG_FILE.print(" OID:");
|
|
|
|
- LOG_FILE.print(sd_cid.oid[0]);
|
|
|
|
- LOG_FILE.println(sd_cid.oid[1]);
|
|
|
|
-
|
|
|
|
- LOG_FILE.print("Sd Name:");
|
|
|
|
- LOG_FILE.print(sd_cid.pnm[0]);
|
|
|
|
- LOG_FILE.print(sd_cid.pnm[1]);
|
|
|
|
- LOG_FILE.print(sd_cid.pnm[2]);
|
|
|
|
- LOG_FILE.print(sd_cid.pnm[3]);
|
|
|
|
- LOG_FILE.println(sd_cid.pnm[4]);
|
|
|
|
-
|
|
|
|
- LOG_FILE.print("Sd Date:");
|
|
|
|
- LOG_FILE.print(sd_cid.mdt_month);
|
|
|
|
- LOG_FILE.print("/20"); // CID year is 2000 + high/low
|
|
|
|
- LOG_FILE.print(sd_cid.mdt_year_high);
|
|
|
|
- LOG_FILE.println(sd_cid.mdt_year_low);
|
|
|
|
-
|
|
|
|
- LOG_FILE.print("Sd Serial:");
|
|
|
|
- LOG_FILE.println(sd_cid.psn);
|
|
|
|
- LOG_FILE.sync();
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
/*
|
|
/*
|
|
* Open HDD image file
|
|
* Open HDD image file
|
|
*/
|
|
*/
|
|
@@ -411,37 +282,19 @@ void setup()
|
|
|
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
- // PIN initialization
|
|
|
|
- pinMode(BOARD_LED1_PIN , OUTPUT);
|
|
|
|
- pinMode(BOARD_LED2_PIN , OUTPUT);
|
|
|
|
- pinMode(BOARD_LED3_PIN , OUTPUT);
|
|
|
|
- pinMode(BOARD_SDCARD_INSERT, INPUT_PULLUP);
|
|
|
|
- pinMode(BOARD_SWITCH1_PIN , INPUT_PULLUP);
|
|
|
|
- pinMode(BOARD_SWITCH2_PIN , INPUT_PULLUP);
|
|
|
|
- pinMode(BOARD_SWITCH3_PIN , INPUT_PULLUP);
|
|
|
|
- pinMode(BOARD_SWITCH4_PIN , INPUT_PULLUP);
|
|
|
|
- pinMode(BOARD_SCSI_TERM_HIGH, OUTPUT);
|
|
|
|
- pinMode(BOARD_SCSI_TERM_LOW, OUTPUT);
|
|
|
|
- pinMode(BOARD_SCSI_TERM_POWER, INPUT); //Check if external termination power is provided
|
|
|
|
|
|
+ gpioInit();
|
|
|
|
|
|
//Default turn termination off
|
|
//Default turn termination off
|
|
TERMINATION_HIGH();
|
|
TERMINATION_HIGH();
|
|
|
|
|
|
//Turn Power LED ON
|
|
//Turn Power LED ON
|
|
LED2_ON();
|
|
LED2_ON();
|
|
-
|
|
|
|
- attachInterrupt(BOARD_SDCARD_INSERT,sdCardInsert, CHANGE);
|
|
|
|
-
|
|
|
|
//Check if SD card is inserted
|
|
//Check if SD card is inserted
|
|
sdCardInsert();
|
|
sdCardInsert();
|
|
|
|
|
|
- attachInterrupt(BOARD_SWITCH1_PIN,switchImage, CHANGE);
|
|
|
|
- attachInterrupt(BOARD_SWITCH2_PIN,switchImage, CHANGE);
|
|
|
|
- attachInterrupt(BOARD_SWITCH3_PIN,switchImage, CHANGE);
|
|
|
|
- attachInterrupt(BOARD_SWITCH4_PIN,switchImage, CHANGE);
|
|
|
|
-
|
|
|
|
//Check which image to load
|
|
//Check which image to load
|
|
switchImage();
|
|
switchImage();
|
|
|
|
+
|
|
/*
|
|
/*
|
|
// set up OTYPER for open drain on SCSI pins of PA and PB
|
|
// set up OTYPER for open drain on SCSI pins of PA and PB
|
|
// PA 0-7, 11-14
|
|
// PA 0-7, 11-14
|
|
@@ -456,23 +309,7 @@ void setup()
|
|
uint32_t oTypeB_Or = 0x0000F7FD;
|
|
uint32_t oTypeB_Or = 0x0000F7FD;
|
|
GPIOB->regs->OTYPER = (GPIOB->regs->OTYPER & oTypeB_And) | oTypeB_Or;
|
|
GPIOB->regs->OTYPER = (GPIOB->regs->OTYPER & oTypeB_And) | oTypeB_Or;
|
|
*/
|
|
*/
|
|
- pinMode(BOARD_SCSI_ATN, INPUT_PULLUP);
|
|
|
|
- pinMode(BOARD_SCSI_BSY, INPUT_PULLUP);
|
|
|
|
- pinMode(BOARD_SCSI_ACK, INPUT_PULLUP);
|
|
|
|
- pinMode(BOARD_SCSI_RST, INPUT_PULLUP);
|
|
|
|
- pinMode(BOARD_SCSI_SEL, INPUT_PULLUP);
|
|
|
|
-
|
|
|
|
- // Output port
|
|
|
|
- pinMode(BOARD_SCSI_MSG, OUTPUT_OPEN_DRAIN);
|
|
|
|
- pinMode(BOARD_SCSI_CD, OUTPUT_OPEN_DRAIN);
|
|
|
|
- pinMode(BOARD_SCSI_REQ, OUTPUT_OPEN_DRAIN);
|
|
|
|
- pinMode(BOARD_SCSI_IO, OUTPUT_OPEN_DRAIN);
|
|
|
|
-
|
|
|
|
- // Control SCSI drivers
|
|
|
|
- pinMode(BOARD_SCSI_DTD, OUTPUT_OPEN_DRAIN);
|
|
|
|
- pinMode(BOARD_SCSI_IND, OUTPUT_OPEN_DRAIN);
|
|
|
|
- pinMode(BOARD_SCSI_TAD, OUTPUT_OPEN_DRAIN);
|
|
|
|
- pinMode(BOARD_TRANS_OE, OUTPUT_OPEN_DRAIN);
|
|
|
|
|
|
+
|
|
/*
|
|
/*
|
|
// Turn off the output port
|
|
// Turn off the output port
|
|
SCSI_TARGET_INACTIVE()
|
|
SCSI_TARGET_INACTIVE()
|
|
@@ -495,9 +332,6 @@ void setup()
|
|
readSCSIDeviceConfig();
|
|
readSCSIDeviceConfig();
|
|
initFileLog();
|
|
initFileLog();
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
//Sector data overrun byte setting
|
|
//Sector data overrun byte setting
|
|
m_buf[MAX_BLOCKSIZE] = 0xff; // DB0 all off,DBP off
|
|
m_buf[MAX_BLOCKSIZE] = 0xff; // DB0 all off,DBP off
|
|
//HD image file open
|
|
//HD image file open
|
|
@@ -589,62 +423,9 @@ void setup()
|
|
attachInterrupt(BOARD_SCSI_RST, onBusReset, FALLING);
|
|
attachInterrupt(BOARD_SCSI_RST, onBusReset, FALLING);
|
|
}
|
|
}
|
|
|
|
|
|
-/*
|
|
|
|
- * Setup initialization logfile
|
|
|
|
- */
|
|
|
|
-void initFileLog() {
|
|
|
|
- LOG_FILE = SD.open(LOG_FILENAME, O_WRONLY | O_CREAT | O_TRUNC);
|
|
|
|
- LOG_FILE.println("BlackSASI F411 <-> SD ");
|
|
|
|
- LOG_FILE.print("VERSION: ");
|
|
|
|
- LOG_FILE.println(VERSION);
|
|
|
|
- LOG_FILE.print("DEBUG:");
|
|
|
|
- LOG_FILE.print(DEBUG);
|
|
|
|
- LOG_FILE.print(" SCSI_SELECT:");
|
|
|
|
- LOG_FILE.print(SCSI_SELECT);
|
|
|
|
- LOG_FILE.print(" SDFAT_FILE_TYPE:");
|
|
|
|
- LOG_FILE.println(SDFAT_FILE_TYPE);
|
|
|
|
- LOG_FILE.print("SdFat version: ");
|
|
|
|
- LOG_FILE.println(SD_FAT_VERSION_STR);
|
|
|
|
- LOG_FILE.print("SdFat Max FileName Length: ");
|
|
|
|
- LOG_FILE.println(MAX_FILE_PATH);
|
|
|
|
- LOG_FILE.println("Initialized SD Card - lets go!");
|
|
|
|
- LOG_FILE.sync();
|
|
|
|
-}
|
|
|
|
|
|
|
|
-/*
|
|
|
|
- * Finalize initialization logfile
|
|
|
|
- */
|
|
|
|
-void finalizeFileLog() {
|
|
|
|
- // View support drive map
|
|
|
|
- LOG_FILE.print("ID");
|
|
|
|
- for(int lun=0;lun<NUM_SCSILUN;lun++)
|
|
|
|
- {
|
|
|
|
- LOG_FILE.print(":LUN");
|
|
|
|
- LOG_FILE.print(lun);
|
|
|
|
- }
|
|
|
|
- LOG_FILE.println(":");
|
|
|
|
- //
|
|
|
|
- for(int id=0;id<NUM_SCSIID;id++)
|
|
|
|
- {
|
|
|
|
- LOG_FILE.print(" ");
|
|
|
|
- LOG_FILE.print(id);
|
|
|
|
- for(int lun=0;lun<NUM_SCSILUN;lun++)
|
|
|
|
- {
|
|
|
|
- HDDIMG *h = &img[id][lun];
|
|
|
|
- if( (lun<NUM_SCSILUN) && (h->m_file))
|
|
|
|
- {
|
|
|
|
- LOG_FILE.print((h->m_blocksize<1000) ? ": " : ":");
|
|
|
|
- LOG_FILE.print(h->m_blocksize);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- LOG_FILE.print(":----");
|
|
|
|
- }
|
|
|
|
- LOG_FILE.println(":");
|
|
|
|
- }
|
|
|
|
- LOG_FILE.println("Finished initialization of SCSI Devices - Entering main loop.");
|
|
|
|
- LOG_FILE.sync();
|
|
|
|
- LOG_FILE.close();
|
|
|
|
-}
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
/*
|
|
/*
|
|
* Initialization failed, blink 3x fast
|
|
* Initialization failed, blink 3x fast
|
|
@@ -663,28 +444,7 @@ void onFalseInit(void)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-/*
|
|
|
|
- * No SC Card found, blink 5x fast
|
|
|
|
- */
|
|
|
|
-void noSDCardFound(void)
|
|
|
|
-{
|
|
|
|
- while(!SD.begin(SdSpiConfig(SS, DEDICATED_SPI))) {
|
|
|
|
- for(int i = 0; i < 5; i++) {
|
|
|
|
- LED3_ON();
|
|
|
|
- delay(500);
|
|
|
|
- LED3_OFF();
|
|
|
|
- delay(500);
|
|
|
|
- }
|
|
|
|
- delay(1000);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-void sdCardInsert(void){
|
|
|
|
- if (digitalRead(BOARD_SDCARD_INSERT)){
|
|
|
|
- LED1_OFF();
|
|
|
|
- }else{
|
|
|
|
- LED1_ON();
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+
|
|
void switchImage(void){
|
|
void switchImage(void){
|
|
|
|
|
|
uint16_t oldimageSelect = imageSelect;
|
|
uint16_t oldimageSelect = imageSelect;
|