Selaa lähdekoodia

Some more pin fixes

Per Mårtensson 2 vuotta sitten
vanhempi
commit
83cd053a77
7 muutettua tiedostoa jossa 74 lisäystä ja 96 poistoa
  1. 1 1
      sw/include/blacksasi.h
  2. 1 0
      sw/include/config.h
  3. 8 4
      sw/json/blacksasi.json
  4. 4 0
      sw/src/config.cpp
  5. 21 11
      sw/src/gpio.cpp
  6. 26 5
      sw/src/log.cpp
  7. 13 75
      sw/src/main.cpp

+ 1 - 1
sw/include/blacksasi.h

@@ -162,7 +162,7 @@ typedef struct hddimg_struct
 void onFalseInit(void);
 void onBusReset(void);
 void switchImage(void);
-void initFileLog(void);
+void initFileLog(int);
 void finalizeFileLog(void);
 
 

+ 1 - 0
sw/include/config.h

@@ -4,4 +4,5 @@
 #include "sdios.h"
 #include "blacksasi.h"
 void readSCSIDeviceConfig(uint8_t disc);
+uint32 readHWVersion();
 #endif // __BLACKSASI_CONFIG_H__

+ 8 - 4
sw/json/blacksasi.json

@@ -19,7 +19,8 @@
                     "readonly": "false",
                     "vendor": "SWEPROJ",
                     "product": "BLACKSASI",
-                    "version": "1.0"
+                    "version": "1.0",
+                    "type": "HDD"
                 },
                 {
                     "name": "ABC1600 disc 2",
@@ -30,7 +31,8 @@
                     "readonly": "false",
                     "vendor": "SWEPROJ",
                     "product": "BLACKSASI",
-                    "version": "1.0"
+                    "version": "1.0",
+                    "type": "HDD"
                 }
             ]
         },
@@ -48,7 +50,8 @@
                     "readonly": "false",
                     "vendor": "SWEPROJ",
                     "product": "BLACKSASI",
-                    "version": "1.0"
+                    "version": "1.0",
+                    "type": "HDD"
                 },
                 {
                     "name": "ABC1600 disc 2",
@@ -59,7 +62,8 @@
                     "readonly": "false",
                     "vendor": "SWEPROJ",
                     "product": "BLACKSASI",
-                    "version": "1.0"
+                    "version": "1.0",
+                    "type": "CDROM"
                 }
             ]
         }

+ 4 - 0
sw/src/config.cpp

@@ -22,4 +22,8 @@ void readSCSIDeviceConfig(uint8_t disc) {
   String configx =config["config"];
   Serial.println(configx);
 
+}
+uint32 readHWVersion(){
+    return((digitalRead(BOARD_REV_PIN0 ) == LOW) ) | ((digitalRead(BOARD_REV_PIN1 ) == LOW) ) << 1 | ((digitalRead(BOARD_REV_PIN2) == LOW) ) << 2;
+  
 }

+ 21 - 11
sw/src/gpio.cpp

@@ -1,6 +1,6 @@
 #include <Arduino.h>
 #include "gpio.h"
-
+#include "blacksasi.h"
 extern void sdCardInsert();
 extern void switchImage();
 bool gpioInit(void){
@@ -26,17 +26,7 @@ bool gpioInit(void){
     attachInterrupt(BOARD_SWITCH3_PIN,switchImage, CHANGE);
     attachInterrupt(BOARD_SWITCH4_PIN,switchImage, CHANGE);
 
-    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);
-    pinMode(BOARD_SCSI_CD, OUTPUT);
-    pinMode(BOARD_SCSI_REQ, OUTPUT);
-    pinMode(BOARD_SCSI_IO, OUTPUT);
 
     // Control SCSI drivers
     pinMode(BOARD_SCSI_DTD, OUTPUT);
@@ -45,5 +35,25 @@ bool gpioInit(void){
     pinMode(BOARD_TRANS_OE, OUTPUT);
 
     digitalWrite(BOARD_TRANS_OE, LOW);
+    SCSI_DB_INPUT()
+    TRANSCEIVER_IO_SET(vDTD,DB_INPUT);
+    SCSI_DB_INPUT()
+
+    TRANSCEIVER_IO_SET(vDTD,DB_INPUT);
+    
+    // Initiator port
+    pinMode(BOARD_SCSI_ATN, INPUT);
+    pinMode(BOARD_SCSI_BSY, INPUT);
+    pinMode(BOARD_SCSI_ACK, INPUT);
+    pinMode(BOARD_SCSI_RST, INPUT);
+    pinMode(BOARD_SCSI_SEL, INPUT);
+    TRANSCEIVER_IO_SET(vIND,TR_INPUT);
+
+    // Target port
+    pinMode(BOARD_SCSI_MSG, INPUT);
+    pinMode(BOARD_SCSI_CD, INPUT);
+    pinMode(BOARD_SCSI_REQ, INPUT);
+    pinMode(BOARD_SCSI_IO, INPUT);
+    TRANSCEIVER_IO_SET(vTAD,TR_INPUT);
 }
   

+ 26 - 5
sw/src/log.cpp

@@ -9,24 +9,45 @@ extern SCSI_DEVICE scsi_device_list[NUM_SCSIID][NUM_SCSILUN];
 /*
  * Setup initialization logfile
  */
-void initFileLog() {
+
+/*
+ * Setup initialization logfile
+ */
+void initFileLog(int success_mhz) {
   LOG_FILE = SD.open(LOG_FILENAME, O_WRONLY | O_CREAT | O_TRUNC);
-  LOG_FILE.println("BlackSASI F411 <-> SD ");
+  LOG_FILE.println("BlackSASI <-> 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("Sd Format: ");
+  switch(SD.vol()->fatType()) {
+    case FAT_TYPE_EXFAT:
+    LOG_FILE.println("exFAT");
+    break;
+    case FAT_TYPE_FAT32:
+    LOG_FILE.print("FAT32");
+    case FAT_TYPE_FAT16:
+    LOG_FILE.print("FAT16");
+    default:
+    LOG_FILE.println(" - Consider formatting the SD Card with exFAT for improved performance.");
+  }
+  LOG_FILE.print("SPI speed: ");
+  LOG_FILE.print(success_mhz);
+  LOG_FILE.println("Mhz");
+  if (success_mhz <= 24) {
+    LOG_FILE.println("*** Slow SPI connection to SD card may cause performance degradation");
+  }
   LOG_FILE.print("SdFat Max FileName Length: ");
   LOG_FILE.println(MAX_FILE_PATH);
-  LOG_FILE.println("Initialized SD Card - lets go!");
+  LOG_FILE.println("Initialized SD Card - let's go!");
   LOG_FILE.sync();
 }
+
 void errorPrint() {
   if (SD.sdErrorCode()) {
     cout << F("SD errorCode: ") << hex << showbase;

+ 13 - 75
sw/src/main.cpp

@@ -47,18 +47,10 @@
                                 // 1: Debug information output to USB Serial
                                 // 2: Debug information output to LOG.txt (slow)
 
-
-
-#ifndef MCU_STM32F401CC
-#define MCV "F4"
-#else
-#define MCV "F4Lite"
-#endif
-
 #define VDS "2022-09-20"
 
 // Log File
-#define VERSION "1.1-" VDS "-XCVR-" MCV
+#define VERSION "1.1-" VDS "-BLACKSASI"
 #define LOG_FILENAME "LOG.txt"
 
 #include "blacksasi.h"
@@ -122,9 +114,7 @@ static uint32_t MSFtoLBA(const byte *msf);
 static void LBAtoMSF(const uint32_t lba, byte *msf);
 
 static void flashError(const unsigned error);
-void onBusReset(void);
-void initFileLog(int);
-void finalizeFileLog(void);
+
 void findDriveImages(FsFile root);
 
 /*
@@ -367,7 +357,10 @@ void setup()
   delay(3000);
 
 
-  int image_file_set = ((digitalRead(BOARD_SWITCH1_PIN) == LOW) ) | ((digitalRead(BOARD_SWITCH2_PIN) == LOW) ) << 1 | ((digitalRead(BOARD_SWITCH3_PIN) == LOW) ) << 2 | ((digitalRead(BOARD_SWITCH4_PIN) == LOW) ) << 3;
+  int image_file_set =  ((digitalRead(BOARD_SWITCH1_PIN) == LOW) ) | 
+                        ((digitalRead(BOARD_SWITCH2_PIN) == LOW) ) << 1 | 
+                        ((digitalRead(BOARD_SWITCH3_PIN) == LOW) ) << 2 | 
+                        ((digitalRead(BOARD_SWITCH4_PIN) == LOW) ) << 3;
   
 
   // Transceiver Pin Initialization
@@ -379,24 +372,7 @@ void setup()
   TRANSCEIVER_IO_SET(vTAD,TR_INPUT);
 
 
-  SCSI_DB_INPUT()
-
-  TRANSCEIVER_IO_SET(vDTD,DB_INPUT);
-  
-  // Initiator port
-  pinMode(BOARD_SCSI_ATN, INPUT);
-  pinMode(BOARD_SCSI_BSY, INPUT);
-  pinMode(BOARD_SCSI_ACK, INPUT);
-  pinMode(BOARD_SCSI_RST, INPUT);
-  pinMode(BOARD_SCSI_SEL, INPUT);
-  TRANSCEIVER_IO_SET(vIND,TR_INPUT);
 
-  // Target port
-  pinMode(BOARD_SCSI_MSG, INPUT);
-  pinMode(BOARD_SCSI_CD, INPUT);
-  pinMode(BOARD_SCSI_REQ, INPUT);
-  pinMode(BOARD_SCSI_IO, INPUT);
-  TRANSCEIVER_IO_SET(vTAD,TR_INPUT);
   
   // Turn off the output port
   SCSI_TARGET_INACTIVE()
@@ -410,7 +386,7 @@ void setup()
   // Try each speed bucket a few times, and go way down for very old SD cards
   // Most will initialize immediately at the highest speed
   int speedsToTry[] = {50, 49, 43, 42, 25, 24, 17, 16, 8, 7, 5, 4, 3, 1 };
-  for (int i = 0; i < 14; i++) {
+  for (int i = 0; i < sizeof(speedsToTry); i++) {
     if(SD.begin(SdSpiConfig(SS, DEDICATED_SPI, SD_SCK_MHZ(speedsToTry[i])))) {
       mhz = speedsToTry[i];
       break;
@@ -600,44 +576,6 @@ void findDriveImages(FsFile root) {
   SD.chdir("/");
 }
 
-/*
- * Setup initialization logfile
- */
-void initFileLog(int success_mhz) {
-  LOG_FILE = SD.open(LOG_FILENAME, O_WRONLY | O_CREAT | O_TRUNC);
-  LOG_FILE.println("BlackSASI <-> SD");
-  LOG_FILE.print("VERSION: ");
-  LOG_FILE.println(VERSION);
-  LOG_FILE.print("DEBUG:");
-  LOG_FILE.print(DEBUG);
-  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("Sd Format: ");
-  switch(SD.vol()->fatType()) {
-    case FAT_TYPE_EXFAT:
-    LOG_FILE.println("exFAT");
-    break;
-    case FAT_TYPE_FAT32:
-    LOG_FILE.print("FAT32");
-    case FAT_TYPE_FAT16:
-    LOG_FILE.print("FAT16");
-    default:
-    LOG_FILE.println(" - Consider formatting the SD Card with exFAT for improved performance.");
-  }
-  LOG_FILE.print("SPI speed: ");
-  LOG_FILE.print(success_mhz);
-  LOG_FILE.println("Mhz");
-  if (success_mhz <= 24) {
-    LOG_FILE.println("*** Slow SPI connection to SD card may cause performance degradation");
-  }
-  LOG_FILE.print("SdFat Max FileName Length: ");
-  LOG_FILE.println(MAX_FILE_PATH);
-  LOG_FILE.println("Initialized SD Card - let's go!");
-  LOG_FILE.sync();
-}
-
 
 
 static void flashError(const unsigned error)
@@ -755,8 +693,8 @@ inline void writeHandshake(byte d)
   //while(!SCSI_IN(vACK)) { if(m_isBusReset){ SCSI_DB_INPUT() return; }}
   while(!SCSI_IN(vACK));
   // ACK.Fall to REQ.Raise delay 500ns(typ.) (DTC-510B)
-  uint32_t bsrrCall = ((db_bsrr[0xff] & 0xFFBFFFFF) | 0x00000040);
-  GPIOB->regs->BSRR = bsrrCall;  // DB=0xFF , SCSI_OUT(vREQ,inactive)
+  uint32_t bsrrCall = ((db_bsrr[0xff] & 0xFFDFFFFF) | 0x00000020);
+  GPIOE->regs->BSRR = bsrrCall;  // DB=0xFF , SCSI_OUT(vREQ,inactive)
   
   // REQ.Raise to DB hold time 0ns
   SCSI_DB_INPUT() // (150ns)
@@ -883,9 +821,9 @@ void readDataLoop(uint32_t blockSize, byte* dstptr)
   // Start of the do/while and WAIT are already aligned to 8 bytes.
   do {
     WAIT_ACK_ACTIVE();
-    uint32_t ret = PBREG->IDR;
+    uint32_t ret = PDREG->IDR;
     REQ_OFF();
-    *dstptr++ = (byte)~(((ret >> 8) & 0b11110111) | ((ret & 0x00000004) << 1));
+    *dstptr++ = (byte)~(((ret) & 0b11111111));
     // Move wait loop in to a single 8 byte prefetch buffer
     asm("nop.w;nop");
     WAIT_ACK_INACTIVE();
@@ -894,9 +832,9 @@ void readDataLoop(uint32_t blockSize, byte* dstptr)
     asm("nop");
   } while(dstptr<endptr);
   WAIT_ACK_ACTIVE();
-  uint32_t ret = GPIOB->regs->IDR;
+  uint32_t ret = GPIOD->regs->IDR;
   REQ_OFF();
-  *dstptr = (byte)~(((ret >> 8) & 0b11110111) | ((ret & 0x00000004) << 1));
+  *dstptr = (byte)~(((ret ) & 0b11111111) );
   WAIT_ACK_INACTIVE();
 }
 #pragma GCC pop_options