170 likes | 200 Views
Learn about MAC protocols, RF chips, and ZigbeX in TinyOS. Understand CCA, backoff, ACK packets for reliable wireless communication. Practice BasicMAC with CC2420Radio component.
E N D
RF Chip and MAC Protocol in ZigbeX • MAC Protocol in TinyOS • RF chip for Wireless Personal area networks (WPAN) by chipcon isCC2420. • TinyOS provides a CC2420Radio component for CC2420 control, which includes MAC implementation in CC2420Radio component.
MAC Protocolin TinyOS - 1 • CCA(Clear Channel Assessment) • In order to use CSMA, it requires to assess channel status. • To sense carrier, TinyOS provides RSSI (Received Signal Strength Indicator) based CCA. • RSSIisstrength of propagated signal by neighbors. CCA decides if the channel is busy based on the RSSI value.. • If CCA decides the channel busy, then the node need to wait till available.
MAC Protocolin TinyOS - 2 • RandomBackoff • Backoff is used to avoid same time transmission by multiple nodes • Pick a random number within [0, N]. Wait for n*Slot-time. where N is # of attempts.
MAC Protocolin TinyOS - 3 • ACK packet • If confliction, MAC protocol need to retransmit. • MAC protocol in TinyOS checksconfliction using DATA/ACK packet. • If no ACK delivered to sender, retransmit the Data
WirelessRF Comm. Component • CC2420RadioC component • GenericComm also is operated byCC2420RadioC component. • CC2420C located in \opt\tinyos‐1.x\tos\lib\CC2420Radio • Basic MAC protocol used in TinyOS runs on CC2420RadioC.
BasicMAC practice • BasicMAC example • BasicMAC examplesends light value every second. A receiver blinks LED to tell successful delivery. • BasicMAC example location • c:\Programfiles\UCB\cygwin\opt\tinyos‐1.x\contrib\zigbex\BasicMAC\ • BasicMAC.nc &BasicMACM.nc
BasicMAC.nc • BasicMAC.nc • Components used in BasicMAC • TimerC &LedsC • DemoSensorC for light sensor • GenericComm for RF communication includes BMAC; configuration BasicMAC { } implementation { components Main, BasicMACM, TimerC, LedsC, DemoSensorC as Sensor , GenericComm as Comm; Main.StdControl -> BasicMACM; … BasicMACM.CommControl -> Comm; BasicMACM.ResetCounterMsg -> Comm.ReceiveMsg[AM_BMACMSG]; BasicMACM.DataMsg -> Comm.SendMsg[AM_BMACMSG]; }
BasicMACM.nc • BasicMACM.nc (1) includes BMAC; module BasicMACM { provides interface StdControl; uses { … } } implementation { … command result_t StdControl.init() { call Leds.init(); call Leds.yellowOff(); call Leds.redOff(); call Leds.greenOff(); call SensorControl.init(); call CommControl.init(); recvNumber = 0; return SUCCESS; } Inlcudes BMAC.h
BasicMACM.nc • BasicMACM.nc (2) command result_t StdControl.start() { call SensorControl.start(); call CommControl.start(); call Timer.start(TIMER_REPEAT, 1000); return SUCCESS; } command result_t StdControl.stop() { call SensorControl.stop(); call Timer.stop(); call CommControl.stop(); return SUCCESS; } event result_t Timer.fired() { call Leds.greenToggle(); call Leds.yellowOn(); return call ADC.getData(); }
BasicMACM.nc • BasicMACM.nc (3) async event result_t ADC.dataReady(uint16_t data) { atomic { pack = (struct BasicMAC_Msg *)msg.data; pack->data[0] = data; } if (call DataMsg.send(TOS_BCAST_ADDR, sizeof(struct BasicMAC_Msg), &msg)){ dbg(DBG_USR1, "DATA send SUCCESS!!!!!\n"); } return SUCCESS; } event result_t DataMsg.sendDone(TOS_MsgPtr sent, result_t success) { call Leds.yellowOff(); return SUCCESS; }
BasicMACM.nc • BasicMACM.nc (4) event TOS_MsgPtr ResetCounterMsg.receive (TOS_MsgPtr m) { call Leds.redToggle(); recvNumber++; return m; }
BasicMAC Lab 1 • startscygwin and move to c:\Programfiles\UCB\cygwin\opt\tinyos‐1.x\contrib\zigbex\BasicMAC\ • Compile - make zigbex cd /opt/tinyos‐1.x/contrib/zigbex cd BasicMAC
BasicMAC results • result • At every second Green LED & Yellow LED blinks • After Yellow LED blink(received) in one node, another node on/off Red LED (ACK received).