BlueSCSI_platform.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. // Returns the state of any platform-specific buttons.
  47. // The returned value should be a mask for buttons 1-8 in bits 0-7 respectively,
  48. // where '1' is a button pressed and '0' is a button released.
  49. // Debouncing logic is left up to the specific implementation.
  50. // This function should return without significantly delay.
  51. uint8_t platform_get_buttons();
  52. // Set callback that will be called during data transfer to/from SD card.
  53. // This can be used to implement simultaneous transfer to SCSI bus.
  54. typedef void (*sd_callback_t)(uint32_t bytes_complete);
  55. void platform_set_sd_callback(sd_callback_t func, const uint8_t *buffer);
  56. // Below are GPIO access definitions that are used from scsiPhy.cpp.
  57. // The definitions shown will work for STM32 style devices, other platforms
  58. // will need adaptations.
  59. // Write a single SCSI pin.
  60. // Example use: SCSI_OUT(ATN, 1) sets SCSI_ATN to low (active) state.
  61. #define SCSI_OUT(pin, state) \
  62. (SCSI_OUT_ ## pin ## _PORT)->BSRR = (SCSI_OUT_ ## pin ## _PIN) << (state ? 16 : 0)
  63. // Read a single SCSI pin.
  64. // Example use: SCSI_IN(ATN), returns 1 for active low state.
  65. #define SCSI_IN(pin) \
  66. (((SCSI_ ## pin ## _PORT)->IDR & (SCSI_ ## pin ## _PIN)) ? 0 : 1)
  67. // Write SCSI data bus, also sets REQ to inactive.
  68. extern const uint32_t g_scsi_out_byte_to_bop[256];
  69. #define SCSI_OUT_DATA(data) \
  70. (SCSI_OUT_PORT)->BSRR = g_scsi_out_byte_to_bop[(uint8_t)(data)]
  71. // Release SCSI data bus and REQ signal
  72. #define SCSI_RELEASE_DATA_REQ() \
  73. (SCSI_OUT_PORT)->BSRR = SCSI_OUT_DATA_MASK | SCSI_OUT_REQ
  74. // Release all SCSI outputs
  75. #define SCSI_RELEASE_OUTPUTS() \
  76. (SCSI_OUT_PORT)->BSRR = SCSI_OUT_DATA_MASK | SCSI_OUT_REQ, \
  77. (SCSI_OUT_IO_PORT)->BSRR = SCSI_OUT_IO_PIN, \
  78. (SCSI_OUT_CD_PORT)->BSRR = SCSI_OUT_CD_PIN, \
  79. (SCSI_OUT_SEL_PORT)->BSRR = SCSI_OUT_SEL_PIN, \
  80. (SCSI_OUT_MSG_PORT)->BSRR = SCSI_OUT_MSG_PIN, \
  81. (SCSI_OUT_RST_PORT)->BSRR = SCSI_OUT_RST_PIN, \
  82. (SCSI_OUT_BSY_PORT)->BSRR = SCSI_OUT_BSY_PIN
  83. // Read SCSI data bus
  84. #define SCSI_IN_DATA(data) \
  85. (((~(SCSI_IN_PORT->IDR)) & SCSI_IN_MASK) >> SCSI_IN_SHIFT)
  86. #ifdef __cplusplus
  87. }
  88. // SD card driver for SdFat
  89. class SdSpiConfig;
  90. extern SdSpiConfig g_sd_spi_config;
  91. #define SD_CONFIG g_sd_spi_config
  92. #define SD_CONFIG_CRASH g_sd_spi_config
  93. #endif