Exemple #1
0
int main(void)
{
 	uint8_t val, totval;
 	uint32_t val32=0;
 	char description[48];
 	int error = 0;

 	flink_dev*    dev;
 	flink_subdev* subdev;
 	flink_subdev* sdPWM;

 	dev = flink_open();

 	subdev = flink_get_subdevice_by_unique_id(dev, 3); // info device

 	error = flink_info_get_description(subdev, description);

 	sdPWM = flink_get_subdevice_by_unique_id(dev, 2);
 	error = flink_pwm_get_baseclock(sdPWM,&val32);
 	error = flink_pwm_set_period(sdPWM,0,1e6);		// 50 MHz / 1 MHz = 50 Hz = 20 msec periode
 	error = flink_pwm_set_hightime(sdPWM,0,100e3);	// 50 MHz / 100 kHz = 500 Hz = 2 msec high time

 	subdev = flink_get_subdevice_by_unique_id(dev, 1); // GPIO device

 	error = flink_dio_set_direction(subdev, 0x02, 0x01);	// LEDR0
 	error = flink_dio_set_direction(subdev, 0x03, 0x01);	// LEDR1

 	while(1) {

  		error = flink_dio_get_value(subdev,0x00,&val);	// SW0 --> LEDR0
 		totval = val;
 		error = flink_dio_set_value(subdev,0x02,val);
 		error = flink_dio_get_value(subdev,0x01,&val);	// SW1 --> LEDR1
 		totval += val<<1;
 		error = flink_dio_set_value(subdev,0x03,val);

  		switch(totval) {
  			case 0:
  			   	error = flink_pwm_set_hightime(sdPWM,0,100e3);	// 2.00 msec high time
  				break;
  			case 1:
  				error = flink_pwm_set_hightime(sdPWM,0,83e3);	// 1.67 msec high time
  				break;
  			case 2:
  				error = flink_pwm_set_hightime(sdPWM,0,67e3);	// 1.34 msec high time
  				break;
  			case 3:
  				error = flink_pwm_set_hightime(sdPWM,0,50e3);	// 1.00 msec high time
  				break;
  			default:
  				break;
  		} // switch

		usleep(50000);

 	} // while(1)

 	return 0;
} // main
Exemple #2
0
int main(int argc, char* argv[]) {
	flink_dev* dev;
	flink_subdev* subdev;
	char* dev_name = DEFAULT_DEV;
	uint8_t subdevice_id = 0;
	char c;
	uint32_t offset;
	uint32_t value;
	uint8_t write;
	int error = 0;
	
	/* Compute command line arguments */
	while((c = getopt(argc, argv, "d:s:o:v:rw")) != -1) {
		switch(c) {
			case 'd': // device
				dev_name = optarg;
				break;
			case 's':
				subdevice_id = atoi(optarg);
				break;
			case 'o':
				offset = atoi(optarg);
				break;
			case 'r':
				write = 0;
				break;
			case 'w':
				write = 1;
				break;
			case 'v':
				if(!write) {
					fprintf(stderr, "You can not set a value if you want to read from a device!");
				}
				else {
					value = atoi(optarg);
				}
				break;
			case '?':
				if(optopt == 'd' || optopt == 's' || optopt == 'o' || optopt == 'v') fprintf(stderr, "Option -%c requires an argument.\n", optopt);
				else if(isprint(optopt)) fprintf (stderr, "Unknown option `-%c'.\n", optopt);
				else fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
				return -1;
			default:
				abort();
		}
	}
	
	printf("Opening device %s...\n", dev_name);
	dev = flink_open(dev_name);
	if(dev == NULL) {
		printf("Failed to open device!\n");
		return -1;
	}
	
	subdev = flink_get_subdevice_by_id(dev, subdevice_id);
	
	if(write) {
		printf("Writing 0x%x (%u) to offset 0x%x at subdevice %u on device %s...\n", value, value, offset, subdevice_id, dev_name);
		error = flink_write(subdev, offset, SIZE, &value);
		if(dev == NULL) {
			printf("Failure while writing to device: %u!\n", error);
			return -1;
		}
	}
	else {
		printf("Reading from offset 0x%x at subdevice %u on device %s...\n", offset, subdevice_id, dev_name);
		error = flink_read(subdev, offset, SIZE, &value);
		if(dev == NULL) {
			printf("Failure while reading from device: %u!\n", error);
			return -1;
		}
		else {
			printf("--> Read: 0x%x (%u)\n", value, value);
		}
	}
	
	printf("Closing device %s...\n", dev_name);
	flink_close(dev);
	
    return EXIT_SUCCESS;
}
Exemple #3
0
int main(int argc, char* argv[]) {
	flink_dev* dev;
	char*      dev_name = DEFAULT_DEV;
	bool       verbose = false;
	
	// Error message if long dashes (en dash) are used
	int i;
	for (i=0; i < argc; i++) {
		 if ((argv[i][0] == 226) && (argv[i][1] == 128) && (argv[i][2] == 147)) {
			fprintf(stderr, "Error: Invalid arguments. En dashes are used.\n");
			return -1;
		 }
	}
	
	/* Compute command line arguments */
	int c;
	while((c = getopt(argc, argv, "d:v")) != -1) {
		switch(c) {
			case 'd': // device file
				dev_name = optarg;
				break;
			case 'v': // verbose mode
				verbose = true;
				break;
			case '?':
				if(optopt == 'd') fprintf(stderr, "Option -%c requires an argument.\n", optopt);
				else if(isprint(optopt)) fprintf (stderr, "Unknown option `-%c'.\n", optopt);
				else fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
				return -1;
			default:
				abort();
		}
	}
	
	dev = flink_open(dev_name);
	if(dev == NULL) {
		printf("Failed to open device!\n");
		return -1;
	}
	
	int nof_subdevs = flink_get_nof_subdevices(dev);
	
	printf("Subdevices of %s (%d):\n", dev_name, nof_subdevs);
	
	for(int i = 0; i < nof_subdevs; i++) {
		flink_subdev* subdev = flink_get_subdevice_by_id(dev, i);
		if(subdev) {
			uint8_t  id          = flink_subdevice_get_id(subdev);
			uint32_t baseaddr    = flink_subdevice_get_baseaddr(subdev);
			uint32_t memsize     = flink_subdevice_get_memsize(subdev);
			uint32_t lastaddr    = baseaddr + memsize - 1;
			uint16_t func        = flink_subdevice_get_function(subdev);
			uint8_t  subfunc     = flink_subdevice_get_subfunction(subdev);
			uint8_t  func_ver    = flink_subdevice_get_function_version(subdev);
			uint32_t nofchannels = flink_subdevice_get_nofchannels(subdev);
			uint32_t uniqueId    = flink_subdevice_get_unique_id(subdev);
			
			if(verbose) {
				printf("  %3d:\n", id);
				printf("       Address range:      0x%08x - 0x%08x\n", baseaddr, lastaddr);
				printf("       Memory size:        0x%08x (%d bytes)\n", memsize, memsize);
				printf("       Function:           0x%04x (%s)\n", func, flink_subdevice_id2str(func));
				printf("       Sub function:       0x%02x (%d)\n", subfunc, subfunc);
				printf("       Function version:   %d\n", func_ver);
				printf("       Number of channels: %d\n", nofchannels);
				printf("       Unique id:          0x%08x\n", uniqueId);
			}
			else {
				printf("  %3d: 0x%08x - 0x%08x, Type %d.%d-%d, %d channels, Id 0x%08x\n", id, baseaddr, lastaddr, func, subfunc, func_ver, nofchannels, uniqueId);
			}
		}
	}
	
	flink_close(dev);
	
	return EXIT_SUCCESS;
}
Exemple #4
0
int main(int argc, char* argv[]) {
	flink_dev*    dev;
	flink_subdev* subdev;
	char*         dev_name = DEFAULT_DEV;
	uint8_t       subdevice_id = 0;
	int           error = 0,e;
	char          str[29];
	
	// Error message if long dashes (en dash) are used
	int i;
	for (i=0; i < argc; i++) {
		 if ((argv[i][0] == 226) && (argv[i][1] == 128) && (argv[i][2] == 147)) {
			fprintf(stderr, "Error: Invalid arguments. En dashes are used.\n");
			return -1;
		 }
	}

	/* Compute command line arguments */
	int c;
	while((c = getopt(argc, argv, "d:s:c:rwhl")) != -1) {
		switch(c) {
			case 'd': // device file
				dev_name = optarg;
				break;
			case 's': // subdevice id
				subdevice_id = atoi(optarg);
				break;
			case '?':
				if(optopt == 'd' || optopt == 's' || optopt == 'c') fprintf(stderr, "Option -%c requires an argument.\n", optopt);
				else if(isprint(optopt)) fprintf (stderr, "Unknown option `-%c'.\n", optopt);
				else fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
				return -1;
			default:
				abort();
		}
	}

	// Open flink device
	dev = flink_open(dev_name);
	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_id(dev, subdevice_id);
	if(subdev == NULL) {
		fprintf(stderr, "Illegal subdevice id %d!\n", subdevice_id);
		return -1;
	}

	// Read description
	printf("Reading info device: subdevice %u\n", subdevice_id);
	error = flink_info_get_description(subdev, str);
	if(error != 0) {
		printf("Reading description failed!\n");
		return -1;
	} else {
		printf("Description: %s\n", str);
	}

	// Close flink device
	flink_close(dev);

    return EXIT_SUCCESS;
}