scsiPhy.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * SCSI2SD V6 - Copyright (C) 2013 Michael McMaster <michael@codesrc.com>
  3. * ZuluSCSI™ - Copyright (c) 2022-2025 Rabbit Hole Computing™
  4. *
  5. * This file is licensed under the GPL version 3 or any later version.  
  6. * It is derived from scsiPhy.h in SCSI2SD V6.
  7. *
  8. * https://www.gnu.org/licenses/gpl-3.0.html
  9. * ----
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version. 
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. * GNU General Public License for more details. 
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  22. **/
  23. // Interface to SCSI physical interface.
  24. // This file is derived from scsiPhy.h in SCSI2SD-V6.
  25. #pragma once
  26. #include <stdint.h>
  27. #include <stdbool.h>
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. // Read SCSI status signals
  32. bool scsiStatusATN();
  33. bool scsiStatusBSY();
  34. bool scsiStatusSEL();
  35. // Parity not yet implemented
  36. #define scsiParityError() 0
  37. // Get SCSI selection status.
  38. // This is latched by interrupt when BSY is deasserted while SEL is asserted.
  39. // Lowest 3 bits are the selected target id.
  40. // Highest bits are status information.
  41. #define SCSI_STS_SELECTION_SUCCEEDED 0x40
  42. #define SCSI_STS_SELECTION_ATN 0x80
  43. extern volatile uint8_t g_scsi_sts_selection;
  44. #define SCSI_STS_SELECTED (&g_scsi_sts_selection)
  45. extern volatile uint8_t g_scsi_ctrl_bsy;
  46. #define SCSI_CTRL_BSY (&g_scsi_ctrl_bsy)
  47. // Called when SCSI RST signal has been asserted, should release bus.
  48. void scsiPhyReset(void);
  49. // Change MSG / CD / IO signal states and wait for necessary transition time.
  50. // Phase argument is one of SCSI_PHASE enum values.
  51. void scsiEnterPhase(int phase);
  52. // Change state and return nanosecond delay to wait
  53. uint32_t scsiEnterPhaseImmediate(int phase);
  54. // Release all signals
  55. void scsiEnterBusFree(void);
  56. // Blocking data transfer
  57. void scsiWrite(const uint8_t* data, uint32_t count);
  58. void scsiRead(uint8_t* data, uint32_t count, int* parityError);
  59. void scsiWriteByte(uint8_t value);
  60. uint8_t scsiReadByte(void);
  61. // Non-blocking data transfer.
  62. // Depending on platform support the start() function may block.
  63. // The start function can be called multiple times, it may internally
  64. // either combine transfers or block until previous transfer completes.
  65. void scsiStartWrite(const uint8_t* data, uint32_t count);
  66. void scsiFinishWrite();
  67. void scsiStartRead(uint8_t* data, uint32_t count, int *parityError);
  68. void scsiFinishRead(uint8_t* data, uint32_t count, int *parityError);
  69. // Query whether the data at pointer has already been read, i.e. buffer can be reused.
  70. // If data is NULL, checks if all writes have completed.
  71. bool scsiIsWriteFinished(const uint8_t *data);
  72. // Query whether the data at pointer has already been written, i.e. can be processed.
  73. // If data is NULL, checks if all reads have completed.
  74. bool scsiIsReadFinished(const uint8_t *data);
  75. #define PLATFORM_SCSIPHY_HAS_NONBLOCKING_READ 1
  76. #define s2s_getScsiRateKBs() 0
  77. #ifdef __cplusplus
  78. }
  79. #endif