Sfoglia il codice sorgente

Prototype 1 Working

androda 3 anni fa
parent
commit
8971584485

+ 36 - 34
lib/BlueSCSI_platform_RP2040/BlueSCSI_platform.cpp

@@ -45,38 +45,39 @@ void bluescsiplatform_init()
      * RP2040 defaults to pulldowns, while these pins have external pull-ups.
      */
     //        pin             function       pup   pdown  out    state fast
-    gpio_conf(SCSI_DATA_DIR,  GPIO_FUNC_SIO, false,false, true,  true, true);
-    gpio_conf(SCSI_OUT_RST,   GPIO_FUNC_SIO, false,false, true,  true, true);
-    gpio_conf(SCSI_OUT_BSY,   GPIO_FUNC_SIO, false,false, true,  true, true);
-    gpio_conf(SCSI_OUT_SEL,   GPIO_FUNC_SIO, false,false, true,  true, true);
+    gpio_conf(SCSI_DATA_DIR,  GPIO_FUNC_SIO, false,false, true,  false, true);
+    //gpio_conf(SCSI_OUT_RST,   GPIO_FUNC_SIO, false,false, true,  true, true);
+    gpio_conf(SCSI_OUT_BSY,   GPIO_FUNC_SIO, false,false, true,  true, false);   
+    //gpio_set_drive_strength(SCSI_OUT_BSY, GPIO_DRIVE_STRENGTH_8MA);
+    gpio_conf(SCSI_OUT_SEL,   GPIO_FUNC_SIO, false,false, true,  true, false);
 
     /* Check dip switch settings */
-    gpio_conf(DIP_INITIATOR,  GPIO_FUNC_SIO, false, false, false, false, false);
-    gpio_conf(DIP_DBGLOG,     GPIO_FUNC_SIO, false, false, false, false, false);
-    gpio_conf(DIP_TERM,       GPIO_FUNC_SIO, false, false, false, false, false);
+    //gpio_conf(DIP_INITIATOR,  GPIO_FUNC_SIO, false, false, false, false, false);
+    //gpio_conf(DIP_DBGLOG,     GPIO_FUNC_SIO, false, false, false, false, false);
+    //gpio_conf(DIP_TERM,       GPIO_FUNC_SIO, false, false, false, false, false);
 
     delay(10); // 10 ms delay to let pull-ups do their work
 
-    bool dbglog = !gpio_get(DIP_DBGLOG);
-    bool termination = !gpio_get(DIP_TERM);
+    //bool dbglog = !gpio_get(DIP_DBGLOG);
+    //bool termination = !gpio_get(DIP_TERM);
 
     /* Initialize logging to SWO pin (UART0) */
     gpio_conf(SWO_PIN,        GPIO_FUNC_UART,false,false, true,  false, true);
     uart_init(uart0, 1000000);
     mbed_set_error_hook(mbed_error_hook);
 
-    bluelog("DIP switch settings: debug log ", (int)dbglog, ", termination ", (int)termination);
+    //bluelog("DIP switch settings: debug log ", (int)dbglog, ", termination ", (int)termination);
 
-    g_bluelog_debug = dbglog;
+    g_bluelog_debug = false; // Debug logging can be handled with a debug firmware, very easy to reflash
 
-    if (termination)
-    {
-        bluelog("SCSI termination is enabled");
-    }
-    else
-    {
-        bluelog("NOTE: SCSI termination is disabled");
-    }
+    // if (termination)  // Termination is handled by hardware jumper
+    // {
+    //     bluelog("SCSI termination is enabled");
+    // }
+    // else
+    // {
+    //     bluelog("NOTE: SCSI termination is disabled");
+    // }
 
     // SD card pins
     // Card is used in SDIO mode for main program, and in SPI mode for crash handler & bootloader.
@@ -106,23 +107,23 @@ static bool read_initiator_dip_switch()
 
     // Strong output high, then pulldown
     //        pin             function       pup   pdown   out    state  fast
-    gpio_conf(DIP_INITIATOR,  GPIO_FUNC_SIO, false, false, true,  true,  false);
-    gpio_conf(DIP_INITIATOR,  GPIO_FUNC_SIO, false, true,  false, true,  false);
-    delay(1);
-    bool initiator_state1 = gpio_get(DIP_INITIATOR);
+    //gpio_conf(DIP_INITIATOR,  GPIO_FUNC_SIO, false, false, true,  true,  false);
+    //gpio_conf(DIP_INITIATOR,  GPIO_FUNC_SIO, false, true,  false, true,  false);
+    //delay(1);
+    //bool initiator_state1 = gpio_get(DIP_INITIATOR);
 
     // Strong output low, then pullup
     //        pin             function       pup   pdown   out    state  fast
-    gpio_conf(DIP_INITIATOR,  GPIO_FUNC_SIO, false, false, true,  false, false);
-    gpio_conf(DIP_INITIATOR,  GPIO_FUNC_SIO, true,  false, false, false, false);
-    delay(1);
-    bool initiator_state2 = gpio_get(DIP_INITIATOR);
+    //gpio_conf(DIP_INITIATOR,  GPIO_FUNC_SIO, false, false, true,  false, false);
+    //gpio_conf(DIP_INITIATOR,  GPIO_FUNC_SIO, true,  false, false, false, false);
+    //delay(1);
+    //bool initiator_state2 = gpio_get(DIP_INITIATOR);
 
-    if (initiator_state1 == initiator_state2)
-    {
+    //if (initiator_state1 == initiator_state2)
+    //{
         // Ok, was able to read the state directly
-        return !initiator_state1;
-    }
+        //return !initiator_state1;
+    //}
 
     // Enable OUT_BSY for a short time.
     // If in target mode, this will force GPIO_ACK high.
@@ -130,7 +131,8 @@ static bool read_initiator_dip_switch()
     delay_100ns();
     gpio_put(SCSI_OUT_BSY, 1);
 
-    return !gpio_get(DIP_INITIATOR);
+    //return !gpio_get(DIP_INITIATOR);
+    return false;
 }
 
 // late_init() only runs in main application, SCSI not needed in bootloader
@@ -191,8 +193,8 @@ void bluescsiplatform_late_init()
 
         // SCSI control inputs
         //        pin             function       pup   pdown  out    state fast
-        gpio_conf(SCSI_IN_ACK,    GPIO_FUNC_SIO, true, false, false, true, false);
-        gpio_conf(SCSI_IN_ATN,    GPIO_FUNC_SIO, true, false, false, true, false);
+        gpio_conf(SCSI_IN_ACK,    GPIO_FUNC_SIO, false, false, false, true, false);
+        gpio_conf(SCSI_IN_ATN,    GPIO_FUNC_SIO, false, false, false, true, false);
         gpio_conf(SCSI_IN_RST,    GPIO_FUNC_SIO, true, false, false, true, false);
     }
     else

+ 7 - 5
lib/BlueSCSI_platform_RP2040/BlueSCSI_platform.h

@@ -102,7 +102,7 @@ void bluescsiplatform_boot_to_main_firmware();
 
 // Set SCSI data bus to output
 #define SCSI_ENABLE_DATA_OUT() \
-    (sio_hw->gpio_clr = (1 << SCSI_DATA_DIR), \
+    (sio_hw->gpio_set = (1 << SCSI_DATA_DIR), \
      sio_hw->gpio_oe_set = SCSI_IO_DATA_MASK)
 
 // Write SCSI data bus, also sets REQ to inactive.
@@ -115,20 +115,22 @@ extern const uint32_t g_scsi_parity_lookup[256];
 // Release SCSI data bus and REQ signal
 #define SCSI_RELEASE_DATA_REQ() \
     (sio_hw->gpio_oe_clr = SCSI_IO_DATA_MASK, \
-     sio_hw->gpio_set = (1 << SCSI_DATA_DIR) | (1 << SCSI_OUT_REQ))
+     sio_hw->gpio_clr = (1 << SCSI_DATA_DIR), \
+     sio_hw->gpio_set = ((1 << SCSI_OUT_REQ)))
 
 // Release all SCSI outputs
 #define SCSI_RELEASE_OUTPUTS() \
     SCSI_RELEASE_DATA_REQ(), \
-    sio_hw->gpio_oe_clr = (1 << SCSI_OUT_CD) | \
-                          (1 << SCSI_OUT_MSG), \
     sio_hw->gpio_set = (1 << SCSI_OUT_IO) | \
                        (1 << SCSI_OUT_CD) | \
                        (1 << SCSI_OUT_MSG) | \
                        (1 << SCSI_OUT_RST) | \
                        (1 << SCSI_OUT_BSY) | \
                        (1 << SCSI_OUT_REQ) | \
-                       (1 << SCSI_OUT_SEL)
+                       (1 << SCSI_OUT_SEL), \
+                       delay(1), \
+    sio_hw->gpio_oe_clr = (1 << SCSI_OUT_CD) | \
+                          (1 << SCSI_OUT_MSG)
 
 // Read SCSI data bus
 #define SCSI_IN_DATA() \

+ 41 - 36
lib/BlueSCSI_platform_RP2040/BlueSCSI_platform_gpio.h

@@ -20,23 +20,26 @@
 #define SCSI_IO_SHIFT 0
 
 // Data direction control
-#define SCSI_DATA_DIR 17
-
-// SCSI output status lines
-#define SCSI_OUT_IO   12
-#define SCSI_OUT_CD   11
-#define SCSI_OUT_MSG  13
-#define SCSI_OUT_RST  28
-#define SCSI_OUT_BSY  26
-#define SCSI_OUT_REQ  9
-#define SCSI_OUT_SEL  24
-
-// SCSI input status signals
-#define SCSI_IN_SEL  11
-#define SCSI_IN_ACK  10
-#define SCSI_IN_ATN  29
-#define SCSI_IN_BSY  13
-#define SCSI_IN_RST  27
+#define SCSI_DATA_DIR 9
+
+// SCSI control lines
+#define SCSI_OUT_IO   22  // Used to be 16
+#define SCSI_OUT_REQ  17
+
+#define SCSI_OUT_CD   18  // TODO hardware design
+#define SCSI_IN_SEL  18
+
+#define SCSI_OUT_SEL  19
+
+#define SCSI_OUT_MSG  20
+#define SCSI_IN_BSY  20  // TODO hardware design
+
+#define SCSI_IN_RST  21
+#define SCSI_OUT_RST  22  // Same as IO currently, not initialized or used
+
+#define SCSI_IN_ACK  26
+#define SCSI_OUT_BSY  27
+#define SCSI_IN_ATN  28
 
 // Status line outputs for initiator mode
 #define SCSI_OUT_ACK  10
@@ -53,29 +56,31 @@
 #define LED_ON()     sio_hw->gpio_set = 1 << LED_PIN
 #define LED_OFF()    sio_hw->gpio_clr = 1 << LED_PIN
 
-// SD card pins in SDIO mode
-#define SDIO_CLK 18
-#define SDIO_CMD 19
-#define SDIO_D0  20
-#define SDIO_D1  21
-#define SDIO_D2  22
-#define SDIO_D3  23
-
-// SD card pins in SPI mode
-#define SD_SPI       spi0
-#define SD_SPI_SCK   18
-#define SD_SPI_MOSI  19
-#define SD_SPI_MISO  20
-#define SD_SPI_CS    23
+// SDIO and SPI block
+#define SD_SPI_SCK   10
+#define SDIO_CLK 10
+
+#define SD_SPI_MOSI  11
+#define SDIO_CMD 11
+
+#define SD_SPI_MISO  12
+#define SDIO_D0  12
+
+#define SDIO_D1  13
+
+#define SDIO_D2  14
+
+#define SDIO_D3  15
+#define SD_SPI_CS    15
 
 // IO expander I2C
-#define GPIO_I2C_SDA 14
-#define GPIO_I2C_SCL 15
+// #define GPIO_I2C_SDA 14
+// #define GPIO_I2C_SCL 15
 
 // DIP switch pins
-#define DIP_INITIATOR 10
-#define DIP_DBGLOG 16
-#define DIP_TERM 9
+// #define DIP_INITIATOR 10
+// #define DIP_DBGLOG 28
+// #define DIP_TERM 9
 
 // Other pins
 #define SWO_PIN 16

+ 1 - 1
lib/BlueSCSI_platform_RP2040/rp2040_sdio.pio

@@ -24,7 +24,7 @@
 .define CLKDIV 5
 .define D0 ((CLKDIV + 1) / 2 - 1)
 .define D1 (CLKDIV/2 - 1)
-.define SDIO_CLK_GPIO 18
+.define SDIO_CLK_GPIO 10
 
 ; State machine 0 is used to:
 ; - generate continuous clock on SDIO_CLK

+ 6 - 3
lib/BlueSCSI_platform_RP2040/rp2040_sdio.pio.h

@@ -64,7 +64,8 @@ static const uint16_t sdio_data_rx_program_instructions[] = {
             //     .wrap_target
     0xa022, //  0: mov    x, y                       
     0x2020, //  1: wait   0 pin, 0                   
-    0x2492, //  2: wait   1 gpio, 18             [4] 
+    //0x2492, //  2: wait   1 gpio, 18             [4] 
+    0x248A, // 2: wait 1 gpio 10
     0x4304, //  3: in     pins, 4                [3] 
     0x0043, //  4: jmp    x--, 3                     
             //     .wrap
@@ -92,8 +93,10 @@ static inline pio_sm_config sdio_data_rx_program_get_default_config(uint offset)
 #define sdio_data_tx_wrap 8
 
 static const uint16_t sdio_data_tx_program_instructions[] = {
-    0x2012, //  0: wait   0 gpio, 18                 
-    0x2592, //  1: wait   1 gpio, 18             [5] 
+    // 0x2012, //  0: wait   0 gpio, 18                 
+    0x200A,  // 0: wait 0 GPIO 10
+   // 0x2592, //  1: wait   1 gpio, 18             [5] 
+    0x258A, // 1: wait 1 gpio 10
     0x6204, //  2: out    pins, 4                [2] 
     0x0142, //  3: jmp    x--, 2                 [1] 
     0xe280, //  4: set    pindirs, 0             [2] 

+ 3 - 0
lib/BlueSCSI_platform_RP2040/scsiPhy.cpp

@@ -76,6 +76,9 @@ extern "C" bool scsiStatusSEL()
         // Instead update the state here.
         // Releasing happens with bus release.
         g_scsi_ctrl_bsy = 0;
+        SCSI_OUT(CD, 0);
+        SCSI_OUT(MSG, 0);
+        SCSI_ENABLE_CONTROL_OUT();
         SCSI_OUT(BSY, 1);
 
         // On RP2040 hardware the ATN signal is only available after OUT_BSY enables

+ 2 - 2
lib/BlueSCSI_platform_RP2040/scsi_accel.pio

@@ -5,8 +5,8 @@
 ; -   8: DBP
 ; Side set is REQ pin
 
-.define REQ 9
-.define ACK 10
+.define REQ 17  ; was 9
+.define ACK 26  ; was 10
 
 ; Delay from data setup to REQ assertion.
 ; deskew delay + cable skew delay = 55 ns minimum

+ 11 - 11
lib/BlueSCSI_platform_RP2040/scsi_accel.pio.h

@@ -20,8 +20,8 @@ static const uint16_t scsi_accel_async_write_program_instructions[] = {
     0x90e0, //  0: pull   ifempty block   side 1     
     0x7009, //  1: out    pins, 9         side 1     
     0x7567, //  2: out    null, 7         side 1 [5] 
-    0x308a, //  3: wait   1 gpio, 10      side 1     
-    0x200a, //  4: wait   0 gpio, 10      side 0     
+    0x309a, //  3: wait   1 gpio, 26      side 1     
+    0x201a, //  4: wait   0 gpio, 26      side 0     
             //     .wrap
 };
 
@@ -51,11 +51,11 @@ static const uint16_t scsi_accel_async_read_program_instructions[] = {
             //     .wrap_target
     0x90a0, //  0: pull   block           side 1     
     0xb027, //  1: mov    x, osr          side 1     
-    0x308a, //  2: wait   1 gpio, 10      side 1     
-    0x200a, //  3: wait   0 gpio, 10      side 0     
+    0x309a, //  2: wait   1 gpio, 26      side 1     
+    0x201a, //  3: wait   0 gpio, 26      side 0     
     0x5009, //  4: in     pins, 9         side 1     
     0x5067, //  5: in     null, 7         side 1     
-    0x1042, //  6: jmp    x--, 2          side 1
+    0x1042, //  6: jmp    x--, 2          side 1     
             //     .wrap
 };
 
@@ -83,9 +83,9 @@ static inline pio_sm_config scsi_accel_async_read_program_get_default_config(uin
 
 static const uint16_t scsi_sync_write_program_instructions[] = {
             //     .wrap_target
-    0x7009, //  0: out    pins, 9         side 1
-    0x6067, //  1: out    null, 7         side 0
-    0x5061, //  2: in     null, 1         side 1
+    0x7009, //  0: out    pins, 9         side 1     
+    0x6067, //  1: out    null, 7         side 0     
+    0x5061, //  2: in     null, 1         side 1     
             //     .wrap
 };
 
@@ -113,9 +113,9 @@ static inline pio_sm_config scsi_sync_write_program_get_default_config(uint offs
 
 static const uint16_t scsi_sync_write_pacer_program_instructions[] = {
             //     .wrap_target
-    0x208a, //  0: wait   1 gpio, 10
-    0x200a, //  1: wait   0 gpio, 10
-    0x6061, //  2: out    null, 1
+    0x209a, //  0: wait   1 gpio, 26                 
+    0x201a, //  1: wait   0 gpio, 26                 
+    0x6061, //  2: out    null, 1                    
             //     .wrap
 };
 

+ 12 - 4
lib/BlueSCSI_platform_RP2040/scsi_accel_rp2040.cpp

@@ -133,8 +133,15 @@ 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_DMA_SM, 0x3FF);
-        pio_sm_set_consecutive_pindirs(SCSI_DMA_PIO, SCSI_DMA_SM, 0, 10, true);
+        pio_sm_set_pins(SCSI_DMA_PIO, SCSI_DMA_SM, 0x201FF);  //0x3FF
+        // Binary of 0x3FF is is 0 0 1 1 11111111
+        //                       ? A R P DBP
+        // A = ACK, R = REQ, DBP are the data pins
+        // REQ internal state needs to be set 'high'
+        // 100000000111111111
+        // Probably right to left here, so 0 - 9 are set 'high' and 10/11 are set 'low'
+        pio_sm_set_consecutive_pindirs(SCSI_DMA_PIO, SCSI_DMA_SM, 0, 9, true);
+        pio_sm_set_consecutive_pindirs(SCSI_DMA_PIO, SCSI_DMA_SM, 17, 1, true);
 
         iobank0_hw->io[SCSI_IO_DB0].ctrl  = GPIO_FUNC_PIO0;
         iobank0_hw->io[SCSI_IO_DB1].ctrl  = GPIO_FUNC_PIO0;
@@ -150,9 +157,10 @@ static void scsidma_config_gpio()
     else if (g_scsi_dma_state == SCSIDMA_READ)
     {
         // Data bus as input, REQ pin as output
-        pio_sm_set_pins(SCSI_DMA_PIO, SCSI_DMA_SM, 0x3FF);
+        pio_sm_set_pins(SCSI_DMA_PIO, SCSI_DMA_SM, 0x201FF); // 0x3FF
         pio_sm_set_consecutive_pindirs(SCSI_DMA_PIO, SCSI_DMA_SM, 0, 9, false);
-        pio_sm_set_consecutive_pindirs(SCSI_DMA_PIO, SCSI_DMA_SM, 9, 1, true);
+        pio_sm_set_consecutive_pindirs(SCSI_DMA_PIO, SCSI_DMA_SM, 17, 1, true);
+        // pio_sm_set_consecutive_pindirs(SCSI_DMA_PIO, SCSI_DMA_SM, 26, 1, false);  // not sure if this needs to be here
 
         iobank0_hw->io[SCSI_IO_DB0].ctrl  = GPIO_FUNC_SIO;
         iobank0_hw->io[SCSI_IO_DB1].ctrl  = GPIO_FUNC_SIO;