Saving 64KB/s from custom module with C program

Applications, development tools, FPGA, C, WEB
Post Reply
coreyb
Posts: 4
Joined: Fri Jul 15, 2022 4:25 am

Saving 64KB/s from custom module with C program

Post by coreyb » Fri Jul 22, 2022 5:27 pm

Hello,

I was wondering if anyone could help me figure out how to stream approximately 64KB/s from a custom module to a PC, or even put that data into the SD card of the Red Pitaya. I have a module which outputs to 32 registers (in the 0x406... mmap area) at approximately 500Hz, and I would like to operate the module for a long time (an hour or so), saving all the data acquired (so close to 250MB).

I was thinking about writing a C program to do this, but I'm a little lost in how to access the mapped memory from the FPGA with C. I understand that you can use a pointer to this memory, but to do this you need to generate a virtual address, and I'm somewhat confused by how to do that.

Code: Select all

void* virt_addr = map_base + (a_addr & MAP_MASK);
Trying to work through this, it seems the map_base is derived as follows:

Code: Select all

map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, addr & ~MAP_MASK);
I can see MAP_SIZE hardcoded, PROT_READ, PROT_WRITE, and MAP_SHARED seem to be built in parameters, I can see MAP_MASK defined, but I'm a little confused by the fd part. Ignoring that part for a moment, if I copy the above code into a C file, and then set a_addr = 0x40600000, would I be able to access that register using this?

Code: Select all

read_result = *((uint32_t *) virt_addr);
Or am I missing something? And could anyone help explain what's going on with fd?

This is the code I'm looking at: https://github.com/RedPitaya/RedPitaya/ ... /monitor.c

Thank you,
Corey

User avatar
M0JPI
Posts: 19
Joined: Wed Jun 15, 2022 8:06 pm
Location: Cumbria, UK

Re: Saving 64KB/s from custom module with C program

Post by M0JPI » Sat Jul 23, 2022 2:06 pm

Hi Corey,

I got the memory map working on Python, I only tried the examples in C, but it seems to be a widespread system call valid in most operating systems.

The definition is:
#include <sys/mman.h>
void *mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off);

The mmap() function shall establish a mapping between the address space of the process at an address pa for len bytes to the memory object represented by the file descriptor fildes at offset off for len bytes.
The file descriptor seems to be opened in the example here:

Code: Select all

if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) FATAL;
If the file descriptor is still -1 it didn't open successfully.
I think you should be able to change the offset to 0x40600000 if your programmable logic maps to that part of the memory.

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 12 guests