scsiTarget.v 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. //`#start header` -- edit after this line, do not edit this line
  2. // Copyright (C) 2013 Michael McMaster <michael@codesrc.com>
  3. //
  4. // This file is part of SCSI2SD.
  5. //
  6. // SCSI2SD is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // SCSI2SD is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public License
  17. // along with SCSI2SD. If not, see <http://www.gnu.org/licenses/>.
  18. `include "cypress.v"
  19. //`#end` -- edit above this line, do not edit this line
  20. // Generated on 10/16/2013 at 00:01
  21. // Component: scsiTarget
  22. module scsiTarget (
  23. output [7:0] DBx_out, // Active High, connected to SCSI bus via inverter
  24. output REQ, // Active High, connected to SCSI bus via inverter
  25. input nACK, // Active LOW, connected directly to SCSI bus.
  26. input [7:0] nDBx_in, // Active LOW, connected directly to SCSI bus.
  27. input IO, // Active High, set by CPU via status register.
  28. input nRST, // Active LOW, connected directly to SCSI bus.
  29. input clk
  30. );
  31. //`#start body` -- edit after this line, do not edit this line
  32. /////////////////////////////////////////////////////////////////////////////
  33. // Force Clock Sync
  34. /////////////////////////////////////////////////////////////////////////////
  35. // The udb_clock_enable primitive component is used to indicate that the input
  36. // clock must always be synchronous and if not implement synchronizers to make
  37. // it synchronous.
  38. wire op_clk;
  39. cy_psoc3_udb_clock_enable_v1_0 #(.sync_mode(`TRUE)) ClkSync
  40. (
  41. .clock_in(clk),
  42. .enable(1'b1),
  43. .clock_out(op_clk)
  44. );
  45. /////////////////////////////////////////////////////////////////////////////
  46. // FIFO Status Register
  47. /////////////////////////////////////////////////////////////////////////////
  48. // Status Register: scsiTarget_StatusReg__STATUS_REG
  49. // Bit 0: Tx FIFO not full
  50. // Bit 1: Rx FIFO not empty
  51. // Bit 2: Tx FIFO empty
  52. // Bit 3: Rx FIFO full
  53. //
  54. // TX FIFO Register: scsiTarget_scsiTarget_u0__F0_REG
  55. // RX FIFO Register: scsiTarget_scsiTarget_u0__F1_REG
  56. // Use with CY_GET_REG8 and CY_SET_REG8
  57. wire f0_bus_stat; // Tx FIFO not full
  58. wire f0_blk_stat; // Tx FIFO empty
  59. wire f1_bus_stat; // Rx FIFO not empty
  60. wire f1_blk_stat; // Rx FIFO full
  61. cy_psoc3_status #(.cy_force_order(1), .cy_md_select(8'h00)) StatusReg
  62. (
  63. /* input */ .clock(op_clk),
  64. /* input [04:00] */ .status({4'b0, f1_blk_stat, f0_blk_stat, f1_bus_stat, f0_bus_stat})
  65. );
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CONSTANTS
  68. /////////////////////////////////////////////////////////////////////////////
  69. localparam IO_WRITE = 1'b1;
  70. localparam IO_READ = 1'b0;
  71. /////////////////////////////////////////////////////////////////////////////
  72. // STATE MACHINE
  73. /////////////////////////////////////////////////////////////////////////////
  74. // TX States:
  75. // IDLE
  76. // Wait for an entry in the FIFO, and for the SCSI Initiator to be ready
  77. // FIFOLOAD
  78. // Load F0 into A0. Feed (old) A0 into the ALU SRCA.
  79. // TX
  80. // Load data register from PO. PO is fed by A0 going into the ALU via SRCA
  81. // A0 must remain unchanged.
  82. // DESKEW_INIT
  83. // DBx output signals will be output in this state
  84. // Load deskew clock count into A0 from D0
  85. // DESKEW
  86. // DBx output signals will be output in this state
  87. // Wait for the SCSI deskew time of 55ms. (DEC A0).
  88. // A1 must be fed into SRCA, so PO is now useless.
  89. // READY
  90. // REQ and DBx output signals will be output in this state
  91. // Wait for acknowledgement from the SCSI initiator.
  92. // RX
  93. // Dummy state for flow control.
  94. // REQ signal will be output in this state
  95. // PI enabled for input into ALU "PASS" operation, storing into F1.
  96. //
  97. // RX States:
  98. // IDLE
  99. // Wait for a dummy "enabling" entry in the input FIFO, and wait for space
  100. // in output the FIFO, and for the SCSI Initiator to be ready
  101. // FIFOLOAD
  102. // Load F0 into A0.
  103. // The input FIFO is used to control the number of bytes we attempt to
  104. // read from the SCSI bus.
  105. // READY
  106. // REQ signal will be output in this state
  107. // Wait for the initiator to send a byte on the SCSI bus.
  108. // RX
  109. // REQ signal will be output in this state
  110. // PI enabled for input into ALU "PASS" operation, storing into F1.
  111. localparam STATE_IDLE = 3'b000;
  112. localparam STATE_FIFOLOAD = 3'b001;
  113. localparam STATE_TX = 3'b010;
  114. localparam STATE_DESKEW_INIT = 3'b011;
  115. localparam STATE_DESKEW = 3'b100;
  116. // This state intentionally not used.
  117. localparam STATE_READY = 3'b110;
  118. localparam STATE_RX = 3'b111;
  119. // state selects the datapath register.
  120. reg[2:0] state;
  121. // Data being read/written from/to the SCSI bus
  122. reg[7:0] data;
  123. // Set by the datapath zero detector (z1). High when A1 counts down to zero.
  124. // D1 set to constant by .d1_init_a(4) (55ns at 66MHz)
  125. wire deskewComplete;
  126. // Parallel input to the datapath SRCA.
  127. // Selected for input through to the ALU if CFB EN bit set for the datapath
  128. // state and enabled by PI DYN bit in CFG15-14
  129. wire[7:0] pi;
  130. // Parallel output from the selected SRCA value (A0 or A1) to the ALU.
  131. wire[7:0] po;
  132. // Set true to trigger storing A1 into F1.
  133. wire fifoStore;
  134. // Set Output Pins
  135. assign REQ = state[1] & state[2]; // STATE_READY & STATE_RX
  136. assign DBx_out[7:0] = data;
  137. assign pi[7:0] = ~nDBx_in[7:0]; // Invert active low scsi bus
  138. assign fifoStore = (state == STATE_RX) ? 1'b1 : 1'b0;
  139. always @(posedge op_clk) begin
  140. case (state)
  141. STATE_IDLE:
  142. begin
  143. // Check that SCSI initiator is ready, and input FIFO is not empty,
  144. // and output FIFO is not full.
  145. // Note that output FIFO is unused in TX mode.
  146. if (nACK & !f0_blk_stat && !f1_blk_stat)
  147. state <= STATE_FIFOLOAD;
  148. else
  149. state <= STATE_IDLE;
  150. // Clear our output pins
  151. data <= 8'b0;
  152. end
  153. STATE_FIFOLOAD:
  154. state <= IO == IO_WRITE ? STATE_TX : STATE_READY;
  155. STATE_TX:
  156. begin
  157. state <= STATE_DESKEW_INIT;
  158. data <= po;
  159. end
  160. STATE_DESKEW_INIT: state <= STATE_DESKEW;
  161. STATE_DESKEW:
  162. if(deskewComplete) state <= STATE_READY;
  163. else state <= STATE_DESKEW;
  164. STATE_READY:
  165. //if ((IO == IO_WRITE) & ~nACK) state <= STATE_IDLE;
  166. //else if ((IO == IO_READ) & ~nACK) state <= STATE_RX;
  167. if (~nACK) state <= STATE_RX;
  168. else state <= STATE_READY;
  169. STATE_RX: state <= STATE_IDLE;
  170. default: state <= STATE_IDLE;
  171. endcase
  172. end
  173. cy_psoc3_dp #(.d1_init(3),
  174. .cy_dpconfig(
  175. {
  176. `CS_ALU_OP_PASS, `CS_SRCA_A0, `CS_SRCB_D0,
  177. `CS_SHFT_OP_PASS, `CS_A0_SRC_NONE, `CS_A1_SRC_NONE,
  178. `CS_FEEDBACK_DSBL, `CS_CI_SEL_CFGA, `CS_SI_SEL_CFGA,
  179. `CS_CMP_SEL_CFGA, /*CFGRAM0: IDLE*/
  180. `CS_ALU_OP_PASS, `CS_SRCA_A0, `CS_SRCB_D0,
  181. `CS_SHFT_OP_PASS, `CS_A0_SRC___F0, `CS_A1_SRC_NONE,
  182. `CS_FEEDBACK_DSBL, `CS_CI_SEL_CFGA, `CS_SI_SEL_CFGA,
  183. `CS_CMP_SEL_CFGA, /*CFGRAM1: FIFO Load*/
  184. `CS_ALU_OP_PASS, `CS_SRCA_A0, `CS_SRCB_D0,
  185. `CS_SHFT_OP_PASS, `CS_A0_SRC_NONE, `CS_A1_SRC_NONE,
  186. `CS_FEEDBACK_DSBL, `CS_CI_SEL_CFGA, `CS_SI_SEL_CFGA,
  187. `CS_CMP_SEL_CFGA, /*CFGRAM2: TX*/
  188. `CS_ALU_OP_PASS, `CS_SRCA_A0, `CS_SRCB_D0,
  189. `CS_SHFT_OP_PASS, `CS_A0_SRC___D0, `CS_A1_SRC_NONE,
  190. `CS_FEEDBACK_DSBL, `CS_CI_SEL_CFGA, `CS_SI_SEL_CFGA,
  191. `CS_CMP_SEL_CFGA, /*CFGRAM3: DESKEW INIT*/
  192. `CS_ALU_OP__DEC, `CS_SRCA_A0, `CS_SRCB_D0,
  193. `CS_SHFT_OP_PASS, `CS_A0_SRC__ALU, `CS_A1_SRC_NONE,
  194. `CS_FEEDBACK_DSBL, `CS_CI_SEL_CFGA, `CS_SI_SEL_CFGA,
  195. `CS_CMP_SEL_CFGA, /*CFGRAM4: DESKEW*/
  196. `CS_ALU_OP_PASS, `CS_SRCA_A0, `CS_SRCB_D0,
  197. `CS_SHFT_OP_PASS, `CS_A0_SRC_NONE, `CS_A1_SRC_NONE,
  198. `CS_FEEDBACK_DSBL, `CS_CI_SEL_CFGA, `CS_SI_SEL_CFGA,
  199. `CS_CMP_SEL_CFGA, /*CFGRAM5: Not used*/
  200. `CS_ALU_OP_PASS, `CS_SRCA_A0, `CS_SRCB_D0,
  201. `CS_SHFT_OP_PASS, `CS_A0_SRC_NONE, `CS_A1_SRC_NONE,
  202. `CS_FEEDBACK_DSBL, `CS_CI_SEL_CFGA, `CS_SI_SEL_CFGA,
  203. `CS_CMP_SEL_CFGA, /*CFGRAM6: READY*/
  204. `CS_ALU_OP_PASS, `CS_SRCA_A0, `CS_SRCB_D0,
  205. `CS_SHFT_OP_PASS, `CS_A0_SRC_NONE, `CS_A1_SRC_NONE,
  206. `CS_FEEDBACK_ENBL, `CS_CI_SEL_CFGA, `CS_SI_SEL_CFGA,
  207. `CS_CMP_SEL_CFGA, /*CFGRAM7: RX*/
  208. 8'hFF, 8'h00, /*CFG9: */
  209. 8'hFF, 8'hFF, /*CFG11-10: */
  210. `SC_CMPB_A1_D1, `SC_CMPA_A1_D1, `SC_CI_B_ARITH,
  211. `SC_CI_A_ARITH, `SC_C1_MASK_DSBL, `SC_C0_MASK_DSBL,
  212. `SC_A_MASK_DSBL, `SC_DEF_SI_0, `SC_SI_B_DEFSI,
  213. `SC_SI_A_DEFSI, /*CFG13-12: */
  214. `SC_A0_SRC_ACC, `SC_SHIFT_SL, `SC_PI_DYN_EN,
  215. 1'h0, `SC_FIFO1_ALU, `SC_FIFO0_BUS,
  216. `SC_MSB_DSBL, `SC_MSB_BIT0, `SC_MSB_NOCHN,
  217. `SC_FB_NOCHN, `SC_CMP1_NOCHN,
  218. `SC_CMP0_NOCHN, /*CFG15-14: */
  219. 10'h00, `SC_FIFO_CLK__DP,`SC_FIFO_CAP_AX,
  220. `SC_FIFO_LEVEL,`SC_FIFO__SYNC,`SC_EXTCRC_DSBL,
  221. `SC_WRK16CAT_DSBL /*CFG17-16: */
  222. }
  223. )) datapath(
  224. /* input */ .reset(1'b0),
  225. /* input */ .clk(op_clk),
  226. /* input [02:00] */ .cs_addr(state),
  227. /* input */ .route_si(1'b0),
  228. /* input */ .route_ci(1'b0),
  229. /* input */ .f0_load(1'b0),
  230. /* input */ .f1_load(fifoStore),
  231. /* input */ .d0_load(1'b0),
  232. /* input */ .d1_load(1'b0),
  233. /* output */ .ce0(),
  234. /* output */ .cl0(),
  235. /* output */ .z0(deskewComplete),
  236. /* output */ .ff0(),
  237. /* output */ .ce1(),
  238. /* output */ .cl1(),
  239. /* output */ .z1(),
  240. /* output */ .ff1(),
  241. /* output */ .ov_msb(),
  242. /* output */ .co_msb(),
  243. /* output */ .cmsb(),
  244. /* output */ .so(),
  245. /* output */ .f0_bus_stat(f0_bus_stat),
  246. /* output */ .f0_blk_stat(f0_blk_stat),
  247. /* output */ .f1_bus_stat(f1_bus_stat),
  248. /* output */ .f1_blk_stat(f1_blk_stat),
  249. /* input */ .ci(1'b0), // Carry in from previous stage
  250. /* output */ .co(), // Carry out to next stage
  251. /* input */ .sir(1'b0), // Shift in from right side
  252. /* output */ .sor(), // Shift out to right side
  253. /* input */ .sil(1'b0), // Shift in from left side
  254. /* output */ .sol(), // Shift out to left side
  255. /* input */ .msbi(1'b0), // MSB chain in
  256. /* output */ .msbo(), // MSB chain out
  257. /* input [01:00] */ .cei(2'b0), // Compare equal in from prev stage
  258. /* output [01:00] */ .ceo(), // Compare equal out to next stage
  259. /* input [01:00] */ .cli(2'b0), // Compare less than in from prv stage
  260. /* output [01:00] */ .clo(), // Compare less than out to next stage
  261. /* input [01:00] */ .zi(2'b0), // Zero detect in from previous stage
  262. /* output [01:00] */ .zo(), // Zero detect out to next stage
  263. /* input [01:00] */ .fi(2'b0), // 0xFF detect in from previous stage
  264. /* output [01:00] */ .fo(), // 0xFF detect out to next stage
  265. /* input [01:00] */ .capi(2'b0), // Software capture from previous stage
  266. /* output [01:00] */ .capo(), // Software capture to next stage
  267. /* input */ .cfbi(1'b0), // CRC Feedback in from previous stage
  268. /* output */ .cfbo(), // CRC Feedback out to next stage
  269. /* input [07:00] */ .pi(pi), // Parallel data port
  270. /* output [07:00] */ .po(po) // Parallel data port
  271. );
  272. //`#end` -- edit above this line, do not edit this line
  273. endmodule
  274. //`#start footer` -- edit after this line, do not edit this line
  275. //`#end` -- edit above this line, do not edit this line