|
@@ -71,18 +71,15 @@ SdFs SD;
|
|
|
// Logfile
|
|
|
FsFile LOG_FILE;
|
|
|
|
|
|
-static const uint32_t scsiDbOutputRegOr = 0x55150011;
|
|
|
-static const uint32_t scsiDbInputOutputAnd = 0x00C0FFCC;
|
|
|
+static const uint32_t scsiDbOutputRegOr = 0x55150011; // 0b01010101 00010101 00000000 00010001
|
|
|
+static const uint32_t scsiDbInputOutputAnd = 0x00C0FFCC; // 0b00000000 11000000 11111111 11001100
|
|
|
// Put DB and DP in output mode
|
|
|
#define SCSI_DB_OUTPUT() { PBREG->MODER = (PBREG->MODER & scsiDbInputOutputAnd) | scsiDbOutputRegOr; }
|
|
|
|
|
|
// Put DB and DP in input mode
|
|
|
#define SCSI_DB_INPUT() { PBREG->MODER = (PBREG->MODER & scsiDbInputOutputAnd); }
|
|
|
|
|
|
-// Turn on the output only for BSY
|
|
|
-#define SCSI_BSY_ACTIVE() { pinMode(BOARD_SCSI_BSY, OUTPUT_OPEN_DRAIN); SCSI_OUT(vBSY, active) }
|
|
|
-// BSY,REQ,MSG,CD,IO Turn on the output (no change required for OD)
|
|
|
-#define SCSI_TARGET_ACTIVE() { }
|
|
|
+
|
|
|
// 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); }
|
|
|
|
|
@@ -198,7 +195,7 @@ static const byte db2scsiid[256]={
|
|
|
|
|
|
|
|
|
// SCSI Drive Vendor information
|
|
|
-byte SCSI_INFO_BUF[36] = {
|
|
|
+byte SCSI_INFO_BUF[SCSI_INFO_BUF_SIZE] = {
|
|
|
0x00, //device type
|
|
|
0x00, //RMB = 0
|
|
|
0x01, //ISO, ECMA, ANSI version
|
|
@@ -218,8 +215,10 @@ byte SCSI_INFO_BUF[36] = {
|
|
|
inline byte readIO(void)
|
|
|
{
|
|
|
// Port input data register
|
|
|
- uint32_t ret = GPIOB->regs->IDR;
|
|
|
- byte bret = (byte)~(((ret >> 8) & 0b11110111) | ((ret & 0x00000004) << 1));
|
|
|
+ // FIXED FOR BLACKSASI
|
|
|
+ uint32_t ret = GPIOD->regs->IDR;
|
|
|
+ byte bret = (byte)(~(ret));
|
|
|
+
|
|
|
|
|
|
#if READ_PARITY_CHECK
|
|
|
if((db_bsrr[bret]^ret)&1) // TODO fix parity calculation
|
|
@@ -230,6 +229,21 @@ inline byte readIO(void)
|
|
|
}
|
|
|
|
|
|
|
|
|
+/*
|
|
|
+ * Read by handshake.
|
|
|
+ */
|
|
|
+inline byte readHandshake(void)
|
|
|
+{
|
|
|
+ // FIXED FOR BLACKSASI
|
|
|
+ SCSI_OUT(vREQ,active)
|
|
|
+ //SCSI_DB_INPUT()
|
|
|
+ while( ! SCSI_IN(vACK)) { if(m_isBusReset) return 0; }
|
|
|
+ byte r = readIO();
|
|
|
+ SCSI_OUT(vREQ,inactive)
|
|
|
+ while( SCSI_IN(vACK)) { if(m_isBusReset) return 0; }
|
|
|
+ return r;
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
/*
|
|
|
* Open HDD image file
|
|
@@ -266,6 +280,9 @@ bool hddimageOpen(HDDIMG *h,const char *image_name,int id,int lun,int blocksize)
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/*
|
|
|
* Initialization.
|
|
|
* Initialize the bus and set the PIN orientation
|
|
@@ -277,7 +294,6 @@ void setup()
|
|
|
Serial.begin(19200);
|
|
|
delay(3000);
|
|
|
Serial.println("BLACKSASI");
|
|
|
- Serial.println("BLACKSASI");
|
|
|
Serial.flush();
|
|
|
|
|
|
#endif
|
|
@@ -295,7 +311,7 @@ void setup()
|
|
|
//Check which image to load
|
|
|
switchImage();
|
|
|
|
|
|
- /*
|
|
|
+
|
|
|
// set up OTYPER for open drain on SCSI pins of PA and PB
|
|
|
// PA 0-7, 11-14
|
|
|
uint32_t oTypeA_And = 0x000078FF;
|
|
@@ -308,17 +324,15 @@ void setup()
|
|
|
// PB 0, 2-10, 12-15 are used for SCSI, set open drain
|
|
|
uint32_t oTypeB_Or = 0x0000F7FD;
|
|
|
GPIOB->regs->OTYPER = (GPIOB->regs->OTYPER & oTypeB_And) | oTypeB_Or;
|
|
|
-*/
|
|
|
|
|
|
-/*
|
|
|
+
|
|
|
+
|
|
|
// Turn off the output port
|
|
|
SCSI_TARGET_INACTIVE()
|
|
|
|
|
|
//Occurs when the RST pin state changes from HIGH to LOW
|
|
|
- //attachInterrupt(PIN_MAP[RST].gpio_bit, onBusReset, FALLING);
|
|
|
+ attachInterrupt(BOARD_SCSI_RST, onBusReset, FALLING);
|
|
|
|
|
|
- LED_ON();
|
|
|
- */
|
|
|
|
|
|
if(!SD.begin(SdSpiConfig(SS, DEDICATED_SPI))) {
|
|
|
#if DEBUG > 0
|
|
@@ -425,8 +439,6 @@ void setup()
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/*
|
|
|
* Initialization failed, blink 3x fast
|
|
|
*/
|
|
@@ -445,21 +457,7 @@ void onFalseInit(void)
|
|
|
}
|
|
|
|
|
|
|
|
|
-void switchImage(void){
|
|
|
-
|
|
|
- uint16_t oldimageSelect = imageSelect;
|
|
|
- imageSelect = digitalRead(BOARD_SWITCH1_PIN) |
|
|
|
- digitalRead(BOARD_SWITCH2_PIN) << 1 |
|
|
|
- digitalRead(BOARD_SWITCH3_PIN) << 2 |
|
|
|
- digitalRead(BOARD_SWITCH4_PIN) << 3;
|
|
|
- if ( oldimageSelect!=imageSelect){
|
|
|
- Serial.print("Image: ");
|
|
|
- Serial.println(15-imageSelect);
|
|
|
- Serial.flush();
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
-}
|
|
|
/*
|
|
|
* Bus reset interrupt.
|
|
|
*/
|
|
@@ -488,19 +486,7 @@ void onBusReset(void)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
- * Read by handshake.
|
|
|
- */
|
|
|
-inline byte readHandshake(void)
|
|
|
-{
|
|
|
- SCSI_OUT(vREQ,active)
|
|
|
- //SCSI_DB_INPUT()
|
|
|
- while( ! SCSI_IN(vACK)) { if(m_isBusReset) return 0; }
|
|
|
- byte r = readIO();
|
|
|
- SCSI_OUT(vREQ,inactive)
|
|
|
- while( SCSI_IN(vACK)) { if(m_isBusReset) return 0; }
|
|
|
- return r;
|
|
|
-}
|
|
|
+
|
|
|
|
|
|
/*
|
|
|
* Write with a handshake.
|
|
@@ -518,7 +504,7 @@ inline void writeHandshake(byte d)
|
|
|
while(!m_isBusReset && !SCSI_IN(vACK));
|
|
|
|
|
|
// ACK.Fall to REQ.Raise delay 500ns(typ.) (DTC-510B)
|
|
|
- uint32_t bsrrCall = ((db_bsrr[0xff] & 0xFFBFFFFF) | 0x00000040);
|
|
|
+ uint32_t bsrrCall = ((db_bsrr[0xff] & 0xFFBFFFFF) | 0x00000040); //BLACKSASI CHECK
|
|
|
GPIOB->regs->BSRR = bsrrCall; // DB=0xFF , SCSI_OUT(vREQ,inactive)
|
|
|
|
|
|
// REQ.Raise to DB hold time 0ns
|
|
@@ -799,9 +785,9 @@ byte onReadCommand(uint32_t adds, uint32_t len)
|
|
|
|
|
|
if(!m_img) return 0x02; // Image file absent
|
|
|
|
|
|
- //LED_ON();
|
|
|
+ LED1_ON();
|
|
|
writeDataPhaseSD(adds, len);
|
|
|
- //LED_OFF();
|
|
|
+ LED1_OFF();
|
|
|
return 0x00; //sts
|
|
|
}
|
|
|
|
|
@@ -817,9 +803,9 @@ byte onWriteCommand(uint32_t adds, uint32_t len)
|
|
|
|
|
|
if(!m_img) return 0x02; // Image file absent
|
|
|
|
|
|
- //LED_ON();
|
|
|
+ LED1_ON();
|
|
|
readDataPhaseSD(adds, len);
|
|
|
- //LED_OFF();
|
|
|
+ LED1_OFF();
|
|
|
return 0; //sts
|
|
|
}
|
|
|
|