MdeModulePkg/TerminalDxe: Separate state machine start/stop logic
authorRuiyu Ni <ruiyu.ni@intel.com>
Tue, 10 Jan 2017 05:25:27 +0000 (13:25 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Wed, 11 Jan 2017 09:25:26 +0000 (17:25 +0800)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c

index 129d7b3e60803fd3c54d8c3959990877c50852d6..b8dcf0c472bd2670d1f5d8a4e51618833418558d 100644 (file)
@@ -487,6 +487,63 @@ InitializeTerminalConsoleTextMode (
   return TextModeData;\r
 }\r
 \r
+/**\r
+  Stop the terminal state machine.\r
+\r
+  @param TerminalDevice    The terminal device.\r
+**/\r
+VOID\r
+StopTerminalStateMachine (\r
+  TERMINAL_DEV             *TerminalDevice\r
+  )\r
+{\r
+  EFI_TPL                  OriginalTpl;\r
+\r
+  OriginalTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  gBS->CloseEvent (TerminalDevice->TimerEvent);\r
+  gBS->CloseEvent (TerminalDevice->TwoSecondTimeOut);\r
+\r
+  gBS->RestoreTPL (OriginalTpl);\r
+}\r
+\r
+/**\r
+  Start the terminal state machine.\r
+\r
+  @param TerminalDevice    The terminal device.\r
+**/\r
+VOID\r
+StartTerminalStateMachine (\r
+  TERMINAL_DEV             *TerminalDevice\r
+  )\r
+{\r
+  EFI_STATUS               Status;\r
+  Status = gBS->CreateEvent (\r
+                  EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  TerminalConInTimerHandler,\r
+                  TerminalDevice,\r
+                  &TerminalDevice->TimerEvent\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = gBS->SetTimer (\r
+                  TerminalDevice->TimerEvent,\r
+                  TimerPeriodic,\r
+                  KEYBOARD_TIMER_INTERVAL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = gBS->CreateEvent (\r
+                  EVT_TIMER,\r
+                  TPL_CALLBACK,\r
+                  NULL,\r
+                  NULL,\r
+                  &TerminalDevice->TwoSecondTimeOut\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
 /**\r
   Initialize the controller name table.\r
 \r
@@ -893,30 +950,7 @@ TerminalDriverBindingStart (
       goto ReportError;\r
     }\r
 \r
-    Status = gBS->CreateEvent (\r
-                    EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
-                    TPL_NOTIFY,\r
-                    TerminalConInTimerHandler,\r
-                    TerminalDevice,\r
-                    &TerminalDevice->TimerEvent\r
-                    );\r
-    ASSERT_EFI_ERROR (Status);\r
-\r
-    Status = gBS->SetTimer (\r
-                    TerminalDevice->TimerEvent,\r
-                    TimerPeriodic,\r
-                    KEYBOARD_TIMER_INTERVAL\r
-                    );\r
-    ASSERT_EFI_ERROR (Status);\r
-\r
-    Status = gBS->CreateEvent (\r
-                    EVT_TIMER,\r
-                    TPL_CALLBACK,\r
-                    NULL,\r
-                    NULL,\r
-                    &TerminalDevice->TwoSecondTimeOut\r
-                    );\r
-    ASSERT_EFI_ERROR (Status);\r
+    StartTerminalStateMachine (TerminalDevice);\r
 \r
     Status = gBS->CreateEvent (\r
                     EVT_NOTIFY_SIGNAL,\r
@@ -1326,8 +1360,7 @@ TerminalDriverBindingStop (
           FreeUnicodeStringTable (TerminalDevice->ControllerNameTable);\r
         }\r
 \r
-        gBS->CloseEvent (TerminalDevice->TimerEvent);\r
-        gBS->CloseEvent (TerminalDevice->TwoSecondTimeOut);\r
+        StopTerminalStateMachine (TerminalDevice);\r
         gBS->CloseEvent (TerminalDevice->SimpleInput.WaitForKey);\r
         gBS->CloseEvent (TerminalDevice->SimpleInputEx.WaitForKeyEx);\r
         gBS->CloseEvent (TerminalDevice->KeyNotifyProcessEvent);\r