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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ucos-ii/] [2.91/] [drivers/] [uart.c] - Blame information for rev 654

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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