File indexing completed on 2025-05-11 08:23:59
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 <rtems/bspIo.h>
0035 #include <rtems/console.h>
0036 #include <rtems/termiostypes.h>
0037
0038 RTEMS_SECTION(".rtemsrwset.t32") volatile unsigned char messagebufferin[256];
0039
0040 RTEMS_SECTION(".rtemsrwset.t32") volatile unsigned char messagebufferout[256];
0041
0042 typedef struct {
0043 rtems_termios_device_context base;
0044 int input_size;
0045 int input_index;
0046 } t32_console_context;
0047
0048 static t32_console_context t32_console_instance;
0049
0050 static bool t32_console_first_open(
0051 rtems_termios_tty *tty,
0052 rtems_termios_device_context *base,
0053 struct termios *term,
0054 rtems_libio_open_close_args_t *args
0055 )
0056 {
0057 rtems_termios_set_initial_baud(tty, 115200);
0058
0059 return true;
0060 }
0061
0062 static int t32_console_read_polled(rtems_termios_device_context *base)
0063 {
0064 t32_console_context *ctx = (t32_console_context *) base;
0065 int c;
0066
0067 if (ctx->input_size == 0) {
0068 int new_bufsize = messagebufferin[0];
0069
0070 if (new_bufsize != 0) {
0071 ctx->input_size = new_bufsize;
0072 ctx->input_index = 0;
0073 } else {
0074 return -1;
0075 }
0076 }
0077
0078 c = messagebufferin[4 + ctx->input_index];
0079
0080 ++ctx->input_index;
0081 if (ctx->input_index >= ctx->input_size) {
0082 messagebufferin[0] = 0;
0083 ctx->input_size = 0;
0084 }
0085
0086 return c;
0087 }
0088
0089 static void t32_console_write_char_polled(char c)
0090 {
0091 while (messagebufferout[0] != 0) {
0092
0093 }
0094
0095 messagebufferout[4] = (unsigned char) c;
0096 messagebufferout[0] = 1;
0097 }
0098
0099 static void t32_console_write_polled(
0100 rtems_termios_device_context *base,
0101 const char *s,
0102 size_t n
0103 )
0104 {
0105 size_t i;
0106
0107 for (i = 0; i < n; ++i) {
0108 t32_console_write_char_polled(s[i]);
0109 }
0110 }
0111
0112 const rtems_termios_device_handler t32_console_handler = {
0113 .first_open = t32_console_first_open,
0114 .poll_read = t32_console_read_polled,
0115 .write = t32_console_write_polled,
0116 .mode = TERMIOS_POLLED
0117 };
0118
0119 rtems_device_driver console_initialize(
0120 rtems_device_major_number major,
0121 rtems_device_minor_number minor,
0122 void *arg
0123 )
0124 {
0125 t32_console_context *ctx = &t32_console_instance;
0126
0127 rtems_termios_initialize();
0128 rtems_termios_device_context_initialize(&ctx->base, "T32 Console");
0129 rtems_termios_device_install(
0130 CONSOLE_DEVICE_NAME,
0131 &t32_console_handler,
0132 NULL,
0133 &ctx->base
0134 );
0135
0136 return RTEMS_SUCCESSFUL;
0137 }
0138
0139 BSP_output_char_function_type BSP_output_char = t32_console_write_char_polled;
0140
0141 BSP_polling_getchar_function_type BSP_poll_char = NULL;