diff options
Diffstat (limited to 'firmware/microblaze')
-rw-r--r-- | firmware/microblaze/lib/hal_io.c | 14 | ||||
-rw-r--r-- | firmware/microblaze/lib/hal_uart.c | 48 | ||||
-rw-r--r-- | firmware/microblaze/lib/hal_uart.h | 8 | ||||
-rw-r--r-- | firmware/microblaze/usrp2p/memory_map.h | 5 |
4 files changed, 50 insertions, 25 deletions
diff --git a/firmware/microblaze/lib/hal_io.c b/firmware/microblaze/lib/hal_io.c index 58b1e681e..b68067308 100644 --- a/firmware/microblaze/lib/hal_io.c +++ b/firmware/microblaze/lib/hal_io.c @@ -102,7 +102,7 @@ hal_finish(void) // %c inline int -putchar(int ch) +fputchar(int ch) { hal_gpio_set_rx((s << 8) | W, 0xff80); hal_gpio_set_rx(0, 0xff80); @@ -124,14 +124,14 @@ hal_finish(void) // %c inline int -putchar(int ch) +fputchar(int ch) { hal_uart_putc(ch); return ch; } int -getchar(void) +fgetchar(void) { return hal_uart_getc(); } @@ -172,13 +172,13 @@ getchar(void) // \n inline void -newline(void) +fnewline(void) { putchar('\n'); } int -putstr(const char *s) +fputstr(const char *s) { while (*s) putchar(*s++); @@ -187,7 +187,7 @@ putstr(const char *s) } int -puts(const char *s) +fputs(const char *s) { putstr(s); putchar('\n'); @@ -195,7 +195,7 @@ puts(const char *s) } char * -gets(char * const s) +fgets(char * const s) { char *x = s; while((*x=(char)hal_uart_getc()) != '\n') x++; diff --git a/firmware/microblaze/lib/hal_uart.c b/firmware/microblaze/lib/hal_uart.c index fe3b7515a..91d67b5e0 100644 --- a/firmware/microblaze/lib/hal_uart.c +++ b/firmware/microblaze/lib/hal_uart.c @@ -37,28 +37,30 @@ divisor_table[MAX_WB_DIV+1][NSPEEDS] = { { 163, 81, 41, 27, 14, 7 }, // 4: 25 MHz }; -#define u uart_regs +//we wrap hal_uart_putc hal_uart_putc_nowait, and hal_uart_getc to accept a UART pointer given by hal_get_uart. we modify hal_io.c to use the new versions. -static char uart_mode = UART_MODE_ONLCR; +static char uart_mode[4] = {UART_MODE_ONLCR, UART_MODE_ONLCR, UART_MODE_ONLCR, UART_MODE_ONLCR}; void -hal_uart_set_mode(int mode) +hal_uart_set_mode(int uart, int mode) { - uart_mode = mode; + uart_mode[uart] = mode; } void hal_uart_init(void) { - hal_uart_set_mode(UART_MODE_ONLCR); - u->clkdiv = 217; // 230400 bps + for(int i = 0; i < 4; i++) { + hal_uart_set_mode(i, UART_MODE_ONLCR); + u->clkdiv = 217; // 230400 bps TODO: change to reflect new quad UART + } } void -hal_uart_putc(int ch) +hal_uart_putc(uart_regs_t *u, int ch) { - if (ch == '\n')// && (uart_mode == UART_MODE_ONLCR)) //map \n->\r\n if necessary - hal_uart_putc('\r'); + if (ch == '\n')// && (uart_mode[uart] == UART_MODE_ONLCR)) //map \n->\r\n if necessary + hal_uart_putc(u, '\r'); while (u->txlevel == 0) // wait for fifo to have space ; @@ -67,20 +69,40 @@ hal_uart_putc(int ch) } void -hal_uart_putc_nowait(int ch) +hal_uart_putc_nowait(uart_regs_t *u, int ch) { - if (ch == '\n')// && (uart_mode == UART_MODE_ONLCR)) //map \n->\r\n if necessary - hal_uart_putc('\r'); + if (ch == '\n')// && (uart_mode[uart] == UART_MODE_ONLCR)) //map \n->\r\n if necessary + hal_uart_putc(u, '\r'); if(u->txlevel) // If fifo has space u->txchar = ch; } int -hal_uart_getc(void) +hal_uart_getc(uart_regs_t *u) { while ((u->rxlevel) == 0) // wait for data to be ready ; return u->rxchar; } + +uart_regs_t * +hal_get_uart(int number) +{ + switch(number) { + case 0: + return uart_regs_0; + break; + case 1: + return uart_regs_1; + break; + case 2: + return uart_regs_2; + break; + case 3: + return uart_regs_3; + break; + default: + return uart_regs_0; //for safety +} diff --git a/firmware/microblaze/lib/hal_uart.h b/firmware/microblaze/lib/hal_uart.h index dfd73c323..218bd7cb4 100644 --- a/firmware/microblaze/lib/hal_uart.h +++ b/firmware/microblaze/lib/hal_uart.h @@ -28,7 +28,7 @@ /* * \brief Set uart mode */ -void hal_uart_set_mode(int flags); +void hal_uart_set_mode(int uart, int flags); /*! * \brief one-time call to init @@ -62,17 +62,17 @@ void hal_uart_get_config(hal_uart_config_t *c); /*! * \brief Enqueue \p ch for output over serial port */ -void hal_uart_putc(int ch); +void hal_uart_putc(uart_regs_t *u, int ch); /*! * \brief Enqueue \p ch for output over serial port, silent fail if queue is full */ -void hal_uart_putc_nowait(int ch); +void hal_uart_putc_nowait(uart_regs_t *u, int ch); /* * \brief Blocking read of next char from serial port */ -int hal_uart_getc(void); +int hal_uart_getc(uart_regs_t *u); #endif /* INCLUDED_HAL_UART_H */ diff --git a/firmware/microblaze/usrp2p/memory_map.h b/firmware/microblaze/usrp2p/memory_map.h index 9c5b576d7..b69cc59bd 100644 --- a/firmware/microblaze/usrp2p/memory_map.h +++ b/firmware/microblaze/usrp2p/memory_map.h @@ -781,7 +781,10 @@ typedef struct { volatile uint32_t rxchar; // Read received characters here } uart_regs_t; -#define uart_regs ((uart_regs_t *) UART_BASE) +#define uart_regs_0 ((uart_regs_t *) UART_BASE) +#define uart_regs_1 ((uart_regs_t *) UART_BASE + 0x0020) +#define uart_regs_2 ((uart_regs_t *) UART_BASE + 0x0040) +#define uart_regs_3 ((uart_regs_t *) UART_BASE + 0x0060) /////////////////////////////////////////////////// // ATR Controller, Slave 11 |