1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// mpc555_serial_with_ints.c
|
4 |
|
|
//
|
5 |
|
|
// PowerPC 5xx MPC555 Serial I/O Interface Module (interrupt driven)
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//==========================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): Bob Koninckx
|
43 |
|
|
// Contributors:
|
44 |
|
|
// Date: 2002-04-25
|
45 |
|
|
// Purpose: MPC555 Serial I/O module (interrupt driven version)
|
46 |
|
|
// Description:
|
47 |
|
|
//
|
48 |
|
|
//
|
49 |
|
|
//####DESCRIPTIONEND####
|
50 |
|
|
//==========================================================================
|
51 |
|
|
//----------------------------------
|
52 |
|
|
// Includes and forward declarations
|
53 |
|
|
//----------------------------------
|
54 |
|
|
#include <pkgconf/io_serial.h>
|
55 |
|
|
#include <pkgconf/io.h>
|
56 |
|
|
|
57 |
|
|
#include <cyg/io/io.h>
|
58 |
|
|
#include <cyg/hal/hal_intr.h>
|
59 |
|
|
#include <cyg/hal/hal_arbiter.h>
|
60 |
|
|
#include <cyg/io/devtab.h>
|
61 |
|
|
#include <cyg/infra/diag.h>
|
62 |
|
|
#include <cyg/io/serial.h>
|
63 |
|
|
|
64 |
|
|
// Only build this driver for the MPC555 based boards
|
65 |
|
|
#if defined (CYGPKG_IO_SERIAL_POWERPC_MPC555) && \
|
66 |
|
|
(defined (CYGPKG_IO_SERIAL_POWERPC_MPC555_SERIAL_A) || \
|
67 |
|
|
defined (CYGPKG_IO_SERIAL_POWERPC_MPC555_SERIAL_B))
|
68 |
|
|
|
69 |
|
|
#include "mpc555_serial.h"
|
70 |
|
|
|
71 |
|
|
//---------------------------------------------------------------------------
|
72 |
|
|
// Type definitions
|
73 |
|
|
//---------------------------------------------------------------------------
|
74 |
|
|
#define MPC555_SCI_RX_BUFF_SIZE 256
|
75 |
|
|
typedef struct st_sci_circbuf {
|
76 |
|
|
cyg_uint8 buf[MPC555_SCI_RX_BUFF_SIZE];
|
77 |
|
|
cyg_uint16 scsr[MPC555_SCI_RX_BUFF_SIZE];
|
78 |
|
|
cyg_uint8 fill_pos;
|
79 |
|
|
cyg_uint8 read_pos;
|
80 |
|
|
} mpc555_sci_circbuf_t;
|
81 |
|
|
|
82 |
|
|
typedef struct mpc555_serial_info {
|
83 |
|
|
CYG_ADDRWORD base; // The base address of the serial port
|
84 |
|
|
CYG_WORD tx_interrupt_num; // trivial
|
85 |
|
|
CYG_WORD rx_interrupt_num; // trivial
|
86 |
|
|
cyg_priority_t tx_interrupt_priority;// trivial
|
87 |
|
|
cyg_priority_t rx_interrupt_priority;// trivial
|
88 |
|
|
bool tx_interrupt_enable; // can the tx interrupt be re-enabled?
|
89 |
|
|
mpc555_sci_circbuf_t* rx_circbuf; // rx buff for ISR to DSR data exchange
|
90 |
|
|
bool use_queue; // Use the queue when available?
|
91 |
|
|
CYG_WORD rx_last_queue_pointer;// Keep track where queue read is upto
|
92 |
|
|
CYG_WORD rx_interrupt_idle_line_num; // trivial
|
93 |
|
|
CYG_WORD tx_interrupt_queue_top_empty_num; // trivial
|
94 |
|
|
CYG_WORD tx_interrupt_queue_bot_empty_num; // trivial
|
95 |
|
|
CYG_WORD rx_interrupt_queue_top_full_num; // trivial
|
96 |
|
|
CYG_WORD rx_interrupt_queue_bot_full_num; // trivial
|
97 |
|
|
cyg_priority_t rx_interrupt_idle_line_priority; // trivial
|
98 |
|
|
cyg_priority_t tx_interrupt_queue_top_empty_priority; // trivial
|
99 |
|
|
cyg_priority_t tx_interrupt_queue_bot_empty_priority; // trivial
|
100 |
|
|
cyg_priority_t rx_interrupt_queue_top_full_priority; // trivial
|
101 |
|
|
cyg_priority_t rx_interrupt_queue_bot_full_priority; // trivial
|
102 |
|
|
cyg_interrupt tx_interrupt; // the tx interrupt object
|
103 |
|
|
cyg_handle_t tx_interrupt_handle; // the tx interrupt handle
|
104 |
|
|
cyg_interrupt rx_interrupt; // the rx interrupt object
|
105 |
|
|
cyg_handle_t rx_interrupt_handle; // the rx interrupt handle
|
106 |
|
|
cyg_interrupt rx_idle_interrupt; // the rx idle line isr object
|
107 |
|
|
cyg_handle_t rx_idle_interrupt_handle; // the rx idle line isr handle
|
108 |
|
|
cyg_interrupt tx_queue_top_interrupt; // the tx interrupt object
|
109 |
|
|
cyg_handle_t tx_queue_top_interrupt_handle;// the tx interrupt handle
|
110 |
|
|
cyg_interrupt tx_queue_bot_interrupt; // the tx interrupt object
|
111 |
|
|
cyg_handle_t tx_queue_bot_interrupt_handle;// the tx interrupt handle
|
112 |
|
|
cyg_interrupt rx_queue_top_interrupt; // the tx interrupt object
|
113 |
|
|
cyg_handle_t rx_queue_top_interrupt_handle;// the tx interrupt handle
|
114 |
|
|
cyg_interrupt rx_queue_bot_interrupt; // the tx interrupt object
|
115 |
|
|
cyg_handle_t rx_queue_bot_interrupt_handle;// the tx interrupt handle
|
116 |
|
|
} mpc555_serial_info;
|
117 |
|
|
|
118 |
|
|
//--------------------
|
119 |
|
|
// Function prototypes
|
120 |
|
|
//--------------------
|
121 |
|
|
static bool mpc555_serial_putc(serial_channel * chan, unsigned char c);
|
122 |
|
|
static unsigned char mpc555_serial_getc(serial_channel *chan);
|
123 |
|
|
static Cyg_ErrNo mpc555_serial_set_config(serial_channel *chan, cyg_uint32 key,
|
124 |
|
|
const void *xbuf, cyg_uint32 *len);
|
125 |
|
|
static void mpc555_serial_start_xmit(serial_channel *chan);
|
126 |
|
|
static void mpc555_serial_stop_xmit(serial_channel *chan);
|
127 |
|
|
static Cyg_ErrNo mpc555_serial_lookup(struct cyg_devtab_entry ** tab,
|
128 |
|
|
struct cyg_devtab_entry * sub_tab,
|
129 |
|
|
const char * name);
|
130 |
|
|
static bool mpc555_serial_init(struct cyg_devtab_entry * tab);
|
131 |
|
|
|
132 |
|
|
// The interrupt servers
|
133 |
|
|
static cyg_uint32 mpc555_serial_tx_ISR(cyg_vector_t vector, cyg_addrword_t data);
|
134 |
|
|
static cyg_uint32 mpc555_serial_rx_ISR(cyg_vector_t vector, cyg_addrword_t data);
|
135 |
|
|
static void mpc555_serial_tx_DSR(cyg_vector_t vector,
|
136 |
|
|
cyg_ucount32 count,
|
137 |
|
|
cyg_addrword_t data);
|
138 |
|
|
static void mpc555_serial_rx_DSR(cyg_vector_t vector,
|
139 |
|
|
cyg_ucount32 count,
|
140 |
|
|
cyg_addrword_t data);
|
141 |
|
|
|
142 |
|
|
#ifdef CYGPKG_IO_SERIAL_POWERPC_MPC555_SERIAL_A
|
143 |
|
|
static cyg_uint32 mpc555_serial_tx_queue_top_ISR(cyg_vector_t vector,
|
144 |
|
|
cyg_addrword_t data);
|
145 |
|
|
static cyg_uint32 mpc555_serial_tx_queue_bot_ISR(cyg_vector_t vector,
|
146 |
|
|
cyg_addrword_t data);
|
147 |
|
|
static cyg_uint32 mpc555_serial_rx_queue_top_ISR(cyg_vector_t vector,
|
148 |
|
|
cyg_addrword_t data);
|
149 |
|
|
static cyg_uint32 mpc555_serial_rx_queue_bot_ISR(cyg_vector_t vector,
|
150 |
|
|
cyg_addrword_t data);
|
151 |
|
|
static cyg_uint32 mpc555_serial_rx_idle_line_ISR(cyg_vector_t vector,
|
152 |
|
|
cyg_addrword_t data);
|
153 |
|
|
|
154 |
|
|
static void mpc555_serial_tx_queue_DSR(cyg_vector_t vector,
|
155 |
|
|
cyg_ucount32 count,
|
156 |
|
|
cyg_addrword_t data);
|
157 |
|
|
static void mpc555_serial_rx_queue_DSR(cyg_vector_t vector,
|
158 |
|
|
cyg_ucount32 count,
|
159 |
|
|
cyg_addrword_t data);
|
160 |
|
|
|
161 |
|
|
static int mpc555_serial_read_queue(serial_channel* chan, int start, int end);
|
162 |
|
|
#endif
|
163 |
|
|
|
164 |
|
|
//------------------------------------------------------------------------------
|
165 |
|
|
// Register the device driver with the kernel
|
166 |
|
|
//------------------------------------------------------------------------------
|
167 |
|
|
static SERIAL_FUNS(mpc555_serial_funs,
|
168 |
|
|
mpc555_serial_putc,
|
169 |
|
|
mpc555_serial_getc,
|
170 |
|
|
mpc555_serial_set_config,
|
171 |
|
|
mpc555_serial_start_xmit,
|
172 |
|
|
mpc555_serial_stop_xmit);
|
173 |
|
|
|
174 |
|
|
//------------------------------------------------------------------------------
|
175 |
|
|
// Device driver data
|
176 |
|
|
//------------------------------------------------------------------------------
|
177 |
|
|
#ifdef CYGPKG_IO_SERIAL_POWERPC_MPC555_SERIAL_A
|
178 |
|
|
#ifdef CYGDAT_IO_SERIAL_POWERPC_MPC555_SERIAL_A_USE_HWARE_QUEUE
|
179 |
|
|
//static mpc555_sci_circbuf_t mpc555_serial_isr_to_dsr_buf0;
|
180 |
|
|
|
181 |
|
|
static mpc555_serial_info mpc555_serial_info0 = {
|
182 |
|
|
MPC555_SERIAL_BASE_A,
|
183 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_TX,
|
184 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_RX,
|
185 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_TX_PRIORITY,
|
186 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_RX_PRIORITY,
|
187 |
|
|
false,
|
188 |
|
|
NULL, // Don't need software buffer
|
189 |
|
|
true, // Use queue
|
190 |
|
|
0, // init queue pointer
|
191 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_IDLE,
|
192 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_TXQTHE,
|
193 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_TXQBHE,
|
194 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_RXQTHF,
|
195 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_RXQBHF,
|
196 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_IDLE_PRIORITY,
|
197 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_TXQTHE_PRIORITY,
|
198 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_TXQBHE_PRIORITY,
|
199 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_RXQTHF_PRIORITY,
|
200 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_RXQBHF_PRIORITY};
|
201 |
|
|
|
202 |
|
|
static unsigned char mpc555_serial_out_buf0[CYGNUM_IO_SERIAL_POWERPC_MPC555_SERIAL_A_BUFSIZE];
|
203 |
|
|
static unsigned char mpc555_serial_in_buf0[CYGNUM_IO_SERIAL_POWERPC_MPC555_SERIAL_A_BUFSIZE];
|
204 |
|
|
|
205 |
|
|
static SERIAL_CHANNEL_USING_INTERRUPTS(
|
206 |
|
|
mpc555_serial_channel0,
|
207 |
|
|
mpc555_serial_funs,
|
208 |
|
|
mpc555_serial_info0,
|
209 |
|
|
CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_POWERPC_MPC555_SERIAL_A_BAUD),
|
210 |
|
|
CYG_SERIAL_STOP_DEFAULT,
|
211 |
|
|
CYG_SERIAL_PARITY_DEFAULT,
|
212 |
|
|
CYG_SERIAL_WORD_LENGTH_DEFAULT,
|
213 |
|
|
CYG_SERIAL_FLAGS_DEFAULT,
|
214 |
|
|
&mpc555_serial_out_buf0[0],
|
215 |
|
|
sizeof(mpc555_serial_out_buf0),
|
216 |
|
|
&mpc555_serial_in_buf0[0],
|
217 |
|
|
sizeof(mpc555_serial_in_buf0));
|
218 |
|
|
|
219 |
|
|
#elif CYGNUM_IO_SERIAL_POWERPC_MPC555_SERIAL_A_BUFSIZE > 0
|
220 |
|
|
static mpc555_sci_circbuf_t mpc555_serial_isr_to_dsr_buf0;
|
221 |
|
|
|
222 |
|
|
static mpc555_serial_info mpc555_serial_info0 = {
|
223 |
|
|
MPC555_SERIAL_BASE_A,
|
224 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_TX,
|
225 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_RX,
|
226 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_TX_PRIORITY,
|
227 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_RX_PRIORITY,
|
228 |
|
|
false,
|
229 |
|
|
&mpc555_serial_isr_to_dsr_buf0,
|
230 |
|
|
false};
|
231 |
|
|
|
232 |
|
|
static unsigned char mpc555_serial_out_buf0[CYGNUM_IO_SERIAL_POWERPC_MPC555_SERIAL_A_BUFSIZE];
|
233 |
|
|
static unsigned char mpc555_serial_in_buf0[CYGNUM_IO_SERIAL_POWERPC_MPC555_SERIAL_A_BUFSIZE];
|
234 |
|
|
|
235 |
|
|
static SERIAL_CHANNEL_USING_INTERRUPTS(
|
236 |
|
|
mpc555_serial_channel0,
|
237 |
|
|
mpc555_serial_funs,
|
238 |
|
|
mpc555_serial_info0,
|
239 |
|
|
CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_POWERPC_MPC555_SERIAL_A_BAUD),
|
240 |
|
|
CYG_SERIAL_STOP_DEFAULT,
|
241 |
|
|
CYG_SERIAL_PARITY_DEFAULT,
|
242 |
|
|
CYG_SERIAL_WORD_LENGTH_DEFAULT,
|
243 |
|
|
CYG_SERIAL_FLAGS_DEFAULT,
|
244 |
|
|
&mpc555_serial_out_buf0[0],
|
245 |
|
|
sizeof(mpc555_serial_out_buf0),
|
246 |
|
|
&mpc555_serial_in_buf0[0],
|
247 |
|
|
sizeof(mpc555_serial_in_buf0));
|
248 |
|
|
#else
|
249 |
|
|
static mpc555_serial_info mpc555_serial_info0 = {
|
250 |
|
|
MPC555_SERIAL_BASE_A,
|
251 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_TX,
|
252 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_RX,
|
253 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_TX_PRIORITY,
|
254 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_RX_PRIORITY,
|
255 |
|
|
false,
|
256 |
|
|
NULL,
|
257 |
|
|
false};
|
258 |
|
|
|
259 |
|
|
static SERIAL_CHANNEL(
|
260 |
|
|
mpc555_serial_channel0,
|
261 |
|
|
mpc555_serial_funs,
|
262 |
|
|
mpc555_serial_info0,
|
263 |
|
|
CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_POWERPC_MPC555_SERIAL_A_BAUD),
|
264 |
|
|
CYG_SERIAL_STOP_DEFAULT,
|
265 |
|
|
CYG_SERIAL_PARITY_DEFAULT,
|
266 |
|
|
CYG_SERIAL_WORD_LENGTH_DEFAULT,
|
267 |
|
|
CYG_SERIAL_FLAGS_DEFAULT);
|
268 |
|
|
#endif
|
269 |
|
|
DEVTAB_ENTRY(mpc555_serial_io0,
|
270 |
|
|
CYGDAT_IO_SERIAL_POWERPC_MPC555_SERIAL_A_NAME,
|
271 |
|
|
0, // does not depend on a lower level device driver
|
272 |
|
|
&cyg_io_serial_devio,
|
273 |
|
|
mpc555_serial_init,
|
274 |
|
|
mpc555_serial_lookup,
|
275 |
|
|
&mpc555_serial_channel0);
|
276 |
|
|
#endif // ifdef CYGPKG_IO_SERIAL_POWERPC_MPC555_SERIAL_A
|
277 |
|
|
|
278 |
|
|
#ifdef CYGPKG_IO_SERIAL_POWERPC_MPC555_SERIAL_B
|
279 |
|
|
|
280 |
|
|
#if CYGNUM_IO_SERIAL_POWERPC_MPC555_SERIAL_B_BUFSIZE > 0
|
281 |
|
|
static mpc555_sci_circbuf_t mpc555_serial_isr_to_dsr_buf1;
|
282 |
|
|
|
283 |
|
|
static mpc555_serial_info mpc555_serial_info1 = {
|
284 |
|
|
MPC555_SERIAL_BASE_B,
|
285 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI2_TX,
|
286 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI2_RX,
|
287 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI2_TX_PRIORITY,
|
288 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI2_RX_PRIORITY,
|
289 |
|
|
false,
|
290 |
|
|
&mpc555_serial_isr_to_dsr_buf1,
|
291 |
|
|
false};
|
292 |
|
|
|
293 |
|
|
static unsigned char mpc555_serial_out_buf1[CYGNUM_IO_SERIAL_POWERPC_MPC555_SERIAL_B_BUFSIZE];
|
294 |
|
|
static unsigned char mpc555_serial_in_buf1[CYGNUM_IO_SERIAL_POWERPC_MPC555_SERIAL_B_BUFSIZE];
|
295 |
|
|
|
296 |
|
|
static SERIAL_CHANNEL_USING_INTERRUPTS(
|
297 |
|
|
mpc555_serial_channel1,
|
298 |
|
|
mpc555_serial_funs,
|
299 |
|
|
mpc555_serial_info1,
|
300 |
|
|
CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_POWERPC_MPC555_SERIAL_B_BAUD),
|
301 |
|
|
CYG_SERIAL_STOP_DEFAULT,
|
302 |
|
|
CYG_SERIAL_PARITY_DEFAULT,
|
303 |
|
|
CYG_SERIAL_WORD_LENGTH_DEFAULT,
|
304 |
|
|
CYG_SERIAL_FLAGS_DEFAULT,
|
305 |
|
|
&mpc555_serial_out_buf1[0],
|
306 |
|
|
sizeof(mpc555_serial_out_buf1),
|
307 |
|
|
&mpc555_serial_in_buf1[0],
|
308 |
|
|
sizeof(mpc555_serial_in_buf1));
|
309 |
|
|
#else
|
310 |
|
|
static mpc555_serial_info mpc555_serial_info1 = {
|
311 |
|
|
MPC555_SERIAL_BASE_B,
|
312 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_TX,
|
313 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_RX,
|
314 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_TX_PRIORITY,
|
315 |
|
|
CYGNUM_HAL_INTERRUPT_IMB3_SCI1_RX_PRIORITY,
|
316 |
|
|
false,
|
317 |
|
|
NULL,
|
318 |
|
|
false};
|
319 |
|
|
static SERIAL_CHANNEL(
|
320 |
|
|
mpc555_serial_channel1,
|
321 |
|
|
mpc555_serial_funs,
|
322 |
|
|
mpc555_serial_info1,
|
323 |
|
|
CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_POWERPC_MPC555_SERIAL_B_BAUD),
|
324 |
|
|
CYG_SERIAL_STOP_DEFAULT,
|
325 |
|
|
CYG_SERIAL_PARITY_DEFAULT,
|
326 |
|
|
CYG_SERIAL_WORD_LENGTH_DEFAULT,
|
327 |
|
|
CYG_SERIAL_FLAGS_DEFAULT);
|
328 |
|
|
#endif
|
329 |
|
|
DEVTAB_ENTRY(mpc555_serial_io1,
|
330 |
|
|
CYGDAT_IO_SERIAL_POWERPC_MPC555_SERIAL_B_NAME,
|
331 |
|
|
0, // does not depend on a lower level device driver
|
332 |
|
|
&cyg_io_serial_devio,
|
333 |
|
|
mpc555_serial_init,
|
334 |
|
|
mpc555_serial_lookup,
|
335 |
|
|
&mpc555_serial_channel1);
|
336 |
|
|
#endif // ifdef CYGPKG_IO_SERIAL_POWERPC_MPC555_SERIAL_B
|
337 |
|
|
|
338 |
|
|
//------------------------------------------------------------------------------
|
339 |
|
|
// Device driver implementation
|
340 |
|
|
//------------------------------------------------------------------------------
|
341 |
|
|
|
342 |
|
|
// The arbitration isr.
|
343 |
|
|
// I think this is the best place to implement it.
|
344 |
|
|
// The device driver is the only place in the code where the knowledge is
|
345 |
|
|
// present about how the hardware is used.
|
346 |
|
|
//
|
347 |
|
|
// Always check receive interrupts.
|
348 |
|
|
// Some rom monitor might be waiting for CTRL-C
|
349 |
|
|
static cyg_uint32 hal_arbitration_isr_qsci(CYG_ADDRWORD a_vector,
|
350 |
|
|
CYG_ADDRWORD a_data)
|
351 |
|
|
{
|
352 |
|
|
cyg_uint16 status;
|
353 |
|
|
cyg_uint16 control;
|
354 |
|
|
|
355 |
|
|
HAL_READ_UINT16(CYGARC_REG_IMM_SC1SR, status);
|
356 |
|
|
HAL_READ_UINT16(CYGARC_REG_IMM_SCC1R1, control);
|
357 |
|
|
if((status & CYGARC_REG_IMM_SCxSR_RDRF) &&
|
358 |
|
|
(control & CYGARC_REG_IMM_SCCxR1_RIE))
|
359 |
|
|
return hal_call_isr(CYGNUM_HAL_INTERRUPT_IMB3_SCI1_RX);
|
360 |
|
|
// Do not waist time on unused hardware
|
361 |
|
|
#ifdef CYGPKG_IO_SERIAL_POWERPC_MPC555_SERIAL_A
|
362 |
|
|
#ifdef CYGDAT_IO_SERIAL_POWERPC_MPC555_SERIAL_A_USE_HWARE_QUEUE
|
363 |
|
|
// Only one port supports queue mode
|
364 |
|
|
if((status & CYGARC_REG_IMM_SCxSR_IDLE) &&
|
365 |
|
|
(control & CYGARC_REG_IMM_SCCxR1_ILIE))
|
366 |
|
|
return hal_call_isr(CYGNUM_HAL_INTERRUPT_IMB3_SCI1_IDLE);
|
367 |
|
|
HAL_READ_UINT16(CYGARC_REG_IMM_QSCI1SR, status);
|
368 |
|
|
HAL_READ_UINT16(CYGARC_REG_IMM_QSCI1CR, control);
|
369 |
|
|
if((status & CYGARC_REG_IMM_QSCI1SR_QTHF) &&
|
370 |
|
|
(control & CYGARC_REG_IMM_QSCI1CR_QTHFI))
|
371 |
|
|
return hal_call_isr(CYGNUM_HAL_INTERRUPT_IMB3_SCI1_RXQTHF);
|
372 |
|
|
if((status & CYGARC_REG_IMM_QSCI1SR_QBHF) &&
|
373 |
|
|
(control & CYGARC_REG_IMM_QSCI1CR_QBHFI))
|
374 |
|
|
return hal_call_isr(CYGNUM_HAL_INTERRUPT_IMB3_SCI1_RXQBHF);
|
375 |
|
|
if((status & CYGARC_REG_IMM_QSCI1SR_QTHE) &&
|
376 |
|
|
(control & CYGARC_REG_IMM_QSCI1CR_QTHEI))
|
377 |
|
|
return hal_call_isr(CYGNUM_HAL_INTERRUPT_IMB3_SCI1_TXQTHE);
|
378 |
|
|
if((status & CYGARC_REG_IMM_QSCI1SR_QBHE) &&
|
379 |
|
|
(control & CYGARC_REG_IMM_QSCI1CR_QBHEI))
|
380 |
|
|
return hal_call_isr(CYGNUM_HAL_INTERRUPT_IMB3_SCI1_TXQBHE);
|
381 |
|
|
// Only for SPI, leave fo future reference
|
382 |
|
|
#if 0
|
383 |
|
|
HAL_READ_UINT16(CYGARC_REG_IMM_SPSR, status);
|
384 |
|
|
HAL_READ_UINT16(CYGARC_REG_IMM_SPCR2, control);
|
385 |
|
|
if((status & CYGARC_REG_IMM_SPSR_SPIF) &&
|
386 |
|
|
(control & CYGARC_REG_IMM_SPCR2_SPIFIE))
|
387 |
|
|
return hal_call_isr(CYGNUM_HAL_INTERRUPT_IMB3_SPI_FI);
|
388 |
|
|
|
389 |
|
|
HAL_READ_UINT16(CYGARC_REG_IMM_SPCR3, control);
|
390 |
|
|
if((status & CYGARC_REG_IMM_SPSR_MODF) &&
|
391 |
|
|
(control & CYGARC_REG_IMM_SPCR3_HMIE))
|
392 |
|
|
return hal_call_isr(CYGNUM_HAL_INTERRUPT_IMB3_SPI_MODF);
|
393 |
|
|
|
394 |
|
|
if((status & CYGARC_REG_IMM_SPSR_HALTA) &&
|
395 |
|
|
(control & CYGARC_REG_IMM_SPCR3_HMIE))
|
396 |
|
|
return hal_call_isr(CYGNUM_HAL_INTERRUPT_IMB3_SPI_HALTA);
|
397 |
|
|
#endif
|
398 |
|
|
#else //No HW Queue
|
399 |
|
|
if((status & CYGARC_REG_IMM_SCxSR_TDRE) &&
|
400 |
|
|
(control & CYGARC_REG_IMM_SCCxR1_TIE))
|
401 |
|
|
return hal_call_isr(CYGNUM_HAL_INTERRUPT_IMB3_SCI1_TX);
|
402 |
|
|
// Don't waist time on unused interrupts
|
403 |
|
|
// Transmit complete interrupt enabled (not used)
|
404 |
|
|
// if((status & CYGARC_REG_IMM_SCxSR_TC) && (control & CYGARC_REG_IMM_SCCxR1_TCIE))
|
405 |
|
|
// return hal_call_isr(CYGNUM_HAL_INTERRUPT_IMB3_SCI1_TXC);
|
406 |
|
|
// Don't waist time on unused interrupts
|
407 |
|
|
// Idle-line interrupt enabled (not used)
|
408 |
|
|
// if((status & CYGARC_REG_IMM_SCxSR_IDLE) && (control & CYGARC_REG_IMM_SCCxR1_ILIE))
|
409 |
|
|
// return hal_call_isr(CYGNUM_HAL_INTERRUPT_IMB3_SCI1_IDLE);
|
410 |
|
|
#endif // HW_QUEUE
|
411 |
|
|
#endif // SERIAL_A
|
412 |
|
|
|
413 |
|
|
HAL_READ_UINT16(CYGARC_REG_IMM_SC2SR, status);
|
414 |
|
|
HAL_READ_UINT16(CYGARC_REG_IMM_SCC2R1, control);
|
415 |
|
|
if((status & CYGARC_REG_IMM_SCxSR_RDRF) &&
|
416 |
|
|
(control & CYGARC_REG_IMM_SCCxR1_RIE))
|
417 |
|
|
return hal_call_isr(CYGNUM_HAL_INTERRUPT_IMB3_SCI2_RX);
|
418 |
|
|
// Do not waist time on unused hardware
|
419 |
|
|
#ifdef CYGPKG_IO_SERIAL_POWERPC_MPC555_SERIAL_B
|
420 |
|
|
if((status & CYGARC_REG_IMM_SCxSR_TDRE) &&
|
421 |
|
|
(control & CYGARC_REG_IMM_SCCxR1_TIE))
|
422 |
|
|
return hal_call_isr(CYGNUM_HAL_INTERRUPT_IMB3_SCI2_TX);
|
423 |
|
|
// Don't waist time on unused interrupts
|
424 |
|
|
// Transmit complete interrupt enabled (not used)
|
425 |
|
|
// if((status & CYGARC_REG_IMM_SCxSR_TC) && (control & CYGARC_REG_IMM_SCCxR1_TCIE))
|
426 |
|
|
// return hal_call_isr(CYGNUM_HAL_INTERRUPT_IMB3_SCI2_TXC);
|
427 |
|
|
// Don't waist time on unused interrupts
|
428 |
|
|
// Idle-line interrupt enabled (not used)
|
429 |
|
|
// if((status & CYGARC_REG_IMM_SCxSR_IDLE) && (control & CYGARC_REG_IMM_SCCxR1_ILIE))
|
430 |
|
|
// return hal_call_isr(CYGNUM_HAL_INTERRUPT_IMB3_SCI2_IDLE);
|
431 |
|
|
#endif
|
432 |
|
|
|
433 |
|
|
return 0;
|
434 |
|
|
}
|
435 |
|
|
|
436 |
|
|
//------------------------------------------------------------------------------
|
437 |
|
|
// Internal function to configure the hardware to desired baud rate, etc.
|
438 |
|
|
//------------------------------------------------------------------------------
|
439 |
|
|
static bool mpc555_serial_config_port(serial_channel * chan,
|
440 |
|
|
cyg_serial_info_t * new_config,
|
441 |
|
|
bool init)
|
442 |
|
|
{
|
443 |
|
|
mpc555_serial_info * mpc555_chan = (mpc555_serial_info *)(chan->dev_priv);
|
444 |
|
|
|
445 |
|
|
cyg_addrword_t port = mpc555_chan->base;
|
446 |
|
|
cyg_uint16 baud_rate = select_baud[new_config->baud];
|
447 |
|
|
unsigned char frame_length = 1; // The start bit
|
448 |
|
|
|
449 |
|
|
cyg_uint16 old_isrstate;
|
450 |
|
|
cyg_uint16 sccxr;
|
451 |
|
|
|
452 |
|
|
if(!baud_rate)
|
453 |
|
|
return false; // Invalid baud rate selected
|
454 |
|
|
|
455 |
|
|
if((new_config->word_length != CYGNUM_SERIAL_WORD_LENGTH_7) &&
|
456 |
|
|
(new_config->word_length != CYGNUM_SERIAL_WORD_LENGTH_8))
|
457 |
|
|
return false; // Invalid word length selected
|
458 |
|
|
|
459 |
|
|
if((new_config->parity != CYGNUM_SERIAL_PARITY_NONE) &&
|
460 |
|
|
(new_config->parity != CYGNUM_SERIAL_PARITY_EVEN) &&
|
461 |
|
|
(new_config->parity != CYGNUM_SERIAL_PARITY_ODD))
|
462 |
|
|
return false; // Invalid parity selected
|
463 |
|
|
|
464 |
|
|
if((new_config->stop != CYGNUM_SERIAL_STOP_1) &&
|
465 |
|
|
(new_config->stop != CYGNUM_SERIAL_STOP_2))
|
466 |
|
|
return false; // Invalid stop bits selected
|
467 |
|
|
|
468 |
|
|
frame_length += select_word_length[new_config->word_length -
|
469 |
|
|
CYGNUM_SERIAL_WORD_LENGTH_5];
|
470 |
|
|
frame_length += select_stop_bits[new_config->stop];
|
471 |
|
|
frame_length += select_parity[new_config->parity];
|
472 |
|
|
|
473 |
|
|
if((frame_length != 10) && (frame_length != 11))
|
474 |
|
|
return false; // Invalid frame format selected
|
475 |
|
|
|
476 |
|
|
// Disable port interrupts while changing hardware
|
477 |
|
|
HAL_READ_UINT16(port + MPC555_SERIAL_SCCxR1, sccxr);
|
478 |
|
|
old_isrstate = sccxr;
|
479 |
|
|
old_isrstate &= ~((cyg_uint16)MPC555_SERIAL_SCCxR1_LOOPS);
|
480 |
|
|
old_isrstate &= ~((cyg_uint16)MPC555_SERIAL_SCCxR1_WOMS);
|
481 |
|
|
old_isrstate &= ~((cyg_uint16)MPC555_SERIAL_SCCxR1_ILT);
|
482 |
|
|
old_isrstate &= ~((cyg_uint16)MPC555_SERIAL_SCCxR1_PT);
|
483 |
|
|
old_isrstate &= ~((cyg_uint16)MPC555_SERIAL_SCCxR1_PE);
|
484 |
|
|
old_isrstate &= ~((cyg_uint16)MPC555_SERIAL_SCCxR1_M);
|
485 |
|
|
old_isrstate &= ~((cyg_uint16)MPC555_SERIAL_SCCxR1_WAKE);
|
486 |
|
|
old_isrstate &= ~((cyg_uint16)MPC555_SERIAL_SCCxR1_TE);
|
487 |
|
|
old_isrstate &= ~((cyg_uint16)MPC555_SERIAL_SCCxR1_RE);
|
488 |
|
|
old_isrstate &= ~((cyg_uint16)MPC555_SERIAL_SCCxR1_RWU);
|
489 |
|
|
old_isrstate &= ~((cyg_uint16)MPC555_SERIAL_SCCxR1_SBK);
|
490 |
|
|
sccxr &= ~((cyg_uint16)MPC555_SERIAL_SCCxR1_TIE);
|
491 |
|
|
sccxr &= ~((cyg_uint16)MPC555_SERIAL_SCCxR1_TCIE);
|
492 |
|
|
sccxr &= ~((cyg_uint16)MPC555_SERIAL_SCCxR1_RIE);
|
493 |
|
|
sccxr &= ~((cyg_uint16)MPC555_SERIAL_SCCxR1_ILIE);
|
494 |
|
|
HAL_WRITE_UINT16(port + MPC555_SERIAL_SCCxR1, sccxr);
|
495 |
|
|
|
496 |
|
|
#ifdef CYGDAT_IO_SERIAL_POWERPC_MPC555_SERIAL_A_USE_HWARE_QUEUE
|
497 |
|
|
cyg_uint16 qsci1cr = 0;
|
498 |
|
|
if(mpc555_chan->use_queue){
|
499 |
|
|
HAL_READ_UINT16( CYGARC_REG_IMM_QSCI1SR, qsci1cr);
|
500 |
|
|
// disable queue
|
501 |
|
|
qsci1cr &= ~((cyg_uint16)CYGARC_REG_IMM_QSCI1CR_QTE);
|
502 |
|
|
qsci1cr &= ~((cyg_uint16)CYGARC_REG_IMM_QSCI1CR_QRE);
|
503 |
|
|
// disable queue interrupts
|
504 |
|
|
qsci1cr &= ~((cyg_uint16)CYGARC_REG_IMM_QSCI1CR_QTHFI);
|
505 |
|
|
qsci1cr &= ~((cyg_uint16)CYGARC_REG_IMM_QSCI1CR_QBHFI);
|
506 |
|
|
qsci1cr &= ~((cyg_uint16)CYGARC_REG_IMM_QSCI1CR_QTHEI);
|
507 |
|
|
qsci1cr &= ~((cyg_uint16)CYGARC_REG_IMM_QSCI1CR_QBHEI);
|
508 |
|
|
HAL_WRITE_UINT16( CYGARC_REG_IMM_QSCI1SR, qsci1cr);
|
509 |
|
|
}
|
510 |
|
|
#endif
|
511 |
|
|
// Set databits, stopbits and parity.
|
512 |
|
|
HAL_READ_UINT16(port + MPC555_SERIAL_SCCxR1, sccxr);
|
513 |
|
|
|
514 |
|
|
if(frame_length == 11)
|
515 |
|
|
sccxr |= (cyg_uint16)MPC555_SERIAL_SCCxR1_M;
|
516 |
|
|
else
|
517 |
|
|
sccxr &= ~((cyg_uint16)MPC555_SERIAL_SCCxR1_M);
|
518 |
|
|
|
519 |
|
|
switch(new_config->parity){
|
520 |
|
|
case CYGNUM_SERIAL_PARITY_NONE:
|
521 |
|
|
sccxr &= ~((cyg_uint16)MPC555_SERIAL_SCCxR1_PE);
|
522 |
|
|
break;
|
523 |
|
|
case CYGNUM_SERIAL_PARITY_EVEN:
|
524 |
|
|
sccxr |= (cyg_uint16)MPC555_SERIAL_SCCxR1_PE;
|
525 |
|
|
sccxr &= ~((cyg_uint16)MPC555_SERIAL_SCCxR1_PT);
|
526 |
|
|
break;
|
527 |
|
|
case CYGNUM_SERIAL_PARITY_ODD:
|
528 |
|
|
sccxr |= (cyg_uint16)MPC555_SERIAL_SCCxR1_PE;
|
529 |
|
|
sccxr |= (cyg_uint16)MPC555_SERIAL_SCCxR1_PT;
|
530 |
|
|
break;
|
531 |
|
|
default:
|
532 |
|
|
break;
|
533 |
|
|
}
|
534 |
|
|
HAL_WRITE_UINT16(port + MPC555_SERIAL_SCCxR1, sccxr);
|
535 |
|
|
|
536 |
|
|
// Set baud rate.
|
537 |
|
|
baud_rate &= ~((cyg_uint16)MPC555_SERIAL_SCCxR0_OTHR);
|
538 |
|
|
baud_rate &= ~((cyg_uint16)MPC555_SERIAL_SCCxR0_LINKBD);
|
539 |
|
|
HAL_READ_UINT16(port + MPC555_SERIAL_SCCxR0, sccxr);
|
540 |
|
|
sccxr &= ~(MPC555_SERIAL_SCCxR0_SCxBR);
|
541 |
|
|
sccxr |= baud_rate;
|
542 |
|
|
HAL_WRITE_UINT16(port + MPC555_SERIAL_SCCxR0, sccxr);
|
543 |
|
|
|
544 |
|
|
// Enable the device
|
545 |
|
|
HAL_READ_UINT16(port + MPC555_SERIAL_SCCxR1, sccxr);
|
546 |
|
|
sccxr |= MPC555_SERIAL_SCCxR1_TE;
|
547 |
|
|
sccxr |= MPC555_SERIAL_SCCxR1_RE;
|
548 |
|
|
HAL_WRITE_UINT16(port + MPC555_SERIAL_SCCxR1, sccxr);
|
549 |
|
|
|
550 |
|
|
if(init){
|
551 |
|
|
#ifdef CYGDAT_IO_SERIAL_POWERPC_MPC555_SERIAL_A_USE_HWARE_QUEUE
|
552 |
|
|
HAL_READ_UINT16(port + MPC555_SERIAL_SCCxR1, sccxr);
|
553 |
|
|
if(mpc555_chan->use_queue){
|
554 |
|
|
cyg_uint16 qsci1sr;
|
555 |
|
|
// enable read queue
|
556 |
|
|
qsci1cr |= ((cyg_uint16)CYGARC_REG_IMM_QSCI1CR_QRE);
|
557 |
|
|
// enable receive queue interrupts
|
558 |
|
|
qsci1cr |= ((cyg_uint16)CYGARC_REG_IMM_QSCI1CR_QTHFI);
|
559 |
|
|
qsci1cr |= ((cyg_uint16)CYGARC_REG_IMM_QSCI1CR_QBHFI);
|
560 |
|
|
HAL_WRITE_UINT16( CYGARC_REG_IMM_QSCI1CR, qsci1cr);
|
561 |
|
|
// also enable idle line detect interrupt
|
562 |
|
|
sccxr |= MPC555_SERIAL_SCxSR_IDLE;
|
563 |
|
|
HAL_READ_UINT16( CYGARC_REG_IMM_QSCI1SR, qsci1sr);
|
564 |
|
|
qsci1sr &= ~((cyg_uint16)CYGARC_REG_IMM_QSCI1SR_QBHF);
|
565 |
|
|
qsci1sr &= ~((cyg_uint16)CYGARC_REG_IMM_QSCI1SR_QTHF);
|
566 |
|
|
HAL_WRITE_UINT16(CYGARC_REG_IMM_QSCI1SR, qsci1sr);
|
567 |
|
|
}
|
568 |
|
|
else {
|
569 |
|
|
// enable the receiver interrupt
|
570 |
|
|
sccxr |= MPC555_SERIAL_SCCxR1_RIE;
|
571 |
|
|
}
|
572 |
|
|
HAL_WRITE_UINT16(port + MPC555_SERIAL_SCCxR1, sccxr);
|
573 |
|
|
#else
|
574 |
|
|
// enable the receiver interrupt
|
575 |
|
|
HAL_READ_UINT16(port + MPC555_SERIAL_SCCxR1, sccxr);
|
576 |
|
|
sccxr |= MPC555_SERIAL_SCCxR1_RIE;
|
577 |
|
|
HAL_WRITE_UINT16(port + MPC555_SERIAL_SCCxR1, sccxr);
|
578 |
|
|
#endif
|
579 |
|
|
}
|
580 |
|
|
else {// Restore the old interrupt state
|
581 |
|
|
|
582 |
|
|
HAL_READ_UINT16(port + MPC555_SERIAL_SCCxR1, sccxr);
|
583 |
|
|
sccxr |= old_isrstate;
|
584 |
|
|
HAL_WRITE_UINT16(port + MPC555_SERIAL_SCCxR1, sccxr);
|
585 |
|
|
}
|
586 |
|
|
|
587 |
|
|
if(new_config != &chan->config)
|
588 |
|
|
chan->config = *new_config;
|
589 |
|
|
|
590 |
|
|
return true;
|
591 |
|
|
}
|
592 |
|
|
|
593 |
|
|
//------------------------------------------------------------------------------
|
594 |
|
|
// Function to initialize the device. Called at bootstrap time.
|
595 |
|
|
//------------------------------------------------------------------------------
|
596 |
|
|
static hal_mpc5xx_arbitration_data arbiter;
|
597 |
|
|
static bool mpc555_serial_init(struct cyg_devtab_entry * tab){
|
598 |
|
|
serial_channel * chan = (serial_channel *)tab->priv;
|
599 |
|
|
mpc555_serial_info * mpc555_chan = (mpc555_serial_info *)chan->dev_priv;
|
600 |
|
|
|
601 |
|
|
if(!mpc555_serial_config_port(chan, &chan->config, true))
|
602 |
|
|
return false;
|
603 |
|
|
|
604 |
|
|
// Really only required for interrupt driven devices
|
605 |
|
|
(chan->callbacks->serial_init)(chan);
|
606 |
|
|
if(chan->out_cbuf.len != 0){
|
607 |
|
|
arbiter.priority = CYGNUM_HAL_ISR_SOURCE_PRIORITY_QSCI;
|
608 |
|
|
arbiter.data = 0;
|
609 |
|
|
arbiter.arbiter = hal_arbitration_isr_qsci;
|
610 |
|
|
|
611 |
|
|
// Install the arbitration isr, Make sure that is is not installed twice
|
612 |
|
|
hal_mpc5xx_remove_arbitration_isr(CYGNUM_HAL_ISR_SOURCE_PRIORITY_QSCI);
|
613 |
|
|
hal_mpc5xx_install_arbitration_isr(&arbiter);
|
614 |
|
|
|
615 |
|
|
// if !(Chan_B && using queue)
|
616 |
|
|
if(!mpc555_chan->use_queue){
|
617 |
|
|
mpc555_chan->rx_circbuf->fill_pos = 0;
|
618 |
|
|
mpc555_chan->rx_circbuf->read_pos = 0;
|
619 |
|
|
|
620 |
|
|
// Create the Tx interrupt, do not enable it yet
|
621 |
|
|
cyg_drv_interrupt_create(mpc555_chan->tx_interrupt_num,
|
622 |
|
|
mpc555_chan->tx_interrupt_priority,
|
623 |
|
|
(cyg_addrword_t)chan,//Data item passed to isr
|
624 |
|
|
mpc555_serial_tx_ISR,
|
625 |
|
|
mpc555_serial_tx_DSR,
|
626 |
|
|
&mpc555_chan->tx_interrupt_handle,
|
627 |
|
|
&mpc555_chan->tx_interrupt);
|
628 |
|
|
cyg_drv_interrupt_attach(mpc555_chan->tx_interrupt_handle);
|
629 |
|
|
|
630 |
|
|
// Create the Rx interrupt, this can be safely unmasked now
|
631 |
|
|
cyg_drv_interrupt_create(mpc555_chan->rx_interrupt_num,
|
632 |
|
|
mpc555_chan->rx_interrupt_priority,
|
633 |
|
|
(cyg_addrword_t)chan,
|
634 |
|
|
mpc555_serial_rx_ISR,
|
635 |
|
|
mpc555_serial_rx_DSR,
|
636 |
|
|
&mpc555_chan->rx_interrupt_handle,
|
637 |
|
|
&mpc555_chan->rx_interrupt);
|
638 |
|
|
cyg_drv_interrupt_attach(mpc555_chan->rx_interrupt_handle);
|
639 |
|
|
cyg_drv_interrupt_unmask(mpc555_chan->rx_interrupt_num);
|
640 |
|
|
}
|
641 |
|
|
#ifdef CYGDAT_IO_SERIAL_POWERPC_MPC555_SERIAL_A_USE_HWARE_QUEUE
|
642 |
|
|
else {// Use HW queue
|
643 |
|
|
// Create the Tx interrupt, do not enable it yet
|
644 |
|
|
cyg_drv_interrupt_create(mpc555_chan->tx_interrupt_queue_top_empty_num,
|
645 |
|
|
mpc555_chan->tx_interrupt_queue_top_empty_priority,
|
646 |
|
|
(cyg_addrword_t)chan,//Data item passed to isr
|
647 |
|
|
mpc555_serial_tx_queue_top_ISR,
|
648 |
|
|
mpc555_serial_tx_queue_DSR,
|
649 |
|
|
&mpc555_chan->tx_queue_top_interrupt_handle,
|
650 |
|
|
&mpc555_chan->tx_queue_top_interrupt);
|
651 |
|
|
cyg_drv_interrupt_attach(mpc555_chan->tx_queue_top_interrupt_handle);
|
652 |
|
|
|
653 |
|
|
|
654 |
|
|
cyg_drv_interrupt_create(mpc555_chan->tx_interrupt_queue_bot_empty_num,
|
655 |
|
|
mpc555_chan->tx_interrupt_queue_bot_empty_priority,
|
656 |
|
|
(cyg_addrword_t)chan,//Data passed to isr
|
657 |
|
|
mpc555_serial_tx_queue_bot_ISR,
|
658 |
|
|
mpc555_serial_tx_queue_DSR,
|
659 |
|
|
&mpc555_chan->tx_queue_bot_interrupt_handle,
|
660 |
|
|
&mpc555_chan->tx_queue_bot_interrupt);
|
661 |
|
|
cyg_drv_interrupt_attach(mpc555_chan->tx_queue_bot_interrupt_handle);
|
662 |
|
|
|
663 |
|
|
// Rx queue interrupts
|
664 |
|
|
cyg_drv_interrupt_create(mpc555_chan->rx_interrupt_queue_top_full_num,
|
665 |
|
|
mpc555_chan->rx_interrupt_queue_top_full_priority,
|
666 |
|
|
(cyg_addrword_t)chan,//Data item passed to isr
|
667 |
|
|
mpc555_serial_rx_queue_top_ISR,
|
668 |
|
|
mpc555_serial_rx_queue_DSR,
|
669 |
|
|
&mpc555_chan->rx_queue_top_interrupt_handle,
|
670 |
|
|
&mpc555_chan->rx_queue_top_interrupt);
|
671 |
|
|
cyg_drv_interrupt_attach(mpc555_chan->rx_queue_top_interrupt_handle);
|
672 |
|
|
|
673 |
|
|
cyg_drv_interrupt_create(mpc555_chan->rx_interrupt_queue_bot_full_num,
|
674 |
|
|
mpc555_chan->rx_interrupt_queue_bot_full_priority,
|
675 |
|
|
(cyg_addrword_t)chan,//Data item passed to isr
|
676 |
|
|
mpc555_serial_rx_queue_bot_ISR,
|
677 |
|
|
mpc555_serial_rx_queue_DSR,
|
678 |
|
|
&mpc555_chan->rx_queue_bot_interrupt_handle,
|
679 |
|
|
&mpc555_chan->rx_queue_bot_interrupt);
|
680 |
|
|
cyg_drv_interrupt_attach(mpc555_chan->rx_queue_bot_interrupt_handle);
|
681 |
|
|
|
682 |
|
|
cyg_drv_interrupt_create(mpc555_chan->rx_interrupt_idle_line_num,
|
683 |
|
|
mpc555_chan->rx_interrupt_idle_line_priority,
|
684 |
|
|
(cyg_addrword_t)chan,//Data item passed to isr
|
685 |
|
|
mpc555_serial_rx_idle_line_ISR,
|
686 |
|
|
mpc555_serial_rx_queue_DSR,
|
687 |
|
|
&mpc555_chan->rx_idle_interrupt_handle,
|
688 |
|
|
&mpc555_chan->rx_idle_interrupt);
|
689 |
|
|
cyg_drv_interrupt_attach(mpc555_chan->rx_idle_interrupt_handle);
|
690 |
|
|
}
|
691 |
|
|
#endif // use queue
|
692 |
|
|
}
|
693 |
|
|
return true;
|
694 |
|
|
}
|
695 |
|
|
|
696 |
|
|
//----------------------------------------------------------------------------
|
697 |
|
|
// This routine is called when the device is "looked" up (i.e. attached)
|
698 |
|
|
//----------------------------------------------------------------------------
|
699 |
|
|
static Cyg_ErrNo mpc555_serial_lookup(struct cyg_devtab_entry ** tab,
|
700 |
|
|
struct cyg_devtab_entry * sub_tab,
|
701 |
|
|
const char * name)
|
702 |
|
|
{
|
703 |
|
|
serial_channel * chan = (serial_channel *)(*tab)->priv;
|
704 |
|
|
//Really only required for interrupt driven devices
|
705 |
|
|
(chan->callbacks->serial_init)(chan);
|
706 |
|
|
|
707 |
|
|
return ENOERR;
|
708 |
|
|
}
|
709 |
|
|
|
710 |
|
|
//----------------------------------------------------------------------------
|
711 |
|
|
// Send a character to the device output buffer.
|
712 |
|
|
// Return 'true' if character is sent to device
|
713 |
|
|
//----------------------------------------------------------------------------
|
714 |
|
|
static bool mpc555_serial_putc(serial_channel * chan, unsigned char c){
|
715 |
|
|
mpc555_serial_info * mpc555_chan = (mpc555_serial_info *)chan->dev_priv;
|
716 |
|
|
cyg_addrword_t port = mpc555_chan->base;
|
717 |
|
|
|
718 |
|
|
cyg_uint16 scsr;
|
719 |
|
|
cyg_uint16 scdr;
|
720 |
|
|
|
721 |
|
|
HAL_READ_UINT16(port + MPC555_SERIAL_SCxSR, scsr);
|
722 |
|
|
if(scsr & MPC555_SERIAL_SCxSR_TDRE){
|
723 |
|
|
// Ok, we have space, write the character and return success
|
724 |
|
|
scdr = (cyg_uint16)c;
|
725 |
|
|
HAL_WRITE_UINT16(port + MPC555_SERIAL_SCxDR, scdr);
|
726 |
|
|
return true;
|
727 |
|
|
}
|
728 |
|
|
else
|
729 |
|
|
// We cannot write to the transmitter, return failure
|
730 |
|
|
return false;
|
731 |
|
|
}
|
732 |
|
|
|
733 |
|
|
//----------------------------------------------------------------------------
|
734 |
|
|
// Fetch a character from the device input buffer, waiting if necessary
|
735 |
|
|
//----------------------------------------------------------------------------
|
736 |
|
|
static unsigned char mpc555_serial_getc(serial_channel * chan){
|
737 |
|
|
unsigned char c;
|
738 |
|
|
mpc555_serial_info * mpc555_chan = (mpc555_serial_info *)chan->dev_priv;
|
739 |
|
|
cyg_addrword_t port = mpc555_chan->base;
|
740 |
|
|
|
741 |
|
|
cyg_uint16 scsr;
|
742 |
|
|
cyg_uint16 scdr;
|
743 |
|
|
|
744 |
|
|
do {
|
745 |
|
|
HAL_READ_UINT16(port + MPC555_SERIAL_SCxSR, scsr);
|
746 |
|
|
} while(!(scsr & MPC555_SERIAL_SCxSR_RDRF));
|
747 |
|
|
|
748 |
|
|
// Ok, data is received, read it out and return
|
749 |
|
|
HAL_READ_UINT16(port + MPC555_SERIAL_SCxDR, scdr);
|
750 |
|
|
c = (unsigned char)scdr;
|
751 |
|
|
|
752 |
|
|
return c;
|
753 |
|
|
}
|
754 |
|
|
|
755 |
|
|
//----------------------------------------------------------------------------
|
756 |
|
|
// Set up the device characteristics; baud rate, etc.
|
757 |
|
|
//----------------------------------------------------------------------------
|
758 |
|
|
static bool mpc555_serial_set_config(serial_channel * chan, cyg_uint32 key,
|
759 |
|
|
const void *xbuf, cyg_uint32 * len)
|
760 |
|
|
{
|
761 |
|
|
switch(key){
|
762 |
|
|
case CYG_IO_SET_CONFIG_SERIAL_INFO:{
|
763 |
|
|
cyg_serial_info_t *config = (cyg_serial_info_t *)xbuf;
|
764 |
|
|
if(*len < sizeof(cyg_serial_info_t)){
|
765 |
|
|
return -EINVAL;
|
766 |
|
|
}
|
767 |
|
|
*len = sizeof(cyg_serial_info_t);
|
768 |
|
|
if(true != mpc555_serial_config_port(chan, config, false))
|
769 |
|
|
return -EINVAL;
|
770 |
|
|
}
|
771 |
|
|
break;
|
772 |
|
|
default:
|
773 |
|
|
return -EINVAL;
|
774 |
|
|
}
|
775 |
|
|
return ENOERR;
|
776 |
|
|
}
|
777 |
|
|
|
778 |
|
|
//------------------------------------------------------------------------------
|
779 |
|
|
// Enable the transmitter on the device
|
780 |
|
|
//------------------------------------------------------------------------------
|
781 |
|
|
static void mpc555_serial_start_xmit(serial_channel * chan)
|
782 |
|
|
{
|
783 |
|
|
mpc555_serial_info * mpc555_chan = (mpc555_serial_info *)chan->dev_priv;
|
784 |
|
|
#ifdef CYGDAT_IO_SERIAL_POWERPC_MPC555_SERIAL_A_USE_HWARE_QUEUE
|
785 |
|
|
cyg_addrword_t port = mpc555_chan->base;
|
786 |
|
|
if(mpc555_chan->use_queue){
|
787 |
|
|
cyg_uint16 qscicr;
|
788 |
|
|
cyg_uint16 qscisr;
|
789 |
|
|
cyg_uint16 scsr;
|
790 |
|
|
|
791 |
|
|
int chars_avail;
|
792 |
|
|
unsigned char* chars;
|
793 |
|
|
int block_index = 0;
|
794 |
|
|
cyg_addrword_t i;
|
795 |
|
|
cyg_uint16 queue_transfer;
|
796 |
|
|
|
797 |
|
|
if(!(mpc555_chan->tx_interrupt_enable) &&
|
798 |
|
|
(chan->callbacks->data_xmt_req)(chan, 32, &chars_avail, &chars)
|
799 |
|
|
== CYG_XMT_OK){
|
800 |
|
|
queue_transfer = (chars_avail > 16) ? 16 : chars_avail;
|
801 |
|
|
|
802 |
|
|
HAL_READ_UINT16( CYGARC_REG_IMM_QSCI1CR, qscicr);
|
803 |
|
|
// Write QTSZ for first pass through the queue
|
804 |
|
|
qscicr &= ~(CYGARC_REG_IMM_QSCI1CR_QTSZ);
|
805 |
|
|
qscicr |= (CYGARC_REG_IMM_QSCI1CR_QTSZ & (queue_transfer - 1));
|
806 |
|
|
HAL_WRITE_UINT16( CYGARC_REG_IMM_QSCI1CR, qscicr);
|
807 |
|
|
// Read SC1SR to clear TC bit when followed by a write of sctq
|
808 |
|
|
HAL_READ_UINT16(port + MPC555_SERIAL_SCxSR, scsr);
|
809 |
|
|
|
810 |
|
|
for(i=0; i < queue_transfer; i++){
|
811 |
|
|
HAL_WRITE_UINT16(CYGARC_REG_IMM_SCTQ + (i * 2), chars[block_index]);
|
812 |
|
|
++block_index;
|
813 |
|
|
}
|
814 |
|
|
chan->callbacks->data_xmt_done(chan, queue_transfer);
|
815 |
|
|
|
816 |
|
|
// clear QTHE and QBHE
|
817 |
|
|
HAL_READ_UINT16(CYGARC_REG_IMM_QSCI1SR, qscisr);
|
818 |
|
|
|
819 |
|
|
qscisr &= ~(CYGARC_REG_IMM_QSCI1SR_QTHE);
|
820 |
|
|
HAL_WRITE_UINT16(CYGARC_REG_IMM_QSCI1SR, qscisr);
|
821 |
|
|
if(queue_transfer > 8){
|
822 |
|
|
qscisr &= ~(CYGARC_REG_IMM_QSCI1SR_QBHE);
|
823 |
|
|
HAL_WRITE_UINT16(CYGARC_REG_IMM_QSCI1SR, qscisr);
|
824 |
|
|
}
|
825 |
|
|
|
826 |
|
|
mpc555_chan->tx_interrupt_enable = true;
|
827 |
|
|
|
828 |
|
|
cyg_drv_interrupt_unmask(mpc555_chan->tx_interrupt_queue_top_empty_num);
|
829 |
|
|
if(queue_transfer > 8){
|
830 |
|
|
cyg_drv_interrupt_unmask(mpc555_chan->tx_interrupt_queue_bot_empty_num);
|
831 |
|
|
}
|
832 |
|
|
|
833 |
|
|
HAL_READ_UINT16( CYGARC_REG_IMM_QSCI1CR, qscicr);
|
834 |
|
|
qscicr |= ((cyg_uint16)CYGARC_REG_IMM_QSCI1CR_QTE);
|
835 |
|
|
HAL_WRITE_UINT16( CYGARC_REG_IMM_QSCI1CR, qscicr);
|
836 |
|
|
}
|
837 |
|
|
}
|
838 |
|
|
else { // no queue
|
839 |
|
|
mpc555_chan->tx_interrupt_enable = true;
|
840 |
|
|
cyg_drv_interrupt_unmask(mpc555_chan->tx_interrupt_num);
|
841 |
|
|
// No need to call xmt_char, this will generate an interrupt immediately.
|
842 |
|
|
}
|
843 |
|
|
#else // No queue
|
844 |
|
|
mpc555_chan->tx_interrupt_enable = true;
|
845 |
|
|
cyg_drv_interrupt_unmask(mpc555_chan->tx_interrupt_num);
|
846 |
|
|
// No need to call xmt_char, this will generate an interrupt immediately.
|
847 |
|
|
#endif
|
848 |
|
|
}
|
849 |
|
|
|
850 |
|
|
//----------------------------------------------------------------------------
|
851 |
|
|
// Disable the transmitter on the device
|
852 |
|
|
//----------------------------------------------------------------------------
|
853 |
|
|
static void mpc555_serial_stop_xmit(serial_channel * chan){
|
854 |
|
|
mpc555_serial_info * mpc555_chan = (mpc555_serial_info *)chan->dev_priv;
|
855 |
|
|
|
856 |
|
|
if(!mpc555_chan->use_queue){
|
857 |
|
|
cyg_drv_dsr_lock();
|
858 |
|
|
mpc555_chan->tx_interrupt_enable = false;
|
859 |
|
|
cyg_drv_interrupt_mask(mpc555_chan->tx_interrupt_num);
|
860 |
|
|
cyg_drv_dsr_unlock();
|
861 |
|
|
}
|
862 |
|
|
}
|
863 |
|
|
|
864 |
|
|
//----------------------------------------------------------------------------
|
865 |
|
|
// The low level transmit interrupt handler
|
866 |
|
|
//----------------------------------------------------------------------------
|
867 |
|
|
static cyg_uint32 mpc555_serial_tx_ISR(cyg_vector_t vector,
|
868 |
|
|
cyg_addrword_t data){
|
869 |
|
|
serial_channel * chan = (serial_channel *)data;
|
870 |
|
|
mpc555_serial_info * mpc555_chan = (mpc555_serial_info *)chan->dev_priv;
|
871 |
|
|
|
872 |
|
|
cyg_drv_interrupt_mask(mpc555_chan->tx_interrupt_num);
|
873 |
|
|
cyg_drv_interrupt_acknowledge(mpc555_chan->tx_interrupt_num);
|
874 |
|
|
|
875 |
|
|
return CYG_ISR_CALL_DSR; // cause the DSR to run
|
876 |
|
|
}
|
877 |
|
|
|
878 |
|
|
//----------------------------------------------------------------------------
|
879 |
|
|
// The low level receive interrupt handler
|
880 |
|
|
//----------------------------------------------------------------------------
|
881 |
|
|
static cyg_uint32 mpc555_serial_rx_ISR(cyg_vector_t vector,
|
882 |
|
|
cyg_addrword_t data){
|
883 |
|
|
serial_channel * chan = (serial_channel *)data;
|
884 |
|
|
mpc555_serial_info * mpc555_chan = (mpc555_serial_info *)chan->dev_priv;
|
885 |
|
|
|
886 |
|
|
cyg_drv_interrupt_mask(mpc555_chan->rx_interrupt_num);
|
887 |
|
|
cyg_drv_interrupt_acknowledge(mpc555_chan->rx_interrupt_num);
|
888 |
|
|
|
889 |
|
|
cyg_addrword_t port = mpc555_chan->base;
|
890 |
|
|
cyg_uint16 scdr;
|
891 |
|
|
cyg_uint16 scsr;
|
892 |
|
|
|
893 |
|
|
HAL_READ_UINT16(port + MPC555_SERIAL_SCxSR, scsr);
|
894 |
|
|
// Always read out the received character, in order to clear receiver flags
|
895 |
|
|
HAL_READ_UINT16(port + MPC555_SERIAL_SCxDR, scdr);
|
896 |
|
|
|
897 |
|
|
mpc555_chan->rx_circbuf->scsr[mpc555_chan->rx_circbuf->fill_pos] = scsr;
|
898 |
|
|
mpc555_chan->rx_circbuf->buf[mpc555_chan->rx_circbuf->fill_pos] = (cyg_uint8)scdr;
|
899 |
|
|
|
900 |
|
|
if(mpc555_chan->rx_circbuf->fill_pos < MPC555_SCI_RX_BUFF_SIZE - 1){
|
901 |
|
|
mpc555_chan->rx_circbuf->fill_pos = mpc555_chan->rx_circbuf->fill_pos + 1;
|
902 |
|
|
}
|
903 |
|
|
else {
|
904 |
|
|
mpc555_chan->rx_circbuf->fill_pos = 0;
|
905 |
|
|
}
|
906 |
|
|
cyg_drv_interrupt_unmask(mpc555_chan->rx_interrupt_num);
|
907 |
|
|
return CYG_ISR_CALL_DSR; // cause the DSR to run
|
908 |
|
|
}
|
909 |
|
|
|
910 |
|
|
#ifdef CYGPKG_IO_SERIAL_POWERPC_MPC555_SERIAL_A
|
911 |
|
|
//----------------------------------------------------------------------------
|
912 |
|
|
// The low level queued receive interrupt handlers
|
913 |
|
|
//----------------------------------------------------------------------------
|
914 |
|
|
static cyg_uint32 mpc555_serial_rx_queue_top_ISR(cyg_vector_t vector,
|
915 |
|
|
cyg_addrword_t data){
|
916 |
|
|
serial_channel * chan = (serial_channel *)data;
|
917 |
|
|
mpc555_serial_info * mpc555_chan = (mpc555_serial_info *)chan->dev_priv;
|
918 |
|
|
|
919 |
|
|
cyg_drv_interrupt_mask(mpc555_chan->rx_interrupt_queue_top_full_num);
|
920 |
|
|
cyg_drv_interrupt_acknowledge(mpc555_chan->rx_interrupt_queue_top_full_num);
|
921 |
|
|
|
922 |
|
|
return CYG_ISR_CALL_DSR; // cause the DSR to run
|
923 |
|
|
}
|
924 |
|
|
|
925 |
|
|
static cyg_uint32 mpc555_serial_rx_queue_bot_ISR(cyg_vector_t vector,
|
926 |
|
|
cyg_addrword_t data){
|
927 |
|
|
serial_channel* chan = (serial_channel *)data;
|
928 |
|
|
mpc555_serial_info* mpc555_chan = (mpc555_serial_info *)chan->dev_priv;
|
929 |
|
|
|
930 |
|
|
cyg_drv_interrupt_mask(mpc555_chan->rx_interrupt_queue_bot_full_num);
|
931 |
|
|
cyg_drv_interrupt_acknowledge(mpc555_chan->rx_interrupt_queue_bot_full_num);
|
932 |
|
|
|
933 |
|
|
return CYG_ISR_CALL_DSR; // cause the DSR to run
|
934 |
|
|
}
|
935 |
|
|
|
936 |
|
|
// This is used to flush the queue when the line falls idle
|
937 |
|
|
static cyg_uint32 mpc555_serial_rx_idle_line_ISR(cyg_vector_t vector,
|
938 |
|
|
cyg_addrword_t data){
|
939 |
|
|
serial_channel* chan = (serial_channel *)data;
|
940 |
|
|
mpc555_serial_info* mpc555_chan = (mpc555_serial_info *)chan->dev_priv;
|
941 |
|
|
|
942 |
|
|
cyg_drv_interrupt_mask(mpc555_chan->rx_interrupt_idle_line_num);
|
943 |
|
|
cyg_drv_interrupt_acknowledge(mpc555_chan->rx_interrupt_idle_line_num);
|
944 |
|
|
|
945 |
|
|
return CYG_ISR_CALL_DSR; // cause the DSR to run
|
946 |
|
|
}
|
947 |
|
|
|
948 |
|
|
//----------------------------------------------------------------------------
|
949 |
|
|
// The low level queued transmit interrupt handlers
|
950 |
|
|
//----------------------------------------------------------------------------
|
951 |
|
|
static cyg_uint32 mpc555_serial_tx_queue_top_ISR(cyg_vector_t vector,
|
952 |
|
|
cyg_addrword_t data){
|
953 |
|
|
serial_channel * chan = (serial_channel *)data;
|
954 |
|
|
mpc555_serial_info * mpc555_chan = (mpc555_serial_info *)chan->dev_priv;
|
955 |
|
|
|
956 |
|
|
cyg_drv_interrupt_mask(mpc555_chan->tx_interrupt_queue_top_empty_num);
|
957 |
|
|
cyg_drv_interrupt_acknowledge(mpc555_chan->tx_interrupt_queue_top_empty_num);
|
958 |
|
|
|
959 |
|
|
return CYG_ISR_CALL_DSR; // cause the DSR to run
|
960 |
|
|
}
|
961 |
|
|
|
962 |
|
|
static cyg_uint32 mpc555_serial_tx_queue_bot_ISR(cyg_vector_t vector,
|
963 |
|
|
cyg_addrword_t data){
|
964 |
|
|
serial_channel * chan = (serial_channel *)data;
|
965 |
|
|
mpc555_serial_info * mpc555_chan = (mpc555_serial_info *)chan->dev_priv;
|
966 |
|
|
|
967 |
|
|
cyg_drv_interrupt_mask(mpc555_chan->tx_interrupt_queue_bot_empty_num);
|
968 |
|
|
cyg_drv_interrupt_acknowledge(mpc555_chan->tx_interrupt_queue_bot_empty_num);
|
969 |
|
|
|
970 |
|
|
return CYG_ISR_CALL_DSR; // cause the DSR to run
|
971 |
|
|
}
|
972 |
|
|
#endif // SERIAL_A
|
973 |
|
|
|
974 |
|
|
//----------------------------------------------------------------------------
|
975 |
|
|
// The high level transmit interrupt handler
|
976 |
|
|
//----------------------------------------------------------------------------
|
977 |
|
|
static void mpc555_serial_tx_DSR(cyg_vector_t vector, cyg_ucount32 count,
|
978 |
|
|
cyg_addrword_t data){
|
979 |
|
|
serial_channel * chan = (serial_channel *)data;
|
980 |
|
|
mpc555_serial_info * mpc555_chan = (mpc555_serial_info *)chan->dev_priv;
|
981 |
|
|
|
982 |
|
|
(chan->callbacks->xmt_char)(chan);
|
983 |
|
|
if(mpc555_chan->tx_interrupt_enable)
|
984 |
|
|
cyg_drv_interrupt_unmask(mpc555_chan->tx_interrupt_num);
|
985 |
|
|
}
|
986 |
|
|
|
987 |
|
|
//----------------------------------------------------------------------------
|
988 |
|
|
// The high level receive interrupt handler
|
989 |
|
|
//----------------------------------------------------------------------------
|
990 |
|
|
#define MPC555_SERIAL_SCxSR_ERRORS (MPC555_SERIAL_SCxSR_OR | \
|
991 |
|
|
MPC555_SERIAL_SCxSR_NF | \
|
992 |
|
|
MPC555_SERIAL_SCxSR_FE | \
|
993 |
|
|
MPC555_SERIAL_SCxSR_PF)
|
994 |
|
|
|
995 |
|
|
static void mpc555_serial_rx_DSR(cyg_vector_t vector, cyg_ucount32 count,
|
996 |
|
|
cyg_addrword_t data){
|
997 |
|
|
serial_channel * chan = (serial_channel *)data;
|
998 |
|
|
mpc555_serial_info * mpc555_chan = (mpc555_serial_info *)chan->dev_priv;
|
999 |
|
|
// cyg_addrword_t port = mpc555_chan->base;
|
1000 |
|
|
// cyg_uint16 scdr;
|
1001 |
|
|
cyg_uint16 scsr;
|
1002 |
|
|
|
1003 |
|
|
#ifdef CYGOPT_IO_SERIAL_SUPPORT_LINE_STATUS
|
1004 |
|
|
cyg_serial_line_status_t stat;
|
1005 |
|
|
#endif
|
1006 |
|
|
|
1007 |
|
|
|
1008 |
|
|
int i = mpc555_chan->rx_circbuf->read_pos;
|
1009 |
|
|
while (i < mpc555_chan->rx_circbuf->fill_pos){
|
1010 |
|
|
scsr = mpc555_chan->rx_circbuf->scsr[i];
|
1011 |
|
|
if(scsr & (cyg_uint16)MPC555_SERIAL_SCxSR_ERRORS){
|
1012 |
|
|
#ifdef CYGOPT_IO_SERIAL_SUPPORT_LINE_STATUS
|
1013 |
|
|
if(scsr & MPC555_SERIAL_SCxSR_OR){
|
1014 |
|
|
stat.which = CYGNUM_SERIAL_STATUS_OVERRUNERR;
|
1015 |
|
|
(chan->callbacks->indicate_status)(chan, &stat);
|
1016 |
|
|
// The current byte is still valid when OR is set
|
1017 |
|
|
(chan->callbacks->rcv_char)(chan, mpc555_chan->rx_circbuf->buf[i]);
|
1018 |
|
|
}
|
1019 |
|
|
else { // OR is never set with any other error bits
|
1020 |
|
|
if(scsr & MPC555_SERIAL_SCxSR_NF){
|
1021 |
|
|
stat.which = CYGNUM_SERIAL_STATUS_NOISEERR;
|
1022 |
|
|
(chan->callbacks->indicate_status)(chan, &stat);
|
1023 |
|
|
}
|
1024 |
|
|
if(scsr & MPC555_SERIAL_SCxSR_FE){
|
1025 |
|
|
stat.which = CYGNUM_SERIAL_STATUS_FRAMEERR;
|
1026 |
|
|
(chan->callbacks->indicate_status)(chan, &stat);
|
1027 |
|
|
}
|
1028 |
|
|
if(scsr & MPC555_SERIAL_SCxSR_PF){
|
1029 |
|
|
stat.which = CYGNUM_SERIAL_STATUS_PARITYERR;
|
1030 |
|
|
(chan->callbacks->indicate_status)(chan, &stat);
|
1031 |
|
|
}
|
1032 |
|
|
}
|
1033 |
|
|
#endif
|
1034 |
|
|
}
|
1035 |
|
|
else {
|
1036 |
|
|
(chan->callbacks->rcv_char)(chan, mpc555_chan->rx_circbuf->buf[i]);
|
1037 |
|
|
}
|
1038 |
|
|
++i;
|
1039 |
|
|
}
|
1040 |
|
|
|
1041 |
|
|
cyg_drv_isr_lock();
|
1042 |
|
|
mpc555_chan->rx_circbuf->fill_pos = 0;
|
1043 |
|
|
mpc555_chan->rx_circbuf->read_pos = 0;
|
1044 |
|
|
cyg_drv_isr_unlock();
|
1045 |
|
|
}
|
1046 |
|
|
|
1047 |
|
|
#ifdef CYGPKG_IO_SERIAL_POWERPC_MPC555_SERIAL_A
|
1048 |
|
|
//----------------------------------------------------------------------------
|
1049 |
|
|
// The high level queued transmit interrupt handler
|
1050 |
|
|
//----------------------------------------------------------------------------
|
1051 |
|
|
static void mpc555_serial_tx_queue_DSR(cyg_vector_t vector, cyg_ucount32 count,
|
1052 |
|
|
cyg_addrword_t data){
|
1053 |
|
|
serial_channel * chan = (serial_channel *)data;
|
1054 |
|
|
mpc555_serial_info * mpc555_chan = (mpc555_serial_info *)chan->dev_priv;
|
1055 |
|
|
bool QTHE = false;
|
1056 |
|
|
bool QBHE = false;
|
1057 |
|
|
cyg_uint16 qscisr;
|
1058 |
|
|
cyg_uint16 qscicr;
|
1059 |
|
|
HAL_READ_UINT16(CYGARC_REG_IMM_QSCI1SR, qscisr);
|
1060 |
|
|
QTHE = (qscisr & CYGARC_REG_IMM_QSCI1SR_QTHE) ? true : false;
|
1061 |
|
|
QBHE = (qscisr & CYGARC_REG_IMM_QSCI1SR_QBHE) ? true : false;
|
1062 |
|
|
|
1063 |
|
|
CYG_ASSERT(QTHE || QBHE,"In tx queue DSR for no reason");
|
1064 |
|
|
|
1065 |
|
|
HAL_READ_UINT16(CYGARC_REG_IMM_QSCI1CR, qscicr);
|
1066 |
|
|
int chars_avail;
|
1067 |
|
|
unsigned char* chars;
|
1068 |
|
|
int block_index = 0;
|
1069 |
|
|
cyg_addrword_t i;
|
1070 |
|
|
cyg_uint16 queue_transfer;
|
1071 |
|
|
xmt_req_reply_t result = (chan->callbacks->data_xmt_req)(chan, 24, &chars_avail, &chars);
|
1072 |
|
|
if(CYG_XMT_OK == result){
|
1073 |
|
|
queue_transfer = (chars_avail > 8) ? 8 : chars_avail;
|
1074 |
|
|
if(QTHE){
|
1075 |
|
|
for(i=0; i < queue_transfer; i++){
|
1076 |
|
|
HAL_WRITE_UINT16(CYGARC_REG_IMM_SCTQ + (i * 2), chars[block_index]);
|
1077 |
|
|
++block_index;
|
1078 |
|
|
}
|
1079 |
|
|
chan->callbacks->data_xmt_done(chan, queue_transfer);
|
1080 |
|
|
// Clear QTHE
|
1081 |
|
|
qscisr &= ~(CYGARC_REG_IMM_QSCI1SR_QTHE);
|
1082 |
|
|
HAL_WRITE_UINT16(CYGARC_REG_IMM_QSCI1SR, qscisr);
|
1083 |
|
|
|
1084 |
|
|
// Re-enable wrap QTWE
|
1085 |
|
|
HAL_READ_UINT16(CYGARC_REG_IMM_QSCI1CR, qscicr);
|
1086 |
|
|
qscicr |= ((cyg_uint16)CYGARC_REG_IMM_QSCI1CR_QTWE);
|
1087 |
|
|
HAL_WRITE_UINT16(CYGARC_REG_IMM_QSCI1CR, qscicr);
|
1088 |
|
|
HAL_READ_UINT16(CYGARC_REG_IMM_QSCI1CR, qscicr);
|
1089 |
|
|
// load QTSZ with how many chars *after* the next wrap
|
1090 |
|
|
cyg_uint16 next_time = (chars_avail) > 16 ? 15 : chars_avail -1;
|
1091 |
|
|
qscicr &= ~(CYGARC_REG_IMM_QSCI1CR_QTSZ);
|
1092 |
|
|
qscicr |= (CYGARC_REG_IMM_QSCI1CR_QTSZ & next_time);
|
1093 |
|
|
HAL_WRITE_UINT16(CYGARC_REG_IMM_QSCI1CR, qscicr);
|
1094 |
|
|
cyg_drv_interrupt_unmask(mpc555_chan->tx_interrupt_queue_top_empty_num);
|
1095 |
|
|
}
|
1096 |
|
|
else if(QBHE){
|
1097 |
|
|
for(i=8; i < queue_transfer + 8; i++){
|
1098 |
|
|
HAL_WRITE_UINT16(CYGARC_REG_IMM_SCTQ + (i * 2), chars[block_index]);
|
1099 |
|
|
++block_index;
|
1100 |
|
|
}
|
1101 |
|
|
chan->callbacks->data_xmt_done(chan, queue_transfer);
|
1102 |
|
|
// Clear QBHE
|
1103 |
|
|
qscisr &= ~(CYGARC_REG_IMM_QSCI1SR_QBHE);
|
1104 |
|
|
HAL_WRITE_UINT16(CYGARC_REG_IMM_QSCI1SR, qscisr);
|
1105 |
|
|
cyg_drv_interrupt_unmask(mpc555_chan->tx_interrupt_queue_bot_empty_num);
|
1106 |
|
|
}
|
1107 |
|
|
|
1108 |
|
|
}
|
1109 |
|
|
else if(CYG_XMT_EMPTY== result){
|
1110 |
|
|
// No more data
|
1111 |
|
|
cyg_drv_interrupt_mask(mpc555_chan->tx_interrupt_queue_top_empty_num);
|
1112 |
|
|
cyg_drv_interrupt_mask(mpc555_chan->tx_interrupt_queue_bot_empty_num);
|
1113 |
|
|
mpc555_chan->tx_interrupt_enable = false;
|
1114 |
|
|
|
1115 |
|
|
// Clear QTHE
|
1116 |
|
|
HAL_READ_UINT16(CYGARC_REG_IMM_QSCI1SR, qscisr);
|
1117 |
|
|
qscisr &= ~(CYGARC_REG_IMM_QSCI1SR_QTHE);
|
1118 |
|
|
HAL_WRITE_UINT16(CYGARC_REG_IMM_QSCI1SR, qscisr);
|
1119 |
|
|
}
|
1120 |
|
|
}
|
1121 |
|
|
|
1122 |
|
|
//----------------------------------------------------------------------------
|
1123 |
|
|
// The high level queued receive interrupt handler
|
1124 |
|
|
//----------------------------------------------------------------------------
|
1125 |
|
|
static void mpc555_serial_rx_queue_DSR(cyg_vector_t vector,
|
1126 |
|
|
cyg_ucount32 count, cyg_addrword_t data){
|
1127 |
|
|
serial_channel * chan = (serial_channel *)data;
|
1128 |
|
|
mpc555_serial_info * mpc555_chan = (mpc555_serial_info *)chan->dev_priv;
|
1129 |
|
|
cyg_addrword_t port = mpc555_chan->base;
|
1130 |
|
|
cyg_uint16 scrq;
|
1131 |
|
|
cyg_uint16 qscisr;
|
1132 |
|
|
cyg_uint16 scsr;
|
1133 |
|
|
cyg_uint16 scdr;
|
1134 |
|
|
bool QTHF = false;
|
1135 |
|
|
bool QBHF = false;
|
1136 |
|
|
bool idle = false;
|
1137 |
|
|
// Read status reg before reading any data otherwise NE flag will be lost
|
1138 |
|
|
HAL_READ_UINT16(port + MPC555_SERIAL_SCxSR, scsr);
|
1139 |
|
|
HAL_READ_UINT16(CYGARC_REG_IMM_QSCI1SR, qscisr);
|
1140 |
|
|
QTHF = (qscisr & CYGARC_REG_IMM_QSCI1SR_QTHF) ? true : false;
|
1141 |
|
|
QBHF = (qscisr & CYGARC_REG_IMM_QSCI1SR_QBHF) ? true : false;
|
1142 |
|
|
idle = (scsr & CYGARC_REG_IMM_SCxSR_IDLE)? true : false;
|
1143 |
|
|
// The queue pointer is the next place to be filled by incomming data
|
1144 |
|
|
cyg_uint16 queue_pointer = (qscisr & CYGARC_REG_IMM_QSCI1SR_QRPNT) >> 4;
|
1145 |
|
|
|
1146 |
|
|
int start;
|
1147 |
|
|
int space_req = 0;
|
1148 |
|
|
// Idle needs to be handled first as the IDLE bit will be cleared by a read of
|
1149 |
|
|
// scsr followed by a read of scrq[0:16]
|
1150 |
|
|
|
1151 |
|
|
if(queue_pointer > mpc555_chan->rx_last_queue_pointer){
|
1152 |
|
|
start = mpc555_chan->rx_last_queue_pointer;
|
1153 |
|
|
space_req = mpc555_serial_read_queue(chan, start, queue_pointer - 1);
|
1154 |
|
|
}
|
1155 |
|
|
else {// Its wrapped around
|
1156 |
|
|
if(mpc555_chan->rx_last_queue_pointer > queue_pointer){
|
1157 |
|
|
space_req = mpc555_serial_read_queue(chan, mpc555_chan->rx_last_queue_pointer,15);
|
1158 |
|
|
if(queue_pointer != 0){
|
1159 |
|
|
mpc555_serial_read_queue(chan, 0,queue_pointer -1);
|
1160 |
|
|
}
|
1161 |
|
|
}
|
1162 |
|
|
else // No new data to read, do nothing here
|
1163 |
|
|
{
|
1164 |
|
|
}
|
1165 |
|
|
}
|
1166 |
|
|
|
1167 |
|
|
mpc555_chan->rx_last_queue_pointer = queue_pointer;
|
1168 |
|
|
|
1169 |
|
|
if(CYGARC_REG_IMM_QSCI1SR_QOR & qscisr){
|
1170 |
|
|
// Need to re-enable the queue
|
1171 |
|
|
cyg_uint16 qscicr;
|
1172 |
|
|
HAL_READ_UINT16( CYGARC_REG_IMM_QSCI1CR, qscicr);
|
1173 |
|
|
qscicr |= ((cyg_uint16)CYGARC_REG_IMM_QSCI1CR_QRE);
|
1174 |
|
|
HAL_WRITE_UINT16( CYGARC_REG_IMM_QSCI1CR, qscicr);
|
1175 |
|
|
// Queue has overrun but data might not have been lost yet
|
1176 |
|
|
if(scsr & MPC555_SERIAL_SCxSR_OR){
|
1177 |
|
|
#ifdef CYGOPT_IO_SERIAL_SUPPORT_LINE_STATUS
|
1178 |
|
|
cyg_serial_line_status_t stat;
|
1179 |
|
|
stat.which = CYGNUM_SERIAL_STATUS_OVERRUNERR;
|
1180 |
|
|
(chan->callbacks->indicate_status)(chan, &stat);
|
1181 |
|
|
#endif
|
1182 |
|
|
}
|
1183 |
|
|
}
|
1184 |
|
|
|
1185 |
|
|
if(scsr & (cyg_uint16)MPC555_SERIAL_SCxSR_ERRORS){
|
1186 |
|
|
// Special case for queue overrun handled above.
|
1187 |
|
|
// Only data without FE or PF is allowed into the queue.
|
1188 |
|
|
// Data with NE is allowed into the queue.
|
1189 |
|
|
// If FE or PF have occured then the queue is disabled
|
1190 |
|
|
// until they are cleared (by reading scsr then scdr).
|
1191 |
|
|
|
1192 |
|
|
#ifdef CYGOPT_IO_SERIAL_SUPPORT_LINE_STATUS
|
1193 |
|
|
cyg_serial_line_status_t stat;
|
1194 |
|
|
if(scsr & MPC555_SERIAL_SCxSR_NF){
|
1195 |
|
|
// Note if there is more than one frame in the queue
|
1196 |
|
|
// it is not possible to tell which frame
|
1197 |
|
|
// in the queue caused the noise error.
|
1198 |
|
|
// The error has already been cleared by reading
|
1199 |
|
|
// srsr then scrq[n], so no action is required here.
|
1200 |
|
|
stat.which = CYGNUM_SERIAL_STATUS_NOISEERR;
|
1201 |
|
|
(chan->callbacks->indicate_status)(chan, &stat);
|
1202 |
|
|
}
|
1203 |
|
|
#endif
|
1204 |
|
|
if(scsr & (MPC555_SERIAL_SCxSR_FE | MPC555_SERIAL_SCxSR_PF)){
|
1205 |
|
|
// This action needs to be taken clear the status bits so that
|
1206 |
|
|
// the queue can be re-enabled.
|
1207 |
|
|
HAL_READ_UINT16(port + MPC555_SERIAL_SCxDR, scdr);
|
1208 |
|
|
// Need to re-enable the queue
|
1209 |
|
|
cyg_uint16 qscicr;
|
1210 |
|
|
HAL_READ_UINT16(CYGARC_REG_IMM_QSCI1CR, qscicr);
|
1211 |
|
|
qscicr |= ((cyg_uint16)CYGARC_REG_IMM_QSCI1CR_QRE);
|
1212 |
|
|
HAL_WRITE_UINT16(CYGARC_REG_IMM_QSCI1CR, qscicr);
|
1213 |
|
|
|
1214 |
|
|
#ifdef CYGOPT_IO_SERIAL_SUPPORT_LINE_STATUS
|
1215 |
|
|
if(scsr & MPC555_SERIAL_SCxSR_FE){
|
1216 |
|
|
stat.which = CYGNUM_SERIAL_STATUS_FRAMEERR;
|
1217 |
|
|
(chan->callbacks->indicate_status)(chan, &stat);
|
1218 |
|
|
}
|
1219 |
|
|
if(scsr & MPC555_SERIAL_SCxSR_PF){
|
1220 |
|
|
stat.which = CYGNUM_SERIAL_STATUS_PARITYERR;
|
1221 |
|
|
(chan->callbacks->indicate_status)(chan, &stat);
|
1222 |
|
|
}
|
1223 |
|
|
#endif
|
1224 |
|
|
}
|
1225 |
|
|
}
|
1226 |
|
|
if(QTHF){
|
1227 |
|
|
qscisr &= ~((cyg_uint16)CYGARC_REG_IMM_QSCI1SR_QTHF);
|
1228 |
|
|
HAL_WRITE_UINT16(CYGARC_REG_IMM_QSCI1SR, qscisr);
|
1229 |
|
|
//cyg_drv_interrupt_unmask(mpc555_chan->rx_interrupt_queue_top_full_num);
|
1230 |
|
|
}
|
1231 |
|
|
if(QBHF){
|
1232 |
|
|
qscisr &= ~((cyg_uint16)CYGARC_REG_IMM_QSCI1SR_QBHF);
|
1233 |
|
|
HAL_WRITE_UINT16(CYGARC_REG_IMM_QSCI1SR, qscisr);
|
1234 |
|
|
//cyg_drv_interrupt_unmask(mpc555_chan->rx_interrupt_queue_bot_full_num);
|
1235 |
|
|
}
|
1236 |
|
|
if(idle){
|
1237 |
|
|
if(idle && !space_req){
|
1238 |
|
|
// The IDLE flag can be set sometimes when RE is set
|
1239 |
|
|
// so a read of scrq is needed to clear it.
|
1240 |
|
|
// If this occurs there should be no new data yet otherwise the
|
1241 |
|
|
// condition is impossible to detect
|
1242 |
|
|
HAL_READ_UINT16(CYGARC_REG_IMM_SCRQ, scrq);
|
1243 |
|
|
}
|
1244 |
|
|
HAL_READ_UINT16(CYGARC_REG_IMM_SCRQ, scrq);
|
1245 |
|
|
//cyg_drv_interrupt_unmask(mpc555_chan->rx_interrupt_idle_line_num);
|
1246 |
|
|
}
|
1247 |
|
|
// A bit lasy, but we don't know or care what the original ISR source
|
1248 |
|
|
// was so to cover all bases re-enble them all
|
1249 |
|
|
cyg_drv_interrupt_unmask(mpc555_chan->rx_interrupt_queue_top_full_num);
|
1250 |
|
|
cyg_drv_interrupt_unmask(mpc555_chan->rx_interrupt_queue_bot_full_num);
|
1251 |
|
|
cyg_drv_interrupt_unmask(mpc555_chan->rx_interrupt_idle_line_num);
|
1252 |
|
|
}
|
1253 |
|
|
|
1254 |
|
|
static int mpc555_serial_read_queue(serial_channel* chan, int start, int end)
|
1255 |
|
|
{
|
1256 |
|
|
int block_index = 0;
|
1257 |
|
|
cyg_uint16 scrq;
|
1258 |
|
|
cyg_addrword_t i;
|
1259 |
|
|
unsigned char* space;
|
1260 |
|
|
int space_avail = 0;
|
1261 |
|
|
int space_req = end - start + 1;
|
1262 |
|
|
if((space_req > 0) &&
|
1263 |
|
|
((chan->callbacks->data_rcv_req)
|
1264 |
|
|
(chan, space_req, &space_avail, &space) == CYG_RCV_OK)) {
|
1265 |
|
|
CYG_ASSERT((start >= 0) && (start < 16),"rx queue read start point out of range");
|
1266 |
|
|
CYG_ASSERT(start <= end,"rx queue read start and end points reversed");
|
1267 |
|
|
for(i=start ;i < (start + space_avail); i++){
|
1268 |
|
|
CYG_ASSERT((i >= 0) && (i < 16),"rx queue read out of range");
|
1269 |
|
|
HAL_READ_UINT16(CYGARC_REG_IMM_SCRQ + (i * 2), scrq);
|
1270 |
|
|
space[block_index] = scrq;
|
1271 |
|
|
++block_index;
|
1272 |
|
|
}
|
1273 |
|
|
(chan->callbacks->data_rcv_done)(chan,space_avail);
|
1274 |
|
|
#ifdef CYGOPT_IO_SERIAL_SUPPORT_LINE_STATUS
|
1275 |
|
|
// If there's not enough room data will be lost.
|
1276 |
|
|
// There's no point calling rcv_char because the reader is blocked by this DSR.
|
1277 |
|
|
if(space_avail < space_req){
|
1278 |
|
|
cyg_serial_line_status_t stat;
|
1279 |
|
|
stat.which = CYGNUM_SERIAL_STATUS_OVERRUNERR;
|
1280 |
|
|
(chan->callbacks->indicate_status)(chan, &stat);
|
1281 |
|
|
}
|
1282 |
|
|
#endif
|
1283 |
|
|
}
|
1284 |
|
|
return space_req;
|
1285 |
|
|
}
|
1286 |
|
|
#endif // SERIAL_A
|
1287 |
|
|
#endif // CYGPKG_IO_SERIAL_POWERPC_MPC555
|
1288 |
|
|
|
1289 |
|
|
// EOF mpc555_serial_with_ints.c
|
1290 |
|
|
|