u32_t sys_arch_sem_wait(sys_sem_t sem, u32_t timeout)
{
    volatile UINT32* semaphore = (volatile UINT32*)sem;

    if(timeout != 0) 
    {
        INT64 now = ::HAL_Time_CurrentTime();
        INT64 elapsed = now + (timeout * 10000);
        
        while(elapsed > ::HAL_Time_CurrentTime()) 
        {
            if(IsSemaphoreGreen(semaphore)) 
            {
                AcquireSemaphore(semaphore); 
                break;
            }

            if(INTERRUPTS_ENABLED_STATE())
            {
                if(Events_WaitForEvents(SYSTEM_EVENT_FLAG_NETWORK, timeout))
                {
                    Events_Clear(SYSTEM_EVENT_FLAG_NETWORK);
                }
            }
            else
            {
                break;
            }
        }
    }
    else
    {
        while(1) 
        {
            // wait and call the continuation for tcpip_thread
            if(IsSemaphoreGreen(semaphore)) 
            {
                AcquireSemaphore(semaphore);
                break;
            }
            
            if(INTERRUPTS_ENABLED_STATE())
            {
                Events_WaitForEvents(SYSTEM_EVENT_FLAG_NETWORK, EVENTS_TIMEOUT_INFINITE);
                Events_Clear(SYSTEM_EVENT_FLAG_NETWORK);
            }
            else
            {
                break;
            }
        }
    }
    
    return *semaphore;
}
Пример #2
0
void sys_sem_signal(sys_sem_t sem)
{
    volatile UINT32* semaphore = (volatile UINT32*)sem;
    ReleaseSemaphore(semaphore);

    if(IsSemaphoreGreen(semaphore))
    {
        Events_Set(SYSTEM_EVENT_FLAG_NETWORK);
    }
}