static void send_request(void *arg) { struct deluge_object *obj; struct deluge_msg_request request; obj = (struct deluge_object *)arg; request.cmd = DELUGE_CMD_REQUEST; request.pagenum = obj->current_rx_page; request.version = obj->pages[request.pagenum].version; request.request_set = ~obj->pages[obj->current_rx_page].packet_set; request.object_id = obj->object_id; PRINTF("Sending request for page %d, version %u, request_set %u\n", request.pagenum, request.version, request.request_set); packetbuf_copyfrom(&request, sizeof(request)); unicast_send(&deluge_uc, &obj->summary_from); /* Deluge R.2 */ if(++obj->nrequests == CONST_LAMBDA) { /* XXX check rate here too. */ obj->nrequests = 0; transition(DELUGE_STATE_MAINTAIN); } else { ctimer_reset(&rx_timer); } }
/*---------------------------------------------------------------*/ static void sample_fun(void) { ctimer_reset(&ct); ctimer_restart(&reset_timer); MPU_status = mpu_sample_all(&sample_data); if (MPU_status != 0) { PRINTF("%d,%d,%d,%d,%d,%d,%d\n",sample_data.data.accel_x,sample_data.data.accel_y,sample_data.data.accel_z,sample_data.data.tp,sample_data.data.gyro_x,sample_data.data.gyro_y,sample_data.data.gyro_z); // sending acceleration data mpu_get_acc(&sample_data,&data_sample); app_conn_send((uint8_t*)&data_sample,MPU_DATA_ACC_GYRO_SIZE); // sending gyro data mpu_get_gyro(&sample_data,&data_sample); app_conn_send((uint8_t*)&data_sample,MPU_DATA_ACC_GYRO_SIZE); // sending temperature data //mpu_get_tp(&sample_data,&tp_data_sample); //app_conn_send((uint8_t*)&tp_data_sample,MPU_DATA_TP_SIZE); } else { printf("Cannot sample data\n"); } }
/*---------------------------------------------------------------------------*/ static void timeout(void *data) { quarkX1000_i2c_write(&tx_data, sizeof(tx_data), LSM9DS0_I2C_ADDR); ctimer_reset(&timer); }
/* -------------------------------------------------------------------------------*/ static void handle_probe_timer(void *pt) { struct ip_addr_list_struct *ptr; uip_ipaddr_t *dest; ptr =(struct ip_addr_list_struct *)pt; //ptr =(list_t)pt; index=0; int rand_time=1*CLOCK_SECOND; //printf("probe timer handler\n"); //for(i=0; ptr[i].rank!=INFINITE_RANK && i<3; i++) //{ if (ptr[0].rank==INFINITE_RANK) return; dest=ptr[index].ipaddr; ctimer_set(&stagger_timer, rand_time, &handle_stagger_timer, dest); probe_number ++; if(probe_number<PROBE_NUM_THRESHOLD) { ctimer_reset(&probe_timer); } else { return; } }
static void reset_sample_timer(void) { //ctimer_set(&ct,SAMPLE_RATE,sample_fun,(void*)NULL); ctimer_reset(&ct); ctimer_restart(&reset_timer); has_reset = has_reset + 1; printf("reset sample fun ctimer %u\n",has_reset); }
/*---------------------------------------------------------------------------*/ static void timeout(void *data) { /* toggle pin state */ value = !value; quarkX1000_gpio_write(PIN, value); ctimer_reset(&timer); }
/* Periodic timer called every FRESHNESS_HALF_LIFE minutes */ static void periodic(void *ptr) { /* Age (by halving) freshness counter of all neighbors */ struct link_stats *stats; ctimer_reset(&periodic_timer); for(stats = nbr_table_head(link_stats); stats != NULL; stats = nbr_table_next(link_stats, stats)) { stats->freshness >>= 1; } }
/*---------------------------------------------------------------*/ static void scan_channel(void) { uint i = 0; int rx_power = 0; for(i = 11; i <= 26; i++) { cc2420_set_channel(i); rx_power = cc2420_rssi()-45; printf("Channel %u: %d dBm\n",i,rx_power); } printf("\n"); ctimer_reset(&ct); }
/*---------------------------------------------------------------------------*/ static void send(void *ptr) { struct stbroadcast_conn *c = ptr; /* DEBUGF(3, "stbroadcast: send()\n");*/ queuebuf_to_packetbuf(c->buf); broadcast_send(&c->c); ctimer_reset(&c->t); if(c->u->sent != NULL) { c->u->sent(c); } }
/*---------------------------------------------------------------------------*/ void ct_callback_sch_tick(void *ptr) { printf("===========in intterupt=======\n"); //printf("\t\t\t[schedule tick]\n"); schedule_tick(sch_process_current); //printf("<-\"crt\"-> sch[%s]---\n", sch_process_current->old->name); if (is_set_need_resched(sch_process_current)) { //printf("\t\t\t[schedule]\n"); schedule(); } ctimer_reset(&ct_sch_tick); }
static void handle_rxdma_timer(void *ptr) { uint16_t size; size = DMA0SZ; /* Note: loop requires that size is less or eq to RXBUFSIZE */ while(last_size != size) { /* printf("read: %c [%d,%d]\n", (unsigned char)rxbuf[RXBUFSIZE - last_size], */ /* last_size, size); */ uart1_input_handler((unsigned char)rxbuf[RXBUFSIZE - last_size]); last_size--; if(last_size == 0) last_size = RXBUFSIZE; } ctimer_reset(&rxdma_timer); }
/*---------------------------------------------------------------*/ static void sample_fun(void) { ctimer_reset(&ct); uint8_t MPU_status = 0; MPU_status = mpu_sample_acc(&sample_data); if (MPU_status != 0) { PRINTF("%d,%d,%d\n",sample_data.data.x,sample_data.data.y,sample_data.data.z); app_conn_send((uint8_t*)&sample_data,MPU_DATA_ACC_GYRO_SIZE); } else { printf("Cannot sample data\n"); } }
static void handle_rxdma_timer(void *ptr) { uint16_t size; size = DMA0SZ; /* Note: loop requires that size is less or eq to RXBUFSIZE */ while(last_size != size) { uart0_input_handler((unsigned char)rxbuf[RXBUFSIZE - last_size]); last_size--; if(last_size == 0) { last_size = RXBUFSIZE; } } ctimer_reset(&rxdma_timer); }
/*---------------------------------------------------------------*/ static void sample_fun(void) { ctimer_reset(&ct); ctimer_restart(&reset_timer); ADC_status = adxl_sample(&sample); if (ADC_status == 1) app_conn_send((uint8_t*)&sample,ADXL_DATA_SIZE); PRINTF("%u,%u,%u,%u\n",sample.x.data,sample.y.data,sample.z.data,sample.vref.data); }
static void sample_fun(void) { ctimer_reset(&ct); uint8_t i; for(i = 0; i < 6; i++) { data_buf[i] = sinI(counter); counter++; } app_conn_send((uint8_t *)data_buf,6*sizeof(int8_t)); //printf("%d %d %d %d %d %d\n",data_buf[0],data_buf[1],data_buf[2],data_buf[3],data_buf[4],data_buf[5]); //printf("%s %s\n",ct.p->name,ct.next->p->name); }
/*---------------------------------------------------------------------------*/ static void handle_periodic_timer(void *ptr) { rpl_purge_routes(); rpl_recalculate_ranks(); /* handle DIS */ #if RPL_DIS_SEND next_dis++; if(rpl_get_any_dag() == NULL && next_dis >= RPL_DIS_INTERVAL) { next_dis = 0; dis_output(NULL); } #endif ctimer_reset(&periodic_timer); }
void blink_looper() { #if PLATFORM_HAS_LEDS if(blink_state){ leds_off(BLINKER_PIN); } else { leds_on(BLINKER_PIN); } #else printf("Platform does not support LED. Unique ID: %u", OTA_EXAMPLE_UNIQUE_ID); #endif blink_state = !blink_state; ctimer_reset( &blink_timer ); }
/*---------------------------------------------------------------------------*/ static void timeout(void *data) { uint8_t value_in; /* toggle pin state */ value = !value; quarkX1000_gpio_write(PIN_OUTPUT, value); quarkX1000_gpio_read(PIN_INPUT, &value_in); if (value == value_in) printf("GPIO pin value match!\n"); else printf("GPIO pin value DOESN'T match!\n"); ctimer_reset(&timer); }
static void tx_callback(void *arg) { struct deluge_object *obj; obj = (struct deluge_object *)arg; if(obj->current_tx_page >= 0 && obj->tx_set) { send_page(obj, obj->current_tx_page); /* Deluge T.2. */ if(obj->tx_set) { packetbuf_set_attr(PACKETBUF_ATTR_PACKET_TYPE, PACKETBUF_ATTR_PACKET_TYPE_STREAM); ctimer_reset(&tx_timer); } else { packetbuf_set_attr(PACKETBUF_ATTR_PACKET_TYPE, PACKETBUF_ATTR_PACKET_TYPE_STREAM_END); obj->current_tx_page = -1; transition(DELUGE_STATE_MAINTAIN); } } }
/*---------------------------------------------------------------------------*/ static void handle_periodic_timer(void *ptr) { rpl_purge_routes(); rpl_recalculate_ranks(); /* handle DIS */ #if UIP_ND6_ENGINE != UIP_ND6_ENGINE_RPL #if RPL_DIS_SEND next_dis++; if(rpl_get_any_dag() == NULL && next_dis >= RPL_DIS_INTERVAL) { next_dis = 0; dis_output(NULL); } #endif #else if(rpl_get_any_dag() == NULL && stimer_expired(&uip_ds6_timer_dis)) { discount++; dis_output(NULL); stimer_set(&uip_ds6_timer_dis, rs_rtx_time(discount)); } #endif ctimer_reset(&periodic_timer); }
/*---------------------------------------------------------------------------*/ void execute_select_query(void * data) { int i; int retval; char all_true; uint16_t current_epoch, nepochs; field_data_t * field_data; attr_entry_t * attr_entry; expression_data_t * expr_data; qtable_entry_t * qtable_entry = (qtable_entry_t *)data; squery_data_t * squery_data = (squery_data_t *)qtable_entry->qptr; current_epoch = ntoh_leuint16(&squery_data->current_epoch); nepochs = ntoh_leuint16(&squery_data->nepochs); PRINTF("[DEBUG]: Executing query qid %d\n", squery_data->qid); field_data = (field_data_t *)(squery_data + 1); /* Read all needed data. */ for(i=0; i<squery_data->nfields; i++, field_data++) { attr_entry = get_attr_entry(field_data->id); if(attr_entry && attr_entry->get_data) { attr_entry->get_data(&(field_data->data)); } else { PRINTF("[DEBUG]: Warning! get_data not defined attr_id %d\n", field_data->id); } } all_true = TRUE; expr_data = (expression_data_t *)field_data; /* Evaluate expressions. * NOTE: Currently, we consider only about simple conjunctions. */ for(i=0; i<squery_data->nexprs; i++, expr_data++) { if(!evaluate_expression(expr_data)) { PRINTF("[DEBUG]: Expression evalution faild. qid %d\n",squery_data->qid); all_true = FALSE; break; } } if(all_true) { /* Send results to query root. */ packetbuf_clear(); retval = create_query_result(squery_data, packetbuf_dataptr(), 64); if(retval > 0) { packetbuf_set_datalen(retval); if(send_data) { /* SendResult(squery_data->qroot); */ send_data(&qtable_entry->qroot); } } else { PRINTF("[DEBUG]: Error! sending data failed qid %d\n", squery_data->qid); } } current_epoch++; hton_leuint16(&squery_data->current_epoch, current_epoch); if(nepochs == 0 || nepochs > current_epoch) { ctimer_reset(&squery_data->timer); } else { PRINTF("[DEBUG]: Deleting query. qid %d\n", squery_data->qid); remove_query_entry(squery_data->qid, &qtable_entry->qroot); qfree(squery_data); } leds_toggle(LEDS_YELLOW); }
//Ctimer callback function void do_timeout2() { ctimer_reset(&timer_ctimer); printf("\n\rProcess 2: CTimer callback called"); counter_ctimer++; }
/*---------------------------------------------------------------------------*/ static void handle_scan_timer(struct net_buf *mbuf, void *p) { if(!scan) { return; } if(scan > 1) { int callback_status; callback_status = callback(current_channel, NULL, CALLBACK_ACTION_CHANNEL_DONE); if(callback_status == CALLBACK_STATUS_FINISHED) { end_scan(); return; } else if(callback_status == CALLBACK_STATUS_NEED_MORE_TIME) { ctimer_reset(&scan_timer); return; } } scan++; #if DISABLE_NETSELECT_RANDOM_CHANNEL if(current_channel == 26) { /* Last channel has been scanned. Report that the process is over. */ end_scan(); return; } if(current_channel == 0) { current_channel = 11; } else { current_channel++; } #else /* DISABLE_NETSELECT_RANDOM_CHANNEL */ if(channel_index > (CHANNEL_HIGH - CHANNEL_LOW)) { /* Last channel has been scanned. Report that the process is over. */ end_scan(); return; } if(current_channel == 0) { /* new scan, randomize channels */ int i; int j; channel_index = 0; /* Initialize a random list as shown by Durstenfelds' Fisher–Yates shuffle. */ for(i = 0; i <= (CHANNEL_HIGH - CHANNEL_LOW); i++) { j = random_rand() % (i + 1); if(j != i) { channel_list[i] = channel_list[j]; } channel_list[j] = i + CHANNEL_LOW; } #if DEBUG PRINTF("New netselect search: channel order: "); for(i = 0; i <= (CHANNEL_HIGH - CHANNEL_LOW); i++) { PRINTF("%d ", channel_list[i]); } PRINTF("\n"); #endif } current_channel = channel_list[channel_index++]; #endif /* DISABLE_NETSELECT_RANDOM_CHANNEL */ NETSTACK_RADIO.set_value(RADIO_PARAM_RX_MODE, 0); NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, current_channel); handler_802154_send_beacon_request(); ctimer_reset(&scan_timer); }