source: rtems/c/src/lib/libbsp/m68k/mcf5206elite/console/console.c @ e56c3546

4.104.114.84.95
Last change on this file since e56c3546 was e56c3546, checked in by Joel Sherrill <joel.sherrill@…>, on 10/26/01 at 19:30:11

2001-10-26 Victor V. Vengerov <vvv@…>

  • New BSP for MCF5206eLITE evaluation board BSP.
  • ChangeLog?, README, bsp_specs, configure.ac, console/console.c, console/.cvsignore, i2c/i2c.c, i2c/i2cdrv.c, i2c/.cvsignore, include/bsp.h, include/bspopts.h.in, include/coverhd.h, include/ds1307.h, include/i2c.h, include/i2cdrv.h, include/nvram.h, include/.cvsignore, nvram/nvram.c, nvram/.cvsignore, start/start.S, start/.cvsignore, startup/bspclean.c, startup/bspstart.c, startup/gdbinit, startup/init5206e.c, startup/linkcmds, startup/linkcmds.flash, startup/.cvsignore, times, tod/ds1307.c, tod/todcfg.c, tod/.cvsignore, tools/.cvsignore, tools/configure.ac, tools/runtest, tools/changes, wrapup/.cvsignore, .cvsignore: New files.
  • Property mode set to 100644
File size: 11.4 KB
Line 
1/*
2 * Console driver for Motorola MCF5206E UART modules
3 *
4 * Copyright (C) 2000 OKTET Ltd., St.-Petersburg, Russia
5 * Author: Victor V. Vengerov <vvv@oktet.ru>
6 *
7 *  COPYRIGHT (c) 1989-1998.
8 *  On-Line Applications Research Corporation (OAR).
9 *  Copyright assigned to U.S. Government, 1994.
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *
14 *  http://www.OARcorp.com/rtems/license.html.
15 *
16 *  $Id$
17 */
18
19#include <termios.h>
20#include <bsp.h>
21#include <rtems/libio.h>
22#include "mcf5206/mcf5206e.h"
23#include "mcf5206/mcfuart.h"
24
25
26/* Descriptor structures for two on-chip UART channels */
27static mcfuart uart[2];
28
29/* Console operations mode:
30 *     0 - raw (non-termios) polled input/output
31 *     1 - termios-based polled input/output
32 *     2 - termios-based interrupt-driven input/output
33 */
34int console_mode = 2;
35#define CONSOLE_MODE_RAW  (0)
36#define CONSOLE_MODE_POLL (1)
37#define CONSOLE_MODE_INT  (2)
38
39/* Wrapper functions for MCF UART generic driver */
40
41/* console_poll_read --
42 *     wrapper for poll read function
43 *
44 * PARAMETERS:
45 *     minor - minor device number
46 *
47 * RETURNS:
48 *     character code readed from UART, or -1 if there is no characters
49 *     available
50 */
51static int
52console_poll_read(int minor)
53{
54    return mcfuart_poll_read(&uart[minor]);
55}
56
57/* console_interrupt_write --
58 *     wrapper for interrupt write function
59 *
60 * PARAMETERS:
61 *     minor - minor device number
62 *     buf - output buffer
63 *     len - output buffer length
64 *
65 * RETURNS:
66 *     result code
67 */
68static int
69console_interrupt_write(int minor, const char *buf, int len)
70{
71    return mcfuart_interrupt_write(&uart[minor], buf, len);
72}
73
74/* console_poll_write --
75 *     wrapper for polling mode write function
76 *
77 * PARAMETERS:
78 *     minor - minor device number
79 *     buf - output buffer
80 *     len - output buffer length
81 *
82 * RETURNS:
83 *     result code
84 */
85static int
86console_poll_write(int minor, const char *buf, int len)
87{
88    return mcfuart_poll_write(&uart[minor], buf, len);
89}
90
91/* console_set_attributes --
92 *     wrapper for hardware-dependent termios attributes setting
93 *
94 * PARAMETERS:
95 *     minor - minor device number
96 *     t - pointer to the termios structure
97 *
98 * RETURNS:
99 *     result code
100 */
101static int
102console_set_attributes(int minor, const struct termios *t)
103{
104    return mcfuart_set_attributes(&uart[minor], t);
105}
106
107/* console_stop_remote_tx --
108 *     wrapper for stopping data flow from remote party.
109 *
110 * PARAMETERS:
111 *     minor - minor device number
112 *
113 * RETURNS:
114 *     result code
115 */
116static int
117console_stop_remote_tx(int minor)
118{
119    if (minor < sizeof(uart)/sizeof(uart[0]))
120        return mcfuart_stop_remote_tx(&uart[minor]);
121    else
122        return RTEMS_INVALID_NUMBER;
123}
124
125/* console_start_remote_tx --
126 *     wrapper for resuming data flow from remote party.
127 *
128 * PARAMETERS:
129 *     minor - minor device number
130 *
131 */
132static int
133console_start_remote_tx(int minor)
134{
135    if (minor < sizeof(uart)/sizeof(uart[0]))
136        return mcfuart_start_remote_tx(&uart[minor]);
137    else
138        return RTEMS_INVALID_NUMBER;
139}
140
141/* console_first_open --
142 *     wrapper for UART controller initialization functions
143 *
144 * PARAMETERS:
145 *     major - major device number
146 *     minor - minor device number
147 *     arg - libio device open argument
148 *
149 * RETURNS:
150 *     error code
151 */
152static int
153console_first_open(int major, int minor, void *arg)
154{
155    rtems_libio_open_close_args_t *args = arg;
156    rtems_status_code sc;
157    rtems_unsigned8 intvec;
158   
159    switch (minor)
160    {
161        case 0: intvec = BSP_INTVEC_UART1; break;
162        case 1: intvec = BSP_INTVEC_UART2; break;
163        default:
164            return RTEMS_INVALID_NUMBER;
165    }
166
167    if (console_mode != CONSOLE_MODE_INT)
168    {
169        intvec = 0;
170    }
171
172    sc = mcfuart_init(&uart[minor],          /* uart */
173                      args->iop->data1,      /* tty */
174                      intvec,                /* interrupt vector number */
175                      minor+1);
176
177    if (sc == RTEMS_SUCCESSFUL)
178        sc = mcfuart_reset(&uart[minor]);
179
180    return sc;
181}
182
183/* console_last_close --
184 *     wrapper for UART controller close function
185 *
186 * PARAMETERS:
187 *     major - major device number
188 *     minor - minor device number
189 *     arg - libio device close argument
190 *
191 * RETURNS:
192 *     error code
193 */
194static int
195console_last_close(int major, int minor, void *arg)
196{
197    return mcfuart_disable(&uart[minor]);
198}
199
200/* console_reserve_resources --
201 *     reserve termios resources for 2 UART channels
202 *
203 * PARAMETERS:
204 *     configuration -- pointer to the RTEMS configuration table
205 *
206 * RETURNS:
207 *     none
208 */
209void
210console_reserve_resources(rtems_configuration_table *configuration)
211{
212    if (console_mode != CONSOLE_MODE_RAW)
213        rtems_termios_reserve_resources (configuration, 2);
214}
215
216/* console_initialize --
217 *     This routine initializes the console IO drivers and register devices
218 *     in RTEMS I/O system.
219 *
220 * PARAMETERS:
221 *     major - major console device number
222 *     minor - minor console device number (not used)
223 *     arg - device initialize argument
224 *
225 * RETURNS:
226 *     RTEMS error code (RTEMS_SUCCESSFUL if device initialized successfuly)
227 */
228rtems_device_driver
229console_initialize(rtems_device_major_number major,
230                   rtems_device_minor_number minor,
231                   void *arg)
232{
233    rtems_status_code status;
234
235    /*
236     * Set up TERMIOS
237     */
238    if (console_mode != CONSOLE_MODE_RAW)
239        rtems_termios_initialize ();
240
241    /*
242     * Register the devices
243     */
244    status = rtems_io_register_name ("/dev/console", major, 0);
245    if (status != RTEMS_SUCCESSFUL)
246        rtems_fatal_error_occurred (status);
247    status = rtems_io_register_name ("/dev/aux", major, 1);
248    if (status != RTEMS_SUCCESSFUL)
249        rtems_fatal_error_occurred (status);
250
251    if (console_mode == CONSOLE_MODE_RAW)
252    {
253        rtems_status_code sc;
254        sc = mcfuart_init(&uart[0],              /* uart */
255                          NULL,                  /* tty */
256                          0,                     /* interrupt vector number */
257                          1);                    /* UART channel number */
258
259        if (sc == RTEMS_SUCCESSFUL)
260            sc = mcfuart_reset(&uart[0]);
261
262        sc = mcfuart_init(&uart[1],              /* uart */
263                          NULL,                  /* tty */
264                          0,                     /* interrupt vector number */
265                          2);                    /* UART channel number */
266
267        if (sc == RTEMS_SUCCESSFUL)
268            sc = mcfuart_reset(&uart[1]);
269        return sc;
270    }
271   
272    return RTEMS_SUCCESSFUL;
273}
274
275/* console_open --
276 *     Open console device driver. Pass appropriate termios callback
277 *     functions to termios library.
278 *
279 * PARAMETERS:
280 *     major - major device number for console devices
281 *     minor - minor device number for console
282 *     arg - device opening argument
283 *
284 * RETURNS:
285 *     RTEMS error code
286 */
287rtems_device_driver
288console_open(rtems_device_major_number major,
289             rtems_device_minor_number minor,
290             void *arg)
291{
292    static const rtems_termios_callbacks intr_callbacks = {
293        console_first_open,        /* firstOpen */
294        console_last_close,        /* lastClose */
295        NULL,                      /* pollRead */
296        console_interrupt_write,   /* write */
297        console_set_attributes,    /* setAttributes */
298        console_stop_remote_tx,    /* stopRemoteTx */
299        console_start_remote_tx,   /* startRemoteTx */
300        1                          /* outputUsesInterrupts */
301    };
302    static const rtems_termios_callbacks poll_callbacks = {
303        console_first_open,        /* firstOpen */
304        console_last_close,        /* lastClose */
305        console_poll_read,         /* pollRead */
306        console_poll_write,        /* write */
307        console_set_attributes,    /* setAttributes */
308        console_stop_remote_tx,    /* stopRemoteTx */
309        console_start_remote_tx,   /* startRemoteTx */
310        0                          /* outputUsesInterrupts */
311    };
312
313    switch (console_mode)
314    {
315        case CONSOLE_MODE_RAW:
316            return RTEMS_SUCCESSFUL;
317           
318        case CONSOLE_MODE_INT:
319            return rtems_termios_open(major, minor, arg, &intr_callbacks);
320           
321        case CONSOLE_MODE_POLL:
322            return rtems_termios_open(major, minor, arg, &poll_callbacks);
323
324        default:
325            rtems_fatal_error_occurred(0xC07A1310);
326    }
327    return RTEMS_INTERNAL_ERROR;
328}
329
330/* console_close --
331 *     Close console device.
332 *
333 * PARAMETERS:
334 *     major - major device number for console devices
335 *     minor - minor device number for console
336 *     arg - device close argument
337 *
338 * RETURNS:
339 *     RTEMS error code
340 */
341rtems_device_driver
342console_close(rtems_device_major_number major,
343              rtems_device_minor_number minor,
344              void *arg)
345{
346    if (console_mode != CONSOLE_MODE_RAW)
347        return rtems_termios_close (arg);
348    else
349        return RTEMS_SUCCESSFUL;
350}
351
352/* console_read --
353 *     Read from the console device
354 *
355 * PARAMETERS:
356 *     major - major device number for console devices
357 *     minor - minor device number for console
358 *     arg - device read argument
359 *
360 * RETURNS:
361 *     RTEMS error code
362 */
363rtems_device_driver
364console_read(rtems_device_major_number major,
365             rtems_device_minor_number minor,
366             void *arg)
367{
368    if (console_mode != CONSOLE_MODE_RAW)
369    {
370        return rtems_termios_read (arg);
371    }
372    else
373    {
374        rtems_libio_rw_args_t *argp = arg;
375        char *buf = argp->buffer;
376        int count = argp->count;
377        int n = 0;
378        int c;
379        while (n < count)
380        {
381            do {
382                c = mcfuart_poll_read(&uart[minor]);
383            } while (c == -1);
384            if (c == '\r')
385                c = '\n';
386            *(buf++) = c;
387            n++;
388            if (c == '\n')
389                break;
390        }
391        argp->bytes_moved = n;
392        return RTEMS_SUCCESSFUL;
393    }
394}
395
396/* console_write --
397 *     Write to the console device
398 *
399 * PARAMETERS:
400 *     major - major device number for console devices
401 *     minor - minor device number for console
402 *     arg - device write argument
403 *
404 * RETURNS:
405 *     RTEMS error code
406 */
407rtems_device_driver
408console_write(rtems_device_major_number major,
409              rtems_device_minor_number minor,
410              void *arg
411)
412{
413    if (console_mode != CONSOLE_MODE_RAW)
414    {
415        return rtems_termios_write (arg);
416    }
417    else
418    {
419        rtems_libio_rw_args_t *argp = arg;
420        char cr = '\r';
421        char *buf = argp->buffer;
422        int count = argp->count;
423        int i;
424        for (i = 0; i < count; i++)
425        {
426            if (*buf == '\n')
427                mcfuart_poll_write(&uart[minor], &cr, 1);
428            mcfuart_poll_write(&uart[minor], buf, 1);
429            buf++;
430        }
431        argp->bytes_moved = count;
432        return RTEMS_SUCCESSFUL;
433    }
434}
435
436/* console_control --
437 *     Handle console device I/O control (IOCTL)
438 *
439 * PARAMETERS:
440 *     major - major device number for console devices
441 *     minor - minor device number for console
442 *     arg - device ioctl argument
443 *
444 * RETURNS:
445 *     RTEMS error code
446 */
447rtems_device_driver
448console_control(rtems_device_major_number major,
449                rtems_device_minor_number minor,
450                void *arg)
451{
452    if (console_mode != CONSOLE_MODE_RAW)
453    {
454        return rtems_termios_ioctl (arg);
455    }
456    else
457    {
458        return RTEMS_SUCCESSFUL;
459    }
460}
Note: See TracBrowser for help on using the repository browser.