Commit c64cb5c6 authored by Alessandro Rubini's avatar Alessandro Rubini

uart code: fixed write_byte, added write_string

parent fba4cbd6
......@@ -5,7 +5,9 @@
#include <hw/wb_vuart.h>
#define CALC_BAUD(baudrate) (((((unsigned long long)baudrate*8ULL)<<(16-7))+(CPU_CLOCK>>8))/(CPU_CLOCK>>7))
#define CALC_BAUD(baudrate) \
( ((( (unsigned long long)baudrate * 8ULL) << (16 - 7)) + \
(CPU_CLOCK >> 8)) / (CPU_CLOCK >> 7) )
static volatile struct UART_WB *uart = (volatile struct UART_WB *) BASE_UART;
......@@ -14,10 +16,17 @@ void uart_init()
uart->BCR = CALC_BAUD(UART_BAUDRATE);
}
void uart_write_byte(unsigned char x)
void uart_write_byte(int b)
{
while(uart->SR & UART_SR_TX_BUSY);
uart->TDR = x;
if(x == '\n')
if(b == '\n')
uart_write_byte('\r');
while(uart->SR & UART_SR_TX_BUSY)
;
uart->TDR = b;
}
void uart_write_string(char *s)
{
while (*s)
uart_write_byte(*(s++));
}
......@@ -4,6 +4,7 @@
int mprintf(char const *format, ...);
void uart_init();
void uart_write_byte(unsigned char x);
void uart_write_byte(int b);
void uart_write_string(char *s);
#endif
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