scsiPhyTiming108MHz.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright (C) 2021 Michael McMaster <michael@codesrc.com>
  2. //
  3. // This file is part of SCSI2SD.
  4. //
  5. // SCSI2SD is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // SCSI2SD is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with SCSI2SD. If not, see <http://www.gnu.org/licenses/>.
  17. #ifndef S2S_SCSIPHYTIMING
  18. // Timing at a 108MHz clock.
  19. static uint8_t asyncTimings[][4] =
  20. {
  21. /* Speed, Assert, Deskew, Hold, Glitch */
  22. {/*1.5MB/s*/ 28, 18, 7, 15},
  23. //{/*1.5MB/s*/ 63, 31, 7, 15},
  24. {/*3.3MB/s*/ 13, 6, 6, 13},
  25. {/*5MB/s*/ 9, 6, 6, 6}, // 80ns
  26. {/*safe*/ 3, 6, 6, 6}, // Probably safe
  27. {/*turbo*/ 3, 3, 3, 2}
  28. };
  29. // 5MB/s synchronous timing
  30. #define SCSI_FAST5_DESKEW 6 // 55ns
  31. #define SCSI_FAST5_HOLD 6 // 53ns
  32. // 10MB/s synchronous timing
  33. // 2:0 Deskew count, 25ns
  34. // 6:4 Hold count, 33ns
  35. // 3:0 Assertion count, 30ns
  36. // We want deskew + hold + assert + 3 to add up to 11 clocks
  37. // the fpga code has 1 clock of overhead when transitioning from deskew to
  38. // assert to hold
  39. #define SCSI_FAST10_DESKEW 2 // 25ns
  40. #define SCSI_FAST10_HOLD 3 // 33ns
  41. #define SCSI_FAST10_WRITE_ASSERT 3 // 30ns. Overall clocks only works if fpga overhead is 3.
  42. // Slow down the cycle to be valid. 2x assert period is TOO FAST when
  43. // reading data. It's ok when writing due to the deskew.
  44. // 50ns. ie. 100ns / 2. Rounded down because there's likely a few extra cycles
  45. // here and there.
  46. #define SCSI_FAST10_READ_ASSERT 5
  47. // Fastest possible timing, probably not 20MB/s
  48. #define SCSI_FAST20_DESKEW 1
  49. #define SCSI_FAST20_HOLD 2
  50. #define SCSI_FAST20_ASSERT 2
  51. #define syncDeskew(period) ((period) < 35 ? \
  52. SCSI_FAST10_DESKEW : SCSI_FAST5_DESKEW)
  53. #define syncHold(period) ((period) < 35 ? \
  54. ((period) == 25 ? SCSI_FAST10_HOLD : 4) /* 25ns/33ns */\
  55. : SCSI_FAST5_HOLD)
  56. // Number of overhead cycles per period.
  57. #define FPGA_OVERHEAD 2
  58. #define FPGA_CYCLES_PER_NS 9
  59. #define SCSI_PERIOD_CLKS(period) ((((int)period * 4) + (FPGA_CYCLES_PER_NS/2)) / FPGA_CYCLES_PER_NS)
  60. // 3.125MB/s (80 period) to < 10MB/s sync
  61. // Assumes a 108MHz fpga clock. (9 ns)
  62. // 3:0 Assertion count, variable
  63. #define syncAssertionWrite(period,deskew) ((SCSI_PERIOD_CLKS(period) - deskew - FPGA_OVERHEAD + 1) / 2)
  64. #define syncAssertionRead(period) syncAssertionWrite(period,0)
  65. // Time until we consider ourselves selected
  66. // 400ns at 108MHz
  67. #define SCSI_DEFAULT_SELECTION 43
  68. #define SCSI_FAST_SELECTION 5
  69. #endif // S2S_SCSIPHYTIMING