timings_RP2MCU.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. #include "timings_RP2MCU.h"
  22. #include <string.h>
  23. #include "timings.h"
  24. static zuluscsi_timings_t predefined_timings[] = {
  25. {
  26. .clk_hz = 125000000,
  27. .pll =
  28. {
  29. .refdiv = 1,
  30. .vco_freq = 1500000000,
  31. .post_div1 = 6,
  32. .post_div2 = 2
  33. },
  34. .scsi =
  35. {
  36. .req_delay = 7,
  37. .clk_period_ps = 8000
  38. },
  39. .scsi_20 =
  40. {
  41. .delay0 = 4,
  42. .delay1 = 6,
  43. .total_delay_adjust = -1,
  44. .max_sync = 25,
  45. },
  46. .scsi_10 =
  47. {
  48. .delay0 = 4,
  49. .delay1 = 6,
  50. .total_delay_adjust = -1,
  51. .max_sync = 25,
  52. },
  53. .scsi_5 =
  54. {
  55. .delay0 = 10 - 1,
  56. .delay1 = 15 - 1,
  57. .total_delay_adjust = -1,
  58. .max_sync = 50,
  59. },
  60. .sdio =
  61. {
  62. .clk_div_1mhz = 25, // = 125MHz clk / clk_div_pio
  63. .clk_div_pio = 5,
  64. .delay0 = 3 - 1, // subtract one for the instruction delay
  65. .delay1 = 2 - 1 // clk_div_pio - delay0 and subtract one for the instruction delay
  66. }
  67. },
  68. {
  69. .clk_hz = 133000000,
  70. .pll =
  71. {
  72. .refdiv = 1,
  73. .vco_freq = 1596000000,
  74. .post_div1 = 6,
  75. .post_div2 = 2
  76. },
  77. .scsi =
  78. {
  79. .req_delay = 7,
  80. .clk_period_ps = 7519
  81. },
  82. .scsi_20 =
  83. {
  84. .delay0 = 4,
  85. .delay1 = 6,
  86. .total_delay_adjust = -1,
  87. .max_sync = 25,
  88. },
  89. .scsi_10 =
  90. {
  91. .delay0 = 4,
  92. .delay1 = 6,
  93. .total_delay_adjust = -1,
  94. .max_sync = 25,
  95. },
  96. .scsi_5 =
  97. {
  98. .delay0 = 10 - 1,
  99. .delay1 = 15 - 1,
  100. .total_delay_adjust = -1,
  101. .max_sync = 50,
  102. },
  103. .sdio =
  104. {
  105. .clk_div_1mhz = 25,
  106. .clk_div_pio = 5,
  107. .delay0 = 3 - 1, // subtract one for the instruction delay
  108. .delay1 = 2 - 1 // clk_div_pio - delay0 and subtract one for the instruction delay
  109. }
  110. },
  111. {
  112. .clk_hz = 135428571,
  113. .pll =
  114. {
  115. .refdiv = 1,
  116. .vco_freq = 948000000,
  117. .post_div1 = 7,
  118. .post_div2 = 1
  119. },
  120. .scsi =
  121. {
  122. .req_delay = 7,
  123. .clk_period_ps = 7384
  124. },
  125. .scsi_20 =
  126. {
  127. .delay0 = 4,
  128. .delay1 = 6,
  129. .total_delay_adjust = -1,
  130. .max_sync = 25,
  131. },
  132. .scsi_10 =
  133. {
  134. .delay0 = 4,
  135. .delay1 = 6,
  136. .total_delay_adjust = -1,
  137. .max_sync = 25,
  138. },
  139. .scsi_5 =
  140. {
  141. .delay0 = 10 - 1,
  142. .delay1 = 15 - 1,
  143. .total_delay_adjust = -1,
  144. .max_sync = 50,
  145. },
  146. .sdio =
  147. {
  148. .clk_div_1mhz = 27 , // = 135MHz clk / clk_div_pio
  149. .clk_div_pio = 5,
  150. .delay0 = 3 - 1, // subtract one for the instruction delay
  151. .delay1 = 2 - 1 // clk_div_pio - delay0 and subtract one for the instruction delay
  152. }
  153. },
  154. {
  155. .clk_hz = 150000000,
  156. .pll =
  157. {
  158. .refdiv = 1,
  159. .vco_freq = 1500000000,
  160. .post_div1 = 5,
  161. .post_div2 = 2
  162. },
  163. .scsi =
  164. {
  165. .req_delay = 9,
  166. .clk_period_ps = 6667
  167. },
  168. .scsi_20 =
  169. {
  170. .delay0 = 3 - 1,
  171. .delay1 = 4 - 1,
  172. .total_delay_adjust = 0,
  173. .max_sync = 18,
  174. },
  175. .scsi_10 =
  176. {
  177. .delay0 = 4 - 1,
  178. .delay1 = 5 - 1,
  179. .total_delay_adjust = 0,
  180. .max_sync = 25,
  181. },
  182. .scsi_5 =
  183. {
  184. .delay0 = 10 - 1,
  185. .delay1 = 15, // should be 18 - 1 but max currently is 15
  186. .total_delay_adjust = 0,
  187. .max_sync = 50,
  188. },
  189. .sdio =
  190. {
  191. .clk_div_1mhz = 30, // = 150MHz clk / clk_div_pio
  192. .clk_div_pio = 5,
  193. .delay0 = 3 - 1, // subtract one for the instruction delay
  194. .delay1 = 2 - 1 // clk_div_pio - delay0 and subtract one for the instruction delay
  195. }
  196. },
  197. {
  198. .clk_hz = 250000000,
  199. .pll =
  200. {
  201. .refdiv = 1,
  202. .vco_freq = 1500000000,
  203. .post_div1 = 6,
  204. .post_div2 = 1
  205. },
  206. .scsi =
  207. {
  208. .req_delay = 14,
  209. .clk_period_ps = 4000,
  210. },
  211. .scsi_20 =
  212. {
  213. .delay0 = 3 - 1,
  214. .delay1 = 5 - 1,
  215. .total_delay_adjust = 1,
  216. .max_sync = 12,
  217. },
  218. .scsi_10 =
  219. {
  220. .delay0 = 6 - 1,
  221. .delay1 = 9 - 1,
  222. .total_delay_adjust = 1,
  223. .max_sync = 25,
  224. },
  225. .scsi_5 =
  226. {
  227. .delay0 = 15, // maxed out should be 16
  228. .delay1 = 15, // maxed out should be 30
  229. .total_delay_adjust = 1,
  230. .max_sync = 50,
  231. },
  232. #ifdef ZULUSCSI_PICO_2
  233. .sdio =
  234. {
  235. .clk_div_1mhz = 30, // set by trail and error
  236. .clk_div_pio = 6, // SDIO at 41.7MHz
  237. .delay0 = 4 - 1, // subtract one for the instruction delay
  238. .delay1 = 2 - 1 // clk_div_pio - delay0 and subtract one for the instruction delay
  239. }
  240. #else
  241. .sdio =
  242. {
  243. .clk_div_1mhz = 50, // = 250MHz clk / clk_div_pio
  244. .clk_div_pio = 5, // SDIO at 50MHz
  245. .delay0 = 4 - 1, // subtract one for the instruction delay
  246. .delay1 = 1 - 1 // clk_div_pio - delay0 and subtract one for the instruction delay
  247. }
  248. #endif
  249. },
  250. };
  251. zuluscsi_timings_t current_timings;
  252. #ifdef ENABLE_AUDIO_OUTPUT
  253. zuluscsi_timings_t *g_zuluscsi_timings = &predefined_timings[2];
  254. #elif defined(ZULUSCSI_MCU_RP23XX)
  255. zuluscsi_timings_t *g_zuluscsi_timings = &predefined_timings[3];
  256. #elif defined(ZULUSCSI_PICO)
  257. zuluscsi_timings_t *g_zuluscsi_timings = &predefined_timings[1];
  258. #else
  259. zuluscsi_timings_t *g_zuluscsi_timings = &predefined_timings[0];
  260. #endif
  261. bool set_timings(uint32_t target_clk_in_khz)
  262. {
  263. uint32_t number_of_timings = sizeof(predefined_timings)/sizeof( predefined_timings[0]);
  264. for (uint8_t i = 0; i < number_of_timings; i++)
  265. {
  266. if (target_clk_in_khz == predefined_timings[i].clk_hz / 1000)
  267. {
  268. g_zuluscsi_timings = &current_timings;
  269. memcpy(g_zuluscsi_timings, &predefined_timings[i], sizeof(current_timings));
  270. g_max_sync_10_period = g_zuluscsi_timings->scsi_10.max_sync;
  271. g_max_sync_20_period = g_zuluscsi_timings->scsi_20.max_sync;
  272. g_max_sync_5_period = g_zuluscsi_timings->scsi_5.max_sync;
  273. return true;
  274. }
  275. }
  276. return false;
  277. }