int main(void)
{
/* UART return code */
ADI_UART_RESULT eResult;
/* SEC return code */
ADI_SEC_RESULT eSECResult;
/* Tx size */
uint32_t nTxSize = 1;
/* Flag which indicates whether to stop the program */
_Bool bStopFlag = false;
/**
* Initialize managed drivers and/or services that have been added to
* the project.
* @return zero on success
*/
adi_initComponents();
/**
* The default startup code does not include any functionality to allow
* core 0 to enable core 1. A convenient way to enable core 1 is to use the
* 'adi_core_1_enable' function.
*/
// adi_core_1_enable();
/* Begin adding your custom code here */
printf("UART Char echo blocking mode example \n");
// /* Set the Software controlled switches to default values */
// ConfigSoftSwitches();
//
// /* Initialize Power service */
if(adi_pwr_Init(CLKIN, CORE_MAX, SYSCLK_MAX, VCO_MIN) != ADI_PWR_SUCCESS)
{
REPORT_ERROR("Failed to initialize power service \n");
return FAILED;
}
// /*
// * Initialize UART
// */
// /* Open UART driver */
if((eResult = adi_uart_Open(UART_DEVICE_NUM,
ADI_UART_DIR_BIDIRECTION,
gUARTMemory,
ADI_UART_BIDIR_DMA_MEMORY_SIZE,
&ghUART)) != ADI_UART_SUCCESS)
{
REPORT_ERROR("Could not open UART Device 0x%08X \n", eResult);
return FAILED;
}
// /* Set the UART Mode */
if((eResult = adi_uart_SetMode(ghUART,
ADI_UART_MODE_UART
)) != ADI_UART_SUCCESS)
{
REPORT_ERROR("Could not set the Mode 0x%08X \n", eResult);
return FAILED;
}
//
//
// /* Set UART Baud Rate */
if((eResult = adi_uart_SetBaudRate(ghUART,
BAUD_RATE
)) != ADI_UART_SUCCESS)
{
REPORT_ERROR("Could not set the Baud Rate 0x%08X \n", eResult);
return FAILED;
}
//
// /* Set number of stop bits */
if((eResult = adi_uart_SetNumStopBits(ghUART,
ADI_UART_ONE_STOPBIT
)) != ADI_UART_SUCCESS)
{
REPORT_ERROR("Could not set the stop bits 0x%08X \n", eResult);
return FAILED;
}
//
// /* Set number of stop bits */
if((eResult = adi_uart_SetWordLen(ghUART,
ADI_UART_WORDLEN_8BITS
)) != ADI_UART_SUCCESS)
{
REPORT_ERROR("Could not set word length 0x%08X \n", eResult);
return FAILED;
}
//
printf("Setup Hyperterminal as described in Readme file. \n");
printf("Press any key on the key board and notice the character being echoed to Hyperterminal. \n");
printf("\n Press return key to stop the program.\n");
//
char szs[16] = "start..";
memcpy(RxBuffer,szs,strlen(szs));
/* Write back the character */
if((eResult = adi_uart_Write(ghUART,
&RxBuffer[0],
strlen(szs)
)) != ADI_UART_SUCCESS)
{
REPORT_ERROR("Could not do a write 0x%08X \n", eResult);
return FAILED;
}
// /* UART processing loop */
while(bStopFlag == false)
{
// /* Read a character */
if((eResult = adi_uart_Read(ghUART,
&RxBuffer[0],
1
)) != ADI_UART_SUCCESS)
{
REPORT_ERROR("Could not do a read 0x%08X \n", eResult);
return FAILED;
}
/* If return character is pressed, write back \n character along with \r */
if(RxBuffer[0] == '\r')
{
RxBuffer[1] = '\n';
/* Transmit two characters in this case */
nTxSize = 2u;
/* Stop the program upon receiving carriage return */
bStopFlag = true;
}
/* Write back the character */
if((eResult = adi_uart_Write(ghUART,
&RxBuffer[0],
nTxSize
)) != ADI_UART_SUCCESS)
{
REPORT_ERROR("Could not do a write 0x%08X \n", eResult);
return FAILED;
}
}
/* Close the UART */
if((eResult = adi_uart_Close(ghUART)) != ADI_UART_SUCCESS)
{
REPORT_ERROR("Could not close UART driver 0x%08X \n", eResult);
return FAILED;
}
// return PASSED;
return 0;
}