1 | /* |
---|
2 | * Copyright (c) 2012, 2015 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | /* |
---|
16 | * Console driver for Lauterbach Trace32 Simulator. The implementation is |
---|
17 | * based on the example in "demo/powerpc/etc/terminal/terminal_mpc85xx.cmm" in |
---|
18 | * the Trace32 system directory. |
---|
19 | */ |
---|
20 | |
---|
21 | #include <rtems/bspIo.h> |
---|
22 | #include <rtems/console.h> |
---|
23 | #include <rtems/termiostypes.h> |
---|
24 | |
---|
25 | volatile unsigned char messagebufferin[256]; |
---|
26 | |
---|
27 | volatile unsigned char messagebufferout[256]; |
---|
28 | |
---|
29 | typedef struct { |
---|
30 | rtems_termios_device_context base; |
---|
31 | int input_size; |
---|
32 | int input_index; |
---|
33 | } t32_console_context; |
---|
34 | |
---|
35 | static t32_console_context t32_console_instance; |
---|
36 | |
---|
37 | static bool t32_console_first_open( |
---|
38 | rtems_termios_tty *tty, |
---|
39 | rtems_termios_device_context *base, |
---|
40 | struct termios *term, |
---|
41 | rtems_libio_open_close_args_t *args |
---|
42 | ) |
---|
43 | { |
---|
44 | rtems_termios_set_initial_baud(tty, 115200); |
---|
45 | |
---|
46 | return true; |
---|
47 | } |
---|
48 | |
---|
49 | static int t32_console_read_polled(rtems_termios_device_context *base) |
---|
50 | { |
---|
51 | t32_console_context *ctx = (t32_console_context *) base; |
---|
52 | int c; |
---|
53 | |
---|
54 | if (ctx->input_size == 0) { |
---|
55 | int new_bufsize = messagebufferin[0]; |
---|
56 | |
---|
57 | if (new_bufsize != 0) { |
---|
58 | ctx->input_size = new_bufsize; |
---|
59 | ctx->input_index = 0; |
---|
60 | } else { |
---|
61 | return -1; |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | c = messagebufferin[4 + ctx->input_index]; |
---|
66 | |
---|
67 | ++ctx->input_index; |
---|
68 | if (ctx->input_index >= ctx->input_size) { |
---|
69 | messagebufferin[0] = 0; |
---|
70 | ctx->input_size = 0; |
---|
71 | } |
---|
72 | |
---|
73 | return c; |
---|
74 | } |
---|
75 | |
---|
76 | static void t32_console_write_char_polled(char c) |
---|
77 | { |
---|
78 | while (messagebufferout[0] != 0) { |
---|
79 | /* Wait for ready */ |
---|
80 | } |
---|
81 | |
---|
82 | messagebufferout[4] = (unsigned char) c; |
---|
83 | messagebufferout[0] = 1; |
---|
84 | } |
---|
85 | |
---|
86 | static void t32_console_write_polled( |
---|
87 | rtems_termios_device_context *base, |
---|
88 | const char *s, |
---|
89 | size_t n |
---|
90 | ) |
---|
91 | { |
---|
92 | size_t i; |
---|
93 | |
---|
94 | for (i = 0; i < n; ++i) { |
---|
95 | t32_console_write_char_polled(s[i]); |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | const rtems_termios_device_handler t32_console_handler = { |
---|
100 | .first_open = t32_console_first_open, |
---|
101 | .poll_read = t32_console_read_polled, |
---|
102 | .write = t32_console_write_polled, |
---|
103 | .mode = TERMIOS_POLLED |
---|
104 | }; |
---|
105 | |
---|
106 | rtems_device_driver console_initialize( |
---|
107 | rtems_device_major_number major, |
---|
108 | rtems_device_minor_number minor, |
---|
109 | void *arg |
---|
110 | ) |
---|
111 | { |
---|
112 | t32_console_context *ctx = &t32_console_instance; |
---|
113 | |
---|
114 | rtems_termios_initialize(); |
---|
115 | rtems_termios_device_context_initialize(&ctx->base, "T32 Console"); |
---|
116 | rtems_termios_device_install( |
---|
117 | CONSOLE_DEVICE_NAME, |
---|
118 | &t32_console_handler, |
---|
119 | NULL, |
---|
120 | &ctx->base |
---|
121 | ); |
---|
122 | |
---|
123 | return RTEMS_SUCCESSFUL; |
---|
124 | } |
---|
125 | |
---|
126 | BSP_output_char_function_type BSP_output_char = t32_console_write_char_polled; |
---|
127 | |
---|
128 | BSP_polling_getchar_function_type BSP_poll_char = NULL; |
---|