void __timer_set_helper(uint16_t time) { if(time == 0) return; if(timer_reached()) return; //won't harm to be sure timer_init(); if(timerstack_count <= TIMER_STACK_SIZE) { if (timerstack_count != 0) { if(timer_remaining() > time) { timerstack[timerstack_count-1] = timer_remaining()-time; timer_set(time); } else timerstack[timerstack_count-1] = 0; } else timer_set(time); } timerstack_count++; }
/*---------------------------------------------------------------------------*/ static int recycle(void) { /* Find the oldest recyclable mapping and remove it. */ struct ip64_addrmap_entry *m, *oldest; /* Walk through the list of address mappings, throw away the ones that are too old. */ oldest = NULL; for(m = list_head(entrylist); m != NULL; m = list_item_next(m)) { if(m->flags & FLAGS_RECYCLABLE) { if(oldest == NULL) { oldest = m; } else { if(timer_remaining(&m->timer) < timer_remaining(&oldest->timer)) { oldest = m; } } } } /* If we found an oldest recyclable entry, remove it and return non-zero. */ if(oldest != NULL) { list_remove(entrylist, oldest); memb_free(&entrymemb, oldest); return 1; } return 0; }
static int free_oldest(void) { /* Find the oldest mapping and remove it. */ struct ip64_addrmap_entry *m, *oldest; /* Walk through the list of address mappings, throw away the oldest one. * LifeTime of the timers is set to 0, if SKIP_LIFETIME is enabled, since there is no * expiration concept in this case. */ oldest = NULL; for(m = list_head(entrylist); m != NULL; m = list_item_next(m)) { if(oldest == NULL) { oldest = m; } else { if(timer_remaining(&m->timer) < timer_remaining(&oldest->timer)) { oldest = m; } } } /* If we found the oldest entry, remove it and return non-zero. */ if(oldest != NULL) { list_remove(entrylist, oldest); memb_free(&entrymemb, oldest); return 1; } return 0; }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(etimer_process, ev, data, buf, user_data) { struct etimer *t; PROCESS_BEGIN(); while(1) { PROCESS_YIELD(); PRINTF("%s():%d timerlist %p\n", __FUNCTION__, __LINE__, timerlist); for(t = timerlist; t != NULL; t = t->next) { PRINTF("%s():%d timer %p remaining %d triggered %d\n", __FUNCTION__, __LINE__, t, timer_remaining(&t->timer), etimer_is_triggered(t)); if(etimer_expired(t) && !etimer_is_triggered(t)) { PRINTF("%s():%d timer %p expired, process %p\n", __FUNCTION__, __LINE__, t, t->p); if (t->p == NULL) { PRINTF("calling tcpip_process\n"); process_post_synch(&tcpip_process, PROCESS_EVENT_TIMER, t, NULL); } else { process_post_synch(t->p, PROCESS_EVENT_TIMER, t, NULL); } } } update_time(); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ static void update_time(void) { struct etimer *t; clock_time_t remaining; if (timerlist == NULL) { next_expiration = 0; } else { clock_time_t shortest = 0; for(t = timerlist; t != NULL; t = t->next) { remaining = timer_remaining(&t->timer); PRINTF("%s():%d etimer %p left %d shortest %d triggered %d\n", __FUNCTION__, __LINE__, t, remaining, shortest, etimer_is_triggered(t)); if((shortest > remaining || shortest == 0) && remaining != 0) { shortest = remaining; } } next_expiration = shortest; PRINTF("%s():%d next expiration %d\n", __FUNCTION__, __LINE__, next_expiration); } net_timer_check(); }
static void print_scope(struct scope *scope) { LOG_L("scope-id=%u, super-scope-id=%u, owner-sid=%u, ttl=%u, flags=%u, status=%u, spec-len=%u\n", scope->scope_id, scope->super_scope_id, scope->owner->id, timer_remaining(&(scope->ttl_timer.etimer.timer)) / CLOCK_SECOND, scope->flags, scope->status, scope->spec_len); }
bool __timer_timeout_helper(bool cond) { if(timer_reached() || !cond) { timerstack_count--; if(timerstack_count == 0) timer_reset(); else if (timerstack_count <= TIMER_STACK_SIZE) { if(timerstack[timerstack_count-1] != 0) timer_set(timer_remaining()+timerstack[timerstack_count-1]); } return false; } else return true; }
void stack_check_timer_fired(void){ pmesg(200, "%s :: %s :: Line #%d\n", __FILE__, __func__, __LINE__); static bool bpIncrease = false; static uint16_t diffBackpressure =0; static uint16_t newLocalBackpressure =0; static uint32_t beacon_time =0; beacon_time = ULONG_MAX - (uint32_t)timer_remaining(&beacon_timerTime); newLocalBackpressure = list_length(send_stack) + sendQeOccupied + virtualQueueSize; if(beacon_time >= BEACON_TH_INTERVAL){ //recently we have not broadcast a beacon //update backpressure to other nodes if(oldLocalBackpressure < newLocalBackpressure) bpIncrease = true; if(bpIncrease) diffBackpressure = newLocalBackpressure - oldLocalBackpressure; else diffBackpressure = oldLocalBackpressure - newLocalBackpressure; if(diffBackpressure>=DIFF_QUEUE_TH){ if( extraBeaconSending == false){ extraBeaconSending = true; } else { return; } beaconType = NORMAL_BEACON; process_post(&sendBeaconTask, NULL, NULL); skipExtraBeaconCnt=3; } } else { if(skipExtraBeaconCnt>0) { skipExtraBeaconCnt--; } } oldLocalBackpressure = newLocalBackpressure; }
//void sendDataTask() { PROCESS_THREAD(sendDataTask, ev, data) { PROCESS_BEGIN(); while(1) { PROCESS_WAIT_EVENT(); pmesg(200, "%s :: %s :: Line #%d\n", __FILE__, __func__, __LINE__); static fe_queue_entry_t* qe; static fe_queue_entry_t* nullQe; static message_wrapper_t* nullMsg; static bcp_data_header_t* nullHdr; static int subsendResult; static error_t retVal; static uint8_t payloadLen; static rimeaddr_t dest; static message_wrapper_t* hdr; static uint32_t sendTime; static uint32_t checksum; checksum = 0; // Specialty handling of loopback or sudden sink designation if(rootControl_isRoot()) { sending = false; // If we are sending we'll abort if(sendQeOccupied == true) { qe = sendQe; sendQeOccupied = false; // Guaranteed succcessful service } else { if(list_length(send_stack) == 0 && virtualQueueSize == 0) { //This shouldn't be possible pmesg(10, "FAILURE IN BCP_FORWARDING_ENGINE.c SENDDATATASK()"); continue; } qe = sendQe = list_pop(send_stack); } memcpy(loopbackMsgPtr, qe -> msg, sizeof(message_wrapper_t)); //Deallocate the message in qe list_remove(message_pool, qe -> msg); memb_free(&message_pool_mem, qe -> msg); //Deallocate the qe object list_remove(q_entry_pool, qe); memb_free(&q_entry_pool_mem, qe); //Signal the event if(ev_msg_receive != NULL) loopbackMsgPtr = ev_msg_receive(loopbackMsgPtr); //Maybe do it again, if we are sink and there are data packets forwarderActivity(); continue; } if(sendQeOccupied == true) { qe = sendQe; } else { if(list_length(send_stack) == 0 && virtualQueueSize == 0) { pmesg(10, "ERROR: BcpForwardingEngine sendDataTask()\n"); continue; } //Check to see whether there exists a neighbor to route to with positive weight. retVal = routerForwarder_updateRouting(list_length(send_stack) + sendQeOccupied + virtualQueueSize); //NO_SNOOP: add another retVal response type, //if there is no entry in our routing table //request a RR beacon if(retVal == ESIZE) { sending = false; pmesg(200, "DEBUG: RR Beacon Send\n"); beaconType = RR_BEACON; process_post(&sendBeaconTask, NULL, NULL); //Stop the timer, reset it. We have two, one for keeping time, // one for the function call back ctimer_stop(&txRetryTimer); ctimer_set(&txRetryTimer, REROUTE_TIME, tx_retry_timer_fired, NULL); timer_reset(&txRetryTimerTime); continue; } if(retVal == FAIL) { //No neighbor is a good option right now, wait on a recompute-time sending = false; ctimer_stop(&txRetryTimer); ctimer_set(&txRetryTimer, REROUTE_TIME, tx_retry_timer_fired, NULL); timer_reset(&txRetryTimerTime); continue; } if(list_length(send_stack) == 0) { // Create a null packet, place it on the stack (must be here by virtue of a virtual backlog) nullQe = memb_alloc(&q_entry_pool_mem); if(nullQe == NULL) { pmesg(10, "ERROR: BcpForwardingEngine - sendDataTask. Cannot enqueue nullQe\n"); continue; } list_add(q_entry_pool, nullQe); nullMsg = memb_alloc(&message_pool_mem); if(nullMsg == NULL) { pmesg(10, "ERROR: BcpForwardingEngine - sendDataTask. Cannot enqueue nullMsg\n"); //Deallocate list_remove(q_entry_pool, nullQe); memb_free(&q_entry_pool_mem, nullQe); continue; } list_add(message_pool, nullMsg); nullHdr = &(nullMsg -> bcp_data_header); nullHdr -> hopCount = 0; rimeaddr_copy(&(nullHdr -> origin), &rimeaddr_node_addr); nullHdr -> originSeqNo = nullSeqNo++; nullHdr -> bcpDelay = 0; nullHdr -> txCount = 0; nullHdr -> pktType = PKT_NULL; nullQe -> arrivalTime = 0; //call DelayPacketTimer.getNow(); nullQe -> firstTxTime = 0; nullQe -> bcpArrivalDelay = 0; nullQe -> msg = nullMsg; nullQe -> source = LOCAL_SEND; nullQe -> txCount = 0; list_push(send_stack, nullQe); virtualQueueSize--; } qe = sendQe = list_pop(send_stack); pmesg(10, "SENDING MESSAGE ORIGINATING FROM = %d.%d\n", qe -> msg -> bcp_data_header.origin.u8[0], qe -> msg -> bcp_data_header.origin.u8[1]); qe -> firstTxTime = timer_remaining(&txRetryTimerTime); //call txRetryTimer.getNow(); sendQeOccupied = true; } //End else // payloadLen = sizeof(qe -> msg); //call SubPacket.payloadLength(qe->msg); // Give up on a link after MAX_RETX_ATTEMPTS retransmit attempts, link is lousy! // Furthermore, penalize by double MAX_RETX_ATTEMPTS, due to cutoff. if(qe -> txCount >= MAX_RETX_ATTEMPTS) { static bool isBroadcast = 0; isBroadcast = rimeaddr_cmp(&(qe -> msg -> from), &rimeaddr_null); routerForwarder_updateLinkSuccess(&(qe -> msg -> from), isBroadcast, 2*MAX_RETX_ATTEMPTS); //call RouterForwarderIF.updateLinkSuccess(call AMDataPacket.destination(qe->msg), 2*MAX_RETX_ATTEMPTS); // call BcpDebugIF.reportValues( 0,0,0,0,0,MAX_RETX_ATTEMPTS, call AMDataPacket.destination(qe->msg),0x77 ); qe -> txCount = 0; // Place back on the Stack, discard element if necesary conditionalFQDiscard(); list_push(send_stack, qe); // retVal = call SendStack.pushTop( qe ); sendQeOccupied = false; // Try again after a REROUTE_TIME, this choice was bad. sending = false; ctimer_stop(&txRetryTimer); ctimer_set(&txRetryTimer, REROUTE_TIME, tx_retry_timer_fired, NULL); timer_reset(&txRetryTimerTime); continue; } qe -> txCount++; localTXCount++; rimeaddr_copy(&dest, &nextHopAddress_m); //Request an ack, not going to support DL without ack (for now) //Store the local backpressure level to the backpressure field hdr = qe -> msg; //getHeader(qe->msg); hdr -> bcp_data_header.bcpBackpressure = list_length(send_stack) + sendQeOccupied + virtualQueueSize; //Fill in the next hop Backpressure value hdr -> bcp_data_header.nhBackpressure = nextHopBackpressure_m; //Fill in the node tx count field (burst success detection by neighbors #ifndef BEACON_ONLY hdr -> bcp_data_header.nodeTxCount = localTXCount; // Fill in the burstNotifyAddr, then reset to TOS_NODE_ID immediately rimeaddr_copy(&(hdr->bcp_data_header.burstNotifyAddr), ¬ifyBurstyLinkNeighbor_m); rimeaddr_copy(¬ifyBurstyLinkNeighbor_m, &rimeaddr_node_addr); #endif //Update the txCount field hdr -> bcp_data_header.txCount = hdr -> bcp_data_header.txCount + 1; sendTime = 0; //This timer is never implemented in TinyOS: timer_remaining(&delayPacketTimer); //regardless of transmission history, lastTxTime and BcpDelay are re-comptued. hdr -> bcp_data_header.bcpDelay = qe -> bcpArrivalDelay + (sendTime - qe -> arrivalTime) + PER_HOP_MAC_DLY; //Calculate the checksum! checksum = calcHdrChecksum(qe -> msg); hdr -> bcp_data_header.hdrChecksum = checksum; // #ifdef LOW_POWER_LISTENING // // call LowPowerListening.setRxSleepInterval(qe->msg, LPL_SLEEP_INTERVAL_MS); // call LowPowerListening.setRemoteWakeupInterval(qe->msg, LPL_SLEEP_INTERVAL_MS); // #endif //Send thge packet!! rimeaddr_copy(&(qe -> msg -> to), &dest); rimeaddr_copy(&(qe -> msg -> from), &rimeaddr_node_addr); payloadLen = sizeof(message_wrapper_t); //call SubPacket.payloadLength(qe->msg); packetbuf_clear(); packetbuf_set_datalen(payloadLen); packetbuf_copyfrom(qe -> msg, payloadLen); pmesg(10, "Checksum from packet about to send: %u\n", ((message_wrapper_t*)packetbuf_dataptr()) -> bcp_data_header.hdrChecksum); //Non-zero if the packet could be sent, zero otherwise subsendResult = unicast_send(&unicast, &dest); //Success if(subsendResult != 0) { // Successfully submitted to the data-link layer. pmesg(100, "BcpForwardingEngine: Successfully Sent Unicast Message\n"); //Print out end-to-end message only if packet is originating from here if(rimeaddr_cmp(&(qe -> msg -> from), &(qe -> msg -> bcp_data_header.origin)) != 0) printf("Sent Packet from: %d.%d with SequenceNum = %lu\n", qe -> msg -> bcp_data_header.origin.u8[0], qe -> msg -> bcp_data_header.origin.u8[1], qe -> msg -> bcp_data_header.packetSeqNum); continue; } else { pmesg(100, "BcpForwardingEngine: Failed to Send Unicast Message. Trying again\n"); // radioOn = false; // NO_SNOOP: set beacon type beaconType = NORMAL_BEACON; process_post(&sendDataTask, NULL, NULL); } } //End while(1) PROCESS_END(); }
void subscription_sync_jitter(struct subscription *s, struct subscription_item *si) { //Whatever set here will be negated later below. s->jitter = timer_remaining(&si->t.etimer.timer) + (si->sub.jitter > 0 ? si->sub.period/2 - si->sub.jitter : 0); }