OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [drivers/] [uart.c] - Blame information for rev 467

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 marcus.erl
#include "support.h"
2
#include "board.h"
3
#include "uart.h"
4
 
5
#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
6
 
7
#define WAIT_FOR_XMITR \
8
        do { \
9
                lsr = REG8(UART_BASE + UART_LSR); \
10
        } while ((lsr & BOTH_EMPTY) != BOTH_EMPTY)
11
 
12
#define WAIT_FOR_THRE \
13
        do { \
14
                lsr = REG8(UART_BASE + UART_LSR); \
15
        } while ((lsr & UART_LSR_THRE) != UART_LSR_THRE)
16
 
17
#define CHECK_FOR_CHAR (REG8(UART_BASE + UART_LSR) & UART_LSR_DR)
18
 
19
#define WAIT_FOR_CHAR \
20
         do { \
21
                lsr = REG8(UART_BASE + UART_LSR); \
22
         } while ((lsr & UART_LSR_DR) != UART_LSR_DR)
23
 
24
#define UART_TX_BUFF_LEN 32
25
#define UART_TX_BUFF_MASK (UART_TX_BUFF_LEN -1)
26
 
27
char tx_buff[UART_TX_BUFF_LEN];
28
volatile int tx_level, rx_level;
29
 
30
void uart_init(void)
31
{
32
        int divisor;
33 140 julius
        float float_divisor;
34 246 julius
 
35 2 marcus.erl
        /* Reset receiver and transmiter */
36 467 julius
        REG8(UART_BASE + UART_FCR) = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR
37
                | UART_FCR_CLEAR_XMIT | UART_FCR_TRIGGER_4;
38 2 marcus.erl
 
39
        /* Disable all interrupts */
40
        REG8(UART_BASE + UART_IER) = 0x00;
41
 
42
        /* Set 8 bit char, 1 stop bit, no parity */
43 467 julius
        REG8(UART_BASE + UART_LCR) = UART_LCR_WLEN8 & ~(UART_LCR_STOP |
44
                                                        UART_LCR_PARITY);
45
 
46 2 marcus.erl
        /* Set baud rate */
47 140 julius
        float_divisor = (float) IN_CLK/(16 * UART_BAUD_RATE);
48
        float_divisor += 0.50f; // Ensure round up
49
        divisor = (int) float_divisor;
50
 
51 2 marcus.erl
        REG8(UART_BASE + UART_LCR) |= UART_LCR_DLAB;
52
        REG8(UART_BASE + UART_DLL) = divisor & 0x000000ff;
53
        REG8(UART_BASE + UART_DLM) = (divisor >> 8) & 0x000000ff;
54
        REG8(UART_BASE + UART_LCR) &= ~(UART_LCR_DLAB);
55
}
56
 
57
void uart_putc(char c)
58
{
59
        unsigned char lsr;
60
 
61
        WAIT_FOR_THRE;
62
        REG8(UART_BASE + UART_TX) = c;
63
        if(c == '\n') {
64
          WAIT_FOR_THRE;
65
          REG8(UART_BASE + UART_TX) = '\r';
66
        }
67
        WAIT_FOR_XMITR;
68
}
69
 
70
char uart_getc(void)
71
{
72
        unsigned char lsr;
73
        char c;
74
 
75
        WAIT_FOR_CHAR;
76
        c = REG8(UART_BASE + UART_RX);
77
        return c;
78
}
79
 
80
char uart_testc(void)
81
{
82
        if((REG8(UART_BASE + UART_LSR) & UART_LSR_DR) == UART_LSR_DR)
83
                return REG8(UART_BASE + UART_RX);
84
        else
85
                return 0;
86
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.