OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [libchip/] [serial/] [mc68681.c] - Blame information for rev 609

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 *  This file contains the termios TTY driver for the Motorola MC68681.
3
 *
4
 *  This part is available from a number of secondary sources.
5
 *  In particular, we know about the following:
6
 *
7
 *     + Exar 88c681 and 68c681
8
 *
9
 *  COPYRIGHT (c) 1989-1999.
10
 *  On-Line Applications Research Corporation (OAR).
11
 *
12
 *  The license and distribution terms for this file may be
13
 *  found in the file LICENSE in this distribution or at
14
 *  http://www.OARcorp.com/rtems/license.html.
15
 *
16
 *  $Id: mc68681.c,v 1.2 2001-09-27 12:01:42 chris Exp $
17
 */
18
 
19
#include <rtems.h>
20
#include <rtems/libio.h>
21
#include <stdlib.h>
22
 
23
#include <libchip/serial.h>
24
#include <libchip/mc68681.h>
25
#include "sersupp.h"
26
#include "mc68681_p.h"
27
 
28
/*
29
 * Flow control is only supported when using interrupts
30
 */
31
 
32
console_fns mc68681_fns =
33
{
34
  libchip_serial_default_probe,   /* deviceProbe */
35
  mc68681_open,                   /* deviceFirstOpen */
36
  NULL,                           /* deviceLastClose */
37
  NULL,                           /* deviceRead */
38
  mc68681_write_support_int,      /* deviceWrite */
39
  mc68681_initialize_interrupts,  /* deviceInitialize */
40
  mc68681_write_polled,           /* deviceWritePolled */
41
  mc68681_set_attributes,         /* deviceSetAttributes */
42
  TRUE                            /* deviceOutputUsesInterrupts */
43
};
44
 
45
console_fns mc68681_fns_polled =
46
{
47
  libchip_serial_default_probe,        /* deviceProbe */
48
  mc68681_open,                        /* deviceFirstOpen */
49
  mc68681_close,                       /* deviceLastClose */
50
  mc68681_inbyte_nonblocking_polled,   /* deviceRead */
51
  mc68681_write_support_polled,        /* deviceWrite */
52
  mc68681_init,                        /* deviceInitialize */
53
  mc68681_write_polled,                /* deviceWritePolled */
54
  mc68681_set_attributes,              /* deviceSetAttributes */
55
  FALSE,                               /* deviceOutputUsesInterrupts */
56
};
57
 
58
extern void set_vector( rtems_isr_entry, rtems_vector_number, int );
59
 
60
/*
61
 *  Console Device Driver Entry Points
62
 */
63
 
64
/*
65
 *  mc68681_baud_rate
66
 *
67
 *  This routine returns the proper ACR bit and baud rate field values
68
 *  based on the requested baud rate.  The baud rate set to be used
69
 *  must be configured by the user.
70
 */
71
 
72
MC68681_STATIC int mc68681_baud_rate(
73
  int           minor,
74
  int           baud,
75
  unsigned int *baud_mask_p,
76
  unsigned int *acr_bit_p,
77
  unsigned int *command
78
);
79
 
80
/*
81
 *  mc68681_set_attributes
82
 *
83
 *  This function sets the DUART channel to reflect the requested termios
84
 *  port settings.
85
 */
86
 
87
MC68681_STATIC int mc68681_set_attributes(
88
  int minor,
89
  const struct termios *t
90
)
91
{
92
  unsigned32             pMC68681_port;
93
  unsigned32             pMC68681;
94
  unsigned int           mode1;
95
  unsigned int           mode2;
96
  unsigned int           baud_mask;
97
  unsigned int           acr_bit;
98
  unsigned int           cmd;
99
  setRegister_f          setReg;
100
  rtems_interrupt_level  Irql;
101
 
102
  pMC68681      = Console_Port_Tbl[minor].ulCtrlPort1;
103
  pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2;
104
  setReg        = Console_Port_Tbl[minor].setRegister;
105
 
106
  /*
107
   *  Set the baud rate
108
   */
109
 
110
  if (mc68681_baud_rate( minor, t->c_cflag, &baud_mask, &acr_bit, &cmd ) == -1)
111
    return -1;
112
 
113
  baud_mask |=  baud_mask << 4;
114
  acr_bit   <<= 7;
115
 
116
  /*
117
   *  Parity
118
   */
119
 
120
  mode1 = 0;
121
  mode2 = 0;
122
 
123
  if (t->c_cflag & PARENB) {
124
    if (t->c_cflag & PARODD)
125
      mode1 |= 0x04;
126
    else
127
      mode1 |= 0x04;
128
  } else {
129
   mode1 |= 0x10;
130
  }
131
 
132
  /*
133
   *  Character Size
134
   */
135
 
136
  if (t->c_cflag & CSIZE) {
137
    switch (t->c_cflag & CSIZE) {
138
      case CS5:  break;
139
      case CS6:  mode1 |= 0x01;  break;
140
      case CS7:  mode1 |= 0x02;  break;
141
      case CS8:  mode1 |= 0x03;  break;
142
    }
143
  } else {
144
    mode1 |= 0x03;       /* default to 9600,8,N,1 */
145
  }
146
 
147
  /*
148
   *  Stop Bits
149
   */
150
 
151
  if (t->c_cflag & CSTOPB) {
152
    mode2 |= 0x07;                      /* 2 stop bits */
153
  } else {
154
    if ((t->c_cflag & CSIZE) == CS5)    /* CS5 and 2 stop bits not supported */
155
      return -1;
156
    mode2 |= 0x0F;                      /* 1 stop bit */
157
  }
158
 
159
  rtems_interrupt_disable(Irql);
160
    (*setReg)( pMC68681, MC68681_AUX_CTRL_REG, acr_bit );
161
    (*setReg)( pMC68681_port, MC68681_CLOCK_SELECT, baud_mask );
162
    if ( cmd ) {
163
      (*setReg)( pMC68681_port, MC68681_COMMAND, cmd );         /* RX */
164
      (*setReg)( pMC68681_port, MC68681_COMMAND, cmd | 0x20 );  /* TX */
165
    }
166
    (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_MR_PTR );
167
    (*setReg)( pMC68681_port, MC68681_MODE, mode1 );
168
    (*setReg)( pMC68681_port, MC68681_MODE, mode2 );
169
  rtems_interrupt_enable(Irql);
170
  return 0;
171
}
172
 
173
/*
174
 *  mc68681_initialize_context
175
 *
176
 *  This function sets the default values of the per port context structure.
177
 */
178
 
179
MC68681_STATIC void mc68681_initialize_context(
180
  int               minor,
181
  mc68681_context  *pmc68681Context
182
)
183
{
184
  int          port;
185
  unsigned int pMC68681;
186
  unsigned int pMC68681_port;
187
 
188
  pMC68681      = Console_Port_Tbl[minor].ulCtrlPort1;
189
  pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2;
190
 
191
  pmc68681Context->mate = -1;
192
 
193
  for (port=0 ; port<Console_Port_Count ; port++ ) {
194
    if ( Console_Port_Tbl[port].ulCtrlPort1 == pMC68681 &&
195
         Console_Port_Tbl[port].ulCtrlPort2 != pMC68681_port ) {
196
      pmc68681Context->mate = port;
197
      pmc68681Context->imr  = 0;
198
      break;
199
    }
200
  }
201
 
202
}
203
 
204
/*
205
 *  mc68681_init
206
 *
207
 *  This function initializes the DUART to a quiecsent state.
208
 */
209
 
210
MC68681_STATIC void mc68681_init(int minor)
211
{
212
  unsigned32              pMC68681_port;
213
  unsigned32              pMC68681;
214
  mc68681_context        *pmc68681Context;
215
  setRegister_f           setReg;
216
  getRegister_f           getReg;
217
 
218
  pmc68681Context = (mc68681_context *) malloc(sizeof(mc68681_context));
219
 
220
  Console_Port_Data[minor].pDeviceContext = (void *)pmc68681Context;
221
 
222
  mc68681_initialize_context( minor, pmc68681Context );
223
 
224
  pMC68681      = Console_Port_Tbl[minor].ulCtrlPort1;
225
  pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2;
226
  setReg        = Console_Port_Tbl[minor].setRegister;
227
  getReg        = Console_Port_Tbl[minor].getRegister;
228
 
229
  /*
230
   *  Reset everything and leave this port disabled.
231
   */
232
 
233
  (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_RX );
234
  (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_TX );
235
  (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_ERROR );
236
  (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_BREAK );
237
  (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_STOP_BREAK );
238
  (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_DISABLE_TX );
239
  (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_DISABLE_RX );
240
 
241
 
242
  (*setReg)( pMC68681_port, MC68681_MODE_REG_1A, 0x00 );
243
  (*setReg)( pMC68681_port, MC68681_MODE_REG_2A, 0x02 );
244
 
245
  /*
246
   *  Disable interrupts on RX and TX for this port
247
   */
248
 
249
  mc68681_enable_interrupts( minor, MC68681_IMR_DISABLE_ALL );
250
}
251
 
252
/*
253
 *  mc68681_open
254
 *
255
 *  This function opens a port for communication.
256
 *
257
 *  Default state is 9600 baud, 8 bits, No parity, and 1 stop bit.
258
 */
259
 
260
MC68681_STATIC int mc68681_open(
261
  int      major,
262
  int      minor,
263
  void    *arg
264
)
265
{
266
  unsigned32             pMC68681;
267
  unsigned32             pMC68681_port;
268
  unsigned int           baud;
269
  unsigned int           acr;
270
  unsigned int           vector;
271
  unsigned int           command;
272
  rtems_interrupt_level  Irql;
273
  setRegister_f          setReg;
274
 
275
  pMC68681      = Console_Port_Tbl[minor].ulCtrlPort1;
276
  pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2;
277
  setReg        = Console_Port_Tbl[minor].setRegister;
278
  vector        = Console_Port_Tbl[minor].ulIntVector;
279
 
280
  /* XXX default baud rate should be from configuration table */
281
 
282
  (void) mc68681_baud_rate( minor, B9600, &baud, &acr, &command );
283
 
284
  /*
285
   *  Set the DUART channel to a default useable state
286
   */
287
 
288
  rtems_interrupt_disable(Irql);
289
    (*setReg)( pMC68681, MC68681_AUX_CTRL_REG, acr );
290
    (*setReg)( pMC68681_port, MC68681_CLOCK_SELECT, baud );
291
    if ( command ) {
292
      (*setReg)( pMC68681_port, MC68681_COMMAND, command );         /* RX */
293
      (*setReg)( pMC68681_port, MC68681_COMMAND, command | 0x20 );  /* TX */
294
    }
295
    (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_MR_PTR );
296
    (*setReg)( pMC68681_port, MC68681_MODE, 0x13 );
297
    (*setReg)( pMC68681_port, MC68681_MODE, 0x07 );
298
  rtems_interrupt_enable(Irql);
299
 
300
  (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_ENABLE_TX );
301
  (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_ENABLE_RX );
302
 
303
  (*setReg)( pMC68681, MC68681_INTERRUPT_VECTOR_REG, vector );
304
 
305
  return RTEMS_SUCCESSFUL;
306
}
307
 
308
/*
309
 *  mc68681_close
310
 *
311
 *  This function shuts down the requested port.
312
 */
313
 
314
MC68681_STATIC int mc68681_close(
315
  int      major,
316
  int      minor,
317
  void    *arg
318
)
319
{
320
  unsigned32      pMC68681;
321
  unsigned32      pMC68681_port;
322
  setRegister_f   setReg;
323
 
324
  pMC68681      = Console_Port_Tbl[minor].ulCtrlPort1;
325
  pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2;
326
  setReg        = Console_Port_Tbl[minor].setRegister;
327
 
328
  /*
329
   *  Disable interrupts from this channel and then disable it totally.
330
   */
331
 
332
#if 0
333
  (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_DISABLE_TX );
334
  (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_DISABLE_RX );
335
#endif
336
 
337
  return(RTEMS_SUCCESSFUL);
338
}
339
 
340
/*
341
 *  mc68681_write_polled
342
 *
343
 *  This routine polls out the requested character.
344
 */
345
 
346
MC68681_STATIC void mc68681_write_polled(
347
  int   minor,
348
  char  cChar
349
)
350
{
351
  unsigned32              pMC68681_port;
352
  unsigned char           ucLineStatus;
353
  int                     iTimeout;
354
  getRegister_f           getReg;
355
  setRegister_f           setReg;
356
 
357
  pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2;
358
  getReg        = Console_Port_Tbl[minor].getRegister;
359
  setReg        = Console_Port_Tbl[minor].setRegister;
360
 
361
  /*
362
   * wait for transmitter holding register to be empty
363
   */
364
  iTimeout = 1000;
365
  ucLineStatus = (*getReg)(pMC68681_port, MC68681_STATUS);
366
  while ((ucLineStatus & (MC68681_TX_READY|MC68681_TX_EMPTY)) == 0) {
367
 
368
    if ((ucLineStatus & 0xF0))
369
      (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_ERROR );
370
 
371
    /*
372
     * Yield while we wait
373
     */
374
 
375
#if 0
376
     if(_System_state_Is_up(_System_state_Get())) {
377
       rtems_task_wake_after(RTEMS_YIELD_PROCESSOR);
378
     }
379
#endif
380
     ucLineStatus = (*getReg)(pMC68681_port, MC68681_STATUS);
381
     if(!--iTimeout) {
382
       break;
383
     }
384
  }
385
 
386
  /*
387
   * transmit character
388
   */
389
 
390
  (*setReg)(pMC68681_port, MC68681_TX_BUFFER, cChar);
391
}
392
 
393
/*
394
 *  mc68681_isr
395
 *
396
 *  This is the single interrupt entry point which parcels interrupts
397
 *  out to the various ports.
398
 */
399
 
400
MC68681_STATIC rtems_isr mc68681_isr(
401
  rtems_vector_number vector
402
)
403
{
404
  int     minor;
405
 
406
  for(minor=0 ; minor<Console_Port_Count ; minor++) {
407
    if(Console_Port_Tbl[minor].ulIntVector == vector &&
408
       Console_Port_Tbl[minor].deviceType == SERIAL_MC68681 ) {
409
      mc68681_process(minor);
410
    }
411
  }
412
}
413
 
414
/*
415
 *  mc68681_initialize_interrupts
416
 *
417
 *  This routine initializes the console's receive and transmit
418
 *  ring buffers and loads the appropriate vectors to handle the interrupts.
419
 */
420
 
421
MC68681_STATIC void mc68681_initialize_interrupts(int minor)
422
{
423
  mc68681_init(minor);
424
 
425
  Console_Port_Data[minor].bActive = FALSE;
426
 
427
  set_vector(mc68681_isr, Console_Port_Tbl[minor].ulIntVector, 1);
428
 
429
  mc68681_enable_interrupts(minor,MC68681_IMR_ENABLE_ALL_EXCEPT_TX);
430
}
431
 
432
/*
433
 *  mc68681_write_support_int
434
 *
435
 *  Console Termios output entry point when using interrupt driven output.
436
 */
437
 
438
MC68681_STATIC int mc68681_write_support_int(
439
  int         minor,
440
  const char *buf,
441
  int         len
442
)
443
{
444
  unsigned32      Irql;
445
  unsigned32      pMC68681_port;
446
  setRegister_f   setReg;
447
 
448
  pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2;
449
  setReg        = Console_Port_Tbl[minor].setRegister;
450
 
451
  /*
452
   *  We are using interrupt driven output and termios only sends us
453
   *  one character at a time.
454
   */
455
 
456
  if ( !len )
457
    return 0;
458
 
459
  /*
460
   *  Put the character out and enable interrupts if necessary.
461
   */
462
 
463
  rtems_interrupt_disable(Irql);
464
    if ( Console_Port_Data[minor].bActive == FALSE ) {
465
      Console_Port_Data[minor].bActive = TRUE;
466
      mc68681_enable_interrupts(minor, MC68681_IMR_ENABLE_ALL);
467
    }
468
    (*setReg)(pMC68681_port, MC68681_TX_BUFFER, *buf);
469
  rtems_interrupt_enable(Irql);
470
 
471
  return 1;
472
}
473
 
474
/*
475
 *  mc68681_write_support_polled
476
 *
477
 *  Console Termios output entry point when using polled output.
478
 *
479
 */
480
 
481
MC68681_STATIC int mc68681_write_support_polled(
482
  int         minor,
483
  const char *buf,
484
  int         len
485
)
486
{
487
  int nwrite = 0;
488
 
489
  /*
490
   * poll each byte in the string out of the port.
491
   */
492
  while (nwrite < len) {
493
    /*
494
     * transmit character
495
     */
496
    mc68681_write_polled(minor, *buf++);
497
    nwrite++;
498
  }
499
 
500
  /*
501
   * return the number of bytes written.
502
   */
503
  return nwrite;
504
}
505
 
506
/*
507
 *  mc68681_inbyte_nonblocking_polled
508
 *
509
 *  Console Termios polling input entry point.
510
 */
511
 
512
MC68681_STATIC int mc68681_inbyte_nonblocking_polled(
513
  int minor
514
)
515
{
516
  unsigned32           pMC68681_port;
517
  unsigned char        ucLineStatus;
518
  unsigned char        cChar;
519
  getRegister_f        getReg;
520
 
521
  pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2;
522
  getReg        = Console_Port_Tbl[minor].getRegister;
523
 
524
  ucLineStatus = (*getReg)(pMC68681_port, MC68681_STATUS);
525
  if(ucLineStatus & MC68681_RX_READY) {
526
    cChar = (*getReg)(pMC68681_port, MC68681_RX_BUFFER);
527
    return (int)cChar;
528
  } else {
529
    return -1;
530
  }
531
}
532
 
533
/*
534
 *  mc68681_baud_rate
535
 */
536
 
537
MC68681_STATIC int mc68681_baud_rate(
538
  int           minor,
539
  int           baud,
540
  unsigned int *baud_mask_p,
541
  unsigned int *acr_bit_p,
542
  unsigned int *command
543
)
544
{
545
  unsigned int           baud_mask;
546
  unsigned int           acr_bit;
547
  int                    status;
548
  int                    is_extended;
549
  int                    baud_requested;
550
  mc68681_baud_table_t  *baud_tbl;
551
 
552
  baud_mask = 0;
553
  acr_bit = 0;
554
  status = 0;
555
 
556
  if ( !(Console_Port_Tbl[minor].ulDataPort & MC68681_DATA_BAUD_RATE_SET_1) )
557
    acr_bit = 1;
558
 
559
  is_extended = 0;
560
 
561
  switch (Console_Port_Tbl[minor].ulDataPort & MC68681_XBRG_MASK) {
562
    case MC68681_XBRG_IGNORED:
563
      *command = 0x00;
564
      break;
565
    case MC68681_XBRG_ENABLED:
566
      *command = 0x80;
567
      is_extended = 1;
568
      break;
569
    case MC68681_XBRG_DISABLED:
570
      *command = 0x90;
571
      break;
572
  }
573
 
574
  baud_requested = baud & CBAUD;
575
  if (!baud_requested)
576
    baud_requested = B9600;              /* default to 9600 baud */
577
 
578
  baud_requested = termios_baud_to_index( baud_requested );
579
 
580
  baud_tbl = (mc68681_baud_table_t *) Console_Port_Tbl[minor].ulClock;
581
  if (!baud_tbl)
582
    rtems_fatal_error_occurred(RTEMS_INVALID_ADDRESS);
583
 
584
  if ( is_extended )
585
    baud_mask = (unsigned int)baud_tbl[ acr_bit + 2 ][ baud_requested ];
586
  else
587
    baud_mask = baud_tbl[ acr_bit ][ baud_requested ];
588
 
589
  if ( baud_mask == MC68681_BAUD_NOT_VALID )
590
    status = -1;
591
 
592
  /*
593
   *  upper nibble is receiver and lower nibble is transmitter
594
   */
595
 
596
  *baud_mask_p = (baud_mask << 4) | baud_mask;
597
  *acr_bit_p   = acr_bit;
598
  return status;
599
}
600
 
601
/*
602
 *  mc68681_process
603
 *
604
 *  This routine is the per port console interrupt handler.
605
 */
606
 
607
MC68681_STATIC void mc68681_process(
608
  int  minor
609
)
610
{
611
  unsigned32              pMC68681;
612
  unsigned32              pMC68681_port;
613
  volatile unsigned8      ucLineStatus;
614
  unsigned char           cChar;
615
  getRegister_f           getReg;
616
  setRegister_f           setReg;
617
 
618
  pMC68681      = Console_Port_Tbl[minor].ulCtrlPort1;
619
  pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2;
620
  getReg        = Console_Port_Tbl[minor].getRegister;
621
  setReg        = Console_Port_Tbl[minor].setRegister;
622
 
623
  /*
624
   * Deal with any received characters
625
   */
626
  while(TRUE) {
627
    ucLineStatus = (*getReg)(pMC68681_port, MC68681_STATUS);
628
    if(!(ucLineStatus & MC68681_RX_READY)) {
629
      break;
630
    }
631
    /*
632
     *  If there is a RX error, then dump all the data.
633
     */
634
    if ( ucLineStatus & MC68681_RX_ERRORS ) {
635
      do {
636
        cChar = (*getReg)(pMC68681_port, MC68681_RX_BUFFER);
637
        ucLineStatus = (*getReg)(pMC68681_port, MC68681_STATUS);
638
      } while ( ucLineStatus & MC68681_RX_READY );
639
      continue;
640
    }
641
    cChar = (*getReg)(pMC68681_port, MC68681_RX_BUFFER);
642
    rtems_termios_enqueue_raw_characters(
643
      Console_Port_Data[minor].termios_data,
644
      &cChar,
645
      1
646
    );
647
  }
648
 
649
  /*
650
   *  Deal with the transmitter
651
   */
652
 
653
  ucLineStatus = (*getReg)(pMC68681, MC68681_INTERRUPT_STATUS_REG);
654
  if (pMC68681 != pMC68681_port)
655
    ucLineStatus >>= 4;
656
 
657
  if(ucLineStatus & MC68681_IR_TX_READY) {
658
    if (rtems_termios_dequeue_characters(
659
         Console_Port_Data[minor].termios_data, 1)) {
660
      Console_Port_Data[minor].bActive = FALSE;
661
      mc68681_enable_interrupts(minor, MC68681_IMR_ENABLE_ALL_EXCEPT_TX);
662
    }
663
  }
664
 
665
}
666
 
667
/*
668
 *  mc68681_build_imr
669
 *
670
 *  This function returns the value for the interrupt mask register for this
671
 *  DUART.  Since this is a shared register, we must look at the other port
672
 *  on this chip to determine whether or not it is using interrupts.
673
 */
674
 
675
MC68681_STATIC unsigned int mc68681_build_imr(
676
  int  minor,
677
  int  enable_flag
678
)
679
{
680
  int              mate;
681
  int              is_a;
682
  unsigned int     mask;
683
  unsigned int     mate_mask;
684
  unsigned int     pMC68681;
685
  unsigned int     pMC68681_port;
686
  mc68681_context *pmc68681Context;
687
  mc68681_context *mateContext;
688
 
689
  pMC68681        = Console_Port_Tbl[minor].ulCtrlPort1;
690
  pMC68681_port   = Console_Port_Tbl[minor].ulCtrlPort2;
691
  pmc68681Context = (mc68681_context *) Console_Port_Data[minor].pDeviceContext;
692
  mate            = pmc68681Context->mate;
693
 
694
  mask = 0;
695
  mate_mask = 0;
696
 
697
  is_a = (pMC68681 == pMC68681_port);
698
 
699
  /*
700
   *  If there is a mate for this port, get its IMR mask.
701
   */
702
 
703
  if ( mate != -1 ) {
704
    mateContext = Console_Port_Data[mate].pDeviceContext;
705
 
706
    if (mateContext)
707
      mate_mask = mateContext->imr;
708
  }
709
 
710
  /*
711
   *  Calculate this port's IMR mask and save it in the context area.
712
   */
713
 
714
  if ( Console_Port_Tbl[minor].pDeviceFns->deviceOutputUsesInterrupts )
715
    mask = enable_flag;
716
 
717
  pmc68681Context->imr = mask;
718
 
719
  /*
720
   *  Now return the full IMR value
721
   */
722
 
723
  if (is_a)
724
    return (mate_mask << 4) | mask;
725
 
726
  return (mask << 4) | mate_mask;
727
}
728
 
729
/*
730
 *  mc68681_enable_interrupts
731
 *
732
 *  This function enables specific interrupt sources on the DUART.
733
 */
734
 
735
MC68681_STATIC void mc68681_enable_interrupts(
736
  int minor,
737
  int imr_mask
738
)
739
{
740
  unsigned32            pMC68681;
741
  setRegister_f         setReg;
742
 
743
  pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1;
744
  setReg   = Console_Port_Tbl[minor].setRegister;
745
 
746
  /*
747
   *  Enable interrupts on RX and TX -- not break
748
   */
749
 
750
  (*setReg)(
751
     pMC68681,
752
     MC68681_INTERRUPT_MASK_REG,
753
     mc68681_build_imr(minor, imr_mask)
754
  );
755
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.