aboutsummaryrefslogtreecommitdiffstats
path: root/firmware/microblaze/lib/hal_io.c
diff options
context:
space:
mode:
authorNick Foster <nick@nerdnetworks.org>2010-08-12 10:23:33 -0700
committerNick Foster <nick@nerdnetworks.org>2010-08-12 10:23:33 -0700
commit32c40b5f5956d29e3be1fc3c94a213f8f0d68f42 (patch)
tree3e059559d9b1d80e807a114240052b2947684e87 /firmware/microblaze/lib/hal_io.c
parentdfafbd5f2dbf0758df33d10922eec3c1a37dd32b (diff)
downloaduhd-32c40b5f5956d29e3be1fc3c94a213f8f0d68f42.tar.gz
uhd-32c40b5f5956d29e3be1fc3c94a213f8f0d68f42.tar.bz2
uhd-32c40b5f5956d29e3be1fc3c94a213f8f0d68f42.zip
Working support for multiple UARTs.
Default behavior (printf, gets, etc.) routes to DEFAULT_UART, set in hal_uart.h. Use fputstr() to print to other UARTs. Bring fgets() from hal_io.c out in hal_io.h if you want to read data from other UARTs. Still blocking. No interrupt-driven stuff yet.
Diffstat (limited to 'firmware/microblaze/lib/hal_io.c')
-rw-r--r--firmware/microblaze/lib/hal_io.c66
1 files changed, 51 insertions, 15 deletions
diff --git a/firmware/microblaze/lib/hal_io.c b/firmware/microblaze/lib/hal_io.c
index b68067308..8bb5e2af8 100644
--- a/firmware/microblaze/lib/hal_io.c
+++ b/firmware/microblaze/lib/hal_io.c
@@ -18,9 +18,9 @@
// conditionalized on HAL_IO_USES_DBOARD_PINS && HAL_IO_USES_UART
-#include "hal_io.h"
#include "memory_map.h"
#include "hal_uart.h"
+#include "hal_io.h"
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
@@ -102,7 +102,7 @@ hal_finish(void)
// %c
inline int
-fputchar(int ch)
+putchar(int ch)
{
hal_gpio_set_rx((s << 8) | W, 0xff80);
hal_gpio_set_rx(0, 0xff80);
@@ -124,16 +124,29 @@ hal_finish(void)
// %c
inline int
-fputchar(int ch)
+fputchar(hal_uart_name_t u, int ch)
+{
+ hal_uart_putc(u, ch);
+ return ch;
+}
+
+inline int
+putchar(int ch)
{
- hal_uart_putc(ch);
+ hal_uart_putc(DEFAULT_UART, ch);
return ch;
}
int
-fgetchar(void)
+fgetchar(hal_uart_name_t u)
+{
+ return hal_uart_getc(u);
+}
+
+int
+getchar(void)
{
- return hal_uart_getc();
+ return fgetchar(DEFAULT_UART);
}
#else // nop all i/o
@@ -172,34 +185,57 @@ getchar(void)
// \n
inline void
-fnewline(void)
+fnewline(hal_uart_name_t u)
{
- putchar('\n');
+ fputchar(u, '\n');
+}
+
+inline void
+newline(void)
+{
+ fnewline(DEFAULT_UART);
}
int
-fputstr(const char *s)
+fputstr(hal_uart_name_t u, const char *s)
{
while (*s)
- putchar(*s++);
+ fputchar(u, *s++);
return 0;
}
int
-fputs(const char *s)
+putstr(const char *s)
+{
+ return fputstr(DEFAULT_UART, s);
+}
+
+int
+fputs(hal_uart_name_t u, const char *s)
{
- putstr(s);
- putchar('\n');
+ fputstr(u, s);
+ fputchar(u, '\n');
return 0;
}
+int puts(const char *s)
+{
+ return fputs(DEFAULT_UART, s);
+}
+
char *
-fgets(char * const s)
+fgets(hal_uart_name_t u, char * const s)
{
char *x = s;
- while((*x=(char)hal_uart_getc()) != '\n') x++;
+ while((*x=(char)hal_uart_getc(u)) != '\n') x++;
*x = 0;
return s;
}
+char *
+gets(char * const s)
+{
+ return fgets(DEFAULT_UART, s);
+}
+