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

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.8 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.rtems.org/license/LICENSE.
13 */
14
15#include <bsp.h>
16#include <rtems/libio.h>
17#include <stdlib.h>
18#include <assert.h>
19
20/* external prototypes for monitor interface routines */
21
22#define READ_UINT8( _register_, _value_ ) \
23        ((_value_) = *((volatile unsigned char *)(_register_)))
24
25#define WRITE_UINT8( _register_, _value_ ) \
26        (*((volatile unsigned char *)(_register_)) = (_value_))
27
28#define READ_UINT16( _register_, _value_ ) \
29     ((_value_) = *((volatile unsigned short *)(_register_)))
30
31#define WRITE_UINT16( _register_, _value_ ) \
32     (*((volatile unsigned short *)(_register_)) = (_value_))
33
34 /* - Board specific addresses for serial chip */
35#define DIAG_BASE       0xfffff300
36#define DIAG_SLCR       (DIAG_BASE+0x00)
37#define DIAG_SLSR       (DIAG_BASE+0x04)
38#define DIAG_SLDICR     (DIAG_BASE+0x08)
39#define DIAG_SLDISR     (DIAG_BASE+0x0C)
40#define DIAG_SFCR       (DIAG_BASE+0x10)
41#define DIAG_SBRG       (DIAG_BASE+0x14)
42#define DIAG_TFIFO      (DIAG_BASE+0x20)
43#define DIAG_RFIFO      (DIAG_BASE+0x30)
44
45#define BRG_T0          0x0000
46#define BRG_T2          0x0100
47#define BRG_T4          0x0200
48#define BRG_T5          0x0300
49
50/*
51 *  Eventually console-polled.c should hook to this better.
52 */
53
54/*
55 *  console_initialize_hardware
56 *
57 *  This routine initializes the console hardware.
58 *
59 */
60
61void console_initialize_hardware(void)
62{
63  WRITE_UINT16 (DIAG_SLCR, 0x0020);
64  WRITE_UINT16 (DIAG_SLDICR, 0x0000);
65  WRITE_UINT16 (DIAG_SFCR, 0x0000);
66  WRITE_UINT16 (DIAG_SBRG, BRG_T2 | 5);
67}
68
69/*
70 *  console_outbyte_polled
71 *
72 *  This routine transmits a character using polling.
73 */
74
75void console_outbyte_polled(
76  int  port,
77  char ch
78)
79{
80  unsigned short disr;
81
82  for (;;) {
83    READ_UINT16 (DIAG_SLDISR, disr);
84    if (disr & 0x0002)
85      break;
86  }
87  disr = disr & ~0x0002;
88  WRITE_UINT8 (DIAG_TFIFO, (unsigned char) ch);
89  WRITE_UINT16 (DIAG_SLDISR, disr);
90}
91
92/*
93 *  console_inbyte_nonblocking
94 *
95 *  This routine polls for a character.
96 */
97
98int console_inbyte_nonblocking(
99  int port
100)
101{
102  unsigned char c;
103  unsigned short disr;
104
105  READ_UINT16 (DIAG_SLDISR, disr);
106  if (disr & 0x0001) {
107    disr = disr & ~0x0001;
108    READ_UINT8 (DIAG_RFIFO, c);
109    WRITE_UINT16 (DIAG_SLDISR, disr);
110    return (char) c;
111  }
112  return -1;
113}
114
115#include <rtems/bspIo.h>
116
117void JMR3904_output_char(char c) { console_outbyte_polled( 0, c ); }
118
119BSP_output_char_function_type           BSP_output_char = JMR3904_output_char;
120BSP_polling_getchar_function_type       BSP_poll_char = NULL;
Note: See TracBrowser for help on using the repository browser.