/* Wait for a semaphore with timeout (specified in ms) */
int sys_sem_wait_timeout(sys_sem_t sem, u32_t timeout)
/* Wait for a semaphore with timeout (specified in ms) */
int sys_sem_wait_timeout(sys_sem_t sem, u32_t timeout)
{
  struct sswt_cb sswt_cb;
  sswt_cb.psem = &sem;
  sswt_cb.timeflag = 0;
  if (timeout > 0) {
    sys_timeout(timeout, sswt_handler, &sswt_cb);
  }
  sys_sem_wait(sem);
  if (sswt_cb.timeflag) {
    return 0;
  } else {
    sys_untimeout(sswt_handler, &sswt_cb);
    return 1;
  }
}