📄 boot sequence - tinyos documentation wiki.htm
字号:
<P>A common issue in initialization code is dependencies between different parts
of the system. These are handled in three ways in TinyOS: </P>
<UL>
<LI>Hardware-specific initialization issues are handled directly by each
platform's <CODE>PlatformC</CODE> component.
<LI>System services (e.g., the timer, the radio) are typically written to be
independently initializable. For instance, a radio that uses a timer does not
setup the timer at radio initialisation time, rather it defers that action
until the radio is started. In other words, initialisation is used to setup
software state, and hardware state wholly owned by the service.
<LI>When a service is split into several components, the <CODE>Init</CODE>
interface for one of these components may well call <CODE>Init</CODE> (and
other) interfaces of the other components forming the service, if a specific
order is needed. </LI></UL><A
name=Signal_that_the_boot_process_has_completed.></A>
<H2><SPAN class=mw-headline>Signal that the boot process has
completed.</SPAN></H2>
<P>Once all initialization has completed, <CODE>MainC</CODE>'s
<CODE>Boot.booted()</CODE> event is signaled. Components are now free to call
<CODE>start()</CODE> and other commands on any components they are using. Recall
that in the <CODE>Blink</CODE> application, the timers were started from the
<CODE>booted()</CODE> event. This <CODE>booted</CODE> event is TinyOS's analogue
of <CODE>main</CODE> in a Unix application. </P><A
name=Run_the_scheduler_loop.></A>
<H2><SPAN class=mw-headline>Run the scheduler loop.</SPAN></H2>
<P>Once the application has been informed that the system as booted and started
needed services, TinyOS enters its core scheduling loop. The scheduler runs as
long as there are tasks on the queue. As soon as it detects an empty queue, the
scheduler puts the microcontroller into the lowest power state allowed by the
active hardware resources. For example, only having timers running usually
allows a lower power state than peripheral buses like the UART. <A
class="external text"
title=http://www.tinyos.net/tinyos-2.x/doc/html/tep112.html
href="http://www.tinyos.net/tinyos-2.x/doc/html/tep112.html" rel=nofollow>TEP
112</A> describes in detail how this process works. </P>
<P>The processor goes to sleep until it handles an interrupt. When an interrupt
arrives, the MCU exits its sleep state and runs the interrupt handler. This
causes the scheduler loop to restart. If the interrupt handler posted one or
more tasks, the scheduler runs tasks until the task queue and then returns to
sleep. </P><A name=Boot_and_SoftwareInit></A>
<H1><SPAN class=mw-headline>Boot and SoftwareInit</SPAN></H1>
<P>From the perspective of an application or high-level services, the two
important interfaces in the boot sequence are those which MainC exports: Boot
and SoftwareInit. Boot is typically only handled by the top-level application:
it starts services like timers or the radio. SoftwareInit, in contrast, touches
many difference parts of the system. If a component needs code that runs once to
initialize its state or configuration, then it can wire to SoftwareInit. </P>
<P>Typically, service components that require intialization wire themselves to
SoftwareInit rather than depend on the application writer to do so. When an
application developer is writing a large, complex system, keeping track of all
of the initialization routines can be difficult, and debugging when one is not
being called can be very difficult. To prevent bugs and simplify application
development, services typically use <I>auto-wiring</I>. </P>
<P>The term auto-wiring refers to when a component automatically wires its
dependencies rather than export them for the application writer to resolve. In
this case, rather than provide the Init interface, a service component wires its
Init interface to RealMainC. For example, <TT>PoolC</TT> is a generic memory
pool abstraction that allows you to declare a collection of memory objects for
dynamic allocation. Underneath, its implementation (<TT>PoolP</TT>) needs to
initialize its data structures. Given that this must happen for the component to
operate properly, an application writer shouldn't have to worry about it. So the
PoolC component instantiates a PoolP and wires it to MainC.SoftwareInit: </P><PRE>generic configuration PoolC(typedef pool_t, uint8_t POOL_SIZE) {
provides interface Pool;
}
implementation {
components MainC, new PoolP(pool_t, POOL_SIZE);
MainC.SoftwareInit -> PoolP;
Pool = PoolP;
}
</PRE>
<P>In practice, this means that when MainP calls SoftwareInit.init, it calls
Init.init on a large number of components. In a typical large application, the
initialization sequence might involve as many as thirty components. But the
application developer doesn't have to worry about this: properly written
components take care of it automatically. </P><A name=Related_Documentation></A>
<H1><SPAN class=mw-headline>Related Documentation</SPAN></H1>
<UL>
<LI><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: Schedulers and Tasks</A>
<LI><A class="external text"
title=http://www.tinyos.net/tinyos-2.x/doc/html/tep107.html
href="http://www.tinyos.net/tinyos-2.x/doc/html/tep107.html" rel=nofollow>TEP
107: Boot Sequence</A> </LI></UL>
<P><B>Programming Hint 8:</B> In the top-level configuration of a software
abstraction, auto-wire Init to MainC. This removes the burden of wiring Init
from the programmer, which removes unnecessary work from the boot sequence and
removes the possibility of bugs from forgetting to wire. From <A
class="external text"
title=http://www.tinyos.net/tinyos-2.x/doc/pdf/tinyos-programming.pdf
href="http://www.tinyos.net/tinyos-2.x/doc/pdf/tinyos-programming.pdf"
rel=nofollow><I>TinyOS Programming</I></A><BR></P>
<HR>
<CENTER>
<P>< <B><A title=Sensing
href="http://docs.tinyos.net/index.php/Sensing">Previous Lesson</A></B> | <B><A
title="Boot Sequence"
href="http://docs.tinyos.net/index.php/Boot_Sequence#Introduction">Top</A></B> |
<B><A title=Storage href="http://docs.tinyos.net/index.php/Storage">Next Lesson
</A>></B> </P></CENTER><!-- Saved in parser cache with key tinyosdocs:pcache:idhash:12-0!1!0!!en!2!edit=0 and timestamp 20080401123003 -->
<DIV class=printfooter>Retrieved from "<A
href="http://docs.tinyos.net/index.php/Boot_Sequence">http://docs.tinyos.net/index.php/Boot_Sequence</A>"</DIV><!-- end content -->
<DIV class=visualClear></DIV></DIV></DIV></DIV>
<DIV id=column-one>
<DIV class=portlet id=p-cactions>
<H5>Views</H5>
<DIV class=pBody>
<UL>
<LI class=selected id=ca-nstab-main><A title="View the content page [c]"
accessKey=c href="http://docs.tinyos.net/index.php/Boot_Sequence">Article</A>
<LI class=new id=ca-talk><A title="Discussion about the content page [t]"
accessKey=t
href="http://docs.tinyos.net/index.php?title=Talk:Boot_Sequence&action=edit">Discussion</A>
<LI id=ca-viewsource><A
title="This page is protected. You can view its source. [e]" accessKey=e
href="http://docs.tinyos.net/index.php?title=Boot_Sequence&action=edit">View
source</A>
<LI id=ca-history><A title="Past versions of this page. [h]" accessKey=h
href="http://docs.tinyos.net/index.php?title=Boot_Sequence&action=history">History</A>
</LI></UL></DIV></DIV>
<DIV class=portlet id=p-personal>
<H5>Personal tools</H5>
<DIV class=pBody>
<UL>
<LI id=pt-login><A
title="You are encouraged to log in, it is not mandatory however. [o]"
accessKey=o
href="http://docs.tinyos.net/index.php?title=Special:Userlogin&returnto=Boot_Sequence">Log
in / create account</A> </LI></UL></DIV></DIV>
<DIV class=portlet id=p-logo><A title="Visit the Main Page [z]"
style="BACKGROUND-IMAGE: url(/images/tos-jwall-small.jpg)" accessKey=z
href="http://docs.tinyos.net/index.php/Main_Page"></A></DIV>
<SCRIPT type=text/javascript> if (window.isMSIE55) fixalpha(); </SCRIPT>
<DIV class=portlet id=p-navigation>
<H5>Navigation</H5>
<DIV class=pBody>
<UL>
<LI id=n-mainpage><A title="Visit the Main Page [z]" accessKey=z
href="http://docs.tinyos.net/index.php/Main_Page">Main Page</A>
<LI id=n-portal><A
title="About the project, what you can do, where to find things"
href="http://docs.tinyos.net/index.php/TinyOS_Documentation_Wiki:Community_Portal">Community
portal</A>
<LI id=n-currentevents><A
title="Find background information on current events"
href="http://docs.tinyos.net/index.php/Current_events">Current events</A>
<LI id=n-recentchanges><A title="The list of recent changes in the wiki. [r]"
accessKey=r
href="http://docs.tinyos.net/index.php/Special:Recentchanges">Recent
changes</A>
<LI id=n-randompage><A title="Load a random page [x]" accessKey=x
href="http://docs.tinyos.net/index.php/Special:Random">Random page</A>
<LI id=n-help><A title="The place to find out."
href="http://docs.tinyos.net/index.php/Help:Contents">Help</A>
<LI id=n-sitesupport><A title="Support us"
href="http://docs.tinyos.net/index.php/TinyOS_Documentation_Wiki:Site_support">Donations</A>
</LI></UL></DIV></DIV>
<DIV class=portlet id=p-search>
<H5><LABEL for=searchInput>Search</LABEL></H5>
<DIV class=pBody id=searchBody>
<FORM id=searchform action=/index.php/Special:Search>
<DIV><INPUT id=searchInput title="Search TinyOS Documentation Wiki [f]"
accessKey=f name=search> <INPUT class=searchButton id=searchGoButton type=submit value=Go name=go> <INPUT class=searchButton id=mw-searchButton type=submit value=Search name=fulltext>
</DIV></FORM></DIV></DIV>
<DIV class=portlet id=p-tb>
<H5>Toolbox</H5>
<DIV class=pBody>
<UL>
<LI id=t-whatlinkshere><A title="List of all wiki pages that link here [j]"
accessKey=j
href="http://docs.tinyos.net/index.php/Special:Whatlinkshere/Boot_Sequence">What
links here</A>
<LI id=t-recentchangeslinked><A
title="Recent changes in pages linked from this page [k]" accessKey=k
href="http://docs.tinyos.net/index.php/Special:Recentchangeslinked/Boot_Sequence">Related
changes</A>
<LI id=t-upload><A title="Upload images or media files [u]" accessKey=u
href="http://docs.tinyos.net/index.php/Special:Upload">Upload file</A>
<LI id=t-specialpages><A title="List of all special pages [q]" accessKey=q
href="http://docs.tinyos.net/index.php/Special:Specialpages">Special pages</A>
<LI id=t-print><A title="Printable version of this page [p]" accessKey=p
href="http://docs.tinyos.net/index.php?title=Boot_Sequence&printable=yes">Printable
version</A>
<LI id=t-permalink><A title="Permanent link to this version of the page"
href="http://docs.tinyos.net/index.php?title=Boot_Sequence&oldid=261">Permanent
link</A> </LI></UL></DIV></DIV></DIV><!-- end of the left (by default at least) column -->
<DIV class=visualClear></DIV>
<DIV id=footer>
<DIV id=f-poweredbyico><A href="http://www.mediawiki.org/"><IMG
alt="Powered by MediaWiki"
src="Boot Sequence - TinyOS Documentation Wiki.files/poweredby_mediawiki_88x31.png"></A></DIV>
<UL id=f-list>
<LI id=lastmod>This page was last modified 00:55, 28 December 2007.
<LI id=viewcount>This page has been accessed 569 times.
<LI id=privacy><A title="TinyOS Documentation Wiki:Privacy policy"
href="http://docs.tinyos.net/index.php/TinyOS_Documentation_Wiki:Privacy_policy">Privacy
policy</A>
<LI id=about><A title="TinyOS Documentation Wiki:About"
href="http://docs.tinyos.net/index.php/TinyOS_Documentation_Wiki:About">About
TinyOS Documentation Wiki</A>
<LI id=disclaimer><A title="TinyOS Documentation Wiki:General disclaimer"
href="http://docs.tinyos.net/index.php/TinyOS_Documentation_Wiki:General_disclaimer">Disclaimers</A>
</LI></UL></DIV>
<SCRIPT type=text/javascript>if (window.runOnloadHook) runOnloadHook();</SCRIPT>
</DIV><!-- Served in 0.333 secs. --></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -