ZuluSCSI_platform.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.
  22. //
  23. // This file is example platform definition that can easily be
  24. // customized for a different board / CPU.
  25. #pragma once
  26. /* Add any platform-specific includes you need here */
  27. #include <stdint.h>
  28. #include <Arduino.h>
  29. #include "ZuluSCSI_platform_gpio.h"
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /* These are used in debug output and default SCSI strings */
  34. extern const char *g_platform_name;
  35. #define PLATFORM_NAME "Example"
  36. #define PLATFORM_REVISION "1.0"
  37. // Debug logging function, can be used to print to e.g. serial port.
  38. // May get called from interrupt handlers.
  39. void platform_log(const char *s);
  40. // Timing and delay functions.
  41. // Arduino platform already provides these
  42. unsigned long millis(void);
  43. void delay(unsigned long ms);
  44. // Short delays, can be called from interrupt mode
  45. static inline void delay_ns(unsigned long ns)
  46. {
  47. delayMicroseconds(ns / 1000);
  48. }
  49. // Approximate fast delay
  50. static inline void delay_100ns()
  51. {
  52. asm volatile ("nop \n nop \n nop \n nop \n nop");
  53. }
  54. // Initialize SD card and GPIO configuration
  55. void platform_init();
  56. // Initialization for main application, not used for bootloader
  57. void platform_late_init();
  58. // Disable the status LED
  59. void platform_disable_led(void);
  60. // Setup soft watchdog if supported
  61. void platform_reset_watchdog();
  62. // Poll function that is called every few milliseconds.
  63. // The SD card is free to access during this time, and pauses up to
  64. // few milliseconds shouldn't disturb SCSI communication.
  65. void platform_poll();
  66. // Set callback that will be called during data transfer to/from SD card.
  67. // This can be used to implement simultaneous transfer to SCSI bus.
  68. typedef void (*sd_callback_t)(uint32_t bytes_complete);
  69. void platform_set_sd_callback(sd_callback_t func, const uint8_t *buffer);
  70. // Below are GPIO access definitions that are used from scsiPhy.cpp.
  71. // The definitions shown will work for STM32 style devices, other platforms
  72. // will need adaptations.
  73. // Write a single SCSI pin.
  74. // Example use: SCSI_OUT(ATN, 1) sets SCSI_ATN to low (active) state.
  75. #define SCSI_OUT(pin, state) \
  76. (SCSI_OUT_ ## pin ## _PORT)->BSRR = (SCSI_OUT_ ## pin ## _PIN) << (state ? 16 : 0)
  77. // Read a single SCSI pin.
  78. // Example use: SCSI_IN(ATN), returns 1 for active low state.
  79. #define SCSI_IN(pin) \
  80. (((SCSI_ ## pin ## _PORT)->IDR & (SCSI_ ## pin ## _PIN)) ? 0 : 1)
  81. // Write SCSI data bus, also sets REQ to inactive.
  82. extern const uint32_t g_scsi_out_byte_to_bop[256];
  83. #define SCSI_OUT_DATA(data) \
  84. (SCSI_OUT_PORT)->BSRR = g_scsi_out_byte_to_bop[(uint8_t)(data)]
  85. // Release SCSI data bus and REQ signal
  86. #define SCSI_RELEASE_DATA_REQ() \
  87. (SCSI_OUT_PORT)->BSRR = SCSI_OUT_DATA_MASK | SCSI_OUT_REQ
  88. // Release all SCSI outputs
  89. #define SCSI_RELEASE_OUTPUTS() \
  90. (SCSI_OUT_PORT)->BSRR = SCSI_OUT_DATA_MASK | SCSI_OUT_REQ, \
  91. (SCSI_OUT_IO_PORT)->BSRR = SCSI_OUT_IO_PIN, \
  92. (SCSI_OUT_CD_PORT)->BSRR = SCSI_OUT_CD_PIN, \
  93. (SCSI_OUT_SEL_PORT)->BSRR = SCSI_OUT_SEL_PIN, \
  94. (SCSI_OUT_MSG_PORT)->BSRR = SCSI_OUT_MSG_PIN, \
  95. (SCSI_OUT_RST_PORT)->BSRR = SCSI_OUT_RST_PIN, \
  96. (SCSI_OUT_BSY_PORT)->BSRR = SCSI_OUT_BSY_PIN
  97. // Read SCSI data bus
  98. #define SCSI_IN_DATA(data) \
  99. (((~(SCSI_IN_PORT->IDR)) & SCSI_IN_MASK) >> SCSI_IN_SHIFT)
  100. #ifdef __cplusplus
  101. }
  102. // SD card driver for SdFat
  103. class SdSpiConfig;
  104. extern SdSpiConfig g_sd_spi_config;
  105. #define SD_CONFIG g_sd_spi_config
  106. #define SD_CONFIG_CRASH g_sd_spi_config
  107. #endif