Build the block between the fast bus and the SRAM port: byte strobes from size and offset, a write that waits for its data, and one wait cycle for a read that follows a write.
Hardware context: The memories of ap_soc side by side: a ROM, a register file of flip-flops and the on-chip SRAM. Choosing memories for a chip and sizing a boot ROM
The SRAM of ap_soc has one port, and it samples everything on one clock edge. The bus does not work that way: it gives the address in one cycle and the write data in the next. Write the wrapper that makes the two fit.
The bench is the only manager, and your wrapper is the only subordinate. So an address phase is accepted at a rising edge when hsel is 1 and your own hreadyout is 1. Its data phase is the cycle after, and it lasts until an edge with hreadyout at 1.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
trial | 10 | input of each check |
Full specification
| SRAM pin | Meaning |
|---|---|
| ce | Chip enable. The SRAM does something at a rising edge only when ce is 1. |
| we | 1: write the strobed bytes of wdata into word addr. 0: read word addr. |
| be | One strobe for each byte of a write. Bit 0 is bits 7 to 0 of the word. |
| addr | A word address: the byte offset divided by four. |
| rdata | The word of the last read. It changes just after a read edge, and at no other time. |
A transfer of one byte uses the byte lane given by the two low bits of haddr. A transfer of two bytes uses lanes 0 and 1, or lanes 2 and 3. The bench keeps every transfer aligned. On a write, hwdata carries the data in those lanes and junk in the others. On a read, return the whole word: the manager picks its lanes.
When hsel is 0, the other bus inputs hold junk. Outside the data phase of a write, hwdata holds junk.
Examples
Example 1
Write, Idle, Read- Input
write word at 0x0010 with HWDATA 0x11223344, then idle, then read word at 0x0010; then look at word 4
- Output
cycles = 4, sram_accesses = 2, last_read = 0x11223344, stored_word = 0x11223344
Three items take four cycles: the last data phase follows the last address phase. The write lands in word 4, and the read returns it.
Example 2
One Byte, Then a Read at Once- Input
write byte at 0x0016 with HWDATA 0x55ab5555, then read word at 0x0014; then look at word 5
- Output
cycles = 4, sram_accesses = 2, last_read = 0xc0ab0005, stored_word = 0xc0ab0005
Only the byte at offset 2 of word 5 changes. The read follows the write at once, so it waits one cycle: two items, four cycles.
Example 3
Two Writes, Then a Read- Input
write two bytes at 0x001a with HWDATA 0xbeef7777, then write word at 0x0020 with HWDATA 0x01020304, then read word at 0x0018; then look at word 8
- Output
cycles = 5, sram_accesses = 3, last_read = 0xbeef0006, stored_word = 0x1020304
A write after a write needs no wait. The read after the second write does. The two high bytes of word 6 changed, and word 8 holds the whole word.
Constraints and Contract
- Each transfer must cause exactly one SRAM access: one edge with ce at 1. Keep ce at 0 on every other edge.
- A write is done at the edge that ends its data phase, with hreadyout at 1 throughout.
- A read whose address phase is accepted while no write is in its data phase must complete with no wait: hrdata is valid in the next cycle.
- A read whose address phase is accepted during the data phase of a write must wait exactly one cycle: hreadyout is 0 for one cycle, and then hrdata is valid. It must see the data of that write.
- While hreadyout is 0 the bus holds the next address phase. Do not accept it twice.
- hresetn is 0 for two clock edges at the start, and is sampled on the rising edge.
Hints
Hint 1
Work out the four strobes from hsize and the two low bits of haddr, in the address phase.
Hint 2
A write cannot be done in its address phase: the data is not there yet. Keep what you need for one cycle.
Hint 3
The port can do one thing at each edge. Ask what happens when a write is in its data phase and a read is in its address phase.
What the grader checks: Every size at every aligned offset; a read at once after a write, after an idle cycle and after two writes; a write right behind a stretched read; both ends of the memory; idle cycles with junk on the bus; random sequences of up to twelve items. Each check compares the cycle count, the number of SRAM accesses, the last read word and one stored word.
104 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 problems on this path