AzulSCSI_platform.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. #ifdef __cplusplus
  7. // SD card driver for SdFat
  8. class SdSpiConfig;
  9. extern SdSpiConfig g_sd_spi_config;
  10. #define SD_CONFIG g_sd_spi_config
  11. extern "C" {
  12. #endif
  13. // GPIO definitions
  14. // SCSI output port.
  15. // This is written using BSRR mechanism, so all output pins must be on same GPIO port.
  16. // The output pins are open-drain in hardware, using separate buffer chips for driving.
  17. #define SCSI_OUT_PORT GPIOD
  18. #define SCSI_OUT_DB7 GPIO_PIN_0
  19. #define SCSI_OUT_DB6 GPIO_PIN_1
  20. #define SCSI_OUT_DB5 GPIO_PIN_2
  21. #define SCSI_OUT_DB4 GPIO_PIN_3
  22. #define SCSI_OUT_DB3 GPIO_PIN_4
  23. #define SCSI_OUT_DB2 GPIO_PIN_5
  24. #define SCSI_OUT_DB1 GPIO_PIN_6
  25. #define SCSI_OUT_DB0 GPIO_PIN_7
  26. #define SCSI_OUT_IO GPIO_PIN_8
  27. #define SCSI_OUT_REQ GPIO_PIN_9
  28. #define SCSI_OUT_CD GPIO_PIN_10
  29. #define SCSI_OUT_SEL GPIO_PIN_11
  30. #define SCSI_OUT_MSG GPIO_PIN_12
  31. #define SCSI_OUT_RST GPIO_PIN_13
  32. #define SCSI_OUT_BSY GPIO_PIN_14
  33. #define SCSI_OUT_DBP GPIO_PIN_15
  34. #define SCSI_OUT_DATA_MASK (0x00FF | SCSI_OUT_DBP)
  35. #define SCSI_OUT_MASK 0xFFFF
  36. // SCSI input port
  37. #define SCSI_IN_PORT GPIOE
  38. #define SCSI_IN_DB7 GPIO_PIN_15
  39. #define SCSI_IN_DB6 GPIO_PIN_14
  40. #define SCSI_IN_DB5 GPIO_PIN_13
  41. #define SCSI_IN_DB4 GPIO_PIN_12
  42. #define SCSI_IN_DB3 GPIO_PIN_11
  43. #define SCSI_IN_DB2 GPIO_PIN_10
  44. #define SCSI_IN_DB1 GPIO_PIN_9
  45. #define SCSI_IN_DB0 GPIO_PIN_8
  46. #define SCSI_IN_DBP GPIO_PIN_7
  47. #define SCSI_IN_MASK (SCSI_IN_DB7|SCSI_IN_DB6|SCSI_IN_DB5|SCSI_IN_DB4|SCSI_IN_DB3|SCSI_IN_DB2|SCSI_IN_DB1|SCSI_IN_DB0|SCSI_IN_DBP)
  48. #define SCSI_IN_SHIFT 8
  49. // Various SCSI status signals
  50. #define SCSI_ATN_PORT GPIOB // FIXME: Change to 5V-tolerant pin
  51. #define SCSI_ATN_PIN GPIO_PIN_0
  52. #define SCSI_BSY_PORT GPIOB
  53. #define SCSI_BSY_PIN GPIO_PIN_10
  54. #define SCSI_SEL_PORT GPIOB
  55. #define SCSI_SEL_PIN GPIO_PIN_11
  56. #define SCSI_ACK_PORT GPIOB
  57. #define SCSI_ACK_PIN GPIO_PIN_12
  58. // RST pin uses EXTI interrupt
  59. #define SCSI_RST_PORT GPIOB
  60. #define SCSI_RST_PIN GPIO_PIN_13
  61. #define SCSI_RST_EXTI EXTI_13
  62. #define SCSI_RST_EXTI_SOURCE_PORT GPIO_PORT_SOURCE_GPIOB
  63. #define SCSI_RST_EXTI_SOURCE_PIN GPIO_PIN_SOURCE_13
  64. #define SCSI_RST_IRQ EXTI10_15_IRQHandler
  65. #define SCSI_RST_IRQn EXTI10_15_IRQn
  66. // Terminator enable/disable config, active low
  67. #define SCSI_TERM_EN_PORT GPIOC
  68. #define SCSI_TERM_EN_PIN GPIO_PIN_8
  69. // SD card pins
  70. #define SD_PORT GPIOA
  71. #define SD_CS_PIN GPIO_PIN_4
  72. #define SD_CLK_PIN GPIO_PIN_5
  73. #define SD_MISO_PIN GPIO_PIN_6
  74. #define SD_MOSI_PIN GPIO_PIN_7
  75. // DIP switches
  76. #define DIP_PORT GPIOB
  77. #define DIPSW1_PIN GPIO_PIN_4
  78. #define DIPSW2_PIN GPIO_PIN_5
  79. #define DIPSW3_PIN GPIO_PIN_6
  80. // Status LED pins
  81. #define LED_PORT GPIOC
  82. #define LED_I_PIN GPIO_PIN_4
  83. #define LED_E_PIN GPIO_PIN_5
  84. #define LED_PINS (LED_I_PIN | LED_E_PIN)
  85. #define LED_ON() gpio_bit_reset(LED_PORT, LED_PINS)
  86. #define LED_OFF() gpio_bit_set(LED_PORT, LED_PINS)
  87. // Debug logging functions
  88. void azplatform_log(const char *s);
  89. // Minimal millis() implementation as GD32F205 does not
  90. // have an Arduino core yet.
  91. unsigned long millis();
  92. void delay(unsigned long ms);
  93. // Precise nanosecond delays
  94. static inline void delay_100ns()
  95. {
  96. asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop");
  97. }
  98. // Initialize SPI and GPIO configuration
  99. void azplatform_init();
  100. // Set callback for when SCSI_RST pin goes low
  101. void azplatform_set_rst_callback(void (*callback)());
  102. // Write a single SCSI pin.
  103. // Example use: SCSI_OUT(ATN, 1) sets SCSI_ATN to low (active) state.
  104. #define SCSI_OUT(pin, state) \
  105. GPIO_BOP(SCSI_OUT_PORT) = (SCSI_OUT_ ## pin) << (state ? 16 : 0)
  106. // Read a single SCSI pin.
  107. // Example use: SCSI_IN(ATN), returns 1 for active low state.
  108. #define SCSI_IN(pin) \
  109. ((GPIO_ISTAT(SCSI_ ## pin ## _PORT) & (SCSI_ ## pin ## _PIN)) ? 0 : 1)
  110. // Write SCSI data bus
  111. extern const uint32_t g_scsi_out_byte_to_bop[256];
  112. #define SCSI_OUT_DATA(data) \
  113. GPIO_BOP(SCSI_OUT_PORT) = g_scsi_out_byte_to_bop[(uint8_t)(data)]
  114. // Release SCSI data bus
  115. #define SCSI_RELEASE_DATA() \
  116. GPIO_BOP(SCSI_OUT_PORT) = SCSI_OUT_DATA_MASK
  117. // Release all SCSI outputs
  118. #define SCSI_RELEASE_OUTPUTS() \
  119. GPIO_BOP(SCSI_OUT_PORT) = SCSI_OUT_MASK
  120. // Read SCSI data bus
  121. #define SCSI_IN_DATA(data) \
  122. (((~GPIO_ISTAT(SCSI_IN_PORT)) & SCSI_IN_MASK) >> SCSI_IN_SHIFT)
  123. #ifdef __cplusplus
  124. }
  125. #endif