2007-03-15 21:26:00 +00: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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* This code is almost device independent and should be easy to port.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "contiki.h"
|
|
|
|
|
2008-05-14 19:44:30 +00:00
|
|
|
#include "dev/leds.h"
|
2007-03-15 21:26:00 +00:00
|
|
|
#include "dev/spi.h"
|
2013-11-28 13:04:34 +00:00
|
|
|
#include "cc2420.h"
|
|
|
|
#include "cc2420_const.h"
|
2007-03-15 21:26:00 +00:00
|
|
|
|
2010-06-14 19:19:16 +00:00
|
|
|
#include "net/packetbuf.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 21:48:39 +00:00
|
|
|
#include "net/netstack.h"
|
2007-05-22 20:51:30 +00:00
|
|
|
|
2014-02-09 22:16:48 +00:00
|
|
|
enum write_ram_order {
|
|
|
|
/* Begin with writing the first given byte */
|
|
|
|
WRITE_RAM_IN_ORDER,
|
|
|
|
/* Begin with writing the last given byte */
|
|
|
|
WRITE_RAM_REVERSE
|
|
|
|
};
|
|
|
|
|
2007-05-15 07:53:09 +00:00
|
|
|
#define DEBUG 0
|
|
|
|
#if DEBUG
|
2010-06-30 09:03:20 +00:00
|
|
|
#include <stdio.h>
|
2007-03-15 21:26:00 +00:00
|
|
|
#define PRINTF(...) printf(__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define PRINTF(...) do {} while (0)
|
|
|
|
#endif
|
2007-05-25 08:06:15 +00:00
|
|
|
|
2010-04-20 11:41:16 +00:00
|
|
|
#define DEBUG_LEDS DEBUG
|
|
|
|
#undef LEDS_ON
|
|
|
|
#undef LEDS_OFF
|
|
|
|
#if DEBUG_LEDS
|
|
|
|
#define LEDS_ON(x) leds_on(x)
|
|
|
|
#define LEDS_OFF(x) leds_off(x)
|
|
|
|
#else
|
|
|
|
#define LEDS_ON(x)
|
|
|
|
#define LEDS_OFF(x)
|
|
|
|
#endif
|
|
|
|
|
2014-04-07 13:42:39 +00:00
|
|
|
/* Conversion map between PA_LEVEL and output power in dBm
|
|
|
|
(from table 9 in CC2420 specification).
|
|
|
|
*/
|
|
|
|
struct output_config {
|
|
|
|
int8_t power;
|
|
|
|
uint8_t config;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct output_config output_power[] = {
|
|
|
|
{ 0, 31 }, /* 0xff */
|
|
|
|
{ -1, 27 }, /* 0xfb */
|
|
|
|
{ -3, 23 }, /* 0xf7 */
|
|
|
|
{ -5, 19 }, /* 0xf3 */
|
|
|
|
{ -7, 15 }, /* 0xef */
|
|
|
|
{-10, 11 }, /* 0xeb */
|
|
|
|
{-15, 7 }, /* 0xe7 */
|
|
|
|
{-25, 3 }, /* 0xe3 */
|
|
|
|
};
|
|
|
|
#define OUTPUT_NUM (sizeof(output_power) / sizeof(struct output_config))
|
|
|
|
#define OUTPUT_POWER_MAX 0
|
|
|
|
#define OUTPUT_POWER_MIN -25
|
|
|
|
|
2008-07-02 09:05:40 +00:00
|
|
|
void cc2420_arch_init(void);
|
2007-05-25 08:06:15 +00:00
|
|
|
|
2007-12-16 14:30:36 +00:00
|
|
|
/* XXX hack: these will be made as Chameleon packet attributes */
|
2008-07-02 09:05:40 +00:00
|
|
|
rtimer_clock_t cc2420_time_of_arrival, cc2420_time_of_departure;
|
2007-12-16 14:30:36 +00:00
|
|
|
|
2008-07-02 09:05:40 +00:00
|
|
|
int cc2420_authority_level_of_sender;
|
2007-12-16 14:30:36 +00:00
|
|
|
|
2010-12-16 22:40:52 +00:00
|
|
|
volatile uint8_t cc2420_sfd_counter;
|
|
|
|
volatile uint16_t cc2420_sfd_start_time;
|
|
|
|
volatile uint16_t cc2420_sfd_end_time;
|
|
|
|
|
|
|
|
static volatile uint16_t last_packet_timestamp;
|
2007-03-15 21:26:00 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2008-07-02 09:05:40 +00:00
|
|
|
PROCESS(cc2420_process, "CC2420 driver");
|
2007-03-15 21:26:00 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
|
2015-09-21 20:03:51 +00:00
|
|
|
#define AUTOACK (1 << 4)
|
|
|
|
#define AUTOCRC (1 << 5)
|
|
|
|
#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);
|
2007-03-15 21:26:00 +00:00
|
|
|
|
2008-07-02 09:05:40 +00:00
|
|
|
int cc2420_on(void);
|
|
|
|
int cc2420_off(void);
|
2007-05-25 08:06:15 +00: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 21:48:39 +00:00
|
|
|
static int cc2420_read(void *buf, unsigned short bufsize);
|
2007-05-25 08:06:15 +00: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 21:48:39 +00: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 08:06:15 +00: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 21:48:39 +00:00
|
|
|
static int cc2420_receiving_packet(void);
|
|
|
|
static int pending_packet(void);
|
2015-02-19 10:26:43 +00:00
|
|
|
static int get_cca_threshold(void);
|
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 21:48:39 +00:00
|
|
|
static int cc2420_cca(void);
|
2015-09-21 20:03:51 +00:00
|
|
|
static uint16_t getreg(enum cc2420_register regname);
|
|
|
|
|
|
|
|
static void set_frame_filtering(uint8_t enable);
|
|
|
|
static void set_poll_mode(uint8_t enable);
|
|
|
|
static void set_send_on_cca(uint8_t enable);
|
|
|
|
static void set_auto_ack(uint8_t enable);
|
2007-05-25 08:06:15 +00:00
|
|
|
|
2008-07-02 09:05:40 +00:00
|
|
|
signed char cc2420_last_rssi;
|
|
|
|
uint8_t cc2420_last_correlation;
|
2007-03-15 21:26:00 +00:00
|
|
|
|
2014-04-01 13:22:17 +00:00
|
|
|
static uint8_t receive_on;
|
|
|
|
static int channel;
|
|
|
|
|
2015-09-21 20:03:51 +00:00
|
|
|
/* Are we currently in poll mode? */
|
|
|
|
static uint8_t volatile poll_mode = 0;
|
|
|
|
/* Do we perform a CCA before sending? */
|
|
|
|
static uint8_t send_on_cca = WITH_SEND_CCA;
|
|
|
|
|
2014-04-01 13:22:17 +00:00
|
|
|
static radio_result_t
|
|
|
|
get_value(radio_param_t param, radio_value_t *value)
|
|
|
|
{
|
2014-04-07 13:42:39 +00:00
|
|
|
int i, v;
|
|
|
|
|
2014-04-01 13:22:17 +00:00
|
|
|
if(!value) {
|
|
|
|
return RADIO_RESULT_INVALID_VALUE;
|
|
|
|
}
|
|
|
|
switch(param) {
|
|
|
|
case RADIO_PARAM_POWER_MODE:
|
|
|
|
*value = receive_on ? RADIO_POWER_MODE_ON : RADIO_POWER_MODE_OFF;
|
|
|
|
return RADIO_RESULT_OK;
|
|
|
|
case RADIO_PARAM_CHANNEL:
|
|
|
|
*value = cc2420_get_channel();
|
|
|
|
return RADIO_RESULT_OK;
|
2015-09-21 20:03:51 +00:00
|
|
|
case RADIO_PARAM_RX_MODE:
|
|
|
|
*value = 0;
|
|
|
|
if(getreg(CC2420_MDMCTRL0) & ADR_DECODE) {
|
|
|
|
*value |= RADIO_RX_MODE_ADDRESS_FILTER;
|
|
|
|
}
|
|
|
|
if(getreg(CC2420_MDMCTRL0) & AUTOACK) {
|
|
|
|
*value |= RADIO_RX_MODE_AUTOACK;
|
|
|
|
}
|
|
|
|
if(poll_mode) {
|
|
|
|
*value |= RADIO_RX_MODE_POLL_MODE;
|
|
|
|
}
|
|
|
|
return RADIO_RESULT_OK;
|
|
|
|
case RADIO_PARAM_TX_MODE:
|
|
|
|
*value = 0;
|
|
|
|
if(send_on_cca) {
|
|
|
|
*value |= RADIO_TX_MODE_SEND_ON_CCA;
|
|
|
|
}
|
|
|
|
return RADIO_RESULT_OK;
|
2014-04-07 13:42:39 +00:00
|
|
|
case RADIO_PARAM_TXPOWER:
|
|
|
|
v = cc2420_get_txpower();
|
|
|
|
*value = OUTPUT_POWER_MIN;
|
|
|
|
/* Find the actual estimated output power in conversion table */
|
|
|
|
for(i = 0; i < OUTPUT_NUM; i++) {
|
|
|
|
if(v >= output_power[i].config) {
|
|
|
|
*value = output_power[i].power;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return RADIO_RESULT_OK;
|
2015-02-19 10:26:43 +00:00
|
|
|
case RADIO_PARAM_CCA_THRESHOLD:
|
|
|
|
*value = get_cca_threshold() + RSSI_OFFSET;
|
|
|
|
return RADIO_RESULT_OK;
|
2014-04-07 13:42:39 +00:00
|
|
|
case RADIO_PARAM_RSSI:
|
|
|
|
/* Return the RSSI value in dBm */
|
2014-02-20 12:34:25 +00:00
|
|
|
*value = cc2420_rssi();
|
2014-04-07 13:42:39 +00:00
|
|
|
return RADIO_RESULT_OK;
|
2015-09-21 20:03:51 +00:00
|
|
|
case RADIO_PARAM_LAST_RSSI:
|
|
|
|
/* RSSI of the last packet received */
|
|
|
|
*value = cc2420_last_rssi;
|
|
|
|
return RADIO_RESULT_OK;
|
|
|
|
case RADIO_PARAM_LAST_LINK_QUALITY:
|
|
|
|
/* LQI of the last packet received */
|
|
|
|
*value = cc2420_last_correlation;
|
|
|
|
return RADIO_RESULT_OK;
|
2014-04-01 13:22:17 +00:00
|
|
|
case RADIO_CONST_CHANNEL_MIN:
|
|
|
|
*value = 11;
|
|
|
|
return RADIO_RESULT_OK;
|
|
|
|
case RADIO_CONST_CHANNEL_MAX:
|
|
|
|
*value = 26;
|
|
|
|
return RADIO_RESULT_OK;
|
2014-04-07 13:42:39 +00:00
|
|
|
case RADIO_CONST_TXPOWER_MIN:
|
|
|
|
*value = OUTPUT_POWER_MIN;
|
|
|
|
return RADIO_RESULT_OK;
|
|
|
|
case RADIO_CONST_TXPOWER_MAX:
|
|
|
|
*value = OUTPUT_POWER_MAX;
|
|
|
|
return RADIO_RESULT_OK;
|
2014-04-01 13:22:17 +00:00
|
|
|
default:
|
|
|
|
return RADIO_RESULT_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static radio_result_t
|
|
|
|
set_value(radio_param_t param, radio_value_t value)
|
|
|
|
{
|
2014-04-07 13:42:39 +00:00
|
|
|
int i;
|
|
|
|
|
2014-04-01 13:22:17 +00:00
|
|
|
switch(param) {
|
|
|
|
case RADIO_PARAM_POWER_MODE:
|
|
|
|
if(value == RADIO_POWER_MODE_ON) {
|
|
|
|
cc2420_on();
|
|
|
|
return RADIO_RESULT_OK;
|
|
|
|
}
|
|
|
|
if(value == RADIO_POWER_MODE_OFF) {
|
|
|
|
cc2420_off();
|
|
|
|
return RADIO_RESULT_OK;
|
|
|
|
}
|
|
|
|
return RADIO_RESULT_INVALID_VALUE;
|
|
|
|
case RADIO_PARAM_CHANNEL:
|
|
|
|
if(value < 11 || value > 26) {
|
|
|
|
return RADIO_RESULT_INVALID_VALUE;
|
|
|
|
}
|
|
|
|
cc2420_set_channel(value);
|
|
|
|
return RADIO_RESULT_OK;
|
2015-09-21 20:03:51 +00:00
|
|
|
case RADIO_PARAM_RX_MODE:
|
|
|
|
if(value & ~(RADIO_RX_MODE_ADDRESS_FILTER |
|
|
|
|
RADIO_RX_MODE_AUTOACK | RADIO_RX_MODE_POLL_MODE)) {
|
|
|
|
return RADIO_RESULT_INVALID_VALUE;
|
|
|
|
}
|
|
|
|
set_frame_filtering((value & RADIO_RX_MODE_ADDRESS_FILTER) != 0);
|
|
|
|
set_auto_ack((value & RADIO_RX_MODE_AUTOACK) != 0);
|
|
|
|
set_poll_mode((value & RADIO_RX_MODE_POLL_MODE) != 0);
|
|
|
|
return RADIO_RESULT_OK;
|
|
|
|
case RADIO_PARAM_TX_MODE:
|
|
|
|
if(value & ~(RADIO_TX_MODE_SEND_ON_CCA)) {
|
|
|
|
return RADIO_RESULT_INVALID_VALUE;
|
|
|
|
}
|
|
|
|
set_send_on_cca((value & RADIO_TX_MODE_SEND_ON_CCA) != 0);
|
|
|
|
return RADIO_RESULT_OK;
|
2014-04-07 13:42:39 +00:00
|
|
|
case RADIO_PARAM_TXPOWER:
|
2014-04-13 19:43:37 +00:00
|
|
|
if(value < OUTPUT_POWER_MIN || value > OUTPUT_POWER_MAX) {
|
|
|
|
return RADIO_RESULT_INVALID_VALUE;
|
|
|
|
}
|
2014-04-07 13:42:39 +00:00
|
|
|
/* Find the closest higher PA_LEVEL for the desired output power */
|
|
|
|
for(i = 1; i < OUTPUT_NUM; i++) {
|
|
|
|
if(value > output_power[i].power) {
|
2014-04-13 19:43:37 +00:00
|
|
|
break;
|
2014-04-07 13:42:39 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-13 19:43:37 +00:00
|
|
|
cc2420_set_txpower(output_power[i - 1].config);
|
2014-04-07 13:42:39 +00:00
|
|
|
return RADIO_RESULT_OK;
|
2015-02-19 10:26:43 +00:00
|
|
|
case RADIO_PARAM_CCA_THRESHOLD:
|
|
|
|
cc2420_set_cca_threshold(value - RSSI_OFFSET);
|
|
|
|
return RADIO_RESULT_OK;
|
2014-04-01 13:22:17 +00:00
|
|
|
default:
|
|
|
|
return RADIO_RESULT_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static radio_result_t
|
|
|
|
get_object(radio_param_t param, void *dest, size_t size)
|
|
|
|
{
|
2015-09-21 20:03:51 +00:00
|
|
|
if(param == RADIO_PARAM_LAST_PACKET_TIMESTAMP) {
|
|
|
|
#if CC2420_CONF_SFD_TIMESTAMPS
|
|
|
|
if(size != sizeof(rtimer_clock_t) || !dest) {
|
|
|
|
return RADIO_RESULT_INVALID_VALUE;
|
|
|
|
}
|
|
|
|
*(rtimer_clock_t*)dest = cc2420_sfd_start_time;
|
|
|
|
return RADIO_RESULT_OK;
|
|
|
|
#else
|
|
|
|
return RADIO_RESULT_NOT_SUPPORTED;
|
|
|
|
#endif
|
|
|
|
}
|
2014-04-01 13:22:17 +00:00
|
|
|
return RADIO_RESULT_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static radio_result_t
|
|
|
|
set_object(radio_param_t param, const void *src, size_t size)
|
|
|
|
{
|
|
|
|
return RADIO_RESULT_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
2008-07-02 09:05:40 +00:00
|
|
|
const struct radio_driver cc2420_driver =
|
2007-05-15 07:53:09 +00: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 21:48:39 +00:00
|
|
|
cc2420_init,
|
|
|
|
cc2420_prepare,
|
|
|
|
cc2420_transmit,
|
2008-07-02 09:05:40 +00: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 21:48:39 +00:00
|
|
|
cc2420_cca,
|
|
|
|
cc2420_receiving_packet,
|
|
|
|
pending_packet,
|
2008-07-02 09:05:40 +00:00
|
|
|
cc2420_on,
|
|
|
|
cc2420_off,
|
2014-04-01 13:22:17 +00:00
|
|
|
get_value,
|
|
|
|
set_value,
|
|
|
|
get_object,
|
|
|
|
set_object
|
2007-05-15 07:53:09 +00:00
|
|
|
};
|
|
|
|
|
2008-08-26 21:44:03 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-02-09 22:16:48 +00:00
|
|
|
/* Sends a strobe */
|
2014-04-11 10:58:49 +00:00
|
|
|
static void
|
|
|
|
strobe(enum cc2420_register regname)
|
|
|
|
{
|
2014-02-09 22:16:48 +00:00
|
|
|
CC2420_SPI_ENABLE();
|
|
|
|
SPI_WRITE(regname);
|
|
|
|
CC2420_SPI_DISABLE();
|
2014-04-11 10:58:49 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-02-09 22:16:48 +00:00
|
|
|
/* Reads a register */
|
2013-05-24 10:13:47 +00:00
|
|
|
static uint16_t
|
|
|
|
getreg(enum cc2420_register regname)
|
|
|
|
{
|
2014-02-09 22:16:48 +00:00
|
|
|
uint16_t value;
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2014-02-09 22:16:48 +00:00
|
|
|
CC2420_SPI_ENABLE();
|
|
|
|
SPI_WRITE(regname | 0x40);
|
|
|
|
value = (uint8_t)SPI_RXBUF;
|
|
|
|
SPI_TXBUF = 0;
|
|
|
|
SPI_WAITFOREORx();
|
|
|
|
value = SPI_RXBUF << 8;
|
|
|
|
SPI_TXBUF = 0;
|
|
|
|
SPI_WAITFOREORx();
|
|
|
|
value |= SPI_RXBUF;
|
|
|
|
CC2420_SPI_DISABLE();
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2014-02-09 22:16:48 +00:00
|
|
|
return value;
|
2013-05-24 10:13:47 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2017-05-13 11:09:58 +00:00
|
|
|
/**
|
2014-02-09 22:16:48 +00:00
|
|
|
* Writes to a register.
|
|
|
|
* Note: the SPI_WRITE(0) seems to be needed for getting the
|
|
|
|
* write reg working on the Z1 / MSP430X platform
|
|
|
|
*/
|
2013-05-24 10:13:47 +00:00
|
|
|
static void
|
|
|
|
setreg(enum cc2420_register regname, uint16_t value)
|
|
|
|
{
|
2014-02-09 22:16:48 +00:00
|
|
|
CC2420_SPI_ENABLE();
|
|
|
|
SPI_WRITE_FAST(regname);
|
|
|
|
SPI_WRITE_FAST((uint8_t) (value >> 8));
|
|
|
|
SPI_WRITE_FAST((uint8_t) (value & 0xff));
|
|
|
|
SPI_WAITFORTx_ENDED();
|
|
|
|
SPI_WRITE(0);
|
|
|
|
CC2420_SPI_DISABLE();
|
2013-05-24 10:13:47 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
read_ram(uint8_t *buffer, uint16_t adr, uint16_t count)
|
|
|
|
{
|
2014-02-09 22:16:48 +00:00
|
|
|
uint8_t i;
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2014-02-09 22:16:48 +00:00
|
|
|
CC2420_SPI_ENABLE();
|
|
|
|
SPI_WRITE(0x80 | ((adr) & 0x7f));
|
|
|
|
SPI_WRITE((((adr) >> 1) & 0xc0) | 0x20);
|
|
|
|
SPI_RXBUF;
|
|
|
|
for(i = 0; i < count; i++) {
|
|
|
|
SPI_READ(((uint8_t*) buffer)[i]);
|
|
|
|
}
|
|
|
|
CC2420_SPI_DISABLE();
|
2013-05-24 10:13:47 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-02-09 22:16:48 +00:00
|
|
|
/* Write to RAM in the CC2420 */
|
2013-05-24 10:13:47 +00:00
|
|
|
static void
|
2013-05-25 11:53:41 +00:00
|
|
|
write_ram(const uint8_t *buffer,
|
|
|
|
uint16_t adr,
|
|
|
|
uint16_t count,
|
2014-02-09 22:16:48 +00:00
|
|
|
enum write_ram_order order)
|
2013-05-24 10:13:47 +00:00
|
|
|
{
|
2014-02-09 22:16:48 +00:00
|
|
|
uint8_t i;
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2014-02-09 22:16:48 +00:00
|
|
|
CC2420_SPI_ENABLE();
|
|
|
|
SPI_WRITE_FAST(0x80 | (adr & 0x7f));
|
|
|
|
SPI_WRITE_FAST((adr >> 1) & 0xc0);
|
|
|
|
if(order == WRITE_RAM_IN_ORDER) {
|
|
|
|
for(i = 0; i < count; i++) {
|
|
|
|
SPI_WRITE_FAST((buffer)[i]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(i = count; i > 0; i--) {
|
|
|
|
SPI_WRITE_FAST((buffer)[i - 1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SPI_WAITFORTx_ENDED();
|
|
|
|
CC2420_SPI_DISABLE();
|
2013-05-24 10:13:47 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
write_fifo_buf(const uint8_t *buffer, uint16_t count)
|
|
|
|
{
|
2014-02-09 22:16:48 +00:00
|
|
|
uint8_t i;
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2014-02-09 22:16:48 +00:00
|
|
|
CC2420_SPI_ENABLE();
|
|
|
|
SPI_WRITE_FAST(CC2420_TXFIFO);
|
|
|
|
for(i = 0; i < count; i++) {
|
|
|
|
SPI_WRITE_FAST((buffer)[i]);
|
|
|
|
}
|
|
|
|
SPI_WAITFORTx_ENDED();
|
|
|
|
CC2420_SPI_DISABLE();
|
2013-05-24 10:13:47 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-02-09 22:16:48 +00:00
|
|
|
/* Returns the current status */
|
2013-05-24 10:13:47 +00:00
|
|
|
static uint8_t
|
|
|
|
get_status(void)
|
|
|
|
{
|
|
|
|
uint8_t status;
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2014-02-09 22:16:48 +00:00
|
|
|
CC2420_SPI_ENABLE();
|
|
|
|
SPI_WRITE(CC2420_SNOP);
|
|
|
|
status = SPI_RXBUF;
|
|
|
|
CC2420_SPI_DISABLE();
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2013-05-24 10:13:47 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2008-08-26 21:44:03 +00:00
|
|
|
static void
|
2014-02-09 22:16:48 +00:00
|
|
|
getrxdata(uint8_t *buffer, int count)
|
2008-08-26 21:44:03 +00:00
|
|
|
{
|
2014-02-09 22:16:48 +00:00
|
|
|
uint8_t i;
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2014-02-09 22:16:48 +00:00
|
|
|
CC2420_SPI_ENABLE();
|
|
|
|
SPI_WRITE(CC2420_RXFIFO | 0x40);
|
|
|
|
(void) SPI_RXBUF;
|
|
|
|
for(i = 0; i < count; i++) {
|
|
|
|
SPI_READ(buffer[i]);
|
|
|
|
}
|
|
|
|
clock_delay(1);
|
|
|
|
CC2420_SPI_DISABLE();
|
2008-08-26 21:44:03 +00:00
|
|
|
}
|
2013-05-24 10:13:47 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2008-08-26 21:44:03 +00:00
|
|
|
static void
|
|
|
|
flushrx(void)
|
|
|
|
{
|
|
|
|
uint8_t dummy;
|
2009-08-19 12:00:04 +00:00
|
|
|
|
2013-06-06 13:54:20 +00:00
|
|
|
getrxdata(&dummy, 1);
|
2014-04-11 10:58:49 +00:00
|
|
|
strobe(CC2420_SFLUSHRX);
|
|
|
|
strobe(CC2420_SFLUSHRX);
|
|
|
|
if(dummy) {
|
|
|
|
/* avoid unused variable compiler warning */
|
|
|
|
}
|
2007-03-15 21:26:00 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-04-11 10:58:49 +00:00
|
|
|
static void
|
2013-05-24 10:13:47 +00:00
|
|
|
wait_for_status(uint8_t status_bit)
|
2014-04-11 10:58:49 +00:00
|
|
|
{
|
2013-05-24 10:13:47 +00:00
|
|
|
rtimer_clock_t t0;
|
|
|
|
t0 = RTIMER_NOW();
|
|
|
|
while(!(get_status() & status_bit)
|
|
|
|
&& RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (RTIMER_SECOND / 10)));
|
2014-04-11 10:58:49 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2013-05-24 10:13:47 +00:00
|
|
|
wait_for_transmission(void)
|
2014-04-11 10:58:49 +00:00
|
|
|
{
|
2013-05-24 10:13:47 +00:00
|
|
|
rtimer_clock_t t0;
|
|
|
|
t0 = RTIMER_NOW();
|
|
|
|
while((get_status() & BV(CC2420_TX_ACTIVE))
|
|
|
|
&& RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (RTIMER_SECOND / 10)));
|
2014-04-11 10:58:49 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-03-15 21:26:00 +00:00
|
|
|
static void
|
2007-05-15 07:53:09 +00:00
|
|
|
on(void)
|
2007-03-15 21:26:00 +00:00
|
|
|
{
|
2015-09-21 20:03:51 +00:00
|
|
|
if(!poll_mode) {
|
|
|
|
CC2420_ENABLE_FIFOP_INT();
|
|
|
|
}
|
|
|
|
|
2008-08-26 21:44:03 +00:00
|
|
|
strobe(CC2420_SRXON);
|
2010-09-22 22:01:53 +00:00
|
|
|
|
2010-04-04 07:49:30 +00:00
|
|
|
ENERGEST_ON(ENERGEST_TYPE_LISTEN);
|
2010-09-22 22:01:53 +00:00
|
|
|
receive_on = 1;
|
2007-05-15 07:53:09 +00:00
|
|
|
}
|
2014-02-09 22:55:32 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-05-15 07:53:09 +00:00
|
|
|
static void
|
|
|
|
off(void)
|
|
|
|
{
|
2010-03-14 22:45:20 +00:00
|
|
|
/* PRINTF("off\n");*/
|
2007-05-15 07:53:09 +00:00
|
|
|
receive_on = 0;
|
2009-08-19 12:00:04 +00:00
|
|
|
|
2007-05-15 07:53:09 +00:00
|
|
|
/* Wait for transmission to end before turning radio off. */
|
2013-05-24 10:13:47 +00:00
|
|
|
wait_for_transmission();
|
2009-08-19 12:00:04 +00:00
|
|
|
|
2007-10-25 09:30:39 +00:00
|
|
|
ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
|
2010-04-08 18:23:24 +00:00
|
|
|
strobe(CC2420_SRFOFF);
|
2015-09-21 20:03:51 +00:00
|
|
|
if(!poll_mode) {
|
|
|
|
CC2420_DISABLE_FIFOP_INT();
|
|
|
|
}
|
2010-04-04 07:49:30 +00:00
|
|
|
|
2010-06-23 10:15:28 +00:00
|
|
|
if(!CC2420_FIFOP_IS_1) {
|
2010-04-04 07:49:30 +00:00
|
|
|
flushrx();
|
|
|
|
}
|
2007-05-15 07:53:09 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-02-09 22:55:32 +00:00
|
|
|
static uint8_t locked, lock_on, lock_off;
|
2010-03-14 22:45:20 +00:00
|
|
|
#define GET_LOCK() locked++
|
2007-05-15 07:53:09 +00:00
|
|
|
static void RELEASE_LOCK(void) {
|
2010-03-14 22:45:20 +00:00
|
|
|
if(locked == 1) {
|
|
|
|
if(lock_on) {
|
|
|
|
on();
|
|
|
|
lock_on = 0;
|
|
|
|
}
|
|
|
|
if(lock_off) {
|
|
|
|
off();
|
|
|
|
lock_off = 0;
|
|
|
|
}
|
2007-05-15 07:53:09 +00:00
|
|
|
}
|
2010-03-14 22:45:20 +00:00
|
|
|
locked--;
|
2007-03-15 21:26:00 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-04-11 10:58:49 +00:00
|
|
|
static void
|
2014-02-09 22:55:32 +00:00
|
|
|
init_security(void)
|
|
|
|
{
|
|
|
|
/* only use key 0 */
|
|
|
|
setreg(CC2420_SECCTRL0, 0);
|
|
|
|
setreg(CC2420_SECCTRL1, 0);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2015-10-01 09:10:46 +00:00
|
|
|
set_key(const uint8_t *key)
|
2014-02-09 22:55:32 +00:00
|
|
|
{
|
|
|
|
GET_LOCK();
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2014-02-09 22:55:32 +00:00
|
|
|
write_ram(key, CC2420RAM_KEY0, 16, WRITE_RAM_REVERSE);
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2014-02-09 22:55:32 +00:00
|
|
|
RELEASE_LOCK();
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
encrypt(uint8_t *plaintext_and_result)
|
|
|
|
{
|
|
|
|
GET_LOCK();
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2014-02-09 22:55:32 +00:00
|
|
|
write_ram(plaintext_and_result,
|
|
|
|
CC2420RAM_SABUF,
|
|
|
|
16,
|
|
|
|
WRITE_RAM_IN_ORDER);
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2014-02-09 22:55:32 +00:00
|
|
|
strobe(CC2420_SAES);
|
|
|
|
while(get_status() & BV(CC2420_ENC_BUSY));
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2014-02-09 22:55:32 +00:00
|
|
|
read_ram(plaintext_and_result, CC2420RAM_SABUF, 16);
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2014-02-09 22:55:32 +00:00
|
|
|
RELEASE_LOCK();
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
const struct aes_128_driver cc2420_aes_128_driver = {
|
|
|
|
set_key,
|
|
|
|
encrypt
|
|
|
|
};
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2009-08-19 15:05:05 +00:00
|
|
|
set_txpower(uint8_t power)
|
|
|
|
{
|
|
|
|
uint16_t reg;
|
|
|
|
|
|
|
|
reg = getreg(CC2420_TXCTRL);
|
|
|
|
reg = (reg & 0xffe0) | (power & 0x1f);
|
|
|
|
setreg(CC2420_TXCTRL, reg);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
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 21:48:39 +00:00
|
|
|
int
|
2008-07-02 09:05:40 +00:00
|
|
|
cc2420_init(void)
|
2007-03-15 21:26:00 +00:00
|
|
|
{
|
2008-01-23 14:57:19 +00:00
|
|
|
uint16_t reg;
|
2007-03-15 21:26:00 +00:00
|
|
|
{
|
|
|
|
int s = splhigh();
|
2008-07-02 09:05:40 +00:00
|
|
|
cc2420_arch_init(); /* Initalize ports and SPI. */
|
2010-06-23 10:15:28 +00:00
|
|
|
CC2420_DISABLE_FIFOP_INT();
|
|
|
|
CC2420_FIFOP_INT_INIT();
|
2007-03-15 21:26:00 +00:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Turn on voltage regulator and reset. */
|
|
|
|
SET_VREG_ACTIVE();
|
2011-06-04 22:20:25 +00:00
|
|
|
clock_delay(250);
|
2007-03-15 21:26:00 +00:00
|
|
|
SET_RESET_ACTIVE();
|
|
|
|
clock_delay(127);
|
|
|
|
SET_RESET_INACTIVE();
|
2011-06-04 22:20:25 +00:00
|
|
|
clock_delay(125);
|
2007-03-15 21:26:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Turn on the crystal oscillator. */
|
|
|
|
strobe(CC2420_SXOSCON);
|
2013-05-25 13:37:08 +00:00
|
|
|
/* And wait until it stabilizes */
|
|
|
|
wait_for_status(BV(CC2420_XOSC16M_STABLE));
|
2007-03-15 21:26:00 +00:00
|
|
|
|
2015-09-21 20:03:51 +00:00
|
|
|
/* Set auto-ack and frame filtering */
|
|
|
|
set_auto_ack(CC2420_CONF_AUTOACK);
|
|
|
|
set_frame_filtering(CC2420_CONF_AUTOACK);
|
2010-02-23 18:24:49 +00:00
|
|
|
|
2013-05-24 10:04:17 +00:00
|
|
|
/* Enabling CRC in hardware; this is required by AUTOACK anyway
|
|
|
|
and provides us with RSSI and link quality indication (LQI)
|
|
|
|
information. */
|
2015-09-21 20:03:51 +00:00
|
|
|
reg = getreg(CC2420_MDMCTRL0);
|
2013-05-24 10:04:17 +00:00
|
|
|
reg |= AUTOCRC;
|
2007-03-15 21:26:00 +00:00
|
|
|
setreg(CC2420_MDMCTRL0, reg);
|
|
|
|
|
2010-03-30 23:00:05 +00:00
|
|
|
/* Set transmission turnaround time to the lower setting (8 symbols
|
|
|
|
= 0.128 ms) instead of the default (12 symbols = 0.192 ms). */
|
|
|
|
/* reg = getreg(CC2420_TXCTRL);
|
|
|
|
reg &= ~(1 << 13);
|
|
|
|
setreg(CC2420_TXCTRL, reg);*/
|
|
|
|
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2007-03-15 21:26:00 +00:00
|
|
|
/* 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 12:00:04 +00:00
|
|
|
|
2007-03-15 21:26:00 +00:00
|
|
|
/* Set the FIFOP threshold to maximum. */
|
|
|
|
setreg(CC2420_IOCFG0, FIFOP_THR(127));
|
|
|
|
|
2013-05-24 12:24:14 +00:00
|
|
|
init_security();
|
2007-03-15 21:26:00 +00:00
|
|
|
|
2008-07-02 09:05:40 +00:00
|
|
|
cc2420_set_pan_addr(0xffff, 0x0000, NULL);
|
2013-11-07 14:17:38 +00:00
|
|
|
cc2420_set_channel(CC2420_CONF_CHANNEL);
|
|
|
|
cc2420_set_cca_threshold(CC2420_CONF_CCA_THRESH);
|
2007-03-15 21:26:00 +00:00
|
|
|
|
2010-04-04 07:49:30 +00:00
|
|
|
flushrx();
|
2010-06-23 10:15:28 +00:00
|
|
|
|
2015-09-21 20:03:51 +00:00
|
|
|
set_poll_mode(0);
|
|
|
|
|
2008-07-02 09:05:40 +00: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 21:48:39 +00:00
|
|
|
return 1;
|
2007-03-15 21:26:00 +00: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 21:48:39 +00:00
|
|
|
static int
|
|
|
|
cc2420_transmit(unsigned short payload_len)
|
2007-03-15 21:26:00 +00:00
|
|
|
{
|
2017-05-13 11:09:58 +00:00
|
|
|
int i;
|
2007-05-22 20:51:30 +00:00
|
|
|
|
2017-05-13 11:09:58 +00:00
|
|
|
GET_LOCK();
|
2009-08-19 12:00:04 +00:00
|
|
|
|
2008-01-23 14:57:19 +00:00
|
|
|
/* The TX FIFO can only hold one packet. Make sure to not overrun
|
2007-03-15 21:26:00 +00: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.
|
|
|
|
*/
|
2010-06-21 19:48:00 +00:00
|
|
|
#ifndef CC2420_CONF_SYMBOL_LOOP_COUNT
|
|
|
|
#error CC2420_CONF_SYMBOL_LOOP_COUNT needs to be set!!!
|
|
|
|
#else
|
|
|
|
#define LOOP_20_SYMBOLS CC2420_CONF_SYMBOL_LOOP_COUNT
|
2007-03-15 21:26:00 +00:00
|
|
|
#endif
|
2008-01-23 14:57:19 +00:00
|
|
|
|
2015-09-21 20:03:51 +00:00
|
|
|
if(send_on_cca) {
|
|
|
|
strobe(CC2420_SRXON);
|
|
|
|
wait_for_status(BV(CC2420_RSSI_VALID));
|
|
|
|
strobe(CC2420_STXONCCA);
|
|
|
|
} else {
|
|
|
|
strobe(CC2420_STXON);
|
|
|
|
}
|
2007-03-15 21:26:00 +00:00
|
|
|
for(i = LOOP_20_SYMBOLS; i > 0; i--) {
|
2010-06-23 10:15:28 +00:00
|
|
|
if(CC2420_SFD_IS_1) {
|
2013-05-24 10:13:47 +00:00
|
|
|
if(!(get_status() & BV(CC2420_TX_ACTIVE))) {
|
2010-02-23 18:24:49 +00:00
|
|
|
/* SFD went high but we are not transmitting. This means that
|
|
|
|
we just started receiving a packet, so we drop the
|
|
|
|
transmission. */
|
2010-03-14 22:45:20 +00:00
|
|
|
RELEASE_LOCK();
|
2010-03-30 23:00:05 +00:00
|
|
|
return RADIO_TX_COLLISION;
|
2010-02-23 18:24:49 +00:00
|
|
|
}
|
2008-05-14 19:44:30 +00:00
|
|
|
if(receive_on) {
|
|
|
|
ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
|
|
|
|
}
|
2007-09-18 10:36:31 +00:00
|
|
|
ENERGEST_ON(ENERGEST_TYPE_TRANSMIT);
|
2008-01-24 13:09:16 +00:00
|
|
|
/* We wait until transmission has ended so that we get an
|
|
|
|
accurate measurement of the transmission time.*/
|
2013-05-24 10:13:47 +00:00
|
|
|
wait_for_transmission();
|
2008-01-23 14:57:19 +00:00
|
|
|
|
|
|
|
#ifdef ENERGEST_CONF_LEVELDEVICE_LEVELS
|
2008-07-02 09:05:40 +00:00
|
|
|
ENERGEST_OFF_LEVEL(ENERGEST_TYPE_TRANSMIT,cc2420_get_txpower());
|
2008-01-15 08:33:02 +00:00
|
|
|
#endif
|
2007-05-15 07:53:09 +00:00
|
|
|
ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
|
2008-05-14 19:44:30 +00:00
|
|
|
if(receive_on) {
|
|
|
|
ENERGEST_ON(ENERGEST_TYPE_LISTEN);
|
2009-08-19 12:00:04 +00:00
|
|
|
} else {
|
2009-09-09 21:07:42 +00:00
|
|
|
/* We need to explicitly turn off the radio,
|
|
|
|
* since STXON[CCA] -> TX_ACTIVE -> RX_ACTIVE */
|
|
|
|
off();
|
2008-05-14 19:44:30 +00:00
|
|
|
}
|
2008-01-23 14:57:19 +00:00
|
|
|
|
2007-10-25 13:29:21 +00:00
|
|
|
RELEASE_LOCK();
|
2010-02-23 18:24:49 +00:00
|
|
|
return RADIO_TX_OK;
|
2007-03-15 21:26:00 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-19 12:00:04 +00:00
|
|
|
|
2015-09-21 20:03:51 +00:00
|
|
|
/* If we send with cca (cca_on_send), we get here if the packet wasn't
|
2008-01-23 14:57:19 +00:00
|
|
|
transmitted because of other channel activity. */
|
2008-07-02 09:05:40 +00:00
|
|
|
PRINTF("cc2420: do_send() transmission never started\n");
|
2009-08-19 15:05:05 +00:00
|
|
|
|
2007-05-15 07:53:09 +00:00
|
|
|
RELEASE_LOCK();
|
2010-03-30 23:00:05 +00:00
|
|
|
return RADIO_TX_COLLISION;
|
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 21:48:39 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static int
|
|
|
|
cc2420_prepare(const void *payload, unsigned short payload_len)
|
|
|
|
{
|
|
|
|
uint8_t total_len;
|
2017-05-13 11:09:58 +00: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 21:48:39 +00:00
|
|
|
GET_LOCK();
|
|
|
|
|
|
|
|
PRINTF("cc2420: sending %d bytes\n", payload_len);
|
|
|
|
|
|
|
|
/* Wait for any previous transmission to finish. */
|
2010-02-23 18:24:49 +00: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 21:48:39 +00:00
|
|
|
|
|
|
|
/* Write packet to TX FIFO. */
|
|
|
|
strobe(CC2420_SFLUSHTX);
|
|
|
|
|
2013-05-24 10:04:17 +00:00
|
|
|
total_len = payload_len + CHECKSUM_LEN;
|
2013-05-24 10:13:47 +00:00
|
|
|
write_fifo_buf(&total_len, 1);
|
|
|
|
write_fifo_buf(payload, payload_len);
|
2017-05-13 11:09:58 +00: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 21:48:39 +00:00
|
|
|
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 21:26:00 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-05-15 07:53:09 +00:00
|
|
|
int
|
2008-07-02 09:05:40 +00:00
|
|
|
cc2420_off(void)
|
2007-03-15 21:26:00 +00:00
|
|
|
{
|
2008-08-26 21:44:03 +00:00
|
|
|
/* Don't do anything if we are already turned off. */
|
2007-04-03 19:05:44 +00:00
|
|
|
if(receive_on == 0) {
|
2007-05-15 07:53:09 +00:00
|
|
|
return 1;
|
2007-04-03 19:05:44 +00:00
|
|
|
}
|
2007-03-15 21:26:00 +00:00
|
|
|
|
2008-08-26 21:44:03 +00: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 07:53:09 +00:00
|
|
|
if(locked) {
|
2010-03-14 22:45:20 +00:00
|
|
|
/* printf("Off when locked (%d)\n", locked);*/
|
2007-05-15 07:53:09 +00:00
|
|
|
lock_off = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-03-14 22:45:20 +00:00
|
|
|
GET_LOCK();
|
2008-08-26 21:44:03 +00: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. */
|
2013-05-24 10:13:47 +00:00
|
|
|
if(get_status() & BV(CC2420_TX_ACTIVE)) {
|
2007-05-15 07:53:09 +00:00
|
|
|
lock_off = 1;
|
2010-03-14 22:45:20 +00:00
|
|
|
} else {
|
|
|
|
off();
|
2007-05-15 07:53:09 +00:00
|
|
|
}
|
2010-03-14 22:45:20 +00:00
|
|
|
RELEASE_LOCK();
|
2007-05-15 07:53:09 +00:00
|
|
|
return 1;
|
2007-03-15 21:26:00 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-05-15 07:53:09 +00:00
|
|
|
int
|
2008-07-02 09:05:40 +00:00
|
|
|
cc2420_on(void)
|
2007-03-15 21:26:00 +00:00
|
|
|
{
|
|
|
|
if(receive_on) {
|
2007-05-15 07:53:09 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if(locked) {
|
|
|
|
lock_on = 1;
|
|
|
|
return 1;
|
2007-03-15 21:26:00 +00:00
|
|
|
}
|
|
|
|
|
2010-03-14 22:45:20 +00:00
|
|
|
GET_LOCK();
|
2007-05-15 07:53:09 +00:00
|
|
|
on();
|
2010-03-14 22:45:20 +00:00
|
|
|
RELEASE_LOCK();
|
2007-05-15 07:53:09 +00:00
|
|
|
return 1;
|
2007-03-15 21:26:00 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2008-01-23 14:57:19 +00:00
|
|
|
int
|
2008-07-02 09:05:40 +00:00
|
|
|
cc2420_get_channel(void)
|
2008-01-23 14:57:19 +00:00
|
|
|
{
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-09-22 22:01:53 +00:00
|
|
|
int
|
2008-07-02 09:05:40 +00:00
|
|
|
cc2420_set_channel(int c)
|
2007-12-05 13:21:05 +00:00
|
|
|
{
|
2008-01-23 14:57:19 +00:00
|
|
|
uint16_t f;
|
2010-03-14 22:45:20 +00:00
|
|
|
|
|
|
|
GET_LOCK();
|
2008-01-23 14:57:19 +00:00
|
|
|
/*
|
|
|
|
* 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 12:00:04 +00:00
|
|
|
|
2008-01-23 14:57:19 +00:00
|
|
|
f = 5 * (c - 11) + 357 + 0x4000;
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2008-01-24 13:09:16 +00:00
|
|
|
/* Wait for any transmission to end. */
|
2013-05-24 10:13:47 +00:00
|
|
|
wait_for_transmission();
|
2008-01-24 13:09:16 +00:00
|
|
|
|
2007-12-05 13:21:05 +00:00
|
|
|
setreg(CC2420_FSCTRL, f);
|
2008-01-24 13:09:16 +00: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);
|
|
|
|
}
|
|
|
|
|
2010-03-14 22:45:20 +00:00
|
|
|
RELEASE_LOCK();
|
2010-09-22 22:01:53 +00:00
|
|
|
return 1;
|
2007-12-05 13:21:05 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2008-07-02 09:05:40 +00: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 21:48:39 +00:00
|
|
|
unsigned addr,
|
|
|
|
const uint8_t *ieee_addr)
|
2007-03-15 21:26:00 +00:00
|
|
|
{
|
2010-03-14 22:45:20 +00:00
|
|
|
GET_LOCK();
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2014-02-09 22:16:48 +00:00
|
|
|
write_ram((uint8_t *) &pan, CC2420RAM_PANID, 2, WRITE_RAM_IN_ORDER);
|
|
|
|
write_ram((uint8_t *) &addr, CC2420RAM_SHORTADDR, 2, WRITE_RAM_IN_ORDER);
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2007-03-15 21:26:00 +00:00
|
|
|
if(ieee_addr != NULL) {
|
2014-02-09 22:16:48 +00:00
|
|
|
write_ram(ieee_addr, CC2420RAM_IEEEADDR, 8, WRITE_RAM_REVERSE);
|
2007-03-15 21:26:00 +00:00
|
|
|
}
|
2010-03-14 22:45:20 +00:00
|
|
|
RELEASE_LOCK();
|
2007-04-03 19:05:44 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-03-15 21:26:00 +00:00
|
|
|
/*
|
2008-08-26 21:44:03 +00:00
|
|
|
* Interrupt leaves frame intact in FIFO.
|
2007-03-15 21:26:00 +00:00
|
|
|
*/
|
|
|
|
int
|
2008-07-02 09:05:40 +00:00
|
|
|
cc2420_interrupt(void)
|
2007-03-15 21:26:00 +00:00
|
|
|
{
|
2010-06-23 10:15:28 +00:00
|
|
|
CC2420_CLEAR_FIFOP_INT();
|
2008-07-02 09:05:40 +00:00
|
|
|
process_poll(&cc2420_process);
|
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 21:48:39 +00:00
|
|
|
|
2010-12-16 22:40:52 +00:00
|
|
|
last_packet_timestamp = cc2420_sfd_start_time;
|
2007-03-15 21:26:00 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2008-07-02 09:05:40 +00:00
|
|
|
PROCESS_THREAD(cc2420_process, ev, data)
|
2007-03-15 21:26:00 +00: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 21:48:39 +00:00
|
|
|
int len;
|
2007-03-15 21:26:00 +00:00
|
|
|
PROCESS_BEGIN();
|
|
|
|
|
2008-07-02 09:05:40 +00:00
|
|
|
PRINTF("cc2420_process: started\n");
|
2009-08-19 12:00:04 +00:00
|
|
|
|
2007-03-15 21:26:00 +00:00
|
|
|
while(1) {
|
2015-09-21 20:03:51 +00:00
|
|
|
PROCESS_YIELD_UNTIL(!poll_mode && ev == PROCESS_EVENT_POLL);
|
2013-11-19 07:29:23 +00: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 21:48:39 +00:00
|
|
|
PRINTF("cc2420_process: calling receiver callback\n");
|
|
|
|
|
|
|
|
packetbuf_clear();
|
2010-12-16 22:40:52 +00:00
|
|
|
packetbuf_set_attr(PACKETBUF_ATTR_TIMESTAMP, last_packet_timestamp);
|
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 21:48:39 +00:00
|
|
|
len = cc2420_read(packetbuf_dataptr(), PACKETBUF_SIZE);
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2011-01-09 21:09:28 +00:00
|
|
|
packetbuf_set_datalen(len);
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2017-05-17 13:09:19 +00:00
|
|
|
NETSTACK_MAC.input();
|
2007-03-15 21:26:00 +00: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 21:48:39 +00:00
|
|
|
static int
|
2008-07-02 09:05:40 +00:00
|
|
|
cc2420_read(void *buf, unsigned short bufsize)
|
2007-03-15 21:26:00 +00:00
|
|
|
{
|
2013-05-24 10:04:17 +00:00
|
|
|
uint8_t footer[FOOTER_LEN];
|
2008-08-26 21:44:03 +00:00
|
|
|
uint8_t len;
|
2009-08-19 12:00:04 +00:00
|
|
|
|
2010-06-23 10:15:28 +00:00
|
|
|
if(!CC2420_FIFOP_IS_1) {
|
2010-03-19 13:18:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2007-05-15 07:53:09 +00:00
|
|
|
GET_LOCK();
|
2010-03-14 22:45:20 +00:00
|
|
|
|
2013-06-06 13:54:20 +00:00
|
|
|
getrxdata(&len, 1);
|
2007-05-15 07:53:09 +00:00
|
|
|
|
2008-07-02 09:05:40 +00:00
|
|
|
if(len > CC2420_MAX_PACKET_LEN) {
|
2007-05-15 07:53:09 +00:00
|
|
|
/* Oops, we must be out of sync. */
|
2013-06-05 14:50:21 +00:00
|
|
|
} else if(len <= FOOTER_LEN) {
|
2017-06-22 16:27:04 +00:00
|
|
|
/* Packet too short */
|
2013-06-05 14:50:21 +00:00
|
|
|
} else if(len - FOOTER_LEN > bufsize) {
|
2017-06-22 16:27:04 +00:00
|
|
|
/* Packet too long */
|
2008-08-26 21:44:03 +00:00
|
|
|
} else {
|
2014-02-09 22:16:48 +00:00
|
|
|
getrxdata((uint8_t *) buf, len - FOOTER_LEN);
|
2013-06-05 14:50:21 +00:00
|
|
|
getrxdata(footer, FOOTER_LEN);
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2013-06-05 14:50:21 +00:00
|
|
|
if(footer[1] & FOOTER1_CRC_OK) {
|
2014-02-20 12:34:25 +00:00
|
|
|
cc2420_last_rssi = footer[0] + RSSI_OFFSET;
|
2013-06-05 14:50:21 +00:00
|
|
|
cc2420_last_correlation = footer[1] & FOOTER1_CORRELATION;
|
2015-09-21 20:03:51 +00:00
|
|
|
if(!poll_mode) {
|
|
|
|
/* Not in poll mode: packetbuf should not be accessed in interrupt context.
|
|
|
|
* In poll mode, the last packet RSSI and link quality can be obtained through
|
|
|
|
* RADIO_PARAM_LAST_RSSI and RADIO_PARAM_LAST_LINK_QUALITY */
|
|
|
|
packetbuf_set_attr(PACKETBUF_ATTR_RSSI, cc2420_last_rssi);
|
|
|
|
packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, cc2420_last_correlation);
|
|
|
|
}
|
2010-04-04 07:49:30 +00:00
|
|
|
} else {
|
2013-06-05 14:50:21 +00:00
|
|
|
len = FOOTER_LEN;
|
2010-04-04 07:49:30 +00:00
|
|
|
}
|
2015-09-21 20:03:51 +00:00
|
|
|
|
|
|
|
if(!poll_mode) {
|
|
|
|
if(CC2420_FIFOP_IS_1) {
|
|
|
|
if(!CC2420_FIFO_IS_1) {
|
|
|
|
/* Clean up in case of FIFO overflow! This happens for every
|
|
|
|
* full length frame and is signaled by FIFOP = 1 and FIFO =
|
|
|
|
* 0. */
|
|
|
|
flushrx();
|
|
|
|
} else {
|
|
|
|
/* Another packet has been received and needs attention. */
|
|
|
|
process_poll(&cc2420_process);
|
|
|
|
}
|
2013-06-05 14:50:21 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2013-06-05 14:50:21 +00:00
|
|
|
RELEASE_LOCK();
|
|
|
|
return len - FOOTER_LEN;
|
2007-03-15 21:26:00 +00:00
|
|
|
}
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2013-06-05 14:50:21 +00:00
|
|
|
flushrx();
|
2007-05-15 07:53:09 +00:00
|
|
|
RELEASE_LOCK();
|
2013-06-05 14:50:21 +00:00
|
|
|
return 0;
|
2007-05-15 07:53:09 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2008-07-02 09:05:40 +00:00
|
|
|
cc2420_set_txpower(uint8_t power)
|
2007-05-15 07:53:09 +00:00
|
|
|
{
|
|
|
|
GET_LOCK();
|
2009-08-19 15:05:05 +00:00
|
|
|
set_txpower(power);
|
2007-05-15 07:53:09 +00:00
|
|
|
RELEASE_LOCK();
|
2007-03-15 21:26:00 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-12-05 13:21:05 +00:00
|
|
|
int
|
2008-07-02 09:05:40 +00:00
|
|
|
cc2420_get_txpower(void)
|
2008-01-14 16:19:25 +00:00
|
|
|
{
|
2010-03-14 22:45:20 +00:00
|
|
|
int power;
|
|
|
|
GET_LOCK();
|
|
|
|
power = (int)(getreg(CC2420_TXCTRL) & 0x001f);
|
|
|
|
RELEASE_LOCK();
|
|
|
|
return power;
|
2008-01-14 16:19:25 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
int
|
2008-07-02 09:05:40 +00:00
|
|
|
cc2420_rssi(void)
|
2007-12-05 13:21:05 +00:00
|
|
|
{
|
|
|
|
int rssi;
|
|
|
|
int radio_was_off = 0;
|
2009-08-19 12:00:04 +00:00
|
|
|
|
2010-09-22 22:01:53 +00:00
|
|
|
if(locked) {
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2010-03-14 22:45:20 +00:00
|
|
|
GET_LOCK();
|
|
|
|
|
2007-12-05 13:21:05 +00:00
|
|
|
if(!receive_on) {
|
|
|
|
radio_was_off = 1;
|
2008-07-02 09:05:40 +00:00
|
|
|
cc2420_on();
|
2007-12-05 13:21:05 +00:00
|
|
|
}
|
2014-04-11 10:58:49 +00:00
|
|
|
wait_for_status(BV(CC2420_RSSI_VALID));
|
2007-12-05 13:21:05 +00:00
|
|
|
|
2014-02-20 12:34:25 +00:00
|
|
|
rssi = (int)((signed char) getreg(CC2420_RSSI));
|
|
|
|
rssi += RSSI_OFFSET;
|
2007-12-05 13:21:05 +00:00
|
|
|
|
|
|
|
if(radio_was_off) {
|
2008-07-02 09:05:40 +00:00
|
|
|
cc2420_off();
|
2007-12-05 13:21:05 +00:00
|
|
|
}
|
2010-03-14 22:45:20 +00:00
|
|
|
RELEASE_LOCK();
|
2007-12-05 13:21:05 +00:00
|
|
|
return rssi;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
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 21:48:39 +00: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;
|
|
|
|
}
|
2010-03-14 22:45:20 +00:00
|
|
|
|
|
|
|
GET_LOCK();
|
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 21:48:39 +00:00
|
|
|
if(!receive_on) {
|
|
|
|
radio_was_off = 1;
|
|
|
|
cc2420_on();
|
|
|
|
}
|
2010-02-23 18:24:49 +00:00
|
|
|
|
2010-03-09 13:18:16 +00:00
|
|
|
/* Make sure that the radio really got turned on. */
|
|
|
|
if(!receive_on) {
|
2010-03-14 22:45:20 +00:00
|
|
|
RELEASE_LOCK();
|
2010-12-05 00:14:24 +00:00
|
|
|
if(radio_was_off) {
|
|
|
|
cc2420_off();
|
|
|
|
}
|
2010-03-09 13:18:16 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2010-02-23 18:24:49 +00:00
|
|
|
|
2014-04-11 10:58:49 +00:00
|
|
|
wait_for_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 21:48:39 +00:00
|
|
|
|
2010-06-23 10:15:28 +00:00
|
|
|
cca = CC2420_CCA_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 21:48:39 +00:00
|
|
|
|
|
|
|
if(radio_was_off) {
|
|
|
|
cc2420_off();
|
|
|
|
}
|
2010-03-14 22:45:20 +00:00
|
|
|
RELEASE_LOCK();
|
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 21:48:39 +00:00
|
|
|
return cca;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
int
|
|
|
|
cc2420_receiving_packet(void)
|
|
|
|
{
|
2010-06-23 10:15:28 +00:00
|
|
|
return CC2420_SFD_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 21:48:39 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static int
|
|
|
|
pending_packet(void)
|
|
|
|
{
|
2010-06-23 10:15:28 +00:00
|
|
|
return CC2420_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 21:48:39 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2015-02-19 10:26:43 +00:00
|
|
|
static int
|
|
|
|
get_cca_threshold(void)
|
|
|
|
{
|
|
|
|
int value;
|
|
|
|
|
|
|
|
GET_LOCK();
|
|
|
|
value = (int8_t)(getreg(CC2420_RSSI) >> 8);
|
|
|
|
RELEASE_LOCK();
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
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 21:48:39 +00:00
|
|
|
void
|
2010-02-23 18:24:49 +00:00
|
|
|
cc2420_set_cca_threshold(int value)
|
|
|
|
{
|
|
|
|
uint16_t shifted = value << 8;
|
2010-03-14 22:45:20 +00:00
|
|
|
GET_LOCK();
|
2010-02-23 18:24:49 +00:00
|
|
|
setreg(CC2420_RSSI, shifted);
|
2010-03-14 22:45:20 +00:00
|
|
|
RELEASE_LOCK();
|
2010-02-23 18:24:49 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2015-09-21 20:03:51 +00:00
|
|
|
/* Set or unset frame autoack */
|
|
|
|
static void
|
|
|
|
set_auto_ack(uint8_t enable)
|
|
|
|
{
|
|
|
|
GET_LOCK();
|
|
|
|
|
|
|
|
uint16_t reg = getreg(CC2420_MDMCTRL0);
|
|
|
|
if(enable) {
|
|
|
|
reg |= AUTOACK;
|
|
|
|
} else {
|
|
|
|
reg &= ~(AUTOACK);
|
|
|
|
}
|
|
|
|
|
|
|
|
setreg(CC2420_MDMCTRL0, reg);
|
|
|
|
RELEASE_LOCK();
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/* Set or unset frame filtering */
|
|
|
|
static void
|
|
|
|
set_frame_filtering(uint8_t enable)
|
|
|
|
{
|
|
|
|
GET_LOCK();
|
|
|
|
|
|
|
|
/* Turn on/off address decoding. */
|
|
|
|
uint16_t reg = getreg(CC2420_MDMCTRL0);
|
|
|
|
if(enable) {
|
|
|
|
reg |= ADR_DECODE;
|
|
|
|
} else {
|
|
|
|
reg &= ~(ADR_DECODE);
|
|
|
|
}
|
|
|
|
|
|
|
|
setreg(CC2420_MDMCTRL0, reg);
|
|
|
|
RELEASE_LOCK();
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/* Enable or disable radio interrupts (both FIFOP and SFD timer capture) */
|
|
|
|
static void
|
|
|
|
set_poll_mode(uint8_t enable)
|
|
|
|
{
|
|
|
|
GET_LOCK();
|
|
|
|
poll_mode = enable;
|
|
|
|
if(enable) {
|
|
|
|
/* Disable FIFOP interrupt */
|
|
|
|
CC2420_CLEAR_FIFOP_INT();
|
|
|
|
CC2420_DISABLE_FIFOP_INT();
|
|
|
|
} else {
|
|
|
|
/* Initialize and enable FIFOP interrupt */
|
|
|
|
CC2420_FIFOP_INT_INIT();
|
|
|
|
CC2420_ENABLE_FIFOP_INT();
|
|
|
|
CC2420_CLEAR_FIFOP_INT();
|
|
|
|
}
|
|
|
|
RELEASE_LOCK();
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/* Enable or disable CCA before sending */
|
|
|
|
static void
|
|
|
|
set_send_on_cca(uint8_t enable)
|
|
|
|
{
|
|
|
|
send_on_cca = enable;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|