//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;
}
本文探讨了在UEFI环境下使用EFI Boot Services创建和管理定时器的示例,展示了如何利用`Timeout`回调函数实现周期性输出。核心内容包括事件处理和定时器设置。
1561

被折叠的 条评论
为什么被折叠?



