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 620

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 620 jeremybenn
        /* Diable interrupt */
32
        REG8(UART_BASE + UART_IER) = 0x0;
33
 
34 584 jeremybenn
        /* Reset receiver and transmiter */
35
        /* Set RX interrupt for each byte */
36
        REG8(UART_BASE + UART_FCR) = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT | UART_FCR_TRIGGER_1;
37
 
38
        /* Enable RX interrupt */
39
        REG8(UART_BASE + UART_IER) = UART_IER_RDI | UART_IER_THRI;
40
 
41
        /* Set 8 bit char, 1 stop bit, no parity */
42
        REG8(UART_BASE + UART_LCR) = UART_LCR_WLEN8 & ~(UART_LCR_STOP | UART_LCR_PARITY);
43
 
44
        /* Set baud rate */
45
        divisor = IN_CLK / (16 * UART_BAUD_RATE);
46
        REG8(UART_BASE + UART_LCR) |= UART_LCR_DLAB;
47
        REG8(UART_BASE + UART_DLL) = divisor & 0x000000ff;
48
        REG8(UART_BASE + UART_DLM) = (divisor >> 8) & 0x000000ff;
49
        REG8(UART_BASE + UART_LCR) &= ~(UART_LCR_DLAB);
50
 
51
        return;
52
}
53
 
54
void uart_putc(char c) {
55
        unsigned char lsr;
56
 
57
        WAIT_FOR_THRE;
58
        REG8(UART_BASE + UART_TX) = c;
59
        if(c == '\n') {
60
                WAIT_FOR_THRE;
61
                REG8(UART_BASE + UART_TX) = '\r';
62
        }
63
        WAIT_FOR_XMITR;
64
}
65
 
66
 
67
char uart_getc(void) {
68
        unsigned char lsr;
69
        char c;
70
 
71
        WAIT_FOR_CHAR;
72
        c = REG8(UART_BASE + UART_RX);
73
        return c;
74
}
75
 
76
void uart_print_str(char *p) {
77
        while(*p != 0) {
78
                uart_putc(*p);
79
                p++;
80
        }
81
}
82
 
83
void uart_put_int(int n) {
84
        int  a;
85
        char c;
86
        if (n<0) {
87
                uart_putc('-');
88
                n = -n;
89
        }
90
 
91
        a = n/10;
92
        if(a) uart_put_int(a);
93
 
94
        c = '0' + (n % 10);
95
        uart_putc(c);
96
}
97
 
98
 

powered by: WebSVN 2.1.0

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