Ejemplo n.º 1
0
int vmodttl_io_chan_config(int lun, enum vmodttl_channel chan, struct vmodttl_config conf)
{
	struct vmodttl_config ttl_conf;
	int i;

	vmodttl_read_config(lun, &ttl_conf);
	
	switch(chan) {
	case VMOD_TTL_CHANNEL_A:
		ttl_conf.dir_a = conf.dir_a;
		ttl_conf.mode_a = conf.mode_a;
		ttl_conf.pattern_mode_a = conf.pattern_mode_a;	
		for(i = 0; i < NR_BITS; i++) 
			ttl_conf.conf_pattern_a[i] = conf.conf_pattern_a[i];
		break;
	case VMOD_TTL_CHANNEL_B:
		ttl_conf.dir_b = conf.dir_b;
		ttl_conf.mode_b = conf.mode_b;
		ttl_conf.pattern_mode_b = conf.pattern_mode_b;
		for(i = 0; i < NR_BITS; i++) 
			ttl_conf.conf_pattern_b[i] = conf.conf_pattern_b[i];
		
		break;
	case VMOD_TTL_CHANNELS_AB:
		return vmodttl_io_config(lun, conf);
		break;
	default:
		
		fprintf(stderr, "libvmodttl: Invalid channel (%d) to configure.\n", chan);
		return -1;
	
	}

	return vmodttl_io_config(lun, ttl_conf);
}
Ejemplo n.º 2
0
int main (int argc, char *argv[])
{        
        char tmp;
	struct vmodttl_config conf;
	int val;
	int i;


	printf("  ______________________________________  \n");
	printf(" |                                      | \n");
	printf(" |       VMOD-TTL Testing program       | \n");
	printf(" |______________________________________| \n");
	printf(" |                                      | \n");
	printf(" | Created by: Samuel I. Gonsalvez      | \n");
	printf(" | Email: [email protected]              | \n");
	printf(" |______________________________________| \n");

	if (argc == 2)
	{
		device = atoi(argv[1]);
	}
	else
	{
		printf("\n Please use: tstlibttl <lun_of_the_device>.\n");
		exit(-1);
	}

	if(vmodttl_open (device) < 0) {
		perror("open failed");	
		return -1;
	}

	printf("\n Port configuration \n");
	printf("\n Channel A [ (0) Input - (1) Output]: \n");
	scanf("%d", &val);
	conf.dir_a = val;
	conf.mode_a = 0; 	/* It's not open collector */

	printf("\n Channel B [ (0) Input - (1) Output]: \n");
	scanf("%d", &val);
	conf.dir_b = val;
	conf.mode_b = 0;	/* It's not open collector */

	conf.mode_c = 0; 	/* It's not open collector */

	printf("\n Up time of the pulse in the data strobe (useg): \n");
	scanf("%d", &val);
	conf.us_pulse = val;

	printf("\n In all the channels: [ (0) Non-inverting Logic - (1) Inverting logic]: \n");
	scanf("%d", &val);
	conf.inverting_logic = val;

	conf.pattern_mode_a = AND;
	conf.pattern_mode_b = OR;
	
	for(i = 0; i< NUM_BITS; i++) {
			conf.conf_pattern_a[i] = OFF;
			conf.conf_pattern_b[i] = OFF;
	}

	if (vmodttl_io_config(device, conf) < 0)
		exit(-1);


	do{
		if(tmp != '\n'){	
			printf("\n **** OPTIONS ****\n\n");
			printf(" a) Write channel.\n");
			printf(" b) Read channel.\n");
			printf(" Press \'q\' to exit...\n");
		}

		scanf("%c", &tmp);

		switch(tmp){
		case 'a':
			write_channel(device);
			break;
		case 'b':
			read_channel(device);
			break;
		case 'q':
			printf(" Exiting...\n");
			break;
		default:
			break;	
		}

	}while(tmp != 'q');

	conf.pattern_mode_a = 1;
	conf.mode_a = 1;
	conf.dir_a = 1;

	if(vmodttl_io_chan_config(device, 0, conf))
		exit(-1);

	if(vmodttl_read_config(device, &conf))
		exit(-1);
	printf("\n\n ------------------------------- \n");
	printf("\n\n 	I/O Config used!             \n");
	printf(" ------------------------------- \n");
	printf(" dir a: %d mode a: %d \n", conf.dir_a, conf.mode_a);	
	printf(" dir b: %d mode b: %d \n", conf.dir_b, conf.mode_b);	
	printf(" mode c: %d \n", conf.mode_c);	
	printf(" us_pulse: %d  inverting_logic: %d\n", conf.us_pulse, conf.inverting_logic);	
	printf(" pattern mode A: %d  pattern mode B: %d\n", conf.pattern_mode_a, conf.pattern_mode_b);	
	printf(" port A: %d/%d/%d/%d/%d/%d/%d/%d  port B: %d/%d/%d/%d/%d/%d/%d/%d \n", 
			conf.conf_pattern_a[0],
			conf.conf_pattern_a[1],
			conf.conf_pattern_a[2],
			conf.conf_pattern_a[3],
			conf.conf_pattern_a[4],
			conf.conf_pattern_a[5],
			conf.conf_pattern_a[6],
			conf.conf_pattern_a[7],
			conf.conf_pattern_b[0],
			conf.conf_pattern_b[1],
			conf.conf_pattern_b[2],
			conf.conf_pattern_b[3],
			conf.conf_pattern_b[4],
			conf.conf_pattern_b[5],
			conf.conf_pattern_b[6],
			conf.conf_pattern_b[7]
			);	
	printf("\n\n ------------------------------- \n");
	vmodttl_close(device); 

	return 0;
}