Friday, January 1, 2016

Creating an Custom AXI4 Slave Component in Vivado

If we have a custom VHDL code block and want to control and access this block from Microblaze or other AXI4 standart master, we'll see how to create a Custom peripheral in this tutorial:)

2x1 MUX(only process part..)
Input and port widths can be any size. I used 8 bits ports.
   process (a,b,sel)  
   begin  
    case sel is   
      when '0' => c <= a;  
      when '1' => c <= b;  
      when others => c <= a;  
    end case;  
   end process;  



First from Tools-> Create and Package New IP in Vivado we will create a new AXI4 Lite interface peripheral. In this case default 4 32 bits registers enough for us.
We give mux_wind name to new peripheral. 2 files created in the project. One of them top entity , and the other which include AXI interface communication codes. We will add MUX code to second mentioned.

Our Mux block works that the inputs and select will come from Microblaze and the Mux output will be connected the leds on the board.

Component instantiation:
      -- Add user logic here  
 mux_ins : mux_wind  
 port map(  
 sel => slv_reg1(0),  
 a => slv_reg0(7 downto 0),  
 b => slv_reg0(15 downto 8),  
 c => mux  
 );  
      -- User logic ends  

Component declaration:
      component mux_wind is   
   port (sel: in std_logic;  
   a : in std_logic_vector (7 downto 0);  
   b : in std_logic_vector (7 downto 0);  
   c : out std_logic_vector(7 downto 0)  
   );  
   end component mux_wind;  

After packaging our custom ip we should add it to our block design and connect it to Microblaze using AXI Interconnect.

 To launch SDK and write c code first we implement the block design and generate its bitstream file.

We have to add 2 library in the below to our source code.
 #include "xparameters.h"  
 #include "xil_io.h"  

 
The slave registers are 32 bits widths. There are a lot of way to read&write registers. 2 ways of them;

1) Also we have 32 bits pointer object. If we increase one we can access next slave register.
2) If we go four byte(8 bit) after register we can access next slave register too.

 int *cust_ptr = (int *)cust_add;  
 int data = 0x00330044;  
 int sw1 = 0x00000000;  
 int sw2 = 0x00000001;  
  *(cust_ptr) = data;  
  *(cust_ptr+1)= sw1;  
  //OR  
  Xil_Out32(cust_add,data);  
  Xil_Out32(cust_add+4,sw2);  

thanks..

No comments:

Post a Comment