Merge branch 'develop' of github.com:contiki-ng/contiki-ng into feature/ipv6_over_ble

This commit is contained in:
spoerk 2017-12-15 11:35:16 +01:00
commit fd0f0ca4b6
118 changed files with 6069 additions and 1515 deletions

View File

@ -31,3 +31,4 @@ env:
- TEST_NAME='compile-nxp-ports'
- TEST_NAME='doxygen'
- TEST_NAME='compile-tools'
- TEST_NAME='native-runs'

76
arch/cpu/arm/arm-def.h Normal file
View File

@ -0,0 +1,76 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup arm
* @{
*
* \file
* Compiler and data type definitions for all ARM-based CPUs
*/
/*---------------------------------------------------------------------------*/
#ifndef ARM_DEF_
#define ARM_DEF_
/*---------------------------------------------------------------------------*/
#include <stdint.h>
/*---------------------------------------------------------------------------*/
/**
* \name Compiler configuration
*
* Those values are not meant to be modified by the user
* @{
*/
#define CCIF
#define CLIF
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Macros and typedefs
*
* Those values are not meant to be modified by the user
* @{
*/
#define CLOCK_CONF_SECOND 128
/* Clock (time) comparison macro */
#define CLOCK_LT(a, b) ((signed long)((a) - (b)) < 0)
/* Platform typedefs */
typedef uint32_t clock_time_t;
typedef uint32_t uip_stats_t;
typedef uint32_t rtimer_clock_t;
#define RTIMER_CLOCK_DIFF(a, b) ((int32_t)((a) - (b)))
/** @} */
/*---------------------------------------------------------------------------*/
#endif /* ARM_DEF_ */
/*---------------------------------------------------------------------------*/
/** @} */

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup arm
* @{
*
* \defgroup cm3 Arm Cortex-M3
* @{
*
* \file
* Compiler and data type definitions for all CM3-based CPUs
*/
/*---------------------------------------------------------------------------*/
#ifndef CM3_DEF_H_
#define CM3_DEF_H_
/*---------------------------------------------------------------------------*/
#include "arm-def.h"
/*---------------------------------------------------------------------------*/
#endif /* CM3_DEF_H_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup arm
* @{
*
* \defgroup cm4 Arm Cortex-M4
* @{
*
* \file
* Compiler and data type definitions for all CM4-based CPUs
*/
/*---------------------------------------------------------------------------*/
#ifndef CM4_DEF_H_
#define CM4_DEF_H_
/*---------------------------------------------------------------------------*/
#include "arm-def.h"
/*---------------------------------------------------------------------------*/
#endif /* CM4_DEF_H_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
#ifndef MEMORY_BARRIER_CORTEX_H_
#define MEMORY_BARRIER_CORTEX_H_
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#ifdef CMSIS_CONF_HEADER_PATH
#include CMSIS_CONF_HEADER_PATH
#endif
/*---------------------------------------------------------------------------*/
#define memory_barrier() __DMB()
/*---------------------------------------------------------------------------*/
#endif /* MEMORY_BARRIER_CORTEX_H_ */
/*---------------------------------------------------------------------------*/

View File

@ -0,0 +1,82 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup arm
*
* Arm Cortex-M implementation of mutexes using the LDREX, STREX and DMB
* instructions.
*
* @{
*/
/*---------------------------------------------------------------------------*/
#ifndef MUTEX_CORTEX_H_
#define MUTEX_CORTEX_H_
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#ifdef CMSIS_CONF_HEADER_PATH
#include CMSIS_CONF_HEADER_PATH
#endif
#include <stdint.h>
#include <stdbool.h>
/*---------------------------------------------------------------------------*/
#define mutex_try_lock(m) mutex_cortex_try_lock(m)
#define mutex_unlock(m) mutex_cortex_unlock(m)
/*---------------------------------------------------------------------------*/
#define MUTEX_CONF_HAS_MUTEX_T 1
typedef uint8_t mutex_t;
/*---------------------------------------------------------------------------*/
static inline bool
mutex_cortex_try_lock(volatile mutex_t *mutex)
{
int status = 1;
if(__LDREXB(mutex) == 0) {
status = __STREXB(1, mutex);
}
__DMB();
return status == 0 ? true : false;
}
/*---------------------------------------------------------------------------*/
static inline void
mutex_cortex_unlock(volatile mutex_t *mutex)
{
__DMB();
*mutex = 0;
}
/*---------------------------------------------------------------------------*/
#endif /* MUTEX_CORTEX_H_ */
/*---------------------------------------------------------------------------*/
/** @} */

View File

@ -19,7 +19,7 @@ CONTIKI_CPU_SOURCEFILES += nvic.c sys-ctrl.c gpio.c ioc.c spi.c adc.c
CONTIKI_CPU_SOURCEFILES += crypto.c aes.c ecb.c cbc.c ctr.c cbc-mac.c gcm.c
CONTIKI_CPU_SOURCEFILES += ccm.c sha256.c
CONTIKI_CPU_SOURCEFILES += cc2538-aes-128.c cc2538-ccm-star.c
CONTIKI_CPU_SOURCEFILES += cc2538-rf.c udma.c lpm.c
CONTIKI_CPU_SOURCEFILES += cc2538-rf.c udma.c lpm.c int-master.c
CONTIKI_CPU_SOURCEFILES += pka.c bignum-driver.c ecc-driver.c ecc-algorithm.c
CONTIKI_CPU_SOURCEFILES += ecc-curve.c
CONTIKI_CPU_SOURCEFILES += dbg.c ieee-addr.c

View File

@ -0,0 +1,330 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup cc2538
* @{
*/
/*---------------------------------------------------------------------------*/
#ifndef CC2538_CONF_H_
#define CC2538_CONF_H_
/*---------------------------------------------------------------------------*/
/**
* \name CFS configuration
*
* @{
*/
#ifndef COFFEE_CONF_SIZE
#define COFFEE_CONF_SIZE (4 * COFFEE_SECTOR_SIZE)
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name CC2538 System Control configuration
*
* @{
*/
#ifndef SYS_CTRL_CONF_OSC32K_USE_XTAL
#define SYS_CTRL_CONF_OSC32K_USE_XTAL 0 /**< Use the on-board 32.768-kHz crystal */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Watchdog Timer configuration
*
* @{
*/
#ifndef WATCHDOG_CONF_ENABLE
#define WATCHDOG_CONF_ENABLE 1 /**< Enable the watchdog timer */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name USB 'core' configuration
*
* Those values are not meant to be modified by the user, except where stated
* otherwise
* @{
*/
#define CTRL_EP_SIZE 8
#define USB_EP1_SIZE 32
#define USB_EP2_SIZE 64
#define USB_EP3_SIZE 64
#define USB_ARCH_WRITE_NOTIFY 0
#ifndef USB_ARCH_CONF_DMA
#define USB_ARCH_CONF_DMA 1 /**< Change to Enable/Disable USB DMA */
#endif
/** @} */
/**
* \name uDMA Configuration and channel allocations
*
* @{
*/
#define USB_ARCH_CONF_RX_DMA_CHAN 0 /**< USB -> RAM DMA channel */
#define USB_ARCH_CONF_TX_DMA_CHAN 1 /**< RAM -> USB DMA channel */
#define CC2538_RF_CONF_TX_DMA_CHAN 2 /**< RF -> RAM DMA channel */
#define CC2538_RF_CONF_RX_DMA_CHAN 3 /**< RAM -> RF DMA channel */
#define UDMA_CONF_MAX_CHANNEL CC2538_RF_CONF_RX_DMA_CHAN
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Character I/O Configuration
*
* @{
*/
#ifndef UART_CONF_ENABLE
#define UART_CONF_ENABLE 1 /**< Enable/Disable UART I/O */
#endif
#ifndef UART0_CONF_BAUD_RATE
#define UART0_CONF_BAUD_RATE 115200 /**< Default UART0 baud rate */
#endif
#ifndef UART1_CONF_BAUD_RATE
#define UART1_CONF_BAUD_RATE 115200 /**< Default UART1 baud rate */
#endif
#ifndef SLIP_ARCH_CONF_USB
#define SLIP_ARCH_CONF_USB 0 /**< SLIP over UART by default */
#endif
#ifndef DBG_CONF_USB
#define DBG_CONF_USB 0 /**< All debugging over UART by default */
#endif
#ifndef SERIAL_LINE_CONF_UART
#define SERIAL_LINE_CONF_UART 0 /**< UART to use with serial line */
#endif
#if !SLIP_ARCH_CONF_USB
#ifndef SLIP_ARCH_CONF_UART
#define SLIP_ARCH_CONF_UART 0 /**< UART to use with SLIP */
#endif
#endif
#if !DBG_CONF_USB
#ifndef DBG_CONF_UART
#define DBG_CONF_UART 0 /**< UART to use for debugging */
#endif
#endif
#ifndef UART1_CONF_UART
#define UART1_CONF_UART 0 /**< UART to use for examples relying on
the uart1_* API */
#endif
#ifndef SLIP_ARCH_CONF_ENABLED
/*
* Determine whether we need SLIP
* This will keep working while UIP_FALLBACK_INTERFACE and CMD_CONF_OUTPUT
* keep using SLIP
*/
#if defined(UIP_FALLBACK_INTERFACE) || defined(CMD_CONF_OUTPUT)
#define SLIP_ARCH_CONF_ENABLED 1
#endif
#endif
/**
* \brief Define this as 1 to build a headless node.
*
* The UART will not be initialised its clock will be gated, offering some
* energy savings. The USB will not be initialised either
*/
#ifndef CC2538_CONF_QUIET
#define CC2538_CONF_QUIET 0
#endif
/* CC2538_CONF_QUIET is hard and overrides all other related defines */
#if CC2538_CONF_QUIET
#undef USB_SERIAL_CONF_ENABLE
#define USB_SERIAL_CONF_ENABLE 0
#undef UART_CONF_ENABLE
#define UART_CONF_ENABLE 0
#endif /* CC2538_CONF_QUIET */
/**
* \brief Enable the USB core only if we need it
*/
#ifndef USB_SERIAL_CONF_ENABLE
#define USB_SERIAL_CONF_ENABLE \
((SLIP_ARCH_CONF_USB && SLIP_ARCH_CONF_ENABLED) || \
(MAC_CONF_WITH_TSCH && (SLIP_ARCH_CONF_ENABLED || BUILD_WITH_SHELL)) || \
DBG_CONF_USB)
#endif
/*
* If debugging and SLIP use the same peripheral, this will be 1. Don't modify
* this
*/
#if SLIP_ARCH_CONF_ENABLED
#define DBG_CONF_SLIP_MUX (SLIP_ARCH_CONF_USB == DBG_CONF_USB && \
(SLIP_ARCH_CONF_USB || \
SLIP_ARCH_CONF_UART == DBG_CONF_UART))
#endif
/*
* Automatic detection of whether a specific UART is in use
*/
#define UART_IN_USE_BY_SERIAL_LINE(u) (SERIAL_LINE_CONF_UART == (u))
#define UART_IN_USE_BY_SLIP(u) (SLIP_ARCH_CONF_ENABLED && \
!SLIP_ARCH_CONF_USB && \
SLIP_ARCH_CONF_UART == (u))
#define UART_IN_USE_BY_DBG(u) (!DBG_CONF_USB && DBG_CONF_UART == (u))
#define UART_IN_USE_BY_UART1(u) (UART1_CONF_UART == (u))
#define UART_IN_USE(u) ( \
UART_CONF_ENABLE && \
(UART_IN_USE_BY_SERIAL_LINE(u) || \
UART_IN_USE_BY_SLIP(u) || \
UART_IN_USE_BY_DBG(u) || \
UART_IN_USE_BY_UART1(u)) \
)
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name RF configuration
*
* @{
*/
/* RF Config */
#ifdef RF_CHANNEL
#define CC2538_RF_CONF_CHANNEL RF_CHANNEL
#endif
#ifndef CC2538_RF_CONF_CHANNEL
#define CC2538_RF_CONF_CHANNEL 26
#endif /* CC2538_RF_CONF_CHANNEL */
#ifndef CC2538_RF_CONF_AUTOACK
#define CC2538_RF_CONF_AUTOACK 1 /**< RF H/W generates ACKs */
#endif /* CC2538_CONF_AUTOACK */
#ifndef CC2538_RF_CONF_TX_USE_DMA
#define CC2538_RF_CONF_TX_USE_DMA 1 /**< RF TX over DMA */
#endif
#ifndef CC2538_RF_CONF_RX_USE_DMA
#define CC2538_RF_CONF_RX_USE_DMA 1 /**< RF RX over DMA */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name LPM configuration
* @{
*/
#ifndef LPM_CONF_ENABLE
#define LPM_CONF_ENABLE 1 /**< Set to 0 to disable LPM entirely */
#endif
/**
* \brief Maximum PM
*
* The SoC will never drop to a Power Mode deeper than the one specified here.
* 0 for PM0, 1 for PM1 and 2 for PM2
*/
#ifndef LPM_CONF_MAX_PM
#define LPM_CONF_MAX_PM 1
#endif
#ifndef LPM_CONF_STATS
#define LPM_CONF_STATS 0 /**< Set to 1 to enable LPM-related stats */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Radio Configuration
*
* @{
*/
#ifndef NETSTACK_CONF_RADIO
#define NETSTACK_CONF_RADIO cc2538_rf_driver
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name IEEE address configuration
*
* Used to generate our link-layer & IPv6 address
* @{
*/
/**
* \brief Location of the IEEE address
* 0 => Read from InfoPage,
* 1 => Use a hardcoded address, configured by IEEE_ADDR_CONF_ADDRESS
*/
#ifndef IEEE_ADDR_CONF_HARDCODED
#define IEEE_ADDR_CONF_HARDCODED 0
#endif
/**
* \brief The hardcoded IEEE address to be used when IEEE_ADDR_CONF_HARDCODED
* is defined as 1
*/
#ifndef IEEE_ADDR_CONF_ADDRESS
#define IEEE_ADDR_CONF_ADDRESS { 0x00, 0x12, 0x4B, 0x00, 0x89, 0xAB, 0xCD, 0xEF }
#endif
/**
* \brief Location of the IEEE address in the InfoPage when
* IEEE_ADDR_CONF_HARDCODED is defined as 0
* 0 => Use the primary address location
* 1 => Use the secondary address location
*/
#ifndef IEEE_ADDR_CONF_USE_SECONDARY_LOCATION
#define IEEE_ADDR_CONF_USE_SECONDARY_LOCATION 0
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Security
*
* @{
*/
#ifndef CRYPTO_CONF_INIT
#define CRYPTO_CONF_INIT 1 /**< Whether to init cryptoprocessor */
#endif
#ifndef AES_128_CONF
#define AES_128_CONF cc2538_aes_128_driver /**< AES-128 driver */
#endif
#ifndef CCM_STAR_CONF
#define CCM_STAR_CONF cc2538_ccm_star_driver /**< AES-CCM* driver */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
#endif /* CC2538_CONF_H_ */
/*---------------------------------------------------------------------------*/
/** @} */

View File

@ -0,0 +1,69 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
#ifndef CC2538_DEF_H_
#define CC2538_DEF_H_
/*---------------------------------------------------------------------------*/
#include "cm3/cm3-def.h"
/*---------------------------------------------------------------------------*/
#define RTIMER_ARCH_SECOND 32768
/*---------------------------------------------------------------------------*/
/* 352us from calling transmit() until the SFD byte has been sent */
#define RADIO_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(352))
/* 192us as in datasheet but ACKs are not always received, so adjusted to 250us */
#define RADIO_DELAY_BEFORE_RX ((unsigned)US_TO_RTIMERTICKS(250))
#define RADIO_DELAY_BEFORE_DETECT 0
#ifndef TSCH_CONF_BASE_DRIFT_PPM
/* The drift compared to "true" 10ms slots.
* Enable adaptive sync to enable compensation for this.
* Slot length 10000 usec
* 328 ticks
* Tick duration 30.517578125 usec
* Real slot duration 10009.765625 usec
* Target - real duration = -9.765625 usec
* TSCH_CONF_BASE_DRIFT_PPM -977
*/
#define TSCH_CONF_BASE_DRIFT_PPM -977
#endif
#if MAC_CONF_WITH_TSCH
#define TSCH_CONF_HW_FRAME_FILTERING 0
#endif /* MAC_CONF_WITH_TSCH */
/*---------------------------------------------------------------------------*/
/* Path to CMSIS header */
#define CMSIS_CONF_HEADER_PATH "cc2538_cm3.h"
/* Path to headers with implementation of mutexes and memory barriers */
#define MUTEX_CONF_ARCH_HEADER_PATH "mutex-cortex.h"
#define MEMORY_BARRIER_CONF_ARCH_HEADER_PATH "memory-barrier-cortex.h"
/*---------------------------------------------------------------------------*/
#endif /* CC2538_DEF_H_ */
/*---------------------------------------------------------------------------*/

View File

@ -96,11 +96,18 @@ SECTIONS
_ebss = .;
} > FRSRAM
_end = .; /* End of the .bss segment. */
/* This symbol is used by the stack check library. */
_stack = .;
.stack (NOLOAD) :
{
*(.stack)
} > FRSRAM
/* This symbol is used by the stack check library. */
_stack_origin = .;
_heap = .;
_eheap = ORIGIN(FRSRAM) + LENGTH(FRSRAM);

View File

@ -0,0 +1,82 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup cc2538
* @{
*
* \defgroup cc2538-interrupts CC2538 master interrupt manipulation
*
* Master interrupt manipulation routines for the CC2538 CPU
*
* @{
*
* \file
* Master interrupt manipulation implementation for the TI CC2538
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "sys/int-master.h"
#include <stdbool.h>
/*---------------------------------------------------------------------------*/
void
int_master_enable(void)
{
__enable_irq();
}
/*---------------------------------------------------------------------------*/
int_master_status_t
int_master_read_and_disable(void)
{
int_master_status_t primask = __get_PRIMASK();
__disable_irq();
return primask;
}
/*---------------------------------------------------------------------------*/
void
int_master_status_set(int_master_status_t status)
{
__set_PRIMASK(status);
}
/*---------------------------------------------------------------------------*/
bool
int_master_is_enabled(void)
{
return __get_PRIMASK() ? false : true;
}
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -63,8 +63,6 @@
#include "contiki.h"
#include "dev/gptimer.h"
#define RTIMER_ARCH_SECOND 32768
/* Do the math in 32bits to save precision.
* Round to nearest integer rather than truncate. */
#define US_TO_RTIMERTICKS(US) ((US) >= 0 ? \

View File

@ -36,7 +36,7 @@ CONTIKI_CPU_SOURCEFILES += gpio-interrupt.c oscillators.c
CONTIKI_CPU_SOURCEFILES += rf-core.c rf-ble.c ieee-mode.c
CONTIKI_CPU_SOURCEFILES += ble-cc2650.c ble-hal-cc26xx.c ble-addr.c rf-ble-cmd.c
CONTIKI_CPU_SOURCEFILES += ble-l2cap.c
CONTIKI_CPU_SOURCEFILES += random.c soc-trng.c
CONTIKI_CPU_SOURCEFILES += random.c soc-trng.c int-master.c
DEBUG_IO_SOURCEFILES += dbg-printf.c dbg-snprintf.c dbg-sprintf.c strformat.c

View File

@ -0,0 +1,206 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup cc26xx
* @{
*
* \file
* Header with configuration defines common to all CC13xx/CC26xx platforms
*/
/*---------------------------------------------------------------------------*/
#ifndef CC13XX_CC26XX_CONF_H_
#define CC13XX_CC26XX_CONF_H_
/*---------------------------------------------------------------------------*/
/**
* \name Network Stack Configuration
*
* @{
*/
/*
* If set, the systems keeps the HF crystal oscillator on even when the radio is off.
* You need to set this to 1 to use TSCH with its default 2.2ms or larger guard time.
*/
#ifndef CC2650_FAST_RADIO_STARTUP
#define CC2650_FAST_RADIO_STARTUP (MAC_CONF_WITH_TSCH)
#endif
#ifdef RF_CHANNEL
#define RF_CORE_CONF_CHANNEL RF_CHANNEL
#endif
#ifndef RF_CORE_CONF_CHANNEL
#define RF_CORE_CONF_CHANNEL 25
#endif
/* Number of Prop Mode RX buffers */
#ifndef PROP_MODE_CONF_RX_BUF_CNT
#define PROP_MODE_CONF_RX_BUF_CNT 4
#endif
/*
* Auto-configure Prop-mode radio if we are running on CC13xx, unless the
* project has specified otherwise. Depending on the final mode, determine a
* default channel (again, if unspecified) and configure RDC params
*/
#if CPU_FAMILY_CC13XX
#ifndef CC13XX_CONF_PROP_MODE
#define CC13XX_CONF_PROP_MODE 1
#endif /* CC13XX_CONF_PROP_MODE */
#endif /* CPU_FAMILY_CC13XX */
#if CC13XX_CONF_PROP_MODE
#define NETSTACK_CONF_RADIO prop_mode_driver
#ifndef RF_CORE_CONF_CHANNEL
#define RF_CORE_CONF_CHANNEL 0
#endif
#define CSMA_CONF_ACK_WAIT_TIME (RTIMER_SECOND / 400)
#define CSMA_CONF_AFTER_ACK_DETECTED_WAIT_TIME (RTIMER_SECOND / 1000)
#define CSMA_CONF_SEND_SOFT_ACK 1
#else /* CC13XX_CONF_PROP_MODE */
#ifndef NETSTACK_CONF_RADIO
#define NETSTACK_CONF_RADIO ieee_mode_driver
#endif
#define CSMA_CONF_SEND_SOFT_ACK 0
#endif /* CC13XX_CONF_PROP_MODE */
#define NETSTACK_RADIO_MAX_PAYLOAD_LEN 125
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name IEEE address configuration
*
* Used to generate our link-local & IPv6 address
* @{
*/
/**
* \brief Location of the IEEE address
* 0 => Read from InfoPage,
* 1 => Use a hardcoded address, configured by IEEE_ADDR_CONF_ADDRESS
*/
#ifndef IEEE_ADDR_CONF_HARDCODED
#define IEEE_ADDR_CONF_HARDCODED 0
#endif
/**
* \brief The hardcoded IEEE address to be used when IEEE_ADDR_CONF_HARDCODED
* is defined as 1
*/
#ifndef IEEE_ADDR_CONF_ADDRESS
#define IEEE_ADDR_CONF_ADDRESS { 0x00, 0x12, 0x4B, 0x00, 0x89, 0xAB, 0xCD, 0xEF }
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name RF configuration
*
* @{
*/
/* RF Config */
#ifndef IEEE_MODE_CONF_AUTOACK
#define IEEE_MODE_CONF_AUTOACK 1 /**< RF H/W generates ACKs */
#endif
#ifndef IEEE_MODE_CONF_PROMISCOUS
#define IEEE_MODE_CONF_PROMISCOUS 0 /**< 1 to enable promiscous mode */
#endif
#ifndef RF_BLE_CONF_ENABLED
#define RF_BLE_CONF_ENABLED 0 /**< 0 to disable BLE support */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Character I/O Configuration
*
* @{
*/
#ifndef CC26XX_UART_CONF_ENABLE
#define CC26XX_UART_CONF_ENABLE 1 /**< Enable/Disable UART I/O */
#endif
#ifndef CC26XX_UART_CONF_BAUD_RATE
#define CC26XX_UART_CONF_BAUD_RATE 115200 /**< Default UART0 baud rate */
#endif
/* Enable I/O over the Debugger Devpack - Only relevant for the SensorTag */
#ifndef BOARD_CONF_DEBUGGER_DEVPACK
#define BOARD_CONF_DEBUGGER_DEVPACK 1
#endif
#ifndef SLIP_ARCH_CONF_ENABLED
/*
* Determine whether we need SLIP
* This will keep working while UIP_FALLBACK_INTERFACE and CMD_CONF_OUTPUT
* keep using SLIP
*/
#if defined(UIP_FALLBACK_INTERFACE) || defined(CMD_CONF_OUTPUT)
#define SLIP_ARCH_CONF_ENABLED 1
#endif
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name JTAG interface configuration
*
* Enable/Disable the JTAG DAP and TAP interfaces on the chip.
* Setting this to 0 will disable access to the debug interface
* to secure deployed images.
* @{
*/
#ifndef CCXXWARE_CONF_JTAG_INTERFACE_ENABLE
#define CCXXWARE_CONF_JTAG_INTERFACE_ENABLE 1
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name ROM Bootloader configuration
*
* Enable/Disable the ROM bootloader in your image, if the board supports it.
* Look in board.h to choose the DIO and corresponding level that will cause
* the chip to enter bootloader mode.
* @{
*/
#ifndef ROM_BOOTLOADER_ENABLE
#define ROM_BOOTLOADER_ENABLE 0
#endif
/** @} */
/*---------------------------------------------------------------------------*/
#endif /* CC13XX_CC26XX_CONF_H_ */
/*---------------------------------------------------------------------------*/
/** @} */

View File

@ -0,0 +1,104 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
#ifndef CC13XX_CC26XX_DEF_H_
#define CC13XX_CC26XX_DEF_H_
/*---------------------------------------------------------------------------*/
#include "cm3/cm3-def.h"
/*---------------------------------------------------------------------------*/
/* TSCH related defines */
/* Delay between GO signal and SFD */
#define RADIO_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(81))
/* Delay between GO signal and start listening.
* This value is so small because the radio is constantly on within each timeslot. */
#define RADIO_DELAY_BEFORE_RX ((unsigned)US_TO_RTIMERTICKS(15))
/* Delay between the SFD finishes arriving and it is detected in software. */
#define RADIO_DELAY_BEFORE_DETECT ((unsigned)US_TO_RTIMERTICKS(352))
/* Timer conversion; radio is running at 4 MHz */
#define RADIO_TIMER_SECOND 4000000u
#if (RTIMER_SECOND % 256) || (RADIO_TIMER_SECOND % 256)
#error RADIO_TO_RTIMER macro must be fixed!
#endif
#define RADIO_TO_RTIMER(X) ((uint32_t)(((uint64_t)(X) * (RTIMER_SECOND / 256)) / (RADIO_TIMER_SECOND / 256)))
#define USEC_TO_RADIO(X) ((X) * 4)
/* The PHY header (preamble + SFD, 4+1 bytes) duration is equivalent to 10 symbols */
#define RADIO_IEEE_802154_PHY_HEADER_DURATION_USEC 160
/* Do not turn off TSCH within a timeslot: not enough time */
#define TSCH_CONF_RADIO_ON_DURING_TIMESLOT 1
/* Disable TSCH frame filtering */
#define TSCH_CONF_HW_FRAME_FILTERING 0
/* Use hardware timestamps */
#ifndef TSCH_CONF_RESYNC_WITH_SFD_TIMESTAMPS
#define TSCH_CONF_RESYNC_WITH_SFD_TIMESTAMPS 1
#define TSCH_CONF_TIMESYNC_REMOVE_JITTER 0
#endif
#ifndef TSCH_CONF_BASE_DRIFT_PPM
/* The drift compared to "true" 10ms slots.
* Enable adaptive sync to enable compensation for this.
* Slot length 10000 usec
* 328 ticks
* Tick duration 30.517578125 usec
* Real slot duration 10009.765625 usec
* Target - real duration = -9.765625 usec
* TSCH_CONF_BASE_DRIFT_PPM -977
*/
#define TSCH_CONF_BASE_DRIFT_PPM -977
#endif
/* 10 times per second */
#ifndef TSCH_CONF_CHANNEL_SCAN_DURATION
#define TSCH_CONF_CHANNEL_SCAN_DURATION (CLOCK_SECOND / 10)
#endif
/* Slightly reduce the TSCH guard time (from 2200 usec to 1800 usec) to make sure
* the CC26xx radio has sufficient time to start up. */
#ifndef TSCH_CONF_RX_WAIT
#define TSCH_CONF_RX_WAIT 1800
#endif
/*---------------------------------------------------------------------------*/
#define RTIMER_ARCH_SECOND 65536
/*---------------------------------------------------------------------------*/
/* Path to CMSIS header */
#define CMSIS_CONF_HEADER_PATH "cc13x0-cc26x0-cm3.h"
/* Path to headers with implementation of mutexes and memory barriers */
#define MUTEX_CONF_ARCH_HEADER_PATH "mutex-cortex.h"
#define MEMORY_BARRIER_CONF_ARCH_HEADER_PATH "memory-barrier-cortex.h"
/*---------------------------------------------------------------------------*/
#endif /* CC13XX_CC26XX_DEF_H_ */
/*---------------------------------------------------------------------------*/

View File

@ -90,6 +90,12 @@ SECTIONS
_ebss = .;
} > SRAM
_end = .; /* End of the .bss segment. */
/* These symbols are used by the stack check library. */
_stack = .;
_stack_origin = ORIGIN(SRAM) + LENGTH(SRAM);
.ccfg :
{
KEEP(*(.ccfg))

View File

@ -0,0 +1,81 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup cc26xx
* @{
*
* \defgroup cc26xx-interrupts CC13xx-CC26xx master interrupt manipulation
*
* Master interrupt manipulation routines for the CC13xx and CC26xx CPUs
*
* @{
*
* \file
* Master interrupt manipulation implementation for the TI CC13xx/CC26xx
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "sys/int-master.h"
#include "cc13x0-cc26x0-cm3.h"
#include "ti-lib.h"
#include <stdbool.h>
/*---------------------------------------------------------------------------*/
void
int_master_enable(void)
{
ti_lib_int_master_enable();
}
/*---------------------------------------------------------------------------*/
int_master_status_t
int_master_read_and_disable(void)
{
return ti_lib_int_master_disable();
}
/*---------------------------------------------------------------------------*/
void
int_master_status_set(int_master_status_t status)
{
__set_PRIMASK(status);
}
/*---------------------------------------------------------------------------*/
bool
int_master_is_enabled(void)
{
return ti_lib_cpu_primask() ? false : true;
}
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -7,7 +7,7 @@ This Contiki extenstion implements [BLEach][bleachWeb], a fully open-source IPv6
BLEach in Contiki-NG can be used for node (BLE slave) devices.
It was developed by
* [Michael Spoerk](www.michaelspoerk.com), Graz University of Technology, michael.spoerk@tugraz.at, github user: [spoerk](https://github.com/spoerk)
* [Michael Spoerk](http://www.michaelspoerk.com), Graz University of Technology, michael.spoerk@tugraz.at, github user: [spoerk](https://github.com/spoerk)
This IPv6-over-BLE stack is presented and evaluated in the paper:
[BLEach: Exploiting the Full Potential of IPv6 over BLE in Constrained Embedded IoT Devices](http://sensys.acm.org/2017/), ACM SenSys'17.

View File

@ -47,8 +47,6 @@
/*---------------------------------------------------------------------------*/
#include "contiki.h"
/*---------------------------------------------------------------------------*/
#define RTIMER_ARCH_SECOND 65536
/*---------------------------------------------------------------------------*/
rtimer_clock_t rtimer_arch_now(void);
/* HW oscillator frequency is 32 kHz, not 64 kHz and RTIMER_NOW() never returns

View File

@ -37,7 +37,7 @@ endif
CONTIKI_CPU_DIRS = $(CONTIKI_CPU_FAM_DIR) . dev
MSP430 = msp430.c flash.c clock.c leds.c leds-arch.c \
watchdog.c lpm.c rtimer-arch.c
watchdog.c lpm.c rtimer-arch.c int-master.c
UIPDRIVERS = slip.c crc16.c
CONTIKI_TARGET_SOURCEFILES += $(MSP430) \
@ -182,6 +182,9 @@ endif # SMALL
endif # IAR
# Define the `_stack` symbol used by the stack check library to be equal to `_end`
LDFLAGS += -Wl,--defsym=_stack=_end
CFLAGS += $(CFLAGSNO)
PROJECT_OBJECTFILES += ${addprefix $(OBJECTDIR)/,$(CONTIKI_TARGET_MAIN:.c=.o)}

View File

@ -0,0 +1,67 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
/**
* \file
* Master interrupt manipulation implementation for the MSP430
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "sys/int-master.h"
#include <stdbool.h>
/*---------------------------------------------------------------------------*/
void
int_master_enable(void)
{
eint();
}
/*---------------------------------------------------------------------------*/
int_master_status_t
int_master_read_and_disable(void)
{
__istate_t status = __get_interrupt_state();
dint();
return status;
}
/*---------------------------------------------------------------------------*/
void
int_master_status_set(int_master_status_t status)
{
__set_interrupt_state(status);
}
/*---------------------------------------------------------------------------*/
bool
int_master_is_enabled(void)
{
return __get_interrupt_state() & GIE ? true : false;
}
/*---------------------------------------------------------------------------*/

View File

@ -0,0 +1,47 @@
/*
* 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.
*/
/*---------------------------------------------------------------------------*/
#ifndef MSP430_CONF_H_
#define MSP430_CONF_H_
/*---------------------------------------------------------------------------*/
/* default DCOSYNCH Period is 30 seconds */
#ifdef DCOSYNCH_CONF_PERIOD
#define DCOSYNCH_PERIOD DCOSYNCH_CONF_PERIOD
#else
#define DCOSYNCH_PERIOD 30
#endif
#ifdef F_CPU
#define MSP430_CPU_SPEED F_CPU
#else
#define MSP430_CPU_SPEED 2457600UL
#endif
/*---------------------------------------------------------------------------*/
#endif /* MSP430_CONF_H_ */
/*---------------------------------------------------------------------------*/

View File

@ -27,8 +27,8 @@
* SUCH DAMAGE.
*/
#ifndef MSP430DEF_H
#define MSP430DEF_H
#ifndef MSP430_DEF_H_
#define MSP430_DEF_H_
#ifdef __IAR_SYSTEMS_ICC__
#include <intrinsics.h>
@ -56,22 +56,14 @@
#endif /* __IAR_SYSTEMS_ICC__ */
/* Master interrupt state representation data type */
#define INT_MASTER_CONF_STATUS_DATATYPE __istate_t
#ifndef BV
#define BV(x) (1 << x)
#endif
#ifdef HAVE_STDINT_H
#include <stdint.h>
#else
#ifndef uint8_t
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
typedef signed char int8_t;
typedef short int16_t;
typedef long int32_t;
#endif
#endif /* !HAVE_STDINT_H */
/* These names are deprecated, use C99 names. */
typedef uint8_t u8_t;
@ -79,23 +71,18 @@ typedef uint16_t u16_t;
typedef uint32_t u32_t;
typedef int32_t s32_t;
/* default DCOSYNCH Period is 30 seconds */
#ifdef DCOSYNCH_CONF_PERIOD
#define DCOSYNCH_PERIOD DCOSYNCH_CONF_PERIOD
#else
#define DCOSYNCH_PERIOD 30
#endif
/* Types for clocks and uip_stats */
typedef unsigned short uip_stats_t;
typedef unsigned long clock_time_t;
typedef long off_t;
void msp430_cpu_init(void); /* Rename to cpu_init() later! */
void msp430_sync_dco(void);
/* Our clock resolution, this is the same as Unix HZ. */
#define CLOCK_CONF_SECOND 128UL
#define cpu_init() msp430_cpu_init()
void *sbrk(int);
#define CCIF
#define CLIF
typedef int spl_t;
/* void splx_(spl_t); */
spl_t splhigh_(void);
#define splhigh() splhigh_()
@ -119,21 +106,23 @@ void *w_memset(void *out, int value, size_t n);
#endif /* memcpy */
#endif /* __GNUC__ && __MSP430__ && MSP430_MEMCPY_WORKAROUND */
/* Moved from the msp430.h file with other msp430 related defines */
#ifdef F_CPU
#define MSP430_CPU_SPEED F_CPU
#else
#define MSP430_CPU_SPEED 2457600UL
#endif
#define memory_barrier() asm volatile("" : : : "memory")
#define MSP430_REQUIRE_CPUON 0
#define MSP430_REQUIRE_LPM1 1
#define MSP430_REQUIRE_LPM2 2
#define MSP430_REQUIRE_LPM3 3
/* Platform-specific checksum implementation */
#define UIP_ARCH_IPCHKSUM 1
#define BAUD2UBR(baud) ((F_CPU/baud))
void msp430_add_lpm_req(int req);
void msp430_remove_lpm_req(int req);
void msp430_cpu_init(void); /* Rename to cpu_init() later! */
void msp430_sync_dco(void);
#define cpu_init() msp430_cpu_init()
void *sbrk(int);
#endif /* MSP430DEF_H */
#endif /* MSP430_DEF_H_ */

View File

@ -79,11 +79,11 @@ rtimer_arch_schedule(rtimer_clock_t t)
c = t - (unsigned short)clock_time();
val.it_value.tv_sec = c / 1000;
val.it_value.tv_usec = (c % 1000) * 1000;
val.it_value.tv_sec = c / CLOCK_SECOND;
val.it_value.tv_usec = (c % CLOCK_SECOND) * CLOCK_SECOND;
PRINTF("rtimer_arch_schedule time %u %u in %d.%d seconds\n", t, c, c / 1000,
(c % 1000) * 1000);
PRINTF("rtimer_arch_schedule time %u %u in %d.%d seconds\n", t, c, val.it_value.tv_sec,
val.it_value.tv_usec);
val.it_interval.tv_sec = val.it_interval.tv_usec = 0;
setitimer(ITIMER_REAL, &val, NULL);

View File

@ -61,6 +61,7 @@ CONTIKI_CPU_DIRS += . dev ble #compat
### CPU-dependent source files
CONTIKI_CPU_SOURCEFILES += clock.c rtimer-arch.c uart0.c putchar.c watchdog.c
CONTIKI_CPU_SOURCEFILES += int-master.c
ifneq ($(NRF52_WITHOUT_SOFTDEVICE),1)
CONTIKI_CPU_SOURCEFILES += ble-core.c ble-mac.c

View File

@ -53,7 +53,6 @@
#include "nrf_delay.h"
#include "app_error.h"
#include "contiki.h"
#include "platform-conf.h"
/*---------------------------------------------------------------------------*/
const nrf_drv_rtc_t rtc = NRF_DRV_RTC_INSTANCE(PLATFORM_RTC_INSTANCE_ID); /**< RTC instance used for platform clock */

View File

@ -0,0 +1,70 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
/**
* \file
* Master interrupt manipulation implementation for the nrf52832
*/
/*---------------------------------------------------------------------------*/
#include "nordic_common.h"
#include "contiki.h"
#include "sys/int-master.h"
#include <stdbool.h>
/*---------------------------------------------------------------------------*/
void
int_master_enable(void)
{
__enable_irq();
}
/*---------------------------------------------------------------------------*/
int_master_status_t
int_master_read_and_disable(void)
{
int_master_status_t primask = __get_PRIMASK();
__disable_irq();
return primask;
}
/*---------------------------------------------------------------------------*/
void
int_master_status_set(int_master_status_t status)
{
__set_PRIMASK(status);
}
/*---------------------------------------------------------------------------*/
bool
int_master_is_enabled(void)
{
return __get_PRIMASK() ? false : true;
}
/*---------------------------------------------------------------------------*/

View File

@ -9,4 +9,8 @@ MEMORY
RAM (rwx) : ORIGIN = 0x08000000, LENGTH = 0x8000
}
INCLUDE "nrf5x_common.ld"
INCLUDE "nrf5x_common.ld"
/* These symbols are used by the stack check library. */
_stack = end;
_stack_origin = ORIGIN(RAM) + LENGTH(RAM);

View File

@ -9,4 +9,8 @@ MEMORY
RAM (rwx) : ORIGIN = 0x20002800, LENGTH = 0xD800
}
INCLUDE "nrf5x_common.ld"
INCLUDE "nrf5x_common.ld"
/* These symbols are used by the stack check library. */
_stack = end;
_stack_origin = ORIGIN(RAM) + LENGTH(RAM);

View File

@ -9,4 +9,8 @@ MEMORY
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x8000
}
INCLUDE "nrf5x_common.ld"
INCLUDE "nrf5x_common.ld"
/* These symbols are used by the stack check library. */
_stack = end;
_stack_origin = ORIGIN(RAM) + LENGTH(RAM);

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
#ifndef NRF52832_DEF_H_
#define NRF52832_DEF_H_
/*---------------------------------------------------------------------------*/
#include "cm4/cm4-def.h"
/*---------------------------------------------------------------------------*/
#define RTIMER_ARCH_SECOND 62500
/*---------------------------------------------------------------------------*/
#endif /* NRF52832_DEF_H_ */
/*---------------------------------------------------------------------------*/

View File

@ -44,7 +44,6 @@
#include "nrf_drv_timer.h"
#include "app_error.h"
#include "contiki.h"
#include "platform-conf.h"
static const nrf_drv_timer_t timer = NRF_DRV_TIMER_INSTANCE(PLATFORM_TIMER_INSTANCE_ID); /**< Timer instance used for rtimer */

View File

@ -47,51 +47,7 @@
#include PROJECT_CONF_PATH
#endif /* PROJECT_CONF_PATH */
/*---------------------------------------------------------------------------*/
/**
* \name Compiler configuration and platform-specific type definitions
*
* Those values are not meant to be modified by the user
* @{
*/
#define CLOCK_CONF_SECOND 128
/* Compiler configurations */
#define CCIF
#define CLIF
/* Platform typedefs */
typedef uint32_t clock_time_t;
typedef uint32_t uip_stats_t;
/*
* rtimer.h typedefs rtimer_clock_t as unsigned short. We need to define
* RTIMER_CLOCK_DIFF to override this
*/
typedef uint32_t rtimer_clock_t;
#define RTIMER_CLOCK_DIFF(a,b) ((int32_t)((a)-(b)))
/** @} */
/*---------------------------------------------------------------------------*/
/* 352us from calling transmit() until the SFD byte has been sent */
#define RADIO_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(352))
/* 192us as in datasheet but ACKs are not always received, so adjusted to 250us */
#define RADIO_DELAY_BEFORE_RX ((unsigned)US_TO_RTIMERTICKS(250))
#define RADIO_DELAY_BEFORE_DETECT 0
#ifndef TSCH_CONF_BASE_DRIFT_PPM
/* The drift compared to "true" 10ms slots.
* Enable adaptive sync to enable compensation for this.
* Slot length 10000 usec
* 328 ticks
* Tick duration 30.517578125 usec
* Real slot duration 10009.765625 usec
* Target - real duration = -9.765625 usec
* TSCH_CONF_BASE_DRIFT_PPM -977
*/
#define TSCH_CONF_BASE_DRIFT_PPM -977
#endif
#if MAC_CONF_WITH_TSCH
#define TSCH_CONF_HW_FRAME_FILTERING 0
#endif /* MAC_CONF_WITH_TSCH */
#include "cc2538-def.h"
/*---------------------------------------------------------------------------*/
/**
* \name Serial Boot Loader Backdoor configuration
@ -99,7 +55,7 @@ typedef uint32_t rtimer_clock_t;
* @{
*/
#ifndef FLASH_CCA_CONF_BOOTLDR_BACKDOOR
#define FLASH_CCA_CONF_BOOTLDR_BACKDOOR 1 /**<Enable the boot loader backdoor */
#define FLASH_CCA_CONF_BOOTLDR_BACKDOOR 1 /**<Enable the boot loader backdoor */
#endif
#ifndef FLASH_CCA_CONF_BOOTLDR_BACKDOOR_PORT_A_PIN
@ -121,274 +77,12 @@ typedef uint32_t rtimer_clock_t;
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Watchdog Timer configuration
*
* @{
*/
#ifndef WATCHDOG_CONF_ENABLE
#define WATCHDOG_CONF_ENABLE 1 /**< Enable the watchdog timer */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name USB 'core' configuration
*
* Those values are not meant to be modified by the user, except where stated
* otherwise
* @{
*/
#define CTRL_EP_SIZE 8
#define USB_EP1_SIZE 32
#define USB_EP2_SIZE 64
#define USB_EP3_SIZE 64
#define USB_ARCH_WRITE_NOTIFY 0
#ifndef USB_ARCH_CONF_DMA
#define USB_ARCH_CONF_DMA 1 /**< Change to Enable/Disable USB DMA */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name uDMA Configuration and channel allocations
*
* @{
*/
#define USB_ARCH_CONF_RX_DMA_CHAN 0 /**< USB -> RAM DMA channel */
#define USB_ARCH_CONF_TX_DMA_CHAN 1 /**< RAM -> USB DMA channel */
#define CC2538_RF_CONF_TX_DMA_CHAN 2 /**< RF -> RAM DMA channel */
#define CC2538_RF_CONF_RX_DMA_CHAN 3 /**< RAM -> RF DMA channel */
#define UDMA_CONF_MAX_CHANNEL CC2538_RF_CONF_RX_DMA_CHAN
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Character I/O Configuration
*
* @{
*/
#ifndef UART_CONF_ENABLE
#define UART_CONF_ENABLE 1 /**< Enable/Disable UART I/O */
#endif
#ifndef UART0_CONF_BAUD_RATE
#define UART0_CONF_BAUD_RATE 115200 /**< Default UART0 baud rate */
#endif
#ifndef UART1_CONF_BAUD_RATE
#define UART1_CONF_BAUD_RATE 115200 /**< Default UART1 baud rate */
#endif
#ifndef SLIP_ARCH_CONF_USB
#define SLIP_ARCH_CONF_USB 0 /**< SLIP over UART by default */
#endif
#ifndef DBG_CONF_USB
#define DBG_CONF_USB 0 /**< All debugging over UART by default */
#endif
#ifndef SERIAL_LINE_CONF_UART
#define SERIAL_LINE_CONF_UART 0 /**< UART to use with serial line */
#endif
#if !SLIP_ARCH_CONF_USB
#ifndef SLIP_ARCH_CONF_UART
#define SLIP_ARCH_CONF_UART 0 /**< UART to use with SLIP */
#endif
#endif
#if !DBG_CONF_USB
#ifndef DBG_CONF_UART
#define DBG_CONF_UART 0 /**< UART to use for debugging */
#endif
#endif
#ifndef UART1_CONF_UART
#define UART1_CONF_UART 0 /**< UART to use for examples relying on
the uart1_* API */
#endif
#ifndef SLIP_ARCH_CONF_ENABLED
/*
* Determine whether we need SLIP
* This will keep working while UIP_FALLBACK_INTERFACE and CMD_CONF_OUTPUT
* keep using SLIP
*/
#if defined (UIP_FALLBACK_INTERFACE) || defined (CMD_CONF_OUTPUT)
#define SLIP_ARCH_CONF_ENABLED 1
#endif
#endif
/**
* \brief Define this as 1 to build a headless node.
*
* The UART will not be initialised its clock will be gated, offering some
* energy savings. The USB will not be initialised either
*/
#ifndef CC2538_CONF_QUIET
#define CC2538_CONF_QUIET 0
#endif
/* CC2538_CONF_QUIET is hard and overrides all other related defines */
#if CC2538_CONF_QUIET
#undef USB_SERIAL_CONF_ENABLE
#define USB_SERIAL_CONF_ENABLE 0
#undef UART_CONF_ENABLE
#define UART_CONF_ENABLE 0
#endif /* CC2538_CONF_QUIET */
/**
* \brief Enable the USB core only if we need it
*/
#ifndef USB_SERIAL_CONF_ENABLE
#define USB_SERIAL_CONF_ENABLE \
((SLIP_ARCH_CONF_USB && SLIP_ARCH_CONF_ENABLED) || \
(MAC_CONF_WITH_TSCH && (SLIP_ARCH_CONF_ENABLED || BUILD_WITH_SHELL)) || \
DBG_CONF_USB)
#endif
/*
* If debugging and SLIP use the same peripheral, this will be 1. Don't modify
* this
*/
#if SLIP_ARCH_CONF_ENABLED
#define DBG_CONF_SLIP_MUX (SLIP_ARCH_CONF_USB == DBG_CONF_USB && \
(SLIP_ARCH_CONF_USB || \
SLIP_ARCH_CONF_UART == DBG_CONF_UART))
#endif
/*
* Automatic detection of whether a specific UART is in use
*/
#define UART_IN_USE_BY_SERIAL_LINE(u) (SERIAL_LINE_CONF_UART == (u))
#define UART_IN_USE_BY_SLIP(u) (SLIP_ARCH_CONF_ENABLED && \
!SLIP_ARCH_CONF_USB && \
SLIP_ARCH_CONF_UART == (u))
#define UART_IN_USE_BY_DBG(u) (!DBG_CONF_USB && DBG_CONF_UART == (u))
#define UART_IN_USE_BY_UART1(u) (UART1_CONF_UART == (u))
#define UART_IN_USE(u) ( \
UART_CONF_ENABLE && \
(UART_IN_USE_BY_SERIAL_LINE(u) || \
UART_IN_USE_BY_SLIP(u) || \
UART_IN_USE_BY_DBG(u) || \
UART_IN_USE_BY_UART1(u)) \
)
/** @} */
/*---------------------------------------------------------------------------*/
/* board.h assumes that basic configuration is done */
#include "board.h"
/*---------------------------------------------------------------------------*/
#define NETSTACK_CONF_RADIO cc2538_rf_driver
/** @} */
/* Include CPU-related configuration */
#include "cc2538-conf.h"
/*---------------------------------------------------------------------------*/
/**
* \name LPM configuration
* @{
*/
#ifndef LPM_CONF_ENABLE
#define LPM_CONF_ENABLE 1 /**< Set to 0 to disable LPM entirely */
#endif
/**
* \brief Maximum PM
*
* The SoC will never drop to a Power Mode deeper than the one specified here.
* 0 for PM0, 1 for PM1 and 2 for PM2
*/
#ifndef LPM_CONF_MAX_PM
#define LPM_CONF_MAX_PM 1
#endif
#ifndef LPM_CONF_STATS
#define LPM_CONF_STATS 0 /**< Set to 1 to enable LPM-related stats */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name IEEE address configuration
*
* Used to generate our link-layer & IPv6 address
* @{
*/
/**
* \brief Location of the IEEE address
* 0 => Read from InfoPage,
* 1 => Use a hardcoded address, configured by IEEE_ADDR_CONF_ADDRESS
*/
#ifndef IEEE_ADDR_CONF_HARDCODED
#define IEEE_ADDR_CONF_HARDCODED 0
#endif
/**
* \brief The hardcoded IEEE address to be used when IEEE_ADDR_CONF_HARDCODED
* is defined as 1
*/
#ifndef IEEE_ADDR_CONF_ADDRESS
#define IEEE_ADDR_CONF_ADDRESS { 0x00, 0x12, 0x4B, 0x00, 0x89, 0xAB, 0xCD, 0xEF }
#endif
/**
* \brief Location of the IEEE address in the InfoPage when
* IEEE_ADDR_CONF_HARDCODED is defined as 0
* 0 => Use the primary address location
* 1 => Use the secondary address location
*/
#ifndef IEEE_ADDR_CONF_USE_SECONDARY_LOCATION
#define IEEE_ADDR_CONF_USE_SECONDARY_LOCATION 0
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name RF configuration
*
* @{
*/
/* RF Config */
#ifdef RF_CHANNEL
#define CC2538_RF_CONF_CHANNEL RF_CHANNEL
#endif
#ifndef CC2538_RF_CONF_CHANNEL
#define CC2538_RF_CONF_CHANNEL 25
#endif /* CC2538_RF_CONF_CHANNEL */
#ifndef CC2538_RF_CONF_AUTOACK
#define CC2538_RF_CONF_AUTOACK 1 /**< RF H/W generates ACKs */
#endif /* CC2538_CONF_AUTOACK */
#ifndef CC2538_RF_CONF_TX_USE_DMA
#define CC2538_RF_CONF_TX_USE_DMA 1 /**< RF TX over DMA */
#endif
#ifndef CC2538_RF_CONF_RX_USE_DMA
#define CC2538_RF_CONF_RX_USE_DMA 1 /**< RF RX over DMA */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Security
*
* @{
*/
#ifndef CRYPTO_CONF_INIT
#define CRYPTO_CONF_INIT 1 /**< Whether to init cryptoprocessor */
#endif
#ifndef AES_128_CONF
#define AES_128_CONF cc2538_aes_128_driver /**< AES-128 driver */
#endif
#ifndef CCM_STAR_CONF
#define CCM_STAR_CONF cc2538_ccm_star_driver /**< AES-CCM* driver */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
#endif /* CONTIKI_CONF_H_ */
/*---------------------------------------------------------------------------*/
/** @} */

View File

@ -135,4 +135,6 @@ typedef uint64_t rtimer_clock_t;
#define RF_CHANNEL 26
#define NETSTACK_RADIO_MAX_PAYLOAD_LEN 125
#define PLATFORM_CONF_SUPPORTS_STACK_CHECK 0
#endif /* CONTIKI_CONF_H_ */

View File

@ -81,7 +81,7 @@ OBJCOPY:=$(CROSS_COMPILE)-objcopy
OBJDUMP:=$(CROSS_COMPILE)-objdump
ARCH = jn516x-ccm-star.c exceptions.c rtimer-arch.c rtimer-arch-slow.c \
slip_uart0.c clock.c micromac-radio.c \
slip_uart0.c clock.c micromac-radio.c int-master.c \
node-id.c watchdog.c slip.c sprintf.c
# Default uart0 for printf and slip
TARGET_WITH_UART0 ?= 1
@ -164,6 +164,10 @@ CFLAGS := $(patsubst -I/cygdrive/c/%,-Ic:/%,$(CFLAGS))
LDFLAGS := $(patsubst -L/cygdrive/c/%,-Lc:/%,$(LDFLAGS))
endif
# These symbols are used by the stack check library
LDFLAGS += -Wl,--defsym=_stack=_stack_low_water_mark
LDFLAGS += -Wl,--defsym=_stack_origin=_ram_top
########################################################################
MOTELIST = python $(CONTIKI)/tools/jn516x/mote-list.py

View File

@ -38,11 +38,15 @@
#include PROJECT_CONF_PATH
#endif /* PROJECT_CONF_PATH */
#ifdef PLATFORM_CONF_H
#include PLATFORM_CONF_H
#else
#include "platform-conf.h"
#endif /* PLATFORM_CONF_H */
#include "jn516x-def.h"
#ifdef RF_CHANNEL
#define MICROMAC_CONF_CHANNEL RF_CHANNEL
#endif
#ifndef MICROMAC_CONF_CHANNEL
#define MICROMAC_CONF_CHANNEL 26
#endif
/* Configure radio driver */
#ifndef NETSTACK_CONF_RADIO

View File

@ -5,4 +5,4 @@ Mapping of LEDs on JN516x DR1174:
leds.h: led on DR1174:
LEDS_GP0 LED D3
LEDS_GP1 LED D6
Note: LEDS_GPx definitions included in leds.h via platform-conf.h
Note: LEDS_GPx definitions included in leds.h via jn516x-def.h

View File

@ -14,4 +14,4 @@ DR1174+DR1175:
LEDS_WHITE White power led with level control on DR1175
LEDS_GP0 LEDS D3 on DR1174
LEDS_GP1 LEDS D6 on DR1174
Note: LEDS_GPx and LEDS_WHITE definitions included in leds.h via platform-conf.h
Note: LEDS_GPx and LEDS_WHITE definitions included in leds.h via jn516x-def.h

View File

@ -16,4 +16,4 @@ DR1174+DR1199:
LEDS_RED LED D3 on DR1199
LEDS_GP0 LED D3 on DR1174
LEDS_GP1 LED D6 on DR1174
Note: LEDS_GPx definitions included in leds.h via platform-conf.h
Note: LEDS_GPx definitions included in leds.h via jn516x-def.h

View File

@ -0,0 +1,74 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
/**
* \file
* Master interrupt manipulation implementation for the JN516x
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "MicroSpecific.h"
#include "sys/int-master.h"
#include <stdbool.h>
/*---------------------------------------------------------------------------*/
void
int_master_enable(void)
{
MICRO_ENABLE_INTERRUPTS();
}
/*---------------------------------------------------------------------------*/
int_master_status_t
int_master_read_and_disable(void)
{
int_master_status_t status;
MICRO_DISABLE_AND_SAVE_INTERRUPTS(status);
return status;
}
/*---------------------------------------------------------------------------*/
void
int_master_status_set(int_master_status_t status)
{
MICRO_RESTORE_INTERRUPTS(status);
}
/*---------------------------------------------------------------------------*/
bool
int_master_is_enabled(void)
{
int_master_status_t status;
asm volatile ("bw.mfspr %0, r0, 17;" :"=r"(status) : );
return status;
}
/*---------------------------------------------------------------------------*/

View File

@ -30,8 +30,8 @@
*
*/
#ifndef PLATFORM_CONF_H
#define PLATFORM_CONF_H
#ifndef JN516X_DEF_H_
#define JN516X_DEF_H_
#include <inttypes.h>
#include <jendefs.h>
@ -56,14 +56,6 @@
#define MIRCOMAC_CONF_BUF_NUM 2
#endif
#ifdef RF_CHANNEL
#define MICROMAC_CONF_CHANNEL RF_CHANNEL
#endif
#ifndef MICROMAC_CONF_CHANNEL
#define MICROMAC_CONF_CHANNEL 26
#endif
/* 32kHz or 16MHz rtimers? */
#ifdef RTIMER_CONF_USE_32KHZ
#define RTIMER_USE_32KHZ RTIMER_CONF_USE_32KHZ
@ -314,4 +306,5 @@ DR1174+DR1175:
#define LEDS_GP2 64
#define LEDS_GP3 128
#define LEDS_CONF_ALL 255
#endif /* PLATFORM_CONF_H */
#endif /* JN516X_DEF_H_ */

View File

@ -19,6 +19,10 @@ else
CONTIKI_TARGET_SOURCEFILES += tun6-net.c
endif
ifeq ($(HOST_OS),Linux)
TARGET_LIBFILES += -lrt
endif
CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)
.SUFFIXES:

View File

@ -42,24 +42,49 @@
#include <sys/time.h>
/*---------------------------------------------------------------------------*/
clock_time_t
clock_time(void)
typedef struct clock_timespec_s {
time_t tv_sec;
long tv_nsec;
} clock_timespec_t;
/*---------------------------------------------------------------------------*/
static void
get_time(clock_timespec_t *spec)
{
#if defined(__linux__) || (defined(__MACH__) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200)
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
spec->tv_sec = ts.tv_sec;
spec->tv_nsec = ts.tv_nsec;
#else
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
spec->tv_sec = tv.tv_sec;
spec->tv_nsec = tv.tv_usec * 1000;
#endif
}
/*---------------------------------------------------------------------------*/
clock_time_t
clock_time(void)
{
clock_timespec_t ts;
get_time(&ts);
return ts.tv_sec * CLOCK_SECOND + ts.tv_nsec / (1000000000 / CLOCK_SECOND);
}
/*---------------------------------------------------------------------------*/
unsigned long
clock_seconds(void)
{
struct timeval tv;
clock_timespec_t ts;
gettimeofday(&tv, NULL);
get_time(&ts);
return tv.tv_sec;
return ts.tv_sec;
}
/*---------------------------------------------------------------------------*/
void

View File

@ -101,5 +101,6 @@ int strcasecmp(const char*, const char*);
#define PLATFORM_CONF_PROVIDES_MAIN_LOOP 1
#define PLATFORM_CONF_MAIN_ACCEPTS_ARGS 1
#define PLATFORM_CONF_SUPPORTS_STACK_CHECK 0
#endif /* CONTIKI_CONF_H_ */

View File

@ -158,6 +158,7 @@ set_lladdr(void)
linkaddr_set_node_addr(&addr);
}
/*---------------------------------------------------------------------------*/
#if NETSTACK_CONF_WITH_IPV6
static void
set_global_address(void)
{
@ -183,6 +184,7 @@ set_global_address(void)
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 1);
uip_ds6_defrt_add(&ipaddr, 0);
}
#endif
/*---------------------------------------------------------------------------*/
int contiki_argc = 0;
char **contiki_argv;

View File

@ -48,7 +48,8 @@
#endif /* PROJECT_CONF_PATH */
/*---------------------------------------------------------------------------*/
/* Include platform peripherals configuration */
#include "platform-conf.h"
#include "nrf52dk-def.h"
#include "nrf52832-def.h"
/*---------------------------------------------------------------------------*/
/**
* \name Network Stack Configuration

View File

@ -43,8 +43,8 @@
* Wojciech Bober <wojciech.bober@nordicsemi.no>
*
*/
#ifndef PLATFORM_CONF_H_
#define PLATFORM_CONF_H_
#ifndef NRF52DK_DEF_H_
#define NRF52DK_DEF_H_
#include "boards.h"
@ -107,39 +107,10 @@
*/
#define PLATFORM_TIMER_INSTANCE_ID 1
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Compiler configuration and platform-specific type definitions
*
* Those values are not meant to be modified by the user
* @{
*/
#define CLOCK_CONF_SECOND 128
/* Compiler configurations */
#define CCIF
#define CLIF
/* Platform typedefs */
typedef uint32_t clock_time_t;
typedef uint32_t uip_stats_t;
/* Clock (time) comparison macro */
#define CLOCK_LT(a, b) ((signed long)((a) - (b)) < 0)
#define RTIMER_ARCH_SECOND 62500
/*
* rtimer.h typedefs rtimer_clock_t as unsigned short. We need to define
* RTIMER_CLOCK_DIFF to override this
*/
typedef uint32_t rtimer_clock_t;
#define RTIMER_CLOCK_DIFF(a,b) ((int32_t)((a)-(b)))
/** @} */
/*---------------------------------------------------------------------------*/
/** @}
* @}
* @}
*/
#endif /* PLATFORM_CONF_H_ */
#endif /* NRF52DK_DEF_H_ */

View File

@ -56,51 +56,7 @@
#include PROJECT_CONF_PATH
#endif /* PROJECT_CONF_PATH */
/*---------------------------------------------------------------------------*/
/**
* \name Compiler configuration and platform-specific type definitions
*
* Those values are not meant to be modified by the user
* @{
*/
#define CLOCK_CONF_SECOND 128
/* Compiler configurations */
#define CCIF
#define CLIF
/* Platform typedefs */
typedef uint32_t clock_time_t;
typedef uint32_t uip_stats_t;
/*
* rtimer.h typedefs rtimer_clock_t as unsigned short. We need to define
* RTIMER_CLOCK_DIFF to override this
*/
typedef uint32_t rtimer_clock_t;
#define RTIMER_CLOCK_DIFF(a, b) ((int32_t)((a) - (b)))
/** @} */
/*---------------------------------------------------------------------------*/
/* 352us from calling transmit() until the SFD byte has been sent */
#define RADIO_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(352))
/* 192us as in datasheet but ACKs are not always received, so adjusted to 250us */
#define RADIO_DELAY_BEFORE_RX ((unsigned)US_TO_RTIMERTICKS(250))
#define RADIO_DELAY_BEFORE_DETECT 0
#ifndef TSCH_CONF_BASE_DRIFT_PPM
/* The drift compared to "true" 10ms slots.
* Enable adaptive sync to enable compensation for this.
* Slot length 10000 usec
* 328 ticks
* Tick duration 30.517578125 usec
* Real slot duration 10009.765625 usec
* Target - real duration = -9.765625 usec
* TSCH_CONF_BASE_DRIFT_PPM -977
*/
#define TSCH_CONF_BASE_DRIFT_PPM -977
#endif
#if MAC_CONF_WITH_TSCH
#define TSCH_CONF_HW_FRAME_FILTERING 0
#endif /* MAC_CONF_WITH_TSCH */
#include "cc2538-def.h"
/*---------------------------------------------------------------------------*/
/**
* \name Serial Boot Loader Backdoor configuration
@ -130,290 +86,11 @@ typedef uint32_t rtimer_clock_t;
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name CFS configuration
*
* @{
*/
#ifndef COFFEE_CONF_SIZE
#define COFFEE_CONF_SIZE (4 * COFFEE_SECTOR_SIZE)
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Watchdog Timer configuration
*
* @{
*/
#ifndef WATCHDOG_CONF_ENABLE
#define WATCHDOG_CONF_ENABLE 1 /**< Enable the watchdog timer */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name USB 'core' configuration
*
* Those values are not meant to be modified by the user, except where stated
* otherwise
* @{
*/
#define CTRL_EP_SIZE 8
#define USB_EP1_SIZE 32
#define USB_EP2_SIZE 64
#define USB_EP3_SIZE 64
#define USB_ARCH_WRITE_NOTIFY 0
#ifndef USB_ARCH_CONF_DMA
#define USB_ARCH_CONF_DMA 1 /**< Change to Enable/Disable USB DMA */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name uDMA Configuration and channel allocations
*
* @{
*/
#define USB_ARCH_CONF_RX_DMA_CHAN 0 /**< USB -> RAM DMA channel */
#define USB_ARCH_CONF_TX_DMA_CHAN 1 /**< RAM -> USB DMA channel */
#define CC2538_RF_CONF_TX_DMA_CHAN 2 /**< RF -> RAM DMA channel */
#define CC2538_RF_CONF_RX_DMA_CHAN 3 /**< RAM -> RF DMA channel */
#define UDMA_CONF_MAX_CHANNEL CC2538_RF_CONF_RX_DMA_CHAN
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Character I/O Configuration
*
* @{
*/
#ifndef UART_CONF_ENABLE
#define UART_CONF_ENABLE 1 /**< Enable/Disable UART I/O */
#endif
#ifndef UART0_CONF_BAUD_RATE
#define UART0_CONF_BAUD_RATE 115200 /**< Default UART0 baud rate */
#endif
#ifndef UART1_CONF_BAUD_RATE
#define UART1_CONF_BAUD_RATE 115200 /**< Default UART1 baud rate */
#endif
#ifndef SLIP_ARCH_CONF_USB
#define SLIP_ARCH_CONF_USB 0 /**< SLIP over UART by default */
#endif
#ifndef DBG_CONF_USB
#define DBG_CONF_USB 0 /**< All debugging over UART by default */
#endif
#ifndef SERIAL_LINE_CONF_UART
#define SERIAL_LINE_CONF_UART 0 /**< UART to use with serial line */
#endif
#if !SLIP_ARCH_CONF_USB
#ifndef SLIP_ARCH_CONF_UART
#define SLIP_ARCH_CONF_UART 0 /**< UART to use with SLIP */
#endif
#endif
#if !DBG_CONF_USB
#ifndef DBG_CONF_UART
#define DBG_CONF_UART 0 /**< UART to use for debugging */
#endif
#endif
#ifndef UART1_CONF_UART
#define UART1_CONF_UART 0 /**< UART to use for examples relying on
the uart1_* API */
#endif
#ifndef SLIP_ARCH_CONF_ENABLED
/*
* Determine whether we need SLIP
* This will keep working while UIP_FALLBACK_INTERFACE and CMD_CONF_OUTPUT
* keep using SLIP
*/
#if defined(UIP_FALLBACK_INTERFACE) || defined(CMD_CONF_OUTPUT)
#define SLIP_ARCH_CONF_ENABLED 1
#endif
#endif
/**
* \brief Define this as 1 to build a headless node.
*
* The UART will not be initialised its clock will be gated, offering some
* energy savings. The USB will not be initialised either
*/
#ifndef CC2538_CONF_QUIET
#define CC2538_CONF_QUIET 0
#endif
/* CC2538_CONF_QUIET is hard and overrides all other related defines */
#if CC2538_CONF_QUIET
#undef USB_SERIAL_CONF_ENABLE
#define USB_SERIAL_CONF_ENABLE 0
#undef UART_CONF_ENABLE
#define UART_CONF_ENABLE 0
#endif /* CC2538_CONF_QUIET */
/**
* \brief Enable the USB core only if we need it
*/
#ifndef USB_SERIAL_CONF_ENABLE
#define USB_SERIAL_CONF_ENABLE \
((SLIP_ARCH_CONF_USB && SLIP_ARCH_CONF_ENABLED) || \
(MAC_CONF_WITH_TSCH && (SLIP_ARCH_CONF_ENABLED || BUILD_WITH_SHELL)) || \
DBG_CONF_USB)
#endif
/*
* If debugging and SLIP use the same peripheral, this will be 1. Don't modify
* this
*/
#if SLIP_ARCH_CONF_ENABLED
#define DBG_CONF_SLIP_MUX (SLIP_ARCH_CONF_USB == DBG_CONF_USB && \
(SLIP_ARCH_CONF_USB || \
SLIP_ARCH_CONF_UART == DBG_CONF_UART))
#endif
/*
* Automatic detection of whether a specific UART is in use
*/
#define UART_IN_USE_BY_SERIAL_LINE(u) (SERIAL_LINE_CONF_UART == (u))
#define UART_IN_USE_BY_SLIP(u) (SLIP_ARCH_CONF_ENABLED && \
!SLIP_ARCH_CONF_USB && \
SLIP_ARCH_CONF_UART == (u))
#define UART_IN_USE_BY_DBG(u) (!DBG_CONF_USB && DBG_CONF_UART == (u))
#define UART_IN_USE_BY_UART1(u) (UART1_CONF_UART == (u))
#define UART_IN_USE(u) ( \
UART_CONF_ENABLE && \
(UART_IN_USE_BY_SERIAL_LINE(u) || \
UART_IN_USE_BY_SLIP(u) || \
UART_IN_USE_BY_DBG(u) || \
UART_IN_USE_BY_UART1(u)) \
)
/** @} */
/*---------------------------------------------------------------------------*/
/* board.h assumes that basic configuration is done */
#include "board.h"
/*---------------------------------------------------------------------------*/
/**
* \name Radio Configuration
*
* @{
*/
#ifndef NETSTACK_CONF_RADIO
#define NETSTACK_CONF_RADIO cc2538_rf_driver
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name LPM configuration
* @{
*/
#ifndef LPM_CONF_ENABLE
#define LPM_CONF_ENABLE 1 /**< Set to 0 to disable LPM entirely */
#endif
/**
* \brief Maximum PM
*
* The SoC will never drop to a Power Mode deeper than the one specified here.
* 0 for PM0, 1 for PM1 and 2 for PM2
*/
#ifndef LPM_CONF_MAX_PM
#define LPM_CONF_MAX_PM 1
#endif
#ifndef LPM_CONF_STATS
#define LPM_CONF_STATS 0 /**< Set to 1 to enable LPM-related stats */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name IEEE address configuration
*
* Used to generate our link-layer & IPv6 address
* @{
*/
/**
* \brief Location of the IEEE address
* 0 => Read from InfoPage,
* 1 => Use a hardcoded address, configured by IEEE_ADDR_CONF_ADDRESS
*/
#ifndef IEEE_ADDR_CONF_HARDCODED
#define IEEE_ADDR_CONF_HARDCODED 0
#endif
/**
* \brief The hardcoded IEEE address to be used when IEEE_ADDR_CONF_HARDCODED
* is defined as 1
*/
#ifndef IEEE_ADDR_CONF_ADDRESS
#define IEEE_ADDR_CONF_ADDRESS { 0x00, 0x12, 0x4B, 0x00, 0x89, 0xAB, 0xCD, 0xEF }
#endif
/**
* \brief Location of the IEEE address in the InfoPage when
* IEEE_ADDR_CONF_HARDCODED is defined as 0
* 0 => Use the primary address location
* 1 => Use the secondary address location
*/
#ifndef IEEE_ADDR_CONF_USE_SECONDARY_LOCATION
#define IEEE_ADDR_CONF_USE_SECONDARY_LOCATION 0
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name RF configuration
*
* @{
*/
/* RF Config */
#ifdef RF_CHANNEL
#define CC2538_RF_CONF_CHANNEL RF_CHANNEL
#endif
#ifndef CC2538_RF_CONF_CHANNEL
#define CC2538_RF_CONF_CHANNEL 26
#endif /* CC2538_RF_CONF_CHANNEL */
#ifndef CC2538_RF_CONF_AUTOACK
#define CC2538_RF_CONF_AUTOACK 1 /**< RF H/W generates ACKs */
#endif /* CC2538_CONF_AUTOACK */
#ifndef CC2538_RF_CONF_TX_USE_DMA
#define CC2538_RF_CONF_TX_USE_DMA 1 /**< RF TX over DMA */
#endif
#ifndef CC2538_RF_CONF_RX_USE_DMA
#define CC2538_RF_CONF_RX_USE_DMA 1 /**< RF RX over DMA */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Security
*
* @{
*/
#ifndef CRYPTO_CONF_INIT
#define CRYPTO_CONF_INIT 1 /**< Whether to init cryptoprocessor */
#endif
#ifndef AES_128_CONF
#define AES_128_CONF cc2538_aes_128_driver /**< AES-128 driver */
#endif
#ifndef CCM_STAR_CONF
#define CCM_STAR_CONF cc2538_ccm_star_driver /**< AES-CCM* driver */
#endif
/** @} */
/* Include CPU-related configuration */
#include "cc2538-conf.h"
/*---------------------------------------------------------------------------*/
#endif /* CONTIKI_CONF_H_ */
/*---------------------------------------------------------------------------*/

View File

@ -7,12 +7,14 @@
#ifdef PROJECT_CONF_PATH
#include PROJECT_CONF_PATH
#endif /* PROJECT_CONF_PATH */
#ifdef PLATFORM_CONF_H
#include PLATFORM_CONF_H
#else
#include "platform-conf.h"
#endif /* PLATFORM_CONF_H */
/*---------------------------------------------------------------------------*/
#include "sky-def.h"
#include "msp430-def.h"
/*---------------------------------------------------------------------------*/
/* Map RF_CHANNEL to cc2420 default channel */
#ifdef RF_CHANNEL
#define CC2420_CONF_CHANNEL RF_CHANNEL
#endif /* RF_CHANNEL */
/* Configure radio driver */
#ifndef NETSTACK_CONF_RADIO
@ -30,12 +32,16 @@
#define UIP_CONF_BUFFER_SIZE 240
#endif
/* Platform-specific checksum implementation */
#define UIP_ARCH_IPCHKSUM 1
/* Platform-specific (H/W) AES implementation */
#ifndef AES_128_CONF
#define AES_128_CONF cc2420_aes_128_driver
#endif /* AES_128_CONF */
/* Disable the stack check library by default: .rom overflow otherwise */
#ifndef STACK_CHECK_CONF_ENABLED
#define STACK_CHECK_CONF_ENABLED 0
#endif
/*---------------------------------------------------------------------------*/
#include "msp430-conf.h"
/*---------------------------------------------------------------------------*/
#endif /* CONTIKI_CONF_H */

View File

@ -200,18 +200,18 @@ platform_init_stage_three(void)
cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
if(node_id > 0) {
LOG_INFO("Node id is set to %u.\n", node_id);
LOG_INFO("Node id: %u\n", node_id);
} else {
LOG_INFO("Node id is not set.\n");
LOG_INFO("Node id: N/A\n");
}
#if NETSTACK_CONF_WITH_IPV6
LOG_INFO("%s, radio channel %u, CCA threshold %i\n",
LOG_INFO("%s, rf channel %u, CCA threshold %i\n",
NETSTACK_MAC.name,
CC2420_CONF_CHANNEL,
CC2420_CONF_CCA_THRESH);
#else /* NETSTACK_CONF_WITH_IPV6 */
LOG_INFO("%s, radio channel %u\n",
LOG_INFO("%s, rf channel %u\n",
NETSTACK_MAC.name, CC2420_CONF_CHANNEL);
#endif /* NETSTACK_CONF_WITH_IPV6 */

View File

@ -36,16 +36,13 @@
* Joakim Eriksson <joakime@sics.se>
*/
#ifndef PLATFORM_CONF_H_
#define PLATFORM_CONF_H_
#ifndef SKY_DEF_H_
#define SKY_DEF_H_
/*
* Definitions below are dictated by the hardware and not really
* changeable!
*/
/* Platform TMOTE_SKY */
#define TMOTE_SKY 1
/* Delay between GO signal and SFD: radio fixed delay + 4Bytes preample + 1B SFD -- 1Byte time is 32us
* ~327us + 129preample = 456 us */
#define RADIO_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(456))
@ -62,31 +59,9 @@
#define PLATFORM_HAS_SHT11 1
#define PLATFORM_HAS_RADIO 1
/* Map RF_CHANNEL to cc2420 default channel */
#ifdef RF_CHANNEL
#define CC2420_CONF_CHANNEL RF_CHANNEL
#endif /* RF_CHANNEL */
/* CPU target speed in Hz */
#define F_CPU 3900000uL /*2457600uL*/
/* Our clock resolution, this is the same as Unix HZ. */
#define CLOCK_CONF_SECOND 128UL
#define BAUD2UBR(baud) ((F_CPU/baud))
#define CCIF
#define CLIF
#define HAVE_STDINT_H
#include "msp430def.h"
/* Types for clocks and uip_stats */
typedef unsigned short uip_stats_t;
typedef unsigned long clock_time_t;
typedef long off_t;
/* the low-level radio driver */
#define NETSTACK_CONF_RADIO cc2420_driver
@ -230,4 +205,7 @@ for SFD timestamping */
#define CC2420_SPI_DISABLE() (CC2420_CSN_PORT(OUT) |= BV(CC2420_CSN_PIN))
#define CC2420_SPI_IS_ENABLED() ((CC2420_CSN_PORT(OUT) & BV(CC2420_CSN_PIN)) != BV(CC2420_CSN_PIN))
#endif /* PLATFORM_CONF_H_ */
/* Platform-specific define for the end of the stack region */
#define STACK_CONF_ORIGIN ((void *)0x3900)
#endif /* SKY_DEF_H_ */

View File

@ -44,166 +44,7 @@
#include PROJECT_CONF_PATH
#endif /* PROJECT_CONF_PATH */
/*---------------------------------------------------------------------------*/
/**
* \name Network Stack Configuration
*
* @{
*/
/*
* If set, the systems keeps the HF crystal oscillator on even when the radio is off.
* You need to set this to 1 to use TSCH with its default 2.2ms or larger guard time.
*/
#ifndef CC2650_FAST_RADIO_STARTUP
#define CC2650_FAST_RADIO_STARTUP (MAC_CONF_WITH_TSCH)
#endif
#ifdef RF_CHANNEL
#define RF_CORE_CONF_CHANNEL RF_CHANNEL
#endif
#ifndef RF_CORE_CONF_CHANNEL
#define RF_CORE_CONF_CHANNEL 25
#endif
/* Number of Prop Mode RX buffers */
#ifndef PROP_MODE_CONF_RX_BUF_CNT
#define PROP_MODE_CONF_RX_BUF_CNT 4
#endif
/*
* Auto-configure Prop-mode radio if we are running on CC13xx, unless the
* project has specified otherwise. Depending on the final mode, determine a
* default channel (again, if unspecified) and configure RDC params
*/
#if CPU_FAMILY_CC13XX
#ifndef CC13XX_CONF_PROP_MODE
#define CC13XX_CONF_PROP_MODE 1
#endif /* CC13XX_CONF_PROP_MODE */
#endif /* CPU_FAMILY_CC13XX */
#if CC13XX_CONF_PROP_MODE
#define NETSTACK_CONF_RADIO prop_mode_driver
#ifndef RF_CORE_CONF_CHANNEL
#define RF_CORE_CONF_CHANNEL 0
#endif
#define CSMA_CONF_ACK_WAIT_TIME (RTIMER_SECOND / 400)
#define CSMA_CONF_AFTER_ACK_DETECTED_WAIT_TIME (RTIMER_SECOND / 1000)
#define CSMA_CONF_SEND_SOFT_ACK 1
#else /* CC13XX_CONF_PROP_MODE */
#ifndef NETSTACK_CONF_RADIO
#define NETSTACK_CONF_RADIO ieee_mode_driver
#endif
#define CSMA_CONF_SEND_SOFT_ACK 0
#endif /* CC13XX_CONF_PROP_MODE */
#define NETSTACK_RADIO_MAX_PAYLOAD_LEN 125
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name IEEE address configuration
*
* Used to generate our link-local & IPv6 address
* @{
*/
/**
* \brief Location of the IEEE address
* 0 => Read from InfoPage,
* 1 => Use a hardcoded address, configured by IEEE_ADDR_CONF_ADDRESS
*/
#ifndef IEEE_ADDR_CONF_HARDCODED
#define IEEE_ADDR_CONF_HARDCODED 0
#endif
/**
* \brief The hardcoded IEEE address to be used when IEEE_ADDR_CONF_HARDCODED
* is defined as 1
*/
#ifndef IEEE_ADDR_CONF_ADDRESS
#define IEEE_ADDR_CONF_ADDRESS { 0x00, 0x12, 0x4B, 0x00, 0x89, 0xAB, 0xCD, 0xEF }
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name RF configuration
*
* @{
*/
/* RF Config */
#ifndef IEEE_MODE_CONF_AUTOACK
#define IEEE_MODE_CONF_AUTOACK 1 /**< RF H/W generates ACKs */
#endif
#ifndef IEEE_MODE_CONF_PROMISCOUS
#define IEEE_MODE_CONF_PROMISCOUS 0 /**< 1 to enable promiscous mode */
#endif
#ifndef RF_BLE_CONF_ENABLED
#define RF_BLE_CONF_ENABLED 0 /**< 0 to disable BLE support */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Character I/O Configuration
*
* @{
*/
#ifndef CC26XX_UART_CONF_ENABLE
#define CC26XX_UART_CONF_ENABLE 1 /**< Enable/Disable UART I/O */
#endif
#ifndef CC26XX_UART_CONF_BAUD_RATE
#define CC26XX_UART_CONF_BAUD_RATE 115200 /**< Default UART0 baud rate */
#endif
/* Enable I/O over the Debugger Devpack - Only relevant for the SensorTag */
#ifndef BOARD_CONF_DEBUGGER_DEVPACK
#define BOARD_CONF_DEBUGGER_DEVPACK 1
#endif
#ifndef SLIP_ARCH_CONF_ENABLED
/*
* Determine whether we need SLIP
* This will keep working while UIP_FALLBACK_INTERFACE and CMD_CONF_OUTPUT
* keep using SLIP
*/
#if defined(UIP_FALLBACK_INTERFACE) || defined(CMD_CONF_OUTPUT)
#define SLIP_ARCH_CONF_ENABLED 1
#endif
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name JTAG interface configuration
*
* Enable/Disable the JTAG DAP and TAP interfaces on the chip.
* Setting this to 0 will disable access to the debug interface
* to secure deployed images.
* @{
*/
#ifndef CCXXWARE_CONF_JTAG_INTERFACE_ENABLE
#define CCXXWARE_CONF_JTAG_INTERFACE_ENABLE 1
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name ROM Bootloader configuration
*
* Enable/Disable the ROM bootloader in your image, if the board supports it.
* Look in board.h to choose the DIO and corresponding level that will cause
* the chip to enter bootloader mode.
* @{
*/
#ifndef ROM_BOOTLOADER_ENABLE
#define ROM_BOOTLOADER_ENABLE 0
#endif
/** @} */
#include "cc13xx-cc26xx-def.h"
/*---------------------------------------------------------------------------*/
/**
* \name Button configurations
@ -229,95 +70,12 @@
/* Platform-specific define to signify sensor reading failure */
#define CC26XX_SENSOR_READING_ERROR 0x80000000
/*---------------------------------------------------------------------------*/
/**
* \name Compiler configuration and platform-specific type definitions
*
* Those values are not meant to be modified by the user
* @{
*/
#define CLOCK_CONF_SECOND 128
/* Compiler configurations */
#define CCIF
#define CLIF
/* Platform typedefs */
typedef uint32_t clock_time_t;
typedef uint32_t uip_stats_t;
/* Clock (time) comparison macro */
#define CLOCK_LT(a, b) ((signed long)((a) - (b)) < 0)
/*
* rtimer.h typedefs rtimer_clock_t as unsigned short. We need to define
* RTIMER_CLOCK_DIFF to override this
*/
typedef uint32_t rtimer_clock_t;
#define RTIMER_CLOCK_DIFF(a, b) ((int32_t)((a) - (b)))
/* --------------------------------------------------------------------- */
/* TSCH related defines */
/* Delay between GO signal and SFD */
#define RADIO_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(81))
/* Delay between GO signal and start listening.
* This value is so small because the radio is constantly on within each timeslot. */
#define RADIO_DELAY_BEFORE_RX ((unsigned)US_TO_RTIMERTICKS(15))
/* Delay between the SFD finishes arriving and it is detected in software. */
#define RADIO_DELAY_BEFORE_DETECT ((unsigned)US_TO_RTIMERTICKS(352))
/* Timer conversion; radio is running at 4 MHz */
#define RADIO_TIMER_SECOND 4000000u
#if (RTIMER_SECOND % 256) || (RADIO_TIMER_SECOND % 256)
#error RADIO_TO_RTIMER macro must be fixed!
#endif
#define RADIO_TO_RTIMER(X) ((uint32_t)(((uint64_t)(X)*(RTIMER_SECOND / 256)) / (RADIO_TIMER_SECOND / 256)))
#define USEC_TO_RADIO(X) ((X) * 4)
/* The PHY header (preamble + SFD, 4+1 bytes) duration is equivalent to 10 symbols */
#define RADIO_IEEE_802154_PHY_HEADER_DURATION_USEC 160
/* Do not turn off TSCH within a timeslot: not enough time */
#define TSCH_CONF_RADIO_ON_DURING_TIMESLOT 1
/* Disable TSCH frame filtering */
#define TSCH_CONF_HW_FRAME_FILTERING 0
/* Use hardware timestamps */
#ifndef TSCH_CONF_RESYNC_WITH_SFD_TIMESTAMPS
#define TSCH_CONF_RESYNC_WITH_SFD_TIMESTAMPS 1
#define TSCH_CONF_TIMESYNC_REMOVE_JITTER 0
#endif
#ifndef TSCH_CONF_BASE_DRIFT_PPM
/* The drift compared to "true" 10ms slots.
* Enable adaptive sync to enable compensation for this.
* Slot length 10000 usec
* 328 ticks
* Tick duration 30.517578125 usec
* Real slot duration 10009.765625 usec
* Target - real duration = -9.765625 usec
* TSCH_CONF_BASE_DRIFT_PPM -977
*/
#define TSCH_CONF_BASE_DRIFT_PPM -977
#endif
/* 10 times per second */
#ifndef TSCH_CONF_CHANNEL_SCAN_DURATION
#define TSCH_CONF_CHANNEL_SCAN_DURATION (CLOCK_SECOND / 10)
#endif
/* Slightly reduce the TSCH guard time (from 2200 usec to 1800 usec) to make sure
* the CC26xx radio has sufficient time to start up. */
#ifndef TSCH_CONF_RX_WAIT
#define TSCH_CONF_RX_WAIT 1800
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/* board.h assumes that basic configuration is done */
#include "board.h"
/*---------------------------------------------------------------------------*/
/* Include CPU-related configuration */
#include "cc13xx-cc26xx-conf.h"
/*---------------------------------------------------------------------------*/
#endif /* CONTIKI_CONF_H */
/** @} */

View File

@ -53,51 +53,7 @@
#include PROJECT_CONF_PATH
#endif /* PROJECT_CONF_PATH */
/*---------------------------------------------------------------------------*/
/**
* \name Compiler configuration and platform-specific type definitions
*
* Those values are not meant to be modified by the user
* @{
*/
#define CLOCK_CONF_SECOND 128
/* Compiler configurations */
#define CCIF
#define CLIF
/* Platform typedefs */
typedef uint32_t clock_time_t;
typedef uint32_t uip_stats_t;
/*
* rtimer.h typedefs rtimer_clock_t as unsigned short. We need to define
* RTIMER_CLOCK_DIFF to override this
*/
typedef uint32_t rtimer_clock_t;
#define RTIMER_CLOCK_DIFF(a, b) ((int32_t)((a) - (b)))
/** @} */
/*---------------------------------------------------------------------------*/
/* 352us from calling transmit() until the SFD byte has been sent */
#define RADIO_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(352))
/* 192us as in datasheet but ACKs are not always received, so adjusted to 250us */
#define RADIO_DELAY_BEFORE_RX ((unsigned)US_TO_RTIMERTICKS(250))
#define RADIO_DELAY_BEFORE_DETECT 0
#ifndef TSCH_CONF_BASE_DRIFT_PPM
/* The drift compared to "true" 10ms slots.
* Enable adaptive sync to enable compensation for this.
* Slot length 10000 usec
* 328 ticks
* Tick duration 30.517578125 usec
* Real slot duration 10009.765625 usec
* Target - real duration = -9.765625 usec
* TSCH_CONF_BASE_DRIFT_PPM -977
*/
#define TSCH_CONF_BASE_DRIFT_PPM -977
#endif
#if MAC_CONF_WITH_TSCH
#define TSCH_CONF_HW_FRAME_FILTERING 0
#endif /* MAC_CONF_WITH_TSCH */
#include "cc2538-def.h"
/*---------------------------------------------------------------------------*/
/**
* \name Serial Boot Loader Backdoor configuration
@ -127,172 +83,6 @@ typedef uint32_t rtimer_clock_t;
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name CFS configuration
*
* @{
*/
#ifndef COFFEE_CONF_SIZE
#define COFFEE_CONF_SIZE (4 * COFFEE_SECTOR_SIZE)
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Watchdog Timer configuration
*
* @{
*/
#ifndef WATCHDOG_CONF_ENABLE
#define WATCHDOG_CONF_ENABLE 1 /**< Enable the watchdog timer */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name USB 'core' configuration
*
* Those values are not meant to be modified by the user, except where stated
* otherwise
* @{
*/
#define CTRL_EP_SIZE 8
#define USB_EP1_SIZE 32
#define USB_EP2_SIZE 64
#define USB_EP3_SIZE 64
#define USB_ARCH_WRITE_NOTIFY 0
#ifndef USB_ARCH_CONF_DMA
#define USB_ARCH_CONF_DMA 1 /**< Change to Enable/Disable USB DMA */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name uDMA Configuration and channel allocations
*
* @{
*/
#define USB_ARCH_CONF_RX_DMA_CHAN 0 /**< USB -> RAM DMA channel */
#define USB_ARCH_CONF_TX_DMA_CHAN 1 /**< RAM -> USB DMA channel */
#define CC2538_RF_CONF_TX_DMA_CHAN 2 /**< RF -> RAM DMA channel */
#define CC2538_RF_CONF_RX_DMA_CHAN 3 /**< RAM -> RF DMA channel */
#define UDMA_CONF_MAX_CHANNEL CC2538_RF_CONF_RX_DMA_CHAN
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Character I/O Configuration
*
* @{
*/
#ifndef UART_CONF_ENABLE
#define UART_CONF_ENABLE 1 /**< Enable/Disable UART I/O */
#endif
#ifndef UART0_CONF_BAUD_RATE
#define UART0_CONF_BAUD_RATE 115200 /**< Default UART0 baud rate */
#endif
#ifndef UART1_CONF_BAUD_RATE
#define UART1_CONF_BAUD_RATE 115200 /**< Default UART1 baud rate */
#endif
#ifndef SLIP_ARCH_CONF_USB
#define SLIP_ARCH_CONF_USB 0 /**< SLIP over UART by default */
#endif
#ifndef DBG_CONF_USB
#define DBG_CONF_USB 0 /**< All debugging over UART by default */
#endif
#ifndef SERIAL_LINE_CONF_UART
#define SERIAL_LINE_CONF_UART 0 /**< UART to use with serial line */
#endif
#if !SLIP_ARCH_CONF_USB
#ifndef SLIP_ARCH_CONF_UART
#define SLIP_ARCH_CONF_UART 0 /**< UART to use with SLIP */
#endif
#endif
#if !DBG_CONF_USB
#ifndef DBG_CONF_UART
#define DBG_CONF_UART 0 /**< UART to use for debugging */
#endif
#endif
#ifndef UART1_CONF_UART
#define UART1_CONF_UART 0 /**< UART to use for examples relying on
the uart1_* API */
#endif
#ifndef SLIP_ARCH_CONF_ENABLED
/*
* Determine whether we need SLIP
* This will keep working while UIP_FALLBACK_INTERFACE and CMD_CONF_OUTPUT
* keep using SLIP
*/
#if defined(UIP_FALLBACK_INTERFACE) || defined(CMD_CONF_OUTPUT)
#define SLIP_ARCH_CONF_ENABLED 1
#endif
#endif
/**
* \brief Define this as 1 to build a headless node.
*
* The UART will not be initialised its clock will be gated, offering some
* energy savings. The USB will not be initialised either
*/
#ifndef CC2538_CONF_QUIET
#define CC2538_CONF_QUIET 0
#endif
/* CC2538_CONF_QUIET is hard and overrides all other related defines */
#if CC2538_CONF_QUIET
#undef USB_SERIAL_CONF_ENABLE
#define USB_SERIAL_CONF_ENABLE 0
#undef UART_CONF_ENABLE
#define UART_CONF_ENABLE 0
#endif /* CC2538_CONF_QUIET */
/**
* \brief Enable the USB core only if we need it
*/
#ifndef USB_SERIAL_CONF_ENABLE
#define USB_SERIAL_CONF_ENABLE \
((SLIP_ARCH_CONF_USB && SLIP_ARCH_CONF_ENABLED) || \
(MAC_CONF_WITH_TSCH && (SLIP_ARCH_CONF_ENABLED || BUILD_WITH_SHELL)) || \
DBG_CONF_USB)
#endif
/*
* If debugging and SLIP use the same peripheral, this will be 1. Don't modify
* this
*/
#if SLIP_ARCH_CONF_ENABLED
#define DBG_CONF_SLIP_MUX (SLIP_ARCH_CONF_USB == DBG_CONF_USB && \
(SLIP_ARCH_CONF_USB || \
SLIP_ARCH_CONF_UART == DBG_CONF_UART))
#endif
/*
* Automatic detection of whether a specific UART is in use
*/
#define UART_IN_USE_BY_SERIAL_LINE(u) (SERIAL_LINE_CONF_UART == (u))
#define UART_IN_USE_BY_SLIP(u) (SLIP_ARCH_CONF_ENABLED && \
!SLIP_ARCH_CONF_USB && \
SLIP_ARCH_CONF_UART == (u))
#define UART_IN_USE_BY_DBG(u) (!DBG_CONF_USB && DBG_CONF_UART == (u))
#define UART_IN_USE_BY_UART1(u) (UART1_CONF_UART == (u))
#define UART_IN_USE(u) ( \
UART_CONF_ENABLE && \
(UART_IN_USE_BY_SERIAL_LINE(u) || \
UART_IN_USE_BY_SLIP(u) || \
UART_IN_USE_BY_DBG(u) || \
UART_IN_USE_BY_UART1(u)) \
)
/** @} */
/*---------------------------------------------------------------------------*/
/* board.h assumes that basic configuration is done */
#include "board.h"
/*---------------------------------------------------------------------------*/
@ -363,86 +153,6 @@ typedef uint32_t rtimer_clock_t;
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name IEEE address configuration
*
* Used to generate our link-layer & IPv6 address
* @{
*/
/**
* \brief Location of the IEEE address
* 0 => Read from InfoPage,
* 1 => Use a hardcoded address, configured by IEEE_ADDR_CONF_ADDRESS
*/
#ifndef IEEE_ADDR_CONF_HARDCODED
#define IEEE_ADDR_CONF_HARDCODED 0
#endif
/**
* \brief The hardcoded IEEE address to be used when IEEE_ADDR_CONF_HARDCODED
* is defined as 1
*/
#ifndef IEEE_ADDR_CONF_ADDRESS
#define IEEE_ADDR_CONF_ADDRESS { 0x00, 0x12, 0x4B, 0x00, 0x89, 0xAB, 0xCD, 0xEF }
#endif
/**
* \brief Location of the IEEE address in the InfoPage when
* IEEE_ADDR_CONF_HARDCODED is defined as 0
* 0 => Use the primary address location
* 1 => Use the secondary address location
*/
#ifndef IEEE_ADDR_CONF_USE_SECONDARY_LOCATION
#define IEEE_ADDR_CONF_USE_SECONDARY_LOCATION 0
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name RF configuration
*
* @{
*/
/* RF Config */
#ifdef RF_CHANNEL
#define CC2538_RF_CONF_CHANNEL RF_CHANNEL
#endif
#ifndef CC2538_RF_CONF_CHANNEL
#define CC2538_RF_CONF_CHANNEL 26
#endif /* CC2538_RF_CONF_CHANNEL */
#ifndef CC2538_RF_CONF_AUTOACK
#define CC2538_RF_CONF_AUTOACK 1 /**< RF H/W generates ACKs */
#endif /* CC2538_CONF_AUTOACK */
#ifndef CC2538_RF_CONF_TX_USE_DMA
#define CC2538_RF_CONF_TX_USE_DMA 1 /**< RF TX over DMA */
#endif
#ifndef CC2538_RF_CONF_RX_USE_DMA
#define CC2538_RF_CONF_RX_USE_DMA 1 /**< RF RX over DMA */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Security
*
* @{
*/
#ifndef CRYPTO_CONF_INIT
#define CRYPTO_CONF_INIT 1 /**< Whether to init cryptoprocessor */
#endif
#ifndef AES_128_CONF
#define AES_128_CONF cc2538_aes_128_driver /**< AES-128 driver */
#endif
#ifndef CCM_STAR_CONF
#define CCM_STAR_CONF cc2538_ccm_star_driver /**< AES-CCM* driver */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name RTC
*
@ -464,7 +174,9 @@ typedef uint32_t rtimer_clock_t;
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/* Include CPU-related configuration */
#include "cc2538-conf.h"
/*---------------------------------------------------------------------------*/
#endif /* CONTIKI_CONF_H_ */
/*---------------------------------------------------------------------------*/
/** @} */

View File

@ -0,0 +1,7 @@
CONTIKI_PROJECT = data-structures
all: $(CONTIKI_PROJECT)
CONTIKI = ../../..
include $(CONTIKI)/Makefile.include

View File

@ -0,0 +1,383 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* Copyright (c) 2017, James Pope
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "lib/stack.h"
#include "lib/queue.h"
#include "lib/circular-list.h"
#include "lib/dbl-list.h"
#include "lib/dbl-circ-list.h"
#include "lib/random.h"
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
/*---------------------------------------------------------------------------*/
PROCESS(data_structure_process, "Data structure process");
AUTOSTART_PROCESSES(&data_structure_process);
/*---------------------------------------------------------------------------*/
STACK(demo_stack);
QUEUE(demo_queue);
CIRCULAR_LIST(demo_cll);
DBL_LIST(demo_dbl);
DBL_CIRC_LIST(demo_dblcl);
/*---------------------------------------------------------------------------*/
typedef struct demo_struct_s {
struct demo_struct_s *next;
struct demo_struct_s *previous;
unsigned short value;
} demo_struct_t;
/*---------------------------------------------------------------------------*/
#define DATA_STRUCTURE_DEMO_ELEMENT_COUNT 4
static demo_struct_t elements[DATA_STRUCTURE_DEMO_ELEMENT_COUNT];
/*---------------------------------------------------------------------------*/
static void
dbl_circ_list_print(dbl_circ_list_t dblcl)
{
demo_struct_t *this = *dblcl;
if(*dblcl == NULL) {
printf("Length=0\n");
return;
}
do {
printf("<--(0x%04x)--0x%04x--(0x%04x)-->", this->previous->value,
this->value, this->next->value);
this = this->next;
} while(this != *dblcl);
printf(" (Length=%lu)\n", dbl_circ_list_length(dblcl));
}
/*---------------------------------------------------------------------------*/
static void
demonstrate_dbl_circ_list(void)
{
int i;
demo_struct_t *this;
dbl_circ_list_init(demo_dblcl);
printf("============================\n");
printf("Circular, doubly-linked list\n");
for(i = 0; i < DATA_STRUCTURE_DEMO_ELEMENT_COUNT; i++) {
elements[i].next = NULL;
elements[i].previous = NULL;
}
/* Add elements */
dbl_circ_list_add_tail(demo_dblcl, &elements[0]);
printf("Add tail : 0x%04x | ", elements[0].value);
dbl_circ_list_print(demo_dblcl);
dbl_circ_list_add_after(demo_dblcl, &elements[0], &elements[1]);
printf("Add after : 0x%04x | ", elements[1].value);
dbl_circ_list_print(demo_dblcl);
dbl_circ_list_add_head(demo_dblcl, &elements[2]);
printf("Add head : 0x%04x | ", elements[2].value);
dbl_circ_list_print(demo_dblcl);
dbl_circ_list_add_before(demo_dblcl, &elements[2], &elements[3]);
printf("Add before: 0x%04x | ", elements[3].value);
dbl_circ_list_print(demo_dblcl);
/* Remove head */
this = dbl_circ_list_head(demo_dblcl);
printf("Rm head: (0x%04x) | ", this->value);
dbl_circ_list_remove(demo_dblcl, this);
dbl_circ_list_print(demo_dblcl);
/* Remove currently second element */
this = ((demo_struct_t *)dbl_circ_list_head(demo_dblcl))->next;
printf("Rm 2nd : (0x%04x) | ", this->value);
dbl_circ_list_remove(demo_dblcl, this);
dbl_circ_list_print(demo_dblcl);
/* Remove tail */
this = dbl_circ_list_tail(demo_dblcl);
printf("Rm tail: (0x%04x) | ", this->value);
dbl_circ_list_remove(demo_dblcl, this);
dbl_circ_list_print(demo_dblcl);
/* Remove last remaining element */
this = dbl_circ_list_tail(demo_dblcl);
printf("Rm last: (0x%04x) | ", this->value);
dbl_circ_list_remove(demo_dblcl, this);
dbl_circ_list_print(demo_dblcl);
printf("Circular, doubly-linked list is%s empty\n",
dbl_circ_list_is_empty(demo_dblcl) ? "" : " not");
}
/*---------------------------------------------------------------------------*/
static void
dbl_list_print(dbl_list_t dll)
{
demo_struct_t *this;
for(this = *dll; this != NULL; this = this->next) {
printf("<--(");
if(this->previous == NULL) {
printf(" null ");
} else {
printf("0x%04x", this->previous->value);
}
printf(")--0x%04x--(", this->value);
if(this->next == NULL) {
printf(" null ");
} else {
printf("0x%04x", this->next->value);
}
printf(")-->");
}
printf(" (Length=%lu)\n", dbl_list_length(dll));
}
/*---------------------------------------------------------------------------*/
static void
demonstrate_dbl_list(void)
{
int i;
demo_struct_t *this;
dbl_list_init(demo_dbl);
printf("==================\n");
printf("Doubly-linked list\n");
for(i = 0; i < DATA_STRUCTURE_DEMO_ELEMENT_COUNT; i++) {
elements[i].next = NULL;
elements[i].previous = NULL;
}
/* Add elements */
dbl_list_add_tail(demo_dbl, &elements[0]);
printf("Add tail : 0x%04x | ", elements[0].value);
dbl_list_print(demo_dbl);
dbl_list_add_after(demo_dbl, &elements[0], &elements[1]);
printf("Add after : 0x%04x | ", elements[1].value);
dbl_list_print(demo_dbl);
dbl_list_add_head(demo_dbl, &elements[2]);
printf("Add head : 0x%04x | ", elements[2].value);
dbl_list_print(demo_dbl);
dbl_list_add_before(demo_dbl, &elements[2], &elements[3]);
printf("Add before: 0x%04x | ", elements[3].value);
dbl_list_print(demo_dbl);
/* Remove head */
this = dbl_list_head(demo_dbl);
printf("Rm head: (0x%04x) | ", this->value);
dbl_list_remove(demo_dbl, this);
dbl_list_print(demo_dbl);
/* Remove currently second element */
this = ((demo_struct_t *)dbl_list_head(demo_dbl))->next;
printf("Rm 2nd : (0x%04x) | ", this->value);
dbl_list_remove(demo_dbl, this);
dbl_list_print(demo_dbl);
/* Remove tail */
this = dbl_list_tail(demo_dbl);
printf("Rm tail: (0x%04x) | ", this->value);
dbl_list_remove(demo_dbl, this);
dbl_list_print(demo_dbl);
/* Remove last remaining element */
this = dbl_list_tail(demo_dbl);
printf("Rm last: (0x%04x) | ", this->value);
dbl_list_remove(demo_dbl, this);
dbl_list_print(demo_dbl);
printf("Doubly-linked list is%s empty\n",
dbl_list_is_empty(demo_dbl) ? "" : " not");
}
/*---------------------------------------------------------------------------*/
static void
circular_list_print(circular_list_t cl)
{
demo_struct_t *this = *cl;
if(*cl == NULL) {
printf("Length=0\n");
return;
}
do {
printf("0x%04x-->", this->value);
this = this->next;
} while(this != *cl);
printf("0x%04x (Length=%lu)\n", this->value, circular_list_length(cl));
}
/*---------------------------------------------------------------------------*/
static void
demonstrate_circular_list(void)
{
int i;
circular_list_init(demo_cll);
printf("============================\n");
printf("Circular, singly-linked list\n");
/* Add elements */
for(i = 0; i < DATA_STRUCTURE_DEMO_ELEMENT_COUNT; i++) {
elements[i].next = NULL;
circular_list_add(demo_cll, &elements[i]);
printf("Add: 0x%04x | ", elements[i].value);
circular_list_print(demo_cll);
}
/* Remove head */
circular_list_remove(demo_cll, circular_list_head(demo_cll));
printf("Remove head | ");
circular_list_print(demo_cll);
/* Remove currently second element */
circular_list_remove(demo_cll,
((demo_struct_t *)circular_list_head(demo_cll))->next);
printf("Remove 2nd | ");
circular_list_print(demo_cll);
/* Remove tail */
circular_list_remove(demo_cll, circular_list_tail(demo_cll));
printf("Remove tail | ");
circular_list_print(demo_cll);
/* Remove last remaining element */
circular_list_remove(demo_cll, circular_list_tail(demo_cll));
printf("Remove last | ");
circular_list_print(demo_cll);
printf("Circular list is%s empty\n",
circular_list_is_empty(demo_cll) ? "" : " not");
}
/*---------------------------------------------------------------------------*/
static void
demonstrate_stack(void)
{
int i;
demo_struct_t *this;
printf("=====\n");
printf("Stack\n");
stack_init(demo_stack);
/* Add elements */
for(i = 0; i < DATA_STRUCTURE_DEMO_ELEMENT_COUNT; i++) {
elements[i].next = NULL;
stack_push(demo_stack, &elements[i]);
printf("Push: 0x%04x\n", elements[i].value);
}
printf("Peek: 0x%04x\n",
((demo_struct_t *)stack_peek(demo_stack))->value);
for(i = 0; i <= DATA_STRUCTURE_DEMO_ELEMENT_COUNT; i++) {
this = stack_pop(demo_stack);
printf("Pop: ");
if(this == NULL) {
printf("(stack underflow)\n");
} else {
printf("0x%04x\n", this->value);
}
}
printf("Stack is%s empty\n",
stack_is_empty(demo_stack) ? "" : " not");
}
/*---------------------------------------------------------------------------*/
static void
demonstrate_queue(void)
{
int i;
demo_struct_t *this;
printf("=====\n");
printf("Queue\n");
queue_init(demo_queue);
/* Add elements */
for(i = 0; i < DATA_STRUCTURE_DEMO_ELEMENT_COUNT; i++) {
elements[i].next = NULL;
queue_enqueue(demo_queue, &elements[i]);
printf("Enqueue: 0x%04x\n", elements[i].value);
}
printf("Peek: 0x%04x\n",
((demo_struct_t *)queue_peek(demo_queue))->value);
for(i = 0; i <= DATA_STRUCTURE_DEMO_ELEMENT_COUNT; i++) {
this = queue_dequeue(demo_queue);
printf("Dequeue: ");
if(this == NULL) {
printf("(queue underflow)\n");
} else {
printf("0x%04lx\n", (unsigned long)this->value);
}
}
printf("Queue is%s empty\n",
queue_is_empty(demo_queue) ? "" : " not");
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(data_structure_process, ev, data)
{
int i;
PROCESS_BEGIN();
/* Generate some elements */
printf("Elements: [");
for(i = 0; i < DATA_STRUCTURE_DEMO_ELEMENT_COUNT; i++) {
elements[i].next = NULL;
elements[i].value = random_rand();
printf(" 0x%04x", elements[i].value);
}
printf(" ]\n");
demonstrate_stack();
demonstrate_queue();
demonstrate_circular_list();
demonstrate_dbl_list();
demonstrate_dbl_circ_list();
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View File

@ -0,0 +1,5 @@
CONTIKI_PROJECT = example-stack-check
all: $(CONTIKI_PROJECT)
CONTIKI = ../../..
include $(CONTIKI)/Makefile.include

View File

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<simconf>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mrm</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mspsim</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/avrora</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/serial_socket</project>
<simulation>
<title>Stack checker example</title>
<delaytime>0</delaytime>
<randomseed>123456</randomseed>
<motedelay_us>1000000</motedelay_us>
<radiomedium>
org.contikios.cooja.radiomediums.UDGM
<transmitting_range>50.0</transmitting_range>
<interference_range>50.0</interference_range>
<success_ratio_tx>1.0</success_ratio_tx>
<success_ratio_rx>1.0</success_ratio_rx>
</radiomedium>
<events>
<logoutput>40000</logoutput>
</events>
<motetype>
org.contikios.cooja.mspmote.SkyMoteType
<identifier>node</identifier>
<description>RPL Root</description>
<source EXPORT="discard">[CONFIG_DIR]/example-stack-check.c</source>
<commands EXPORT="discard">make example-stack-check.sky TARGET=sky</commands>
<firmware EXPORT="copy">[CONFIG_DIR]/example-stack-check.sky</firmware>
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
<moteinterface>org.contikios.cooja.interfaces.RimeAddress</moteinterface>
<moteinterface>org.contikios.cooja.interfaces.IPAddress</moteinterface>
<moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
<moteinterface>org.contikios.cooja.interfaces.MoteAttributes</moteinterface>
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspClock</moteinterface>
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspMoteID</moteinterface>
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyButton</moteinterface>
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyFlash</moteinterface>
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyCoffeeFilesystem</moteinterface>
<moteinterface>org.contikios.cooja.mspmote.interfaces.Msp802154Radio</moteinterface>
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspSerial</moteinterface>
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyLED</moteinterface>
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspDebugOutput</moteinterface>
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyTemperature</moteinterface>
</motetype>
<mote>
<breakpoints />
<interface_config>
org.contikios.cooja.interfaces.Position
<x>33.260163187353555</x>
<y>30.643217359962595</y>
<z>0.0</z>
</interface_config>
<interface_config>
org.contikios.cooja.mspmote.interfaces.MspMoteID
<id>1</id>
</interface_config>
<motetype_identifier>node</motetype_identifier>
</mote>
</simulation>
<plugin>
org.contikios.cooja.plugins.SimControl
<width>259</width>
<z>4</z>
<height>179</height>
<location_x>0</location_x>
<location_y>0</location_y>
</plugin>
<plugin>
org.contikios.cooja.plugins.Visualizer
<plugin_config>
<skin>org.contikios.cooja.plugins.skins.IDVisualizerSkin</skin>
<skin>org.contikios.cooja.plugins.skins.UDGMVisualizerSkin</skin>
<skin>org.contikios.cooja.plugins.skins.MoteTypeVisualizerSkin</skin>
<viewport>2.898638306051894 0.0 0.0 2.898638306051894 -68.40918308040007 -27.82360366026197</viewport>
</plugin_config>
<width>258</width>
<z>2</z>
<height>209</height>
<location_x>0</location_x>
<location_y>178</location_y>
</plugin>
<plugin>
org.contikios.cooja.plugins.LogListener
<width>1024</width>
<z>3</z>
<height>311</height>
<location_x>0</location_x>
<location_y>385</location_y>
</plugin>
</simconf>

View File

@ -0,0 +1,88 @@
/*
* Copyright (c) 2017, University of Bristol - http://www.bris.ac.uk/
* 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.
*
*/
/**
* \file
* Test of Contiki system's stack checker functionality
* \author
* Atis Elsts <atis.elsts@bristol.ac.uk>
*/
#include "contiki.h"
#include "sys/stack-check.h"
#include "random.h"
#include <stdio.h>
#include <string.h>
#include <alloca.h>
/*---------------------------------------------------------------------------*/
PROCESS(example_process, "Stack check example");
AUTOSTART_PROCESSES(&example_process);
/*---------------------------------------------------------------------------*/
static void
nested_function(void)
{
printf("stack usage: %u permitted: %u\n",
stack_check_get_usage(), stack_check_get_reserved_size());
}
/*---------------------------------------------------------------------------*/
static void
test_function(void)
{
void *p;
uint16_t s;
/* allocate and fill some random bytes */
s = random_rand() % 1000;
printf("allocating %u bytes on the stack\n", s);
p = alloca(s);
memset(p, 0, s);
/* call the nested function to print stack usage */
nested_function();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(example_process, ev, data)
{
static struct etimer et;
PROCESS_BEGIN();
while(1) {
etimer_set(&et, CLOCK_SECOND * 2);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
test_function();
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 2017, University of Bristol - http://www.bris.ac.uk/
* 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.
*
*/
/**
* \file
* Project config file
* \author
* Atis Elsts <atis.elsts@bristol.ac.uk>
*
*/
#ifndef __PROJECT_CONF_H__
#define __PROJECT_CONF_H__
#define STACK_CHECK_CONF_ENABLED 1
#endif /* __PROJECT_CONF_H__ */

View File

@ -15,7 +15,7 @@ One possible border router is the Raspberry Pi 3 with the Raspbian OS
(for detailed instructions see the [Nordic Semiconductor guide](http://developer.nordicsemi.com/nRF5_IoT_SDK/doc/0.9.0/html/a00092.html)).
## Configuration
In addition to the configuration described in [BLEach README](../../../../arch/cpu/cc26xx-cc13xx/net/README.md) the following configuration is needed.
In addition to the configuration described in [BLEach README](../../../../arch/cpu/cc26xx-cc13xx/rf-core/README.md) the following configuration is needed.
To successfully communicate with a UDP server, the `SERVER_IP` define in `client.c` needs to be configured
to the IPv6 address of the UDP server.

View File

@ -37,14 +37,11 @@
* Joakim Eriksson <joakime@sics.se>
*/
#include <stdio.h>
#include <string.h>
#include "contiki.h"
#include "contiki-net.h"
#if UIP_CONF_TCP == 0
#error HTTP server needs TCP enabled
#endif
#include <stdio.h>
#include <string.h>
#include "httpd-simple.h"
#define webserver_log_file(...)

View File

@ -310,7 +310,6 @@ PT_THREAD(generate_routes(struct httpd_state *s))
PSOCK_END(&s->sout);
}
#if BORDER_ROUTER_CONF_WEBSERVER
/*---------------------------------------------------------------------------*/
PROCESS(webserver_nogui_process, "Web server");
PROCESS_THREAD(webserver_nogui_process, ev, data)
@ -332,4 +331,4 @@ httpd_simple_get_script(const char *name)
{
return generate_routes;
}
#endif /* BORDER_ROUTER_CONF_WEBSERVER */
/*---------------------------------------------------------------------------*/

View File

@ -44,7 +44,9 @@
#define WEBSERVER_CONF_CFS_CONNS 2
#endif
#ifndef BORDER_ROUTER_CONF_WEBSERVER
#define BORDER_ROUTER_CONF_WEBSERVER 1
#endif
#if BORDER_ROUTER_CONF_WEBSERVER
#define UIP_CONF_TCP 1

View File

@ -32,8 +32,10 @@
#ifndef TARGET_CONF_H_
#define TARGET_CONF_H_
/*---------------------------------------------------------------------------*/
#define QUEUEBUF_CONF_NUM 4
#define UIP_CONF_BUFFER_SIZE 140
/* Save some RAM and ROM */
#define QUEUEBUF_CONF_NUM 4
#define UIP_CONF_BUFFER_SIZE 140
#define BORDER_ROUTER_CONF_WEBSERVER 0
/*---------------------------------------------------------------------------*/
#endif /* TARGET_CONF_H_ */
/*---------------------------------------------------------------------------*/

View File

@ -33,7 +33,10 @@ udp_rx_callback(struct simple_udp_connection *c,
uint16_t datalen)
{
unsigned count = *(unsigned *)data;
LOG_INFO("Received response %u from ", count);
/* If tagging of traffic class is enabled tc will print number of
transmission - otherwise it will be 0 */
LOG_INFO("Received response %u (tc:%d) from ", count,
uipbuf_get_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS));
LOG_INFO_6ADDR(sender_addr);
LOG_INFO_("\n");
}
@ -61,6 +64,12 @@ PROCESS_THREAD(udp_client_process, ev, data)
LOG_INFO("Sending request %u to ", count);
LOG_INFO_6ADDR(&dag->dag_id);
LOG_INFO_("\n");
/* Set the number of transmissions to use for this packet -
this can be used to create more reliable transmissions or
less reliable than the default. Works end-to-end if
UIP_CONF_TAG_TC_WITH_VARIABLE_RETRANSMISSIONS is set to 1.
*/
uipbuf_set_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS, 1 + count % 5);
simple_udp_sendto(&udp_conn, &count, sizeof(count), &dag->dag_id);
count++;
}

View File

@ -2,7 +2,8 @@ sensniff Contiki Project
========================
This example can be used to create an IEEE 802.15.4 wireless sniffer firmware,
meant to be used in parallel with
[sensniff](https://github.com/g-oikonomou/sensniff).
[sensniff](https://github.com/g-oikonomou/sensniff). Sensniff is distributed
standalone, but also as part of Contiki-NG under `tools/sensniff`.
Running
=======

View File

@ -44,6 +44,7 @@
#include "contiki-net.h"
#include "sys/platform.h"
#include "sys/energest.h"
#include "sys/stack-check.h"
#include "dev/watchdog.h"
#include "services/orchestra/orchestra.h"
@ -77,14 +78,16 @@ main(void)
energest_init();
#if STACK_CHECK_ENABLED
stack_check_init();
#endif
platform_init_stage_two();
LOG_INFO("Starting " CONTIKI_VERSION_STRING "\n");
LOG_INFO(" Net: ");
LOG_INFO_("%s\n", NETSTACK_NETWORK.name);
LOG_INFO(" MAC: ");
LOG_INFO_("%s\n", NETSTACK_MAC.name);
LOG_INFO(" Net: %s\n", NETSTACK_NETWORK.name);
LOG_INFO(" MAC: %s\n", NETSTACK_MAC.name);
netstack_init();

157
os/lib/circular-list.c Normal file
View File

@ -0,0 +1,157 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* Copyright (c) 2017, James Pope
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup circular-singly-linked-list
* @{
*
* \file
* Implementation of circular singly linked lists
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "lib/circular-list.h"
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
/*---------------------------------------------------------------------------*/
struct cl {
struct cl *next;
};
/*---------------------------------------------------------------------------*/
void
circular_list_init(circular_list_t cl)
{
*cl = NULL;
}
/*---------------------------------------------------------------------------*/
void *
circular_list_head(circular_list_t cl)
{
return *cl;
}
/*---------------------------------------------------------------------------*/
void *
circular_list_tail(circular_list_t cl)
{
struct cl *this;
if(*cl == NULL) {
return NULL;
}
for(this = *cl; this->next != *cl; this = this->next);
return this;
}
/*---------------------------------------------------------------------------*/
void
circular_list_remove(circular_list_t cl, void *element)
{
struct cl *this, *previous;
if(*cl == NULL) {
return;
}
/*
* We start traversing from the second element.
* The head will be visited last. We always update the list's head after
* removal, just in case we have just removed the head.
*/
previous = *cl;
this = previous->next;
do {
if(this == element) {
previous->next = this->next;
*cl = this->next == this ? NULL : previous;
return;
}
previous = this;
this = this->next;
} while(this != ((struct cl *)*cl)->next);
}
/*---------------------------------------------------------------------------*/
void
circular_list_add(circular_list_t cl, void *element)
{
struct cl *head;
if(element == NULL) {
return;
}
/* Don't add twice */
circular_list_remove(cl, element);
head = *cl;
if(head == NULL) {
/* If the list was empty, we update the new element to point to itself */
((struct cl *)element)->next = element;
} else {
/* If the list exists, we add the new element between the current head and
* the previously second element. */
((struct cl *)element)->next = head->next;
head->next = element;
}
/* In all cases, the new element becomes the list's new head */
*cl = element;
}
/*---------------------------------------------------------------------------*/
unsigned long
circular_list_length(circular_list_t cl)
{
unsigned long len = 1;
struct cl *this;
if(circular_list_is_empty(cl)) {
return 0;
}
for(this = *cl; this->next != *cl; this = this->next) {
len++;
}
return len;
}
/*---------------------------------------------------------------------------*/
bool
circular_list_is_empty(circular_list_t cl)
{
return *cl == NULL ? true : false;
}
/*---------------------------------------------------------------------------*/
/** @} */

155
os/lib/circular-list.h Normal file
View File

@ -0,0 +1,155 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* Copyright (c) 2017, James Pope
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
/** \addtogroup data
* @{
*
* \defgroup circular-singly-linked-list Circular, singly-linked list
*
* This library provides functions for the creation and manipulation of
* circular, singly-linked lists.
*
* A circular, singly-linked list is declared using the CIRCULAR_LIST macro.
* Elements must be allocated by the calling code and must be of a C struct
* datatype. In this struct, the first field must be a pointer called \e next.
* This field will be used by the library to maintain the list. Application
* code must not modify this field directly.
*
* Functions that modify the list (add / remove) will, in the general case,
* update the list's head and item order. If you call one of these functions
* as part of a list traversal, it is advised to stop / restart traversing
* after the respective function returns.
* @{
*/
/*---------------------------------------------------------------------------*/
#ifndef CIRCULAR_LIST_H_
#define CIRCULAR_LIST_H_
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
/*---------------------------------------------------------------------------*/
/**
* \brief Define a circular, singly-linked list.
*
* This macro defines a circular, singly-linked list.
*
* The datatype for elements must be a C struct. The struct's first member must
* be a pointer called \e next. This is used internally by the library to
* maintain data structure integrity and must not be modified directly by
* application code.
*
* \param name The name of the circular, singly-linked list.
*/
#define CIRCULAR_LIST(name) \
static void *name##_circular_list = NULL; \
static circular_list_t name = (circular_list_t)&name##_circular_list
/*---------------------------------------------------------------------------*/
/**
* \brief The circular, singly-linked list datatype
*/
typedef void **circular_list_t;
/*---------------------------------------------------------------------------*/
/**
* \brief Initialise a circular, singly-linked list.
* \param cl The circular, singly-linked list.
*/
void circular_list_init(circular_list_t cl);
/**
* \brief Return the tail of a circular, singly-linked list.
* \param cl The circular, singly-linked list.
* \return A pointer to the list's head, or NULL if the list is empty
*/
void *circular_list_head(circular_list_t cl);
/**
* \brief Return the tail of a circular, singly-linked list.
* \param cl The circular, singly-linked list.
* \return A pointer to the list's tail, or NULL if the list is empty
*/
void *circular_list_tail(circular_list_t cl);
/**
* \brief Add an element to a circular, singly-linked list.
* \param cl The circular, singly-linked list.
* \param element A pointer to the element to be added.
*
* The caller should make no assumptions as to the position in the list of the
* new element.
*
* After this function returns, the list's head is not guaranteed to be the
* same as it was before the addition.
*
* Calling this function will update the list's head and item order. If you
* call this function as part of a list traversal, it is advised to stop
* traversing after this function returns.
*/
void circular_list_add(circular_list_t cl, void *element);
/**
* \brief Remove an element from a circular, singly-linked list.
* \param cl The circular, singly-linked list.
* \param element A pointer to the element to be removed.
*
* After this function returns, the list's head is not guaranteed to be the
* same as it was before the addition.
*
* Calling this function will update the list's head and item order. If you
* call this function as part of a list traversal, it is advised to stop
* traversing after this function returns.
*/
void circular_list_remove(circular_list_t cl, void *element);
/**
* \brief Get the length of a circular, singly-linked list.
* \param cl The circular, singly-linked list.
* \return The number of elements in the list
*/
unsigned long circular_list_length(circular_list_t cl);
/**
* \brief Determine whether a circular, singly-linked list is empty.
* \param cl The circular, singly-linked list.
* \retval true The list is empty
* \retval false The list is not empty
*/
bool circular_list_is_empty(circular_list_t cl);
/*---------------------------------------------------------------------------*/
#endif /* CIRCULAR_LIST_H_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

227
os/lib/dbl-circ-list.c Normal file
View File

@ -0,0 +1,227 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* Copyright (c) 2017, James Pope
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup doubly-linked-circular-list
* @{
*
* \file
* Implementation of circular, doubly-linked lists
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "lib/dbl-circ-list.h"
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
/*---------------------------------------------------------------------------*/
struct dblcl {
struct dblcl *next;
struct dblcl *previous;
};
/*---------------------------------------------------------------------------*/
void
dbl_circ_list_init(dbl_circ_list_t dblcl)
{
*dblcl = NULL;
}
/*---------------------------------------------------------------------------*/
void *
dbl_circ_list_head(dbl_circ_list_t dblcl)
{
return *dblcl;
}
/*---------------------------------------------------------------------------*/
void *
dbl_circ_list_tail(dbl_circ_list_t dblcl)
{
struct dblcl *this;
if(*dblcl == NULL) {
return NULL;
}
for(this = *dblcl; this->next != *dblcl; this = this->next);
return this;
}
/*---------------------------------------------------------------------------*/
void
dbl_circ_list_remove(dbl_circ_list_t dblcl, void *element)
{
struct dblcl *this;
if(*dblcl == NULL || element == NULL) {
return;
}
this = *dblcl;
do {
if(this == element) {
this->previous->next = this->next;
this->next->previous = this->previous;
/* We need to update the head of the list if we removed the head */
if(*dblcl == element) {
*dblcl = this->next == this ? NULL : this->next;
}
this->next = NULL;
this->previous = NULL;
return;
}
this = this->next;
} while(this != *dblcl);
}
/*---------------------------------------------------------------------------*/
void
dbl_circ_list_add_head(dbl_circ_list_t dblcl, void *element)
{
struct dblcl *head;
if(element == NULL) {
return;
}
/* Don't add twice */
dbl_circ_list_remove(dblcl, element);
head = dbl_circ_list_head(dblcl);
if(head == NULL) {
/* If the list was empty */
((struct dblcl *)element)->next = element;
((struct dblcl *)element)->previous = element;
} else {
/* If the list was not empty */
((struct dblcl *)element)->next = head;
((struct dblcl *)element)->previous = head->previous;
head->previous->next = element;
head->previous = element;
}
*dblcl = element;
}
/*---------------------------------------------------------------------------*/
void
dbl_circ_list_add_tail(dbl_circ_list_t dblcl, void *element)
{
struct dblcl *tail;
if(element == NULL) {
return;
}
/* Don't add twice */
dbl_circ_list_remove(dblcl, element);
tail = dbl_circ_list_tail(dblcl);
if(tail == NULL) {
/* If the list was empty */
((struct dblcl *)element)->next = element;
((struct dblcl *)element)->previous = element;
*dblcl = element;
} else {
/* If the list was not empty */
((struct dblcl *)element)->next = *dblcl;
((struct dblcl *)element)->previous = tail;
tail->next->previous = element;
tail->next = element;
}
}
/*---------------------------------------------------------------------------*/
void
dbl_circ_list_add_after(dbl_circ_list_t dblcl, void *existing, void *element)
{
if(element == NULL || existing == NULL) {
return;
}
/* Don't add twice */
dbl_circ_list_remove(dblcl, element);
((struct dblcl *)element)->next = ((struct dblcl *)existing)->next;
((struct dblcl *)element)->previous = existing;
((struct dblcl *)existing)->next->previous = element;
((struct dblcl *)existing)->next = element;
}
/*---------------------------------------------------------------------------*/
void
dbl_circ_list_add_before(dbl_circ_list_t dblcl, void *existing, void *element)
{
if(element == NULL || existing == NULL) {
return;
}
/* Don't add twice */
dbl_circ_list_remove(dblcl, element);
((struct dblcl *)element)->next = existing;
((struct dblcl *)element)->previous = ((struct dblcl *)existing)->previous;
((struct dblcl *)existing)->previous->next = element;
((struct dblcl *)existing)->previous = element;
/* If we added before the list's head, we must update the head */
if(*dblcl == existing) {
*dblcl = element;
}
}
/*---------------------------------------------------------------------------*/
unsigned long
dbl_circ_list_length(dbl_circ_list_t dblcl)
{
unsigned long len = 1;
struct dblcl *this;
if(*dblcl == NULL) {
return 0;
}
for(this = *dblcl; this->next != *dblcl; this = this->next) {
len++;
}
return len;
}
/*---------------------------------------------------------------------------*/
bool
dbl_circ_list_is_empty(dbl_circ_list_t dblcl)
{
return *dblcl == NULL ? true : false;
}
/*---------------------------------------------------------------------------*/
/** @} */

193
os/lib/dbl-circ-list.h Normal file
View File

@ -0,0 +1,193 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* Copyright (c) 2017, James Pope
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
/** \addtogroup data
* @{
*
* \defgroup doubly-linked-circular-list Circular, doubly-linked list
*
* This library provides functions for the creation and manipulation of
* circular, doubly-linked lists.
*
* A circular, doubly-linked list is declared using the DBL_CIRC_LIST macro.
* Elements must be allocated by the calling code and must be of a C struct
* datatype. In this struct, the first field must be a pointer called \e next.
* The second field must be a pointer called \e previous.
* These fields will be used by the library to maintain the list. Application
* code must not modify these fields directly.
*
* Functions that modify the list (add / remove) will, in the general case,
* update the list's head and item order. If you call one of these functions
* as part of a list traversal, it is advised to stop / restart traversing
* after the respective function returns.
* @{
*/
/*---------------------------------------------------------------------------*/
#ifndef DBL_CIRC_LIST_H_
#define DBL_CIRC_LIST_H_
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
/*---------------------------------------------------------------------------*/
/**
* \brief Define a circular, doubly-linked list.
*
* This macro defines a circular, doubly-linked list.
*
* The datatype for elements must be a C struct.
* The struct's first member must be a pointer called \e next.
* The second field must be a pointer called \e previous.
* These fields will be used by the library to maintain the list. Application
* code must not modify these fields directly.
*
* \param name The name of the circular, doubly-linked list.
*/
#define DBL_CIRC_LIST(name) \
static void *name##_dbl_circ_list = NULL; \
static dbl_list_t name = (dbl_circ_list_t)&name##_dbl_circ_list
/*---------------------------------------------------------------------------*/
/**
* \brief The doubly-linked list datatype
*/
typedef void **dbl_circ_list_t;
/*---------------------------------------------------------------------------*/
/**
* \brief Initialise a circular, doubly-linked list.
* \param dblcl The circular, doubly-linked list.
*/
void dbl_circ_list_init(dbl_circ_list_t dblcl);
/**
* \brief Return the tail of a circular, doubly-linked list.
* \param dblcl The circular, doubly-linked list.
* \return A pointer to the list's head, or NULL if the list is empty
*/
void *dbl_circ_list_head(dbl_circ_list_t dblcl);
/**
* \brief Return the tail of a circular, doubly-linked list.
* \param dblcl The circular, doubly-linked list.
* \return A pointer to the list's tail, or NULL if the list is empty
*/
void *dbl_circ_list_tail(dbl_circ_list_t dblcl);
/**
* \brief Add an element to the head of a circular, doubly-linked list.
* \param dblcl The circular, doubly-linked list.
* \param element A pointer to the element to be added.
*
* Calling this function will update the list's head and item order. If you
* call this function as part of a list traversal, it is advised to stop
* traversing after this function returns.
*/
void dbl_circ_list_add_head(dbl_circ_list_t dblcl, void *element);
/**
* \brief Add an element to the tail of a circular, doubly-linked list.
* \param dblcl The circular, doubly-linked list.
* \param element A pointer to the element to be added.
*
* Calling this function will update the list's head and item order. If you
* call this function as part of a list traversal, it is advised to stop
* traversing after this function returns.
*/
void dbl_circ_list_add_tail(dbl_circ_list_t dblcl, void *element);
/**
* \brief Add an element to a circular, doubly linked list after an existing element.
* \param dblcl The circular, doubly-linked list.
* \param existing A pointer to the existing element.
* \param element A pointer to the element to be added.
*
* This function will add \e element after \e existing
*
* The function will not verify that \e existing is already part of the list.
*
* Calling this function will update the list's head and item order. If you
* call this function as part of a list traversal, it is advised to stop
* traversing after this function returns.
*/
void dbl_circ_list_add_after(dbl_circ_list_t dblcl, void *existing,
void *element);
/**
* \brief Add an element to a circular, doubly linked list before an existing element.
* \param dblcl The circular, doubly-linked list.
* \param existing A pointer to the existing element.
* \param element A pointer to the element to be added.
*
* This function will add \e element before \e existing
*
* The function will not verify that \e existing is already part of the list.
*
* Calling this function will update the list's head and item order. If you
* call this function as part of a list traversal, it is advised to stop
* traversing after this function returns.
*/
void dbl_circ_list_add_before(dbl_circ_list_t dblcl, void *existing,
void *element);
/**
* \brief Remove an element from a circular, doubly-linked list.
* \param dblcl The circular, doubly-linked list.
* \param element A pointer to the element to be removed.
*
* Calling this function will update the list's head and item order. If you
* call this function as part of a list traversal, it is advised to stop
* traversing after this function returns.
*/
void dbl_circ_list_remove(dbl_circ_list_t dblcl, void *element);
/**
* \brief Get the length of a circular, doubly-linked list.
* \param dblcl The circular, doubly-linked list.
* \return The number of elements in the list
*/
unsigned long dbl_circ_list_length(dbl_circ_list_t dblcl);
/**
* \brief Determine whether a circular, doubly-linked list is empty.
* \param dblcl The circular, doubly-linked list.
* \retval true The list is empty
* \retval false The list is not empty
*/
bool dbl_circ_list_is_empty(dbl_circ_list_t dblcl);
/*---------------------------------------------------------------------------*/
#endif /* DBL_CIRC_LIST_H_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

226
os/lib/dbl-list.c Normal file
View File

@ -0,0 +1,226 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* Copyright (c) 2017, James Pope
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup doubly-linked-list
* @{
*
* \file
* Implementation of doubly-linked lists
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "lib/dbl-list.h"
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
/*---------------------------------------------------------------------------*/
struct dll {
struct dll *next;
struct dll *previous;
};
/*---------------------------------------------------------------------------*/
void
dbl_list_init(dbl_list_t dll)
{
*dll = NULL;
}
/*---------------------------------------------------------------------------*/
void *
dbl_list_head(dbl_list_t dll)
{
return *dll;
}
/*---------------------------------------------------------------------------*/
void *
dbl_list_tail(dbl_list_t dll)
{
struct dll *this;
if(*dll == NULL) {
return NULL;
}
for(this = *dll; this->next != NULL; this = this->next);
return this;
}
/*---------------------------------------------------------------------------*/
void
dbl_list_remove(dbl_list_t dll, void *element)
{
struct dll *this, *previous, *next;
if(*dll == NULL || element == NULL) {
return;
}
for(this = *dll; this != NULL; this = this->next) {
if(this == element) {
previous = this->previous;
next = this->next;
if(previous) {
previous->next = this->next;
}
if(next) {
next->previous = this->previous;
}
if(*dll == this) {
*dll = next;
}
return;
}
}
}
/*---------------------------------------------------------------------------*/
void
dbl_list_add_head(dbl_list_t dll, void *element)
{
struct dll *head;
if(element == NULL) {
return;
}
/* Don't add twice */
dbl_list_remove(dll, element);
head = dbl_list_head(dll);
((struct dll *)element)->previous = NULL;
((struct dll *)element)->next = head;
if(head) {
/* If the list was not empty, update ->previous on the old head */
head->previous = element;
}
*dll = element;
}
/*---------------------------------------------------------------------------*/
void
dbl_list_add_tail(dbl_list_t dll, void *element)
{
struct dll *tail;
if(element == NULL) {
return;
}
/* Don't add twice */
dbl_list_remove(dll, element);
tail = dbl_list_tail(dll);
if(tail == NULL) {
/* The list was empty */
*dll = element;
} else {
tail->next = element;
}
((struct dll *)element)->previous = tail;
((struct dll *)element)->next = NULL;
}
/*---------------------------------------------------------------------------*/
void
dbl_list_add_after(dbl_list_t dll, void *existing, void *element)
{
if(element == NULL || existing == NULL) {
return;
}
/* Don't add twice */
dbl_list_remove(dll, element);
((struct dll *)element)->next = ((struct dll *)existing)->next;
((struct dll *)element)->previous = existing;
if(((struct dll *)existing)->next) {
((struct dll *)existing)->next->previous = element;
}
((struct dll *)existing)->next = element;
}
/*---------------------------------------------------------------------------*/
void
dbl_list_add_before(dbl_list_t dll, void *existing, void *element)
{
if(element == NULL || existing == NULL) {
return;
}
/* Don't add twice */
dbl_list_remove(dll, element);
((struct dll *)element)->next = existing;
((struct dll *)element)->previous = ((struct dll *)existing)->previous;
if(((struct dll *)existing)->previous) {
((struct dll *)existing)->previous->next = element;
}
((struct dll *)existing)->previous = element;
/* If we added before the list's head, we must update the head */
if(*dll == existing) {
*dll = element;
}
}
/*---------------------------------------------------------------------------*/
unsigned long
dbl_list_length(dbl_list_t dll)
{
unsigned long len = 0;
struct dll *this;
if(*dll == NULL) {
return 0;
}
for(this = *dll; this != NULL; this = this->next) {
len++;
}
return len;
}
/*---------------------------------------------------------------------------*/
bool
dbl_list_is_empty(dbl_list_t dll)
{
return *dll == NULL ? true : false;
}
/*---------------------------------------------------------------------------*/
/** @} */

191
os/lib/dbl-list.h Normal file
View File

@ -0,0 +1,191 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* Copyright (c) 2017, James Pope
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
/** \addtogroup data
* @{
*
* \defgroup doubly-linked-list Doubly-linked list
*
* This library provides functions for the creation and manipulation of
* doubly-linked lists.
*
* A doubly-linked list is declared using the DBL_LIST macro.
* Elements must be allocated by the calling code and must be of a C struct
* datatype. In this struct, the first field must be a pointer called \e next.
* The second field must be a pointer called \e previous.
* These fields will be used by the library to maintain the list. Application
* code must not modify these fields directly.
*
* Functions that modify the list (add / remove) will, in the general case,
* update the list's head and item order. If you call one of these functions
* as part of a list traversal, it is advised to stop / restart traversing
* after the respective function returns.
* @{
*/
/*---------------------------------------------------------------------------*/
#ifndef DBL_LIST_H_
#define DBL_LIST_H_
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
/*---------------------------------------------------------------------------*/
/**
* \brief Define a doubly-linked list.
*
* This macro defines a doubly-linked list.
*
* The datatype for elements must be a C struct.
* The struct's first member must be a pointer called \e next.
* The second field must be a pointer called \e previous.
* These fields will be used by the library to maintain the list. Application
* code must not modify these fields directly.
*
* \param name The name of the doubly-linked list.
*/
#define DBL_LIST(name) \
static void *name##_dbl_list = NULL; \
static dbl_list_t name = (dbl_list_t)&name##_dbl_list
/*---------------------------------------------------------------------------*/
/**
* \brief The doubly-linked list datatype
*/
typedef void **dbl_list_t;
/*---------------------------------------------------------------------------*/
/**
* \brief Initialise a doubly-linked list.
* \param dll The doubly-linked list.
*/
void dbl_list_init(dbl_list_t dll);
/**
* \brief Return the tail of a doubly-linked list.
* \param dll The doubly-linked list.
* \return A pointer to the list's head, or NULL if the list is empty
*/
void *dbl_list_head(dbl_list_t dll);
/**
* \brief Return the tail of a doubly-linked list.
* \param dll The doubly-linked list.
* \return A pointer to the list's tail, or NULL if the list is empty
*/
void *dbl_list_tail(dbl_list_t dll);
/**
* \brief Add an element to the head of a doubly-linked list.
* \param dll The doubly-linked list.
* \param element A pointer to the element to be added.
*
* Calling this function will update the list's head and item order. If you
* call this function as part of a list traversal, it is advised to stop
* traversing after this function returns.
*/
void dbl_list_add_head(dbl_list_t dll, void *element);
/**
* \brief Add an element to the tail of a doubly-linked list.
* \param dll The doubly-linked list.
* \param element A pointer to the element to be added.
*
* Calling this function will update the list's head and item order. If you
* call this function as part of a list traversal, it is advised to stop
* traversing after this function returns.
*/
void dbl_list_add_tail(dbl_list_t dll, void *element);
/**
* \brief Add an element to a doubly linked list after an existing element.
* \param dll The doubly-linked list.
* \param existing A pointer to the existing element.
* \param element A pointer to the element to be added.
*
* This function will add \e element after \e existing
*
* The function will not verify that \e existing is already part of the list.
*
* Calling this function will update the list's head and item order. If you
* call this function as part of a list traversal, it is advised to stop
* traversing after this function returns.
*/
void dbl_list_add_after(dbl_list_t dll, void *existing, void *element);
/**
* \brief Add an element to a doubly linked list before an existing element.
* \param dll The doubly-linked list.
* \param existing A pointer to the existing element.
* \param element A pointer to the element to be added.
*
* This function will add \e element before \e existing
*
* The function will not verify that \e existing is already part of the list.
*
* Calling this function will update the list's head and item order. If you
* call this function as part of a list traversal, it is advised to stop
* traversing after this function returns.
*/
void dbl_list_add_before(dbl_list_t dll, void *existing, void *element);
/**
* \brief Remove an element from a doubly-linked list.
* \param dll The doubly-linked list.
* \param element A pointer to the element to be removed.
*
* Calling this function will update the list's head and item order. If you
* call this function as part of a list traversal, it is advised to stop
* traversing after this function returns.
*/
void dbl_list_remove(dbl_list_t dll, void *element);
/**
* \brief Get the length of a doubly-linked list.
* \param dll The doubly-linked list.
* \return The number of elements in the list
*/
unsigned long dbl_list_length(dbl_list_t dll);
/**
* \brief Determine whether a doubly-linked list is empty.
* \param dll The doubly-linked list.
* \retval true The list is empty
* \retval false The list is not empty
*/
bool dbl_list_is_empty(dbl_list_t dll);
/*---------------------------------------------------------------------------*/
#endif /* DBL_LIST_H_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

143
os/lib/queue.h Normal file
View File

@ -0,0 +1,143 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* Copyright (c) 2017, James Pope
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup data
* @{
*
* \defgroup queue Queue library
*
* This library provides functions for the creation and manipulation of
* queues. The library is implemented as a wrapper around the list library.
*
* A queue is declared using the QUEUE macro. Queue elements must be
* allocated by the calling code and must be of a C struct datatype. In this
* struct, the first field must be a pointer called \e next. This field will
* be used by the library to maintain the queue. Application code must not
* modify this field directly.
* @{
*/
/*---------------------------------------------------------------------------*/
#ifndef QUEUE_H_
#define QUEUE_H_
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "lib/list.h"
#include <stdbool.h>
/*---------------------------------------------------------------------------*/
/**
* \brief The queue data type
*/
typedef list_t queue_t;
/*---------------------------------------------------------------------------*/
/**
* \brief Define a queue.
*
* This macro defines a queue.
*
* The datatype for elements must be a C struct. The struct's first member must
* be a pointer called \e next. This is used internally by the library to
* maintain data structure integrity and must not be modified directly by
* application code.
*
* \param name The name of the queue.
*/
#define QUEUE(name) LIST(name)
/*---------------------------------------------------------------------------*/
struct queue {
struct queue *next;
};
/*---------------------------------------------------------------------------*/
/**
* \brief Initialise a queue
* \param queue The queue
*/
static inline void
queue_init(queue_t queue)
{
list_init(queue);
}
/*---------------------------------------------------------------------------*/
/**
* \brief Adds an element to the tail of the queue
* \param queue The queue
* \param element A pointer to the element to be added
*/
static inline void
queue_enqueue(queue_t queue, void *element)
{
list_add(queue, element);
}
/*---------------------------------------------------------------------------*/
/**
* \brief Removes the element at the front of the queue
* \param queue The queue
* \return A pointer to the element removed
*
* If this function returns NULL if the queue was empty (queue underflow)
*/
static inline void *
queue_dequeue(queue_t queue)
{
return list_pop(queue);
}
/*---------------------------------------------------------------------------*/
/**
* \brief Returns the front element of the queue, without removing it
* \param queue The queue
* \return A pointer to the element at the front of the queue
*/
static inline void *
queue_peek(queue_t queue)
{
return list_head(queue);
}
/*---------------------------------------------------------------------------*/
/**
* \brief Check if a queue is empty
* \param queue The queue
* \retval true The queue is empty
* \retval false The queue has at least one element
*/
static inline bool
queue_is_empty(queue_t queue)
{
return *queue == NULL ? true : false;
}
/*---------------------------------------------------------------------------*/
#endif /* QUEUE_H_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

143
os/lib/stack.h Normal file
View File

@ -0,0 +1,143 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* Copyright (c) 2017, James Pope
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup data
* @{
*
* \defgroup stack-data-structure Stack library
*
* This library provides functions for the creation and manipulation of
* stacks. The library is implemented as a wrapper around the list library.
*
* A stack is declared using the STACK macro. Stack elements must be
* allocated by the calling code and must be of a C struct datatype. In this
* struct, the first field must be a pointer called \e next. This field will
* be used by the library to maintain the stack. Application code must not
* modify this field directly.
* @{
*/
/*---------------------------------------------------------------------------*/
#ifndef STACK_H_
#define STACK_H_
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "lib/list.h"
#include <stdbool.h>
/*---------------------------------------------------------------------------*/
/**
* \brief The stack data type
*/
typedef list_t stack_t;
/*---------------------------------------------------------------------------*/
/**
* \brief Define a stack.
*
* This macro defines a stack.
*
* The datatype for elements must be a C struct. The struct's first member must
* be a pointer called \e next. This is used internally by the library to
* maintain data structure integrity and must not be modified directly by
* application code.
*
* \param name The name of the stack.
*/
#define STACK(name) LIST(name)
/*---------------------------------------------------------------------------*/
struct stack {
struct stack *next;
};
/*---------------------------------------------------------------------------*/
/**
* \brief Initialise a stack
* \param stack The stack
*/
static inline void
stack_init(stack_t stack)
{
list_init(stack);
}
/*---------------------------------------------------------------------------*/
/**
* \brief Adds an element to the top of the stack
* \param stack The stack
* \param element A pointer to the element to be added
*/
static inline void
stack_push(stack_t stack, void *element)
{
list_push(stack, element);
}
/*---------------------------------------------------------------------------*/
/**
* \brief Removes the top element from the stack
* \param stack The stack
* \return A pointer to the element popped
*
* If this function returns NULL if the stack was empty (stack underflow)
*/
static inline void *
stack_pop(stack_t stack)
{
return list_pop(stack);
}
/*---------------------------------------------------------------------------*/
/**
* \brief Returns the top element of the stack, without popping it
* \param stack The stack
* \return A pointer to the element at the top of the stack
*/
static inline void *
stack_peek(stack_t stack)
{
return list_head(stack);
}
/*---------------------------------------------------------------------------*/
/**
* \brief Check if a stack is empty
* \param stack The stack
* \retval true The stack is empty
* \retval false The stack has at least one element
*/
static inline bool
stack_is_empty(stack_t stack)
{
return *stack == NULL ? true : false;
}
/*---------------------------------------------------------------------------*/
#endif /* STACK_H_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -46,7 +46,7 @@
/* sanity check for configured values */
#define COAP_MAX_PACKET_SIZE (COAP_MAX_HEADER_SIZE + REST_MAX_CHUNK_SIZE)
#if COAP_MAX_PACKET_SIZE > (UIP_BUFSIZE - UIP_IPH_LEN - UIP_UDPH_LEN)
#if COAP_MAX_PACKET_SIZE > (UIP_BUFSIZE - UIP_LLH_LEN - UIP_IPH_LEN - UIP_UDPH_LEN)
#error "UIP_CONF_BUFFER_SIZE too small for REST_MAX_CHUNK_SIZE"
#endif

View File

@ -229,7 +229,7 @@ icmp_input()
uip_process(UIP_UDP_SEND_CONN);
memcpy(&mcast_buf, uip_buf, uip_len);
memcpy(&mcast_buf, &uip_buf[UIP_LLH_LEN], uip_len);
mcast_len = uip_len;
/* pass the packet to our uip_process to check if it is allowed to
* accept this packet or not */
@ -239,7 +239,7 @@ icmp_input()
uip_process(UIP_DATA);
memcpy(uip_buf, &mcast_buf, mcast_len);
memcpy(&uip_buf[UIP_LLH_LEN], &mcast_buf, mcast_len);
uip_len = mcast_len;
/* Return the IP of the original Multicast sender */
uip_ipaddr_copy(&UIP_IP_BUF->srcipaddr, &src_ip);
@ -257,7 +257,7 @@ icmp_input()
static void
mcast_fwd(void *p)
{
memcpy(uip_buf, &mcast_buf, mcast_len);
memcpy(&uip_buf[UIP_LLH_LEN], &mcast_buf, mcast_len);
uip_len = mcast_len;
UIP_IP_BUF->ttl--;
tcpip_output(NULL);
@ -291,7 +291,7 @@ in()
parent_lladdr = uip_ds6_nbr_lladdr_from_ipaddr(parent_ipaddr);
if(parent_lladdr == NULL) {
PRINTF("ESMRF: NO Parent exist \n");
PRINTF("ESMRF: No Parent found\n");
UIP_MCAST6_STATS_ADD(mcast_dropped);
return UIP_MCAST6_DROP;
}
@ -309,6 +309,7 @@ in()
if(UIP_IP_BUF->ttl <= 1) {
UIP_MCAST6_STATS_ADD(mcast_dropped);
PRINTF("ESMRF: TTL too low\n");
return UIP_MCAST6_DROP;
}
@ -350,12 +351,14 @@ in()
fwd_delay = fwd_delay * (1 + ((random_rand() >> 11) % fwd_spread));
}
memcpy(&mcast_buf, uip_buf, uip_len);
memcpy(&mcast_buf, &uip_buf[UIP_LLH_LEN], uip_len);
mcast_len = uip_len;
ctimer_set(&mcast_periodic, fwd_delay, mcast_fwd, NULL);
}
PRINTF("ESMRF: %u bytes: fwd in %u [%u]\n",
uip_len, fwd_delay, fwd_spread);
} else {
PRINTF("ESMRF: Group unknown, dropping\n");
}
/* Done with this packet unless we are a member of the mcast group */

View File

@ -1321,7 +1321,7 @@ static void
out()
{
if(uip_len + HBHO_TOTAL_LEN > UIP_BUFSIZE) {
if(uip_len + HBHO_TOTAL_LEN > UIP_BUFSIZE - UIP_LLH_LEN) {
PRINTF("ROLL TM: Multicast Out can not add HBHO. Packet too long\n");
goto drop;
}

View File

@ -82,7 +82,7 @@ static uint8_t fwd_spread;
static void
mcast_fwd(void *p)
{
memcpy(uip_buf, &mcast_buf, mcast_len);
memcpy(&uip_buf[UIP_LLH_LEN], &mcast_buf, mcast_len);
uip_len = mcast_len;
UIP_IP_BUF->ttl--;
tcpip_output(NULL);
@ -106,6 +106,7 @@ in()
*/
d = rpl_get_any_dag();
if(!d) {
PRINTF("SMRF: No DODAG\n");
UIP_MCAST6_STATS_ADD(mcast_dropped);
return UIP_MCAST6_DROP;
}
@ -115,6 +116,7 @@ in()
parent_lladdr = uip_ds6_nbr_lladdr_from_ipaddr(parent_ipaddr);
if(parent_lladdr == NULL) {
PRINTF("SMRF: No Parent found\n");
UIP_MCAST6_STATS_ADD(mcast_dropped);
return UIP_MCAST6_DROP;
}
@ -132,6 +134,7 @@ in()
if(UIP_IP_BUF->ttl <= 1) {
UIP_MCAST6_STATS_ADD(mcast_dropped);
PRINTF("SMRF: TTL too low\n");
return UIP_MCAST6_DROP;
}
@ -173,12 +176,14 @@ in()
fwd_delay = fwd_delay * (1 + ((random_rand() >> 11) % fwd_spread));
}
memcpy(&mcast_buf, uip_buf, uip_len);
memcpy(&mcast_buf, &uip_buf[UIP_LLH_LEN], uip_len);
mcast_len = uip_len;
ctimer_set(&mcast_periodic, fwd_delay, mcast_fwd, NULL);
}
PRINTF("SMRF: %u bytes: fwd in %u [%u]\n",
uip_len, fwd_delay, fwd_spread);
} else {
PRINTF("SMRF: Group unknown, dropping\n");
}
/* Done with this packet unless we are a member of the mcast group */

View File

@ -68,6 +68,7 @@
#include "net/ipv6/tcpip.h"
#include "net/ipv6/uip.h"
#include "net/ipv6/uip-ds6.h"
#include "net/ipv6/uipbuf.h"
#include "net/ipv6/sicslowpan.h"
#include "net/netstack.h"
#include "net/packetbuf.h"
@ -122,7 +123,7 @@
/* NOTE: In the multiple-reassembly context there is only room for the header / first fragment */
#define SICSLOWPAN_IP_BUF(buf) ((struct uip_ip_hdr *)buf)
#define SICSLOWPAN_UDP_BUF(buf) ((struct uip_udp_hdr *)&buf[UIP_IPH_LEN])
#define SICSLOWPAN_IPPAYLOAD_BUF(buf) (&buf[UIP_LLIPH_LEN])
#define SICSLOWPAN_IPPAYLOAD_BUF(buf) (&buf[UIP_IPH_LEN])
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
@ -1504,17 +1505,6 @@ output(const linkaddr_t *localdest)
set_packet_attrs();
}
#if UIP_WITH_VARIABLE_RETRANSMISSIONS
{
uint8_t traffic_class = (UIP_IP_BUF->vtc << 4) | (UIP_IP_BUF->tcflow >> 4);
if(traffic_class & UIP_TC_MAC_TRANSMISSION_COUNTER_BIT) {
uint8_t max_mac_transmissions = traffic_class & UIP_TC_MAC_TRANSMISSION_COUNTER_MASK;
/* propagate the MAC transmission limit to lower layers */
packetbuf_set_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS, max_mac_transmissions);
}
}
#endif /* UIP_WITH_VARIABLE_RETRANSMISSIONS */
/*
* The destination address will be tagged to each outbound
* packet. If the argument localdest is NULL, we are sending a
@ -1528,6 +1518,10 @@ output(const linkaddr_t *localdest)
LOG_INFO("output: sending packet len %d\n", uip_len);
/* copy over the retransmission count from uipbuf attributes */
packetbuf_set_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS,
uipbuf_get_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS));
/* Try to compress the headers */
#if SICSLOWPAN_COMPRESSION == SICSLOWPAN_COMPRESSION_IPV6
compress_hdr_ipv6(&dest);

View File

@ -121,6 +121,19 @@ uint8_t
tcpip_output(const uip_lladdr_t *a)
{
int ret;
/* Tag Traffic Class if we are using TC for variable retrans */
#if UIP_TAG_TC_WITH_VARIABLE_RETRANSMISSIONS
if(uipbuf_get_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS) !=
UIP_MAX_MAC_TRANSMISSIONS_UNDEFINED) {
LOG_INFO("Tagging TC with retrans: %d\n", uipbuf_get_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS));
/* Encapsulate the MAC transmission limit in the Traffic Class field */
UIP_IP_BUF->vtc = 0x60 | (UIP_TC_MAC_TRANSMISSION_COUNTER_BIT >> 4);
UIP_IP_BUF->tcflow =
uipbuf_get_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS) << 4;
}
#endif
if(netstack_process_ip_callback(NETSTACK_IP_OUTPUT, (const linkaddr_t *)a) ==
NETSTACK_IP_PROCESS) {
ret = NETSTACK_NETWORK.output((const linkaddr_t *) a);
@ -167,6 +180,19 @@ packet_input(void)
{
if(uip_len > 0) {
check_for_tcp_syn();
#if UIP_TAG_TC_WITH_VARIABLE_RETRANSMISSIONS
{
uint8_t traffic_class = (UIP_IP_BUF->vtc << 4) | (UIP_IP_BUF->tcflow >> 4);
if(traffic_class & UIP_TC_MAC_TRANSMISSION_COUNTER_BIT) {
uint8_t max_mac_transmissions = traffic_class & UIP_TC_MAC_TRANSMISSION_COUNTER_MASK;
uipbuf_set_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS, max_mac_transmissions);
LOG_INFO("Received packet tagged with TC retrans: %d (%x)",
max_mac_transmissions, traffic_class);
}
}
#endif /* UIP_TAG_TC_WITH_VARIABLE_RETRANSMISSIONS */
uip_input();
if(uip_len > 0) {
tcpip_ipv6_output();
@ -446,12 +472,7 @@ output_fallback(void)
#ifdef UIP_FALLBACK_INTERFACE
LOG_INFO("fallback: removing ext hdrs & setting proto %d %d\n",
uip_ext_len, *((uint8_t *)UIP_IP_BUF + 40));
if(uip_ext_len > 0) {
uint8_t proto = *((uint8_t *)UIP_IP_BUF + 40);
remove_ext_hdr();
/* This should be copied from the ext header... */
UIP_IP_BUF->proto = proto;
}
remove_ext_hdr();
/* Inform the other end that the destination is not reachable. If it's
* not informed routes might get lost unexpectedly until there's a need
* to send a new packet to the peer */

View File

@ -238,12 +238,8 @@ uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) {
return;
}
} else {
#if UIP_CONF_ROUTER
/* need to pick a source that corresponds to this node */
uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &tmp_ipaddr);
#else
uip_ipaddr_copy(&UIP_IP_BUF->srcipaddr, &tmp_ipaddr);
#endif
}
UIP_ICMP_BUF->type = type;

View File

@ -80,6 +80,7 @@
#include "net/ipv6/uipopt.h"
#include "net/ipv6/uipbuf.h"
/* For memcmp */
#include <string.h>
@ -820,18 +821,6 @@ CCIF void uip_send(const void *data, int len);
*/
#define uip_mss() (uip_conn->mss)
/**
* Set the maximal number of MAC transmissions.
*
* \hideinitializer
*/
#if UIP_WITH_VARIABLE_RETRANSMISSIONS
#define uip_set_max_mac_transmissions(conn, value) ((conn)->max_mac_transmissions = (value))
#else
#define uip_set_max_mac_transmissions(conn, value)
#endif
/**
* Set up a new UDP connection.
*
@ -1328,10 +1317,12 @@ extern uint16_t uip_urglen, uip_surglen;
#define uip_clear_buf() { \
uip_len = 0; \
uip_ext_len = 0; \
uipbuf_clear_attr();\
}
#else /*NETSTACK_CONF_WITH_IPV6*/
#define uip_clear_buf() { \
uip_len = 0; \
uipbuf_clear_attr();\
}
#endif /*NETSTACK_CONF_WITH_IPV6*/
@ -1365,10 +1356,6 @@ struct uip_conn {
uint8_t timer; /**< The retransmission timer. */
uint8_t nrtx; /**< The number of retransmissions for the last
segment sent. */
#if UIP_WITH_VARIABLE_RETRANSMISSIONS
uint8_t max_mac_transmissions; /**< Number of max MAC-layer transmissions. */
#endif
uip_tcp_appstate_t appstate; /** The application state. */
};
@ -1405,10 +1392,6 @@ struct uip_udp_conn {
uint16_t lport; /**< The local port number in network byte order. */
uint16_t rport; /**< The remote port number in network byte order. */
uint8_t ttl; /**< Default time-to-live. */
#if UIP_WITH_VARIABLE_RETRANSMISSIONS
uint8_t max_mac_transmissions; /**< Number of max MAC-layer transmissions. */
#endif
/** The application state. */
uip_udp_appstate_t appstate;
};

View File

@ -98,6 +98,10 @@
#define LOG_MODULE "IPv6"
#define LOG_LEVEL LOG_LEVEL_IPV6
#if UIP_STATISTICS == 1
struct uip_stats uip_stat;
#endif /* UIP_STATISTICS == 1 */
/*---------------------------------------------------------------------------*/
/**
* \name Layer 2 variables
@ -508,9 +512,6 @@ uip_connect(const uip_ipaddr_t *ripaddr, uint16_t rport)
conn->rto = UIP_RTO;
conn->sa = 0;
conn->sv = 16; /* Initial value of the RTT variance. */
#if UIP_WITH_VARIABLE_RETRANSMISSIONS
conn->max_mac_transmissions = UIP_MAX_MAC_TRANSMISSIONS_UNDEFINED;
#endif
conn->lport = uip_htons(lastport);
conn->rport = rport;
uip_ipaddr_copy(&conn->ripaddr, ripaddr);
@ -522,6 +523,7 @@ uip_connect(const uip_ipaddr_t *ripaddr, uint16_t rport)
void
remove_ext_hdr(void)
{
int last_uip_ext_len;
/* Remove ext header before TCP/UDP processing. */
if(uip_ext_len > 0) {
LOG_DBG("Cutting ext-header before processing (extlen: %d, uiplen: %d)\n",
@ -531,15 +533,17 @@ remove_ext_hdr(void)
uip_clear_buf();
return;
}
memmove(((uint8_t *)UIP_TCP_BUF), (uint8_t *)UIP_TCP_BUF + uip_ext_len,
uip_len - UIP_IPH_LEN - uip_ext_len);
last_uip_ext_len = uip_ext_len;
uip_ext_len = 0;
UIP_IP_BUF->proto = UIP_EXT_BUF->next;
memmove(((uint8_t *)UIP_TCP_BUF), (uint8_t *)UIP_TCP_BUF + last_uip_ext_len,
uip_len - UIP_IPH_LEN - last_uip_ext_len);
uip_len -= uip_ext_len;
uip_len -= last_uip_ext_len;
/* Update the IP length. */
UIP_IP_BUF->len[0] = (uip_len - UIP_IPH_LEN) >> 8;
UIP_IP_BUF->len[1] = (uip_len - UIP_IPH_LEN) & 0xff;
uip_ext_len = 0;
}
}
/*---------------------------------------------------------------------------*/
@ -584,9 +588,6 @@ uip_udp_new(const uip_ipaddr_t *ripaddr, uint16_t rport)
uip_ipaddr_copy(&conn->ripaddr, ripaddr);
}
conn->ttl = uip_ds6_if.cur_hop_limit;
#if UIP_WITH_VARIABLE_RETRANSMISSIONS
conn->max_mac_transmissions = UIP_MAX_MAC_TRANSMISSIONS_UNDEFINED;
#endif
return conn;
}
@ -1496,7 +1497,6 @@ uip_process(uint8_t flag)
udp_input:
remove_ext_hdr();
UIP_IP_BUF->proto = UIP_PROTO_UDP;
LOG_INFO("Receiving UDP packet\n");
@ -1578,14 +1578,6 @@ uip_process(uint8_t flag)
UIP_IP_BUF->vtc = 0x60;
UIP_IP_BUF->tcflow = 0x00;
#if UIP_WITH_VARIABLE_RETRANSMISSIONS
if(uip_udp_conn->max_mac_transmissions != UIP_MAX_MAC_TRANSMISSIONS_UNDEFINED) {
/* Encapsulate the MAC transmission limit in the Traffic Class field */
UIP_IP_BUF->vtc = 0x60 | (UIP_TC_MAC_TRANSMISSION_COUNTER_BIT >> 4);
UIP_IP_BUF->tcflow = uip_udp_conn->max_mac_transmissions << 4;
}
#endif /* UIP_WITH_VARIABLE_RETRANSMISSIONS */
UIP_IP_BUF->ttl = uip_udp_conn->ttl;
UIP_IP_BUF->proto = UIP_PROTO_UDP;
@ -1617,7 +1609,6 @@ uip_process(uint8_t flag)
tcp_input:
remove_ext_hdr();
UIP_IP_BUF->proto = UIP_PROTO_TCP;
UIP_STAT(++uip_stat.tcp.recv);
LOG_INFO("Receiving TCP packet\n");
@ -2292,13 +2283,6 @@ uip_process(uint8_t flag)
UIP_IP_BUF->vtc = 0x60;
UIP_IP_BUF->tcflow = 0x00;
#if UIP_WITH_VARIABLE_RETRANSMISSIONS
if(uip_connr->max_mac_transmissions != UIP_MAX_MAC_TRANSMISSIONS_UNDEFINED) {
/* Encapsulate the MAC transmission limit in the Traffic Class field */
UIP_IP_BUF->vtc = 0x60 | (UIP_TC_MAC_TRANSMISSION_COUNTER_BIT >> 4);
UIP_IP_BUF->tcflow = uip_connr->max_mac_transmissions << 4;
}
#endif /* UIP_WITH_VARIABLE_RETRANSMISSIONS */
uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &uip_connr->ripaddr);
uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, RISE SICS
* Copyright (c) 2017, RISE SICS, Yanzi Networks
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -31,7 +31,14 @@
*/
#include "contiki.h"
#include "uip.h"
#include "net/ipv6/uipbuf.h"
#include <string.h>
/*---------------------------------------------------------------------------*/
static uint16_t uipbuf_attrs[UIPBUF_ATTR_MAX];
/*---------------------------------------------------------------------------*/
/* Get the next header given the buffer - start indicates that this is
start of the IPv6 header - needs to be set to 0 when in an ext hdr */
uint8_t*
@ -54,7 +61,7 @@ uipbuf_get_next_header(uint8_t *buffer, uint16_t size, uint8_t *protocol, uint8_
return buffer + ext_len;
}
}
/*---------------------------------------------------------------------------*/
/* Get the final header given the buffer - that is assumed to be at start
of an IPv6 header */
uint8_t*
@ -69,3 +76,58 @@ uipbuf_get_last_header(uint8_t *buffer, uint16_t size, uint8_t *protocol)
}
return nbuf;
}
/*---------------------------------------------------------------------------*/
/**
* Common functions for uipbuf (attributes, etc).
*
*/
/*---------------------------------------------------------------------------*/
uint16_t
uipbuf_get_attr(uint8_t type)
{
if(type < UIPBUF_ATTR_MAX) {
return uipbuf_attrs[type];
}
return 0;
}
/*---------------------------------------------------------------------------*/
int
uipbuf_set_attr(uint8_t type, uint16_t value)
{
if(type < UIPBUF_ATTR_MAX) {
uipbuf_attrs[type] = value;
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
void
uipbuf_clear_attr(void)
{
/* set everything to "zero" */
memset(uipbuf_attrs, 0, sizeof(uipbuf_attrs));
/* And initialize anything that should be initialized */
uipbuf_set_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS,
UIP_MAX_MAC_TRANSMISSIONS_UNDEFINED);
}
/*---------------------------------------------------------------------------*/
void
uipbuf_set_attr_flag(uint16_t flag)
{
/* Assume only 16-bits for flags now */
uipbuf_attrs[UIPBUF_ATTR_FLAGS] |= flag;
}
/*---------------------------------------------------------------------------*/
void
uipbuf_clr_attr_flag(uint16_t flag)
{
uipbuf_attrs[UIPBUF_ATTR_FLAGS] &= ~flag;
}
/*---------------------------------------------------------------------------*/
uint16_t
uipbuf_is_attr_flag(uint16_t flag)
{
return (uipbuf_attrs[UIPBUF_ATTR_FLAGS] & flag) == flag;
}
/*---------------------------------------------------------------------------*/

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, RISE SICS
* Copyright (c) 2017, RISE SICS, Yanzi Networks
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -30,12 +30,112 @@
*
*/
#ifndef UIPBUF_H_
#define UIPBUF_H_
#include "contiki.h"
/* Get the next header given the buffer - start indicates that this is
start of the IPv6 header - needs to be set to 0 when in an ext hdr */
/**
* \brief Get the next IPv6 header.
* \param buffer A pointer to the buffer holding the IPv6 packet
* \param size The size of the data in the buffer
* \param protocol A pointer to a variable where the protocol of the header will be stored
* \param start A flag that indicates if this is expected to be the IPv6 packet header or a later header (Extension header)
* \retval returns address of the starting position of the next header
*
* This function moves to the next header in a IPv6 packet.
*/
uint8_t* uipbuf_get_next_header(uint8_t *buffer, uint16_t size, uint8_t *protocol, uint8_t start);
/* Get the final header given the buffer - that is assumed to be at start
of an IPv6 header */
/**
* \brief Get the last IPv6 header.
* \param buffer A pointer to the buffer holding the IPv6 packet
* \param size The size of the data in the buffer
* \param protocol A pointer to a variable where the protocol of the header will be stored
* \retval returns address of the starting position of the next header
*
* This function moves to the last header of the IPv6 packet.
*/
uint8_t* uipbuf_get_last_header(uint8_t *buffer, uint16_t size, uint8_t *protocol);
/**
* \brief Get the value of the attribute
* \param type The attribute to get the value of
* \retval the value of the attribute
*
* This function gets the value of a specific uipbuf attribute.
*/
uint16_t uipbuf_get_attr(uint8_t type);
/**
* \brief Set the value of the attribute
* \param type The attribute to set the value of
* \param value The value to set
* \retval 0 - indicates failure of setting the value
* \retval 1 - indicates success of setting the value
*
* This function sets the value of a specific uipbuf attribute.
*/
int uipbuf_set_attr(uint8_t type, uint16_t value);
/**
* \brief Set bits in the uipbuf attribute flags.
* \param flag_bits The bits to set in the flag.
*
* This function sets the uipbuf attributes flag of specified bits.
*/
void uipbuf_set_attr_flag(uint16_t flag_bits);
/**
* \brief Clear bits in the uipbuf attribute flags.
* \param flag_bits The bits to clear in the flag.
*
* This function clears the uipbuf attributes flag of specified bits.
*/
void uipbuf_clr_attr_flag(uint16_t flag_bits);
/**
* \brief Check if bits in the uipbuf attribute flag are set.
* \param flag_bits The bits to check in the flag.
*
* This function checks if the specified bits are set in the
* uipbuf attributes flag.
*/
uint16_t uipbuf_is_attr_flag(uint16_t flag_bits);
/**
* \brief Clear all attributes.
*
* This function clear all attributes in the uipbuf attributes
* including all flags.
*/
void uipbuf_clear_attr(void);
/**
* \brief The bits defined for uipbuf attributes flag.
*
*/
/* Avoid using NHC compression on the packet (6LoWPAN) */
#define UIPBUF_ATTR_FLAGS_6LOWPAN_NO_NHC_COMPRESSION 0x01
/* Avoid using prefix compression on the packet (6LoWPAN) */
#define UIPBUF_ATTR_FLAGS_6LOWPAN_NO_PREFIX_COMPRESSION 0x02
/**
* \brief The attributes defined for uipbuf attributes function.
*
*/
enum {
UIPBUF_ATTR_LLSEC_LEVEL, /**< Control link layer security level. */
UIPBUF_ATTR_LLSEC_KEY_ID, /**< Control link layer security key ID. */
UIPBUF_ATTR_INTERFACE_ID, /**< The interface to output packet on */
UIPBUF_ATTR_PHYSICAL_NETWORK_ID, /**< Physical network ID (mapped to PAN ID)*/
UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS, /**< MAX transmissions of the packet MAC */
UIPBUF_ATTR_FLAGS, /**< Flags that can control lower layers. see above. */
UIPBUF_ATTR_MAX
};
#endif /* UIPBUF_H_ */

View File

@ -518,22 +518,6 @@ void uip_log(char *msg);
#define UIP_DEFAULT_PREFIX_LEN 64
/**
* Enables selection of maximal MAC-layer transmission count at application layer
*/
#ifdef UIP_CONF_WITH_VARIABLE_RETRANSMISSIONS
#define UIP_WITH_VARIABLE_RETRANSMISSIONS UIP_CONF_WITH_VARIABLE_RETRANSMISSIONS
#else
#define UIP_WITH_VARIABLE_RETRANSMISSIONS 0
#endif
/**
* This is the default value of MAC-layer transmissons for uIPv6
*
* It means that the limit is selected by the MAC protocol instead of uIPv6.
*/
#define UIP_MAX_MAC_TRANSMISSIONS_UNDEFINED 0
/**
* The MAC-layer transmissons limit is encapslated in "Traffic Class" field
*
@ -547,6 +531,19 @@ void uip_log(char *msg);
*/
#define UIP_TC_MAC_TRANSMISSION_COUNTER_MASK 0x3F
#ifdef UIP_CONF_TAG_TC_WITH_VARIABLE_RETRANSMISSIONS
#define UIP_TAG_TC_WITH_VARIABLE_RETRANSMISSIONS UIP_CONF_TAG_TC_WITH_VARIABLE_RETRANSMISSIONS
#else
#define UIP_TAG_TC_WITH_VARIABLE_RETRANSMISSIONS 0
#endif
/**
* This is the default value of MAC-layer transmissons for uIPv6
*
* It means that the limit is selected by the MAC protocol instead of uIPv6.
*/
#define UIP_MAX_MAC_TRANSMISSIONS_UNDEFINED 0
/** @} */
/*------------------------------------------------------------------------------*/

View File

@ -506,15 +506,11 @@ csma_output_packet(mac_callback_t sent, void *ptr)
if(q->buf != NULL) {
struct qbuf_metadata *metadata = (struct qbuf_metadata *)q->ptr;
/* Neighbor and packet successfully allocated */
#if UIP_WITH_VARIABLE_RETRANSMISSIONS
metadata->max_transmissions = packetbuf_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS);
if(metadata->max_transmissions == 0) {
/* If not set by the application, use the default CSMA value */
metadata->max_transmissions = CSMA_MAX_FRAME_RETRIES + 1;
}
#else
metadata->max_transmissions = CSMA_MAX_FRAME_RETRIES + 1;
#endif
metadata->sent = sent;
metadata->cptr = ptr;
list_add(n->packet_queue, q);

View File

@ -1007,9 +1007,7 @@ send_packet(mac_callback_t sent, void *ptr)
packetbuf_set_addr(PACKETBUF_ADDR_SENDER, &linkaddr_node_addr);
#endif
#if UIP_WITH_VARIABLE_RETRANSMISSIONS
max_transmissions = packetbuf_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS);
#endif
if(max_transmissions == 0) {
/* If not set by the application, use the default TSCH value */
max_transmissions = TSCH_MAC_MAX_FRAME_RETRIES + 1;

View File

@ -217,9 +217,7 @@ enum {
PACKETBUF_ATTR_LINK_QUALITY,
PACKETBUF_ATTR_RSSI,
PACKETBUF_ATTR_TIMESTAMP,
#if UIP_WITH_VARIABLE_RETRANSMISSIONS
PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS,
#endif /* UIP_WITH_VARIABLE_RETRANSMISSIONS */
PACKETBUF_ATTR_MAC_SEQNO,
PACKETBUF_ATTR_MAC_ACK,
PACKETBUF_ATTR_MAC_METADATA,

View File

@ -370,6 +370,7 @@ rpl_set_root(uint8_t instance_id, uip_ipaddr_t *dag_id)
}
if(dag == dag->instance->current_dag) {
PRINTF("RPL: Dropping a joined DAG when setting this node as root");
rpl_set_default_route(instance, NULL);
dag->instance->current_dag = NULL;
} else {
PRINTF("RPL: Dropping a DAG when setting this node as root");
@ -522,14 +523,16 @@ rpl_set_prefix(rpl_dag_t *dag, uip_ipaddr_t *prefix, unsigned len)
dag->prefix_info.length = len;
dag->prefix_info.flags = UIP_ND6_RA_FLAG_AUTONOMOUS;
PRINTF("RPL: Prefix set - will announce this in DIOs\n");
/* Autoconfigure an address if this node does not already have an address
with this prefix. Otherwise, update the prefix */
if(last_len == 0) {
PRINTF("rpl_set_prefix - prefix NULL\n");
check_prefix(NULL, &dag->prefix_info);
} else {
PRINTF("rpl_set_prefix - prefix NON-NULL\n");
check_prefix(&last_prefix, &dag->prefix_info);
if(dag->rank != ROOT_RANK(dag->instance)) {
/* Autoconfigure an address if this node does not already have an address
with this prefix. Otherwise, update the prefix */
if(last_len == 0) {
PRINTF("rpl_set_prefix - prefix NULL\n");
check_prefix(NULL, &dag->prefix_info);
} else {
PRINTF("rpl_set_prefix - prefix NON-NULL\n");
check_prefix(&last_prefix, &dag->prefix_info);
}
}
return 1;
}
@ -665,6 +668,10 @@ rpl_free_dag(rpl_dag_t *dag)
if(RPL_IS_STORING(dag->instance)) {
rpl_remove_routes(dag);
}
/* Stop the DAO retransmit timer */
#if RPL_WITH_DAO_ACK
ctimer_stop(&dag->instance->dao_retransmit_timer);
#endif /* RPL_WITH_DAO_ACK */
/* Remove autoconfigured address */
if((dag->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS)) {
@ -757,22 +764,17 @@ rpl_select_dag(rpl_instance_t *instance, rpl_parent_t *p)
old_rank = instance->current_dag->rank;
last_parent = instance->current_dag->preferred_parent;
best_dag = instance->current_dag;
if(best_dag->rank != ROOT_RANK(instance)) {
if(rpl_select_parent(p->dag) != NULL) {
if(p->dag != best_dag) {
best_dag = instance->of->best_dag(best_dag, p->dag);
}
} else if(p->dag == best_dag) {
best_dag = NULL;
for(dag = &instance->dag_table[0], end = dag + RPL_MAX_DAG_PER_INSTANCE; dag < end; ++dag) {
if(dag->used && dag->preferred_parent != NULL && dag->preferred_parent->rank != RPL_INFINITE_RANK) {
if(best_dag == NULL) {
best_dag = dag;
} else {
best_dag = instance->of->best_dag(best_dag, dag);
}
}
if(instance->current_dag->rank != ROOT_RANK(instance)) {
rpl_select_parent(p->dag);
}
best_dag = NULL;
for(dag = &instance->dag_table[0], end = dag + RPL_MAX_DAG_PER_INSTANCE; dag < end; ++dag) {
if(dag->used && dag->preferred_parent != NULL && dag->preferred_parent->rank != RPL_INFINITE_RANK) {
if(best_dag == NULL) {
best_dag = dag;
} else {
best_dag = instance->of->best_dag(best_dag, dag);
}
}
}
@ -1323,6 +1325,9 @@ rpl_local_repair(rpl_instance_t *instance)
/* no downward route anymore */
instance->has_downward_route = 0;
#if RPL_WITH_DAO_ACK
ctimer_stop(&instance->dao_retransmit_timer);
#endif /* RPL_WITH_DAO_ACK */
rpl_reset_dio_timer(instance);
if(RPL_IS_STORING(instance)) {

View File

@ -408,7 +408,7 @@ insert_srh_header(void)
path_len, cmpri, cmpre, ext_len, padding);
/* Check if there is enough space to store the extension header */
if(uip_len + ext_len > UIP_BUFSIZE) {
if(uip_len + ext_len > UIP_BUFSIZE - UIP_LLH_LEN) {
PRINTF("RPL: Packet too long: impossible to add source routing header (%u bytes)\n", ext_len);
return 0;
}
@ -553,7 +553,7 @@ insert_hbh_header(const rpl_instance_t *instance)
/* Insert hop-by-hop header */
PRINTF("RPL: Creating hop-by-hop option\n");
if(uip_len + RPL_HOP_BY_HOP_LEN > UIP_BUFSIZE) {
if(uip_len + RPL_HOP_BY_HOP_LEN > UIP_BUFSIZE - UIP_LLH_LEN) {
PRINTF("RPL: Packet too long: impossible to add hop-by-hop option\n");
uip_ext_len = last_uip_ext_len;
return 0;
@ -592,9 +592,11 @@ rpl_ext_header_remove(void)
{
uint8_t temp_len;
uint8_t rpl_ext_hdr_len;
int uip_ext_opt_offset;
uint8_t *uip_next_hdr;
uip_ext_len = 0;
uip_ext_opt_offset = 2;
uip_next_hdr = &UIP_IP_BUF->proto;
/* Look for hop-by-hop and routing headers */
@ -602,17 +604,22 @@ rpl_ext_header_remove(void)
switch(*uip_next_hdr) {
case UIP_PROTO_HBHO:
case UIP_PROTO_ROUTING:
/* Remove hop-by-hop and routing headers */
*uip_next_hdr = UIP_EXT_BUF->next;
rpl_ext_hdr_len = (UIP_EXT_BUF->len * 8) + 8;
temp_len = UIP_IP_BUF->len[1];
uip_len -= rpl_ext_hdr_len;
UIP_IP_BUF->len[1] -= rpl_ext_hdr_len;
if(UIP_IP_BUF->len[1] > temp_len) {
UIP_IP_BUF->len[0]--;
if((*uip_next_hdr != UIP_PROTO_HBHO || UIP_EXT_HDR_OPT_RPL_BUF->opt_type == UIP_EXT_HDR_OPT_RPL)) {
/* Remove hop-by-hop and routing headers */
*uip_next_hdr = UIP_EXT_BUF->next;
rpl_ext_hdr_len = (UIP_EXT_BUF->len * 8) + 8;
temp_len = UIP_IP_BUF->len[1];
uip_len -= rpl_ext_hdr_len;
UIP_IP_BUF->len[1] -= rpl_ext_hdr_len;
if(UIP_IP_BUF->len[1] > temp_len) {
UIP_IP_BUF->len[0]--;
}
PRINTF("RPL: Removing RPL extension header (type %u, len %u)\n", *uip_next_hdr, rpl_ext_hdr_len);
memmove(UIP_EXT_BUF, ((uint8_t *)UIP_EXT_BUF) + rpl_ext_hdr_len, uip_len - UIP_IPH_LEN);
} else {
uip_next_hdr = &UIP_EXT_BUF->next;
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
}
PRINTF("RPL: Removing RPL extension header (type %u, len %u)\n", *uip_next_hdr, rpl_ext_hdr_len);
memmove(UIP_EXT_BUF, ((uint8_t *)UIP_EXT_BUF) + rpl_ext_hdr_len, uip_len - UIP_IPH_LEN);
break;
case UIP_PROTO_DESTO:
/*
@ -626,6 +633,7 @@ rpl_ext_header_remove(void)
/* Move to next header */
uip_next_hdr = &UIP_EXT_BUF->next;
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
break;
default:
return;
}

View File

@ -1282,6 +1282,12 @@ dao_ack_input(void)
parent = NULL;
}
if(instance->current_dag->rank == ROOT_RANK(instance)) {
PRINTF("RPL: DODAG root received a DAO ACK, ignoring it\n");
uip_clear_buf();
return;
}
PRINTF("RPL: Received a DAO %s with sequence number %d (%d) and status %d from ",
status < 128 ? "ACK" : "NACK",
sequence, instance->my_dao_seqno, status);

View File

@ -56,6 +56,7 @@
typedef struct rpl_ns_node {
struct rpl_ns_node *next;
uint32_t lifetime;
rpl_dag_t *dag;
/* Store only IPv6 link identifiers as all nodes in the DAG share the same prefix */
unsigned char link_identifier[8];
struct rpl_ns_node *parent;

View File

@ -199,13 +199,6 @@
#define RPL_ROUTE_FROM_MULTICAST_DAO 2
#define RPL_ROUTE_FROM_DIO 3
/* Multicast Route Lifetime as a multiple of the lifetime unit */
#ifdef RPL_CONF_MCAST_LIFETIME
#define RPL_MCAST_LIFETIME RPL_CONF_MCAST_LIFETIME
#else
#define RPL_MCAST_LIFETIME 3
#endif
/* DIS related */
#define RPL_DIS_SEND 1

View File

@ -283,7 +283,7 @@ handle_dao_timer(void *ptr)
if(uip_ds6_if.maddr_list[i].isused
&& uip_is_addr_mcast_global(&uip_ds6_if.maddr_list[i].ipaddr)) {
dao_output_target(instance->current_dag->preferred_parent,
&uip_ds6_if.maddr_list[i].ipaddr, RPL_MCAST_LIFETIME);
&uip_ds6_if.maddr_list[i].ipaddr, instance->default_lifetime);
}
}
@ -293,7 +293,7 @@ handle_dao_timer(void *ptr)
/* Don't send if it's also our own address, done that already */
if(uip_ds6_maddr_lookup(&mcast_route->group) == NULL) {
dao_output_target(instance->current_dag->preferred_parent,
&mcast_route->group, RPL_MCAST_LIFETIME);
&mcast_route->group, instance->default_lifetime);
}
mcast_route = list_item_next(mcast_route);
}
@ -457,11 +457,29 @@ get_probing_target(rpl_dag_t *dag)
return probing_target;
}
/*---------------------------------------------------------------------------*/
static rpl_dag_t *
get_next_dag(rpl_instance_t *instance)
{
rpl_dag_t *dag = NULL;
int new_dag = instance->last_dag;
do {
new_dag++;
if(new_dag >= RPL_MAX_DAG_PER_INSTANCE) {
new_dag = 0;
}
if(instance->dag_table[new_dag].used) {
dag = &instance->dag_table[new_dag];
}
} while(new_dag != instance->last_dag && dag == NULL);
instance->last_dag = new_dag;
return dag;
}
/*---------------------------------------------------------------------------*/
static void
handle_probing_timer(void *ptr)
{
rpl_instance_t *instance = (rpl_instance_t *)ptr;
rpl_parent_t *probing_target = RPL_PROBING_SELECT_FUNC(instance->current_dag);
rpl_parent_t *probing_target = RPL_PROBING_SELECT_FUNC(get_next_dag(instance));
uip_ipaddr_t *target_ipaddr = rpl_parent_get_ipaddr(probing_target);
/* Perform probing */

View File

@ -252,6 +252,7 @@ struct rpl_instance {
#if RPL_WITH_PROBING
struct ctimer probing_timer;
rpl_parent_t *urgent_probing_target;
int last_dag;
#endif /* RPL_WITH_PROBING */
struct ctimer dio_timer;
struct ctimer dao_timer;

View File

@ -302,7 +302,7 @@ insert_srh_header(void)
path_len, cmpri, cmpre, ext_len, padding);
/* Check if there is enough space to store the extension header */
if(uip_len + ext_len > UIP_BUFSIZE) {
if(uip_len + ext_len > UIP_BUFSIZE - UIP_LLH_LEN) {
LOG_ERR("packet too long: impossible to add source routing header (%u bytes)\n", ext_len);
return 0;
}
@ -464,7 +464,7 @@ insert_hbh_header(void)
/* Insert hop-by-hop header */
LOG_INFO("creating hop-by-hop option\n");
if(uip_len + RPL_HOP_BY_HOP_LEN > UIP_BUFSIZE) {
if(uip_len + RPL_HOP_BY_HOP_LEN > UIP_BUFSIZE - UIP_LLH_LEN) {
LOG_ERR("packet too long: impossible to add hop-by-hop option\n");
uip_ext_len = last_uip_ext_len;
return 0;
@ -531,9 +531,11 @@ rpl_ext_header_remove(void)
{
uint8_t temp_len;
uint8_t rpl_ext_hdr_len;
int uip_ext_opt_offset;
uint8_t *uip_next_hdr;
uip_ext_len = 0;
uip_ext_opt_offset = 2;
uip_next_hdr = &UIP_IP_BUF->proto;
/* Look for hop-by-hop and routing headers */
@ -541,17 +543,22 @@ rpl_ext_header_remove(void)
switch(*uip_next_hdr) {
case UIP_PROTO_HBHO:
case UIP_PROTO_ROUTING:
/* Remove hop-by-hop and routing headers */
*uip_next_hdr = UIP_EXT_BUF->next;
rpl_ext_hdr_len = (UIP_EXT_BUF->len * 8) + 8;
temp_len = UIP_IP_BUF->len[1];
uip_len -= rpl_ext_hdr_len;
UIP_IP_BUF->len[1] -= rpl_ext_hdr_len;
if(UIP_IP_BUF->len[1] > temp_len) {
UIP_IP_BUF->len[0]--;
if((*uip_next_hdr != UIP_PROTO_HBHO || UIP_EXT_HDR_OPT_RPL_BUF->opt_type == UIP_EXT_HDR_OPT_RPL)) {
/* Remove hop-by-hop and routing headers */
*uip_next_hdr = UIP_EXT_BUF->next;
rpl_ext_hdr_len = (UIP_EXT_BUF->len * 8) + 8;
temp_len = UIP_IP_BUF->len[1];
uip_len -= rpl_ext_hdr_len;
UIP_IP_BUF->len[1] -= rpl_ext_hdr_len;
if(UIP_IP_BUF->len[1] > temp_len) {
UIP_IP_BUF->len[0]--;
}
LOG_INFO("removing RPL extension header (type %u, len %u)\n", *uip_next_hdr, rpl_ext_hdr_len);
memmove(UIP_EXT_BUF, ((uint8_t *)UIP_EXT_BUF) + rpl_ext_hdr_len, uip_len - UIP_IPH_LEN);
} else {
uip_next_hdr = &UIP_EXT_BUF->next;
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
}
LOG_INFO("removing RPL extension header (type %u, len %u)\n", *uip_next_hdr, rpl_ext_hdr_len);
memmove(UIP_EXT_BUF, ((uint8_t *)UIP_EXT_BUF) + rpl_ext_hdr_len, uip_len - UIP_IPH_LEN);
break;
case UIP_PROTO_DESTO:
/*
@ -565,6 +572,7 @@ rpl_ext_header_remove(void)
/* Move to next header */
uip_next_hdr = &UIP_EXT_BUF->next;
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
break;
default:
return;
}

View File

@ -61,9 +61,9 @@ struct dhcp_msg {
uint8_t options[312];
};
#if (UIP_BUFSIZE - UIP_UDPIP_HLEN) < 548
#if (UIP_BUFSIZE - UIP_LLH_LEN - UIP_UDPIP_HLEN) < 548
#error UIP_CONF_BUFFER_SIZE may be too small to accomodate DHCPv4 packets
#error Increase UIP_CONF_BUFFER_SIZE in your project-conf.h, platform-conf.h, or contiki-conf.h
#error Increase UIP_CONF_BUFFER_SIZE in your project-conf.h, or contiki-conf.h
#error A good size is 600 bytes
#endif

92
os/sys/critical.h Normal file
View File

@ -0,0 +1,92 @@
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup sys
* @{
*
* \defgroup critical Critical sections
* @{
*
* Platform-independent functions for critical section entry and exit
*/
/*---------------------------------------------------------------------------*/
#ifndef CRITICAL_H_
#define CRITICAL_H_
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "sys/memory-barrier.h"
#include "sys/int-master.h"
#include <stdint.h>
/*---------------------------------------------------------------------------*/
/**
* \brief Enter a critical section
* \return The status of the master interrupt before entering the critical
*
* This function will return the status of the master interrupt as it was
* before entering the critical section.
*
* The semantics of the return value are entirely platform-specific. The
* calling code should not try to determine whether the master interrupt was
* previously enabled/disabled by interpreting the return value of this
* function. The return value should only be used as an argument to
* critical_exit().
*/
static inline int_master_status_t
critical_enter()
{
int_master_status_t status = int_master_read_and_disable();
memory_barrier();
return status;
}
/*---------------------------------------------------------------------------*/
/**
* \brief Exit a critical section and restore the master interrupt
* \param status The new status of the master interrupt
*
* The semantics of \e status are platform-dependent. Normally, the argument
* provided to this function will be a value previously retrieved through a
* call to critical_enter().
*/
static inline void
critical_exit(int_master_status_t status)
{
memory_barrier();
int_master_status_set(status);
}
/*---------------------------------------------------------------------------*/
#endif /* CRITICAL_H_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

Some files were not shown because too many files have changed in this diff Show More