From b4c2cd9619aac07bce4eefc706ef443b8b58c3c2 Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Mon, 7 Mar 2016 17:25:40 +0100 Subject: [PATCH 01/31] Macros for TSCH US_TO_RTIMERTICKS(US) and RTIMERTICKS_TO_US(T) --- cpu/cc2538/rtimer-arch.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cpu/cc2538/rtimer-arch.h b/cpu/cc2538/rtimer-arch.h index ddb020af1..45ebc5c5d 100644 --- a/cpu/cc2538/rtimer-arch.h +++ b/cpu/cc2538/rtimer-arch.h @@ -65,6 +65,20 @@ #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 ? \ + (((int32_t)(US) * (RTIMER_ARCH_SECOND) + 500000) / 1000000L) : \ + ((int32_t)(US) * (RTIMER_ARCH_SECOND) - 500000) / 1000000L) + +#define RTIMERTICKS_TO_US(T) ((T) >= 0 ? \ + (((int32_t)(T) * 1000000L + ((RTIMER_ARCH_SECOND) / 2)) / (RTIMER_ARCH_SECOND)) : \ + ((int32_t)(T) * 1000000L - ((RTIMER_ARCH_SECOND) / 2)) / (RTIMER_ARCH_SECOND)) + +/* A 64-bit version because the 32-bit one cannot handle T >= 4295 ticks. + Intended only for positive values of T. */ +#define RTIMERTICKS_TO_US_64(T) ((uint32_t)(((uint64_t)(T) * 1000000 + ((RTIMER_ARCH_SECOND) / 2)) / (RTIMER_ARCH_SECOND))) + /** \sa RTIMER_NOW() */ rtimer_clock_t rtimer_arch_now(void); From b0a673ca5c24155bc95b6b7faacef3f99da6b2f2 Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Mon, 7 Mar 2016 17:46:53 +0100 Subject: [PATCH 02/31] Changes to enable TSCH poll mode for TSCH including SFD timestamps and send_on_cca --- cpu/cc2538/dev/cc2538-rf.c | 137 ++++++++++++++++++++++++++++++------- 1 file changed, 111 insertions(+), 26 deletions(-) diff --git a/cpu/cc2538/dev/cc2538-rf.c b/cpu/cc2538/dev/cc2538-rf.c index 58b464fc5..a76c1c356 100644 --- a/cpu/cc2538/dev/cc2538-rf.c +++ b/cpu/cc2538/dev/cc2538-rf.c @@ -120,6 +120,17 @@ static const uint8_t magic[] = { 0x53, 0x6E, 0x69, 0x66 }; /** Snif */ #define CC2538_RF_AUTOACK 1 #endif /*---------------------------------------------------------------------------*/ +#if CC2538_RF_CONF_SFD_TIMESTAMPS +static rtimer_clock_t cc2538_sfd_rtime; +#endif + +/* Are we currently in poll mode? Disabled by default */ +static uint8_t volatile poll_mode = 0; +/* Do we perform a CCA before sending? Enabled by default. */ +static uint8_t send_on_cca = 1; +static int8_t cc2538_last_rssi; +static uint8_t cc2538_last_crc_corr_lqi; +/*---------------------------------------------------------------------------*/ static uint8_t rf_flags; static uint8_t rf_channel = CC2538_RF_CHANNEL; @@ -329,6 +340,29 @@ set_frame_filtering(uint8_t enable) } /*---------------------------------------------------------------------------*/ static void +set_poll_mode(uint8_t enable) +{ + poll_mode = enable; + + if(enable) { + REG(RFCORE_XREG_RFIRQM0) &= ~RFCORE_XREG_RFIRQM0_FIFOP; // mask out FIFOP interrupt source + REG(RFCORE_SFR_RFIRQF0) &= ~RFCORE_SFR_RFIRQF0_FIFOP; // clear pending FIFOP interrupt + REG(RFCORE_XREG_RFIRQM0) |= RFCORE_XREG_RFIRQM0_SFD; // enable SFD interrupt source + } else { + REG(RFCORE_XREG_RFIRQM0) |= RFCORE_XREG_RFIRQM0_FIFOP; // enable FIFOP interrupt source + REG(RFCORE_XREG_RFIRQM0) &= ~RFCORE_XREG_RFIRQM0_SFD; // mask out SFD interrupt source + REG(RFCORE_SFR_RFIRQF0) &= ~RFCORE_SFR_RFIRQF0_SFD; // clear pending SFD interrupt + } + nvic_interrupt_enable(NVIC_INT_RF_RXTX); // enable RF interrupts +} +/*---------------------------------------------------------------------------*/ +static void +set_send_on_cca(uint8_t enable) +{ + send_on_cca = enable; +} +/*---------------------------------------------------------------------------*/ +static void set_auto_ack(uint8_t enable) { if(enable) { @@ -395,7 +429,9 @@ off(void) /* Wait for ongoing TX to complete (e.g. this could be an outgoing ACK) */ while(REG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_TX_ACTIVE); - CC2538_RF_CSP_ISFLUSHRX(); + if (!(REG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_FIFOP)) { + CC2538_RF_CSP_ISFLUSHRX(); + } /* Don't turn off if we are off as this will trigger a Strobe Error */ if(REG(RFCORE_XREG_RXENABLE) != 0) { @@ -459,10 +495,6 @@ init(void) set_channel(rf_channel); - /* Acknowledge RF interrupts, FIFOP only */ - REG(RFCORE_XREG_RFIRQM0) |= RFCORE_XREG_RFIRQM0_FIFOP; - nvic_interrupt_enable(NVIC_INT_RF_RXTX); - /* Acknowledge all RF Error interrupts */ REG(RFCORE_XREG_RFERRM) = RFCORE_XREG_RFERRM_RFERRM; nvic_interrupt_enable(NVIC_INT_RF_ERR); @@ -488,6 +520,8 @@ init(void) */ udma_set_channel_src(CC2538_RF_CONF_RX_DMA_CHAN, RFCORE_SFR_RFDATA); } + + set_poll_mode(poll_mode); process_start(&cc2538_rf_process, NULL); @@ -700,15 +734,15 @@ read(void *buf, unsigned short bufsize) } /* Read the RSSI and CRC/Corr bytes */ - rssi = ((int8_t)REG(RFCORE_SFR_RFDATA)) - RSSI_OFFSET; - crc_corr = REG(RFCORE_SFR_RFDATA); + cc2538_last_rssi = ((int8_t)REG(RFCORE_SFR_RFDATA)) - RSSI_OFFSET; + cc2538_last_crc_corr_lqi = REG(RFCORE_SFR_RFDATA); - PRINTF("%02x%02x\n", (uint8_t)rssi, crc_corr); + PRINTF("%02x%02x\n", (uint8_t)cc2538_last_rssi, cc2538_last_crc_corr_lqi); /* MS bit CRC OK/Not OK, 7 LS Bits, Correlation value */ - if(crc_corr & CRC_BIT_MASK) { - packetbuf_set_attr(PACKETBUF_ATTR_RSSI, rssi); - packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, crc_corr & LQI_BIT_MASK); + if(cc2538_last_crc_corr_lqi & CRC_BIT_MASK) { + packetbuf_set_attr(PACKETBUF_ATTR_RSSI, cc2538_last_rssi); + packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, cc2538_last_crc_corr_lqi & LQI_BIT_MASK); RIMESTATS_ADD(llrx); } else { RIMESTATS_ADD(badcrc); @@ -731,14 +765,18 @@ read(void *buf, unsigned short bufsize) flush(); #endif - /* If FIFOP==1 and FIFO==0 then we had a FIFO overflow at some point. */ - if(REG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_FIFOP) { - if(REG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_FIFO) { - process_poll(&cc2538_rf_process); - } else { - CC2538_RF_CSP_ISFLUSHRX(); + if(!poll_mode) { + /* If FIFOP==1 and FIFO==0 then we had a FIFO overflow at some point. */ + if(REG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_FIFOP) { + if(REG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_FIFO) { + process_poll(&cc2538_rf_process); + } else { + CC2538_RF_CSP_ISFLUSHRX(); + } } } + + CC2538_RF_CSP_ISFLUSHRX(); return (len); } @@ -796,6 +834,15 @@ get_value(radio_param_t param, radio_value_t *value) if(REG(RFCORE_XREG_FRMCTRL0) & RFCORE_XREG_FRMCTRL0_AUTOACK) { *value |= RADIO_RX_MODE_AUTOACK; } + if(poll_mode) { + *value |= RADIO_RX_MODE_POLL_MODE; + } + return RADIO_RESULT_OK; + case RADIO_PARAM_TX_MODE: + *value = 0; + if(send_on_cca) { + *value |= RADIO_TX_MODE_SEND_ON_CCA; + } return RADIO_RESULT_OK; case RADIO_PARAM_TXPOWER: *value = get_tx_power(); @@ -806,6 +853,12 @@ get_value(radio_param_t param, radio_value_t *value) case RADIO_PARAM_RSSI: *value = get_rssi(); return RADIO_RESULT_OK; + case RADIO_PARAM_LAST_RSSI: + *value = cc2538_last_rssi; + return RADIO_RESULT_OK; + case RADIO_PARAM_LAST_LINK_QUALITY: + *value = cc2538_last_crc_corr_lqi & LQI_BIT_MASK; + return RADIO_RESULT_OK; case RADIO_CONST_CHANNEL_MIN: *value = CC2538_RF_CHANNEL_MIN; return RADIO_RESULT_OK; @@ -854,13 +907,21 @@ set_value(radio_param_t param, radio_value_t value) return RADIO_RESULT_OK; case RADIO_PARAM_RX_MODE: if(value & ~(RADIO_RX_MODE_ADDRESS_FILTER | - RADIO_RX_MODE_AUTOACK)) { + RADIO_RX_MODE_AUTOACK | + RADIO_RX_MODE_POLL_MODE)) { return RADIO_RESULT_INVALID_VALUE; } set_frame_filtering((value & RADIO_RX_MODE_ADDRESS_FILTER) != 0); set_auto_ack((value & RADIO_RX_MODE_AUTOACK) != 0); + set_poll_mode((value & RADIO_RX_MODE_POLL_MODE) != 0); + return RADIO_RESULT_OK; + case RADIO_PARAM_TX_MODE: + if(value & ~(RADIO_TX_MODE_SEND_ON_CCA)) { + return RADIO_RESULT_INVALID_VALUE; + } + set_send_on_cca((value & RADIO_TX_MODE_SEND_ON_CCA) != 0); return RADIO_RESULT_OK; case RADIO_PARAM_TXPOWER: if(value < OUTPUT_POWER_MIN || value > OUTPUT_POWER_MAX) { @@ -895,6 +956,19 @@ get_object(radio_param_t param, void *dest, size_t size) return RADIO_RESULT_OK; } + + if(param == RADIO_PARAM_LAST_PACKET_TIMESTAMP) { +#if CC2538_RF_CONF_SFD_TIMESTAMPS + if(size != sizeof(rtimer_clock_t) || !dest) { + return RADIO_RESULT_INVALID_VALUE; + } + *(rtimer_clock_t*)dest = cc2538_sfd_rtime; + return RADIO_RESULT_OK; +#else + return RADIO_RESULT_NOT_SUPPORTED; +#endif + } + return RADIO_RESULT_NOT_SUPPORTED; } /*---------------------------------------------------------------------------*/ @@ -950,15 +1024,18 @@ PROCESS_THREAD(cc2538_rf_process, ev, data) PROCESS_BEGIN(); while(1) { - PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL); + /* Only if we are not in poll mode oder we are in poll mode and transceiver has to be reset */ + PROCESS_YIELD_UNTIL((!poll_mode || (poll_mode && (rf_flags & RF_MUST_RESET))) && (ev == PROCESS_EVENT_POLL)); - packetbuf_clear(); - len = read(packetbuf_dataptr(), PACKETBUF_SIZE); + if(!poll_mode) { + packetbuf_clear(); + len = read(packetbuf_dataptr(), PACKETBUF_SIZE); - if(len > 0) { - packetbuf_set_datalen(len); + if(len > 0) { + packetbuf_set_datalen(len); - NETSTACK_RDC.input(); + NETSTACK_RDC.input(); + } } /* If we were polled due to an RF error, reset the transceiver */ @@ -995,10 +1072,18 @@ void cc2538_rf_rx_tx_isr(void) { ENERGEST_ON(ENERGEST_TYPE_IRQ); + +#if CC2538_RF_CONF_SFD_TIMESTAMPS + if(poll_mode) { + cc2538_sfd_rtime = RTIMER_NOW(); + } +#endif - process_poll(&cc2538_rf_process); + if(!poll_mode) { + process_poll(&cc2538_rf_process); + } - /* We only acknowledge FIFOP so we can safely wipe out the entire SFR */ + /* We only acknowledge FIFOP or SFD so we can safely wipe out the entire SFR */ REG(RFCORE_SFR_RFIRQF0) = 0; ENERGEST_OFF(ENERGEST_TYPE_IRQ); From 73d36ebb6b9d7291fdb43592b271dd8b161ccad9 Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Mon, 7 Mar 2016 18:34:54 +0100 Subject: [PATCH 03/31] SFD timestamp Only save SFD timestamp when we are actually receiving. --- cpu/cc2538/dev/cc2538-rf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cpu/cc2538/dev/cc2538-rf.c b/cpu/cc2538/dev/cc2538-rf.c index a76c1c356..fda88ceed 100644 --- a/cpu/cc2538/dev/cc2538-rf.c +++ b/cpu/cc2538/dev/cc2538-rf.c @@ -1075,7 +1075,9 @@ cc2538_rf_rx_tx_isr(void) #if CC2538_RF_CONF_SFD_TIMESTAMPS if(poll_mode) { - cc2538_sfd_rtime = RTIMER_NOW(); + if(REG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_RX_ACTIVE) { + cc2538_sfd_rtime = RTIMER_NOW(); + } } #endif From b32ad0dbbdf77b0bf5c2c738694e40ffb3fe478c Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Mon, 7 Mar 2016 18:37:03 +0100 Subject: [PATCH 04/31] define for SFD timestamp on cc2538 --- examples/ipv6/rpl-tsch/project-conf.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/ipv6/rpl-tsch/project-conf.h b/examples/ipv6/rpl-tsch/project-conf.h index 7ecfb74c1..13595f333 100644 --- a/examples/ipv6/rpl-tsch/project-conf.h +++ b/examples/ipv6/rpl-tsch/project-conf.h @@ -67,6 +67,11 @@ #define TSCH_CALLBACK_JOINING_NETWORK tsch_rpl_callback_joining_network #define TSCH_CALLBACK_LEAVING_NETWORK tsch_rpl_callback_leaving_network +/* Needed for cc2538 platform only */ +/* Enable SFD timestamp (uses SFD interrupt) */ +#undef CC2538_RF_CONF_SFD_TIMESTAMPS +#define CC2538_RF_CONF_SFD_TIMESTAMPS 1 + /* Needed for cc2420 platforms only */ /* Disable DCO calibration (uses timerB) */ #undef DCOSYNCH_CONF_ENABLED From 9ac14d1c7bf1d831de885fc139010411c7eba222 Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Mon, 7 Mar 2016 18:39:13 +0100 Subject: [PATCH 05/31] defines needed for TSCH --- platform/cc2538dk/contiki-conf.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/platform/cc2538dk/contiki-conf.h b/platform/cc2538dk/contiki-conf.h index 34a7f1673..380288f02 100644 --- a/platform/cc2538dk/contiki-conf.h +++ b/platform/cc2538dk/contiki-conf.h @@ -40,6 +40,12 @@ typedef uint32_t rtimer_clock_t; #define RTIMER_CLOCK_LT(a,b) ((int32_t)((a)-(b)) < 0) /** @} */ /*---------------------------------------------------------------------------*/ +#define SYS_CTRL_CONF_OSC32K_USE_XTAL 1 + +#define RADIO_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(300)) +#define RADIO_DELAY_BEFORE_RX ((unsigned)US_TO_RTIMERTICKS(100)) +#define RADIO_DELAY_BEFORE_DETECT 0 +/*---------------------------------------------------------------------------*/ /** * \name Serial Boot Loader Backdoor configuration * From 6e5e1d05cdc9e6fb6dddaf95da5608d5687a808c Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Tue, 8 Mar 2016 15:48:16 +0100 Subject: [PATCH 06/31] TSCH: define to enable/disable HW frame filtering --- core/net/mac/tsch/tsch-conf.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/net/mac/tsch/tsch-conf.h b/core/net/mac/tsch/tsch-conf.h index bd9726042..b23355539 100644 --- a/core/net/mac/tsch/tsch-conf.h +++ b/core/net/mac/tsch/tsch-conf.h @@ -175,4 +175,11 @@ #define TSCH_ADAPTIVE_TIMESYNC 0 #endif +/* HW frame filtering enabled */ +#ifdef TSCH_CONF_HW_FRAME_FILTERING +#define TSCH_HW_FRAME_FILTERING TSCH_CONF_HW_FRAME_FILTERING +#else /* TSCH_CONF_HW_FRAME_FILTERING */ +#define TSCH_HW_FRAME_FILTERING 1 +#endif + #endif /* __TSCH_CONF_H__ */ From 38348b8703b7f914cf892ef71b4969de0b7c8851 Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Tue, 8 Mar 2016 15:50:37 +0100 Subject: [PATCH 07/31] enable/disable HW frame filtering enable/disable HW frame filtering as defined in TSCH_CONF_HW_FRAME_FILTERING --- core/net/mac/tsch/tsch-slot-operation.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/net/mac/tsch/tsch-slot-operation.c b/core/net/mac/tsch/tsch-slot-operation.c index 3174787c2..be1885bc7 100644 --- a/core/net/mac/tsch/tsch-slot-operation.c +++ b/core/net/mac/tsch/tsch-slot-operation.c @@ -514,9 +514,11 @@ PT_THREAD(tsch_tx_slot(struct pt *pt, struct rtimer *t)) TSCH_DEBUG_TX_EVENT(); NETSTACK_RADIO.off(); +#if TSCH_HW_FRAME_FILTERING /* Leaving promiscuous mode */ NETSTACK_RADIO.get_value(RADIO_PARAM_RX_MODE, &radio_rx_mode); NETSTACK_RADIO.set_value(RADIO_PARAM_RX_MODE, radio_rx_mode | RADIO_RX_MODE_ADDRESS_FILTER); +#endif /* TSCH_HW_FRAME_FILTERING */ /* Read ack frame */ ack_len = NETSTACK_RADIO.read((void *)ackbuf, sizeof(ackbuf)); From 0e0dba932ffcfcf7d08857cb5f500403ee2116e6 Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Tue, 8 Mar 2016 15:52:40 +0100 Subject: [PATCH 08/31] disable TSCH HW frame filtering --- platform/cc2538dk/contiki-conf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/cc2538dk/contiki-conf.h b/platform/cc2538dk/contiki-conf.h index 380288f02..c91338849 100644 --- a/platform/cc2538dk/contiki-conf.h +++ b/platform/cc2538dk/contiki-conf.h @@ -40,7 +40,7 @@ typedef uint32_t rtimer_clock_t; #define RTIMER_CLOCK_LT(a,b) ((int32_t)((a)-(b)) < 0) /** @} */ /*---------------------------------------------------------------------------*/ -#define SYS_CTRL_CONF_OSC32K_USE_XTAL 1 +#define TSCH_CONF_HW_FRAME_FILTERING 0 #define RADIO_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(300)) #define RADIO_DELAY_BEFORE_RX ((unsigned)US_TO_RTIMERTICKS(100)) From a4ccce8dac213de5b581cddbf2d861a908309ff6 Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Tue, 8 Mar 2016 15:54:03 +0100 Subject: [PATCH 09/31] enable 32 kHz crystal oscillator for TSCH --- examples/ipv6/rpl-tsch/project-conf.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/ipv6/rpl-tsch/project-conf.h b/examples/ipv6/rpl-tsch/project-conf.h index 13595f333..71a8e5425 100644 --- a/examples/ipv6/rpl-tsch/project-conf.h +++ b/examples/ipv6/rpl-tsch/project-conf.h @@ -71,6 +71,10 @@ /* Enable SFD timestamp (uses SFD interrupt) */ #undef CC2538_RF_CONF_SFD_TIMESTAMPS #define CC2538_RF_CONF_SFD_TIMESTAMPS 1 +/* For TSCH we have to use the more accurate crystal oscillator + * by default the RC oscillator is activated */ +#undef SYS_CTRL_CONF_OSC32K_USE_XTAL +#define SYS_CTRL_CONF_OSC32K_USE_XTAL 1 /* Needed for cc2420 platforms only */ /* Disable DCO calibration (uses timerB) */ From 1b185392e444d2f22559db60d1f1a0f0a31f6a61 Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Tue, 8 Mar 2016 16:17:40 +0100 Subject: [PATCH 10/31] make cc2538_sfd_rtime volatile --- cpu/cc2538/dev/cc2538-rf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu/cc2538/dev/cc2538-rf.c b/cpu/cc2538/dev/cc2538-rf.c index fda88ceed..f889a373d 100644 --- a/cpu/cc2538/dev/cc2538-rf.c +++ b/cpu/cc2538/dev/cc2538-rf.c @@ -121,7 +121,7 @@ static const uint8_t magic[] = { 0x53, 0x6E, 0x69, 0x66 }; /** Snif */ #endif /*---------------------------------------------------------------------------*/ #if CC2538_RF_CONF_SFD_TIMESTAMPS -static rtimer_clock_t cc2538_sfd_rtime; +static rtimer_clock_t volatile cc2538_sfd_rtime; #endif /* Are we currently in poll mode? Disabled by default */ From 217e623337620c3e463f91ed4994668a9dc93cb4 Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Thu, 10 Mar 2016 18:09:00 +0100 Subject: [PATCH 11/31] remove unused variables --- cpu/cc2538/dev/cc2538-rf.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/cpu/cc2538/dev/cc2538-rf.c b/cpu/cc2538/dev/cc2538-rf.c index f889a373d..9a1957fe0 100644 --- a/cpu/cc2538/dev/cc2538-rf.c +++ b/cpu/cc2538/dev/cc2538-rf.c @@ -664,8 +664,6 @@ read(void *buf, unsigned short bufsize) { uint8_t i; uint8_t len; - uint8_t crc_corr; - int8_t rssi; PRINTF("RF: Read\n"); From 57a47bb12f6639c1cccb87b06bd6862ed693a8e7 Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Thu, 10 Mar 2016 18:36:47 +0100 Subject: [PATCH 12/31] node_id on cc2538dk --- examples/ipv6/rpl-tsch/node.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/ipv6/rpl-tsch/node.c b/examples/ipv6/rpl-tsch/node.c index 2aee41d81..beceff326 100644 --- a/examples/ipv6/rpl-tsch/node.c +++ b/examples/ipv6/rpl-tsch/node.c @@ -38,6 +38,7 @@ #include "contiki.h" #include "node-id.h" +#include "linkaddr.h" #include "net/rpl/rpl.h" #include "net/ipv6/uip-ds6-route.h" #include "net/mac/tsch/tsch.h" @@ -131,6 +132,7 @@ net_init(uip_ipaddr_t *br_prefix) PROCESS_THREAD(node_process, ev, data) { static struct etimer et; + static unsigned short node_id; PROCESS_BEGIN(); /* 3 possible roles: @@ -142,6 +144,8 @@ PROCESS_THREAD(node_process, ev, data) static enum { role_6ln, role_6dr, role_6dr_sec } node_role; node_role = role_6ln; + node_id = linkaddr_node_addr.u8[LINKADDR_SIZE - 2] | linkaddr_node_addr.u8[LINKADDR_SIZE - 1]; + /* Set node with ID == 1 as coordinator, convenient in Cooja. */ if(node_id == 1) { if(LLSEC802154_CONF_SECURITY_LEVEL) { From 45c7477650a19c2cbee5162c652e33786aa86b4d Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Fri, 11 Mar 2016 11:02:43 +0100 Subject: [PATCH 13/31] original node.c --- examples/ipv6/rpl-tsch/node.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/ipv6/rpl-tsch/node.c b/examples/ipv6/rpl-tsch/node.c index beceff326..2aee41d81 100644 --- a/examples/ipv6/rpl-tsch/node.c +++ b/examples/ipv6/rpl-tsch/node.c @@ -38,7 +38,6 @@ #include "contiki.h" #include "node-id.h" -#include "linkaddr.h" #include "net/rpl/rpl.h" #include "net/ipv6/uip-ds6-route.h" #include "net/mac/tsch/tsch.h" @@ -132,7 +131,6 @@ net_init(uip_ipaddr_t *br_prefix) PROCESS_THREAD(node_process, ev, data) { static struct etimer et; - static unsigned short node_id; PROCESS_BEGIN(); /* 3 possible roles: @@ -144,8 +142,6 @@ PROCESS_THREAD(node_process, ev, data) static enum { role_6ln, role_6dr, role_6dr_sec } node_role; node_role = role_6ln; - node_id = linkaddr_node_addr.u8[LINKADDR_SIZE - 2] | linkaddr_node_addr.u8[LINKADDR_SIZE - 1]; - /* Set node with ID == 1 as coordinator, convenient in Cooja. */ if(node_id == 1) { if(LLSEC802154_CONF_SECURITY_LEVEL) { From 400a09e82ceb8e77464bf072748ba42f18ed38e6 Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Fri, 11 Mar 2016 11:05:04 +0100 Subject: [PATCH 14/31] comment --- platform/cc2538dk/contiki-conf.h | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/cc2538dk/contiki-conf.h b/platform/cc2538dk/contiki-conf.h index c91338849..ae7c3275d 100644 --- a/platform/cc2538dk/contiki-conf.h +++ b/platform/cc2538dk/contiki-conf.h @@ -42,6 +42,7 @@ typedef uint32_t rtimer_clock_t; /*---------------------------------------------------------------------------*/ #define TSCH_CONF_HW_FRAME_FILTERING 0 +/* TODO: measure the delays, this are only estimations */ #define RADIO_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(300)) #define RADIO_DELAY_BEFORE_RX ((unsigned)US_TO_RTIMERTICKS(100)) #define RADIO_DELAY_BEFORE_DETECT 0 From 2d9b53667fdd49573a703bbf226c73115bcca817 Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Wed, 16 Mar 2016 12:24:49 +0100 Subject: [PATCH 15/31] not leaving promiscuous mode anymore if TSCH_HW_FRAME_FILTERING disabled --- core/net/mac/tsch/tsch-slot-operation.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/net/mac/tsch/tsch-slot-operation.c b/core/net/mac/tsch/tsch-slot-operation.c index be1885bc7..7deccaa92 100644 --- a/core/net/mac/tsch/tsch-slot-operation.c +++ b/core/net/mac/tsch/tsch-slot-operation.c @@ -493,9 +493,11 @@ PT_THREAD(tsch_tx_slot(struct pt *pt, struct rtimer *t)) uint8_t ack_hdrlen; frame802154_t frame; +#if TSCH_HW_FRAME_FILTERING /* Entering promiscuous mode so that the radio accepts the enhanced ACK */ NETSTACK_RADIO.get_value(RADIO_PARAM_RX_MODE, &radio_rx_mode); NETSTACK_RADIO.set_value(RADIO_PARAM_RX_MODE, radio_rx_mode & (~RADIO_RX_MODE_ADDRESS_FILTER)); +#endif /* TSCH_HW_FRAME_FILTERING */ /* Unicast: wait for ack after tx: sleep until ack time */ TSCH_SCHEDULE_AND_YIELD(pt, t, current_slot_start, tsch_timing[tsch_ts_tx_offset] + tx_duration + tsch_timing[tsch_ts_rx_ack_delay] - RADIO_DELAY_BEFORE_RX, "TxBeforeAck"); From 66a0bbcd24dbd529586de9400e0e045c5744f63d Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Wed, 16 Mar 2016 16:38:04 +0100 Subject: [PATCH 16/31] renaming variables back to their original name --- cpu/cc2538/dev/cc2538-rf.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cpu/cc2538/dev/cc2538-rf.c b/cpu/cc2538/dev/cc2538-rf.c index 9a1957fe0..a07108e8b 100644 --- a/cpu/cc2538/dev/cc2538-rf.c +++ b/cpu/cc2538/dev/cc2538-rf.c @@ -128,8 +128,8 @@ static rtimer_clock_t volatile cc2538_sfd_rtime; static uint8_t volatile poll_mode = 0; /* Do we perform a CCA before sending? Enabled by default. */ static uint8_t send_on_cca = 1; -static int8_t cc2538_last_rssi; -static uint8_t cc2538_last_crc_corr_lqi; +static int8_t rssi; +static uint8_t crc_corr; /*---------------------------------------------------------------------------*/ static uint8_t rf_flags; static uint8_t rf_channel = CC2538_RF_CHANNEL; @@ -732,15 +732,15 @@ read(void *buf, unsigned short bufsize) } /* Read the RSSI and CRC/Corr bytes */ - cc2538_last_rssi = ((int8_t)REG(RFCORE_SFR_RFDATA)) - RSSI_OFFSET; - cc2538_last_crc_corr_lqi = REG(RFCORE_SFR_RFDATA); + rssi = ((int8_t)REG(RFCORE_SFR_RFDATA)) - RSSI_OFFSET; + crc_corr = REG(RFCORE_SFR_RFDATA); - PRINTF("%02x%02x\n", (uint8_t)cc2538_last_rssi, cc2538_last_crc_corr_lqi); + PRINTF("%02x%02x\n", (uint8_t)rssi, crc_corr); /* MS bit CRC OK/Not OK, 7 LS Bits, Correlation value */ - if(cc2538_last_crc_corr_lqi & CRC_BIT_MASK) { - packetbuf_set_attr(PACKETBUF_ATTR_RSSI, cc2538_last_rssi); - packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, cc2538_last_crc_corr_lqi & LQI_BIT_MASK); + if(crc_corr & CRC_BIT_MASK) { + packetbuf_set_attr(PACKETBUF_ATTR_RSSI, rssi); + packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, crc_corr & LQI_BIT_MASK); RIMESTATS_ADD(llrx); } else { RIMESTATS_ADD(badcrc); @@ -852,10 +852,10 @@ get_value(radio_param_t param, radio_value_t *value) *value = get_rssi(); return RADIO_RESULT_OK; case RADIO_PARAM_LAST_RSSI: - *value = cc2538_last_rssi; + *value = rssi; return RADIO_RESULT_OK; case RADIO_PARAM_LAST_LINK_QUALITY: - *value = cc2538_last_crc_corr_lqi & LQI_BIT_MASK; + *value = crc_corr & LQI_BIT_MASK; return RADIO_RESULT_OK; case RADIO_CONST_CHANNEL_MIN: *value = CC2538_RF_CHANNEL_MIN; From fb6e6d9ea3ae763c8a3a60a0bb868732a7d5be0c Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Tue, 22 Mar 2016 18:51:05 +0100 Subject: [PATCH 17/31] macros for MAC timer --- cpu/cc2538/dev/cc2538-rf.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cpu/cc2538/dev/cc2538-rf.h b/cpu/cc2538/dev/cc2538-rf.h index 5edb478ba..287147a92 100644 --- a/cpu/cc2538/dev/cc2538-rf.h +++ b/cpu/cc2538/dev/cc2538-rf.h @@ -129,6 +129,15 @@ REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHTX; \ REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHTX; \ } while(0) +/*--------------------------------------------------------------------------- + * MAC timer + *---------------------------------------------------------------------------*/ +/* Timer conversion */ +#define RADIO_TO_RTIMER(X) ((X) * RTIMER_ARCH_SECOND / SYS_CTRL_32MHZ) + +#define CLOCK_STABLE() do { \ + while ( !(REG(SYS_CTRL_CLOCK_STA) & (SYS_CTRL_CLOCK_STA_XOSC_STB))); \ + } while(0) /*---------------------------------------------------------------------------*/ /** The NETSTACK data structure for the cc2538 RF driver */ extern const struct radio_driver cc2538_rf_driver; From a4f575b8f03fca1f297409598fad1c5e05fea0a7 Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Wed, 23 Mar 2016 09:08:54 +0100 Subject: [PATCH 18/31] use MAC timer instead of SFD interrupt --- cpu/cc2538/dev/cc2538-rf.c | 65 ++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/cpu/cc2538/dev/cc2538-rf.c b/cpu/cc2538/dev/cc2538-rf.c index a07108e8b..0ecf7cb59 100644 --- a/cpu/cc2538/dev/cc2538-rf.c +++ b/cpu/cc2538/dev/cc2538-rf.c @@ -120,16 +120,15 @@ static const uint8_t magic[] = { 0x53, 0x6E, 0x69, 0x66 }; /** Snif */ #define CC2538_RF_AUTOACK 1 #endif /*---------------------------------------------------------------------------*/ -#if CC2538_RF_CONF_SFD_TIMESTAMPS -static rtimer_clock_t volatile cc2538_sfd_rtime; -#endif - /* Are we currently in poll mode? Disabled by default */ static uint8_t volatile poll_mode = 0; /* Do we perform a CCA before sending? Enabled by default. */ static uint8_t send_on_cca = 1; static int8_t rssi; static uint8_t crc_corr; + +void mac_timer_init(void); +uint32_t get_sfd_timestamp(void); /*---------------------------------------------------------------------------*/ static uint8_t rf_flags; static uint8_t rf_channel = CC2538_RF_CHANNEL; @@ -347,13 +346,14 @@ set_poll_mode(uint8_t enable) if(enable) { REG(RFCORE_XREG_RFIRQM0) &= ~RFCORE_XREG_RFIRQM0_FIFOP; // mask out FIFOP interrupt source REG(RFCORE_SFR_RFIRQF0) &= ~RFCORE_SFR_RFIRQF0_FIFOP; // clear pending FIFOP interrupt - REG(RFCORE_XREG_RFIRQM0) |= RFCORE_XREG_RFIRQM0_SFD; // enable SFD interrupt source + REG(RFCORE_XREG_RFIRQM0) &= ~RFCORE_XREG_RFIRQM0_SFD; // disable SFD interrupt source + nvic_interrupt_disable(NVIC_INT_RF_RXTX); } else { REG(RFCORE_XREG_RFIRQM0) |= RFCORE_XREG_RFIRQM0_FIFOP; // enable FIFOP interrupt source - REG(RFCORE_XREG_RFIRQM0) &= ~RFCORE_XREG_RFIRQM0_SFD; // mask out SFD interrupt source - REG(RFCORE_SFR_RFIRQF0) &= ~RFCORE_SFR_RFIRQF0_SFD; // clear pending SFD interrupt + REG(RFCORE_XREG_RFIRQM0) &= ~RFCORE_XREG_RFIRQM0_SFD; // mask out SFD interrupt source + REG(RFCORE_SFR_RFIRQF0) &= ~RFCORE_SFR_RFIRQF0_SFD; // clear pending SFD interrupt + nvic_interrupt_enable(NVIC_INT_RF_RXTX); // enable RF interrupts } - nvic_interrupt_enable(NVIC_INT_RF_RXTX); // enable RF interrupts } /*---------------------------------------------------------------------------*/ static void @@ -521,6 +521,8 @@ init(void) udma_set_channel_src(CC2538_RF_CONF_RX_DMA_CHAN, RFCORE_SFR_RFDATA); } + mac_timer_init(); + set_poll_mode(poll_mode); process_start(&cc2538_rf_process, NULL); @@ -956,15 +958,11 @@ get_object(radio_param_t param, void *dest, size_t size) } if(param == RADIO_PARAM_LAST_PACKET_TIMESTAMP) { -#if CC2538_RF_CONF_SFD_TIMESTAMPS if(size != sizeof(rtimer_clock_t) || !dest) { return RADIO_RESULT_INVALID_VALUE; } *(rtimer_clock_t*)dest = cc2538_sfd_rtime; return RADIO_RESULT_OK; -#else - return RADIO_RESULT_NOT_SUPPORTED; -#endif } return RADIO_RESULT_NOT_SUPPORTED; @@ -1071,14 +1069,6 @@ cc2538_rf_rx_tx_isr(void) { ENERGEST_ON(ENERGEST_TYPE_IRQ); -#if CC2538_RF_CONF_SFD_TIMESTAMPS - if(poll_mode) { - if(REG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_RX_ACTIVE) { - cc2538_sfd_rtime = RTIMER_NOW(); - } - } -#endif - if(!poll_mode) { process_poll(&cc2538_rf_process); } @@ -1130,4 +1120,39 @@ cc2538_rf_set_promiscous_mode(char p) set_frame_filtering(p); } /*---------------------------------------------------------------------------*/ +uint32_t get_sfd_timestamp(void) +{ + uint32_t sfd, timer_val; + + REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMSEL) | 0x00000000; + REG(RFCORE_SFR_MTCTRL) |= RFCORE_SFR_MTCTRL_LATCH_MODE; + timer_val = REG(RFCORE_SFR_MTM0) & RFCORE_SFR_MTM0_MTM0; + timer_val |= ((REG(RFCORE_SFR_MTM1) & RFCORE_SFR_MTM1_MTM1) << 8); + REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMOVFSEL) | 0x00000000; + timer_val |= ((REG(RFCORE_SFR_MTMOVF0) & RFCORE_SFR_MTMOVF0_MTMOVF0) << 16); + timer_val |= ((REG(RFCORE_SFR_MTMOVF1) & RFCORE_SFR_MTMOVF1_MTMOVF1) << 24); + + REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMSEL) | 0x00000001; + REG(RFCORE_SFR_MTCTRL) |= RFCORE_SFR_MTCTRL_LATCH_MODE; + sfd = REG(RFCORE_SFR_MTM0) & RFCORE_SFR_MTM0_MTM0; + sfd |= ((REG(RFCORE_SFR_MTM1) & RFCORE_SFR_MTM1_MTM1) << 8); + REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMOVFSEL) | 0x00000010; + sfd |= ((REG(RFCORE_SFR_MTMOVF0) & RFCORE_SFR_MTMOVF0_MTMOVF0) << 16); + sfd |= ((REG(RFCORE_SFR_MTMOVF1) & RFCORE_SFR_MTMOVF1_MTMOVF1) << 24); + + return (RTIMER_NOW() - RADIO_TO_RTIMER(timer_val - sfd)); +} +/*---------------------------------------------------------------------------*/ +void mac_timer_init(void) +{ + CLOCK_STABLE(); + REG(RFCORE_SFR_MTCTRL) |= RFCORE_SFR_MTCTRL_SYNC; + REG(RFCORE_SFR_MTCTRL) |= RFCORE_SFR_MTCTRL_RUN; + while(!(REG(RFCORE_SFR_MTCTRL) & RFCORE_SFR_MTCTRL_STATE)); + REG(RFCORE_SFR_MTCTRL) &= ~RFCORE_SFR_MTCTRL_RUN; + while(REG(RFCORE_SFR_MTCTRL) & RFCORE_SFR_MTCTRL_STATE); + REG(RFCORE_SFR_MTCTRL) |= (RFCORE_SFR_MTCTRL_RUN | RFCORE_SFR_MTCTRL_SYNC); + while(!(REG(RFCORE_SFR_MTCTRL) & RFCORE_SFR_MTCTRL_STATE)); +} +/*---------------------------------------------------------------------------*/ /** @} */ From 199b1b531649b6276d07c96aaf13e4bab1f9e444 Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Wed, 23 Mar 2016 09:10:19 +0100 Subject: [PATCH 19/31] remove define for SFD interrupt not needed anymore when using MAC timer --- examples/ipv6/rpl-tsch/project-conf.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/ipv6/rpl-tsch/project-conf.h b/examples/ipv6/rpl-tsch/project-conf.h index 71a8e5425..81f7a01b6 100644 --- a/examples/ipv6/rpl-tsch/project-conf.h +++ b/examples/ipv6/rpl-tsch/project-conf.h @@ -67,10 +67,6 @@ #define TSCH_CALLBACK_JOINING_NETWORK tsch_rpl_callback_joining_network #define TSCH_CALLBACK_LEAVING_NETWORK tsch_rpl_callback_leaving_network -/* Needed for cc2538 platform only */ -/* Enable SFD timestamp (uses SFD interrupt) */ -#undef CC2538_RF_CONF_SFD_TIMESTAMPS -#define CC2538_RF_CONF_SFD_TIMESTAMPS 1 /* For TSCH we have to use the more accurate crystal oscillator * by default the RC oscillator is activated */ #undef SYS_CTRL_CONF_OSC32K_USE_XTAL From 4e446bc178c82b60ebc5fc6882f2ff52c0df6cca Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Wed, 23 Mar 2016 10:16:06 +0100 Subject: [PATCH 20/31] fix error --- cpu/cc2538/dev/cc2538-rf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu/cc2538/dev/cc2538-rf.c b/cpu/cc2538/dev/cc2538-rf.c index 0ecf7cb59..a9ea369d6 100644 --- a/cpu/cc2538/dev/cc2538-rf.c +++ b/cpu/cc2538/dev/cc2538-rf.c @@ -961,7 +961,7 @@ get_object(radio_param_t param, void *dest, size_t size) if(size != sizeof(rtimer_clock_t) || !dest) { return RADIO_RESULT_INVALID_VALUE; } - *(rtimer_clock_t*)dest = cc2538_sfd_rtime; + *(rtimer_clock_t*)dest = get_sfd_timestamp(); return RADIO_RESULT_OK; } From bc2f1b5a2ac2f83594b587d1efa6bbff2ee48206 Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Tue, 29 Mar 2016 10:24:38 +0200 Subject: [PATCH 21/31] update delay constants --- platform/cc2538dk/contiki-conf.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/platform/cc2538dk/contiki-conf.h b/platform/cc2538dk/contiki-conf.h index ae7c3275d..22891f5ba 100644 --- a/platform/cc2538dk/contiki-conf.h +++ b/platform/cc2538dk/contiki-conf.h @@ -42,9 +42,10 @@ typedef uint32_t rtimer_clock_t; /*---------------------------------------------------------------------------*/ #define TSCH_CONF_HW_FRAME_FILTERING 0 -/* TODO: measure the delays, this are only estimations */ -#define RADIO_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(300)) -#define RADIO_DELAY_BEFORE_RX ((unsigned)US_TO_RTIMERTICKS(100)) +/* 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 /*---------------------------------------------------------------------------*/ /** From 871c725144210b0d85c153e64fa6f19403aba5cd Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Thu, 31 Mar 2016 11:24:57 +0200 Subject: [PATCH 22/31] spaces instead of tabs --- core/net/mac/tsch/tsch-conf.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/net/mac/tsch/tsch-conf.h b/core/net/mac/tsch/tsch-conf.h index b23355539..43e50d7c3 100644 --- a/core/net/mac/tsch/tsch-conf.h +++ b/core/net/mac/tsch/tsch-conf.h @@ -177,9 +177,9 @@ /* HW frame filtering enabled */ #ifdef TSCH_CONF_HW_FRAME_FILTERING -#define TSCH_HW_FRAME_FILTERING TSCH_CONF_HW_FRAME_FILTERING +#define TSCH_HW_FRAME_FILTERING TSCH_CONF_HW_FRAME_FILTERING #else /* TSCH_CONF_HW_FRAME_FILTERING */ #define TSCH_HW_FRAME_FILTERING 1 -#endif +#endif /* TSCH_CONF_HW_FRAME_FILTERING */ #endif /* __TSCH_CONF_H__ */ From 2a6999921497172f94fa2237aea3d4e052857c32 Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Tue, 5 Apr 2016 17:12:48 +0200 Subject: [PATCH 23/31] space instead of tab --- core/net/mac/tsch/tsch-conf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/net/mac/tsch/tsch-conf.h b/core/net/mac/tsch/tsch-conf.h index 43e50d7c3..0cbce5913 100644 --- a/core/net/mac/tsch/tsch-conf.h +++ b/core/net/mac/tsch/tsch-conf.h @@ -179,7 +179,7 @@ #ifdef TSCH_CONF_HW_FRAME_FILTERING #define TSCH_HW_FRAME_FILTERING TSCH_CONF_HW_FRAME_FILTERING #else /* TSCH_CONF_HW_FRAME_FILTERING */ -#define TSCH_HW_FRAME_FILTERING 1 +#define TSCH_HW_FRAME_FILTERING 1 #endif /* TSCH_CONF_HW_FRAME_FILTERING */ #endif /* __TSCH_CONF_H__ */ From a7b43de535956178260c22d56eeb3046b2b920e6 Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Wed, 6 Apr 2016 16:54:45 +0200 Subject: [PATCH 24/31] add comment, use spaces --- examples/ipv6/rpl-tsch/project-conf.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/ipv6/rpl-tsch/project-conf.h b/examples/ipv6/rpl-tsch/project-conf.h index 81f7a01b6..1d3ad605d 100644 --- a/examples/ipv6/rpl-tsch/project-conf.h +++ b/examples/ipv6/rpl-tsch/project-conf.h @@ -67,18 +67,19 @@ #define TSCH_CALLBACK_JOINING_NETWORK tsch_rpl_callback_joining_network #define TSCH_CALLBACK_LEAVING_NETWORK tsch_rpl_callback_leaving_network +/* Needed for CC2538 platforms only */ /* For TSCH we have to use the more accurate crystal oscillator * by default the RC oscillator is activated */ #undef SYS_CTRL_CONF_OSC32K_USE_XTAL -#define SYS_CTRL_CONF_OSC32K_USE_XTAL 1 +#define SYS_CTRL_CONF_OSC32K_USE_XTAL 1 /* Needed for cc2420 platforms only */ /* Disable DCO calibration (uses timerB) */ #undef DCOSYNCH_CONF_ENABLED -#define DCOSYNCH_CONF_ENABLED 0 +#define DCOSYNCH_CONF_ENABLED 0 /* Enable SFD timestamps (uses timerB) */ #undef CC2420_CONF_SFD_TIMESTAMPS -#define CC2420_CONF_SFD_TIMESTAMPS 1 +#define CC2420_CONF_SFD_TIMESTAMPS 1 /*******************************************************/ /******************* Configure TSCH ********************/ From 9ac859a2af439cfea168a44c66cc25f2e198118d Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Thu, 7 Apr 2016 15:17:44 +0200 Subject: [PATCH 25/31] add send_on_cca if query --- cpu/cc2538/dev/cc2538-rf.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cpu/cc2538/dev/cc2538-rf.c b/cpu/cc2538/dev/cc2538-rf.c index a9ea369d6..3f79f2bb8 100644 --- a/cpu/cc2538/dev/cc2538-rf.c +++ b/cpu/cc2538/dev/cc2538-rf.c @@ -607,9 +607,11 @@ transmit(unsigned short transmit_len) while(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + ONOFF_TIME)); } - if(channel_clear() == CC2538_RF_CCA_BUSY) { - RIMESTATS_ADD(contentiondrop); - return RADIO_TX_COLLISION; + if(send_on_cca) { + if(channel_clear() == CC2538_RF_CCA_BUSY) { + RIMESTATS_ADD(contentiondrop); + return RADIO_TX_COLLISION; + } } /* From 5753fb5173501e1b4f1c2be440e7ad1d63a23848 Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Thu, 7 Apr 2016 15:41:15 +0200 Subject: [PATCH 26/31] Clean up the driver Move mac_timer_init() into set_poll_mode() and remove now unneccesary clear outs and mask outs of interrupt sources and pending interrupts --- cpu/cc2538/dev/cc2538-rf.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/cpu/cc2538/dev/cc2538-rf.c b/cpu/cc2538/dev/cc2538-rf.c index 3f79f2bb8..12fe9ffae 100644 --- a/cpu/cc2538/dev/cc2538-rf.c +++ b/cpu/cc2538/dev/cc2538-rf.c @@ -344,14 +344,12 @@ set_poll_mode(uint8_t enable) poll_mode = enable; if(enable) { - REG(RFCORE_XREG_RFIRQM0) &= ~RFCORE_XREG_RFIRQM0_FIFOP; // mask out FIFOP interrupt source - REG(RFCORE_SFR_RFIRQF0) &= ~RFCORE_SFR_RFIRQF0_FIFOP; // clear pending FIFOP interrupt - REG(RFCORE_XREG_RFIRQM0) &= ~RFCORE_XREG_RFIRQM0_SFD; // disable SFD interrupt source - nvic_interrupt_disable(NVIC_INT_RF_RXTX); + mac_timer_init(); + REG(RFCORE_XREG_RFIRQM0) &= ~RFCORE_XREG_RFIRQM0_FIFOP; // mask out FIFOP interrupt source + REG(RFCORE_SFR_RFIRQF0) &= ~RFCORE_SFR_RFIRQF0_FIFOP; // clear pending FIFOP interrupt + nvic_interrupt_disable(NVIC_INT_RF_RXTX); // disable RF interrupts } else { - REG(RFCORE_XREG_RFIRQM0) |= RFCORE_XREG_RFIRQM0_FIFOP; // enable FIFOP interrupt source - REG(RFCORE_XREG_RFIRQM0) &= ~RFCORE_XREG_RFIRQM0_SFD; // mask out SFD interrupt source - REG(RFCORE_SFR_RFIRQF0) &= ~RFCORE_SFR_RFIRQF0_SFD; // clear pending SFD interrupt + REG(RFCORE_XREG_RFIRQM0) |= RFCORE_XREG_RFIRQM0_FIFOP; // enable FIFOP interrupt source nvic_interrupt_enable(NVIC_INT_RF_RXTX); // enable RF interrupts } } @@ -521,8 +519,6 @@ init(void) udma_set_channel_src(CC2538_RF_CONF_RX_DMA_CHAN, RFCORE_SFR_RFDATA); } - mac_timer_init(); - set_poll_mode(poll_mode); process_start(&cc2538_rf_process, NULL); From 3bf05d664e77b6e6e43b3f7bd34e3b1f4d3fc715 Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Fri, 15 Apr 2016 15:50:01 +0200 Subject: [PATCH 27/31] moving macros to .c --- cpu/cc2538/dev/cc2538-rf.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/cpu/cc2538/dev/cc2538-rf.h b/cpu/cc2538/dev/cc2538-rf.h index 287147a92..5edb478ba 100644 --- a/cpu/cc2538/dev/cc2538-rf.h +++ b/cpu/cc2538/dev/cc2538-rf.h @@ -129,15 +129,6 @@ REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHTX; \ REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHTX; \ } while(0) -/*--------------------------------------------------------------------------- - * MAC timer - *---------------------------------------------------------------------------*/ -/* Timer conversion */ -#define RADIO_TO_RTIMER(X) ((X) * RTIMER_ARCH_SECOND / SYS_CTRL_32MHZ) - -#define CLOCK_STABLE() do { \ - while ( !(REG(SYS_CTRL_CLOCK_STA) & (SYS_CTRL_CLOCK_STA_XOSC_STB))); \ - } while(0) /*---------------------------------------------------------------------------*/ /** The NETSTACK data structure for the cc2538 RF driver */ extern const struct radio_driver cc2538_rf_driver; From 6262025ef3befe7afc0b653444c3d7276d6c5aaa Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Fri, 15 Apr 2016 15:50:20 +0200 Subject: [PATCH 28/31] code style fixes and insert macros from .h --- cpu/cc2538/dev/cc2538-rf.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cpu/cc2538/dev/cc2538-rf.c b/cpu/cc2538/dev/cc2538-rf.c index 12fe9ffae..652480a9e 100644 --- a/cpu/cc2538/dev/cc2538-rf.c +++ b/cpu/cc2538/dev/cc2538-rf.c @@ -119,6 +119,15 @@ static const uint8_t magic[] = { 0x53, 0x6E, 0x69, 0x66 }; /** Snif */ #else #define CC2538_RF_AUTOACK 1 #endif +/*--------------------------------------------------------------------------- + * MAC timer + *---------------------------------------------------------------------------*/ +/* Timer conversion */ +#define RADIO_TO_RTIMER(X) ((X) * RTIMER_ARCH_SECOND / SYS_CTRL_32MHZ) + +#define CLOCK_STABLE() do { \ + while ( !(REG(SYS_CTRL_CLOCK_STA) & (SYS_CTRL_CLOCK_STA_XOSC_STB))); \ + } while(0) /*---------------------------------------------------------------------------*/ /* Are we currently in poll mode? Disabled by default */ static uint8_t volatile poll_mode = 0; @@ -427,7 +436,7 @@ off(void) /* Wait for ongoing TX to complete (e.g. this could be an outgoing ACK) */ while(REG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_TX_ACTIVE); - if (!(REG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_FIFOP)) { + if(!(REG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_FIFOP)) { CC2538_RF_CSP_ISFLUSHRX(); } @@ -1071,7 +1080,7 @@ cc2538_rf_rx_tx_isr(void) process_poll(&cc2538_rf_process); } - /* We only acknowledge FIFOP or SFD so we can safely wipe out the entire SFR */ + /* We only acknowledge FIFOP so we can safely wipe out the entire SFR */ REG(RFCORE_SFR_RFIRQF0) = 0; ENERGEST_OFF(ENERGEST_TYPE_IRQ); @@ -1149,7 +1158,8 @@ void mac_timer_init(void) while(!(REG(RFCORE_SFR_MTCTRL) & RFCORE_SFR_MTCTRL_STATE)); REG(RFCORE_SFR_MTCTRL) &= ~RFCORE_SFR_MTCTRL_RUN; while(REG(RFCORE_SFR_MTCTRL) & RFCORE_SFR_MTCTRL_STATE); - REG(RFCORE_SFR_MTCTRL) |= (RFCORE_SFR_MTCTRL_RUN | RFCORE_SFR_MTCTRL_SYNC); + REG(RFCORE_SFR_MTCTRL) |= RFCORE_SFR_MTCTRL_SYNC; + REG(RFCORE_SFR_MTCTRL) |= (RFCORE_SFR_MTCTRL_RUN); while(!(REG(RFCORE_SFR_MTCTRL) & RFCORE_SFR_MTCTRL_STATE)); } /*---------------------------------------------------------------------------*/ From 3a76207b5958d34c587ee83b7a46d54cf7cd4a3e Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Mon, 18 Apr 2016 11:40:52 +0200 Subject: [PATCH 29/31] Use 64 bit values for MAC timer --- cpu/cc2538/dev/cc2538-rf.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cpu/cc2538/dev/cc2538-rf.c b/cpu/cc2538/dev/cc2538-rf.c index 652480a9e..52708e0ca 100644 --- a/cpu/cc2538/dev/cc2538-rf.c +++ b/cpu/cc2538/dev/cc2538-rf.c @@ -123,7 +123,7 @@ static const uint8_t magic[] = { 0x53, 0x6E, 0x69, 0x66 }; /** Snif */ * MAC timer *---------------------------------------------------------------------------*/ /* Timer conversion */ -#define RADIO_TO_RTIMER(X) ((X) * RTIMER_ARCH_SECOND / SYS_CTRL_32MHZ) +#define RADIO_TO_RTIMER(X) ((uint32_t)((uint64_t)(X) * RTIMER_ARCH_SECOND / SYS_CTRL_32MHZ)) #define CLOCK_STABLE() do { \ while ( !(REG(SYS_CTRL_CLOCK_STA) & (SYS_CTRL_CLOCK_STA_XOSC_STB))); \ @@ -1129,7 +1129,7 @@ cc2538_rf_set_promiscous_mode(char p) /*---------------------------------------------------------------------------*/ uint32_t get_sfd_timestamp(void) { - uint32_t sfd, timer_val; + uint64_t sfd, timer_val, buffer; REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMSEL) | 0x00000000; REG(RFCORE_SFR_MTCTRL) |= RFCORE_SFR_MTCTRL_LATCH_MODE; @@ -1138,6 +1138,8 @@ uint32_t get_sfd_timestamp(void) REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMOVFSEL) | 0x00000000; timer_val |= ((REG(RFCORE_SFR_MTMOVF0) & RFCORE_SFR_MTMOVF0_MTMOVF0) << 16); timer_val |= ((REG(RFCORE_SFR_MTMOVF1) & RFCORE_SFR_MTMOVF1_MTMOVF1) << 24); + buffer = REG(RFCORE_SFR_MTMOVF2) & RFCORE_SFR_MTMOVF2_MTMOVF2; + timer_val |= (buffer << 32); REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMSEL) | 0x00000001; REG(RFCORE_SFR_MTCTRL) |= RFCORE_SFR_MTCTRL_LATCH_MODE; @@ -1146,6 +1148,8 @@ uint32_t get_sfd_timestamp(void) REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMOVFSEL) | 0x00000010; sfd |= ((REG(RFCORE_SFR_MTMOVF0) & RFCORE_SFR_MTMOVF0_MTMOVF0) << 16); sfd |= ((REG(RFCORE_SFR_MTMOVF1) & RFCORE_SFR_MTMOVF1_MTMOVF1) << 24); + buffer = REG(RFCORE_SFR_MTMOVF2) & RFCORE_SFR_MTMOVF2_MTMOVF2; + sfd |= (buffer << 32); return (RTIMER_NOW() - RADIO_TO_RTIMER(timer_val - sfd)); } From e537a2ea92e3097bc971bda4452d4ab75c8ce024 Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Wed, 1 Jun 2016 16:01:58 +0200 Subject: [PATCH 30/31] Add CC2538DK --- core/net/mac/tsch/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/net/mac/tsch/README.md b/core/net/mac/tsch/README.md index ffd6dc789..dea59dedc 100644 --- a/core/net/mac/tsch/README.md +++ b/core/net/mac/tsch/README.md @@ -36,6 +36,7 @@ It has been tested on the following platforms: * NXP JN516x (`jn516x`, tested on hardware) * Tmote Sky (`sky`, tested on hardware and in cooja) * Zolertia Z1 (`z1`, tested in cooja only) + * CC2538DK (`cc2538dk`, tested on hardware) This implementation was present at the ETSI Plugtest event in Prague in July 2015, and did successfully inter-operate with all @@ -76,7 +77,7 @@ Orchestra is implemented in: A simple TSCH+RPL example is included under `examples/ipv6/rpl-tsch`. To use TSCH, first make sure your platform supports it. -Currently, `jn516x`, `sky` and `z1` are the supported platforms. +Currently, `jn516x`, `sky`, `z1` and `cc2538dk` are the supported platforms. To add your own, we refer the reader to the next section. To add TSCH to your application, first include the TSCH module from your makefile with: From 8a7b1f07d19e202d24b2703d072d321348d4665c Mon Sep 17 00:00:00 2001 From: thomas-ha Date: Wed, 1 Jun 2016 17:58:57 +0200 Subject: [PATCH 31/31] add cc2538dk --- core/net/mac/tsch/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/net/mac/tsch/README.md b/core/net/mac/tsch/README.md index dea59dedc..fd512a896 100644 --- a/core/net/mac/tsch/README.md +++ b/core/net/mac/tsch/README.md @@ -163,7 +163,7 @@ Finally, one can also implement his own scheduler, centralized or distributed, b ## Porting TSCH to a new platform Porting TSCH to a new platform requires a few new features in the radio driver, a number of timing-related configuration paramters. -The easiest is probably to start from one of the existing port: `jn516x`, `sky`, `z1`. +The easiest is probably to start from one of the existing port: `jn516x`, `sky`, `z1`, `cc2538dk`. ### Radio features required for TSCH