1 / 36

David Culler, Jason Hill, Robert Szewczyk, Alec Woo U.C. Berkeley 2/9/2001

TinyOS Programming Boot Camp Part IV – Tiny OS 4.3 Component Overview. David Culler, Jason Hill, Robert Szewczyk, Alec Woo U.C. Berkeley 2/9/2001. Groupings:. Main. Application. Actuating. Sensing. Communication. Communication. Hardware Abstractions. Hardware Abstraction Components.

dalia
Download Presentation

David Culler, Jason Hill, Robert Szewczyk, Alec Woo U.C. Berkeley 2/9/2001

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TinyOS Programming Boot CampPart IV – Tiny OS 4.3 Component Overview David Culler, Jason Hill, Robert Szewczyk, Alec Woo U.C. Berkeley 2/9/2001

  2. Groupings: Main Application Actuating Sensing Communication Communication Hardware Abstractions

  3. Hardware Abstraction Components • LEDs • Clock • UART • ADC • RFM

  4. LEDs – LEDS.comp TOS_MODULE LEDS; ACCEPTS{ char LEDS_INIT(void); char RED_LED_ON(void); char RED_LED_OFF(void); char RED_LED_TOGGLE(void); char GREEN_LED_ON(void); char GREEN_LED_OFF(void); char GREEN_LED_TOGGLE(void); char YELLOW_LED_ON(void); char YELLOW_LED_OFF(void); char YELLOW_LED_TOGGLE(void); }; • Provides a generic interface to the LED outputs • Abstracts away pin numbering and hardware wiring • INIT turns off all LEDs • Provide on, off, and toggle interface for each LED

  5. Timing – CLOCK.comp • Generates periodic events to trigger applications • Abstracts away counter registers, interrupt masks, and interrupt vectors • Initialize with number of ticks between events and scale of the ticks • Can use predefined definitions of the form ticksNps • All components that connect to the clock event will receive the same event rate • Initialization rests counter to zero TOS_MODULE CLOCK; ACCEPTS{ char CLOCK_INIT(char interval, char scale); }; SIGNALS{ void CLOCK_FIRE_EVENT(void); };

  6. Timing (cont.) • Example initializations: • CLOCK_INIT(64, 2) or CLOCK_INIT(tick64ps) • Fire every 64 ticks where each tick is 1/4096 seconds, or fire 64 times per second Predefined Intervals tick1000ps, tick100ps tick10ps, tick4096ps tick2048ps, tick1024ps tick512ps, tick256ps tick128ps, tick64ps tick32ps, tick16ps tick8ps, tick4ps tick2ps, tick1ps Scale 0 - OFF 1 - 32768 ticks/second 2 - 4096 ticks/second 3 - 1024 ticks/second 4 - 512 ticks/second 5 - 256 ticks/second 6 - 128 ticks/second 7 - 32 ticks/second system/include/hardware.h

  7. UART – UART.comp TOS_MODULE UART; ACCEPTS{ char UART_INIT(void); char UART_TX_BYTES(char data); char UART_PWR(char data); }; SIGNALS{ char UART_RX_BYTE_READY(char data, char error); char UART_TX_BYTE_READY(char success); }; • Abstracts away baud rate control, data transfer registers, interrupt control and data buffering • Fires event on RX and TX completion • Operates at the byte level • TX_READY signals that the component can handle another byte

  8. ADC – ADC.comp TOS_MODULE ADC; ACCEPTS{ char ADC_INIT(void); char ADC_GET_DATA(char port); }; SIGNALS{ char ADC_DATA_READY_PORT_0(int data); char ADC_DATA_READY_PORT_1(int data); char ADC_DATA_READY_PORT_2(int data); char ADC_DATA_READY_PORT_3(int data); char ADC_DATA_READY_PORT_4(int data); char ADC_DATA_READY_PORT_5(int data); char ADC_DATA_READY_PORT_6(int data); char ADC_DATA_READY_PORT_7(int data); }; • Abstracts away ADC control registers, ADC interrupt handling and sample timing • Accepts request for data that contains the port number of the data being requested • Fires separate events for each data port – common way of avoiding dynamic dispatching • Asynchronous data request, data ready interface

  9. The sensor stack TOS_MODULE PHOTO; JOINTLY IMPLEMENTED_BY PHOTO; ACCEPTS{ char PHOTO_INIT(void); char PHOTO_GET_DATA(void); char PHOTO_PWR(char mode); }; SIGNALS{ char PHOTO_DATA_READY(int data); }; USES{ char SUB_ADC_INIT(void); char SUB_ADC_GET_DATA(char port); }; HANDLES{ char PHOTO_ADC_DONE(int data); }; • Photo, and Temperature sensing components • Sits on top of ADC component • Typical request data, wait for data event paradigm Typical Application PHOTO.comp interface PHOTO.c ADC

  10. RFM – RFM.comp TOS_MODULE RFM; ACCEPTS{ char RFM_INIT(void); char RFM_TX_MODE(void); char RFM_TX_BIT(char data); char RFM_RX_MODE(void); char RFM_PWR(char mode); char RFM_SET_BIT_RATE(char level); }; SIGNALS{ char RFM_TX_BIT_EVENT(void); char RFM_RX_BIT_EVENT(char data); }; • Bit level interface to the RFM radio • Abstracts away bit level timing, RFM specific control logic (TX vs. RX modes) • Signals RX and TX bit events • RFM_SET_BIT_RATE accepts 3 sampling rates… 0 = 50us (2 x bit rate) 1 = 75us (1.5 x bit rate) 2 = 100us (1x bit rate) 2x Bit rate used for detecting start symbol, bit rate 1.5 x used to transition to middle of bit transmission, 1x bit rate used to read and write data

  11. The Communications Stack • Building up from the RFM bit level • Bit level abstracts away radio specifics • Byte level radio component collects individual bits into bytes • Packet Level constructs packets from bytes • Messaging layer interprets packets as messages • Data pump paradigm used to connect layers Messaging Packet Level Byte Level RFM Bit Level

  12. Data Pump Paradigm • High level components initiate transfer (COMMANDS) • Lower level components signal when more data can be handled (EVENTS) • Collection of bit events aggregated into single byte event • Collection of byte events collected into single packet event … Packet Level Byte Level RFM Bit Level

  13. RFM and RFM_LOW_POWER TOS_MODULE RFM; ACCEPTS{ char RFM_INIT(void); char RFM_TX_MODE(void); char RFM_TX_BIT(char data); char RFM_RX_MODE(void); char RFM_PWR(char mode); char RFM_SET_BIT_RATE(char level); }; SIGNALS{ char RFM_TX_BIT_EVENT(void); char RFM_RX_BIT_EVENT(char data); }; • Two options for bit level components: • RFM and RFM_LOW_POWER • RFM low_power • Performs turn off radio when channel is idle • Radio on 1/10th of the time • When idle, 270us off and 30us on • If transmission detected, it returns to normal mode of operation

  14. Radio Byte Level • RADIO_BYTE.comp, FOUR_B_RADIO_BYTE.comp, SEC_DED_RADIO_BYTE.comp, SEC_DED_RADIO_BYTE_SIGNAL.comp • All have similar interfaces • Transfer individual bits to the radio • Fires off TX_READY event when it can accept another byte TOS_MODULE RADIO_BYTE; ACCEPTS{ char RADIO_BYTE_INIT(void); char RADIO_BYTE_TX_BYTES(char data); char RADIO_BYTE_PWR(char mode); }; SIGNALS{ char RADIO_BYTE_RX_BYTE_READY(char data, char error); char RADIO_BYTE_TX_BYTE_READY(char success); char RADIO_BYTE_TX_DONE(void); };

  15. General Radio Byte Operation • Pipelines transmission – transmits single byte while encoding next byte • Trades 1 byte of buffering for additional latency • Separates high level latencies from low level latency requirements • Encoding Task must complete before byte transmission completes • Decode must complete before next byte arrives … Encode Task Byte 1 Byte 2 Byte 3 Byte 4 Bit transmission start Byte 1 Byte 2 Byte 3 RFM Bits

  16. Radio Byte FSM with Tasks (Sending) 0 tx_bit &c16 / tx_byte_rdy,tx_done tx_bytes/POST_TASK 1 2 tx_bit &~c16 tx_bit &c16 / tx_byte_rdy tx_bytes/POST_TASK 4 3 tx_bit &~c16 tx_bit &~c16 State Table 0 = idle 1 = waiting to send out first byte 2 = sending out byte, no next byte 3 = sending out byte, waiting to encode next byte 4 = sending out byte, done encoding next byte Encode Task Executed tx_bit called tx_bytes accepted tx_byte_rdy signaled tx_done signaled

  17. Radio Byte FSM with Tasks (Receiving) rx_bit &~start symbol 0 rx_bit & start frame byte_rdy_evt 5 6+ rx_bit &~c16 rx_bit & c16/POST_TASK rx_bit byte_rdy_evt 6 rx_bit &~c16 State Table 0 = idle 5 = Start Symbol Received 6 = Reading in byte 6+ = Reading in byte, waiting to decode previous Decode Task byte_rdy_evt signaled rx_bit handled

  18. Different Encoding Options • RADIO_BYTE.comp • Basic Manchester encoding • Each bit encoded as two bits • 0 -> 01, 1 -> 10 • 2x overhead, provides no error correction • Does not perform error detection • FOUR_B_RADIO_BYTE.comp • Performs 4b/6b, DC balancing encoding • 4 bite nibbles transmitted at 6 bits • 1.5 x overhead, no error correction possible • Does not perform error detection • Table look-up used to perform encoding

  19. Different Encoding Options (cont.) • SEC_DED_RADIO_BYTE.comp • Combination of SEC_DED forward error correction and DC balancing • 8 bits encoded as 17 bits • Can correct 1 bit errors and detect two bit errors • Based on binary matrix multiplication • SEC_DED_RADIO_BYTE_SIGNAL.comp • Same as SEC_DED_RADIO_BYTE except it also provides the value of the BBOUT pin from the RFM • Each time a 1 bit is read in, the ADC samples the value of the BBOUT pin. The readings are averaged and put into the Byte_Ready event

  20. SEC_DED_BYTE encoding matrix • Based on hamming codes • Performs both DC_balance and FEC in one step • Generator Matrix:

  21. Packet Level Components TOS_MODULE PACKETOBJ; ACCEPTS{ char PACKET_TX_PACKET( TOS_MsgPtr data); void PACKET_POWER(char mode); char PACKET_INIT(void); }; SIGNALS{ char PACKET_TX_PACKET_DONE( TOS_MsgPtr packet); TOS_MsgPtr PACKET_RX_PACKET_DONE( TOS_MsgPtr packet); }; • UART_PACKET.comp, PACKETOBJ.comp, PACKETOBJ_SIGNAL.comp, CRCPACKETOBJ.comp, RED_PACKETOBJ.comp • Transfer individual bytes down to byte level components • Top of the communications data pumps • Deals with fixed length packets • Refuses to accept packet if busy

  22. Packet Options • PACKETOBJ.comp • Generic fixed length packets • CRCPACKETOBJ.comp • Add a 16 bit CRC check to the end of the packet • Drops packet if CRC check fails • RED_PACKET.comp • Redundancy based forward error correction • Each packet is transmitted 3 times • For each byte, if two of the three version match, it accepts the value • Otherwise the first version is used • PACKETOBJ_SIGNAL.comp • Designed to work with SED_DED_RADIO_BYTE_SIGNAL.comp • Averages the signal strength readings and places it in the strength variable of the packet • Requires that MSG.h be modified to add the strength field to the end of the packet

  23. Tasks in low-level packet processing char TOS_COMMAND(PACKET_TX_PACKET)(TOS_MsgPtr data){ if(VAR(state) == 0){ /* receiving */ VAR(data) = (char*)data; if(TOS_CALL_COMMAND(PACKET_SUB_TX_BYTES)(VAR(data)[0])){ /* start tx */ TOS_POST_TASK(CRC_calc); VAR(state) = 1; /* transmitting */ VAR(count) = 1; return 1; }else{ return 0; } }else{ return 0; } } Post task to calculate CRC in the background while event driven data pumps push bytes system/CRC_PACKET_OBJ.c

  24. Messaging Level Components TOS_MODULE AM; ACCEPTS{ char AM_SEND_MSG(char addr,char type, TOS_MsgPtr data); char AM_POWER(char mode); char AM_INIT(void); }; SIGNALS{ char AM_MSG_SEND_DONE(TOS_MsgPtr msg); TOS_MsgPtr AM_MSG_HANDLER_0(TOS_MsgPtr data); TOS_MsgPtr AM_MSG_HANDLER_1(TOS_MsgPtr data); . . . TOS_MsgPtr AM_MSG_HANDLER_255(TOS_MsgPtr data); }; • AM.comp, AM_BASE.comp • Adds Addressing, Active Message Dispatching, and Group ID’s to the communications layer • One byte message type used to direct packet to handlers • AM_MSG_HANDLER_0handles message 0 • Buffer Swapping on message receipt • 0xff = Broadcast Address • AM_BASE sends 0x7E to UART interface

  25. Messaging Format struct MSG_VALS{ char addr; char type; char group; char data[DATA_LENGTH]; //short crc; //int strength; }; • Set in system/include/MSG.h • Data structure needs to be modified to account for the packet layer used • Packet layers use sizeof(MSG_VALS) to set transmission size system/include/MSG.h

  26. Communications Packages: • GENERIC_COMM.comp • Contains AM, PACKETOBJ, SEC_DED_RADIO_BYTE and RFM • BASE_COMM.comp • Contains AM_BASE, PACKETOBJ, SEC_DED_RADIO_BYTE, RFM, UART_PACKET and UART • CRC_COMM.comp • Contains AM, CRCPACKETOBJ, FOUR_B_RADIO_BYTE and RFM

  27. Full PC support of communication • Hardware abstraction components modified to work on PCs • RFM and UART replaced by sockets • Each individual radio bit is sent as a character over a socket • RFM connects to “127.0.0.1:9876” • UART connects to “127.0.0.1:8765” • Implemented in: • “system/include/Fullpc_radio.h” • “system/include/Fullpc_uart_connect.h” • RF_simulator used to simulate connectivity

  28. RF_Simulator • Connects individual Mote processes together • By default, nodes 1->10 are fully connected • Edit RF_simulator/ConnectionManager.java to change topology • Can construct arbitrary topologies of connectivity • 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 RF_simulator/ConnectionManager.java

  29. Example use of RF_simulator • Compile CNT_TO_RFM.decs for the PC Copy main.exe to counter.exe • Compile generic_base.desc for the PC • Open three console windows • In the first, cd RF_simulator; java ConnectionManager • In the second, run main 5 • In the third, run counter 3 • You will see packets transmitted by counter, forwarded by the connection manager and received by the generic_base • The generic base will then send the packet out the UART

  30. Other System Components • MAIN • I2C_OBJ • LOGGER

  31. MAIN.comp • Issues INIT and Start command to applications • Required to be in all applications • Actually calls and includes the scheduler • Should not need to be modified TOS_MODULE MAIN USES{ char MAIN_SUB_INIT(void); char MAIN_SUB_START(void); };

  32. I2C_OBJ.comp • Implementation of I2C protocol on I2C bus 2 • Single Master Only • Transmissions take place inside individual tasks • Used to interact with EEPROM or external digital sensors • Uses tasks to implement split phase protocol ACCEPTS{ char I2C_init(void); char I2C_read(void); char I2C_write(char val); char I2C_send_start(void); char I2C_send_end(void); }; SIGNALS{ char I2C_read_done(char val, char error); char I2C_write_done(char success); char I2C_send_start_done(void); char I2C_send_end_done(void); };

  33. Logger ACCEPTS{ char APPEND_LOG(char* data); char READ_LOG(int line, char* dest); char LOGGER_INIT(void); }; SIGNALS{ char APPEND_LOG_DONE(char success); char READ_LOG_DONE(char* packet, char success); }; • Uses on-board I2C based EEPROM to store log entries • Has 30 byte log entries • Append Only Log • Currently starts over at 0 when initialized

  34. Application Level Components • AM_BEACON.comp • Sends out periodic beacons that contain the local address • AM_ECHO.comp • Responds to a message by sending out a message to the address specified by data[0] • AM_ROUTE.comp • Ad-hoc routing application that sends collected data to a base station • BLINK.comp • Blinks the LEDS • CHIRP.comp • Repeatedly sends out packets that contain light sensor readings

  35. Application Level Components (cont.) • CONNECT.comp • Ad-hoc routing application that maintains the connectivity graph of which surrounding nodes can be heard • COUNTER.comp • Sends the value of the counter to an output device (leds or RFM) • SENS_OUTPUT.comp • Send the value of a sensor to an output device • GENERIC_BASE.comp • Listens on the RADIO and forwards any packets received to the UART

  36. Application Level Components (cont.) • INTERP.comp • Virtual machine for programming the motes • LOGGER_TEST.comp • Demonstrations of the Logger functionality. It takes periodic sensor readings and records them to the log. It also sends the values to the UART. It will respond to active messages that request log entries to be read • MAGS.comp • Reads data from the ADC and forwards it to the UART. It performs band pass filtering on the data for event detection. Data readings are double buffered • WAVE.comp • Changes the values displayed on the LEDs based on the value read from PHOTO.comp

More Related