How to read & write to fifo from Microblaze?

3.3k views Asked by At

I have made my project and i have added a microblaze processor to my project.I have also added a H/W core that has a FIFO to my project.I want to read and write to the FIFO from the processor(by writing a c code in SDK).What should I do?

2

There are 2 answers

0
N. Mos. On BEST ANSWER

I have used Microblazed with customs IP's that use FIFO's to communicate with the Microblaze (EDK 14.7).

When you set up the Microblaze, it asks you to specify some "Software Registers". This software registers are located at the "user_logic.vhd" that is created automatically when you try to "Import as Peripheral" your custom IP (for example your FIFO). Choose the number of software registers that is appropriate for your project and connect them (in the user_logic.vhd) with the signaling of your FIFO (Inpout/Output/Empty/Full), in order to control the contents of the FIFO (Read and Write transactions). When you generate the bitstream of your hardware implementation and download it to your FPGA, in your project file there will also be created a file named "drivers" which contains all the library files with implemented functions to Read and Write at the software registers of the Microblaze.

Now you can import those drivers in your C project in the SDK enviroment, in order to use those automatically implemented functions and access the Software Registers (and through them, your FIFO).

Nassos

1
Paebbels On

Normally an I/O device, like your FIFO, is memory-mapped to one address or to a memory-address range.

If it's mapped to one address you should use multiple read or write instructions to the same address like this:

// example address for the FIFO
void myFifo = 0x0000AB00;
// write
*myFifo = dataToWrite;
//read
dataFromFifo = *myFifo;

If your FIFO is mapped to an address-range, then myFifo would represent the FIFO's base address and you can use memcpy to copy multiple bytes/words to the FIFO.

The address mapping can be done by this pseudo code:

  1. single address:

    fifo_write <= '1' when (bus_address = x"0000AB00") and (bus_we = '1') else '0';
    
  2. address-range:

    fifo_write <= '1' when (bus_address(31 downto 8) = x"0000AB") and (bus_we = '1') else '0';
    

In case 2. the lowest 8 bits are don't care and any write access is translated to a FIFO write operation.