Browse Source

New version

Per Mårtensson 2 years ago
parent
commit
a30fd75c8f
11 changed files with 1097 additions and 400 deletions
  1. 294 1
      sw/include/blacksasi.h
  2. 3 3
      sw/platformio.ini
  3. 0 22
      sw/src/config.cpp
  4. 1 1
      sw/src/gpio.cpp
  5. 7 4
      sw/src/log.cpp
  6. 608 343
      sw/src/main.cpp
  7. 85 0
      sw/src/scsi_cmds.h
  8. 9 0
      sw/src/scsi_mode.h
  9. 50 0
      sw/src/scsi_sense.h
  10. 14 0
      sw/src/scsi_status.h
  11. 26 26
      sw/src/sdcard.cpp

+ 294 - 1
sw/include/blacksasi.h

@@ -6,7 +6,7 @@
 #include "config.h"
 #include "scsi.h"
 // Log File
-#define VERSION "0.xx-SNAPSHOT-BLACKSASI-2022-03-20-F4"
+#define VERSION "0.xx-SNAPSHOT-BLACKSASI-2022-09-28-F4"
 
 #define LOG_FILENAME "LOG.txt"
 
@@ -114,6 +114,7 @@
 #define GPIOREG(VPIN)     ((VPIN) >= 16 ? ((VPIN) >= 32 ? ((VPIN) >= 48 ? ((VPIN) >= 48 ? PEREG : PDREG) : PCREG) : PBREG) : PAREG)
 #define BITMASK(VPIN)     (1 << ((VPIN % 16) & 15))
 
+
 #define vATN       PB(14)     // SCSI:ATN
 #define vBSY       PB(6)      // SCSI:BSY
 #define vACK       PB(7)      // SCSI:ACK
@@ -159,4 +160,296 @@ void switchImage(void);
 void initFileLog(void);
 void finalizeFileLog(void);
 
+
+// SCSI config
+#define MAX_SCSIID  7          // Maximum number of supported SCSI-IDs (The minimum is 0)
+#define MAX_SCSILUN 8          // Maximum number of LUNs supported     (The minimum is 0)
+#define NUM_SCSIID  MAX_SCSIID // Number of enabled SCSI IDs
+#define NUM_SCSILUN 1          // Number of enabled LUNs
+#define READ_PARITY_CHECK 0    // Perform read parity check (unverified)
+#define DEFAULT_SCSI_ID 1
+#define DEFAULT_SCSI_LUN 0
+#define SCSI_BUF_SIZE 512      // Size of the SCSI Buffer
+#define HDD_BLOCK_SIZE 512
+#define OPTICAL_BLOCK_SIZE 2048
+
+// HDD format
+#define MAX_BLOCKSIZE 4096     // Maximum BLOCK size
+
+// LED ERRORS
+#define ERROR_FALSE_INIT  3
+#define ERROR_NO_SDCARD   5
+
+enum SCSI_DEVICE_TYPE
+{
+  SCSI_DEVICE_HDD,
+  SCSI_DEVICE_OPTICAL,
+};
+
+#define CDROM_RAW_SECTORSIZE    2352
+#define CDROM_COMMON_SECTORSIZE 2048
+
+#define MAX_SCSI_COMMAND  0xff
+#define SCSI_COMMAND_HANDLER(x) static byte x(SCSI_DEVICE *dev, const byte *cdb)
+
+
+#define ATN       PB14      // SCSI:ATN
+#define BSY       PB6      // SCSI:BSY
+#define ACK       PB7     // SCSI:ACK
+#define RST       PA15     // SCSI:RST
+#define MSG       PE2      // SCSI:MSG
+#define SEL       PE3      // SCSI:SEL
+#define CD        PE4      // SCSI:C/D
+#define REQ       PE5      // SCSI:REQ
+#define IO        PB1      // SCSI:I/O
+
+#define LED1      PA4     // LED
+#define LED2      PA5     // Driven LED
+#define LED3      PA6     // Driven LED
+// Image Set Selector
+#define IMAGE_SELECT1   PC4
+#define IMAGE_SELECT2   PC5
+
+
+#define NOP(x) for(unsigned _nopcount = x; _nopcount; _nopcount--) { asm("NOP"); }
+
+/* SCSI Timing delays */
+// Due to limitations in timing granularity all of these are "very" rough estimates
+#define SCSI_BUS_SETTLE() NOP(30);                            // spec 400ns ours ~420us
+#define SCSI_DATA_RELEASE() NOP(30);                          // spec 400ns ours ~420us
+#define SCSI_HOLD_TIME() asm("NOP"); asm("NOP"); asm("NOP");  // spec 45ns ours ~42ns
+#define SCSI_DESKEW() // asm("NOP"); asm("NOP"); asm("NOP");     // spec 45ns ours ~42ns
+#define SCSI_CABLE_SKEW() // asm("NOP");                         // spec 10ns ours ~14ns
+#define SCSI_RESET_HOLD() asm("NOP"); asm("NOP");             // spec 25ns ours ~28ns
+#define SCSI_DISCONNECTION_DELAY() NOP(15);                   // spec 200ns ours ~210ns
+
+/* SCSI phases
++=============-===============-==================================-============+
+|    Signal   |  Phase name   |       Direction of transfer      |  Comment   |
+|-------------|               |                                  |            |
+| MSG|C/D|I/O |               |                                  |            |
+|----+---+----+---------------+----------------------------------+------------|
+|  0 | 0 | 0  |  DATA OUT     |       Initiator to target     \  |  Data      |
+|  0 | 0 | 1  |  DATA IN      |       Initiator from target   /  |  phase     |
+|  0 | 1 | 0  |  COMMAND      |       Initiator to target        |            |
+|  0 | 1 | 1  |  STATUS       |       Initiator from target      |            |
+|  1 | 0 | 0  |  *            |                                  |            |
+|  1 | 0 | 1  |  *            |                                  |            |
+|  1 | 1 | 0  |  MESSAGE OUT  |       Initiator to target     \  |  Message   |
+|  1 | 1 | 1  |  MESSAGE IN   |       Initiator from target   /  |  phase     |
+|-----------------------------------------------------------------------------|
+| Key:  0 = False,  1 = True,  * = Reserved for future standardization        |
++=============================================================================+ 
+*/
+// SCSI phase change as single write to port B
+#define SCSIPHASEMASK(MSGACTIVE, CDACTIVE, IOACTIVE) ((BITMASK(vMSG)<<((MSGACTIVE)?16:0)) | (BITMASK(vCD)<<((CDACTIVE)?16:0)) | (BITMASK(vIO)<<((IOACTIVE)?16:0)))
+
+#define SCSI_PHASE_DATAOUT SCSIPHASEMASK(inactive, inactive, inactive)
+#define SCSI_PHASE_DATAIN SCSIPHASEMASK(inactive, inactive, active)
+#define SCSI_PHASE_COMMAND SCSIPHASEMASK(inactive, active, inactive)
+#define SCSI_PHASE_STATUS SCSIPHASEMASK(inactive, active, active)
+#define SCSI_PHASE_MESSAGEOUT SCSIPHASEMASK(active, active, inactive)
+#define SCSI_PHASE_MESSAGEIN SCSIPHASEMASK(active, active, active)
+
+#define SCSI_PHASE_CHANGE(MASK) { PBREG->BSRR = (MASK); }
+//BLACKSASI clean this up and use defines
+// Data pins
+//                                                         5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 
+static const uint32_t scsiDbOutputRegOr_PDREG         = 0b00000000000000000101010101010101;
+static const uint32_t scsiDbInputOutputAnd_PDREG      = 0b00000000000000000000000000000000;
+static const uint32_t scsiDbInputOutputPullAnd_PDREG  = 0b00000000000000000101010101010101;
+// Control pins
+//                                                         5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 
+static const uint32_t scsiDbOutputRegOr_PEREG         = 0b00000000000000000000000000000001;
+static const uint32_t scsiDbInputOutputAnd_PEREG      = 0b00000000000000000011111111110000;
+static const uint32_t scsiDbInputOutputPullAnd_PEREG  = 0b00000000000000000101010101010001;
+
+// Put DB and DP in output mode and control buffers
+#define SCSI_DB_OUTPUT() { PDREG->MODER = (PDREG->MODER & scsiDbInputOutputAnd_PDREG) | scsiDbOutputRegOr_PDREG; PEREG->MODER = (PEREG->MODER & scsiDbInputOutputAnd_PEREG) | scsiDbOutputRegOr_PEREG; SCSI_DATABUS_OUT() ;}
+
+// Put DB and DP in input mode and control buffers
+#define SCSI_DB_INPUT()  { PDREG->MODER = (PDREG->MODER & scsiDbInputOutputAnd_PDREG); PEREG->MODER = (PEREG->MODER & scsiDbInputOutputAnd_PEREG); SCSI_DATABUS_IN();}
+#define SCSI_SET_PULL()  { PDREG->PUPDR |= scsiDbInputOutputPullAnd_PDREG; PEREG->PUPDR |= scsiDbInputOutputPullAnd_PEREG; }
+
+/*
+static const uint32_t scsiDbOutputRegOr = 0x55150011;
+static const uint32_t scsiDbInputOutputAnd = 0x00C0FFCC;
+// 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); }
+*/
+
+#if XCVR == 1
+
+#define TR_TARGET        PC2   // Target Transceiver Control Pin
+#define TR_DBP           PC0   // Data Pins Transceiver Control Pin
+#define TR_INITIATOR     PC1   // Initiator Transciever Control Pin
+
+#define vTR_TARGET       PC(2) // Target Transceiver Control Pin
+#define vTR_DBP          PC(0) // Data Pins Transceiver Control Pin
+#define vTR_INITIATOR    PC(1) // Initiator Transciever Control Pin
+
+#define TR_INPUT 1
+#define TR_OUTPUT 0
+
+// Transceiver control definitions
+#define TRANSCEIVER_IO_SET(VPIN,TR_INPUT) { GPIOREG(VPIN)->BSRR = BITMASK(VPIN) << ((TR_INPUT) ? 16 : 0); }
+
+static const uint32_t SCSI_TARGET_PORTA_AND = 0xFFF3FFFF;  // Sets input mode when AND-ed against MODER
+static const uint32_t SCSI_TARGET_PORTA_OR = 0x00040000;  // Sets output mode when AND+OR against MODER
+static const uint32_t SCSI_TARGET_PORTB_AND = 0xFFFF033F;  // Sets input mode when AND-ed against MODER
+static const uint32_t SCSI_TARGET_PORTB_OR = 0x00005440;  // Sets output mode when AND+OR against MODER
+
+// Turn on the output only for BSY
+#define SCSI_BSY_ACTIVE()      { PAREG->MODER = (PAREG->MODER & SCSI_TARGET_PORTA_AND) | SCSI_TARGET_PORTA_OR; PBREG->MODER = (PBREG->MODER & SCSI_TARGET_PORTB_AND) | SCSI_TARGET_PORTB_OR; SCSI_OUT(vBSY, active) }
+
+// BSY,REQ,MSG,CD,IO Turn off output, BSY is the last input
+#define SCSI_TARGET_INACTIVE() { PAREG->MODER = (PAREG->MODER & SCSI_TARGET_PORTA_AND); PBREG->MODER = (PBREG->MODER & SCSI_TARGET_PORTB_AND); TRANSCEIVER_IO_SET(vTR_TARGET,TR_INPUT); }
+
+#define SCSI_TARGET_ACTIVE()   { PAREG->MODER = (PAREG->MODER & SCSI_TARGET_PORTA_AND) | SCSI_TARGET_PORTA_OR; PBREG->MODER = (PBREG->MODER & SCSI_TARGET_PORTB_AND) | SCSI_TARGET_PORTB_OR; }
+
+#else
+
+// Turn on the output only for BSY
+#define SCSI_BSY_ACTIVE()      { pinMode(BSY, OUTPUT_OPEN_DRAIN); SCSI_OUT(vBSY,  active) }
+
+// BSY,REQ,MSG,CD,IO Turn off output, BSY is the last input
+#define SCSI_TARGET_INACTIVE() { SCSI_OUT(vREQ,inactive); SCSI_PHASE_CHANGE(SCSI_PHASE_DATAOUT); SCSI_OUT(vBSY,inactive); pinMode(BSY, INPUT); }
+
+// BSY,REQ,MSG,CD,IO Turn on the output (no change required for OD)
+#define SCSI_TARGET_ACTIVE()   { }
+
+#endif
+
+// HDDimage 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 64                // Maximum file name length
+
+/*
+ *  Data byte to BSRR register setting value and parity table
+*/
+/**
+ * BSRR register generator
+ * Totally configurable for which pin is each data bit, which pin is PTY, and which pin is REQ.
+ * The only requirement is that data and parity pins are in the same GPIO block.
+ * REQ can be specified as -1 to ignore, as it doesn't have to be in the same GPIO block.
+ * This is dramatically slower than the original static array, but is easier to configure
+ */
+static uint32_t genBSRR(uint32_t data) {
+  uint8_t masks[] = {0UL, 1UL, 2UL, 3UL, 4UL, 5UL, 6UL, 7UL};
+  // Positions array indicates which bit position each data bit goes in
+  // positions[0] is for data bit 0, position[1] for data bit 1, etc
+  // DB0, DB1, DB2, DB4, DB5, DB6, DB7 in order
+  uint8_t positions[] = {8UL, 9UL, 10UL, 2UL, 12UL, 13UL, 14UL, 15UL};
+  uint8_t dbpPosition = 0UL;
+  int reqPosition = 6;
+  uint8_t bitsAsserted = 0;
+
+  uint32_t output = 0x00000000;
+  for (int i = 0; i < 8; i++) {
+    if (data & (0x1 << masks[i])) {
+      // There's a one in this bit position, BSRR reset
+      output |= 0x1 << (positions[i] + 16);
+      bitsAsserted++;
+    } else {
+      // There's a 0 in this bit position, BSRR set high
+      output |= (0x1 << positions[i]);
+    }
+  }
+
+  // Set the parity bit
+  if (bitsAsserted % 2 == 0) {
+    // Even number of bits asserted, Parity asserted (0, low, BSRR reset)
+    output |= 0x01 << (dbpPosition + 16);
+  } else {
+    // Odd number of bits asserted, Parity deasserted (1, high, BSRR set)
+    output |= 0x01 << dbpPosition;
+  }
+
+  // BSRR set REQ if specified
+  // Only set > 0 if it's in the same GPIO block as DB and DBP
+  if (reqPosition >= 0) {
+    output |= 0x01 << reqPosition;
+  }
+
+  return output;
+}
+
+// BSRR register control value that simultaneously performs DB set, DP set, and REQ = H (inactrive)
+//uint32_t db_bsrr[256];
+// Parity bit acquisition
+#define PARITY(DB) (db_bsrr[DB]&1)
+
+// #define GET_CDB6_LBA(x) ((x[2] & 01f) << 16) | (x[3] << 8) | x[4]
+#define READ_DATA_BUS() (byte)((~(uint32_t)GPIOB->regs->IDR)>>8)
+
+
+
+struct SCSI_INQUIRY_DATA
+{
+  union
+  {
+  struct {
+    // bitfields are in REVERSE order for ARM
+    // byte 0
+    byte peripheral_device_type:5;
+    byte peripheral_qualifier:3;
+    // byte 1
+    byte reserved_byte2:7;
+    byte rmb:1;
+    // byte 2
+    byte ansi_version:3;
+    byte always_zero_byte3:5;
+    // byte 3
+    byte response_format:4;
+    byte reserved_byte4:2;
+    byte tiop:1;
+    byte always_zero_byte4:1;
+    // byte 4
+    byte additional_length;
+    // byte 5-6
+    byte reserved_byte5;
+    byte reserved_byte6;
+    // byte 7
+    byte sync:1;
+    byte always_zero_byte7_more:4;
+    byte always_zero_byte7:3;
+    // byte 8-15
+    char vendor[8];
+    // byte 16-31
+    char product[16];
+    // byte 32-35
+    char revision[4];
+    // byte 36
+    byte release;
+    // 37-46
+    char revision_date[10];
+  };
+  // raw bytes
+  byte raw[64];
+  };
+};
+
+// HDD image
+typedef __attribute__((aligned(4))) struct _SCSI_DEVICE
+{
+	FsFile        *m_file;                  // File object
+	uint64_t      m_fileSize;               // File size
+	uint16_t      m_blocksize;              // SCSI BLOCK size
+  uint16_t      m_rawblocksize;           // OPTICAL raw sector size
+  uint8_t       m_type;                   // SCSI device type
+  uint32_t      m_blockcount;             // blockcount
+  bool          m_raw;                    // Raw disk
+  SCSI_INQUIRY_DATA *inquiry_block;       // SCSI information
+  uint8_t       m_senseKey;               // Sense key
+  uint16_t      m_additional_sense_code;  // ASC/ASCQ 
+  bool          m_mode2;                  // MODE2 CDROM
+  uint8_t       m_sector_offset;          // optical sector offset for missing sync header
+} SCSI_DEVICE;
+
+
 #endif // __BLACKSASI_H__

+ 3 - 3
sw/platformio.ini

@@ -14,9 +14,9 @@ board = blacksasi_f411m
 board.variants_dir = /home/pm/project/stm32/BlackSASI/sw/variant/blacksasi_f411m
 framework = arduino
 board_build.core = maple
-lib_deps =
-    greiman/SdFat@^2.1.2
-    bblanchon/ArduinoJson@^6.19.3
+;lib_deps =
+;    greiman/SdFat@^2.2.0
+ ;   bblanchon/ArduinoJson@^6.19.3
 upload_protocol = stlink
 debug_tool = stlink
 ; Different gcc versions produce much different binaries in terms of speed.

+ 0 - 22
sw/src/config.cpp

@@ -21,27 +21,5 @@ void readSCSIDeviceConfig(uint8_t disc) {
   }
   String configx =config["config"];
   Serial.println(configx);
-  /*
-  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[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[SCSI_INFO_VERSION_SIZE];
-  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();
-  */
 }

+ 1 - 1
sw/src/gpio.cpp

@@ -44,6 +44,6 @@ bool gpioInit(void){
     pinMode(BOARD_SCSI_TAD, OUTPUT);
     pinMode(BOARD_TRANS_OE, OUTPUT);
 
-    digitalWrite(BOARD_TRANS_OE, HIGH);
+    digitalWrite(BOARD_TRANS_OE, LOW);
 }
   

+ 7 - 4
sw/src/log.cpp

@@ -5,6 +5,7 @@ extern FsFile LOG_FILE;
 extern SdFs SD;
 extern ArduinoOutStream cout(Serial);
 extern HDDIMG  img[NUM_SCSIID][NUM_SCSILUN]; 
+extern SCSI_DEVICE scsi_device_list[NUM_SCSIID][NUM_SCSILUN];
 /*
  * Setup initialization logfile
  */
@@ -68,11 +69,11 @@ void finalizeFileLog() {
     LOG_FILE.print(id);
     for(int lun=0;lun<NUM_SCSILUN;lun++)
     {
-      HDDIMG *h = &img[id][lun];
-      if( (lun<NUM_SCSILUN) && (h->m_file))
+      SCSI_DEVICE *dev = &scsi_device_list[id][lun];
+      if( (lun<NUM_SCSILUN) && (dev->m_file))
       {
-        LOG_FILE.print((h->m_blocksize<1000) ? ": " : ":");
-        LOG_FILE.print(h->m_blocksize);
+        LOG_FILE.print((dev->m_blocksize<1000) ? ": " : ":");
+        LOG_FILE.print(dev->m_blocksize);
       }
       else      
         LOG_FILE.print(":----");
@@ -81,5 +82,7 @@ void finalizeFileLog() {
   }
   LOG_FILE.println("Finished initialization of SCSI Devices - Entering main loop.");
   LOG_FILE.sync();
+  #if DEBUG < 2
   LOG_FILE.close();
+  #endif
 }

File diff suppressed because it is too large
+ 608 - 343
sw/src/main.cpp


+ 85 - 0
sw/src/scsi_cmds.h

@@ -0,0 +1,85 @@
+#ifndef __SCSI_CMDS_H__
+#define __SCSI_CMDS_H__
+
+// defines for SCSI commands
+#define SCSI_TEST_UNIT_READY        0
+#define SCSI_REZERO_UNIT            0x1
+#define SCSI_REQUEST_SENSE          0x3
+#define SCSI_FORMAT_UNIT4           0x4
+#define SCSI_FORMAT_UNIT6           0x6
+#define SCSI_REASSIGN_BLOCKS        0x7
+#define SCSI_READ6                  0x8
+#define SCSI_WRITE6                 0xA
+#define SCSI_SEEK6                  0xB
+#define SCSI_INQUIRY                0x12
+#define SCSI_MODE_SELECT6           0x15
+#define SCSI_RESERVE                0x16
+#define SCSI_RELEASE                0x17
+#define SCSI_COPY                   0x18
+#define SCSI_MODE_SENSE6            0x1A
+#define SCSI_START_STOP_UNIT        0x1B
+#define SCSI_RECV_DIAG_RESULTS      0x1C
+#define SCSI_SEND_DIAG              0x1D
+#define SCSI_PREVENT_ALLOW_REMOVAL  0x1E
+#define SCSI_ICD_EXTENDED_CMD       0x1F
+#define SCSI_READ_CAPACITY          0x25
+#define SCSI_READ10                 0x28
+#define SCSI_WRITE10                0x2A
+#define SCSI_SEEK10                 0x2B
+#define SCSI_WRITE_AND_VERIFY       0x2E
+#define SCSI_VERIFY10               0x2F
+#define SCSI_SEARCH_DATA_HIGH       0x30
+#define SCSI_SEARCH_DATA_EQUAL      0x31
+#define SCSI_SEARCH_DATA_LOW        0x32
+#define SCSI_SET_LIMITS             0x33
+#define SCSI_PREFETCH               0x34
+#define SCSI_SYNCHRONIZE_CACHE      0x35
+#define SCSI_LOCK_UNLOCK_CACHE      0x36
+#define SCSI_READ_DEFECT_DATA       0x37
+#define SCSI_COMPARE                0x39
+#define SCSI_COPY_AND_VERIFY        0x3A
+#define SCSI_WRITE_BUFFER           0x3B
+#define SCSI_READ_BUFFER            0x3C
+#define SCSI_READ_LONG              0x3E
+#define SCSI_WRITE_LONG             0x3F
+#define SCSI_CHANGE_DEFINITION      0x40
+#define SCSI_WRITE_SAME             0x41
+#define SCSI_LOG_SELECT             0x4C
+#define SCSI_LOG_SENSE              0x4D
+#define SCSI_MODE_SELECT10          0x55
+#define SCSI_MODE_SENSE10           0x5A
+#define SCSI_READ12                 0xA8
+#define SCSI_VERIFY12               0xAF
+
+
+#define SCSI_TOC_LENGTH 20 // length for default CDROM TOC
+
+// SCSI CDROM commands
+#define SCSI_AUDIO_SCAN1            0xBA
+#define SCSI_AUDIO_SCAN2            0xCD
+#define SCSI_PAUSE_RESUME           0x4B
+#define SCSI_PLAY_AUDIO10           0x45
+#define SCSI_PLAY_AUDIO12           0xA5
+#define SCSI_PLAY_AUDIO_MSF         0x47
+#define SCSI_PLAY_AUDIO_TRACK_IDX   0x48
+#define SCSI_PLAY_TRACK_RELATIVE10  0x49
+#define SCSI_PLAY_TRACK_RELATIVE12  0xA9
+#define SCSI_READ_CD                0xBE
+#define SCSI_READ_CD_DD             0xD8
+#define SCSI_READ_CD_MSF            0xB9
+#define SCSI_READ_CDDA_MSF          0xD9
+#define SCSI_READ_CDXA              0xDB
+#define SCSI_READ_ALL_SUBCODE       0xDF
+#define SCSI_READ_HEADER            0x44
+#define SCSI_READ_SUBCHANNEL        0x42
+#define SCSI_READ_TOC               0x43
+#define SCSI_READ_DISC_INFORMATION  0x51
+#define SCSI_READ_DVD_STRUCTURE     0xAD
+#define SCSI_SET_CDROM_SPEED1       0xBB
+#define SCSI_SET_CDROM_SPEED2       0xDA
+#define SCSI_STOP_PLAY_SCAN         0x4E
+#define SCSI_READ_CDP               0xE4
+#define SCSI_READ_DRIVE_STATUS      0xE0
+#define SCSI_WRITE_CDP              0xE3
+
+#endif // __SCSI_CMDS_H__

+ 9 - 0
sw/src/scsi_mode.h

@@ -0,0 +1,9 @@
+#ifndef __SCSI_MODE_H__
+#define __SCSI_MODE_H__
+
+#define MODE_COMBINED_HEADER_DATA   0x00
+#define MODE_NOT_SUPPORTED          0x01
+#define MODE_DATA                   0x02
+#define MODE_DESCRIPTOR             0x03
+
+#endif

+ 50 - 0
sw/src/scsi_sense.h

@@ -0,0 +1,50 @@
+#ifndef __SCSI_SENSE_H__
+#define __SCSI_SENSE_H__
+
+#define SCSI_SENSE_NO_SENSE         0
+#define SCSI_SENSE_RECOVERED_ERROR  0x1
+#define SCSI_SENSE_NOT_READY        0x2
+#define SCSI_SENSE_MEDUIM_ERROR     0x3
+#define SCSI_SENSE_HARDWARE_ERROR   0x4
+#define SCSI_SENSE_ILLEGAL_REQUEST  0x5
+#define SCSI_SENSE_UNIT_ATTENTION   0x6
+#define SCSI_SENSE_DATA_PROTECT     0x7
+#define SCSI_SENSE_BLANK_CHECK      0x8
+#define SCSI_SENSE_VENDOR_SPECIFIC  0x9
+#define SCSI_SENSE_COPY_ABORTED     0xa
+#define SCSI_SENSE_ABORTED_COMMAND  0xb
+#define SCSI_SENSE_EQUAL            0xc
+#define SCSI_SENSE_VOLUME_OVERFLOW  0xd
+#define SCSI_SENSE_MISCOMPARE       0xe
+#define SCSI_SENSE_RESERVED         0xf
+
+
+#define SCSI_ASC_INVALID_OPERATION_CODE                         0x2000
+#define SCSI_ASC_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE             0x2100
+#define SCSI_ASC_INVALID_FIELD_IN_CDB                           0x2400
+#define SCSI_ASC_LOGICAL_UNIT_NOT_SUPPORTED                     0x2500
+#define SCSI_ASC_INVALID_FIELD_PARAMETER_LIST                   0x2600
+#define SCSI_ASC_WRITE_PROTECTED                                0x2700
+#define SCSI_ASC_CANNOT_READ_MEDIUM_UNKNOWN_FORMAT              0x3001
+#define SCSI_ASC_CANNOT_READ_MEDIUM_INCOMPATIBLE_FORMAT         0x3002
+#define SCSI_ASC_SAVING_PARAMETERS_NOT_SUPPORTED                0x3900
+#define SCSI_ASC_MEDIUM_NOT_PRESENT                             0x3A00
+#define SCSI_ASC_LUN_NOT_READY_MANUAL_INTERVENTION_REQUIRED     0x0403
+
+
+// SCSI mode page codes
+#define SCSI_SENSE_MODE_VENDOR                      0x00
+#define SCSI_SENSE_MODE_READ_WRITE_ERROR_RECOVERY   0x01
+#define SCSI_SENSE_MODE_DISCONNECT_RECONNECT        0x02
+#define SCSI_SENSE_MODE_FORMAT_DEVICE               0x03
+#define SCSI_SENSE_MODE_DISK_GEOMETRY               0x04
+#define SCSI_SENSE_MODE_FLEXABLE_GEOMETRY           0x05
+#define SCSI_SENSE_MODE_CACHING                     0x08
+#define SCSI_SENSE_MODE_CDROM                       0x0D
+#define SCSI_SENSE_MODE_CDROM_AUDIO_CONTROL         0x0E
+#define SCSI_SENSE_MODE_VENDOR_APPLE                0x30
+
+#define SCSI_SENSE_MODE_ALL                         0x3F
+
+
+#endif

+ 14 - 0
sw/src/scsi_status.h

@@ -0,0 +1,14 @@
+#ifndef __SCSI_STATUS_H__
+#define __SCSI_STATUS_H__
+
+#define SCSI_STATUS_GOOD                            0
+#define SCSI_STATUS_CHECK_CONDITION                 0x2
+#define SCSI_STATUS_CONDITION_MET                   0x4
+#define SCSI_STATUS_BUSY                            0x8
+#define SCSI_STATUS_INTERMEDIATE                    0x16
+#define SCSI_STATUS_INTERMEDIATE_CONDITION_MET      0x20
+#define SCSI_STATUS_RESERVATION_CONFLICT            0x24
+#define SCSI_STATUS_COMMAND_TERMINATED              0x34
+#define SCSI_STATUS_QUEUE_FULL                      0x40
+
+#endif

+ 26 - 26
sw/src/sdcard.cpp

@@ -9,27 +9,27 @@ void readSDCardInfo()
 
   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);
+    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.mdtMonth());
+
+    serial.println(sd_cid.mdtYear());
+
+    serial.print("Sd Serial:");
+    serial.println(sd_cid.psn());
+    serial.flush();
   }
 }
 void readSDCardInfo2()
@@ -52,13 +52,13 @@ void readSDCardInfo2()
     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_cid.mdtMonth());
+
+    LOG_FILE.println(sd_cid.mdtYear());
+
 
     LOG_FILE.print("Sd Serial:");
-    LOG_FILE.println(sd_cid.psn);
+    LOG_FILE.println(sd_cid.psn());
     LOG_FILE.sync();
   }
 }

Some files were not shown because too many files changed in this diff