You are here: Home / easyFPGA sample code / C++
Wednesday, 2024-07-24

Software development for your ideas

Software Development
for your ideas.

Impossible is nothing

Impossible is nothing.

We make it yours

We make it yours.

Supporting your business

Supporting your business.

Software development for your ideas

Definition of the FPGA

Without the need of delving into hardware description languages, the FPGA's behavior can be defined using ready-made modules (easyCores). For that purpose the implementation of the abstract method defineStructure() of the class EasyFPGA is used in C++:

// pwm_fpga.h


#include "easyfpga/easyfpga.h"
#include "easyfpga/easycores/pwm/pwm8_ptr.h"

/* FPGA description template for the user application */
class PwmFpga : public EasyFpga
        // easyCores will be instantiated in the constructor

        // here, the easyCores will be added and connected
        void defineStructure(void);

        // the easyCore getter method to be called in the host application
        pwm8_ptr getPwm8(void);

        pwm8_ptr _pwm8;

/* This macro is necessary for the binary generation process. Please
make sure, that the macro's parameter has the same value as the name of
this binary description class (here: PwmFpga). */



#include "pwm_fpga.h"
#include "easyfpga/easycores/pwm/pwm8.h"

PwmFpga::PwmFpga() :


void PwmFpga::defineStructure(void)
    // prior to connecting an easyCore it has to be added

    // connect to an external pin
    this->connect(_pwm8, Pwm8::PIN::PWM_OUT, GPIOPIN::BANK0_PIN0);

pwm8_ptr PwmFpga::getPwm8(void)
    return _pwm8;

Communication via USB

As shown below, an arbitrary C++ application can connect to the easyFPGA board and communicate with the easyCores.


#include "pwm_fpga.h"

#include "easyfpga/easycores/pwm/pwm8.h"
#include "easyfpga/easycores/pwm/pwm8_ptr.h"

#include <memory> // for shared pointers

int main(int argc, char** argv)
    // Initialize the FPGA with the init() member. That does:
    // 1) Check if the specified binary exists or tries to create it.
    // 2) Connect to an easyFPGA board specified by a serial number,
    //    here 0, which will connect the framework to first easyFPGA
    //    board found.
    // 3) Upload the generated binary and configure it into the FPGA's
    //    RAM if this isn't already done before with this binary.
    std::shared_ptr<PwmFpga> fpga = std::make_shared<PwmFpga>();
    fpga->init(0, "PwmFpga.bin");

    // Gets an easyCore instance from the description class
    pwm8_ptr pwm = fpga->getPwm8();

    // Start communication by using the respective core API.

    return 0;