source: rtems/c/src/lib/libbsp/arm/nds/console/console.c @ af3fd0c6

4.104.115
Last change on this file since af3fd0c6 was af3fd0c6, checked in by Joel Sherrill <joel.sherrill@…>, on 04/26/10 at 02:28:02

2010-04-25 Joel Sherrill <joel.sherrilL@…>

  • console/console.c: Fix warnings.
  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 * RTEMS for Nintendo DS console driver.
3 *
4 * Copyright (c) 2008 by Renaud Voltz <renaud.voltz@gmail.com>
5 *                       Matthieu Bucchianeri <mbucchia@gmail.com>
6 *
7 * The license and distribution terms for this file may be
8 * found in the file LICENSE in this distribution or at
9 *
10 * http://www.rtems.com/license/LICENSE
11 *
12 * $Id$
13 */
14
15#include <bsp.h>
16#include <nds.h>
17#include <rtems/libio.h>
18#include <nds/arm9/console.h>
19#include <sys/iosupport.h>
20
21#include <rtems/mw_uid.h>
22
23/*
24 * enables testsuite output to desmume. this is used to pass the rtems
25 * testsuite.
26 * comment the following line to disable (recommended).
27 */
28
29//#define TESTSUITE
30
31/*
32 * printk support.
33 */
34
35/* from NDS support library */
36extern void consolePrintChar(char c);
37void
38nds_putch (char c)
39{
40#ifdef TESTSUITE
41  asm volatile ("swi $0x1");
42#endif
43  consolePrintChar (c);
44}
45
46static volatile char ch = 0;
47
48void
49console_push (char c)
50{
51  ch = c;
52}
53
54int
55nds_getch (void)
56{
57  char c;
58
59  while (ch == 0);
60  c = ch;
61  ch = 0;
62  return c;
63}
64
65BSP_output_char_function_type BSP_output_char = nds_putch;
66BSP_polling_getchar_function_type BSP_poll_char = nds_getch;
67
68/*
69 * console write operation.
70 */
71
72static ssize_t
73nds_write (int minor, const char *buf, size_t len)
74{
75  int count;
76
77  for (count = 0; count < len; count++) {
78    nds_putch (buf[count]);
79  }
80
81  return 0;
82}
83
84/*
85 * console read operation.
86 */
87
88static int
89nds_read (int minor)
90{
91  return nds_getch ();
92}
93
94/*
95 * from touchscreen/parser.c
96 */
97
98void register_kbd_msg_queue (char *q_name);
99void unregister_kbd_msg_queue (void);
100
101/*
102 * Console driver
103 */
104
105rtems_device_driver
106console_initialize (rtems_device_major_number major,
107                    rtems_device_minor_number minor, void *arg)
108{
109  rtems_status_code status;
110
111  printk ("[+] console started\n");
112
113  rtems_termios_initialize ();
114
115  status = rtems_io_register_name ("/dev/console", major, 0);
116  if (status != RTEMS_SUCCESSFUL) {
117    printk ("[!] error registering console\n");
118    rtems_fatal_error_occurred (status);
119  }
120
121  return (RTEMS_SUCCESSFUL);
122}
123
124rtems_device_driver
125console_open (rtems_device_major_number major,
126              rtems_device_minor_number minor, void *arg)
127{
128  rtems_status_code status;
129  static rtems_termios_callbacks cb = {
130    NULL,                       /* firstOpen     */
131    NULL,                       /* lastClose     */
132    nds_read,                   /* pollRead      */
133    nds_write,                  /* write         */
134    NULL,                       /* setAttributes */
135    NULL,                       /* stopRemoteTx  */
136    NULL,                       /* startRemoteTx */
137    0                           /* 1 = outputUsesInterrupts */
138  };
139
140  status = rtems_termios_open (major, minor, arg, &cb);
141  if (status != RTEMS_SUCCESSFUL)
142    printk ("[!] error opening console\n");
143
144  return (status);
145}
146
147rtems_device_driver
148console_close (rtems_device_major_number major,
149               rtems_device_minor_number minor, void *arg)
150{
151  rtems_device_driver res = RTEMS_SUCCESSFUL;
152
153  res = rtems_termios_close (arg);
154
155  return res;
156}
157
158rtems_device_driver
159console_read (rtems_device_major_number major,
160              rtems_device_minor_number minor, void *arg)
161{
162  return rtems_termios_read (arg);
163}
164
165rtems_device_driver
166console_write (rtems_device_major_number major,
167               rtems_device_minor_number minor, void *arg)
168{
169  return rtems_termios_write (arg);
170}
171
172rtems_device_driver
173console_control (rtems_device_major_number major,
174                 rtems_device_minor_number minor, void *arg)
175{
176  rtems_libio_ioctl_args_t *args = arg;
177
178  switch (args->command) {
179  case MW_UID_REGISTER_DEVICE:
180    register_kbd_msg_queue (args->buffer);
181    break;
182  case MW_UID_UNREGISTER_DEVICE:
183    unregister_kbd_msg_queue ();
184    break;
185  default:
186    return rtems_termios_ioctl (arg);
187  }
188  args->ioctl_return = 0;
189
190  return RTEMS_SUCCESSFUL;
191}
Note: See TracBrowser for help on using the repository browser.