Fix bug in using nor flash storage without SD master
authorMichael McMaster <michael@codesrc.com>
Mon, 22 Mar 2021 03:48:51 +0000 (13:48 +1000)
committerMichael McMaster <michael@codesrc.com>
Mon, 22 Mar 2021 03:48:51 +0000 (13:48 +1000)
software/SCSI2SD/src/config.c
software/SCSI2SD/src/disk.c
software/SCSI2SD/src/flash.c
software/SCSI2SD/src/main.c
software/SCSI2SD/src/scsiPhy.c
software/SCSI2SD/src/sd.c
software/SCSI2SD/src/storedevice.h
software/SCSI2SD/v5.2/SCSI2SD.cydsn/SCSI2SD.cyfit

index ddc146a..2d4c628 100755 (executable)
@@ -67,7 +67,7 @@ static int usbReady;
 static void initBoardConfig(S2S_BoardConfig* config) {\r
        memcpy(\r
                config,\r
-               (\r
+               (const void*)(\r
                        CY_FLASH_BASE +\r
                        (CY_FLASH_SIZEOF_ARRAY * (size_t) SCSI_CONFIG_ARRAY) +\r
                        (CY_FLASH_SIZEOF_ROW * SCSI_CONFIG_BOARD_ROW)\r
@@ -472,7 +472,7 @@ void debugPoll()
                dbgHidBuffer[61] = sdCard.capacity;\r
 \r
                dbgHidBuffer[62] = FIRMWARE_VERSION >> 8;\r
-               dbgHidBuffer[63] = FIRMWARE_VERSION;\r
+               dbgHidBuffer[63] = FIRMWARE_VERSION & 0xFF;\r
 \r
                USBFS_LoadInEP(USB_EP_DEBUG, (uint8 *)&dbgHidBuffer, sizeof(dbgHidBuffer));\r
                usbDebugEpState = USB_DATA_SENT;\r
index 48f5890..9fbeeba 100755 (executable)
@@ -576,8 +576,14 @@ void scsiDiskPoll()
                        // Wait for the next DMA interrupt. It's beneficial to halt the\r
                        // processor to give the DMA controller more memory bandwidth to\r
                        // work with.\r
-                       int scsiBusy = 1;\r
-                       int sdBusy = 1;\r
+                       int scsiBusy;\r
+                       int sdBusy;\r
+                       {\r
+                               uint8_t intr = CyEnterCriticalSection();\r
+                               scsiBusy = scsiDMABusy();\r
+                               sdBusy = isSDDevice && sdDMABusy();\r
+                               CyExitCriticalSection(intr);\r
+                       }\r
                        while (scsiBusy && sdBusy && isSDDevice)\r
                        {\r
                                uint8_t intr = CyEnterCriticalSection();\r
index 0e6ba95..44b0280 100644 (file)
@@ -47,7 +47,7 @@ static void spiFlash_erase(S2S_Device* dev, uint32_t sectorNumber, uint32_t coun
 static void spiFlash_read(S2S_Device* dev, uint32_t sectorNumber, uint32_t count, uint8_t* buffer);
 static void spiFlash_readAsync(S2S_Device* dev, uint32_t sectorNumber, uint32_t count, uint8_t* buffer);
 static int  spiFlash_readAsyncPoll(S2S_Device* dev);
-static void spiFlash_write(S2S_Device* dev, uint32_t sectorNumber, uint32_t count, uint8_t* buffer);
+static void spiFlash_write(S2S_Device* dev, uint32_t sectorNumber, uint32_t count, const uint8_t* buffer);
 
 SpiFlash spiFlash = {
     {
@@ -298,7 +298,7 @@ static void spiFlash_erase(S2S_Device* dev, uint32_t sectorNumber, uint32_t coun
     nNOR_CS_Write(1); // Deselect
 }
 
-static void spiFlash_write(S2S_Device* dev, uint32_t sectorNumber, uint32_t count, uint8_t* buffer)
+static void spiFlash_write(S2S_Device* dev, uint32_t sectorNumber, uint32_t count, const uint8_t* buffer)
 {
     // SpiFlash* spiFlash = (SpiFlash*)dev;
 
index b9a6215..cead0c7 100755 (executable)
@@ -24,7 +24,7 @@
 #include "time.h"\r
 #include "trace.h"\r
 \r
-const char* Notice = "Copyright (C) 2015-2018 Michael McMaster <michael@codesrc.com>";\r
+const char* Notice = "Copyright (C) 2015-2021 Michael McMaster <michael@codesrc.com>";\r
 \r
 int main()\r
 {\r
index 46f6653..0ba494a 100755 (executable)
@@ -309,11 +309,11 @@ doTxSingleDMA(const uint8* data, uint32 count)
 }\r
 \r
 void\r
-scsiWriteDMA(const uint8* data, uint32 count)\r
+scsiWriteDMA(const uint8_t* data, uint32 count)\r
 {\r
        dmaSentCount = 0;\r
        dmaTotalCount = count;\r
-       dmaBuffer = data;\r
+       dmaBuffer = (uint8_t*) data;\r
 \r
        uint32_t singleCount = (count > MAX_DMA_BYTES) ? MAX_DMA_BYTES : count;\r
        doTxSingleDMA(data, singleCount);\r
index 7bf25fc..279499b 100755 (executable)
@@ -38,7 +38,7 @@ static void sd_erase(S2S_Device* dev, uint32_t sectorNumber, uint32_t count);
 static void sd_read(S2S_Device* dev, uint32_t sectorNumber, uint32_t count, uint8_t* buffer);\r
 static void sd_readAsync(S2S_Device* dev, uint32_t sectorNumber, uint32_t count, uint8_t* buffer);\r
 static int  sd_readAsyncPoll(S2S_Device* dev);\r
-static void sd_write(S2S_Device* dev, uint32_t sectorNumber, uint32_t count, uint8_t* buffer);\r
+static void sd_write(S2S_Device* dev, uint32_t sectorNumber, uint32_t count, const uint8_t* buffer);\r
 \r
 \r
 // Global\r
@@ -1139,7 +1139,7 @@ static int sd_readAsyncPoll(S2S_Device* dev)
 }\r
 \r
 \r
-static void sd_write(S2S_Device* dev, uint32_t sectorNumber, uint32_t count, uint8_t* buffer)\r
+static void sd_write(S2S_Device* dev, uint32_t sectorNumber, uint32_t count, const uint8_t* buffer)\r
 {\r
     // TODO\r
 }\r
index e66c640..90ad86d 100644 (file)
@@ -80,7 +80,7 @@ struct S2S_DeviceStruct
     void (*read)(S2S_Device* dev, uint32_t sectorNumber, uint32_t count, uint8_t* buffer);
     void (*readAsync)(S2S_Device* dev, uint32_t sectorNumber, uint32_t count, uint8_t* buffer);
     int  (*readAsyncPoll)(S2S_Device* dev);
-    void (*write)(S2S_Device* dev, uint32_t sectorNumber, uint32_t count, uint8_t* buffer);
+    void (*write)(S2S_Device* dev, uint32_t sectorNumber, uint32_t count, const uint8_t* buffer);
 
        MEDIA_STATE mediaState;
     CONFIG_STOREDEVICE deviceType;
index 944974d..9765968 100644 (file)
Binary files a/software/SCSI2SD/v5.2/SCSI2SD.cydsn/SCSI2SD.cyfit and b/software/SCSI2SD/v5.2/SCSI2SD.cydsn/SCSI2SD.cyfit differ