flinklib
flinklib: flink C library for Linux
base_device_test.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <stdbool.h>
5 #include <getopt.h>
6 #include <ctype.h>
7 #include <string.h>
8 #include <sys/time.h>
9 #include <time.h>
10 
11 #include <flinklib.h>
12 #include <flink_funcid.h>
13 
14 
15 #define DEFAULT_DEV "/dev/flink0"
16 
17 
18 #define INFO_DEVICE_DESCRIPTOR "baseDeviceTesting"
19 #define INFO_DEVICE_DESCRIPTOR_LENGTH strlen(INFO_DEVICE_DESCRIPTOR)
20 
21 #define COUNTER_FUNCTION_ID 0x6
22 
23 
24 
25 #define NUMBER_OF_SUBDEVICES 8
26 #define INFO_DEVICE_UNIQUE_ID 1
27 #define ENC_B_GPIO_UNIQUE_ID 0x2
28 #define ENC_A_GPIO_UNIQUE_ID 0x3
29 #define FQD_GPIO_UNIQUE_ID 0x4
30 
31 #define PWM_UNIQUE_ID 0x5
32 #define PWM_IN_GPIO_UNIQUE_ID 0x6
33 #define NUMBER_OF_PWM_CHANNELS 4
34 #define PWM_RATIO_THRESHOLD 0.2
35 #define PWM_PERIOD_THRESHOLD 0.2
36 #define NUMBER_OF_PWM_RATIO_PERIOD_TEST 100
37 #define PWM_TIMEOUT 10000000
38 
39 
40 
41 #define IN_GPIO_UNIQUE_ID 0x7
42 #define OUT_GPIO_UNIQUE_ID 0x8
43 #define NUMBER_OF_GPIO_CHANNELS_TEST 128
44 #define NUMBER_OF_GPIO_TESTS 1000
45 
46 
47 
48 
49 
50 #define NUMBER_OF_FQD_CHANNELS 4
51 #define OUT_IO_SUBFUNCTION_ID 1
52 #define IN_IO_SUBFUNCTION_ID 2
53 
54 
55 
56 int testInfoDevice(flink_dev* dev,int unique_id, char* designDescriptor,int descriptorLength);
57 void stepVorward(int channel);
58 void stepBackward(int channel);
59 int testFQD();
60 int testGPIODevice();
61 int testPWMDevice();
62 int testRatio(float ratio,uint32_t period,int channel);
63 
64 
68 
69 
70 int main(int argc, char* argv[]) {
71  char* dev_name = DEFAULT_DEV;
72 
73  // Error message if long dashes (en dash) are used
74  int i;
75  for (i=0; i < argc; i++) {
76  if ((argv[i][0] == 226) && (argv[i][1] == 128) && (argv[i][2] == 147)) {
77  fprintf(stderr, "Error: Invalid arguments. En dashes are used.\n");
78  return -1;
79  }
80  }
81 
82  /* Compute command line arguments */
83  int c;
84  while((c = getopt(argc, argv, "d:v")) != -1) {
85  switch(c) {
86  case 'd': // device file
87  dev_name = optarg;
88  break;
89  case 'v': // verbose mode
90  break;
91  case '?':
92  if(optopt == 'd') fprintf(stderr, "Option -%c requires an argument.\n", optopt);
93  else if(isprint(optopt)) fprintf (stderr, "Unknown option `-%c'.\n", optopt);
94  else fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
95  return -1;
96  default:
97  abort();
98  }
99  }
100  printf("FLink Base Device Testing\n");
101 
102  //get flink device
103  dev = flink_open(dev_name);
104  if(dev == NULL) {
105  printf("Failed to open device!\n");
106  return -1;
107  }
108  int nof_subdevs = flink_get_nof_subdevices(dev);
109 
110  if(nof_subdevs != NUMBER_OF_SUBDEVICES){
111  printf("Wrong number of subdevices: %d\n",nof_subdevs);
112  return -1;
113  }
114 
115 
116 
117  //test info device
118  printf("Testing info device.....\n");
120  printf("Testing info device error! Is the right design loaded?\n");
121  }
122 
123  printf("Testing FQD device.....\n");
124  if(testFQD() != 0){
125  printf("Testing fqd device error!\n");
126  }
127  printf("Testing GPIO device.....\n");
128  if(testGPIODevice() != 0){
129  printf("Testing gpio device error!\n");
130  }
131  printf("Testing PWM device.....\n");
132  if(testPWMDevice() != 0){
133  printf("Testing pwm device error!\n");
134  }
135 
136 
137  printf("Test Successfull!\n");
138  flink_close(dev);
139 
140  return EXIT_SUCCESS;
141 }
142 
143 
144 void stepVorward(int channel){
145  uint8_t value_a;
146  uint8_t value_b;
147  flink_dio_get_value(enc_a_gpio_device, channel,&value_a);
148  flink_dio_get_value(enc_b_gpio_device, channel,&value_b);
149 
150  if(value_a == 0 && value_b == 0){
151  flink_dio_set_value(enc_a_gpio_device, channel ,0x1);
152  }else if(value_a == 1 && value_b == 0){
153  flink_dio_set_value(enc_b_gpio_device, channel ,0x1);
154  }else if(value_a == 1 && value_b == 1){
155  flink_dio_set_value(enc_a_gpio_device, channel ,0x0);
156  }else if(value_a == 0 && value_b == 1){
157  flink_dio_set_value(enc_b_gpio_device, channel ,0x0);
158  }
159 }
160 
161 void stepBackward(int channel){
162  uint8_t value_a;
163  uint8_t value_b;
164  flink_dio_get_value(enc_a_gpio_device, channel,&value_a);
165  flink_dio_get_value(enc_b_gpio_device, channel,&value_b);
166 
167  if(value_a == 0 && value_b == 0){
168  flink_dio_set_value(enc_b_gpio_device, channel ,0x1);
169  }else if(value_a == 0 && value_b == 1){
170  flink_dio_set_value(enc_a_gpio_device, channel ,0x1);
171  }else if(value_a == 1 && value_b == 1){
172  flink_dio_set_value(enc_b_gpio_device, channel ,0x0);
173  }else if(value_a == 1 && value_b == 0){
174  flink_dio_set_value(enc_a_gpio_device, channel ,0x0);
175  }
176 }
177 
178 
179 int testFQD(){
180  //get enc_a io device
181  enc_a_gpio_device = flink_get_subdevice_by_unique_id(dev, ENC_A_GPIO_UNIQUE_ID);
182  if(enc_a_gpio_device == NULL) {
183  printf("No subdevice with unique id %d found.\n",ENC_A_GPIO_UNIQUE_ID);
184  return -1;
185  }
186 
187  if(flink_subdevice_get_function(enc_a_gpio_device) != GPIO_INTERFACE_ID) {
188  printf("out gpio device has wrong function id!\n");
189  return -1;
190  }
191 
192  if(flink_subdevice_get_subfunction(enc_a_gpio_device) != OUT_IO_SUBFUNCTION_ID) { //TODO get from include
193  printf("gpio device enc a has wrong subfunction id!\n");
194  return -1;
195  }
196 
197  if(flink_subdevice_get_nofchannels(enc_a_gpio_device) != NUMBER_OF_FQD_CHANNELS) {
198  printf("gpio device enc b has wrong number of channels!\n");
199  return -1;
200  }
201 
202 
203  //get enc_b io device
204  enc_b_gpio_device = flink_get_subdevice_by_unique_id(dev, ENC_B_GPIO_UNIQUE_ID);
205  if(enc_b_gpio_device == NULL) {
206  printf("No subdevice with unique id %d found.\n",ENC_B_GPIO_UNIQUE_ID);
207  return -1;
208  }
209 
210  if(flink_subdevice_get_function(enc_b_gpio_device) != GPIO_INTERFACE_ID) {
211  printf("gpio device enc b has wrong function id!\n");
212  return -1;
213  }
214 
215  if(flink_subdevice_get_subfunction(enc_b_gpio_device) != OUT_IO_SUBFUNCTION_ID) { //TODO get from include
216  printf("gpio device enc b has wrong subfunction id!\n");
217  return -1;
218  }
219 
220  if(flink_subdevice_get_nofchannels(enc_b_gpio_device) != NUMBER_OF_FQD_CHANNELS) {
221  printf("gpio device enc b has wrong number of channels!\n");
222  return -1;
223  }
224 
225  for(int i = 0; i < NUMBER_OF_FQD_CHANNELS; i++){
226  flink_dio_set_value(enc_a_gpio_device, i ,0x0);
227  flink_dio_set_value(enc_b_gpio_device, i ,0x0);
228  }
229 
230 
231 
232  //get fqd device
234  if(fqd_device == NULL) {
235  printf("No subdevice with unique id %d found.\n",FQD_GPIO_UNIQUE_ID);
236  return -1;
237  }
238 
240  printf("fqd device has wrong function id!\n");
241  return -1;
242  }
243 
244  if(flink_subdevice_get_nofchannels(fqd_device) != NUMBER_OF_FQD_CHANNELS) {
245  printf("gpio device enc b has wrong number of channels!\n");
246  return -1;
247  }
248 
249  //reset device and test if the counter value resets to zero
250  flink_subdevice_reset(fqd_device);
251  uint32_t data = 0;
252  int nrOfError = 0;
253  for(int i = 0; i < NUMBER_OF_FQD_CHANNELS; i++){
254  flink_counter_get_count(fqd_device,i,&data);
255  if(data!=0){
256  nrOfError++;
257  }
258  }
259  if(nrOfError != 0){
260  printf("Error reseting device\n");
261  return -1;
262  }
263 
264  //start testing the fqd device
265  //step forward
266  nrOfError = 0;
267  int numberOfSteps = 10000;
268  for(int u = 0; u < numberOfSteps ; u++){
269  for(int i = 0; i < NUMBER_OF_FQD_CHANNELS; i++){
270  stepVorward(i);
271  flink_counter_get_count(fqd_device,i,&data);
272  if(data!=u+1){
273  printf("data= %d!\n",data);
274  nrOfError++;
275  }
276  }
277  usleep(100);
278  }
279 
280  if(nrOfError != 0){
281  printf("Error steping forward!\n");
282  return -1;
283  }
284  //steb backward
285  nrOfError = 0;
286  for(int u = 0; u < numberOfSteps ; u++){
287  for(int i = 0; i < NUMBER_OF_FQD_CHANNELS; i++){
288  stepBackward(i);
289  flink_counter_get_count(fqd_device,i,&data);
290  if(data!= numberOfSteps-u-1){
291  printf("data= %d!\n",data);
292  nrOfError++;
293  }
294  }
295  usleep(100);
296  }
297 
298  if(nrOfError != 0){
299  printf("Error steping backwards!\n");
300  return -1;
301  }
302  return 0;
303 }
304 
305 
307  int error;
309  if(out_gpio_device == NULL) {
310  printf("No subdevice with unique id %d found.\n",OUT_GPIO_UNIQUE_ID);
311  return -1;
312  }
313 
314  if(flink_subdevice_get_function(out_gpio_device) != GPIO_INTERFACE_ID) {
315  printf("out gpio device has wrong function id!\n");
316  return -1;
317  }
318 
319 
321  if(in_gpio_device == NULL) {
322  printf("No subdevice with unique id %d found.\n",IN_GPIO_UNIQUE_ID);
323  return -1;
324  }
325 
326  if(flink_subdevice_get_function(in_gpio_device) != GPIO_INTERFACE_ID) {
327  printf("in gpio device has wrong function id!\n");
328  return -1;
329  }
330 
331 
332  int number_of_channels = flink_subdevice_get_nofchannels(out_gpio_device);
333  if(flink_subdevice_get_nofchannels(out_gpio_device) != number_of_channels){
334  printf("gpio devices have not the same amount of channels!\n");
335  return -1;
336  }
337 
338  if(number_of_channels != NUMBER_OF_GPIO_CHANNELS_TEST){
339  printf("gpio devices wrong number of channels!\n");
340  return -1;
341  }
342 
343  for(int i = 0; i < NUMBER_OF_GPIO_CHANNELS_TEST; i++){
344  error = flink_dio_set_direction(out_gpio_device, i, FLINK_OUTPUT);
345  if(error != 0) {
346  printf("Configuring out GPIO direction failed!\n");
347  return -1;
348  }
349  error = flink_dio_set_direction(in_gpio_device, i, FLINK_INPUT);
350  if(error != 0) {
351  printf("Configuring in GPIO direction failed!\n");
352  return -1;
353  }
354  }
355 
356 
357  //set out gpio and imidiatly read in gpio
358  int set_read_error = 0;
359  for(int i = 0; i < NUMBER_OF_GPIO_CHANNELS_TEST; i++){
360  uint8_t result = 0;
361  error = flink_dio_set_value(out_gpio_device, i, 1);
362  if(error != 0) {
363  printf("Set value error!\n");
364  return -1;
365  }
366  error = flink_dio_get_value(in_gpio_device, i, &result);
367  if(error != 0) {
368  printf("Get value error!\n");
369  return -1;
370  }
371  if(result != 1){
372  set_read_error++;
373  }
374  }
375  if(set_read_error != 0){
376  printf("Error set gpio to high and read imidiatly back: %d\n",set_read_error);
377  return -1;
378  }
379 
380 
381  //set random channel to random value
382  int channels[NUMBER_OF_GPIO_TESTS];
383  int values[NUMBER_OF_GPIO_TESTS];
384 
385  srand(time(NULL));
386  for(int i = 0; i< NUMBER_OF_GPIO_TESTS; i++){
387  int r = rand();
388  float f = r*1.0/RAND_MAX;
389  channels[i] = (int) (f*NUMBER_OF_GPIO_CHANNELS_TEST);
390  r = rand();
391  f = r*1.0/RAND_MAX;
392  if(f>0.5){
393  values[i] = 1;
394  }else{
395  values[i] = 0;
396  }
397  }
398 
399  set_read_error = 0;
400  for(int i = 0; i< NUMBER_OF_GPIO_TESTS; i++){
401  uint8_t result = 0;
402  flink_dio_set_value(out_gpio_device, channels[i], values[i]);
403  flink_dio_get_value(in_gpio_device, channels[i], &result);
404  if(result != values[i]){
405  set_read_error++;
406  }
407  }
408  if(set_read_error != 0){
409  printf("Error set random number to random channel: %d\n",set_read_error);
410  return -1;
411  }
412 
413 
414 
415 
416  //set all gpios first than read them
417  for(int i = 0; i< NUMBER_OF_GPIO_TESTS;i++){
418  values[i] = 0;
419  channels[i] = 0;
420  }
421  for(int i = 0; i + NUMBER_OF_GPIO_CHANNELS_TEST < NUMBER_OF_GPIO_TESTS; i = i + NUMBER_OF_GPIO_CHANNELS_TEST){
422  int r = rand();
423  float f = r*1.0/RAND_MAX;
424  int firstchannel = (int) (f*NUMBER_OF_GPIO_CHANNELS_TEST);
425  for (int u = 0; u < NUMBER_OF_GPIO_CHANNELS_TEST; u++){
426 
427  channels[i+u] = (firstchannel + u) % NUMBER_OF_GPIO_CHANNELS_TEST;
428  r = rand();
429  f = r*1.0/RAND_MAX;
430  if(f>0.5){
431  values[i+u] = 1;
432  }else{
433  values[i+u] = 0;
434  }
435  }
436  }
437 
438  set_read_error = 0;
439  for(int i = 0; i + NUMBER_OF_GPIO_CHANNELS_TEST < NUMBER_OF_GPIO_TESTS; i = i + NUMBER_OF_GPIO_CHANNELS_TEST){
440  for (int u = 0; u < NUMBER_OF_GPIO_CHANNELS_TEST; u++){
441  flink_dio_set_value(out_gpio_device, channels[i+u], values[i+u]);
442 
443  }
444  uint8_t result = 0;
445  for (int u = 0; u < NUMBER_OF_GPIO_CHANNELS_TEST; u++){
446  if(i+u<NUMBER_OF_GPIO_TESTS){
447  flink_dio_get_value(in_gpio_device, channels[i+u], &result);
448  if(result != values[i+u]){
449  printf("Error at channel: %d, value: %d, result: %d, nr= %d\n",channels[i+u],values[i+u],result,i+u);
450  set_read_error++;
451  }
452  }
453  }
454  }
455  if(set_read_error != 0){
456  printf("Error set random number to random channel first write than read: %d\n",set_read_error);
457  return -1;
458  }
459 
460 
461  return 0;
462 
463 }
464 uint32_t frequency = 0;
467 
468 
470  //get pwm device
472  if(pwm_device == NULL) {
473  printf("No subdevice with unique id %d found.\n",PWM_UNIQUE_ID);
474  return -1;
475  }
476 
477  if(flink_subdevice_get_function(pwm_device) != PWM_INTERFACE_ID) {
478  printf("pwm device has wrong function id!\n");
479  return -1;
480  }
481 
483  printf("pwm device has wrong number of channels!\n");
484  return -1;
485  }
486  if(flink_subdevice_reset(pwm_device) != 0){
487  printf("reset pwm reset failed!\n");
488  return -1;
489  }
490 
491  if(flink_pwm_get_baseclock(pwm_device, &frequency) != 0){
492  printf("get pwm base frequency failed!\n");
493  return -1;
494  }
495  printf("pwm base frequency = %d\n",frequency);
496  if(frequency <= 0){
497  printf("pwm base frequency should be bigger than 0\n");
498  return -1;
499  }
500 
501  for (int i = 0; i< NUMBER_OF_PWM_CHANNELS; i++){
502 
503  if(flink_pwm_set_period(pwm_device,i,0) != 0){
504  printf("set pwm period failed!\n");
505  return -1;
506  }
507  if(flink_pwm_set_hightime(pwm_device,i,0) != 0){
508  printf("set pwm hightime failed!\n");
509  return -1;
510  }
511  }
512 
513 
514 
515  //get in io device
517  if(in_gpio_device == NULL) {
518  printf("No subdevice with unique id %d found.\n",PWM_IN_GPIO_UNIQUE_ID );
519  return -1;
520  }
521 
522  if(flink_subdevice_get_function(in_gpio_device) != GPIO_INTERFACE_ID) {
523  printf("gpio device pwm in has wrong function id!\n");
524  return -1;
525  }
526 
527  if(flink_subdevice_get_subfunction(in_gpio_device) != IN_IO_SUBFUNCTION_ID) { //TODO get from include
528  printf("gpio device in pwm has wrong subfunction id!\n");
529  return -1;
530  }
531 
532  if(flink_subdevice_get_nofchannels(in_gpio_device) != NUMBER_OF_PWM_CHANNELS) {
533  printf("gpio device pwm has wrong number of channels!\n");
534  return -1;
535  }
536 
537 
538 
539 
540 
541  for (int i = 0 ; i < NUMBER_OF_PWM_RATIO_PERIOD_TEST; i++){
542  int r = rand();
543  float f = r*1.0/RAND_MAX;
544  uint32_t period = 1 + (int) (f*999);
545  r = rand();
546  f = r*1.0/RAND_MAX;
547  float ratio = 2.0 + f*97.5;
548  r = rand();
549  f = r*1.0/RAND_MAX;
550  int channel = (int) (f*NUMBER_OF_PWM_CHANNELS);
551 
552  //printf("Test pwm with period= %d, ratio= %f, channel= %d!\n",period,ratio,channel);
553  if(testRatio(ratio,period,channel) != 0)return -1;
554  }
555 
556  //reset device and test if the ratio and period register resets
557  flink_subdevice_reset(pwm_device);
558 
559  for (int i = 0 ; i < NUMBER_OF_PWM_CHANNELS; i++){
560  uint32_t period;
561  uint32_t hightime;
562  if(flink_pwm_get_period(pwm_device, i, &period) != 0){
563  printf("error getting pwm period\n");
564  return -1;
565  }
566  if(flink_pwm_get_hightime(pwm_device, i, &hightime) != 0){
567  printf("error getting pwm hightime\n");
568  return -1;
569  };
570  if(period != 0){
571  printf("pwm wrong period value after reset!\n");
572  return -1;
573  }
574  if(hightime != 0){
575  printf("pwm wrong hightime value after reset!\n");
576  return -1;
577  }
578  }
579 
580 
581  return 0;
582 }
583 
584 
585 int testRatio(float ratio_desired,uint32_t desired_period, int channel){
586  //set period with 50/50 ratio and measure it with polling
587  float period_us = 1.0/desired_period*1000000;
588  uint32_t period_reg = frequency/desired_period;
589  uint32_t ratio_reg = (uint32_t) (period_reg*ratio_desired/100.0);
590 
591  for (int i = 0; i< NUMBER_OF_PWM_CHANNELS; i++){
592  if(flink_pwm_set_period(pwm_device,i,period_reg) != 0){
593  printf("set pwm period failed!\n");
594  return -1;
595  }
596  if(flink_pwm_set_hightime(pwm_device,i,ratio_reg) != 0){
597  printf("set pwm hightime failed!\n");
598  return -1;
599  }
600  }
601 
602  struct timeval time;
603  struct timeval old;
604  struct timeval periodTime;
605  uint8_t value;
606  uint8_t oldvalue;
607  bool running = true;
608  uint8_t numberOfEdges = 0;
609  int error = 0;
610  int timeout = 0;
611  gettimeofday(&old,NULL);
612  flink_dio_get_value(in_gpio_device, channel, &oldvalue);
613  while(running && timeout < PWM_TIMEOUT){
614  timeout++;
615  flink_dio_get_value(in_gpio_device, channel, &value);
616  if(oldvalue != value){//edge detected
617  numberOfEdges++;
618  gettimeofday(&time,NULL);
619  if(numberOfEdges > 1){
620  unsigned long long deltaT= (time.tv_usec + 1000000 *time.tv_sec) -(old.tv_usec + 1000000 *old.tv_sec);
621  float ratio = deltaT/period_us;
622  if(ratio < ratio_desired + PWM_RATIO_THRESHOLD && ratio > ratio_desired - PWM_RATIO_THRESHOLD){
623  printf("delta= %llu, ratio= %f/%f\n",deltaT,ratio,ratio_desired);
624  error++;
625  }
626  }
627  if(numberOfEdges == 1){
628  gettimeofday(&periodTime,NULL);
629  }
630  if(numberOfEdges == 3){
631  unsigned long long deltaT= (time.tv_usec + 1000000 *time.tv_sec) -(periodTime.tv_usec + 1000000 *periodTime.tv_sec);
632  float period = 1.0/period_us*1000000;
633  if(period < desired_period + PWM_PERIOD_THRESHOLD && period > desired_period - PWM_PERIOD_THRESHOLD){
634  printf("delta= %llu, period= %f/%d\n",deltaT,period,desired_period);
635  error++;
636  }
637  }
638  old = time;
639  }
640  oldvalue = value;
641 
642  running = false;
643  for (int i = 0; i< NUMBER_OF_PWM_CHANNELS; i++){
644  if(numberOfEdges <6){
645  running = true;
646  }
647  }
648  if(timeout >= PWM_TIMEOUT){
649  printf("pwm period timeout ratio= %f,period= %d\n",ratio_desired,desired_period);
650  return -1;
651  }
652  }
653 
654  return error;
655 }
656 
657 
658 
659 int testInfoDevice(flink_dev* dev,int unique_id, char* designDescriptor,int descriptorLength){
660  char str[INFO_DESC_SIZE];
661  char descriptor[descriptorLength + 1];
662 
663  flink_subdev* info_device = flink_get_subdevice_by_id(dev, 0); //Info device is allways at id zero
664  if(flink_subdevice_get_function(info_device) != INFO_DEVICE_ID){
665  printf("Subdevice with id %d is no info device\n",0);
666  return -1;
667  }
668  if(flink_subdevice_get_unique_id(info_device) != unique_id){
669  printf("Info device wrong unique id\n");
670  return -1;
671  }
672 
673  if(flink_info_get_description(info_device, str) != 0) {
674  printf("Reading info device description failed!\n");
675  return -1;
676  }
677  int u = 0;
678  for(int i = 0; i < INFO_DESC_SIZE;i++){
679  if(str[i]!=0 && u < descriptorLength){
680  descriptor[u] = str[i];
681  u++;
682 
683  }
684  }
685  descriptor[descriptorLength] = 0;
686  if (strcmp(descriptor,designDescriptor) != 0) {
687  printf("Wrong descriptor from info device: %s/%s \n",descriptor,designDescriptor);
688  return -1;
689  }
690  return 0;
691 }
void stepVorward(int channel)
int testPWMDevice()
int testRatio(float ratio, uint32_t period, int channel)
#define NUMBER_OF_GPIO_CHANNELS_TEST
void stepBackward(int channel)
flink_subdev * enc_a_gpio_device
#define IN_GPIO_UNIQUE_ID
int testInfoDevice(flink_dev *dev, int unique_id, char *designDescriptor, int descriptorLength)
uint32_t frequency
#define PWM_IN_GPIO_UNIQUE_ID
#define NUMBER_OF_SUBDEVICES
flink_dev * flink_open(const char *file_name)
Opens a flink device file.
Definition: base.c:113
#define FLINK_OUTPUT
Definition: flinklib.h:97
#define ENC_A_GPIO_UNIQUE_ID
int flink_pwm_set_hightime(flink_subdev *subdev, uint32_t channel, uint32_t hightime)
Sets the PWM hightime.
Definition: pwm.c:104
int flink_dio_set_value(flink_subdev *subdev, uint32_t channel, uint8_t high)
Sets a output channel to a value.
Definition: dio.c:64
#define PWM_PERIOD_THRESHOLD
int flink_close(flink_dev *dev)
Close an open flink device.
Definition: base.c:146
int flink_get_nof_subdevices(flink_dev *dev)
Returns the number of subdevices of a fink device.
Definition: base.c:167
#define PWM_TIMEOUT
int flink_pwm_get_hightime(flink_subdev *subdev, uint32_t channel, uint32_t *hightime)
Gets the PWM hightime.
Definition: pwm.c:126
#define NUMBER_OF_PWM_CHANNELS
#define NUMBER_OF_FQD_CHANNELS
uint32_t flink_subdevice_get_unique_id(flink_subdev *subdev)
Get the unique id of a subdevice.
Definition: base.c:333
int main(int argc, char *argv[])
uint8_t flink_subdevice_get_subfunction(flink_subdev *subdev)
Get the subfunction of a subdevice.
Definition: base.c:288
#define PWM_RATIO_THRESHOLD
flink_subdev * enc_b_gpio_device
int flink_subdevice_reset(flink_subdev *subdev)
Reset a flink subdevice.
Definition: base.c:183
#define OUT_IO_SUBFUNCTION_ID
int flink_dio_get_value(flink_subdev *subdev, uint32_t channel, uint8_t *value)
Reads an input channel.
Definition: dio.c:93
#define EXIT_SUCCESS
Definition: flinklib.h:128
#define INFO_DEVICE_DESCRIPTOR_LENGTH
#define FLINK_INPUT
Definition: flinklib.h:98
flink_subdev * in_gpio_device
#define IN_IO_SUBFUNCTION_ID
flink_subdev * flink_get_subdevice_by_id(flink_dev *dev, uint8_t subdev_id)
Find subdevice of a device with a given id.
Definition: base.c:223
#define NUMBER_OF_GPIO_TESTS
int flink_info_get_description(flink_subdev *subdev, char *value)
Reads the description field of an info subdevice.
Definition: info.c:37
#define DEFAULT_DEV
#define NUMBER_OF_PWM_RATIO_PERIOD_TEST
int flink_counter_get_count(flink_subdev *subdev, uint32_t channel, uint32_t *data)
Definition: counter.c:35
int flink_pwm_set_period(flink_subdev *subdev, uint32_t channel, uint32_t period)
Sets the PWM period.
Definition: pwm.c:57
flink_dev * dev
int testFQD()
#define PWM_UNIQUE_ID
int flink_pwm_get_baseclock(flink_subdev *subdev, uint32_t *frequency)
Reads the base clock of a PWM subdevice.
Definition: pwm.c:35
#define FQD_GPIO_UNIQUE_ID
#define ENC_B_GPIO_UNIQUE_ID
int flink_dio_set_direction(flink_subdev *subdev, uint32_t channel, uint8_t output)
Configures a channel as input or output.
Definition: dio.c:38
#define INFO_DESC_SIZE
Definition: flinklib.h:55
uint16_t flink_subdevice_get_function(flink_subdev *subdev)
Get the function of a subdevice.
Definition: base.c:279
uint32_t flink_subdevice_get_nofchannels(flink_subdev *subdev)
Get the number of channels of a subdevice.
Definition: base.c:324
#define INFO_DEVICE_DESCRIPTOR
flink_subdev * pwm_device
#define OUT_GPIO_UNIQUE_ID
int flink_pwm_get_period(flink_subdev *subdev, uint32_t channel, uint32_t *period)
Gets the PWM period.
Definition: pwm.c:80
#define INFO_DEVICE_UNIQUE_ID
int testGPIODevice()
flink_subdev * flink_get_subdevice_by_unique_id(flink_dev *dev, uint32_t unique_id)
Find subdevice of a device with a given unique id.
Definition: base.c:246