Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
toki
components
freertos-portable
Commits
9af215bc
Commit
9af215bc
authored
Dec 12, 2017
by
Mahmoud Rushdi
Committed by
Oliver Horst
Aug 15, 2020
Browse files
[chg] Check if the UART controller is initialized.
parent
b88f17ae
Changes
1
Hide whitespace changes
Inline
Side-by-side
drivers/uart.c
View file @
9af215bc
/**
* \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
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment