59 #ifndef TSCH_DEBUG_INIT 60 #define TSCH_DEBUG_INIT() 62 #ifndef TSCH_DEBUG_INTERRUPT 63 #define TSCH_DEBUG_INTERRUPT() 65 #ifndef TSCH_DEBUG_RX_EVENT 66 #define TSCH_DEBUG_RX_EVENT() 68 #ifndef TSCH_DEBUG_TX_EVENT 69 #define TSCH_DEBUG_TX_EVENT() 71 #ifndef TSCH_DEBUG_SLOT_START 72 #define TSCH_DEBUG_SLOT_START() 74 #ifndef TSCH_DEBUG_SLOT_END 75 #define TSCH_DEBUG_SLOT_END() 79 #if (TSCH_MAX_INCOMING_PACKETS & (TSCH_MAX_INCOMING_PACKETS - 1)) != 0 80 #error TSCH_MAX_INCOMING_PACKETS must be power of two 84 #if TSCH_DEQUEUED_ARRAY_SIZE < QUEUEBUF_NUM 85 #error TSCH_DEQUEUED_ARRAY_SIZE must be greater or equal to QUEUEBUF_NUM 87 #if (TSCH_DEQUEUED_ARRAY_SIZE & (TSCH_DEQUEUED_ARRAY_SIZE - 1)) != 0 88 #error TSCH_DEQUEUED_ARRAY_SIZE must be power of two 93 #define SYNC_IE_BOUND ((int32_t)US_TO_RTIMERTICKS(tsch_timing_us[tsch_ts_rx_wait] / 4)) 96 #if RTIMER_SECOND < (32 * 1024) 97 #error "TSCH: RTIMER_SECOND < (32 * 1024)" 99 #if CONTIKI_TARGET_COOJA 101 #define RTIMER_GUARD 0u 102 #elif RTIMER_SECOND >= 200000 103 #define RTIMER_GUARD (RTIMER_SECOND / 100000) 105 #define RTIMER_GUARD 2u 108 enum tsch_radio_state_on_cmd {
109 TSCH_RADIO_CMD_ON_START_OF_TIMESLOT,
110 TSCH_RADIO_CMD_ON_WITHIN_TIMESLOT,
111 TSCH_RADIO_CMD_ON_FORCE,
114 enum tsch_radio_state_off_cmd {
115 TSCH_RADIO_CMD_OFF_END_OF_TIMESLOT,
116 TSCH_RADIO_CMD_OFF_WITHIN_TIMESLOT,
117 TSCH_RADIO_CMD_OFF_FORCE,
122 struct ringbufindex dequeued_ringbuf;
123 struct tsch_packet *dequeued_array[TSCH_DEQUEUED_ARRAY_SIZE];
126 struct ringbufindex input_ringbuf;
127 struct input_packet input_array[TSCH_MAX_INCOMING_PACKETS];
131 clock_time_t last_sync_time;
134 static volatile int tsch_locked = 0;
136 static volatile int tsch_lock_requested = 0;
140 static int32_t drift_correction = 0;
142 static uint8_t is_drift_correction_used;
148 static rtimer_clock_t
volatile current_slot_start;
151 static volatile int tsch_in_slot_operation = 0;
154 uint8_t tsch_current_channel;
162 static struct tsch_link *backup_link = NULL;
167 static int burst_link_scheduled = 0;
169 int tsch_current_burst_count = 0;
176 static struct pt slot_operation_pt;
196 rtimer_clock_t busy_wait_time;
199 tsch_lock_requested = 1;
201 if(tsch_in_slot_operation) {
204 while(tsch_in_slot_operation) {
207 busy_wait_time =
RTIMER_NOW() - busy_wait_time;
212 tsch_lock_requested = 0;
216 snprintf(log->message,
sizeof(log->message),
217 "!get lock delay %u", (
unsigned)busy_wait_time);
224 snprintf(log->message,
sizeof(log->message),
244 uint16_t index_of_0 =
TSCH_ASN_MOD(*asn, tsch_hopping_sequence_length);
245 uint16_t index_of_offset = (index_of_0 + channel_offset) % tsch_hopping_sequence_length.val;
246 return tsch_hopping_sequence[index_of_offset];
255 check_timer_miss(rtimer_clock_t ref_time, rtimer_clock_t offset, rtimer_clock_t now)
257 rtimer_clock_t target = ref_time + offset;
258 int now_has_overflowed = now < ref_time;
259 int target_has_overflowed = target < ref_time;
261 if(now_has_overflowed == target_has_overflowed) {
263 return target <= now;
269 return now_has_overflowed;
277 tsch_schedule_slot_operation(
struct rtimer *tm, rtimer_clock_t ref_time, rtimer_clock_t offset,
const char *str)
283 int missed = check_timer_miss(ref_time, offset - RTIMER_GUARD, now);
287 snprintf(log->message,
sizeof(log->message),
289 str, (
int)(now-ref_time), (
int)offset);
292 r =
rtimer_set(tm, ref_time + offset, 1, (
void (*)(
struct rtimer *,
void *))tsch_slot_operation, NULL);
306 #define TSCH_SCHEDULE_AND_YIELD(pt, tm, ref_time, offset, str) \ 308 if(tsch_schedule_slot_operation(tm, ref_time, offset - RTIMER_GUARD, str)) { \ 310 RTIMER_BUSYWAIT_UNTIL_ABS(0, ref_time, offset); \ 322 if(link->link_options & LINK_OPTION_TX) {
324 if(link->link_type == LINK_TYPE_ADVERTISING || link->link_type == LINK_TYPE_ADVERTISING_ONLY) {
329 if(link->link_type != LINK_TYPE_ADVERTISING_ONLY) {
336 if(p == NULL && n == n_broadcast) {
343 if(target_neighbor != NULL) {
344 *target_neighbor = n;
362 case TSCH_RADIO_CMD_ON_START_OF_TIMESLOT:
363 if(TSCH_RADIO_ON_DURING_TIMESLOT) {
367 case TSCH_RADIO_CMD_ON_WITHIN_TIMESLOT:
368 if(!TSCH_RADIO_ON_DURING_TIMESLOT) {
372 case TSCH_RADIO_CMD_ON_FORCE:
393 case TSCH_RADIO_CMD_OFF_END_OF_TIMESLOT:
394 if(TSCH_RADIO_ON_DURING_TIMESLOT) {
398 case TSCH_RADIO_CMD_OFF_WITHIN_TIMESLOT:
399 if(!TSCH_RADIO_ON_DURING_TIMESLOT) {
403 case TSCH_RADIO_CMD_OFF_FORCE:
408 NETSTACK_RADIO.off();
427 static uint8_t mac_tx_status;
430 static int dequeued_index;
431 static int packet_ready = 1;
435 TSCH_DEBUG_TX_EVENT();
440 if(dequeued_index != -1) {
441 if(current_packet == NULL || current_packet->qb == NULL) {
442 mac_tx_status = MAC_TX_ERR_FATAL;
446 #if LLSEC802154_ENABLED 448 static uint8_t encrypted_packet[TSCH_PACKET_MAX_LEN];
451 static uint8_t packet_len;
453 static uint8_t seqno;
455 static uint8_t is_broadcast;
456 static rtimer_clock_t tx_start_time;
458 static int burst_link_requested;
461 static uint8_t cca_status;
465 packet = queuebuf_dataptr(current_packet->qb);
466 packet_len = queuebuf_datalen(current_packet->qb);
468 is_broadcast = current_neighbor->is_broadcast;
470 burst_link_requested = 0;
472 && tsch_current_burst_count + 1 < TSCH_BURST_MAX_LEN
474 burst_link_requested = 1;
478 seqno = ((uint8_t *)(packet))[2];
480 if(current_neighbor == n_eb) {
486 #if LLSEC802154_ENABLED 487 if(tsch_is_pan_secured) {
490 int with_encryption = queuebuf_attr(current_packet->qb, PACKETBUF_ATTR_SECURITY_LEVEL) & 0x4;
492 packet_len - current_packet->header_len, &tsch_current_asn);
493 if(with_encryption) {
494 packet = encrypted_packet;
500 if(packet_ready && NETSTACK_RADIO.prepare(packet, packet_len) == 0) {
501 static rtimer_clock_t tx_duration;
506 TSCH_SCHEDULE_AND_YIELD(pt, t, current_slot_start, tsch_timing[tsch_ts_cca_offset],
"cca");
507 TSCH_DEBUG_TX_EVENT();
511 current_slot_start, tsch_timing[tsch_ts_cca_offset] + tsch_timing[tsch_ts_cca]);
512 TSCH_DEBUG_TX_EVENT();
515 if(cca_status == 0) {
521 TSCH_SCHEDULE_AND_YIELD(pt, t, current_slot_start, tsch_timing[tsch_ts_tx_offset] - RADIO_DELAY_BEFORE_TX,
"TxBeforeTx");
522 TSCH_DEBUG_TX_EVENT();
524 mac_tx_status = NETSTACK_RADIO.transmit(packet_len);
527 tx_start_time = current_slot_start + tsch_timing[tsch_ts_tx_offset];
529 tx_duration = TSCH_PACKET_DURATION(packet_len);
531 tx_duration = MIN(tx_duration, tsch_timing[tsch_ts_max_tx]);
535 if(mac_tx_status == RADIO_TX_OK) {
537 uint8_t ackbuf[TSCH_PACKET_MAX_LEN];
539 rtimer_clock_t ack_start_time;
541 struct ieee802154_ies ack_ies;
545 #if TSCH_HW_FRAME_FILTERING 548 NETSTACK_RADIO.get_value(RADIO_PARAM_RX_MODE, &radio_rx_mode);
552 TSCH_SCHEDULE_AND_YIELD(pt, t, current_slot_start,
553 tsch_timing[tsch_ts_tx_offset] + tx_duration + tsch_timing[tsch_ts_rx_ack_delay] - RADIO_DELAY_BEFORE_RX,
"TxBeforeAck");
554 TSCH_DEBUG_TX_EVENT();
558 tx_start_time, tx_duration + tsch_timing[tsch_ts_rx_ack_delay] + tsch_timing[tsch_ts_ack_wait] + RADIO_DELAY_BEFORE_DETECT);
559 TSCH_DEBUG_TX_EVENT();
561 ack_start_time =
RTIMER_NOW() - RADIO_DELAY_BEFORE_DETECT;
565 ack_start_time, tsch_timing[tsch_ts_max_ack]);
566 TSCH_DEBUG_TX_EVENT();
569 #if TSCH_HW_FRAME_FILTERING 571 NETSTACK_RADIO.get_value(RADIO_PARAM_RX_MODE, &radio_rx_mode);
576 ack_len = NETSTACK_RADIO.read((
void *)ackbuf,
sizeof(ackbuf));
581 is_time_source = current_neighbor != NULL && current_neighbor->is_time_source;
583 &frame, &ack_ies, &ack_hdrlen) == 0) {
587 #if LLSEC802154_ENABLED 590 &frame, ¤t_neighbor->addr, &tsch_current_asn)) {
592 snprintf(log->message,
sizeof(log->message),
593 "!failed to authenticate ACK"));
598 snprintf(log->message,
sizeof(log->message),
599 "!failed to parse ACK"));
606 int32_t eack_time_correction = US_TO_RTIMERTICKS(ack_ies.ie_time_correction);
607 int32_t since_last_timesync =
TSCH_ASN_DIFF(tsch_current_asn, last_sync_asn);
608 if(eack_time_correction > SYNC_IE_BOUND) {
609 drift_correction = SYNC_IE_BOUND;
610 }
else if(eack_time_correction < -SYNC_IE_BOUND) {
611 drift_correction = -SYNC_IE_BOUND;
613 drift_correction = eack_time_correction;
615 if(drift_correction != eack_time_correction) {
617 snprintf(log->message,
sizeof(log->message),
618 "!truncated dr %d %d", (
int)eack_time_correction, (
int)drift_correction);
621 tsch_stats_on_time_synchronization(eack_time_correction);
622 is_drift_correction_used = 1;
625 last_sync_asn = tsch_current_asn;
633 if(burst_link_requested) {
634 burst_link_scheduled = 1;
653 current_packet->transmissions++;
654 current_packet->ret = mac_tx_status;
661 dequeued_array[dequeued_index] = current_packet;
666 if(current_neighbor != NULL && current_neighbor->is_time_source) {
667 tsch_stats_tx_packet(current_neighbor, mac_tx_status, tsch_current_channel);
672 log->tx.mac_tx_status = mac_tx_status;
673 log->tx.num_tx = current_packet->transmissions;
674 log->tx.datalen = queuebuf_datalen(current_packet->qb);
675 log->tx.drift = drift_correction;
676 log->tx.drift_used = is_drift_correction_used;
677 log->tx.is_data = ((((uint8_t *)(queuebuf_dataptr(current_packet->qb)))[0]) & 7) == FRAME802154_DATAFRAME;
678 #
if LLSEC802154_ENABLED
679 log->tx.sec_level = queuebuf_attr(current_packet->qb, PACKETBUF_ATTR_SECURITY_LEVEL);
681 log->tx.sec_level = 0;
683 linkaddr_copy(&log->tx.dest, queuebuf_addr(current_packet->qb, PACKETBUF_ADDR_RECEIVER));
684 log->tx.seqno = queuebuf_attr(current_packet->qb, PACKETBUF_ATTR_MAC_SEQNO);
691 TSCH_DEBUG_TX_EVENT();
709 static linkaddr_t source_address;
710 static linkaddr_t destination_address;
711 static int16_t input_index;
712 static int input_queue_drop = 0;
716 TSCH_DEBUG_RX_EVENT();
719 if(input_index == -1) {
724 static int32_t estimated_drift;
726 static rtimer_clock_t rx_start_time;
727 static rtimer_clock_t expected_rx_time;
728 static rtimer_clock_t packet_duration;
731 expected_rx_time = current_slot_start + tsch_timing[tsch_ts_tx_offset];
733 rx_start_time = expected_rx_time;
735 current_input = &input_array[input_index];
738 TSCH_SCHEDULE_AND_YIELD(pt, t, current_slot_start, tsch_timing[tsch_ts_rx_offset] - RADIO_DELAY_BEFORE_RX,
"RxBeforeListen");
739 TSCH_DEBUG_RX_EVENT();
743 packet_seen = NETSTACK_RADIO.receiving_packet() || NETSTACK_RADIO.pending_packet();
747 current_slot_start, tsch_timing[tsch_ts_rx_offset] + tsch_timing[tsch_ts_rx_wait] + RADIO_DELAY_BEFORE_DETECT);
753 TSCH_DEBUG_RX_EVENT();
755 rx_start_time =
RTIMER_NOW() - RADIO_DELAY_BEFORE_DETECT;
759 current_slot_start, tsch_timing[tsch_ts_rx_offset] + tsch_timing[tsch_ts_rx_wait] + tsch_timing[tsch_ts_max_tx]);
760 TSCH_DEBUG_RX_EVENT();
763 if(NETSTACK_RADIO.pending_packet()) {
764 static int frame_valid;
765 static int header_len;
771 current_input->len = NETSTACK_RADIO.read((
void *)current_input->payload, TSCH_PACKET_MAX_LEN);
772 NETSTACK_RADIO.get_value(RADIO_PARAM_LAST_RSSI, &radio_last_rssi);
773 current_input->rx_asn = tsch_current_asn;
774 current_input->rssi = (signed)radio_last_rssi;
775 current_input->channel = tsch_current_channel;
776 header_len =
frame802154_parse((uint8_t *)current_input->payload, current_input->len, &frame);
777 frame_valid = header_len > 0 &&
778 frame802154_check_dest_panid(&frame) &&
779 frame802154_extract_linkaddr(&frame, &source_address, &destination_address);
781 #if TSCH_RESYNC_WITH_SFD_TIMESTAMPS 783 NETSTACK_RADIO.get_object(RADIO_PARAM_LAST_PACKET_TIMESTAMP, &rx_start_time,
sizeof(rtimer_clock_t));
786 packet_duration = TSCH_PACKET_DURATION(current_input->len);
788 packet_duration = MIN(packet_duration, tsch_timing[tsch_ts_max_tx]);
792 snprintf(log->message,
sizeof(log->message),
793 "!failed to parse frame %u %u", header_len, current_input->len));
800 snprintf(log->message,
sizeof(log->message),
801 "!discarding frame with type %u, len %u", frame.
fcf.
frame_type, current_input->len));
806 #if LLSEC802154_ENABLED 811 &frame, &source_address, &tsch_current_asn)) {
815 snprintf(log->message,
sizeof(log->message),
816 "!failed to authenticate frame %u", current_input->len));
827 estimated_drift = RTIMER_CLOCK_DIFF(expected_rx_time, rx_start_time);
828 tsch_stats_on_time_synchronization(estimated_drift);
830 #if TSCH_TIMESYNC_REMOVE_JITTER 832 if(ABS(estimated_drift) <= TSCH_TIMESYNC_MEASUREMENT_ERROR) {
834 }
else if(estimated_drift > 0) {
835 estimated_drift -= TSCH_TIMESYNC_MEASUREMENT_ERROR;
837 estimated_drift += TSCH_TIMESYNC_MEASUREMENT_ERROR;
841 #ifdef TSCH_CALLBACK_DO_NACK 843 do_nack = TSCH_CALLBACK_DO_NACK(current_link,
844 &source_address, &destination_address);
849 static uint8_t ack_buf[TSCH_PACKET_MAX_LEN];
854 &source_address, frame.
seq, (int16_t)RTIMERTICKS_TO_US(estimated_drift), do_nack);
857 #if LLSEC802154_ENABLED 858 if(tsch_is_pan_secured) {
865 NETSTACK_RADIO.prepare((
const void *)ack_buf, ack_len);
868 TSCH_SCHEDULE_AND_YIELD(pt, t, rx_start_time,
869 packet_duration + tsch_timing[tsch_ts_tx_ack_delay] - RADIO_DELAY_BEFORE_TX,
"RxBeforeAck");
870 TSCH_DEBUG_RX_EVENT();
871 NETSTACK_RADIO.transmit(ack_len);
881 if(n != NULL && n->is_time_source) {
882 int32_t since_last_timesync =
TSCH_ASN_DIFF(tsch_current_asn, last_sync_asn);
884 last_sync_asn = tsch_current_asn;
887 drift_correction = -estimated_drift;
888 is_drift_correction_used = 1;
899 NETSTACK_RADIO.get_value(RADIO_PARAM_LAST_LINK_QUALITY, &radio_last_lqi);
900 tsch_stats_rx_packet(n, current_input->rssi, radio_last_lqi, tsch_current_channel);
907 log->rx.datalen = current_input->len;
908 log->rx.drift = drift_correction;
909 log->rx.drift_used = is_drift_correction_used;
910 log->rx.is_data = frame.
fcf.
frame_type == FRAME802154_DATAFRAME;
912 log->rx.estimated_drift = estimated_drift;
913 log->rx.seqno = frame.
seq;
925 if(input_queue_drop != 0) {
927 snprintf(log->message,
sizeof(log->message),
928 "!queue full skipped %u", input_queue_drop);
930 input_queue_drop = 0;
934 TSCH_DEBUG_RX_EVENT();
944 TSCH_DEBUG_INTERRUPT();
948 while(tsch_is_associated) {
950 if(current_link == NULL || tsch_lock_requested) {
954 snprintf(log->message,
sizeof(log->message),
955 "!skipped slot %u %u %u",
958 current_link == NULL);
963 TSCH_DEBUG_SLOT_START();
964 tsch_in_slot_operation = 1;
966 tsch_stats_sample_rssi();
968 drift_correction = 0;
969 is_drift_correction_used = 0;
971 current_packet = get_packet_and_neighbor_for_link(current_link, ¤t_neighbor);
974 if(current_packet == NULL && !(current_link->link_options & LINK_OPTION_RX) && backup_link != NULL) {
975 current_link = backup_link;
976 current_packet = get_packet_and_neighbor_for_link(current_link, ¤t_neighbor);
978 is_active_slot = current_packet != NULL || (current_link->link_options & LINK_OPTION_RX);
982 if(burst_link_scheduled) {
984 burst_link_scheduled = 0;
989 NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, tsch_current_channel);
994 if(current_packet != NULL) {
1000 static struct pt slot_tx_pt;
1001 PT_SPAWN(&slot_operation_pt, &slot_tx_pt, tsch_tx_slot(&slot_tx_pt, t));
1004 static struct pt slot_rx_pt;
1005 PT_SPAWN(&slot_operation_pt, &slot_rx_pt, tsch_rx_slot(&slot_rx_pt, t));
1010 burst_link_scheduled = 0;
1012 TSCH_DEBUG_SLOT_END();
1018 if(!tsch_is_coordinator && (
TSCH_ASN_DIFF(tsch_current_asn, last_sync_asn) >
1019 (100 * TSCH_CLOCK_TO_SLOTS(TSCH_DESYNC_THRESHOLD / 100, tsch_timing[tsch_ts_timeslot_length])))) {
1021 snprintf(log->message,
sizeof(log->message),
1022 "! leaving the network, last sync %u",
1025 last_timesource_neighbor = NULL;
1030 uint16_t timeslot_diff = 0;
1031 rtimer_clock_t prev_slot_start;
1033 rtimer_clock_t time_to_next_active_slot;
1036 if(current_link != NULL
1037 && current_link->link_options & LINK_OPTION_TX
1038 && current_link->link_options & LINK_OPTION_SHARED) {
1046 if(burst_link_scheduled) {
1050 tsch_current_burst_count++;
1054 if(current_link == NULL) {
1061 tsch_current_burst_count = 0;
1068 time_to_next_active_slot = timeslot_diff * tsch_timing[tsch_ts_timeslot_length] + drift_correction;
1070 drift_correction = 0;
1071 is_drift_correction_used = 0;
1073 prev_slot_start = current_slot_start;
1074 current_slot_start += time_to_next_active_slot;
1075 }
while(!tsch_schedule_slot_operation(t, prev_slot_start, time_to_next_active_slot,
"main"));
1078 tsch_in_slot_operation = 0;
1082 PT_END(&slot_operation_pt);
1090 static struct rtimer slot_operation_timer;
1091 rtimer_clock_t time_to_next_active_slot;
1092 rtimer_clock_t prev_slot_start;
1095 uint16_t timeslot_diff;
1098 if(current_link == NULL) {
1106 time_to_next_active_slot = timeslot_diff * tsch_timing[tsch_ts_timeslot_length];
1108 prev_slot_start = current_slot_start;
1109 current_slot_start += time_to_next_active_slot;
1110 }
while(!tsch_schedule_slot_operation(&slot_operation_timer, prev_slot_start, time_to_next_active_slot,
"assoc"));
1118 current_slot_start = next_slot_start;
1119 tsch_current_asn = *next_slot_asn;
1120 last_sync_asn = tsch_current_asn;
1122 current_link = NULL;
#define TSCH_LOG_ADD(log_type, init_code)
Use this macro to add a log to the queue (will be printed out later, after leaving interrupt context)...
frame802154_scf_t security_control
Security control bitfield.
struct tsch_neighbor * tsch_queue_get_nbr(const linkaddr_t *addr)
Get a TSCH neighbor.
static void tsch_radio_off(enum tsch_radio_state_off_cmd command)
This function turns off the radio.
int rtimer_set(struct rtimer *rtimer, rtimer_clock_t time, rtimer_clock_t duration, rtimer_callback_t func, void *ptr)
Post a real-time task.
frame802154_fcf_t fcf
Frame control field.
Representation of a real-time task.
struct tsch_neighbor * last_timesource_neighbor
The neighbor last used as our time source.
The MAC layer transmission could not be performed because of a fatal error.
int tsch_get_lock(void)
Takes the TSCH lock.
Header file for the radio API
uint8_t security_level
3 bit.
void tsch_release_lock(void)
Releases the TSCH lock.
int frame802154_parse(uint8_t *data, int len, frame802154_t *pf)
Parses an input frame.
TSCH neighbor information.
void tsch_queue_update_all_backoff_windows(const linkaddr_t *dest_addr)
Decrement backoff window for the queue(s) able to Tx to a given address.
unsigned int tsch_security_parse_frame(const uint8_t *hdr, int hdrlen, int datalen, const frame802154_t *frame, const linkaddr_t *sender, struct tsch_asn_t *asn)
Parse and check a frame protected with encryption and/or MIC.
#define PT_BEGIN(pt)
Declare the start of a protothread inside the C function implementing the protothread.
void tsch_timesync_update(struct tsch_neighbor *n, uint16_t time_delta_asn, int32_t drift_correction)
Updates timesync information for a given neighbor.
int radio_value_t
Each radio has a set of parameters that designate the current configuration and state of the radio...
uint8_t src_addr[8]
Source address.
void tsch_schedule_keepalive(void)
Schedule a keep-alive transmission within [timeout*0.9, timeout[.
A MAC framer for IEEE 802.15.4
const linkaddr_t linkaddr_null
The null link-layer address.
#define PT_SPAWN(pt, child, thread)
Spawn a child protothread and wait until it exits.
int tsch_packet_update_eb(uint8_t *buf, int buf_size, uint8_t tsch_sync_ie_offset)
Update ASN in EB packet.
linkaddr_t linkaddr_node_addr
The link-layer address of the node.
uint8_t tsch_calculate_channel(struct tsch_asn_t *asn, uint8_t channel_offset)
Returns a 802.15.4 channel from an ASN and channel offset.
#define RTIMER_NOW()
Get the current clock time.
int32_t tsch_timesync_adaptive_compensate(rtimer_clock_t delta_ticks)
Computes time compensation for a given point in the future.
unsigned int tsch_security_mic_len(const frame802154_t *frame)
Return MIC length.
#define PT_END(pt)
Declare the end of a protothread.
Header file for the Packet queue buffer management
The MAC layer did not get an acknowledgement for the packet.
void process_poll(struct process *p)
Request a process to be polled.
struct tsch_link * tsch_schedule_get_next_active_link(struct tsch_asn_t *asn, uint16_t *time_offset, struct tsch_link **backup_link)
Returns the next active link after a given ASN, and a backup link (for the same ASN, with Rx flag)
The MAC layer transmission was OK.
#define TSCH_ASN_MOD(asn, div)
Returns the result (16 bits) of a modulo operation on ASN, with divisor being a struct asn_divisor_t...
#define PT_YIELD(pt)
Yield from the current protothread.
int tsch_packet_parse_eack(const uint8_t *buf, int buf_size, uint8_t seqno, frame802154_t *frame, struct ieee802154_ies *ies, uint8_t *hdr_len)
Parse enhanced ACK packet.
Main API declarations for TSCH.
clock_time_t clock_time(void)
Get the current clock time.
#define RTIMER_BUSYWAIT_UNTIL_ABS(cond, t0, max_time)
Busy-wait until a condition.
struct tsch_packet * tsch_queue_get_packet_for_nbr(const struct tsch_neighbor *n, struct tsch_link *link)
Returns the first packet that can be sent from a queue on a given link.
#define RADIO_RX_MODE_ADDRESS_FILTER
The radio reception mode controls address filtering and automatic transmission of acknowledgements in...
int tsch_is_locked(void)
Checks if the TSCH lock is set.
void tsch_slot_operation_sync(rtimer_clock_t next_slot_start, struct tsch_asn_t *next_slot_asn)
Set global time before starting slot operation, with a rtimer time and an ASN.
The MAC layer deferred the transmission for a later time.
Parameters used by the frame802154_create() function.
void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *src)
Copy a link-layer address.
#define PT_THREAD(name_args)
Declaration of a protothread.
void tsch_packet_set_frame_pending(uint8_t *buf, int buf_size)
Set frame pending bit in a packet (whose header was already build)
int tsch_queue_packet_sent(struct tsch_neighbor *n, struct tsch_packet *p, struct tsch_link *link, uint8_t mac_tx_status)
Updates neighbor queue state after a transmission.
#define TSCH_ASN_DIFF(asn1, asn2)
Returns the 32-bit diff between asn1 and asn2.
int linkaddr_cmp(const linkaddr_t *addr1, const linkaddr_t *addr2)
Compare two link-layer addresses.
static void tsch_radio_on(enum tsch_radio_state_on_cmd command)
This function turns on the radio.
int tsch_queue_packet_count(const linkaddr_t *addr)
Returns the number of packets currently a given neighbor queue.
#define TSCH_ASN_INC(asn, inc)
Increment an ASN by inc (32 bits)
uint8_t seq
Sequence number.
int tsch_packet_get_frame_pending(uint8_t *buf, int buf_size)
Get frame pending bit from a packet.
int ringbufindex_peek_put(const struct ringbufindex *r)
Check if there is space to put an element.
void tsch_disassociate(void)
Leave the TSCH network we are currently in.
An IEEE 802.15.4-2015 TSCH link (also called cell or slot)
Header file for the Packet buffer (packetbuf) management
Include file for the Contiki low-layer network stack (NETSTACK)
void watchdog_periodic(void)
Writes the WDT clear sequence.
struct tsch_packet * tsch_queue_get_unicast_packet_for_any(struct tsch_neighbor **n, struct tsch_link *link)
Gets the head packet of any neighbor queue with zero backoff counter.
unsigned int tsch_security_secure_frame(uint8_t *hdr, uint8_t *outbuf, int hdrlen, int datalen, struct tsch_asn_t *asn)
Protect a frame with encryption and/or MIC.
Header file for the logging system
uint8_t ack_required
1 bit.
int ringbufindex_put(struct ringbufindex *r)
Put one element to the ring buffer.
void tsch_slot_operation_start(void)
Start actual slot operation.
The ASN is an absolute slot number over 5 bytes.
frame802154_aux_hdr_t aux_hdr
Aux security header.
int tsch_packet_create_eack(uint8_t *buf, uint16_t buf_len, const linkaddr_t *dest_addr, uint8_t seqno, int16_t drift, int nack)
Construct Enhanced ACK packet.