avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] code sequence, function order


From: Erik Christiansen
Subject: Re: [avr-gcc-list] code sequence, function order
Date: Fri, 2 Jul 2004 15:55:57 +1000
User-agent: Mutt/1.3.28i

On Thu, Jul 01, 2004 at 09:50:15AM +0200, sebastian meuren wrote:
> I'm developing a mt enviroment and every task looks like that:
> void task(void* arg);
> 
> but because it's the entry-function (like main), the compiler doesn't have
> to save any registers or so.

   I must admit to implementing the scheduler for the current project in
assembler. It provides only semaphore based scheduling of "tasks"
that are really only functions, and is an easy way out of the kind of
dilemma that you face. You put your scheduler in a separate file, and
link it with the 'C'.

   On a larger scheduler, providing a separate stack space for each
task, I've found it helpful to do things backwards. A task calls a
function to pend on a semaphore, for example. The OS saves the context,
chooses the next task to run, sets the stack pointer to that task's
saved value, and _returns_ to the new task. Since it has to have made
some suspending call, or it would still be running, the task is resumed
at the line after the suspending call. A full epilogue could be part of
your context restoration, avoiding the need to write the few lines of
assembler to restore the registers. (YMMV)

  Admittedly, it is probably easiest to achieve this if part of the OS
is implemented in assembler. (Even though one was on PowerPC, and one on
avr, I haven't tried doing it all in 'C'.)

   Looking at some of the free source that's out there isn't cheating.
Trying out ideas gained from it is just a quicker way to learn.

HTH,
Erik


reply via email to

[Prev in Thread] Current Thread [Next in Thread]