2010-01-25 12:46: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
|
|
|
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
2010-01-25 12:46:44 +01:00
|
|
|
* 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.
|
|
|
|
*
|
2011-01-25 15:24:38 +01:00
|
|
|
* $Id: csma.c,v 1.27 2011/01/25 14:24:38 adamdunkels Exp $
|
2010-01-25 12:46:44 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
2010-02-28 11:07:17 +01:00
|
|
|
* A Carrier Sense Multiple Access (CSMA) MAC layer
|
2010-01-25 12:46:44 +01:00
|
|
|
* \author
|
|
|
|
* Adam Dunkels <adam@sics.se>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "net/mac/csma.h"
|
2010-06-14 21:19:16 +02:00
|
|
|
#include "net/packetbuf.h"
|
|
|
|
#include "net/queuebuf.h"
|
2010-06-14 09:34:36 +02:00
|
|
|
|
|
|
|
#include "sys/ctimer.h"
|
2010-01-25 12:46:44 +01:00
|
|
|
|
|
|
|
#include "lib/random.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"
|
|
|
|
|
2010-01-25 12:46:44 +01:00
|
|
|
#include "lib/list.h"
|
|
|
|
#include "lib/memb.h"
|
|
|
|
|
2010-01-27 08:36:31 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2010-12-14 08:57:14 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2010-03-09 14:23:58 +01:00
|
|
|
#define DEBUG 0
|
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 DEBUG
|
|
|
|
#include <stdio.h>
|
|
|
|
#define PRINTF(...) printf(__VA_ARGS__)
|
|
|
|
#else /* DEBUG */
|
|
|
|
#define PRINTF(...)
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2010-03-26 13:29:29 +01:00
|
|
|
#ifndef CSMA_MAX_MAC_TRANSMISSIONS
|
|
|
|
#ifdef CSMA_CONF_MAX_MAC_TRANSMISSIONS
|
|
|
|
#define CSMA_MAX_MAC_TRANSMISSIONS CSMA_CONF_MAX_MAC_TRANSMISSIONS
|
|
|
|
#else
|
2011-01-18 17:03:57 +01:00
|
|
|
#define CSMA_MAX_MAC_TRANSMISSIONS 3
|
2010-03-26 13:29:29 +01:00
|
|
|
#endif /* CSMA_CONF_MAX_MAC_TRANSMISSIONS */
|
|
|
|
#endif /* CSMA_MAX_MAC_TRANSMISSIONS */
|
|
|
|
|
|
|
|
#if CSMA_MAX_MAC_TRANSMISSIONS < 1
|
|
|
|
#error CSMA_CONF_MAX_MAC_TRANSMISSIONS must be at least 1.
|
|
|
|
#error Change CSMA_CONF_MAX_MAC_TRANSMISSIONS in contiki-conf.h or in your Makefile.
|
|
|
|
#endif /* CSMA_CONF_MAX_MAC_TRANSMISSIONS < 1 */
|
|
|
|
|
2010-01-25 12:46:44 +01:00
|
|
|
struct queued_packet {
|
|
|
|
struct queued_packet *next;
|
|
|
|
struct queuebuf *buf;
|
2010-12-14 08:57:14 +01:00
|
|
|
/* struct ctimer retransmit_timer;*/
|
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
|
|
|
mac_callback_t sent;
|
|
|
|
void *cptr;
|
2010-02-28 09:35:16 +01:00
|
|
|
uint8_t transmissions, max_transmissions;
|
2010-03-09 14:20:08 +01:00
|
|
|
uint8_t collisions, deferrals;
|
2010-01-25 12:46:44 +01:00
|
|
|
};
|
|
|
|
|
2010-12-16 23:44:02 +01:00
|
|
|
#define MAX_QUEUED_PACKETS 6
|
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
|
|
|
MEMB(packet_memb, struct queued_packet, MAX_QUEUED_PACKETS);
|
2010-12-14 08:57:14 +01:00
|
|
|
LIST(queued_packet_list);
|
|
|
|
|
|
|
|
static struct ctimer transmit_timer;
|
2010-01-25 12:46:44 +01:00
|
|
|
|
2011-01-13 20:06:22 +01:00
|
|
|
static uint8_t rdc_is_transmitting;
|
|
|
|
|
2010-03-09 21:38:55 +01:00
|
|
|
static void packet_sent(void *ptr, int status, int num_transmissions);
|
2010-01-25 12:46:44 +01:00
|
|
|
|
2010-12-16 23:44:02 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static clock_time_t
|
|
|
|
default_timebase(void)
|
|
|
|
{
|
|
|
|
clock_time_t time;
|
|
|
|
/* The retransmission time must be proportional to the channel
|
|
|
|
check interval of the underlying radio duty cycling layer. */
|
|
|
|
time = NETSTACK_RDC.channel_check_interval();
|
|
|
|
|
|
|
|
/* If the radio duty cycle has no channel check interval (i.e., it
|
|
|
|
does not turn the radio off), we make the retransmission time
|
|
|
|
proportional to the configured MAC channel check rate. */
|
|
|
|
if(time == 0) {
|
|
|
|
time = CLOCK_SECOND / NETSTACK_RDC_CHANNEL_CHECK_RATE;
|
|
|
|
}
|
|
|
|
return time;
|
|
|
|
}
|
2010-01-25 12:46:44 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-03-09 21:38:55 +01:00
|
|
|
static void
|
2010-12-14 08:57:14 +01:00
|
|
|
transmit_queued_packet(void *ptr)
|
2010-03-09 21:38:55 +01:00
|
|
|
{
|
2010-12-14 08:57:14 +01:00
|
|
|
/* struct queued_packet *q = ptr;*/
|
|
|
|
struct queued_packet *q;
|
|
|
|
|
2011-01-13 20:06:22 +01:00
|
|
|
/* Don't transmit a packet if the RDC is still transmitting the
|
|
|
|
previous one. */
|
|
|
|
if(rdc_is_transmitting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-16 23:44:02 +01:00
|
|
|
// printf("q %d\n", list_length(queued_packet_list));
|
|
|
|
|
2010-12-14 08:57:14 +01:00
|
|
|
q = list_head(queued_packet_list);
|
2010-03-09 21:38:55 +01:00
|
|
|
|
2010-12-14 08:57:14 +01:00
|
|
|
if(q != NULL) {
|
|
|
|
queuebuf_to_packetbuf(q->buf);
|
2010-12-16 23:44:02 +01:00
|
|
|
PRINTF("csma: sending number %d %p, queue len %d\n", q->transmissions, q,
|
|
|
|
list_length(queued_packet_list));
|
|
|
|
// printf("s %d\n", packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[0]);
|
2011-01-13 20:06:22 +01:00
|
|
|
rdc_is_transmitting = 1;
|
2010-12-14 08:57:14 +01:00
|
|
|
NETSTACK_RDC.send(packet_sent, q);
|
|
|
|
}
|
2010-03-09 21:38:55 +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 void
|
2010-12-14 08:57:14 +01:00
|
|
|
start_transmission_timer(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 22:48:39 +01:00
|
|
|
{
|
2010-12-16 23:44:02 +01:00
|
|
|
PRINTF("csma: start_transmission_timer, queue len %d\n",
|
|
|
|
list_length(queued_packet_list));
|
2010-12-14 08:57:14 +01:00
|
|
|
if(list_length(queued_packet_list) > 0) {
|
|
|
|
if(ctimer_expired(&transmit_timer)) {
|
2010-12-16 23:44:02 +01:00
|
|
|
ctimer_set(&transmit_timer, 0,
|
|
|
|
transmit_queued_packet, NULL);
|
2010-12-14 08:57:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
free_queued_packet(void)
|
|
|
|
{
|
|
|
|
struct queued_packet *q;
|
|
|
|
|
2010-12-16 23:44:02 +01:00
|
|
|
// printf("q %d\n", list_length(queued_packet_list));
|
2011-01-13 20:06:22 +01:00
|
|
|
|
2010-12-14 08:57:14 +01:00
|
|
|
q = list_head(queued_packet_list);
|
|
|
|
|
|
|
|
if(q != NULL) {
|
|
|
|
queuebuf_free(q->buf);
|
|
|
|
list_remove(queued_packet_list, q);
|
|
|
|
memb_free(&packet_memb, q);
|
2010-12-16 23:44:02 +01:00
|
|
|
PRINTF("csma: free_queued_packet, queue length %d\n",
|
|
|
|
list_length(queued_packet_list));
|
2010-12-14 08:57:14 +01:00
|
|
|
if(list_length(queued_packet_list) > 0) {
|
2010-12-16 23:44:02 +01:00
|
|
|
ctimer_set(&transmit_timer, default_timebase(), transmit_queued_packet, NULL);
|
2010-12-14 08:57:14 +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
|
|
|
}
|
2010-03-09 21:38:55 +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 void
|
|
|
|
packet_sent(void *ptr, int status, int num_transmissions)
|
|
|
|
{
|
|
|
|
struct queued_packet *q = ptr;
|
|
|
|
clock_time_t time = 0;
|
|
|
|
mac_callback_t sent;
|
|
|
|
void *cptr;
|
|
|
|
int num_tx;
|
2010-12-14 08:57:14 +01:00
|
|
|
int backoff_transmissions;
|
2010-03-09 14:20:08 +01:00
|
|
|
|
2011-01-13 20:06:22 +01:00
|
|
|
rdc_is_transmitting = 0;
|
|
|
|
|
2010-03-09 14:20:08 +01:00
|
|
|
switch(status) {
|
|
|
|
case MAC_TX_OK:
|
|
|
|
case MAC_TX_NOACK:
|
|
|
|
q->transmissions++;
|
|
|
|
break;
|
|
|
|
case MAC_TX_COLLISION:
|
|
|
|
q->collisions++;
|
|
|
|
break;
|
|
|
|
case MAC_TX_DEFERRED:
|
|
|
|
q->deferrals++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
sent = q->sent;
|
|
|
|
cptr = q->cptr;
|
2010-03-09 14:23:58 +01:00
|
|
|
num_tx = q->transmissions;
|
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
|
|
|
|
2010-03-09 14:20:08 +01:00
|
|
|
if(status == MAC_TX_COLLISION ||
|
|
|
|
status == MAC_TX_NOACK) {
|
2010-03-09 21:38:55 +01:00
|
|
|
|
|
|
|
/* If the transmission was not performed because of a collision or
|
|
|
|
noack, we must retransmit the packet. */
|
|
|
|
|
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
|
|
|
switch(status) {
|
|
|
|
case MAC_TX_COLLISION:
|
|
|
|
PRINTF("csma: rexmit collision %d\n", q->transmissions);
|
2010-10-24 23:07:00 +02:00
|
|
|
break;
|
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
|
|
|
case MAC_TX_NOACK:
|
|
|
|
PRINTF("csma: rexmit noack %d\n", q->transmissions);
|
|
|
|
break;
|
2010-03-09 21:38:55 +01:00
|
|
|
default:
|
|
|
|
PRINTF("csma: rexmit err %d, %d\n", status, q->transmissions);
|
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
|
|
|
}
|
2010-03-09 21:38:55 +01:00
|
|
|
|
|
|
|
/* The retransmission time must be proportional to the channel
|
|
|
|
check interval of the underlying radio duty cycling layer. */
|
2010-12-16 23:44:02 +01:00
|
|
|
time = default_timebase();
|
2010-03-09 21:38:55 +01:00
|
|
|
|
|
|
|
/* The retransmission time uses a linear backoff so that the
|
|
|
|
interval between the transmissions increase with each
|
|
|
|
retransmit. */
|
2010-12-14 08:57:14 +01:00
|
|
|
backoff_transmissions = q->transmissions + 1;
|
|
|
|
|
|
|
|
/* Clamp the number of backoffs so that we don't get a too long
|
|
|
|
timeout here, since that will delay all packets in the
|
|
|
|
queue. */
|
|
|
|
if(backoff_transmissions > 3) {
|
|
|
|
backoff_transmissions = 3;
|
|
|
|
}
|
2010-12-16 23:44:02 +01:00
|
|
|
time = time + (random_rand() % (backoff_transmissions * time));
|
2010-10-03 22:37:32 +02:00
|
|
|
|
2010-12-14 08:57:14 +01:00
|
|
|
if(q->transmissions < q->max_transmissions) {
|
2010-10-03 22:37:32 +02:00
|
|
|
PRINTF("csma: retransmitting with time %lu %p\n", time, q);
|
2010-12-14 08:57:14 +01:00
|
|
|
ctimer_set(&transmit_timer, time,
|
|
|
|
transmit_queued_packet, NULL);
|
2011-04-13 14:10:39 +02:00
|
|
|
|
|
|
|
/* This is needed to correctly attribute energy that we spent
|
|
|
|
transmitting this packet. */
|
2011-06-15 16:10:07 +02:00
|
|
|
queuebuf_update_attr_from_packetbuf(q->buf);
|
2011-04-13 14:10:39 +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
|
|
|
} else {
|
2010-12-14 08:57:14 +01:00
|
|
|
PRINTF("csma: drop with status %d after %d transmissions, %d collisions\n",
|
|
|
|
status, q->transmissions, q->collisions);
|
|
|
|
/* queuebuf_to_packetbuf(q->buf);*/
|
|
|
|
free_queued_packet();
|
2010-02-23 19:49:45 +01:00
|
|
|
mac_call_sent_callback(sent, cptr, status, num_tx);
|
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
|
|
|
}
|
2010-10-24 23:07:00 +02:00
|
|
|
} else {
|
2010-10-14 21:08:39 +02:00
|
|
|
if(status == MAC_TX_OK) {
|
|
|
|
PRINTF("csma: rexmit ok %d\n", q->transmissions);
|
|
|
|
} else {
|
|
|
|
PRINTF("csma: rexmit failed %d: %d\n", q->transmissions, status);
|
|
|
|
}
|
2010-12-14 08:57:14 +01:00
|
|
|
/* queuebuf_to_packetbuf(q->buf);*/
|
|
|
|
free_queued_packet();
|
2010-02-23 19:49:45 +01:00
|
|
|
mac_call_sent_callback(sent, cptr, status, num_tx);
|
2010-01-25 12:46:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static 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 22:48:39 +01:00
|
|
|
send_packet(mac_callback_t sent, void *ptr)
|
2010-01-25 12:46: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
|
|
|
struct queued_packet *q;
|
2010-04-08 11:32:56 +02:00
|
|
|
static uint16_t seqno;
|
|
|
|
|
|
|
|
packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, seqno++);
|
|
|
|
|
2010-12-14 08:57:14 +01:00
|
|
|
/* If the packet is a broadcast, do not allocate a queue
|
|
|
|
entry. Instead, just send it out. */
|
|
|
|
if(!rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
|
2011-01-18 17:03:57 +01:00
|
|
|
&rimeaddr_null)) {
|
2010-12-14 08:57:14 +01:00
|
|
|
|
|
|
|
/* Remember packet for later. */
|
|
|
|
q = memb_alloc(&packet_memb);
|
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(q != NULL) {
|
2010-12-14 08:57:14 +01:00
|
|
|
q->buf = queuebuf_new_from_packetbuf();
|
2011-01-25 15:24:38 +01:00
|
|
|
if(q->buf != NULL) {
|
2010-12-14 08:57:14 +01:00
|
|
|
if(packetbuf_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS) == 0) {
|
|
|
|
/* Use default configuration for max transmissions */
|
|
|
|
q->max_transmissions = CSMA_MAX_MAC_TRANSMISSIONS;
|
|
|
|
} else {
|
|
|
|
q->max_transmissions =
|
|
|
|
packetbuf_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS);
|
|
|
|
}
|
|
|
|
q->transmissions = 0;
|
|
|
|
q->collisions = 0;
|
|
|
|
q->deferrals = 0;
|
|
|
|
q->sent = sent;
|
|
|
|
q->cptr = ptr;
|
2010-12-16 23:44:02 +01:00
|
|
|
if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) ==
|
|
|
|
PACKETBUF_ATTR_PACKET_TYPE_ACK) {
|
|
|
|
list_push(queued_packet_list, q);
|
|
|
|
} else {
|
|
|
|
list_add(queued_packet_list, q);
|
|
|
|
}
|
2010-12-14 08:57:14 +01:00
|
|
|
start_transmission_timer();
|
|
|
|
return;
|
2010-03-26 13:29:29 +01:00
|
|
|
}
|
2010-12-14 08:57:14 +01:00
|
|
|
memb_free(&packet_memb, q);
|
|
|
|
PRINTF("csma: could not allocate queuebuf, will drop if collision or noack\n");
|
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
|
|
|
}
|
2010-12-14 08:57:14 +01:00
|
|
|
PRINTF("csma: could not allocate memb, will drop if collision or noack\n");
|
2010-12-16 23:44:02 +01:00
|
|
|
} else {
|
|
|
|
PRINTF("csma: send broadcast (%d) or without retransmissions (%d)\n",
|
|
|
|
!rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
|
|
|
|
&rimeaddr_null),
|
|
|
|
packetbuf_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS));
|
2010-01-25 12:46: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
|
|
|
NETSTACK_RDC.send(sent, ptr);
|
2010-01-25 12:46:44 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static 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 22:48:39 +01:00
|
|
|
input_packet(void)
|
2010-01-25 12:46: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
|
|
|
NETSTACK_NETWORK.input();
|
2010-01-25 12:46:44 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static int
|
|
|
|
on(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 22:48:39 +01:00
|
|
|
return NETSTACK_RDC.on();
|
2010-01-25 12:46:44 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static int
|
|
|
|
off(int keep_radio_on)
|
|
|
|
{
|
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 NETSTACK_RDC.off(keep_radio_on);
|
2010-01-25 12:46:44 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static unsigned short
|
|
|
|
channel_check_interval(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 22:48:39 +01:00
|
|
|
if(NETSTACK_RDC.channel_check_interval) {
|
|
|
|
return NETSTACK_RDC.channel_check_interval();
|
2010-01-25 12:46:44 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
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 void
|
|
|
|
init(void)
|
|
|
|
{
|
|
|
|
memb_init(&packet_memb);
|
2011-01-13 20:06:22 +01:00
|
|
|
rdc_is_transmitting = 0;
|
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
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-01-25 12:46:44 +01:00
|
|
|
const struct mac_driver csma_driver = {
|
2010-02-23 21:42:45 +01:00
|
|
|
"CSMA",
|
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
|
|
|
init,
|
2010-01-25 12:46:44 +01:00
|
|
|
send_packet,
|
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
|
|
|
input_packet,
|
2010-01-25 12:46:44 +01:00
|
|
|
on,
|
|
|
|
off,
|
|
|
|
channel_check_interval,
|
|
|
|
};
|
|
|
|
/*---------------------------------------------------------------------------*/
|