Exemplo n.º 1
0
/**
 * \brief Start capture process.
 *
 */
static void ov7740_test_capture_process_run(const struct test_case* const test)
{
	if (g_ul_init_error_flag == true) {
		/* Return error if previous test about initialization failed */
		test_assert_true(test, 0, "OV7740 capture test failed!");
	} else {
		/* Enable vsync interrupt */
		pio_enable_interrupt(OV7740_VSYNC_PIO, OV7740_VSYNC_MASK);

		/* Capture acquisition will start on rising edge of Vsync
		 * signal.
		 * So wait vsync_flag = 1 before starting the process
		 */
		while (!g_ul_vsync_flag) {
		}

		/* Enable vsync interrupt */
		pio_disable_interrupt(OV7740_VSYNC_PIO, OV7740_VSYNC_MASK);

		/* Reset vsync flag */
		g_ul_vsync_flag = false;

		/* Configure the PDC Buffer and next Buffer for image capture */
		pio_capture_to_buffer(OV7740_VSYNC_PIO, g_auc_capture_buffer,
				sizeof(g_auc_capture_buffer));

		/* Enable PIO capture */
		pio_capture_enable(OV7740_DATA_BUS_PIO);

		/* Wait for the end of capture of the g_auc_capture_buffer */
		while (!((OV7740_DATA_BUS_PIO->PIO_PCISR & PIO_PCIMR_ENDRX) ==
				PIO_PCIMR_ENDRX)) {
		}
	}
}
Exemplo n.º 2
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;
}