console.c File Reference

#include "stddef.h"
#include "console.h"
#include <gpxe/process.h>
#include <gpxe/nap.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
void putchar (int character)
 Write a single character to each console device.
static struct console_driverhas_input (void)
 Check to see if any input is available on any console.
int getchar (void)
 Read a single character from any console.
int iskey (void)
 Check for available input on any console.


Detailed Description

Definition in file console.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

void putchar ( int  character  ) 

Write a single character to each console device.

Parameters:
character Character to be written
Return values:
None -
Exceptions:
None -
The character is written out to all enabled console devices, using each device's console_driver::putchar() method.

Definition at line 21 of file console.c.

References CONSOLES, console_driver::disabled, for_each_table_entry, console_driver::putchar, and putchar().

Referenced by ansiscr_putc(), clrline(), eepro_poll(), epic100_open(), falcon_init_xmac(), get_eeprom_data(), int21(), print_user_string(), printf_putchar(), putchar(), readline(), and sync_console().

00021                                {
00022         struct console_driver *console;
00023 
00024         /* Automatic LF -> CR,LF translation */
00025         if ( character == '\n' )
00026                 putchar ( '\r' );
00027 
00028         for_each_table_entry ( console, CONSOLES ) {
00029                 if ( ( ! console->disabled ) && console->putchar )
00030                         console->putchar ( character );
00031         }
00032 }

static struct console_driver* has_input ( void   )  [static, read]

Check to see if any input is available on any console.

Parameters:
None -
Return values:
console Console device that has input available, if any.
NULL No console device has input available.
Exceptions:
None -
All enabled console devices are checked once for available input using each device's console_driver::iskey() method. The first console device that has available input will be returned, if any.

Definition at line 47 of file console.c.

References CONSOLES, console_driver::disabled, for_each_table_entry, console_driver::iskey, and NULL.

Referenced by getchar(), and iskey().

00047                                                   {
00048         struct console_driver *console;
00049 
00050         for_each_table_entry ( console, CONSOLES ) {
00051                 if ( ( ! console->disabled ) && console->iskey ) {
00052                         if ( console->iskey () )
00053                                 return console;
00054                 }
00055         }
00056         return NULL;
00057 }

int getchar ( void   ) 

Read a single character from any console.

Parameters:
None -
Return values:
character Character read from a console.
Exceptions:
None -
A character will be read from the first enabled console device that has input available using that console's console_driver::getchar() method. If no console has input available to be read, this method will block. To perform a non-blocking read, use something like

   int key = iskey() ? getchar() : -1;

The character read will not be echoed back to any console.

Definition at line 80 of file console.c.

References cpu_nap(), console_driver::getchar, has_input(), and step().

Referenced by ansiscr_getc(), getchar_timeout(), getkey(), iflinkwait(), int21(), monojob_wait(), more(), pause(), and shell_banner().

00080                      {
00081         struct console_driver *console;
00082         int character;
00083 
00084         while ( 1 ) {
00085                 console = has_input();
00086                 if ( console && console->getchar ) {
00087                         character = console->getchar ();
00088                         break;
00089                 }
00090 
00091                 /* Doze for a while (until the next interrupt).  This works
00092                  * fine, because the keyboard is interrupt-driven, and the
00093                  * timer interrupt (approx. every 50msec) takes care of the
00094                  * serial port, which is read by polling.  This reduces the
00095                  * power dissipation of a modern CPU considerably, and also
00096                  * makes Etherboot waiting for user interaction waste a lot
00097                  * less CPU time in a VMware session.
00098                  */
00099                 cpu_nap();
00100 
00101                 /* Keep processing background tasks while we wait for
00102                  * input.
00103                  */
00104                 step();
00105         }
00106 
00107         /* CR -> LF translation */
00108         if ( character == '\r' )
00109                 character = '\n';
00110 
00111         return character;
00112 }

int iskey ( void   ) 

Check for available input on any console.

Parameters:
None -
Return values:
True Input is available on a console
False Input is not available on any console
Exceptions:
None -
All enabled console devices are checked once for available input using each device's console_driver::iskey() method. If any console device has input available, this call will return True. If this call returns True, you can then safely call getchar() without blocking.

Definition at line 128 of file console.c.

References has_input().

Referenced by ansiscr_peek(), getchar_timeout(), iflinkwait(), int21(), monojob_wait(), pxe_menu_prompt_and_select(), pxe_menu_select(), and shell_banner().

00128                    {
00129         return has_input() ? 1 : 0;
00130 }


Generated on Tue Apr 6 20:01:14 2010 for gPXE by  doxygen 1.5.7.1