source: rtems/c/src/lib/libbsp/powerpc/dmv177/console/duart.c @ c932d85

4.104.114.84.95
Last change on this file since c932d85 was c932d85, checked in by Joel Sherrill <joel.sherrill@…>, on May 30, 1998 at 10:09:14 AM

New files -- from rtems-LM-980406 which was based on an RTEMS from 12/97.
This was called the dmv170 BSP in that source tree but since the DMV171
is now obsolete, we have transitioned to the DMV177 and have no intention
of checking compatibility with any other models.

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 *  duart.c
3 *
4 *  This code is a modified version of what you will find at the
5 *  end of the IDP User's manual.  The original code is copyrighted
6 *  by Motorola and Motorola Semiconductor Products as well as
7 *  Motorola Software products group.
8 * 
9 *  Modifications to the original IDP code by Doug McBride, Colorado
10 *  Space Grant College.  Modifications include a means of accessing
11 *  port B of the duart as well as port A as well as modifications for
12 *  buffering and RTEMS support.  Modifications are provided
13 *  as is and may not be correct.
14 * 
15 *  Rob Savoye provided the format for the mc68681 header file
16 * 
17 *  Joel Sherrill provided inspiration for recoding my original assembly
18 *  for this file into C (a good idea)
19 * 
20 *  COPYRIGHT (c) 1989-1998.
21 *  On-Line Applications Research Corporation (OAR).
22 *  Copyright assigned to U.S. Government, 1994.
23 *
24 *  The license and distribution terms for this file may be
25 *  found in the file LICENSE in this distribution or at
26 *  http://www.OARcorp.com/rtems/license.html.
27 *
28 *  $Id: duart.c
29 */
30
31#define MC68681_OFFSET_MULTIPLIER 8
32#include <motorola/mc68681.h>
33#include <bsp.h>
34#include <ringbuf.h>
35         
36rtems_isr console_isr (rtems_vector_number vector);
37
38Ring_buffer_t TX_Buffer[2];
39Ring_buffer_t RX_Buffer[2];
40
41/*  PAGE
42 *
43 *  init_mc88681
44 *
45 *  volatile routine to initialize duart
46 *
47 *  Input parameters: NONE
48 *
49 *  Output parameters: NONE
50 *
51 *  Return Values:     NONE 
52 */
53
54volatile void init_mc88681()
55{
56  /*
57   *  Initialize Ring buffers
58   */
59  Ring_buffer_Initialize( &RX_Buffer[ 0 ] );
60  Ring_buffer_Initialize( &RX_Buffer[ 1 ] );
61
62  Ring_buffer_Initialize( &TX_Buffer[ 0 ] );
63  Ring_buffer_Initialize( &TX_Buffer[ 1 ] );
64}
65
66/*  PAGE
67 *
68 *  console_isr
69 *
70 *  interrupt handler for receive of character from duart on ports A & B
71 *
72 *  Input parameters: NONE
73 *
74 *  Output parameters: NONE
75 *
76 *  Return Values:     NONE 
77 */
78
79rtems_isr console_isr (rtems_vector_number vector)
80{
81
82   /*
83    *  Fill me in later ...
84    */
85
86}
87
88
89/*  PAGE
90 *
91 *  console_outbyte_polled
92 *
93 *  This routine transmits a character out.
94 *
95 *  Input parameters:
96 *    port - port to transmit character to
97 *    ch  - character to be transmitted
98 *
99 *  Output parameters:  NONE
100 *
101 *  Return values: NONE
102 */
103
104void console_outbyte_polled(
105  int port,
106  char ch
107)
108{
109  unsigned char status;
110  unsigned char data;
111  unsigned char t = 0;
112
113  if (port == MC68681_PORT_A) { 
114    status = MC68681_STATUS_REG_A;
115    data = MC68681_TRANSMIT_BUFFER_A;
116  } else {
117    status = MC68681_STATUS_REG_B;
118    data = MC68681_TRANSMIT_BUFFER_B;
119  }
120
121  while ( !(MC68681_READ(DUART_ADDR, status) & MC68681_TX_READY) ){
122    if (t == 0) {
123      Debug_Entry( 0x8000 );
124      t++;
125    }
126  }
127 
128  Debug_Entry( 0x9000 );
129  MC68681_WRITE(DUART_ADDR, data, ch);
130}
131
132
133/*  PAGE
134 *
135 *  console_inbyte_polled
136 *
137 *  This routine reads a character from the UART.
138 *
139 *  Input parameters:
140 *    port - port to read character from
141 *
142 *  Output parameters:  NONE
143 *
144 *  Return values:
145 *    character read from UART
146 */
147
148#define MC68681_RECEIVE_ERRORS \
149      (MC68681_OVERRUN_ERROR | MC68681_PARITY_ERROR | MC68681_FRAMING_ERROR)
150
151char console_inbyte_polled( int port )
152{
153  char status;
154  char data;
155  char cmd;
156  unsigned char status_info;
157
158  /* 
159   * Set Port A or B unique variables.         
160   */
161  if (port == MC68681_PORT_A)  {
162    status = MC68681_STATUS_REG_A;
163    data   = MC68681_RECEIVE_BUFFER_A;
164    cmd    = MC68681_COMMAND_REG_A;
165  } else {
166    status = MC68681_STATUS_REG_B;
167    data   = MC68681_RECEIVE_BUFFER_B;
168    cmd    = MC68681_COMMAND_REG_B;
169  }
170
171  /* Wait for the Ready bit and Clear any errors */
172  for ( ; ; ) {
173    status_info = MC68681_READ(DUART_ADDR, status);
174    if ( status_info & MC68681_RX_READY )
175      break;
176
177     if ( status_info & MC68681_RECEIVE_ERRORS )
178         MC68681_WRITE( DUART_ADDR, cmd, MC68681_MODE_REG_RESET_ERROR );
179  }
180
181  return MC68681_READ(DUART_ADDR, data);
182}
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
Note: See TracBrowser for help on using the repository browser.