static void handle_options(int argc, char **argv) { while (1) { int c, option_index; static struct option long_options[] = { { "mode", 1, 0, 'm' }, { "help", 0, 0, 'h' }, { 0, 0, 0, 0}, }; c = getopt_long(argc, argv, "m:h", long_options, &option_index); if (c == -1) break; switch (c) { case 'm': if (strcasecmp(optarg, "umts") == 0) { sleep_for_mode = MSEC(200); } else if (strcasecmp(optarg, "gsm") == 0) { sleep_for_mode = MSEC(900); } else if (strcasecmp(optarg, "lan") == 0) { sleep_for_mode = MSEC(70); } else { fprintf(stderr, "Unknown mode: '%s'\n", optarg); exit(-1); } break; case 'h': print_usage(); print_help(); exit(0); } } }
void setupTask( void * pvParameters ) { for( ; ; ) { vTaskDelay( MSEC( 10 ) ); SET_GPIO_SET( GPIOB, 3 ); vTaskDelay( MSEC( 10 ) ); SET_GPIO_CLR( GPIOB, 3 ); } }
void upm_delay_ms(unsigned int time) { if (time <= 0) time = 1; #if defined(UPM_PLATFORM_LINUX) struct timespec delay_time; delay_time.tv_sec = time / 1000; delay_time.tv_nsec = (time % 1000) * 1000000; // here we spin until the delay is complete - detecting signals // and continuing where we left off while (nanosleep(&delay_time, &delay_time) && errno == EINTR) ; // loop #elif defined(UPM_PLATFORM_ZEPHYR) # if KERNEL_VERSION_MAJOR == 1 && KERNEL_VERSION_MINOR >= 6 struct k_timer timer; k_timer_init(&timer, NULL, NULL); k_timer_start(&timer, time, 0); k_timer_status_sync(&timer); # else struct nano_timer timer; void *timer_data[1]; nano_timer_init(&timer, timer_data); nano_timer_start(&timer, MSEC(time) + 1); nano_timer_test(&timer, TICKS_UNLIMITED); # endif #endif }
void repeat(HELP* self, int incordec){ PULSEGEN* pulse; if(self->gui->pulseUsed == 0){ pulse = self->gui->pulse1; }else{ pulse = self->gui->pulse2; } if(self->firstpress){ self->firstpress = 0; AFTER(MSEC(1000), self, repeat, 0); } if((((PINB >> 6) & 1) == 0 && incordec == 0)){ //Up SYNC(pulse, pulseInc, 0); SYNC(self->gui, update, 0); AFTER(MSEC(400), self, repeat, 0); }else if (((PINB >> 7) == 0) && incordec == 1){ //Down
time_t usr_timer_cb(timer_arg_t ta) { uint8_t tvar; tvar = (uint8_t) ta; PRINTF("usr_timer_cb: tvar=%d now = %ld ticks\n", tvar, timer_systime()); LED_TOGGLE(1); /* restart timer afer 1000ms */ return MSEC(1000); }
void upm_delay_ms(int time){ #if defined(linux) usleep(1000 * time); #elif defined(CONFIG_BOARD_ARDUINO_101) || defined(CONFIG_BOARD_ARDUINO_101_SSS) || defined(CONFIG_BOARD_QUARK_D2000_CRB) struct nano_timer timer; void *timer_data[1]; nano_timer_init(&timer, timer_data); nano_timer_start(&timer, MSEC(time)); nano_timer_test(&timer, TICKS_UNLIMITED); #endif }
static void blink(Blinker *self, int flag) { if(self->period > 0) { if(flag) { SYNC(self->lcd, segmentOn, self->segment); } else { SYNC(self->lcd, segmentOff, self->segment); } AFTER(MSEC(self->period), self, blink, !flag); // BEFORE(MSEC(self->period), self, blink, nothing); } }
/** * Main scheduler routine in RR policy implmentation * * @param * @return next_vcpuid */ int sched_rr_do_schedule(uint64_t *expiration) { uint32_t pcpu = smp_processor_id(); /* TODO:(igkang) change type to bool */ struct rq_entry_rr *next_entry = NULL; bool is_switching_needed = false; int next_vcpuid = VCPUID_INVALID; /* check pending attach list * then attach them to runqueue_rr */ /* TODO:(igkang) write code to attach pending attach requests */ /* TODO:(igkang) improve logical code structure to make it easier to read */ /* determine next vcpu to be run * - if there is an detach-pending vcpu than detach it. */ if (current[pcpu] == NULL) { /* No vCPU is running */ if (!LIST_IS_EMPTY(&runqueue_rr[pcpu])) { /* and there are some vcpus waiting */ is_switching_needed = true; } } else { /* There's a vCPU currently running */ struct rq_entry_rr *current_entry = NULL; /* put current entry back to runqueue_rr */ current_entry = LIST_ENTRY(struct rq_entry_rr, current[pcpu], head); LIST_ADDTAIL(current[pcpu], &runqueue_rr[pcpu]); /* let's switch as tick is over */ current_entry->state = WAITING; current[pcpu] = NULL; is_switching_needed = true; } /* update scheduling-related data (like tick) */ if (is_switching_needed) { /* move entry from runqueue_rr to current */ current[pcpu] = runqueue_rr[pcpu].next; LIST_DELINIT(current[pcpu]); next_entry = LIST_ENTRY(struct rq_entry_rr, current[pcpu], head); *expiration = timer_get_timenow() + MSEC(1) * (uint64_t) next_entry->tick_reset_val; } /* vcpu of current entry will be the next vcpu */ if (current[pcpu] != NULL) { next_entry = LIST_ENTRY(struct rq_entry_rr, current[pcpu], head); next_entry->state = RUNNING; /* set return next_vcpuid value */ next_vcpuid = next_entry->vcpuid; }
static inline uint8_t wait_for_ack(bool broadcast, bool ack_required) { if (broadcast || !ack_required) { return MAC_TX_OK; } if (nano_sem_take(&ack_lock, MSEC(10)) == 0) { nano_sem_init(&ack_lock); } if (!ack_received) { return MAC_TX_NOACK; } return MAC_TX_OK; }
int main(void) { timer_hdl_t th; uint8_t ta; /* init peripherals */ xmpl_init(); ta = 42; th = timer_start ( usr_timer_cb, MSEC(1000), (timer_arg_t) ta); while(1) { /*todo: add sleep macros here */ } }
void main(void) { struct device *gpiob; gpiob = device_get_binding(PORT); gpio_pin_configure(gpiob, PIN, GPIO_DIR_IN | GPIO_INT | EDGE | PULL_UP); gpio_init_callback(&gpio_cb, button_pressed, BIT(PIN)); gpio_add_callback(gpiob, &gpio_cb); gpio_pin_enable_callback(gpiob, PIN); while (1) { int val = 0; gpio_pin_read(gpiob, PIN, &val); PRINT("GPIO val: %d\n", val); task_sleep(MSEC(500)); } }
int bt_enable(bt_ready_cb_t cb) { struct device *gpio; int ret; BT_DBG(""); gpio = device_get_binding(CONFIG_GPIO_DW_0_NAME); if (!gpio) { BT_ERR("Cannot find %s", CONFIG_GPIO_DW_0_NAME); return -ENODEV; } ret = gpio_pin_configure(gpio, NBLE_RESET_PIN, GPIO_DIR_OUT); if (ret) { BT_ERR("Error configuring pin %d", NBLE_RESET_PIN); return -ENODEV; } /* Reset hold time is 0.2us (normal) or 100us (SWD debug) */ ret = gpio_pin_write(gpio, NBLE_RESET_PIN, 0); if (ret) { BT_ERR("Error pin write %d", NBLE_RESET_PIN); return -EINVAL; } ret = gpio_pin_configure(gpio, NBLE_BTWAKE_PIN, GPIO_DIR_OUT); if (ret) { BT_ERR("Error configuring pin %d", NBLE_BTWAKE_PIN); return -ENODEV; } ret = gpio_pin_write(gpio, NBLE_BTWAKE_PIN, 1); if (ret) { BT_ERR("Error pin write %d", NBLE_BTWAKE_PIN); return -EINVAL; } /** * NBLE reset is achieved by asserting low the SWDIO pin. * However, the BLE Core chip can be in SWD debug mode, * and NRF_POWER->RESET = 0 due to, other constraints: therefore, * this reset might not work everytime, especially after * flashing or debugging. */ /* sleep 1ms depending on context */ switch (sys_execution_context_type_get()) { case NANO_CTX_FIBER: fiber_sleep(MSEC(1)); break; case NANO_CTX_TASK: task_sleep(MSEC(1)); break; default: BT_ERR("ISR context is not supported"); return -EINVAL; } ret = nble_open(); if (ret) { return ret; } ret = gpio_pin_write(gpio, NBLE_RESET_PIN, 1); if (ret) { BT_ERR("Error pin write %d", NBLE_RESET_PIN); return -EINVAL; } /* Set back GPIO to input to avoid interfering with external debugger */ ret = gpio_pin_configure(gpio, NBLE_RESET_PIN, GPIO_DIR_IN); if (ret) { BT_ERR("Error configuring pin %d", NBLE_RESET_PIN); return -ENODEV; } bt_ready_cb = cb; return 0; }
/** * @brief * Internal session cpu time decoding routine. * * @param[in] job - a job pointer. * * @return ulong * @retval sum of all cpu time consumed for all tasks executed by the job, in seconds, * adjusted by cputfactor. * */ static unsigned long cput_sum(job *pjob) { static char id[] = "cput_sum"; ulong cputime; mtime_t addtime; int i, ret; int nps = 0; int taskprocs; proc_t *pp; pbs_task *ptask; ulong tcput; struct jresourcecpu jcpu; cputime = 0; for (ptask = (pbs_task *)GET_NEXT(pjob->ji_tasks); ptask != NULL; ptask = (pbs_task *)GET_NEXT(ptask->ti_jobtask)) { id_t jid = ptask->ti_qs.ti_u.ti_ext.ti_jid; /* DEAD task */ if (ptask->ti_qs.ti_sid <= 1) { cputime += ptask->ti_cput; continue; } /* check the job time */ if (jid > 0) { ret = getresourcej(jid, CURR_CPU, (long long)&jcpu); if (ret == -1) { if (errno != ESRCH) { sprintf(log_buffer, "getresourcej: jid %d " "task %08.8X", jid, ptask->ti_qs.ti_task); log_joberr(errno, id, log_buffer, pjob->ji_qs.ji_jobid); } } else { tcput = MSEC(jcpu.jr_cpu); if (tcput > ptask->ti_cput) ptask->ti_cput = tcput; cputime += ptask->ti_cput; DBPRT(("%s: task %08.8X jid %d " "jcpu %ld cput %lu total %lu\n", id, ptask->ti_qs.ti_task, jid, tcput, ptask->ti_cput, cputime)) continue; } } tcput = 0; taskprocs = 0; for (i=0; i<nproc; i++) { pp = &proct[i]; if (BOGUS_PROC(pp)) continue; /* is this process part of the task? */ if (ptask->ti_qs.ti_sid != pp->p_sid && ptask->ti_qs.ti_u.ti_ext.ti_parent != pp->p_pid) continue; nps++; taskprocs++; DBPRT(("%s: task %08.8X jid %d ses %d pid %d ppid %d ", id, ptask->ti_qs.ti_task, jid, pp->p_sid, pp->p_pid, pp->p_ppid)) if (pp->p_task.t_stat == SZOMB) { /* get zombie time only if top process */ if ((pp->p_sid == pp->p_pid) || (pp->p_ppid == mom_pid)) { addtime = pp->p_hcutime+pp->p_hcstime; DBPRT(("cput %lu ", CKSEC(addtime))) } DBPRT(("(zombie)\n")) } else {
#include <stdio.h> #include <stdlib.h> #include <strings.h> #include <unistd.h> #include <sys/time.h> #include <netinet/in.h> #include <linux/types.h> #include <linux/netfilter.h> /* for NF_ACCEPT */ #include <libnetfilter_queue/libnetfilter_queue.h> #define MICRO_SECONDS 1000000LL #define TO_MICRO(tv) (tv->tv_sec * MICRO_SECONDS + tv->tv_usec) #define MSEC(X) (X*1000) static int sleep_for_mode = MSEC(70); /* the maximum usleep can sleep */ #define WAIT_MAX 1000000 /* convert the time to microseconds and return the diff */ static long long diff_time(struct timeval *packet, struct timeval *now) { unsigned long long packet_time = TO_MICRO(packet); unsigned long long now_time = TO_MICRO(now); return now_time - packet_time; } static int cb(struct nfq_q_handle *qh, struct nfgenmsg *nfmsg, struct nfq_data *nfa, void *data)
* Created: 2014-03-03 18:05:51 * Author: SIMON */ #include <avr/io.h> #include "GUI.h" #include "helper.h" #include "PulseGene.h" void repeat(HELP* self, int incordec){ PULSEGEN* pulse; if(self->gui->pulseUsed == 0){ pulse = self->gui->pulse1; }else{ pulse = self->gui->pulse2; } if(self->firstpress){ self->firstpress = 0; AFTER(MSEC(1000), self, repeat, 0); } if((((PINB >> 6) & 1) == 0 && incordec == 0)){ //Up SYNC(pulse, pulseInc, 0); SYNC(self->gui, update, 0); AFTER(MSEC(400), self, repeat, 0); }else if (((PINB >> 7) == 0) && incordec == 1){ //Down SYNC(pulse, pulseDec, 0); SYNC(self->gui, update, 0); AFTER(MSEC(400), self, repeat, 1); } }