Title: Get Start with TinyOS From technique perspective
1Get Start with TinyOS
From technique perspective
2Road Map
- TinyOS overview
- How TinyOS works
- Programming the mote
- Programming environment guide
3 Traditional OS Architectures
- Problem with Large Scale Deeply embedded system..
- Large memory storage requirement
- Unnecessary and overkill functionality (
address space isolation, - complex I/O subsystem , UI ) for our scenario.
- Relative high system overhead ( e.g, context
switch ) - Require complex and power consuming hardware
support.
4Which OS architecture we want
- Extremely small footprint.
- Extremely low system overhead.
- Extremely low power consumption
- Only thing we need , nothing we dont
5TinyOS Architecture Overview (1)
TinyOS
Scheduler
.
I/O
COMM .
NO Kernel Direct hardware
manipulation NO Process management Only
one process on the fly. NO Virtual memory
Single linear physical address space NO Dynamic
memory allocation Assigned at compile
time NO Software signal or exception
Function Call instead Goal to strip down memory
size and system overhead.
6TinyOS Architecture Overview (2)
- Characteristic of TinyOS
- No UI, power constrained
- Unusually application specific HW and SW
- Multiple flows, concurrency intensive bursts
- Extremely passive vigilance ( power saving )
- Tightly coupled with the application.
Main (includes Scheduler)
Application (User Components)
Simplified TinyOS Architecture
Mote Hardware
7Road Map
- TinyOS overview
- How TinyOS works
- Programming the mote
- Programming environment guide
8How it works Scheduling
- Two-level scheduling ( Event and Task )
- Single shared stack ( used by both interrupt and
function call) - Scheduler is simple FIFO with bounded number of
pending task. - Task can NOT preempt each other.
- Event has high priority than Task. Event can
preempt task - Event can preempt each other , once enabled
- When idle , scheduler shut down node except for
clock
9Simplified Main Loop
- int main()
-
- TOS_CALL_COMMAND(MAIN_SUB_INIT)() //
initialize the subcomponents - TOS_CALL_COMMAND(MAIN_SUB_START)() //start
the subcomponents - while(1)
-
- while(!TOS_schedule_task()) //Run
until no task in the FIFO Queue -
- asm volatile ("sleep" ) // save power
-
-
10Scheduler in main function
- int TOS_schedule_task ()
- TOS_sched_entry_T TOS_queueMAX_TASK
-
- if (EMPTY) return -1
- TOS_queueTOS_sched_full.tp()
- TOS_queueTOS_sched_full.tp 0
- TOS_sched_full (TOS_sched_full 1 MAX_TASKS
) ? 0 TOS_sched_full 1 -
- int TOS_post ( task_function_pointer)
- if( FULL) return 1
- //Post the associated task to the next free
slot - TOS_queueTOS_sched_free .tp
task_function_pointer
11Event implementation
- Event is independent of FIFO scheduler.
-
- Lowest level events are supported directly by
Hardware interrupt -
- Software events propagate from lower level to
upper level through function call. - INTERRUPT(_output_compare2_) // Hardware Timer
Event Handler -
- TOS_SIGNAL_EVENT(CLOCK_FIRE_EVENT)( )
//Software Event -
-
12How it works Sensor Actuator
Sensor stack
Actuator stack
Application
LEDs Clock UART ADC RFM
Application
Clock Inter.
LED interface
PHOTO interface
LED.c
Clock.c
PHOTO.c
LED Hardware
Timer
ADC Hardware
Sensor and actuator are achieved mainly through
periodically polling
13How it works Communication
- Bit Encoding
- Manchester encoding (1b ?2b)
- DC balancing (4b ? 6b)
- SEC_DED forward error correction
- (8b ? 17b)
- Error detection correction
- SEC_DED Correct 1b Detect 2b
- Signal strength
- Each time a 1 bit is read in,
- the ADC samples the value
- of the BBOUT pin.
- CSMA
- Detect whether current channel
- is free to transmit, otherwise wait
- for random of clock ticks 12,75
- clock rate (10kHZ) LFSR
-
One byte message type used to direct packet to
handlers Real implementation if(msg.type 0)
val Handler0(data) if(msg.type 1) val
Handler1(data) . . if(msg.type 255) val
Handler255(data) User need to redefine handler
name define Handler1 XXXX define Handler5
NULL_FUNC
Application Component
H2
H1
H3
Application
Packaging Dividing/Combine Routing Echo
Base_station Relay. Special address 0xff
Broadcast Address 0x7E UART interface
30 Byte Fix length Packet CRC check 16 bit
CRC check, Drops packet if fails Redundancy
transmit transmitted 3 times
Content-based routing Consensus
algorithm Location Service Tracking Sensor data
processing
AM Dispatcher
messaging
Simplex transceiver We can Set Operation
Mode (TX/RX) Set Sampling Rate Receive one
Bit Transmit one Bit Notify TX/RX is
finished Shut down RFM (1/10th)
Messaging
packet
Radio byte
byte
RFM
bit
14Road Map
- TinyOS overview
- How TinyOS works
- Programming the mote
- Programming environment guide
15Programming the Mote (1)
- Program graph of components FIFO scheduler.
16Programming the Mote (2)
- Individual component
- Component interface (.comp)
- Commands that it accepts(implemented)
- Commands that it uses
- Events that it signals
- Events that it handles
- Component implementation (.c)
- Functions that implement interface
- Frame internal state
- Tasks internal concurrency
- Uses only internal namespace
A typical TinyOS component
17Programming the Mote (3)
- Relations
- Component dependence (.desc)
- Glue the components
- Denote the dependence among component.
- Mapping the interface between the component.
MAIN
COUNTER
CLOCK
LEDS
18Declare and access variable
- TOS_FRAME_BEGIN, TOS_FRAME_END to declare a
component frame - example
- VAR(foo) to access a
variable (foo) in the frame
TOS_FRAME_BEGIN(COUNTER_frame) char
state TOS_FRAME_END(COUNTER_frame)
Real implementation define TOS_FRAME_BEGIN(frame
_type) typedef struct define
TOS_FRAME_END(frame_type) frame_type
static frame_type
TOS_MY_Frame define VAR(x)
TOS_MY_Frame.x
19TinyOS Commands,Events and Tasks
TOS_EVENT(name)(args) ... return status
TOS_COMMAND(name)(args) ... return status
TOS_TASK(name)(args) ... return status
Real implementation define TOS_COMMAND(command_n
ame) TOS_CALL_COMMAND(command_name) define
TOS_EVENT(event_name)
TOS_SIGNAL_EVENT(event_name)
20TinyOS Application by Composition
- Application graph of components scheduler
sensing application
application
Routing Layer
routing
Messaging Layer
messaging
packet
Radio byte
Temp
UART byte
byte
photo
SW
HW
RFM
i2c
ADC
bit
clocks
21Composing applications from components
Simple counter
program
.desc file describe the relationships
between the component
Interfaces are defined through .COMP File
.c file implement the interface
22Files for this simple application
- Seven Files
- Describe the relation between compoents
- cnt_to_led.desc
- Describe three components ( two files each)
- Counter.c Counter.comp
- Clock.c Clock.comp
- INT_TO_LED.c INT_TO_LED.comp
23Composing applications from components
Example
apps/cnt_to_led.desc
include modules MAIN COUNTER INT_TO_LEDS CLOCK
MAINMAIN_SUB_INIT COUNTERCOUNTER_INIT
MAINMAIN_SUB_START COUNTERCOUNTER_START COUNTE
RCOUNTER_CLOCK_EVENT CLOCKCLOCK_FIRE_EVENT COUNT
ERCOUNTER_SUB_CLOCK_INIT CLOCKCLOCK_INIT COUNTE
RCOUNTER_SUB_OUTPUT_INIT INT_TO_LEDSINT_TO_LEDS_
INIT COUNTERCOUNTER_OUTPUT INT_TO_LEDSINT_TO_LED
S_OUTPUT
COUNTER
apps/cnt_to_led.desc
24.comp component interface file
TOS_MODULE COUNTER ACCEPTS char
COUNTER_START(void) char COUNTER_INIT(void)
HANDLES void COUNTER_CLOCK_EVENT(void) US
ES //need following service provide by other
component char COUNTER_SUB_CLOCK_INIT(char
interval, char scale) char
COUNTER_SUB_OUTPUT_INIT() char
COUNTER_OUTPUT(int value) SIGNALS // no
signal it will generate
To be implemented in .c file
COUNTER.comp
25Implemention COUNTER.c
include "tos.h" include "COUNTER.h" //Frame
Declaration define TOS_FRAME_TYPE
COUNTER_frame TOS_FRAME_BEGIN(COUNTER_frame)
char state TOS_FRAME_END(COUNTER_frame)
//Events handled / Clock Event Handler / void
TOS_EVENT(COUNTER_CLOCK_EVENT)() VAR(state)
TOS_CALL_COMMAND(COUNTER_OUTPUT)(VAR(state)
) / update LED state /
COUNTER.c
26COUNTER.c - rudimentary event processing
//Commands accepted char TOS_COMMAND(COUNTER_INIT
)() VAR(state) 0 / initialize output
component / return TOS_CALL_COMMAND(COUNTER_SUB
_OUTPUT_INIT)() char TOS_COMMAND(COUNTER_STA
RT)() / initialize clock component and start
event processing / return TOS_CALL_COMMAND(COUN
TER_SUB_CLOCK_INIT)(tick2ps)
27More complicate example
28Low level Mote Programming Detail
- ATMEL 90S8535 can respond to 16 different
interrupt sources. - Avr-gcc pre-defines interrupt symbols and
interrupt jump table
29Low level Mote Programming Detail
- To establish interrupt hander
- 1. include the following headers in your C file
- include "io-avr.h"
- include "signal.h"
- include "interrupt.h
- 2. Write following subroutine
- INTERRUPT(_uart_recv_) ... // Preemptive
Event - SIGNAL(_uart_recv_) ... //non-preemptive
Event - Alternative sei() and cei() macros can enable
and disable interrupt
30Low level Mote Programming Detail
Vector jump table (16)
31Road Map
- TinyOS overview
- How TinyOS works
- Programming the mote
- Programming environment guide
32Programming Environment
- Lab Location Olsson 018
- Platform cygwin on top of Windows 2000
- Software perl, gcc, java, atmel tools
,cygwin
Mote-to-mote communication
Program Code
Mote-PC communication
33Steps
- Write Component ( .c and .comp file )
- Write Relation ( .desc file )
- Run on Mote
- Modify makefile
- Set GROUP_ID
- redefine Macro DESC XXXXX.desc
- Build
- Make clean make
- Upload the image into Mote and run
- Make install_windows
- Run on PC
- Modify makefilePC
- Build make clean make -f makefilePC
- Run main lt node_ID gt
- Details to upload Image to Mote
- transcode your executable into Motorola S-record
format - avr-objcopy --output-targetsrec ledblink
ledblink.srec - erase the flash on the mote
- uisp -dapa -dno-poll --erase
- transfer the program to the mote
- uisp -dapa -dno-poll --upload ifledblink.srec
- verify the flash
- uisp -dapa -dno-poll --verify ifledblink.srec
34Programming debug Tools
- Makefile
- Create super.h from DESC and COMP file, then link
all component into one single image that is
executable by ATMEL AVR AT90S2343 processor. - MakefilePC
- Its for debug purpose and run on the PC
- gdb main ltnod_IDgt
- Serial Port listener -- monitor traffic between
mote and PC.
35RF_Simulation Tools
- Simulate Radio communication with
ConnectionManager program - RFM and UART replaced by sockets
- RFM connects to 127.0.0.19876
- UART connects to 127.0.0.18765
- add_conn(ID1, ID2) creates a bi-directional link
between mote with ID1 and ID2
3
add_conn(1, 2)add_conn(2, 3)add_conn(3,
4)add_conn(4, 2)
1
2
4
36Possible Project on Mote Test-Bed
- Redesign the FIFO scheduler
- Redesign MAC Layer from CSMA to
- Ultra-Sound Device for location service ?
- Distributed ConnectionManager for large scale
Sim. - New Ad Hoc network algorithm
- New application design (How to use mote novelty)
37Related URL
- http//tinyos.millennium.berkeley.edu