source: rtems/c/src/lib/libbsp/arm/gba/console/console.c @ 6789d70

4.104.115
Last change on this file since 6789d70 was 6789d70, checked in by Ralf Corsepius <ralf.corsepius@…>, on 12/07/09 at 16:21:07

2009-12-07 Ralf Corsépius <ralf.corsepius@…>

  • console/conio.c, console/console.c, include/conio.h: Let *getch return "int". Remove casts.
  • Property mode set to 100644
File size: 5.8 KB
Line 
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 <unistd.h>
21
22#include <bsp.h>
23#include <rtems/bspIo.h>
24#include <rtems/libio.h>
25#include <rtems/termiostypes.h>
26#include <termios.h>
27#include <irq.h>
28#include <gba.h>
29#include <conio.h>
30
31/**
32 *  @brief gba_pollRead function read char
33 *
34 *  @param  minor unused
35 *  @return character code
36 */
37static int gba_pollRead(int minor)
38{
39    return(gba_getch());
40}
41
42/**
43 *  @brief gba_write function writes chars
44 *
45 *  Input parameters:   minor code, buffer pointer and lenght
46 *  @param  minor unused
47 *  @param  *buf buffer pointer
48 *  @param  len lenght of buffer
49 *  @return character code
50 *
51 */
52static int gba_write(int minor, const char *buf, int len)
53{
54  int i;
55
56  for (i=0;i<len;i++) {
57     gba_putch((unsigned short)buf[i]);
58  }
59  return len;
60}
61
62/**
63 *  @brief gba_setAttributes function is empty
64 *
65 *  @param  minor unused
66 *  @param  *t unused
67 *  @return constant 0
68 */
69static int gba_setAttributes(int minor, const struct termios *t)
70{
71  return 0;
72}
73
74/** BSP_output_char for printk support */
75BSP_output_char_function_type     BSP_output_char = (BSP_output_char_function_type)     gba_putch;
76/** BSP_poll_char for printk support */
77BSP_polling_getchar_function_type BSP_poll_char   = gba_getch;
78
79/**
80 *  @brief Console device driver INITIALIZE entry point
81 *
82 *  Initilizes the I/O console driver.
83 *
84 *  @param  major diver major number
85 *  @param  minor driver minor mumber
86 *  @param  *arg pointer to parameters
87 *  @return status code
88 */
89rtems_device_driver
90console_initialize(rtems_device_major_number  major,
91                   rtems_device_minor_number  minor,
92                   void                      *arg)
93{
94  rtems_status_code status;
95
96  /* Set up TERMIOS */
97  rtems_termios_initialize ();
98
99  /* Do device-specific initialization  */
100  /* Allready done in bspstart.c -> gba_textmode(CO60); */
101
102  /* Register the device */
103  status = rtems_io_register_name ("/dev/console", major, 0);
104  if (status != RTEMS_SUCCESSFUL) {
105      printk("Error registering console device!\n");
106      rtems_fatal_error_occurred (status);
107  }
108
109  printk("Initialized GBA console\n\n");
110
111  return RTEMS_SUCCESSFUL;
112}
113
114/**
115 *  @brief console_first_open function is empty
116 *
117 *  @param  major diver major number
118 *  @param  minor driver minor mumber
119 *  @param  *arg pointer to parameters
120 *  @return status code
121 */
122static int console_first_open(int major, int minor, void *arg)
123{
124    return 0;
125}
126
127/**
128 *  @brief console_last_close function is empty
129 *
130 *  @param  major diver major number
131 *  @param  minor driver minor mumber
132 *  @param  *arg pointer to parameters
133 *  @return status code
134 */
135static int console_last_close(int major, int minor, void *arg)
136{
137    return 0;
138}
139
140
141/**
142 *  @brief Console device driver OPEN entry point
143 *
144 *  @param  major diver major number
145 *  @param  minor driver minor mumber
146 *  @param  *arg pointer to parameters
147 *  @return status code
148 */
149rtems_device_driver
150console_open(rtems_device_major_number major,
151             rtems_device_minor_number minor,
152             void                      *arg)
153{
154  rtems_status_code              status;
155  static rtems_termios_callbacks cb =
156  {
157    console_first_open,         /* firstOpen     */
158    console_last_close,         /* lastClose     */
159    gba_pollRead,               /* pollRead      */
160    gba_write,                  /* write         */
161    gba_setAttributes,          /* setAttributes */
162    NULL,                       /* stopRemoteTx  */
163    NULL,                       /* startRemoteTx */
164    TERMIOS_POLLED              /* 1 = outputUsesInterrupts */
165  };
166
167  status = rtems_termios_open (major, minor, arg, &cb);
168
169  if (status != RTEMS_SUCCESSFUL) {
170      printk("Error openning console device\n");
171      return status;
172  }
173
174  return RTEMS_SUCCESSFUL;
175}
176
177/**
178 *  @brief Console device driver CLOSE 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 */
185rtems_device_driver
186console_close(rtems_device_major_number major,
187              rtems_device_minor_number minor,
188              void                      *arg)
189{
190  rtems_device_driver res = RTEMS_SUCCESSFUL;
191
192  res =  rtems_termios_close (arg);
193
194  return res;
195}
196
197/**
198 *  @brief Console device driver READ entry point.
199 *
200 *  Read characters from the I/O console.
201 *
202 *  @param  major diver major number
203 *  @param  minor driver minor mumber
204 *  @param  *arg pointer to parameters
205 *  @return status code
206 */
207rtems_device_driver
208console_read(rtems_device_major_number major,
209             rtems_device_minor_number minor,
210             void                      *arg)
211{
212
213    return rtems_termios_read (arg);
214
215}
216
217/**
218 *  @brief Console device driver WRITE entry point.
219 *
220 *  Write characters to the I/O console.
221 *
222 *  @param  major diver major number
223 *  @param  minor driver minor mumber
224 *  @param  *arg pointer to parameters
225 *  @return status code
226*/
227rtems_device_driver
228console_write(rtems_device_major_number major,
229              rtems_device_minor_number minor,
230              void                      *arg)
231{
232    return rtems_termios_write (arg);
233}
234
235/**
236 *  @brief Handle ioctl request.
237 *
238 *  @param  major diver major number
239 *  @param  minor driver minor mumber
240 *  @param  *arg pointer to parameters
241 *  @return status code
242 */
243rtems_device_driver
244console_control(rtems_device_major_number major,
245                rtems_device_minor_number minor,
246                void                      *arg
247)
248{
249    return rtems_termios_ioctl (arg);
250}
Note: See TracBrowser for help on using the repository browser.