ZuluSCSI_platform.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // Platform-specific definitions for ZuluSCSI RP2040 hardware.
  2. #pragma once
  3. #include <stdint.h>
  4. #include <Arduino.h>
  5. #include "ZuluSCSI_platform_gpio.h"
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. /* These are used in debug output and default SCSI strings */
  10. extern const char *g_azplatform_name;
  11. #define PLATFORM_NAME "ZuluSCSI RP2040"
  12. #define PLATFORM_REVISION "2.0"
  13. #define SD_USE_SDIO 1
  14. // Debug logging function, can be used to print to e.g. serial port.
  15. // May get called from interrupt handlers.
  16. void azplatform_log(const char *s);
  17. // Timing and delay functions.
  18. // Arduino platform already provides these
  19. unsigned long millis(void);
  20. void delay(unsigned long ms);
  21. // Short delays, can be called from interrupt mode
  22. static inline void delay_ns(unsigned long ns)
  23. {
  24. delayMicroseconds((ns + 999) / 1000);
  25. }
  26. // Approximate fast delay
  27. static inline void delay_100ns()
  28. {
  29. asm volatile ("nop \n nop \n nop \n nop \n nop");
  30. }
  31. // Initialize SD card and GPIO configuration
  32. void azplatform_init();
  33. // Initialization for main application, not used for bootloader
  34. void azplatform_late_init();
  35. // Setup soft watchdog if supported
  36. void azplatform_reset_watchdog();
  37. // Set callback that will be called during data transfer to/from SD card.
  38. // This can be used to implement simultaneous transfer to SCSI bus.
  39. typedef void (*sd_callback_t)(uint32_t bytes_complete);
  40. void azplatform_set_sd_callback(sd_callback_t func, const uint8_t *buffer);
  41. // Below are GPIO access definitions that are used from scsiPhy.cpp.
  42. // Write a single SCSI pin.
  43. // Example use: SCSI_OUT(ATN, 1) sets SCSI_ATN to low (active) state.
  44. #define SCSI_OUT(pin, state) \
  45. *(state ? &sio_hw->gpio_clr : &sio_hw->gpio_set) = 1 << (SCSI_OUT_ ## pin)
  46. // Read a single SCSI pin.
  47. // Example use: SCSI_IN(ATN), returns 1 for active low state.
  48. #define SCSI_IN(pin) \
  49. ((sio_hw->gpio_in & (1 << (SCSI_IN_ ## pin))) ? 0 : 1)
  50. // Enable driving of shared control pins
  51. #define SCSI_ENABLE_CONTROL_OUT() \
  52. (sio_hw->gpio_oe_set = (1 << SCSI_OUT_CD) | \
  53. (1 << SCSI_OUT_MSG))
  54. // Set SCSI data bus to output
  55. #define SCSI_ENABLE_DATA_OUT() \
  56. (sio_hw->gpio_clr = (1 << SCSI_DATA_DIR), \
  57. sio_hw->gpio_oe_set = SCSI_IO_DATA_MASK)
  58. // Write SCSI data bus, also sets REQ to inactive.
  59. extern const uint32_t g_scsi_parity_lookup[256];
  60. #define SCSI_OUT_DATA(data) \
  61. gpio_put_masked(SCSI_IO_DATA_MASK | (1 << SCSI_OUT_REQ), \
  62. g_scsi_parity_lookup[(uint8_t)(data)] | (1 << SCSI_OUT_REQ)), \
  63. SCSI_ENABLE_DATA_OUT()
  64. // Release SCSI data bus and REQ signal
  65. #define SCSI_RELEASE_DATA_REQ() \
  66. (sio_hw->gpio_oe_clr = SCSI_IO_DATA_MASK, \
  67. sio_hw->gpio_set = (1 << SCSI_DATA_DIR) | (1 << SCSI_OUT_REQ))
  68. // Release all SCSI outputs
  69. #define SCSI_RELEASE_OUTPUTS() \
  70. SCSI_RELEASE_DATA_REQ(), \
  71. sio_hw->gpio_oe_clr = (1 << SCSI_OUT_CD) | \
  72. (1 << SCSI_OUT_MSG), \
  73. sio_hw->gpio_set = (1 << SCSI_OUT_IO) | \
  74. (1 << SCSI_OUT_CD) | \
  75. (1 << SCSI_OUT_MSG) | \
  76. (1 << SCSI_OUT_RST) | \
  77. (1 << SCSI_OUT_BSY) | \
  78. (1 << SCSI_OUT_REQ) | \
  79. (1 << SCSI_OUT_SEL)
  80. // Read SCSI data bus
  81. #define SCSI_IN_DATA(data) \
  82. (~sio_hw->gpio_in & SCSI_IO_DATA_MASK) >> SCSI_IO_SHIFT
  83. #ifdef __cplusplus
  84. }
  85. // SD card driver for SdFat
  86. #ifdef SD_USE_SDIO
  87. class SdioConfig;
  88. extern SdioConfig g_sd_sdio_config;
  89. #define SD_CONFIG g_sd_sdio_config
  90. #define SD_CONFIG_CRASH g_sd_sdio_config
  91. #else
  92. class SdSpiConfig;
  93. extern SdSpiConfig g_sd_spi_config;
  94. #define SD_CONFIG g_sd_spi_config
  95. #define SD_CONFIG_CRASH g_sd_spi_config
  96. #endif
  97. #endif