diff --git a/miosix/kernel/kernel.cpp b/miosix/kernel/kernel.cpp index 79e8c50762446ae8278b28c461245f74b8c5c7ab..80856516090149bbb492c4f04568ff50720a60e2 100644 --- a/miosix/kernel/kernel.cpp +++ b/miosix/kernel/kernel.cpp @@ -83,6 +83,8 @@ static unsigned char interruptDisableNesting=0; #ifdef USE_CSTIMER +#define CST_QUANTUM 84000 //FIXME: find a way to propagate this here!!! + /// Used for context switches with the high resolution timer static SleepData csRecord; @@ -210,7 +212,6 @@ void startKernel() // Dispatch the task to the architecture-specific function #ifdef USE_CSTIMER // Set the first checkpoint interrupt -#define CST_QUANTUM 84000 //FIXME: find a way to propagate this here!!! csRecord.p = 0; csRecord.wakeup_time = CST_QUANTUM; csRecord.next = sleeping_list; @@ -293,7 +294,7 @@ void IRQaddToSleepingList(SleepData *x) * It is used by the kernel, and should not be used by end users. * \return true if some thread was woken. */ -bool IRQwakeThreads(long long currentTick, unsigned int burst) +bool IRQwakeThreads(long long currentTick) { #ifndef USE_CSTIMER tick++;//Increment tick @@ -318,7 +319,7 @@ bool IRQwakeThreads(long long currentTick, unsigned int burst) //Add next cs item to the list via IRQaddToSleepingList //Note that the next timer interrupt is set by IRQaddToSleepingList //according to the head of the list! - csRecord.wakeup_time += burst; + csRecord.wakeup_time += CST_QUANTUM; IRQaddToSleepingList(&csRecord); //It would also set the next timer interrupt } #endif //USE_CSTIMER diff --git a/miosix/kernel/kernel.h b/miosix/kernel/kernel.h index 50c8d951cde98f90da3480f891c44b313f75c8b2..936e6ed4addd792075a65b6fd5539483cc9bf56e 100644 --- a/miosix/kernel/kernel.h +++ b/miosix/kernel/kernel.h @@ -1010,7 +1010,7 @@ private: //Need access to status friend void IRQaddToSleepingList(SleepData *x); //Needs access to status - friend bool IRQwakeThreads(long long currentTick, unsigned int burst); + friend bool IRQwakeThreads(long long currentTick); //Needs access to watermark, status, next friend void *idleThread(void *argv); //Needs to create the idle thread diff --git a/miosix/kernel/scheduler/priority/priority_scheduler.cpp b/miosix/kernel/scheduler/priority/priority_scheduler.cpp index 3645335486f8b2fe47a534a8d50eac72eb5a197a..6f58904e0999509934f648934700e028c5c3b133 100644 --- a/miosix/kernel/scheduler/priority/priority_scheduler.cpp +++ b/miosix/kernel/scheduler/priority/priority_scheduler.cpp @@ -29,8 +29,6 @@ #include "kernel/error.h" #include "kernel/process.h" -static const unsigned int cstQuantum=84000; ///FIXME: remove - #ifdef SCHED_TYPE_PRIORITY namespace miosix { @@ -199,9 +197,9 @@ void PriorityScheduler::IRQsetIdleThread(Thread *idleThread) idle=idleThread; } -unsigned int PriorityScheduler::IRQfindNextThread() +void PriorityScheduler::IRQfindNextThread() { - if(kernel_running!=0) return cstQuantum;//If kernel is paused, do nothing + if(kernel_running!=0) return;//If kernel is paused, do nothing for(int i=PRIORITY_MAX-1;i>=0;i--) { if(thread_list[i]==NULL) continue; @@ -228,7 +226,7 @@ unsigned int PriorityScheduler::IRQfindNextThread() //Rotate to next thread so that next time the list is walked //a different thread, if available, will be chosen first thread_list[i]=temp; - return cstQuantum; + return; } else temp=temp->schedData.next; if(temp==thread_list[i]->schedData.next) break; } @@ -239,7 +237,6 @@ unsigned int PriorityScheduler::IRQfindNextThread() #ifdef WITH_PROCESSES MPUConfiguration::IRQdisable(); #endif //WITH_PROCESSES - return cstQuantum; } Thread *PriorityScheduler::thread_list[PRIORITY_MAX]={0}; diff --git a/miosix/kernel/scheduler/priority/priority_scheduler.h b/miosix/kernel/scheduler/priority/priority_scheduler.h index bc7d335fe5fd9cce3be47391be2d72f11fd7eb61..510042980fcd4eea989626c3929f6a773d98bd0e 100644 --- a/miosix/kernel/scheduler/priority/priority_scheduler.h +++ b/miosix/kernel/scheduler/priority/priority_scheduler.h @@ -136,10 +136,8 @@ public: * If the kernel is paused does nothing. * It's behaviour is to modify the global variable miosix::cur which always * points to the currently running thread. - * \return the burst or time quantum. That is, the time till the next - * preemption */ - static unsigned int IRQfindNextThread(); + static void IRQfindNextThread(); private: diff --git a/miosix/kernel/scheduler/scheduler.h b/miosix/kernel/scheduler/scheduler.h index 566c98cc0f374f4d12fe673fa00e6b4aeef71058..08e1f1620a5b94a3ff6e92ec762b2830f5c1f451 100644 --- a/miosix/kernel/scheduler/scheduler.h +++ b/miosix/kernel/scheduler/scheduler.h @@ -163,12 +163,10 @@ public: * If the kernel is paused does nothing. * It's behaviour is to modify the global variable miosix::cur which always * points to the currently running thread. - * \return the burst or time quantum. That is, the time till the next - * preemption */ - static unsigned int IRQfindNextThread() + static void IRQfindNextThread() { - return T::IRQfindNextThread(); + T::IRQfindNextThread(); } }; diff --git a/miosix/kernel/scheduler/timer_interrupt.h b/miosix/kernel/scheduler/timer_interrupt.h index f7d05a7415b9fda36adfb1c4fcf63ef593825dc7..6ae1406889051148a92d918a4bc3ebe31ddd6a98 100644 --- a/miosix/kernel/scheduler/timer_interrupt.h +++ b/miosix/kernel/scheduler/timer_interrupt.h @@ -40,15 +40,16 @@ namespace miosix { extern volatile int kernel_running;///\internal Do not use outside the kernel extern volatile bool tick_skew;///\internal Do not use outside the kernel extern volatile Thread *cur;///\internal Do not use outside the kernel -extern bool IRQwakeThreads(long long currentTick, unsigned int burst);///\internal Do not use outside the kernel +extern bool IRQwakeThreads(long long currentTick);///\internal Do not use outside the kernel inline void IRQtimerInterrupt(long long currentTick) { miosix_private::IRQstackOverflowCheck(); + IRQwakeThreads(currentTick); - unsigned int burst=Scheduler::IRQfindNextThread();//If the kernel is running, preempt + Scheduler::IRQfindNextThread();//If the kernel is running, preempt if(kernel_running!=0) tick_skew=true; - IRQwakeThreads(currentTick,burst); + #ifndef SCHED_TYPE_PRIORITY