source: rtems/c/src/libchip/serial/z85c30.c @ a29909cb

4.115
Last change on this file since a29909cb was a29909cb, checked in by Joel Sherrill <joel.sherrill@…>, on 05/07/12 at 23:26:51

libchip/serial - Only use set_vector() on Simple Vectored Architectures

  • Property mode set to 100644
File size: 20.2 KB
Line 
1/*
2 *  This file contains the console driver chip level routines for the
3 *  Zilog z85c30 chip.
4 *
5 *  The Zilog Z8530 is also available as:
6 *
7 *    + Intel 82530
8 *    + AMD ???
9 *
10 *  COPYRIGHT (c) 1998 by Radstone Technology
11 *
12 *
13 * THIS FILE IS PROVIDED TO YOU, THE USER, "AS IS", WITHOUT WARRANTY OF ANY
14 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK
16 * AS TO THE QUALITY AND PERFORMANCE OF ALL CODE IN THIS FILE IS WITH YOU.
17 *
18 * You are hereby granted permission to use, copy, modify, and distribute
19 * this file, provided that this notice, plus the above copyright notice
20 * and disclaimer, appears in all copies. Radstone Technology will provide
21 * no support for this code.
22 *
23 *  COPYRIGHT (c) 1989-1997.
24 *  On-Line Applications Research Corporation (OAR).
25 *
26 *  The license and distribution terms for this file may be
27 *  found in the file LICENSE in this distribution or at
28 *  http://www.rtems.com/license/LICENSE.
29 *
30 *  $Id$
31 */
32
33#include <rtems.h>
34#include <rtems/libio.h>
35#include <stdlib.h>
36
37#include <libchip/serial.h>
38#include <libchip/sersupp.h>
39#include "z85c30_p.h"
40
41/*
42 * Flow control is only supported when using interrupts
43 */
44
45console_flow z85c30_flow_RTSCTS = {
46  z85c30_negate_RTS,    /* deviceStopRemoteTx */
47  z85c30_assert_RTS     /* deviceStartRemoteTx */
48};
49
50console_flow z85c30_flow_DTRCTS = {
51  z85c30_negate_DTR,    /* deviceStopRemoteTx */
52  z85c30_assert_DTR     /* deviceStartRemoteTx */
53};
54
55/*
56 * Exported driver function table
57 */
58
59console_fns z85c30_fns = {
60  libchip_serial_default_probe,  /* deviceProbe */
61  z85c30_open,                   /* deviceFirstOpen */
62  NULL,                          /* deviceLastClose */
63  NULL,                          /* deviceRead */
64  z85c30_write_support_int,      /* deviceWrite */
65  z85c30_initialize_interrupts,  /* deviceInitialize */
66  z85c30_write_polled,           /* deviceWritePolled */
67  NULL,                          /* deviceSetAttributes */
68  true                           /* deviceOutputUsesInterrupts */
69};
70
71console_fns z85c30_fns_polled = {
72  libchip_serial_default_probe,      /* deviceProbe */
73  z85c30_open,                       /* deviceFirstOpen */
74  z85c30_close,                      /* deviceLastClose */
75  z85c30_inbyte_nonblocking_polled,  /* deviceRead */
76  z85c30_write_support_polled,       /* deviceWrite */
77  z85c30_init,                       /* deviceInitialize */
78  z85c30_write_polled,               /* deviceWritePolled */
79  NULL,                              /* deviceSetAttributes */
80  false                              /* deviceOutputUsesInterrupts */
81};
82
83#if (CPU_SIMPLE_VECTORED_INTERRUPTS == TRUE)
84  extern void set_vector( rtems_isr_entry, rtems_vector_number, int );
85#endif
86
87/*
88 *  z85c30_initialize_port
89 *
90 *  initialize a z85c30 Port
91 */
92
93Z85C30_STATIC void z85c30_initialize_port(
94  int minor
95)
96{
97  uintptr_t       ulCtrlPort;
98  uintptr_t       ulBaudDivisor;
99  setRegister_f   setReg;
100
101  ulCtrlPort = Console_Port_Tbl[minor]->ulCtrlPort1;
102  setReg   = Console_Port_Tbl[minor]->setRegister;
103
104  /*
105   * Using register 4
106   * Set up the clock rate is 16 times the data
107   * rate, 8 bit sync char, 1 stop bit, no parity
108   */
109
110  (*setReg)( ulCtrlPort, SCC_WR0_SEL_WR4, SCC_WR4_1_STOP | SCC_WR4_16_CLOCK );
111
112  /*
113   * Set up for 8 bits/character on receive with
114   * receiver disable via register 3
115   */
116  (*setReg)( ulCtrlPort, SCC_WR0_SEL_WR3, SCC_WR3_RX_8_BITS );
117
118  /*
119   * Set up for 8 bits/character on transmit
120   * with transmitter disable via register 5
121   */
122  (*setReg)( ulCtrlPort, SCC_WR0_SEL_WR5, SCC_WR5_TX_8_BITS );
123
124  /*
125   * Clear misc control bits
126   */
127  (*setReg)( ulCtrlPort, SCC_WR0_SEL_WR10, 0x00 );
128
129  /*
130   * Setup the source of the receive and xmit
131   * clock as BRG output and the transmit clock
132   * as the output source for TRxC pin via register 11
133   */
134  (*setReg)(
135    ulCtrlPort,
136    SCC_WR0_SEL_WR11,
137    SCC_WR11_OUT_BR_GEN | SCC_WR11_TRXC_OI |
138      SCC_WR11_TX_BR_GEN | SCC_WR11_RX_BR_GEN
139  );
140
141  ulBaudDivisor = Z85C30_Baud(
142    (uint32_t) Console_Port_Tbl[minor]->ulClock,
143    (uint32_t) ((uintptr_t)Console_Port_Tbl[minor]->pDeviceParams)
144  );
145
146  /*
147   * Setup the lower 8 bits time constants=1E.
148   * If the time constans=1E, then the desire
149   * baud rate will be equilvalent to 9600, via register 12.
150   */
151  (*setReg)( ulCtrlPort, SCC_WR0_SEL_WR12, ulBaudDivisor & 0xff );
152
153  /*
154   * using register 13
155   * Setup the upper 8 bits time constant
156   */
157  (*setReg)( ulCtrlPort, SCC_WR0_SEL_WR13, (ulBaudDivisor>>8) & 0xff );
158
159  /*
160   * Enable the baud rate generator enable with clock from the
161   * SCC's PCLK input via register 14.
162   */
163  (*setReg)(
164    ulCtrlPort,
165    SCC_WR0_SEL_WR14,
166    SCC_WR14_BR_EN | SCC_WR14_BR_SRC | SCC_WR14_NULL
167  );
168
169  /*
170   * We are only interested in CTS state changes
171   */
172  (*setReg)( ulCtrlPort, SCC_WR0_SEL_WR15, SCC_WR15_CTS_IE );
173
174  /*
175   * Reset errors
176   */
177  (*setReg)( ulCtrlPort, SCC_WR0_SEL_WR0, SCC_WR0_RST_INT );
178
179  (*setReg)( ulCtrlPort, SCC_WR0_SEL_WR0, SCC_WR0_ERR_RST );
180
181  /*
182   * Enable the receiver via register 3
183   */
184  (*setReg)( ulCtrlPort, SCC_WR0_SEL_WR3, SCC_WR3_RX_8_BITS | SCC_WR3_RX_EN );
185
186  /*
187   * Enable the transmitter pins set via register 5.
188   */
189  (*setReg)( ulCtrlPort, SCC_WR0_SEL_WR5, SCC_WR5_TX_8_BITS | SCC_WR5_TX_EN );
190
191  /*
192   * Disable interrupts
193   */
194  (*setReg)( ulCtrlPort, SCC_WR0_SEL_WR1, 0 );
195
196  /*
197   * Reset TX CRC
198   */
199  (*setReg)( ulCtrlPort, SCC_WR0_SEL_WR0, SCC_WR0_RST_TX_CRC );
200
201  /*
202   * Reset interrupts
203   */
204  (*setReg)( ulCtrlPort, SCC_WR0_SEL_WR0, SCC_WR0_RST_INT );
205}
206
207/*
208 *  z85c30_open
209 */
210
211Z85C30_STATIC int z85c30_open(
212  int   major,
213  int   minor,
214  void *arg
215)
216{
217
218  z85c30_initialize_port(minor);
219
220  /*
221   * Assert DTR
222   */
223
224  if (Console_Port_Tbl[minor]->pDeviceFlow !=&z85c30_flow_DTRCTS) {
225    z85c30_assert_DTR(minor);
226  }
227
228  return(RTEMS_SUCCESSFUL);
229}
230
231/*
232 *  z85c30_close
233 */
234
235Z85C30_STATIC int z85c30_close(
236  int   major,
237  int   minor,
238  void *arg
239)
240{
241  /*
242   * Negate DTR
243   */
244
245  if (Console_Port_Tbl[minor]->pDeviceFlow !=&z85c30_flow_DTRCTS) {
246    z85c30_negate_DTR(minor);
247  }
248
249  return(RTEMS_SUCCESSFUL);
250}
251
252/*
253 *  z85c30_init
254 */
255
256Z85C30_STATIC void z85c30_init(int minor)
257{
258  uintptr_t        ulCtrlPort;
259  z85c30_context  *pz85c30Context;
260  setRegister_f    setReg;
261  getRegister_f    getReg;
262
263  ulCtrlPort = Console_Port_Tbl[minor]->ulCtrlPort1;
264  setReg     = Console_Port_Tbl[minor]->setRegister;
265  getReg     = Console_Port_Tbl[minor]->getRegister;
266
267  pz85c30Context = (z85c30_context *)malloc(sizeof(z85c30_context));
268
269  Console_Port_Data[minor].pDeviceContext = (void *)pz85c30Context;
270
271  pz85c30Context->ucModemCtrl = SCC_WR5_TX_8_BITS | SCC_WR5_TX_EN;
272
273  ulCtrlPort = Console_Port_Tbl[minor]->ulCtrlPort1;
274  if ( ulCtrlPort == Console_Port_Tbl[minor]->ulCtrlPort2 ) {
275    /*
276     * This is channel A
277     */
278    /*
279     * Ensure port state machine is reset
280     */
281    (*getReg)(ulCtrlPort, SCC_WR0_SEL_RD0);
282
283    (*setReg)(ulCtrlPort, SCC_WR0_SEL_WR9, SCC_WR9_CH_A_RST);
284
285  } else {
286    /*
287     * This is channel B
288     */
289    /*
290     * Ensure port state machine is reset
291     */
292    (*getReg)(ulCtrlPort, SCC_WR0_SEL_RD0);
293
294    (*setReg)(ulCtrlPort, SCC_WR0_SEL_WR9, SCC_WR9_CH_B_RST);
295  }
296}
297
298/*
299 * These routines provide control of the RTS and DTR lines
300 */
301
302/*
303 *  z85c30_assert_RTS
304 */
305
306Z85C30_STATIC int z85c30_assert_RTS(int minor)
307{
308  rtems_interrupt_level  Irql;
309  z85c30_context        *pz85c30Context;
310  setRegister_f          setReg;
311
312  setReg = Console_Port_Tbl[minor]->setRegister;
313
314  pz85c30Context = (z85c30_context *) Console_Port_Data[minor].pDeviceContext;
315
316  /*
317   * Assert RTS
318   */
319
320  rtems_interrupt_disable(Irql);
321    pz85c30Context->ucModemCtrl|=SCC_WR5_RTS;
322    (*setReg)(
323      Console_Port_Tbl[minor]->ulCtrlPort1,
324      SCC_WR0_SEL_WR5,
325      pz85c30Context->ucModemCtrl
326    );
327  rtems_interrupt_enable(Irql);
328  return 0;
329}
330
331/*
332 *  z85c30_negate_RTS
333 */
334
335Z85C30_STATIC int z85c30_negate_RTS(int minor)
336{
337  rtems_interrupt_level  Irql;
338  z85c30_context        *pz85c30Context;
339  setRegister_f          setReg;
340
341  setReg = Console_Port_Tbl[minor]->setRegister;
342
343  pz85c30Context = (z85c30_context *) Console_Port_Data[minor].pDeviceContext;
344
345  /*
346   * Negate RTS
347   */
348
349  rtems_interrupt_disable(Irql);
350    pz85c30Context->ucModemCtrl&=~SCC_WR5_RTS;
351    (*setReg)(
352      Console_Port_Tbl[minor]->ulCtrlPort1,
353      SCC_WR0_SEL_WR5,
354      pz85c30Context->ucModemCtrl
355    );
356  rtems_interrupt_enable(Irql);
357  return 0;
358}
359
360/*
361 * These flow control routines utilise a connection from the local DTR
362 * line to the remote CTS line
363 */
364
365/*
366 *  z85c30_assert_DTR
367 */
368
369Z85C30_STATIC int z85c30_assert_DTR(int minor)
370{
371  rtems_interrupt_level  Irql;
372  z85c30_context        *pz85c30Context;
373  setRegister_f          setReg;
374
375  setReg = Console_Port_Tbl[minor]->setRegister;
376
377  pz85c30Context = (z85c30_context *) Console_Port_Data[minor].pDeviceContext;
378
379  /*
380   * Assert DTR
381   */
382
383  rtems_interrupt_disable(Irql);
384    pz85c30Context->ucModemCtrl|=SCC_WR5_DTR;
385    (*setReg)(
386      Console_Port_Tbl[minor]->ulCtrlPort1,
387      SCC_WR0_SEL_WR5,
388      pz85c30Context->ucModemCtrl
389  );
390  rtems_interrupt_enable(Irql);
391  return 0;
392}
393
394/*
395 *  z85c30_negate_DTR
396 */
397
398Z85C30_STATIC int z85c30_negate_DTR(int minor)
399{
400  rtems_interrupt_level  Irql;
401  z85c30_context        *pz85c30Context;
402  setRegister_f          setReg;
403
404  setReg = Console_Port_Tbl[minor]->setRegister;
405
406  pz85c30Context = (z85c30_context *) Console_Port_Data[minor].pDeviceContext;
407
408  /*
409   * Negate DTR
410   */
411
412  rtems_interrupt_disable(Irql);
413    pz85c30Context->ucModemCtrl&=~SCC_WR5_DTR;
414    (*setReg)(
415      Console_Port_Tbl[minor]->ulCtrlPort1,
416      SCC_WR0_SEL_WR5,
417      pz85c30Context->ucModemCtrl
418  );
419  rtems_interrupt_enable(Irql);
420  return 0;
421}
422
423/*
424 *  z85c30_set_attributes
425 *
426 *  This function sets the SCC channel to reflect the requested termios
427 *  port settings.
428 */
429
430Z85C30_STATIC int z85c30_set_attributes(
431  int                   minor,
432  const struct termios *t
433)
434{
435  uintptr_t              ulCtrlPort;
436  uint32_t               ulBaudDivisor;
437  uint32_t               wr3;
438  uint32_t               wr4;
439  uint32_t               wr5;
440  int                    baud_requested;
441  setRegister_f          setReg;
442  rtems_interrupt_level  Irql;
443
444  ulCtrlPort = Console_Port_Tbl[minor]->ulCtrlPort1;
445  setReg     = Console_Port_Tbl[minor]->setRegister;
446
447  /*
448   *  Calculate the baud rate divisor
449   */
450
451  baud_requested = t->c_cflag & CBAUD;
452  if (!baud_requested)
453    baud_requested = B9600;              /* default to 9600 baud */
454
455  ulBaudDivisor = Z85C30_Baud(
456    (uint32_t) Console_Port_Tbl[minor]->ulClock,
457    (uint32_t) rtems_termios_baud_to_number( baud_requested )
458  );
459
460  wr3 = SCC_WR3_RX_EN;
461  wr4 = SCC_WR4_16_CLOCK;
462  wr5 = SCC_WR5_TX_EN;
463
464  /*
465   *  Parity
466   */
467
468  if (t->c_cflag & PARENB) {
469    wr4 |= SCC_WR4_PAR_EN;
470    if (!(t->c_cflag & PARODD))
471      wr4 |= SCC_WR4_PAR_EVEN;
472  }
473
474  /*
475   *  Character Size
476   */
477
478  if (t->c_cflag & CSIZE) {
479    switch (t->c_cflag & CSIZE) {
480      case CS5:   break;
481      case CS6:  wr3 |= SCC_WR3_RX_6_BITS;  wr5 |= SCC_WR5_TX_6_BITS;  break;
482      case CS7:  wr3 |= SCC_WR3_RX_7_BITS;  wr5 |= SCC_WR5_TX_7_BITS;  break;
483      case CS8:  wr3 |= SCC_WR3_RX_8_BITS;  wr5 |= SCC_WR5_TX_8_BITS;  break;
484    }
485  } else {
486    wr3 |= SCC_WR3_RX_8_BITS;       /* default to 9600,8,N,1 */
487    wr5 |= SCC_WR5_TX_8_BITS;       /* default to 9600,8,N,1 */
488  }
489
490  /*
491   *  Stop Bits
492   */
493
494  if (t->c_cflag & CSTOPB) {
495    wr4 |= SCC_WR4_2_STOP;                      /* 2 stop bits */
496  } else {
497    wr4 |= SCC_WR4_1_STOP;                      /* 1 stop bits */
498  }
499
500  /*
501   *  Now actually set the chip
502   */
503
504  rtems_interrupt_disable(Irql);
505    (*setReg)( ulCtrlPort, SCC_WR0_SEL_WR4, wr4 );
506    (*setReg)( ulCtrlPort, SCC_WR0_SEL_WR3, wr3 );
507    (*setReg)( ulCtrlPort, SCC_WR0_SEL_WR5, wr5 );
508
509    /*
510     * Setup the lower 8 bits time constants=1E.
511     * If the time constans=1E, then the desire
512     * baud rate will be equilvalent to 9600, via register 12.
513     */
514
515    (*setReg)( ulCtrlPort, SCC_WR0_SEL_WR12, ulBaudDivisor & 0xff );
516
517    /*
518     * using register 13
519     * Setup the upper 8 bits time constant
520     */
521
522    (*setReg)( ulCtrlPort, SCC_WR0_SEL_WR13, (ulBaudDivisor>>8) & 0xff );
523
524  rtems_interrupt_enable(Irql);
525
526  return 0;
527}
528
529/*
530 *  z85c30_process
531 *
532 *  This is the per port ISR handler.
533 */
534
535Z85C30_STATIC void z85c30_process(
536  int        minor,
537  uint8_t    ucIntPend
538)
539{
540  uint32_t            ulCtrlPort;
541  volatile uint8_t    z85c30_status;
542  char                cChar;
543  setRegister_f       setReg;
544  getRegister_f       getReg;
545
546  ulCtrlPort = Console_Port_Tbl[minor]->ulCtrlPort1;
547  setReg     = Console_Port_Tbl[minor]->setRegister;
548  getReg     = Console_Port_Tbl[minor]->getRegister;
549
550  /*
551   * Deal with any received characters
552   */
553
554  while (ucIntPend&SCC_RR3_B_RX_IP)
555  {
556    z85c30_status = (*getReg)(ulCtrlPort, SCC_WR0_SEL_RD0);
557    if (!Z85C30_Status_Is_RX_character_available(z85c30_status)) {
558      break;
559    }
560
561    /*
562     * Return the character read.
563     */
564
565    cChar = (*getReg)(ulCtrlPort, SCC_WR0_SEL_RD8);
566
567    rtems_termios_enqueue_raw_characters(
568      Console_Port_Data[minor].termios_data,
569      &cChar,
570      1
571    );
572  }
573
574  /*
575   *  There could be a race condition here if there is not yet a TX
576   *  interrupt pending but the buffer is empty.  This condition has
577   *  been seen before on other z8530 drivers but has not been seen
578   *  with this one.  The typical solution is to use "vector includes
579   *  status" or to only look at the interrupts actually pending
580   *  in RR3.
581   */
582
583  while (true) {
584    z85c30_status = (*getReg)(ulCtrlPort, SCC_WR0_SEL_RD0);
585    if (!Z85C30_Status_Is_TX_buffer_empty(z85c30_status)) {
586      /*
587       * We'll get another interrupt when
588       * the transmitter holding reg. becomes
589       * free again and we are clear to send
590       */
591      break;
592    }
593
594#if 0
595    if (!Z85C30_Status_Is_CTS_asserted(z85c30_status)) {
596      /*
597       * We can't transmit yet
598       */
599      (*setReg)(ulCtrlPort, SCC_WR0_SEL_WR0, SCC_WR0_RST_TX_INT);
600      /*
601       * The next state change of CTS will wake us up
602       */
603      break;
604    }
605#endif
606
607    rtems_termios_dequeue_characters(Console_Port_Data[minor].termios_data, 1);
608    if (rtems_termios_dequeue_characters(
609         Console_Port_Data[minor].termios_data, 1)) {
610      if (Console_Port_Tbl[minor]->pDeviceFlow != &z85c30_flow_RTSCTS) {
611        z85c30_negate_RTS(minor);
612      }
613      Console_Port_Data[minor].bActive = FALSE;
614      z85c30_enable_interrupts(minor, SCC_ENABLE_ALL_INTR_EXCEPT_TX);
615      (*setReg)(ulCtrlPort, SCC_WR0_SEL_WR0, SCC_WR0_RST_TX_INT);
616      break;
617    }
618
619  }
620
621  if (ucIntPend & SCC_RR3_B_EXT_IP) {
622    /*
623     * Clear the external status interrupt
624     */
625    (*setReg)(ulCtrlPort, SCC_WR0_SEL_WR0, SCC_WR0_RST_INT);
626    z85c30_status = (*getReg)(ulCtrlPort, SCC_WR0_SEL_RD0);
627  }
628
629  /*
630   * Reset interrupts
631   */
632  (*setReg)(ulCtrlPort, SCC_WR0_SEL_WR0, SCC_WR0_RST_HI_IUS);
633}
634
635/*
636 *  z85c30_isr
637 *
638 *  This is the ISR handler for each Z8530.
639 */
640
641Z85C30_STATIC rtems_isr z85c30_isr(
642  rtems_vector_number vector
643)
644{
645  int                 minor;
646  uint32_t            ulCtrlPort;
647  volatile uint8_t    ucIntPend;
648  volatile uint8_t    ucIntPendPort;
649  getRegister_f       getReg;
650
651  for (minor=0;minor<Console_Port_Count;minor++) {
652    if(Console_Port_Tbl[minor]->ulIntVector == vector &&
653       Console_Port_Tbl[minor]->deviceType == SERIAL_Z85C30 ) {
654      ulCtrlPort = Console_Port_Tbl[minor]->ulCtrlPort2;
655      getReg     = Console_Port_Tbl[minor]->getRegister;
656      do {
657        ucIntPend = (*getReg)(ulCtrlPort, SCC_WR0_SEL_RD3);
658
659          /*
660           * If this is channel A select channel A status
661           */
662
663          if (ulCtrlPort == Console_Port_Tbl[minor]->ulCtrlPort1) {
664            ucIntPendPort = ucIntPend >> 3;
665            ucIntPendPort &= 7;
666          } else {
667            ucIntPendPort = ucIntPend &= 7;
668          }
669
670          if (ucIntPendPort) {
671            z85c30_process(minor, ucIntPendPort);
672          }
673      } while (ucIntPendPort);
674    }
675  }
676}
677
678/*
679 *  z85c30_enable_interrupts
680 *
681 *  This routine enables the specified interrupts for this minor.
682 */
683
684Z85C30_STATIC void z85c30_enable_interrupts(
685  int minor,
686  int interrupt_mask
687)
688{
689  uint32_t       ulCtrlPort;
690  setRegister_f  setReg;
691
692  ulCtrlPort = Console_Port_Tbl[minor]->ulCtrlPort1;
693  setReg     = Console_Port_Tbl[minor]->setRegister;
694
695  (*setReg)(ulCtrlPort, SCC_WR0_SEL_WR1, interrupt_mask);
696}
697
698/*
699 *  z85c30_initialize_interrupts
700 *
701 *  This routine initializes the port to use interrupts.
702 */
703
704Z85C30_STATIC void z85c30_initialize_interrupts(
705  int minor
706)
707{
708  uint32_t       ulCtrlPort1;
709  uint32_t       ulCtrlPort2;
710  setRegister_f  setReg;
711
712  ulCtrlPort1 = Console_Port_Tbl[minor]->ulCtrlPort1;
713  ulCtrlPort2 = Console_Port_Tbl[minor]->ulCtrlPort2;
714  setReg      = Console_Port_Tbl[minor]->setRegister;
715
716
717  z85c30_init(minor);
718
719  Console_Port_Data[minor].bActive=FALSE;
720
721  z85c30_initialize_port( minor );
722
723  if (Console_Port_Tbl[minor]->pDeviceFlow != &z85c30_flow_RTSCTS) {
724    z85c30_negate_RTS(minor);
725  }
726
727#if (CPU_SIMPLE_VECTORED_INTERRUPTS == TRUE)
728  set_vector(z85c30_isr, Console_Port_Tbl[minor]->ulIntVector, 1);
729#endif
730
731  z85c30_enable_interrupts(minor, SCC_ENABLE_ALL_INTR_EXCEPT_TX);
732
733  (*setReg)(ulCtrlPort1, SCC_WR0_SEL_WR2, 0);              /* XXX vector */
734  (*setReg)(ulCtrlPort1, SCC_WR0_SEL_WR9, SCC_WR9_MIE);
735
736  /*
737   * Reset interrupts
738   */
739
740  (*setReg)(ulCtrlPort1, SCC_WR0_SEL_WR0, SCC_WR0_RST_INT);
741}
742
743/*
744 *  z85c30_write_support_int
745 *
746 *  Console Termios output entry point.
747 *
748 */
749
750Z85C30_STATIC ssize_t z85c30_write_support_int(
751  int   minor,
752  const char *buf,
753  size_t len)
754{
755  uint32_t       Irql;
756  uint32_t       ulCtrlPort;
757  setRegister_f  setReg;
758
759  ulCtrlPort = Console_Port_Tbl[minor]->ulCtrlPort1;
760  setReg     = Console_Port_Tbl[minor]->setRegister;
761
762  /*
763   *  We are using interrupt driven output and termios only sends us
764   *  one character at a time.
765   */
766
767  if ( !len )
768    return 0;
769
770  /*
771   *  Put the character out and enable interrupts if necessary.
772   */
773
774  if (Console_Port_Tbl[minor]->pDeviceFlow != &z85c30_flow_RTSCTS) {
775    z85c30_assert_RTS(minor);
776  }
777  rtems_interrupt_disable(Irql);
778    if ( Console_Port_Data[minor].bActive == FALSE) {
779      Console_Port_Data[minor].bActive = TRUE;
780      z85c30_enable_interrupts(minor, SCC_ENABLE_ALL_INTR);
781    }
782    (*setReg)(ulCtrlPort, SCC_WR0_SEL_WR8, *buf);
783  rtems_interrupt_enable(Irql);
784
785  return 0;
786}
787
788/*
789 *  z85c30_inbyte_nonblocking_polled
790 *
791 *  This routine polls for a character.
792 */
793
794Z85C30_STATIC int z85c30_inbyte_nonblocking_polled(
795  int  minor
796)
797{
798  volatile uint8_t    z85c30_status;
799  uint32_t            ulCtrlPort;
800  getRegister_f       getReg;
801
802  ulCtrlPort = Console_Port_Tbl[minor]->ulCtrlPort1;
803  getReg     = Console_Port_Tbl[minor]->getRegister;
804
805  /*
806   * return -1 if a character is not available.
807   */
808  z85c30_status = (*getReg)(ulCtrlPort, SCC_WR0_SEL_RD0);
809  if (!Z85C30_Status_Is_RX_character_available(z85c30_status)) {
810    return -1;
811  }
812
813  /*
814   * Return the character read.
815   */
816
817  return (*getReg)(ulCtrlPort, SCC_WR0_SEL_RD8);
818}
819
820/*
821 *  z85c30_write_support_polled
822 *
823 *  Console Termios output entry point.
824 *
825 */
826
827Z85C30_STATIC ssize_t z85c30_write_support_polled(
828  int   minor,
829  const char *buf,
830  size_t len)
831{
832  int nwrite=0;
833
834  /*
835   * poll each byte in the string out of the port.
836   */
837  while (nwrite < len) {
838    z85c30_write_polled(minor, *buf++);
839    nwrite++;
840  }
841
842  /*
843   * return the number of bytes written.
844   */
845  return nwrite;
846}
847
848/*
849 *  z85c30_write_polled
850 *
851 *  This routine transmits a character using polling.
852 */
853
854Z85C30_STATIC void z85c30_write_polled(
855  int   minor,
856  char  cChar
857)
858{
859  volatile uint8_t   z85c30_status;
860  uint32_t           ulCtrlPort;
861  getRegister_f      getReg;
862  setRegister_f      setReg;
863
864  ulCtrlPort = Console_Port_Tbl[minor]->ulCtrlPort1;
865  getReg     = Console_Port_Tbl[minor]->getRegister;
866  setReg     = Console_Port_Tbl[minor]->setRegister;
867
868  /*
869   * Wait for the Transmit buffer to indicate that it is empty.
870   */
871
872  z85c30_status = (*getReg)( ulCtrlPort, SCC_WR0_SEL_RD0 );
873
874  while (!Z85C30_Status_Is_TX_buffer_empty(z85c30_status)) {
875    /*
876     * Yield while we wait
877     */
878#if 0
879    if (_System_state_Is_up(_System_state_Get())) {
880      rtems_task_wake_after(RTEMS_YIELD_PROCESSOR);
881    }
882#endif
883    z85c30_status = (*getReg)(ulCtrlPort, SCC_WR0_SEL_RD0);
884  }
885
886  /*
887   * Write the character.
888   */
889
890  (*setReg)( ulCtrlPort, SCC_WR0_SEL_WR8, cChar );
891}
Note: See TracBrowser for help on using the repository browser.