/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// void rf_configure_debug(bool rx, unsigned char p0_payload_width, bool enable_auto_ack)
//
// Description:
//  Configures the RF block for debugging
//
// Parameters:
//  bool rx - true to operate as RX, false for TX
//  unsigned char p0_payload_width - payload width in number of bytes for pipe 0
//  bool enable_auto_ack - true to enable auto-acknowledge on pipe 0, false to disable
//
// Return value:
//  None
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void rf_configure_debug(bool rx, unsigned char p0_payload_width, bool enable_auto_ack)
{
	unsigned char config;
	unsigned char en_aa;

	config = RF_CONFIG_DEFAULT_VAL | RF_CONFIG_PWR_UP; //Set config to the default value of CONFIG with the PWR_UP bit set

	//Enable auto-ack on pipe 0 if requested
	if(enable_auto_ack != false)
	{
		en_aa = RF_EN_AA_ENAA_P0;
	}
	else
	{
		en_aa = RF_EN_AA_ENAA_NONE;
	}

	//Set the PRIM_RX bit if RX is requested
	if(rx == true)
	{
		config = config | RF_CONFIG_PRIM_RX;
	}

	//Run the full configuration on the device with the above specs and all others as defaults
	rf_configure(config,
				 true,
				 en_aa,
				 RF_EN_RXADDR_DEFAULT_VAL,
				 RF_SETUP_AW_DEFAULT_VAL,
				 RF_SETUP_RETR_DEFAULT_VAL,
				 RF_RF_CH_DEFAULT_VAL,
				 RF_RF_SETUP_DEFAULT_VAL,
				 NULL,
				 NULL,
				 RF_RX_ADDR_P2_DEFAULT_VAL,
				 RF_RX_ADDR_P3_DEFAULT_VAL,
				 RF_RX_ADDR_P4_DEFAULT_VAL,
				 RF_RX_ADDR_P5_DEFAULT_VAL,
				 NULL,
				 p0_payload_width,
				 RF_RX_PW_P1_DEFAULT_VAL,
				 RF_RX_PW_P2_DEFAULT_VAL,
				 RF_RX_PW_P3_DEFAULT_VAL,
				 RF_RX_PW_P4_DEFAULT_VAL,
				 RF_RX_PW_P5_DEFAULT_VAL);
}
Esempio n. 2
0
File: main.c Progetto: xwaynec/eplab
int main()
{
	unsigned char idx;
	unsigned int i = 0;
	store_cpu_rate(16);
	P0_DIR &= ~0x28;
	P0_ALT &= ~0x28;

	rf_init();
	rf_configure(cfg);
	serial_init(19200);	
	eco_page_init();
	
	//long_function(4,6,8,4);

	msg[0] = 0x0A;
	msg[1] = 0x00;
	/* ADDR */
	msg[2] = 0x02;
	msg[3] = 0xA0;
	/* LEN */
	msg[4] = 0x02;
	msg[5] = 0xDD;
	msg[6] = 0xCC;
	
	for(idx = 4; idx > 0; idx--)
	{
		blink_led();		
		mdelay(300);
	}

	mdelay(1000);

	while(1)
	{
		blink4();
		rf_send(dst_addr, 3, msg, 7);
		blink2();
		mdelay(200);	
		blink6();
	}

	return 0;
}
Esempio n. 3
0
int
main(int argc,char *argv[])
{
	int ch;
	int num_options;
	unsigned long action;
	char config_filename[PATH_MAX];
	char dev_name[PATH_MAX];
	char name[PATH_MAX];
	char component[PATH_MAX];
	char autoconf[10];
	int do_output;
	int do_recon;
	int do_rewrite;
	int is_clean;
	int raidID;
	int serial_number;
	struct stat st;
	int fd;
	int force;
	int openmode;

	num_options = 0;
	action = 0;
	do_output = 0;
	do_recon = 0;
	do_rewrite = 0;
	is_clean = 0;
	serial_number = 0;
	force = 0;
	openmode = O_RDWR;	/* default to read/write */

	while ((ch = getopt(argc, argv, "a:A:Bc:C:f:F:g:GiI:l:r:R:sSpPuv")) 
	       != -1)
		switch(ch) {
		case 'a':
			action = RAIDFRAME_ADD_HOT_SPARE;
			strlcpy(component, optarg, sizeof(component));
			num_options++;
			break;
		case 'A':
			action = RAIDFRAME_SET_AUTOCONFIG;
			strlcpy(autoconf, optarg, sizeof(autoconf));
			num_options++;
			break;
		case 'B':
			action = RAIDFRAME_COPYBACK;
			num_options++;
			break;
		case 'c':
			action = RAIDFRAME_CONFIGURE;
			strlcpy(config_filename, optarg,
			    sizeof(config_filename));
			force = 0;
			num_options++;
			break;
		case 'C':
			strlcpy(config_filename, optarg,
			    sizeof(config_filename));
			action = RAIDFRAME_CONFIGURE;
			force = 1;
			num_options++;
			break;
		case 'f':
			action = RAIDFRAME_FAIL_DISK;
			strlcpy(component, optarg, sizeof(component));
			do_recon = 0;
			num_options++;
			break;
		case 'F':
			action = RAIDFRAME_FAIL_DISK;
			strlcpy(component, optarg, sizeof(component));
			do_recon = 1;
			num_options++;
			break;
		case 'g':
			action = RAIDFRAME_GET_COMPONENT_LABEL;
			strlcpy(component, optarg, sizeof(component));
			openmode = O_RDONLY;
			num_options++;
			break;
		case 'G':
			action = RAIDFRAME_GET_INFO;
			openmode = O_RDONLY;
			do_output = 1;
			num_options++;
			break;
		case 'i':
			action = RAIDFRAME_REWRITEPARITY;
			num_options++;
			break;
		case 'I':
			action = RAIDFRAME_INIT_LABELS;
			serial_number = atoi(optarg);
			num_options++;
			break;
		case 'l': 
			action = RAIDFRAME_SET_COMPONENT_LABEL;
			strlcpy(component, optarg, sizeof(component));
			num_options++;
			break;
		case 'r':
			action = RAIDFRAME_REMOVE_HOT_SPARE;
			strlcpy(component, optarg, sizeof(component));
			num_options++;
			break;
		case 'R':
			strlcpy(component, optarg, sizeof(component));
			action = RAIDFRAME_REBUILD_IN_PLACE;
			num_options++;
			break;
		case 's':
			action = RAIDFRAME_GET_INFO;
			openmode = O_RDONLY;
			num_options++;
			break;
		case 'S':
			action = RAIDFRAME_CHECK_RECON_STATUS_EXT;
			openmode = O_RDONLY;
			num_options++;
			break;
		case 'p':
			action = RAIDFRAME_CHECK_PARITY;
			openmode = O_RDONLY;
			num_options++;
			break;
		case 'P':
			action = RAIDFRAME_CHECK_PARITY;
			do_rewrite = 1;
			num_options++;
			break;
		case 'u':
			action = RAIDFRAME_SHUTDOWN;
			num_options++;
			break;
		case 'v':
			verbose = 1;
			/* Don't bump num_options, as '-v' is not 
			   an option like the others */
			/* num_options++; */
			break;
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if ((num_options > 1) || (argc == 0)) 
		usage();

	strlcpy(name, argv[0], sizeof(name));
	fd = opendisk(name, openmode, dev_name, sizeof(dev_name), 0);
	if (fd == -1) {
		fprintf(stderr, "%s: unable to open device file: %s\n",
			getprogname(), name);
		exit(1);
	}
	if (fstat(fd, &st) != 0) {
		fprintf(stderr,"%s: stat failure on: %s\n",
			getprogname(), dev_name);
		exit(1);
	}
	if (!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode)) {
		fprintf(stderr,"%s: invalid device: %s\n",
			getprogname(), dev_name);
		exit(1);
	}

	raidID = DISKUNIT(st.st_rdev);

	switch(action) {
	case RAIDFRAME_ADD_HOT_SPARE:
		add_hot_spare(fd, component);
		break;
	case RAIDFRAME_REMOVE_HOT_SPARE:
		remove_hot_spare(fd, component);
		break;
	case RAIDFRAME_CONFIGURE:
		rf_configure(fd, config_filename, force);
		break;
	case RAIDFRAME_SET_AUTOCONFIG:
		set_autoconfig(fd, raidID, autoconf);
		break;
	case RAIDFRAME_COPYBACK:
		printf("Copyback.\n");
		do_ioctl(fd, RAIDFRAME_COPYBACK, NULL, "RAIDFRAME_COPYBACK");
		if (verbose) {
			sleep(3); /* XXX give the copyback a chance to start */
			printf("Copyback status:\n");
			do_meter(fd,RAIDFRAME_CHECK_COPYBACK_STATUS_EXT);
		}
		break;
	case RAIDFRAME_FAIL_DISK:
		rf_fail_disk(fd, component, do_recon);
		break;
	case RAIDFRAME_SET_COMPONENT_LABEL:
		set_component_label(fd, component);
		break;
	case RAIDFRAME_GET_COMPONENT_LABEL:
		get_component_label(fd, component);
		break;
	case RAIDFRAME_INIT_LABELS:
		init_component_labels(fd, serial_number);
		break;
	case RAIDFRAME_REWRITEPARITY:
		printf("Initiating re-write of parity\n");
		do_ioctl(fd, RAIDFRAME_REWRITEPARITY, NULL, 
			 "RAIDFRAME_REWRITEPARITY");
		if (verbose) {
			sleep(3); /* XXX give it time to get started */
			printf("Parity Re-write status:\n");
			do_meter(fd, RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT);
		}
		break;
	case RAIDFRAME_CHECK_RECON_STATUS_EXT:
		check_status(fd,1);
		break;
	case RAIDFRAME_GET_INFO:
		if (do_output)
			rf_output_configuration(fd, dev_name);
		else
			rf_get_device_status(fd);
		break;
	case RAIDFRAME_REBUILD_IN_PLACE:
		rebuild_in_place(fd, component);
		break;
	case RAIDFRAME_CHECK_PARITY:
		check_parity(fd, do_rewrite, dev_name);
		break;
	case RAIDFRAME_SHUTDOWN:
		do_ioctl(fd, RAIDFRAME_SHUTDOWN, NULL, "RAIDFRAME_SHUTDOWN");
		break;
	default:
		break;
	}

	close(fd);
	exit(0);
}
Esempio n. 4
0
int
main(int argc,char *argv[])
{
	int ch, i;
	int num_options;
	unsigned long action;
	char config_filename[PATH_MAX];
	char dev_name[PATH_MAX];
	char name[PATH_MAX];
	char component[PATH_MAX];
	char autoconf[10];
	char *parityconf = NULL;
	int parityparams[3];
	int do_output;
	int do_recon;
	int do_rewrite;
	int raidID;
	int serial_number;
	struct stat st;
	int fd;
	int force;
	int openmode;
	int last_unit;

	num_options = 0;
	action = 0;
	do_output = 0;
	do_recon = 0;
	do_rewrite = 0;
	serial_number = 0;
	force = 0;
	last_unit = 0;
	openmode = O_RDWR;	/* default to read/write */

	while ((ch = getopt(argc, argv, "a:A:Bc:C:f:F:g:GiI:l:mM:r:R:sSpPuU:v"))
	       != -1)
		switch(ch) {
		case 'a':
			action = RAIDFRAME_ADD_HOT_SPARE;
			strlcpy(component, optarg, sizeof(component));
			num_options++;
			break;
		case 'A':
			action = RAIDFRAME_SET_AUTOCONFIG;
			strlcpy(autoconf, optarg, sizeof(autoconf));
			num_options++;
			break;
		case 'B':
			action = RAIDFRAME_COPYBACK;
			num_options++;
			break;
		case 'c':
			action = RAIDFRAME_CONFIGURE;
			strlcpy(config_filename, optarg,
			    sizeof(config_filename));
			force = 0;
			num_options++;
			break;
		case 'C':
			strlcpy(config_filename, optarg,
			    sizeof(config_filename));
			action = RAIDFRAME_CONFIGURE;
			force = 1;
			num_options++;
			break;
		case 'f':
			action = RAIDFRAME_FAIL_DISK;
			strlcpy(component, optarg, sizeof(component));
			do_recon = 0;
			num_options++;
			break;
		case 'F':
			action = RAIDFRAME_FAIL_DISK;
			strlcpy(component, optarg, sizeof(component));
			do_recon = 1;
			num_options++;
			break;
		case 'g':
			action = RAIDFRAME_GET_COMPONENT_LABEL;
			strlcpy(component, optarg, sizeof(component));
			openmode = O_RDONLY;
			num_options++;
			break;
		case 'G':
			action = RAIDFRAME_GET_INFO;
			openmode = O_RDONLY;
			do_output = 1;
			num_options++;
			break;
		case 'i':
			action = RAIDFRAME_REWRITEPARITY;
			num_options++;
			break;
		case 'I':
			action = RAIDFRAME_INIT_LABELS;
			serial_number = xstrtouint(optarg);
			num_options++;
			break;
		case 'm':
			action = RAIDFRAME_PARITYMAP_STATUS;
			openmode = O_RDONLY;
			num_options++;
			break;
		case 'M':
			action = RAIDFRAME_PARITYMAP_SET_DISABLE;
			parityconf = strdup(optarg);
			num_options++;
			/* XXXjld: should rf_pm_configure do the strtol()s? */
			i = 0;
			while (i < 3 && optind < argc &&
			    isdigit((int)argv[optind][0]))
				parityparams[i++] = xstrtouint(argv[optind++]);
			while (i < 3)
				parityparams[i++] = 0;
			break;
		case 'l': 
			action = RAIDFRAME_SET_COMPONENT_LABEL;
			strlcpy(component, optarg, sizeof(component));
			num_options++;
			break;
		case 'r':
			action = RAIDFRAME_REMOVE_HOT_SPARE;
			strlcpy(component, optarg, sizeof(component));
			num_options++;
			break;
		case 'R':
			strlcpy(component, optarg, sizeof(component));
			action = RAIDFRAME_REBUILD_IN_PLACE;
			num_options++;
			break;
		case 's':
			action = RAIDFRAME_GET_INFO;
			openmode = O_RDONLY;
			num_options++;
			break;
		case 'S':
			action = RAIDFRAME_CHECK_RECON_STATUS_EXT;
			openmode = O_RDONLY;
			num_options++;
			break;
		case 'p':
			action = RAIDFRAME_CHECK_PARITY;
			openmode = O_RDONLY;
			num_options++;
			break;
		case 'P':
			action = RAIDFRAME_CHECK_PARITY;
			do_rewrite = 1;
			num_options++;
			break;
		case 'u':
			action = RAIDFRAME_SHUTDOWN;
			num_options++;
			break;
		case 'U':
			action = RAIDFRAME_SET_LAST_UNIT;
			num_options++;
			last_unit = atoi(optarg);
			if (last_unit < 0)
				errx(1, "Bad last unit %s", optarg);
			break;
		case 'v':
			verbose = 1;
			/* Don't bump num_options, as '-v' is not 
			   an option like the others */
			/* num_options++; */
			break;
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if ((num_options > 1) || (argc == 0)) 
		usage();

	if (prog_init && prog_init() == -1)
		err(1, "init failed");

	strlcpy(name, argv[0], sizeof(name));
	fd = opendisk1(name, openmode, dev_name, sizeof(dev_name), 0,
	    prog_open);
	if (fd == -1)
		err(1, "Unable to open device file: %s", name);
	if (prog_fstat(fd, &st) == -1)
		err(1, "stat failure on: %s", dev_name);
	if (!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode))
		err(1, "invalid device: %s", dev_name);

	raidID = DISKUNIT(st.st_rdev);

	switch(action) {
	case RAIDFRAME_ADD_HOT_SPARE:
		add_hot_spare(fd, component);
		break;
	case RAIDFRAME_REMOVE_HOT_SPARE:
		remove_hot_spare(fd, component);
		break;
	case RAIDFRAME_CONFIGURE:
		rf_configure(fd, config_filename, force);
		break;
	case RAIDFRAME_SET_AUTOCONFIG:
		set_autoconfig(fd, raidID, autoconf);
		break;
	case RAIDFRAME_COPYBACK:
		printf("Copyback.\n");
		do_ioctl(fd, RAIDFRAME_COPYBACK, NULL, "RAIDFRAME_COPYBACK");
		if (verbose) {
			sleep(3); /* XXX give the copyback a chance to start */
			printf("Copyback status:\n");
			do_meter(fd,RAIDFRAME_CHECK_COPYBACK_STATUS_EXT);
		}
		break;
	case RAIDFRAME_FAIL_DISK:
		rf_fail_disk(fd, component, do_recon);
		break;
	case RAIDFRAME_SET_COMPONENT_LABEL:
		set_component_label(fd, component);
		break;
	case RAIDFRAME_GET_COMPONENT_LABEL:
		get_component_label(fd, component);
		break;
	case RAIDFRAME_INIT_LABELS:
		init_component_labels(fd, serial_number);
		break;
	case RAIDFRAME_REWRITEPARITY:
		printf("Initiating re-write of parity\n");
		do_ioctl(fd, RAIDFRAME_REWRITEPARITY, NULL, 
			 "RAIDFRAME_REWRITEPARITY");
		if (verbose) {
			sleep(3); /* XXX give it time to get started */
			printf("Parity Re-write status:\n");
			do_meter(fd, RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT);
		}
		break;
	case RAIDFRAME_CHECK_RECON_STATUS_EXT:
		check_status(fd,1);
		break;
	case RAIDFRAME_GET_INFO:
		if (do_output)
			rf_output_configuration(fd, dev_name);
		else
			rf_get_device_status(fd);
		break;
	case RAIDFRAME_PARITYMAP_STATUS:
		rf_output_pmstat(fd, raidID);
		break;
	case RAIDFRAME_PARITYMAP_SET_DISABLE:
		rf_pm_configure(fd, raidID, parityconf, parityparams);
		break;
	case RAIDFRAME_REBUILD_IN_PLACE:
		rebuild_in_place(fd, component);
		break;
	case RAIDFRAME_CHECK_PARITY:
		check_parity(fd, do_rewrite, dev_name);
		break;
	case RAIDFRAME_SHUTDOWN:
		do_ioctl(fd, RAIDFRAME_SHUTDOWN, NULL, "RAIDFRAME_SHUTDOWN");
		break;
	case RAIDFRAME_SET_LAST_UNIT:
		do_ioctl(fd, RAIDFRAME_SET_LAST_UNIT, &last_unit,
		    "RAIDFRAME_SET_LAST_UNIT");
		break;
	default:
		break;
	}

	prog_close(fd);
	exit(0);
}