Page 1 of 1

Erika OSEK general query

Posted: Sat Mar 08, 2014 6:33 pm
by katoch
Hi,

I am looking forward to adapt my current application program to schedule by OSEk .
So found on net Erika OSEK is open source to use.

My application have 4 task called every 5,10,20 & 40 ms interval :--
5_ms_task, 10_ms_task, 20_ms_task, 40_ms_task

I am using a 1_ms timer which use to increment the counter for each task, and call each task
from my startOS() function depending upon their turn :--


My scheduler code :--

Code: Select all

void StartOS(void)
{
    /* Start the OS */
    for(;;){

        if(COUNTER_5MS == COUNTER_5MS_MAX){

            TaskOs_05();

            COUNTER_5MS = 0x00;
        }else {
            /*do Nothing*/
        }


        if(COUNTER_10MS == COUNTER_10MS_MAX){

            TaskOs_10();

            COUNTER_10MS = 0x00;

        }else {
            /*do Nothing*/
        }

        if(COUNTER_20MS == COUNTER_20MS_MAX){

            TaskOs_20();

            COUNTER_20MS = 0x00;

        }else {
            /*do Nothing*/
        }

        if(COUNTER_40MS == COUNTER_40MS_MAX){

            TaskOs_40();

            COUNTER_40MS = 0x00;

        }else {
            /*do Nothing*/
        }

}

timer for 1-msec Interrupt :---

Code: Select all

__interrupt static void r_wutm_interrupt(void)
{
`
   if(COUNTER_10MS < COUNTER_10MS_MAX){
       COUNTER_10MS++;
   }else {
       /*do Nothing*/
   }

   if(COUNTER_20MS < COUNTER_20MS_MAX){
       COUNTER_20MS++;
   }else {
       /*do Nothing*/
   }

   if(COUNTER_40MS < COUNTER_40MS_MAX){
       COUNTER_40MS++;
   }else {
       /*do Nothing*/
   }

}
5ms task have more priority so i have kept it on top of all the task in the scheduler.
But this is a simple scheduler and do have some disadvantage that if suppose 20 ms task is running and during that time timer interrupt occurs
and condition for 40ms & 5ms task both are satisfied then my top priority task will have to wait for completion of 20 & 40 msec task to complete
before getting share of processor. Preemption property is not their at present in this scheduler.


As per the OSEK specification for BCC1 :--
BCC1 (only basic tasks, limited to one activation request per task and one task per priority, while all tasks have different priorities)

I have few questions now, So if i switch to ERIKA OSEK and configure it for conformance class BCC1 :---
1> Does BCC1 conformance class provide preemption of the low priority task if high priority task is ready to be scheduled (like the case which i have covered above) ?
2> How does ERIKA osek keep track of time tick for each task do i have to use some hardware timer to give support to this O.S ?
3> suppose 20 ms task is running and in between during that time timer interrupt occurs and condition for 5ms task are satisfied then will OSEK preempt the 20ms task run the 5ms task & after 5 ms task finishes OSEK will resume 20 ms task is it right ? or osek will continue with current task of 20 ms & after this is completed OSEK will switch to high priority task of 5ms ?

Please suggest.

Regards,
Katoch

Re: Erika OSEK general query

Posted: Sat Mar 08, 2014 10:28 pm
by paolo.gai
Hi!

First of all, to implement a non-preemptive realtime scheduler you need to insert a "continue" statement at the end of each "then" clause... otherwise your "tasks" will not be scheduled following priority order. This somehow solves your disadvantage, but you will still have no preemption between each task.

Apart for that, the answers are:

1) yes - ERIKA can be configured to be fully preemptive (the "task" example available in many architectures shows that)
2) just look at some demos... you declare an ISR2 attached to the timer, and you call the CounterTick / IncrementCounter function inside the interrupt handler. Afterwards, you handle everything with OSEK Alarms. A subset of the MCUs also have support for a systemtimer.
3) Yes if the 20ms task has SCHEDULE=FULL (not if SCHEDULE=NON).

I hope it helps,

PJ

Re: Erika OSEK general query

Posted: Mon Mar 10, 2014 7:19 pm
by katoch
Thanks, Paolo for your reply. I need some more help fom your side to get started. Few more questions from my side :--

>> just look at some demos.
please suggest path to demo & actual source code of ERIKA OSEK, is it on GIT ?

>> Afterwards, you handle everything with OSEK Alarms.
Means task are called in the form of Cyclic alarms ? Also for each task will there be a seperate alarm ?

>> Yes if the 20ms task has SCHEDULE=FULL (not if SCHEDULE=NON).
Means if SCHEDULE=NON then in this case current running task is completed first & then we move to other tasks depending on priority of task.
While if SCHEDULE=FULL then OS will leave the current running task inbetween & schedule the higher priority task immediately.
Have i got it right ?

1> Can ERIKA run on small micocontrollers with 4K of RAM and 32K of flash ? I am asking this question because contex switching of task will require snapshot of processor registers & stack to be saved some where in RAM ?

2> Is it possible to configure Erika osek code & use it's files within my project IDE & compile along with other files ?

Regards,
Katoch

Re: Erika OSEK general query

Posted: Mon Mar 10, 2014 7:46 pm
by paolo.gai
katoch wrote: >> just look at some demos.
please suggest path to demo & actual source code of ERIKA OSEK, is it on GIT ?
Just follow one of the many tutorials... when you cerate a new project in Eclipse, you have the possibility to select an already made example.

One with alarms is pic30/flex demo board /OO examples/event
(or something like it

The code is on SVN, check the wiki for the URLs.
katoch wrote: >> Afterwards, you handle everything with OSEK Alarms.
Means task are called in the form of Cyclic alarms ? Also for each task will there be a seperate alarm ?
You have a task, and then you have an alarm periodically activating the task. periodicity is orthogonal to task activation in osek/vdx.
katoch wrote: >> Yes if the 20ms task has SCHEDULE=FULL (not if SCHEDULE=NON).
Means if SCHEDULE=NON then in this case current running task is completed first & then we move to other tasks depending on priority of task.
While if SCHEDULE=FULL then OS will leave the current running task inbetween & schedule the higher priority task immediately.
Have i got it right ?
yes.
katoch wrote: 1> Can ERIKA run on small micocontrollers with 4K of RAM and 32K of flash ? I am asking this question because contex switching of task will require snapshot of processor registers & stack to be saved some where in RAM ?
Yes! check the various ports page. the minimal configuration is 1k flash and a few bytes of ram.
katoch wrote: 2> Is it possible to configure Erika osek code & use it's files within my project IDE & compile along with other files ?
If you use another IDE, then you need to take care of your makefiles. or you can use the RT-Druid generated makefiles to compile the project.

Ciao,

PJ

Re: Erika OSEK general query

Posted: Tue Mar 11, 2014 8:47 am
by katoch
First of all, to implement a non-preemptive realtime scheduler you need to insert a "continue" statement at the end of each "then" clause... otherwise your "tasks" will not be scheduled following priority order.
Yes i made this change this was a bug in the code, thanks.

Thanks Paolo for replying. Few more questions will come from my side to get started. Please try to answer them.

1> Pic contains very good examples, now i am able to understand how everything is going on inside OSEK :--
http://svn.tuxfamily.org/viewvc.cgi/eri ... iew=markup

Example source code is available on SVN. But i did not found the source code foe Erika OSEK on SVN where exactly it is ?

2> OIL file does not states which Conformance classes is used by OSEK where do we have to do this ?
http://svn.tuxfamily.org/viewvc.cgi/eri ... iew=markup

3> Compiling without using RT-Druid :----
I think it will be a very painfull task because ERIKA osek depends on some configuration values READ from OIL.
Did some one ever succeed in this (as you are the moderator of forum so you may know) just want to know if it is worth putting time in this ?

4> I was going through this link :---
http://erika.tuxfamily.org/wiki/index.p ... controller

What is the diffrence between mono stack & multistack , Mosly a c program memory map contains only one area of stack ?


5> Why download is so slow for the windows 32 bit executable :--
http://erika.tuxfamily.org/drupal/download.html

Regards,
katoch

Re: Erika OSEK general query

Posted: Tue Mar 11, 2014 11:31 am
by e.guidieri
katoch wrote: Example source code is available on SVN. But i did not found the source code foe Erika OSEK on SVN where exactly it is ?
The Wiki page with all the information to access repository is this
http://erika.tuxfamily.org/wiki/index.p ... SVN_Access

as shortcut I add the url for a svn anonymous checkout
[url]svn://svn.tuxfamily.org/svnroot/erika/erikae/repos/ee/trunk/ee[/url]
katoch wrote: 2> OIL file does not states which Conformance classes is used by OSEK where do we have to do this ?
http://svn.tuxfamily.org/viewvc.cgi/eri ... iew=markup
The OIL field to specify the Kernel/conformance classes is:

Code: Select all

KERNEL_TYPE = FP;
In the demo you choose, the Kernel that have been used is FP (Fixed Priority). FP it's not a true OSEK kernel, it lacks of some features, but it's a subset of OSEK even more lightweight, perfect to start to explore TASK and ALARMS.

To specify an OSEK Kernel you can use the following values (that are OSEK conformance classes):
BCC1, BCC2, ECC1, ECC2

For some architectures (like pic30) some experimental kernels/scheduler have been developed as result of reserch project. If you are interested you can ask
katoch wrote: 3> Compiling without using RT-Druid :----
I think it will be a very painfull task because ERIKA osek depends on some configuration values READ from OIL.
Did some one ever succeed in this (as you are the moderator of forum so you may know) just want to know if it is worth putting time in this ?
RT-Druid generate configuration for ERIKA and its own build system. You can use RT-Druid just to generate ERIKA configuration files eecfg.{h,c}, and plug the result in your build system. This has been done multiple time, but it's not trivial.
katoch wrote: 4> I was going through this link :---
http://erika.tuxfamily.org/wiki/index.p ... controller

What is the diffrence between mono stack & multistack , Mosly a c program memory map contains only one area of stack ?
Well usally in a normal Multitask/thread environment there's no choice that to use one stack space for each TASK/Thread because blocking semantic it's forced by syncronization API (think to posix multithread-paradigm with mutexes and condition variables). Because of the RTC (Run-to-Completition) model of the OSEK's Basic TASKs you can share stack between them (but you could still reserve a private stack in anycase). You are forced to declare a private stack if you will use Extended Task (OSEK ECC1, ECC2 conformace classes), because this kind of task can block (wait) on EVENTS.
katoch wrote: 5> Why download is so slow for the windows 32 bit executable :--
http://erika.tuxfamily.org/drupal/download.html
I think that thw hosting service that we are using has some bandwith problem in this moment. I hope this will going to the normal state soon, in any case we will check.

Regards,
Errico

Re: Erika OSEK general query

Posted: Wed Mar 12, 2014 10:07 am
by katoch
Thanks Errico for you reply, i will try my hand on it with basic Tasks & Alarm . Just last thing which i want to clarify from your last post.
Because of the RTC (Run-to-Completition) model of the OSEK's Basic TASKs you can share stack between them (but you could still reserve a private stack in anycase).
Mean to say if Erika OSEK is configured for BCC1 with basic task with SCHEDULE=FULL. Then current running task will run to complete irrespective of condiditon that high priority task is waiting for it turn. And once the current running task is completed then the execution will start as per the priority of the task waiting in the ready queue ? That Means that Preemption of current running task does not take place even if high priority task is waiting for its turn. Have i got it right ?

You can use RT-Druid just to generate ERIKA configuration files eecfg.{h,c}, and plug the result in your build system.
as shortcut I add the url for a svn anonymous checkout
svn://svn.tuxfamily.org/svnroot/erika/erikae/repos/ee/trunk/ee
I have gone through the repository you suggested in your previous post. I was able to find the eecfg.h & eecfg.c files for various controllers.
But did not found the source code of OSEK in this repository. Can you please post the exact path where OSEK source code (which will schedule the task & alarms. Lets say where is the file is SVN repository which contains definition of following function is ActivateTask() & SetRelAlarm() ) is lying ?
eecfg.h & eecfg.c files :--
http://svn.tuxfamily.org/viewvc.cgi/eri ... ake_druid/
http://svn.tuxfamily.org/viewvc.cgi/eri ... ake_druid/

In the demo you choose, the Kernel that have been used is FP (Fixed Priority). FP it's not a true OSEK kernel, it lacks of some features, but it's a subset of OSEK even more lightweight, perfect to start to explore TASK and ALARMS.
FP definition from ee_porting_1_0_1.pdf :---
The minimal API supports a conformance class named FP, which is similar to the
BCC2 conformance class of Erika Enterprise (or ECC2 if multistack is selected).

If we see the OSEK specs it states the definition of BCC2 :---
BCC2 (like BCC1, plus more than one task per priority possible and multiple requesting of task activation allowed)

So if i chose Kernel as FT with MULTI_STACK = FALSE; (i.e i am selecting mono stack), then as per above statement it is almost like BCC2.
What exactly we mean here multiple requesting of task activation allowed ? Does it means current running task can be preempted if high priority task is waiting in ready queue ?
I think that thw hosting service that we are using has some bandwith problem in this moment.
Any idea when it will be rectified ?


Please suggest on these points.

Re: Erika OSEK general query

Posted: Wed Mar 12, 2014 1:08 pm
by e.guidieri
katoch wrote:Mean to say if Erika OSEK is configured for BCC1 with basic task with SCHEDULE=FULL. Then current running task will run to complete irrespective of condiditon that high priority task is waiting for it turn. And once the current running task is completed then the execution will start as per the priority of the task waiting in the ready queue ? That Means that Preemption of current running task does not take place even if high priority task is waiting for its turn. Have i got it right ?
No.

Basic Task with SCHEDULE=FULL can be preempted and this the only way that thay "leave the execution" before the completion.

In a posix-like thread model with preemption your code looks like this

Code: Select all

 void blocking_task ( void )  {
    while ( the_task_is_Alive )  {
        /* do your stuff and can get the preempted */

        block_on_something(); /* The task wait some time and/or event before get back in the schedulable state */
    }
    /* If your task return. Usually it's dead and have to be recreated (more expensive activity than RTC activation) */
    return;
  }
In a RTC task model with preemption you cannot block but you can be re-activated in a cheap way

Code: Select all

 void task_rtc ( void ) {
    /* each activation does this stuff and can get preempted (if SCHEDULE=FULL) */
    return; /* Just return for next activation. */
 }
Two very differnt task models how you can see.
http://en.wikipedia.org/wiki/Run_to_com ... scheduling
You can use RT-Druid just to generate ERIKA configuration files eecfg.{h,c}, and plug the result in your build system.
as shortcut I add the url for a svn anonymous checkout
svn://svn.tuxfamily.org/svnroot/erika/erikae/repos/ee/trunk/ee
...
But did not found the source code of OSEK in this repository. Can you please post the exact path where OSEK source code (which will schedule the task & alarms. Lets say where is the file is SVN repository which contains definition of following function is ActivateTask() & SetRelAlarm() ) ...
Usually grep is a good tool for investigate source files. If you are under windows: Notepad++ has 'find in files' command that's as good as grep.

in any case: %ERIKA_FILES%\pkg\kernel\oo\src\ee_activate.c for ActivateTask, %ERIKA_FILES%\pkg\kernel\oo\src\ee_alsetrel.c for SetRelAlarm
...
So if i chose Kernel as FT with MULTI_STACK = FALSE; (i.e i am selecting mono stack), then as per above statement it is almost like BCC2.
What exactly we mean here multiple requesting of task activation allowed ? Does it means current running task can be preempted if high priority task is waiting in ready queue ?
I didn't undestand your question completly.
But yes, anyTASK can be preempted by one with higher priority, unless preemption is disabled for that TASK with SCHEDULE=NON OIL Field.

Re: Erika OSEK general query

Posted: Thu Mar 13, 2014 12:31 pm
by katoch
Thanks for replying.
I didn't undestand your question completly.
Actually my question is from the definition of BCC2 class. BCC2 class defination from osek specs :---
BCC2 (like BCC1, plus more than one task per priority possible and multiple requesting of task activation allowed)

Here what do we exactly mean by multiple requesting of task activation allowed ?

Also in this document :---
http://download.tuxfamily.org/erika/web ... _1_0_1.pdf
what do we mean by term pending activation (Topic - 2.2.4 Number of pending activations) ?

Please suggest.

Re: Erika OSEK general query

Posted: Thu Mar 13, 2014 1:03 pm
by e.guidieri
Ok, now the question it's more clear.
katoch wrote: Actually my question is from the definition of BCC2 class. BCC2 class defination from osek specs :---
BCC2 (like BCC1, plus more than one task per priority possible and multiple requesting of task activation allowed)
Here what do we exactly mean by multiple requesting of task activation allowed ?
In BCC1 a TASK can be inserted in ready queue only one time. All the following activation to the first (via any method like: ActivateTask, Alarm expiring, ChainTask ecc..) fail with a E_OS_LIMIT error.
Only when the TASK go back to the SUSPENDED status that means that current TASK activation end with the TASK's function calling TerminateTask, ChainTask or, improprially, simply return, another activation can be done and the status of the TASK goes from SUSPENDED to READY.

When a TASK is configured to have more than 1 activation (Conformance classes BCC2/ECC2 + TASK.ACTIVATION OIL Field > 1) the TASK can be put in ready queue multiple time (MAX until activation value). When an activation end, if the TASK have been activated multiple time, the status goes from RUNNING to READY (not supsended) and maybe can be immediatly be reactivated (if no other TASK with the same priority have been activated before the second activation of the TASK we are analysing) executing the TASK's function again (and TASK switch back to the RUNNING status).
Also in this document :---
http://download.tuxfamily.org/erika/web ... _1_0_1.pdf
what do we mean by term pending activation (Topic - 2.2.4 Number of pending activations) ?
Pending activation is the number of time that a TASK have been currently activated (this number is always less equal or led than the numer of TASK.ACTIVATION OIL Field).

One more thing: ERIKA BCC1 conformance class (and FP too), is not limited by one TASK for priority, you can define multiple TASK with the same priority, this is in fact an ERIKA's specific extension to BCC1 conformance class.

Errico

Re: Erika OSEK general query

Posted: Fri Mar 14, 2014 6:15 am
by katoch
Thanks Paolo & Errico for helping me to understand the concept.

I will start with FP & then test the behavior on the other conformance classes (BCC* & ECC*).

I will be trying on RL78/F12 controller board which i am having. I will use the freeware compiler CC78K0R which comes with cubesuite+.

This is the good link to start with. Right ?
http://erika.tuxfamily.org/wiki/index.p ... controller

Re: Erika OSEK general query

Posted: Fri Mar 14, 2014 7:59 am
by paolo.gai
Yes, this is a good starting point...

Paolo