• skip to content



flink-project

Universal Serial Interface to FPGA's

User Tools

  • Admin
  • Log In

Site Tools

  • Recent Changes
  • Media Manager
  • Sitemap
You are here: start » flink_lib » low_level_example

Sidebar

Navigation

  • Home
  • flink VHDL subdevices and interfaces
  • flink Linux Kernel Modules
  • flink Userspace Library
  • flink Library Lite
  • flink Utilities
  • flink Java Library

  • flink First Steps
  • flink on a Phytec PCM032 Board
  • flink on a Digilent ZYBO
flink_lib:low_level_example

Example using low-level API

The following example demonstrates how a flink device can be opened and a subdevice selected. The subdevice is of type GPIO. One of it's channels is configured as output and set to true.

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <flinklib.h>
#include <types.h>
 
 
int main(void) {
  char*         DEFAULT_DEV = (char*)"/dev/flink0";
  flink_dev*    dev;
  flink_subdev* subdev;
  char*         dev_name = DEFAULT_DEV;
  uint32_t      subdevice_id = 0x12705002;
  uint32_t      channel = 0;
  int           error = 0;
 
  // Open flink device
  dev = flink_open(DEFAULT_DEV);
  if(dev == NULL) {
    fprintf(stderr, "Failed to open device %s!\n", dev_name);
    return -1;
  }
 
  // Get a pointer to the choosen subdevice
  subdev = flink_get_subdevice_by_unique_id(dev, subdevice_id );
  if(subdev == NULL) {
    fprintf(stderr, "Illegal subdevice id %d!\n", subdevice_id);
    return -1;
  }
 
  // Set I/O direction to output
  uint8_t out = true;
  uint32_t offset = HEADER_SIZE + SUBHEADER_SIZE + (channel / (REGISTER_WITH * 8)) * REGISTER_WITH;
  uint8_t bit = channel % (REGISTER_WITH * 8);
  if(flink_write_bit(subdev, offset, bit, &out)) {
    fprintf(stderr, "Configuring GPIO direction failed!\n");
    return -1;
  }
 
  // toggle an output for 20s
  offset = HEADER_SIZE + SUBHEADER_SIZE + ((subdev->nof_channels - 1) / (REGISTER_WITH * 8) + 1) * REGISTER_WITH + (channel / (REGISTER_WITH * 8)) * REGISTER_WITH;
  bit = channel % (REGISTER_WITH * 8);
  out = 1;
  for (int count = 0; count < 200; count++) {
    if(flink_write_bit(subdev, offset, bit, &out)) {
      fprintf(stderr, "Writing GPIO value failed!\n");
      return -1;
    }
    usleep(100000);
    out = !out;
  }
 
  // Close flink device
  flink_close(dev);
 
  return EXIT_SUCCESS;
}
flink_lib/low_level_example.txt · Last modified: 2020/05/26 17:20 by ursgraf

Page Tools

  • Show pagesource
  • Old revisions
  • Back to top
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki