source: rtems/c/src/lib/libbsp/m68k/gen68302/console/console.c @ d6284ab

4.104.114.84.9
Last change on this file since d6284ab was d6284ab, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2003 at 6:51:48 PM

2003-09-04 Joel Sherrill <joel@…>

  • clock/ckinit.c, console/console.c, include/bsp.h, include/coverhd.h, start/start.S, startup/bspclean.c, startup/bspstart.c, startup/linkcmds, timer/timer.c: URL for license changed.
  • Property mode set to 100644
File size: 6.8 KB
Line 
1/*
2 * Initialize the MC68302 SCC2 for console IO board support package.
3 *
4 *  COPYRIGHT (c) 1989-1999.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#define GEN68302_INIT
15
16#include <bsp.h>
17#include <rtems/libio.h>
18
19#include "m68302.h"
20
21/*  console_initialize
22 *
23 *  This routine initializes the console IO driver.
24 *
25 *  Input parameters: NONE
26 *
27 *  Output parameters:  NONE
28 *
29 *  Return values:
30 */
31
32rtems_device_driver console_initialize(
33  rtems_device_major_number  major,
34  rtems_device_minor_number  minor,
35  void                      *arg
36)
37{
38  rtems_status_code status;
39  volatile m302_dualPortRAM_t *p = &m302;
40
41  p->reg.pacnt |= 0x0003;               /* enable RXD2 and TXD2 signals */
42  /*
43   * TODO: Check assembly code.  I think gcc's volatile semantics force
44   * this to not use a CLR.
45   */
46  p->reg.simode = 0;                    /* NMSI mode */
47
48  p->reg.scc[1].scon = 0x00d8;          /* 9600 baud */
49  p->reg.scc[1].scm  = 0x01b1;
50
51  p->scc2.parm.rfcr = 0x50;             /* Rx buffers in supervisor data */
52  p->scc2.parm.tfcr = 0x50;             /* Tx buffers in supervisor data */
53  p->scc2.parm.mrblr = 0x0001;          /* Max Rx buffer length is 1 byte */
54
55  p->scc2.prot.uart.max_idl = 0x0000;   /* 0 = maximum timeout value */
56  p->scc2.prot.uart.brkcr = 0x0001;     /* send 1 break char on STOP TX cmd */
57  p->scc2.prot.uart.parec = 0x0000;     /* reset parity error counter */
58  p->scc2.prot.uart.frmec = 0x0000;     /* reset framing error counter */
59  p->scc2.prot.uart.nosec = 0x0000;     /* reset noise error counter */
60  p->scc2.prot.uart.brkec = 0x0000;     /* reset break condition counter */
61
62  p->scc2.prot.uart.character[0] = 0x0003; /* use <ctrl>c as control char */
63  p->scc2.prot.uart.character[1] = 0x8000; /* set end of cntrl char table */
64
65  p->scc2.bd.rx[0].status = 0xA000;     /* RxBD0 empty, wrap, no intr */
66  p->scc2.bd.rx[0].length = 0x0000;
67  p->scc2.bd.rx[0].buffer =
68      (rtems_unsigned8 *) &m302.scc2.bd.rx[1]; /* RxBD1 is Rx buffer */
69
70  p->reg.scc[1].dsr = 0x7000;           /* set full-length last stop bit */
71
72  p->scc2.bd.tx[0].status = 0x3000;     /* TxBD0 not ready, wrap, intr */
73  p->scc2.bd.tx[0].length = 0x0001;
74  p->scc2.bd.tx[0].buffer =
75      (rtems_unsigned8 *) &m302.scc2.bd.tx[1]; /* TxBD1 is Tx buffer */
76
77  p->reg.scc[1].scce = 0xFF;            /* clear all SCC event flags */
78  p->reg.scc[1].sccm = 0x03;            /* enable only Tx & Rx interrupts */
79  p->reg.scc[1].scm  = 0x01BD;
80
81  status = rtems_io_register_name(
82    "/dev/console",
83    major,
84    (rtems_device_minor_number) 0
85  );
86 
87  if (status != RTEMS_SUCCESSFUL)
88    rtems_fatal_error_occurred(status);
89 
90  return RTEMS_SUCCESSFUL;
91
92}
93
94/*  is_character_ready
95 *
96 *  Check to see if a character is available on the MC68302's SCC2.  If so,
97 *  then return a TRUE (along with the character).  Otherwise return FALSE.
98 *
99 *  Input parameters:   pointer to location in which to return character
100 *
101 *  Output parameters:  character (if available)
102 *
103 *  Return values:      TRUE - character available
104 *                      FALSE - no character available
105 */
106
107rtems_boolean is_character_ready(
108  char *ch                              /* -> character  */
109)
110{
111#define RXS (m302.scc2.bd.rx[0].status)
112#define RXD (* ((volatile char *) m302.scc2.bd.rx[0].buffer))
113
114    for (;;) {
115        if (RXS & RBIT_HDLC_EMPTY_BIT)
116            return FALSE;
117
118        *ch = RXD;
119        RXS = RBIT_HDLC_EMPTY_BIT | RBIT_HDLC_WRAP_BIT;
120        if ( *ch >= ' ' &&  *ch <= '~' )
121            return TRUE;
122    }
123}
124
125
126/*  inbyte
127 *
128 *  Receive a character from the MC68302's SCC2.
129 *
130 *  Input parameters:   NONE
131 *
132 *  Output parameters:  NONE
133 *
134 *  Return values:      character read
135 */
136
137char inbyte( void )
138{
139    char ch;
140
141#define RXS (m302.scc2.bd.rx[0].status)
142#define RXD (* ((volatile char *) m302.scc2.bd.rx[0].buffer))
143
144    do {
145        while (RXS & RBIT_HDLC_EMPTY_BIT)
146            /* Wait until character received */ ;
147
148        ch = RXD;
149        RXS = RBIT_HDLC_EMPTY_BIT | RBIT_HDLC_WRAP_BIT;
150
151        if (ch == '\r' || ch == '\n')
152            break;
153    } while (ch < ' ' ||  ch > '~');
154
155    return ch;
156}
157
158
159/*  outbyte
160 *
161 *  Transmit a character out on the MC68302's SCC2.
162 *  It may support XON/XOFF flow control.
163 *
164 *  Input parameters:
165 *    ch  - character to be transmitted
166 *
167 *  Output parameters:  NONE
168 */
169
170void outbyte(
171  char ch
172)
173{
174#define TXS (m302.scc2.bd.tx[0].status)
175#define TXD (* ((volatile char *) m302.scc2.bd.tx[0].buffer))
176
177#define RXS (m302.scc2.bd.rx[0].status)
178#define RXD (* ((volatile char *) m302.scc2.bd.rx[0].buffer))
179
180    while (TXS & RBIT_HDLC_READY_BIT)
181        /* Wait until okay to transmit */ ;
182
183    /*
184     * Check for flow control requests and process.
185     */
186    while ( ! (RXS & RBIT_HDLC_EMPTY_BIT)) {
187        if (RXD == XOFF)
188            do {
189                RXS = RBIT_HDLC_EMPTY_BIT | RBIT_HDLC_WRAP_BIT;
190                while (RXS & RBIT_HDLC_EMPTY_BIT)
191                    /* Wait until character received */ ;
192            } while (RXD != XON);
193        RXS = RBIT_HDLC_EMPTY_BIT | RBIT_HDLC_WRAP_BIT;
194    }
195
196    TXD = ch;
197    TXS = RBIT_HDLC_READY_BIT | RBIT_HDLC_WRAP_BIT;
198    if (ch == '\n')
199        outbyte('\r');
200}
201
202/*
203 *  Open entry point
204 */
205
206rtems_device_driver console_open(
207  rtems_device_major_number major,
208  rtems_device_minor_number minor,
209  void                    * arg
210)
211{
212  return RTEMS_SUCCESSFUL;
213}
214 
215/*
216 *  Close entry point
217 */
218
219rtems_device_driver console_close(
220  rtems_device_major_number major,
221  rtems_device_minor_number minor,
222  void                    * arg
223)
224{
225  return RTEMS_SUCCESSFUL;
226}
227
228/*
229 * read bytes from the serial port. We only have stdin.
230 */
231
232rtems_device_driver console_read(
233  rtems_device_major_number major,
234  rtems_device_minor_number minor,
235  void                    * arg
236)
237{
238  rtems_libio_rw_args_t *rw_args;
239  char *buffer;
240  int maximum;
241  int count = 0;
242 
243  rw_args = (rtems_libio_rw_args_t *) arg;
244
245  buffer = rw_args->buffer;
246  maximum = rw_args->count;
247
248  for (count = 0; count < maximum; count++) {
249    buffer[ count ] = inbyte();
250    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
251      buffer[ count++ ]  = '\n';
252      break;
253    }
254  }
255
256  rw_args->bytes_moved = count;
257  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
258}
259
260/*
261 * write bytes to the serial port. Stdout and stderr are the same.
262 */
263
264rtems_device_driver console_write(
265  rtems_device_major_number major,
266  rtems_device_minor_number minor,
267  void                    * arg
268)
269{
270  int count;
271  int maximum;
272  rtems_libio_rw_args_t *rw_args;
273  char *buffer;
274
275  rw_args = (rtems_libio_rw_args_t *) arg;
276
277  buffer = rw_args->buffer;
278  maximum = rw_args->count;
279
280  for (count = 0; count < maximum; count++) {
281    if ( buffer[ count ] == '\n') {
282      outbyte('\r');
283    }
284    outbyte( buffer[ count ] );
285  }
286
287  rw_args->bytes_moved = maximum;
288  return 0;
289}
290
291/*
292 *  IO Control entry point
293 */
294
295rtems_device_driver console_control(
296  rtems_device_major_number major,
297  rtems_device_minor_number minor,
298  void                    * arg
299)
300{
301  return RTEMS_SUCCESSFUL;
302}
Note: See TracBrowser for help on using the repository browser.