Exemple #1
0
/**
 * \brief Interrupt handler. Record the number of bytes received,
 * and then restart a read transfer on the UART if the transfer was stopped.
 */
void TC_UART_Handler(void)
{
	uint32_t ul_status;
	uint32_t ul_byte_total = 0;

	/* Read TC_UART Status. */
	ul_status = tc_get_status(TC_UART, TC_UART_CHN);

	/* RC compare. */
	if ((ul_status & TC_SR_CPCS) == TC_SR_CPCS) {
#ifdef CONF_BOARD_UART0
		if (buart_chn_open[0]) {
			/* Flush PDC buffer. */
			ul_byte_total = UART_BUFFER_SIZE - pdc_read_rx_counter(g_p_uart_pdc0);
			if (ul_byte_total > 0) {
				if (ul_byte_total == num_bytes_rx_uart0) {
					/* Disable timer. */
					tc_stop(TC_UART, TC_UART_CHN);

					/* Log current size */
					gs_ul_size_uart_buf0 = ul_byte_total;

					/* Stop DMA UART_RX -> force Uart Handler*/
					g_st_uart_rx_packet0.ul_size = 0;
					pdc_rx_init(g_p_uart_pdc0, &g_st_uart_rx_packet0, NULL);
				} else {
					num_bytes_rx_uart0 = ul_byte_total;
				}
			} else {
				num_bytes_rx_uart0 = 0;
			}
		}
#endif
#ifdef CONF_BOARD_UART1
		if (buart_chn_open[1]) {
			/* Flush PDC buffer. */
			ul_byte_total = UART_BUFFER_SIZE - pdc_read_rx_counter(g_p_uart_pdc1);
			if (ul_byte_total > 0) {
				if (ul_byte_total == num_bytes_rx_uart1) {
					/* Disable timer. */
					tc_stop(TC_UART, TC_UART_CHN);

					/* Log current size */
					gs_ul_size_uart_buf1 = ul_byte_total;

					/* Stop DMA UART_RX -> force Uart Handler*/
					g_st_uart_rx_packet1.ul_size = 0;
					pdc_rx_init(g_p_uart_pdc1, &g_st_uart_rx_packet1, NULL);
				} else {
					num_bytes_rx_uart1 = ul_byte_total;
				}
			} else {
				num_bytes_rx_uart1 = 0;
			}
		}
#endif
	}
}
Exemple #2
0
/**
 *  \brief Interrupt handler for TC0.
 *
 * Display the number of bytes received during the last second and the total
 * number of bytes received, and then restart a read transfer on the USART if it
 * was stopped.
 */
void TC0_Handler(void)
{
	uint32_t ul_status;
	static uint32_t bytes_total = 0;

	/* Read TC0 status. */
	ul_status = tc_get_status(TC0, 0);

	/* RC compare. */
	if ((ul_status & TC_SR_CPCS) == TC_SR_CPCS) {
		if((pdc_read_rx_counter(g_p_pdc) != 0) &&
				(pdc_read_rx_counter(g_p_pdc) != BUFFER_SIZE)) {
			if(pdc_read_rx_next_counter(g_p_pdc) == 0) {
				g_ul_bytes_received += (2 * BUFFER_SIZE - pdc_read_rx_counter(g_p_pdc));
			} else {
				g_ul_bytes_received += (BUFFER_SIZE - pdc_read_rx_counter(g_p_pdc));
			}
			memset(gs_dump_buffer, 0, BUFFER_SIZE);
			memcpy(gs_dump_buffer, gs_puc_buffer, BUFFER_SIZE -
					pdc_read_rx_counter(g_p_pdc));
		} else if((pdc_read_rx_counter(g_p_pdc) == BUFFER_SIZE) &&
				(pdc_read_rx_next_counter(g_p_pdc) == 0)) {
			g_ul_bytes_received += BUFFER_SIZE;
			memcpy(gs_dump_buffer, gs_puc_buffer, BUFFER_SIZE);
		}

		/* Display info. */
		bytes_total += g_ul_bytes_received;
		memset(g_puc_string, 0, BUFFER_SIZE);
		sprintf((char *)g_puc_string, "Bps: %4lu; Tot: %6lu\r\n",
				(unsigned long)g_ul_bytes_received,
				(unsigned long)bytes_total);
		usart_write_line(BOARD_USART, (char *)g_puc_string);
		/* Resume transfer */
		g_st_packet.ul_addr = (uint32_t)gs_puc_buffer;
		g_st_packet.ul_size = BUFFER_SIZE;
		g_st_nextpacket.ul_addr = (uint32_t)gs_puc_nextbuffer;
		g_st_nextpacket.ul_size = BUFFER_SIZE;
		pdc_rx_init(g_p_pdc, &g_st_packet, &g_st_nextpacket);
			usart_enable_interrupt(BOARD_USART, US_IER_RXBUFF);

		g_ul_bytes_received = 0;
	}
}