Jason
Jason

Reputation: 13

How to create multiprocess with edk2?

i have create a timer like this, and it work will, but when I want to create two timer work together, only one timer' call back function can work, please help, thanks:

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

if I create two timer, I will create another TimeoutSelf function. too.

Upvotes: 0

Views: 159

Answers (1)

Jason
Jason

Reputation: 13

//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.

Upvotes: 0

Related Questions