AzulSCSI_platform.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Platform-specific definitions for AzulSCSI.
  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 "AzulSCSI_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_azplatform_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 azplatform_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 azplatform_init();
  36. // Initialization for main application, not used for bootloader
  37. void azplatform_late_init();
  38. // Setup soft watchdog if supported
  39. void azplatform_reset_watchdog();
  40. // Set callback that will be called during data transfer to/from SD card.
  41. // This can be used to implement simultaneous transfer to SCSI bus.
  42. typedef void (*sd_callback_t)(uint32_t bytes_complete);
  43. void azplatform_set_sd_callback(sd_callback_t func, const uint8_t *buffer);
  44. // Below are GPIO access definitions that are used from scsiPhy.cpp.
  45. // The definitions shown will work for STM32 style devices, other platforms
  46. // will need adaptations.
  47. // Write a single SCSI pin.
  48. // Example use: SCSI_OUT(ATN, 1) sets SCSI_ATN to low (active) state.
  49. #define SCSI_OUT(pin, state) \
  50. (SCSI_OUT_ ## pin ## _PORT)->BSRR = (SCSI_OUT_ ## pin ## _PIN) << (state ? 16 : 0)
  51. // Read a single SCSI pin.
  52. // Example use: SCSI_IN(ATN), returns 1 for active low state.
  53. #define SCSI_IN(pin) \
  54. (((SCSI_ ## pin ## _PORT)->IDR & (SCSI_ ## pin ## _PIN)) ? 0 : 1)
  55. // Write SCSI data bus, also sets REQ to inactive.
  56. extern const uint32_t g_scsi_out_byte_to_bop[256];
  57. #define SCSI_OUT_DATA(data) \
  58. (SCSI_OUT_PORT)->BSRR = g_scsi_out_byte_to_bop[(uint8_t)(data)]
  59. // Release SCSI data bus and REQ signal
  60. #define SCSI_RELEASE_DATA_REQ() \
  61. (SCSI_OUT_PORT)->BSRR = SCSI_OUT_DATA_MASK | SCSI_OUT_REQ
  62. // Release all SCSI outputs
  63. #define SCSI_RELEASE_OUTPUTS() \
  64. (SCSI_OUT_PORT)->BSRR = SCSI_OUT_DATA_MASK | SCSI_OUT_REQ, \
  65. (SCSI_OUT_IO_PORT)->BSRR = SCSI_OUT_IO_PIN, \
  66. (SCSI_OUT_CD_PORT)->BSRR = SCSI_OUT_CD_PIN, \
  67. (SCSI_OUT_SEL_PORT)->BSRR = SCSI_OUT_SEL_PIN, \
  68. (SCSI_OUT_MSG_PORT)->BSRR = SCSI_OUT_MSG_PIN, \
  69. (SCSI_OUT_RST_PORT)->BSRR = SCSI_OUT_RST_PIN, \
  70. (SCSI_OUT_BSY_PORT)->BSRR = SCSI_OUT_BSY_PIN
  71. // Read SCSI data bus
  72. #define SCSI_IN_DATA(data) \
  73. (((~(SCSI_IN_PORT->IDR)) & SCSI_IN_MASK) >> SCSI_IN_SHIFT)
  74. #ifdef __cplusplus
  75. }
  76. // SD card driver for SdFat
  77. class SdSpiConfig;
  78. extern SdSpiConfig g_sd_spi_config;
  79. #define SD_CONFIG g_sd_spi_config
  80. #define SD_CONFIG_CRASH g_sd_spi_config
  81. #endif