Hello, using Verilog and I am creating a 'memory', e.g.:
Code:
reg [7:0] registers [0:4];
This memory is read/write accessible via a bus, and some of the bits will be read only and some will be write only.
I am trying to construct a "core-wide" set of definitions to use throughout my core so I can easily change the memory descriptions in one place. For example I have a file RegisterDefinitions.v containing:
Code:
`define REG_NUMBEROFREGISTERS 4
then in my registers module:
Code:
reg [7:0] registers [0:`REG_NUMBEROFREGISTERS];
How can I define the read/write masks in a generic way, so that I can easily add a new mask if I add a new register? For example in C I would do:
then when accessing register n I would OR with it ReadMasks[n].
I know I can do:
Code:
reg [7:0] ReadMasks[0:`REG_NUMBEROFREGISTERS];
always @ (posedge clk) begin
if (!nReset) begin
// initialize ReadMasks here without knowing in advance the number of registers and
// use masks that have been `defined
end
end