Commit 9af215bc authored by Mahmoud Rushdi's avatar Mahmoud Rushdi Committed by Oliver Horst
Browse files

[chg] Check if the UART controller is initialized.

parent b88f17ae
/**
* \file
* \brief UART driver abstraction (platform specific part: xilinx zcu102).
*/
/******************************************************************************/
/*** Includes ***/
/******************************************************************************/
#include "freertos/hal/drivers/uart.h"
#include "xil/xparameters.h"
#include "xil/drivers/xuartps_hw.h"
#include "xil/drivers/xuartps.h"
/******************************************************************************/
/*** Declarations ***/
/******************************************************************************/
/******************************************************************************/
/*** Defines ***/
/******************************************************************************/
#define MAX_NUM_UART_CONTROLLERS 2U /* Maximum number of supported UART
Controllers */
/******************************************************************************/
/*** Type definitions ***/
/******************************************************************************/
typedef struct
{
BaseType_t isCtrlInit; /* Is the controller already initialized? */
XUartPs uartXilinxInst; /* Instances of Xilinx UART controller */
uint32_t baudrate; /* Requested UART Baud Rate, in bit/s */
}uartInstance_t;
/******************************************************************************/
/*** Variables ***/
/******************************************************************************/
/* Instances of the UART controllers */
static uartInstance_t uartInstance[MAX_NUM_UART_CONTROLLERS];
/******************************************************************************/
/*** Prototypes ***/
/******************************************************************************/
/******************************************************************************/
/*** Implementation ***/
/******************************************************************************/
void hal_uart_setup(void)
{
......@@ -10,12 +56,103 @@ void hal_uart_setup(void)
int hal_uart_init_channel(hal_io_handle_t handle, uint32_t baudrate)
{
uartInstance_t *uartInstPtr;
XUartPs *xilUartPtr;
XUartPs_Config *cfgPtr;
int status, i;
if (handle >= MAX_NUM_UART_CONTROLLERS )
{
// Unsupported handle
// xil_printf( "UART: hal_uart_init_channel: handle should be less than %d. \n", MAX_NUM_UART_CONTROLLERS);
return pdFAIL;
}
else
{
uartInstPtr = & uartInstance[handle];
xilUartPtr = & uartInstPtr->uartXilinxInst;
cfgPtr = XUartPs_LookupConfig( handle );
if ( !cfgPtr )
{
// xil_printf( "UART: hal_uart_init_channel: handle can't be resolved. \n");
return pdFAIL;
}
else
{
uartInstPtr->uartXilinxInst.Config = *cfgPtr;
}
status = XUartPs_CfgInitialize(
xilUartPtr,
&xilUartPtr->Config,
xilUartPtr->Config.BaseAddress
);
if ( XST_SUCCESS != status )
{
// xil_printf( "UART: hal_uart_init_channel: Xilinx driver initialization failed. \n");
return pdFAIL;
}
else
{
/*
* Run self-test on the UART controller.
*/
status = XUartPs_SelfTest( xilUartPtr );
if ( XST_SUCCESS != status )
{
// xil_printf( "UART: hal_uart_init_channel: Xilinx driver self-test failed. \n");
return pdFAIL;
}
else
{
/*
* Set the baudrate.
*/
status = XUartPs_SetBaudRate( xilUartPtr, baudrate);
if ( XST_SUCCESS != status )
{
// xil_printf( "UART: hal_uart_init_channel: Xilinx driver Set Baudrate failed. \n");
return pdFAIL;
}
/* Store the baudrate, for reconfiguring the controller in case
* of bus-off state. */
uartInstPtr->baudrate = baudrate;
/*
* Enter Normal Mode.
*/
XUartPs_SetOperMode(xilUartPtr, XUARTPS_OPER_MODE_NORMAL);
while( XUARTPS_OPER_MODE_NORMAL != XUartPs_GetOperMode(xilUartPtr) );
uartInstPtr->isCtrlInit = pdTRUE;
return pdPASS;
}
}
}
}
int hal_uart_getchar(hal_io_handle_t handle, uint8_t *ch)
{
*ch = XUartPs_RecvByte(STDIN_BASEADDRESS);
return 0;
if (handle >= MAX_NUM_UART_CONTROLLERS )
{
// Unsupported handle
// xil_printf( "UART: hal_uart_getchar: handle should be less than %d. \n", MAX_NUM_UART_CONTROLLERS);
return pdFAIL;
}
else
{
if (pdTRUE == uartInstance[handle].isCtrlInit)
{
*ch = XUartPs_RecvByte(uartInstance[handle].uartXilinxInst.Config.BaseAddress);
return pdPASS;
}
return pdFAIL;
}
}
int hal_uart_getchar_timeout(hal_io_handle_t handle, uint8_t *ch, TickType_t timeout)
......@@ -24,6 +161,19 @@ int hal_uart_getchar_timeout(hal_io_handle_t handle, uint8_t *ch, TickType_t tim
int hal_uart_putchar(hal_io_handle_t handle, uint8_t ch)
{
XUartPs_SendByte(STDOUT_BASEADDRESS, ch);
return 0;
if (handle >= MAX_NUM_UART_CONTROLLERS )
{
// Unsupported handle
// xil_printf( "UART: hal_uart_putchar: handle should be less than %d. \n", MAX_NUM_UART_CONTROLLERS);
return pdFAIL;
}
else
{
if (pdTRUE == uartInstance[handle].isCtrlInit)
{
XUartPs_SendByte(uartInstance[handle].uartXilinxInst.Config.BaseAddress, ch);
return pdPASS;
}
return pdFAIL;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment