/* Notice that lwIP implements a function with a similar name, sys_sem_wait(), that uses the sys_arch_sem_wait() function.  */
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
/* Notice that lwIP implements a function with a similar name, sys_sem_wait(), that uses the sys_arch_sem_wait() function.  */
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
{
    u32_t begin_ms, end_ms, elapsed_ms;
    u32_t ret;
    if (sem == NULL)
        return SYS_ARCH_TIMEOUT;
    begin_ms = sys_now();
    if( timeout != 0UL ) {
        ret = aos_sem_wait(sem,timeout);
        if(ret == 0) {
            end_ms = sys_now();
            elapsed_ms = end_ms - begin_ms;
            ret = elapsed_ms;
        } else {
            ret = SYS_ARCH_TIMEOUT;
        }
    } else {
        while( !(aos_sem_wait(sem, AOS_WAIT_FOREVER) == 0));
        end_ms = sys_now();
        elapsed_ms = end_ms - begin_ms;
        if( elapsed_ms == 0UL ) {
            elapsed_ms = 1UL;
        }
        ret = elapsed_ms;
    }
    return ret;
}