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

4.115
Last change on this file since ff8922c was ff8922c, checked in by Joel Sherrill <joel.sherrill@…>, on 10/12/14 at 20:22:27

arm/gba/console: Fix warnings and clean up

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