sdram.sv 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. // -----------------------------------------------------------------------
  2. //
  3. // Copyright 2010-2021 H. Peter Anvin - All Rights Reserved
  4. //
  5. // This program 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, Inc., 51 Franklin St, Fifth Floor,
  8. // Boston MA 02110-1301, USA; either version 2 of the License, or
  9. // (at your option) any later version; incorporated herein by reference.
  10. //
  11. // -----------------------------------------------------------------------
  12. //
  13. // Simple SDRAM controller
  14. //
  15. // Very simple non-parallelizing SDRAM controller.
  16. //
  17. //
  18. // Two ports are provided:
  19. // Port 1 does aligned 4-byte accesses with byte enables.
  20. // Port 2 does aligned 8-byte accesses, write only, with no byte
  21. // enables; it supports streaming from a FIFO.
  22. //
  23. // Port 1 is multiplexed via an arbiter, which receives a bus
  24. // defined by the sdram_bus interface.
  25. //
  26. // All signals are in the sdram clock domain.
  27. //
  28. // [rw]ack is asserted at the beginning of a read- or write cycle and
  29. // deasserted afterwards; rready is asserted once all data is read and
  30. // the read data (rdX port) is valid; it remains asserted after the
  31. // transaction is complete and rack is deasserted.
  32. //
  33. //
  34. // The interface to the port modules. The read data is 16 bits
  35. // at a time, and is only valid in the cycle rstrb[x] is asserted.
  36. //
  37. // The only output signal that is unique to this port
  38. // is "start". All other signals are broadcast.
  39. //
  40. interface dram_bus;
  41. logic [1:0] prio; // Priority vs refresh
  42. logic rst_n;
  43. logic clk;
  44. logic [24:0] addr;
  45. logic addr0; // addr[0] latched at transaction start
  46. logic [15:0] rd;
  47. logic req;
  48. logic [1:0] rstrb; // Data read strobe
  49. logic [31:0] wd;
  50. logic [3:0] wstrb;
  51. logic start; // Transaction start
  52. logic wrack; // Transaction is a write
  53. // Upstream direction
  54. modport ustr (
  55. input prio,
  56. output rst_n,
  57. output clk,
  58. input addr,
  59. output addr0,
  60. output rd,
  61. input req,
  62. output rstrb,
  63. input wd,
  64. input wstrb,
  65. output start,
  66. output wrack
  67. );
  68. // Downstream direction
  69. modport dstr (
  70. output prio,
  71. input rst_n,
  72. input clk,
  73. output addr,
  74. input addr0,
  75. input rd,
  76. output req,
  77. input rstrb,
  78. output wd,
  79. output wstrb,
  80. input start,
  81. input wrack
  82. );
  83. endinterface // dram_bus
  84. // Port into the DRAM
  85. module dram_port
  86. #(parameter width = 32)
  87. (
  88. dram_bus.dstr bus,
  89. input [1:0] prio,
  90. input [24:0] addr,
  91. output reg [width-1:0] rd,
  92. input valid,
  93. output reg ready,
  94. input [width-1:0] wd,
  95. input [(width >> 3)-1:0] wstrb
  96. );
  97. reg started;
  98. assign bus.prio = prio;
  99. assign bus.addr = addr;
  100. assign bus.req = valid & ~started;
  101. always_comb
  102. begin
  103. bus.wd = 32'hxxxx_xxxx;
  104. bus.wstrb = 4'b0000;
  105. if (width == 8)
  106. begin
  107. bus.wd[15:0] = { wd, wd };
  108. bus.wstrb[1:0] = { wstrb[0] & addr[0], wstrb[0] & ~addr[0] };
  109. end
  110. else
  111. begin
  112. bus.wd[width-1:0] = wd;
  113. bus.wstrb[(width >> 3)-1:0] = wstrb;
  114. end
  115. end
  116. always @(negedge bus.rst_n or posedge bus.clk)
  117. if (~bus.rst_n)
  118. begin
  119. ready <= 1'b0;
  120. started <= 1'b0;
  121. end
  122. else
  123. begin
  124. if (~valid)
  125. begin
  126. ready <= 1'b0;
  127. started <= 1'b0;
  128. end
  129. else if (bus.start)
  130. begin
  131. started <= 1'b1;
  132. ready <= |bus.wstrb; // All write data latched
  133. end
  134. else if (started & ~ready)
  135. begin
  136. ready <= bus.rstrb[(width - 1) >> 4];
  137. end
  138. end // else: !if(~bus.rst_n)
  139. genvar i;
  140. generate
  141. for (i = 0; i < (width >> 4); i++)
  142. begin : w
  143. always @(posedge bus.clk)
  144. if (started & ~ready & bus.rstrb[i])
  145. begin
  146. if (width == 8)
  147. rd <= bus.addr0 ? bus.rd[15:8] : bus.rd[7:0];
  148. else
  149. rd[i*16+15:i*16] <= bus.rd;
  150. end
  151. end
  152. endgenerate
  153. endmodule // dram_port
  154. module dram_arbiter
  155. #(parameter port_count = 1)
  156. (
  157. dram_bus.ustr ustr [1:port_count],
  158. dram_bus.dstr dstr,
  159. input [1:0] rfsh_prio,
  160. output logic do_rfsh
  161. );
  162. logic [port_count:0] requesting;
  163. logic [24:0] addr [1:port_count];
  164. logic [31:0] wd [1:port_count];
  165. logic [3:0] wstrb [1:port_count];
  166. logic [1:0] prio [1:port_count];
  167. always_comb
  168. requesting[0] = 1'b0;
  169. genvar i;
  170. generate
  171. for (i = 1; i <= port_count; i++)
  172. begin : u
  173. always_comb
  174. begin
  175. ustr[i].rst_n = dstr.rst_n;
  176. ustr[i].clk = dstr.clk;
  177. ustr[i].addr0 = dstr.addr0;
  178. ustr[i].rd = dstr.rd;
  179. ustr[i].rstrb = dstr.rstrb;
  180. ustr[i].wrack = dstr.wrack;
  181. ustr[i].start = 1'b0;
  182. addr[i] = ustr[i].addr;
  183. wd[i] = ustr[i].wd;
  184. wstrb[i] = ustr[i].wstrb;
  185. prio[i] = ustr[i].prio;
  186. if (~|requesting[i-1:0] & ustr[i].req)
  187. begin
  188. requesting[i] = 1'b1;
  189. ustr[i].start = dstr.start & (ustr[i].prio >= rfsh_prio);
  190. end
  191. else
  192. begin
  193. requesting[i] = 1'b0;
  194. ustr[i].start = 1'b0;
  195. end
  196. end // always_comb
  197. end // for (i = 1; i <= port_count; i++)
  198. endgenerate
  199. always_comb
  200. begin
  201. dstr.req = 1'b0;
  202. dstr.addr = 25'bx;
  203. dstr.wd = 32'bx;
  204. dstr.wstrb = 4'bx;
  205. do_rfsh = |rfsh_prio;
  206. for (int j = 1; j <= port_count; j++)
  207. begin
  208. if (requesting[j])
  209. begin
  210. dstr.req = 1'b1;
  211. dstr.addr = addr[j];
  212. dstr.wd = wd[j];
  213. dstr.wstrb = wstrb[j];
  214. do_rfsh = prio[j] < rfsh_prio;
  215. end
  216. end // for (int j = 1; j <= port_count; j++)
  217. end // always_comb
  218. endmodule // dram_arbiter
  219. module sdram
  220. #( parameter
  221. port1_count = 1,
  222. // Timing parameters
  223. // The parameters are hardcoded for Micron MT48LC16M16A2-6A,
  224. // per datasheet:
  225. // 100 MHz 167 MHz
  226. // ----------------------------------------------------------
  227. // CL 2 3 READ to data out
  228. // tRCD 18 ns 2 3 ACTIVE to READ/WRITE
  229. // tRFC 60 ns 6 10 REFRESH to ACTIVE
  230. // tRP 18 ns 2 3 PRECHARGE to ACTIVE/REFRESH
  231. // tRAS 42 ns 5 7 ACTIVE to PRECHARGE
  232. // tRC 60 ns 6 10 ACTIVE to ACTIVE (same bank)
  233. // tRRD 12 ns 2 2 ACTICE to ACTIVE (different bank)
  234. // tWR 12 ns 2 2 Last write data to PRECHARGE
  235. // tMRD 2 2 MODE REGISTER to ACTIVE/REFRESH
  236. //
  237. // These parameters are set by power of 2:
  238. // tREFi 64/8192 ms 781 1302 Refresh time per row (max)
  239. // tP 100 us 10000 16667 Time until first command (min)
  240. t_cl = 3,
  241. t_rcd = 3,
  242. t_rfc = 10,
  243. t_rp = 3,
  244. t_ras = 7,
  245. t_rc = 10,
  246. t_rrd = 2,
  247. t_wr = 2,
  248. t_mrd = 2,
  249. t_refi_lg2 = 10, // 1024 cycles
  250. t_p_lg2 = 15, // 32768 cycles
  251. burst_lg2 = 1 // log2(burst length)
  252. )
  253. (
  254. // Reset and clock
  255. input rst_n,
  256. input clk,
  257. input out_clk, // Phase shifted external clock
  258. // SDRAM hardware interface
  259. output sr_clk, // SDRAM clock output buffer
  260. output sr_cke, // SDRAM clock enable
  261. output sr_cs_n, // SDRAM CS#
  262. output sr_ras_n, // SDRAM RAS#
  263. output sr_cas_n, // SDRAM CAS#
  264. output sr_we_n, // SDRAM WE#
  265. output [1:0] sr_dqm, // SDRAM DQM (per byte)
  266. output [1:0] sr_ba, // SDRAM bank selects
  267. output [12:0] sr_a, // SDRAM address bus
  268. inout [15:0] sr_dq, // SDRAM data bus
  269. // Port 1
  270. dram_bus.ustr port1 [1:port1_count],
  271. // Port 2
  272. input [24:1] a2,
  273. input [15:0] wd2,
  274. input [1:0] wrq2,
  275. output reg wacc2 // Data accepted, advance data & addr
  276. );
  277. `include "functions.sv" // For modelsim
  278. // Mode register data
  279. wire mrd_wburst = 1'b1; // Write bursts enabled
  280. wire [2:0] mrd_cl = t_cl;
  281. wire [2:0] mrd_burst = burst_lg2;
  282. wire mrd_interleave = 1'b0; // Interleaved bursts
  283. wire [12:0] mrd_val = { 3'b000, // Reserved
  284. ~mrd_wburst, // Write burst disable
  285. 2'b00, // Normal operation
  286. mrd_cl, // CAS latency
  287. mrd_interleave, // Interleaved bursts
  288. mrd_burst }; // Burst length
  289. // Where to issue a PRECHARGE when we only want to read one word
  290. // (terminate the burst as soon as possible, but no sooner...)
  291. localparam t_pre_rd_when = max(t_ras, t_rcd + 1);
  292. // Where to issue a PRECHARGE when we only want to write one word
  293. // (terminate the burst as soon as possible, but no sooner...)
  294. localparam t_pre_wr_when = max(t_ras, t_rcd + t_wr);
  295. // Actual burst length (2^burst_lg2)
  296. localparam burst_n = 1 << burst_lg2;
  297. // Command opcodes and attributes (is_rfsh, CS#, RAS#, CAS#, WE#)
  298. localparam cmd_desl = 5'b0_1111; // Deselect (= NOP)
  299. localparam cmd_nop = 5'b0_0111; // NO OPERATION
  300. localparam cmd_bst = 5'b0_0110; // BURST TERMINATE
  301. localparam cmd_rd = 5'b0_0101; // READ
  302. localparam cmd_wr = 5'b0_0100; // WRITE
  303. localparam cmd_act = 5'b0_0011; // ACTIVE
  304. localparam cmd_pre = 5'b0_0010; // PRECHARGE
  305. localparam cmd_ref = 5'b1_0001; // AUTO REFRESH
  306. localparam cmd_mrd = 5'b0_0000; // LOAD MODE REGISTER
  307. reg [4:0] dram_cmd;
  308. wire is_rfsh = dram_cmd[4];
  309. assign sr_cs_n = dram_cmd[3];
  310. assign sr_ras_n = dram_cmd[2];
  311. assign sr_cas_n = dram_cmd[1];
  312. assign sr_we_n = dram_cmd[0];
  313. assign sr_cke = 1'b1;
  314. `ifdef SD_CLK_USE_DDIO
  315. // SDRAM output clock buffer. The SDRAM output clock is
  316. // inverted with respect to our internal clock, so that
  317. // the SDRAM sees the positive clock edge in the middle of
  318. // our clocks.
  319. //
  320. // Use a DDIO buffer for best performance
  321. // For EP4CE15 only could use a secondary PLL here, but it
  322. // isn't clear it buys us a whole lot.
  323. //
  324. // This buffer is driven by a separate PLL output, so that
  325. // the phase shift between the clock and the outputs/inputs
  326. // can be tuned.
  327. ddio_out sr_clk_out (
  328. .aclr ( 1'b0 ),
  329. .datain_h ( 1'b1 ),
  330. .datain_l ( 1'b0 ),
  331. .outclock ( out_clk ),
  332. .dataout ( sr_clk )
  333. );
  334. `else // !`ifdef SD_CLK_USE_DDIO
  335. // Dedicated clock pin
  336. assign sr_clk = out_clk;
  337. `endif
  338. // SDRAM output signal registers
  339. reg [12:0] dram_a;
  340. assign sr_a = dram_a;
  341. reg [1:0] dram_ba;
  342. assign sr_ba = dram_ba;
  343. reg [1:0] dram_dqm;
  344. assign sr_dqm = dram_dqm;
  345. reg [15:0] dram_d; // Data to DRAM
  346. reg [15:0] dram_q; // Data from DRAM (I/O buffers)
  347. reg dram_d_en; // Drive data out
  348. assign sr_dq = dram_d_en ? dram_d : 16'hzzzz;
  349. // State machine and counters
  350. reg [t_refi_lg2-2:0] rfsh_ctr; // Refresh timer
  351. wire rfsh_ctr_msb = rfsh_ctr[t_refi_lg2-2];
  352. reg rfsh_ctr_last_msb;
  353. wire rfsh_tick = rfsh_ctr_last_msb & ~rfsh_ctr_msb;
  354. reg [t_p_lg2:t_refi_lg2-1] init_ctr; // Reset to init counter
  355. reg [1:0] rfsh_prio; // Refresh priority (0-3)
  356. // Port1 and refresh arbiter
  357. dram_bus p1 ();
  358. wire do_rfsh;
  359. assign p1.rst_n = rst_n;
  360. assign p1.clk = clk;
  361. dram_arbiter #(.port_count(port1_count))
  362. arbiter (
  363. .ustr ( port1 ),
  364. .dstr ( p1.dstr ),
  365. .rfsh_prio ( rfsh_prio ),
  366. .do_rfsh ( do_rfsh )
  367. );
  368. // The actual values are unimportant; the compiler will optimize
  369. // the state machine implementation.
  370. typedef enum logic [2:0] {
  371. st_reset, // Reset until init timer expires
  372. st_init_rfsh, // Refresh cycles during initialization
  373. st_init_mrd, // MRD register write during initialization
  374. st_idle, // Idle state: all banks precharged
  375. st_rfsh,
  376. st_rd_wr, // Port 0/1 transaction
  377. st_wr2 // Port 2 write (burstable)
  378. } state_t;
  379. state_t state = st_reset;
  380. always @(posedge clk or negedge rst_n)
  381. if (~rst_n)
  382. begin
  383. rfsh_ctr <= 1'b0;
  384. rfsh_prio <= 2'b00;
  385. init_ctr <= 1'b0;
  386. end
  387. else
  388. begin
  389. rfsh_ctr <= rfsh_ctr + 1'b1;
  390. rfsh_ctr_last_msb <= rfsh_ctr_msb;
  391. // Refresh priority management: saturating 2-bit counter
  392. if (is_rfsh)
  393. rfsh_prio <= 2'b00; // This is a refresh cycle
  394. else
  395. rfsh_prio <= rfsh_prio + (rfsh_tick & ~&rfsh_prio);
  396. // The refresh counter is also used as a prescaler
  397. // for the initialization counter.
  398. // Note that means init_ctr is two cycles "behind"
  399. // rfsh_ctr; this is totally fine.
  400. init_ctr <= init_ctr + rfsh_tick;
  401. end // else: !if(~rst_n)
  402. reg [5:0] op_ctr; // Cycle into the current state
  403. wire [3:0] op_cycle = op_ctr[3:0]; // Cycle into the current command
  404. wire [1:0] init_op_ctr = op_ctr[5:4]; // Init operation counter
  405. reg op_zero; // op_cycle wrap around (init_op_ctr changed)
  406. reg [31:0] wdata_q;
  407. reg [ 3:0] be_q;
  408. reg [ 9:0] col_addr;
  409. reg wrq2_more;
  410. assign p1.start = (state == st_idle);
  411. assign p1.addr0 = col_addr[0];
  412. assign p1.rd = dram_q;
  413. //
  414. // Careful with the timing here... there is one cycle between
  415. // registers and wires, and the DRAM observes the clock 1/2
  416. // cycle from the internal logic. This affects read timing.
  417. //
  418. // Note that rready starts out as 1. This allows a 0->1 detection
  419. // on the rready line to be used as cycle termination signal.
  420. //
  421. always @(posedge clk or negedge rst_n)
  422. if (~rst_n)
  423. begin
  424. dram_cmd <= cmd_desl;
  425. dram_a <= 13'hxxxx;
  426. dram_ba <= 2'bxx;
  427. dram_dqm <= 2'b00;
  428. dram_d <= 16'hxxxx;
  429. dram_q <= 16'hxxxx;
  430. dram_d_en <= 1'b1; // Don't float except during read
  431. op_ctr <= 6'h0;
  432. op_zero <= 1'b0;
  433. state <= st_reset;
  434. p1.wrack <= 1'bx;
  435. p1.rd <= 16'hxxxx;
  436. p1.rstrb <= 2'b00;
  437. wacc2 <= 1'b0;
  438. wrq2_more <= 1'bx;
  439. wdata_q <= 32'hxxxx_xxxx;
  440. be_q <= 4'bxxxx;
  441. col_addr <= 10'hxxx;
  442. end
  443. else
  444. begin
  445. // Default values
  446. // Note: dram_ba are preserved
  447. dram_a <= 13'b0;
  448. dram_dqm <= 2'b00;
  449. dram_d <= 16'haaaa;
  450. dram_cmd <= cmd_nop;
  451. dram_d_en <= 1'b1; // Don't float except during read
  452. dram_q <= sr_dq;
  453. p1.rstrb <= 2'b00;
  454. wacc2 <= 1'b0;
  455. if (state == st_reset || state == st_idle)
  456. begin
  457. op_ctr <= 6'b0;
  458. op_zero <= 1'b0;
  459. end
  460. else
  461. begin
  462. op_ctr <= op_ctr + 1'b1;
  463. op_zero <= &op_cycle; // About to wrap around
  464. end // else: !if(state == st_reset || state == st_idle)
  465. case (state)
  466. st_reset:
  467. begin
  468. dram_a[10] <= 1'b1; // Precharge all banks
  469. dram_cmd <= cmd_nop;
  470. if (init_ctr[t_p_lg2])
  471. begin
  472. dram_cmd <= cmd_pre;
  473. state <= st_init_rfsh;
  474. end
  475. end
  476. st_init_rfsh:
  477. begin
  478. if (op_zero)
  479. begin
  480. dram_cmd <= cmd_ref;
  481. if (init_op_ctr == 2'b11)
  482. state <= st_init_mrd;
  483. end
  484. end
  485. st_init_mrd:
  486. begin
  487. dram_a <= mrd_val;
  488. dram_ba <= 2'b00;
  489. if (op_zero)
  490. if (init_op_ctr[0])
  491. state <= st_idle;
  492. else
  493. dram_cmd <= cmd_mrd;
  494. end
  495. st_idle:
  496. begin
  497. p1.wrack <= 1'bx;
  498. be_q <= 4'bxxxx;
  499. wdata_q <= 32'hxxxx_xxxx;
  500. // A data transaction starts with ACTIVE command;
  501. // a refresh transaction starts with REFRESH.
  502. // Port 0 has the highest priority, then
  503. // refresh, then port 1; a refresh transaction
  504. // is started opportunistically if nothing is
  505. // pending and the refresh counter is no less than
  506. // half expired.
  507. dram_a <= 13'h1bb;
  508. dram_ba <= 2'bxx;
  509. dram_d <= 16'hbbbb;
  510. if (do_rfsh)
  511. begin
  512. dram_cmd <= cmd_ref;
  513. state <= st_rfsh;
  514. end
  515. else if (p1.req)
  516. begin
  517. dram_cmd <= cmd_act;
  518. dram_a <= p1.addr[24:12];
  519. dram_ba <= p1.addr[11:10];
  520. col_addr <= p1.addr[9:0];
  521. p1.wrack <= |p1.wstrb;
  522. wdata_q <= p1.wd;
  523. be_q <= p1.wstrb;
  524. state <= st_rd_wr;
  525. end // if (p1.req)
  526. else if (wrq2[0])
  527. begin
  528. // Begin port 2 write
  529. dram_cmd <= cmd_act;
  530. dram_a <= a2[24:12];
  531. dram_ba <= a2[11:10];
  532. state <= st_wr2;
  533. end
  534. else
  535. begin
  536. dram_cmd <= cmd_desl;
  537. state <= st_idle;
  538. end
  539. end // case: st_idle
  540. st_rfsh:
  541. begin
  542. if (op_cycle == t_rfc-2)
  543. state <= st_idle;
  544. end
  545. st_rd_wr:
  546. begin
  547. dram_d_en <= p1.wrack;
  548. dram_dqm <= {2{p1.wrack}};
  549. dram_d <= 16'hcccc ^ {16{p1.wrack}};
  550. if (op_cycle < 7)
  551. dram_q <= op_cycle * 16'h1111;
  552. // Commands
  553. //
  554. // This assumes:
  555. // tRCD = 3
  556. // rRRD = 2
  557. // CL = 3
  558. // tRC = 10
  559. // tRAS = 7
  560. // tWR = 2
  561. // tRP = 3
  562. //
  563. case (op_cycle)
  564. 2: begin
  565. dram_a[10] <= 1'b0; // No auto precharge
  566. dram_a[8:0] <= col_addr[9:1];
  567. dram_cmd <= p1.wrack ? cmd_wr : cmd_rd;
  568. dram_d <= wdata_q[15:0];
  569. dram_dqm <= {2{p1.wrack}} & ~be_q[1:0];
  570. end
  571. 3: begin
  572. dram_d <= wdata_q[31:16];
  573. dram_dqm <= {2{p1.wrack}} & ~be_q[3:2];
  574. end
  575. 6: begin
  576. // Earliest legal cycle to precharge
  577. // It seems auto precharge violates tRAS(?)
  578. // so do it explicitly.
  579. dram_a[10] <= 1'b1; // One bank
  580. dram_cmd <= cmd_pre;
  581. end
  582. // CL+2 cycles after the read command
  583. // The +2 accounts for internal and I/O delays
  584. 7: begin
  585. p1.rstrb[0] <= ~p1.wrack;
  586. end
  587. 8: begin
  588. p1.rstrb[1] <= ~p1.wrack;
  589. end
  590. 9: begin
  591. state <= st_idle;
  592. end
  593. endcase // case (op_cycle)
  594. end // case: st_rd_wr
  595. st_wr2:
  596. begin
  597. // Streamable write from flash ROM
  598. dram_d <= wd2;
  599. dram_a[10] <= 1'b0; // No auto precharge/precharge one bank
  600. dram_a[8:0] <= a2[9:1];
  601. case (op_cycle)
  602. 0: begin
  603. wacc2 <= 1'b1;
  604. end
  605. 1: begin
  606. wacc2 <= 1'b1;
  607. end
  608. 2: begin
  609. dram_cmd <= cmd_wr;
  610. wacc2 <= 1'b1;
  611. wrq2_more <= wrq2[1];
  612. end
  613. 3: begin
  614. wacc2 <= 1'b1;
  615. end
  616. 4: begin
  617. dram_cmd <= cmd_wr;
  618. if (wrq2_more & ~(p1.req | do_rfsh))
  619. begin
  620. // Burst can continue
  621. wacc2 <= 1'b1;
  622. op_ctr[3:0] <= 4'd1;
  623. end
  624. end // case: 4
  625. 6: begin
  626. dram_dqm <= 2'b11; // This shouldn't be necessary?!
  627. end
  628. 7: begin
  629. // tWR completed
  630. dram_cmd <= cmd_pre;
  631. dram_dqm <= 2'b11;
  632. end
  633. 8: begin
  634. dram_dqm <= 2'b11;
  635. end
  636. 9: begin
  637. // tRP will be complete in the next cycle
  638. dram_dqm <= 2'b11;
  639. state <= st_idle;
  640. end
  641. endcase // case (op_cycle)
  642. end // case: st_wr2
  643. endcase // case(state)
  644. end // else: !if(~rst_n)
  645. endmodule // dram