]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Update the Timeout used for Write() operations to consider the case where the Tx...
authormdkinney <mdkinney@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 30 Dec 2010 22:30:57 +0000 (22:30 +0000)
committermdkinney <mdkinney@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 30 Dec 2010 22:30:57 +0000 (22:30 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11211 6f19259b-4bc3-4df7-8a09-765794883524

IntelFrameworkModulePkg/Bus/Isa/IsaSerialDxe/Serial.c

index c62e60b6f5c3806c83e9f76870678410b29cf5e9..4a12eb9e041488930cd2c766368c137729d84a56 100644 (file)
@@ -1744,6 +1744,8 @@ IsaSerialWrite (
   UINTN       Elapsed;\r
   UINTN       ActualWrite;\r
   EFI_TPL     Tpl;\r
+  UINTN       Timeout;\r
+  UINTN       BitsPerCharacter;\r
 \r
   SerialDevice  = SERIAL_DEV_FROM_THIS (This);\r
   Elapsed       = 0;\r
@@ -1767,6 +1769,36 @@ IsaSerialWrite (
 \r
   CharBuffer  = (UINT8 *) Buffer;\r
 \r
+  //\r
+  // Compute the number of bits in a single character.  This is a start bit,\r
+  // followed by the number of data bits, followed by the number of stop bits.\r
+  // The number of stop bits is specified by an enumeration that includes \r
+  // support for 1.5 stop bits.  Treat 1.5 stop bits as 2 stop bits.\r
+  //\r
+  BitsPerCharacter = \r
+    1 + \r
+    This->Mode->DataBits + \r
+    ((This->Mode->StopBits == TwoStopBits) ? 2 : This->Mode->StopBits);\r
+\r
+  //\r
+  // Compute the timeout in microseconds to wait for a single byte to be \r
+  // transmitted.  The Mode structure contans a Timeout field that is the \r
+  // maximum time to transmit or receive a character.  However, many UARTs \r
+  // have a FIFO for transmits, so the time required to add one new character\r
+  // to the transmit FIFO may be the time required to flush a full FIFO.  If \r
+  // the Timeout in the Mode structure is smaller than the time required to\r
+  // flush a full FIFO at the current baud rate, then use a timeout value that\r
+  // is required to flush a full transmit FIFO.\r
+  //\r
+  Timeout = MAX (\r
+              This->Mode->Timeout,\r
+              (UINTN)DivU64x64Remainder (\r
+                BitsPerCharacter * (SERIAL_PORT_MAX_RECEIVE_FIFO_DEPTH + 1) * 1000000,\r
+                This->Mode->BaudRate,\r
+                NULL\r
+                )\r
+              );\r
+  \r
   for (Index = 0; Index < *BufferSize; Index++) {\r
     IsaSerialFifoAdd (&SerialDevice->Transmit, CharBuffer[Index]);\r
 \r
@@ -1775,7 +1807,7 @@ IsaSerialWrite (
       //  Unsuccessful write so check if timeout has expired, if not,\r
       //  stall for a bit, increment time elapsed, and try again\r
       //\r
-      if (Elapsed >= This->Mode->Timeout) {\r
+      if (Elapsed >= Timeout) {\r
         *BufferSize = ActualWrite;\r
         gBS->RestoreTPL (Tpl);\r
         return EFI_TIMEOUT;\r