Besides registers, RAL can also model memories using uvm_mem. This is useful
for modeling SRAMs, FIFOs, or any large memory blocks in your DUT.
class my_memory extends uvm_mem;
function new(string name = "my_memory");
// Arguments: name, size_in_words, data_width, access, has_coverage
// This creates a 1024-word memory, each word is 32 bits
super.new(name, 1024, 32, "RW", UVM_NO_COVERAGE);
endfunction
endclass
class my_reg_block extends uvm_reg_block;
my_memory mem;
virtual function void build();
// Create and configure memory
mem = my_memory::type_id::create("mem");
mem.configure(this);
// Add to address map at offset 0x2000
default_map.add_mem(mem, 'h2000);
lock_model();
endfunction
endclass
task body();
uvm_status_e status;
uvm_reg_data_t rd_data;
// === Single Word Access ===
// Write 0xDEADBEEF to offset 0 (address = 0x2000 + 0)
reg_model.mem.write(status, .offset(0), .value(32'hDEAD_BEEF));
// Read from offset 0
reg_model.mem.read(status, .offset(0), .value(rd_data));
// rd_data = 0xDEADBEEF
// === Burst Access (Multiple Words) ===
// Prepare data array to write
uvm_reg_data_t wr_burst[4];
wr_burst[0] = 32'h1111_1111;
wr_burst[1] = 32'h2222_2222;
wr_burst[2] = 32'h3333_3333;
wr_burst[3] = 32'h4444_4444;
// Burst write 4 words starting at offset 10
reg_model.mem.burst_write(status, .offset(10), .value(wr_burst));
// Prepare array to receive read data
uvm_reg_data_t rd_burst[4];
// Burst read 4 words starting at offset 10
reg_model.mem.burst_read(status, .offset(10), .value(rd_burst));
// rd_burst[0] = 0x11111111, rd_burst[1] = 0x22222222, ...
endtask
What the code does:
write(status, offset, value) - Writes a single word to the memory at the
specified offset
read(status, offset, value) - Reads a single word from the memory
burst_write(status, offset, data_array) - Writes multiple consecutive words
starting at offset
burst_read(status, offset, data_array) - Reads multiple consecutive words into
the array
Key Difference: Registers vs Memories
- Registers: Have defined fields, can be randomized, accessed by name
- Memories: Large arrays, accessed by offset, no field structure, support burst
operations