1 | /* |
---|
2 | * This file contains the hardware independent portion of a polled |
---|
3 | * console device driver. If a BSP chooses to use this, then it |
---|
4 | * only has to provide a few board dependent routines. |
---|
5 | */ |
---|
6 | |
---|
7 | /* |
---|
8 | * COPYRIGHT (c) 1989-1997. |
---|
9 | * On-Line Applications Research Corporation (OAR). |
---|
10 | * |
---|
11 | * The license and distribution terms for this file may be |
---|
12 | * found in the file LICENSE in this distribution or at |
---|
13 | * http://www.rtems.org/license/LICENSE. |
---|
14 | */ |
---|
15 | |
---|
16 | #include <bsp.h> |
---|
17 | #include <rtems/libio.h> |
---|
18 | #include <stdlib.h> |
---|
19 | #include <assert.h> |
---|
20 | |
---|
21 | #include <bsp/console-polled.h> |
---|
22 | #include <rtems/console.h> |
---|
23 | |
---|
24 | /* |
---|
25 | * Prototypes |
---|
26 | */ |
---|
27 | ssize_t console_write_support(int, const char *, size_t); |
---|
28 | |
---|
29 | /* |
---|
30 | * Console Termios Support Entry Points |
---|
31 | * |
---|
32 | */ |
---|
33 | ssize_t console_write_support ( |
---|
34 | int minor, |
---|
35 | const char *bufarg, |
---|
36 | size_t len |
---|
37 | ) |
---|
38 | { |
---|
39 | int nwrite = 0; |
---|
40 | const char *buf = bufarg; |
---|
41 | |
---|
42 | while (nwrite < len) { |
---|
43 | console_outbyte_polled( minor, *buf++ ); |
---|
44 | nwrite++; |
---|
45 | } |
---|
46 | return nwrite; |
---|
47 | } |
---|
48 | |
---|
49 | /* |
---|
50 | * Console Device Driver Entry Points |
---|
51 | * |
---|
52 | */ |
---|
53 | |
---|
54 | rtems_device_driver console_initialize( |
---|
55 | rtems_device_major_number major, |
---|
56 | rtems_device_minor_number minor, |
---|
57 | void *arg |
---|
58 | ) |
---|
59 | { |
---|
60 | rtems_status_code status; |
---|
61 | |
---|
62 | /* |
---|
63 | * Ensure Termios is initialized |
---|
64 | */ |
---|
65 | rtems_termios_initialize(); |
---|
66 | |
---|
67 | /* |
---|
68 | * Make sure the hardware is initialized. |
---|
69 | */ |
---|
70 | console_initialize_hardware(); |
---|
71 | |
---|
72 | /* |
---|
73 | * Register Device Names |
---|
74 | */ |
---|
75 | status = rtems_io_register_name( "/dev/console", major, 0 ); |
---|
76 | if (status != RTEMS_SUCCESSFUL) |
---|
77 | rtems_fatal_error_occurred(BSP_FATAL_CONSOLE_REGISTER_DEV_0); |
---|
78 | |
---|
79 | return RTEMS_SUCCESSFUL; |
---|
80 | } |
---|
81 | |
---|
82 | rtems_device_driver console_open( |
---|
83 | rtems_device_major_number major, |
---|
84 | rtems_device_minor_number minor, |
---|
85 | void * arg |
---|
86 | ) |
---|
87 | { |
---|
88 | static const rtems_termios_callbacks pollCallbacks = { |
---|
89 | NULL, /* firstOpen */ |
---|
90 | NULL, /* lastClose */ |
---|
91 | console_inbyte_nonblocking, /* pollRead */ |
---|
92 | console_write_support, /* write */ |
---|
93 | NULL, /* setAttributes */ |
---|
94 | NULL, /* stopRemoteTx */ |
---|
95 | NULL, /* startRemoteTx */ |
---|
96 | 0 /* outputUsesInterrupts */ |
---|
97 | }; |
---|
98 | |
---|
99 | assert( minor == 0 ); |
---|
100 | if ( minor != 0 ) |
---|
101 | return RTEMS_INVALID_NUMBER; |
---|
102 | |
---|
103 | rtems_termios_open( major, minor, arg, &pollCallbacks ); |
---|
104 | |
---|
105 | return RTEMS_SUCCESSFUL; |
---|
106 | } |
---|
107 | |
---|
108 | rtems_device_driver console_close( |
---|
109 | rtems_device_major_number major, |
---|
110 | rtems_device_minor_number minor, |
---|
111 | void * arg |
---|
112 | ) |
---|
113 | { |
---|
114 | return rtems_termios_close( arg ); |
---|
115 | } |
---|
116 | |
---|
117 | rtems_device_driver console_read( |
---|
118 | rtems_device_major_number major, |
---|
119 | rtems_device_minor_number minor, |
---|
120 | void * arg |
---|
121 | ) |
---|
122 | { |
---|
123 | return rtems_termios_read( arg ); |
---|
124 | } |
---|
125 | |
---|
126 | rtems_device_driver console_write( |
---|
127 | rtems_device_major_number major, |
---|
128 | rtems_device_minor_number minor, |
---|
129 | void * arg |
---|
130 | ) |
---|
131 | { |
---|
132 | return rtems_termios_write( arg ); |
---|
133 | } |
---|
134 | |
---|
135 | rtems_device_driver console_control( |
---|
136 | rtems_device_major_number major, |
---|
137 | rtems_device_minor_number minor, |
---|
138 | void * arg |
---|
139 | ) |
---|
140 | { |
---|
141 | return rtems_termios_ioctl( arg ); |
---|
142 | } |
---|