Skip to content

Commit

Permalink
Merge pull request #468 from ZuluSCSI/feature/scsi-ultra
Browse files Browse the repository at this point in the history
Ultra SCSI (Fast20) support with reclocking the RP2040 and RP2350 line of boards and user editable reclocking timings
  • Loading branch information
aperezbios authored Nov 4, 2024
2 parents 5c620ac + 6484158 commit 79b5c40
Show file tree
Hide file tree
Showing 56 changed files with 1,773 additions and 2,635 deletions.
2 changes: 1 addition & 1 deletion lib/SCSI2SD/include/scsi2sd.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ typedef enum
S2S_CFG_SPEED_ASYNC_50,
S2S_CFG_SPEED_SYNC_5,
S2S_CFG_SPEED_SYNC_10,
S2S_CFG_SPEED_TURBO
S2S_CFG_SPEED_SYNC_20
} S2S_CFG_SPEED;

typedef struct __attribute__((packed))
Expand Down
60 changes: 36 additions & 24 deletions lib/SCSI2SD/src/firmware/scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "led.h"
#include "mode.h"
#include "scsi2sd_time.h"
#include "timings.h"
#include "bsp.h"
#include "cdrom.h"
#include "network.h"
Expand Down Expand Up @@ -758,8 +759,16 @@ static void scsiReset()

for (int i = 0; i < S2S_MAX_TARGETS; ++i)
{
scsiDev.targets[i].syncOffset = 0;
scsiDev.targets[i].syncPeriod = 0;
if (g_force_sync > 0)
{
scsiDev.targets[i].syncPeriod = g_force_sync;
scsiDev.targets[i].syncOffset = g_force_offset;
}
else
{
scsiDev.targets[i].syncOffset = 0;
scsiDev.targets[i].syncPeriod = 0;
}
}
scsiDev.minSyncPeriod = 0;

Expand Down Expand Up @@ -1105,31 +1114,26 @@ static void process_MessageOut()
//The speeds above correspond to syncPeriod values of 25, 18, 15 and 12 (maybe, the last 3 are truncated)
//We will set the syncPeriod and syncOffset to the fastest we
//can support if the initiator requests a faster speed
if ((scsiDev.boardCfg.scsiSpeed == S2S_CFG_SPEED_TURBO) &&
(transferPeriod <= 18))
if (scsiDev.boardCfg.scsiSpeed == S2S_CFG_SPEED_SYNC_20 || scsiDev.boardCfg.scsiSpeed == S2S_CFG_SPEED_NoLimit)
{
scsiDev.target->syncPeriod = 18; // 20 corresponds to 12.5 MB/s
if (transferPeriod <= g_max_sync_20_period)
scsiDev.target->syncPeriod = g_max_sync_20_period;
else
scsiDev.target->syncPeriod = transferPeriod;
}
else if (scsiDev.boardCfg.scsiSpeed == S2S_CFG_SPEED_TURBO)
else if (scsiDev.boardCfg.scsiSpeed >= S2S_CFG_SPEED_SYNC_10)
{
scsiDev.target->syncPeriod = transferPeriod;
if (transferPeriod <= g_max_sync_10_period)
scsiDev.target->syncPeriod = g_max_sync_10_period;
else
scsiDev.target->syncPeriod = transferPeriod;
}
else if (transferPeriod <= 25 &&
((scsiDev.boardCfg.scsiSpeed == S2S_CFG_SPEED_NoLimit) ||
(scsiDev.boardCfg.scsiSpeed >= S2S_CFG_SPEED_SYNC_10)))
{
scsiDev.target->syncPeriod = 25; // 100ns, 10MB/s

} else if (transferPeriod < 50 &&
((scsiDev.boardCfg.scsiSpeed == S2S_CFG_SPEED_NoLimit) ||
(scsiDev.boardCfg.scsiSpeed >= S2S_CFG_SPEED_SYNC_10)))
else if (scsiDev.boardCfg.scsiSpeed == S2S_CFG_SPEED_SYNC_5)
{
scsiDev.target->syncPeriod = transferPeriod;
} else if (transferPeriod >= 50)
{
scsiDev.target->syncPeriod = transferPeriod;
} else {
scsiDev.target->syncPeriod = 50;
if (transferPeriod <= g_max_sync_5_period)
scsiDev.target->syncPeriod = g_max_sync_5_period;
else
scsiDev.target->syncPeriod = transferPeriod;
}
}

Expand Down Expand Up @@ -1350,8 +1354,16 @@ void scsiInit()
scsiDev.targets[i].sense.code = NO_SENSE;
scsiDev.targets[i].sense.asc = NO_ADDITIONAL_SENSE_INFORMATION;

scsiDev.targets[i].syncOffset = 0;
scsiDev.targets[i].syncPeriod = 0;
if (g_force_sync > 0)
{
scsiDev.targets[i].syncPeriod = g_force_sync;
scsiDev.targets[i].syncOffset = g_force_offset;
}
else
{
scsiDev.targets[i].syncOffset = 0;
scsiDev.targets[i].syncPeriod = 0;
}

// Always "start" the device. Many systems (eg. Apple System 7)
// won't respond properly to
Expand Down
29 changes: 29 additions & 0 deletions lib/SCSI2SD/src/firmware/timings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* ZuluSCSI™ - Copyright (c) 2024 Rabbit Hole Computing™
*
* ZuluSCSI™ firmware is licensed under the GPL version 3 or any later version. 
*
* https://www.gnu.org/licenses/gpl-3.0.html
* ----
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. 
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details. 
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <https://www.gnu.org/licenses/>.
**/
#ifndef ZULUSCSI_SCSI2SD_TIMINGS_H
#define ZULUSCSI_SCSI2SD_TIMINGS_H
#include <stdint.h>
extern uint8_t g_max_sync_20_period;
extern uint8_t g_max_sync_10_period;
extern uint8_t g_max_sync_5_period;
extern uint8_t g_force_sync;
extern uint8_t g_force_offset;
#endif // ZULUSCSI_SCSI2SD_TIMINGS_H
6 changes: 6 additions & 0 deletions lib/ZuluSCSI_platform_GD32F205/ZuluSCSI_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ void SysTick_Handle_PreEmptively()
__enable_irq();
}

uint32_t platform_sys_clock_in_hz()
{
return rcu_clock_freq_get(CK_SYS);
}


/***************/
/* GPIO init */
/***************/
Expand Down
38 changes: 13 additions & 25 deletions lib/ZuluSCSI_platform_GD32F205/ZuluSCSI_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,14 @@
#include <gd32f20x.h>
#include <gd32f20x_gpio.h>
#include <scsi2sd.h>
#include <ZuluSCSI_config.h>

#ifdef __cplusplus
extern "C" {
#endif

extern const char *g_platform_name;

#if defined(ZULUSCSI_V1_0)
# if defined(ZULUSCSI_V1_0_mini)
# define PLATFORM_NAME "ZuluSCSI mini v1.0"
# else
# define PLATFORM_NAME "ZuluSCSI v1.0"
# endif
# define PLATFORM_REVISION "1.0"
# define PLATFORM_MAX_SCSI_SPEED S2S_CFG_SPEED_ASYNC_50
# include "ZuluSCSI_v1_0_gpio.h"
#else
# define PLATFORM_NAME "ZuluSCSI v1.1+"
# define PLATFORM_REVISION "1.1+"
# define PLATFORM_MAX_SCSI_SPEED S2S_CFG_SPEED_SYNC_10
# define PLATFORM_OPTIMAL_MIN_SD_WRITE_SIZE 4096
# define PLATFORM_OPTIMAL_MAX_SD_WRITE_SIZE 65536
# define PLATFORM_OPTIMAL_LAST_SD_WRITE_SIZE 8192
# define PLATFORM_VERSION_1_1_PLUS
# define ZULUSCSI_HARDWARE_CONFIG
# include "ZuluSCSI_v1_1_gpio.h"
#endif

#include "platform_hw_config.h"

enum ZuluSCSIVersion_t
Expand All @@ -69,10 +49,6 @@ enum ZuluSCSIVersion_t
extern enum ZuluSCSIVersion_t g_zuluscsi_version;
extern bool g_moved_select_in;

#ifndef PLATFORM_VDD_WARNING_LIMIT_mV
#define PLATFORM_VDD_WARNING_LIMIT_mV 2800
#endif

// Debug logging functions
void platform_log(const char *s);

Expand Down Expand Up @@ -126,6 +102,18 @@ void platform_poll();
// This function should return without significantly delay.
uint8_t platform_get_buttons();

// Return system clock in Hz
uint32_t platform_sys_clock_in_hz();

// Attempt to reclock the MCU - unsupported
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();
Expand Down
47 changes: 47 additions & 0 deletions lib/ZuluSCSI_platform_GD32F205/ZuluSCSI_platform_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* ZuluSCSI™ - Copyright (c) 2024 Rabbit Hole Computing™
*
* ZuluSCSI™ firmware is licensed under the GPL version 3 or any later version. 
*
* https://www.gnu.org/licenses/gpl-3.0.html
* ----
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. 
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details. 
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <https://www.gnu.org/licenses/>.
**/
#pragma once
#if defined(ZULUSCSI_V1_0)
# if defined(ZULUSCSI_V1_0_mini)
# define PLATFORM_NAME "ZuluSCSI mini v1.0"
# else
# define PLATFORM_NAME "ZuluSCSI v1.0"
# endif
# define PLATFORM_REVISION "1.0"
# define PLATFORM_MAX_SCSI_SPEED S2S_CFG_SPEED_ASYNC_50
# include "ZuluSCSI_v1_0_gpio.h"
#else
# define PLATFORM_NAME "ZuluSCSI v1.1+"
# define PLATFORM_REVISION "1.1+"
# define PLATFORM_MAX_SCSI_SPEED S2S_CFG_SPEED_SYNC_10
# define PLATFORM_OPTIMAL_MIN_SD_WRITE_SIZE 4096
# define PLATFORM_OPTIMAL_MAX_SD_WRITE_SIZE 65536
# define PLATFORM_OPTIMAL_LAST_SD_WRITE_SIZE 8192
# define PLATFORM_VERSION_1_1_PLUS
# define ZULUSCSI_HARDWARE_CONFIG
# include "ZuluSCSI_v1_1_gpio.h"
#endif

#ifndef PLATFORM_VDD_WARNING_LIMIT_mV
#define PLATFORM_VDD_WARNING_LIMIT_mV 2800
#endif

#define PLATFORM_DEFAULT_SCSI_SPEED_SETTING 10
26 changes: 26 additions & 0 deletions lib/ZuluSCSI_platform_GD32F205/scsi2sd_timings.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* ZuluSCSI™ - Copyright (c) 2024 Rabbit Hole Computing™
*
* ZuluSCSI™ firmware is licensed under the GPL version 3 or any later version.
*
* https://www.gnu.org/licenses/gpl-3.0.html
* ----
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <https://www.gnu.org/licenses/>.
**/
#include "timings.h"
uint8_t g_max_sync_20_period = 25;
uint8_t g_max_sync_10_period = 25;
uint8_t g_max_sync_5_period = 50;
uint8_t g_force_sync = 0;
uint8_t g_force_offset = 15;
5 changes: 5 additions & 0 deletions lib/ZuluSCSI_platform_GD32F450/ZuluSCSI_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ void SysTick_Handle_PreEmptively()
__enable_irq();
}

uint32_t platform_sys_clock_in_hz()
{
return rcu_clock_freq_get(CK_SYS);
}

/***************/
/* GPIO init */
/***************/
Expand Down
31 changes: 14 additions & 17 deletions lib/ZuluSCSI_platform_GD32F450/ZuluSCSI_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
#include <gd32f4xx.h>
#include <gd32f4xx_gpio.h>
#include <scsi2sd.h>
#include "ZuluSCSI_config.h"

#include <ZuluSCSI_config.h>

#ifdef __cplusplus
#include <SdFat.h>
Expand All @@ -38,21 +37,6 @@ extern "C" {

extern const char *g_platform_name;

#if defined(ZULUSCSI_V1_4)
# define PLATFORM_NAME "ZuluSCSI v1.4"
# define PLATFORM_REVISION "1.4"
# define PLATFORM_MAX_SCSI_SPEED S2S_CFG_SPEED_SYNC_10
# define PLATFORM_OPTIMAL_MIN_SD_WRITE_SIZE 4096
# define PLATFORM_OPTIMAL_MAX_SD_WRITE_SIZE 65536
# define PLATFORM_OPTIMAL_LAST_SD_WRITE_SIZE 8192
# define PLATFORM_FLASH_SECTOR_ERASE
# include "ZuluSCSI_v1_4_gpio.h"
#endif

#ifndef PLATFORM_VDD_WARNING_LIMIT_mV
#define PLATFORM_VDD_WARNING_LIMIT_mV 2800
#endif

// Debug logging functions
void platform_log(const char *s);

Expand Down Expand Up @@ -110,6 +94,19 @@ void platform_poll();
// This function should return without significantly delay.
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(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();
Expand Down
38 changes: 38 additions & 0 deletions lib/ZuluSCSI_platform_GD32F450/ZuluSCSI_platform_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* ZuluSCSI™ - Copyright (c) 2024 Rabbit Hole Computing™
*
* ZuluSCSI™ firmware is licensed under the GPL version 3 or any later version. 
*
* https://www.gnu.org/licenses/gpl-3.0.html
* ----
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. 
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details. 
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <https://www.gnu.org/licenses/>.
**/
#pragma once

#if defined(ZULUSCSI_V1_4)
# define PLATFORM_NAME "ZuluSCSI v1.4"
# define PLATFORM_REVISION "1.4"
# define PLATFORM_MAX_SCSI_SPEED S2S_CFG_SPEED_SYNC_10
# define PLATFORM_OPTIMAL_MIN_SD_WRITE_SIZE 4096
# define PLATFORM_OPTIMAL_MAX_SD_WRITE_SIZE 65536
# define PLATFORM_OPTIMAL_LAST_SD_WRITE_SIZE 8192
# define PLATFORM_FLASH_SECTOR_ERASE
# include "ZuluSCSI_v1_4_gpio.h"
#endif

#ifndef PLATFORM_VDD_WARNING_LIMIT_mV
#define PLATFORM_VDD_WARNING_LIMIT_mV 2800
#endif

#define PLATFORM_DEFAULT_SCSI_SPEED_SETTING 10
Loading

0 comments on commit 79b5c40

Please sign in to comment.