File indexing completed on 2025-05-11 08:23:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include <bsp.h> /* Must be before libio.h */
0018 #include <rtems/libio.h>
0019 #include <termios.h>
0020 #include <rtems/bspIo.h>
0021
0022
0023 #include <lpc22xx.h>
0024 #include "lpc22xx_uart.h"
0025
0026 #include <libchip/serial.h>
0027 #include <libchip/sersupp.h>
0028
0029
0030 #define NUM_DEVS 1
0031
0032 int dbg_dly;
0033
0034
0035 static int uart_first_open(int major, int minor, void *arg);
0036 static int uart_last_close(int major, int minor, void *arg);
0037 static int uart_read(int minor);
0038 static ssize_t uart_write(int minor, const char *buf, size_t len);
0039 static void uart_init(int minor);
0040 static void uart_write_polled(int minor, char c);
0041 static int uart_set_attributes(int minor, const struct termios *t);
0042
0043
0044 unsigned long Console_Configuration_Count = NUM_DEVS;
0045
0046
0047 const console_fns uart_fns = {
0048 libchip_serial_default_probe,
0049 uart_first_open,
0050 uart_last_close,
0051 uart_read,
0052 uart_write,
0053 uart_init,
0054 uart_write_polled,
0055 uart_set_attributes,
0056 FALSE
0057 };
0058
0059
0060
0061
0062
0063
0064
0065 console_tbl Console_Configuration_Ports[] = {
0066 {
0067 "/dev/com0",
0068 SERIAL_CUSTOM,
0069 &uart_fns,
0070 NULL,
0071 NULL,
0072 0,
0073 0,
0074 NULL,
0075 0,
0076 0,
0077 0,
0078 NULL,
0079 NULL,
0080 NULL,
0081 NULL,
0082 0,
0083 0
0084 }
0085 #if 0
0086 {
0087 "/dev/com1",
0088 SERIAL_CUSTOM,
0089 &uart_fns,
0090 NULL,
0091 NULL,
0092 0,
0093 0,
0094 NULL,
0095 0,
0096 0,
0097 0,
0098 NULL,
0099 NULL,
0100 NULL,
0101 NULL,
0102 0,
0103 0
0104 }
0105 #endif
0106 };
0107
0108
0109
0110
0111
0112
0113
0114
0115 static int uart_first_open(int major, int minor, void *arg)
0116 {
0117 return 0;
0118 }
0119
0120
0121
0122
0123
0124
0125 static int uart_last_close(int major, int minor, void *arg)
0126 {
0127 return 0;
0128 }
0129
0130
0131
0132
0133
0134
0135
0136 static int uart_read(int minor)
0137 {
0138 char c;
0139
0140 switch (minor) {
0141 case 0:
0142 if (U0LSR & ULSR_RDR) {
0143 c = U0RBR;
0144 return c;
0145 }
0146 return -1;
0147 case 1:
0148 if (U1LSR & ULSR_RDR) {
0149 c = U1RBR;
0150 return c;
0151 }
0152 return -1;
0153 default:
0154 break;
0155 }
0156 printk("Unknown console minor number %d\n", minor);
0157 return -1;
0158 }
0159
0160
0161
0162
0163
0164
0165 static ssize_t uart_write(int minor, const char *buf, size_t len)
0166 {
0167 size_t i;
0168
0169 switch (minor) {
0170 case 0:
0171 for (i = 0; i < len; i++) {
0172 while (!(U0LSR & ULSR_THRE))
0173 continue;
0174 U0THR = (char) buf[i];
0175 }
0176 break;
0177 case 1:
0178 for (i = 0; i < len; i++) {
0179 while (!(U0LSR & ULSR_THRE))
0180 continue;
0181 U0THR = (char) buf[i];
0182 }
0183 break;
0184 default:
0185 printk("Unknown console minor number %d\n", minor);
0186 return -1;
0187 }
0188
0189 return len;
0190 }
0191
0192
0193 static void uart_init(int minor)
0194 {
0195 #if 0
0196 int baud=6;
0197 int mode =0x03;
0198 if(minor==0){
0199
0200 PINSEL0 = (PINSEL0 & ~U0_PINMASK) | U0_PINSEL;
0201
0202 U0IER = 0x00;
0203
0204
0205 U0LCR = 1<<7;
0206 U0DLL = (uint8_t)baud;
0207 U0DLM = (uint8_t)(baud >> 8);
0208
0209
0210
0211 U0LCR = (mode & ~ULCR_DLAB_ENABLE);
0212 U0FCR = mode>>8;
0213
0214
0215 PINSEL0 = (PINSEL0 & ~U1_PINMASK) | U1_PINSEL;
0216
0217 U1IER = 0x00;
0218 }else if(minor==1){
0219
0220 U1LCR = ULCR_DLAB_ENABLE;
0221 U1DLL = (uint8_t)baud;
0222 U1DLM = (uint8_t)(baud >> 8);
0223
0224
0225
0226 U1LCR = (mode & ~ULCR_DLAB_ENABLE);
0227 U1FCR = mode>>8;
0228 }
0229
0230 #endif
0231 }
0232
0233
0234 static void uart_write_polled(int minor, char c)
0235 {
0236 uart_write(minor, &c, 1);
0237 }
0238
0239
0240 static int uart_set_attributes(int minor, const struct termios *t)
0241 {
0242 return 0;
0243 }
0244
0245
0246
0247
0248
0249
0250 static void _BSP_put_char( char c )
0251 {
0252 uart_write_polled(0, c);
0253 }
0254
0255 BSP_output_char_function_type BSP_output_char = _BSP_put_char;
0256
0257 static int _BSP_get_char(void)
0258 {
0259 return uart_read(0);
0260 }
0261
0262 BSP_polling_getchar_function_type BSP_poll_char = _BSP_get_char;
0263
0264
0265
0266
0267 void UART0_Ini(void)
0268 {
0269 long Fdiv;
0270 int i;
0271
0272 PINSEL0 = 0x00000005;
0273 U0LCR = 0x83;
0274 Fdiv = (Fpclk >>4) / UART_BPS;
0275 U0DLM = Fdiv/256;
0276 U0DLL = Fdiv%256;
0277 U0LCR = 0x03;
0278
0279 for(i=0;i<10;i++){
0280 U0THR = 67;
0281 while ( (U0LSR&0x40)==0 );
0282 }
0283 }