Browse Source

WIP Add back Initiator

Eric Helgeson 6 months ago
parent
commit
20beb1b889

+ 73 - 7
lib/BlueSCSI_platform_RP2MCU/BlueSCSI_platform.cpp

@@ -39,6 +39,7 @@
 #include "scsi_accel_target.h"
 #include "custom_timings.h"
 #include <BlueSCSI_settings.h>
+#include <minIni.h>
 
 #ifdef SD_USE_RP2350_SDIO
 #include <sdio_rp2350.h>
@@ -53,6 +54,10 @@
 
 #include <pico/multicore.h>
 
+// Definitions of Global PIN definitions that may change depending on hardware rev
+uint32_t SCSI_ACCEL_PINMASK = SCSI_ACCEL_SETPINS;
+uint8_t SCSI_OUT_REQ = SCSI_OUT_REQ_CURRENT;
+
 #ifdef BLUESCSI_NETWORK
 extern "C" {
 #  include <pico/cyw43_arch.h>
@@ -78,10 +83,10 @@ extern "C" {
 #include "timings_RP2MCU.h"
 const char *g_platform_name = PLATFORM_NAME;
 static bool g_scsi_initiator = false;
+static bool g_supports_initiator = false;
 static uint32_t g_flash_chip_size = 0;
 static bool g_uart_initialized = false;
 static bool g_led_blinking = false;
-
 static void usb_log_poll();
 
 /***************/
@@ -247,6 +252,46 @@ static pin_setup_state_t read_setup_ack_pin()
 }
 #endif
 
+bool is2023a() {
+    gpio_conf(GPIO_I2C_SCL,   GPIO_FUNC_I2C, false, false, false,  false, true);
+    gpio_conf(GPIO_I2C_SDA,   GPIO_FUNC_I2C, false, false, false,  false, true);
+    delay(10);
+    bool d50_2023_09a = gpio_get(GPIO_I2C_SCL) && gpio_get(GPIO_I2C_SDA);
+
+    if (d50_2023_09a) {
+        logmsg("I2C Supported");
+        g_supports_initiator = true;
+        gpio_conf(GPIO_I2C_SCL,   GPIO_FUNC_I2C, true, false, false,  true, true);
+        gpio_conf(GPIO_I2C_SDA,   GPIO_FUNC_I2C, true, false, false,  true, true);
+
+        // Use Pico SDK methods
+        gpio_set_function(GPIO_I2C_SCL, GPIO_FUNC_I2C);
+        gpio_set_function(GPIO_I2C_SDA, GPIO_FUNC_I2C);
+        // gpio_pull_up(GPIO_I2C_SCL);  // TODO necessary?
+        // gpio_pull_up(GPIO_I2C_SDA);
+    } else {
+        logmsg("I2C Not Supported on this rev of hardware");
+        /* Check option switch settings */
+        // Option switches: S1 is iATN, S2 is iACK
+        gpio_conf(SCSI_IN_ACK,    GPIO_FUNC_SIO, true, false, false, false, false);
+        gpio_conf(SCSI_IN_ATN,    GPIO_FUNC_SIO, false, false, false, false, false);
+        delay(10); /// Settle time
+        // Check option switches
+        [[maybe_unused]] bool optionS1 = !gpio_get(SCSI_IN_ATN);
+        [[maybe_unused]] bool optionS2 = !gpio_get(SCSI_IN_ACK);
+
+        // Reset REQ to the appropriate pin for older hardware
+        SCSI_OUT_REQ = SCSI_OUT_REQ_PRE09A;
+        SCSI_ACCEL_PINMASK = SCSI_ACCEL_SETPINS_PRE09A;
+
+        // Initialize logging to SWO pin (UART0)
+        gpio_conf(SWO_PIN,        GPIO_FUNC_UART,false,false, true,  false, true);
+        uart_init(uart0, 115200);
+        g_uart_initialized = true;
+    }
+    return d50_2023_09a;
+}
+
 void platform_init()
 {
     // Make sure second core is stopped
@@ -315,11 +360,10 @@ void platform_init()
 
 #ifndef DISABLE_SWO
     /* Initialize logging to SWO pin (UART0) */
-    gpio_conf(SWO_PIN,        GPIO_FUNC_UART,false,false, true,  false, true);
-    uart_init(uart0, 1000000);
-    g_uart_initialized = true;
+    // gpio_conf(SWO_PIN,        GPIO_FUNC_UART,false,false, true,  false, true);
+    // uart_init(uart0, 1000000);
+    // g_uart_initialized = true;
 #endif // DISABLE_SWO
-
     logmsg("Platform: ", g_platform_name);
     logmsg("FW Version: ", g_log_firmwareversion);
 
@@ -398,8 +442,29 @@ void platform_init()
 #ifdef GPIO_USB_POWER
     gpio_conf(GPIO_USB_POWER, GPIO_FUNC_SIO, false, false, false,  false, false);
 #endif
+    is2023a();
 
 }
+void platform_enable_initiator_mode()
+{
+    logmsg("platform_enable_initiator_mode");
+    if (ini_getbool("SCSI", "InitiatorMode", false, CONFIGFILE))
+    {
+        logmsg("InitiatorMode true");
+
+        if (g_supports_initiator) {
+            g_scsi_initiator = true;
+            logmsg("SCSI Initiator Mode");
+            if (! ini_getbool("SCSI", "InitiatorParity", true, CONFIGFILE))
+            {
+                logmsg("Initiator Mode Skipping Parity Check.");
+                // setInitiatorModeParityCheck(false);
+            }
+        } else {
+            logmsg("SCSI Initiator Mode not supported.");
+        }
+    }
+}
 
 // late_init() only runs in main application, SCSI not needed in bootloader
 void platform_late_init()
@@ -416,8 +481,8 @@ void platform_late_init()
         logmsg("SCSI target/disk mode selected by DIP switch, acting as a SCSI disk");
     }
 #else
-    g_scsi_initiator = false;
-    logmsg("SCSI target/disk mode, acting as a SCSI disk");
+    // Initiator mode detected via ini.
+    platform_enable_initiator_mode();
 #endif // defined(HAS_DIP_SWITCHES) && defined(PLATFORM_HAS_INITIATOR_MODE)
 
     /* Initialize SCSI pins to required modes.
@@ -561,6 +626,7 @@ void platform_post_sd_card_init() {}
 
 bool platform_is_initiator_mode_enabled()
 {
+    // logmsg("Initiator mode enabled: ", g_scsi_initiator);
     return g_scsi_initiator;
 }
 

+ 29 - 3
lib/BlueSCSI_platform_RP2MCU/BlueSCSI_platform_gpio_v2.h

@@ -38,7 +38,6 @@
 #define SCSI_IO_DBP  8
 #define SCSI_IO_DATA_MASK 0x1FF
 #define SCSI_IO_SHIFT 0
-
 // Data direction control
 #define SCSI_DATA_DIR 9
 
@@ -48,8 +47,14 @@
 #define SCSI_OUT_MSG  20
 #define SCSI_OUT_RST  22
 #define SCSI_OUT_BSY  27
-#define SCSI_OUT_REQ  17
-#define SCSI_OUT_SEL  19
+#define SCSI_OUT_REQ_CURRENT  19
+#define SCSI_OUT_REQ_PRE09A  17
+extern uint8_t SCSI_OUT_REQ;
+#define SCSI_OUT_SEL  21
+
+#define SCSI_ACCEL_SETPINS 0x801FF
+#define SCSI_ACCEL_SETPINS_PRE09A 0x201FF
+extern uint32_t SCSI_ACCEL_PINMASK;
 
 // SCSI input status signals
 #define SCSI_IN_SEL  18
@@ -76,10 +81,22 @@
 #define SD_SPI_MISO  12
 #define SD_SPI_CS    15
 
+// IO expander I2C
+#define GPIO_I2C_SDA 16
+#define GPIO_I2C_SCL 17
 
 // Other pins
 #define SWO_PIN 16
 
+// Status line outputs for initiator mode
+#define SCSI_OUT_ACK  26
+#define SCSI_OUT_ATN  29  // ATN output is unused
+
+// Status line inputs for initiator mode
+#define SCSI_IN_IO    22
+#define SCSI_IN_CD    18
+#define SCSI_IN_MSG   28
+#define SCSI_IN_REQ   19
 
 // Below are GPIO access definitions that are used from scsiPhy.cpp.
 
@@ -93,6 +110,15 @@
 #define SCSI_IN(pin) \
     ((sio_hw->gpio_in & (1 << (SCSI_IN_ ## pin))) ? 0 : 1)
 
+// Set pin directions for initiator vs. target mode
+#define SCSI_ENABLE_INITIATOR() \
+    (sio_hw->gpio_oe_set = (1 << SCSI_OUT_ACK) | \
+    (1 << SCSI_OUT_ATN)), \
+    (sio_hw->gpio_oe_clr = (1 << SCSI_IN_IO) | \
+    (1 << SCSI_IN_CD) | \
+    (1 << SCSI_IN_MSG) | \
+    (1 << SCSI_IN_REQ))
+
 // Enable driving of shared control pins
 #define SCSI_ENABLE_CONTROL_OUT() \
     (sio_hw->gpio_oe_set = (1 << SCSI_OUT_CD) | \

+ 2 - 2
lib/BlueSCSI_platform_RP2MCU/BlueSCSI_platform_msc.cpp

@@ -107,8 +107,8 @@ public:
 
 /* return true if USB presence detected / eligible to enter CR mode */
 bool platform_sense_msc() {
-
-#if defined(BLUESCSI_PICO) || defined(BLUESCSI_PICO_2)
+  logmsg("platform_sense_msc");
+#if defined(BLUESCSI_PICO) || defined(BLUESCSI_PICO_2) || defined(BLUESCSI_V2)
   // check if we're USB powered, if not, exit immediately
   // pin on the wireless module, see https://github.com/earlephilhower/arduino-pico/discussions/835
   // Update: from the above discussion the offset 32 has been changed to 64 to access CYW43 GPIO pins

+ 3 - 1
lib/BlueSCSI_platform_RP2MCU/scsi_accel_target.cpp

@@ -937,7 +937,7 @@ static void scsidma_config_gpio()
     else if (g_scsi_dma_state == SCSIDMA_WRITE)
     {
         // Make sure the initial state of all pins is high and output
-        pio_sm_set_pins(SCSI_DMA_PIO, SCSI_DATA_SM, SCSI_IO_DATA_MASK | (1 << SCSI_OUT_REQ));
+        pio_sm_set_pins(SCSI_DMA_PIO, SCSI_DATA_SM, SCSI_ACCEL_PINMASK);
         pio_sm_set_consecutive_pindirs(SCSI_DMA_PIO, SCSI_DATA_SM, SCSI_IO_DB0, 9, true);
         pio_sm_set_consecutive_pindirs(SCSI_DMA_PIO, SCSI_DATA_SM, SCSI_OUT_REQ, 1, true);
 
@@ -959,6 +959,7 @@ static void scsidma_config_gpio()
             // Asynchronous read
             // Data bus as input, REQ pin as output
             pio_sm_set_pins(SCSI_DMA_PIO, SCSI_DATA_SM, SCSI_IO_DATA_MASK | (1 << SCSI_OUT_REQ));
+            pio_sm_set_pins(SCSI_DMA_PIO, SCSI_DATA_SM, SCSI_ACCEL_PINMASK);
             pio_sm_set_consecutive_pindirs(SCSI_DMA_PIO, SCSI_DATA_SM, SCSI_IO_DB0, 9, false);
             pio_sm_set_consecutive_pindirs(SCSI_DMA_PIO, SCSI_DATA_SM, SCSI_OUT_REQ, 1, true);
         }
@@ -966,6 +967,7 @@ static void scsidma_config_gpio()
         {
             // Synchronous read, REQ pin is written by SYNC_SM
             pio_sm_set_pins(SCSI_DMA_PIO, SCSI_SYNC_SM, SCSI_IO_DATA_MASK | (1 << SCSI_OUT_REQ));
+            pio_sm_set_pins(SCSI_DMA_PIO, SCSI_SYNC_SM, SCSI_ACCEL_PINMASK);
             pio_sm_set_consecutive_pindirs(SCSI_DMA_PIO, SCSI_DATA_SM, SCSI_IO_DB0, 9, false);
             pio_sm_set_consecutive_pindirs(SCSI_DMA_PIO, SCSI_SYNC_SM, SCSI_OUT_REQ, 1, true);
         }

+ 5 - 2
platformio.ini

@@ -45,6 +45,9 @@ build_flags =
     -DFILE_COPY_CONSTRUCTOR_SELECT=FILE_COPY_CONSTRUCTOR_PUBLIC
     -DDISABLE_FS_H_WARNING
     -DRECLOCKING_SUPPORTED
+    -DPLATFORM_HAS_INITIATOR_MODE
+; SWO detection handled at runtime
+    -DDISABLE_SWO
 ; build flags mirroring the "framework-arduinopico#x.x.x-DaynaPORT" static library build
     -DPICO_CYW43_ARCH_POLL=1
     -DCYW43_PIN_WL_DYNAMIC=1
@@ -82,7 +85,7 @@ extends = env:BlueSCSI_RP2MCU
 board = rpipicow
 ; How much flash in bytes the bootloader and main app will be allocated
 ; It is used as the starting point for a ROM image saved in flash
-program_flash_allocation = 589824
+program_flash_allocation = 590936
 linker_script_template = lib/BlueSCSI_platform_RP2MCU/rp2040-template.ld
 ldscript_bootloader = lib/BlueSCSI_platform_RP2MCU/rp2040_btldr.ld
 debug_build_flags =
@@ -105,7 +108,7 @@ build_flags =
     -DCYW43_PIO_CLOCK_DIV_DYNAMIC=1
     -DROMDRIVE_OFFSET=${env:BlueSCSI_Pico_DaynaPORT.program_flash_allocation}
 ; These take a large portion of the SRAM and can be adjusted
-    -DLOGBUFSIZE=8192
+    -DLOGBUFSIZE=2048
     -DPREFETCH_BUFFER_SIZE=4608
     -DSCSI2SD_BUFFER_SIZE=57344
 ; This controls the depth of NETWORK_PACKET_MAX_SIZE (1520 bytes)