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

4.104.114.95
Last change on this file since 06d9c0e was 06d9c0e, checked in by Joel Sherrill <joel.sherrill@…>, on 02/15/08 at 18:54:35

2008-02-15 Joel Sherrill <joel.sherrill@…>

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