/* Sends the current thread sleeping and sets a reference variable.  */
msg_t osalThreadSuspendTimeoutS(thread_reference_t *trp, sysinterval_t timeout)
/* Sends the current thread sleeping and sets a reference variable.  */
msg_t osalThreadSuspendTimeoutS(thread_reference_t *trp, sysinterval_t timeout)
{
    TX_TIMER timer;
    msg_t msg;
    osalDbgCheck(trp != NULL);
    if (TIME_IMMEDIATE == timeout)
    {
        return MSG_TIMEOUT;
    }
    if (TIME_INFINITE == timeout)
    {
        return osalThreadSuspendS(trp);
    }
    tx_timer_create(&timer, NULL, SuspendTimeoutCallback, (uint32_t)trp, timeout, 0, TX_AUTO_ACTIVATE);
    msg = osalThreadSuspendS(trp);
    tx_timer_delete(&timer);
    return msg;
}