source: rtems/c/src/lib/libbsp/m68k/idp/console/duart.c @ fd36451

4.115
Last change on this file since fd36451 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 8.3 KB
Line 
1/*#########################################################
2#
3# This code is a modified version of what you will find at the
4# end of the IDP User's manual.  The original code is copyrighted
5# by Motorola and Motorola Semiconductor Products as well as
6# Motorola Software products group.
7#
8# Modifications to the original IDP code by Doug McBride, Colorado
9# Space Grant College.  Modifications include a means of accessing
10# port B of the duart as well as port A as well as modifications for
11# buffering and RTEMS support.  Modifications are provided
12# as is and may not be correct.
13#
14# Rob Savoye provided the format for the mc68681 header file
15#
16# Joel Sherrill provided inspiration for recoding my original assembly
17# for this file into C (a good idea)
18#
19##########################################################*/
20
21#include <bsp.h>
22#include <rtems/ringbuf.h>
23
24rtems_isr C_Receive_ISR(rtems_vector_number vector);
25extern Ring_buffer_t  Console_Buffer[];
26
27extern unsigned char inbuf[];
28extern unsigned char inbuf_portb[];
29extern unsigned tail;
30extern unsigned tail_portb;
31unsigned char Pit_initialized = 0;
32
33/*#####################################################################
34# The volatile routine to initialize the duart -- port a and port b
35######################################################################*/
36void init_pit()
37{
38  /*
39   *  ports A & B while configuring PIT by:
40   *
41   *    + disable Interrupt Mask Register
42   *    + disable port A transmitter
43   *    + disable port A receiver
44   *    + disable port B transmitter
45   *    + disable port B receiver
46   */
47
48  MC68681_WRITE(DUART_ADDR, MC68681_INTERRUPT_MASK_REG, 0x00);
49  MC68681_WRITE(DUART_ADDR, MC68681_COMMAND_REG_A ,MC68681_MODE_REG_DISABLE_TX);
50  MC68681_WRITE(DUART_ADDR, MC68681_COMMAND_REG_A, MC68681_MODE_REG_DISABLE_RX);
51  MC68681_WRITE(DUART_ADDR, MC68681_COMMAND_REG_B, MC68681_MODE_REG_DISABLE_TX);
52  MC68681_WRITE(DUART_ADDR, MC68681_COMMAND_REG_B, MC68681_MODE_REG_DISABLE_RX);
53
54  /*
55   *  install ISR for ports A and B
56   */
57  set_vector(C_Receive_ISR, (MC68230_VECT+MC68230_H3VECT), 1);
58
59  /*
60   *  initialize pit
61   *
62   *  set mode to 0 -- disable all ports
63   *  set up pirq and piack
64   *  all pins on port b are input
65   *  submode 1x, h3 interrupt enabled
66   *  setup pivr
67   *  turn on all ports
68   */
69  MC68230_WRITE(MC68230_PGCR, 0x00);
70  MC68230_WRITE(MC68230_PSRR, 0x18);
71  MC68230_WRITE(MC68230_PBDDR, 0x00);
72  MC68230_WRITE(MC68230_PBCR, 0x82);
73  MC68230_WRITE(MC68230_PIVR, MC68230_VECT);
74  MC68230_WRITE(MC68230_PGCR, 0x20);
75
76  /*
77   *  For some reason, the reset of receiver/transmitter only works for
78   *  the first time around -- it garbles the output otherwise
79   *  (e.g., sp21)
80   */
81  if (!Pit_initialized)
82  {
83    /*
84     * initialize the duart registers on port b
85     * WARNING:OPTIMIZER MAY ONLY EXECUTE THIRD STATEMENT IF NOT VOLATILE
86     *
87     *  reset tx, channel b
88     *  reset rx, channel b
89     *  reset mr pointer, ch
90     */
91     MC68681_WRITE(DUART_ADDR, MC68681_COMMAND_REG_B, MC68681_MODE_REG_RESET_TX);
92     MC68681_WRITE(DUART_ADDR, MC68681_COMMAND_REG_B, MC68681_MODE_REG_RESET_RX);
93     MC68681_WRITE(DUART_ADDR, MC68681_COMMAND_REG_B, MC68681_MODE_REG_RESET_MR_PTR);
94
95    /*
96     * initialize the duart registers on port a
97     * WARNING:OPTIMIZER MAY ONLY EXECUTE THIRD STATEMENT IF NOT VOLATILE
98     *
99     *  reset tx, channel a
100     *  reset rx, channel a
101     *  reset mr pointer, ch
102     */
103     MC68681_WRITE(DUART_ADDR, MC68681_COMMAND_REG_A, MC68681_MODE_REG_RESET_TX);
104     MC68681_WRITE(DUART_ADDR, MC68681_COMMAND_REG_A, MC68681_MODE_REG_RESET_RX);
105     MC68681_WRITE(DUART_ADDR, MC68681_COMMAND_REG_A, MC68681_MODE_REG_RESET_MR_PTR);
106
107     Pit_initialized = 1;
108  }
109
110  /*
111   * Init the general registers of the duart
112   *
113   * init ivr
114   * init imr
115   * init acr
116   * init ctur
117   * init ctlr
118   * init opcr
119   * init cts
120   */
121  MC68681_WRITE(DUART_ADDR, MC68681_INTERRUPT_VECTOR_REG,
122                MC68681_INTERRUPT_VECTOR_INIT);
123  MC68681_WRITE(DUART_ADDR, MC68681_INTERRUPT_MASK_REG,
124                MC68681_IR_RX_READY_A | MC68681_IR_RX_READY_B);
125  MC68681_WRITE(DUART_ADDR, MC68681_AUX_CTRL_REG, MC68681_CLEAR);
126  MC68681_WRITE(DUART_ADDR, MC68681_COUNTER_TIMER_UPPER_REG, 0x00);
127  MC68681_WRITE(DUART_ADDR, MC68681_COUNTER_TIMER_LOWER_REG, 0x02);
128  MC68681_WRITE(DUART_ADDR, MC68681_OUTPUT_PORT_CONFIG_REG, MC68681_CLEAR);
129  MC68681_WRITE(DUART_ADDR, MC68681_OUTPUT_PORT_SET_REG, 0x01);
130
131  /*
132   * init the actual serial port for port a
133   *
134   * Set Baud Rate to 9600
135   * Set Stop bit length of 1
136   * enable Transmit and receive
137   */
138  MC68681_WRITE(DUART_ADDR, MC68681_CLOCK_SELECT_REG_A, MC68681_BAUD_RATE_MASK_9600);
139  MC68681_WRITE(DUART_ADDR, MC68681_MODE_REG_1A,
140                (MC68681_8BIT_CHARS | MC68681_NO_PARITY));
141  MC68681_WRITE(DUART_ADDR, MC68681_MODE_REG_2A,MC68681_STOP_BIT_LENGTH_1);
142  MC68681_WRITE(DUART_ADDR, MC68681_COMMAND_REG_A,
143                (MC68681_MODE_REG_ENABLE_TX | MC68681_MODE_REG_ENABLE_RX));
144
145  /*
146   * init the actual serial port for port b
147   * init csrb -- 9600 baud
148   */
149  MC68681_WRITE(DUART_ADDR, MC68681_CLOCK_SELECT_REG_B, MC68681_BAUD_RATE_MASK_9600);
150
151#define EIGHT_BITS_NO_PARITY
152#ifdef EIGHT_BITS_NO_PARITY
153  /*
154   * Set 8 Bit characters with no parity
155   */
156  MC68681_WRITE(DUART_ADDR, MC68681_MODE_REG_1B,
157                (MC68681_NO_PARITY | MC68681_8BIT_CHARS) );
158#else
159  /*
160   * Set 7 Bit Characters with parity
161   */
162  MC68681_WRITE(DUART_ADDR, MC68681_MODE_REG_1B,
163                (MC68681_WITH_PARITY |  MC68681_7BIT_CHARS) );
164#endif
165
166  /*
167   * Set Stop Bit length to 1
168   * Disable Recieve and transmit on B
169   */
170  MC68681_WRITE(DUART_ADDR, MC68681_MODE_REG_2B,MC68681_STOP_BIT_LENGTH_1);
171  MC68681_WRITE(DUART_ADDR, MC68681_COMMAND_REG_B,
172                (MC68681_MODE_REG_ENABLE_TX | MC68681_MODE_REG_ENABLE_RX) );
173}
174
175/*#####################################################################
176# interrupt handler for receive of character from duart on ports A & B
177#####################################################################*/
178rtems_isr C_Receive_ISR(rtems_vector_number vector)
179{
180  volatile unsigned char *_addr;
181
182  /*
183   *  Clear pit interrupt.
184   */
185  _addr = (unsigned char *) (MC68230_PIT_ADDR + MC68230_PITSR);
186  *_addr = 0x04;
187
188  /*
189   *  check port A first for input
190   *     extract rcvrdy on port B
191   *     set ptr to recieve buffer and read character into ring buffer
192   */
193  _addr = (unsigned char *) (DUART_ADDR + MC68681_STATUS_REG_A);
194  if (*_addr & MC68681_RX_READY)  /* extract rcvrdy on port A */
195  {
196    _addr = (unsigned char *) (DUART_ADDR + MC68681_RECEIVE_BUFFER_A);
197    Ring_buffer_Add_character( &Console_Buffer[ 0 ], *_addr );
198  }
199
200  /*
201   *  If not on port A, let's check port B
202   *     extract rcvrdy on port B
203   *     set ptr to recieve buffer and read character into ring buffer
204   */
205  else
206  {
207    _addr = (unsigned char *) (DUART_ADDR + MC68681_STATUS_REG_B);
208    if (*_addr & MC68681_RX_READY)  /* extract rcvrdy on port B */
209    {
210      _addr = (unsigned char *) (DUART_ADDR + MC68681_RECEIVE_BUFFER_B);
211      Ring_buffer_Add_character( &Console_Buffer[ 1 ], *_addr );
212    }
213
214    /*
215     * if not ready on port A or port B, must be an error
216     * if error, get out so that fifo is undisturbed
217     */
218  }
219}
220
221/*#####################################################################
222# This is the routine that actually transmits a character one at a time
223# This routine transmits on port A of the IDP board
224#####################################################################*/
225void transmit_char(char ch)
226{
227  volatile unsigned char *_addr;
228
229  /*
230   * Get SRA (extract txrdy)
231   */
232  _addr = (unsigned char *) (DUART_ADDR + MC68681_STATUS_REG_A);
233  while (!(*_addr & MC68681_TX_READY))
234  {
235  }
236
237  /*
238   * transmit character over port A
239   */
240  MC68681_WRITE(DUART_ADDR, MC68681_TRANSMIT_BUFFER_A, ch);
241}
242
243/*#####################################################################
244# This is the routine that actually transmits a character one at a time
245# This routine transmits on port B of the IDP board
246#####################################################################*/
247void transmit_char_portb(char ch)
248{
249  volatile unsigned char *_addr;
250
251  /*
252   * Get SRB (extract txrdy)
253   */
254  _addr = (unsigned char *) (DUART_ADDR + MC68681_STATUS_REG_B);
255  while (!(*_addr &  MC68681_TX_READY))
256  {
257  }
258
259  /*
260   * transmit character over port B
261   */
262  MC68681_WRITE(DUART_ADDR, MC68681_TRANSMIT_BUFFER_B, ch);
263}
Note: See TracBrowser for help on using the repository browser.