File indexing completed on 2025-05-11 08:23:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089 #include <stdarg.h>
0090 #include <stdio.h>
0091 #include <termios.h>
0092
0093 #include <rtems/console.h>
0094 #include <rtems/bspIo.h>
0095 #include <rtems/libio.h>
0096 #include <bsp.h>
0097
0098 static void _BSP_output_char( char c );
0099 static rtems_status_code do_poll_read( rtems_device_major_number major, rtems_device_minor_number minor, void * arg);
0100 static rtems_status_code do_poll_write( rtems_device_major_number major, rtems_device_minor_number minor, void * arg);
0101
0102 BSP_output_char_function_type BSP_output_char = _BSP_output_char;
0103 BSP_polling_getchar_function_type BSP_poll_char = NULL;
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128 static rtems_status_code do_poll_read(
0129 rtems_device_major_number major,
0130 rtems_device_minor_number minor,
0131 void * arg
0132 )
0133 {
0134 rtems_libio_rw_args_t *rw_args = arg;
0135 int c;
0136
0137 #define BSP_READ m8xx_uart_pollRead
0138
0139 while( (c = BSP_READ(minor)) == -1 );
0140 rw_args->buffer[0] = (uint8_t)c;
0141 if( rw_args->buffer[0] == '\r' )
0142 rw_args->buffer[0] = '\n';
0143 rw_args->bytes_moved = 1;
0144 return RTEMS_SUCCESSFUL;
0145 }
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168 static rtems_status_code do_poll_write(
0169 rtems_device_major_number major,
0170 rtems_device_minor_number minor,
0171 void * arg
0172 )
0173 {
0174 rtems_libio_rw_args_t *rw_args = arg;
0175 uint32_t i;
0176 char cr ='\r';
0177
0178 #define BSP_WRITE m8xx_uart_pollWrite
0179
0180 for( i = 0; i < rw_args->count; i++ ) {
0181 BSP_WRITE(minor, &(rw_args->buffer[i]), 1);
0182 if ( rw_args->buffer[i] == '\n' )
0183 BSP_WRITE(minor, &cr, 1);
0184 }
0185 rw_args->bytes_moved = i;
0186 return RTEMS_SUCCESSFUL;
0187
0188 }
0189
0190
0191
0192
0193
0194 static void _BSP_output_char( char c )
0195 {
0196
0197
0198
0199
0200 #define PRINTK_WRITE m8xx_uart_pollWrite
0201
0202 PRINTK_WRITE( PRINTK_MINOR, &c, 1 );
0203 }
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216 rtems_device_driver console_initialize(
0217 rtems_device_major_number major,
0218 rtems_device_minor_number minor,
0219 void *arg
0220 )
0221 {
0222 rtems_status_code status;
0223 rtems_device_minor_number console_minor;
0224
0225
0226
0227
0228
0229 console_minor = CONSOLE_MINOR;
0230
0231 #if UARTS_USE_TERMIOS == 1
0232
0233 rtems_termios_initialize ();
0234 #else
0235 rtems_termios_initialize ();
0236 #endif
0237
0238
0239
0240
0241 m8xx_uart_initialize();
0242
0243
0244
0245
0246 #if 0
0247 m8xx_uart_smc_initialize(SMC1_MINOR);
0248 m8xx_uart_smc_initialize(SMC2_MINOR);
0249 #endif
0250
0251 m8xx_uart_scc_initialize(SCC1_MINOR);
0252 m8xx_uart_scc_initialize(SCC2_MINOR);
0253
0254 #if 0
0255 m8xx_uart_scc_initialize(SCC3_MINOR);
0256 m8xx_uart_scc_initialize(SCC4_MINOR);
0257 #endif
0258
0259
0260
0261
0262 m8xx_uart_interrupts_initialize();
0263
0264 status = rtems_io_register_name ("/dev/tty0", major, SCC1_MINOR);
0265 if (status != RTEMS_SUCCESSFUL)
0266 rtems_fatal_error_occurred (status);
0267 chmod("/dev/tty0",0660);
0268 chown("/dev/tty0",2,0);
0269
0270 status = rtems_io_register_name ("/dev/tty1", major, SCC2_MINOR);
0271 if (status != RTEMS_SUCCESSFUL)
0272 rtems_fatal_error_occurred (status);
0273 chmod("/dev/tty1",0660);
0274 chown("/dev/tty1",2,0);
0275
0276 #if 0
0277 status = rtems_io_register_name ("/dev/tty2", major, SCC3_MINOR);
0278 if (status != RTEMS_SUCCESSFUL)
0279 rtems_fatal_error_occurred (status);
0280
0281 status = rtems_io_register_name ("/dev/tty3", major, SCC4_MINOR);
0282 if (status != RTEMS_SUCCESSFUL)
0283 rtems_fatal_error_occurred (status);
0284
0285 status = rtems_io_register_name ("/dev/tty4", major, SMC1_MINOR);
0286 if (status != RTEMS_SUCCESSFUL)
0287 rtems_fatal_error_occurred (status);
0288
0289 status = rtems_io_register_name ("/dev/tty5", major, SMC2_MINOR);
0290 if (status != RTEMS_SUCCESSFUL)
0291 rtems_fatal_error_occurred (status);
0292 #endif
0293
0294 status = rtems_io_register_name ("/dev/console", major, console_minor);
0295 if (status != RTEMS_SUCCESSFUL)
0296 rtems_fatal_error_occurred (status);
0297 chmod("/dev/console",0666);
0298 chown("/dev/console",2,0);
0299
0300 return RTEMS_SUCCESSFUL;
0301 }
0302
0303
0304
0305
0306 rtems_device_driver console_open(
0307 rtems_device_major_number major,
0308 rtems_device_minor_number minor,
0309 void *arg
0310 )
0311 {
0312 #if UARTS_IO_MODE == 1
0313
0314 extern struct rtems_termios_tty *ttyp[];
0315 rtems_libio_open_close_args_t *args = arg;
0316
0317 static const rtems_termios_callbacks intrCallbacks = {
0318 NULL,
0319 NULL,
0320 NULL,
0321 m8xx_uart_write,
0322 m8xx_uart_setAttributes,
0323 NULL,
0324 NULL,
0325 TERMIOS_IRQ_DRIVEN
0326 };
0327 #else
0328 #if (UARTS_USE_TERMIOS == 1) && (UARTS_IO_MODE != 1)
0329 static const rtems_termios_callbacks pollCallbacks = {
0330 NULL,
0331 NULL,
0332 m8xx_uart_pollRead,
0333 m8xx_uart_pollWrite,
0334 m8xx_uart_setAttributes,
0335 NULL,
0336 NULL,
0337 TERMIOS_POLLED
0338 };
0339 #endif
0340
0341 #endif
0342
0343 rtems_status_code sc;
0344
0345 if ( minor > NUM_PORTS-1 )
0346 return RTEMS_INVALID_NUMBER;
0347
0348 #if UARTS_USE_TERMIOS == 1
0349
0350 #if UARTS_IO_MODE == 1
0351 sc = rtems_termios_open( major, minor, arg, &intrCallbacks );
0352 ttyp[minor] = args->iop->data1;
0353 #else
0354 sc = rtems_termios_open( major, minor, arg, &pollCallbacks );
0355 #endif
0356
0357 #else
0358
0359 sc = RTEMS_SUCCESSFUL;
0360 #endif
0361
0362 return sc;
0363
0364 }
0365
0366
0367
0368
0369 rtems_device_driver console_close(
0370 rtems_device_major_number major,
0371 rtems_device_minor_number minor,
0372 void *arg
0373 )
0374 {
0375 if ( minor > NUM_PORTS-1 )
0376 return RTEMS_INVALID_NUMBER;
0377
0378 #if UARTS_USE_TERMIOS == 1
0379 return rtems_termios_close( arg );
0380 #else
0381 return RTEMS_SUCCESSFUL;
0382 #endif
0383
0384 }
0385
0386
0387
0388
0389 rtems_device_driver console_read(
0390 rtems_device_major_number major,
0391 rtems_device_minor_number minor,
0392 void *arg
0393 )
0394 {
0395 if ( minor > NUM_PORTS-1 )
0396 return RTEMS_INVALID_NUMBER;
0397
0398 #if UARTS_USE_TERMIOS == 1
0399 return rtems_termios_read( arg );
0400 #else
0401 return do_poll_read( major, minor, arg );
0402 #endif
0403
0404 }
0405
0406
0407
0408
0409 rtems_device_driver console_write(
0410 rtems_device_major_number major,
0411 rtems_device_minor_number minor,
0412 void *arg
0413 )
0414 {
0415 if ( minor > NUM_PORTS-1 )
0416 return RTEMS_INVALID_NUMBER;
0417
0418 #if UARTS_USE_TERMIOS == 1
0419 return rtems_termios_write( arg );
0420 #else
0421
0422 return do_poll_write( major, minor, arg );
0423 #endif
0424
0425 }
0426
0427
0428
0429
0430 rtems_device_driver console_control(
0431 rtems_device_major_number major,
0432 rtems_device_minor_number minor,
0433 void *arg
0434 )
0435 {
0436 if ( minor > NUM_PORTS-1 )
0437 return RTEMS_INVALID_NUMBER;
0438
0439 #if UARTS_USE_TERMIOS == 1
0440 return rtems_termios_ioctl( arg );
0441 #else
0442 return RTEMS_SUCCESSFUL;
0443 #endif
0444
0445 }
0446
0447
0448
0449
0450 int mbx8xx_console_get_configuration(void)
0451 {
0452 #if UARTS_IO_MODE == 1
0453 return 0x02;
0454 #else
0455 return 0;
0456 #endif
0457
0458 }