【问题标题】:How to create multiprocess with edk2?如何使用 edk2 创建多进程?
【发布时间】:2021-07-13 04:33:20
【问题描述】:

我已经创建了一个这样的计时器,它可以工作,但是当我想创建两个计时器一起工作时,只有一个计时器的回调功能可以工作,请帮助,谢谢:

EFI_STATUS TimerInit()
{
    EFI_STATUS  Status;
    EFI_HANDLE  TimerOne    = NULL;
    //BOOLEAN       ExitMark    = FALSE;
    static const UINTN SecondsToNanoSeconds = 1000000;

    Status = gBS->CreateEvent(
                                EVT_NOTIFY_SIGNAL | EVT_TIMER,
                                TPL_CALLBACK,
                                TimeoutSelf,
                                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 (1 )
    {       
        // do something
    }
    
    // cancel timer
    gBS->SetTimer( TimerOne, TimerCancel, 0 );
    gBS->CloseEvent( TimerOne );    

    return EFI_SUCCESS;
}

如果我创建两个计时器,我将创建另一个 TimeoutSelf 函数。也是。

【问题讨论】:

  • 能否将您的代码分享给 2 个计时器?
  • @MiSimon,我已经意识到它使用 3 个事件和 1 个计时器,谢谢。

标签: edk2


【解决方案1】:
//this is timer:
EFI_STATUS SystemTimeIntervalInit()
{
    EFI_STATUS  Status;
    EFI_HANDLE  TimerOne    = NULL;
    static const UINTN SecondsToNanoSeconds = 1000000;

    Status = gBS->CreateEvent(
                                EVT_NOTIFY_SIGNAL | EVT_TIMER,
                                TPL_CALLBACK,
                                TimeSlice,
                                NULL,
                                &TimerOne
                                );

    Status = gBS->SetTimer(
        TimerOne,
        TimerPeriodic,
        MultU64x32( SecondsToNanoSeconds, 1)
        );

    while (1)
    {       
    }
    
    gBS->SetTimer( TimerOne, TimerCancel, 0 );
    gBS->CloseEvent( TimerOne );    

    return EFI_SUCCESS;
}

//this is signal event 
VOID EFIAPI TimeSlice(IN EFI_EVENT Event,   IN VOID  *Context)
{    
    DEBUG ((EFI_D_INFO, "System time slice Loop ...\n"));
    gBS->SignalEvent (MultiTaskTriggerEvent);

    return;
}

//this is three events:
EFI_STATUS MultiProcessInit ()
{
    UINT8 i;
    EFI_GUID gMultiProcessGuid  = { 0x0579257E, 0x1843, 0x45FB, { 0x83, 0x9D, 0x6B, 0x79, 0x09, 0x38, 0x29, 0xA9 } };
    
    EFI_EVENT_NOTIFY TaskProcesses[] = {DisplaySystemDateTime, HandleKeyboardEvent, HandleMouseEvent};

    for (i = 0; i < sizeof(TaskProcesses) /sizeof(EFI_EVENT_NOTIFY); i++)
    {
        gBS->CreateEventEx(
                          EVT_NOTIFY_SIGNAL,
                          TPL_NOTIFY,
                          TaskProcesses[i],
                          NULL,
                          &gMultiProcessGuid,
                          &MultiTaskTriggerEvent
                          );
    }    

    return EFI_SUCCESS;
}
@MiSimon, I have use one timer and three events to realize it at finally. 
thanks a lot.

【讨论】:

    猜你喜欢
    • 2014-01-31
    • 2014-07-20
    • 2016-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-15
    • 1970-01-01
    相关资源
    最近更新 更多