source: rtems/bsps/i386/pc386/console/printk_support.c

Last change on this file was a52aa5b4, checked in by Joel Sherrill <joel@…>, on 07/08/22 at 13:45:31

bsps/i386/pc386: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 * @file
5 *
6 * @ingroup Console
7 *
8 * @brief printk support routines
9 *
10 * This file contains the required printk support.
11 */
12
13/*
14 *  COPYRIGHT (c) 1989-2012.
15 *  On-Line Applications Research Corporation (OAR).
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 *    notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 *    notice, this list of conditions and the following disclaimer in the
24 *    documentation and/or other materials provided with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#include <rtems.h>
40#include <rtems/bspIo.h>
41#if BSP_ENABLE_VGA
42  #include <rtems/keyboard.h>
43#endif
44#include <bsp.h>
45#include <libchip/serial.h>
46#include <libchip/ns16550.h>
47#include "../../shared/dev/serial/legacy-console.h"
48
49rtems_device_minor_number BSPPrintkPort = 0;
50
51static bool serialInit;
52static bool serialOK;
53
54static bool serialValid(console_tbl *port)
55{
56  if (port->pDeviceFns) {
57    if (!serialInit) {
58      serialOK = true;
59      if (port->pDeviceFns->deviceProbe != NULL) {
60        if (!port->pDeviceFns->deviceProbe( BSPPrintkPort ))
61          serialOK = false;
62        else if (port->pDeviceFns->deviceInitialize != NULL)
63          port->pDeviceFns->deviceInitialize( BSPPrintkPort );
64        else
65          serialOK = false;
66      }
67      serialInit = true;
68    }
69  }
70  return serialOK;
71}
72
73void BSP_outch(char ch);
74int BSP_inch(void);
75
76void BSP_outch(char ch)
77{
78  #if BSP_ENABLE_VGA
79    bool isVga =  BSPPrintkPort == BSP_CONSOLE_VGA;
80  #else
81    bool isVga = false;
82  #endif
83
84  if ( !isVga ) {
85    console_tbl *port = Console_Port_Tbl[BSPPrintkPort];
86    if (serialValid(port)) {
87      if (port->pDeviceFns->deviceWritePolled) {
88        port->pDeviceFns->deviceWritePolled( BSPPrintkPort, ch );
89      }
90      return;
91    }
92  }
93
94  #if BSP_ENABLE_VGA
95    _IBMPC_outch( ch );
96  #endif
97}
98
99int BSP_inch(void)
100{
101  #if BSP_ENABLE_VGA
102    bool isVga =  BSPPrintkPort == BSP_CONSOLE_VGA;
103  #else
104    bool isVga = false;
105  #endif
106
107  int result = -1;
108
109  if ( !isVga ) {
110    console_tbl *port = Console_Port_Tbl[BSPPrintkPort];
111    if (serialValid(port)) {
112      if (port->pDeviceFns->deviceRead) {
113        do {
114          result = port->pDeviceFns->deviceRead( BSPPrintkPort );
115        } while (result == -1);
116        return result;
117      }
118    }
119  }
120
121  #if BSP_ENABLE_VGA
122    result = BSP_wait_polled_input();
123  #endif
124
125  return result;
126}
127
128BSP_output_char_function_type     BSP_output_char = BSP_outch;
129BSP_polling_getchar_function_type BSP_poll_char = BSP_inch;
Note: See TracBrowser for help on using the repository browser.