• 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 » high_level_example

flink_lib:high_level_example

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
flink_lib:high_level_example [2016/02/25 13:32] – external edit 127.0.0.1flink_lib:high_level_example [2020/05/26 17:14] (current) – ursgraf
Line 6: Line 6:
 #include <stdlib.h> #include <stdlib.h>
 #include <stdbool.h> #include <stdbool.h>
 +#include <unistd.h>
 #include <flinklib.h> #include <flinklib.h>
- + 
-#define DEFAULT_DEV "/dev/flink0" +
 int main(void) { int main(void) {
 +  char*         DEFAULT_DEV = (char*)"/dev/flink0";
   flink_dev*    dev;   flink_dev*    dev;
   flink_subdev* subdev;   flink_subdev* subdev;
   char*         dev_name = DEFAULT_DEV;   char*         dev_name = DEFAULT_DEV;
-  uint8_t       subdevice_id = 0;+  uint32_t      subdevice_id = 0x12705002;
   uint32_t      channel = 0;   uint32_t      channel = 0;
   int           error = 0;   int           error = 0;
- + 
   // Open flink device   // Open flink device
-  dev = flink_open(DEFAULT_DEV );+  dev = flink_open(DEFAULT_DEV);
   if(dev == NULL) {   if(dev == NULL) {
     fprintf(stderr, "Failed to open device %s!\n", dev_name);     fprintf(stderr, "Failed to open device %s!\n", dev_name);
     return -1;     return -1;
   }   }
- + 
   // Get a pointer to the choosen subdevice   // Get a pointer to the choosen subdevice
-  subdev = flink_get_subdevice_by_id(dev, subdevice_id );+  subdev = flink_get_subdevice_by_unique_id(dev, subdevice_id );
   if(subdev == NULL) {   if(subdev == NULL) {
     fprintf(stderr, "Illegal subdevice id %d!\n", subdevice_id);     fprintf(stderr, "Illegal subdevice id %d!\n", subdevice_id);
     return -1;     return -1;
   }   }
- + 
   // Set I/O direction to output   // Set I/O direction to output
   error = flink_dio_set_direction(subdev, channel, true);   error = flink_dio_set_direction(subdev, channel, true);
   if(error != 0) {   if(error != 0) {
-    printf("Configuring GPIO direction failed!\n");+    fprintf(stderr, "Configuring GPIO direction failed!\n");
     return -1;     return -1;
   }   }
-  +  
-  // Write 'true' on output +  // toggle an output for 20s 
-  error = flink_dio_set_value(subdev, channel, true); +  uint8_t out = 1; 
-  if(error != 0) { +  for (int count = 0; count < 200; count++) { 
-    printf("Writing value failed!\n"); +    error = flink_dio_set_value(subdev, channel, out); 
-    return -1;+    if(error != 0) { 
 +      fprintf(stderr, "Writing value failed!\n"); 
 +      return -1; 
 +    } 
 +    usleep(100000); 
 +    out = !out;
   }   }
- + 
   // Close flink device   // Close flink device
   flink_close(dev);   flink_close(dev);
-  + 
   return EXIT_SUCCESS;   return EXIT_SUCCESS;
 } }
 </code> </code>
flink_lib/high_level_example.1456403564.txt.gz · Last modified: 2016/02/25 13:32 by 127.0.0.1

Page Tools

  • Show page
  • 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