+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * A component that multiplexes the use of an alarm. The assumption is\r
- * that its use is mutually exclusive and users check whether the\r
- * events are for them.\r
- *\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-#include <Timer.h>\r
-\r
-configuration AlarmMultiplexC {\r
-\r
- provides interface Init;\r
- provides interface Alarm<T32khz,uint32_t> as Alarm32khz32;\r
-\r
-}\r
-\r
-implementation {\r
-\r
- components new HplCC2420AlarmC() as Alarm;\r
-\r
- Init = Alarm;\r
- Alarm32khz32 = Alarm;\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- *\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-#ifndef __CC2420_H__\r
-#define __CC2420_H__\r
-\r
-//#include "message.h"\r
-\r
-typedef uint8_t cc2420_status_t;\r
-\r
-typedef nx_struct cc2420_header_t {\r
- nxle_uint8_t length;\r
- nxle_uint16_t fcf;\r
- nxle_uint8_t dsn;\r
- nxle_uint16_t destpan;\r
- nxle_uint16_t dest;\r
- nxle_uint16_t src;\r
- nxle_uint8_t type;\r
-} cc2420_header_t;\r
-\r
-typedef nx_struct cc2420_footer_t {\r
-} cc2420_footer_t;\r
-\r
-typedef nx_struct cc2420_metadata_t {\r
- nx_uint8_t tx_power;\r
- nx_uint8_t rssi;\r
- nx_uint8_t lqi;\r
- nx_bool crc;\r
- nx_bool ack;\r
- nx_uint16_t time;\r
- nx_uint16_t rxInterval;\r
-} cc2420_metadata_t;\r
-\r
-typedef nx_struct cc2420_packet_t {\r
- cc2420_header_t packet;\r
- nx_uint8_t data[];\r
-} cc2420_packet_t;\r
-\r
-#ifndef TOSH_DATA_LENGTH\r
-#define TOSH_DATA_LENGTH 28\r
-#endif\r
-\r
-#ifndef CC2420_DEF_CHANNEL\r
-#define CC2420_DEF_CHANNEL 26\r
-#endif\r
-\r
-#ifndef CC2420_DEF_RFPOWER\r
-#define CC2420_DEF_RFPOWER 31\r
-#endif\r
-\r
-enum {\r
- // size of the header not including the length byte\r
- MAC_HEADER_SIZE = sizeof( cc2420_header_t ) - 1,\r
- // size of the footer (FCS field)\r
- MAC_FOOTER_SIZE = sizeof( uint16_t ),\r
- // MDU\r
- MAC_PACKET_SIZE = MAC_HEADER_SIZE + TOSH_DATA_LENGTH + MAC_FOOTER_SIZE,\r
-};\r
-\r
-enum cc2420_enums {\r
- CC2420_TIME_ACK_TURNAROUND = 7, // jiffies\r
- CC2420_TIME_VREN = 20, // jiffies\r
- CC2420_TIME_SYMBOL = 2, // 2 symbols / jiffy\r
- CC2420_BACKOFF_PERIOD = ( 20 / CC2420_TIME_SYMBOL ), // symbols\r
- CC2420_MIN_BACKOFF = ( 20 / CC2420_TIME_SYMBOL ), // platform specific?\r
- CC2420_ACK_WAIT_DELAY = 128, // jiffies\r
-};\r
-\r
-enum cc2420_status_enums {\r
- CC2420_STATUS_RSSI_VALID = 1 << 1,\r
- CC2420_STATUS_LOCK = 1 << 2,\r
- CC2420_STATUS_TX_ACTIVE = 1 << 3,\r
- CC2420_STATUS_ENC_BUSY = 1 << 4,\r
- CC2420_STATUS_TX_UNDERFLOW = 1 << 5,\r
- CC2420_STATUS_XOSC16M_STABLE = 1 << 6,\r
-};\r
-\r
-enum cc2420_config_reg_enums {\r
- CC2420_SNOP = 0x00,\r
- CC2420_SXOSCON = 0x01,\r
- CC2420_STXCAL = 0x02,\r
- CC2420_SRXON = 0x03,\r
- CC2420_STXON = 0x04,\r
- CC2420_STXONCCA = 0x05,\r
- CC2420_SRFOFF = 0x06,\r
- CC2420_SXOSCOFF = 0x07,\r
- CC2420_SFLUSHRX = 0x08,\r
- CC2420_SFLUSHTX = 0x09,\r
- CC2420_SACK = 0x0a,\r
- CC2420_SACKPEND = 0x0b,\r
- CC2420_SRXDEC = 0x0c,\r
- CC2420_SRXENC = 0x0d,\r
- CC2420_SAES = 0x0e,\r
- CC2420_MAIN = 0x10,\r
- CC2420_MDMCTRL0 = 0x11,\r
- CC2420_MDMCTRL1 = 0x12,\r
- CC2420_RSSI = 0x13,\r
- CC2420_SYNCWORD = 0x14,\r
- CC2420_TXCTRL = 0x15,\r
- CC2420_RXCTRL0 = 0x16,\r
- CC2420_RXCTRL1 = 0x17,\r
- CC2420_FSCTRL = 0x18,\r
- CC2420_SECCTRL0 = 0x19,\r
- CC2420_SECCTRL1 = 0x1a,\r
- CC2420_BATTMON = 0x1b,\r
- CC2420_IOCFG0 = 0x1c,\r
- CC2420_IOCFG1 = 0x1d,\r
- CC2420_MANFIDL = 0x1e,\r
- CC2420_MANFIDH = 0x1f,\r
- CC2420_FSMTC = 0x20,\r
- CC2420_MANAND = 0x21,\r
- CC2420_MANOR = 0x22,\r
- CC2420_AGCCTRL = 0x23,\r
- CC2420_AGCTST0 = 0x24,\r
- CC2420_AGCTST1 = 0x25,\r
- CC2420_AGCTST2 = 0x26,\r
- CC2420_FSTST0 = 0x27,\r
- CC2420_FSTST1 = 0x28,\r
- CC2420_FSTST2 = 0x29,\r
- CC2420_FSTST3 = 0x2a,\r
- CC2420_RXBPFTST = 0x2b,\r
- CC2420_FMSTATE = 0x2c,\r
- CC2420_ADCTST = 0x2d,\r
- CC2420_DACTST = 0x2e,\r
- CC2420_TOPTST = 0x2f,\r
- CC2420_TXFIFO = 0x3e,\r
- CC2420_RXFIFO = 0x3f,\r
-};\r
-\r
-enum cc2420_ram_addr_enums {\r
- CC2420_RAM_TXFIFO = 0x000,\r
- CC2420_RAM_RXFIFO = 0x080,\r
- CC2420_RAM_KEY0 = 0x100,\r
- CC2420_RAM_RXNONCE = 0x110,\r
- CC2420_RAM_SABUF = 0x120,\r
- CC2420_RAM_KEY1 = 0x130,\r
- CC2420_RAM_TXNONCE = 0x140,\r
- CC2420_RAM_CBCSTATE = 0x150,\r
- CC2420_RAM_IEEEADR = 0x160,\r
- CC2420_RAM_PANID = 0x168,\r
- CC2420_RAM_SHORTADR = 0x16a,\r
-};\r
-\r
-enum cc2420_nonce_enums {\r
- CC2420_NONCE_BLOCK_COUNTER = 0,\r
- CC2420_NONCE_KEY_SEQ_COUNTER = 2,\r
- CC2420_NONCE_FRAME_COUNTER = 3,\r
- CC2420_NONCE_SOURCE_ADDRESS = 7,\r
- CC2420_NONCE_FLAGS = 15,\r
-};\r
-\r
-enum cc2420_main_enums {\r
- CC2420_MAIN_RESETn = 15,\r
- CC2420_MAIN_ENC_RESETn = 14,\r
- CC2420_MAIN_DEMOD_RESETn = 13,\r
- CC2420_MAIN_MOD_RESETn = 12,\r
- CC2420_MAIN_FS_RESETn = 11,\r
- CC2420_MAIN_XOSC16M_BYPASS = 0,\r
-};\r
-\r
-enum cc2420_mdmctrl0_enums {\r
- CC2420_MDMCTRL0_RESERVED_FRAME_MODE = 13,\r
- CC2420_MDMCTRL0_PAN_COORDINATOR = 12,\r
- CC2420_MDMCTRL0_ADR_DECODE = 11,\r
- CC2420_MDMCTRL0_CCA_HYST = 8,\r
- CC2420_MDMCTRL0_CCA_MOD = 6,\r
- CC2420_MDMCTRL0_AUTOCRC = 5,\r
- CC2420_MDMCTRL0_AUTOACK = 4,\r
- CC2420_MDMCTRL0_PREAMBLE_LENGTH = 0,\r
-};\r
-\r
-enum cc2420_mdmctrl1_enums {\r
- CC2420_MDMCTRL1_CORR_THR = 6,\r
- CC2420_MDMCTRL1_DEMOD_AVG_MODE = 5,\r
- CC2420_MDMCTRL1_MODULATION_MODE = 4,\r
- CC2420_MDMCTRL1_TX_MODE = 2,\r
- CC2420_MDMCTRL1_RX_MODE = 0,\r
-};\r
-\r
-enum cc2420_rssi_enums {\r
- CC2420_RSSI_CCA_THR = 8,\r
- CC2420_RSSI_RSSI_VAL = 0,\r
-};\r
-\r
-enum cc2420_syncword_enums {\r
- CC2420_SYNCWORD_SYNCWORD = 0,\r
-};\r
-\r
-enum cc2420_txctrl_enums {\r
- CC2420_TXCTRL_TXMIXBUF_CUR = 14,\r
- CC2420_TXCTRL_TX_TURNAROUND = 13,\r
- CC2420_TXCTRL_TXMIX_CAP_ARRAY = 11,\r
- CC2420_TXCTRL_TXMIX_CURRENT = 9,\r
- CC2420_TXCTRL_PA_CURRENT = 6,\r
- CC2420_TXCTRL_RESERVED = 5,\r
- CC2420_TXCTRL_PA_LEVEL = 0,\r
-};\r
-\r
-enum cc2420_rxctrl0_enums {\r
- CC2420_RXCTRL0_RXMIXBUF_CUR = 12,\r
- CC2420_RXCTRL0_HIGH_LNA_GAIN = 10,\r
- CC2420_RXCTRL0_MED_LNA_GAIN = 8,\r
- CC2420_RXCTRL0_LOW_LNA_GAIN = 6,\r
- CC2420_RXCTRL0_HIGH_LNA_CURRENT = 4,\r
- CC2420_RXCTRL0_MED_LNA_CURRENT = 2,\r
- CC2420_RXCTRL0_LOW_LNA_CURRENT = 0,\r
-};\r
-\r
-enum cc2420_rxctrl1_enums {\r
- CC2420_RXCTRL1_RXBPF_LOCUR = 13,\r
- CC2420_RXCTRL1_RXBPF_MIDCUR = 12,\r
- CC2420_RXCTRL1_LOW_LOWGAIN = 11,\r
- CC2420_RXCTRL1_MED_LOWGAIN = 10,\r
- CC2420_RXCTRL1_HIGH_HGM = 9,\r
- CC2420_RXCTRL1_MED_HGM = 8,\r
- CC2420_RXCTRL1_LNA_CAP_ARRAY = 6,\r
- CC2420_RXCTRL1_RXMIX_TAIL = 4,\r
- CC2420_RXCTRL1_RXMIX_VCM = 2,\r
- CC2420_RXCTRL1_RXMIX_CURRENT = 0,\r
-};\r
-\r
-enum cc2420_rsctrl_enums {\r
- CC2420_FSCTRL_LOCK_THR = 14,\r
- CC2420_FSCTRL_CAL_DONE = 13,\r
- CC2420_FSCTRL_CAL_RUNNING = 12,\r
- CC2420_FSCTRL_LOCK_LENGTH = 11,\r
- CC2420_FSCTRL_LOCK_STATUS = 10,\r
- CC2420_FSCTRL_FREQ = 0,\r
-};\r
-\r
-enum cc2420_secctrl0_enums {\r
- CC2420_SECCTRL0_RXFIFO_PROTECTION = 9,\r
- CC2420_SECCTRL0_SEC_CBC_HEAD = 8,\r
- CC2420_SECCTRL0_SEC_SAKEYSEL = 7,\r
- CC2420_SECCTRL0_SEC_TXKEYSEL = 6,\r
- CC2420_SECCTRL0_SEC_RXKEYSEL = 5,\r
- CC2420_SECCTRL0_SEC_M = 2,\r
- CC2420_SECCTRL0_SEC_MODE = 0,\r
-};\r
-\r
-enum cc2420_secctrl1_enums {\r
- CC2420_SECCTRL1_SEC_TXL = 8,\r
- CC2420_SECCTRL1_SEC_RXL = 0,\r
-};\r
-\r
-enum cc2420_battmon_enums {\r
- CC2420_BATTMON_BATT_OK = 6,\r
- CC2420_BATTMON_BATTMON_EN = 5,\r
- CC2420_BATTMON_BATTMON_VOLTAGE = 0,\r
-};\r
-\r
-enum cc2420_iocfg0_enums {\r
- CC2420_IOCFG0_BCN_ACCEPT = 11,\r
- CC2420_IOCFG0_FIFO_POLARITY = 10,\r
- CC2420_IOCFG0_FIFOP_POLARITY = 9,\r
- CC2420_IOCFG0_SFD_POLARITY = 8,\r
- CC2420_IOCFG0_CCA_POLARITY = 7,\r
- CC2420_IOCFG0_FIFOP_THR = 0,\r
-};\r
-\r
-enum cc2420_iocfg1_enums {\r
- CC2420_IOCFG1_HSSD_SRC = 10,\r
- CC2420_IOCFG1_SFDMUX = 5,\r
- CC2420_IOCFG1_CCAMUX = 0,\r
-};\r
-\r
-enum cc2420_manfidl_enums {\r
- CC2420_MANFIDL_PARTNUM = 12,\r
- CC2420_MANFIDL_MANFID = 0,\r
-};\r
-\r
-enum cc2420_manfidh_enums {\r
- CC2420_MANFIDH_VERSION = 12,\r
- CC2420_MANFIDH_PARTNUM = 0,\r
-};\r
-\r
-enum cc2420_fsmtc_enums {\r
- CC2420_FSMTC_TC_RXCHAIN2RX = 13,\r
- CC2420_FSMTC_TC_SWITCH2TX = 10,\r
- CC2420_FSMTC_TC_PAON2TX = 6,\r
- CC2420_FSMTC_TC_TXEND2SWITCH = 3,\r
- CC2420_FSMTC_TC_TXEND2PAOFF = 0,\r
-};\r
-\r
-enum cc2420_sfdmux_enums {\r
- CC2420_SFDMUX_SFD = 0,\r
- CC2420_SFDMUX_XOSC16M_STABLE = 24,\r
-};\r
-\r
-#endif\r
+++ /dev/null
-/* tab:4\r
- * "Copyright (c) 2005 Stanford University. All rights reserved.\r
- *\r
- * Permission to use, copy, modify, and distribute this software and\r
- * its documentation for any purpose, without fee, and without written\r
- * agreement is hereby granted, provided that the above copyright\r
- * notice, the following two paragraphs and the author appear in all\r
- * copies of this software.\r
- * \r
- * IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE TO ANY PARTY FOR\r
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES\r
- * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN\r
- * IF STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\r
- * DAMAGE.\r
- * \r
- * STANFORD UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,\r
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE\r
- * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND STANFORD UNIVERSITY\r
- * HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,\r
- * ENHANCEMENTS, OR MODIFICATIONS."\r
- */\r
-\r
-/**\r
- * The Active Message layer for the CC2420 radio. This configuration\r
- * just layers the AM dispatch (CC2420ActiveMessageM) on top of the\r
- * underlying CC2420 radio packet (CC2420CsmaRadioC), which is\r
- * inherently an AM packet (acknowledgements based on AM destination\r
- * addr and group). Note that snooping may not work, due to CC2420\r
- * early packet rejection if acknowledgements are enabled.\r
- *\r
- * @author Philip Levis\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-#include "CC2420.h"\r
-\r
-configuration CC2420ActiveMessageC {\r
- provides {\r
- interface SplitControl;\r
- interface AMSend[am_id_t id];\r
- interface Receive[am_id_t id];\r
- interface Receive as Snoop[am_id_t id];\r
- interface AMPacket;\r
- interface Packet;\r
- interface CC2420Packet;\r
- interface PacketAcknowledgements;\r
- interface CsmaBackoff[am_id_t amId];\r
- interface LowPowerListening;\r
- }\r
-}\r
-implementation {\r
-\r
- components CC2420ActiveMessageP as AM;\r
- components CC2420CsmaC as Radio;\r
- components ActiveMessageAddressC as Address;\r
- \r
- CsmaBackoff = Radio;\r
- Packet = AM;\r
- AMSend = AM;\r
- Receive = AM.Receive;\r
- Snoop = AM.Snoop;\r
- AMPacket = AM;\r
- \r
-#ifdef LOW_POWER_LISTENING\r
- components CC2420LowPowerListeningC as Lpl;\r
- LowPowerListening = Lpl;\r
- AM.SubSend -> Lpl.Send;\r
- AM.SubReceive -> Lpl.Receive;\r
- SplitControl = Lpl;\r
- \r
-#else\r
- components CC2420LplDummyP;\r
- LowPowerListening = CC2420LplDummyP;\r
- AM.SubSend -> Radio.Send;\r
- AM.SubReceive -> Radio.Receive;\r
- SplitControl = Radio;\r
-#endif\r
-\r
- AM.amAddress -> Address;\r
- Radio.AMPacket -> AM;\r
-\r
- components CC2420PacketC;\r
- CC2420Packet = CC2420PacketC;\r
- PacketAcknowledgements = CC2420PacketC;\r
-\r
-\r
-}\r
+++ /dev/null
-/* tab:4\r
- * "Copyright (c) 2005 Stanford University. All rights reserved.\r
- *\r
- * Permission to use, copy, modify, and distribute this software and\r
- * its documentation for any purpose, without fee, and without written\r
- * agreement is hereby granted, provided that the above copyright\r
- * notice, the following two paragraphs and the author appear in all\r
- * copies of this software.\r
- * \r
- * IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE TO ANY PARTY FOR\r
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES\r
- * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN\r
- * IF STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\r
- * DAMAGE.\r
- * \r
- * STANFORD UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,\r
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE\r
- * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND STANFORD UNIVERSITY\r
- * HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,\r
- * ENHANCEMENTS, OR MODIFICATIONS."\r
- */\r
-\r
-\r
-/**\r
- * Active message implementation on top of the CC2420 radio. This\r
- * implementation uses the 16-bit addressing mode of 802.15.4: the\r
- * only additional byte it adds is the AM id byte, as the first byte\r
- * of the data payload.\r
- *\r
- * @author Philip Levis\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-module CC2420ActiveMessageP {\r
- provides {\r
- interface AMSend[am_id_t id];\r
- interface Receive[am_id_t id];\r
- interface Receive as Snoop[am_id_t id];\r
- interface AMPacket;\r
- interface Packet;\r
- }\r
- uses {\r
- interface Send as SubSend;\r
- interface Receive as SubReceive;\r
- command am_addr_t amAddress();\r
- }\r
-}\r
-implementation {\r
-\r
- enum {\r
- CC2420_SIZE = MAC_HEADER_SIZE + MAC_FOOTER_SIZE,\r
- };\r
- \r
- cc2420_header_t* getHeader( message_t* msg ) {\r
- return (cc2420_header_t*)( msg->data - sizeof(cc2420_header_t) );\r
- }\r
- \r
- command error_t AMSend.send[am_id_t id](am_addr_t addr,\r
- message_t* msg,\r
- uint8_t len) {\r
- cc2420_header_t* header = getHeader( msg );\r
- header->type = id;\r
- header->dest = addr;\r
- header->destpan = TOS_AM_GROUP;\r
-\r
- return call SubSend.send( msg, len + CC2420_SIZE );\r
- }\r
-\r
- command error_t AMSend.cancel[am_id_t id](message_t* msg) {\r
- return call SubSend.cancel(msg);\r
- }\r
-\r
- command uint8_t AMSend.maxPayloadLength[am_id_t id]() {\r
- return call Packet.maxPayloadLength();\r
- }\r
-\r
- command void* AMSend.getPayload[am_id_t id](message_t* m) {\r
- return call Packet.getPayload(m, NULL);\r
- }\r
-\r
- command void* Receive.getPayload[am_id_t id](message_t* m, uint8_t* len) {\r
- return call Packet.getPayload(m, len);\r
- }\r
-\r
- command uint8_t Receive.payloadLength[am_id_t id](message_t* m) {\r
- return call Packet.payloadLength(m);\r
- }\r
- \r
- command void* Snoop.getPayload[am_id_t id](message_t* m, uint8_t* len) {\r
- return call Packet.getPayload(m, len);\r
- }\r
-\r
- command uint8_t Snoop.payloadLength[am_id_t id](message_t* m) {\r
- return call Packet.payloadLength(m);\r
- }\r
- \r
- event void SubSend.sendDone(message_t* msg, error_t result) {\r
- signal AMSend.sendDone[call AMPacket.type(msg)](msg, result);\r
- }\r
-\r
- /* Receiving a packet */\r
-\r
- event message_t* SubReceive.receive(message_t* msg, void* payload, uint8_t len) {\r
- if (call AMPacket.isForMe(msg)) {\r
- return signal Receive.receive[call AMPacket.type(msg)](msg, payload, len - CC2420_SIZE);\r
- }\r
- else {\r
- return signal Snoop.receive[call AMPacket.type(msg)](msg, payload, len - CC2420_SIZE);\r
- }\r
- }\r
- \r
- command am_addr_t AMPacket.address() {\r
- return call amAddress();\r
- }\r
- \r
- command am_addr_t AMPacket.destination(message_t* amsg) {\r
- cc2420_header_t* header = getHeader(amsg);\r
- return header->dest;\r
- }\r
- \r
- command am_addr_t AMPacket.source(message_t* amsg) {\r
- cc2420_header_t* header = getHeader(amsg);\r
- return header->src;\r
- }\r
-\r
- command void AMPacket.setDestination(message_t* amsg, am_addr_t addr) {\r
- cc2420_header_t* header = getHeader(amsg);\r
- header->dest = addr;\r
- }\r
-\r
- command void AMPacket.setSource(message_t* amsg, am_addr_t addr) {\r
- cc2420_header_t* header = getHeader(amsg);\r
- header->src = addr;\r
- }\r
-\r
- command bool AMPacket.isForMe(message_t* amsg) {\r
- return (call AMPacket.destination(amsg) == call AMPacket.address() ||\r
- call AMPacket.destination(amsg) == AM_BROADCAST_ADDR);\r
- }\r
-\r
- command am_id_t AMPacket.type(message_t* amsg) {\r
- cc2420_header_t* header = getHeader(amsg);\r
- return header->type;\r
- }\r
-\r
- command void AMPacket.setType(message_t* amsg, am_id_t type) {\r
- cc2420_header_t* header = getHeader(amsg);\r
- header->type = type;\r
- }\r
-\r
- default event message_t* Receive.receive[am_id_t id](message_t* msg, void* payload, uint8_t len) {\r
- return msg;\r
- }\r
- \r
- default event message_t* Snoop.receive[am_id_t id](message_t* msg, void* payload, uint8_t len) {\r
- return msg;\r
- }\r
-\r
- default event void AMSend.sendDone[uint8_t id](message_t* msg, error_t err) {\r
- return;\r
- }\r
-\r
- \r
- command void Packet.clear(message_t* msg) {}\r
- \r
- command uint8_t Packet.payloadLength(message_t* msg) {\r
- return getHeader(msg)->length - CC2420_SIZE;\r
- }\r
-\r
-\r
- command void Packet.setPayloadLength(message_t* msg, uint8_t len) {\r
- getHeader(msg)->length = len + CC2420_SIZE;\r
- }\r
-\r
- command uint8_t Packet.maxPayloadLength() {\r
- return TOSH_DATA_LENGTH;\r
- }\r
- \r
- command void* Packet.getPayload(message_t* msg, uint8_t* len) {\r
- if (len != NULL) {\r
- *len = call Packet.payloadLength(msg);\r
- }\r
- return msg->data;\r
- }\r
-\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Rincon Research Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
- \r
-/**\r
- * Interface to obtain a CCA reading from the CC2420 radio\r
- * to determine if a neighbor is transmitting\r
- * @author David Moss\r
- */\r
- \r
-interface CC2420Cca {\r
- \r
- /**\r
- * @return TRUE if the CCA pin shows a clear channel\r
- */\r
- command bool isChannelClear();\r
- \r
-}\r
-\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * An HAL abstraction of the ChipCon CC2420 radio. This abstraction\r
- * deals specifically with radio configurations. All get() and set()\r
- * commands are single-phase. After setting some values, a call to\r
- * sync() is required for the changes to propagate to the cc2420\r
- * hardware chip. This interface allows setting multiple parameters\r
- * before calling sync().\r
- *\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-interface CC2420Config {\r
-\r
- /**\r
- * Sync configuration changes with the radio hardware. This only\r
- * applies to set commands below.\r
- *\r
- * @return SUCCESS if the request was accepted, FAIL otherwise.\r
- */\r
- command error_t sync();\r
- event void syncDone( error_t error );\r
-\r
- /**\r
- * Change the channel of the radio.\r
- */\r
- command uint8_t getChannel();\r
- command void setChannel( uint8_t channel );\r
-\r
- /**\r
- * Change the short address of the radio.\r
- */\r
- command uint16_t getShortAddr();\r
- command void setShortAddr( uint16_t address );\r
-\r
- /**\r
- * Change the PAN address of the radio.\r
- */\r
- command uint16_t getPanAddr();\r
- command void setPanAddr( uint16_t address );\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * Implementation for configuring a ChipCon CC2420 radio.\r
- *\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-#include "CC2420.h"\r
-#include "IEEE802154.h"\r
-\r
-configuration CC2420ControlC {\r
-\r
- provides interface Init;\r
- provides interface Resource;\r
- provides interface CC2420Config;\r
- provides interface CC2420Power;\r
-\r
- uses interface AMPacket;\r
-\r
-}\r
-\r
-implementation {\r
- \r
- components CC2420ControlP;\r
- Init = CC2420ControlP;\r
- Resource = CC2420ControlP;\r
- CC2420Config = CC2420ControlP;\r
- CC2420Power = CC2420ControlP;\r
- AMPacket = CC2420ControlP;\r
-\r
- components AlarmMultiplexC as Alarm;\r
- CC2420ControlP.StartupTimer -> Alarm;\r
-\r
- components HplCC2420PinsC as Pins;\r
- CC2420ControlP.CSN -> Pins.CSN;\r
- CC2420ControlP.RSTN -> Pins.RSTN;\r
- CC2420ControlP.VREN -> Pins.VREN;\r
-\r
- components HplCC2420InterruptsC as Interrupts;\r
- CC2420ControlP.InterruptCCA -> Interrupts.InterruptCCA;\r
-\r
- components new CC2420SpiC() as Spi;\r
- CC2420ControlP.SpiResource -> Spi;\r
- CC2420ControlP.SRXON -> Spi.SRXON;\r
- CC2420ControlP.SRFOFF -> Spi.SRFOFF;\r
- CC2420ControlP.SXOSCON -> Spi.SXOSCON;\r
- CC2420ControlP.SXOSCOFF -> Spi.SXOSCOFF;\r
- CC2420ControlP.FSCTRL -> Spi.FSCTRL;\r
- CC2420ControlP.IOCFG0 -> Spi.IOCFG0;\r
- CC2420ControlP.IOCFG1 -> Spi.IOCFG1;\r
- CC2420ControlP.MDMCTRL0 -> Spi.MDMCTRL0;\r
- CC2420ControlP.MDMCTRL1 -> Spi.MDMCTRL1;\r
- CC2420ControlP.PANID -> Spi.PANID;\r
-\r
- components new CC2420SpiC() as SyncSpiC;\r
- CC2420ControlP.SyncResource -> SyncSpiC;\r
-\r
- components LedsC as Leds;\r
- CC2420ControlP.Leds -> Leds;\r
-\r
-}\r
-\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-#include "Timer.h"\r
-\r
-module CC2420ControlP {\r
-\r
- provides interface Init;\r
- provides interface Resource;\r
- provides interface CC2420Config;\r
- provides interface CC2420Power;\r
-\r
- uses interface Alarm<T32khz,uint32_t> as StartupTimer;\r
- uses interface GeneralIO as CSN;\r
- uses interface GeneralIO as RSTN;\r
- uses interface GeneralIO as VREN;\r
- uses interface GpioInterrupt as InterruptCCA;\r
-\r
- uses interface Resource as SpiResource;\r
- uses interface CC2420Ram as PANID;\r
- uses interface CC2420Register as FSCTRL;\r
- uses interface CC2420Register as IOCFG0;\r
- uses interface CC2420Register as IOCFG1;\r
- uses interface CC2420Register as MDMCTRL0;\r
- uses interface CC2420Register as MDMCTRL1;\r
- uses interface CC2420Strobe as SRXON;\r
- uses interface CC2420Strobe as SRFOFF;\r
- uses interface CC2420Strobe as SXOSCOFF;\r
- uses interface CC2420Strobe as SXOSCON;\r
- uses interface AMPacket;\r
-\r
- uses interface Resource as SyncResource;\r
-\r
- uses interface Leds;\r
-\r
-}\r
-\r
-implementation {\r
-\r
- typedef enum {\r
- S_VREG_STOPPED,\r
- S_VREG_STARTING,\r
- S_VREG_STARTED,\r
- S_XOSC_STARTING,\r
- S_XOSC_STARTED,\r
- } cc2420_control_state_t;\r
-\r
- uint8_t m_channel = CC2420_DEF_CHANNEL;\r
- uint8_t m_tx_power = CC2420_DEF_RFPOWER;\r
- uint16_t m_pan = TOS_AM_GROUP;\r
- uint16_t m_short_addr;\r
- bool m_sync_busy;\r
- task void syncDone_task();\r
-\r
- norace cc2420_control_state_t m_state = S_VREG_STOPPED;\r
-\r
- command error_t Init.init() {\r
- call CSN.makeOutput();\r
- call RSTN.makeOutput();\r
- call VREN.makeOutput();\r
- m_short_addr = call AMPacket.address();\r
- return SUCCESS;\r
- }\r
-\r
- async command error_t Resource.immediateRequest() {\r
- error_t error = call SpiResource.immediateRequest();\r
- if ( error == SUCCESS )\r
- call CSN.clr();\r
- return error;\r
- }\r
-\r
- async command error_t Resource.request() {\r
- return call SpiResource.request();\r
- }\r
-\r
- async command uint8_t Resource.isOwner() {\r
- return call SpiResource.isOwner();\r
- }\r
-\r
- async command error_t Resource.release() {\r
- atomic {\r
- call CSN.set();\r
- return call SpiResource.release();\r
- }\r
- }\r
-\r
- event void SpiResource.granted() {\r
- call CSN.clr();\r
- signal Resource.granted();\r
- }\r
-\r
- async command error_t CC2420Power.startVReg() {\r
- atomic {\r
- if ( m_state != S_VREG_STOPPED )\r
- return FAIL;\r
- m_state = S_VREG_STARTING;\r
- }\r
- call VREN.set();\r
- call StartupTimer.start( CC2420_TIME_VREN );\r
- return SUCCESS;\r
- }\r
-\r
- async event void StartupTimer.fired() {\r
- if ( m_state == S_VREG_STARTING ) {\r
- m_state = S_VREG_STARTED;\r
- call RSTN.clr();\r
- call RSTN.set();\r
- signal CC2420Power.startVRegDone();\r
- }\r
- }\r
-\r
- async command error_t CC2420Power.stopVReg() {\r
- m_state = S_VREG_STOPPED;\r
- call RSTN.clr();\r
- call VREN.clr();\r
- call RSTN.set();\r
- return SUCCESS;\r
- }\r
-\r
- async command error_t CC2420Power.startOscillator() {\r
- atomic {\r
- if ( m_state != S_VREG_STARTED )\r
- return FAIL;\r
- \r
- m_state = S_XOSC_STARTING;\r
- call IOCFG1.write( CC2420_SFDMUX_XOSC16M_STABLE << \r
- CC2420_IOCFG1_CCAMUX );\r
- call InterruptCCA.enableRisingEdge();\r
- call SXOSCON.strobe();\r
- call IOCFG0.write( ( 1 << CC2420_IOCFG0_FIFOP_POLARITY ) |\r
- ( 127 << CC2420_IOCFG0_FIFOP_THR ) );\r
- call FSCTRL.write( ( 1 << CC2420_FSCTRL_LOCK_THR ) |\r
- ( ( (m_channel - 11)*5+357 ) \r
- << CC2420_FSCTRL_FREQ ) );\r
- call MDMCTRL0.write( ( 1 << CC2420_MDMCTRL0_RESERVED_FRAME_MODE ) |\r
- ( 1 << CC2420_MDMCTRL0_ADR_DECODE ) |\r
- ( 2 << CC2420_MDMCTRL0_CCA_HYST ) |\r
- ( 3 << CC2420_MDMCTRL0_CCA_MOD ) |\r
- ( 1 << CC2420_MDMCTRL0_AUTOCRC ) |\r
- ( 1 << CC2420_MDMCTRL0_AUTOACK ) |\r
- ( 2 << CC2420_MDMCTRL0_PREAMBLE_LENGTH ) );\r
- }\r
- return SUCCESS;\r
- }\r
-\r
- async event void InterruptCCA.fired() {\r
- nxle_uint16_t id[ 2 ];\r
- m_state = S_XOSC_STARTED;\r
- id[ 0 ] = m_pan;\r
- id[ 1 ] = m_short_addr;\r
- call InterruptCCA.disable();\r
- call IOCFG1.write( 0 );\r
- call PANID.write( 0, (uint8_t*)&id, 4 );\r
- call CSN.set();\r
- call CSN.clr();\r
- signal CC2420Power.startOscillatorDone();\r
- }\r
-\r
- async command error_t CC2420Power.stopOscillator() {\r
- atomic {\r
- if ( m_state != S_XOSC_STARTED )\r
- return FAIL;\r
- m_state = S_VREG_STARTED;\r
- call SXOSCOFF.strobe();\r
- }\r
- return SUCCESS;\r
- }\r
-\r
- async command error_t CC2420Power.rxOn() {\r
- atomic {\r
- if ( m_state != S_XOSC_STARTED )\r
- return FAIL;\r
- call SRXON.strobe();\r
- }\r
- return SUCCESS;\r
- }\r
-\r
- async command error_t CC2420Power.rfOff() {\r
- atomic { \r
- if ( m_state != S_XOSC_STARTED )\r
- return FAIL;\r
- call SRFOFF.strobe();\r
- }\r
- return SUCCESS;\r
- }\r
-\r
- command uint8_t CC2420Config.getChannel() {\r
- atomic return m_channel;\r
- }\r
-\r
- command void CC2420Config.setChannel( uint8_t channel ) {\r
- atomic m_channel = channel;\r
- }\r
-\r
- command uint16_t CC2420Config.getShortAddr() {\r
- atomic return m_short_addr;\r
- }\r
-\r
- command void CC2420Config.setShortAddr( uint16_t addr ) {\r
- atomic m_short_addr = addr;\r
- }\r
-\r
- command uint16_t CC2420Config.getPanAddr() {\r
- return m_pan;\r
- }\r
-\r
- command void CC2420Config.setPanAddr( uint16_t pan ) {\r
- atomic m_pan = pan;\r
- }\r
-\r
- command error_t CC2420Config.sync() {\r
- atomic {\r
- if ( m_sync_busy )\r
- return FAIL;\r
- m_sync_busy = TRUE;\r
- if ( m_state == S_XOSC_STARTED )\r
- call SyncResource.request();\r
- else\r
- post syncDone_task();\r
- }\r
- return SUCCESS;\r
- }\r
-\r
- event void SyncResource.granted() {\r
-\r
- nxle_uint16_t id[ 2 ];\r
- uint8_t channel;\r
-\r
- atomic {\r
- channel = m_channel;\r
- id[ 0 ] = m_pan;\r
- id[ 1 ] = m_short_addr;\r
- }\r
-\r
- call CSN.clr();\r
- call FSCTRL.write( ( 1 << CC2420_FSCTRL_LOCK_THR ) |\r
- ( ( (channel - 11)*5+357 ) << CC2420_FSCTRL_FREQ ) );\r
- call PANID.write( 0, (uint8_t*)id, sizeof( id ) );\r
- call CSN.set();\r
- call SyncResource.release();\r
- \r
- post syncDone_task();\r
- \r
- }\r
-\r
- task void syncDone_task() {\r
- atomic m_sync_busy = FALSE;\r
- signal CC2420Config.syncDone( SUCCESS );\r
- }\r
-\r
- default event void CC2420Config.syncDone( error_t error ) {}\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * Basic implementation of a CSMA MAC for the ChipCon CC2420 radio.\r
- *\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-#include "CC2420.h"\r
-#include "IEEE802154.h"\r
-\r
-configuration CC2420CsmaC {\r
-\r
- provides interface SplitControl;\r
- provides interface Send;\r
- provides interface Receive;\r
- provides interface CsmaBackoff[am_id_t amId];\r
-\r
- uses interface AMPacket;\r
-\r
-}\r
-\r
-implementation {\r
-\r
- components CC2420CsmaP as CsmaP;\r
-\r
- CsmaBackoff = CsmaP;\r
- SplitControl = CsmaP;\r
- Send = CsmaP;\r
- AMPacket = CsmaP;\r
-\r
- components CC2420ControlC;\r
- AMPacket = CC2420ControlC;\r
- CsmaP.Resource -> CC2420ControlC;\r
- CsmaP.CC2420Power -> CC2420ControlC;\r
-\r
- components CC2420TransmitC;\r
-\r
- CsmaP.SubControl -> CC2420TransmitC;\r
- CsmaP.CC2420Transmit -> CC2420TransmitC;\r
- CsmaP.SubBackoff -> CC2420TransmitC;\r
-\r
- components CC2420ReceiveC;\r
- Receive = CC2420ReceiveC;\r
- CsmaP.SubControl -> CC2420ReceiveC;\r
-\r
- components RandomC;\r
- CsmaP.Random -> RandomC;\r
-\r
- components LedsC as Leds;\r
- CsmaP.Leds -> Leds;\r
-\r
- components MainC;\r
- MainC.SoftwareInit -> CsmaP;\r
- MainC.SoftwareInit -> CC2420ControlC;\r
- MainC.SoftwareInit -> CC2420TransmitC;\r
- MainC.SoftwareInit -> CC2420ReceiveC;\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-module CC2420CsmaP {\r
-\r
- provides interface Init;\r
- provides interface SplitControl;\r
- provides interface Send;\r
- provides interface CsmaBackoff[am_id_t amId];\r
-\r
- uses interface Resource;\r
- uses interface CC2420Power;\r
- uses interface AsyncStdControl as SubControl;\r
- uses interface CC2420Transmit;\r
- uses interface CsmaBackoff as SubBackoff;\r
- uses interface Random;\r
- uses interface AMPacket;\r
- uses interface Leds;\r
-\r
-}\r
-\r
-implementation {\r
-\r
- enum {\r
- S_PREINIT,\r
- S_STOPPED,\r
- S_STARTING,\r
- S_STARTED,\r
- S_STOPPING,\r
- S_TRANSMIT,\r
- };\r
-\r
- message_t* m_msg;\r
- uint8_t m_state = S_PREINIT;\r
- uint8_t m_dsn;\r
- error_t sendErr = SUCCESS;\r
- \r
- task void startDone_task();\r
- task void stopDone_task();\r
- task void sendDone_task();\r
-\r
- cc2420_header_t* getHeader( message_t* msg ) {\r
- return (cc2420_header_t*)( msg->data - sizeof( cc2420_header_t ) );\r
- }\r
-\r
- cc2420_metadata_t* getMetadata( message_t* msg ) {\r
- return (cc2420_metadata_t*)msg->metadata;\r
- }\r
-\r
- command error_t Init.init() {\r
- \r
- if ( m_state != S_PREINIT )\r
- return FAIL;\r
-\r
- m_state = S_STOPPED;\r
-\r
- return SUCCESS;\r
-\r
- }\r
-\r
- command error_t SplitControl.start() {\r
-\r
- if ( m_state != S_STOPPED ) \r
- return FAIL;\r
-\r
- m_state = S_STARTING;\r
-\r
- m_dsn = call Random.rand16();\r
- call CC2420Power.startVReg();\r
-\r
- return SUCCESS;\r
-\r
- }\r
-\r
- async event void CC2420Power.startVRegDone() {\r
- call Resource.request();\r
- }\r
-\r
- event void Resource.granted() {\r
- call CC2420Power.startOscillator();\r
- }\r
-\r
- async event void CC2420Power.startOscillatorDone() {\r
- call SubControl.start();\r
- call CC2420Power.rxOn();\r
- call Resource.release();\r
- post startDone_task();\r
- }\r
-\r
- task void startDone_task() {\r
- m_state = S_STARTED;\r
- signal SplitControl.startDone( SUCCESS );\r
- }\r
-\r
- command error_t SplitControl.stop() {\r
-\r
- if ( m_state != S_STARTED )\r
- return FAIL;\r
-\r
- m_state = S_STOPPING;\r
-\r
- call SubControl.stop();\r
- call CC2420Power.stopVReg();\r
- post stopDone_task();\r
-\r
- return SUCCESS;\r
-\r
- }\r
-\r
- task void stopDone_task() {\r
- m_state = S_STOPPED;\r
- signal SplitControl.stopDone( SUCCESS );\r
- }\r
-\r
- command error_t Send.cancel( message_t* p_msg ) {\r
- return FAIL;\r
- }\r
-\r
- command error_t Send.send( message_t* p_msg, uint8_t len ) {\r
- \r
- cc2420_header_t* header = getHeader( p_msg );\r
- cc2420_metadata_t* metadata = getMetadata( p_msg );\r
-\r
- atomic {\r
- if ( m_state != S_STARTED )\r
- return FAIL;\r
- m_state = S_TRANSMIT;\r
- m_msg = p_msg;\r
- header->dsn = ++m_dsn;\r
- }\r
-\r
- header->length = len;\r
- header->fcf &= 1 << IEEE154_FCF_ACK_REQ;\r
- header->fcf |= ( ( IEEE154_TYPE_DATA << IEEE154_FCF_FRAME_TYPE ) |\r
- ( 1 << IEEE154_FCF_INTRAPAN ) |\r
- ( IEEE154_ADDR_SHORT << IEEE154_FCF_DEST_ADDR_MODE ) |\r
- ( IEEE154_ADDR_SHORT << IEEE154_FCF_SRC_ADDR_MODE ) );\r
- header->src = call AMPacket.address();\r
- metadata->ack = FALSE;\r
- metadata->rssi = 0;\r
- metadata->lqi = 0;\r
- metadata->time = 0;\r
-\r
- call CC2420Transmit.sendCCA( m_msg );\r
-\r
- return SUCCESS;\r
-\r
- }\r
-\r
- command void* Send.getPayload(message_t* m) {\r
- return m->data;\r
- }\r
-\r
- command uint8_t Send.maxPayloadLength() {\r
- return TOSH_DATA_LENGTH;\r
- }\r
-\r
- async event uint16_t SubBackoff.initial( message_t* msg ) {\r
- return signal CsmaBackoff.initial[((cc2420_header_t*)(msg->data - \r
- sizeof(cc2420_header_t)))->type](msg);\r
- }\r
-\r
- async event uint16_t SubBackoff.congestion( message_t* msg ) {\r
- return signal CsmaBackoff.congestion[((cc2420_header_t*)(msg->data - \r
- sizeof(cc2420_header_t)))->type](msg);\r
- }\r
-\r
- async event void CC2420Transmit.sendDone( message_t* p_msg, error_t err ) {\r
- atomic sendErr = err;\r
- post sendDone_task();\r
- }\r
-\r
- task void sendDone_task() {\r
- error_t packetErr;\r
- atomic packetErr = sendErr;\r
- m_state = S_STARTED;\r
- signal Send.sendDone( m_msg, packetErr );\r
- }\r
-\r
-\r
- /***************** Defaults ***************/\r
- default async event uint16_t CsmaBackoff.initial[am_id_t amId](\r
- message_t *m) {\r
- return ( call Random.rand16() % (0x1F * CC2420_BACKOFF_PERIOD) \r
- + CC2420_MIN_BACKOFF);\r
- }\r
-\r
- default async event uint16_t CsmaBackoff.congestion[am_id_t amId](\r
- message_t *m) {\r
- return ( call Random.rand16() % (0x7 * CC2420_BACKOFF_PERIOD) \r
- + CC2420_MIN_BACKOFF);\r
- }\r
- \r
- default event void SplitControl.startDone(error_t error) {\r
- }\r
- \r
- default event void SplitControl.stopDone(error_t error) {\r
- }\r
-}\r
-\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Rincon Research Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * @author David Moss\r
- */\r
- \r
-#ifndef CC2420DUTYCYCLE_H\r
-#define CC2420DUTYCYCLE_H\r
-\r
-/**\r
- * Default duty period is 0, which is "always on"\r
- */\r
-#ifndef DEFAULT_DUTY_PERIOD\r
-#define DEFAULT_DUTY_PERIOD 0\r
-#endif\r
-\r
-/**\r
- * This is a measured value of the time the radio is actually on (5.8 ms)\r
- * We round this up to 6 ms for erring on the side of better performance ratios\r
- */\r
-#ifndef DUTY_ON_TIME\r
-#define DUTY_ON_TIME 6 // TODO re-measure\r
-#endif\r
-\r
-/**\r
- * The maximum number of CCA checks performed on each wakeup.\r
- * If there are too few, the receiver may wake up between messages\r
- * and not detect the transmitter.\r
- */\r
-#ifndef MAX_LPL_CCA_CHECKS\r
-#define MAX_LPL_CCA_CHECKS 100\r
-#endif\r
-\r
-#endif\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Rincon Research Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
- \r
-/**\r
- * Manage the CC2420's duty cycle and power\r
- * @author David Moss\r
- */\r
- \r
-interface CC2420DutyCycle {\r
- \r
- /**\r
- * Set the sleep interval, in binary milliseconds\r
- * @param sleepIntervalMs the sleep interval in [ms]\r
- */\r
- command void setSleepInterval(uint16_t sleepIntervalMs);\r
- \r
- /**\r
- * @return the sleep interval in [ms]\r
- */\r
- command uint16_t getSleepInterval();\r
- \r
- /**\r
- * A transmitter was detected. You must now take action to\r
- * turn the radio off when the transaction is complete.\r
- */\r
- event void detected();\r
-\r
-}\r
-\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Rincon Research Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
- \r
-/**\r
- * Use this component to duty cycle the radio. When a message is heard, \r
- * disable DutyCycling.\r
- *\r
- * @author David Moss dmm@rincon.com\r
- */\r
-\r
-#include "CC2420DutyCycle.h"\r
-\r
-configuration CC2420DutyCycleC {\r
- provides {\r
- interface CC2420DutyCycle;\r
- interface SplitControl;\r
- interface State as SplitControlState;\r
- }\r
-}\r
-\r
-implementation {\r
- components MainC,\r
- CC2420DutyCycleP,\r
- CC2420TransmitC,\r
- CC2420CsmaC,\r
- LedsC,\r
- new StateC() as RadioPowerStateC,\r
- new StateC() as DutyCycleStateC,\r
- new StateC() as CheckStateC,\r
- new StateC() as SplitControlStateC,\r
- new TimerMilliC() as OnTimerC,\r
- new TimerMilliC() as CheckTimerC,\r
- RandomC;\r
- \r
- CC2420DutyCycle = CC2420DutyCycleP;\r
- SplitControl = CC2420DutyCycleP;\r
- SplitControlState = SplitControlStateC;\r
- \r
- MainC.SoftwareInit -> CC2420DutyCycleP;\r
- \r
- CC2420DutyCycleP.Random -> RandomC;\r
- CC2420DutyCycleP.CC2420Cca -> CC2420TransmitC;\r
- CC2420DutyCycleP.SubControl -> CC2420CsmaC;\r
- CC2420DutyCycleP.RadioPowerState -> RadioPowerStateC;\r
- CC2420DutyCycleP.DutyCycleState -> DutyCycleStateC;\r
- CC2420DutyCycleP.SplitControlState -> SplitControlStateC;\r
- CC2420DutyCycleP.CheckState -> CheckStateC;\r
- CC2420DutyCycleP.OnTimer -> OnTimerC;\r
- CC2420DutyCycleP.Leds -> LedsC;\r
-}\r
-\r
-\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Rincon Research Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
- \r
-/** \r
- * Module to duty cycle the radio on and off, performing CCA receive checks.\r
- * When a carrier is sensed, this will leave the radio on. It is then up\r
- * to higher layers to turn the radio off again. Once the radio is turned\r
- * off, this module will automatically continue duty cycling and looking for\r
- * a modulated signal.\r
- *\r
- * @author David Moss\r
- */\r
- \r
-#include "CC2420DutyCycle.h"\r
-\r
-module CC2420DutyCycleP {\r
- provides {\r
- interface CC2420DutyCycle;\r
- interface Init;\r
- interface SplitControl;\r
- }\r
-\r
- uses {\r
- interface Timer<TMilli> as OnTimer;\r
- interface SplitControl as SubControl;\r
- interface State as RadioPowerState;\r
- interface State as DutyCycleState;\r
- interface State as SplitControlState;\r
- interface State as CheckState;\r
- interface Leds;\r
- interface CC2420Cca;\r
- interface Random;\r
- }\r
-}\r
-\r
-implementation {\r
- \r
- /** The current period of the duty cycle, equivalent of wakeup interval */\r
- uint16_t sleepInterval;\r
- \r
- /** The number of times the CCA has been sampled in this wakeup period */\r
- uint8_t ccaChecks;\r
- \r
- /**\r
- * Radio Power, Check State, and Duty Cycling State\r
- */\r
- enum {\r
- S_OFF, // off by default\r
- S_ON,\r
- };\r
- \r
- \r
- /***************** Prototypes ****************/\r
- task void stopRadio();\r
- task void startRadio();\r
- task void getCca();\r
- \r
- /***************** Init Commands ****************/\r
- command error_t Init.init() {\r
- sleepInterval = DEFAULT_DUTY_PERIOD;\r
- return SUCCESS;\r
- }\r
- \r
- /***************** CC2420DutyCycle Commands ****************/\r
- /**\r
- * Set the sleep interval, in binary milliseconds\r
- * @param sleepIntervalMs the sleep interval in [ms]\r
- */\r
- command void CC2420DutyCycle.setSleepInterval(uint16_t sleepIntervalMs) {\r
- sleepInterval = sleepIntervalMs;\r
- \r
- if(sleepInterval == 0 && call DutyCycleState.getState() == S_ON) {\r
- call DutyCycleState.forceState(S_OFF);\r
- call CheckState.toIdle();\r
- \r
- /*\r
- * Leave the radio on permanently if sleepInterval == 0 and the radio is \r
- * supposed to be enabled\r
- */\r
- if(call RadioPowerState.getState() == S_OFF) {\r
- call SubControl.start();\r
- }\r
- }\r
- }\r
- \r
- /**\r
- * @return the sleep interval in [ms]\r
- */\r
- command uint16_t CC2420DutyCycle.getSleepInterval() {\r
- return sleepInterval;\r
- }\r
- \r
- /***************** SplitControl Commands ****************/\r
- command error_t SplitControl.start() {\r
- call SplitControlState.forceState(S_ON);\r
- \r
- if(sleepInterval > 0) {\r
- // Begin duty cycling\r
- call DutyCycleState.forceState(S_ON);\r
- call CheckState.toIdle();\r
- post stopRadio();\r
- signal SplitControl.startDone(SUCCESS);\r
- \r
- } else {\r
- call DutyCycleState.forceState(S_OFF);\r
- call CheckState.toIdle();\r
- \r
- /*\r
- * Leave the radio on permanently if sleepInterval == 0 and the radio is \r
- * supposed to be enabled\r
- */\r
- if(call RadioPowerState.getState() == S_OFF) {\r
- call SubControl.start();\r
- // Here, SplitControl.startDone is signaled on SubControl.startDone\r
- \r
- } else {\r
- // Radio is already on\r
- signal SplitControl.startDone(SUCCESS);\r
- }\r
- }\r
-\r
- return SUCCESS;\r
- }\r
- \r
- command error_t SplitControl.stop() {\r
- call SplitControlState.forceState(S_OFF);\r
- call DutyCycleState.forceState(S_OFF);\r
- call CheckState.toIdle();\r
- return call SubControl.stop();\r
- \r
- /*\r
- * SubControl.stopDone signals SplitControl.stopDone when \r
- * DutyCycleState is S_OFF\r
- */\r
- }\r
- \r
- /***************** Timer Events ****************/\r
- event void OnTimer.fired() {\r
- if(call DutyCycleState.getState() == S_ON) {\r
- if(call RadioPowerState.getState() == S_OFF) {\r
- call CheckState.forceState(S_ON);\r
- ccaChecks = 0;\r
- \r
- /*\r
- * The MicaZ, running on an external oscillator I think, and\r
- * returning the microcontroller out of a sleep state to immediately\r
- * perform an ADC conversion, sucks. The first ADC conversion out\r
- * of a sleep state lasts about a second. We don't want the radio\r
- * on that long. Like the CC1000 RSSI pulse check implementation\r
- * done in the Rincon CC1000Radio stack, we will perform\r
- * a single ADC conversion and then flip on the radio to check\r
- * the channel.\r
- */\r
- post getCca();\r
- \r
- } else {\r
- // Someone else turned on the radio, try again in awhile\r
- call OnTimer.startOneShot(sleepInterval);\r
- }\r
- }\r
- }\r
- \r
- /***************** SubControl Events ****************/\r
- event void SubControl.startDone(error_t error) {\r
- if(call DutyCycleState.getState() == S_ON && error) {\r
- // My responsibility to try again\r
- post startRadio();\r
- return;\r
- }\r
- \r
- call RadioPowerState.forceState(S_ON);\r
- //call Leds.led2On();\r
- \r
- if(call DutyCycleState.getState() == S_ON) {\r
- if(call CheckState.getState() == S_ON) {\r
- post getCca();\r
- }\r
- \r
- } else {\r
- // Must have turned the radio on manually\r
- signal SplitControl.startDone(SUCCESS);\r
- }\r
- }\r
- \r
- event void SubControl.stopDone(error_t error) {\r
- if(error && call DutyCycleState.getState() == S_ON) {\r
- // My responsibility to try again\r
- post stopRadio();\r
- return;\r
- }\r
- \r
- call RadioPowerState.forceState(S_OFF);\r
- //call Leds.led2Off();\r
- \r
- if(call DutyCycleState.getState() == S_ON) {\r
- call OnTimer.startOneShot(sleepInterval);\r
-\r
- } else {\r
- // Must have turned off the radio manually\r
- signal SplitControl.stopDone(error);\r
- }\r
- \r
- }\r
- \r
- \r
- /***************** Tasks ****************/\r
- task void stopRadio() {\r
- if(call DutyCycleState.getState() == S_ON) {\r
- if(call SubControl.stop() != SUCCESS) {\r
- // Already stopped?\r
- call OnTimer.startOneShot(sleepInterval);\r
- }\r
- }\r
- }\r
- \r
- task void startRadio() {\r
- if(call DutyCycleState.getState() == S_ON) {\r
- if(call SubControl.start() != SUCCESS) {\r
- post startRadio();\r
- }\r
- }\r
- }\r
- \r
- \r
- task void getCca() {\r
- if(call DutyCycleState.getState() == S_ON) {\r
- \r
- ccaChecks++;\r
- if(ccaChecks == 1) {\r
- // Microcontroller is ready, turn on the radio and sample a few times\r
- post startRadio();\r
- return;\r
- } \r
-\r
- if(!call CC2420Cca.isChannelClear()) {\r
- signal CC2420DutyCycle.detected(); \r
- // Leave the radio on for upper layers to perform some transaction\r
- \r
- } else {\r
- if(ccaChecks <= MAX_LPL_CCA_CHECKS) {\r
- post getCca();\r
- return;\r
- \r
- } else {\r
- call CheckState.toIdle();\r
- post stopRadio();\r
- }\r
- }\r
- } \r
- }\r
- \r
- /**************** Defaults ****************/\r
- default event void CC2420DutyCycle.detected() {\r
- }\r
-\r
-}\r
-\r
-\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * HAL abstraction for accessing the FIFO registers of a ChipCon\r
- * CC2420 radio.\r
- *\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-interface CC2420Fifo {\r
-\r
- /**\r
- * Start reading from the FIFO. The <code>readDone</code> event will\r
- * be signalled upon completion.\r
- *\r
- * @param data a pointer to the receive buffer.\r
- * @param length number of bytes to read.\r
- * @return status byte returned when sending the last address byte\r
- * of the SPI transaction.\r
- */\r
- async command cc2420_status_t beginRead( uint8_t* data, uint8_t length );\r
-\r
- /**\r
- * Continue reading from the FIFO without having to send the address\r
- * byte again. The <code>readDone</code> event will be signalled\r
- * upon completion.\r
- *\r
- * @param data a pointer to the receive buffer.\r
- * @param length number of bytes to read.\r
- * @return SUCCESS always.\r
- */\r
- async command error_t continueRead( uint8_t* data, uint8_t length );\r
-\r
- /**\r
- * Signals the completion of a read operation.\r
- *\r
- * @param data a pointer to the receive buffer.\r
- * @param length number of bytes read.\r
- * @param error notification of how the operation went\r
- */\r
- async event void readDone( uint8_t* data, uint8_t length, error_t error );\r
-\r
- /**\r
- * Start writing the FIFO. The <code>writeDone</code> event will be\r
- * signalled upon completion.\r
- *\r
- * @param data a pointer to the send buffer.\r
- * @param length number of bytes to write.\r
- * @return status byte returned when sending the last address byte\r
- * of the SPI transaction.\r
- */\r
- async command cc2420_status_t write( uint8_t* data, uint8_t length );\r
-\r
- /**\r
- * Signals the completion of a write operation.\r
- *\r
- * @param data a pointer to the send buffer.\r
- * @param length number of bytes written.\r
- * @param error notification of how the operation went\r
- */\r
- async event void writeDone( uint8_t* data, uint8_t length, error_t error );\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Rincon Research Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
- \r
- /**\r
- * @author David Moss\r
- */\r
-#ifndef CC2420LOWPOWERLISTENING_H\r
-#define CC2420LOWPOWERLISTENING_H\r
-\r
-#include "CC2420DutyCycle.h"\r
-\r
-/**\r
- * The default duty period is usually 0, which is the equivalent of\r
- * ONE_MESSAGE (below), which tells the node to transmit the message\r
- * one time without expecting receiver duty cycling.\r
- */\r
-#ifndef DEFAULT_TRANSMIT_PERIOD\r
-#define DEFAULT_TRANSMIT_PERIOD DEFAULT_DUTY_PERIOD\r
-#endif\r
-\r
-/**\r
- * Amount of time, in milliseconds, to keep the radio on after\r
- * a successful receive addressed to this node\r
- */\r
-#ifndef DELAY_AFTER_RECEIVE\r
-#define DELAY_AFTER_RECEIVE 50\r
-#endif\r
-\r
-/**\r
- * Value used to indicate the message being sent should be transmitted\r
- * one time\r
- */\r
-#ifndef ONE_MESSAGE\r
-#define ONE_MESSAGE 0\r
-#endif\r
-\r
-#endif\r
-\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Rincon Research Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * Low Power Listening for the CC2420\r
- * @author David Moss\r
- */\r
- \r
-#include "CC2420LowPowerListening.h"\r
-\r
-configuration CC2420LowPowerListeningC {\r
- provides {\r
- interface LowPowerListening;\r
- interface Send;\r
- interface Receive;\r
- interface SplitControl;\r
- }\r
-}\r
-\r
-implementation {\r
- components MainC,\r
- CC2420LowPowerListeningP,\r
- CC2420DutyCycleC,\r
- CC2420ActiveMessageC,\r
- CC2420CsmaC,\r
- CC2420TransmitC,\r
- RandomC,\r
- new StateC() as SendStateC,\r
- new StateC() as RadioStateC,\r
- new TimerMilliC() as OffTimerC,\r
- new TimerMilliC() as SendDoneTimerC;\r
- \r
- LowPowerListening = CC2420LowPowerListeningP;\r
- Send = CC2420LowPowerListeningP;\r
- Receive = CC2420LowPowerListeningP;\r
- SplitControl = CC2420DutyCycleC;\r
- \r
- MainC.SoftwareInit -> CC2420LowPowerListeningP;\r
- \r
- CC2420LowPowerListeningP.Random -> RandomC;\r
- CC2420LowPowerListeningP.SendState -> SendStateC;\r
- CC2420LowPowerListeningP.RadioState -> RadioStateC;\r
- CC2420LowPowerListeningP.SplitControlState -> CC2420DutyCycleC;\r
- CC2420LowPowerListeningP.OffTimer -> OffTimerC;\r
- CC2420LowPowerListeningP.SendDoneTimer -> SendDoneTimerC;\r
- CC2420LowPowerListeningP.CC2420DutyCycle -> CC2420DutyCycleC;\r
- CC2420LowPowerListeningP.SubSend -> CC2420CsmaC;\r
- CC2420LowPowerListeningP.Resend -> CC2420TransmitC;\r
- CC2420LowPowerListeningP.SubReceive -> CC2420CsmaC;\r
- CC2420LowPowerListeningP.SubControl -> CC2420CsmaC;\r
- CC2420LowPowerListeningP.PacketAcknowledgements -> CC2420ActiveMessageC;\r
- CC2420LowPowerListeningP.AMPacket -> CC2420ActiveMessageC;\r
- \r
-}\r
-\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Rincon Research Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * Low Power Listening for the CC2420\r
- *\r
- * @author David Moss\r
- */\r
-\r
-#include "CC2420LowPowerListening.h"\r
-\r
-module CC2420LowPowerListeningP {\r
- provides {\r
- interface Init;\r
- interface LowPowerListening;\r
- interface Send;\r
- interface Receive;\r
- }\r
- \r
- uses {\r
- interface Leds;\r
- interface Send as SubSend;\r
- interface CC2420Transmit as Resend;\r
- interface Receive as SubReceive;\r
- interface AMPacket;\r
- interface SplitControl as SubControl;\r
- interface CC2420DutyCycle;\r
- interface PacketAcknowledgements;\r
- interface State as SendState;\r
- interface State as RadioState;\r
- interface State as SplitControlState;\r
- interface Random;\r
- interface Timer<TMilli> as OffTimer;\r
- interface Timer<TMilli> as SendDoneTimer;\r
- }\r
-}\r
-\r
-implementation {\r
- \r
- /** The message currently being sent */\r
- message_t *currentSendMsg;\r
- \r
- /** The length of the current send message */\r
- uint8_t currentSendLen;\r
- \r
- /** TRUE if the radio is duty cycling and not always on */\r
- bool dutyCycling;\r
- \r
- /** Tx DSN to ensure multiple transmitted messages get across only once */ \r
- uint8_t txDsn;\r
- \r
- /** The last received broadcast DSN. TODO is this the best way? */\r
- uint8_t lastRxDsn;\r
-\r
- /**\r
- * Radio State\r
- */\r
- enum {\r
- S_OFF,\r
- S_ON,\r
- };\r
- \r
- /**\r
- * Send States\r
- */\r
- enum {\r
- S_IDLE,\r
- S_SENDING,\r
- };\r
- \r
- \r
- /***************** Prototypes ***************/\r
- task void send();\r
- task void resend();\r
- task void startRadio();\r
- task void stopRadio();\r
- \r
- void startOffTimer();\r
- cc2420_header_t *getHeader(message_t *msg);\r
- cc2420_metadata_t *getMetadata(message_t* msg);\r
- uint16_t getActualDutyCycle(uint16_t dutyCycle);\r
- void signalDone(error_t error);\r
- \r
- /***************** Init Commands ***************/\r
- command error_t Init.init() {\r
- txDsn = call Random.rand16();\r
- dutyCycling = FALSE;\r
- return SUCCESS;\r
- }\r
- \r
- /***************** LowPowerListening Commands ***************/\r
- /**\r
- * Set this this node's radio sleep interval, in milliseconds.\r
- * Once every interval, the node will sleep and perform an Rx check \r
- * on the radio. Setting the sleep interval to 0 will keep the radio\r
- * always on.\r
- *\r
- * This is the equivalent of setting the local duty cycle rate.\r
- *\r
- * @param sleepIntervalMs the length of this node's Rx check interval, in [ms]\r
- */\r
- command void LowPowerListening.setLocalSleepInterval(\r
- uint16_t sleepIntervalMs) {\r
- call CC2420DutyCycle.setSleepInterval(sleepIntervalMs);\r
- }\r
- \r
- /**\r
- * @return the local node's sleep interval, in [ms]\r
- */\r
- command uint16_t LowPowerListening.getLocalSleepInterval() {\r
- return call CC2420DutyCycle.getSleepInterval();\r
- }\r
- \r
- /**\r
- * Set this node's radio duty cycle rate, in units of [percentage*100].\r
- * For example, to get a 0.05% duty cycle,\r
- * <code>\r
- * call LowPowerListening.setDutyCycle(5); // or equivalently...\r
- * call LowPowerListening.setDutyCycle(00005); // for better readability?\r
- * </code>\r
- *\r
- * For a 100% duty cycle (always on),\r
- * <code>\r
- * call LowPowerListening.setDutyCycle(10000);\r
- * </code>\r
- *\r
- * This is the equivalent of setting the local sleep interval explicitly.\r
- * \r
- * @param dutyCycle The duty cycle percentage, in units of [percentage*100]\r
- */\r
- command void LowPowerListening.setLocalDutyCycle(uint16_t dutyCycle) {\r
- call CC2420DutyCycle.setSleepInterval(\r
- call LowPowerListening.dutyCycleToSleepInterval(dutyCycle));\r
- }\r
- \r
- /**\r
- * @return this node's radio duty cycle rate, in units of [percentage*100]\r
- */\r
- command uint16_t LowPowerListening.getLocalDutyCycle() {\r
- return call LowPowerListening.sleepIntervalToDutyCycle(\r
- call CC2420DutyCycle.getSleepInterval());\r
- }\r
- \r
- \r
- /**\r
- * Configure this outgoing message so it can be transmitted to a neighbor mote\r
- * with the specified Rx sleep interval.\r
- * @param msg Pointer to the message that will be sent\r
- * @param sleepInterval The receiving node's sleep interval, in [ms]\r
- */\r
- command void LowPowerListening.setRxSleepInterval(message_t *msg, \r
- uint16_t sleepIntervalMs) {\r
- getMetadata(msg)->rxInterval = sleepIntervalMs;\r
- }\r
- \r
- /**\r
- * @return the destination node's sleep interval configured in this message\r
- */\r
- command uint16_t LowPowerListening.getRxSleepInterval(message_t *msg) {\r
- return getMetadata(msg)->rxInterval;\r
- }\r
- \r
- /**\r
- * Configure this outgoing message so it can be transmitted to a neighbor mote\r
- * with the specified Rx duty cycle rate.\r
- * Duty cycle is in units of [percentage*100], i.e. 0.25% duty cycle = 25.\r
- * \r
- * @param msg Pointer to the message that will be sent\r
- * @param dutyCycle The duty cycle of the receiving mote, in units of \r
- * [percentage*100]\r
- */\r
- command void LowPowerListening.setRxDutyCycle(message_t *msg, \r
- uint16_t dutyCycle) {\r
- getMetadata(msg)->rxInterval =\r
- call LowPowerListening.dutyCycleToSleepInterval(dutyCycle);\r
- }\r
- \r
- \r
- /**\r
- * @return the destination node's duty cycle configured in this message\r
- * in units of [percentage*100]\r
- */\r
- command uint16_t LowPowerListening.getRxDutyCycle(message_t *msg) {\r
- return call LowPowerListening.sleepIntervalToDutyCycle(\r
- getMetadata(msg)->rxInterval);\r
- }\r
- \r
- /**\r
- * Convert a duty cycle, in units of [percentage*100], to\r
- * the sleep interval of the mote in milliseconds\r
- * @param dutyCycle The duty cycle in units of [percentage*100]\r
- * @return The equivalent sleep interval, in units of [ms]\r
- */\r
- command uint16_t LowPowerListening.dutyCycleToSleepInterval(\r
- uint16_t dutyCycle) {\r
- dutyCycle = getActualDutyCycle(dutyCycle);\r
- \r
- if(dutyCycle == 10000) {\r
- return 0;\r
- }\r
- \r
- return (DUTY_ON_TIME * (10000 - dutyCycle)) / dutyCycle;\r
- }\r
- \r
- /**\r
- * Convert a sleep interval, in units of [ms], to a duty cycle\r
- * in units of [percentage*100]\r
- * @param sleepInterval The sleep interval in units of [ms]\r
- * @return The duty cycle in units of [percentage*100]\r
- */\r
- command uint16_t LowPowerListening.sleepIntervalToDutyCycle(\r
- uint16_t sleepInterval) {\r
- if(sleepInterval == 0) {\r
- return 10000;\r
- }\r
- \r
- return getActualDutyCycle((DUTY_ON_TIME * 10000) \r
- / (sleepInterval + DUTY_ON_TIME));\r
- }\r
-\r
- \r
- /***************** Send Commands ***************/\r
- /**\r
- * Each call to this send command gives the message a single\r
- * DSN that does not change for every copy of the message\r
- * sent out. For messages that are not acknowledged, such as\r
- * a broadcast address message, the receiving end does not\r
- * signal receive() more than once for that message.\r
- */\r
- command error_t Send.send(message_t *msg, uint8_t len) {\r
- if(call SplitControlState.getState() == S_OFF) {\r
- // Everything is off right now, start SplitControl and try again\r
- return EOFF;\r
- }\r
- \r
- if(call SendState.requestState(S_SENDING) == SUCCESS) {\r
- currentSendMsg = msg;\r
- currentSendLen = len;\r
- (getHeader(msg))->dsn = ++txDsn;\r
- \r
- // In case our off timer is running...\r
- call OffTimer.stop();\r
- \r
- if(call RadioState.getState() == S_ON) {\r
- if(call LowPowerListening.getRxSleepInterval(currentSendMsg) \r
- > ONE_MESSAGE) {\r
- // Send it repetitively within our transmit window\r
- call PacketAcknowledgements.requestAck(currentSendMsg);\r
- call SendDoneTimer.startOneShot(\r
- call LowPowerListening.getRxSleepInterval(currentSendMsg) * 2);\r
- }\r
- \r
- post send();\r
- \r
- } else {\r
- post startRadio();\r
- }\r
- \r
- return SUCCESS;\r
- }\r
- \r
- return FAIL;\r
- }\r
-\r
- command error_t Send.cancel(message_t *msg) {\r
- if(currentSendMsg == msg) {\r
- call SendState.toIdle();\r
- return SUCCESS;\r
- }\r
- \r
- return FAIL;\r
- }\r
- \r
- \r
- command uint8_t Send.maxPayloadLength() {\r
- return call SubSend.maxPayloadLength();\r
- }\r
-\r
- command void *Send.getPayload(message_t* msg) {\r
- return call SubSend.getPayload(msg);\r
- }\r
- \r
- /***************** Receive Commands ***************/\r
- command void *Receive.getPayload(message_t* msg, uint8_t* len) {\r
- return call SubReceive.getPayload(msg, len);\r
- }\r
-\r
- command uint8_t Receive.payloadLength(message_t* msg) {\r
- return call SubReceive.payloadLength(msg);\r
- }\r
-\r
-\r
- /***************** DutyCycle Events ***************/\r
- /**\r
- * A transmitter was detected. You must now take action to\r
- * turn the radio off when the transaction is complete.\r
- */\r
- event void CC2420DutyCycle.detected() {\r
- // At this point, the duty cycling has been disabled temporary\r
- // and it will be this component's job to turn the radio back off\r
- \r
- startOffTimer();\r
- }\r
- \r
- \r
- /***************** SubControl Events ***************/\r
- event void SubControl.startDone(error_t error) {\r
- if(!error) {\r
- call RadioState.forceState(S_ON);\r
- \r
- if(call SendState.getState() == S_SENDING) {\r
- if(call LowPowerListening.getRxSleepInterval(currentSendMsg) \r
- > ONE_MESSAGE) {\r
- // Send it repetitively within our transmit window\r
- call PacketAcknowledgements.requestAck(currentSendMsg);\r
- call SendDoneTimer.startOneShot(\r
- call LowPowerListening.getRxSleepInterval(currentSendMsg) * 2);\r
- }\r
- \r
- post send();\r
- }\r
- }\r
- }\r
- \r
- event void SubControl.stopDone(error_t error) {\r
- if(!error) {\r
- call RadioState.forceState(S_OFF);\r
-\r
- if(call SendState.getState() == S_SENDING) {\r
- // We're in the middle of sending a message; start the radio back up\r
- post startRadio();\r
- }\r
- }\r
- }\r
- \r
- /***************** SubSend Events ***************/\r
- event void SubSend.sendDone(message_t* msg, error_t error) {\r
- if(call SendState.getState() == S_SENDING \r
- && call SendDoneTimer.isRunning()) {\r
- if(call PacketAcknowledgements.wasAcked(msg)) {\r
- signalDone(error);\r
- \r
- } else {\r
- post resend();\r
- }\r
- \r
- return;\r
- }\r
- \r
- signalDone(error);\r
- }\r
- \r
- /***************** SubReceive Events ***************/\r
- /**\r
- * If the received message is new, we signal the receive event and\r
- * start the off timer. If the last message we received had the same\r
- * DSN as this message, then the chances are pretty good\r
- * that this message should be ignored, especially if the destination address\r
- * as the broadcast address\r
- *\r
- * TODO\r
- * What happens if a unicast Tx doesn't get Rx's ack, and resends that\r
- * message?\r
- */\r
- event message_t *SubReceive.receive(message_t* msg, void* payload, \r
- uint8_t len) {\r
- \r
- if((getHeader(msg))->dsn == lastRxDsn \r
- && call AMPacket.destination(msg) == AM_BROADCAST_ADDR) {\r
- // Already got this broadcast message.\r
- // TODO should we do something similar with unicast messages?\r
- return msg;\r
-\r
- } else {\r
- lastRxDsn = (getHeader(msg))->dsn;\r
- startOffTimer();\r
- return signal Receive.receive(msg, payload, len);\r
- }\r
- }\r
- \r
- /***************** Timer Events ****************/\r
- event void OffTimer.fired() {\r
- /*\r
- * Only stop the radio if the radio is supposed to be off permanently\r
- * or if the duty cycle is on and our sleep interval is not 0\r
- */\r
- if(call SplitControlState.getState() == S_OFF\r
- || (call CC2420DutyCycle.getSleepInterval() > 0\r
- && call SplitControlState.getState() == S_ON)) { \r
- post stopRadio();\r
- }\r
- }\r
- \r
- /**\r
- * When this timer is running, that means we're sending repeating messages\r
- * to a node that is receive check duty cycling.\r
- */\r
- event void SendDoneTimer.fired() {\r
- if(call SendState.getState() == S_SENDING) {\r
- // The next time SubSend.sendDone is signaled, send is complete.\r
- call SendState.toIdle();\r
- }\r
- }\r
- \r
- /***************** Resend Events ****************/\r
- /**\r
- * Signal that a message has been sent\r
- *\r
- * @param p_msg message to send.\r
- * @param error notifaction of how the operation went.\r
- */\r
- async event void Resend.sendDone( message_t* p_msg, error_t error ) {\r
- // This is actually caught by SubSend.sendDone\r
- }\r
- \r
- \r
- /***************** Tasks ***************/\r
- task void send() {\r
- if(call SubSend.send(currentSendMsg, currentSendLen) != SUCCESS) {\r
- post send();\r
- }\r
- }\r
- \r
- task void resend() {\r
- // Resend the last message without CCA checks.\r
- if(call Resend.resend() != SUCCESS) {\r
- post resend();\r
- }\r
- }\r
- \r
- task void startRadio() {\r
- if(call SubControl.start() != SUCCESS) {\r
- post startRadio();\r
- }\r
- }\r
- \r
- task void stopRadio() {\r
- if(call SubControl.stop() != SUCCESS) {\r
- post stopRadio();\r
- }\r
- }\r
- \r
- /***************** Functions ***************/\r
- void startOffTimer() {\r
- call OffTimer.startOneShot(DELAY_AFTER_RECEIVE);\r
- }\r
- \r
- /**\r
- * Check the bounds on a given duty cycle\r
- * We're never over 100%, and we're never at 0%\r
- */\r
- uint16_t getActualDutyCycle(uint16_t dutyCycle) {\r
- if(dutyCycle > 10000) {\r
- return 10000;\r
- } else if(dutyCycle == 0) {\r
- return 1;\r
- }\r
- \r
- return dutyCycle;\r
- }\r
- \r
- cc2420_header_t *getHeader(message_t *msg) {\r
- return (cc2420_header_t *)(msg->data - sizeof( cc2420_header_t ));\r
- }\r
- \r
- cc2420_metadata_t *getMetadata(message_t* msg) {\r
- return (cc2420_metadata_t*)msg->metadata;\r
- }\r
- \r
- void signalDone(error_t error) {\r
- call SendState.toIdle();\r
- startOffTimer();\r
- signal Send.sendDone(currentSendMsg, error);\r
- currentSendMsg = NULL;\r
- }\r
-}\r
-\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Rincon Research Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
- \r
-/**\r
- * Dummy low power listening interface used when LowPowerListening is not\r
- * compiled in with the application.\r
- * Sleep interval is always 0, and duty cycle is always 100%\r
- * @author David Moss\r
- */\r
- \r
-module CC2420LplDummyP {\r
- provides {\r
- interface LowPowerListening;\r
- }\r
-}\r
-\r
-implementation {\r
-\r
- command void LowPowerListening.setLocalSleepInterval(uint16_t sleepIntervalMs) {\r
- }\r
- \r
- command uint16_t LowPowerListening.getLocalSleepInterval() {\r
- return 0;\r
- }\r
- \r
- command void LowPowerListening.setLocalDutyCycle(uint16_t dutyCycle) {\r
- }\r
- \r
- command uint16_t LowPowerListening.getLocalDutyCycle() {\r
- return 10000;\r
- }\r
- \r
- command void LowPowerListening.setRxSleepInterval(message_t *msg, uint16_t sleepIntervalMs) {\r
- }\r
- \r
- command uint16_t LowPowerListening.getRxSleepInterval(message_t *msg) {\r
- return 0;\r
- }\r
- \r
- command void LowPowerListening.setRxDutyCycle(message_t *msg, uint16_t dutyCycle) {\r
- }\r
- \r
- command uint16_t LowPowerListening.getRxDutyCycle(message_t *msg) {\r
- return 10000;\r
- }\r
- \r
- command uint16_t LowPowerListening.dutyCycleToSleepInterval(uint16_t dutyCycle) {\r
- return 0;\r
- }\r
- \r
- command uint16_t LowPowerListening.sleepIntervalToDutyCycle(uint16_t sleepInterval) {\r
- return 10000;\r
- }\r
- \r
-}\r
-\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-interface CC2420Packet {\r
- \r
- /**\r
- * Get transmission power setting for current packet.\r
- *\r
- * @param the message\r
- */\r
- async command uint8_t getPower( message_t* p_msg );\r
-\r
- /**\r
- * Set transmission power for a given packet. Valid ranges are\r
- * between 0 and 31.\r
- *\r
- * @param p_msg the message.\r
- * @param power transmission power.\r
- */\r
- async command void setPower( message_t* p_msg, uint8_t power );\r
- \r
- /**\r
- * Get rssi value for a given packet. For received packets, it is\r
- * the received signal strength when receiving that packet. For sent\r
- * packets, it is the received signal strength of the ack if an ack\r
- * was received.\r
- */\r
- async command int8_t getRssi( message_t* p_msg );\r
-\r
- /**\r
- * Get lqi value for a given packet. For received packets, it is the\r
- * link quality indicator value when receiving that packet. For sent\r
- * packets, it is the link quality indicator value of the ack if an\r
- * ack was received.\r
- */\r
- async command uint8_t getLqi( message_t* p_msg );\r
- \r
-}\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-module CC2420PacketC {\r
-\r
- provides interface CC2420Packet;\r
- provides interface PacketAcknowledgements as Acks;\r
-\r
-}\r
-\r
-implementation {\r
-\r
- cc2420_header_t* getHeader( message_t* msg ) {\r
- return (cc2420_header_t*)( msg->data - sizeof( cc2420_header_t ) );\r
- }\r
-\r
- cc2420_metadata_t* getMetadata( message_t* msg ) {\r
- return (cc2420_metadata_t*)msg->metadata;\r
- }\r
-\r
- async command error_t Acks.requestAck( message_t* p_msg ) {\r
- getHeader( p_msg )->fcf |= 1 << IEEE154_FCF_ACK_REQ;\r
- return SUCCESS;\r
- }\r
-\r
- async command error_t Acks.noAck( message_t* p_msg ) {\r
- getHeader( p_msg )->fcf &= ~(1 << IEEE154_FCF_ACK_REQ);\r
- return SUCCESS;\r
- }\r
-\r
- async command bool Acks.wasAcked( message_t* p_msg ) {\r
- return getMetadata( p_msg )->ack;\r
- }\r
-\r
- async command void CC2420Packet.setPower( message_t* p_msg, uint8_t power ) {\r
- if ( power > 31 )\r
- power = 31;\r
- getMetadata( p_msg )->tx_power = power;\r
- }\r
-\r
- async command uint8_t CC2420Packet.getPower( message_t* p_msg ) {\r
- return getMetadata( p_msg )->tx_power;\r
- }\r
- \r
- async command int8_t CC2420Packet.getRssi( message_t* p_msg ) {\r
- return getMetadata( p_msg )->rssi;\r
- }\r
-\r
- async command error_t CC2420Packet.getLqi( message_t* p_msg ) {\r
- return getMetadata( p_msg )->lqi;\r
- }\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * An HAL abstraction of the ChipCon CC2420 radio. This abstraction\r
- * deals specifically with radio power operations (e.g. voltage\r
- * regulator, oscillator, etc). However, it does not include\r
- * transmission power, see the CC2420Config interface.\r
- *\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-interface CC2420Power {\r
-\r
- /**\r
- * Start the voltage regulator on the CC2420. On SUCCESS,\r
- * <code>startVReg()</code> will be signalled when the voltage\r
- * regulator is fully on.\r
- *\r
- * @return SUCCESS if the request was accepted, FAIL otherwise.\r
- */\r
- async command error_t startVReg();\r
-\r
- /**\r
- * Signals that the voltage regulator has been started.\r
- */\r
- async event void startVRegDone();\r
- \r
- /**\r
- * Stop the voltage regulator immediately.\r
- *\r
- * @return SUCCESS always\r
- */\r
- async command error_t stopVReg();\r
-\r
- /**\r
- * Start the oscillator. On SUCCESS, <code>startOscillator</code>\r
- * will be signalled when the oscillator has been started.\r
- *\r
- * @return SUCCESS if the request was accepted, FAIL otherwise.\r
- */\r
- async command error_t startOscillator();\r
-\r
- /**\r
- * Signals that the oscillator has been started.\r
- */\r
- async event void startOscillatorDone();\r
-\r
- /**\r
- * Stop the oscillator.\r
- *\r
- * @return SUCCESS if the oscillator was stopped, FAIL otherwise.\r
- */\r
- async command error_t stopOscillator();\r
-\r
- /**\r
- * Enable RX.\r
- *\r
- * @return SUCCESS if receive mode has been enabled, FAIL otherwise.\r
- */\r
- async command error_t rxOn();\r
-\r
- /**\r
- * Disable RX.\r
- *\r
- * @return SUCCESS if receive mode has been disabled, FAIL otherwise.\r
- */\r
- async command error_t rfOff();\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * HAL abstraction for accessing theRAM of a ChipCon CC2420 radio.\r
- *\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-#include "CC2420.h"\r
-\r
-interface CC2420Ram {\r
-\r
- /**\r
- * Read data from a RAM. This operation is sychronous.\r
- *\r
- * @param offset within the field.\r
- * @param data a pointer to the receive buffer.\r
- * @param length number of bytes to read.\r
- * @return status byte returned when sending the last byte\r
- * of the SPI transaction.\r
- */\r
- async command cc2420_status_t read( uint8_t offset, uint8_t* data, uint8_t length );\r
-\r
- /**\r
- * Write data to RAM. This operation is sychronous.\r
- *\r
- * @param offset within the field.\r
- * @param data a pointer to the send buffer.\r
- * @param length number of bytes to write.\r
- * @return status byte returned when sending the last address byte\r
- * of the SPI transaction.\r
- */\r
- async command cc2420_status_t write( uint8_t offset, uint8_t* data, uint8_t length );\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * Low-level abstraction of the receive path implementation for the\r
- * ChipCon CC2420 radio.\r
- *\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-interface CC2420Receive {\r
-\r
- /**\r
- * Notification that an SFD capture has occured.\r
- *\r
- * @param time at which the capture happened.\r
- */\r
- async command void sfd( uint16_t time );\r
-\r
- /**\r
- * Notification that the packet has been dropped by the radio\r
- * (e.g. due to address rejection).\r
- */\r
- async command void sfd_dropped();\r
-\r
- /**\r
- * Signals that a message has been received.\r
- *\r
- * @param type of the message received.\r
- * @param message pointer to message received.\r
- */\r
- async event void receive( uint8_t type, message_t* message );\r
-\r
-}\r
-\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * Implementation of the receive path for the ChipCon CC2420 radio.\r
- *\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-configuration CC2420ReceiveC {\r
-\r
- provides interface Init;\r
- provides interface AsyncStdControl;\r
- provides interface CC2420Receive;\r
- provides interface Receive;\r
-\r
-}\r
-\r
-implementation {\r
-\r
- components CC2420ReceiveP;\r
- components new CC2420SpiC() as Spi;\r
-\r
- components HplCC2420PinsC as Pins;\r
- components HplCC2420InterruptsC as InterruptsC;\r
-\r
- components LedsC as Leds;\r
- CC2420ReceiveP.Leds -> Leds;\r
-\r
- Init = CC2420ReceiveP;\r
- AsyncStdControl = CC2420ReceiveP;\r
- CC2420Receive = CC2420ReceiveP;\r
- Receive = CC2420ReceiveP;\r
-\r
- CC2420ReceiveP.CSN -> Pins.CSN;\r
- CC2420ReceiveP.FIFO -> Pins.FIFO;\r
- CC2420ReceiveP.FIFOP -> Pins.FIFOP;\r
- CC2420ReceiveP.InterruptFIFOP -> InterruptsC.InterruptFIFOP;\r
-\r
- CC2420ReceiveP.SpiResource -> Spi;\r
- CC2420ReceiveP.RXFIFO -> Spi.RXFIFO;\r
- CC2420ReceiveP.SFLUSHRX -> Spi.SFLUSHRX;\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-module CC2420ReceiveP {\r
-\r
- provides interface Init;\r
- provides interface AsyncStdControl;\r
- provides interface CC2420Receive;\r
- provides interface Receive;\r
-\r
- uses interface GeneralIO as CSN;\r
- uses interface GeneralIO as FIFO;\r
- uses interface GeneralIO as FIFOP;\r
- uses interface GpioInterrupt as InterruptFIFOP;\r
-\r
- uses interface Resource as SpiResource;\r
- uses interface CC2420Fifo as RXFIFO;\r
- uses interface CC2420Strobe as SACK;\r
- uses interface CC2420Strobe as SFLUSHRX;\r
-\r
- uses interface Leds;\r
-\r
-}\r
-\r
-implementation {\r
-\r
- typedef enum {\r
- S_STOPPED,\r
- S_STARTED,\r
- S_RX_HEADER,\r
- S_RX_PAYLOAD,\r
- } cc2420_receive_state_t;\r
-\r
- enum {\r
- RXFIFO_SIZE = 128,\r
- TIMESTAMP_QUEUE_SIZE = 8,\r
- };\r
-\r
- uint16_t m_timestamp_queue[ TIMESTAMP_QUEUE_SIZE ];\r
- uint8_t m_timestamp_head, m_timestamp_size;\r
- uint8_t m_missed_packets;\r
-\r
- bool fallingEdgeEnabled;\r
- \r
- norace uint8_t m_bytes_left;\r
- norace message_t* m_p_rx_buf;\r
-\r
- message_t m_rx_buf;\r
- cc2420_receive_state_t m_state;\r
-\r
- void beginReceive();\r
- void receive();\r
- void waitForNextPacket();\r
- task void receiveDone_task();\r
-\r
- cc2420_header_t* getHeader( message_t* msg ) {\r
- return (cc2420_header_t*)( msg->data - sizeof( cc2420_header_t ) );\r
- }\r
- \r
- cc2420_metadata_t* getMetadata( message_t* msg ) {\r
- return (cc2420_metadata_t*)msg->metadata;\r
- }\r
- \r
- command error_t Init.init() {\r
- fallingEdgeEnabled = FALSE;\r
- m_p_rx_buf = &m_rx_buf;\r
- return SUCCESS;\r
- }\r
-\r
- void reset_state() {\r
- m_bytes_left = RXFIFO_SIZE;\r
- m_timestamp_head = m_timestamp_size = 0;\r
- m_missed_packets = 0;\r
- }\r
-\r
- async command error_t AsyncStdControl.start() {\r
- atomic {\r
- reset_state();\r
- m_state = S_STARTED;\r
- \r
- // MicaZ's don't like to re-enable the falling edge\r
- if(!fallingEdgeEnabled) {\r
- call InterruptFIFOP.enableFallingEdge();\r
- fallingEdgeEnabled = TRUE;\r
- }\r
- }\r
- return SUCCESS;\r
- }\r
-\r
- async command error_t AsyncStdControl.stop() {\r
- atomic {\r
- m_state = S_STOPPED;\r
- // MicaZ's don't like to re-enable the falling edge\r
- //call InterruptFIFOP.disable();\r
- }\r
- return SUCCESS;\r
- }\r
-\r
- async command void CC2420Receive.sfd( uint16_t time ) {\r
- if ( m_timestamp_size < TIMESTAMP_QUEUE_SIZE ) {\r
- uint8_t tail = ( ( m_timestamp_head + m_timestamp_size ) % \r
- TIMESTAMP_QUEUE_SIZE );\r
- m_timestamp_queue[ tail ] = time;\r
- m_timestamp_size++;\r
- }\r
- }\r
-\r
- async command void CC2420Receive.sfd_dropped() {\r
- if ( m_timestamp_size )\r
- m_timestamp_size--;\r
- }\r
-\r
- async event void InterruptFIFOP.fired() {\r
- if ( m_state == S_STARTED )\r
- beginReceive();\r
- else\r
- m_missed_packets++;\r
- }\r
- \r
- void beginReceive() { \r
- m_state = S_RX_HEADER;\r
- if ( call SpiResource.immediateRequest() == SUCCESS )\r
- receive();\r
- else\r
- call SpiResource.request();\r
- }\r
- \r
- event void SpiResource.granted() {\r
- receive();\r
- }\r
-\r
- void receive() {\r
- call CSN.clr();\r
- call RXFIFO.beginRead( (uint8_t*)getHeader( m_p_rx_buf ), 1 );\r
- }\r
-\r
- async event void RXFIFO.readDone( uint8_t* rx_buf, uint8_t rx_len,\r
- error_t error ) {\r
-\r
- cc2420_header_t* header = getHeader( m_p_rx_buf );\r
- cc2420_metadata_t* metadata = getMetadata( m_p_rx_buf );\r
- uint8_t* buf = (uint8_t*)header;\r
- uint8_t length = buf[ 0 ];\r
-\r
- switch( m_state ) {\r
-\r
- case S_RX_HEADER:\r
- m_state = S_RX_PAYLOAD;\r
- if ( length + 1 > m_bytes_left ) {\r
- reset_state();\r
- call CSN.set();\r
- call CSN.clr();\r
- call SFLUSHRX.strobe();\r
- call SFLUSHRX.strobe();\r
- call CSN.set();\r
- call SpiResource.release();\r
- waitForNextPacket();\r
- }\r
- else {\r
- if ( !call FIFO.get() && !call FIFOP.get() )\r
- m_bytes_left -= length + 1;\r
- call RXFIFO.continueRead( (length <= MAC_PACKET_SIZE) ? buf + 1 : NULL,\r
- length );\r
- }\r
- break;\r
- \r
- case S_RX_PAYLOAD:\r
- \r
- call CSN.set();\r
- call SpiResource.release();\r
- \r
- if ( m_timestamp_size ) {\r
- if ( length > 10 ) {\r
- metadata->time = m_timestamp_queue[ m_timestamp_head ];\r
- m_timestamp_head = ( m_timestamp_head + 1 ) % TIMESTAMP_QUEUE_SIZE;\r
- m_timestamp_size--;\r
- }\r
- }\r
- else {\r
- metadata->time = 0xffff;\r
- }\r
- \r
- // pass packet up if crc is good\r
- if ( ( buf[ length ] >> 7 ) && rx_buf ) {\r
- uint8_t type = ( header->fcf >> IEEE154_FCF_FRAME_TYPE ) & 7;\r
- signal CC2420Receive.receive( type, m_p_rx_buf );\r
- if ( type == IEEE154_TYPE_DATA ) {\r
- post receiveDone_task();\r
- return;\r
- }\r
- }\r
- \r
- waitForNextPacket();\r
- break;\r
-\r
- default:\r
- call CSN.set();\r
- call SpiResource.release();\r
- break;\r
- \r
- }\r
- \r
- }\r
-\r
- task void receiveDone_task() {\r
- \r
- cc2420_header_t* header = getHeader( m_p_rx_buf );\r
- cc2420_metadata_t* metadata = getMetadata( m_p_rx_buf );\r
- uint8_t* buf = (uint8_t*)header;\r
- uint8_t length = buf[ 0 ];\r
- \r
- metadata->crc = buf[ length ] >> 7;\r
- metadata->rssi = buf[ length - 1 ];\r
- metadata->lqi = buf[ length ] & 0x7f;\r
- m_p_rx_buf = signal Receive.receive( m_p_rx_buf, m_p_rx_buf->data, \r
- length );\r
-\r
- waitForNextPacket();\r
-\r
- }\r
-\r
- void waitForNextPacket() {\r
-\r
- atomic {\r
- if ( m_state == S_STOPPED )\r
- return;\r
-\r
- if ( ( m_missed_packets && call FIFO.get() ) || !call FIFOP.get() ) {\r
- if ( m_missed_packets )\r
- m_missed_packets--;\r
- beginReceive();\r
- }\r
- else {\r
- m_state = S_STARTED;\r
- m_missed_packets = 0;\r
- }\r
- } \r
- \r
- }\r
-\r
- command void* Receive.getPayload(message_t* m, uint8_t* len) {\r
- if (len != NULL) {\r
- *len = TOSH_DATA_LENGTH;\r
- }\r
- return m->data;\r
- }\r
-\r
- command uint8_t Receive.payloadLength(message_t* m) {\r
- uint8_t* buf = (uint8_t*)getHeader( m_p_rx_buf );\r
- return buf[0];\r
- }\r
-\r
- async event void RXFIFO.writeDone( uint8_t* tx_buf, uint8_t tx_len, error_t error ) {} \r
-}\r
+++ /dev/null
-/* tab:4\r
- * "Copyright (c) 2005 Stanford University. All rights reserved.\r
- *\r
- * Permission to use, copy, modify, and distribute this software and\r
- * its documentation for any purpose, without fee, and without written\r
- * agreement is hereby granted, provided that the above copyright\r
- * notice, the following two paragraphs and the author appear in all\r
- * copies of this software.\r
- * \r
- * IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE TO ANY PARTY FOR\r
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES\r
- * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN\r
- * IF STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\r
- * DAMAGE.\r
- * \r
- * STANFORD UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,\r
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE\r
- * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND STANFORD UNIVERSITY\r
- * HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,\r
- * ENHANCEMENTS, OR MODIFICATIONS."\r
- *\r
- */\r
-\r
-/**\r
- * Interface representing one of the Read/Write registers on the\r
- * CC2420 radio. The return values (when appropriate) refer to the\r
- * status byte returned on the CC2420 SO pin. A full list of RW\r
- * registers can be found on page 61 of the CC2420 datasheet (rev\r
- * 1.2). Page 25 of the same document describes the protocol for\r
- * interacting with these registers over the CC2420 SPI bus.\r
- *\r
- * @author Philip Levis\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-#include "CC2420.h"\r
-\r
-interface CC2420Register {\r
-\r
- /**\r
- * Read a 16-bit data word from the register.\r
- *\r
- * @param data pointer to place the register value.\r
- * @return status byte from the read.\r
- */\r
- async command cc2420_status_t read(uint16_t* data);\r
-\r
- /**\r
- * Write a 16-bit data word to the register.\r
- * \r
- * @param data value to write to register.\r
- * @return status byte from the write.\r
- */\r
- async command cc2420_status_t write(uint16_t data);\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * Implementation of basic SPI primitives for the ChipCon CC2420 radio.\r
- *\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-generic configuration CC2420SpiC() {\r
-\r
- provides interface Resource;\r
-\r
- // commands\r
- provides interface CC2420Strobe as SFLUSHRX;\r
- provides interface CC2420Strobe as SFLUSHTX;\r
- provides interface CC2420Strobe as SNOP;\r
- provides interface CC2420Strobe as SRXON;\r
- provides interface CC2420Strobe as SRFOFF;\r
- provides interface CC2420Strobe as STXON;\r
- provides interface CC2420Strobe as STXONCCA;\r
- provides interface CC2420Strobe as SXOSCON;\r
- provides interface CC2420Strobe as SXOSCOFF;\r
-\r
- // registers\r
- provides interface CC2420Register as FSCTRL;\r
- provides interface CC2420Register as IOCFG0;\r
- provides interface CC2420Register as IOCFG1;\r
- provides interface CC2420Register as MDMCTRL0;\r
- provides interface CC2420Register as MDMCTRL1;\r
- provides interface CC2420Register as TXCTRL;\r
-\r
- // ram\r
- provides interface CC2420Ram as IEEEADR;\r
- provides interface CC2420Ram as PANID;\r
- provides interface CC2420Ram as SHORTADR;\r
- provides interface CC2420Ram as TXFIFO_RAM;\r
-\r
- // fifos\r
- provides interface CC2420Fifo as RXFIFO;\r
- provides interface CC2420Fifo as TXFIFO;\r
-\r
-}\r
-\r
-implementation {\r
-\r
- enum {\r
- CLIENT_ID = unique( "CC2420Spi.Resource" ),\r
- };\r
-\r
- components HplCC2420PinsC as Pins;\r
- components CC2420SpiP as Spi;\r
- \r
- Resource = Spi.Resource[ CLIENT_ID ];\r
-\r
- // commands\r
- SFLUSHRX = Spi.Strobe[ CC2420_SFLUSHRX ];\r
- SFLUSHTX = Spi.Strobe[ CC2420_SFLUSHTX ];\r
- SNOP = Spi.Strobe[ CC2420_SNOP ];\r
- SRXON = Spi.Strobe[ CC2420_SRXON ];\r
- SRFOFF = Spi.Strobe[ CC2420_SRFOFF ];\r
- STXON = Spi.Strobe[ CC2420_STXON ];\r
- STXONCCA = Spi.Strobe[ CC2420_STXONCCA ];\r
- SXOSCON = Spi.Strobe[ CC2420_SXOSCON ];\r
- SXOSCOFF = Spi.Strobe[ CC2420_SXOSCOFF ];\r
-\r
- // registers\r
- FSCTRL = Spi.Reg[ CC2420_FSCTRL ];\r
- IOCFG0 = Spi.Reg[ CC2420_IOCFG0 ];\r
- IOCFG1 = Spi.Reg[ CC2420_IOCFG1 ];\r
- MDMCTRL0 = Spi.Reg[ CC2420_MDMCTRL0 ];\r
- MDMCTRL1 = Spi.Reg[ CC2420_MDMCTRL1 ];\r
- TXCTRL = Spi.Reg[ CC2420_TXCTRL ];\r
-\r
- // ram\r
- IEEEADR = Spi.Ram[ CC2420_RAM_IEEEADR ];\r
- PANID = Spi.Ram[ CC2420_RAM_PANID ];\r
- SHORTADR = Spi.Ram[ CC2420_RAM_SHORTADR ];\r
- TXFIFO_RAM = Spi.Ram[ CC2420_RAM_TXFIFO ];\r
-\r
- // fifos\r
- RXFIFO = Spi.Fifo[ CC2420_RXFIFO ];\r
- TXFIFO = Spi.Fifo[ CC2420_TXFIFO ];\r
-\r
-}\r
-\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-module CC2420SpiImplP {\r
-\r
- provides interface Resource[ uint8_t id ];\r
- provides interface CC2420Fifo as Fifo[ uint8_t id ];\r
- provides interface CC2420Ram as Ram[ uint16_t id ];\r
- provides interface CC2420Register as Reg[ uint8_t id ];\r
- provides interface CC2420Strobe as Strobe[ uint8_t id ];\r
-\r
- uses interface Resource as SpiResource;\r
- uses interface SpiByte;\r
- uses interface SpiPacket;\r
- uses interface Leds;\r
-\r
-}\r
-\r
-implementation {\r
-\r
- enum {\r
- RESOURCE_COUNT = uniqueCount( "CC2420Spi.Resource" ),\r
- NO_HOLDER = 0xff,\r
- };\r
-\r
- norace uint16_t m_addr;\r
- bool m_resource_busy = FALSE;\r
- uint8_t m_requests = 0;\r
- uint8_t m_holder = NO_HOLDER;\r
-\r
- default event void Resource.granted[ uint8_t id ]() {\r
- }\r
-\r
- async command error_t Resource.request[ uint8_t id ]() {\r
- atomic {\r
- if ( m_resource_busy )\r
- m_requests |= 1 << id;\r
- else {\r
- m_holder = id;\r
- m_resource_busy = TRUE;\r
- call SpiResource.request();\r
- }\r
- }\r
- return SUCCESS;\r
- }\r
- \r
- async command error_t Resource.immediateRequest[ uint8_t id ]() {\r
- error_t error;\r
- atomic {\r
- if ( m_resource_busy )\r
- return EBUSY;\r
- error = call SpiResource.immediateRequest();\r
- if ( error == SUCCESS ) {\r
- m_holder = id;\r
- m_resource_busy = TRUE;\r
- }\r
- }\r
- return error;\r
- }\r
-\r
- async command error_t Resource.release[ uint8_t id ]() {\r
- uint8_t i;\r
- atomic {\r
- if ( m_holder != id )\r
- return FAIL;\r
- m_holder = NO_HOLDER;\r
- call SpiResource.release();\r
- if ( !m_requests ) {\r
- m_resource_busy = FALSE;\r
- }\r
- else {\r
- for ( i = m_holder + 1; ; i++ ) {\r
- if ( i >= RESOURCE_COUNT )\r
- i = 0;\r
- if ( m_requests & ( 1 << i ) ) {\r
- m_holder = i;\r
- m_requests &= ~( 1 << i );\r
- call SpiResource.request();\r
- return SUCCESS;\r
- }\r
- }\r
- }\r
- return SUCCESS;\r
- }\r
- }\r
- \r
- async command uint8_t Resource.isOwner[ uint8_t id ]() {\r
- atomic return m_holder == id;\r
- }\r
-\r
- event void SpiResource.granted() {\r
- uint8_t holder;\r
- atomic holder = m_holder;\r
- signal Resource.granted[ holder ]();\r
- }\r
-\r
- async command cc2420_status_t Fifo.beginRead[ uint8_t addr ]( uint8_t* data, \r
- uint8_t len ) {\r
- \r
- cc2420_status_t status;\r
- \r
- m_addr = addr | 0x40;\r
- \r
- status = call SpiByte.write( m_addr );\r
- call Fifo.continueRead[ addr ]( data, len );\r
- \r
- return status;\r
- \r
- }\r
-\r
- async command error_t Fifo.continueRead[ uint8_t addr ]( uint8_t* data,\r
- uint8_t len ) {\r
- call SpiPacket.send( NULL, data, len );\r
- return SUCCESS;\r
- }\r
-\r
- async command cc2420_status_t Fifo.write[ uint8_t addr ]( uint8_t* data, \r
- uint8_t len ) {\r
-\r
- uint8_t status;\r
-\r
- m_addr = addr;\r
-\r
- status = call SpiByte.write( m_addr );\r
- call SpiPacket.send( data, NULL, len );\r
-\r
- return status;\r
-\r
- }\r
-\r
- async command cc2420_status_t Ram.read[ uint16_t addr ]( uint8_t offset,\r
- uint8_t* data, \r
- uint8_t len ) {\r
-\r
- cc2420_status_t status;\r
-\r
- addr += offset;\r
-\r
- call SpiByte.write( addr | 0x80 );\r
- status = call SpiByte.write( ( ( addr >> 1 ) & 0xc0 ) | 0x20 );\r
- for ( ; len; len-- )\r
- *data++ = call SpiByte.write( 0 );\r
-\r
- return status;\r
-\r
- }\r
-\r
- async event void SpiPacket.sendDone( uint8_t* tx_buf, uint8_t* rx_buf, \r
- uint16_t len, error_t error ) {\r
- if ( m_addr & 0x40 )\r
- signal Fifo.readDone[ m_addr & ~0x40 ]( rx_buf, len, error );\r
- else\r
- signal Fifo.writeDone[ m_addr ]( tx_buf, len, error );\r
- }\r
-\r
- async command cc2420_status_t Ram.write[ uint16_t addr ]( uint8_t offset,\r
- uint8_t* data, \r
- uint8_t len ) {\r
-\r
- cc2420_status_t status = 0;\r
-\r
- addr += offset;\r
-\r
- call SpiByte.write( addr | 0x80 );\r
- call SpiByte.write( ( addr >> 1 ) & 0xc0 );\r
- for ( ; len; len-- )\r
- status = call SpiByte.write( *data++ );\r
-\r
- return status;\r
-\r
- }\r
-\r
- async command cc2420_status_t Reg.read[ uint8_t addr ]( uint16_t* data ) {\r
-\r
- cc2420_status_t status;\r
- \r
- status = call SpiByte.write( addr | 0x40 );\r
- *data = (uint16_t)call SpiByte.write( 0 ) << 8;\r
- *data |= call SpiByte.write( 0 );\r
- \r
- return status;\r
-\r
- }\r
-\r
- async command cc2420_status_t Reg.write[ uint8_t addr ]( uint16_t data ) {\r
-\r
- call SpiByte.write( addr );\r
- call SpiByte.write( data >> 8 );\r
- return call SpiByte.write( data & 0xff );\r
-\r
- }\r
-\r
- async command cc2420_status_t Strobe.strobe[ uint8_t addr ]() {\r
- return call SpiByte.write( addr );\r
- }\r
-\r
- default async event void Fifo.readDone[ uint8_t addr ]( uint8_t* rx_buf, uint8_t rx_len, error_t error ) {}\r
- default async event void Fifo.writeDone[ uint8_t addr ]( uint8_t* tx_buf, uint8_t tx_len, error_t error ) {}\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-configuration CC2420SpiP {\r
-\r
- provides interface Resource[ uint8_t id ];\r
- provides interface CC2420Fifo as Fifo[ uint8_t id ];\r
- provides interface CC2420Ram as Ram[ uint16_t id ];\r
- provides interface CC2420Register as Reg[ uint8_t id ];\r
- provides interface CC2420Strobe as Strobe[ uint8_t id ];\r
-\r
-}\r
-\r
-implementation {\r
-\r
- components CC2420SpiImplP as SpiP;\r
- Resource = SpiP;\r
- Fifo = SpiP;\r
- Ram = SpiP;\r
- Reg = SpiP;\r
- Strobe = SpiP;\r
-\r
- components new HplCC2420SpiC();\r
- SpiP.SpiResource -> HplCC2420SpiC;\r
- SpiP.SpiByte -> HplCC2420SpiC;\r
- SpiP.SpiPacket -> HplCC2420SpiC;\r
-\r
- components LedsC;\r
- SpiP.Leds -> LedsC;\r
-\r
-}\r
+++ /dev/null
-/* tab:4\r
- * "Copyright (c) 2005 Stanford University. All rights reserved.\r
- *\r
- * Permission to use, copy, modify, and distribute this software and\r
- * its documentation for any purpose, without fee, and without written\r
- * agreement is hereby granted, provided that the above copyright\r
- * notice, the following two paragraphs and the author appear in all\r
- * copies of this software.\r
- * \r
- * IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE TO ANY PARTY FOR\r
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES\r
- * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN\r
- * IF STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\r
- * DAMAGE.\r
- * \r
- * STANFORD UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,\r
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE\r
- * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND STANFORD UNIVERSITY\r
- * HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,\r
- * ENHANCEMENTS, OR MODIFICATIONS."\r
- *\r
- */\r
-\r
-/**\r
- * Interface representing one of the CC2420 command strobe registers.\r
- * Writing to one of these registers enacts a command on the CC2420,\r
- * such as power-up, transmission, or clear a FIFO.\r
- *\r
- * @author Philip Levis\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-#include "CC2420.h"\r
-\r
-interface CC2420Strobe {\r
-\r
- /**\r
- * Send a command strobe to the register. The return value is the\r
- * CC2420 status register. Table 5 on page 27 of the CC2420\r
- * datasheet (v1.2) describes the contents of this register.\r
- * \r
- * @return Status byte from the CC2420.\r
- */\r
- async command cc2420_status_t strobe();\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * Low-level abstraction for the transmit path implementaiton of the\r
- * ChipCon CC2420 radio.\r
- *\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-interface CC2420Transmit {\r
-\r
- /**\r
- * Send a message with CCA enabled.\r
- *\r
- * @param p_msg message to send.\r
- * @return SUCCESS if the request was accepted, FAIL otherwise.\r
- */\r
- async command error_t sendCCA( message_t* p_msg );\r
-\r
- /**\r
- * Send a message with CCA disabled.\r
- *\r
- * @param p_msg message to send.\r
- * @return SUCCESS if the request was accepted, FAIL otherwise.\r
- */\r
- async command error_t send( message_t* p_msg );\r
-\r
- /**\r
- * Send the previous message again with CCA enabled.\r
- *\r
- * @return SUCCESS if the request was accepted, FAIL otherwise.\r
- */\r
- async command error_t resendCCA();\r
-\r
- /**\r
- * Send the previous message again with CCA disabled.\r
- *\r
- * @return SUCCESS if the request was accepted, FAIL otherwise.\r
- */\r
- async command error_t resend();\r
-\r
- /**\r
- * Cancel sending of the message.\r
- *\r
- * @return SUCCESS if the request was accepted, FAIL otherwise.\r
- */\r
- async command error_t cancel();\r
-\r
- /**\r
- * Signal that a message has been sent\r
- *\r
- * @param p_msg message to send.\r
- * @param error notifaction of how the operation went.\r
- */\r
- async event void sendDone( message_t* p_msg, error_t error );\r
-\r
- /**\r
- * Modify the contents of a packet. This command can only be used\r
- * when an SFD capture event for the sending packet is signalled.\r
- *\r
- * @param offset in the message to start modifying.\r
- * @param buf to data to write\r
- * @param len of bytes to write\r
- * @return SUCCESS if the request was accepted, FAIL otherwise.\r
- */\r
- async command error_t modify( uint8_t offset, uint8_t* buf, uint8_t len );\r
-\r
-}\r
-\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * Implementation of the transmit path for the ChipCon CC2420 radio.\r
- *\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-#include "IEEE802154.h"\r
-\r
-configuration CC2420TransmitC {\r
-\r
- provides {\r
- interface Init;\r
- interface AsyncStdControl;\r
- interface CC2420Transmit;\r
- interface CsmaBackoff;\r
- interface RadioTimeStamping;\r
- interface CC2420Cca;\r
- }\r
-}\r
-\r
-implementation {\r
-\r
- components CC2420TransmitP;\r
- Init = Alarm;\r
- Init = CC2420TransmitP;\r
- AsyncStdControl = CC2420TransmitP;\r
- CC2420Transmit = CC2420TransmitP;\r
- CsmaBackoff = CC2420TransmitP;\r
- RadioTimeStamping = CC2420TransmitP;\r
- CC2420Cca = CC2420TransmitP;\r
-\r
- components AlarmMultiplexC as Alarm;\r
- CC2420TransmitP.BackoffTimer -> Alarm;\r
-\r
-#ifdef PLATFORM_MICAZ\r
- components new TimerMilliC() as WatchdogTimerC;\r
- CC2420TransmitP.WatchdogTimer -> WatchdogTimerC;\r
-#endif\r
-\r
- components HplCC2420PinsC as Pins;\r
- CC2420TransmitP.CCA -> Pins.CCA;\r
- CC2420TransmitP.CSN -> Pins.CSN;\r
- CC2420TransmitP.SFD -> Pins.SFD;\r
-\r
- components HplCC2420InterruptsC as Interrupts;\r
- CC2420TransmitP.CaptureSFD -> Interrupts.CaptureSFD;\r
-\r
- components new CC2420SpiC() as Spi;\r
- CC2420TransmitP.SpiResource -> Spi;\r
- CC2420TransmitP.SNOP -> Spi.SNOP;\r
- CC2420TransmitP.STXON -> Spi.STXON;\r
- CC2420TransmitP.STXONCCA -> Spi.STXONCCA;\r
- CC2420TransmitP.SFLUSHTX -> Spi.SFLUSHTX;\r
- CC2420TransmitP.TXCTRL -> Spi.TXCTRL;\r
- CC2420TransmitP.TXFIFO -> Spi.TXFIFO;\r
- CC2420TransmitP.TXFIFO_RAM -> Spi.TXFIFO_RAM;\r
-\r
- components CC2420ReceiveC;\r
- CC2420TransmitP.CC2420Receive -> CC2420ReceiveC;\r
-\r
- components LedsC as Leds;\r
- CC2420TransmitP.Leds -> Leds;\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- */\r
-\r
-/**\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
- \r
-#include "IEEE802154.h"\r
-\r
-module CC2420TransmitP {\r
-\r
- provides interface Init;\r
- provides interface AsyncStdControl;\r
- provides interface CC2420Transmit as Send;\r
- provides interface CsmaBackoff;\r
- provides interface RadioTimeStamping as TimeStamp;\r
- provides interface CC2420Cca;\r
- \r
- uses interface Alarm<T32khz,uint32_t> as BackoffTimer;\r
-\r
-#ifdef PLATFORM_MICAZ\r
- uses interface Timer<TMilli> as WatchdogTimer;\r
-#endif\r
-\r
- uses interface GpioCapture as CaptureSFD;\r
- uses interface GeneralIO as CCA;\r
- uses interface GeneralIO as CSN;\r
- uses interface GeneralIO as SFD;\r
-\r
- uses interface Resource as SpiResource;\r
- uses interface CC2420Fifo as TXFIFO;\r
- uses interface CC2420Ram as TXFIFO_RAM;\r
- uses interface CC2420Register as TXCTRL;\r
- uses interface CC2420Strobe as SNOP;\r
- uses interface CC2420Strobe as STXON;\r
- uses interface CC2420Strobe as STXONCCA;\r
- uses interface CC2420Strobe as SFLUSHTX;\r
-\r
- uses interface CC2420Receive;\r
- uses interface Leds;\r
-\r
-}\r
-\r
-implementation {\r
-\r
- typedef enum {\r
- S_STOPPED,\r
- S_STARTED,\r
- S_LOAD,\r
- S_SAMPLE_CCA,\r
- S_SAMPLE_CCA_ONLY,\r
- S_BEGIN_TRANSMIT,\r
- S_SFD,\r
- S_EFD,\r
- S_ACK_WAIT,\r
- S_CANCEL,\r
- } cc2420_transmit_state_t;\r
-\r
- // This specifies how many jiffies the stack should wait after a\r
- // TXACTIVE to receive an SFD interrupt before assuming something is\r
- // wrong and aborting the send. There seems to be a condition\r
- // on the micaZ where the SFD interrupt is never handled.\r
- enum {\r
- CC2420_ABORT_PERIOD = 320\r
- };\r
- \r
- norace message_t* m_msg;\r
- \r
- norace bool m_cca;\r
- \r
- norace uint8_t m_tx_power;\r
- \r
- cc2420_transmit_state_t m_state = S_STOPPED;\r
- \r
- bool m_receiving = FALSE;\r
- \r
- uint16_t m_prev_time;\r
-\r
-\r
- /***************** Prototypes ****************/\r
- void loadTXFIFO();\r
- void attemptSend();\r
- cc2420_header_t* getHeader( message_t* msg );\r
- cc2420_metadata_t* getMetadata( message_t* msg );\r
- void startBackoffTimer(uint16_t time);\r
- void stopBackoffTimer();\r
- error_t acquireSpiResource();\r
- void releaseSpiResource();\r
- void signalDone(error_t err);\r
- void congestionBackoff();\r
- error_t send( message_t* p_msg, bool cca );\r
- error_t resend( bool cca );\r
- \r
-#ifdef PLATFORM_MICAZ\r
- task void startWatchdogTimer();\r
- task void stopWatchdogTimer();\r
-#endif\r
-\r
-\r
- /***************** Init Commands ****************/\r
- command error_t Init.init() {\r
- call CCA.makeInput();\r
- call CSN.makeOutput();\r
- call SFD.makeInput();\r
- return SUCCESS;\r
- }\r
-\r
- /***************** AsyncStdControl Commands ****************/\r
- async command error_t AsyncStdControl.start() {\r
- atomic {\r
- call CaptureSFD.captureRisingEdge();\r
- m_state = S_STARTED;\r
- m_receiving = FALSE;\r
- m_tx_power = 0;\r
- }\r
- return SUCCESS;\r
- }\r
-\r
- async command error_t AsyncStdControl.stop() {\r
- atomic {\r
- m_state = S_STOPPED;\r
- stopBackoffTimer();\r
- call CaptureSFD.disable();\r
- }\r
- return SUCCESS;\r
- }\r
-\r
- /***************** Send Commands ****************/\r
- async command error_t Send.sendCCA( message_t* p_msg ) {\r
- return send( p_msg, TRUE );\r
- }\r
-\r
- async command error_t Send.send( message_t* p_msg ) {\r
- return send( p_msg, FALSE );\r
- }\r
-\r
- async command error_t Send.resendCCA() {\r
- return resend( TRUE );\r
- }\r
-\r
- async command error_t Send.resend() {\r
- return resend( FALSE );\r
- }\r
-\r
- async command error_t Send.cancel() {\r
- stopBackoffTimer();\r
-\r
- atomic {\r
- switch( m_state ) {\r
- case S_LOAD:\r
- m_state = S_CANCEL;\r
- break;\r
- \r
- case S_SAMPLE_CCA: \r
- case S_BEGIN_TRANSMIT:\r
- m_state = S_STARTED;\r
- break;\r
- \r
- default:\r
- // cancel not allowed while radio is busy transmitting\r
- return FAIL;\r
- }\r
- }\r
-\r
- return SUCCESS;\r
- }\r
-\r
- async command error_t Send.modify( uint8_t offset, uint8_t* buf, \r
- uint8_t len ) {\r
- call CSN.clr();\r
- call TXFIFO_RAM.write( offset, buf, len );\r
- call CSN.set();\r
- return SUCCESS;\r
- }\r
-\r
- /***************** CC2420Cca Commands ****************/\r
- /**\r
- * @return TRUE if the CCA pin shows a clear channel\r
- */\r
- command bool CC2420Cca.isChannelClear() {\r
- return call CCA.get();\r
- }\r
- \r
- /***************** CaptureSFD Events ****************/\r
- async event void CaptureSFD.captured( uint16_t time ) {\r
-\r
- atomic {\r
- switch( m_state ) {\r
- \r
- case S_SFD:\r
- call CaptureSFD.captureFallingEdge();\r
- signal TimeStamp.transmittedSFD( time, m_msg );\r
- releaseSpiResource();\r
- stopBackoffTimer();\r
- m_state = S_EFD;\r
- if ( ( ( getHeader( m_msg )->fcf >> IEEE154_FCF_FRAME_TYPE ) & 7 ) == \r
- IEEE154_TYPE_DATA )\r
- getMetadata( m_msg )->time = time;\r
- if ( call SFD.get() )\r
- break;\r
- \r
- case S_EFD:\r
- call CaptureSFD.captureRisingEdge();\r
- if ( getHeader( m_msg )->fcf & ( 1 << IEEE154_FCF_ACK_REQ ) ) {\r
- m_state = S_ACK_WAIT;\r
- startBackoffTimer( CC2420_ACK_WAIT_DELAY );\r
- }\r
- else {\r
- signalDone(SUCCESS);\r
- }\r
- if ( !call SFD.get() )\r
- break;\r
- \r
- default:\r
- if ( !m_receiving ) {\r
- call CaptureSFD.captureFallingEdge();\r
- signal TimeStamp.receivedSFD( time );\r
- call CC2420Receive.sfd( time );\r
- m_receiving = TRUE;\r
- m_prev_time = time;\r
- if ( call SFD.get() )\r
- return;\r
- }\r
- if ( m_receiving ) {\r
- call CaptureSFD.captureRisingEdge();\r
- m_receiving = FALSE;\r
- if ( time - m_prev_time < 10 )\r
- call CC2420Receive.sfd_dropped();\r
- }\r
- break;\r
- \r
- }\r
- }\r
- }\r
-\r
- /***************** CC2420Receive Events ****************/\r
- async event void CC2420Receive.receive( uint8_t type, message_t* ack_msg ) {\r
-\r
- if ( type == IEEE154_TYPE_ACK ) {\r
- cc2420_header_t* ack_header = getHeader( ack_msg );\r
- cc2420_header_t* msg_header = getHeader( m_msg );\r
- cc2420_metadata_t* msg_metadata = getMetadata( m_msg );\r
- uint8_t* ack_buf = (uint8_t*)ack_header;\r
- uint8_t length = ack_header->length;\r
- \r
- if ( m_state == S_ACK_WAIT &&\r
- msg_header->dsn == ack_header->dsn ) {\r
- stopBackoffTimer();\r
- msg_metadata->ack = TRUE;\r
- msg_metadata->rssi = ack_buf[ length - 1 ];\r
- msg_metadata->lqi = ack_buf[ length ] & 0x7f;\r
- signalDone(SUCCESS);\r
- }\r
- }\r
- }\r
-\r
- /***************** SpiResource Events ****************/\r
- event void SpiResource.granted() {\r
- uint8_t cur_state;\r
-\r
- atomic {\r
- cur_state = m_state;\r
- }\r
-\r
- switch( cur_state ) {\r
- case S_LOAD: \r
- loadTXFIFO(); \r
- break;\r
- \r
- case S_BEGIN_TRANSMIT: \r
- attemptSend(); \r
- break;\r
- \r
- default: \r
- releaseSpiResource(); \r
- break;\r
- }\r
- }\r
-\r
- /***************** TXFIFO Events ****************/\r
- async event void TXFIFO.readDone( uint8_t* tx_buf, uint8_t tx_len, \r
- error_t error ) {\r
- }\r
-\r
-\r
- async event void TXFIFO.writeDone( uint8_t* tx_buf, uint8_t tx_len,\r
- error_t error ) {\r
- call CSN.set();\r
-\r
- if ( m_state == S_CANCEL ) {\r
- m_state = S_STARTED;\r
- }\r
- else if ( !m_cca ) {\r
- m_state = S_BEGIN_TRANSMIT;\r
- attemptSend();\r
- }\r
- else {\r
- releaseSpiResource();\r
- m_state = S_SAMPLE_CCA;\r
- startBackoffTimer( signal CsmaBackoff.initial( m_msg ) + 1);\r
- }\r
- }\r
- \r
- /***************** Timer Events ****************/\r
- async event void BackoffTimer.fired() {\r
-\r
- atomic {\r
- switch( m_state ) { \r
- case S_SAMPLE_CCA :\r
- // sample CCA and wait a little longer if free, just in case we\r
- // sampled during the ack turn-around window\r
- if ( call CCA.get() ) {\r
- m_state = S_BEGIN_TRANSMIT;\r
- startBackoffTimer( CC2420_TIME_ACK_TURNAROUND );\r
- }\r
- else {\r
- congestionBackoff();\r
- }\r
- break;\r
- \r
- case S_BEGIN_TRANSMIT :\r
- if ( acquireSpiResource() == SUCCESS )\r
- attemptSend();\r
- break;\r
- \r
- case S_ACK_WAIT :\r
- signalDone( SUCCESS );\r
- break;\r
- \r
-#ifdef PLATFORM_MICAZ\r
- case S_SFD:\r
- // We didn't receive an SFD interrupt within CC2420_ABORT_PERIOD\r
- // jiffies. Assume something is wrong.\r
- call SFLUSHTX.strobe();\r
- call CaptureSFD.disable();\r
- call CaptureSFD.captureRisingEdge();\r
- signalDone( ERETRY );\r
- break;\r
-#endif\r
- default:\r
- break;\r
- }\r
- }\r
- }\r
- \r
- \r
-#ifdef PLATFORM_MICAZ\r
- event void WatchdogTimer.fired() {\r
- atomic m_state = S_STARTED;\r
- releaseSpiResource();\r
- signalDone(ERETRY);\r
- }\r
-#endif\r
- \r
- \r
- /***************** Functions ****************/\r
- /**\r
- * Send a message with or without CCA\r
- */\r
- error_t send( message_t* p_msg, bool cca ) {\r
- atomic {\r
- if ( m_state != S_STARTED ) {\r
- return FAIL;\r
- }\r
- \r
- m_state = S_LOAD;\r
- m_cca = cca;\r
- m_msg = p_msg;\r
- }\r
-\r
-#ifdef PLATFORM_MICAZ\r
- post startWatchdogTimer();\r
-#endif\r
-\r
- if ( acquireSpiResource() == SUCCESS ) {\r
- loadTXFIFO();\r
- }\r
- // Else, we wait for the SpiResource.granted event..\r
- \r
- return SUCCESS;\r
- }\r
- \r
- /**\r
- * Resend a message with or without CCA\r
- */\r
- error_t resend( bool cca ) {\r
- atomic {\r
- if ( m_state != S_STARTED )\r
- return FAIL;\r
- m_cca = cca;\r
- m_state = cca ? S_SAMPLE_CCA : S_BEGIN_TRANSMIT;\r
- }\r
-\r
-#ifdef PLATFORM_MICAZ\r
- post startWatchdogTimer();\r
-#endif\r
-\r
- if ( m_cca ) {\r
- startBackoffTimer( signal CsmaBackoff.initial( m_msg ) );\r
- }\r
- else if ( acquireSpiResource() == SUCCESS ) {\r
- attemptSend();\r
- }\r
- \r
- return SUCCESS;\r
- }\r
- \r
- /**\r
- * Attempt to send a message\r
- */\r
- void attemptSend() {\r
- uint8_t status;\r
- bool congestion = TRUE;\r
-\r
- call CSN.clr();\r
-\r
- status = m_cca ? call STXONCCA.strobe() : call STXON.strobe();\r
- if ( !( status & CC2420_STATUS_TX_ACTIVE ) ) {\r
- status = call SNOP.strobe();\r
- if ( status & CC2420_STATUS_TX_ACTIVE )\r
- congestion = FALSE;\r
- }\r
- atomic m_state = congestion ? S_SAMPLE_CCA : S_SFD;\r
- \r
- call CSN.set();\r
-\r
- if ( congestion ) {\r
- releaseSpiResource();\r
- congestionBackoff();\r
- }\r
-#ifdef PLATFORM_MICAZ\r
- else {\r
- startBackoffTimer(CC2420_ABORT_PERIOD);\r
- }\r
-#endif\r
- }\r
- \r
- \r
- /**\r
- * Get the CC2420 message header\r
- */\r
- cc2420_header_t* getHeader( message_t* msg ) {\r
- return (cc2420_header_t*)( msg->data - sizeof( cc2420_header_t ) );\r
- }\r
-\r
- /**\r
- * Get the CC2420 message metadata\r
- */\r
- cc2420_metadata_t* getMetadata( message_t* msg ) {\r
- return (cc2420_metadata_t*)msg->metadata;\r
- }\r
- \r
-#ifdef PLATFORM_MICAZ\r
- /**\r
- * Start the watchdog timer\r
- */\r
- task void startWatchdogTimer() {\r
- call WatchdogTimer.startOneShot(50);\r
- }\r
- \r
- /**\r
- * Stop the watchdog timer\r
- */\r
- task void stopWatchdogTimer() {\r
- call WatchdogTimer.stop();\r
- }\r
-#endif\r
- \r
- /**\r
- * Start the backoff timer\r
- */\r
- void startBackoffTimer(uint16_t time) {\r
- call BackoffTimer.start(time);\r
- }\r
-\r
- /** \r
- * Stop the backoff timer\r
- */\r
- void stopBackoffTimer() {\r
- call BackoffTimer.stop();\r
- }\r
-\r
- /**\r
- * Acquire the SPI bus resource immediately, or defer it till later\r
- */\r
- error_t acquireSpiResource() {\r
- error_t error = call SpiResource.immediateRequest();\r
- if ( error != SUCCESS ) {\r
- call SpiResource.request();\r
- }\r
- return error;\r
- }\r
-\r
- /**\r
- * Release the SPI resource\r
- */\r
- void releaseSpiResource() {\r
- call SpiResource.release();\r
- }\r
-\r
- /**\r
- * Signal done\r
- */\r
- void signalDone( error_t err ) {\r
- atomic m_state = S_STARTED;\r
-\r
-#ifdef PLATFORM_MICAZ\r
- post stopWatchdogTimer();\r
-#endif\r
-\r
- signal Send.sendDone( m_msg, err );\r
- }\r
-\r
- /** \r
- * Congestion Backoff\r
- */\r
- void congestionBackoff() {\r
- atomic {\r
- startBackoffTimer(signal CsmaBackoff.congestion( m_msg ) + 1);\r
- }\r
- }\r
- \r
- /**\r
- * Load TX FIFO\r
- */\r
- void loadTXFIFO() {\r
- cc2420_header_t* header = getHeader( m_msg );\r
- uint8_t tx_power = getMetadata( m_msg )->tx_power;\r
- \r
- if ( !tx_power )\r
- tx_power = CC2420_DEF_RFPOWER;\r
- call CSN.clr();\r
- if ( m_tx_power != tx_power )\r
- call TXCTRL.write( ( 2 << CC2420_TXCTRL_TXMIXBUF_CUR ) |\r
- ( 3 << CC2420_TXCTRL_PA_CURRENT ) |\r
- ( 1 << CC2420_TXCTRL_RESERVED ) |\r
- ( tx_power << CC2420_TXCTRL_PA_LEVEL ) );\r
- m_tx_power = tx_power;\r
- call TXFIFO.write( (uint8_t*)header, header->length - 1 );\r
- }\r
- \r
- /***************** Defaults ****************/\r
- default async event void TimeStamp.transmittedSFD( uint16_t time, message_t* p_msg ) {}\r
- default async event void TimeStamp.receivedSFD( uint16_t time ) {}\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (c) 2005-2006 Arch Rock Corporation\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * - Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the\r
- * distribution.\r
- * - Neither the name of the Arch Rock Corporation nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE\r
- *\r
- * @author Jonathan Hui <jhui@archrock.com>\r
- * @version $Revision$ $Date$\r
- */\r
-\r
-#ifndef __IEEE802154_H__\r
-#define __IEEE802154_H__\r
-\r
-enum ieee154_fcf_enums {\r
- IEEE154_FCF_FRAME_TYPE = 0,\r
- IEEE154_FCF_SECURITY_ENABLED = 3,\r
- IEEE154_FCF_FRAME_PENDING = 4,\r
- IEEE154_FCF_ACK_REQ = 5,\r
- IEEE154_FCF_INTRAPAN = 6,\r
- IEEE154_FCF_DEST_ADDR_MODE = 10,\r
- IEEE154_FCF_SRC_ADDR_MODE = 14,\r
-};\r
-\r
-enum ieee154_fcf_type_enums {\r
- IEEE154_TYPE_BEACON = 0,\r
- IEEE154_TYPE_DATA = 1,\r
- IEEE154_TYPE_ACK = 2,\r
- IEEE154_TYPE_MAC_CMD = 3,\r
-};\r
-\r
-enum iee154_fcf_addr_mode_enums {\r
- IEEE154_ADDR_NONE = 0,\r
- IEEE154_ADDR_SHORT = 2,\r
- IEEE154_ADDR_EXT = 3,\r
-};\r
-\r
-#endif\r
+++ /dev/null
-/*
- * Copyright (c) 2005-2006 Rincon Research Corporation
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the
- * distribution.
- * - Neither the name of the Arch Rock Corporation nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE
- */
-
-/**
- * Low Power Listening interface
- *
- * @author David Moss
- * @author Jonathan Hui
- */
-
-interface LowPowerListening {
-
- /**
- * Set this this node's radio sleep interval, in milliseconds.
- * Once every interval, the node will sleep and perform an Rx check
- * on the radio. Setting the sleep interval to 0 will keep the radio
- * always on.
- *
- * This is the equivalent of setting the local duty cycle rate.
- *
- * @param sleepIntervalMs the length of this node's Rx check interval, in [ms]
- */
- command void setLocalSleepInterval(uint16_t sleepIntervalMs);
-
- /**
- * @return the local node's sleep interval, in [ms]
- */
- command uint16_t getLocalSleepInterval();
-
- /**
- * Set this node's radio duty cycle rate, in units of [percentage*100].
- * For example, to get a 0.05% duty cycle,
- * <code>
- * call LowPowerListening.setDutyCycle(5); // or equivalently...
- * call LowPowerListening.setDutyCycle(00005); // for better readability?
- * </code>
- *
- * For a 100% duty cycle (always on),
- * <code>
- * call LowPowerListening.setDutyCycle(10000);
- * </code>
- *
- * This is the equivalent of setting the local sleep interval explicitly.
- *
- * @param dutyCycle The duty cycle percentage, in units of [percentage*100]
- */
- command void setLocalDutyCycle(uint16_t dutyCycle);
-
- /**
- * @return this node's radio duty cycle rate, in units of [percentage*100]
- */
- command uint16_t getLocalDutyCycle();
-
-
- /**
- * Configure this outgoing message so it can be transmitted to a neighbor mote
- * with the specified Rx sleep interval.
- * @param msg Pointer to the message that will be sent
- * @param sleepInterval The receiving node's sleep interval, in [ms]
- */
- command void setRxSleepInterval(message_t *msg, uint16_t sleepIntervalMs);
-
- /**
- * @return the destination node's sleep interval configured in this message
- */
- command uint16_t getRxSleepInterval(message_t *msg);
-
- /**
- * Configure this outgoing message so it can be transmitted to a neighbor mote
- * with the specified Rx duty cycle rate.
- * Duty cycle is in units of [percentage*100], i.e. 0.25% duty cycle = 25.
- *
- * @param msg Pointer to the message that will be sent
- * @param dutyCycle The duty cycle of the receiving mote, in units of
- * [percentage*100]
- */
- command void setRxDutyCycle(message_t *msg, uint16_t dutyCycle);
-
- /**
- * @return the destination node's duty cycle configured in this message
- * in units of [percentage*100]
- */
- command uint16_t getRxDutyCycle(message_t *msg);
-
- /**
- * Convert a duty cycle, in units of [percentage*100], to
- * the sleep interval of the mote in milliseconds
- * @param dutyCycle The duty cycle in units of [percentage*100]
- * @return The equivalent sleep interval, in units of [ms]
- */
- command uint16_t dutyCycleToSleepInterval(uint16_t dutyCycle);
-
- /**
- * Convert a sleep interval, in units of [ms], to a duty cycle
- * in units of [percentage*100]
- * @param sleepInterval The sleep interval in units of [ms]
- * @return The duty cycle in units of [percentage*100]
- */
- command uint16_t sleepIntervalToDutyCycle(uint16_t sleepInterval);
-
-}