iPXE
Defines | Functions | Variables
serial.c File Reference

Serial console. More...

#include <stddef.h>
#include <string.h>
#include <ipxe/init.h>
#include <ipxe/uart.h>
#include <ipxe/console.h>
#include <ipxe/serial.h>
#include <config/console.h>
#include <config/serial.h>

Go to the source code of this file.

Defines

#define CONSOLE_SERIAL   ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_LOG )
#define CONSOLE_PORT   0
#define CONSOLE_BAUD   COMSPEED
#define CONSOLE_LCR   UART_LCR_WPS ( COMDATA, COMPARITY, COMSTOP )

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static void serial_putchar (int character)
 Print a character to serial console.
static int serial_getchar (void)
 Get character from serial console.
static int serial_iskey (void)
 Check for character ready to read from serial console.
static void serial_init (void)
 Initialise serial console.
static void serial_shutdown (int flags __unused)
 Shut down serial console.
struct init_fn
serial_console_init_fn 
__init_fn (INIT_CONSOLE)
 Serial console initialisation function.
struct startup_fn serial_startup_fn __startup_fn (STARTUP_EARLY)
 Serial console startup function.

Variables

struct uart serial_console
 Serial console UART.
struct console_driver
serial_console_driver 
__console_driver
 Serial console.

Detailed Description

Serial console.

Definition in file serial.c.


Define Documentation

Definition at line 44 of file serial.c.

#define CONSOLE_PORT   0

Definition at line 51 of file serial.c.

Referenced by serial_init().

#define CONSOLE_BAUD   COMSPEED

Definition at line 58 of file serial.c.

Referenced by serial_init().

Definition at line 65 of file serial.c.

Referenced by serial_init().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static void serial_putchar ( int  character) [static]

Print a character to serial console.

Parameters:
characterCharacter to be printed

Definition at line 76 of file serial.c.

References uart::base, serial_console, and uart_transmit().

                                             {

        /* Do nothing if we have no UART */
        if ( ! serial_console.base )
                return;

        /* Transmit character */
        uart_transmit ( &serial_console, character );
}
static int serial_getchar ( void  ) [static]

Get character from serial console.

Return values:
characterCharacter read from console

Definition at line 91 of file serial.c.

References uart::base, data, serial_console, uart_data_ready(), and uart_receive().

                                   {
        uint8_t data;

        /* Do nothing if we have no UART */
        if ( ! serial_console.base )
                return 0;

        /* Wait for data to be ready */
        while ( ! uart_data_ready ( &serial_console ) ) {}

        /* Receive data */
        data = uart_receive ( &serial_console );

        /* Strip any high bit and convert DEL to backspace */
        data &= 0x7f;
        if ( data == 0x7f )
                data = 0x08;

        return data;
}
static int serial_iskey ( void  ) [static]

Check for character ready to read from serial console.

Return values:
TrueCharacter available to read
FalseNo character available to read

Definition at line 118 of file serial.c.

References uart::base, serial_console, and uart_data_ready().

                                 {

        /* Do nothing if we have no UART */
        if ( ! serial_console.base )
                return 0;

        /* Check UART */
        return uart_data_ready ( &serial_console );
}
static void serial_init ( void  ) [static]

Initialise serial console.

Definition at line 137 of file serial.c.

References CONSOLE_BAUD, CONSOLE_LCR, CONSOLE_PORT, DBG, rc, serial_console, strerror(), uart_init(), and uart_select().

                                 {
        int rc;

        /* Do nothing if we have no default port */
        if ( ! CONSOLE_PORT )
                return;

        /* Select UART */
        if ( ( rc = uart_select ( &serial_console, CONSOLE_PORT ) ) != 0 ) {
                DBG ( "Could not select UART %d: %s\n",
                      CONSOLE_PORT, strerror ( rc ) );
                return;
        }

        /* Initialise UART */
        if ( ( rc = uart_init ( &serial_console, CONSOLE_BAUD,
                                CONSOLE_LCR ) ) != 0 ) {
                DBG ( "Could not initialise UART %d baud %d LCR %#02x: %s\n",
                      CONSOLE_PORT, CONSOLE_BAUD, CONSOLE_LCR, strerror ( rc ));
                return;
        }
}
static void serial_shutdown ( int flags  __unused) [static]

Shut down serial console.

Parameters:
flagsShutdown flags

Definition at line 165 of file serial.c.

References uart::base, serial_console, and uart_flush().

                                                   {

        /* Do nothing if we have no UART */
        if ( ! serial_console.base )
                return;

        /* Flush any pending output */
        uart_flush ( &serial_console );

        /* Leave console enabled; it's still usable */
}
struct init_fn serial_console_init_fn __init_fn ( INIT_CONSOLE  ) [read]

Serial console initialisation function.

struct startup_fn serial_startup_fn __startup_fn ( STARTUP_EARLY  ) [read]

Serial console startup function.


Variable Documentation

Serial console UART.

Definition at line 69 of file serial.c.

Referenced by int21(), int22(), serial_getchar(), serial_init(), serial_iskey(), serial_putchar(), and serial_shutdown().

struct console_driver serial_console_driver __console_driver
Initial value:
 {
        .putchar = serial_putchar,
        .getchar = serial_getchar,
        .iskey = serial_iskey,
        .usage = CONSOLE_SERIAL,
}

Serial console.

Definition at line 129 of file serial.c.