ZuluSCSI_platform.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // Platform-specific definitions for AzulSCSI.
  2. // Can be customized for different microcontrollers, this file is for GD32F205VCT6.
  3. #pragma once
  4. #include <gd32f20x.h>
  5. #include <gd32f20x_gpio.h>
  6. #include <scsi2sd.h>
  7. #include "AzulSCSI_config.h"
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. extern const char *g_azplatform_name;
  12. #if defined(AZULSCSI_V1_0)
  13. # define PLATFORM_NAME "AzulSCSI v1.0"
  14. # define PLATFORM_REVISION "1.0"
  15. # define PLATFORM_MAX_SCSI_SPEED S2S_CFG_SPEED_ASYNC_50
  16. # include "AzulSCSI_v1_0_gpio.h"
  17. #elif defined(AZULSCSI_V1_1)
  18. # define PLATFORM_NAME "AzulSCSI v1.1"
  19. # define PLATFORM_REVISION "1.1"
  20. # define PLATFORM_MAX_SCSI_SPEED S2S_CFG_SPEED_SYNC_10
  21. # define PLATFORM_OPTIMAL_MIN_SD_WRITE_SIZE 4096
  22. # define PLATFORM_OPTIMAL_MAX_SD_WRITE_SIZE 65536
  23. # define PLATFORM_OPTIMAL_LAST_SD_WRITE_SIZE 8192
  24. # include "AzulSCSI_v1_1_gpio.h"
  25. #endif
  26. // Debug logging functions
  27. void azplatform_log(const char *s);
  28. // Minimal millis() implementation as GD32F205 does not
  29. // have an Arduino core yet.
  30. unsigned long millis(void);
  31. void delay(unsigned long ms);
  32. // Precise nanosecond delays
  33. // Works in interrupt context also, max delay 500 000 ns, min delay about 500 ns
  34. void delay_ns(unsigned long ns);
  35. static inline void delay_us(unsigned long us)
  36. {
  37. if (us > 0)
  38. {
  39. delay_ns(us * 1000);
  40. }
  41. }
  42. // Approximate fast delay
  43. static inline void delay_100ns()
  44. {
  45. asm volatile ("nop \n nop \n nop \n nop \n nop");
  46. }
  47. // Initialize SPI and GPIO configuration
  48. void azplatform_init();
  49. // Initialization for main application, not used for bootloader
  50. void azplatform_late_init();
  51. // Setup soft watchdog
  52. void azplatform_reset_watchdog();
  53. // Reinitialize SD card connection and save log from interrupt context.
  54. // This can be used in crash handlers.
  55. void azplatform_emergency_log_save();
  56. // Set callback that will be called during data transfer to/from SD card.
  57. // This can be used to implement simultaneous transfer to SCSI bus.
  58. typedef void (*sd_callback_t)(uint32_t bytes_complete);
  59. void azplatform_set_sd_callback(sd_callback_t func, const uint8_t *buffer);
  60. // Reprogram firmware in main program area.
  61. #define AZPLATFORM_BOOTLOADER_SIZE 32768
  62. #define AZPLATFORM_FLASH_TOTAL_SIZE (256 * 1024)
  63. #define AZPLATFORM_FLASH_PAGE_SIZE 2048
  64. bool azplatform_rewrite_flash_page(uint32_t offset, uint8_t buffer[AZPLATFORM_FLASH_PAGE_SIZE]);
  65. void azplatform_boot_to_main_firmware();
  66. // Configuration customizations based on DIP switch settings
  67. // When DIPSW1 is on, Apple quirks are enabled by default.
  68. void azplatform_config_hook(S2S_TargetCfg *config);
  69. #define AZPLATFORM_CONFIG_HOOK(cfg) azplatform_config_hook(cfg)
  70. #define APPLE_DRIVEINFO_FIXED {"SEAGATE", "ST225N", PLATFORM_REVISION, "1.0"}
  71. #define APPLE_DRIVEINFO_REMOVABLE {"AZULSCSI", "APPLE_REMOVABLE", PLATFORM_REVISION, ""}
  72. #define APPLE_DRIVEINFO_OPTICAL {"MATSHITA", "CD-ROM CR-8004A", PLATFORM_REVISION, "2.0a"}
  73. #define APPLE_DRIVEINFO_FLOPPY {"AZULSCSI", "APPLE_FLOPPY", PLATFORM_REVISION, ""}
  74. #define APPLE_DRIVEINFO_MAGOPT {"AZULSCSI", "APPLE_MO", PLATFORM_REVISION, ""}
  75. #define APPLE_DRIVEINFO_TAPE {"AZULSCSI", "APPLE_TAPE", PLATFORM_REVISION, ""}
  76. // Write a single SCSI pin.
  77. // Example use: SCSI_OUT(ATN, 1) sets SCSI_ATN to low (active) state.
  78. #define SCSI_OUT(pin, state) \
  79. GPIO_BOP(SCSI_OUT_ ## pin ## _PORT) = (SCSI_OUT_ ## pin ## _PIN) << (state ? 16 : 0)
  80. // Read a single SCSI pin.
  81. // Example use: SCSI_IN(ATN), returns 1 for active low state.
  82. #define SCSI_IN(pin) \
  83. ((GPIO_ISTAT(SCSI_ ## pin ## _PORT) & (SCSI_ ## pin ## _PIN)) ? 0 : 1)
  84. // Write SCSI data bus, also sets REQ to inactive.
  85. extern const uint32_t g_scsi_out_byte_to_bop[256];
  86. #define SCSI_OUT_DATA(data) \
  87. GPIO_BOP(SCSI_OUT_PORT) = g_scsi_out_byte_to_bop[(uint8_t)(data)]
  88. // Release SCSI data bus and REQ signal
  89. #define SCSI_RELEASE_DATA_REQ() \
  90. GPIO_BOP(SCSI_OUT_PORT) = SCSI_OUT_DATA_MASK | SCSI_OUT_REQ
  91. // Release all SCSI outputs
  92. #define SCSI_RELEASE_OUTPUTS() \
  93. GPIO_BOP(SCSI_OUT_PORT) = SCSI_OUT_DATA_MASK | SCSI_OUT_REQ, \
  94. GPIO_BOP(SCSI_OUT_IO_PORT) = SCSI_OUT_IO_PIN, \
  95. GPIO_BOP(SCSI_OUT_CD_PORT) = SCSI_OUT_CD_PIN, \
  96. GPIO_BOP(SCSI_OUT_SEL_PORT) = SCSI_OUT_SEL_PIN, \
  97. GPIO_BOP(SCSI_OUT_MSG_PORT) = SCSI_OUT_MSG_PIN, \
  98. GPIO_BOP(SCSI_OUT_RST_PORT) = SCSI_OUT_RST_PIN, \
  99. GPIO_BOP(SCSI_OUT_BSY_PORT) = SCSI_OUT_BSY_PIN
  100. // Read SCSI data bus
  101. #define SCSI_IN_DATA(data) \
  102. (((~GPIO_ISTAT(SCSI_IN_PORT)) & SCSI_IN_MASK) >> SCSI_IN_SHIFT)
  103. #ifdef __cplusplus
  104. }
  105. // SD card driver for SdFat
  106. #ifndef SD_USE_SDIO
  107. // SPI interface, AzulSCSI v1.0
  108. class SdSpiConfig;
  109. extern SdSpiConfig g_sd_spi_config;
  110. #define SD_CONFIG g_sd_spi_config
  111. #define SD_CONFIG_CRASH g_sd_spi_config
  112. #else
  113. // SDIO interface, AzulSCSI v1.1
  114. class SdioConfig;
  115. extern SdioConfig g_sd_sdio_config;
  116. extern SdioConfig g_sd_sdio_config_crash;
  117. #define SD_CONFIG g_sd_sdio_config
  118. #define SD_CONFIG_CRASH g_sd_sdio_config_crash
  119. #endif
  120. #endif