BlueSCSI_platform.h 3.4 KB

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