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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [OpenRISC_SIM_GCC/] [drivers/] [uart.c] - Blame information for rev 584

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

Line No. Rev Author Line
1 584 jeremybenn
#include "support.h"
2
#include "board.h"
3
 
4
#include "uart.h"
5
 
6
#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
7
 
8
#define WAIT_FOR_XMITR \
9
        do { \
10
                lsr = REG8(UART_BASE + UART_LSR); \
11
        } while ((lsr & BOTH_EMPTY) != BOTH_EMPTY)
12
 
13
#define WAIT_FOR_THRE \
14
        do { \
15
                lsr = REG8(UART_BASE + UART_LSR); \
16
        } while ((lsr & UART_LSR_THRE) != UART_LSR_THRE)
17
 
18
#define CHECK_FOR_CHAR (REG8(UART_BASE + UART_LSR) & UART_LSR_DR)
19
 
20
#define WAIT_FOR_CHAR \
21
         do { \
22
                lsr = REG8(UART_BASE + UART_LSR); \
23
         } while ((lsr & UART_LSR_DR) != UART_LSR_DR)
24
 
25
#define UART_TX_BUFF_LEN 32
26
#define UART_TX_BUFF_MASK (UART_TX_BUFF_LEN -1)
27
 
28
void uart_init(void) {
29
        int divisor;
30
 
31
        /* Reset receiver and transmiter */
32
        /* Set RX interrupt for each byte */
33
        REG8(UART_BASE + UART_FCR) = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT | UART_FCR_TRIGGER_1;
34
 
35
        /* Enable RX interrupt */
36
        REG8(UART_BASE + UART_IER) = UART_IER_RDI | UART_IER_THRI;
37
 
38
        /* Set 8 bit char, 1 stop bit, no parity */
39
        REG8(UART_BASE + UART_LCR) = UART_LCR_WLEN8 & ~(UART_LCR_STOP | UART_LCR_PARITY);
40
 
41
        /* Set baud rate */
42
        divisor = IN_CLK / (16 * UART_BAUD_RATE);
43
        REG8(UART_BASE + UART_LCR) |= UART_LCR_DLAB;
44
        REG8(UART_BASE + UART_DLL) = divisor & 0x000000ff;
45
        REG8(UART_BASE + UART_DLM) = (divisor >> 8) & 0x000000ff;
46
        REG8(UART_BASE + UART_LCR) &= ~(UART_LCR_DLAB);
47
 
48
        return;
49
}
50
 
51
void uart_putc(char c) {
52
        unsigned char lsr;
53
 
54
        WAIT_FOR_THRE;
55
        REG8(UART_BASE + UART_TX) = c;
56
        if(c == '\n') {
57
                WAIT_FOR_THRE;
58
                REG8(UART_BASE + UART_TX) = '\r';
59
        }
60
        WAIT_FOR_XMITR;
61
}
62
 
63
 
64
char uart_getc(void) {
65
        unsigned char lsr;
66
        char c;
67
 
68
        WAIT_FOR_CHAR;
69
        c = REG8(UART_BASE + UART_RX);
70
        return c;
71
}
72
 
73
void uart_print_str(char *p) {
74
        while(*p != 0) {
75
                uart_putc(*p);
76
                p++;
77
        }
78
}
79
 
80
void uart_put_int(int n) {
81
        int  a;
82
        char c;
83
        if (n<0) {
84
                uart_putc('-');
85
                n = -n;
86
        }
87
 
88
        a = n/10;
89
        if(a) uart_put_int(a);
90
 
91
        c = '0' + (n % 10);
92
        uart_putc(c);
93
}
94
 
95
 

powered by: WebSVN 2.1.0

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