dve12
March 14, 2018, 2:26am
1
Hi,
I have defines as mentioned below.
`define MEM_BANK0_STADDR 1234
`define MEM_BANK0_ENDADDR 6789
and so on till bank20
now i created another define,as i wanted to rewsue it for different memory banks.
`define addr(i) \
addr = $urandom_range(`MEM_BANK``i``_STADDR,`MEM_BANK``i``_ENDADDR)
where i takes integer values from 0 to 20
when i do addr(0) its giving error and interpreting as addr = $urandom_range(
MEM_BANKi_STADDR,`MEM_BANKi_ENDARR)
Here i expect i to be replaced by 0.but this is not happening.Please suggest how to proceed.
In reply to sra1dreddy :
It would help if you show the error message.
Instead of addr(0), do you mean you have
addr(i) in a for loop? That will not work as macros get expanded before any other code gets parsed.
dve12
March 14, 2018, 6:09pm
3
Yes Dave.
Iam calling this macro inside a task.
as shown below.
for(int i =0; i<10; i++)
begin
gen_addr(i); //this is the task
end
task gen_addr(input int i);
`addr(i);
endtask
If this do not work, is there any alternate way to achieve this functionality?
Regards,
Sravan
In reply to sra1dreddy :
It is always better to use arrays than a series of identifiers. You can either create two separate arrays for the starting and ending addresses, or create an array of a structure
typedef struct {int STADDR,ENDADDR;} range_t;
parameter range_t mem_bank[21] = '{ 0:'{'h0010,'h001F},
1:'{'h0020,'h002F},
2:'{'h0020,'h002F},
19:'{'h0100,'h010F},
20:'{'h0200,'h020F} };
function void gen_addr(input int i);
addr = $urandom_range(mem_bank[i].ENDADDR, mem_bank[i].STADDR);
endfunction