EmbeddedRelated.com
Forums

Embeded Tutorial?

Started by Tim Wescott February 10, 2008
I'm looking for a tutorial that I can forward to some folks.  I know of 
three different ways of implementing software.  

In the first, you have just one real and virtual thread of control, and 
the software goes something like:

main()
{
  // setup
  ...
  while(1)
  {
    do_this();
    delay(a_while);
    do_that();
    delay(a_while_longer);
    do_the_other_thing();
    delay(even_more);
  }
}

In the second, you're too cheap to buy an RTOS, but you want to have 
multiple virtual threads of control, so you use what I was taught to call 
a task loop and what most folks seem to call a state machine:

bool this_flag, that_flag, the_other_flag;

interrupt this_isr()      {this_flag = true; /* cleanup */}
interrupt that_isr()      {that_flag = true; /* cleanup */}
interrupt the_other_isr() {the_other_flag = true; /* cleanup */}

main()
{
  // setup
  ...
  while (1)
  {
    if (this_flag)
    {
      do_this();      // resets this_flag
    }
    if (that_flag)
    {
      do_that();      // resets that_flag
    }
    if (the_other_flag)
    {
      do_the_other_thing():  // resets the_other_flag
    }
  }
}

In the third, you spring for an RTOS.  Technically you still only have 
virtual threads of control (since your processor can't really run two 
pieces of code at once), but you use semiphores and what not to create 
the same effect.

My question is:  Does anyone know a good tutorial that covers all of 
this, or at least techniques for implementing the task loop/state machine 
method?

Thanks.

-- 
Tim Wescott
Control systems and communications consulting
http://www.wescottdesign.com

Need to learn how to apply control theory in your embedded system?
"Applied Control Theory for Embedded Systems" by Tim Wescott
Elsevier/Newnes, http://www.wescottdesign.com/actfes/actfes.html

Tim Wescott wrote:

> I'm looking for a tutorial that I can forward to some folks. I know of > three different ways of implementing software. > > In the first, you have just one real and virtual thread of control,
[...]
> In the second, you're too cheap to buy an RTOS, but you want to have > multiple virtual threads of control, so you use what I was taught to call > a task loop and what most folks seem to call a state machine
[...]
> In the third, you spring for an RTOS.
[...]
> My question is: Does anyone know a good tutorial that covers all of > this, or at least techniques for implementing the task loop/state machine > method?
I don't know if there is a book with the necessary depth and breadth. May be you can write one? It will certainly be useful. Jack Ganssle's "Art of designing embedded systems" has a chapter where he talks about interrupts and state machines. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
On Feb 10, 4:03 pm, Tim Wescott <t...@seemywebsite.com> wrote:
> I'm looking for a tutorial that I can forward to some folks. I know of > three different ways of implementing software.
The rule of embedded software is that there is no real rule. I just finished an implementation with a mix of your case 1 and case 2:
> > In the first, you have just one real and virtual thread of control, and > the software goes something like: >
While counting down / timing Data converter Update display Check for buttons Change state Finish tasks When counter/timer expires, switch to:
> > In the second, you're too cheap to buy an RTOS, but you want to have > multiple virtual threads of control, so you use what I was taught to call > a task loop and what most folks seem to call a state machine: >
Button Change Interrupt Service Routine While no Button Change Shutdown data converter Shutdown display Power down / sleep < wake up from interrupt > Update display Do data conversion Back to task loop -------------------------------------------------- I can't say for sure if my software is a task loop or an interrupt loop. So, rules are made to be broken.
Tim Wescott wrote:

<snip>
> > My question is: Does anyone know a good tutorial that covers all of > this, or at least techniques for implementing the task loop/state machine > method?
Believe it or not, LaBrosse's book covers each topic you cited with example (pseudo) code and is quite tutorial in its approach in my opinion. Michael
"Tim Wescott"
> I'm looking for a tutorial that I can forward to some folks. I know of > three different ways of implementing software.
[..]
> In the third, you spring for an RTOS. Technically you still only have > virtual threads of control (since your processor can't really run two > pieces of code at once), but you use semiphores and what not to create > the same effect. > > My question is: Does anyone know a good tutorial that covers all of > this, or at least techniques for implementing the task loop/state machine > method?
There is a book called "Patterns for time triggered embedded systems". "... in the case of many embedded systems, the time triggered approach has many advantages. Indeed, within industrial sectors where safety is an obvious concern, such as the aerospace industry and increasingly the automotive industry, time triggered techniques are widely used because it is accepted both by the system developers and their certification authorities, that they help improve reliability and safety." http://www.le.ac.uk/engineering/mjp9/pttes.html
"Lanarcam" <lanarcam1@yahoo.fr> a &#4294967295;crit dans le message news:
47b02654$0$27988$426a74cc@news.free.fr...
> "Tim Wescott" > > http://www.le.ac.uk/engineering/mjp9/pttes.html >
And there is this free downloadable course http://www.le.ac.uk/engineering/mjp9/pes1ohp_a4.pdf
On Feb 10, 7:03=A0pm, Tim Wescott <t...@seemywebsite.com> wrote:
> I'm looking for a tutorial that I can forward to some folks. =A0I know of > three different ways of implementing software. =A0 > > In the first, you have just one real and virtual thread of control, and > the software goes something like: > > main() > { > =A0 // setup > =A0 ... > =A0 while(1) > =A0 { > =A0 =A0 do_this(); > =A0 =A0 delay(a_while); > =A0 =A0 do_that(); > =A0 =A0 delay(a_while_longer); > =A0 =A0 do_the_other_thing(); > =A0 =A0 delay(even_more); > =A0 } > > } > > In the second, you're too cheap to buy an RTOS, but you want to have > multiple virtual threads of control, so you use what I was taught to call > a task loop and what most folks seem to call a state machine: > > bool this_flag, that_flag, the_other_flag; > > interrupt this_isr() =A0 =A0 =A0{this_flag =3D true; /* cleanup */} > interrupt that_isr() =A0 =A0 =A0{that_flag =3D true; /* cleanup */} > interrupt the_other_isr() {the_other_flag =3D true; /* cleanup */} > > main() > { > =A0 // setup > =A0 ... > =A0 while (1) > =A0 { > =A0 =A0 if (this_flag) > =A0 =A0 { > =A0 =A0 =A0 do_this(); =A0 =A0 =A0// resets this_flag > =A0 =A0 } > =A0 =A0 if (that_flag) > =A0 =A0 { > =A0 =A0 =A0 do_that(); =A0 =A0 =A0// resets that_flag > =A0 =A0 } > =A0 =A0 if (the_other_flag) > =A0 =A0 { > =A0 =A0 =A0 do_the_other_thing(): =A0// resets the_other_flag > =A0 =A0 } > =A0 } > > } > > In the third, you spring for an RTOS. =A0Technically you still only have > virtual threads of control (since your processor can't really run two > pieces of code at once), but you use semiphores and what not to create > the same effect. > > My question is: =A0Does anyone know a good tutorial that covers all of > this, or at least techniques for implementing the task loop/state machine > method? > > Thanks. > > -- > Tim Wescott > Control systems and communications consultinghttp://www.wescottdesign.com > > Need to learn how to apply control theory in your embedded system? > "Applied Control Theory for Embedded Systems" by Tim Wescott > Elsevier/Newnes,http://www.wescottdesign.com/actfes/actfes.html
The following article about hierarchical state machine design might interest you: http://www.eventhelix.com/RealtimeMantra/HierarchicalStateMachine.htm You will also find a lot of articles about Real-time and embedded programming at: http://www.eventhelix.com/RealtimeMantra/ -- EventStudio 4.0 - http://www.Eventhelix.com/Eventstudio/ Sequence diagram based embedded system design tool
msg wrote:
> Tim Wescott wrote: > > <snip> >> >> My question is: Does anyone know a good tutorial that covers all of >> this, or at least techniques for implementing the task loop/state >> machine method? > > Believe it or not, LaBrosse's book covers each topic you cited with > example (pseudo) code and is quite tutorial in its approach in my > opinion. > > Michael
I don't have Labross's book, although I've skimmed it and watched someone use it to port mucus to a brand new chapter. I don't care how good the programmer* is -- any time someone can prop a book up by their monitor, just type in code, and have it all work, it's a good book. So I'll take that quite seriously. * Well, he's a good programmer, too. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" gives you just what it says. See details at http://www.wescottdesign.com/actfes/actfes.html
Lanarcam schrieb:
> http://www.le.ac.uk/engineering/mjp9/pes1ohp_a4.pdf
That's very interesting! I'll keep this as a generic tutorial in case I meet someone who is interested in such a course. It supplemented my knowledge on Embedded stuffs as well :) cheers, Matthias -- Matthias Arndt <marndt@asmsoftware.de> PGP-Key: http://www.final-memory.org/files/marndt.asc ICQ: 40358321
>>> Jabber: simonsunnyboy@jabber.ccc.de <<<
msg wrote:
> Tim Wescott wrote: > > <snip> >> >> My question is: Does anyone know a good tutorial that covers all of >> this, or at least techniques for implementing the task loop/state >> machine method? > > Believe it or not, LaBrosse's book covers each topic you cited with > example (pseudo) code and is quite tutorial in its approach in my > opinion.
Considering that Jean LaBrosse appears to have 4 books in print: http://www.amazon.com/s/ref=nb_ss_b/002-3183383-0799266?url=search-alias%3Dstripbooks&field-keywords=LaBrosse%2C+jean&x=0&y=0 Could you tell us to which one you are referring? Thanks. -- _____________________ Christopher R. Carlen crobc@bogus-remove-me.sbcglobal.net SuSE 9.1 Linux 2.6.5