source: rtems/c/src/lib/libbsp/m68k/gen68360/console/console.c @ e2d79559

4.104.114.84.95
Last change on this file since e2d79559 was e2d79559, checked in by Joel Sherrill <joel.sherrill@…>, on 04/09/97 at 14:05:50

Added ka9q tcpip stack and network driver for the gen68360. This effort
was done based on the 3.6.0 release and had to be autoconf'ed locally.
It is turned on is the bsp enables it and it is not explicitly disabled
via the configure option --disable-tcpip. As many warnings as possible
were removed locally after the code was merged. Only the gen68360
and mvme136 bsps were compiled this way.

The ka9q port and network driver were submitted by Eric Norum
(eric@…).

The network demo programs are not included in the tree at this point.

  • Property mode set to 100644
File size: 6.3 KB
Line 
1/*
2 * Initialize SMC1 for console IO.
3 *
4 * Based on the `gen68302' board support package, and covered by the
5 * original distribution terms.
6 *
7 * W. Eric Norum
8 * Saskatchewan Accelerator Laboratory
9 * University of Saskatchewan
10 * Saskatoon, Saskatchewan, CANADA
11 * eric@skatter.usask.ca
12 *
13 *  $Id$
14 */
15
16/*
17 *
18 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
19 *  On-Line Applications Research Corporation (OAR).
20 *  All rights assigned to U.S. Government, 1994.
21 *
22 *  This material may be reproduced by or for the U.S. Government pursuant
23 *  to the copyright license under the clause at DFARS 252.227-7013.  This
24 *  notice must appear in all copies of this file and its derivatives.
25 */
26
27#define GEN68360_INIT
28
29#include <bsp.h>
30#include <rtems/libio.h>
31#include "m68360.h"
32
33/*  console_initialize
34 *
35 *  This routine initializes the console IO driver.
36 *
37 *  Input parameters: NONE
38 *
39 *  Output parameters:  NONE
40 *
41 *  Return values:
42 */
43
44/*
45 * I/O buffers can be in ordindary RAM
46 */
47static volatile char rxBuf, txBuf;
48static volatile m360BufferDescriptor_t *consoleRxBd, *consoleTxBd;
49
50rtems_device_driver console_initialize(
51  rtems_device_major_number  major,
52  rtems_device_minor_number  minor,
53  void                      *arg
54)
55{
56        rtems_status_code status;
57
58        /*
59         * Allocate buffer descriptors
60         */
61        consoleRxBd = M360AllocateBufferDescriptors (1);
62        consoleTxBd = M360AllocateBufferDescriptors (1);
63
64        /*
65         * Configure port B pins to enable SMTXD1 and SMRXD1 pins
66         */
67        m360.pbpar |=  0xC0;
68        m360.pbdir &= ~0xC0;
69        m360.pbodr &= ~0xC0;
70
71        /*
72         * Set up BRG1 (9,600 baud)
73         */
74        m360.brgc1 = M360_BRG_RST;
75        m360.brgc1 = M360_BRG_EN | M360_BRG_EXTC_BRGCLK | M360_BRG_9600;
76
77        /*
78         * Put SMC1 in NMSI mode, connect SMC1 to BRG1
79         */
80        m360.simode |= M360_SI_SMC1_BRG1;
81         
82        /*
83         * Set up SMC1 parameter RAM common to all protocols
84         */
85        m360.smc1p.rbase = (char *)consoleRxBd - (char *)&m360;
86        m360.smc1p.tbase = (char *)consoleTxBd - (char *)&m360;
87        m360.smc1p.rfcr = M360_RFCR_MOT | M360_RFCR_DMA_SPACE;
88        m360.smc1p.tfcr = M360_TFCR_MOT | M360_TFCR_DMA_SPACE;
89        m360.smc1p.mrblr = 1;
90         
91        /*
92         * Set up SMC1 parameter RAM UART-specific parameters
93         */
94        m360.smc1p.un.uart.max_idl = 0;
95        m360.smc1p.un.uart.brklen = 0;
96        m360.smc1p.un.uart.brkec = 0;
97        m360.smc1p.un.uart.brkcr = 0;
98         
99        /*
100         * Set up the Receive Buffer Descriptor
101         */
102        consoleRxBd->status = M360_BD_EMPTY | M360_BD_WRAP;
103        consoleRxBd->length = 0;
104        consoleRxBd->buffer = &rxBuf;
105         
106        /*
107         * Setup the Transmit Buffer Descriptor
108         */
109        consoleTxBd->length = 1;
110        consoleTxBd->status = M360_BD_WRAP;
111        consoleTxBd->buffer = &txBuf;
112         
113        /*
114         * Set up SMC1 general and protocol-specific mode registers
115         */
116        m360.smc1.smce = ~0;    /* Clear any pending events */
117        m360.smc1.smcm = 0;     /* Mask all interrupt/event sources */
118        m360.smc1.smcmr = M360_SMCMR_CLEN(9) | M360_SMCMR_SM_UART;
119
120        /*
121         * Send "Init parameters" command
122         */
123        M360ExecuteRISC (M360_CR_OP_INIT_RX_TX | M360_CR_CHAN_SMC1);
124
125        /*
126         * Enable receiver and transmitter
127         */
128        m360.smc1.smcmr |= M360_SMCMR_TEN | M360_SMCMR_REN;
129
130        status = rtems_io_register_name(
131                                "/dev/console",
132                                    major,
133                                    (rtems_device_minor_number)0);
134        if (status != RTEMS_SUCCESSFUL)
135                rtems_fatal_error_occurred(status);
136        return RTEMS_SUCCESSFUL;
137}
138
139/*  is_character_ready
140 *
141 *  Check to see if a character is available on the console port.  If so,
142 *  then return a TRUE (along with the character).  Otherwise return FALSE.
143 *
144 *  Input parameters:   pointer to location in which to return character
145 *
146 *  Output parameters:  character (if available)
147 *
148 *  Return values:      TRUE - character available
149 *                      FALSE - no character available
150 */
151
152rtems_boolean is_character_ready(
153  char *ch                              /* -> character  */
154)
155{
156        if (consoleRxBd->status & M360_BD_EMPTY)
157                return FALSE;
158        *ch = rxBuf;
159        consoleRxBd->status = M360_BD_EMPTY | M360_BD_WRAP;
160        return TRUE;
161}
162
163
164/*  inbyte
165 *
166 *  Receive a character from the console port
167 *
168 *  Input parameters:   NONE
169 *
170 *  Output parameters:  NONE
171 *
172 *  Return values:      character read
173 */
174
175char inbyte( void )
176{
177    char ch;
178
179    while (is_character_ready (&ch) == FALSE)
180        continue;
181    return ch;
182}
183
184
185/*  outbyte
186 *
187 *  Transmit a character to the console serial port
188 *
189 *  Input parameters:
190 *    ch  - character to be transmitted
191 *
192 *  Output parameters:  NONE
193 */
194
195void outbyte(
196  char ch
197)
198{
199        if (ch == '\n')
200                outbyte('\r');
201        while (consoleTxBd->status & M360_BD_READY)
202                continue;
203        txBuf = ch;
204        consoleTxBd->status = M360_BD_READY | M360_BD_WRAP;
205}
206
207/*
208 *  Open entry point
209 */
210
211rtems_device_driver console_open(
212  rtems_device_major_number major,
213  rtems_device_minor_number minor,
214  void                    * arg
215)
216{
217  return RTEMS_SUCCESSFUL;
218}
219 
220/*
221 *  Close entry point
222 */
223
224rtems_device_driver console_close(
225  rtems_device_major_number major,
226  rtems_device_minor_number minor,
227  void                    * arg
228)
229{
230  return RTEMS_SUCCESSFUL;
231}
232
233/*
234 * read bytes from the serial port. We only have stdin.
235 */
236
237rtems_device_driver console_read(
238  rtems_device_major_number major,
239  rtems_device_minor_number minor,
240  void                    * arg
241)
242{
243  rtems_libio_rw_args_t *rw_args;
244  char *buffer;
245  int maximum;
246  int count = 0;
247 
248  rw_args = (rtems_libio_rw_args_t *) arg;
249
250  buffer = rw_args->buffer;
251  maximum = rw_args->count;
252
253  for (count = 0; count < maximum; count++) {
254    buffer[ count ] = inbyte();
255    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
256      buffer[ count++ ]  = '\n';
257      buffer[ count ]  = 0;
258      break;
259    }
260  }
261
262  rw_args->bytes_moved = count;
263  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
264}
265
266/*
267 * write bytes to the serial port. Stdout and stderr are the same.
268 */
269
270rtems_device_driver console_write(
271  rtems_device_major_number major,
272  rtems_device_minor_number minor,
273  void                    * arg
274)
275{
276  int count;
277  int maximum;
278  rtems_libio_rw_args_t *rw_args;
279  char *buffer;
280
281  rw_args = (rtems_libio_rw_args_t *) arg;
282
283  buffer = rw_args->buffer;
284  maximum = rw_args->count;
285
286  for (count = 0; count < maximum; count++) {
287    if ( buffer[ count ] == '\n') {
288      outbyte('\r');
289    }
290    outbyte( buffer[ count ] );
291  }
292
293  rw_args->bytes_moved = maximum;
294  return 0;
295}
296
297/*
298 *  IO Control entry point
299 */
300
301rtems_device_driver console_control(
302  rtems_device_major_number major,
303  rtems_device_minor_number minor,
304  void                    * arg
305)
306{
307  return RTEMS_SUCCESSFUL;
308}
Note: See TracBrowser for help on using the repository browser.