Revision: 13708
          http://edk2.svn.sourceforge.net/edk2/?rev=13708&view=rev
Author:   niruiyu
Date:     2012-09-10 02:32:45 +0000 (Mon, 10 Sep 2012)
Log Message:
-----------
When SerialPortWrite() is called with a non-NULL Buffer and NumberOfBytes is 
passed in as 0, just do a flush.

Signed-off-by: Ruiyu Ni<[email protected]>
Reviewed-by: Kinney Michael D<[email protected]>

Modified Paths:
--------------
    
trunk/edk2/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c

Modified: 
trunk/edk2/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c
===================================================================
--- 
trunk/edk2/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c 
    2012-09-07 03:15:25 UTC (rev 13707)
+++ 
trunk/edk2/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c 
    2012-09-10 02:32:45 UTC (rev 13708)
@@ -1,7 +1,7 @@
 /** @file
   16550 UART Serial Port library functions
 
-  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
@@ -89,10 +89,56 @@
 }
 
 /**
+  Return whether the hardware flow control signal allows writing.
+
+  @retval TRUE  The serial port is writable.
+  @retval FALSE The serial port is not writable.
+**/
+BOOLEAN
+SerialPortWritable (
+  VOID
+  )
+{
+  if (PcdGetBool (PcdSerialUseHardwareFlowControl)) {
+    if (PcdGetBool (PcdSerialDetectCable)) {
+      //
+      // Wait for both DSR and CTS to be set
+      //   DSR is set if a cable is connected.
+      //   CTS is set if it is ok to transmit data
+      //
+      //   DSR  CTS  Description                               Action
+      //   ===  ===  ========================================  ========
+      //    0    0   No cable connected.                       Wait
+      //    0    1   No cable connected.                       Wait
+      //    1    0   Cable connected, but not clear to send.   Wait
+      //    1    1   Cable connected, and clear to send.       Transmit
+      //
+      return (BOOLEAN) ((SerialPortReadRegister (R_UART_MSR) & (B_UART_MSR_DSR 
| B_UART_MSR_CTS)) == (B_UART_MSR_DSR | B_UART_MSR_CTS));
+    } else {
+      //
+      // Wait for both DSR and CTS to be set OR for DSR to be clear.  
+      //   DSR is set if a cable is connected.
+      //   CTS is set if it is ok to transmit data
+      //
+      //   DSR  CTS  Description                               Action
+      //   ===  ===  ========================================  ========
+      //    0    0   No cable connected.                       Transmit
+      //    0    1   No cable connected.                       Transmit
+      //    1    0   Cable connected, but not clear to send.   Wait
+      //    1    1   Cable connected, and clar to send.        Transmit
+      //
+      return (BOOLEAN) ((SerialPortReadRegister (R_UART_MSR) & (B_UART_MSR_DSR 
| B_UART_MSR_CTS)) != (B_UART_MSR_DSR));
+    }
+  }
+
+  return TRUE;
+}
+
+/**
   Initialize the serial device hardware.
   
   If no initialization is required, then return RETURN_SUCCESS.
-  If the serial device was successfuly initialized, then return RETURN_SUCCESS.
+  If the serial device was successfully initialized, then return 
RETURN_SUCCESS.
   If the serial device could not be initialized, then return 
RETURN_DEVICE_ERROR.
   
   @retval RETURN_SUCCESS        The serial device was initialized.
@@ -202,6 +248,23 @@
     return 0;
   }
 
+  if (NumberOfBytes == 0) {
+    //
+    // Flush the hardware
+    //
+
+    //
+    // Wait for both the transmit FIFO and shift register empty.
+    //
+    while ((SerialPortReadRegister (R_UART_LSR) & B_UART_LSR_TEMT) == 0);
+
+    //
+    // Wait for the hardware flow control signal
+    //
+    while (!SerialPortWritable ());
+    return 0;
+  }
+
   //
   // Compute the maximum size of the Tx FIFO
   //
@@ -226,39 +289,12 @@
     // Fill then entire Tx FIFO
     //
     for (Index = 0; Index < FifoSize && NumberOfBytes != 0; Index++, 
NumberOfBytes--, Buffer++) {
-      if (PcdGetBool (PcdSerialUseHardwareFlowControl)) {
-        if (PcdGetBool (PcdSerialDetectCable)) {
-          //
-          // Wait for both DSR and CTS to be set
-          //   DSR is set if a cable is connected.
-          //   CTS is set if it is ok to transmit data
-          //
-          //   DSR  CTS  Description                               Action
-          //   ===  ===  ========================================  ========
-          //    0    0   No cable connected.                       Wait
-          //    0    1   No cable connected.                       Wait
-          //    1    0   Cable connected, but not clear to send.   Wait
-          //    1    1   Cable connected, and clear to send.       Transmit
-          //
-          while ((SerialPortReadRegister (R_UART_MSR) & (B_UART_MSR_DSR | 
B_UART_MSR_CTS)) != (B_UART_MSR_DSR | B_UART_MSR_CTS));
-        } else {
-          //
-          // Wait for both DSR and CTS to be set OR for DSR to be clear.  
-          //   DSR is set if a cable is connected.
-          //   CTS is set if it is ok to transmit data
-          //
-          //   DSR  CTS  Description                               Action
-          //   ===  ===  ========================================  ========
-          //    0    0   No cable connected.                       Transmit
-          //    0    1   No cable connected.                       Transmit
-          //    1    0   Cable connected, but not clear to send.   Wait
-          //    1    1   Cable connected, and clar to send.        Transmit
-          //
-          while ((SerialPortReadRegister (R_UART_MSR) & (B_UART_MSR_DSR | 
B_UART_MSR_CTS)) == (B_UART_MSR_DSR));
-        }
-      }
-      
       //
+      // Wait for the hardware flow control signal
+      //
+      while (!SerialPortWritable ());
+
+      //
       // Write byte to the transmit buffer.
       //
       SerialPortWriteRegister (R_UART_TXBUF, *Buffer);

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to