ZuluSCSI_platform.h 3.4 KB

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