ZuluSCSI_platform.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. #include "ZuluSCSI_config.h"
  26. #include "ZuluSCSI_platform_network.h"
  27. #ifdef ZULUSCSI_PICO
  28. // ZuluSCSI Pico carrier board variant
  29. #include "ZuluSCSI_platform_gpio_Pico.h"
  30. #elif defined(ZULUSCSI_PICO_2)
  31. // ZuluSCSI Pico 2 carrier board variant
  32. #include "ZuluSCSI_platform_gpio_Pico_2.h"
  33. #elif defined(ZULUSCSI_BS2)
  34. // BS2 hardware variant, using Raspberry Pico board on a carrier PCB
  35. #include "ZuluSCSI_platform_gpio_BS2.h"
  36. #elif defined(ZULUSCSI_RP2350A)
  37. // RP2350A variant, using mcu chip directly
  38. #include "ZuluSCSI_platform_gpio_RP2350A.h"
  39. #else
  40. // Normal RP2040 variant, using RP2040 chip directly
  41. #include "ZuluSCSI_platform_gpio_RP2040.h"
  42. #endif
  43. #include "scsiHostPhy.h"
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. /* These are used in debug output and default SCSI strings */
  48. extern const char *g_platform_name;
  49. // NOTE: The driver supports synchronous speeds higher than 10MB/s, but this
  50. // has not been tested due to lack of fast enough SCSI adapter.
  51. // #define PLATFORM_MAX_SCSI_SPEED S2S_CFG_SPEED_SYNC_20
  52. // Debug logging function, can be used to print to e.g. serial port.
  53. // May get called from interrupt handlers.
  54. void platform_log(const char *s);
  55. void platform_emergency_log_save();
  56. // Timing and delay functions.
  57. // Arduino platform already provides these
  58. unsigned long millis(void);
  59. void delay(unsigned long ms);
  60. // Short delays, can be called from interrupt mode
  61. static inline void delay_ns(unsigned long ns)
  62. {
  63. delayMicroseconds((ns + 999) / 1000);
  64. }
  65. // Approximate fast delay
  66. static inline void delay_100ns()
  67. {
  68. asm volatile ("nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop");
  69. }
  70. // Initialize SD card and GPIO configuration
  71. void platform_init();
  72. // Initialization for main application, not used for bootloader
  73. void platform_late_init();
  74. // Initialization after the SD Card has been found
  75. void platform_post_sd_card_init();
  76. // Disable the status LED
  77. void platform_disable_led(void);
  78. // Query whether initiator mode is enabled on targets with PLATFORM_HAS_INITIATOR_MODE
  79. bool platform_is_initiator_mode_enabled();
  80. // Setup soft watchdog if supported
  81. void platform_reset_watchdog();
  82. // Poll function that is called every few milliseconds.
  83. // The SD card is free to access during this time, and pauses up to
  84. // few milliseconds shouldn't disturb SCSI communication.
  85. void platform_poll();
  86. // Returns the state of any platform-specific buttons.
  87. // The returned value should be a mask for buttons 1-8 in bits 0-7 respectively,
  88. // where '1' is a button pressed and '0' is a button released.
  89. // Debouncing logic is left up to the specific implementation.
  90. // This function should return without significantly delay.
  91. uint8_t platform_get_buttons();
  92. uint32_t platform_sys_clock_in_hz();
  93. // Attempt to reclock the MCU
  94. zuluscsi_reclock_status_t platform_reclock(uint32_t clk_in_khz);
  95. // Set callback that will be called during data transfer to/from SD card.
  96. // This can be used to implement simultaneous transfer to SCSI bus.
  97. typedef void (*sd_callback_t)(uint32_t bytes_complete);
  98. void platform_set_sd_callback(sd_callback_t func, const uint8_t *buffer);
  99. // Reprogram firmware in main program area.
  100. #ifndef RP2040_DISABLE_BOOTLOADER
  101. #define PLATFORM_BOOTLOADER_SIZE (128 * 1024)
  102. #define PLATFORM_FLASH_TOTAL_SIZE (1024 * 1024)
  103. #define PLATFORM_FLASH_PAGE_SIZE 4096
  104. bool platform_rewrite_flash_page(uint32_t offset, uint8_t buffer[PLATFORM_FLASH_PAGE_SIZE]);
  105. void platform_boot_to_main_firmware();
  106. #endif
  107. // ROM drive in the unused external flash area
  108. #ifndef RP2040_DISABLE_ROMDRIVE
  109. #define PLATFORM_HAS_ROM_DRIVE 1
  110. // Check maximum available space for ROM drive in bytes
  111. uint32_t platform_get_romdrive_maxsize();
  112. // Read ROM drive area
  113. bool platform_read_romdrive(uint8_t *dest, uint32_t start, uint32_t count);
  114. // Reprogram ROM drive area
  115. #define PLATFORM_ROMDRIVE_PAGE_SIZE 4096
  116. bool platform_write_romdrive(const uint8_t *data, uint32_t start, uint32_t count);
  117. #endif
  118. // Parity lookup tables for write and read from SCSI bus.
  119. // These are used by macros below and the code in scsi_accel_rp2040.cpp
  120. extern const uint16_t g_scsi_parity_lookup[256];
  121. extern const uint16_t g_scsi_parity_check_lookup[512];
  122. #ifdef __cplusplus
  123. }
  124. // SD card driver for SdFat
  125. #ifdef SD_USE_SDIO
  126. class SdioConfig;
  127. extern SdioConfig g_sd_sdio_config;
  128. #define SD_CONFIG g_sd_sdio_config
  129. #define SD_CONFIG_CRASH g_sd_sdio_config
  130. #else
  131. class SdSpiConfig;
  132. extern SdSpiConfig g_sd_spi_config;
  133. #define SD_CONFIG g_sd_spi_config
  134. #define SD_CONFIG_CRASH g_sd_spi_config
  135. #endif
  136. #endif