UEFI Spec. Ver.2.4
GUID
#define EFI_SERIAL_IO_PROTOCOL_GUID \
{0xBB25CF6F,0xF1D4,0x11D2,0x9A,0x0C,0x00,0x90,\
0x27,0x3F,0xC1,0xFD}
Revision Number
#define EFI_SERIAL_IO_PROTOCOL_REVISION 0x00010000
Protocol Interface Structure
typedef struct {
UINT32 Revision;
EFI_SERIAL_RESET Reset;
EFI_SERIAL_SET_ATTRIBUTES SetAttributes;
EFI_SERIAL_SET_CONTROL_BITS SetControl;
EFI_SERIAL_GET_CONTROL_BITS GetControl;
EFI_SERIAL_WRITE Write;
EFI_SERIAL_READ Read;
SERIAL_IO_MODE *Mode;
} EFI_SERIAL_IO_PROTOCOL;
Parameters
Revision The revision to which the EFI_SERIAL_IO_PROTOCOL
adheres. All future revisions must be backwards compatible. If a
future version is not back wards compatible, it is not the same
GUID.
Reset Resets the hardware device.
SetAttributes Sets communication parameters for a serial device. These
include the baud rate, receive FIFO depth, transmit/receive time
out, parity, data bits, and stop bit attributes.
SetControl Sets the control bits on a serial device. These include Request to
Send and Data Terminal Ready.
GetControl Reads the status of the control bits on a serial device. These
include Clear to Send, Data Set Ready, Ring Indicator, and
Carrier Detect.
Write Sends a buffer of characters to a serial device.
Read Receives a buffer of characters from a serial device.
Mode Pointer to SERIAL_IO_MODE data. Type SERIAL_IO_MODE
is defined in “Related Definitions” below.
Related Definitions
//*******************************************************
// SERIAL_IO_MODE
//*******************************************************
typedef struct {
UINT32 ControlMask;
// current Attributes
UINT32 Timeout;
UINT64 BaudRate;
UINT32 ReceiveFifoDepth;
UINT32 DataBits;
UINT32 Parity;
UINT32 StopBits;
} SERIAL_IO_MODE;
//*******************************************************
// CONTROL BITS
//*******************************************************
// Read Only#define EFI_SERIAL_CLEAR_TO_SEND 0x0010
#define EFI_SERIAL_DATA_SET_READY 0x0020
#define EFI_SERIAL_RING_INDICATE 0x0040
#define EFI_SERIAL_CARRIER_DETECT 0x0080
#define EFI_SERIAL_INPUT_BUFFER_EMPTY 0x0100 // See if the Receive FIFO is empty.
#define EFI_SERIAL_OUTPUT_BUFFER_EMPTY 0x0200 // See if the Transmit FIFO is empty
// Write Only#define EFI_SERIAL_REQUEST_TO_SEND 0x0002
#define EFI_SERIAL_DATA_TERMINAL_READY 0x0001
// Read Write
#define EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE 0x1000
#define EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE 0x2000
#define EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE 0x4000
串列埠的原理與應用
ReceiveFifoDepth The requested depth of the FIFO on the receive side of the serial
interface. A ReceiveFifoDepth value of 0 will use the
device’s default FIFO depth
Timeout The requested time out for a single character in microseconds.
This timeout applies to both the transmit and receive side of the
interface. A Timeout value of 0 will use the device’s default
time out value.
設定組態
EFI_PARITY_TYPE Parity=NoParity;
EFI_STOP_BITS_TYPE StopBits=OneStopBit;
UINTN BaudRate=9600;
UINTN DataBits=8;
Status = SerialIo->SetAttributes (
SerialIo,
(UINT64) BaudRate, //9600
0, //use default
0, //use default
Parity, // N
(UINT8) DataBits, //8
StopBits //1
);
檢查有無資料進來
UINT32 SerialControl;
Status = SerialIo->GetControl (
SerialIo,
&SerialControl);
if (!EFI_ERROR (Status)) {
if ((SerialControl & EFI_SERIAL_INPUT_BUFFER_EMPTY) != 0) {
Status = EFI_NOT_READY;
} else {
Status = EFI_SUCCESS;
}
}
沒有留言:
張貼留言