Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Real Time Scheduler Implementation ( Preemption Question )

Status
Not open for further replies.

Sobakava

Full Member level 6
Joined
Mar 27, 2002
Messages
350
Helped
8
Reputation
16
Reaction score
8
Trophy points
1,298
Activity points
3,342
scheduler implementation

Hi all,

I'm implementing a Real-Time Task Scheduler using NXP LPC 2148 ARM7 CPU using GCC-Winarm.

The scheduler will be Rate Monotonic ( tasks with shorter periods have higher priorities ) and pre-emptive.

I already implemented rate-monotonism but I've problems with preemption. The scheduler runs with hardware timer interrupt. Then scheduler runs by interrupt, it checks the task list and task status list then decides which task to run.

but,

for instance, ( @ t = at time)

@ 0 : Timer interrupt occurs, scheduler starts TASK1 . Let's say it will run for 10 miliseconds.
@ 1 : Timer interrupt again. Scheduler decides TASK1 can continue. Returns from interrupt. ( It'll return to TASK1(); function )
@ 2: same as 1
@ 3: same as 1
.
.
@ 11: Timer interrupt. Scheduler decides TASK1 should wait and TASK2 should run immediately... Changes the task list. HERE: Now I've to return from interrupt. But it will return to TASK1();



void TASK1( void ) {


do something
do something
--- >>> interrupt ( task1 should continue)
do something
do something
--- >>> interrupt ( task1 should continue)
do something
do something
--- >>> interrupt ( task1 should continue)
do something
do something
--- >>> interrupt ( task1 should be preempted and TASK2 should run! )
do something
do something
do something
do something

}




I need a suggestion on how to let the scheduler manage the task and itself. First interrupt based approach seemed good to me but I can not figure out how to do it now. Any help will be appreciated.

Best Regards
 

+task scheduler+callback

Each task has it's own stack on which to save its context. The interrupt saves the running tasks context on the stack and saves the stack pointer.
It then changes the stack pointer to the next tasks stack and restores the tasks context. When the interrupt returns, the new task resumes execution.
 

    Sobakava

    Points: 2
    Helpful Answer Positive Rating
real time scheduler

I have posted a lightweight rtos/multitasking system for the 16-bit Pic micros on eda board here:



It includes documentation describing the implementation.
Take a look, it might give you some ideas for your system.
 

real-time scheduler

Hi

You can use software interrupt or Callback function (ptr to function) in order to switch task without saving the context.

All the best

Bobi
 

implementierung preemption

U can make your scheduler more simpler rather than using a interrupt in every time slice, u can add a delay routine which will count the time ticks based upon the task start.
It can be as follows, make priority of task 1 highest let say 1.
Then when you want to run the task 2 or task n.
Add the following implementation in your task.
task1()
{
.....
osdelay(20);
...
}
osdelay() should interrupt the task and then invoke the scheduler so that task1 status is delayed or suspended, after 20 ms the task1 again resumes.
So the context switch overhead is avoided.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top