Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:50

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  This file contains the hardware specific portions of the TTY driver
0005  *  for the serial ports on the jmr3904.
0006  *
0007  *  Logic based on the jmr3904-io.c file in newlib 1.8.2
0008  */
0009 
0010 /*
0011  *  COPYRIGHT (c) 1989-2000.
0012  *  On-Line Applications Research Corporation (OAR).
0013  *
0014  * Redistribution and use in source and binary forms, with or without
0015  * modification, are permitted provided that the following conditions
0016  * are met:
0017  * 1. Redistributions of source code must retain the above copyright
0018  *    notice, this list of conditions and the following disclaimer.
0019  * 2. Redistributions in binary form must reproduce the above copyright
0020  *    notice, this list of conditions and the following disclaimer in the
0021  *    documentation and/or other materials provided with the distribution.
0022  *
0023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0033  * POSSIBILITY OF SUCH DAMAGE.
0034  */
0035 
0036 #include <bsp.h>
0037 #include <bsp/console-polled.h>
0038 #include <rtems/libio.h>
0039 #include <stdlib.h>
0040 #include <assert.h>
0041 
0042 /* external prototypes for monitor interface routines */
0043 
0044 #define READ_UINT8( _register_, _value_ ) \
0045         ((_value_) = *((volatile unsigned char *)(_register_)))
0046 
0047 #define WRITE_UINT8( _register_, _value_ ) \
0048         (*((volatile unsigned char *)(_register_)) = (_value_))
0049 
0050 #define READ_UINT16( _register_, _value_ ) \
0051      ((_value_) = *((volatile unsigned short *)(_register_)))
0052 
0053 #define WRITE_UINT16( _register_, _value_ ) \
0054      (*((volatile unsigned short *)(_register_)) = (_value_))
0055 
0056  /* - Board specific addresses for serial chip */
0057 #define DIAG_BASE       0xfffff300
0058 #define DIAG_SLCR       (DIAG_BASE+0x00)
0059 #define DIAG_SLSR       (DIAG_BASE+0x04)
0060 #define DIAG_SLDICR     (DIAG_BASE+0x08)
0061 #define DIAG_SLDISR     (DIAG_BASE+0x0C)
0062 #define DIAG_SFCR       (DIAG_BASE+0x10)
0063 #define DIAG_SBRG       (DIAG_BASE+0x14)
0064 #define DIAG_TFIFO      (DIAG_BASE+0x20)
0065 #define DIAG_RFIFO      (DIAG_BASE+0x30)
0066 
0067 #define BRG_T0          0x0000
0068 #define BRG_T2          0x0100
0069 #define BRG_T4          0x0200
0070 #define BRG_T5          0x0300
0071 
0072 /*
0073  *  Eventually console-polled.c should hook to this better.
0074  */
0075 
0076 /*
0077  *  console_initialize_hardware
0078  *
0079  *  This routine initializes the console hardware.
0080  *
0081  */
0082 
0083 void console_initialize_hardware(void)
0084 {
0085   WRITE_UINT16 (DIAG_SLCR, 0x0020);
0086   WRITE_UINT16 (DIAG_SLDICR, 0x0000);
0087   WRITE_UINT16 (DIAG_SFCR, 0x0000);
0088   WRITE_UINT16 (DIAG_SBRG, BRG_T2 | 5);
0089 }
0090 
0091 /*
0092  *  console_outbyte_polled
0093  *
0094  *  This routine transmits a character using polling.
0095  */
0096 
0097 void console_outbyte_polled(
0098   int  port,
0099   char ch
0100 )
0101 {
0102   unsigned short disr;
0103 
0104   for (;;) {
0105     READ_UINT16 (DIAG_SLDISR, disr);
0106     if (disr & 0x0002)
0107       break;
0108   }
0109   disr = disr & ~0x0002;
0110   WRITE_UINT8 (DIAG_TFIFO, (unsigned char) ch);
0111   WRITE_UINT16 (DIAG_SLDISR, disr);
0112 }
0113 
0114 /*
0115  *  console_inbyte_nonblocking
0116  *
0117  *  This routine polls for a character.
0118  */
0119 
0120 int console_inbyte_nonblocking(
0121   int port
0122 )
0123 {
0124   unsigned char c;
0125   unsigned short disr;
0126 
0127   READ_UINT16 (DIAG_SLDISR, disr);
0128   if (disr & 0x0001) {
0129     disr = disr & ~0x0001;
0130     READ_UINT8 (DIAG_RFIFO, c);
0131     WRITE_UINT16 (DIAG_SLDISR, disr);
0132     return (char) c;
0133   }
0134   return -1;
0135 }
0136 
0137 #include <rtems/bspIo.h>
0138 
0139 static void JMR3904_output_char(char c) { console_outbyte_polled( 0, c ); }
0140 
0141 BSP_output_char_function_type           BSP_output_char = JMR3904_output_char;
0142 BSP_polling_getchar_function_type       BSP_poll_char = NULL;