/** Reads data from a serial device into a buffer. @param Buffer Pointer to the data buffer to store the data read from the serial device. @param NumberOfBytes Number of bytes to read from the serial device. @retval 0 NumberOfBytes is 0. @retval >0 The number of bytes read from the serial device. If this value is less than NumberOfBytes, then the read operation failed. **/ UINTN EFIAPI SerialPortRead ( OUT UINT8 *Buffer, IN UINTN NumberOfBytes ) { FN_SERIAL_PORT_READ_CHAR SerialPortReadChar; UINTN Result; if (NULL == Buffer) { return 0; } SerialPortReadChar = GetSerialPortReadChar(); if (SerialPortReadChar == 0) { return 0; } for (Result = 0; NumberOfBytes-- != 0; Result++, Buffer++) { // // Wait for the serial port to have some data. // while (!SerialPortPoll()); // // Read byte from the receive buffer. // *Buffer = SerialPortReadChar(); } return Result; }
/** Polls a debug device to see if there is any data waiting to be read. Polls a debug device to see if there is any data waiting to be read. If there is data waiting to be read from the debug device, then TRUE is returned. If there is no data waiting to be read from the debug device, then FALSE is returned. @param Handle Debug port handle. @retval TRUE Data is waiting to be read from the debug device. @retval FALSE There is no data waiting to be read from the serial device. **/ BOOLEAN EFIAPI DebugPortPollBuffer ( IN DEBUG_PORT_HANDLE Handle ) { return SerialPortPoll (); }
VOID GetOemSetupConfig(pGBL_DATA pGblData) { UINT8 i; UINT8 input = 0; if (pGblData->mem.marginTest) { pGblData->needColdReset = 1; } else { while (1) { if (SerialPortPoll()) { (VOID)SerialPortRead ((UINT8*)&input, 1); } else { break; } } DEBUG((EFI_D_ERROR, "\nPress 't' or 'T' to run MarginTest in 3 seconds, any other press to pass\n")); for (i = 0; i < 100; i++) { if (SerialPortPoll()) { (VOID)SerialPortRead ((UINT8*)&input, 1); break; } MicroSecondDelay(30000); } if ('T' == input || 't' == input) { pGblData->mem.marginTest = TRUE; pGblData->needColdReset = 1; } } return; }
VOID EFIAPI WaitForKeyEvent ( IN EFI_EVENT Event, IN VOID *Context ) { if (SerialPortPoll ()) { gBS->SignalEvent (Event); } }
/** Retrieve the status of the control bits on a serial device. @param Control A pointer to return the current control signals from the serial device. @retval RETURN_SUCCESS The control bits were read from the serial device. @retval RETURN_UNSUPPORTED The serial device does not support this operation. @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly. **/ RETURN_STATUS EFIAPI SerialPortGetControl ( OUT UINT32 *Control ) { if (!mXenConsoleInterface) { return RETURN_UNSUPPORTED; } *Control = 0; if (!SerialPortPoll ()) { *Control = EFI_SERIAL_INPUT_BUFFER_EMPTY; } return RETURN_SUCCESS; }
/** Get the serial device control bits. @param Control Control signals read from the serial device. @retval EFI_SUCCESS The control bits were read from the serial device. @retval EFI_DEVICE_ERROR The serial device is not functioning correctly. **/ RETURN_STATUS EFIAPI SerialPortGetControl ( OUT UINT32 *Control ) { if (SerialPortPoll ()) { // If a character is pending don't set EFI_SERIAL_INPUT_BUFFER_EMPTY *Control = EFI_SERIAL_OUTPUT_BUFFER_EMPTY; } else { *Control = EFI_SERIAL_INPUT_BUFFER_EMPTY | EFI_SERIAL_OUTPUT_BUFFER_EMPTY; } return EFI_SUCCESS; //return EFI_UNSUPPORTED; }
EFI_STATUS EFIAPI SerialRead ( IN EFI_SERIAL_IO_PROTOCOL *This, IN OUT UINTN *BufferSize, OUT VOID *Buffer ) { UINTN Count = 0; if (SerialPortPoll()) { Count = SerialPortRead (Buffer, *BufferSize); } if (Count != *BufferSize) { *BufferSize = Count; return EFI_TIMEOUT; } return EFI_SUCCESS; }
/** Reads data from a serial device. @param This Protocol instance pointer. @param BufferSize On input, the size of the Buffer. On output, the amount of data returned in Buffer. @param Buffer The buffer to return the data into. @retval EFI_SUCCESS The data was read. @retval EFI_DEVICE_ERROR The device reported an error. @retval EFI_TIMEOUT The data write was stopped due to a timeout. **/ EFI_STATUS EFIAPI SerialRead ( IN EFI_SERIAL_IO_PROTOCOL *This, IN OUT UINTN *BufferSize, OUT VOID *Buffer ) { UINTN Count; UINTN TimeOut; Count = 0; while (Count < *BufferSize) { TimeOut = 0; while (TimeOut < mSerialIoMode.Timeout) { if (SerialPortPoll ()) { break; } gBS->Stall (10); TimeOut += 10; } if (TimeOut >= mSerialIoMode.Timeout) { break; } SerialPortRead (Buffer, 1); Count++; Buffer = (VOID *) ((UINT8 *) Buffer + 1); } if (Count != *BufferSize) { *BufferSize = Count; return EFI_TIMEOUT; } return EFI_SUCCESS; }
EFI_STATUS EFIAPI ReadKeyStroke ( IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, OUT EFI_INPUT_KEY *Key ) { CHAR8 Char; if (!SerialPortPoll ()) { return EFI_NOT_READY; } SerialPortRead ((UINT8 *)&Char, 1); // // Check for ESC sequence. This code is not techincally correct VT100 code. // An illegal ESC sequence represents an ESC and the characters that follow. // This code will eat one or two chars after an escape. This is done to // prevent some complex FIFOing of the data. It is good enough to get // the arrow and delete keys working // Key->UnicodeChar = 0; Key->ScanCode = SCAN_NULL; if (Char == 0x1b) { SerialPortRead ((UINT8 *)&Char, 1); if (Char == '[') { SerialPortRead ((UINT8 *)&Char, 1); switch (Char) { case 'A': Key->ScanCode = SCAN_UP; break; case 'B': Key->ScanCode = SCAN_DOWN; break; case 'C': Key->ScanCode = SCAN_RIGHT; break; case 'D': Key->ScanCode = SCAN_LEFT; break; case 'H': Key->ScanCode = SCAN_HOME; break; case 'K': case 'F': // PC ANSI Key->ScanCode = SCAN_END; break; case '@': case 'L': Key->ScanCode = SCAN_INSERT; break; case 'P': case 'X': // PC ANSI Key->ScanCode = SCAN_DELETE; break; case 'U': case '/': case 'G': // PC ANSI Key->ScanCode = SCAN_PAGE_DOWN; break; case 'V': case '?': case 'I': // PC ANSI Key->ScanCode = SCAN_PAGE_UP; break; // PCANSI that does not conflict with VT100 case 'M': Key->ScanCode = SCAN_F1; break; case 'N': Key->ScanCode = SCAN_F2; break; case 'O': Key->ScanCode = SCAN_F3; break; case 'Q': Key->ScanCode = SCAN_F5; break; case 'R': Key->ScanCode = SCAN_F6; break; case 'S': Key->ScanCode = SCAN_F7; break; case 'T': Key->ScanCode = SCAN_F8; break; default: Key->UnicodeChar = Char; break; } } else if (Char == '0') { SerialPortRead ((UINT8 *)&Char, 1); switch (Char) { case 'P': Key->ScanCode = SCAN_F1; break; case 'Q': Key->ScanCode = SCAN_F2; break; case 'w': Key->ScanCode = SCAN_F3; break; case 'x': Key->ScanCode = SCAN_F4; break; case 't': Key->ScanCode = SCAN_F5; break; case 'u': Key->ScanCode = SCAN_F6; break; case 'q': Key->ScanCode = SCAN_F7; break; case 'r': Key->ScanCode = SCAN_F8; break; case 'p': Key->ScanCode = SCAN_F9; break; case 'm': Key->ScanCode = SCAN_F10; break; default : break; } } } else if (Char < ' ') { if ((Char == CHAR_BACKSPACE) || (Char == CHAR_TAB) || (Char == CHAR_LINEFEED) || (Char == CHAR_CARRIAGE_RETURN)) { // Only let through EFI required control characters Key->UnicodeChar = (CHAR16)Char; } } else if (Char == 0x7f) { Key->ScanCode = SCAN_DELETE; } else { Key->UnicodeChar = (CHAR16)Char; } return EFI_SUCCESS; }