W2.5.1 Bank the Memory

MediumImplementIcarus · browser samples / server checksReview the topic

Write the controller of a memory built from eight sleeping banks. It needs one chip select per access, a sleep timer per bank, and a full-length wake.

Hardware context: Banked memory with chip selects and sleep requests. Wake only the bank an access needs while honouring the wake latency.

A 512-word data memory is built from eight bank macros of 64 words. Each macro has a chip select and a sleep pin. While sleep is high it keeps its data and leaks less, but it cannot be accessed.

After its sleep pin falls, a macro needs WAKE = 3 rising edges with sleep low before the next access. An access too early, or while sleep is high, is illegal: the macro ignores a write and returns unknown read data.

Write memctl. It takes one request at a time and enables only the addressed bank. It puts a bank to sleep after IDLE = 4 idle edges and wakes it on demand. Lesson W2.5 measured the trade; here the timer is fixed, and the budgets check your logic.

Signals in the Timeline

SignalWidthRole
clk1stimulus, the same for every design
req1stimulus, the same for every design
ready1stimulus, the same for every design
addr9stimulus, the same for every design
cs8stimulus, the same for every design
sleep8stimulus, the same for every design
rvalid1stimulus, the same for every design
Full specification
The module you write (keep the name, the parameters and the ports)
module memctl #(parameter int WAKE = 3, parameter int IDLE = 4) (
  input  logic        clk,
  input  logic        rst_n,      // asynchronous, active-low
  input  logic        req,        // a request, held until ready is 1 at a rising edge
  input  logic        we,         // 1: write, 0: read
  input  logic [8:0]  addr,
  input  logic [7:0]  wdata,
  output logic        ready,      // the request is taken at this rising edge
  output logic        rvalid,     // read data valid: the cycle after a read was taken
  output logic [7:0]  rdata,
  output logic [7:0]  cs,         // chip select of each bank
  output logic [7:0]  sleep,      // sleep pin of each bank
  output logic        bwe,        // shared bank write enable
  output logic [5:0]  baddr,      // shared bank address
  output logic [7:0]  bwdata,     // shared bank write data
  input  logic [63:0] brdata      // read data of bank i at bits 8i+7 .. 8i, one cycle after its access
);
  // your design
endmodule
RuleDefinition
Bank of a requestaddr[8:6]. The word inside the bank is addr[5:0].
Requestreq, we, addr and wdata stay the same until a rising edge where ready is 1. That edge takes the request.
Chip selectcs has one bit high, the addressed bank, at the edge that takes a request, and none at any other edge. bwe, baddr and bwdata carry the request.
Read dataA macro shows its word on brdata one cycle after the access. rvalid is 1, and rdata carries that word, in the cycle after the edge that took the read. rvalid is 0 in every other cycle.
SleepAfter reset every bank is awake (sleep low). An awake bank (wake complete) sleeps right after IDLE edges in a row with no request addressed to it.
WakeA request to a sleeping bank lowers its sleep pin. The bank may be accessed once sleep has been low at WAKE rising edges; ready stays 0 until then.
Neversleep high while a request to that bank waits; cs to a sleeping or waking bank.

Each case resets the controller and makes 160 requests from a seed. A home bank takes most of them and changes every 40 requests. Gaps are 0 to 2 idle cycles, and one gap in 8 is a longer pause. The case input gives the share and the pause.

The fixture checks every read against a model of the memory. At every edge it counts the chip selects and any illegal access. It also counts awake-idle bank-edges: banks with sleep low that are not selected. The result shows the requests done and six flags. They are data_ok, no_violation, one_bank (as many chip selects as requests), idle_ok, time_ok and all_done.

Examples

Example 1

A Program That Stays in One Bank
Input
14 in 16 requests to the home bank, pauses of 24 cycles; budgets: 423 awake-idle bank-edges, 844 cycles
Output
data_ok = yes, no_violation = yes, one_bank = yes, idle_ok = yes, time_ok = yes, all_done = yes, requests_done = 160

The home bank stays awake through the short gaps. The other banks fall asleep four edges after their last use and stay asleep. Never sleeping would leave about ten times more awake-idle bank-edges.

Example 2

Pauses of Only 3 Cycles
Input
14 in 16 requests to the home bank, pauses of 3 cycles; budgets: 399 awake-idle bank-edges, 443 cycles
Output
data_ok = yes, no_violation = yes, one_bank = yes, idle_ok = yes, time_ok = yes, all_done = yes, requests_done = 160

A 3-cycle pause is shorter than the timer, so the home bank never sleeps in it. A timer that fired after 3 idle edges would add a 3-edge wake to every pause and miss the time budget.

Example 3

Always the Home Bank, Pauses of 6 Cycles
Input
16 in 16 requests to the home bank, pauses of 6 cycles; budgets: 1358 awake-idle bank-edges, 1075 cycles
Output
data_ok = yes, no_violation = yes, one_bank = yes, idle_ok = yes, time_ok = yes, all_done = yes, requests_done = 160

Every pause outlasts the timer, so the home bank sleeps and wakes again and again. The budget comes from the same policy, so the wakes are expected here; each one must wait the full WAKE edges.

Constraints and Contract

  • The inputs are known 0/1 values. A request is held until it is taken.
  • Keep the module name, the parameters WAKE and IDLE, and the ports. The fixture sets WAKE = 3 and IDLE = 4.

Hints

Hint 1

Give each bank its own small state: asleep or not, edges since its sleep pin fell, and idle edges in a row.

Hint 2

ready depends on the addressed bank only: it is awake and its wake count has reached WAKE. Then cs is that bank's bit when ready is 1.

Hint 3

A bank with a request waiting is not idle, even while it is waking. Remember the bank of a read for one cycle, so rdata picks the right macro.

What the grader checks: Thirteen traffic scripts of 160 requests run with different home-bank shares and pauses. Eight fixture-owned bank macros flag every illegal access. Reads are checked against a model of the memory. The idle and time budgets come from the reference policy (IDLE = 4) with 25 % and 5 % margins. So they check the policy, not one exact count. Leakage and access energy are not modelled: the macro is a timing model with no datasheet behind it.

13 checks on Icarus · browser samples / server checks. 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 1 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

A Program That Stays in One Bank

Input
14 in 16 requests to the home bank, pauses of 24 cycles; budgets: 423 awake-idle bank-edges, 844 cycles
Expected output
data_ok = yes, no_violation = yes, one_bank = yes, idle_ok = yes, time_ok = yes, all_done = yes, requests_done = 160

The home bank stays awake through the short gaps. The other banks fall asleep four edges after their last use and stay asleep. Never sleeping would leave about ten times more awake-idle bank-edges.

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

Icarus · browser samples / server checks