1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * This file contains the libchip configuration information |
---|
5 | * to instantiate the libchip driver for the serial ports. |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2012. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.com/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #include <unistd.h> /* write */ |
---|
18 | |
---|
19 | #include <bsp.h> |
---|
20 | #include <libchip/serial.h> |
---|
21 | #include <libchip/ns16550.h> |
---|
22 | #include <rtems/pci.h> |
---|
23 | #include <bsp/irq.h> |
---|
24 | |
---|
25 | #if 1 |
---|
26 | #define COM_CONSOLE_FUNCTIONS &ns16550_fns_polled |
---|
27 | #else |
---|
28 | #define COM_CONSOLE_FUNCTIONS &ns16550_fns |
---|
29 | #endif |
---|
30 | |
---|
31 | /* |
---|
32 | * Base IO for UART |
---|
33 | */ |
---|
34 | #define COM1_BASE_IO 0x3F8 |
---|
35 | #define COM2_BASE_IO 0x3E8 |
---|
36 | |
---|
37 | // #define CLOCK_RATE 368640 |
---|
38 | #define CLOCK_RATE (115200 * 16) |
---|
39 | |
---|
40 | #define COM_IO_BASE_ADDRESS (0xa0000000UL | 0x18000000UL) |
---|
41 | |
---|
42 | uint8_t com_get_register(uint32_t addr, uint8_t i); |
---|
43 | void com_set_register(uint32_t addr, uint8_t i, uint8_t val); |
---|
44 | uint8_t tty2_get_register(uint32_t addr, uint8_t i); |
---|
45 | void tty2_set_register(uint32_t addr, uint8_t i, uint8_t val); |
---|
46 | |
---|
47 | |
---|
48 | uint8_t com_get_register(uint32_t addr, uint8_t i) |
---|
49 | { |
---|
50 | uint8_t val; |
---|
51 | volatile uint8_t *ptr; |
---|
52 | ptr = (volatile uint8_t *) COM_IO_BASE_ADDRESS; |
---|
53 | ptr += addr; |
---|
54 | ptr += i; |
---|
55 | val = *ptr; |
---|
56 | |
---|
57 | return val; |
---|
58 | } |
---|
59 | |
---|
60 | void com_set_register(uint32_t addr, uint8_t i, uint8_t val) |
---|
61 | { |
---|
62 | volatile uint8_t *ptr; |
---|
63 | |
---|
64 | ptr = (volatile uint8_t *) COM_IO_BASE_ADDRESS; |
---|
65 | ptr += addr; |
---|
66 | ptr += i; |
---|
67 | *ptr = val; |
---|
68 | } |
---|
69 | |
---|
70 | uint8_t tty2_get_register(uint32_t addr, uint8_t i) |
---|
71 | { |
---|
72 | uint8_t val; |
---|
73 | volatile uint8_t *ptr; |
---|
74 | |
---|
75 | ptr = (volatile uint8_t *) COM_IO_BASE_ADDRESS; |
---|
76 | ptr += addr; |
---|
77 | ptr += (i * 8); |
---|
78 | val = *ptr; |
---|
79 | |
---|
80 | return val; |
---|
81 | } |
---|
82 | |
---|
83 | void tty2_set_register(uint32_t addr, uint8_t i, uint8_t val) |
---|
84 | { |
---|
85 | volatile uint8_t *ptr; |
---|
86 | |
---|
87 | ptr = (volatile uint8_t *) COM_IO_BASE_ADDRESS; |
---|
88 | ptr += addr; |
---|
89 | ptr += (i * 8); |
---|
90 | *ptr = val; |
---|
91 | } |
---|
92 | |
---|
93 | console_tbl Console_Configuration_Ports[] = { |
---|
94 | { |
---|
95 | "/dev/tty0", /* sDeviceName */ |
---|
96 | SERIAL_NS16550, /* deviceType */ |
---|
97 | COM_CONSOLE_FUNCTIONS, /* pDeviceFns */ |
---|
98 | NULL, /* deviceProbe, assume it is there */ |
---|
99 | NULL, /* pDeviceFlow */ |
---|
100 | 16, /* ulMargin */ |
---|
101 | 8, /* ulHysteresis */ |
---|
102 | (void *) 9600, /* Baud Rate */ /* pDeviceParams */ |
---|
103 | COM1_BASE_IO, /* ulCtrlPort1 */ |
---|
104 | 0x00000000, /* ulCtrlPort2 */ |
---|
105 | COM1_BASE_IO, /* ulDataPort */ |
---|
106 | com_get_register, /* getRegister */ |
---|
107 | com_set_register, /* setRegister */ |
---|
108 | NULL,/* unused */ /* getData */ |
---|
109 | NULL,/* unused */ /* setData */ |
---|
110 | CLOCK_RATE, /* ulClock */ |
---|
111 | MALTA_IRQ_TTY0 /* ulIntVector -- base for port */ |
---|
112 | }, |
---|
113 | { |
---|
114 | "/dev/tty1", /* sDeviceName */ |
---|
115 | SERIAL_NS16550, /* deviceType */ |
---|
116 | COM_CONSOLE_FUNCTIONS, /* pDeviceFns */ |
---|
117 | NULL, /* deviceProbe, assume it is there */ |
---|
118 | NULL, /* pDeviceFlow */ |
---|
119 | 16, /* ulMargin */ |
---|
120 | 8, /* ulHysteresis */ |
---|
121 | (void *) 9600, /* Baud Rate */ /* pDeviceParams */ |
---|
122 | COM2_BASE_IO, /* ulCtrlPort1 */ |
---|
123 | 0x00000000, /* ulCtrlPort2 */ |
---|
124 | COM2_BASE_IO, /* ulDataPort */ |
---|
125 | com_get_register, /* getRegister */ |
---|
126 | com_set_register, /* setRegister */ |
---|
127 | NULL,/* unused */ /* getData */ |
---|
128 | NULL,/* unused */ /* setData */ |
---|
129 | CLOCK_RATE, /* ulClock */ |
---|
130 | MALTA_IRQ_TTY1 /* ulIntVector -- base for port */ |
---|
131 | }, |
---|
132 | { |
---|
133 | "/dev/tty2", /* sDeviceName */ |
---|
134 | SERIAL_NS16550, /* deviceType */ |
---|
135 | COM_CONSOLE_FUNCTIONS, /* pDeviceFns */ |
---|
136 | NULL, /* deviceProbe, assume it is there */ |
---|
137 | NULL, /* pDeviceFlow */ |
---|
138 | 16, /* ulMargin */ |
---|
139 | 8, /* ulHysteresis */ |
---|
140 | (void *) 9600, /* Baud Rate */ /* pDeviceParams */ |
---|
141 | 0, /* IGNORED */ /* ulCtrlPort1 */ |
---|
142 | 0, /* IGNORED */ /* ulCtrlPort2 */ |
---|
143 | 0, /* IGNORED */ /* ulDataPort */ |
---|
144 | tty2_get_register, /* getRegister */ |
---|
145 | tty2_set_register, /* setRegister */ |
---|
146 | NULL,/* unused */ /* getData */ |
---|
147 | NULL,/* unused */ /* setData */ |
---|
148 | CLOCK_RATE, /* ulClock */ |
---|
149 | MALTA_CPU_INT2 /* ulIntVector -- base for port */ |
---|
150 | }, |
---|
151 | }; |
---|
152 | |
---|
153 | /* |
---|
154 | * Define a variable that contains the number of statically configured |
---|
155 | * console devices. |
---|
156 | */ |
---|
157 | unsigned long Console_Configuration_Count = \ |
---|
158 | (sizeof(Console_Configuration_Ports)/sizeof(console_tbl)); |
---|