Web application with own FPGA funcionalities

Applications, development tools, FPGA, C, WEB
TheGeri
Posts: 32
Joined: Wed Sep 13, 2023 12:46 pm

Web application with own FPGA funcionalities

Post by TheGeri » Fri Oct 11, 2024 7:02 pm

Good afternoon.

If you want to create new functionalities within the FPGA, what would be the best way to be able to use them from the web application interface? For now I was thinking of calling the FPGA functionalities through registers that are not being used. In the Red Pitaya examples I have managed to use a C code (the moving average example in the tutorials) and the monitor tool to control those registers and work with my new functionality, but how could I now link it to the web interface? Should I create new APIs? In this case, how could I do it?

If you can help me it will be very helpful. Thank you very much in advance! :)

TheGeri
Posts: 32
Joined: Wed Sep 13, 2023 12:46 pm

Re: Web application with own FPGA funcionalities

Post by TheGeri » Mon Oct 14, 2024 7:43 am

Good morning,

Following with my question and because this way maybe it is clearer. If for example I want to modify the C code of this example: https://redpitaya.readthedocs.io/en/lat ... EDbut.html How could I do it to call a specific FPGA register from that code?

Thanks very much in advance,

TheGeri
Posts: 32
Joined: Wed Sep 13, 2023 12:46 pm

Re: Web application with own FPGA funcionalities

Post by TheGeri » Thu Oct 17, 2024 12:47 pm

Good afternoon,

To try to figure out how to do it I have done the following:

I have modified the code of the Led Counter FPGA example (see https://redpitaya-knowledge-base.readth ... unter.html) so that with a register I can decide whether to run the LED counter or stop it. I am using the register 0x40300054 and it works, if I set it to 1 using the monitor command from the CMD the process stops and it is set to 0 the counter process continues.

After this, I have followed the example here as template: https://redpitaya.readthedocs.io/en/lat ... EDbut.html so I can set this register from here with the following code:

Code: Select all

#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/sysinfo.h>
#include <sys/mman.h>
#include "main.h"




//Parameters
CBooleanParameter ledState("LED_STATE", CBaseParameter::RW, false, 0);

int fd;
void *cfg;
int led_open;


const char *rp_app_desc(void)
{
    return (const char *)"Red Pitaya LED control.\n";
}


int rp_app_init(void)
{
    fprintf(stderr, "Loading LED control\n");

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

int rp_app_exit(void)
{
    fprintf(stderr, "Unloading LED control\n");

    rpApp_Release();

    return 0;
}


int rp_set_params(rp_app_params_t *p, int len)
{
    return 0;
}


int rp_get_params(rp_app_params_t **p)
{
    return 0;
}


int rp_get_signals(float ***s, int *sig_num, int *sig_len)
{
    return 0;
}

void UpdateSignals(void){}


void UpdateParams(void){}


void OnNewParams(void) 
{

 ledState.Update();

    if (ledState.Value() == false)
    {
        led_open = 0;

    }
    else
    {
        led_open = 1;
    }

 if((fd = open("/dev/mem", O_RDWR)) < 0)
    {
        perror("open");
    //  return EXIT_FAILURE;   
    }

    cfg = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40300054);

    *((uint32_t *)(cfg + 0)) = (0x01 & led_open);   // Control led counter process

    munmap(cfg, sysconf(_SC_PAGESIZE));
    //return 0;

}


void OnNewSignals(void){}

void PostUpdateSignals(void){}

Once I load the web browser of the led application and manually load the FPGA design I can see how the counter leds work but from the button I can't control the register. I think I am doing something wrong from this C code. Where do you think the problem could be here?

Thanks very much in advance!!


TheGeri
Posts: 32
Joined: Wed Sep 13, 2023 12:46 pm

Re: Web application with own FPGA funcionalities

Post by TheGeri » Fri Oct 18, 2024 2:40 pm

Good afternoon and thank you for your reply 33dnp.

I have looked at both the documentation and the examples. In fact the code I provided above is based on one of the examples. From what I understand in these examples specific C APIs are used to communicate with the FPGA. In my case, I would like to be able to control the FPGA registers (registers that are not used, for example) directly from the C code and that is what I have not been able to achieve yet.

Thanks again and kind regards,

33dnp
Posts: 39
Joined: Fri Jul 17, 2020 6:00 am

Re: Web application with own FPGA funcionalities

Post by 33dnp » Mon Oct 21, 2024 4:40 am

And I am sure that the required FPGA is loaded before launching the web application?

FPGA is loaded via this configuration file when the web module is launched.
You need to specify your FPGA there.

https://github.com/RedPitaya/RedPitaya- ... ed/fpga.sh

Here is an example of loading a third-party FPGA.
Note that the FPGA must be in bin format, not bit.
https://github.com/RedPitaya/red-pitaya ... ar/fpga.sh

TheGeri
Posts: 32
Joined: Wed Sep 13, 2023 12:46 pm

Re: Web application with own FPGA funcionalities

Post by TheGeri » Mon Oct 21, 2024 9:40 am

Good morning,

Thank you very much for your answer. Yes, maybe I wasn't doing this right. I've made the changes but I think I'm still not doing something right. This is the code now in fpga.sh:

Code: Select all

rmdir /configfs/device-tree/overlays/Full 2> /dev/null
rm /tmp/loaded_fpga.inf 2> /dev/null
sleep 0.5s
/opt/redpitaya/bin/fpgautil -b /opt/redpitaya/www/apps/myFirstApp/Led_counter.bit.bin -o /opt/redpitaya/www/apps/myFirstApp/Led_counter.dtbo -n Full
Here are the files inside myFirstApp folder, I think the dtbo file is not being created, I don't know why:

Code: Select all

/opt/redpitaya/www/apps/myFirstApp# ls
controllerhf.so fpga.conf index.html js Makefile
css fpga.sh info Led_counter.bit.bin src
If I just execute in fpga.sh the following line:

Code: Select all

/opt/redpitaya/bin/fpgautil -b /opt/redpitaya/www/apps/myFirstApp/Led_counter.bit.bin 
I see that the leds start to move but I can't control the registers from the button either. I don't know what I must be doing wrong.

In any case, if from the cmd I run the following line once the application has been loaded from the web browser I am not able to change any FPGA register so maybe I am missing something else in the C code:

Code: Select all

redpitaya> /opt/redpitaya/bin/fpgautil -b Led_counter.bit.bin
To clarify I am working with a 2.00 version of the OS. Thanks very much in advance, much appreciate it.

33dnp
Posts: 39
Joined: Fri Jul 17, 2020 6:00 am

Re: Web application with own FPGA funcionalities

Post by 33dnp » Tue Oct 22, 2024 7:42 am

I can't say what exactly is wrong with you.
Try to first make a console application for working with registers and make sure that it works, and then integrate it into the server part.

P.S. When working with web applications, there is a log where messages are output. It can help you in development.
tail -f /var/log/redpitaya_debug.log

TheGeri
Posts: 32
Joined: Wed Sep 13, 2023 12:46 pm

Re: Web application with own FPGA funcionalities

Post by TheGeri » Tue Oct 22, 2024 10:10 am

Good morning,

Thanks for your reply. I have followed your advice and it seems to me that the error was when using the register 0x40300054. Now if I use 0x40300000 it works perfectly. I don't know why.

Kind regards,

TheGeri
Posts: 32
Joined: Wed Sep 13, 2023 12:46 pm

Re: Web application with own FPGA funcionalities

Post by TheGeri » Tue Oct 22, 2024 2:39 pm

Good afternoon,

Now that I have accomplished this, my goal is to modify the FPGA to have more functionality within the scopegenpro application interface. I have modified the fpga.sh of the scopegenpro application (note that the Led_counter.bit.bin is in the root):

Code: Select all

/opt/redpitaya/bin/fpgautil -b /root/Led_counter.bit.bin
When I modify the .sh file the application of the scope of the web interface stays all the time loading and from the cmd I see this message:

Code: Select all

Calling application: start
Problem running /opt/redpitaya/sbin/rmoverlay.sh
Loading specific FPGA from: '/opt/redpitaya/fpga/fpga/fpga_0.94.bit'.
Loading application: '/opt/redpitaya/www/apps/scopegenpro/controllerhf.so'
Loading scope version 2.00-35-aff683518.
[E] {sensors.c:sens_GetValueFromFile}(11) Can't open /sys/devices/soc0/axi/83c00000.xadc_wiz/iio:device1/in_temp0_offset
2024/03/06 11:18:18 [alert] 251#0: worker process 2729 exited on signal 11
From the redpitaya_debug_log I have the following:

Code: Select all

Calling application: apps
stop_ws_server()
Cannot resolve 'ws_set_params_interval' function.
Cannot resolve 'ws_set_signals_interval' function.
Cannot resolve 'ws_get_params_interval' function.
Cannot resolve 'ws_get_signals_interval' function.
Cannot resolve 'ws_set_params' function.
Cannot resolve 'ws_get_params' function.
Cannot resolve 'ws_set_signals' function.
Cannot resolve 'ws_get_signals' function.
Cannot resolve 'ws_gzip' function.
stop_ws_server()
/opt/redpitaya/www/apps/scpi_manager/controllerhf.so does not exist.
stop_ws_server()
Cannot resolve 'ws_set_params_interval' function.
Cannot resolve 'ws_set_signals_interval' function.
Cannot resolve 'ws_get_params_interval' function.
[...]
Actually there is no change in the FPGA file, I just compiled the v0.94 from the following Github:
https://github.com/RedPitaya/RedPitaya-FPGA

If for example I execute the following line :

Code: Select all

 fpgautil -b Led_counter.bit.bin
Time taken to load BIN is 36.000000 Milli Seconds
BIN FILE loaded through FPGA manager successfully
And leave the fpga.sh file as default there seems to be no problem loading the scope application from the web browser.

Do you have any idea how to fix this error? Btw I am working with the 2.04-35 OS.
Thanks again for the support :)

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: Google [Bot] and 1 guest