Exemple #1
0
bool nOS_LeaveIsr (void)
{
    nOS_StatusReg   sr;
    bool            swctx = false;

#if (NOS_CONFIG_SAFE > 0)
    if (nOS_running)
#endif
    {
        nOS_EnterCritical(sr);
        nOS_isrNestingCounter--;
#if (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0)
        if (nOS_isrNestingCounter == 0) {
 #if (NOS_CONFIG_SCHED_LOCK_ENABLE > 0)
            if (nOS_lockNestingCounter == 0)
 #endif
            {
                nOS_highPrioThread = nOS_FindHighPrioThread();
                if (nOS_runningThread != nOS_highPrioThread) {
                    swctx = true;
                }
            }
        }
#endif
        nOS_LeaveCritical(sr);
    }

    return swctx;
}
Exemple #2
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);
    }
}
Exemple #3
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;
}
Exemple #4
0
nOS_Stack* nOS_LeaveIsr (nOS_Stack *sp)
{
    nOS_StatusReg   sr;

#if (NOS_CONFIG_SAFE > 0)
    if (nOS_running)
#endif
    {
        nOS_EnterCritical(sr);
        nOS_isrNestingCounter--;
        if (nOS_isrNestingCounter == 0) {
#if (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0)
 #if (NOS_CONFIG_SCHED_LOCK_ENABLE > 0)
            if (nOS_lockNestingCounter == 0)
 #endif
            {
                nOS_highPrioThread = nOS_FindHighPrioThread();
                nOS_runningThread = nOS_highPrioThread;
            }
#endif
            sp = nOS_runningThread->stackPtr;
        }
        nOS_LeaveCritical(sr);
    }

    return sp;
}
Exemple #5
0
static DWORD WINAPI _SysTick (LPVOID lpParameter)
{
    while (true) {
        Sleep(1000/NOS_CONFIG_TICKS_PER_SECOND);

        /* Enter critical section */
        while(WaitForSingleObject(nOS_hCritical, INFINITE) != WAIT_OBJECT_0);
        nOS_criticalNestingCounter = 1;

        /* Simulate entry in interrupt */
        nOS_isrNestingCounter = 1;

        nOS_Tick();

#if (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0)
        nOS_highPrioThread = nOS_FindHighPrioThread();
        if (nOS_runningThread != nOS_highPrioThread) {
            SetEvent(_hSchedRequest);
        }
#endif

        /* Simulate exit of interrupt */
        nOS_isrNestingCounter = 0;

        /* Leave critical section */
        nOS_criticalNestingCounter = 0;
        ReleaseMutex(nOS_hCritical);
    }

    return 0;
}
Exemple #6
0
nOS_Stack *nOS_LeaveIsr (nOS_Stack *sp)
{
    /* Interrupts already disabled before leaving ISR */
    nOS_isrNestingCounter--;
    if (nOS_isrNestingCounter == 0) {
#if (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0)
 #if (NOS_CONFIG_SCHED_LOCK_ENABLE > 0)
        if (nOS_lockNestingCounter == 0)
 #endif
        {
            nOS_highPrioThread = nOS_FindHighPrioThread();
            nOS_runningThread = nOS_highPrioThread;
        }
#endif
        sp = nOS_runningThread->stackPtr;
    }

    return sp;
}
Exemple #7
0
void nOS_LeaveIsr (void)
{
    nOS_EnterCritical();
    nOS_isrNestingCounter--;
#if (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0)
    if (nOS_isrNestingCounter == 0) {
 #if (NOS_CONFIG_SCHED_LOCK_ENABLE > 0)
        if (nOS_lockNestingCounter == 0)
 #endif
        {
            nOS_highPrioThread = nOS_FindHighPrioThread();
            if (nOS_runningThread != nOS_highPrioThread) {
                *(volatile uint32_t *)0xE000ED04UL = 0x10000000UL;
            }
        }
    }
#endif
    nOS_LeaveCritical();
}
Exemple #8
0
nOS_Stack *nOS_LeaveIsr (nOS_Stack *sp)
{
    // Enter critical here is not needed, interrupts are already disabled
    nOS_isrNestingCounter--;
    if (nOS_isrNestingCounter == 0) {
#if (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0)
 #if (NOS_CONFIG_SCHED_LOCK_ENABLE > 0)
        if (nOS_lockNestingCounter == 0)
 #endif
        {
            nOS_highPrioThread = nOS_FindHighPrioThread();
            nOS_runningThread = nOS_highPrioThread;
        }
#endif
        sp = nOS_runningThread->stackPtr;
    }

    return sp;
}
Exemple #9
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;
}
Exemple #10
0
void nOS_LeaveIsr (void)
{
    nOS_StatusReg   sr;

    nOS_EnterCritical(sr);
    nOS_isrNestingCounter--;
#if (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0)
    if (nOS_isrNestingCounter == 0) {
 #if (NOS_CONFIG_SCHED_LOCK_ENABLE > 0)
        if (nOS_lockNestingCounter == 0)
 #endif
        {
            nOS_highPrioThread = nOS_FindHighPrioThread();
            if (nOS_runningThread != nOS_highPrioThread) {
                /* Request a software interrupt when going out of ISR */
                *(uint8_t*)0x000872E0UL = (uint8_t)1;
            }
        }
    }
#endif
    nOS_LeaveCritical(sr);
}