Microchip® Advanced Software Framework

contikimac.c File Reference

    Implementation of the ContikiMAC power-saving radio duty cycling protocol
Author
Adam Dunkels adam@.nosp@m.sics.nosp@m..se Niclas Finne nfi@s.nosp@m.ics..nosp@m.se Joakim Eriksson joaki.nosp@m.me@s.nosp@m.ics.s.nosp@m.e
#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
 

Macros

#define _DEBUG_   0
 
#define ACK_LEN   3
 
#define AFTER_ACK_DETECTECT_WAIT_TIME   RTIMER_ARCH_SECOND / 1500
 
#define CCA_CHECK_TIME   RTIMER_ARCH_SECOND / 8192
 
#define CCA_COUNT_MAX   2
 
#define CCA_COUNT_MAX_TX   6
 
#define CCA_SLEEP_TIME   (RTIMER_ARCH_SECOND / 2000) + 1
 
#define CHECK_TIME   (CCA_COUNT_MAX * (CCA_CHECK_TIME + CCA_SLEEP_TIME))
 
#define CHECK_TIME_TX   (CCA_COUNT_MAX_TX * (CCA_CHECK_TIME + CCA_SLEEP_TIME))
 
#define CONTIKIMAC_ID   0x00
 
#define CYCLE_TIME   (RTIMER_ARCH_SECOND / NETSTACK_RDC_CHANNEL_CHECK_RATE)
 
#define DEFAULT_STREAM_TIME   (4 * CYCLE_TIME)
 
#define GUARD_TIME   10 * CHECK_TIME + CHECK_TIME_TX
 
#define HARDWARE_ACK   0
 
#define INTER_PACKET_DEADLINE   CLOCK_SECOND / 32
 
#define INTER_PACKET_INTERVAL   RTIMER_ARCH_SECOND / 2500
 
#define LISTEN_TIME_AFTER_PACKET_DETECTED   RTIMER_ARCH_SECOND / 80
 
#define MAX_NONACTIVITY_PERIODS   10
 
#define MAX_PHASE_STROBE_TIME   RTIMER_ARCH_SECOND / 60
 
#define MAX_SILENCE_PERIODS   5
 
#define MIN(a, b)   ((a) < (b)? (a) : (b))
 
#define PRINTDEBUG(...)
 
#define PRINTF(...)
 
#define RDC_CONF_HARDWARE_ACK   0
 
#define RDC_CONF_HARDWARE_CSMA   0
 
#define RDC_CONF_MCU_SLEEP   0
 
#define SHORTEST_PACKET_SIZE   43
 
#define STROBE_TIME   (CYCLE_TIME + 2 * CHECK_TIME)
 
#define WITH_CONTIKIMAC_HEADER   1
 
#define WITH_DEEP_SLEEP   0
 
#define WITH_FAST_SLEEP   1
 
#define WITH_PHASE_OPTIMIZATION   1
 

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)
#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,
 
)    ((a) < (b)? (a) : (b))
#define PRINTDEBUG (   ...)

Referenced by input_packet(), and send_packet().

#define PRINTF (   ...)
#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 int broadcast_rate_drop ( void  )
static

References CLOCK_SECOND, timer_expired(), and timer_set().

Referenced by send_packet().

uint16_t contikimac_debug_print ( void  )
static unsigned short duty_cycle ( void  )
static

References CLOCK_SECOND, and CYCLE_TIME.

static void init ( void  )
static
static void on ( void  )
static
static void powercycle_turn_radio_off ( void  )
static
static void powercycle_turn_radio_on ( void  )
static

References on(), we_are_receiving_burst, and we_are_sending.

Referenced by powercycle().

static void qsend_packet ( mac_callback_t  sent,
void *  ptr 
)
static
static void recv_burst_off ( void *  ptr)
static

References off(), and we_are_receiving_burst.

Referenced by input_packet().

static void schedule_powercycle ( struct rtimer t,
rtimer_clock_t  time 
)
static
static void schedule_powercycle_fixed ( struct rtimer t,
rtimer_clock_t  fixed_time 
)
static
static int turn_off ( int  keep_radio_on)
static
static int turn_on ( void  )
static

struct rdc_driver contikimac_driver
Initial value:
= {
"ContikiMAC",
}
static int turn_off(int keep_radio_on)
Definition: contikimac.c:1052
static int turn_on(void)
Definition: contikimac.c:1040
goto init
Definition: dhcpc.c:392
static unsigned short duty_cycle(void)
Definition: contikimac.c:1066
static void qsend_packet(mac_callback_t sent, void *ptr)
Definition: contikimac.c:874
static void input_packet(void)
Definition: contikimac.c:942
static void qsend_list(mac_callback_t sent, void *ptr, struct rdc_buf_list *buf_list)
Definition: contikimac.c:883
volatile uint8_t contikimac_is_on = 0
static
volatile uint8_t contikimac_keep_radio_on = 0
static

Referenced by off(), send_packet(), turn_off(), and turn_on().

volatile rtimer_clock_t cycle_start
static

Referenced by powercycle().

struct pt pt
static
volatile unsigned char radio_is_on = 0
static
volatile unsigned char we_are_sending = 0
static