gnupic: Re: [gnupic] multitasking


Previous by date: 31 Jan 2005 12:58:22 +0000 Re: pic18forth pre-alpha 0.0.3, David McNab
Next by date: 31 Jan 2005 12:58:22 +0000 Re: [gnupic] seek opinion re multitasking, Robert J. Lee
Previous in thread:
Next in thread: 31 Jan 2005 12:58:22 +0000 Re: [gnupic] multitasking, nisma.gmx.net

Subject: Re: [gnupic] multitasking
From: ####@####.####
Date: 31 Jan 2005 12:58:22 +0000
Message-Id: <1629.1107176274@www73.gmx.net>

> David McNab wrote:
> > Hi GnuPic'ers
> >
> > Need some opinions here.
> >
> > Development of Pic18Forth continues to surge, with the current dev
> > version (not yet released) now having throw/catch exception handling,
> > dynamic memory allocation and inline assembly.
> >
> > Now, I'm thinking about multitasking.
> >
> > Since Pic18Forth is VM-based, there's some good opportunities and
> > flexibility for implementing multitasking, with several different
> > schemes possible.
> >
> > Minimal 'task control block' could contain as little as just the current
> > IP, return stack pointer and data stack pointer.
> >
> > Options are:
> > 1) No multitasking - 'desire for multitasking reflects poor software
> > design'
> >
> > 2) Voluntary round-robin - threads explicitly invoke a 'task-switch'
> > function to voluntarily relinquish control of the CPU and allow another
> > task to run - also, potentially blocking functions such as 'get char
> > from tty' imply a task switch.
> >
> > 3) Task-as-event-handler - each task is dispatched like an event
> > handler, and is expected to terminate promptly
> >
> > 4) Pre-emptive task switching - the bytecode execution loop may
> > context-switch at any time before executing the next bytecode.
> >
> > What is your preferred tasking model for PIC programming?
> >I have made good experience with a fixed sheme of task:

32 ticks/second | keep it configurable. 32 tasks works great with rtc
clocks, if
used to provide a reliable timebase and save power.
Every task can set a task done flag. 
If this flag is set, then the task is skipped until the next tick.
Tasks are invoked in a fixed order and are expected to exit shortly. This is
not
a requirement.
The first task, that runs is task 0 and only task 0 is guaranted to be
executed
every tick.
There exists other tasks, 5min, interrupt task and so on.

The task scheduler use a similar schedule:

task_done() { processed|=Task; }

run_task(byte id) {
    task=id&TASKS;
    next_task=task+1;
    Task=pinz(task); /* pinz== 1<<(val&7) , it's only a code optimisation */
    if (task<=USER_TASKS)
    if (processed&Task) return;
    // doit ...
}

scheduler() {
     static byte s,s1,s75;
     static bit s1_set, s300_set, s900_set;
     if (tick_set) /* tick_set is a bit variable set by the interrupt
handler */
            { processed=0; next_task=0; ...; s=++s&32; }
      if (!s) { s1_set=1; if (++s1==75) s75++,s1=0; s300_set=!(s75&3); ... }
     run_task(next_task);
     if (task==task_done) idle_task(); /* generally task_done is
((1<<TASKS)-1) */
     task_00(); /* if a high speed task is needed (sw interrupt running task
INT...)
     if (next_task==TASKS) run_task(INTERNAL0);
     if (s1_set) { s1_set=0; run_task(TASK1S); }
     if (s300_set) { s300_set=0; run_task(TASK5M); }
     ...
}

-- 
GMX im TV ... Die Gedanken sind frei ... Schon gesehen?
Jetzt Spot online ansehen: http://www.gmx.net/de/go/tv-spot

Previous by date: 31 Jan 2005 12:58:22 +0000 Re: pic18forth pre-alpha 0.0.3, David McNab
Next by date: 31 Jan 2005 12:58:22 +0000 Re: [gnupic] seek opinion re multitasking, Robert J. Lee
Previous in thread:
Next in thread: 31 Jan 2005 12:58:22 +0000 Re: [gnupic] multitasking, nisma.gmx.net


Powered by ezmlm-browse 0.20.