コード例 #1
0
/**
 * \brief pio_capture Application entry point.
 *
 * \return Unused (ANSI-C compatibility).
 *
 */
int main(void)
{
	uint8_t uc_i;
	uint32_t ul_length;
	uint32_t ul_mode;
	uint8_t uc_key;
	static uint8_t uc_rx_even_only;
	static uint8_t uc_tx_without_en;

	/* Initialize the SAM system. */
	sysclk_init();
	board_init();

	/* Configure UART for debug message output. */
	configure_console();

	/* Configure PIOA clock. */
	pmc_enable_periph_clk(ID_PIOA);
	pmc_enable_periph_clk(ID_PIOC);

	/* Configure PIO Capture handler */
	pio_capture_handler_set(capture_handler);

	/* Output example information. */
	puts(STRING_HEADER);

	printf("Frequency: %d MHz.\r\n",
			(uint8_t) (sysclk_get_cpu_hz() / 1000000));

	printf("Press r to Receive data on PIO Parallel Capture.\r\n");
	printf("Press s to Send data on PIO Parallel Capture.\r\n");
	uc_key = 0;
	while ((uc_key != 'r') && (uc_key != 's')) {
		uart_read(CONSOLE_UART, &uc_key);
	}
	if (uc_key == 'r') {
		printf("** RECEIVE mode **\r\n");

		/* Initialize PIO capture mode value. */
		ul_mode = 0;
		/* Set up the parallel capture mode data size as 8 bits. */
		ul_mode |= 0 << PIO_PCMR_DSIZE_Pos;

		printf("Press y to sample the data when both data enable pins are enabled.\r\n");
		printf("Press n to sample the data, don't care the status of the data enable pins.\r\n");
		uc_key = 0;
		while ((uc_key != 'y') && (uc_key != 'n')) {
			uart_read(CONSOLE_UART, &uc_key);
		}
		if (uc_key == 'y') {
			/* Sample the data when both data enable pins are enabled. */
			ul_mode &= ~PIO_PCMR_ALWYS;
			printf("Receive data when both data enable pins are enabled.\r\n");
		} else {
			/* Sample the data, don't care the status of the data enable pins. */
			ul_mode |= PIO_PCMR_ALWYS;
			printf("Receive data, don't care the status of the data enable pins.\r\n");
		}
		printf("Press y to sample all the data\r\n");
		printf("Press n to sample the data only one out of two.\r\n");
		uc_key = 0;
		while ((uc_key != 'y') && (uc_key != 'n')) {
			uart_read(CONSOLE_UART, &uc_key);
		}
		if (uc_key == 'y') {
			/* Sample all the data. */
			ul_mode &= ~PIO_PCMR_HALFS;
			printf("All data are sampled.\r\n");
		} else {
			/* Sample the data only one out of two. */
			ul_mode |= PIO_PCMR_HALFS;
			/* Only if half-Sampling is set, data with an even index are sampled. */
			ul_mode &= ~PIO_PCMR_FRSTS;
			printf("Only one out of two data is sampled, with an even index.\r\n");
		}

		/* Initialize PIO Parallel Capture function. */
		pio_capture_set_mode(PIOA, ul_mode);
		pio_capture_enable(PIOA);

		/* Disable all PIOA I/O line interrupt. */
		pio_disable_interrupt(PIOA, 0xFFFFFFFF);

		/* Configure and enable interrupt of PIO. */
		NVIC_DisableIRQ(PIOA_IRQn);
		NVIC_ClearPendingIRQ(PIOA_IRQn);
		NVIC_SetPriority(PIOA_IRQn, PIO_IRQ_PRI);
		NVIC_EnableIRQ(PIOA_IRQn);

		while (1) {
			g_uc_cbk_received = 0;

			/* Clear Receive buffer. */
			for (uc_i = 0; uc_i < SIZE_BUFF_RECEPT; uc_i++) {
				pio_rx_buffer[uc_i] = 0;
			}

			/* Set up PDC receive buffer, waiting for 64 bytes. */
			packet_t.ul_addr = (uint32_t) pio_rx_buffer;
			packet_t.ul_size = SIZE_BUFF_RECEPT;
			p_pdc = pio_capture_get_pdc_base(PIOA);
			pdc_rx_init(p_pdc, &packet_t, NULL);

			/* Enable PDC transfer. */
			pdc_enable_transfer(p_pdc, PERIPH_PTCR_RXTEN);

			/* Configure the PIO capture interrupt mask. */
			pio_capture_enable_interrupt(PIOA,
					(PIO_PCIER_ENDRX | PIO_PCIER_RXBUFF));

			printf("Waiting...\r\n");
			while (g_uc_cbk_received == 0) {
			}
		}
	} else if (uc_key == 's') {
		printf("** SEND mode **\r\n");
		printf("This is for debug purpose only !\r\n");
		printf("Frequency of PIO controller clock must be strictly superior");
		printf("to 2 times the frequency of the clock of the device which");
		printf(" generates the parallel data.\r\n");
		printf("\r\nPlease connect the second board, ");
		printf("and put it in receive mode.\r\n");

		/* Configure PIO pins which simulate as a sensor. */
		pio_configure_pin_group(PIOA, PIO_CAPTURE_CONTROL_PIN_MSK,
			PIO_CAPTURE_OUTPUT_PIN_FLAGS);
		pio_configure_pin_group(PIOC, PIO_CAPTURE_DATA_PINS_MASK,
			PIO_CAPTURE_OUTPUT_PIN_FLAGS);
		pio_set_pin_low(PIO_CAPTURE_EN1_IDX);
		pio_set_pin_low(PIO_CAPTURE_EN2_IDX);
		pio_set_pin_low(PIO_CAPTURE_CCLK_IDX);

		/* Enable sync. output data. */
		pio_enable_output_write(PIOC, PIO_CAPTURE_DATA_PINS_MASK);

		/* Initialize the capture data line. */
		pio_sync_output_write(PIOC, 0);

		printf("Press y to send data with data enable pins.\r\n");
		printf("Press n to send data without data enable pins.\r\n");

		uc_key = 0;
		while ((uc_key != 'y') && (uc_key != 'n')) {
			uart_read(CONSOLE_UART, &uc_key);
		}
		if (uc_key == 'y') {
			uc_tx_without_en = 0;
			printf("Send data with both data enable pins enabled.\r\n");
		} else {
			uc_tx_without_en = 1;
			printf("Send data without enabling the data enable pins.\r\n");
		}

		printf("Press y to indicate that receiver samples all data.\r\n");
		printf("Press n to indicate that receiver samples data with an even index.\r\n");
		uc_key = 0;
		while ((uc_key != 'y') && (uc_key != 'n')) {
			uart_read(CONSOLE_UART, &uc_key);
		}
		if (uc_key == 'y') {
			uc_rx_even_only = 0;
			printf("Receiver samples all data.\r\n");
		} else {
			uc_rx_even_only = 1;
			printf("Receiver samples data with an even index.\r\n");
		}

		ul_length = SIZE_BUFF_RECEPT * (1 + uc_rx_even_only);
		while (1) {
			if (uc_tx_without_en) {
				printf("\r\nSend data without enabling the data enable pins.\r\n");
			} else {
				printf("\r\nSend data with both data enable pins enabled.\r\n");
			}
			if (!uc_tx_without_en) {
				/* Set enable pins. */
				pio_set_pin_high(PIO_CAPTURE_EN1_IDX);
				pio_set_pin_high(PIO_CAPTURE_EN2_IDX);
			}
			for (uc_i = 0; uc_i < ul_length;) {
				/* Send data. */
				pio_sync_output_write(PIOC,
						(uc_i << PIO_CAPTURE_DATA_POS));
				/* Set clock. */
				pio_set_pin_high(PIO_CAPTURE_CCLK_IDX);
				delay_us(20);
				/* Clear clock. */
				pio_set_pin_low(PIO_CAPTURE_CCLK_IDX);
				delay_us(20);
				uc_i++;
			}
			if (!uc_tx_without_en) {
				/* Clear enable pins. */
				pio_set_pin_low(PIO_CAPTURE_EN1_IDX);
				pio_set_pin_low(PIO_CAPTURE_EN2_IDX);
			}
			printf("Press a key.\r\n");
			while (uart_read(CONSOLE_UART, &uc_key)) {
			}
		}
	}

	return 0;
}
コード例 #2
0
ファイル: init.c プロジェクト: EwanLu/chipwhisperer
void iopins_normal(void)
{
	/* Configure LED pins */
	gpio_configure_pin(LED0_GPIO, LED0_FLAGS);
	gpio_configure_pin(LED1_GPIO, LED1_FLAGS);
	
	/* Configure MOSFET for turning on-off system */
	gpio_configure_pin(PIN_PWRON_GPIO, PIN_PWRON_FLAGS);
	board_power(0);
	
	/* FPGA Programming pins */
	FPGA_NPROG_SETUP();
	FPGA_NPROG_HIGH();
	
	/* FPGA External memory interface */
	//Allow sync writing to address pins
	gpio_configure_group(FPGA_ADDR_PORT, FPGA_ADDR_PINS, (PIO_TYPE_PIO_OUTPUT_0 | PIO_DEFAULT));
	pio_enable_output_write(FPGA_ADDR_PORT, FPGA_ADDR_PINS);
	
	//ALE pin under SW control
	gpio_configure_pin(FPGA_ALE_GPIO, FPGA_ALE_FLAGS);
	gpio_set_pin_high(FPGA_ALE_GPIO);

#ifdef CONF_BOARD_UART_CONSOLE
	/* Configure UART pins */
	gpio_configure_group(PINS_UART_PIO, PINS_UART, PINS_UART_FLAGS);
#endif

#ifdef CONF_BOARD_PWM_LED0
	/* Configure PWM LED0 pin */
	gpio_configure_pin(PIN_PWM_LED0_GPIO, PIN_PWM_LED0_FLAGS);
#endif

#ifdef CONF_BOARD_PWM_LED1
	/* Configure PWM LED1 pin */
	gpio_configure_pin(PIN_PWM_LED1_GPIO, PIN_PWM_LED1_FLAGS);
#endif

#ifdef CONF_BOARD_TWI0
	gpio_configure_pin(TWI0_DATA_GPIO, TWI0_DATA_FLAGS);
	gpio_configure_pin(TWI0_CLK_GPIO, TWI0_CLK_FLAGS);
#endif

	/* Configure SPI pins */
#ifdef CONF_BOARD_SPI
	gpio_configure_pin(SPI_MISO_GPIO, SPI_MISO_FLAGS);
	gpio_configure_pin(SPI_MOSI_GPIO, SPI_MOSI_FLAGS);
	gpio_configure_pin(SPI_SPCK_GPIO, SPI_SPCK_FLAGS);

	/**
	 * For NPCS 1, 2, and 3, different PINs can be used to access the same NPCS line.
	 * Depending on the application requirements, the default PIN may not be available.
	 * Hence a different PIN should be selected using the CONF_BOARD_SPI_NPCS_GPIO and
	 * CONF_BOARD_SPI_NPCS_FLAGS macros.
	 */

#  ifdef CONF_BOARD_SPI_NPCS0
	gpio_configure_pin(SPI_NPCS0_GPIO, SPI_NPCS0_FLAGS);
#  endif

#endif /* CONF_BOARD_SPI */

#ifdef CONF_BOARD_USART_RXD
	/* Configure USART RXD pin */
	gpio_configure_pin(PIN_USART1_RXD_IDX, PIN_USART1_RXD_FLAGS);
#endif

#ifdef CONF_BOARD_USART_TXD
	/* Configure USART TXD pin */
	gpio_configure_pin(PIN_USART1_TXD_IDX, PIN_USART1_TXD_FLAGS);
#endif

#ifdef CONF_BOARD_USART_SCK
	/* Configure USART synchronous communication SCK pin */
	gpio_configure_pin(PIN_USART1_SCK_IDX, PIN_USART1_SCK_FLAGS);
#endif

#ifdef CONF_BOARD_SMC_PSRAM
	gpio_configure_pin(PIN_EBI_DATA_BUS_D0, PIN_EBI_DATA_BUS_FLAG1);
	gpio_configure_pin(PIN_EBI_DATA_BUS_D1, PIN_EBI_DATA_BUS_FLAG1);
	gpio_configure_pin(PIN_EBI_DATA_BUS_D2, PIN_EBI_DATA_BUS_FLAG1);
	gpio_configure_pin(PIN_EBI_DATA_BUS_D3, PIN_EBI_DATA_BUS_FLAG1);
	gpio_configure_pin(PIN_EBI_DATA_BUS_D4, PIN_EBI_DATA_BUS_FLAG1);
	gpio_configure_pin(PIN_EBI_DATA_BUS_D5, PIN_EBI_DATA_BUS_FLAG1);
	gpio_configure_pin(PIN_EBI_DATA_BUS_D6, PIN_EBI_DATA_BUS_FLAG1);
	gpio_configure_pin(PIN_EBI_DATA_BUS_D7, PIN_EBI_DATA_BUS_FLAG1);
	gpio_configure_pin(PIN_EBI_DATA_BUS_D8, PIN_EBI_DATA_BUS_FLAG1);
	gpio_configure_pin(PIN_EBI_DATA_BUS_D9, PIN_EBI_DATA_BUS_FLAG1);
	gpio_configure_pin(PIN_EBI_DATA_BUS_D10, PIN_EBI_DATA_BUS_FLAG1);
	gpio_configure_pin(PIN_EBI_DATA_BUS_D11, PIN_EBI_DATA_BUS_FLAG1);
	gpio_configure_pin(PIN_EBI_DATA_BUS_D12, PIN_EBI_DATA_BUS_FLAG1);
	gpio_configure_pin(PIN_EBI_DATA_BUS_D13, PIN_EBI_DATA_BUS_FLAG1);
	gpio_configure_pin(PIN_EBI_DATA_BUS_D14, PIN_EBI_DATA_BUS_FLAG1);
	gpio_configure_pin(PIN_EBI_DATA_BUS_D15, PIN_EBI_DATA_BUS_FLAG2);
	gpio_configure_pin(PIN_EBI_NRD, PIN_EBI_NRD_FLAGS);
	gpio_configure_pin(PIN_EBI_NWE, PIN_EBI_NWE_FLAGS);
	gpio_configure_pin(PIN_EBI_NCS0, PIN_EBI_NCS0_FLAGS);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_NBS0, PIN_EBI_ADDR_BUS_FLAG1);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_NBS1, PIN_EBI_ADDR_BUS_FLAG2);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_A1, PIN_EBI_ADDR_BUS_FLAG1);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_A2, PIN_EBI_ADDR_BUS_FLAG2);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_A3, PIN_EBI_ADDR_BUS_FLAG2);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_A4, PIN_EBI_ADDR_BUS_FLAG2);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_A5, PIN_EBI_ADDR_BUS_FLAG2);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_A6, PIN_EBI_ADDR_BUS_FLAG2);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_A7, PIN_EBI_ADDR_BUS_FLAG2);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_A8, PIN_EBI_ADDR_BUS_FLAG2);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_A9, PIN_EBI_ADDR_BUS_FLAG2);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_A10, PIN_EBI_ADDR_BUS_FLAG2);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_A11, PIN_EBI_ADDR_BUS_FLAG2);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_A12, PIN_EBI_ADDR_BUS_FLAG2);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_A13, PIN_EBI_ADDR_BUS_FLAG2);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_A14, PIN_EBI_ADDR_BUS_FLAG2);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_A15, PIN_EBI_ADDR_BUS_FLAG2);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_A16, PIN_EBI_ADDR_BUS_FLAG2);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_A17, PIN_EBI_ADDR_BUS_FLAG2);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_A18, PIN_EBI_ADDR_BUS_FLAG2);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_A19, PIN_EBI_ADDR_BUS_FLAG2);
	gpio_configure_pin(PIN_EBI_ADDR_BUS_A20, PIN_EBI_ADDR_BUS_FLAG2);
#endif


#ifdef CONF_BOARD_ISO7816_RST
	/* Configure ISO7816 card reset pin */
	gpio_configure_pin(PIN_ISO7816_RST_IDX, PIN_ISO7816_RST_FLAG);
#endif

#ifdef CONF_BOARD_ISO7816
	/* Configure ISO7816 interface TXD & SCK pin */
	gpio_configure_pin(PIN_USART0_TXD_IDX, PIN_USART0_TXD_FLAGS);
	gpio_configure_pin(PIN_USART0_SCK_IDX, PIN_USART0_SCK_FLAGS);
#endif

#ifdef CONF_BOARD_TWI0
	gpio_configure_pin(TWI0_DATA_GPIO, TWI0_DATA_FLAGS);
	gpio_configure_pin(TWI0_CLK_GPIO, TWI0_CLK_FLAGS);
#endif

#ifdef CONF_BOARD_PCK0
	gpio_configure_pin(PIN_PCK0, PIN_PCK0_FLAGS);
#endif

#ifdef CONF_BOARD_PCK1
gpio_configure_pin(PIN_PCK1, PIN_PCK1_FLAGS);
#endif

#if defined(CONF_BOARD_USB_PORT)
#  if defined(CONF_BOARD_USB_VBUS_DETECT)
	gpio_configure_pin(USB_VBUS_PIN, USB_VBUS_FLAGS);
#  endif
#endif	
}