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

4.104.114.84.95
Last change on this file since 9700578 was 9700578, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 30, 1995 at 9:54:45 PM

SPARC port passes all tests

  • Property mode set to 100644
File size: 6.2 KB
Line 
1/*
2 *  $Id$
3 */
4
5/*#########################################################
6#
7# This code is a modified version of what you will find at the
8# end of the IDP User's manual.  The original code is copyrighted
9# by Motorola and Motorola Semiconductor Products as well as
10# Motorola Software products group.
11#
12# Modifications to the original IDP code by Doug McBride, Colorado
13# Space Grant College.  Modifications include a means of accessing
14# port B of the duart as well as port A as well as modifications for
15# buffering and RTEMS support.  Modifications are provided
16# as is and may not be correct.
17#
18# Rob Savoye provided the format for the mc68681 header file
19#
20# Joel Sherrill provided inspiration for recoding my original assembly
21# for this file into C (a good idea)
22#
23##########################################################*/
24
25#include "mc68230.h"
26#include "mc68681.h"
27#include "ringbuf.h"
28#include "rtems.h"
29#include "bsp.h"
30
31rtems_isr C_Receive_ISR(rtems_vector_number vector);
32extern Ring_buffer_t  Buffer[];
33
34extern unsigned char inbuf[];
35extern unsigned char inbuf_portb[];
36extern unsigned tail;
37extern unsigned tail_portb;
38unsigned char Pit_initialized = 0;
39
40/*#####################################################################
41# The volatile routine to initialize the duart -- port a and port b
42######################################################################*/
43volatile void init_pit()
44{
45        /* Disable ports A & B while configuring PIT */
46        MC68681_WRITE(DUART_IMR, 0x00);         /* disable imr */
47        MC68681_WRITE(DUART_CRA, 0x08);         /* disable port a transmitter */
48        MC68681_WRITE(DUART_CRA, 0x02);         /* disable port a receiver */
49        MC68681_WRITE(DUART_CRB, 0x08);         /* disable port b transmitter */
50        MC68681_WRITE(DUART_CRB, 0x02);         /* disable port b receiver */
51
52        /* install ISR for ports A and B */
53        set_vector(C_Receive_ISR, (VECT+H3VECT), 1);
54
55        /* initialize pit */
56        MC68230_WRITE(PGCR, 0x00);  /* set mode to 0 -- disable all ports */
57        MC68230_WRITE(PSRR, 0x18);      /* set up pirq and piack */
58        MC68230_WRITE(PBDDR, 0x00);     /* all pins on port b are input */
59        MC68230_WRITE(PBCR, 0x82);      /* submode 1x, h3 interrupt enabled */
60        MC68230_WRITE(PIVR, VECT);      /* setup pivr */
61        MC68230_WRITE(PGCR, 0x20);      /* turn on all ports */
62
63        /* For some reason, the reset of receiver/transmitter only works for
64       the first time around -- it garbles the output otherwise (e.g., sp21) */
65        if (!Pit_initialized)
66        {
67           /* now initialize the duart registers on port b */
68           /* WARNING:OPTIMIZER MAY ONLY EXECUTE THIRD STATEMENT IF NOT VOLATILE */
69           MC68681_WRITE(DUART_CRB, 0x30);              /* reset tx, channel b */
70           MC68681_WRITE(DUART_CRB, 0x20);              /* reset rx, channel b */
71           MC68681_WRITE(DUART_CRB, 0x10);              /* reset mr pointer, channel b */
72
73           /* now initialize the duart registers on port a */
74           /* WARNING:OPTIMIZER MAY ONLY EXECUTE THIRD STATEMENT IF NOT VOLATILE */
75           MC68681_WRITE(DUART_CRA, 0x30);              /* reset tx, channel a */
76           MC68681_WRITE(DUART_CRA, 0x20);              /* reset rx, channel a */
77           MC68681_WRITE(DUART_CRA, 0x10);              /* reset mr pointer, channel a */
78           Pit_initialized = 1;
79        }
80
81        /* init the general registers of the duart */
82        MC68681_WRITE(DUART_IVR, 0x0f);         /* init ivr */
83        MC68681_WRITE(DUART_IMR, 0x22);         /* init imr */
84        MC68681_WRITE(DUART_ACR, 0x00);         /* init acr */
85        MC68681_WRITE(DUART_CTUR, 0x00);        /* init ctur */
86        MC68681_WRITE(DUART_CTLR, 0x02);        /* init ctlr */
87        MC68681_WRITE(DUART_OPCR, 0x00);        /* init opcr */
88        MC68681_WRITE(DUART_OPRSET, 0x01);      /* init cts */
89
90        /* init the actual serial port for port a */
91        MC68681_WRITE(DUART_CSRA, 0xbb);        /* init csra -- 9600 baud */
92        MC68681_WRITE(DUART_MR1A, 0x13);        /* init mr1a */
93        MC68681_WRITE(DUART_MR2A, 0x07);        /* init mr2a */
94        MC68681_WRITE(DUART_CRA, 0x05);         /* init cra */
95
96        /* init the actual serial port for port b */
97        MC68681_WRITE(DUART_CSRB, 0xbb);        /* init csrb -- 9600 baud */
98#define EIGHT_BITS_NO_PARITY
99#ifdef EIGHT_BITS_NO_PARITY
100        MC68681_WRITE(DUART_MR1B, 0x13);        /* init mr1b */
101#else /* 7 bits, even parity */
102        MC68681_WRITE(DUART_MR1B, 0x02);        /* init mr1b */
103#endif
104        MC68681_WRITE(DUART_MR2B, 0x07);        /* init mr2b -- one stop bit */
105        MC68681_WRITE(DUART_CRB, 0x05);         /* init crb */
106}
107
108/*#####################################################################
109# interrupt handler for receive of character from duart on ports A & B
110#####################################################################*/
111rtems_isr C_Receive_ISR(rtems_vector_number vector)
112{
113        volatile unsigned char *_addr;
114
115        _addr = (unsigned char *) (PIT_ADDR + PITSR);
116        *_addr = 0x04;          /* clear pit interrupt */
117
118        /* Let's check port A first for input */
119        _addr = (unsigned char *) (DUART_ADDR + DUART_SRA);
120        if (*_addr & 0x01)      /* extract rcvrdy on port A */
121        {
122                /* Read input on port A */
123                _addr = (unsigned char *) (DUART_ADDR + DUART_RBA);
124                Ring_buffer_Add_character( &Buffer[ 0 ], *_addr );
125        }
126        else    /* If not on port A, let's check port B */
127        {
128                _addr = (unsigned char *) (DUART_ADDR + DUART_SRB);
129                if (*_addr & 0x01)      /* extract rcvrdy on port B */
130                {
131                        /* Read input on port B */
132                        _addr = (unsigned char *) (DUART_ADDR + DUART_RBB);
133                        Ring_buffer_Add_character( &Buffer[ 1 ], *_addr );
134                }
135                /* if not ready on port A or port B, must be an error */
136                /* if error, get out so that fifo is undisturbed */
137        }
138}
139
140/*#####################################################################
141# This is the routine that actually transmits a character one at a time
142# This routine transmits on port A of the IDP board
143#####################################################################*/
144void transmit_char(char ch)
145{
146        volatile unsigned char *_addr;
147
148        /* Get SRA (extract txrdy) */
149        _addr = (unsigned char *) (DUART_ADDR + DUART_SRA);
150        while (!(*_addr & 0x04))
151        {
152        }
153
154        /* transmit character over port A */
155        MC68681_WRITE(DUART_TBA, ch);
156}
157
158/*#####################################################################
159# This is the routine that actually transmits a character one at a time
160# This routine transmits on port B of the IDP board
161#####################################################################*/
162void transmit_char_portb(char ch)
163{
164        volatile unsigned char *_addr;
165
166        /* Get SRB (extract txrdy) */
167        _addr = (unsigned char *) (DUART_ADDR + DUART_SRB);
168        while (!(*_addr & 0x04))
169        {
170        }
171
172        /* transmit character over port B */
173        MC68681_WRITE(DUART_TBB, ch);
174}
Note: See TracBrowser for help on using the repository browser.