]> git.proxmox.com Git - mirror_edk2.git/commitdiff
When SerialPortWrite() is called with a non-NULL Buffer and NumberOfBytes is passed...
authorniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 10 Sep 2012 02:32:45 +0000 (02:32 +0000)
committerniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 10 Sep 2012 02:32:45 +0000 (02:32 +0000)
Signed-off-by: Ruiyu Ni<ruiyu.ni@intel.com>
Reviewed-by: Kinney Michael D<michael.d.kinney@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13708 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c

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