G8.9.2 Repair a RAM with a Spare Row

MediumImplementIcarus Verilog + Yosys · serverReview the topic

Steer every access to a bad row into a spare row, as the fuses of a repaired memory do.

Hardware context: A controller's state RAM next to a radio, with each 8-bit word stored as a 13-bit SECDED codeword. Steer the accesses of a fused bad row into a spare row, and return each read from the RAM that served it.

Production test found a row of dead cells in a RAM. The chip has one spare row. Fuses now record which row is bad, so the chip can be sold.

This is an Implement problem. Write row_repair, the logic between the address bus and the two RAMs. Every access to the fused row must go to the spare row instead, and every other access to the main RAM.

Both RAMs read at the clock edge, so the word comes back one edge later. rdata must come from the RAM that did the read.

Signals in the Timeline

SignalWidthRole
addrs192input of each check
Full specification
The module you write (keep the name and the ports)
module row_repair (
  input  logic       clk,
  input  logic       we,          // 1: write wdata to word addr at the next rising edge; 0: read it
  input  logic [4:0] addr,        // {row, col}
  input  logic [7:0] wdata,
  output logic [7:0] rdata,       // after a read edge: the word read
  input  logic       fuse_en,     // 1: a row is repaired (set at test, constant afterwards)
  input  logic [2:0] fuse_row,    // the row that the spare replaces
  // the two RAMs
  output logic       main_we,
  output logic [4:0] main_addr,
  output logic       spare_we,
  output logic [1:0] spare_col,
  output logic [7:0] wd,          // write data to both RAMs
  input  logic [7:0] main_q,
  input  logic [7:0] spare_q
);
  // your design
endmodule
The two RAMs, given (the test owns them)
// ram32x8: the main RAM, 8 rows of 4 words (a model). Word {row, col} is at addr = {row, col}.
// The fixture can mark one row bad: its cells read 00 and ignore every write.
module ram32x8 (input logic clk, we, input logic [4:0] addr, input logic [7:0] d, output logic [7:0] q);
  logic [7:0] mem [32];
  logic       bad_en = 1'b0;
  logic [2:0] bad_row = 3'd0;
  wire        bad = bad_en && addr[4:2] == bad_row;
  always @(posedge clk)
    if (we) begin if (!bad) mem[addr] <= d; end
    else q <= bad ? 8'h00 : mem[addr];
endmodule
// ram4x8: the spare row, 4 words (a model). It counts its writes.
module ram4x8 (input logic clk, we, input logic [1:0] col, input logic [7:0] d, output logic [7:0] q);
  logic [7:0] mem [4];
  int         writes = 0;
  always @(posedge clk)
    if (we) begin mem[col] <= d; writes++; end
    else q <= mem[col];
endmodule
RuleDefinition
Repaired rowWith fuse_en = 1, an address whose row addr[4:2] equals fuse_row goes to the spare, at column addr[1:0].
Other rowsEvery other access goes to the main RAM at addr. The main RAM is not written for the repaired row.
No fuseWith fuse_en = 0 every access goes to the main RAM, and the spare is never written.
ReadA read edge (we = 0) loads both RAMs. In the next cycle rdata is the word of the RAM that the access was steered to.

Each test sets the fuse, fills both RAMs, then runs 24 reads and writes, one per cycle. Each read is checked in the next cycle, just before the edge, while the next access is already on the inputs. The result has two fields.

FieldMeaning
spare_misuse1 if the spare was written while fuse_en was 0.
wrong_readsHow many reads returned a wrong word.

Examples

Example 1

Row 5 Is Bad and Fused
Input
fuse row 5, row 5 is bad: read 20, read 21, read 22, read 23, write b4 to 20, write b5 to 21, write b6 to 22, write b7 to 23, read 20, read 21, read 22, read 23, read 19, read 24, read 0, read 31, read 16, read 17, read 18, read 19, read 22, read 21, read 20, read 23
Output
spare_misuse = 0, wrong_reads = 0, operations = 24

Words 20 to 23 live in row 5, whose cells read 00. Steered to the spare, they read their real values, and a write to them sticks.

Example 2

Alternate Between the Spare and the Main RAM
Input
fuse row 2, row 2 is bad: read 8, read 0, read 9, read 1, read 10, read 2, read 11, read 3, write 18 to 8, write 10 to 0, read 8, read 0, read 12, read 9, read 13, read 10, read 4, read 11, write 1b to 11, read 11, read 3, read 11, read 15, read 7
Output
spare_misuse = 0, wrong_reads = 0, operations = 24

Reads go to the spare and to the main RAM in turn. rdata must follow the RAM that read at the last edge, not the address of this cycle.

Example 3

No Fuse
Input
no fuse: write 3c to 12, write 3d to 13, write 3e to 14, write 3f to 15, read 12, read 13, read 14, read 15, write 00 to 0, write 01 to 1, write 02 to 2, write 03 to 3, read 0, read 1, read 2, read 3, read 12, read 1, read 14, read 3, read 31, read 16, read 13, read 15
Output
spare_misuse = 0, wrong_reads = 0, operations = 24

Nothing is repaired. Row 3 is a normal row, and the spare must not be written.

Constraints and Contract

  • The inputs are known 0/1 values. They change while the clock is low. fuse_en and fuse_row stay constant during a test.
  • Keep the module name and the ports. Do not store words in the glue: the test reads the RAMs.

Hints

Hint 1

One compare decides everything: fuse_en and the row bits addr[4:2] equal to fuse_row.

Hint 2

Gate the two write enables with that compare. The spare only needs the column bits.

Hint 3

The read word arrives one edge later, so remember the compare in a flip-flop and use the stored value to pick rdata.

What the grader checks: Four directed and eight seeded scripts of 24 operations, with and without a fuse. Reads are compared with a JavaScript model of a perfect memory, and the spare counts its writes. Column repair, several spare rows and the fuse programming itself are outside this problem.

The submitted design must synthesize with 0 latches and no combinational loop. Counts come from the pinned open-source synthesis flow. They are proxies for logic size and depth, not physical area or timing.

12 checks on Icarus Verilog + Yosys · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 2 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

Row 5 Is Bad and Fused

Input
fuse row 5, row 5 is bad: read 20, read 21, read 22, read 23, write b4 to 20, write b5 to 21, write b6 to 22, write b7 to 23, read 20, read 21, read 22, read 23, read 19, read 24, read 0, read 31, read 16, read 17, read 18, read 19, read 22, read 21, read 20, read 23
Expected output
spare_misuse = 0, wrong_reads = 0, operations = 24

Words 20 to 23 live in row 5, whose cells read 00. Steered to the spare, they read their real values, and a write to them sticks.

Run samples executes all 3 public checks. Check all tests runs 12 checks on the server.

Icarus Verilog + Yosys · server