Kaynağa Gözat

Change matching KHz to Speed Grade Turbo Settings

Removed the `zuluscsi.ini` setting for matching reclocking via KHz
presets to using SpeedGrade = TurboMax etc.
Morio 1 yıl önce
ebeveyn
işleme
3f006998d5

+ 4 - 1
lib/ZuluSCSI_platform_GD32F205/ZuluSCSI_platform.h

@@ -106,7 +106,10 @@ uint8_t platform_get_buttons();
 uint32_t platform_sys_clock_in_hz();
 
 // Attempt to reclock the MCU - unsupported
-inline zuluscsi_reclock_status_t platform_reclock(uint32_t clk_in_khz){return ZULUSCSI_RECLOCK_NOT_SUPPORTED;}
+inline zuluscsi_reclock_status_t platform_reclock(zuluscsi_speed_grade_t speed_grade){return ZULUSCSI_RECLOCK_NOT_SUPPORTED;}
+
+// match string to speed grade - unsupported
+inline zuluscsi_speed_grade_t platform_string_to_speed_grade(const char *speed_grade_str, size_t length){return SPEED_GRADE_DEFAULT;}
 
 // Returns true if reboot was for mass storage - unsupported
 inline bool platform_rebooted_into_mass_storage() {return false;}

+ 6 - 1
lib/ZuluSCSI_platform_GD32F450/ZuluSCSI_platform.h

@@ -97,11 +97,16 @@ uint8_t platform_get_buttons();
 uint32_t platform_sys_clock_in_hz();
 
 // Attempt to reclock the MCU - unsupported
-inline zuluscsi_reclock_status_t platform_reclock(uint32_t clk_in_khz){return ZULUSCSI_RECLOCK_NOT_SUPPORTED;}
+inline zuluscsi_reclock_status_t platform_reclock(zuluscsi_speed_grade_t speed_grade){return ZULUSCSI_RECLOCK_NOT_SUPPORTED;}
+
+// match string to speed grade - unsupported
+inline zuluscsi_speed_grade_t platform_string_to_speed_grade(const char *speed_grade_str, size_t length){return SPEED_GRADE_DEFAULT;}
 
 // Returns true if reboot was for mass storage - unsupported
 inline bool platform_rebooted_into_mass_storage() {return false;}
 
+
+
 // Reinitialize SD card connection and save log from interrupt context.
 // This can be used in crash handlers.
 void platform_emergency_log_save();

+ 49 - 12
lib/ZuluSCSI_platform_RP2MCU/ZuluSCSI_platform.cpp

@@ -125,31 +125,68 @@ uint32_t platform_sys_clock_in_hz()
     return clock_get_hz(clk_sys);
 }
 
-zuluscsi_reclock_status_t platform_reclock(uint32_t clock_in_khz)
+zuluscsi_speed_grade_t platform_string_to_speed_grade(const char *speed_grade_str, size_t length)
+{
+    static const char sg_default[] = "Default";
+    zuluscsi_speed_grade_t grade;
+
+#ifdef ENABLE_AUDIO_OUTPUT
+    logmsg("Audio output enabled, reclocking isn't possible");
+    return SPEED_GRADE_DEFAULT;
+#endif;
+
+    if (strcasecmp(speed_grade_str, sg_default) == 0)
+      grade = SPEED_GRADE_DEFAULT;
+    else if (strcasecmp(speed_grade_str, "TurboMax") == 0)
+      grade = SPEED_GRADE_MAX;
+    else if (strcasecmp(speed_grade_str, "TurboA") == 0)
+      grade = SPEED_GRADE_A;
+    else if (strcasecmp(speed_grade_str, "TurboB") == 0)
+      grade = SPEED_GRADE_B;
+    else if (strcasecmp(speed_grade_str, "TurboC") == 0)
+      grade = SPEED_GRADE_C;
+    else if (strcasecmp(speed_grade_str, "Custom") == 0)
+      grade = SPEED_GRADE_CUSTOM;
+    else
+    {
+      logmsg("Setting \"", speed_grade_str, "\" does not match any know speed grade, using default");
+      grade = SPEED_GRADE_DEFAULT;
+    }
+    return grade;
+}
+
+zuluscsi_reclock_status_t platform_reclock(zuluscsi_speed_grade_t speed_grade)
 {
     CustomTimings ct;
-    if (ct.use_custom_timings())
+    if (speed_grade == SPEED_GRADE_CUSTOM)
     {
-        logmsg("Custom timings found in \"", CUSTOM_TIMINGS_FILE, "\" overriding reclocking");
-        logmsg("Initial Clock set to ", (int) platform_sys_clock_in_hz(), "Hz");
-        if (ct.set_timings_from_file())
+        if (ct.use_custom_timings())
         {
-            reclock();
-            logmsg("SDIO clock set to ", (int)((g_zuluscsi_timings->clk_hz / g_zuluscsi_timings->sdio.clk_div_pio + (5 * MHZ / 10)) / MHZ) , "MHz");
-            return ZULUSCSI_RECLOCK_CUSTOM;
+            logmsg("Custom timings found in \"", CUSTOM_TIMINGS_FILE, "\" overriding reclocking");
+            logmsg("Initial Clock set to ", (int) platform_sys_clock_in_hz(), "Hz");
+            if (ct.set_timings_from_file())
+            {
+                reclock();
+                logmsg("SDIO clock set to ", (int)((g_zuluscsi_timings->clk_hz / g_zuluscsi_timings->sdio.clk_div_pio + (5 * MHZ / 10)) / MHZ) , "MHz");
+                return ZULUSCSI_RECLOCK_CUSTOM;
+            }
+            else
+                return ZULUSCSI_RECLOCK_FAILED;
         }
         else
+        {
+            logmsg("Custom timings file, \"", CUSTOM_TIMINGS_FILE, "\" not found or disabled");
             return ZULUSCSI_RECLOCK_FAILED;
+        }
+
     }
-    else if (set_timings(clock_in_khz))
+    else if (set_timings(speed_grade))
     {
         logmsg("Initial Clock set to ", (int) platform_sys_clock_in_hz(), "Hz");
         reclock();
         logmsg("SDIO clock set to ", (int)((g_zuluscsi_timings->clk_hz / g_zuluscsi_timings->sdio.clk_div_pio + (5 * MHZ / 10)) / MHZ) , "MHz");
         return ZULUSCSI_RECLOCK_SUCCESS;
     }
-    else
-        logmsg("Could not find matching clock rate: ", (int) clock_in_khz, "KHz in presets");
     return ZULUSCSI_RECLOCK_FAILED;
 }
 
@@ -292,7 +329,7 @@ void platform_init()
 
 #ifdef ENABLE_AUDIO_OUTPUT
     logmsg("SP/DIF audio to expansion header enabled");
-    if (platform_reclock(135428) == ZULUSCSI_RECLOCK_SUCCESS)
+    if (platform_reclock(SPEED_GRADE_AUDIO) == ZULUSCSI_RECLOCK_SUCCESS)
     {
         logmsg("Reclocked for Audio Ouput at ", (int) platform_sys_clock_in_hz(), "Hz");
     }

+ 4 - 1
lib/ZuluSCSI_platform_RP2MCU/ZuluSCSI_platform.h

@@ -114,7 +114,10 @@ uint8_t platform_get_buttons();
 uint32_t platform_sys_clock_in_hz();
 
 // Attempt to reclock the MCU
-zuluscsi_reclock_status_t platform_reclock(uint32_t clk_in_khz);
+zuluscsi_reclock_status_t platform_reclock(zuluscsi_speed_grade_t speed_grade);
+
+// convert string to speed grade
+zuluscsi_speed_grade_t platform_string_to_speed_grade(const char *speed_grade_str, size_t length);
 
 // Returns true if reboot was for mass storage
 bool platform_rebooted_into_mass_storage();

+ 7 - 11
lib/ZuluSCSI_platform_RP2MCU/custom_timings.cpp

@@ -23,6 +23,7 @@
 #include <SdFat.h>
 #include <minIni.h>
 #include <ZuluSCSI_log.h>
+#include <ZuluSCSI_platform.h>
 extern SdFs SD;
 
 extern "C"
@@ -68,22 +69,18 @@ bool CustomTimings::set_timings_from_file()
         return false;
     }
 
-    int32_t template_khz = ini_getl(settings_section, "extends_khz", 0, CUSTOM_TIMINGS_FILE);
-    if (template_khz > 0)
-    {
-        if (!set_timings(template_khz))
-        {
-            logmsg("Count not load extends_khz with a value of ", (int) template_khz);
-            return false;
-        }
-    }
-
     g_zuluscsi_timings->pll.vco_freq = vco;
     g_zuluscsi_timings->pll.post_div1 = post_div1;
     g_zuluscsi_timings->pll.post_div2 = post_div2;
     g_zuluscsi_timings->pll.refdiv =  ini_getl(pll_section, "refdiv", g_zuluscsi_timings->pll.refdiv, CUSTOM_TIMINGS_FILE);
 
+    char speed_grade_str[10];
+    ini_gets(settings_section, "extends_speed_grade", "Default", speed_grade_str, sizeof(speed_grade_str), CUSTOM_TIMINGS_FILE);
+    zuluscsi_speed_grade_t speed_grade =  platform_string_to_speed_grade(speed_grade_str, sizeof(speed_grade_str));
+    set_timings(speed_grade);
+
     int32_t number_setting = ini_getl(settings_section, "boot_with_sync_value", 0, CUSTOM_TIMINGS_FILE);
+
     if (number_setting > 0)
     {
         g_force_sync = number_setting;
@@ -94,7 +91,6 @@ bool CustomTimings::set_timings_from_file()
     g_zuluscsi_timings->clk_hz = ini_getl(settings_section, "clk_hz", g_zuluscsi_timings->clk_hz, CUSTOM_TIMINGS_FILE);
 
 
-
     // scsi
     g_zuluscsi_timings->scsi.clk_period_ps = ini_getl(scsi_section, "clk_period_ps", g_zuluscsi_timings->scsi.clk_period_ps, CUSTOM_TIMINGS_FILE);
     g_zuluscsi_timings->scsi.req_delay = ini_getl(scsi_section, "req_delay_cc", g_zuluscsi_timings->scsi.req_delay, CUSTOM_TIMINGS_FILE);

+ 27 - 13
lib/ZuluSCSI_platform_RP2MCU/timings_RP2MCU.c

@@ -74,7 +74,7 @@ static zuluscsi_timings_t  predefined_timings[]  = {
             .delay1 = 2 - 1  // clk_div_pio - delay0 and subtract one for the instruction delay
         }
     },
-        {
+    {
         .clk_hz = 133000000,
 
         .pll =
@@ -300,20 +300,34 @@ static zuluscsi_timings_t  predefined_timings[]  = {
 #endif
 
 
-bool set_timings(uint32_t target_clk_in_khz)
+bool set_timings(zuluscsi_speed_grade_t speed_grade)
 {
-    uint32_t number_of_timings = sizeof(predefined_timings)/sizeof( predefined_timings[0]);
-    for (uint8_t i = 0; i < number_of_timings; i++)
+    uint8_t timings_index;
+
+    switch (speed_grade)
     {
-        if (target_clk_in_khz == predefined_timings[i].clk_hz / 1000)
-        {
-            g_zuluscsi_timings = &current_timings;
-            memcpy(g_zuluscsi_timings, &predefined_timings[i], sizeof(current_timings));
-            g_max_sync_10_period = g_zuluscsi_timings->scsi_10.max_sync;
-            g_max_sync_20_period = g_zuluscsi_timings->scsi_20.max_sync;
-            g_max_sync_5_period = g_zuluscsi_timings->scsi_5.max_sync;
-            return true;
-        }
+        case SPEED_GRADE_MAX:
+        case SPEED_GRADE_A:
+            timings_index = 4;
+            break;
+        case SPEED_GRADE_B:
+            timings_index = 3;
+            break;
+        case SPEED_GRADE_C:
+            timings_index  = 1;
+            break;
+        case SPEED_GRADE_AUDIO:
+            timings_index = 2;
+            break;
+    }   
+    if (speed_grade != SPEED_GRADE_DEFAULT && speed_grade != SPEED_GRADE_CUSTOM)
+    {
+        g_zuluscsi_timings = &current_timings;
+        memcpy(g_zuluscsi_timings, &predefined_timings[timings_index], sizeof(current_timings));
+        g_max_sync_10_period = g_zuluscsi_timings->scsi_10.max_sync;
+        g_max_sync_20_period = g_zuluscsi_timings->scsi_20.max_sync;
+        g_max_sync_5_period = g_zuluscsi_timings->scsi_5.max_sync;
+        return true;
     }
     return false;
 }

+ 3 - 1
lib/ZuluSCSI_platform_RP2MCU/timings_RP2MCU.h

@@ -22,6 +22,7 @@
 #define ZULUSCSI_TIMINGS_RP2MCU_H
 #include <stdint.h>
 #include <stdbool.h>
+#include <ZuluSCSI_config.h>
 
 typedef struct
 {
@@ -102,5 +103,6 @@ typedef struct
 
 extern  zuluscsi_timings_t *g_zuluscsi_timings;
 
-bool set_timings(uint32_t target_clk_in_khz);
+// Sets timings to the speed_grade, returns false on SPEED_GRADE_DEFAULT and SPEED_GRADE_CUSTOM
+bool set_timings(zuluscsi_speed_grade_t speed_grade);
 #endif // ZULUSCSI_TIMINGS_RP2MCU_H

+ 9 - 6
src/ZuluSCSI.cpp

@@ -847,13 +847,16 @@ static void zuluscsi_setup_sd_card()
     } while (!g_sdcard_present);
     logmsg("SD card init succeeded after retry");
   }
-
+  
+  static const char sg_default[] = "Default"; 
   if (g_sdcard_present)
   {
-    int32_t clock_khz = ini_getl("SCSI", "ReclockInKHz", 0, CONFIGFILE);
-    if ( clock_khz > 0)
+    char speed_grade_str[10];
+    ini_gets("SCSI", "SpeedGrade", sg_default, speed_grade_str, sizeof(speed_grade_str), CONFIGFILE);
+    zuluscsi_speed_grade_t grade = platform_string_to_speed_grade(speed_grade_str, sizeof(speed_grade_str));
+    if (grade != SPEED_GRADE_DEFAULT)
     {
-      zuluscsi_reclock_status_t status = platform_reclock(clock_khz);
+      zuluscsi_reclock_status_t status = platform_reclock(grade);
       switch (status)
       {
         case ZULUSCSI_RECLOCK_NOT_SUPPORTED:
@@ -863,7 +866,7 @@ static void zuluscsi_setup_sd_card()
           logmsg("Reclocking failed");
           break;
         case ZULUSCSI_RECLOCK_SUCCESS:
-          logmsg("Reclocking at ", (int) clock_khz , " KHz was successful");
+          logmsg("Reclocking was successful");
           break;
         case ZULUSCSI_RECLOCK_CUSTOM:
           logmsg("Custom reclocking timings used");
@@ -923,7 +926,7 @@ extern "C" void zuluscsi_setup(void)
 
 #ifdef PLATFORM_MASS_STORAGE
   static bool check_mass_storage = true;
-  if (check_mass_storage && g_scsi_settings.getSystem()->enableUSBMassStorage
+  if ((check_mass_storage && g_scsi_settings.getSystem()->enableUSBMassStorage)
       || platform_rebooted_into_mass_storage())
   {
     check_mass_storage = false;

+ 11 - 0
src/ZuluSCSI_config.h

@@ -136,3 +136,14 @@ typedef enum
     ZULUSCSI_RECLOCK_NOT_SUPPORTED,
     ZULUSCSI_RECLOCK_FAILED
 } zuluscsi_reclock_status_t;
+
+typedef enum
+{
+    SPEED_GRADE_DEFAULT,
+    SPEED_GRADE_MAX,
+    SPEED_GRADE_CUSTOM,
+    SPEED_GRADE_A,
+    SPEED_GRADE_B,
+    SPEED_GRADE_C,
+    SPEED_GRADE_AUDIO,
+} zuluscsi_speed_grade_t;

+ 2 - 2
zuluscsi.ini

@@ -31,7 +31,7 @@
 #InitPostDelay = 0 # How many milliseconds to delay after the SCSI interface is initialized
 
 # Will attempt to reclock the board if the board supports both reclocking and the choosen speed
-# ReclockInKHz = 0 # Default is zero, ignore reclocking
+# SpeedGrade = Default # TurboMax - max speed, TurboA - mode A, TurboC, etc
 # When reclocking the board MaxSyncSpeed may need to be increased, see manual for details
 # MaxSyncSpeed = 10 # Set to 5, 10, or 20 to enable synchronous SCSI mode, 0 to disable
 
@@ -56,7 +56,7 @@
 #Product = "FIREBALL1"
 #Version = "1.0"
 #Serial = "0123456789ABCDEF"
-#Type = 0     # 0: Fixed, 1: Removable, 2: Optical, 3: Floppy, 4: Mag-optical, 
+#Type = 0     # 0: Fixed, 1: Removable, 2: Optical, 3: Floppy, 4: Mag-optical,
               # 5: Tape,  6: Network,   7: Zip100
 #VendorExtensions = 0 # Bit flags for specific extensions per device type
 #  CDROM - 1: Plextor's d8h vendor command

+ 7 - 4
zuluscsi_timings.ini

@@ -1,16 +1,19 @@
 [settings]
 disable = False # True: disable custom settings - default false: use the settings of this file
 
-# extends_khz lets you choose a built in timing setting as a template
-# this is the same value as would be set in ReclockInKHz in zuluscsi.ini
-# this allows the ability to use a minimum of below settings in your zuluscsi_timings.ini file
-extends_khz = 125000 # default value is 0 - meaning using the base settings of the board
+# extends_speed_grade lets you choose a built in timing setting as a template
+# this is the same value as would be set as SpeedGrade in zuluscsi.ini
+# this allows the ability to use a minimum of the below settings in your zuluscsi_timings.ini file
+extends_speed_grade = Default # Default, TurboMax, TurboA, TurboB, etc
 
 # boot_with_sync value setting starts the board at an assumed sync value
 # boot_with_offset value setting starts the board at an assumed offset value
 # these are values are usually requested by the host to negotiate sync transfers
 # this is for users who are restarting their boards while the system is running
 # to test their settings and don't want to reboot their computers to renegotiate sync
+# if a USB serial console is used, settings can be change using the key presses 'm' then 'y'
+# for rebooting in mass storage mode, making changes to 'zuluscsi_timings.ini' then
+# ejecting the mass storage device
 # ** hot swapping like this is not recommended **
 # the sync value is explained below
 boot_with_sync_value = 0 # default value is 0 meaning this feature is off