15 #define DEFAULT_DEV "/dev/flink0" 18 #define INFO_DEVICE_DESCRIPTOR "baseDeviceTesting" 19 #define INFO_DEVICE_DESCRIPTOR_LENGTH strlen(INFO_DEVICE_DESCRIPTOR) 21 #define COUNTER_FUNCTION_ID 0x6 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 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 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 50 #define NUMBER_OF_FQD_CHANNELS 4 51 #define OUT_IO_SUBFUNCTION_ID 1 52 #define IN_IO_SUBFUNCTION_ID 2 62 int testRatio(
float ratio,uint32_t period,
int channel);
70 int main(
int argc,
char* argv[]) {
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");
84 while((c = getopt(argc, argv,
"d:v")) != -1) {
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);
100 printf(
"FLink Base Device Testing\n");
105 printf(
"Failed to open device!\n");
111 printf(
"Wrong number of subdevices: %d\n",nof_subdevs);
118 printf(
"Testing info device.....\n");
120 printf(
"Testing info device error! Is the right design loaded?\n");
123 printf(
"Testing FQD device.....\n");
125 printf(
"Testing fqd device error!\n");
127 printf(
"Testing GPIO device.....\n");
129 printf(
"Testing gpio device error!\n");
131 printf(
"Testing PWM device.....\n");
133 printf(
"Testing pwm device error!\n");
137 printf(
"Test Successfull!\n");
150 if(value_a == 0 && value_b == 0){
152 }
else if(value_a == 1 && value_b == 0){
154 }
else if(value_a == 1 && value_b == 1){
156 }
else if(value_a == 0 && value_b == 1){
167 if(value_a == 0 && value_b == 0){
169 }
else if(value_a == 0 && value_b == 1){
171 }
else if(value_a == 1 && value_b == 1){
173 }
else if(value_a == 1 && value_b == 0){
182 if(enc_a_gpio_device == NULL) {
188 printf(
"out gpio device has wrong function id!\n");
193 printf(
"gpio device enc a has wrong subfunction id!\n");
198 printf(
"gpio device enc b has wrong number of channels!\n");
205 if(enc_b_gpio_device == NULL) {
211 printf(
"gpio device enc b has wrong function id!\n");
216 printf(
"gpio device enc b has wrong subfunction id!\n");
221 printf(
"gpio device enc b has wrong number of channels!\n");
234 if(fqd_device == NULL) {
240 printf(
"fqd device has wrong function id!\n");
245 printf(
"gpio device enc b has wrong number of channels!\n");
260 printf(
"Error reseting device\n");
267 int numberOfSteps = 10000;
268 for(
int u = 0; u < numberOfSteps ; u++){
273 printf(
"data= %d!\n",data);
281 printf(
"Error steping forward!\n");
286 for(
int u = 0; u < numberOfSteps ; u++){
290 if(data!= numberOfSteps-u-1){
291 printf(
"data= %d!\n",data);
299 printf(
"Error steping backwards!\n");
309 if(out_gpio_device == NULL) {
315 printf(
"out gpio device has wrong function id!\n");
321 if(in_gpio_device == NULL) {
327 printf(
"in gpio device has wrong function id!\n");
334 printf(
"gpio devices have not the same amount of channels!\n");
339 printf(
"gpio devices wrong number of channels!\n");
346 printf(
"Configuring out GPIO direction failed!\n");
351 printf(
"Configuring in GPIO direction failed!\n");
358 int set_read_error = 0;
363 printf(
"Set value error!\n");
368 printf(
"Get value error!\n");
375 if(set_read_error != 0){
376 printf(
"Error set gpio to high and read imidiatly back: %d\n",set_read_error);
388 float f = r*1.0/RAND_MAX;
389 channels[i] = (int) (f*NUMBER_OF_GPIO_CHANNELS_TEST);
404 if(result != values[i]){
408 if(set_read_error != 0){
409 printf(
"Error set random number to random channel: %d\n",set_read_error);
423 float f = r*1.0/RAND_MAX;
424 int firstchannel = (int) (f*NUMBER_OF_GPIO_CHANNELS_TEST);
427 channels[i+u] = (firstchannel + u) % NUMBER_OF_GPIO_CHANNELS_TEST;
446 if(i+u<NUMBER_OF_GPIO_TESTS){
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);
455 if(set_read_error != 0){
456 printf(
"Error set random number to random channel first write than read: %d\n",set_read_error);
472 if(pwm_device == NULL) {
473 printf(
"No subdevice with unique id %d found.\n",
PWM_UNIQUE_ID);
478 printf(
"pwm device has wrong function id!\n");
483 printf(
"pwm device has wrong number of channels!\n");
487 printf(
"reset pwm reset failed!\n");
492 printf(
"get pwm base frequency failed!\n");
495 printf(
"pwm base frequency = %d\n",
frequency);
497 printf(
"pwm base frequency should be bigger than 0\n");
504 printf(
"set pwm period failed!\n");
508 printf(
"set pwm hightime failed!\n");
517 if(in_gpio_device == NULL) {
523 printf(
"gpio device pwm in has wrong function id!\n");
528 printf(
"gpio device in pwm has wrong subfunction id!\n");
533 printf(
"gpio device pwm has wrong number of channels!\n");
543 float f = r*1.0/RAND_MAX;
544 uint32_t period = 1 + (int) (f*999);
547 float ratio = 2.0 + f*97.5;
550 int channel = (int) (f*NUMBER_OF_PWM_CHANNELS);
553 if(
testRatio(ratio,period,channel) != 0)
return -1;
563 printf(
"error getting pwm period\n");
567 printf(
"error getting pwm hightime\n");
571 printf(
"pwm wrong period value after reset!\n");
575 printf(
"pwm wrong hightime value after reset!\n");
585 int testRatio(
float ratio_desired,uint32_t desired_period,
int channel){
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);
593 printf(
"set pwm period failed!\n");
597 printf(
"set pwm hightime failed!\n");
604 struct timeval periodTime;
608 uint8_t numberOfEdges = 0;
611 gettimeofday(&old,NULL);
616 if(oldvalue != value){
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);
627 if(numberOfEdges == 1){
628 gettimeofday(&periodTime,NULL);
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);
644 if(numberOfEdges <6){
649 printf(
"pwm period timeout ratio= %f,period= %d\n",ratio_desired,desired_period);
661 char descriptor[descriptorLength + 1];
665 printf(
"Subdevice with id %d is no info device\n",0);
669 printf(
"Info device wrong unique id\n");
674 printf(
"Reading info device description failed!\n");
679 if(str[i]!=0 && u < descriptorLength){
680 descriptor[u] = str[i];
685 descriptor[descriptorLength] = 0;
686 if (strcmp(descriptor,designDescriptor) != 0) {
687 printf(
"Wrong descriptor from info device: %s/%s \n",descriptor,designDescriptor);
void stepVorward(int channel)
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)
#define PWM_IN_GPIO_UNIQUE_ID
#define NUMBER_OF_SUBDEVICES
flink_dev * flink_open(const char *file_name)
Opens a flink device file.
#define ENC_A_GPIO_UNIQUE_ID
int flink_pwm_set_hightime(flink_subdev *subdev, uint32_t channel, uint32_t hightime)
Sets the PWM hightime.
int flink_dio_set_value(flink_subdev *subdev, uint32_t channel, uint8_t high)
Sets a output channel to a value.
#define PWM_PERIOD_THRESHOLD
#define COUNTER_INTERFACE_ID
int flink_close(flink_dev *dev)
Close an open flink device.
int flink_get_nof_subdevices(flink_dev *dev)
Returns the number of subdevices of a fink device.
int flink_pwm_get_hightime(flink_subdev *subdev, uint32_t channel, uint32_t *hightime)
Gets the PWM hightime.
#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.
int main(int argc, char *argv[])
uint8_t flink_subdevice_get_subfunction(flink_subdev *subdev)
Get the subfunction of a subdevice.
#define PWM_RATIO_THRESHOLD
flink_subdev * enc_b_gpio_device
int flink_subdevice_reset(flink_subdev *subdev)
Reset a flink subdevice.
#define OUT_IO_SUBFUNCTION_ID
int flink_dio_get_value(flink_subdev *subdev, uint32_t channel, uint8_t *value)
Reads an input channel.
#define INFO_DEVICE_DESCRIPTOR_LENGTH
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.
#define NUMBER_OF_GPIO_TESTS
int flink_info_get_description(flink_subdev *subdev, char *value)
Reads the description field of an info subdevice.
#define NUMBER_OF_PWM_RATIO_PERIOD_TEST
int flink_counter_get_count(flink_subdev *subdev, uint32_t channel, uint32_t *data)
int flink_pwm_set_period(flink_subdev *subdev, uint32_t channel, uint32_t period)
Sets the PWM period.
int flink_pwm_get_baseclock(flink_subdev *subdev, uint32_t *frequency)
Reads the base clock of a PWM subdevice.
#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.
#define GPIO_INTERFACE_ID
uint16_t flink_subdevice_get_function(flink_subdev *subdev)
Get the function of a subdevice.
flink userspace library, strings for subdevice functions.
uint32_t flink_subdevice_get_nofchannels(flink_subdev *subdev)
Get the number of channels of a subdevice.
#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.
#define INFO_DEVICE_UNIQUE_ID
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.