Programming SoC

Just about everything about Red Pitaya
Post Reply
Jreberc
Posts: 1
Joined: Wed Sep 02, 2015 1:12 pm

Programming SoC

Post by Jreberc » Thu Dec 03, 2015 5:08 pm

Hi!

I just started with programming of my RP. I know how to write a code in C and upload it to RP, and i know how to write code in Vivado and then upload it to FPGA. Currently I am working on the code for FPGA, but I would like to do some calculations in linux part of the processor. And here I have a problem, since I don't exactly understand how FPGA is connected to the other part of the chip, so how can I establish connection between these two parts of the chip. So can someone tell me how this works. or at least point me to a nice explanation of this.

Regards, s57jr

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: Programming SoC

Post by Nils Roos » Thu Dec 03, 2015 6:21 pm

Provided you don't want to move large amounts of data or achieve particularly high speeds, the easiest way to communicate between the ARM cores and the FPGA is to tie your FPGA module to one of the memory mapped "system bus" regions.

If you take a look at the housekeeping module and search for "System bus" you will find the connections you need to add to your module (following the first match) and the code that handles the transfer in read and write directions (following the second match). It should be easy to adapt that for your own needs.
(I assume you already have clock and reset signals in your module)

Then you'll need to create the connection to one of the free system bus regions (see "unused system bus slave ports" in red_pitaya_top.v). Delete the dummy signals for your chosen region and connect them instead to your module's new signals. You can copy the code almost verbatim from the i_hk instance definition, just substitute your region number for the region 0 that i_hk uses.

The communication is always initiated from the application's side, either by reading from the memory region or by writing to it. Open "/dev/mem", mmap() your newly created region (for region nr 5, use the address 0x40500000, size is always 0x00100000) and use the resulting pointer for access. All accesses must be 4-byte aligned and 32 bits wide, no matter what width you actually implemented in the logic.

quick and dirty demo code:

Code: Select all

// preparation
fd = open("/dev/mem", O_RDWR);
mapped_io = mmap(NULL, 0x00100000UL, PROT_WRITE | PROT_READ, MAP_SHARED, fd, 0x40500000UL);

// write to 0x4050000c, triggers "if (sys_addr[19:0]==20'h0c) ... <= sys_wdata;"
*(unsigned long *)(mapped_io + 0x0000c) = var;

// read from 0x4050000c, triggers "20'h0000c: begin sys_ack <= sys_en; sys_rdata <= ...; end"
var = *(unsigned long *)(mapped_io + 0x0000c);
Happy coding :mrgreen:

Post Reply
jadalnie klasyczne ekskluzywne meble wypoczynkowe do salonu ekskluzywne meble tapicerowane ekskluzywne meble do sypialni ekskluzywne meble włoskie

Who is online

Users browsing this forum: No registered users and 105 guests