We are closed from December 18, 2024 to January 5, 2025. Orders placed during this time will be processed starting on January 6, 2025.

Linux C++ Drivers

Overview

Operations on FPGA memory registers can be performed on:

  • a single register
  • several consecutive registers
  • a single bit

Example

The C++ driver is written in line with the memory definition in the instrument configuration file.

Configuration file config.yml:

memory:
  - name: control
    offset: '0x60000000'
    range: 4K
  - name: status
    offset: '0x50000000'
    range: 4K

control_registers:
  - led

status_registers:
  - forty_two

C++ driver led_blinker.hpp:

#include <context.hpp>

class LedBlinker
{
  public:
    LedBlinker(Context& ctx)
    : ctl(ctx.mm.get<mem::control>())
    , sts(ctx.mm.get<mem::status>())
    {}

    void set_leds(uint32_t led_value) {
        ctl.write<reg::led>(led_value);
    }

    uint32_t get_leds() {
        return ctl.read<reg::led>();
    }

    void set_led(uint32_t index, bool status) {
        ctl.write_bit_reg(reg::led, index, status);
    }

    uint32_t get_forty_two() {
        return sts.read<reg::forty_two>();
    }

  private:
    Memory<mem::control>& ctl;
    Memory<mem::status>& sts;
};

Constructor

The C++ driver constructor accepts a Context object providing access to the FPGA memory. To retrieve the memory regions of interest, ctx.mm is used.

public:
    LedBlinker(Context& ctx)
    : ctl(ctx.mm.get<mem::control>())
    , sts(ctx.mm.get<mem::status>())
    {}

The returned Memory object is stored in the variable ctl.

Register

A register is identified by its offset in memory.

According to the instrument configuration file, the offset of the led register within the control memory is reg::led.:

memory:
  - name: control
    offset: '0x60000000'
    range: 4K

control_registers:
  - led

See also

[email protected]