ZuluSCSI_platform.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. // Initialization after the SD Card has been found
  59. void platform_post_sd_card_init();
  60. // Disable the status LED
  61. void platform_disable_led(void);
  62. // Setup soft watchdog if supported
  63. void platform_reset_watchdog();
  64. // Poll function that is called every few milliseconds.
  65. // The SD card is free to access during this time, and pauses up to
  66. // few milliseconds shouldn't disturb SCSI communication.
  67. void platform_poll();
  68. // Returns the state of any platform-specific buttons.
  69. // The returned value should be a mask for buttons 1-8 in bits 0-7 respectively,
  70. // where '1' is a button pressed and '0' is a button released.
  71. // Debouncing logic is left up to the specific implementation.
  72. // This function should return without significantly delay.
  73. uint8_t platform_get_buttons();
  74. // Set callback that will be called during data transfer to/from SD card.
  75. // This can be used to implement simultaneous transfer to SCSI bus.
  76. typedef void (*sd_callback_t)(uint32_t bytes_complete);
  77. void platform_set_sd_callback(sd_callback_t func, const uint8_t *buffer);
  78. // Below are GPIO access definitions that are used from scsiPhy.cpp.
  79. // The definitions shown will work for STM32 style devices, other platforms
  80. // will need adaptations.
  81. // Write a single SCSI pin.
  82. // Example use: SCSI_OUT(ATN, 1) sets SCSI_ATN to low (active) state.
  83. #define SCSI_OUT(pin, state) \
  84. (SCSI_OUT_ ## pin ## _PORT)->BSRR = (SCSI_OUT_ ## pin ## _PIN) << (state ? 16 : 0)
  85. // Read a single SCSI pin.
  86. // Example use: SCSI_IN(ATN), returns 1 for active low state.
  87. #define SCSI_IN(pin) \
  88. (((SCSI_ ## pin ## _PORT)->IDR & (SCSI_ ## pin ## _PIN)) ? 0 : 1)
  89. // Write SCSI data bus, also sets REQ to inactive.
  90. extern const uint32_t g_scsi_out_byte_to_bop[256];
  91. #define SCSI_OUT_DATA(data) \
  92. (SCSI_OUT_PORT)->BSRR = g_scsi_out_byte_to_bop[(uint8_t)(data)]
  93. // Release SCSI data bus and REQ signal
  94. #define SCSI_RELEASE_DATA_REQ() \
  95. (SCSI_OUT_PORT)->BSRR = SCSI_OUT_DATA_MASK | SCSI_OUT_REQ
  96. // Release all SCSI outputs
  97. #define SCSI_RELEASE_OUTPUTS() \
  98. (SCSI_OUT_PORT)->BSRR = SCSI_OUT_DATA_MASK | SCSI_OUT_REQ, \
  99. (SCSI_OUT_IO_PORT)->BSRR = SCSI_OUT_IO_PIN, \
  100. (SCSI_OUT_CD_PORT)->BSRR = SCSI_OUT_CD_PIN, \
  101. (SCSI_OUT_SEL_PORT)->BSRR = SCSI_OUT_SEL_PIN, \
  102. (SCSI_OUT_MSG_PORT)->BSRR = SCSI_OUT_MSG_PIN, \
  103. (SCSI_OUT_RST_PORT)->BSRR = SCSI_OUT_RST_PIN, \
  104. (SCSI_OUT_BSY_PORT)->BSRR = SCSI_OUT_BSY_PIN
  105. // Read SCSI data bus
  106. #define SCSI_IN_DATA(data) \
  107. (((~(SCSI_IN_PORT->IDR)) & SCSI_IN_MASK) >> SCSI_IN_SHIFT)
  108. #ifdef __cplusplus
  109. }
  110. // SD card driver for SdFat
  111. class SdSpiConfig;
  112. extern SdSpiConfig g_sd_spi_config;
  113. #define SD_CONFIG g_sd_spi_config
  114. #define SD_CONFIG_CRASH g_sd_spi_config
  115. #endif