2007-03-15 22:26:00 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007, Swedish Institute of Computer Science
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. 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.
|
|
|
|
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE OR 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.
|
|
|
|
*
|
|
|
|
* This file is part of the Contiki operating system.
|
|
|
|
*
|
2010-03-09 16:45:29 +01:00
|
|
|
* @(#)$Id: cc2420.c,v 1.43 2010/03/09 15:45:29 joxe Exp $
|
2007-03-15 22:26:00 +01:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* This code is almost device independent and should be easy to port.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "contiki.h"
|
|
|
|
|
|
|
|
#if defined(__AVR__)
|
|
|
|
#include <avr/io.h>
|
|
|
|
#elif defined(__MSP430__)
|
|
|
|
#include <io.h>
|
|
|
|
#endif
|
|
|
|
|
2008-05-14 21:44:30 +02:00
|
|
|
#include "dev/leds.h"
|
2007-03-15 22:26:00 +01:00
|
|
|
#include "dev/spi.h"
|
2008-07-01 23:02:51 +02:00
|
|
|
#include "dev/cc2420.h"
|
2007-03-15 22:26:00 +01:00
|
|
|
#include "dev/cc2420_const.h"
|
|
|
|
|
2009-03-12 22:58:20 +01:00
|
|
|
#include "net/rime/packetbuf.h"
|
2007-05-22 22:51:30 +02:00
|
|
|
#include "net/rime/rimestats.h"
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
#include "net/netstack.h"
|
2007-05-22 22:51:30 +02:00
|
|
|
|
2008-01-23 15:57:19 +01:00
|
|
|
#include "sys/timetable.h"
|
|
|
|
|
|
|
|
#define WITH_SEND_CCA 0
|
2007-12-16 15:30:36 +01:00
|
|
|
|
2008-08-26 23:44:03 +02:00
|
|
|
#define FOOTER_LEN 2
|
2009-02-25 22:21:06 +01:00
|
|
|
|
|
|
|
#ifndef CC2420_CONF_CHECKSUM
|
|
|
|
#define CC2420_CONF_CHECKSUM 0
|
|
|
|
#endif /* CC2420_CONF_CHECKSUM */
|
|
|
|
|
2009-07-29 00:24:53 +02:00
|
|
|
#ifndef CC2420_CONF_AUTOACK
|
|
|
|
#define CC2420_CONF_AUTOACK 0
|
|
|
|
#endif /* CC2420_CONF_AUTOACK */
|
|
|
|
|
2009-02-25 22:21:06 +01:00
|
|
|
#if CC2420_CONF_CHECKSUM
|
|
|
|
#include "lib/crc16.h"
|
2008-08-26 23:44:03 +02:00
|
|
|
#define CHECKSUM_LEN 2
|
2009-02-25 22:21:06 +01:00
|
|
|
#else
|
|
|
|
#define CHECKSUM_LEN 0
|
|
|
|
#endif /* CC2420_CONF_CHECKSUM */
|
2008-08-26 23:44:03 +02:00
|
|
|
|
2010-02-23 19:24:49 +01:00
|
|
|
#define AUX_LEN (CHECKSUM_LEN + FOOTER_LEN)
|
2007-12-16 15:30:36 +01:00
|
|
|
|
|
|
|
|
2007-03-15 22:26:00 +01:00
|
|
|
#define FOOTER1_CRC_OK 0x80
|
|
|
|
#define FOOTER1_CORRELATION 0x7f
|
|
|
|
|
2007-05-15 09:53:09 +02:00
|
|
|
#define DEBUG 0
|
|
|
|
#if DEBUG
|
2007-03-15 22:26:00 +01:00
|
|
|
#define PRINTF(...) printf(__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define PRINTF(...) do {} while (0)
|
|
|
|
#endif
|
2007-05-25 10:06:15 +02:00
|
|
|
|
2008-07-02 11:05:40 +02:00
|
|
|
void cc2420_arch_init(void);
|
2007-05-25 10:06:15 +02:00
|
|
|
|
2007-12-16 15:30:36 +01:00
|
|
|
/* XXX hack: these will be made as Chameleon packet attributes */
|
2008-07-02 11:05:40 +02:00
|
|
|
rtimer_clock_t cc2420_time_of_arrival, cc2420_time_of_departure;
|
2007-12-16 15:30:36 +01:00
|
|
|
|
2008-07-02 11:05:40 +02:00
|
|
|
int cc2420_authority_level_of_sender;
|
2007-12-16 15:30:36 +01:00
|
|
|
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
int cc2420_packets_seen, cc2420_packets_read;
|
|
|
|
|
|
|
|
static uint8_t volatile pending;
|
|
|
|
|
2007-03-15 22:26:00 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2008-07-02 11:05:40 +02:00
|
|
|
PROCESS(cc2420_process, "CC2420 driver");
|
2007-03-15 22:26:00 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
2008-07-02 11:05:40 +02:00
|
|
|
int cc2420_on(void);
|
|
|
|
int cc2420_off(void);
|
2007-05-25 10:06:15 +02:00
|
|
|
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
static int cc2420_read(void *buf, unsigned short bufsize);
|
2007-05-25 10:06:15 +02:00
|
|
|
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
static int cc2420_prepare(const void *data, unsigned short len);
|
|
|
|
static int cc2420_transmit(unsigned short len);
|
|
|
|
static int cc2420_send(const void *data, unsigned short len);
|
2007-05-25 10:06:15 +02:00
|
|
|
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
static int cc2420_receiving_packet(void);
|
|
|
|
static int pending_packet(void);
|
|
|
|
static int cc2420_cca(void);
|
2007-05-25 10:06:15 +02:00
|
|
|
|
2008-07-02 11:05:40 +02:00
|
|
|
signed char cc2420_last_rssi;
|
|
|
|
uint8_t cc2420_last_correlation;
|
2007-03-15 22:26:00 +01:00
|
|
|
|
2008-07-02 11:05:40 +02:00
|
|
|
const struct radio_driver cc2420_driver =
|
2007-05-15 09:53:09 +02:00
|
|
|
{
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
cc2420_init,
|
|
|
|
cc2420_prepare,
|
|
|
|
cc2420_transmit,
|
2008-07-02 11:05:40 +02:00
|
|
|
cc2420_send,
|
|
|
|
cc2420_read,
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
cc2420_cca,
|
|
|
|
cc2420_receiving_packet,
|
|
|
|
pending_packet,
|
2008-07-02 11:05:40 +02:00
|
|
|
cc2420_on,
|
|
|
|
cc2420_off,
|
2007-05-15 09:53:09 +02:00
|
|
|
};
|
|
|
|
|
2008-01-23 15:57:19 +01:00
|
|
|
static uint8_t receive_on;
|
|
|
|
|
|
|
|
static int channel;
|
|
|
|
|
2008-08-26 23:44:03 +02:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static uint8_t rxptr; /* Pointer to the next byte in the rxfifo. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
getrxdata(void *buf, int len)
|
|
|
|
{
|
|
|
|
FASTSPI_READ_FIFO_NO_WAIT(buf, len);
|
|
|
|
rxptr = (rxptr + len) & 0x7f;
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
getrxbyte(uint8_t *byte)
|
|
|
|
{
|
|
|
|
FASTSPI_READ_FIFO_BYTE(*byte);
|
|
|
|
rxptr = (rxptr + 1) & 0x7f;
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
flushrx(void)
|
|
|
|
{
|
|
|
|
uint8_t dummy;
|
2009-08-19 14:00:04 +02:00
|
|
|
|
2008-08-26 23:44:03 +02:00
|
|
|
FASTSPI_READ_FIFO_BYTE(dummy);
|
|
|
|
FASTSPI_STROBE(CC2420_SFLUSHRX);
|
|
|
|
FASTSPI_STROBE(CC2420_SFLUSHRX);
|
|
|
|
rxptr = 0;
|
|
|
|
}
|
2007-03-15 22:26:00 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-05-15 09:53:09 +02:00
|
|
|
static void
|
|
|
|
strobe(enum cc2420_register regname)
|
2007-03-15 22:26:00 +01:00
|
|
|
{
|
2007-05-15 09:53:09 +02:00
|
|
|
FASTSPI_STROBE(regname);
|
2007-03-15 22:26:00 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-05-15 09:53:09 +02:00
|
|
|
static unsigned int
|
|
|
|
status(void)
|
2007-03-15 22:26:00 +01:00
|
|
|
{
|
2008-01-23 15:57:19 +01:00
|
|
|
uint8_t status;
|
2007-05-15 09:53:09 +02:00
|
|
|
FASTSPI_UPD_STATUS(status);
|
|
|
|
return status;
|
2007-03-15 22:26:00 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2008-08-26 23:44:03 +02:00
|
|
|
static uint8_t locked, lock_on, lock_off;
|
|
|
|
|
2007-03-15 22:26:00 +01:00
|
|
|
static void
|
2007-05-15 09:53:09 +02:00
|
|
|
on(void)
|
2007-03-15 22:26:00 +01:00
|
|
|
{
|
2007-10-25 11:30:39 +02:00
|
|
|
ENERGEST_ON(ENERGEST_TYPE_LISTEN);
|
2007-05-15 09:53:09 +02:00
|
|
|
PRINTF("on\n");
|
|
|
|
receive_on = 1;
|
2008-08-26 23:44:03 +02:00
|
|
|
|
2007-05-15 09:53:09 +02:00
|
|
|
ENABLE_FIFOP_INT();
|
2008-08-26 23:44:03 +02:00
|
|
|
strobe(CC2420_SRXON);
|
|
|
|
flushrx();
|
2007-05-15 09:53:09 +02:00
|
|
|
}
|
|
|
|
static void
|
|
|
|
off(void)
|
|
|
|
{
|
2010-02-23 19:24:49 +01:00
|
|
|
leds_on(LEDS_GREEN);
|
2007-05-15 09:53:09 +02:00
|
|
|
PRINTF("off\n");
|
|
|
|
receive_on = 0;
|
2009-08-19 14:00:04 +02:00
|
|
|
|
2007-05-15 09:53:09 +02:00
|
|
|
/* Wait for transmission to end before turning radio off. */
|
2010-02-23 19:24:49 +01:00
|
|
|
// while(status() & BV(CC2420_TX_ACTIVE));
|
2009-08-19 14:00:04 +02:00
|
|
|
|
2007-05-15 09:53:09 +02:00
|
|
|
strobe(CC2420_SRFOFF);
|
|
|
|
DISABLE_FIFOP_INT();
|
2007-10-25 11:30:39 +02:00
|
|
|
ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
|
2010-02-23 19:24:49 +01:00
|
|
|
leds_off(LEDS_GREEN);
|
2007-05-15 09:53:09 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
#define GET_LOCK() locked = 1
|
|
|
|
static void RELEASE_LOCK(void) {
|
|
|
|
if(lock_on) {
|
|
|
|
on();
|
|
|
|
lock_on = 0;
|
|
|
|
}
|
|
|
|
if(lock_off) {
|
|
|
|
off();
|
|
|
|
lock_off = 0;
|
|
|
|
}
|
|
|
|
locked = 0;
|
2007-03-15 22:26:00 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static unsigned
|
2007-05-15 09:53:09 +02:00
|
|
|
getreg(enum cc2420_register regname)
|
2007-03-15 22:26:00 +01:00
|
|
|
{
|
2007-05-15 09:53:09 +02:00
|
|
|
unsigned reg;
|
|
|
|
FASTSPI_GETREG(regname, reg);
|
|
|
|
return reg;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
setreg(enum cc2420_register regname, unsigned value)
|
|
|
|
{
|
|
|
|
FASTSPI_SETREG(regname, value);
|
2007-03-15 22:26:00 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2009-08-19 17:05:05 +02:00
|
|
|
static void
|
|
|
|
set_txpower(uint8_t power)
|
|
|
|
{
|
|
|
|
uint16_t reg;
|
|
|
|
|
|
|
|
reg = getreg(CC2420_TXCTRL);
|
|
|
|
reg = (reg & 0xffe0) | (power & 0x1f);
|
|
|
|
setreg(CC2420_TXCTRL, reg);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-03-15 22:26:00 +01:00
|
|
|
#define AUTOACK (1 << 4)
|
|
|
|
#define ADR_DECODE (1 << 11)
|
|
|
|
#define RXFIFO_PROTECTION (1 << 9)
|
|
|
|
#define CORR_THR(n) (((n) & 0x1f) << 6)
|
|
|
|
#define FIFOP_THR(n) ((n) & 0x7f)
|
|
|
|
#define RXBPF_LOCUR (1 << 13);
|
|
|
|
/*---------------------------------------------------------------------------*/
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
int
|
2008-07-02 11:05:40 +02:00
|
|
|
cc2420_init(void)
|
2007-03-15 22:26:00 +01:00
|
|
|
{
|
2008-01-23 15:57:19 +01:00
|
|
|
uint16_t reg;
|
2007-03-15 22:26:00 +01:00
|
|
|
{
|
|
|
|
int s = splhigh();
|
2008-07-02 11:05:40 +02:00
|
|
|
cc2420_arch_init(); /* Initalize ports and SPI. */
|
2007-03-15 22:26:00 +01:00
|
|
|
DISABLE_FIFOP_INT();
|
|
|
|
FIFOP_INT_INIT();
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Turn on voltage regulator and reset. */
|
|
|
|
SET_VREG_ACTIVE();
|
|
|
|
//clock_delay(250); OK
|
|
|
|
SET_RESET_ACTIVE();
|
|
|
|
clock_delay(127);
|
|
|
|
SET_RESET_INACTIVE();
|
|
|
|
//clock_delay(125); OK
|
|
|
|
|
|
|
|
|
|
|
|
/* Turn on the crystal oscillator. */
|
|
|
|
strobe(CC2420_SXOSCON);
|
|
|
|
|
2009-07-29 00:24:53 +02:00
|
|
|
/* Turn on/off automatic packet acknowledgment and address decoding. */
|
2007-03-15 22:26:00 +01:00
|
|
|
reg = getreg(CC2420_MDMCTRL0);
|
2010-02-23 19:24:49 +01:00
|
|
|
|
2009-07-29 00:24:53 +02:00
|
|
|
#if CC2420_CONF_AUTOACK
|
|
|
|
reg |= AUTOACK | ADR_DECODE;
|
|
|
|
#else
|
|
|
|
reg &= ~(AUTOACK | ADR_DECODE);
|
|
|
|
#endif /* CC2420_CONF_AUTOACK */
|
2007-03-15 22:26:00 +01:00
|
|
|
setreg(CC2420_MDMCTRL0, reg);
|
|
|
|
|
|
|
|
/* Change default values as recomended in the data sheet, */
|
|
|
|
/* correlation threshold = 20, RX bandpass filter = 1.3uA. */
|
|
|
|
setreg(CC2420_MDMCTRL1, CORR_THR(20));
|
|
|
|
reg = getreg(CC2420_RXCTRL1);
|
|
|
|
reg |= RXBPF_LOCUR;
|
|
|
|
setreg(CC2420_RXCTRL1, reg);
|
2009-08-19 14:00:04 +02:00
|
|
|
|
2007-03-15 22:26:00 +01:00
|
|
|
/* Set the FIFOP threshold to maximum. */
|
|
|
|
setreg(CC2420_IOCFG0, FIFOP_THR(127));
|
|
|
|
|
|
|
|
/* Turn off "Security enable" (page 32). */
|
|
|
|
reg = getreg(CC2420_SECCTRL0);
|
|
|
|
reg &= ~RXFIFO_PROTECTION;
|
|
|
|
setreg(CC2420_SECCTRL0, reg);
|
|
|
|
|
2008-07-02 11:05:40 +02:00
|
|
|
cc2420_set_pan_addr(0xffff, 0x0000, NULL);
|
|
|
|
cc2420_set_channel(26);
|
2007-03-15 22:26:00 +01:00
|
|
|
|
2008-07-02 11:05:40 +02:00
|
|
|
process_start(&cc2420_process, NULL);
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
return 1;
|
2007-03-15 22:26:00 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
static int
|
|
|
|
cc2420_transmit(unsigned short payload_len)
|
2007-03-15 22:26:00 +01:00
|
|
|
{
|
2009-08-19 17:05:05 +02:00
|
|
|
int i, txpower;
|
2007-12-16 15:30:36 +01:00
|
|
|
uint8_t total_len;
|
2009-02-25 22:21:06 +01:00
|
|
|
#if CC2420_CONF_CHECKSUM
|
2008-08-26 23:44:03 +02:00
|
|
|
uint16_t checksum;
|
2009-02-25 22:21:06 +01:00
|
|
|
#endif /* CC2420_CONF_CHECKSUM */
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
|
2007-05-15 09:53:09 +02:00
|
|
|
GET_LOCK();
|
2007-05-22 22:51:30 +02:00
|
|
|
|
2009-08-19 17:05:05 +02:00
|
|
|
txpower = 0;
|
2009-03-12 22:58:20 +01:00
|
|
|
if(packetbuf_attr(PACKETBUF_ATTR_RADIO_TXPOWER) > 0) {
|
2009-08-19 17:05:05 +02:00
|
|
|
/* Remember the current transmission power */
|
|
|
|
txpower = cc2420_get_txpower();
|
|
|
|
/* Set the specified transmission power */
|
|
|
|
set_txpower(packetbuf_attr(PACKETBUF_ATTR_RADIO_TXPOWER) - 1);
|
2009-03-11 21:38:53 +01:00
|
|
|
}
|
2009-08-19 14:00:04 +02:00
|
|
|
|
2008-08-26 23:44:03 +02:00
|
|
|
total_len = payload_len + AUX_LEN;
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
|
2008-01-23 15:57:19 +01:00
|
|
|
/* The TX FIFO can only hold one packet. Make sure to not overrun
|
2007-03-15 22:26:00 +01:00
|
|
|
* FIFO by waiting for transmission to start here and synchronizing
|
|
|
|
* with the CC2420_TX_ACTIVE check in cc2420_send.
|
|
|
|
*
|
|
|
|
* Note that we may have to wait up to 320 us (20 symbols) before
|
|
|
|
* transmission starts.
|
|
|
|
*/
|
|
|
|
#ifdef TMOTE_SKY
|
2009-04-29 13:38:50 +02:00
|
|
|
#define LOOP_20_SYMBOLS 400 /* 326us (msp430 @ 2.4576MHz) */
|
2007-03-15 22:26:00 +01:00
|
|
|
#elif __AVR__
|
|
|
|
#define LOOP_20_SYMBOLS 500 /* XXX */
|
|
|
|
#endif
|
2008-01-23 15:57:19 +01:00
|
|
|
|
|
|
|
#if WITH_SEND_CCA
|
|
|
|
strobe(CC2420_SRXON);
|
|
|
|
while(!(status() & BV(CC2420_RSSI_VALID)));
|
2007-03-15 22:26:00 +01:00
|
|
|
strobe(CC2420_STXONCCA);
|
2008-01-23 15:57:19 +01:00
|
|
|
#else /* WITH_SEND_CCA */
|
|
|
|
strobe(CC2420_STXON);
|
|
|
|
#endif /* WITH_SEND_CCA */
|
2009-08-19 14:00:04 +02:00
|
|
|
|
2007-03-15 22:26:00 +01:00
|
|
|
for(i = LOOP_20_SYMBOLS; i > 0; i--) {
|
|
|
|
if(SFD_IS_1) {
|
2010-02-23 19:24:49 +01:00
|
|
|
if(!(status() & BV(CC2420_TX_ACTIVE))) {
|
|
|
|
/* SFD went high but we are not transmitting. This means that
|
|
|
|
we just started receiving a packet, so we drop the
|
|
|
|
transmission. */
|
|
|
|
return RADIO_TX_ERR;
|
|
|
|
}
|
2008-05-14 21:44:30 +02:00
|
|
|
if(receive_on) {
|
|
|
|
ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
|
|
|
|
}
|
2007-09-18 12:36:31 +02:00
|
|
|
ENERGEST_ON(ENERGEST_TYPE_TRANSMIT);
|
2008-01-23 15:57:19 +01:00
|
|
|
|
2008-01-24 14:09:16 +01:00
|
|
|
/* We wait until transmission has ended so that we get an
|
|
|
|
accurate measurement of the transmission time.*/
|
2008-01-23 15:57:19 +01:00
|
|
|
while(status() & BV(CC2420_TX_ACTIVE));
|
|
|
|
|
|
|
|
#ifdef ENERGEST_CONF_LEVELDEVICE_LEVELS
|
2008-07-02 11:05:40 +02:00
|
|
|
ENERGEST_OFF_LEVEL(ENERGEST_TYPE_TRANSMIT,cc2420_get_txpower());
|
2008-01-15 09:33:02 +01:00
|
|
|
#endif
|
2007-05-15 09:53:09 +02:00
|
|
|
ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
|
2008-05-14 21:44:30 +02:00
|
|
|
if(receive_on) {
|
|
|
|
ENERGEST_ON(ENERGEST_TYPE_LISTEN);
|
2009-08-19 14:00:04 +02:00
|
|
|
} else {
|
2009-09-09 23:07:42 +02:00
|
|
|
/* We need to explicitly turn off the radio,
|
|
|
|
* since STXON[CCA] -> TX_ACTIVE -> RX_ACTIVE */
|
|
|
|
off();
|
2008-05-14 21:44:30 +02:00
|
|
|
}
|
2008-01-23 15:57:19 +01:00
|
|
|
|
2009-08-19 17:05:05 +02:00
|
|
|
if(packetbuf_attr(PACKETBUF_ATTR_RADIO_TXPOWER) > 0) {
|
|
|
|
/* Restore the transmission power */
|
|
|
|
set_txpower(txpower & 0xff);
|
|
|
|
}
|
|
|
|
|
2007-10-25 15:29:21 +02:00
|
|
|
RELEASE_LOCK();
|
2010-02-23 19:24:49 +01:00
|
|
|
return RADIO_TX_OK;
|
2007-03-15 22:26:00 +01:00
|
|
|
}
|
|
|
|
}
|
2009-08-19 14:00:04 +02:00
|
|
|
|
2008-01-23 15:57:19 +01:00
|
|
|
/* If we are using WITH_SEND_CCA, we get here if the packet wasn't
|
|
|
|
transmitted because of other channel activity. */
|
2007-11-12 23:26:03 +01:00
|
|
|
RIMESTATS_ADD(contentiondrop);
|
2008-07-02 11:05:40 +02:00
|
|
|
PRINTF("cc2420: do_send() transmission never started\n");
|
2009-08-19 17:05:05 +02:00
|
|
|
|
|
|
|
if(packetbuf_attr(PACKETBUF_ATTR_RADIO_TXPOWER) > 0) {
|
|
|
|
/* Restore the transmission power */
|
|
|
|
set_txpower(txpower & 0xff);
|
|
|
|
}
|
|
|
|
|
2007-05-15 09:53:09 +02:00
|
|
|
RELEASE_LOCK();
|
2010-02-23 19:24:49 +01:00
|
|
|
return RADIO_TX_ERR; /* Transmission never started! */
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static int
|
|
|
|
cc2420_prepare(const void *payload, unsigned short payload_len)
|
|
|
|
{
|
|
|
|
uint8_t total_len;
|
|
|
|
#if CC2420_CONF_CHECKSUM
|
|
|
|
uint16_t checksum;
|
|
|
|
#endif /* CC2420_CONF_CHECKSUM */
|
|
|
|
GET_LOCK();
|
|
|
|
|
|
|
|
PRINTF("cc2420: sending %d bytes\n", payload_len);
|
|
|
|
|
|
|
|
RIMESTATS_ADD(lltx);
|
|
|
|
|
|
|
|
/* Wait for any previous transmission to finish. */
|
2010-02-23 19:24:49 +01:00
|
|
|
/* while(status() & BV(CC2420_TX_ACTIVE));*/
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
|
|
|
|
/* Write packet to TX FIFO. */
|
|
|
|
strobe(CC2420_SFLUSHTX);
|
|
|
|
|
|
|
|
#if CC2420_CONF_CHECKSUM
|
|
|
|
checksum = crc16_data(payload, payload_len, 0);
|
|
|
|
#endif /* CC2420_CONF_CHECKSUM */
|
|
|
|
total_len = payload_len + AUX_LEN;
|
|
|
|
FASTSPI_WRITE_FIFO(&total_len, 1);
|
|
|
|
FASTSPI_WRITE_FIFO(payload, payload_len);
|
|
|
|
#if CC2420_CONF_CHECKSUM
|
|
|
|
FASTSPI_WRITE_FIFO(&checksum, CHECKSUM_LEN);
|
|
|
|
#endif /* CC2420_CONF_CHECKSUM */
|
|
|
|
|
|
|
|
RELEASE_LOCK();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static int
|
|
|
|
cc2420_send(const void *payload, unsigned short payload_len)
|
|
|
|
{
|
|
|
|
cc2420_prepare(payload, payload_len);
|
|
|
|
return cc2420_transmit(payload_len);
|
2007-03-15 22:26:00 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-05-15 09:53:09 +02:00
|
|
|
int
|
2008-07-02 11:05:40 +02:00
|
|
|
cc2420_off(void)
|
2007-03-15 22:26:00 +01:00
|
|
|
{
|
2008-08-26 23:44:03 +02:00
|
|
|
/* Don't do anything if we are already turned off. */
|
2007-04-03 21:05:44 +02:00
|
|
|
if(receive_on == 0) {
|
2007-05-15 09:53:09 +02:00
|
|
|
return 1;
|
2007-04-03 21:05:44 +02:00
|
|
|
}
|
2007-03-15 22:26:00 +01:00
|
|
|
|
2008-08-26 23:44:03 +02:00
|
|
|
/* If we are called when the driver is locked, we indicate that the
|
|
|
|
radio should be turned off when the lock is unlocked. */
|
2007-05-15 09:53:09 +02:00
|
|
|
if(locked) {
|
|
|
|
lock_off = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-08-26 23:44:03 +02:00
|
|
|
/* If we are currently receiving a packet (indicated by SFD == 1),
|
|
|
|
we don't actually switch the radio off now, but signal that the
|
|
|
|
driver should switch off the radio once the packet has been
|
|
|
|
received and processed, by setting the 'lock_off' variable. */
|
2010-02-23 19:24:49 +01:00
|
|
|
if(status() & BV(CC2420_TX_ACTIVE)) {
|
2007-05-15 09:53:09 +02:00
|
|
|
lock_off = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
2009-08-19 14:00:04 +02:00
|
|
|
|
2007-05-15 09:53:09 +02:00
|
|
|
off();
|
|
|
|
return 1;
|
2007-03-15 22:26:00 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-05-15 09:53:09 +02:00
|
|
|
int
|
2008-07-02 11:05:40 +02:00
|
|
|
cc2420_on(void)
|
2007-03-15 22:26:00 +01:00
|
|
|
{
|
|
|
|
if(receive_on) {
|
2007-05-15 09:53:09 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if(locked) {
|
|
|
|
lock_on = 1;
|
|
|
|
return 1;
|
2007-03-15 22:26:00 +01:00
|
|
|
}
|
|
|
|
|
2007-05-15 09:53:09 +02:00
|
|
|
on();
|
|
|
|
return 1;
|
2007-03-15 22:26:00 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2008-01-23 15:57:19 +01:00
|
|
|
int
|
2008-07-02 11:05:40 +02:00
|
|
|
cc2420_get_channel(void)
|
2008-01-23 15:57:19 +01:00
|
|
|
{
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-03-15 22:26:00 +01:00
|
|
|
void
|
2008-07-02 11:05:40 +02:00
|
|
|
cc2420_set_channel(int c)
|
2007-12-05 14:21:05 +01:00
|
|
|
{
|
2008-01-23 15:57:19 +01:00
|
|
|
uint16_t f;
|
|
|
|
/*
|
|
|
|
* Subtract the base channel (11), multiply by 5, which is the
|
|
|
|
* channel spacing. 357 is 2405-2048 and 0x4000 is LOCK_THR = 1.
|
|
|
|
*/
|
|
|
|
|
|
|
|
channel = c;
|
2009-08-19 14:00:04 +02:00
|
|
|
|
2008-01-23 15:57:19 +01:00
|
|
|
f = 5 * (c - 11) + 357 + 0x4000;
|
2007-12-05 14:21:05 +01:00
|
|
|
/*
|
|
|
|
* Writing RAM requires crystal oscillator to be stable.
|
|
|
|
*/
|
|
|
|
while(!(status() & (BV(CC2420_XOSC16M_STABLE))));
|
2008-01-24 14:09:16 +01:00
|
|
|
|
|
|
|
/* Wait for any transmission to end. */
|
|
|
|
while(status() & BV(CC2420_TX_ACTIVE));
|
|
|
|
|
2007-12-05 14:21:05 +01:00
|
|
|
setreg(CC2420_FSCTRL, f);
|
2008-01-24 14:09:16 +01:00
|
|
|
|
|
|
|
/* If we are in receive mode, we issue an SRXON command to ensure
|
|
|
|
that the VCO is calibrated. */
|
|
|
|
if(receive_on) {
|
|
|
|
strobe(CC2420_SRXON);
|
|
|
|
}
|
|
|
|
|
2007-12-05 14:21:05 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2008-07-02 11:05:40 +02:00
|
|
|
cc2420_set_pan_addr(unsigned pan,
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
unsigned addr,
|
|
|
|
const uint8_t *ieee_addr)
|
2007-03-15 22:26:00 +01:00
|
|
|
{
|
2008-01-23 15:57:19 +01:00
|
|
|
uint16_t f = 0;
|
2010-03-09 16:45:29 +01:00
|
|
|
uint8_t tmp[2];
|
2007-03-15 22:26:00 +01:00
|
|
|
/*
|
|
|
|
* Writing RAM requires crystal oscillator to be stable.
|
|
|
|
*/
|
2008-01-23 15:57:19 +01:00
|
|
|
while(!(status() & (BV(CC2420_XOSC16M_STABLE))));
|
2007-03-15 22:26:00 +01:00
|
|
|
|
2010-03-09 16:45:29 +01:00
|
|
|
tmp[0] = pan & 0xff;
|
|
|
|
tmp[1] = pan >> 8;
|
|
|
|
FASTSPI_WRITE_RAM_LE(&tmp, CC2420RAM_PANID, 2, f);
|
|
|
|
|
|
|
|
tmp[0] = addr & 0xff;
|
|
|
|
tmp[1] = addr >> 8;
|
|
|
|
FASTSPI_WRITE_RAM_LE(&tmp, CC2420RAM_SHORTADDR, 2, f);
|
2007-03-15 22:26:00 +01:00
|
|
|
if(ieee_addr != NULL) {
|
2010-03-09 16:45:29 +01:00
|
|
|
uint8_t tmp_addr[8];
|
2009-07-29 00:24:53 +02:00
|
|
|
/* LSB first, MSB last for 802.15.4 addresses in CC2420 */
|
|
|
|
for (f = 0; f < 8; f++) {
|
2010-03-09 16:45:29 +01:00
|
|
|
tmp_addr[7 - f] = ieee_addr[f];
|
2009-07-29 00:24:53 +02:00
|
|
|
}
|
2010-03-09 16:45:29 +01:00
|
|
|
FASTSPI_WRITE_RAM_LE(tmp_addr, CC2420RAM_IEEEADDR, 8, f);
|
2007-03-15 22:26:00 +01:00
|
|
|
}
|
2007-04-03 21:05:44 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-03-15 22:26:00 +01:00
|
|
|
/*
|
2008-08-26 23:44:03 +02:00
|
|
|
* Interrupt leaves frame intact in FIFO.
|
2007-03-15 22:26:00 +01:00
|
|
|
*/
|
2008-07-02 11:05:40 +02:00
|
|
|
#if CC2420_TIMETABLE_PROFILING
|
|
|
|
#define cc2420_timetable_size 16
|
|
|
|
TIMETABLE(cc2420_timetable);
|
2008-01-23 15:57:19 +01:00
|
|
|
TIMETABLE_AGGREGATE(aggregate_time, 10);
|
2008-07-02 11:05:40 +02:00
|
|
|
#endif /* CC2420_TIMETABLE_PROFILING */
|
2007-03-15 22:26:00 +01:00
|
|
|
int
|
2008-07-02 11:05:40 +02:00
|
|
|
cc2420_interrupt(void)
|
2007-03-15 22:26:00 +01:00
|
|
|
{
|
|
|
|
CLEAR_FIFOP_INT();
|
2008-07-02 11:05:40 +02:00
|
|
|
process_poll(&cc2420_process);
|
|
|
|
#if CC2420_TIMETABLE_PROFILING
|
|
|
|
timetable_clear(&cc2420_timetable);
|
|
|
|
TIMETABLE_TIMESTAMP(cc2420_timetable, "interrupt");
|
|
|
|
#endif /* CC2420_TIMETABLE_PROFILING */
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
|
|
|
|
pending = 1;
|
|
|
|
|
|
|
|
cc2420_packets_seen++;
|
2007-03-15 22:26:00 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2008-07-02 11:05:40 +02:00
|
|
|
PROCESS_THREAD(cc2420_process, ev, data)
|
2007-03-15 22:26:00 +01:00
|
|
|
{
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
int len;
|
2007-03-15 22:26:00 +01:00
|
|
|
PROCESS_BEGIN();
|
|
|
|
|
2008-07-02 11:05:40 +02:00
|
|
|
PRINTF("cc2420_process: started\n");
|
2009-08-19 14:00:04 +02:00
|
|
|
|
2007-03-15 22:26:00 +01:00
|
|
|
while(1) {
|
2007-05-15 09:53:09 +02:00
|
|
|
PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
|
2008-07-02 11:05:40 +02:00
|
|
|
#if CC2420_TIMETABLE_PROFILING
|
|
|
|
TIMETABLE_TIMESTAMP(cc2420_timetable, "poll");
|
|
|
|
#endif /* CC2420_TIMETABLE_PROFILING */
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
|
|
|
|
PRINTF("cc2420_process: calling receiver callback\n");
|
|
|
|
|
|
|
|
packetbuf_clear();
|
|
|
|
len = cc2420_read(packetbuf_dataptr(), PACKETBUF_SIZE);
|
|
|
|
if(len > 0) {
|
|
|
|
packetbuf_set_datalen(len);
|
|
|
|
NETSTACK_RDC.input();
|
2008-07-02 11:05:40 +02:00
|
|
|
#if CC2420_TIMETABLE_PROFILING
|
|
|
|
TIMETABLE_TIMESTAMP(cc2420_timetable, "end");
|
2008-01-23 15:57:19 +01:00
|
|
|
timetable_aggregate_compute_detailed(&aggregate_time,
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
&cc2420_timetable);
|
2008-07-02 11:05:40 +02:00
|
|
|
timetable_clear(&cc2420_timetable);
|
|
|
|
#endif /* CC2420_TIMETABLE_PROFILING */
|
2007-03-15 22:26:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PROCESS_END();
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
static int
|
2008-07-02 11:05:40 +02:00
|
|
|
cc2420_read(void *buf, unsigned short bufsize)
|
2007-03-15 22:26:00 +01:00
|
|
|
{
|
2008-01-23 15:57:19 +01:00
|
|
|
uint8_t footer[2];
|
2008-08-26 23:44:03 +02:00
|
|
|
uint8_t len;
|
2009-02-25 22:21:06 +01:00
|
|
|
#if CC2420_CONF_CHECKSUM
|
2008-08-26 23:44:03 +02:00
|
|
|
uint16_t checksum;
|
2009-02-25 22:21:06 +01:00
|
|
|
#endif /* CC2420_CONF_CHECKSUM */
|
2009-08-19 14:00:04 +02:00
|
|
|
|
2010-02-25 17:06:44 +01:00
|
|
|
pending = 0;
|
|
|
|
|
2010-01-15 00:32:05 +01:00
|
|
|
if(!FIFOP_IS_1) {
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
/* If FIFOP is 0, there is no packet in the RXFIFO. */
|
2007-05-15 09:53:09 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2009-08-19 14:00:04 +02:00
|
|
|
|
2007-05-15 09:53:09 +02:00
|
|
|
GET_LOCK();
|
2010-02-25 17:06:44 +01:00
|
|
|
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
cc2420_packets_read++;
|
|
|
|
|
2008-08-26 23:44:03 +02:00
|
|
|
getrxbyte(&len);
|
2007-05-15 09:53:09 +02:00
|
|
|
|
2008-07-02 11:05:40 +02:00
|
|
|
if(len > CC2420_MAX_PACKET_LEN) {
|
2007-05-15 09:53:09 +02:00
|
|
|
/* Oops, we must be out of sync. */
|
2008-08-26 23:44:03 +02:00
|
|
|
flushrx();
|
2007-05-22 22:51:30 +02:00
|
|
|
RIMESTATS_ADD(badsynch);
|
2007-05-15 09:53:09 +02:00
|
|
|
RELEASE_LOCK();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-26 23:44:03 +02:00
|
|
|
if(len <= AUX_LEN) {
|
|
|
|
flushrx();
|
|
|
|
RIMESTATS_ADD(tooshort);
|
|
|
|
RELEASE_LOCK();
|
|
|
|
return 0;
|
|
|
|
}
|
2009-08-19 14:00:04 +02:00
|
|
|
|
2008-08-26 23:44:03 +02:00
|
|
|
if(len - AUX_LEN > bufsize) {
|
|
|
|
flushrx();
|
|
|
|
RIMESTATS_ADD(toolong);
|
|
|
|
RELEASE_LOCK();
|
|
|
|
return 0;
|
|
|
|
}
|
2008-01-07 15:08:02 +01:00
|
|
|
|
2008-08-26 23:44:03 +02:00
|
|
|
getrxdata(buf, len - AUX_LEN);
|
2009-02-25 22:21:06 +01:00
|
|
|
#if CC2420_CONF_CHECKSUM
|
2008-08-26 23:44:03 +02:00
|
|
|
getrxdata(&checksum, CHECKSUM_LEN);
|
2009-02-25 22:21:06 +01:00
|
|
|
#endif /* CC2420_CONF_CHECKSUM */
|
2008-08-26 23:44:03 +02:00
|
|
|
getrxdata(footer, FOOTER_LEN);
|
2009-08-19 14:00:04 +02:00
|
|
|
|
2009-02-25 22:21:06 +01:00
|
|
|
#if CC2420_CONF_CHECKSUM
|
2009-04-29 13:38:50 +02:00
|
|
|
if(checksum != crc16_data(buf, len - AUX_LEN, 0)) {
|
|
|
|
PRINTF("checksum failed 0x%04x != 0x%04x\n",
|
|
|
|
checksum, crc16_data(buf, len - AUX_LEN, 0));
|
|
|
|
}
|
2009-08-19 14:00:04 +02:00
|
|
|
|
2008-08-26 23:44:03 +02:00
|
|
|
if(footer[1] & FOOTER1_CRC_OK &&
|
|
|
|
checksum == crc16_data(buf, len - AUX_LEN, 0)) {
|
2009-02-25 22:21:06 +01:00
|
|
|
#else
|
|
|
|
if(footer[1] & FOOTER1_CRC_OK) {
|
|
|
|
#endif /* CC2420_CONF_CHECKSUM */
|
2008-08-26 23:44:03 +02:00
|
|
|
cc2420_last_rssi = footer[0];
|
|
|
|
cc2420_last_correlation = footer[1] & FOOTER1_CORRELATION;
|
2009-03-02 22:59:01 +01:00
|
|
|
|
|
|
|
|
2009-03-12 22:58:20 +01:00
|
|
|
packetbuf_set_attr(PACKETBUF_ATTR_RSSI, cc2420_last_rssi);
|
|
|
|
packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, cc2420_last_correlation);
|
2009-08-19 14:00:04 +02:00
|
|
|
|
2008-08-26 23:44:03 +02:00
|
|
|
RIMESTATS_ADD(llrx);
|
2009-08-19 14:00:04 +02:00
|
|
|
|
2008-08-26 23:44:03 +02:00
|
|
|
} else {
|
|
|
|
RIMESTATS_ADD(badcrc);
|
|
|
|
len = AUX_LEN;
|
2007-03-15 22:26:00 +01:00
|
|
|
}
|
2009-08-19 14:00:04 +02:00
|
|
|
|
2007-03-15 22:26:00 +01:00
|
|
|
/* Clean up in case of FIFO overflow! This happens for every full
|
|
|
|
* length frame and is signaled by FIFOP = 1 and FIFO = 0.
|
|
|
|
*/
|
|
|
|
if(FIFOP_IS_1 && !FIFO_IS_1) {
|
2008-07-02 11:05:40 +02:00
|
|
|
/* printf("cc2420_read: FIFOP_IS_1 1\n");*/
|
2008-08-26 23:44:03 +02:00
|
|
|
flushrx();
|
2010-01-15 00:32:05 +01:00
|
|
|
} else if(FIFOP_IS_1) {
|
2007-05-15 09:53:09 +02:00
|
|
|
/* Another packet has been received and needs attention. */
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
/* printf("attention\n");*/
|
2008-07-02 11:05:40 +02:00
|
|
|
process_poll(&cc2420_process);
|
2007-03-15 22:26:00 +01:00
|
|
|
}
|
2009-08-19 14:00:04 +02:00
|
|
|
|
2007-05-15 09:53:09 +02:00
|
|
|
RELEASE_LOCK();
|
2009-08-19 14:00:04 +02:00
|
|
|
|
2008-08-26 23:44:03 +02:00
|
|
|
if(len < AUX_LEN) {
|
2007-05-15 09:53:09 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-26 23:44:03 +02:00
|
|
|
return len - AUX_LEN;
|
2007-05-15 09:53:09 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2008-07-02 11:05:40 +02:00
|
|
|
cc2420_set_txpower(uint8_t power)
|
2007-05-15 09:53:09 +02:00
|
|
|
{
|
|
|
|
GET_LOCK();
|
2009-08-19 17:05:05 +02:00
|
|
|
set_txpower(power);
|
2007-05-15 09:53:09 +02:00
|
|
|
RELEASE_LOCK();
|
2007-03-15 22:26:00 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-12-05 14:21:05 +01:00
|
|
|
int
|
2008-07-02 11:05:40 +02:00
|
|
|
cc2420_get_txpower(void)
|
2008-01-14 17:19:25 +01:00
|
|
|
{
|
|
|
|
return (int)(getreg(CC2420_TXCTRL) & 0x001f);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
int
|
2008-07-02 11:05:40 +02:00
|
|
|
cc2420_rssi(void)
|
2007-12-05 14:21:05 +01:00
|
|
|
{
|
|
|
|
int rssi;
|
|
|
|
int radio_was_off = 0;
|
2009-08-19 14:00:04 +02:00
|
|
|
|
2007-12-05 14:21:05 +01:00
|
|
|
if(!receive_on) {
|
|
|
|
radio_was_off = 1;
|
2008-07-02 11:05:40 +02:00
|
|
|
cc2420_on();
|
2007-12-05 14:21:05 +01:00
|
|
|
}
|
|
|
|
while(!(status() & BV(CC2420_RSSI_VALID))) {
|
2008-07-02 11:05:40 +02:00
|
|
|
/* printf("cc2420_rssi: RSSI not valid.\n");*/
|
2007-12-05 14:21:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
rssi = (int)((signed char)getreg(CC2420_RSSI));
|
|
|
|
|
|
|
|
if(radio_was_off) {
|
2008-07-02 11:05:40 +02:00
|
|
|
cc2420_off();
|
2007-12-05 14:21:05 +01:00
|
|
|
}
|
|
|
|
return rssi;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-02-23 19:24:49 +01:00
|
|
|
int
|
|
|
|
cc2420_cca_valid(void)
|
|
|
|
{
|
|
|
|
return !!(status() & BV(CC2420_RSSI_VALID));
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
static int
|
|
|
|
cc2420_cca(void)
|
|
|
|
{
|
|
|
|
int cca;
|
|
|
|
int radio_was_off = 0;
|
|
|
|
|
|
|
|
/* If the radio is locked by an underlying thread (because we are
|
|
|
|
being invoked through an interrupt), we preted that the coast is
|
|
|
|
clear (i.e., no packet is currently being transmitted by a
|
|
|
|
neighbor). */
|
|
|
|
if(locked) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!receive_on) {
|
|
|
|
radio_was_off = 1;
|
|
|
|
cc2420_on();
|
|
|
|
}
|
2010-02-23 19:24:49 +01:00
|
|
|
|
2010-03-09 14:18:16 +01:00
|
|
|
/* Make sure that the radio really got turned on. */
|
|
|
|
if(!receive_on) {
|
|
|
|
return 1;
|
|
|
|
}
|
2010-02-23 19:24:49 +01:00
|
|
|
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
while(!(status() & BV(CC2420_RSSI_VALID))) {
|
|
|
|
/* printf("cc2420_rssi: RSSI not valid.\n"); */
|
|
|
|
}
|
|
|
|
|
|
|
|
cca = CCA_IS_1;
|
|
|
|
|
|
|
|
if(radio_was_off) {
|
|
|
|
cc2420_off();
|
|
|
|
}
|
|
|
|
return cca;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
int
|
|
|
|
cc2420_receiving_packet(void)
|
|
|
|
{
|
|
|
|
return SFD_IS_1;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static int
|
|
|
|
pending_packet(void)
|
|
|
|
{
|
|
|
|
return pending;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
cc2420_ugly_hack_send_only_one_symbol(void)
|
|
|
|
{
|
|
|
|
uint8_t len;
|
|
|
|
GET_LOCK();
|
|
|
|
|
|
|
|
/* Write packet to TX FIFO. */
|
|
|
|
strobe(CC2420_SFLUSHTX);
|
|
|
|
|
|
|
|
len = 1;
|
|
|
|
FASTSPI_WRITE_FIFO(&len, 1);
|
|
|
|
FASTSPI_WRITE_FIFO(&len, 1);
|
|
|
|
|
|
|
|
strobe(CC2420_STXON);
|
|
|
|
while(!SFD_IS_1);
|
|
|
|
|
|
|
|
/* Turn radio off immediately after sending the first symbol. */
|
|
|
|
strobe(CC2420_SRFOFF);
|
|
|
|
RELEASE_LOCK();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-02-23 19:24:49 +01:00
|
|
|
void
|
|
|
|
cc2420_set_cca_threshold(int value)
|
|
|
|
{
|
|
|
|
uint16_t shifted = value << 8;
|
|
|
|
setreg(CC2420_RSSI, shifted);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|