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