timings.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * ZuluSCSI™ - Copyright (c) 2024 Rabbit Hole Computing™
  3. *
  4. * ZuluSCSI™ firmware is licensed under the GPL version 3 or any later version.
  5. *
  6. * https://www.gnu.org/licenses/gpl-3.0.html
  7. * ----
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  20. **/
  21. #ifndef ZULUSCSI_RP2MCU_TIMINGS_H
  22. #define ZULUSCSI_RP2MCU_TIMINGS_H
  23. #include <stdint.h>
  24. #include <stdbool.h>
  25. typedef enum
  26. {
  27. ZULUSCSI_PIO_TARGET_MODE_SIMPLE,
  28. ZULUSCSI_PIO_TARGET_MODE_EXTRA_DELAY,
  29. } zuluscsi_pio_target_mode_t;
  30. typedef struct
  31. {
  32. uint32_t clk_hz;
  33. struct
  34. {
  35. uint8_t refdiv;
  36. uint32_t vco_freq;
  37. uint8_t post_div1;
  38. uint8_t post_div2;
  39. } pll;
  40. struct
  41. {
  42. // Delay from data setup to REQ assertion.
  43. // deskew delay + cable skew delay = 55 ns minimum
  44. // One clock cycle is x ns => delay (55 / x) clocks
  45. uint8_t req_delay;
  46. // Period of the system clock in pico seconds
  47. uint32_t clk_period_ps;
  48. } scsi;
  49. // delay0: Delay from data write to REQ assertion (data setup)
  50. // delay1: Delay from REQ assert to REQ deassert (req pulse width)
  51. // both values are in clock cycles minus 1 for the pio instruction delay
  52. // total_delay_adjust is manual adjustment value, when checked with a scope
  53. // Max sync - the max sync period that is supported at this clock rate, the number is 1/4 the actual value in ns
  54. struct
  55. {
  56. zuluscsi_pio_target_mode_t mode;
  57. uint8_t delay0;
  58. uint8_t delay1;
  59. int16_t total_delay_adjust;
  60. uint8_t max_sync;
  61. } scsi_20;
  62. struct
  63. {
  64. zuluscsi_pio_target_mode_t mode;
  65. uint8_t delay0;
  66. uint8_t delay1;
  67. int16_t total_delay_adjust;
  68. uint8_t max_sync;
  69. } scsi_10;
  70. struct
  71. {
  72. zuluscsi_pio_target_mode_t mode;
  73. uint8_t delay0;
  74. uint8_t delay1;
  75. int16_t total_delay_adjust;
  76. uint8_t max_sync;
  77. } scsi_5;
  78. struct
  79. {
  80. // System clock speed in MHz clk / clk_div_pio
  81. uint8_t clk_div_1mhz;
  82. // System clock speed / clk_div_pio <= 50MHz
  83. // At 125Hz, the closest dividers 5 is used for 25 MHz for
  84. // stability at that clock speed
  85. // The CPU can apply further divider through state machine
  86. // registers for the initial handshake.
  87. uint8_t clk_div_pio;
  88. // clk_div_pio = (delay0 + 1) + (delay1 + 1)
  89. // delay1 should be shorter than delay0
  90. uint8_t delay0; // subtract one for the instruction delay
  91. uint8_t delay1; // clk_div_pio - delay0 and subtract one for the instruction delay
  92. } sdio;
  93. } zuluscsi_timings_t;
  94. extern zuluscsi_timings_t g_zuluscsi_timings;
  95. bool set_timings(uint32_t target_clk_in_khz);
  96. #endif // ZULUSCSI_RP2MCU_TIMINGS_H