Running multiple C programs

Applications, development tools, FPGA, C, WEB
Post Reply
powle
Posts: 2
Joined: Thu Mar 31, 2016 5:24 pm

Running multiple C programs

Post by powle » Thu Apr 14, 2016 5:24 pm

Hey there,

I've tried out the example C programs and played a little bit around.
My goal is to measure, how much a program slows down, if I runs multiple at once. At first I started the following one:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include "redpitaya/rp.h"

int main (int argc, char **argv) {

    // Initialization of API
    if (rp_Init() != RP_OK) {
        fprintf(stderr, "Red Pitaya API init failed!\n");
        return EXIT_FAILURE;
    }

    rp_DpinSetDirection(RP_DIO1_N, RP_OUT);

    while (1){
        rp_DpinSetState(RP_DIO1_N, RP_HIGH);
        rp_DpinSetState(RP_DIO1_N, RP_LOW);
    }

    // Releasing resources
    rp_Release();

    return EXIT_SUCCESS;
}
It takes ~0.5us to toggle the state of the pin. My idea was to start a second program regarding DIO1_P and start both with

Code: Select all

LD_LIBRARY_PATH=/opt/redpitaya/lib ./<DIO1_P> &
LD_LIBRARY_PATH=/opt/redpitaya/lib ./<DIO1_N> &
In my understanding of Linux, both programs should be scheduled to run next to each other and the remaining processes.
But in my case only DIO1_N toggles its state and DIO1_P remains high.

Thanks in advance :)

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

Re: Running multiple C programs

Post by Nils Roos » Thu Apr 14, 2016 5:57 pm

Hi,

what's happening is that rp_Init() resets all configuration registers to defaults values, and that includes setting all GPIOs to input. So the second process reverses all configurations the first process set up. Or, even worse, it races the first process for them.

It is in general not recommended to call the RP API from multiple processes concurrently, and particularly not when the processes use the same functional units - in this case the housekeeping module which controls the GPIOs.
Competing accesses to shared resources need careful synchronization and the RP API does not provide that.

powle
Posts: 2
Joined: Thu Mar 31, 2016 5:24 pm

Re: Running multiple C programs

Post by powle » Thu Apr 14, 2016 6:08 pm

That makes sense :)
But what if I have different applications, where I, at first, want to observe an input and react to it by toggling an output, but later add a functionality (by starting the process from command line) in using another pin.
Do I have to write it in a single code, which runs exclusively and pays attention to every eventuality?

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

Re: Running multiple C programs

Post by Nils Roos » Thu Apr 14, 2016 6:44 pm

One option is to set up one process that performs all interactions with the RP API. Have this process maintain some kind of instruction queue that can be filled by other processes and is sequentially executed. The scpi-server is a good starting point, but it does not guarantee absolutely conflict-free accesses to the hardware.

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