File indexing completed on 2025-05-11 08:23:54
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 #include <sys/cdefs.h>
0035
0036 #include <bsp.h>
0037 #include <bsp/console-generic.h>
0038 #include <bsp/fatal.h>
0039
0040 #include <rtems/bspIo.h>
0041 #include <rtems/console.h>
0042
0043 static const struct termios console_generic_termios = {
0044 .c_cflag = CS8 | CREAD | CLOCAL | __CONCAT(B, BSP_DEFAULT_BAUD_RATE)
0045 };
0046
0047 static void console_generic_char_out(char c)
0048 {
0049 int minor = (int) console_generic_minor;
0050 const console_generic_callbacks *cb =
0051 console_generic_info_table [minor].callbacks;
0052
0053 (*cb->poll_write)(minor, c);
0054 }
0055
0056 static int console_generic_char_in(void)
0057 {
0058 int minor = (int) console_generic_minor;
0059 const console_generic_callbacks *cb =
0060 console_generic_info_table [minor].callbacks;
0061
0062 return (*cb->poll_read)(minor);
0063 }
0064
0065 static void console_generic_char_out_do_init(void)
0066 {
0067 int minor = (int) console_generic_minor;
0068 const console_generic_callbacks *cb =
0069 console_generic_info_table [minor].callbacks;
0070 const struct termios *term = &console_generic_termios;
0071
0072 BSP_output_char = console_generic_char_out;
0073 (*cb->termios_callbacks.setAttributes)(minor, term);
0074 }
0075
0076 static void console_generic_char_out_init(char c)
0077 {
0078 console_generic_char_out_do_init();
0079 console_generic_char_out(c);
0080 }
0081
0082 rtems_device_driver console_initialize(
0083 rtems_device_major_number major,
0084 rtems_device_minor_number minor,
0085 void *arg
0086 )
0087 {
0088 rtems_status_code sc = RTEMS_SUCCESSFUL;
0089 const console_generic_info *info_table = console_generic_info_table;
0090 rtems_device_minor_number count = console_generic_info_count;
0091 rtems_device_minor_number console = console_generic_minor;
0092
0093 if (count <= 0) {
0094 bsp_fatal(MPC55XX_FATAL_CONSOLE_GENERIC_COUNT);
0095 }
0096
0097 rtems_termios_initialize();
0098
0099 for (minor = 0; minor < count; ++minor) {
0100 const console_generic_info *info = info_table + minor;
0101
0102 sc = rtems_io_register_name(info->device_path, major, minor);
0103 if (sc != RTEMS_SUCCESSFUL) {
0104 bsp_fatal(MPC55XX_FATAL_CONSOLE_GENERIC_REGISTER);
0105 }
0106 }
0107
0108 sc = rtems_io_register_name(CONSOLE_DEVICE_NAME, major, console);
0109 if (sc != RTEMS_SUCCESSFUL) {
0110 bsp_fatal(MPC55XX_FATAL_CONSOLE_GENERIC_REGISTER_CONSOLE);
0111 }
0112
0113 console_generic_char_out_do_init();
0114
0115 return sc;
0116 }
0117
0118 rtems_device_driver console_open(
0119 rtems_device_major_number major,
0120 rtems_device_minor_number minor,
0121 void *arg
0122 )
0123 {
0124 rtems_status_code sc = RTEMS_SUCCESSFUL;
0125 rtems_device_minor_number count = console_generic_info_count;
0126
0127 if (minor < count) {
0128 const console_generic_info *info = &console_generic_info_table [minor];
0129
0130 sc = rtems_termios_open(
0131 major,
0132 minor,
0133 arg,
0134 &info->callbacks->termios_callbacks
0135 );
0136 } else {
0137 sc = RTEMS_INVALID_ID;
0138 }
0139
0140 return sc;
0141 }
0142
0143 rtems_device_driver console_close(
0144 rtems_device_major_number major,
0145 rtems_device_minor_number minor,
0146 void *arg
0147 )
0148 {
0149 return rtems_termios_close(arg);
0150 }
0151
0152 rtems_device_driver console_read(
0153 rtems_device_major_number major,
0154 rtems_device_minor_number minor,
0155 void *arg
0156 )
0157 {
0158 return rtems_termios_read(arg);
0159 }
0160
0161 rtems_device_driver console_write(
0162 rtems_device_major_number major,
0163 rtems_device_minor_number minor,
0164 void *arg
0165 )
0166 {
0167 return rtems_termios_write(arg);
0168 }
0169
0170 rtems_device_driver console_control(
0171 rtems_device_major_number major,
0172 rtems_device_minor_number minor,
0173 void *arg
0174 )
0175 {
0176 return rtems_termios_ioctl(arg);
0177 }
0178
0179 BSP_output_char_function_type BSP_output_char = console_generic_char_out_init;
0180
0181 BSP_polling_getchar_function_type BSP_poll_char = console_generic_char_in;