AMI uefi bios 定时器的使用

it2026-02-28  5

//www.lab-z.com

//感谢这位大哥的无私奉献!!!

#include  <Uefi.h> #include  <Library/UefiLib.h> //#include  <Library/ShellCEntryLib.h>

//#include  <stdio.h> //#include  <stdlib.h> //#include  <wchar.h>

//#include <Protocol/EfiShell.h> //#include <Library/ShellLib.h>

#include <Protocol/SimpleFileSystem.h> #include <Protocol/BlockIo.h> #include <Library/DevicePathLib.h> //#include <Library/HandleParsingLib.h> #include <Library/SortLib.h> #include <Library/MemoryAllocationLib.h> #include <Library/BaseMemoryLib.h>

extern EFI_BOOT_SERVICES         *gBS; extern EFI_SYSTEM_TABLE             *gST; extern EFI_RUNTIME_SERVICES      *gRT;

//extern EFI_SHELL_ENVIRONMENT2    *mEfiShellEnvironment2; extern EFI_HANDLE                 gImageHandle;

STATIC CONST UINTN SecondsToNanoSeconds = 10000000;

UINTN    Counter = 0; /**   The callback function for the timer event used to get map.

  @param[in] Event    The event this function is registered to.   @param[in] Context  The context registered to the event. **/ VOID EFIAPI Timeout (   IN EFI_EVENT      Event,   IN VOID           *Context   ) {   Print(L"www.lab-z.com [%d]\r\n",++ Counter);   return ; }

int main_timer(void ) {   EFI_STATUS                Status;   EFI_HANDLE                TimerOne = NULL;   BOOLEAN                    ExitMark=FALSE;      Status  = gBS->CreateEvent (                     EVT_NOTIFY_SIGNAL | EVT_TIMER,                     TPL_CALLBACK,                     Timeout,                     NULL,                     &TimerOne                     );          if (EFI_ERROR (Status)) {         Print(L"Create Event Error! \r\n");         return 1;     }

    Status = gBS->SetTimer (                    TimerOne,                    TimerPeriodic,                    MultU64x32 (SecondsToNanoSeconds, 1)                    );          if (EFI_ERROR (Status)) {         Print(L"Set Timer Error! \r\n");         return 2;     }

    while (!ExitMark)     {         //if (mEfiShellEnvironment2 -> GetExecutionBreak()) {ExitMark=TRUE;}

        if(Counter>5){            ExitMark=TRUE;          }     }     gBS->SetTimer (TimerOne, TimerCancel, 0);     gBS->CloseEvent (TimerOne);    

  return EFI_SUCCESS; }

最新回复(0)