AzulSCSI_platform.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 "AzulSCSI_config.h"
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. extern const char *g_azplatform_name;
  11. #if defined(AZULSCSI_V1_0)
  12. # define PLATFORM_NAME "AzulSCSI v1.0"
  13. # define PLATFORM_MAX_SCSI_SPEED S2S_CFG_SPEED_ASYNC_50
  14. # include "AzulSCSI_v1_0_gpio.h"
  15. #elif defined(AZULSCSI_V1_1)
  16. # define PLATFORM_NAME "AzulSCSI v1.1"
  17. # define PLATFORM_MAX_SCSI_SPEED S2S_CFG_SPEED_ASYNC_50
  18. # include "AzulSCSI_v1_1_gpio.h"
  19. #endif
  20. // Debug logging functions
  21. void azplatform_log(const char *s);
  22. // Minimal millis() implementation as GD32F205 does not
  23. // have an Arduino core yet.
  24. unsigned long millis(void);
  25. void delay(unsigned long ms);
  26. // Precise nanosecond delays
  27. // Works in interrupt context also, max delay 500 000 ns, min delay about 500 ns
  28. void delay_ns(unsigned long ns);
  29. static inline void delay_us(unsigned long us)
  30. {
  31. if (us > 0)
  32. {
  33. delay_ns(us * 1000);
  34. }
  35. }
  36. // Approximate fast delay
  37. static inline void delay_100ns()
  38. {
  39. asm volatile ("nop \n nop \n nop \n nop \n nop");
  40. }
  41. // Initialize SPI and GPIO configuration
  42. void azplatform_init();
  43. // Setup soft watchdog
  44. void azplatform_reset_watchdog(int timeout_ms);
  45. // Reinitialize SD card connection and save log from interrupt context.
  46. // This can be used in crash handlers.
  47. void azplatform_emergency_log_save();
  48. // Set callback that will be called during data transfer to/from SD card.
  49. // This can be used to implement simultaneous transfer to SCSI bus.
  50. typedef void (*sd_callback_t)(uint32_t bytes_complete);
  51. void azplatform_set_sd_callback(sd_callback_t func, const uint8_t *buffer);
  52. // Write a single SCSI pin.
  53. // Example use: SCSI_OUT(ATN, 1) sets SCSI_ATN to low (active) state.
  54. #define SCSI_OUT(pin, state) \
  55. GPIO_BOP(SCSI_OUT_ ## pin ## _PORT) = (SCSI_OUT_ ## pin ## _PIN) << (state ? 16 : 0)
  56. // Read a single SCSI pin.
  57. // Example use: SCSI_IN(ATN), returns 1 for active low state.
  58. #define SCSI_IN(pin) \
  59. ((GPIO_ISTAT(SCSI_ ## pin ## _PORT) & (SCSI_ ## pin ## _PIN)) ? 0 : 1)
  60. // Write SCSI data bus, also sets REQ to inactive.
  61. extern const uint32_t g_scsi_out_byte_to_bop[256];
  62. #define SCSI_OUT_DATA(data) \
  63. GPIO_BOP(SCSI_OUT_PORT) = g_scsi_out_byte_to_bop[(uint8_t)(data)]
  64. // Release SCSI data bus and REQ signal
  65. #define SCSI_RELEASE_DATA_REQ() \
  66. GPIO_BOP(SCSI_OUT_PORT) = SCSI_OUT_DATA_MASK | SCSI_OUT_REQ
  67. // Release all SCSI outputs
  68. #define SCSI_RELEASE_OUTPUTS() \
  69. GPIO_BOP(SCSI_OUT_PORT) = SCSI_OUT_DATA_MASK | SCSI_OUT_REQ, \
  70. GPIO_BOP(SCSI_OUT_IO_PORT) = SCSI_OUT_IO_PIN, \
  71. GPIO_BOP(SCSI_OUT_CD_PORT) = SCSI_OUT_CD_PIN, \
  72. GPIO_BOP(SCSI_OUT_SEL_PORT) = SCSI_OUT_SEL_PIN, \
  73. GPIO_BOP(SCSI_OUT_MSG_PORT) = SCSI_OUT_MSG_PIN, \
  74. GPIO_BOP(SCSI_OUT_RST_PORT) = SCSI_OUT_RST_PIN, \
  75. GPIO_BOP(SCSI_OUT_BSY_PORT) = SCSI_OUT_BSY_PIN
  76. // Read SCSI data bus
  77. #define SCSI_IN_DATA(data) \
  78. (((~GPIO_ISTAT(SCSI_IN_PORT)) & SCSI_IN_MASK) >> SCSI_IN_SHIFT)
  79. #ifdef __cplusplus
  80. }
  81. // SD card driver for SdFat
  82. #ifndef SD_USE_SDIO
  83. // SPI interface, AzulSCSI v1.0
  84. class SdSpiConfig;
  85. extern SdSpiConfig g_sd_spi_config;
  86. #define SD_CONFIG g_sd_spi_config
  87. #else
  88. // SDIO interface, AzulSCSI v1.1
  89. class SdioConfig;
  90. extern SdioConfig g_sd_sdio_config;
  91. #define SD_CONFIG g_sd_sdio_config
  92. #endif
  93. #endif