int main(void) { xtimer_init(); bloom_t *bloom = bloom_new(1 << 12, 8, fnv_hash, sax_hash, sdbm_hash, djb2_hash, kr_hash, dek_hash, rotating_hash, one_at_a_time_hash); printf("Testing Bloom filter.\n\n"); printf("m: %" PRIu32 " k: %" PRIu32 "\n\n", (uint32_t) bloom->m, (uint32_t) bloom->k); genrand_init(myseed); unsigned long t1 = xtimer_now(); for (int i = 0; i < lenB; i++) { buf_fill(buf, BUF_SIZE); buf[0] = MAGIC_B; bloom_add(bloom, (uint8_t *) buf, BUF_SIZE * sizeof(uint32_t) / sizeof(uint8_t)); } unsigned long t2 = xtimer_now(); printf("adding %d elements took %" PRIu32 "ms\n", lenB, (uint32_t) (t2 - t1) / 1000); int in = 0; int not_in = 0; unsigned long t3 = xtimer_now(); for (int i = 0; i < lenA; i++) { buf_fill(buf, BUF_SIZE); buf[0] = MAGIC_A; if (bloom_check(bloom, (uint8_t *) buf, BUF_SIZE * sizeof(uint32_t) / sizeof(uint8_t))) { in++; } else { not_in++; } } unsigned long t4 = xtimer_now(); printf("checking %d elements took %" PRIu32 "ms\n", lenA, (uint32_t) (t4 - t3) / 1000); printf("\n"); printf("%d elements probably in the filter.\n", in); printf("%d elements not in the filter.\n", not_in); double false_positive_rate = (double) in / (double) lenA; printf("%f false positive rate.\n", false_positive_rate); bloom_del(bloom); printf("\nAll done!\n"); return 0; }
/* start sending beacons */ void beaconing_start(void) { uint8_t remaining_beacons = DOW_BEACONING_COUNT; bool end_beaconing = false; /* register for RX */ gnrc_netreg_entry_t _ne; _ne.target.pid = sched_active_pid; _ne.demux_ctx = GNRC_NETREG_DEMUX_CTX_ALL; gnrc_netreg_register(GNRC_NETTYPE_UNDEF, &_ne); /* schedule beacon */ msg_t beacon_msg; beacon_msg.type = DOW_MSG_BEACON; xtimer_t beacon_timer; beacon_timer.target = beacon_timer.long_target = 0; /* let's delay the first beacon by DOW_BEACONING_WAIT */ uint32_t tmp = DOW_BEACONING_PERIOD + DOW_BEACONING_WAIT; xtimer_set_msg(&beacon_timer, tmp, &beacon_msg, sched_active_pid); tmp -= DOW_BEACONING_WAIT; uint32_t start = xtimer_now().ticks32; while (1) { msg_t m; msg_receive(&m); switch (m.type) { case DOW_MSG_BEACON: LOG_DEBUG("beaconing: ready to send next beacon\n"); beaconing_send(); tmp = DOW_BEACONING_PERIOD; /* check if we need to do further beaconing */ if (--remaining_beacons > 0) { xtimer_set_msg(&beacon_timer, tmp, &beacon_msg, sched_active_pid); } else { beacon_msg.type = DOW_MSG_BEACON_END; tmp = 2 * DOW_BEACONING_WAIT - (xtimer_now().ticks32 - start); LOG_INFO("beaconing: end beaconing period in %" PRIu32 \ " seconds\n", (tmp / US_PER_SEC)); xtimer_set_msg(&beacon_timer, tmp, &beacon_msg, sched_active_pid); } break; case DOW_MSG_BEACON_END: LOG_INFO("beaconing: end beaconing\n"); end_beaconing = true; break; case GNRC_NETAPI_MSG_TYPE_RCV: LOG_DEBUG("beaconing: received packet, assume that it is a beacon\n"); _handle_beacon((gnrc_pktsnip_t *)m.content.ptr); break; default: LOG_WARNING("beaconing: didn't expect message type %X\n", m.type); break; } if (end_beaconing) { break; } } gnrc_netreg_unregister(GNRC_NETTYPE_UNDEF, &_ne); }
static void _xtimer_now64(uint32_t *short_term, uint32_t *long_term) { uint32_t before, after, long_value; /* loop to cope with possible overflow of xtimer_now() */ do { before = xtimer_now(); long_value = _long_cnt; after = xtimer_now(); } while(before > after); *short_term = after; *long_term = long_value; }
int main(void) { phydat_t res; uint32_t last = xtimer_now(); puts("SAUL test application"); while (1) { saul_reg_t *dev = saul_reg; if (dev == NULL) { puts("No SAUL devices present"); return 1; } while (dev) { int dim = saul_reg_read(dev, &res); phydat_dump(&res, dim); dev = dev->next; } xtimer_periodic_wakeup(&last, INTERVAL); } return 0; }
int main(void) { uint32_t last = xtimer_now(); int sample = 0; puts("\nRIOT ADC peripheral driver test\n"); puts("This test will sample all available ADC lines once every 100ms with\n" "a 10-bit resolution and print the sampled results to STDIO\n\n"); /* initialize all available ADC lines */ for (int i = 0; i < ADC_NUMOF; i++) { if (adc_init(ADC_LINE(i)) < 0) { printf("Initialization of ADC_LINE(%i) failed\n", i); return 1; } else { printf("Successfully initialized ADC_LINE(%i)\n", i); } } while (1) { for (int i = 0; i < ADC_NUMOF; i++) { sample = adc_sample(ADC_LINE(i), RES); if (sample < 0) { printf("ADC_LINE(%i): 10-bit resolution not applicable\n", i); } else { printf("ADC_LINE(%i): %i\n", i, sample); } } xtimer_usleep_until(&last, DELAY); } return 0; }
static void *btn_handler_function (void *arg) { uint32_t last = xtimer_now(); int i; flag_state = 0; while (1) { i = gpio_read(BTN_B1_PIN); if (i != 0) { if ( flag_state == 0 ) { LED6_ON; flag_state = 1; xtimer_usleep_until(&last, 1000000); } else { LED6_OFF; flag_state = 0; xtimer_usleep_until(&last, 1000000); } } xtimer_usleep_until(&last, 100000); } return NULL; }
int uart_stdio_write(const char* buffer, int len) { int written = rtt_write(buffer, len); xtimer_ticks32_t last_wakeup = xtimer_now(); while (blocking_stdout && written < len) { xtimer_periodic_wakeup(&last_wakeup, STDIO_POLL_INTERVAL); written += rtt_write(&buffer[written], len-written); } return written; }
int _cs(int argc, char **argv) { (void) argc; (void) argv; #if DOW_DEBUG gnrc_netapi_get(ccnl_pid, NETOPT_CCN, CCNL_CTX_PRINT_CS, &ccnl_relay, sizeof(ccnl_relay)); #else printf("%u CS command\n", (unsigned) xtimer_now().ticks32); //if ((dow_state != DOW_STATE_INACTIVE) && (dow_state != DOW_STATE_HANDOVER)) { if ((dow_state != DOW_STATE_INACTIVE) && (dow_state != DOW_STATE_STOPPED)) { gnrc_netapi_get(ccnl_pid, NETOPT_CCN, CCNL_CTX_PRINT_CS, &ccnl_relay, sizeof(ccnl_relay)); //ccnl_cs_dump(&ccnl_relay); printf("%u DONE\n", (unsigned) xtimer_now().ticks32); } else { puts("NOP"); } #endif return 0; }
void xtimer_set(xtimer_t *timer, uint32_t offset) { DEBUG("timer_set(): offset=%" PRIu32 " now=%" PRIu32 " (%" PRIu32 ")\n", offset, xtimer_now(), _xtimer_now()); if (!timer->callback) { DEBUG("timer_set(): timer has no callback.\n"); return; } xtimer_remove(timer); uint32_t target = xtimer_now() + offset; if (offset < XTIMER_BACKOFF) { xtimer_spin(offset); _shoot(timer); } else { _xtimer_set_absolute(timer, target); } }
int _stats(int argc, char **argv) { (void) argc; (void) argv; printf("RX: %04" PRIu32 ", TX: %04" PRIu32 "\n", ccnl_relay.ifs[0].rx_cnt, ccnl_relay.ifs[0].tx_cnt); if (dow_sleeping) { printf("active: %u, sleeping: %u\n", (unsigned) dow_time_active, (unsigned) (dow_time_sleeping + (xtimer_now().ticks32 - dow_ts_wakeup))); } else { printf("active: %u, sleeping: %u\n", (unsigned) (dow_time_active + (xtimer_now().ticks32 - dow_ts_sleep)), (unsigned) dow_time_sleeping); } return 0; }
static int cmd_sample(int argc, char **argv) { (void)argc; (void)argv; xtimer_ticks32_t wakeup = xtimer_now(); while(1) { sample(); xtimer_periodic_wakeup(&wakeup, SAMPLE_PERIOD); } return 0; }
void _update_lifetime(void) { uint32_t now = xtimer_now(); uint16_t now_sec = now / SEC_IN_USEC; gnrc_rpl_parent_t *parent; gnrc_rpl_instance_t *inst; for (uint8_t i = 0; i < GNRC_RPL_PARENTS_NUMOF; ++i) { parent = &gnrc_rpl_parents[i]; if (parent->state != 0) { if ((int32_t)(parent->lifetime - now_sec) <= GNRC_RPL_LIFETIME_UPDATE_STEP) { gnrc_rpl_dodag_t *dodag = parent->dodag; gnrc_rpl_parent_remove(parent); gnrc_rpl_parent_update(dodag, NULL); continue; } else if ((int32_t)(parent->lifetime - now_sec) <= (GNRC_RPL_LIFETIME_UPDATE_STEP * 2)) { gnrc_rpl_send_DIS(parent->dodag->instance, &parent->addr); } } } for (int i = 0; i < GNRC_RPL_INSTANCES_NUMOF; ++i) { inst = &gnrc_rpl_instances[i]; if (inst->state != 0) { if ((inst->cleanup > 0) && (inst->dodag.parents == NULL) && (inst->dodag.my_rank == GNRC_RPL_INFINITE_RANK)) { inst->cleanup -= GNRC_RPL_LIFETIME_UPDATE_STEP; if (inst->cleanup <= 0) { /* no parents - delete this instance and DODAG */ gnrc_rpl_instance_remove(inst); continue; } } if (inst->dodag.dao_time > GNRC_RPL_LIFETIME_UPDATE_STEP) { inst->dodag.dao_time -= GNRC_RPL_LIFETIME_UPDATE_STEP; } else { _dao_handle_send(&inst->dodag); } } } #ifdef MODULE_GNRC_RPL_P2P gnrc_rpl_p2p_update(); #endif xtimer_set_msg(&_lt_timer, _lt_time, &_lt_msg, gnrc_rpl_pid); }
int _xtimer_set_absolute(xtimer_t *timer, uint32_t target) { uint32_t now = xtimer_now(); int res = 0; DEBUG("timer_set_absolute(): now=%" PRIu32 " target=%" PRIu32 "\n", now, target); timer->next = NULL; if ((target >= now) && ((target - XTIMER_BACKOFF) < now)) { /* backoff */ xtimer_spin_until(target + XTIMER_BACKOFF); _shoot(timer); return 0; } unsigned state = irq_disable(); if (_is_set(timer)) { _remove(timer); } timer->target = target; timer->long_target = _long_cnt; if (target < now) { timer->long_target++; } if ( (timer->long_target > _long_cnt) || !_this_high_period(target) ) { DEBUG("xtimer_set_absolute(): the timer doesn't fit into the low-level timer's mask.\n"); _add_timer_to_long_list(&long_list_head, timer); } else { if (_xtimer_lltimer_mask(now) >= target) { DEBUG("xtimer_set_absolute(): the timer will expire in the next timer period\n"); _add_timer_to_list(&overflow_list_head, timer); } else { DEBUG("timer_set_absolute(): timer will expire in this timer period.\n"); _add_timer_to_list(&timer_list_head, timer); if (timer_list_head == timer) { DEBUG("timer_set_absolute(): timer is new list head. updating lltimer.\n"); _lltimer_set(target - XTIMER_OVERHEAD); } } } irq_restore(state); return res; }
/** * @brief local callback to handle incoming content chunks * * @note Gets called from CCNL thread context * * @returns 1 if chunk is handled and no further processing should happen * @returns 0 otherwise **/ int ccnlriot_consumer(struct ccnl_relay_s *relay, struct ccnl_face_s *from, struct ccnl_pkt_s *pkt) { (void) from; (void) relay; if (dow_state == DOW_STATE_STOPPED) { LOG_DEBUG("ccnl_helper: we're in stopped, do nothing\n"); free_packet(pkt); return 1; } uint32_t cont_id = (uint32_t) strtol((char*)pkt->pfx->comp[2], NULL, 16); if (cont_id > dow_highest_id) { dow_highest_id = cont_id; } LOG_DEBUG("%" PRIu32 " ccnl_helper: local consumer for prefix: %s\n", xtimer_now().ticks32, ccnl_prefix_to_path_detailed(_prefix_str, pkt->pfx, 1, 0, 0)); memset(_prefix_str, 0, CCNLRIOT_PFX_LEN); #if DOW_DEPUTY /* XXX: might be unnecessary du to mutex now */ /* if we're currently transferring our cache to the new deputy, we do not touch the content store */ if (dow_state == DOW_STATE_HANDOVER) { LOG_DEBUG("ccnl_helper: we're in handover state, cannot touch content store right now\n"); free_packet(pkt); return 1; } #endif /* check if prefix is for ALL and contains an ACK */ if ((ccnl_prefix_cmp(ccnl_helper_all_pfx, NULL, pkt->pfx, CMP_MATCH) >= 1) && (strncmp((char*) pkt->content, CCNLRIOT_CONT_ACK, strlen(CCNLRIOT_CONT_ACK)) == 0)) { dow_content_t *cc = (dow_content_t*) pkt->content; LOG_DEBUG("ccnl_helper: content number is %i\n", cc->num); if (cc->num >= 0) { _remove_pit(relay, cc->num); } LOG_DEBUG("ccnl_helper: received ACK, flag the content\n"); msg_t m = { .type = DOW_MSG_RECEIVED_ACK }; msg_try_send(&m, dow_pid); free_packet(pkt); return 1; }
int main(void) { #if defined(MAIN_THREAD_PIN) gpio_t main_pin = MAIN_THREAD_PIN; gpio_init(main_pin, GPIO_OUT); #endif #if defined(WORKER_THREAD_PIN_1) && defined(WORKER_THREAD_PIN_2) timer_arg_t sleep_timer1 = { TEST_SLEEP_TIME_1, WORKER_THREAD_PIN_1 }; timer_arg_t sleep_timer2 = { TEST_SLEEP_TIME_2, WORKER_THREAD_PIN_2 }; #else uint32_t sleep_timer1 = TEST_SLEEP_TIME_1; uint32_t sleep_timer2 = TEST_SLEEP_TIME_2; #endif LOG_DEBUG("[INIT]\n"); thread_create(stack_timer1, TEST_TIMER_STACKSIZE, 2, THREAD_CREATE_STACKTEST, timer_func, &sleep_timer1, "timer1"); thread_create(stack_timer2, TEST_TIMER_STACKSIZE, 3, THREAD_CREATE_STACKTEST, timer_func, &sleep_timer2, "timer2"); uint32_t now = 0; uint32_t start = xtimer_now_usec(); uint32_t until = start + (TEST_TIME_S * US_PER_SEC); uint32_t interval = TEST_INTERVAL_MS * US_PER_MS; xtimer_ticks32_t last_wakeup = xtimer_now(); puts("[START]"); while ((now = xtimer_now_usec()) < until) { unsigned percent = (100 * (now - start)) / (until - start); #if defined(MAIN_THREAD_PIN) gpio_set(main_pin); #endif xtimer_periodic_wakeup(&last_wakeup, interval); #if defined(MAIN_THREAD_PIN) gpio_clear(main_pin); #endif printf("Testing (%3u%%)\n", percent); } puts("Testing (100%)"); puts("[SUCCESS]"); return 0; }
static void *colllision_detection(void *arg) { uint32_t lw = xtimer_now(); while (1) { /* trigger sensor reading */ srf02_trigger(&dist_front, SRF02_MODE_REAL_CM); srf02_trigger(&dist_back, SRF02_MODE_REAL_CM); /* wait for results */ xtimer_usleep(SRF02_RANGE_DELAY); /* read distance data */ front_filter[filter_pos] = srf02_read(&dist_front); xtimer_usleep(1); /* hack, otherwise the 2nd srf02_read f***s up */ back_filter[filter_pos] = srf02_read(&dist_back); // printf(" f: %3i, b: %3i %i\n", (int)front_filter[filter_pos], (int)back_filter[filter_pos], filter_pos); filter_pos = (++filter_pos >= FILTER_SIZE) ? 0 : filter_pos; /* analyze data and trigger events base on it */ uint16_t fd = 0; uint16_t bd = 0; for (int i = 0; i < FILTER_SIZE; i++) { fd += front_filter[i]; bd += back_filter[i]; } if ((fd < (FILTER_SIZE * CONF_DIST_THOLD)) && (front_blocked == 0)) { front_blocked = 1; event(EVT_FRONT_BLOCKED); } else if ((fd >= (FILTER_SIZE * CONF_DIST_THOLD)) && (front_blocked == 1)) { front_blocked = 0; event(EVT_FRONT_FREE); } if ((bd < (FILTER_SIZE * CONF_DIST_THOLD)) && (back_blocked == 0)) { back_blocked = 1; event(EVT_BACK_BLOCKED); } else if ((bd >= (FILTER_SIZE * CONF_DIST_THOLD)) && (back_blocked == 1)) { back_blocked = 0; event(EVT_BACK_FREE); } xtimer_usleep_until(&lw, CONF_DIST_SENSE_DELAY); } return NULL; }
/* The reason we have this strange logic is as follows: If we have an RTT console, we are powered, and so don't care that polling uses a lot of power. If however, we do not actually have an RTT console (because we are deployed on a battery somewhere) then we REALLY don't want to poll especially since we are not expecting to EVER get input. */ int uart_stdio_read(char* buffer, int count) { int res = rtt_read(buffer, count); if (res == 0) { if (!stdin_enabled) { mutex_lock(&_rx_mutex); /* We only unlock when rtt_stdio_enable_stdin is called Note that we assume only one caller invoked this function */ } xtimer_ticks32_t last_wakeup = xtimer_now(); while(1) { xtimer_periodic_wakeup(&last_wakeup, STDIO_POLL_INTERVAL); res = rtt_read(buffer, count); if (res > 0) return res; } } return res; }
int main(void) { int state = 0; int step = STEP; uint32_t last_wakeup = xtimer_now(); puts("\nRIOT PWM test"); puts("Connect an LED or scope to PWM pins to see something\n"); printf("Available PWM devices: %i\n", PWM_NUMOF); for (int i = 0; i < PWM_NUMOF; i++) { uint32_t real_f = pwm_init(PWM_DEV(i), MODE, FREQU, STEPS); if (real_f == 0) { printf("Error initializing PWM_%i\n", i); return 1; } else { printf("Initialized PWM_%i @ %" PRIu32 "Hz\n", i, real_f); } } puts("\nLetting the PWM pins oscillate now..."); while (1) { for (int i = 0; i < PWM_NUMOF; i++) { for (uint8_t chan = 0; chan < pwm_channels(PWM_DEV(i)); chan++) { pwm_set(PWM_DEV(i), chan, state); } } state += step; if (state <= 0 || state >= STEPS) { step = -step; } xtimer_usleep_until(&last_wakeup, INTERVAL); } return 0; }
/** * @brief main xtimer callback function */ static void _timer_callback(void) { uint32_t next_target; uint32_t reference; _in_handler = 1; DEBUG("_timer_callback() now=%" PRIu32 " (%" PRIu32 ")pleft=%" PRIu32 "\n", xtimer_now(), _mask(xtimer_now()), _mask(0xffffffff-xtimer_now())); if (!timer_list_head) { DEBUG("_timer_callback(): tick\n"); /* there's no timer for this timer period, * so this was a timer overflow callback. * * In this case, we advance to the next timer period. */ _next_period(); reference = 0; /* make sure the timer counter also arrived * in the next timer period */ while (_xtimer_now() == _mask(0xFFFFFFFF)); } else { /* we ended up in _timer_callback and there is * a timer waiting. */ /* set our period reference to that timer's target time. */ reference = _mask(timer_list_head->target); } overflow: /* check if next timers are close to expiring */ while (timer_list_head && (_time_left(_mask(timer_list_head->target), reference) < XTIMER_ISR_BACKOFF)) { /* make sure we don't fire too early */ while (_time_left(_mask(timer_list_head->target), reference)); /* pick first timer in list */ xtimer_t *timer = timer_list_head; /* advance list */ timer_list_head = timer->next; /* make sure timer is recognized as being already fired */ timer->target = 0; timer->long_target = 0; /* fire timer */ _shoot(timer); } /* possibly executing all callbacks took enough * time to overflow. In that case we advance to * next timer period and check again for expired * timers.*/ if (reference > _xtimer_now()) { DEBUG("_timer_callback: overflowed while executing callbacks. %i\n", timer_list_head != 0); _next_period(); reference = 0; goto overflow; } if (timer_list_head) { /* schedule callback on next timer target time */ next_target = timer_list_head->target - XTIMER_OVERHEAD; } else { /* there's no timer planned for this timer period */ /* schedule callback on next overflow */ next_target = _mask(0xFFFFFFFF); uint32_t now = _xtimer_now(); /* check for overflow again */ if (now < reference) { _next_period(); reference = 0; goto overflow; } else { /* check if the end of this period is very soon */ if (_mask(now + XTIMER_ISR_BACKOFF) < now) { /* spin until next period, then advance */ while (_xtimer_now() > now); _next_period(); reference = 0; goto overflow; } } } _in_handler = 0; /* set low level timer */ _lltimer_set(next_target); }
clock_time_t hal_getTick(void) { return (clock_time_t)xtimer_now(); }
.code = COAP_METHOD_POST, .mid = {0, 0} // will be overwritten in loop }; coap_packet_t req_pkt = { .header = req_hdr, .token = {NULL, 0}, // will be overwritten in loop .numopts = num_segs, .opts = {dest_uri_opts[0], dest_uri_opts[1], dest_uri_opts[2], dest_uri_opts[3]}, .payload = {.p = payload, .len = sizeof(int)} }; int initval; #ifdef MODULE_XTIMER initval = xtimer_now(); #else initval = 54321; #endif genrand_init(initval); while (1) { pkt_buf_len = sizeof(pkt_buf); rcv_buf_len = sizeof(rcv_buf); mid_rand = (uint16_t)genrand_uint32(); token_rand = genrand_uint32(); req_hdr.mid[0] = ((uint8_t *)&mid_rand)[0]; req_hdr.mid[1] = ((uint8_t *)&mid_rand)[1];
/** * @brief Prints a list of running threads including stack usage to stdout. */ void ps(void) { const char queued_name[] = {'_', 'Q'}; #ifdef DEVELHELP int overall_stacksz = 0, overall_used = 0; #endif printf("\tpid | " #ifdef DEVELHELP "%-21s| " #endif "%-9sQ | pri " #ifdef DEVELHELP "| stack ( used) | location " #endif #ifdef MODULE_SCHEDSTATISTICS "| runtime | switches" #endif "\n", #ifdef DEVELHELP "name", #endif "state"); for (kernel_pid_t i = KERNEL_PID_FIRST; i <= KERNEL_PID_LAST; i++) { tcb_t *p = (tcb_t *)sched_threads[i]; if (p != NULL) { int state = p->status; /* copy state */ const char *sname = state_names[state]; /* get state name */ const char *queued = &queued_name[(int)(state >= STATUS_ON_RUNQUEUE)]; /* get queued flag */ #ifdef DEVELHELP int stacksz = p->stack_size; /* get stack size */ overall_stacksz += stacksz; stacksz -= thread_measure_stack_free(p->stack_start); overall_used += stacksz; #endif #ifdef MODULE_SCHEDSTATISTICS double runtime_ticks = sched_pidlist[i].runtime_ticks / (double) xtimer_now() * 100; int switches = sched_pidlist[i].schedules; #endif printf("\t%3" PRIkernel_pid #ifdef DEVELHELP " | %-20s" #endif " | %-8s %.1s | %3i" #ifdef DEVELHELP " | %5i (%5i) | %p " #endif #ifdef MODULE_SCHEDSTATISTICS " | %6.3f%% | %8d" #endif "\n", p->pid, #ifdef DEVELHELP p->name, #endif sname, queued, p->priority #ifdef DEVELHELP , p->stack_size, stacksz, p->stack_start #endif #ifdef MODULE_SCHEDSTATISTICS , runtime_ticks, switches #endif ); } } #ifdef DEVELHELP printf("\t%5s %-21s|%13s%6s %5i (%5i)\n", "|", "SUM", "|", "|", overall_stacksz, overall_used); #endif }
clock_time_t hal_getSec(void) { return (clock_time_t)xtimer_now() / SEC_IN_USEC; }
int sched_run(void) { sched_context_switch_request = 0; thread_t *active_thread = (thread_t *)sched_active_thread; /* The bitmask in runqueue_bitcache is never empty, * since the threading should not be started before at least the idle thread was started. */ int nextrq = bitarithm_lsb(runqueue_bitcache); thread_t *next_thread = clist_get_container(sched_runqueues[nextrq], thread_t, rq_entry); DEBUG("sched_run: active thread: %" PRIkernel_pid ", next thread: %" PRIkernel_pid "\n", (active_thread == NULL) ? KERNEL_PID_UNDEF : active_thread->pid, next_thread->pid); if (active_thread == next_thread) { DEBUG("sched_run: done, sched_active_thread was not changed.\n"); return 0; } #ifdef MODULE_SCHEDSTATISTICS unsigned long time = xtimer_now(); #endif if (active_thread) { if (active_thread->status == STATUS_RUNNING) { active_thread->status = STATUS_PENDING; } #ifdef SCHED_TEST_STACK if (*((uintptr_t *) active_thread->stack_start) != (uintptr_t) active_thread->stack_start) { LOG_WARNING("scheduler(): stack overflow detected, pid=%" PRIkernel_pid "\n", active_thread->pid); } #endif #ifdef MODULE_SCHEDSTATISTICS schedstat *active_stat = &sched_pidlist[active_thread->pid]; if (active_stat->laststart) { active_stat->runtime_ticks += time - active_stat->laststart; } #endif } #ifdef MODULE_SCHEDSTATISTICS schedstat *next_stat = &sched_pidlist[next_thread->pid]; next_stat->laststart = time; next_stat->schedules++; if (sched_cb) { sched_cb(time, next_thread->pid); } #endif next_thread->status = STATUS_RUNNING; sched_active_pid = next_thread->pid; sched_active_thread = (volatile thread_t *) next_thread; DEBUG("sched_run: done, changed sched_active_thread.\n"); return 1; }
static uint32_t _current_minute(void) { return xtimer_now() / (SEC_IN_USEC * 60); }