source: rtems/c/src/lib/libbsp/mips/jmr3904/console/console-io.c @ c8471315

4.104.114.84.95
Last change on this file since c8471315 was c8471315, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 25, 2000 at 6:58:05 PM

2000-11-25 Joel Sherrill <joel@…>

  • The JMR BSP is for a Toshiba TX39 evaluation board but can also be used with the mips simulator in gdb.
  • .cvsignore, ChangeLog?, Makefile.am, README, bsp_specs, configure.in, clock/.cvsignore, clock/Makefile.am, clock/clockdrv.c, console/.cvsignore, console/Makefile.am, console/console-io.c, include/.cvsignore, include/Makefile.am, include/bsp.h, start/.cvsignore, start/Makefile.am, start/regs.S, start/start.S, startup/.cvsignore, startup/Makefile.am, startup/bspstart.c, startup/linkcmds, wrapup/.cvsignore, wrapup/Makefile.am: New files.
  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 *  This file contains the hardware specific portions of the TTY driver
3 *  for the serial ports on the jmr3904.
4 *
5 *  Logic based on the jmr3904-io.c file in newlib 1.8.2
6 *
7 *  COPYRIGHT (c) 1989-2000.
8 *  On-Line Applications Research Corporation (OAR).
9 *
10 *  The license and distribution terms for this file may be
11 *  found in the file LICENSE in this distribution or at
12 *  http://www.OARcorp.com/rtems/license.html.
13 *
14 *  $Id$
15 */
16
17#include <bsp.h>
18#include <rtems/libio.h>
19#include <stdlib.h>
20#include <assert.h>
21
22/* external prototypes for monitor interface routines */
23
24void outbyte( char );
25char inbyte( void );
26
27#define READ_UINT8( _register_, _value_ ) \
28        ((_value_) = *((volatile unsigned char *)(_register_)))
29
30#define WRITE_UINT8( _register_, _value_ ) \
31        (*((volatile unsigned char *)(_register_)) = (_value_))
32
33#define READ_UINT16( _register_, _value_ ) \
34     ((_value_) = *((volatile unsigned short *)(_register_)))
35
36#define WRITE_UINT16( _register_, _value_ ) \
37     (*((volatile unsigned short *)(_register_)) = (_value_))
38
39
40 /* - Board specific addresses for serial chip */
41#define DIAG_BASE       0xfffff300
42#define DIAG_SLCR       (DIAG_BASE+0x00)
43#define DIAG_SLSR       (DIAG_BASE+0x04)
44#define DIAG_SLDICR     (DIAG_BASE+0x08)
45#define DIAG_SLDISR     (DIAG_BASE+0x0C)
46#define DIAG_SFCR       (DIAG_BASE+0x10)
47#define DIAG_SBRG       (DIAG_BASE+0x14)
48#define DIAG_TFIFO      (DIAG_BASE+0x20)
49#define DIAG_RFIFO      (DIAG_BASE+0x30)
50
51#define BRG_T0          0x0000
52#define BRG_T2          0x0100
53#define BRG_T4          0x0200
54#define BRG_T5          0x0300
55
56/*
57 *  Eventually console-polled.c should hook to this better.
58 */
59
60static char initialized = 0;
61
62void board_serial_init (void)
63{
64  initialized = 1;
65  WRITE_UINT16 (DIAG_SLCR, 0x0020);
66  WRITE_UINT16 (DIAG_SLDICR, 0x0000);
67  WRITE_UINT16 (DIAG_SFCR, 0x0000);
68  WRITE_UINT16 (DIAG_SBRG, BRG_T2 | 5);
69}
70
71/*
72 *  console_outbyte_polled
73 *
74 *  This routine transmits a character using polling.
75 */
76
77void console_outbyte_polled(
78  int  port,
79  char ch
80)
81{
82  unsigned short disr;
83
84  if ( !initialized )
85    board_serial_init();
86
87  for (;;)
88    {
89      READ_UINT16 (DIAG_SLDISR, disr);
90      if (disr & 0x0002)
91        break;
92    }
93  disr = disr & ~0x0002;
94  WRITE_UINT8 (DIAG_TFIFO, (unsigned char) ch);
95  WRITE_UINT16 (DIAG_SLDISR, disr);
96}
97
98/*
99 *  console_inbyte_nonblocking
100 *
101 *  This routine polls for a character.
102 */
103
104int console_inbyte_nonblocking(
105  int port
106)
107{
108  unsigned char c;
109  unsigned short disr;
110
111  if ( !initialized )
112    board_serial_init();
113
114  READ_UINT16 (DIAG_SLDISR, disr);
115  if (disr & 0x0001) {
116    disr = disr & ~0x0001;
117    READ_UINT8 (DIAG_RFIFO, c);
118    WRITE_UINT16 (DIAG_SLDISR, disr);
119    return (char) c;
120  }
121  return -1;
122}
123
Note: See TracBrowser for help on using the repository browser.