summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/powerpc/dmv177/console/duart.c
blob: e74ef7c37855d75cc8b9849598fb45901be68a29 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
 *  duart.c
 *
 *  This code is a modified version of what you will find at the
 *  end of the IDP User's manual.  The original code is copyrighted
 *  by Motorola and Motorola Semiconductor Products as well as
 *  Motorola Software products group.
 *  
 *  Modifications to the original IDP code by Doug McBride, Colorado
 *  Space Grant College.  Modifications include a means of accessing
 *  port B of the duart as well as port A as well as modifications for
 *  buffering and RTEMS support.  Modifications are provided
 *  as is and may not be correct.
 *  
 *  Rob Savoye provided the format for the mc68681 header file
 *  
 *  Joel Sherrill provided inspiration for recoding my original assembly
 *  for this file into C (a good idea)
 *  
 *  COPYRIGHT (c) 1989-1998.
 *  On-Line Applications Research Corporation (OAR).
 *  Copyright assigned to U.S. Government, 1994.
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.OARcorp.com/rtems/license.html.
 *
 *  $Id: duart.c
 */

#define MC68681_OFFSET_MULTIPLIER 8
#include <motorola/mc68681.h>
#include <bsp.h>
#include <ringbuf.h>
          
rtems_isr console_isr (rtems_vector_number vector);

Ring_buffer_t TX_Buffer[2];
Ring_buffer_t RX_Buffer[2];

/*PAGE
 *
 *  init_mc88681
 *
 *  volatile routine to initialize duart
 *
 *  Input parameters: NONE
 *
 *  Output parameters: NONE
 *
 *  Return Values:     NONE  
 */

volatile void init_mc88681()
{
  /*
   *  Initialize Ring buffers
   */
  Ring_buffer_Initialize( &RX_Buffer[ 0 ] );
  Ring_buffer_Initialize( &RX_Buffer[ 1 ] );

  Ring_buffer_Initialize( &TX_Buffer[ 0 ] );
  Ring_buffer_Initialize( &TX_Buffer[ 1 ] );
}

/*PAGE
 *
 *  console_isr
 *
 *  interrupt handler for receive of character from duart on ports A & B 
 *
 *  Input parameters: NONE
 *
 *  Output parameters: NONE
 *
 *  Return Values:     NONE  
 */

rtems_isr console_isr (rtems_vector_number vector)
{

   /*
    *  Fill me in later ...
    */

}


/*PAGE
 *
 *  console_outbyte_polled
 *
 *  This routine transmits a character out.
 *
 *  Input parameters:
 *    port - port to transmit character to
 *    ch  - character to be transmitted
 *
 *  Output parameters:  NONE
 *
 *  Return values: NONE
 */

void console_outbyte_polled(
  int port,
  char ch
)
{
  unsigned char status;
  unsigned char data;
  unsigned char t = 0;

  if (port == MC68681_PORT_A) { 
    status = MC68681_STATUS_REG_A;
    data = MC68681_TRANSMIT_BUFFER_A;
  } else {
    status = MC68681_STATUS_REG_B;
    data = MC68681_TRANSMIT_BUFFER_B;
  }

  while ( !(MC68681_READ(DUART_ADDR, status) & MC68681_TX_READY) ){
    if (t == 0) {
      Debug_Entry( 0x8000 );
      t++;
    }
  }
  
  Debug_Entry( 0x9000 );
  MC68681_WRITE(DUART_ADDR, data, ch);
}


/*PAGE
 *
 *  console_inbyte_nonblocking
 *
 *  This routine reads a character from the UART.
 *
 *  Input parameters:
 *    port - port to read character from
 *
 *  Output parameters:  NONE
 *
 *  Return values:
 *    character read from UART
 */

#define MC68681_RECEIVE_ERRORS \
      (MC68681_OVERRUN_ERROR | MC68681_PARITY_ERROR | MC68681_FRAMING_ERROR)

int console_inbyte_nonblocking( int port )
{
  char status;
  char data;
  char cmd;
  unsigned char status_info;

  /*  
   * Set Port A or B unique variables.         
   */
  if (port == MC68681_PORT_A)  {
    status = MC68681_STATUS_REG_A;
    data   = MC68681_RECEIVE_BUFFER_A;
    cmd    = MC68681_COMMAND_REG_A;
  } else {
    status = MC68681_STATUS_REG_B;
    data   = MC68681_RECEIVE_BUFFER_B;
    cmd    = MC68681_COMMAND_REG_B;
  }

  /* Wait for the Ready bit and Clear any errors */
  for ( ; ; ) {
    status_info = MC68681_READ(DUART_ADDR, status);
    if ( status_info & MC68681_RX_READY )
      break;

     if ( status_info & MC68681_RECEIVE_ERRORS )
         MC68681_WRITE( DUART_ADDR, cmd, MC68681_MODE_REG_RESET_ERROR );
  }

  return MC68681_READ(DUART_ADDR, data);
}