/* Returns the thread control block for the currently active task. In case of an error the functions returns NULL.  */
sys_thread_t sys_arch_thread_current(void)
/* Returns the thread control block for the currently active task. In case of an error the functions returns NULL.  */
sys_thread_t sys_arch_thread_current(void)
{
    sys_tcb_t      *p = tasks;
    xTaskHandle     pid = xTaskGetCurrentTaskHandle(  );
    vPortEnterCritical(  );
    while( ( p != NULL ) && ( p->pid != pid ) )
    {
        p = p->next;
    }
    vPortExitCritical(  );
    return p;
}