Contikimac
Contikimac is a Radio Duty Cycling (RDC) protocol designed to provide an energy efficient method of sending and receiving packets. It is designed for use with the CC2420 however can be used with other radios.
Contikimac relies on retransmissions for reliable communications and it is extremely unlikely that a packet will be received on its first transmission as it turns on and off the radio at a rate of several Hertz (usually 8Hz as specified in the platform-specific configuration) looking for activity. During each turn-on, Contikimac carries out several channel clear checks (by default, two) to see if the channel is clear. Contikimac will then turn off the radio if no activity is detected or, if activity is detected, it will keep the radio on for a set period to try and receive the packet.
Contikimac (is supposed to) pad packets that are short enough to fit between two subsequent CCAs with 0's to ensure that they can be reliably detected and received.
Contents
Contikimac Settings
Contikimac uses several settings to control its operation. These are detailed in the following tables.
General Settings
Definition | Internal Variable | Description | Values | Default |
---|---|---|---|---|
CONTIKIMAC_CONF_WITH_PHASE_OPTIMIZATION | WITH_PHASE_OPTIMIZATION | Controls whether TX/RX cycles are synchronised between neighbours. | 1, 0 | 1 |
CONTIKIMAC_CONF_WITH_CONTIKIMAC_HEADER | WITH_CONTIKIMAC_HEADER | Controls whether a two-byte Contikimac header is added. | 1, 0 | 1 |
WITH_FAST_SLEEP | Controls whether a more agressive radio sleeping algorithm is used on busy channel. | 1 | ||
RDC_CONF_HARDWARE_CSMA | Informs Contikimac whether the radio does CSMA and autobackoff. | 1, 0 | 0 | |
RDC_CONF_HARDWARE_ACK | Informs Contikimac whether the radio blocks until it receives an ACK. | 1, 0 | 0 | |
RDC_CONF_MCU_SLEEP | Informs Contikimac whether the MCU can sleep while the radio is off. | 1, 0 | 0 | |
CONTIKIMAC_CONF_CCA_COUNT_MAX | CCA_COUNT_MAX | Sets how many NETSTACK_RADIO.channel_clear() are done for each channel check. | 2 | |
CONTIKIMAC_CONF_CCA_COUNT_MAX_TX | CCA_COUNT_MAX_TX | Sets how many NETSTACK_RADIO.channel_clear() are done before each TX. | 6 | |
CONTIKIMAC_CONF_SHORTEST_PACKET_SIZE | SHORTEST_PACKET_SIZE | Smallest packet that Contikimac allows. | 43 |
Timining Settings
Definition | Dependant Variable | Description | Default |
---|---|---|---|
NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE | NETSTACK_RDC_CHANNEL_CHECK_RATE | Sets the frequency (in Hz) of channel checking. If this is >= 64, WITH_PHASE_OPTIMIZATION is set to 0. This must be a power-of-2. | 8 (Set in Platform configuration) |
CONTIKIMAC_CONF_CCA_CHECK_TIME | CCA_CHECK_TIME | tr in the Contikimac paper. The rough time it takes to perform a CCA. May be 0, e.g. if the MCU blocks till CCA is done. | RTIMER_ARCH_SECOND / 8192 |
CONTIKIMAC_CONF_CYCLE_TIME | CYCLE_TIME | Cycle time for CCA checks, e.g. how long each CCA check cycle can take. | (RTIMER_ARCH_SECOND / NETSTACK_RDC_CHANNEL_CHECK_RATE) |
CONTIKIMAC_CONF_INTER_PACKET_INTERVAL | INTER_PACKET_INTERVAL | Interval between two successive packet transmissions. | RTIMER_ARCH_SECOND / 2500 |
CONTIKIMAC_CONF_AFTER_ACK_DETECTECT_WAIT_TIME | AFTER_ACK_DETECTECT_WAIT_TIME | The time to wait before reading out a detected potential ACK. | RTIMER_ARCH_SECOND / 1500 |
Internal Settings
Definition | Description | Setting |
---|---|---|
CCA_SLEEP_TIME | tc in the Contikimac paper. This is the time between successive CCA checks | RTIMER_ARCH_SECOND / 2000 or (RTIMER_ARCH_SECOND / 2000) + 1 if RTIMER_ARCH_SECOND is coarse, e.g. <= 8000 |
INTER_PACKET_DEADLINE | Maximum time a receiver waits for next packet in a burst when FRAME_PENDING is set. | CLOCK_SECOND / 32 |
CHECK_TIME | The total time to perform CCA_COUNT_MAX CCAs. | (CCA_COUNT_MAX * (CCA_CHECK_TIME + CCA_SLEEP_TIME)) |
CHECK_TIME_TX | The total time to perform CCA_COUNT_MAX_TX CCAs. | (CCA_COUNT_MAX_TX * (CCA_CHECK_TIME + CCA_SLEEP_TIME)) |
LISTEN_TIME_AFTER_PACKET_DETECTED | How long to keep checking for activity after a CCA has returned activity. tl + ti + tl | RTIMER_ARCH_SECOND / 80 |
MAX_SILENCE_PERIODS | The maximum number of silent periods before the radio is turned off. | 5 |
MAX_NONACTIVITY_PERIODS | The maximum number of periods with no packet being received before the radio is turned off when WITH_FAST_SLEEP is enabled. | 10 |
STROBE_TIME | The maximum amount of time to re-transmit a packet for. | (CYCLE_TIME + 2 * CHECK_TIME) |
GUARD_TIME | The time before the expected phase of a neighbour that a transmission should start. | 10 * CHECK_TIME + CHECK_TIME_TX |
MAX_PHASE_STROBE_TIME | The time to transmit repeated packets to neighbours with a phase lock. | RTIMER_ARCH_SECOND / 60 |
ACK_LEN | The length of an ACK packet. | 3 |
CC1120 Driver
When used with the CC1120 on the Zolertia Z1 with no modifications to any settings, Contikimac does not give the expected results.
The packet time for a 19-byte packet is roughly 4.9ms and the inter-packet time (ti) is in the region of 8.2mS. This does not correspond to the default set time of 0.4mS
With padding, the same packet (padded to 43 bytes) takes 9.1ms to send.
A full 125-byte packet takes 22ms to transmit with preamble, etc.
A full length packet plus five retransmissions with LBT on the initial transmission and ~3ms between each retransmission takes 157ms.
An ACK will take approx 1.28ms
Modifications
- Made LISTEN_TIME_AFTER_PACKET_DETECTED settable from Contiki config as CONTIKIMAC_LISTEN_TIME_AFTER_PACKET_DETECTED rather than just being internally set.
- Made CCA_SLEEP_TIME settable from Contiki config as CONTIKIMAC_CONF_CCA_SLEEP_TIME rather than just being internally set.
- Line 771 to 786: Hardware ACK detection increases the inter-packet interval to inter-packet interval + ACK detection time. To get around this, non-broadcast packets take into account the wait time.
- The CC1120 RSSI valid time is given on P.37 to p.38 of the CC1120 user guide. The calculation of this time is shown in the following table.
Timing | Description | Formula | Value |
---|---|---|---|
CSmax | Maximum CS response time. | ≤ T0 + (T1 + T2)*(2RSSI_VALID_CNT + 1) | 1.23 |
T0 | Start-up delay before RSSI can begin. | D0 + D1 + D3 + D5 | 0.91 |
T1 | AGC transient decay wait time. | ((16.AGC_SETTLE_WAIT + 48) * BB_CIC_DECFACT * Decimation Factor )/fxosc | 0.08 |
T2 | AGC measure time. | ≤ ((2AGC_WIN_SIZE + 4 * BB_CIC_DECFACT * Decimation Factor) + 46)/fxosc | 0.08 |
D0 | ((16 * Decimation Factor) + 74)/fxosc | 0.0123125 | |
D1 | ((1 - DCFILT_FREEZE_COEFF) * (62 + CARRIER_SENSE_GATE * (2(5 + x) - 1)) * Decimation Factor * 2)/fxosc | 0.775 | |
D3 | ((16 * BB_CIC_DECFACT - 2) * Decimation Factor * 2)/fxosc | 0.0375 | |
D5 | (68 * BB_CIC_DECFACT * Decimation Factor)/fxosc | 0.085 | |
fxosc | Example | Example | Example |
AGC_SETTLE_WAIT | AGC gain adjustment wait time. | AGC_CFG1.AGC_SETTLE_WAIT | 1 |
AGC_WIN_SIZE | AGC integration window size. | AGC_CFG1.AGC_WIN_SIZE | 2 |
Decimation Factor | Example | CHAN_BW.ADC_CIC_DECFACT | 20 |
BB_CIC_DECFACT | Example | CHAN_BW.BB_CIC_DECFACT | 2 |
DCFILT_FREEZE_COEFF | Example | DCFILT_CFG.DCFILT_FREEZE_COEFF | 0 |
CARRIER_SENSE_GATE | Example | MDMCFG1.CARRIER_SENSE_GATE | 0 |
x | DCFILT_CFG.DCFILT_BW when < 5, else 4 | DCFILT_CFG.DCFILT_BW | 4 |
- The actual inter-packet interval for the CC1120 with LBT for each retransmission will be a minimum of 6.23ms (the sum of the RSSI valid time plus the mandatory minimum 5ms listening time as required by ETSI EN 300 220-1 V2.3.1[1]). With a busy channel, the actual inter-packet time could be much greater so a timeout is required. This is set at 12.5ms (in CC1120_LBT_TIMEOUT) from the time that the TX strobe is issued. Given that this is a variable amount of time that is quite significant, LBT is only used for the first packet. As long as the time between the end of each transmission and the next retransmission is less than 5ms, no other stations should try to transmit due to the 5ms minimum listen time. As such, the inter-packet interval is set to 3ms.
CC1120 Timings
Timing Value | Description | Time (ms) CC2420 | Time (ms) @ 50kbps/50ksps | Time (ms) @ 100kbps/100ksps | Time (ms) @ 200kbps/100ksps | Source/Calc |
---|---|---|---|---|---|---|
ts | The minimum transmission time for valid detection. | 0.884 | 5.96 | Example | Example | tα + td < ti < tc + 2tr < ts |
tα | Time between sending a packet and receiving an ack. this is 12 symbols in 802.15.4 | 0.192 | 0.24 | 0.12 | 0.12 | 802.15.4 spec, 12 * symbol rate |
ti | Interval between each packet transmission | 0.4 | 3 | Example | Example | Must be less than tc. Must be > 5ms + tr + timeout |
tr | Time for a valid RSSI. | 0.192 | 1.23 | Example | Example | Example |
td | Time for detecting an ACK. | 0.16 | 0.8 | Example | Example | Preamble + sync delimeter TX, 5-bytes total. |
tc | Time between each CCA. | 0.5 | 3.5 | Example | Example | Must be > ti |
tl | Transmission time of the longest possible packet. | 4.1 | 22 | Example | Example |
Achieving a 12-symbol turn around for the ACK is not possible with the CC1120 as it takes 1.6ms to start to TX the ACK from the end of the packet (with a 125-byte received packet) and 2.38ms to actually transmit the ACK. 790μS of the 1.6ms is expended reading a 125-byte packet from the FIFO using burst access.
References
- ↑ EN 300 220 V2.3.1: "Electromagnetic compatability and Radio spectrum Matters (ERM); Short Range Devices (SRD); Radio equipment to be used in the 25MHz to 1000 MHz frequency range with power levels rangeing up to 500 mW" (www.etsi.org)