⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nido.tex

📁 无线通信的主要编程软件,是无线通信工作人员的必备工具,关天相关教程我会在后续传上.
💻 TEX
📖 第 1 页 / 共 4 页
字号:
To run {\tt Blink} with one mote, type {\tt run 1} or {\tt r 1}.  {\ttr} is the GDB command to run the current executable, and all valuesafter the {\tt r} are passed as arguments to the executable. Thereforethe {\tt 1} specifies the number of motes to simulate to \sim. MoteIDsare assigned starting at 0.  In this current example the moteID of thesingle mote being simulated is 0.Upon hitting the breakpoint at {\tt fire}, to print the value of {\ttBlinkM}'s {\tt state}, type \\{\tt printBlinkM\$state[tos\_state.current\_node]} (or {\tt p} for {\ttprint}). {\tt p} is the print command in GDB. {\tt BlinkM} correspondsto the component the field {\tt state} belongs to. Since theapplication was compiled for the pc, it is necessary to specify whichmote's {\tt BlinkM\$state} to access, as {\tt[tos\_state.current\_node]} following the field name does.\section{Concurrency Model}\sim captures the TinyOS event-driven concurrency model at interrupt andtask granularity. For a description of the TinyOS concurrency model,refer to the TinyOS documentation. This document does not describe themodel, merely how \sim implements it.\sim models each TinyOS interrupt as a simulation event. Each event isassociated with a specific mote. Simulator events run atomically withrespect to one another. Therefore, unlike on real hardware, interruptscannot pre-empt one another. After each simulator event executes, \simchecks the task queue for any pending tasks, and executes all of themin FIFO scheduling order. In \sim, interrrupts do not pre-empt tasks.This method of task execution means that spinning tasks (e.g., tasksthat enqueue themselves in a spin-lock fashion) will cause \sim toexecute that task indefinitely. Using tasks in this way is contrary tothe event-driven TinyOS programming model.Once a simulator event calls an interrupt handler, the handlerexecutes TinyOS code through commands and events.\subsection{Sample Execution}\begin{figure*}\scriptsize\centering\begin{tabular}{ll}Time (4MHz ticks) & Action \\ \hline3987340 & Simulator event is dequeued and handled at time 3987340.\\        & The clock interrupt handler is called, signaling the application Timer event.\\        & \hspace{0.2in} {\it The application's Timer handler requests a reading from the ADC.}\\        & The ADC component puts a simulator ADC event on the queue with timestamp 3987540.\\        & The interrupt handler completes; the clock event re-enqueues itself for the next tick.\\3987540 & Simulator ADC event is dequeued and handled at time 3987540.\\        & The ADC interrupt handler is called, signaling an ADC ready event with a sensor value.\\        & \hspace{0.2in}{\it The application event handler takes the top three bits and calls LEDs commands.}\\        & The ADC interrupt handler completes.\\7987340 & Simulator event is dequeued and handled at time 7987340.\\        & The clock interrupt handler is called, signaling the application Timer event.\\        & \ldots execution continues as above\end{tabular}\caption{Sample Execution}\label{fig:exec}\end{figure*}Figure \ref{fig:exec} contains a sample execution that demonstratesthe workings of \sim. A simple program, {\tt SenseToLeds}, is runningon a single \mote. This program has a 1Hz timer that samples the lightsensor and displays the three high order bits of the reading on the\mote LEDs. Since simulator time is kept in terms of a 4MHz clock, thetimer events are four million ticks apart, and the 50$\mu$s ADCcapture takes 200 ticks between request and interrupt. In Figure\ref{fig:exec} \sim-specificexecution is shown in plain text, while unchanged TinyOS execution isshown in italics. This sample execution shows how a small number of\sim events results in the series of TinyOS events and commandscomprising an entire (albeit very simple) application.\section{Internals}\label{sec:internals}Currently, \sim compiles by using alternative implementations of somecore system components (e.g. {\tt Main.nc}, {\tt HPLUART.nc}) andincorporating a few extra files (e.g. {\tt event\_queue.c}).The basic \sim structure definitions exist in {\ttplatform/pc/nido.h}. These include the global simulation state(event queue, time, etc.) and individual node state. Hardware settingsthat affect multiple components (such as the potentiometer setting)currently must be modeled as global node state. {\tt nido.h} alsoincludes a few useful macros, such as {\tt NODE\_NUM} and {\ttTHIS\_NODE}; these should be used whenever possible, so minimal codemodifications will be necessary if the data representationchanges. {\tt Nido.nc} is where the \sim global state is defined. The {\ttmain()} function parses the command line options, initializes the\sim global state, initializes the external communicationfunctionality (defined in {\tt external\_comm.c, PCRadio.h}), theninitializes the state of each of the simulated motes with {\tt callStdControl.init()} and {\tt call StdControl.start()}. It then startsexecuting a small loop that handles events and schedules tasks.\subsection{\sim Architecture}\sim replaces a small number of TinyOS components, the componentsthat handle interrupts and the {\tt Main} component. Interrupts aremodeled as simulatgor discrete events. Normally, the core TinyOS loopthat runs on motes is this:\begin{verbatim}while(1){  TOSH_run_task();}\end{verbatim}{\tt TOSH\_run\_task} runs tasks until the task queue is empty, at whichpoint it puts the CPU to sleep. An interrupt will wake the mote. Ifthe interrupt has caused a task to be scheduled, then that task willbe run. While that task is running, interrupts can be handled.The core \sim loop is slightly different:\begin{verbatim}for (;;) {  while(TOSH_run_next_task()) {}  if (!queue_is_empty(&(tos_state.queue))) {	    tos_state.tos_time =       queue_peek_event_time(&(tos_state.queue));    queue_handle_next_event(&(tos_state.queue));}\end{verbatim}A notion of virtual time (stored as a 64-bit integer) is kept in thesimulator (stored in {\tt tos\_state.tos\_time}), and every event isassociated with a specific mote. Most events are emulations ofhardware interrupts. For example, when the clock in {\tt hpl.c} isinitialized to certain counter values, \sim's implementationenqueues a clock interrupt event, whose handler calls the functionnormally registered as the clock interrupt handler; from this point,normal TinyOS code takes over (in terms of events being signaled,etc.) In addition, the event enqueues another clock event for thefuture, with its time (for the event queue) being the current timeplus the time between interrupts.When compiling for \sim, the nesC compiler modifies code generationfor components such that fields declared in components result inarrays of each field.  The maximum number of motes that can besimulated at once is set at compile time by the size of this array;the default value is 1000 and is specified in {\tt /apps/Makerules}with the {\tt -fnesc-tossim-tosnodes=} flag. Since every event isassociated with a specific mote, the {\tt tos\_state.current\_node}field is set just before the event handler function is called, so thatall modifications to component fields affect the correct mote'sstate. Since all TinyOS tasks enqueued by an event are run tocompletion before the next event is handled, tasks all execute withthe same node number and access the enqueuing mote's state.\subsection{\sim Implementations}To load a component, the nesC compiler uses a directory searchpath. The default search path is:\begin{itemize}\item The application directory\item {\tt tos/platform/xxx} (the selected platform)\item {\tt tos/sensorboards/xxx} (the selected sensor board(s))\item {\tt tos/system}\item {\tt tos/lib}\end{itemize}Entries can be prepended to the search path with the {\tt -I} optionto the compiler. Using the {\tt -I} option therefore allows you to usealternative implementations of components provided by TinyOS. Forexample, one can write a \sim implementation of the microphone, andput it in a separate directory, then include that directory with {\tt-I}. This will cause the compiler to load the new \sim implementationinstead of the default one in the sensor board directory.The component model of TinyOS means that \sim implementations are notconstrained to hardware abstractions. For example, \sim has animplementation of the {\tt EEPROM} component, instead of thelower-level hardware interface. Similarly, instead of using abit-level simulation, one can write a \sim implementation of {\ttAMStandard}, for a packet-level simulation.\subsection{RFM}A \sim network model has the following structure:\begin{verbatim}typedef struct {  void(*init)();  void(*transmit)(int, char);   // int moteID, char bit  void(*stop_transmit)(int);    // int moteID  char(*hears)(int);            // char bit,   int moteID  bool(*connected)(int,int);    // int moteID1, int moteID2  link_t*(*neighbors)(int);      // int moteID} rfm_model;\end{verbatim}{\tt init}, {\tt transmit}, {\tt stop\_transmit} and {\tt hears} arestraightforward; they're used to transmit and receive bits. The {\ttconnected} and {\tt neighbors} functions are used for some specificlow-level emulations of the radio channel during bit synchronization.To give a feel for how the \sim RFM model works, we'll step throughthe lossy model. The variable names have been changed to make it a biteasier to explain.In the lossy model, each mote has four variables: the value itcurrently {\tt hears}, whether it is transmitting or not, and astructure defining its network links. Each network link has a biterror probability and stores the value currently being transmittedalong that link (after error).Every time a mote {\tt transmit()}s (after error) a 1 to another mote,that mote's {\tt hears} variable is incremented. When the transmittingmote calls {\tt stop\_transmit()}, the variable is decremented. Whenthe receiver calls {\tt hears()}, it receives a 1 if the {\tt hears}variable is non-zero. Signals are therefore modeled as a logical or.When a mote transmits a zero or one with {\tt transmit()}, thefunction scans through the list of network connections ({\ttneighbors()}). For each link, it flips the bit with the probabilityspecified by that link, and stores the bit that's actually transmitted(this is needed for when {\tt stop\_transmit()} is called, so {\tthears} can be decremented properly).\bibliographystyle{unsrt}\small\begin{thebibliography}{99}\bibitem{empirical}\newblock{D.~Ganesan, B.~Krishnamachari, A.~Woo, D.~Culler, D.~Estrin, and  S.~Wicker.}\newblock {An empirical study of epidemic algorithms in large scale multihop  wireless networks.}\newblock {\url{citeseer.nj.nec.com/ganesan02empirical.html}, 2002.}\newblock {Submitted for publication, February 2002.}\bibitem{tossim}\newblock{P.~Levis, N.~Lee, M.~Welsh, and D.~Culler.}\newblock{TOSSIM: Accurate and Scalable Simulation of Entire TinyOS Applications}\newblock{To appear in {\it Proceedings of the First ACM Conference on Embedded Networked Sensor Systems (SenSys 2003)}.}\end{thebibliography}\end{document}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -