ZuluSCSI_platform.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /**
  2. * ZuluSCSI™ - Copyright (c) 2022 Rabbit Hole Computing™
  3. *
  4. * ZuluSCSI™ firmware is licensed under the GPL version 3 or any later version. 
  5. *
  6. * https://www.gnu.org/licenses/gpl-3.0.html
  7. * ----
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version. 
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. * GNU General Public License for more details. 
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  20. **/
  21. // Platform-specific definitions for ZuluSCSI RP2040 hardware.
  22. #pragma once
  23. #include <stdint.h>
  24. #include <Arduino.h>
  25. #ifdef ZULUSCSI_PICO
  26. // ZuluSCSI Pico carrier board variant
  27. #include "ZuluSCSI_platform_gpio_Pico.h"
  28. #elif defined(ZULUSCSI_BS2)
  29. // BS2 hardware variant, using Raspberry Pico board on a carrier PCB
  30. #include "ZuluSCSI_platform_gpio_BS2.h"
  31. #else
  32. // Normal RP2040 variant, using RP2040 chip directly
  33. #include "ZuluSCSI_platform_gpio_RP2040.h"
  34. #endif
  35. #include "scsiHostPhy.h"
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. /* These are used in debug output and default SCSI strings */
  40. extern const char *g_platform_name;
  41. #ifdef ZULUSCSI_PICO
  42. # ifdef ZULUSCSI_DAYNAPORT
  43. # define PLATFORM_NAME "ZuluSCSI Pico DaynaPORT"
  44. # else
  45. # define PLATFORM_NAME "ZuluSCSI Pico"
  46. # endif
  47. # define PLATFORM_REVISION "2.0"
  48. # define PLATFORM_HAS_INITIATOR_MODE 1
  49. # define DISABLE_SWO
  50. #elif defined(ZULUSCSI_BS2)
  51. # define PLATFORM_NAME "ZuluSCSI BS2"
  52. # define PLATFORM_REVISION "1.0"
  53. #else
  54. # define PLATFORM_NAME "ZuluSCSI RP2040"
  55. # define PLATFORM_REVISION "2.0"
  56. # define PLATFORM_HAS_INITIATOR_MODE 1
  57. #endif
  58. #define PLATFORM_MAX_SCSI_SPEED S2S_CFG_SPEED_SYNC_10
  59. #define PLATFORM_OPTIMAL_MIN_SD_WRITE_SIZE 32768
  60. #define PLATFORM_OPTIMAL_MAX_SD_WRITE_SIZE 65536
  61. #define PLATFORM_OPTIMAL_LAST_SD_WRITE_SIZE 8192
  62. #define SD_USE_SDIO 1
  63. #define PLATFORM_HAS_PARITY_CHECK 1
  64. #ifndef PLATFORM_VDD_WARNING_LIMIT_mV
  65. #define PLATFORM_VDD_WARNING_LIMIT_mV 2800
  66. #endif
  67. // NOTE: The driver supports synchronous speeds higher than 10MB/s, but this
  68. // has not been tested due to lack of fast enough SCSI adapter.
  69. // #define PLATFORM_MAX_SCSI_SPEED S2S_CFG_SPEED_TURBO
  70. // Debug logging function, can be used to print to e.g. serial port.
  71. // May get called from interrupt handlers.
  72. void platform_log(const char *s);
  73. void platform_emergency_log_save();
  74. // Timing and delay functions.
  75. // Arduino platform already provides these
  76. unsigned long millis(void);
  77. void delay(unsigned long ms);
  78. // Short delays, can be called from interrupt mode
  79. static inline void delay_ns(unsigned long ns)
  80. {
  81. delayMicroseconds((ns + 999) / 1000);
  82. }
  83. // Approximate fast delay
  84. static inline void delay_100ns()
  85. {
  86. asm volatile ("nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop");
  87. }
  88. // Initialize SD card and GPIO configuration
  89. void platform_init();
  90. // Initialization for main application, not used for bootloader
  91. void platform_late_init();
  92. // Disable the status LED
  93. void platform_disable_led(void);
  94. // Query whether initiator mode is enabled on targets with PLATFORM_HAS_INITIATOR_MODE
  95. bool platform_is_initiator_mode_enabled();
  96. // Setup soft watchdog if supported
  97. void platform_reset_watchdog();
  98. // Poll function that is called every few milliseconds.
  99. // The SD card is free to access during this time, and pauses up to
  100. // few milliseconds shouldn't disturb SCSI communication.
  101. void platform_poll();
  102. // Returns the state of any platform-specific buttons.
  103. // The returned value should be a mask for buttons 1-8 in bits 0-7 respectively,
  104. // where '1' is a button pressed and '0' is a button released.
  105. // Debouncing logic is left up to the specific implementation.
  106. // This function should return without significantly delay.
  107. uint8_t platform_get_buttons();
  108. // Set callback that will be called during data transfer to/from SD card.
  109. // This can be used to implement simultaneous transfer to SCSI bus.
  110. typedef void (*sd_callback_t)(uint32_t bytes_complete);
  111. void platform_set_sd_callback(sd_callback_t func, const uint8_t *buffer);
  112. // Reprogram firmware in main program area.
  113. #ifndef RP2040_DISABLE_BOOTLOADER
  114. #define PLATFORM_BOOTLOADER_SIZE (128 * 1024)
  115. #define PLATFORM_FLASH_TOTAL_SIZE (1024 * 1024)
  116. #define PLATFORM_FLASH_PAGE_SIZE 4096
  117. bool platform_rewrite_flash_page(uint32_t offset, uint8_t buffer[PLATFORM_FLASH_PAGE_SIZE]);
  118. void platform_boot_to_main_firmware();
  119. #endif
  120. // ROM drive in the unused external flash area
  121. #ifndef RP2040_DISABLE_ROMDRIVE
  122. #define PLATFORM_HAS_ROM_DRIVE 1
  123. // Check maximum available space for ROM drive in bytes
  124. uint32_t platform_get_romdrive_maxsize();
  125. // Read ROM drive area
  126. bool platform_read_romdrive(uint8_t *dest, uint32_t start, uint32_t count);
  127. // Reprogram ROM drive area
  128. #define PLATFORM_ROMDRIVE_PAGE_SIZE 4096
  129. bool platform_write_romdrive(const uint8_t *data, uint32_t start, uint32_t count);
  130. #endif
  131. // Parity lookup tables for write and read from SCSI bus.
  132. // These are used by macros below and the code in scsi_accel_rp2040.cpp
  133. extern const uint16_t g_scsi_parity_lookup[256];
  134. extern const uint16_t g_scsi_parity_check_lookup[512];
  135. // Network functions
  136. bool platform_network_supported();
  137. void platform_network_poll();
  138. int platform_network_init(char *mac);
  139. void platform_network_add_multicast_address(uint8_t *mac);
  140. bool platform_network_wifi_join(char *ssid, char *password);
  141. int platform_network_wifi_start_scan();
  142. int platform_network_wifi_scan_finished();
  143. void platform_network_wifi_dump_scan_list();
  144. int platform_network_wifi_rssi();
  145. char * platform_network_wifi_ssid();
  146. char * platform_network_wifi_bssid();
  147. int platform_network_wifi_channel();
  148. #ifdef __cplusplus
  149. }
  150. // SD card driver for SdFat
  151. #ifdef SD_USE_SDIO
  152. class SdioConfig;
  153. extern SdioConfig g_sd_sdio_config;
  154. #define SD_CONFIG g_sd_sdio_config
  155. #define SD_CONFIG_CRASH g_sd_sdio_config
  156. #else
  157. class SdSpiConfig;
  158. extern SdSpiConfig g_sd_spi_config;
  159. #define SD_CONFIG g_sd_spi_config
  160. #define SD_CONFIG_CRASH g_sd_spi_config
  161. #endif
  162. #endif