Implementation of the ContikiMAC power-saving radio duty cycling protocol
#include "contiki-conf.h"
#include "dev/leds.h"
#include "dev/radio.h"
#include "dev/watchdog.h"
#include "lib/random.h"
#include "net/mac/mac-sequence.h"
#include "net/mac/contikimac/contikimac.h"
#include "net/netstack.h"
#include "net/rime/rime.h"
#include "sys/compower.h"
#include "sys/pt.h"
#include "sys/rtimer.h"
#include "rtimer-arch.h"
#include <string.h>
#include <stdio.h>
#include "net/mac/phase.h"
Data Structures | |
struct | hdr |
Functions | |
static int | broadcast_rate_drop (void) |
uint16_t | contikimac_debug_print (void) |
static unsigned short | duty_cycle (void) |
static void | init (void) |
static void | input_packet (void) |
static void | off (void) |
static void | on (void) |
static char | powercycle (struct rtimer *t, void *ptr) |
static void | powercycle_turn_radio_off (void) |
static void | powercycle_turn_radio_on (void) |
static void | qsend_list (mac_callback_t sent, void *ptr, struct rdc_buf_list *buf_list) |
static void | qsend_packet (mac_callback_t sent, void *ptr) |
static void | recv_burst_off (void *ptr) |
static void | schedule_powercycle (struct rtimer *t, rtimer_clock_t time) |
static void | schedule_powercycle_fixed (struct rtimer *t, rtimer_clock_t fixed_time) |
static int | send_packet (mac_callback_t mac_callback, void *mac_callback_ptr, struct rdc_buf_list *buf_list, int is_receiver_awake) |
static int | turn_off (int keep_radio_on) |
static int | turn_on (void) |
Variables | |
struct rdc_driver | contikimac_driver |
static volatile uint8_t | contikimac_is_on = 0 |
static volatile uint8_t | contikimac_keep_radio_on = 0 |
static volatile rtimer_clock_t | cycle_start |
static struct pt | pt |
static volatile unsigned char | radio_is_on = 0 |
static struct rtimer | rt |
static int | we_are_receiving_burst = 0 |
static volatile unsigned char | we_are_sending = 0 |
#define _DEBUG_ 0 |
#define ACK_LEN 3 |
Referenced by send_packet().
#define AFTER_ACK_DETECTECT_WAIT_TIME RTIMER_ARCH_SECOND / 1500 |
Referenced by send_packet().
#define CCA_CHECK_TIME RTIMER_ARCH_SECOND / 8192 |
Referenced by powercycle(), and send_packet().
#define CCA_COUNT_MAX 2 |
Referenced by powercycle().
#define CCA_COUNT_MAX_TX 6 |
Referenced by send_packet().
#define CCA_SLEEP_TIME (RTIMER_ARCH_SECOND / 2000) + 1 |
Referenced by powercycle(), and send_packet().
#define CHECK_TIME (CCA_COUNT_MAX * (CCA_CHECK_TIME + CCA_SLEEP_TIME)) |
Referenced by powercycle().
#define CHECK_TIME_TX (CCA_COUNT_MAX_TX * (CCA_CHECK_TIME + CCA_SLEEP_TIME)) |
#define CONTIKIMAC_ID 0x00 |
Referenced by input_packet(), and send_packet().
#define CYCLE_TIME (RTIMER_ARCH_SECOND / NETSTACK_RDC_CHANNEL_CHECK_RATE) |
Referenced by duty_cycle(), init(), powercycle(), send_packet(), and turn_on().
#define DEFAULT_STREAM_TIME (4 * CYCLE_TIME) |
#define GUARD_TIME 10 * CHECK_TIME + CHECK_TIME_TX |
Referenced by send_packet().
#define HARDWARE_ACK 0 |
Referenced by send_packet().
#define INTER_PACKET_DEADLINE CLOCK_SECOND / 32 |
Referenced by input_packet().
#define INTER_PACKET_INTERVAL RTIMER_ARCH_SECOND / 2500 |
Referenced by send_packet().
#define LISTEN_TIME_AFTER_PACKET_DETECTED RTIMER_ARCH_SECOND / 80 |
Referenced by powercycle().
#define MAX_NONACTIVITY_PERIODS 10 |
Referenced by powercycle().
#define MAX_PHASE_STROBE_TIME RTIMER_ARCH_SECOND / 60 |
Referenced by send_packet().
#define MAX_SILENCE_PERIODS 5 |
Referenced by powercycle().
#define MIN | ( | a, | |
b | |||
) | ((a) < (b)? (a) : (b)) |
#define PRINTDEBUG | ( | ... | ) |
Referenced by input_packet(), and send_packet().
#define PRINTF | ( | ... | ) |
Referenced by input_packet(), schedule_powercycle(), schedule_powercycle_fixed(), and send_packet().
#define RDC_CONF_HARDWARE_ACK 0 |
#define RDC_CONF_HARDWARE_CSMA 0 |
#define RDC_CONF_MCU_SLEEP 0 |
#define SHORTEST_PACKET_SIZE 43 |
Referenced by send_packet().
#define STROBE_TIME (CYCLE_TIME + 2 * CHECK_TIME) |
Referenced by send_packet().
#define WITH_CONTIKIMAC_HEADER 1 |
#define WITH_DEEP_SLEEP 0 |
#define WITH_FAST_SLEEP 1 |
Referenced by powercycle().
#define WITH_PHASE_OPTIMIZATION 1 |
|
static |
References CLOCK_SECOND, timer_expired(), and timer_set().
Referenced by send_packet().
uint16_t contikimac_debug_print | ( | void | ) |
|
static |
References CLOCK_SECOND, and CYCLE_TIME.
|
static |
References contikimac_is_on, CYCLE_TIME, NULL, phase_init(), powercycle(), PT_INIT, radio_is_on, rt, RTIMER_NOW, and rtimer_set().
|
static |
References compower_accumulate(), compower_attrconv(), compower_clear(), CONTIKIMAC_ID, ctimer_set(), ctimer_stop(), hdr::id, mac_driver::input, INTER_PACKET_DEADLINE, hdr::len, linkaddr_cmp(), linkaddr_node_addr, linkaddr_null, mac_sequence_is_duplicate(), mac_sequence_register_seqno(), NETSTACK_DECRYPT, NETSTACK_FRAMER, NETSTACK_MAC, NULL, off(), on(), packetbuf_addr(), PACKETBUF_ADDR_RECEIVER, packetbuf_attr(), PACKETBUF_ATTR_PENDING, packetbuf_datalen(), packetbuf_dataptr(), packetbuf_hdrreduce(), packetbuf_set_datalen(), packetbuf_totlen(), framer::parse, PRINTDEBUG, PRINTF, recv_burst_off(), and we_are_receiving_burst.
|
static |
References contikimac_is_on, contikimac_keep_radio_on, NETSTACK_RADIO, radio_driver::off, and radio_is_on.
Referenced by input_packet(), powercycle_turn_radio_off(), recv_burst_off(), and send_packet().
|
static |
References contikimac_is_on, NETSTACK_RADIO, radio_driver::on, and radio_is_on.
Referenced by input_packet(), powercycle_turn_radio_on(), and send_packet().
|
static |
References CCA_CHECK_TIME, CCA_COUNT_MAX, CCA_SLEEP_TIME, radio_driver::channel_clear, CHECK_TIME, count, cycle_start, CYCLE_TIME, LISTEN_TIME_AFTER_PACKET_DETECTED, MAX_NONACTIVITY_PERIODS, MAX_SILENCE_PERIODS, NETSTACK_RADIO, NETSTACK_RDC_CHANNEL_CHECK_RATE, radio_driver::on, radio_driver::pending_packet, powercycle_turn_radio_off(), powercycle_turn_radio_on(), PT_BEGIN, PT_END, PT_YIELD, radio_is_on, radio_driver::receiving_packet, rtimer_arch_sleep(), RTIMER_CLOCK_LT, RTIMER_NOW, schedule_powercycle(), schedule_powercycle_fixed(), radio_driver::sleep, timer::start, we_are_receiving_burst, we_are_sending, and WITH_FAST_SLEEP.
Referenced by init(), schedule_powercycle(), schedule_powercycle_fixed(), and turn_on().
|
static |
References compower_accumulate(), compower_idle_activity, off(), radio_is_on, we_are_receiving_burst, and we_are_sending.
Referenced by powercycle().
|
static |
References on(), we_are_receiving_burst, and we_are_sending.
Referenced by powercycle().
|
static |
|
static |
References mac_call_sent_callback(), MAC_TX_DEFERRED, NULL, ret, and send_packet().
|
static |
References off(), and we_are_receiving_burst.
Referenced by input_packet().
|
static |
References contikimac_is_on, NULL, powercycle(), PRINTF, RTIMER_CLOCK_LT, RTIMER_NOW, RTIMER_OK, rtimer_set(), and RTIMER_TIME.
Referenced by powercycle().
|
static |
References contikimac_is_on, NULL, powercycle(), PRINTF, RTIMER_CLOCK_LT, RTIMER_NOW, RTIMER_OK, and rtimer_set().
Referenced by powercycle().
|
static |
References ACK_LEN, AFTER_ACK_DETECTECT_WAIT_TIME, broadcast_rate_drop(), CCA_CHECK_TIME, CCA_COUNT_MAX_TX, CCA_SLEEP_TIME, radio_driver::channel_clear, compower_accumulate(), compower_attrconv(), compower_clear(), CONTIKIMAC_ID, contikimac_is_on, contikimac_keep_radio_on, framer::create, CYCLE_TIME, GUARD_TIME, HARDWARE_ACK, i, hdr::id, INTER_PACKET_INTERVAL, hdr::len, len, linkaddr_cmp(), linkaddr_node_addr, linkaddr_null, MAC_TX_COLLISION, MAC_TX_DEFERRED, MAC_TX_ERR_FATAL, MAC_TX_NOACK, MAC_TX_OK, MAX_PHASE_STROBE_TIME, NETSTACK_ENCRYPT, NETSTACK_FRAMER, NETSTACK_RADIO, off(), on(), packetbuf_addr(), PACKETBUF_ADDR_RECEIVER, PACKETBUF_ADDR_SENDER, packetbuf_attr(), PACKETBUF_ATTR_MAC_ACK, PACKETBUF_ATTR_MAC_SEQNO, packetbuf_compact(), packetbuf_datalen(), packetbuf_dataptr(), packetbuf_hdr_remove(), packetbuf_hdralloc(), packetbuf_hdrptr(), packetbuf_set_addr(), packetbuf_set_attr(), packetbuf_totlen(), radio_driver::pending_packet, PHASE_DEFERRED, PHASE_UNKNOWN, phase_update(), phase_wait(), radio_driver::prepare, PRINTDEBUG, PRINTF, ptr, RADIO_TX_COLLISION, RADIO_TX_NOACK, RADIO_TX_OK, radio_driver::read, radio_driver::receiving_packet, ret, RTIMER_CLOCK_LT, RTIMER_NOW, SHORTEST_PACKET_SIZE, STROBE_TIME, radio_driver::transmit, wdt_reset_count(), and we_are_sending.
Referenced by qsend_list(), and qsend_packet().
|
static |
References contikimac_is_on, contikimac_keep_radio_on, NETSTACK_RADIO, radio_driver::off, radio_driver::on, and radio_is_on.
|
static |
References contikimac_is_on, contikimac_keep_radio_on, CYCLE_TIME, NULL, powercycle(), rt, RTIMER_NOW, and rtimer_set().
struct rdc_driver contikimac_driver |
|
static |
Referenced by init(), off(), on(), schedule_powercycle(), schedule_powercycle_fixed(), send_packet(), turn_off(), and turn_on().
|
static |
Referenced by off(), send_packet(), turn_off(), and turn_on().
|
static |
Referenced by powercycle().
|
static |
Referenced by init(), off(), on(), powercycle(), powercycle_turn_radio_off(), and turn_off().
|
static |
Referenced by handle_incoming_rerr(), handle_incoming_rrep(), handle_incoming_rreq(), init(), new_route(), turn_on(), uaodv_bad_dest(), and uip_over_mesh_send().
|
static |
Referenced by input_packet(), powercycle(), powercycle_turn_radio_off(), powercycle_turn_radio_on(), qsend_list(), and recv_burst_off().
|
static |
Referenced by powercycle(), powercycle_turn_radio_off(), powercycle_turn_radio_on(), and send_packet().