From f6967c1f58abde06dd5e5d44d36e69c3041498c0 Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Mon, 25 Apr 2016 17:41:56 +0300 Subject: [PATCH] read RADIO_PARAM_LAST_RSSI and RADIO_PARAM_LAST_PACKET_TIMESTAMP only after the last packet has been read in TSCH: reading the packet might update these values --- core/net/mac/tsch/tsch-slot-operation.c | 12 ++++++------ core/net/mac/tsch/tsch.c | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/net/mac/tsch/tsch-slot-operation.c b/core/net/mac/tsch/tsch-slot-operation.c index 54f1b7e65..9f51210a7 100644 --- a/core/net/mac/tsch/tsch-slot-operation.c +++ b/core/net/mac/tsch/tsch-slot-operation.c @@ -769,20 +769,15 @@ PT_THREAD(tsch_rx_slot(struct pt *pt, struct rtimer *t)) TSCH_DEBUG_RX_EVENT(); tsch_radio_off(TSCH_RADIO_CMD_OFF_WITHIN_TIMESLOT); -#if TSCH_RESYNC_WITH_SFD_TIMESTAMPS - /* At the end of the reception, get an more accurate estimate of SFD arrival time */ - NETSTACK_RADIO.get_object(RADIO_PARAM_LAST_PACKET_TIMESTAMP, &rx_start_time, sizeof(rtimer_clock_t)); -#endif - if(NETSTACK_RADIO.pending_packet()) { static int frame_valid; static int header_len; static frame802154_t frame; radio_value_t radio_last_rssi; - NETSTACK_RADIO.get_value(RADIO_PARAM_LAST_RSSI, &radio_last_rssi); /* Read packet */ current_input->len = NETSTACK_RADIO.read((void *)current_input->payload, TSCH_PACKET_MAX_LEN); + NETSTACK_RADIO.get_value(RADIO_PARAM_LAST_RSSI, &radio_last_rssi); current_input->rx_asn = current_asn; current_input->rssi = (signed)radio_last_rssi; header_len = frame802154_parse((uint8_t *)current_input->payload, current_input->len, &frame); @@ -790,6 +785,11 @@ PT_THREAD(tsch_rx_slot(struct pt *pt, struct rtimer *t)) frame802154_check_dest_panid(&frame) && frame802154_extract_linkaddr(&frame, &source_address, &destination_address); +#if TSCH_RESYNC_WITH_SFD_TIMESTAMPS + /* At the end of the reception, get an more accurate estimate of SFD arrival time */ + NETSTACK_RADIO.get_object(RADIO_PARAM_LAST_PACKET_TIMESTAMP, &rx_start_time, sizeof(rtimer_clock_t)); +#endif + packet_duration = TSCH_PACKET_DURATION(current_input->len); #if LLSEC802154_ENABLED diff --git a/core/net/mac/tsch/tsch.c b/core/net/mac/tsch/tsch.c index 2085f39ff..de6619dc5 100644 --- a/core/net/mac/tsch/tsch.c +++ b/core/net/mac/tsch/tsch.c @@ -649,12 +649,12 @@ PT_THREAD(tsch_scan(struct pt *pt)) } if(is_packet_pending) { - /* Save packet timestamp */ - NETSTACK_RADIO.get_object(RADIO_PARAM_LAST_PACKET_TIMESTAMP, &t0, sizeof(rtimer_clock_t)); - /* Read packet */ input_eb.len = NETSTACK_RADIO.read(input_eb.payload, TSCH_PACKET_MAX_LEN); + /* Save packet timestamp */ + NETSTACK_RADIO.get_object(RADIO_PARAM_LAST_PACKET_TIMESTAMP, &t0, sizeof(rtimer_clock_t)); + /* Parse EB and attempt to associate */ PRINTF("TSCH: association: received packet (%u bytes) on channel %u\n", input_eb.len, current_channel);