Commit 8d51feb5 authored by Alessandro Rubini's avatar Alessandro Rubini

softpll-unify: use uart files from wrpc-sw

The commit is part of the effort in unifying softpll with wrpc-sw,
and later remove the duplicated code here in wr-switch-sw.

The uart module in wrpc-sw is a superset of this one (it has vuart), but
all the registers are compatible.

The files were slightly different, but nothing substantial, mainly
because wrpc-sw evolved a little from its original form. By copying
those uart.[ch] we shorten the difference with no techinical change, even
if the binary file differs from the previous commit.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 1f58839b
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2011 CERN (www.cern.ch)
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#include <inttypes.h>
#include "board.h"
#include "uart.h"
......@@ -7,34 +17,51 @@
( ((( (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;
volatile struct UART_WB *uart;
void uart_init()
void uart_init_hw()
{
uart = (volatile struct UART_WB *)BASE_UART;
uart->BCR = CALC_BAUD(UART_BAUDRATE);
}
void __attribute__((weak)) uart_init_sw(void)
{}
void uart_write_byte(int b)
{
if(b == '\n')
if (b == '\n')
uart_write_byte('\r');
while(uart->SR & UART_SR_TX_BUSY)
while (uart->SR & UART_SR_TX_BUSY)
;
uart->TDR = b;
}
void uart_write_string(char *s)
int uart_write_string(const char *s)
{
const char *t = s;
while (*s)
uart_write_byte(*(s++));
return s - t;
}
int uart_poll()
static int uart_poll()
{
return uart->SR & UART_SR_RX_RDY;
return uart->SR & UART_SR_RX_RDY;
}
int uart_read_byte()
{
return uart ->RDR & 0xff;
if (!uart_poll())
return -1;
return uart->RDR & 0xff;
}
int puts(const char *s)
__attribute__((alias("uart_write_string")));
/* The next alias is for ppsi log messages, that go to sw_uart if built */
int uart_sw_write_string(const char *s)
__attribute__((alias("uart_write_string"), weak));
#ifndef __UART_H
#define __UART_H
int mprintf(char const *format, ...);
void uart_init();
void uart_init_sw(void);
void uart_init_hw(void);
void uart_write_byte(int b);
void uart_write_string(char *s);
int uart_poll();
int uart_read_byte();
int uart_write_string(const char *s);
int puts(const char *s);
int uart_read_byte(void);
/* uart-sw is used by ppsi (but may be wrapped to normal uart) */
int uart_sw_write_string(const char *s);
#endif
......@@ -12,7 +12,7 @@ main()
{
uint32_t start_tics = 0;
uart_init();
uart_init_hw();
TRACE("WR Switch Real Time Subsystem (c) CERN 2011 - 2013\n");
TRACE("Revision: %s, built %s.\n", build_revision, build_date);
......
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