Exemplo n.º 1
0
static void enbale_epcs(void)
{
   gpio_export(PIN_AS_MODE);
   gpio_direction(PIN_AS_MODE,OUT);    // GPIO为输出状态
   gpio_write(PIN_AS_MODE,HIGH_LEVEL); //输出高电平
   gpio_export(PIN_EPCS_CONFIG);
   gpio_direction(PIN_EPCS_CONFIG,OUT);   // GPIO为输出状态
   gpio_write(PIN_EPCS_CONFIG,LOW_LEVEL); //输出低电平
}
Exemplo n.º 2
0
static void testgpio(void)
{
#if 1
   gpio_export(PIN_AS_MODE);
   gpio_direction(PIN_AS_MODE,OUT);    // GPIO为输出状态
   gpio_write(PIN_AS_MODE,HIGH_LEVEL); //输出高电平

   gpio_export(PIN_EPCS_CONFIG);
   gpio_direction(PIN_EPCS_CONFIG,OUT);   // GPIO为输出状态
   gpio_write(PIN_EPCS_CONFIG,LOW_LEVEL); //输出低电平
#endif
   gpio_export(PIN_SPI_EN0);
   gpio_direction(PIN_SPI_EN0,OUT);   // GPIO为输出状态
   gpio_write(PIN_SPI_EN0,LOW_LEVEL); //输出低电平

}
Exemplo n.º 3
0
void laserInit(uint8_t pin) {
	laserPin = pin;

	gpio_export(laserPin);
        gpio_direction(laserPin, GPIO_DIR_OUT);
	gpio_write(laserPin, 0);
}
Exemplo n.º 4
0
/***************************************************************************//**
 * @brief main
*******************************************************************************/
int main(void)
{
	Xil_ICacheEnable();
	Xil_DCacheEnable();

	gpio_init(GPIO_DEVICE_ID);
	gpio_direction(54 + 46, 1);
	spi_init(SPI_DEVICE_ID, 1, 0);

	adc_init();
	dac_init(DATA_SEL_DDS);

	ad9361_phy = ad9361_init(&default_init_param);

	ad9361_set_tx_fir_config(ad9361_phy, tx_fir_config);
	ad9361_set_rx_fir_config(ad9361_phy, rx_fir_config);

#ifdef DAC_DMA
	dac_init(DATA_SEL_DMA);
#else
	dac_init(DATA_SEL_DDS);
#endif

#ifdef CAPTURE_SCRIPT
	adc_capture(16384, ADC_DDR_BASEADDR);
	while(1);
#endif
	get_help(NULL, 0);

	while(1)
	{
		console_get_command(received_cmd);
		invalid_cmd = 0;
		for(cmd = 0; cmd < cmd_no; cmd++)
		{
			param_no = 0;
			cmd_type = console_check_commands(received_cmd, cmd_list[cmd].name,
											  param, &param_no);
			if(cmd_type == UNKNOWN_CMD)
			{
				invalid_cmd++;
			}
			else
			{
				cmd_list[cmd].function(param, param_no);
			}
		}
		if(invalid_cmd == cmd_no)
		{
			console_print("Invalid command!\n");
		}
	}

	Xil_DCacheDisable();
	Xil_ICacheDisable();

	return 0;
}
Exemplo n.º 5
0
static int gpio_wait(int pin)
{
	char path[BUFFER_MAX];
	int fd;
 
	snprintf(path, BUFFER_MAX, "/sys/class/gpio/gpio%d/value", pin);
	fd = open(path, O_RDONLY);
	if (-1 == fd) {
		fprintf(stderr, "Failed to open gpio for reading!\n");
		return -1;
	}

	read(fd, path, 3);

	struct pollfd p = {
		.fd = fd,
		.events = POLLPRI|POLLERR,
	};

	int r = poll(&p, 1, -1);
	if(r != 1) {
		fprintf(stderr, "poll() failed!\n");
		close(fd);
		return -1;
	}

	close(fd);
	return 0;
}
 
 
int main(int argv, char** argc)
{
	if(gpio_export(PIN)) {
		return 1;
	}

	gpio_direction(PIN, IN);

	setup();
	setup_gpio(POUT, OUTPUT, PUD_OFF);

	while(1) {
		gpio_edge(PIN, RISING);
		gpio_wait(PIN);
		output_gpio(POUT, HIGH);
		gpio_edge(PIN, FALLING);
		gpio_wait(PIN);
		output_gpio(POUT, LOW);
	}

	if(gpio_unexport(PIN)) {
		return 1;
	}

	return 0;
}
//=========================================================
//
//
//=========================================================
void InicializaSaidas(uint8_t di)
{
	switch(di)
	{
		case OUT_D0:
			gpio_direction(PTA,5,OUTPUT,NO_PULL_RESISTOR);
		break;
		case OUT_D1:
			gpio_direction(PTA,4,OUTPUT,NO_PULL_RESISTOR);			
		break;
		case OUT_D2:
			gpio_direction(PTA,12,OUTPUT,NO_PULL_RESISTOR);
		break;
		case OUT_D3:
			gpio_direction(PTD,4,OUTPUT,NO_PULL_RESISTOR);
		break;
	}
}
Exemplo n.º 7
0
int gpio_direction_output(unsigned gpio, int value)
{
	int ret = gpio_direction(gpio, GPIO_DIRECTION_OUT);

	if (ret < 0)
		return ret;

	gpio_set_value(gpio, value);
	return 0;
}
Exemplo n.º 8
0
FUNC_RESULT cs0_high(spi_context_p dev)
{
	if ( dev== 0 )
		return FUNC_RESULT_INVALID_PARAMETER;

	gpio_context_p cs0 = get_cs0_gpio_context(dev);
	gpio_direction(cs0, GPIO_DIR_OUT);
	FUNC_RESULT res = gpio_write(cs0, 1);
	free(cs0);
	return res;
}
Exemplo n.º 9
0
void stepperInit(uint8_t index, int pin1, int pin2, int pin3, int pin4) {
	if (index >= STEPPER_COUNT) {
		fatal_error("stepper index (%d) is out of range\n", index);
	}
	struct stepper *s = &step[index];
	//printf("stepperInit @ 0x%x\n", step);

	s->pins[0] = pin1;
	s->pins[1] = pin2;
	s->pins[2] = pin3;
	s->pins[3] = pin4;

        gpio_export(pin1);
        gpio_direction(pin1, GPIO_DIR_OUT);
        gpio_export(pin2);
        gpio_direction(pin2, GPIO_DIR_OUT);
        gpio_export(pin3);
        gpio_direction(pin3, GPIO_DIR_OUT);
        gpio_export(pin4);
        gpio_direction(pin4, GPIO_DIR_OUT);

	//printf("initializing semaphore for stepper on pins %d - %d - %d - %d\n", pin1, pin2, pin3, pin4);
        sem_init(&s->sem, 0, 0);
        sem_init(&s->semRT, 0, 0);
	pthread_mutex_init(&s->mutex, NULL);

	s->index = index;

	s->pulseLen = 0;
	s->pulseLenTarget = 0;
	s->stepCurrent = 0;
	s->stepTarget = 0;

	s->homed[0] = 0;
	s->homed[1] = 0;
	s->limit[0] = 0;
	s->limit[1] = 0;
}
Exemplo n.º 10
0
FUNC_RESULT cs0_low(spi_context_p dev)
{
	if ( dev== 0 )
		return FUNC_RESULT_INVALID_PARAMETER;

	gpio_context_p cs0 = get_cs0_gpio_context(dev);
	if ( cs0 == 0 )
	{
		syslog(LOG_ERR, "spi cs0: initialization failed");
		return FUNC_RESULT_FAILED;
	}
	gpio_direction(cs0, GPIO_DIR_OUT);
	FUNC_RESULT res = gpio_write(cs0, 0);
	free(cs0);
	return res;
}
Exemplo n.º 11
0
/*
 * configure multiplexer
 */
FUNC_RESULT enable_spi(spi_context_p spi)
{
	if ( spi == 0 )
		return FUNC_RESULT_INVALID_PARAMETER;
	pBus spi_bus = spi->spi_bus;
	int pinid = 0;
	p_bus_pin current_pin = 0;
	for (; pinid<spi_bus->pins_count; pinid++)
	{
		current_pin = spi_bus->_pins[pinid];
		ChangePinMode(current_pin->mux_id, current_pin->mode_value);
	}

	//	edison doesn`t support hardware cs0, use gpio110 to simulate it
	FUNC_RESULT res = FUNC_RESULT_SUCCESS;
	p_bus_pin cs0_pin = spi_bus->_pins[spi->cs_id];
	gpio_context_p gp110 = gpio_init(cs0_pin->mux_id);
	res = gpio_direction(gp110, GPIO_DIR_OUT);
	gpio_release(gp110);

	return res;
}
Exemplo n.º 12
0
int main(int argc, char *argv[]) {
  parse_options(argc, argv);

  gpio_export(options.gpioNr);
  gpio_direction(options.gpioNr, options.operation);

  if (options.operation == GPIO_GET) {
    int val;
    int i; for(i = 0; i < options.repeat; ++i) {
      val = gpio_get(options.gpioNr);
    }
    printf("%d\n", val);
  } else {
    int i; for(i = 0; i < options.repeat; ++i) {
      gpio_set(options.gpioNr, options.value);
    }
  }

  gpio_unexport(options.gpioNr);

  return 0;
}
Exemplo n.º 13
0
/***************************************************************************//**
 * @brief main
 *******************************************************************************/
int initAd9361(void) {

	int Status;
	uint64_t Value;
	uint8_t en_dis;

	/*
	 * NOTE: The user has to choose the GPIO numbers according to desired
	 * carrier board. The following configuration is valid for boards other
	 * than the Fmcomms5.
	 */
	default_init_param.gpio_resetb = GPIO_RESET_PIN;
	default_init_param.gpio_sync = -1;
	default_init_param.gpio_cal_sw1 = -1;
	default_init_param.gpio_cal_sw2 = -1;

	/*
	 * Initialize the GPIO
	 */
	gpio_init(GPIO_DEVICE_ID);
	gpio_direction(default_init_param.gpio_resetb, 1);

	/*
	 * Initialize the SPI
	 */
	spi_init(SPI_DEVICE_ID, 1, 0);

	/*
	 * Initialize AD9361
	 */
	Status = ad9361_init(&ad9361_phy, &default_init_param);
	if (Status != 0) {
		xil_printf("Could not initialize AD9361\r\n");
		xil_printf("Status\t%d\r\n", Status);
		return 1;
	}

	/*
	 * Sampling frequency
	 */
	Status = ad9361_set_tx_sampling_freq(ad9361_phy, SAMPLING_FREQ);
	if (Status != 0) {
		xil_printf("Could not set Tx sampling freq.\r\n");
		return 1;
	}
	Status = ad9361_set_rx_sampling_freq(ad9361_phy, SAMPLING_FREQ);
	if (Status != 0) {
		xil_printf("Could not set Rx sampling freq.\r\n");
		return 1;
	}
	/*
	 * Set Tx and Rx FIR
	 */
	Status = ad9361_set_tx_fir_config(ad9361_phy, tx_fir_config);
	if (Status != 0) {
		xil_printf("Could not set Tx FIR\r\n");
		return 1;
	}
	Status = ad9361_set_rx_fir_config(ad9361_phy, rx_fir_config);
	if (Status != 0) {
		xil_printf("Could not set Rx FIR\r\n");
		return 1;
	}
	// Enable both at the same time
	Status = ad9361_set_trx_fir_en_dis(ad9361_phy, 1);
	if (Status != 0) {
		xil_printf("Could not enable Tx and Rx FIR\r\n");
		return 1;
	}
	// Check status
	Status = ad9361_get_tx_fir_en_dis(ad9361_phy, &en_dis);
	if (Status == 0) {
		xil_printf("Tx FIR status\t %d\r\n", en_dis);
	} else {
		xil_printf("Could not get Tx FIR enable\r\n");
		return 1;
	}
	Status = ad9361_get_rx_fir_en_dis(ad9361_phy, &en_dis);
	if (Status == 0) {
		xil_printf("Rx FIR status\t %d\r\n", en_dis);
	} else {
		xil_printf("Could not get Rx FIR enable\r\n");
		return 1;
	}
	/*
	 * Rf bandwidth
	 */
	Status = ad9361_set_tx_rf_bandwidth(ad9361_phy, RF_BW);
	if (Status != 0) {
		xil_printf("Could not set Tx Rf bandwidth\r\n");
		return 1;
	}
	Status = ad9361_set_rx_rf_bandwidth(ad9361_phy, RF_BW);
	if (Status != 0) {
		xil_printf("Could not set Rx Rf bandwidth\r\n");
		return 1;
	}
	/*
	 * Gain control mode
	 */
	Status = ad9361_set_rx_gain_control_mode(ad9361_phy, 0,
			RF_GAIN_SLOWATTACK_AGC);
	if (Status != 0) {
		xil_printf("Could not set Rx gain control mode for channel 0\r\n");
		return 1;
	}
	/*
	 * Hardware gains
	 */
	Status = ad9361_set_rx_rf_gain(ad9361_phy, 0, -10);
	if (Status != 0) {
		xil_printf("Could not set Rx gain for channel 0\r\n");
		return 1;
	}

	Status = ad9361_get_rx_lo_freq(ad9361_phy, &Value);
	if (Status == 0) {
		xil_printf("LO Frequency\t %u \r\n", Value);
	} else {
		xil_printf("Could not get current LO frequency\r\n");
		return 1;
	}

#if ROE_CPRI_SINK == ROE_SINK_DAC
	dac_init(ad9361_phy, DATA_SEL_DMA, 1);
#endif

#ifndef AXI_ADC_NOT_PRESENT
#if defined XILINX_PLATFORM && defined CAPTURE_SCRIPT
	// NOTE: To prevent unwanted data loss, it's recommended to invalidate
	// cache after each adc_capture() call, keeping in mind that the
	// size of the capture and the start address must be alinged to the size
	// of the cache line.
	mdelay(1000);
	adc_capture(16384, ADC_DDR_BASEADDR);
	Xil_DCacheInvalidateRange(ADC_DDR_BASEADDR, 16384);
#endif
#endif

#ifdef CONSOLE_COMMANDS
	get_help(NULL, 0);

	while (1)
	{
		console_get_command(received_cmd);
		invalid_cmd = 0;
		for (cmd = 0; cmd < cmd_no; cmd++)
		{
			param_no = 0;
			cmd_type = console_check_commands(received_cmd, cmd_list[cmd].name,
					param, &param_no);
			if (cmd_type == UNKNOWN_CMD)
			{
				invalid_cmd++;
			}
			else
			{
				cmd_list[cmd].function(param, param_no);
			}
		}
		if (invalid_cmd == cmd_no)
		{
			console_print("Invalid command!\n");
		}
	}
#endif

	printf("AD9361 Initialization Done.\n");

#ifdef XILINX_PLATFORM
	Xil_DCacheDisable();
	Xil_ICacheDisable();
#endif

	return 0;
}
Exemplo n.º 14
0
int gpio_direction_input(unsigned gpio)
{
	return gpio_direction(gpio, GPIO_DIRECTION_IN);
}
Exemplo n.º 15
0
/***************************************************************************//**
 * @brief main
*******************************************************************************/
int main(void)
{
#ifdef XILINX_PLATFORM
	Xil_ICacheEnable();
	Xil_DCacheEnable();
#endif

	// NOTE: The user has to choose the GPIO numbers according to desired
	// carrier board.
	default_init_param.gpio_resetb = GPIO_RESET_PIN;
#ifdef FMCOMMS5
	default_init_param.gpio_sync = GPIO_SYNC_PIN;
	default_init_param.gpio_cal_sw1 = GPIO_CAL_SW1_PIN;
	default_init_param.gpio_cal_sw2 = GPIO_CAL_SW2_PIN;
#else
	default_init_param.gpio_sync = -1;
	default_init_param.gpio_cal_sw1 = -1;
	default_init_param.gpio_cal_sw2 = -1;
#endif

#ifdef LINUX_PLATFORM
	gpio_init(default_init_param.gpio_resetb);
#else
	gpio_init(GPIO_DEVICE_ID);
#endif
	gpio_direction(default_init_param.gpio_resetb, 1);

	spi_init(SPI_DEVICE_ID, 1, 0);

#if defined FMCOMMS5 || defined PICOZED_SDR
	default_init_param.xo_disable_use_ext_refclk_enable = 1;
#endif

	ad9361_init(&ad9361_phy, &default_init_param);

	ad9361_set_tx_fir_config(ad9361_phy, tx_fir_config);
	ad9361_set_rx_fir_config(ad9361_phy, rx_fir_config);

#ifdef FMCOMMS5
#ifdef LINUX_PLATFORM
	gpio_init(default_init_param.gpio_sync);
#endif
	gpio_direction(default_init_param.gpio_sync, 1);
	default_init_param.id_no = 1;
	default_init_param.gpio_resetb = GPIO_RESET_PIN_2;
#ifdef LINUX_PLATFORM
	gpio_init(default_init_param.gpio_resetb);
#endif
	default_init_param.gpio_sync = -1;
	default_init_param.gpio_cal_sw1 = -1;
	default_init_param.gpio_cal_sw2 = -1;
	default_init_param.rx_synthesizer_frequency_hz = 2300000000UL;
	default_init_param.tx_synthesizer_frequency_hz = 2300000000UL;
	gpio_direction(default_init_param.gpio_resetb, 1);
	ad9361_init(&ad9361_phy_b, &default_init_param);

	ad9361_set_tx_fir_config(ad9361_phy_b, tx_fir_config);
	ad9361_set_rx_fir_config(ad9361_phy_b, rx_fir_config);
#endif

#if defined XILINX_PLATFORM || defined LINUX_PLATFORM
#ifdef DAC_DMA
#ifdef FMCOMMS5
	dac_init(ad9361_phy_b, DATA_SEL_DMA, 0);
#endif
	dac_init(ad9361_phy, DATA_SEL_DMA, 1);
#else
#ifdef FMCOMMS5
	dac_init(ad9361_phy_b, DATA_SEL_DDS, 0);
#endif
	dac_init(ad9361_phy, DATA_SEL_DDS, 1);
#endif
#endif

#ifdef FMCOMMS5
	ad9361_do_mcs(ad9361_phy, ad9361_phy_b);
#endif

#if defined XILINX_PLATFORM && defined CAPTURE_SCRIPT
    // NOTE: To prevent unwanted data loss, it's recommended to invalidate
    // cache after each adc_capture() call, keeping in mind that the
    // size of the capture and the start address must be alinged to the size
    // of the cache line.
	mdelay(1000);
    adc_capture(16384, ADC_DDR_BASEADDR);
    Xil_DCacheInvalidateRange(ADC_DDR_BASEADDR, 16384);
#endif

#ifdef CONSOLE_COMMANDS
	get_help(NULL, 0);

	while(1)
	{
		console_get_command(received_cmd);
		invalid_cmd = 0;
		for(cmd = 0; cmd < cmd_no; cmd++)
		{
			param_no = 0;
			cmd_type = console_check_commands(received_cmd, cmd_list[cmd].name,
											  param, &param_no);
			if(cmd_type == UNKNOWN_CMD)
			{
				invalid_cmd++;
			}
			else
			{
				cmd_list[cmd].function(param, param_no);
			}
		}
		if(invalid_cmd == cmd_no)
		{
			console_print("Invalid command!\n");
		}
	}
#endif

	printf("Done.\n");

#ifdef XILINX_PLATFORM
	Xil_DCacheDisable();
	Xil_ICacheDisable();
#endif

	return 0;
}
Exemplo n.º 16
0
int main(int argc, char **argv) {
    pthread_t pth;
    int opt;
    struct ifreq ifr;
    struct trigger_t trigger_data;
    struct sockaddr_can caddr;
    fd_set readfds, exceptfds;
    struct can_frame frame;
    uint16_t member;
    uint8_t buffer[MAXLEN];

    memset(&trigger_data, 0, sizeof(trigger_data));
    memset(ifr.ifr_name, 0, sizeof(ifr.ifr_name));
    strcpy(ifr.ifr_name, "can0");

    trigger_data.led_pin = -1;
    trigger_data.pb_pin = -1;

    trigger_data.interval = DEF_INTERVAL;

    while ((opt = getopt(argc, argv, "i:l:p:t:fvh?")) != -1) {
	switch (opt) {
	case 'i':
	    strncpy(ifr.ifr_name, optarg, sizeof(ifr.ifr_name));
	    break;
	case 't':
	    trigger_data.interval = atoi(optarg);
	    break;
	case 'l':
	    trigger_data.led_pin = atoi(optarg);
	    break;
	case 'p':
	    trigger_data.pb_pin = atoi(optarg);
	    break;
	case 'v':
	    trigger_data.verbose = 1;
	    break;
	case 'f':
	    trigger_data.background = 0;
	    break;
	case 'h':
	case '?':
	    usage(basename(argv[0]));
	    exit(EXIT_SUCCESS);
	default:
	    usage(basename(argv[0]));
	    exit(EXIT_FAILURE);
	}
    }

    /* prepare CAN socket */
    if ((trigger_data.socket = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
	fprintf(stderr, "error creating CAN socket: %s\n", strerror(errno));
	exit(EXIT_FAILURE);
    }

    memset(&caddr, 0, sizeof(caddr));
    caddr.can_family = AF_CAN;
    if (ioctl(trigger_data.socket, SIOCGIFINDEX, &ifr) < 0) {
	fprintf(stderr, "setup CAN socket error: %s %s\n", strerror(errno), ifr.ifr_name);
	exit(EXIT_FAILURE);
    }
    caddr.can_ifindex = ifr.ifr_ifindex;

    if (bind(trigger_data.socket, (struct sockaddr *)&caddr, sizeof(caddr)) < 0) {
	fprintf(stderr, "error binding CAN socket: %s\n", strerror(errno));
	exit(EXIT_FAILURE);
    }

    trigger_data.caddr = caddr;

    /* Create thread if LED pin defined */
    if ((trigger_data.led_pin) > 0) {
	trigger_data.led_pattern = LED_ST_HB_SLOW;
	gpio_export(trigger_data.led_pin);
	gpio_direction(trigger_data.led_pin, 0);

	if (pthread_mutex_init(&lock, NULL)) {
	    fprintf(stderr, "can't init mutex %s\n", strerror(errno));
	    exit(EXIT_FAILURE);
	}

	if (pthread_create(&pth, NULL, LEDMod, &trigger_data)) {
	    fprintf(stderr, "can't create pthread %s\n", strerror(errno));
	    exit(EXIT_FAILURE);
	}
	if (!trigger_data.background && trigger_data.verbose)
	    printf("created LED thread\n");
    }

    if (trigger_data.background) {
	pid_t pid;

	/* fork off the parent process */
	pid = fork();
	if (pid < 0) {
	    exit(EXIT_FAILURE);
	}
	/* if we got a good PID, then we can exit the parent process. */
	if (pid > 0) {
	    if (trigger_data.verbose)
		printf("Going into background ...\n");
	    exit(EXIT_SUCCESS);
	}
    }

    /* initialize push button */
    if ((trigger_data.pb_pin) > 0) {
	/* first free pin */
	gpio_unexport(trigger_data.pb_pin);
	gpio_export(trigger_data.pb_pin);
	gpio_direction(trigger_data.pb_pin, 1);
	gpio_edge(trigger_data.pb_pin, EDGE_FALLING);
	trigger_data.pb_fd = gpio_open(trigger_data.pb_pin);
    }

    FD_ZERO(&readfds);
    FD_ZERO(&exceptfds);
    /* delete pending push button event */
    if ((trigger_data.pb_pin) > 0) {
	read(trigger_data.pb_fd, NULL, 100);
	lseek(trigger_data.pb_fd, 0, SEEK_SET);
    }
    /* loop forever TODO: if interval is set */
    while (1) {
	FD_SET(trigger_data.socket, &readfds);
	/* extend FD_SET only if push button pin is set */
	if (trigger_data.pb_pin > 0)
	    FD_SET(trigger_data.pb_fd, &exceptfds);
	if (select(MAX(trigger_data.socket, trigger_data.pb_fd) + 1, &readfds, NULL, &exceptfds, NULL) < 0) {
	    fprintf(stderr, "select error: %s\n", strerror(errno));
	    exit(EXIT_FAILURE);
	}
	/* CAN frame event */
	if (FD_ISSET(trigger_data.socket, &readfds)) {
	    if (read(trigger_data.socket, &frame, sizeof(struct can_frame)) < 0)
		fprintf(stderr, "error reading CAN frame: %s\n", strerror(errno));

	    if (frame.can_id & CAN_EFF_FLAG) {
		switch ((frame.can_id & 0x00FF0000UL) >> 16) {
		case 0x31:
		    if (trigger_data.verbose)
			print_can_frame(F_CAN_FORMAT_STRG, &frame);
		    memcpy(&member, frame.data, sizeof(member));
		    member = ntohs(member);
		    /* look for MS2 */
		    if ((member & 0xfff0) == 0x4d50)
			get_ms2_dbsize(&trigger_data);
		    break;
		case 0x41:
		    if (trigger_data.verbose)
			print_can_frame(F_CAN_FORMAT_STRG, &frame);
		    break;
		case 0x42:
		    get_data(&trigger_data, &frame);
		    /* if (trigger_data.verbose)
		       print_can_frame(F_CAN_FORMAT_STRG, &frame); */
		    break;
		default:
		    if (trigger_data.verbose)
			print_can_frame(F_CAN_FORMAT_STRG, &frame);
		    break;
		}
	    }
	}
	/* push button event */
	if (FD_ISSET(trigger_data.pb_fd, &exceptfds)) {
	    set_led_pattern(&trigger_data, LED_ST_HB_FAST);

	    /* wait some time for LED pattern change */
	    usec_sleep(1000 * 1000);
	    /* send CAN Member Ping */
	    frame.can_id = 0x00300300;
	    frame.can_dlc = 0;
	    memset(frame.data, 0, 8);
	    if (send_can_frame(trigger_data.socket, &frame, trigger_data.verbose) < 0)
		fprintf(stderr, "can't send CAN Member Ping: %s\n", strerror(errno));

	    lseek(trigger_data.pb_fd, 0, SEEK_SET);
	    if (read(trigger_data.pb_fd, buffer, sizeof(buffer)) < 0)
		fprintf(stderr, "error reading GPIO status: %s\n", strerror(errno));
	    printf("push button event\n");
	}
    }

    /* TODO : wait until copy is done */

    if ((trigger_data.pb_pin) > 0)
	gpio_unexport(trigger_data.pb_pin);
    if ((trigger_data.led_pin) > 0) {
	gpio_unexport(trigger_data.led_pin);
	pthread_join(pth, (void *)&trigger_data);
	pthread_mutex_unlock(&lock);
    }
    return 0;
}
Exemplo n.º 17
0
/***************************************************************************//**
 * @brief main
*******************************************************************************/
int main(void)
{
#ifdef XILINX_PLATFORM
	Xil_ICacheEnable();
	Xil_DCacheEnable();
#endif

#ifdef ALTERA_PLATFORM
	if (altera_bridge_init()) {
		printf("Altera Bridge Init Error!\n");
		return -1;
	}
#endif

	// NOTE: The user has to choose the GPIO numbers according to desired
	// carrier board.
	default_init_param.gpio_resetb = GPIO_RESET_PIN;
#ifdef FMCOMMS5
	default_init_param.gpio_sync = GPIO_SYNC_PIN;
	default_init_param.gpio_cal_sw1 = GPIO_CAL_SW1_PIN;
	default_init_param.gpio_cal_sw2 = GPIO_CAL_SW2_PIN;
	default_init_param.rx1rx2_phase_inversion_en = 1;
#else
	default_init_param.gpio_sync = -1;
	default_init_param.gpio_cal_sw1 = -1;
	default_init_param.gpio_cal_sw2 = -1;
#endif

#ifdef LINUX_PLATFORM
	gpio_init(default_init_param.gpio_resetb);
#else
	gpio_init(GPIO_DEVICE_ID);
#endif
	gpio_direction(default_init_param.gpio_resetb, 1);

	spi_init(SPI_DEVICE_ID, 1, 0);

	if (AD9364_DEVICE)
		default_init_param.dev_sel = ID_AD9364;
	if (AD9363A_DEVICE)
		default_init_param.dev_sel = ID_AD9363A;

#if defined FMCOMMS5 || defined PICOZED_SDR || defined PICOZED_SDR_CMOS
	default_init_param.xo_disable_use_ext_refclk_enable = 1;
#endif

#ifdef PICOZED_SDR_CMOS
	default_init_param.swap_ports_enable = 1;
	default_init_param.lvds_mode_enable = 0;
	default_init_param.lvds_rx_onchip_termination_enable = 0;
	default_init_param.full_port_enable = 1;
	default_init_param.digital_interface_tune_fir_disable = 1;
#endif

	ad9361_init(&ad9361_phy, &default_init_param);

	ad9361_set_tx_fir_config(ad9361_phy, tx_fir_config);
	ad9361_set_rx_fir_config(ad9361_phy, rx_fir_config);

#ifdef FMCOMMS5
#ifdef LINUX_PLATFORM
	gpio_init(default_init_param.gpio_sync);
#endif
	gpio_direction(default_init_param.gpio_sync, 1);
	default_init_param.id_no = 1;
	default_init_param.gpio_resetb = GPIO_RESET_PIN_2;
#ifdef LINUX_PLATFORM
	gpio_init(default_init_param.gpio_resetb);
#endif
	default_init_param.gpio_sync = -1;
	default_init_param.gpio_cal_sw1 = -1;
	default_init_param.gpio_cal_sw2 = -1;
	default_init_param.rx_synthesizer_frequency_hz = 2300000000UL;
	default_init_param.tx_synthesizer_frequency_hz = 2300000000UL;
	gpio_direction(default_init_param.gpio_resetb, 1);
	ad9361_init(&ad9361_phy_b, &default_init_param);

	ad9361_set_tx_fir_config(ad9361_phy_b, tx_fir_config);
	ad9361_set_rx_fir_config(ad9361_phy_b, rx_fir_config);
#endif

#ifndef AXI_ADC_NOT_PRESENT
#if defined XILINX_PLATFORM || defined LINUX_PLATFORM
#ifdef DAC_DMA
#ifdef FMCOMMS5
	dac_init(ad9361_phy_b, DATA_SEL_DMA, 0);
#endif
	dac_init(ad9361_phy, DATA_SEL_DMA, 1);
#else
#ifdef FMCOMMS5
	dac_init(ad9361_phy_b, DATA_SEL_DDS, 0);
#endif
	dac_init(ad9361_phy, DATA_SEL_DDS, 1);
#endif
#endif
#endif

#ifdef FMCOMMS5
	ad9361_do_mcs(ad9361_phy, ad9361_phy_b);
#endif

#ifndef AXI_ADC_NOT_PRESENT
#if defined XILINX_PLATFORM && defined CAPTURE_SCRIPT
    // NOTE: To prevent unwanted data loss, it's recommended to invalidate
    // cache after each adc_capture() call, keeping in mind that the
    // size of the capture and the start address must be alinged to the size
    // of the cache line.
	mdelay(1000);
    adc_capture(16384, ADC_DDR_BASEADDR);
    Xil_DCacheInvalidateRange(ADC_DDR_BASEADDR, 16384);
#endif
#endif

#ifdef CONSOLE_COMMANDS
	get_help(NULL, 0);

	while(1)
	{
		console_get_command(received_cmd);
		invalid_cmd = 0;
		for(cmd = 0; cmd < cmd_no; cmd++)
		{
			param_no = 0;
			cmd_type = console_check_commands(received_cmd, cmd_list[cmd].name,
											  param, &param_no);
			if(cmd_type == UNKNOWN_CMD)
			{
				invalid_cmd++;
			}
			else
			{
				cmd_list[cmd].function(param, param_no);
			}
		}
		if(invalid_cmd == cmd_no)
		{
			console_print("Invalid command!\n");
		}
	}
#endif

	printf("Done.\n");

#ifdef TDD_SWITCH_STATE_EXAMPLE
	uint32_t ensm_mode;
	if (!ad9361_phy->pdata->fdd) {
		if (ad9361_phy->pdata->ensm_pin_ctrl) {
			gpio_direction(GPIO_ENABLE_PIN, 1);
			gpio_direction(GPIO_TXNRX_PIN, 1);
			gpio_set_value(GPIO_ENABLE_PIN, 0);
			gpio_set_value(GPIO_TXNRX_PIN, 0);
			udelay(10);
			ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode);
			printf("TXNRX control - Alert: %s\n",
					ensm_mode == ENSM_MODE_ALERT ? "OK" : "Error");
			mdelay(1000);

			if (ad9361_phy->pdata->ensm_pin_pulse_mode) {
				while(1) {
					gpio_set_value(GPIO_TXNRX_PIN, 0);
					udelay(10);
					gpio_set_value(GPIO_ENABLE_PIN, 1);
					udelay(10);
					gpio_set_value(GPIO_ENABLE_PIN, 0);
					ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode);
					printf("TXNRX Pulse control - RX: %s\n",
							ensm_mode == ENSM_MODE_RX ? "OK" : "Error");
					mdelay(1000);

					gpio_set_value(GPIO_ENABLE_PIN, 1);
					udelay(10);
					gpio_set_value(GPIO_ENABLE_PIN, 0);
					ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode);
					printf("TXNRX Pulse control - Alert: %s\n",
							ensm_mode == ENSM_MODE_ALERT ? "OK" : "Error");
					mdelay(1000);

					gpio_set_value(GPIO_TXNRX_PIN, 1);
					udelay(10);
					gpio_set_value(GPIO_ENABLE_PIN, 1);
					udelay(10);
					gpio_set_value(GPIO_ENABLE_PIN, 0);
					ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode);
					printf("TXNRX Pulse control - TX: %s\n",
							ensm_mode == ENSM_MODE_TX ? "OK" : "Error");
					mdelay(1000);

					gpio_set_value(GPIO_ENABLE_PIN, 1);
					udelay(10);
					gpio_set_value(GPIO_ENABLE_PIN, 0);
					ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode);
					printf("TXNRX Pulse control - Alert: %s\n",
							ensm_mode == ENSM_MODE_ALERT ? "OK" : "Error");
					mdelay(1000);
				}
			} else {
				while(1) {
					gpio_set_value(GPIO_TXNRX_PIN, 0);
					udelay(10);
					gpio_set_value(GPIO_ENABLE_PIN, 1);
					udelay(10);
					ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode);
					printf("TXNRX control - RX: %s\n",
							ensm_mode == ENSM_MODE_RX ? "OK" : "Error");
					mdelay(1000);

					gpio_set_value(GPIO_ENABLE_PIN, 0);
					udelay(10);
					ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode);
					printf("TXNRX control - Alert: %s\n",
							ensm_mode == ENSM_MODE_ALERT ? "OK" : "Error");
					mdelay(1000);

					gpio_set_value(GPIO_TXNRX_PIN, 1);
					udelay(10);
					gpio_set_value(GPIO_ENABLE_PIN, 1);
					udelay(10);
					ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode);
					printf("TXNRX control - TX: %s\n",
							ensm_mode == ENSM_MODE_TX ? "OK" : "Error");
					mdelay(1000);

					gpio_set_value(GPIO_ENABLE_PIN, 0);
					udelay(10);
					ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode);
					printf("TXNRX control - Alert: %s\n",
							ensm_mode == ENSM_MODE_ALERT ? "OK" : "Error");
					mdelay(1000);
				}
			}
		} else {
			while(1) {
				ad9361_set_en_state_machine_mode(ad9361_phy, ENSM_MODE_RX);
				ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode);
				printf("SPI control - RX: %s\n",
						ensm_mode == ENSM_MODE_RX ? "OK" : "Error");
				mdelay(1000);

				ad9361_set_en_state_machine_mode(ad9361_phy, ENSM_MODE_ALERT);
				ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode);
				printf("SPI control - Alert: %s\n",
						ensm_mode == ENSM_MODE_ALERT ? "OK" : "Error");
				mdelay(1000);

				ad9361_set_en_state_machine_mode(ad9361_phy, ENSM_MODE_TX);
				ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode);
				printf("SPI control - TX: %s\n",
						ensm_mode == ENSM_MODE_TX ? "OK" : "Error");
				mdelay(1000);

				ad9361_set_en_state_machine_mode(ad9361_phy, ENSM_MODE_ALERT);
				ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode);
				printf("SPI control - Alert: %s\n",
						ensm_mode == ENSM_MODE_ALERT ? "OK" : "Error");
				mdelay(1000);
			}
		}
	}
#endif

#ifdef XILINX_PLATFORM
	Xil_DCacheDisable();
	Xil_ICacheDisable();
#endif

#ifdef ALTERA_PLATFORM
	if (altera_bridge_uninit()) {
		printf("Altera Bridge Uninit Error!\n");
		return -1;
	}
#endif

	return 0;
}