vsi::device Class

Introduction

Available from version 2017.1, this class allows blocks residing in the Software Context, to directly communicate with AXI Memory mapped devices in the Hardware Context. The class exposes a “posix” compliant API which allows easy access to the devices . The class would typically be used as an argument to a function, and should be connected to an AXI Memory Mapped interface in an Hardware Context. If the Argument is a vsi::device the Access Type must be either “Memory” or “Control”.

Public APIs

int vsi::device.write (void *buff, size_t count);

Will write count bytes from buff to the device. It reqturns the number of bytes actually written to the device. Write is a blocking operation.


void write_mem(vsi::device &mem) {
	char buff[12] = “hello world”;
      mem.write(buff,sizeof(buff));
}

int vsi::device.read(void *buff, size_t count);

This is will read the number of count number of bytes from the device and place it into buff, it returns the number of bytes actually read. Read is a blocking operation.


void read_mem(vsi::device &mem) {
     char buff[1024];
     if (mem.read(buff,sizeof(buff)) != sizeof(buff)) {
          printf(“Not Enough Data\n”);
     }
}

int vsi::device.pwrite(void *buff, size_t count, size_t offset);

The function will write count number of bytes from the buff at offset specified by offset. This function is blocking and can be used to write values at a specific offset such as a register in a device. It returns the number of bytes actually written.


void set_timer (vsi::device &t_dev) {
    unsigned int TLR = 0;
    t_dev.pwrite(&TLR,sizeof(TLR),4); // write to 0 register at offset 4
}

int vsi::device.pread(void *buff,size_t count, size_t offset);

The function will read count number of bytes into buff from offset specified by offset. This function is blocking and can be used to read values from a register in a device. It returns the number of bytes actually read.

	int get_timer (vsi::device &t_dev) {
    unsigned int TLR =0;
    if (t_dev.pread(&TLR,sizeof(TLR),4) != sizeof(TLR)) // read from offset 4
        printf(“ Read Failed\n”);
    return TLR;
}

int vsi::device.poll(int timeout);

Waits for interrupt / data to become available to read, for devices with no interrupts this function will return immediately. The timeout parameter is in milliseconds.

int vsi::device.device_fd();

Returns the File Descriptor associated with this device. Note that the file descriptor is NOT available for devices running on a simulator context or a non-hardware context, the function call will cause an assertion if called for a device which is not associated with a file descriptor.