AMI uefi bios 定时器的使用

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

//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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值