Exemplo n.º 1
0
void nOS_LeaveIsr (void)
{
    nOS_StatusReg   sr;

#if (NOS_CONFIG_SAFE > 0)
    if (nOS_running)
#endif
    {
        nOS_EnterCritical(sr);
        nOS_isrNestingCounter--;
#if (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0) || (NOS_CONFIG_SCHED_ROUND_ROBIN_ENABLE > 0)
        if (nOS_isrNestingCounter == 0) {
 #if (NOS_CONFIG_SCHED_LOCK_ENABLE > 0)
            if (nOS_lockNestingCounter == 0)
 #endif
            {
 #if (NOS_CONFIG_HIGHEST_THREAD_PRIO == 0)
                nOS_highPrioThread = nOS_GetHeadOfList(&nOS_readyThreadsList);
 #elif (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0)
                nOS_highPrioThread = nOS_FindHighPrioThread();
 #else
                nOS_highPrioThread = nOS_GetHeadOfList(&nOS_readyThreadsList[nOS_runningThread->prio]);
 #endif
                if (nOS_runningThread != nOS_highPrioThread) {
                    *(volatile uint32_t *)0xE000ED04UL = 0x10000000UL;
                }
            }
        }
#endif
        nOS_LeaveCritical(sr);
    }
}
Exemplo n.º 2
0
nOS_Stack *nOS_LeaveIsr (nOS_Stack *sp)
{
#if (NOS_CONFIG_SAFE > 0)
    if (nOS_running)
#endif
    {
        // Enter critical here is not needed, interrupts are already disabled
        nOS_isrNestingCounter--;
        if (nOS_isrNestingCounter == 0) {
#if (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0) || (NOS_CONFIG_SCHED_ROUND_ROBIN_ENABLE > 0)
 #if (NOS_CONFIG_SCHED_LOCK_ENABLE > 0)
            if (nOS_lockNestingCounter == 0)
 #endif
            {
 #if (NOS_CONFIG_HIGHEST_THREAD_PRIO == 0)
                nOS_highPrioThread = nOS_GetHeadOfList(&nOS_readyThreadsList);
 #elif (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0)
                nOS_highPrioThread = nOS_FindHighPrioThread();
 #else
                nOS_highPrioThread = nOS_GetHeadOfList(&nOS_readyThreadsList[nOS_runningThread->prio]);
 #endif
                nOS_runningThread = nOS_highPrioThread;
            }
#endif
            sp = nOS_runningThread->stackPtr;
        }
    }

    return sp;
}
Exemplo n.º 3
0
bool nOS_QueueIsFull (nOS_Queue *queue)
{
    nOS_StatusReg   sr;
    bool            full;

#if (NOS_CONFIG_SAFE > 0)
    if (queue == NULL) {
        full = false;
    } else
#endif
    {
        nOS_EnterCritical(sr);
#if (NOS_CONFIG_SAFE > 0)
        if (queue->e.type != NOS_EVENT_QUEUE) {
            full = false;
        } else
#endif
        {
            full = queue->buffer != NULL ?
                        queue->bcount == queue->bmax :
                        nOS_GetHeadOfList(&queue->e.waitList) != NULL ?  /* A thread can be ready to consume message */
                            false :
                            true;
        }
        nOS_LeaveCritical(sr);
    }

    return full;
}
Exemplo n.º 4
0
void nOS_SignalProcess (void)
{
    nOS_StatusReg       sr;
    nOS_Signal          *signal  = NULL;
    nOS_SignalCallback  callback = NULL;
    void                *arg     = NULL;

    nOS_EnterCritical(sr);
    if (nOS_SemTake (&_signalSem,
#if (NOS_CONFIG_SIGNAL_THREAD_ENABLE > 0)
                     NOS_WAIT_INFINITE
#else
                     NOS_NO_WAIT
#endif
                     ) == NOS_OK)
    {
        signal = (nOS_Signal *)nOS_GetHeadOfList(&_signalList);
        if (signal != NULL) {
            if (signal->state & NOS_SIGNAL_RAISED) {
                signal->state = (nOS_SignalState)(signal->state &~ NOS_SIGNAL_RAISED);
                nOS_RemoveFromList(&_signalList, &signal->node);

                callback = signal->callback;
                arg      = signal->arg;
            }
        }
    }
    nOS_LeaveCritical(sr);

    if (callback != NULL) {
        callback(signal, arg);
    }
}
Exemplo n.º 5
0
static void _Thread (void *arg)
#endif
{
    nOS_StatusReg   sr;

    NOS_UNUSED(arg);

    while (true) {
        nOS_AlarmProcess();

        nOS_EnterCritical(sr);
        if (nOS_GetHeadOfList(&_triggeredList) == NULL) {
            nOS_WaitForEvent(NULL,
                             NOS_THREAD_ON_HOLD
#if (NOS_CONFIG_WAITING_TIMEOUT_ENABLE > 0) || (NOS_CONFIG_SLEEP_ENABLE > 0) || (NOS_CONFIG_SLEEP_UNTIL_ENABLE > 0)
                            ,NOS_WAIT_INFINITE
#endif
                            );
        }
        nOS_LeaveCritical(sr);

#if (NOS_CONFIG_THREAD_JOIN_ENABLE > 0)
        if (false) break; /* Remove "statement is unreachable" warning */
    }

    return 0;
#else
    }
Exemplo n.º 6
0
static void* _Scheduler (void *arg)
{
    pthread_mutex_lock(&nOS_criticalSection);

    /* Signal to init we're running and ready to accept request */
    _schedStarted = true;
    pthread_cond_signal(&_schedCond);

    /* Wait until scheduler is started */
    pthread_mutex_unlock(&nOS_criticalSection);
    while (!nOS_running) {
        usleep(1000);
    }
    pthread_mutex_lock(&nOS_criticalSection);

    while (true) {
        /* Wait until a thread send a scheduling request */
        while (!_schedRequest) {
            pthread_cond_wait(&_schedCond, &nOS_criticalSection);
        }
        _schedRequest = false;

        /* Find next high prio thread and give him permission to run */
#if (NOS_CONFIG_HIGHEST_THREAD_PRIO == 0)
        nOS_highPrioThread = nOS_GetHeadOfList(&nOS_readyThreadsList);
#elif (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0)
        nOS_highPrioThread = nOS_FindHighPrioThread();
#else
        nOS_highPrioThread = nOS_GetHeadOfList(&nOS_readyThreadsList[nOS_runningThread->prio]);
#endif
        nOS_runningThread = nOS_highPrioThread;
        nOS_highPrioThread->stackPtr->running = true;
        pthread_cond_signal(&nOS_highPrioThread->stackPtr->cond);
    }

    pthread_mutex_unlock(&nOS_criticalSection);

    return 0;
}