Browse Source

Move code between files

Per Mårtensson 3 years ago
parent
commit
96be10c65f
8 changed files with 94 additions and 64 deletions
  1. 9 9
      sw/include/blacksasi.h
  2. 13 0
      sw/include/gpio.h
  3. 11 0
      sw/include/scsi.h
  4. 1 0
      sw/include/sdcard.h
  5. 4 4
      sw/src/config.cpp
  6. 36 50
      sw/src/main.cpp
  7. 3 0
      sw/src/scsi.cpp
  8. 17 1
      sw/src/sdcard.cpp

+ 9 - 9
sw/include/blacksasi.h

@@ -4,6 +4,7 @@
 #include "gpio.h"
 #include "log.h"
 #include "config.h"
+#include "scsi.h"
 // Log File
 #define VERSION "0.xx-SNAPSHOT-BLACKSASI-2022-03-20-F4"
 
@@ -77,15 +78,7 @@
 #define PDREG GPIOD->regs
 #define PEREG GPIOE->regs
 
-// LED control
-#define LED1_ON()           PAREG->BSRR = 0b0000000000010000;
-#define LED1_OFF()          PAREG->BSRR = 0b0000000000010000 << 16;
-#define LED2_ON()           PAREG->BSRR = 0b0000000000100000;
-#define LED2_OFF()          PAREG->BSRR = 0b0000000000100000 << 16;
-#define LED3_ON()           PAREG->BSRR = 0b0000000001000000;
-#define LED3_OFF()          PAREG->BSRR = 0b0000000001000000 << 16;
-#define LED_EXT_ON()        PAREG->BSRR = 0b0000000000000001;
-#define LED_EXT_OFF()       PAREG->BSRR = 0b0000000000000001 << 16;
+
 
 // Termination controll
 #define TERMINATION_HIGH()  PBREG->BSRR = 0b0000000100000000 << 16 | 0b0000001000000000 ;
@@ -98,6 +91,7 @@
 #define PC(BIT)       (BIT + 32)
 #define PD(BIT)       (BIT + 48)
 #define PE(BIT)       (BIT + 64)
+
 // Virtual pin decoding
 #define GPIOREG(VPIN)     ((VPIN) >= 16 ? PBREG : PAREG)
 #define BITMASK(VPIN)     (1 << ((VPIN) & 15))
@@ -128,6 +122,11 @@
 #define HDIMG_BLK_POS 5                 // Position to embed block size numbers
 #define MAX_FILE_PATH 32                // Maximum file name length
 
+// SCSI
+#define SCSI_INFO_BUF_SIZE 36
+#define SCSI_INFO_VENDOR_SIZE 9
+#define SCSI_INFO_PRODUCT_SIZE 17
+#define SCSI_INFO_VERSION_SIZE 5
 typedef struct hddimg_struct
 {
 	FsFile      m_file;                 // File object
@@ -141,4 +140,5 @@ void onBusReset(void);
 void switchImage(void);
 void initFileLog(void);
 void finalizeFileLog(void);
+
 #endif // __BLACKSASI_H__

+ 13 - 0
sw/include/gpio.h

@@ -1,5 +1,18 @@
 #ifndef __BLACKSASI_GPIO_H__
 #define __BLACKSASI_GPIO_H__
+
+
+// LED control
+#define LED1_ON()           PAREG->BSRR = 0b0000000000010000;
+#define LED1_OFF()          PAREG->BSRR = 0b0000000000010000 << 16;
+#define LED2_ON()           PAREG->BSRR = 0b0000000000100000;
+#define LED2_OFF()          PAREG->BSRR = 0b0000000000100000 << 16;
+#define LED3_ON()           PAREG->BSRR = 0b0000000001000000;
+#define LED3_OFF()          PAREG->BSRR = 0b0000000001000000 << 16;
+#define LED_EXT_ON()        PAREG->BSRR = 0b0000000000000001;
+#define LED_EXT_OFF()       PAREG->BSRR = 0b0000000000000001 << 16;
+
 bool gpioInit();
 
+
 #endif // __BLACKSASI_GPIO_H__

+ 11 - 0
sw/include/scsi.h

@@ -0,0 +1,11 @@
+#ifndef __BLACKSASI_SCSI_H__
+#define __BLACKSASI_SCSI_H__
+#include "blacksasi.h"
+
+// 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()   { }
+
+
+#endif // __BLACKSASI_SCSI_H__

+ 1 - 0
sw/include/sdcard.h

@@ -7,4 +7,5 @@ void readSDCardInfo();
 void readSDCardInfo2();
 void sdCardInsert();
 void noSDCardFound();
+void switchImage();
 #endif // __BLACKSASI_SDCARD_H__

+ 4 - 4
sw/src/config.cpp

@@ -3,7 +3,7 @@
 #include "sdcard.h"
 extern SdFs SD;
 extern FsFile LOG_FILE;
-extern byte SCSI_INFO_BUF[36];
+extern byte SCSI_INFO_BUF[SCSI_INFO_BUF_SIZE];
 // 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() {
@@ -11,21 +11,21 @@ void readSCSIDeviceConfig() {
   if (!config_file.isOpen()) {
     return;
   }
-  char vendor[9];
+  char vendor[SCSI_INFO_VENDOR_SIZE];
   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];
+  char product[SCSI_INFO_PRODUCT_SIZE];
   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];
+  char version[SCSI_INFO_VERSION_SIZE];
   memset(version, 0, sizeof(version));
   config_file.readBytes(version, sizeof(version));
   LOG_FILE.print("SCSI VERSION: ");

+ 36 - 50
sw/src/main.cpp

@@ -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
 }
 

+ 3 - 0
sw/src/scsi.cpp

@@ -0,0 +1,3 @@
+#include "scsi.h"
+
+

+ 17 - 1
sw/src/sdcard.cpp

@@ -1,7 +1,7 @@
 #include "sdcard.h"
 extern SdFs SD;
 extern FsFile LOG_FILE;
-
+extern uint16_t imageSelect;
 // read SD information and print to logfile
 void readSDCardInfo()
 {
@@ -85,4 +85,20 @@ void sdCardInsert(void){
   }else{
     LED1_ON();
   }
+}
+
+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();
+    }
+
+
 }