add first peripheral set
[shakti-peripherals.git] / src / lib / axi_addr_generator.bsv
1 package axi_addr_generator;
2 /*=== Project imports ===*/
3 import defined_types::*;
4 `include "instance_defines.bsv"
5 /*=======================*/
6
7 // This function is used by the slaves on the AXI4 bus to generate the sequential addresses in burst mode.
8 // the different modes supported are :
9 // FIXED: the same address is sent in all transactions. Typically used in polling modes.
10 // INCR: The address is simply incremented arlen number of times from the starting address.
11 // WRAP: This mode supports only 4 valid lengths: 2, 4 8 and 16 bursts. the increments happen in a wrap arouind fashion.
12 function Bit#(`PADDR) burst_address_generator(Bit#(8) arlen, Bit#(3) arsize, Bit#(2) arburst, Bit#(`PADDR) address);
13
14 // this variable will decide the index above which part of the address should
15 // not change in WRAP mode. Bits below this index value be incremented according
16 // to the value of arlen and arsize;
17 Bit#(3) wrap_size;
18 case(arlen)
19 3: wrap_size= 2;
20 7: wrap_size= 3;
21 15: wrap_size=4;
22 default:wrap_size=1;
23 endcase
24
25 Bit#(`PADDR) new_address=address+(('b1)<<arsize); // this is address will directly be used for INCR mode.
26 Bit#(`PADDR) mask;
27 mask=('1)<<(arsize+wrap_size); // create a mask for bits which will remain constant in wrap mode.
28 Bit#(`PADDR) temp1=address& mask; // capture the constant part of the address in WRAP mode.
29 Bit#(`PADDR) temp2=new_address& (~mask); // capture the incremental part of the address in WRAP mode.
30
31 if(arburst==0) // FIXED
32 return address;
33 else if(arburst==1)begin // INCR
34 return new_address;
35 end
36 else begin // WRAP
37 return temp1|temp2; // create the new address in the wrap mode by ORing the masked values.
38 end
39 endfunction
40 endpackage