1 | /** |
---|
2 | * @file console.c |
---|
3 | * |
---|
4 | * This file contains the GBA console I/O package. |
---|
5 | */ |
---|
6 | /* |
---|
7 | * RTEMS GBA BSP |
---|
8 | * |
---|
9 | * Copyright (c) 2004 Markku Puro <markku.puro@kopteri.net> |
---|
10 | * |
---|
11 | * The license and distribution terms for this file may be |
---|
12 | * found in found in the file LICENSE in this distribution or at |
---|
13 | * http://www.rtems.com/license/LICENSE. |
---|
14 | * |
---|
15 | * $Id$ |
---|
16 | */ |
---|
17 | |
---|
18 | #include <stdio.h> |
---|
19 | #include <stdlib.h> |
---|
20 | #include <assert.h> |
---|
21 | #include <unistd.h> |
---|
22 | |
---|
23 | #include <bsp.h> |
---|
24 | #include <rtems/bspIo.h> |
---|
25 | #include <rtems/libio.h> |
---|
26 | #include <rtems/termiostypes.h> |
---|
27 | #include <termios.h> |
---|
28 | #include <irq.h> |
---|
29 | #include <gba.h> |
---|
30 | #include <conio.h> |
---|
31 | |
---|
32 | #undef __assert |
---|
33 | void __assert (const char *file, int line, const char *msg); |
---|
34 | |
---|
35 | extern void rtemsReboot(void); |
---|
36 | |
---|
37 | |
---|
38 | /** |
---|
39 | * @brief gba_pollRead function read char |
---|
40 | * |
---|
41 | * @param minor unused |
---|
42 | * @return character code |
---|
43 | */ |
---|
44 | static int gba_pollRead(int minor) |
---|
45 | { |
---|
46 | return(gba_getch()); |
---|
47 | } |
---|
48 | |
---|
49 | /** |
---|
50 | * @brief gba_write function writes chars |
---|
51 | * |
---|
52 | * Input parameters: minor code, buffer pointer and lenght |
---|
53 | * @param minor unused |
---|
54 | * @param *buf buffer pointer |
---|
55 | * @param len lenght of buffer |
---|
56 | * @return character code |
---|
57 | * |
---|
58 | */ |
---|
59 | static int gba_write(int minor, const char *buf, int len) |
---|
60 | { |
---|
61 | int i; |
---|
62 | |
---|
63 | for (i=0;i<len;i++) { |
---|
64 | gba_putch((unsigned short)buf[i]); |
---|
65 | } |
---|
66 | return len; |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | * @brief gba_setAttributes function is empty |
---|
71 | * |
---|
72 | * @param minor unused |
---|
73 | * @param *t unused |
---|
74 | * @return constant 0 |
---|
75 | */ |
---|
76 | static int gba_setAttributes(int minor, const struct termios *t) |
---|
77 | { |
---|
78 | return 0; |
---|
79 | } |
---|
80 | |
---|
81 | /** BSP_output_char for printk support */ |
---|
82 | BSP_output_char_function_type BSP_output_char = (BSP_output_char_function_type) gba_putch; |
---|
83 | /** BSP_poll_char for printk support */ |
---|
84 | BSP_polling_getchar_function_type BSP_poll_char = (BSP_polling_getchar_function_type) gba_getch; |
---|
85 | |
---|
86 | |
---|
87 | /** |
---|
88 | * @brief assert function |
---|
89 | * |
---|
90 | * @param *file file name |
---|
91 | * @param line line number |
---|
92 | * @param *msg assert message |
---|
93 | * @return None |
---|
94 | */ |
---|
95 | void __assert (const char *file, int line, const char *msg) |
---|
96 | { |
---|
97 | static const char exit_msg[] = "EXECUTIVE SHUTDOWN! Any button to reboot..."; |
---|
98 | /* |
---|
99 | * Note we cannot call exit or printf from here, |
---|
100 | * assert can fail inside ISR too |
---|
101 | */ |
---|
102 | close(2); /* Close console */ |
---|
103 | close(1); |
---|
104 | close(0); |
---|
105 | |
---|
106 | printk("\nassert failed: %s: ", file); |
---|
107 | printk("%d: ", line); |
---|
108 | printk("%s\n\n", msg); |
---|
109 | printk("%s",exit_msg); |
---|
110 | while ( !GBA_ANY_KEY(GBA_KEY_ALL) ); |
---|
111 | printk("\n\n"); |
---|
112 | rtemsReboot(); |
---|
113 | } |
---|
114 | |
---|
115 | /** |
---|
116 | * @brief Console device driver INITIALIZE entry point |
---|
117 | * |
---|
118 | * Initilizes the I/O console driver. |
---|
119 | * |
---|
120 | * @param major diver major number |
---|
121 | * @param minor driver minor mumber |
---|
122 | * @param *arg pointer to parameters |
---|
123 | * @return status code |
---|
124 | */ |
---|
125 | rtems_device_driver |
---|
126 | console_initialize(rtems_device_major_number major, |
---|
127 | rtems_device_minor_number minor, |
---|
128 | void *arg) |
---|
129 | { |
---|
130 | rtems_status_code status; |
---|
131 | |
---|
132 | /* Set up TERMIOS */ |
---|
133 | rtems_termios_initialize (); |
---|
134 | |
---|
135 | /* Do device-specific initialization */ |
---|
136 | /* Allready done in bspstart.c -> gba_textmode(CO60); */ |
---|
137 | |
---|
138 | /* Register the device */ |
---|
139 | status = rtems_io_register_name ("/dev/console", major, 0); |
---|
140 | if (status != RTEMS_SUCCESSFUL) { |
---|
141 | printk("Error registering console device!\n"); |
---|
142 | rtems_fatal_error_occurred (status); |
---|
143 | } |
---|
144 | |
---|
145 | printk("Initialized GBA console\n\n"); |
---|
146 | |
---|
147 | return RTEMS_SUCCESSFUL; |
---|
148 | } |
---|
149 | |
---|
150 | /** |
---|
151 | * @brief console_first_open function is empty |
---|
152 | * |
---|
153 | * @param major diver major number |
---|
154 | * @param minor driver minor mumber |
---|
155 | * @param *arg pointer to parameters |
---|
156 | * @return status code |
---|
157 | */ |
---|
158 | static int console_first_open(int major, int minor, void *arg) |
---|
159 | { |
---|
160 | return 0; |
---|
161 | } |
---|
162 | |
---|
163 | /** |
---|
164 | * @brief console_last_close function is empty |
---|
165 | * |
---|
166 | * @param major diver major number |
---|
167 | * @param minor driver minor mumber |
---|
168 | * @param *arg pointer to parameters |
---|
169 | * @return status code |
---|
170 | */ |
---|
171 | static int console_last_close(int major, int minor, void *arg) |
---|
172 | { |
---|
173 | return 0; |
---|
174 | } |
---|
175 | |
---|
176 | |
---|
177 | /** |
---|
178 | * @brief Console device driver OPEN entry point |
---|
179 | * |
---|
180 | * @param major diver major number |
---|
181 | * @param minor driver minor mumber |
---|
182 | * @param *arg pointer to parameters |
---|
183 | * @return status code |
---|
184 | */ |
---|
185 | rtems_device_driver |
---|
186 | console_open(rtems_device_major_number major, |
---|
187 | rtems_device_minor_number minor, |
---|
188 | void *arg) |
---|
189 | { |
---|
190 | rtems_status_code status; |
---|
191 | static rtems_termios_callbacks cb = |
---|
192 | { |
---|
193 | console_first_open, /* firstOpen */ |
---|
194 | console_last_close, /* lastClose */ |
---|
195 | gba_pollRead, /* pollRead */ |
---|
196 | gba_write, /* write */ |
---|
197 | gba_setAttributes, /* setAttributes */ |
---|
198 | NULL, /* stopRemoteTx */ |
---|
199 | NULL, /* startRemoteTx */ |
---|
200 | TERMIOS_POLLED /* 1 = outputUsesInterrupts */ |
---|
201 | }; |
---|
202 | |
---|
203 | status = rtems_termios_open (major, minor, arg, &cb); |
---|
204 | |
---|
205 | if (status != RTEMS_SUCCESSFUL) { |
---|
206 | printk("Error openning console device\n"); |
---|
207 | return status; |
---|
208 | } |
---|
209 | |
---|
210 | return RTEMS_SUCCESSFUL; |
---|
211 | } |
---|
212 | |
---|
213 | /** |
---|
214 | * @brief Console device driver CLOSE entry point |
---|
215 | * |
---|
216 | * @param major diver major number |
---|
217 | * @param minor driver minor mumber |
---|
218 | * @param *arg pointer to parameters |
---|
219 | * @return status code |
---|
220 | */ |
---|
221 | rtems_device_driver |
---|
222 | console_close(rtems_device_major_number major, |
---|
223 | rtems_device_minor_number minor, |
---|
224 | void *arg) |
---|
225 | { |
---|
226 | rtems_device_driver res = RTEMS_SUCCESSFUL; |
---|
227 | |
---|
228 | res = rtems_termios_close (arg); |
---|
229 | |
---|
230 | return res; |
---|
231 | } |
---|
232 | |
---|
233 | /** |
---|
234 | * @brief Console device driver READ entry point. |
---|
235 | * |
---|
236 | * Read characters from the I/O console. |
---|
237 | * |
---|
238 | * @param major diver major number |
---|
239 | * @param minor driver minor mumber |
---|
240 | * @param *arg pointer to parameters |
---|
241 | * @return status code |
---|
242 | */ |
---|
243 | rtems_device_driver |
---|
244 | console_read(rtems_device_major_number major, |
---|
245 | rtems_device_minor_number minor, |
---|
246 | void *arg) |
---|
247 | { |
---|
248 | |
---|
249 | return rtems_termios_read (arg); |
---|
250 | |
---|
251 | } |
---|
252 | |
---|
253 | /** |
---|
254 | * @brief Console device driver WRITE entry point. |
---|
255 | * |
---|
256 | * Write characters to the I/O console. |
---|
257 | * |
---|
258 | * @param major diver major number |
---|
259 | * @param minor driver minor mumber |
---|
260 | * @param *arg pointer to parameters |
---|
261 | * @return status code |
---|
262 | */ |
---|
263 | rtems_device_driver |
---|
264 | console_write(rtems_device_major_number major, |
---|
265 | rtems_device_minor_number minor, |
---|
266 | void *arg) |
---|
267 | { |
---|
268 | return rtems_termios_write (arg); |
---|
269 | } |
---|
270 | |
---|
271 | /** |
---|
272 | * @brief Handle ioctl request. |
---|
273 | * |
---|
274 | * @param major diver major number |
---|
275 | * @param minor driver minor mumber |
---|
276 | * @param *arg pointer to parameters |
---|
277 | * @return status code |
---|
278 | */ |
---|
279 | rtems_device_driver |
---|
280 | console_control(rtems_device_major_number major, |
---|
281 | rtems_device_minor_number minor, |
---|
282 | void *arg |
---|
283 | ) |
---|
284 | { |
---|
285 | return rtems_termios_ioctl (arg); |
---|
286 | } |
---|