📄 boot sequence - tinyos documentation wiki.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0046)http://docs.tinyos.net/index.php/Boot_Sequence -->
<HTML lang=en dir=ltr xml:lang="en"
xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>Boot Sequence - TinyOS Documentation Wiki</TITLE>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<META content="Boot Sequence,Boot Sequence,Sensing,Storage" name=keywords><LINK
href="/favicon.ico" rel="shortcut icon"><LINK
title="TinyOS Documentation Wiki (English)" href="/opensearch_desc.php"
type=application/opensearchdescription+xml rel=search>
<STYLE type=text/css media="screen, projection">@import url( /skins/common/shared.css?97 );
@import url( /skins/monobook/main.css?97 );
</STYLE>
<LINK media=print
href="Boot Sequence - TinyOS Documentation Wiki.files/commonPrint.css"
type=text/css rel=stylesheet><!--[if lt IE 5.5000]><style type="text/css">@import "/skins/monobook/IE50Fixes.css?97";</style><![endif]--><!--[if IE 5.5000]><style type="text/css">@import "/skins/monobook/IE55Fixes.css?97";</style><![endif]--><!--[if IE 6]>
<STYLE type=text/css>@import url( /skins/monobook/IE60Fixes.css?97 );
</STYLE>
<![endif]--><!--[if IE 7]><style type="text/css">@import "/skins/monobook/IE70Fixes.css?97";</style><![endif]--><!--[if lt IE 7]>
<SCRIPT src="Boot Sequence - TinyOS Documentation Wiki.files/IEFixes.js"
type=text/javascript></SCRIPT>
<META http-equiv=imagetoolbar content=no><![endif]-->
<SCRIPT type=text/javascript>/*<![CDATA[*/var skin = "monobook";var stylepath = "/skins";var wgArticlePath = "/index.php/$1";var wgScriptPath = "";var wgScript = "/index.php";var wgServer = "http://docs.tinyos.net";var wgCanonicalNamespace = "";var wgCanonicalSpecialPageName = false;var wgNamespaceNumber = 0;var wgPageName = "Boot_Sequence";var wgTitle = "Boot Sequence";var wgAction = "view";var wgRestrictionEdit = [];var wgRestrictionMove = [];var wgArticleId = "12";var wgIsArticle = true;var wgUserName = null;var wgUserGroups = null;var wgUserLanguage = "en";var wgContentLanguage = "en";var wgBreakFrames = false;var wgCurRevisionId = "261";/*]]>*/</SCRIPT>
<SCRIPT src="Boot Sequence - TinyOS Documentation Wiki.files/wikibits.js"
type=text/javascript><!-- wikibits js --></SCRIPT>
<SCRIPT src="Boot Sequence - TinyOS Documentation Wiki.files/index.php"
type=text/javascript><!-- site js --></SCRIPT>
<STYLE type=text/css>@import url( /index.php?title=MediaWiki:Common.css&usemsgcache=yes&action=raw&ctype=text/css&smaxage=18000 );
@import url( /index.php?title=MediaWiki:Monobook.css&usemsgcache=yes&action=raw&ctype=text/css&smaxage=18000 );
@import url( /index.php?title=-&action=raw&gen=css&maxage=18000 );
</STYLE>
<!-- Head Scripts -->
<SCRIPT src="Boot Sequence - TinyOS Documentation Wiki.files/ajax.js"
type=text/javascript></SCRIPT>
<META content="MSHTML 6.00.2900.3268" name=GENERATOR></HEAD>
<BODY class="mediawiki ns-0 ltr page-Boot_Sequence">
<DIV id=globalWrapper>
<DIV id=column-content>
<DIV id=content><A id=top name=top></A>
<H1 class=firstHeading>Boot Sequence</H1>
<DIV id=bodyContent>
<H3 id=siteSub>From TinyOS Documentation Wiki</H3>
<DIV id=contentSub></DIV>
<DIV id=jump-to-nav>Jump to: <A
href="http://docs.tinyos.net/index.php/Boot_Sequence#column-one">navigation</A>,
<A
href="http://docs.tinyos.net/index.php/Boot_Sequence#searchInput">search</A></DIV><!-- start content -->
<TABLE class=toc id=toc summary=Contents>
<TBODY>
<TR>
<TD>
<DIV id=toctitle>
<H2>Contents</H2></DIV>
<UL>
<LI class=toclevel-1><A
href="http://docs.tinyos.net/index.php/Boot_Sequence#Introduction"><SPAN
class=tocnumber>1</SPAN> <SPAN class=toctext>Introduction</SPAN></A>
<LI class=toclevel-1><A
href="http://docs.tinyos.net/index.php/Boot_Sequence#Boot_Sequence"><SPAN
class=tocnumber>2</SPAN> <SPAN class=toctext>Boot Sequence</SPAN></A>
<UL>
<LI class=toclevel-2><A
href="http://docs.tinyos.net/index.php/Boot_Sequence#Scheduler_Initialization"><SPAN
class=tocnumber>2.1</SPAN> <SPAN class=toctext>Scheduler
Initialization</SPAN></A>
<LI class=toclevel-2><A
href="http://docs.tinyos.net/index.php/Boot_Sequence#Component_initialization."><SPAN
class=tocnumber>2.2</SPAN> <SPAN class=toctext>Component
initialization.</SPAN></A>
<LI class=toclevel-2><A
href="http://docs.tinyos.net/index.php/Boot_Sequence#Signal_that_the_boot_process_has_completed."><SPAN
class=tocnumber>2.3</SPAN> <SPAN class=toctext>Signal that the boot
process has completed.</SPAN></A>
<LI class=toclevel-2><A
href="http://docs.tinyos.net/index.php/Boot_Sequence#Run_the_scheduler_loop."><SPAN
class=tocnumber>2.4</SPAN> <SPAN class=toctext>Run the scheduler
loop.</SPAN></A> </LI></UL>
<LI class=toclevel-1><A
href="http://docs.tinyos.net/index.php/Boot_Sequence#Boot_and_SoftwareInit"><SPAN
class=tocnumber>3</SPAN> <SPAN class=toctext>Boot and
SoftwareInit</SPAN></A>
<LI class=toclevel-1><A
href="http://docs.tinyos.net/index.php/Boot_Sequence#Related_Documentation"><SPAN
class=tocnumber>4</SPAN> <SPAN class=toctext>Related
Documentation</SPAN></A> </LI></UL></TD></TR></TBODY></TABLE>
<SCRIPT type=text/javascript> if (window.showTocToggle) { var tocShowText = "show"; var tocHideText = "hide"; showTocToggle(); } </SCRIPT>
<A name=Introduction></A>
<H1><SPAN class=mw-headline>Introduction</SPAN></H1>
<P>One of the frequently asked questions regarding TinyOS is, "Where is
<CODE>main()</CODE>?". In previous lessons, we deferred detailed discussion of
the TinyOS boot sequence: applications handle the <TT>Boot.booted</TT> event and
start from there. This tutorial describes the steps that occur before and after
this event, showing how to properly initialize components. </P><A
name=Boot_Sequence></A>
<H1><SPAN class=mw-headline>Boot Sequence</SPAN></H1>
<P>The TinyOS boot sequence has four steps: </P>
<OL>
<LI>Scheduler initialization
<LI>Component initialization
<LI>Signal that the boot process has completed
<LI>Run the scheduler </LI></OL>
<P>The application-level boot sequence component is <TT>MainC</TT> (in
tos/system). MainC provides one interface, <TT>Boot</TT> and uses one interface,
<TT>Init as SoftwareInit</TT>. The boot sequence calls SoftwareInit.init() as
part of step 2 and signals Boot.booted in step 3. </P>
<P>The default real boot sequence is in the component <TT>RealMainP</TT>. Note
that its name ends in P, denoting that components should not directly wire to
it. This is RealMainP's signature: </P><PRE> module RealMainP {
provides interface Booted;
uses {
interface Scheduler;
interface Init as PlatformInit;
interface Init as SoftwareInit;
}
}
</PRE>
<P>MainC only provides Boot and uses SoftwareInit; RealMainP uses two additional
interfaces, PlatformInit and Scheduler. MainC hides these from applications by
automatically wiring them to the system's scheduler and platform initialization
sequence. The difference between PlatformInit and SoftwareInit is predominantly
one of hardware vs. software. PlatformInit is responsible for placing core
platform services into meaningful states; for example, the PlatformInit of mica
platforms calibrates their clocks. </P>
<P>This is the code of RealMainP: </P><PRE> implementation {
int main() __attribute__ ((C, spontaneous)) {
atomic {
call Scheduler.init();
call PlatformInit.init();
while (call Scheduler.runNextTask());
call SoftwareInit.init();
while (call Scheduler.runNextTask());
}
__nesc_enable_interrupt();
signal Boot.booted();
call Scheduler.taskLoop();
return -1;
}
default command error_t PlatformInit.init() { return SUCCESS; }
default command error_t SoftwareInit.init() { return SUCCESS; }
default event void Boot.booted() { }
}
</PRE>
<P>The code shows the four steps described above. </P><A
name=Scheduler_Initialization></A>
<H2><SPAN class=mw-headline>Scheduler Initialization</SPAN></H2>
<P>The first boot step is to initialize the scheduler. If the scheduler were not
initialized before the components, component initialization routines would not
be able to post tasks. While not all components require tasks to be posted, this
gives the flexibility required for those components that do. The boot sequence
runs tasks after each initialization stage in order to allow long-running
operations, since they only happen once. <A class="external text"
title=http://www.tinyos.net/tinyos-2.x/doc/html/tep106.html
href="http://www.tinyos.net/tinyos-2.x/doc/html/tep106.html" rel=nofollow>TEP
106</A> describes TinyOS schedulers in greater detail, including information on
how to replace the scheduler. </P><A name=Component_initialization.></A>
<H2><SPAN class=mw-headline>Component initialization.</SPAN></H2>
<P>After RealMainP initializes the scheduler, it initializes the platform. The
<CODE>Init</CODE> interface implements only the single command
<CODE>init()</CODE>. </P><PRE>tos/interfaces/Init.nc:
interface Init {
command error_t init();
}
</PRE>
<P>The platform initialization phase is the responsability of the platform
implementer. Thus, <CODE>PlatformInit</CODE> is wired to the platform-specific
initialization component, <CODE>PlatformC</CODE>. No other component should be
wired to <CODE>PlatformInit</CODE>. Any component that requires initialization
can implement the <CODE>Init</CODE> interface and wire itself to
<CODE>MainC</CODE>'s <CODE>SoftwareInit</CODE> interface: </P><PRE>tos/system/MainC.nc:
configuration MainC {
provides interface Boot;
uses interface Init as SoftwareInit;
}
implementation {
components PlatformC, RealMainP, TinySchedulerC;
RealMainP.Scheduler -> TinySchedulerC;
RealMainP.PlatformInit -> PlatformC;
// Export the SoftwareInit and Booted for applications
SoftwareInit = RealMainP.SoftwareInit;
Boot = RealMainP;
}
</PRE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -