Altera Embedded Peripherals IP User Manual
Page 104

RXMessage[0], Match);
}
break;
case 1:
printf("Ping Pong Baud Rate Test: UART#1 to UART#0\n");
for(j=0; j
altera_16550_uart_write(uart_1, &TXMessage[j], 1, 0);
usleep(1000);
if(ERROR== altera_16550_uart_read(uart_0, RXMessage, 1, 0))
return ERROR;
if(TXMessage[j]==RXMessage[0]) Match=1; else return ERROR;
printf("Sent:'%c', Received:'%c', Match:%d\n", TXMessage[j],
RXMessage[0], Match);
}
break;
default:
break;
}
usleep(1000);
}
}
free(UART0_Config);
free(UART1_Config);
return SUCCESS;
}
int UARTLineControlTest()
{
UartConfig *UART0_Config = malloc(1*sizeof(UartConfig));
UartConfig *UART1_Config = malloc(1*sizeof(UartConfig));
int x=0, y=0, z=0, Match=0;
const int nDataBit = 2, nParityBit=3, nStopBit=2;
int DataBitCoverage[]= { /*CS_5, CS_6,*/ CS_7, CS_8};
int ParityBitCoverage[]= {ODD_PARITY, EVEN_PARITY, NO_PARITY};
int StopBitCoverage[]= {STOPB_1, STOPB_2};
altera_16550_uart_state* uart_0;
altera_16550_uart_state* uart_1;
printf("================================ UART Line Control Test Starts Here
=======================================\n");
uart_0 = altera_16550_uart_open ("/dev/a_16550_uart_0");
uart_1 = altera_16550_uart_open ("/dev/a_16550_uart_1");
for(x=0; x
for (y=0; y
for (z=0; z
UARTDefaultConfig(UART0_Config);
UARTDefaultConfig(UART1_Config);
UART0_Config->stop_bit=StopBitCoverage[x];
UART1_Config->stop_bit=StopBitCoverage[x];
UART0_Config->parity_bit=ParityBitCoverage[y];
UART1_Config->parity_bit=ParityBitCoverage[y];
UART0_Config->data_bit=DataBitCoverage[z];
UART1_Config->data_bit=DataBitCoverage[z];
printf("Testing : Stop Bit=%d, Data Bit=%d, Parity Bit=%d\n",
UART0_Config->stop_bit, UART0_Config->data_bit, UART0_Config->parity_bit);
if(ERROR == alt_16550_uart_config (uart_0, UART0_Config)) return
ERROR;
if(ERROR == alt_16550_uart_config (uart_1, UART1_Config)) return
ERROR;
altera_16550_uart_write(uart_0, &TXMessage[0], 1, 0);
9-18
Driver Examples
UG-01085
2014.24.07
Altera Corporation
16550 UART