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

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_2_x/] [or1ksim/] [peripheral/] [16450.h] - Blame information for rev 713

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

Line No. Rev Author Line
1 31 lampret
/* 16450.h -- Definition of types and structures for 8250/16450 serial UART
2
   Copyright (C) 2000 Damjan Lampret, lampret@opencores.org
3
 
4
This file is part of OpenRISC 1000 Architectural Simulator.
5
 
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
 
20
/* Prototypes */
21
void uart_reset();
22
void uart_clock();
23
 
24 341 markom
/* Definitions */
25 355 markom
#define UART_ADDR_SPACE   (8)         /* UART memory address space size in bytes */
26 341 markom
#define UART_MAX_FIFO_LEN (16)        /* rx FIFO for uart 16550 */
27 355 markom
#define MAX_SKEW          (1)         /* max. clock skew in subclocks */
28 409 markom
#define UART_VAPI_BUF_LEN 128         /* Size of VAPI command buffer - VAPI should not send more
29
                                         that this amout of char before requesting something back */
30
#define UART_CLOCK_DIVIDER 16         /* Uart clock divider */
31 713 markom
#define UART_FGETC_SLOWDOWN     100   /* fgetc slowdown factor */
32 341 markom
 
33 31 lampret
/* Registers */
34
 
35
struct dev_16450 {
36 355 markom
  struct {
37 411 markom
    unsigned txbuf[UART_MAX_FIFO_LEN];
38
    unsigned rxbuf[UART_MAX_FIFO_LEN];
39 355 markom
    unsigned char dll;
40
    unsigned char dlh;
41
    unsigned char ier;
42
    unsigned char iir;
43 409 markom
    unsigned char fcr;
44 355 markom
    unsigned char lcr;
45
    unsigned char mcr;
46
    unsigned char lsr;
47
    unsigned char msr;
48
    unsigned char scr;
49
  } regs;   /* Visible registers */
50
  struct {
51
    unsigned long txser;    /* Character just sending */
52
    unsigned long rxser;    /* Character just receiving */
53
    unsigned char loopback;
54
  } iregs;  /* Internal registers */
55
  struct {
56
    int txbuf_head;
57
    int txbuf_tail;
58
    int rxbuf_head;
59
    int rxbuf_tail;
60
    unsigned int txser_full;
61
    unsigned int rxser_full;
62
    unsigned int txbuf_full;
63
    unsigned int rxbuf_full;
64 409 markom
    unsigned thre_int;
65
    unsigned break_set;
66 355 markom
    unsigned long txser_clks;
67
    unsigned long rxser_clks;
68 409 markom
    unsigned timeout_count;
69 355 markom
  } istat;  /* Internal status */
70 341 markom
 
71 355 markom
  /* Clocks per char */
72
  unsigned long char_clks;
73 341 markom
 
74 355 markom
  /* VAPI internal registers */
75
  struct {
76
    unsigned long char_clks;
77
    int dll, dlh;
78
    int lcr;
79
    int skew;
80 385 markom
    int next_break;
81
    int next_break_cnt;
82
    int cur_break;
83
    int cur_break_cnt;
84 409 markom
    int break_sent;
85 355 markom
  } vapi;
86
 
87
  /* Required by VAPI - circular buffer */
88 409 markom
 unsigned long vapi_buf[UART_VAPI_BUF_LEN];  /* Buffer to store incoming characters to,
89 355 markom
                                          since we cannot handle them so fast - we
90
                                          are serial */
91 341 markom
  int vapi_buf_head_ptr;               /* Where we write to */
92
  int vapi_buf_tail_ptr;               /* Where we read from */
93
 
94
  /* Length of FIFO, 16 for 16550, 1 for 16450 */
95
  int fifo_len;
96 713 markom
 
97
  /* fgetc slowdown */
98
  int slowdown;
99 355 markom
 
100
  /* Required by standard file streams */
101
  FILE * rxfs;
102
  FILE * txfs;
103 31 lampret
};
104
 
105
/*
106
 * Addresses of visible registers
107
 *
108
 */
109 355 markom
#define UART_RXBUF  0 /* R: Rx buffer, DLAB=0 */
110
#define UART_TXBUF  0 /* W: Tx buffer, DLAB=0 */
111
#define UART_DLL  0 /* R/W: Divisor Latch Low, DLAB=1 */
112
#define UART_DLH  1 /* R/W: Divisor Latch High, DLAB=1 */
113
#define UART_IER  1 /* R/W: Interrupt Enable Register */
114
#define UART_IIR  2 /* R: Interrupt ID Register */
115 409 markom
#define UART_FCR  2 /* W: FIFO Control Register */
116 355 markom
#define UART_LCR  3 /* R/W: Line Control Register */
117
#define UART_MCR  4 /* W: Modem Control Register */
118
#define UART_LSR  5 /* R: Line Status Register */
119
#define UART_MSR  6 /* R: Modem Status Register */
120
#define UART_SCR  7 /* R/W: Scratch Register */
121 31 lampret
 
122
/*
123
 * R/W masks for valid bits in 8250/16450 (mask out 16550 and later bits)
124
 *
125
 */
126 355 markom
#define UART_VALID_LCR  0xff
127 409 markom
#define UART_VALID_LSR  0xff
128
#define UART_VALID_IIR  0x0f
129
#define UART_VALID_FCR  0xc0
130 355 markom
#define UART_VALID_IER  0x0f
131
#define UART_VALID_MCR  0x1f
132
#define UART_VALID_MSR  0xff
133 31 lampret
 
134
/*
135
 * Bit definitions for the Line Control Register
136
 *
137
 */
138 355 markom
#define UART_LCR_DLAB 0x80  /* Divisor latch access bit */
139
#define UART_LCR_SBC  0x40  /* Set break control */
140
#define UART_LCR_SPAR 0x20  /* Stick parity (?) */
141
#define UART_LCR_EPAR 0x10  /* Even parity select */
142
#define UART_LCR_PARITY 0x08  /* Parity Enable */
143
#define UART_LCR_STOP 0x04  /* Stop bits: 0=1 stop bit, 1= 2 stop bits */
144
#define UART_LCR_WLEN5  0x00  /* Wordlength: 5 bits */
145
#define UART_LCR_WLEN6  0x01  /* Wordlength: 6 bits */
146
#define UART_LCR_WLEN7  0x02  /* Wordlength: 7 bits */
147
#define UART_LCR_WLEN8  0x03  /* Wordlength: 8 bits */
148 344 markom
#define UART_LCR_RESET  0x03
149 31 lampret
/*
150
 * Bit definitions for the Line Status Register
151
 */
152 409 markom
#define UART_LSR_RXERR  0x80  /* Error in rx fifo */
153 355 markom
#define UART_LSR_TXSERE 0x40  /* Transmitter serial register empty */
154
#define UART_LSR_TXBUFE 0x20  /* Transmitter buffer register empty */
155
#define UART_LSR_BREAK  0x10  /* Break interrupt indicator */
156
#define UART_LSR_FRAME  0x08  /* Frame error indicator */
157
#define UART_LSR_PARITY 0x04  /* Parity error indicator */
158
#define UART_LSR_OVRRUN 0x02  /* Overrun error indicator */
159
#define UART_LSR_RDRDY  0x01  /* Receiver data ready */
160 31 lampret
 
161
/*
162
 * Bit definitions for the Interrupt Identification Register
163
 */
164 355 markom
#define UART_IIR_NO_INT 0x01  /* No interrupts pending */
165
#define UART_IIR_ID 0x06  /* Mask for the interrupt ID */
166 31 lampret
 
167 355 markom
#define UART_IIR_MSI  0x00  /* Modem status interrupt (Low priority) */
168
#define UART_IIR_THRI 0x02  /* Transmitter holding register empty */
169
#define UART_IIR_RDI  0x04  /* Receiver data interrupt */
170
#define UART_IIR_RLSI 0x06  /* Receiver line status interrupt (High p.) */
171 409 markom
#define UART_IIR_CTI  0x0c  /* Character timeout */
172 31 lampret
 
173
/*
174 409 markom
 * Bit Definitions for the FIFO Control Register
175
 */
176
#define UART_FCR_FIE  0x01  /* FIFO enable */
177
#define UART_FCR_RRXFI 0x02 /* Reset rx FIFO */
178 411 markom
#define UART_FCR_RTXFI 0x04 /* Reset tx FIFO */
179 409 markom
#define UART_FIFO_TRIGGER(x) /* Trigger values for indexes 0..3 */\
180 423 markom
  ((x) == 0 ? 1\
181
  :(x) == 1 ? 4\
182
  :(x) == 2 ? 8\
183
  :(x) == 3 ? 14 : 0)
184 409 markom
 
185
/*
186 31 lampret
 * Bit definitions for the Interrupt Enable Register
187
 */
188 355 markom
#define UART_IER_MSI  0x08  /* Enable Modem status interrupt */
189
#define UART_IER_RLSI 0x04  /* Enable receiver line status interrupt */
190
#define UART_IER_THRI 0x02  /* Enable Transmitter holding register int. */
191
#define UART_IER_RDI  0x01  /* Enable receiver data interrupt */
192 31 lampret
 
193
/*
194
 * Bit definitions for the Modem Control Register
195
 */
196 355 markom
#define UART_MCR_LOOP 0x10  /* Enable loopback mode */
197
#define UART_MCR_AUX2 0x08  /* Auxilary 2  */
198
#define UART_MCR_AUX1 0x04  /* Auxilary 1 */
199
#define UART_MCR_RTS  0x02  /* Force RTS */
200
#define UART_MCR_DTR  0x01  /* Force DTR */
201 31 lampret
 
202
/*
203
 * Bit definitions for the Modem Status Register
204
 */
205 355 markom
#define UART_MSR_DCD  0x80  /* Data Carrier Detect */
206 385 markom
#define UART_MSR_RI   0x40  /* Ring Indicator */
207 355 markom
#define UART_MSR_DSR  0x20  /* Data Set Ready */
208
#define UART_MSR_CTS  0x10  /* Clear to Send */
209
#define UART_MSR_DDCD 0x08  /* Delta DCD */
210
#define UART_MSR_TERI 0x04  /* Trailing edge ring indicator */
211
#define UART_MSR_DDSR 0x02  /* Delta DSR */
212
#define UART_MSR_DCTS 0x01  /* Delta CTS */
213 31 lampret
 
214 385 markom
/*
215
 * Various definitions
216
 */
217 423 markom
#define UART_BREAK_COUNT  (1) /* # of chars to count when performing break */
218 409 markom
#define UART_CHAR_TIMEOUT (4) /* # of chars to count when performing timeout int. */

powered by: WebSVN 2.1.0

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