commit 27a83338a8e8dbcd8271b4baba09fa85356b7c5f
parent f40c7be4d1c9a95cd0726ccceb949afd1a03b6a9
Author: Dimitris Papastamos <dimitris.papastamos@arm.com>
Date: Tue, 6 Nov 2018 11:59:52 +0000
[uart] Add retry count
The retry count is set to an arbitrary number for now.
Change-Id: I24e34fe02a4ee66bd7f0a1f0160e15564af20a70
Signed-off-by: Dimitris Papastamos <dimitris.papastamos@arm.com>
Diffstat:
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/drivers/uart.c b/drivers/uart.c
@@ -1,6 +1,8 @@
#include <uart.h>
#include <rcode.h>
+#define NRETRY 10000
+
#define CR 0x30
#define FBRD 0x28
#define IBRD 0x24
@@ -36,10 +38,12 @@ static void
flush(void)
{
char *base = bss->uartbase;
+ int nretry = NRETRY;
- while ((inm32(base + CR) & CR_EN) &&
- (inm32(base + FR) & FR_TXFE))
- ;
+ while (nretry-- > 0)
+ if (!((inm32(base + CR) & CR_EN) &&
+ (inm32(base + FR) & FR_TXFE)))
+ break;
}
static void
@@ -67,9 +71,13 @@ int
uartgetc(void)
{
char *base = bss->uartbase;
+ int nretry = NRETRY;
- while (inm32(base + FR) & FR_RXFE)
- ;
+ while (nretry-- > 0)
+ if (!(inm32(base + FR) & FR_RXFE))
+ break;
+ if (nretry == 0)
+ return -1;
return inm8(base + DR);
}
@@ -77,9 +85,13 @@ int
uartputc(int c)
{
char *base = bss->uartbase;
+ int nretry = NRETRY;
- while (inm32(base + FR) & FR_TXFF)
- ;
+ while (nretry-- > 0)
+ if (!(inm32(base + FR) & FR_TXFF))
+ break;
+ if (nretry == 0)
+ return -1;
outm8(c, base + DR);
return c;
}