static void timer_timeout(int argc, uint32_t itimer) { #ifndef CONFIG_CAN_PASS_STRUCTS /* On many small machines, pointers are encoded and cannot be simply cast from * uint32_t to struct tcb_s*. The following union works around this (see wdogparm_t). */ union { FAR struct posix_timer_s *timer; uint32_t itimer; } u; u.itimer = itimer; /* Send the specified signal to the specified task. Increment the reference * count on the timer first so that will not be deleted until after the * signal handler returns. */ u.timer->pt_crefs++; timer_sigqueue(u.timer); /* Release the reference. timer_release will return nonzero if the timer * was not deleted. */ if (timer_release(u.timer)) { /* If this is a repetitive timer, the restart the watchdog */ timer_restart(u.timer, itimer); } #else /* (casting to uintptr_t first eliminates complaints on some architectures * where the sizeof uint32_t is different from the size of a pointer). */ FAR struct posix_timer_s *timer = (FAR struct posix_timer_s *)((uintptr_t)itimer); /* Send the specified signal to the specified task. Increment the reference * count on the timer first so that will not be deleted until after the * signal handler returns. */ timer->pt_crefs++; timer_sigqueue(timer); /* Release the reference. timer_release will return nonzero if the timer * was not deleted. */ if (timer_release(timer)) { /* If this is a repetitive timer, the restart the watchdog */ timer_restart(timer, itimer); } #endif }
PROCESS_THREAD(ir_receiver_process, ev, data) { PROCESS_BEGIN(); while(1) { PROCESS_WAIT_EVENT(); if(ev == PROCESS_EVENT_POLL) { if(ir_repeat) { PRINTF("Got repeat signal \n"); ir_repeat = 0; } else { if(*(int32_t*)ir_prev_data != *(int32_t*)ir_last_data || timer_expired(&ir_rep_timer) || to_be_repeated()) { memcpy(ir_prev_data, ir_last_data, 4); timer_restart(&ir_rep_timer); PRINTF("Got new command %d,%d,%d,%d!\n", ir_last_data[0],ir_last_data[1],ir_last_data[2],ir_last_data[3]); broadcast_value(30); } else { timer_restart(&ir_rep_timer); } } } } PROCESS_END(); }
/*************************************************************************************************** *FunctionName: activityFresh *Description: 界面刷新 *Input: *Output: *Return: *Author: xsx *Date: 2016年12月21日09:01:16 ***************************************************************************************************/ static void activityFresh(void) { S_WaitPageData->cnt++; if(S_WaitPageData->cnt % 5 == 0) { /*是否插卡*/ if(GetCardState() == CardIN) { stopPlay(); S_WaitPageData->currenttestdata->statues = status_preread; startActivity(createPreReadCardActivity, NULL); return; } /*时间到,未插卡,返回*/ else if(TimeOut == timer_expired(&(S_WaitPageData->timer2))) { AddNumOfSongToList(11, 0); timer_restart(&(S_WaitPageData->timer2)); } } //如果排队中,有卡接近测试时间,则删除当前测试创建任务,返回 if(GetMinWaitTime() < 40) { stopPlay(); MotorMoveTo(1, 2, MaxLocation, FALSE); DeleteCurrentTest(); backToActivity(paiduiActivityName); } }
static inline void _mqttclient_handle_communication_error(void) { _mqttclient_signal_disconnected(); if (current_state == MQTTCLIENT_BROKER_CONNECTING) { /* Another disconnect in reconnecting phase. Shut down for a while, then try again. */ timer_restart(&_disconnected_wait_timer); update_state(MQTTCLIENT_BROKER_DISCONNECTED); } else if (current_state != MQTTCLIENT_BROKER_DISCONNECTED_WAIT) { /* We are not waiting for atother reconnect try. */ update_state(MQTTCLIENT_BROKER_DISCONNECTED); _mqtt.state = UMQTT_STATE_INIT; } }
void main(void) { setup(); sei(); // enable interrupts // This loop runs forever // it can be interrupted at any point by a TWI event for (;;) { dust_process(); // accumulates the dust variables if(timer_expired()){ STATUS_LED_TOGGLE(); dust_clear(); timer_restart(); } } }
/*---------------------------------------------------------------------------*/ void httpd_appcall(void *state) { struct httpd_state *s = (struct httpd_state *)state; if(uip_closed() || uip_aborted() || uip_timedout()) { if(s != NULL) { if(s->fd >= 0) { cfs_close(s->fd); s->fd = -1; } memb_free(&conns, s); } } else if(uip_connected()) { s = (struct httpd_state *)memb_alloc(&conns); if(s == NULL) { uip_abort(); webserver_log_file(&uip_conn->ripaddr, "reset (no memory block)"); return; } tcp_markconn(uip_conn, s); PSOCK_INIT(&s->sin, (uint8_t *)s->inputbuf, sizeof(s->inputbuf) - 1); PSOCK_INIT(&s->sout, (uint8_t *)s->inputbuf, sizeof(s->inputbuf) - 1); PT_INIT(&s->outputpt); s->fd = -1; s->state = STATE_WAITING; timer_set(&s->timer, CLOCK_SECOND * 10); handle_connection(s); } else if(s != NULL) { if(uip_poll()) { if(timer_expired(&s->timer)) { uip_abort(); if(s->fd >= 0) { cfs_close(s->fd); s->fd = -1; } memb_free(&conns, s); webserver_log_file(&uip_conn->ripaddr, "reset (timeout)"); } } else { timer_restart(&s->timer); } handle_connection(s); } else { uip_abort(); } }
/** * @brief Sets the desired LED behaviour * * Led thread handle two functionalities: * - the led state, * - diagnostic button. * The led state service is driving from Proximetry agent. The led can be set to one of three state ON,OFF,BLINKING. * The diagnostic button service allows to determine the end node connection state without console inspection. * The diagnostic button distinguish three states: * - end node disconnected from BR - led blinking with 5Hz frequency for 5s, * - end node connected with BR only - led blinking with 2Hz frequency for 5s , * - end node agent connected to Cloud Serve - led is On for 5s. */ PROCESS_THREAD(led_process, ev, data) { UNUSED(data); UNUSED(ev); PROCESS_BEGIN(); timer_set(&led_timer, LED_TOGGLE_INTERVAL); while(1) { diagnostic_button_service(); if (diagnostic_button_service_is_active()) { diagnostic_button_led_service(); } else { if (!timer_expired(&led_timer)) goto end; timer_restart(&led_timer); switch (get_settings()->led0_state) { case LED_OFF: set_led_state(LED_OFF); break; case LED_ON: set_led_state(LED_ON); break; case LED_BLINK: led_toggle(); break; default: ; } } end: PROCESS_PAUSE(); } PROCESS_END(); }
int main(void) { struct gpio_pin heartbeat_led; struct timer heartbeat_timer; struct aparser_ctx uart_parser; cli(); gpio_init_output(&yellow_led, &PORTC, 0, false); gpio_init_output(&heartbeat_led, &PORTB, 5, false); timer_set_period_ms(&heartbeat_timer, 500); servo_init(); uart_init(); systick_init(); aparser_init(&uart_parser, 2); aparser_register_commands(&uart_parser, uart_parser_item); wdt_enable(WDTO_500MS); sei(); for (;;) { uint8_t data; if (uart_getchar(&data) == UART_RETCODE_SUCCESS) { uart_putchar(data); aparser_update_and_execute(&uart_parser, data); } if (timer_has_expired(&heartbeat_timer)) { timer_restart(&heartbeat_timer); gpio_toggle(&heartbeat_led); } wdt_reset(); } return 0; }
int main (int argc , char **argv) { int i = 0; printf ("My PID : %d\n", getpid ()); tmlib_init (); char task[4] = "TS"; void* id = start_timer (10 * tm_get_ticks_per_second (), NULL, (void (*) (void *))&Just_log, 0); void* id1 = start_timer ((11) * tm_get_ticks_per_second (), NULL, (void (*) (void *))&Just_log, 0); setup_timer (&id2, exp, NULL); mod_timer (id2, 2); #if 1 while (1) { printf ("Remaining time id (10 secs): %u id1 (1 min) : %u \n",timer_get_remaining_time(id) / tm_get_ticks_per_second () ,timer_get_remaining_time(id1) / tm_get_ticks_per_second ()); sleep (3); } #endif timer_restart (id1); while (1) { sleep (1); printf ("Remaining time id (10 secs): %u id1 (1 min) : %u \n",timer_get_remaining_time(id) / tm_get_ticks_per_second () ,timer_get_remaining_time(id1) / tm_get_ticks_per_second ()); } for ( i = 0; i <=25; i++) { task[2] = (char)(97+i); task_create (task, 10,0 ,32000 + i, &(start_rout2), NULL, (void *)(i+1), &rettskid[i]); } sleep_forever (); }
/*---------------------------------------------------------------------------*/ void httpd_appcall(void *state) { struct httpd_state *s = (struct httpd_state *)state; if(uip_closed() || uip_aborted() || uip_timedout()) { if(s != NULL) { memb_free(&conns, s); } } else if(uip_connected()) { s = (struct httpd_state *)memb_alloc(&conns); if(s == NULL) { uip_abort(); return; } tcp_markconn(uip_conn, s); PSOCK_INIT(&s->sin, s->inputbuf, sizeof(s->inputbuf) - 1); PSOCK_INIT(&s->sout, s->inputbuf, sizeof(s->inputbuf) - 1); PT_INIT(&s->outputpt); s->state = STATE_WAITING; timer_set(&s->timer, CLOCK_SECOND * 100); handle_connection(s); } else if(s != NULL) { if(uip_poll()) { if(timer_expired(&s->timer)) { uip_abort(); memb_free(&conns, s); } } timer_restart(&s->timer); handle_connection(s); } else { uip_abort(); } }
/*---------------------------------------------------------------------------*/ void etimer_restart(struct etimer *et) { timer_restart(&et->timer); add_timer(et); }
/*---------------------------------------------------------------------------*/ static PT_THREAD(ajax_call(struct httpd_state *s, char *ptr)) { static struct timer t; static int iter; static char buf[128]; static uint8_t numprinted; PSOCK_BEGIN(&s->sout); /*TODO:pick up time from ? parameter */ timer_set(&t, 2*CLOCK_SECOND); iter = 0; while(1) { iter++; #if CONTIKI_TARGET_SKY SENSORS_ACTIVATE(sht11_sensor); SENSORS_ACTIVATE(light_sensor); numprinted = snprintf(buf, sizeof(buf), "t(%d);h(%d);l1(%d);l2(%d);", sht11_sensor.value(SHT11_SENSOR_TEMP), sht11_sensor.value(SHT11_SENSOR_HUMIDITY), light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC), light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR)); SENSORS_DEACTIVATE(sht11_sensor); SENSORS_DEACTIVATE(light_sensor); #elif CONTIKI_TARGET_MB851 SENSORS_ACTIVATE(acc_sensor); numprinted = snprintf(buf, sizeof(buf),"t(%d);ax(%d);ay(%d);az(%d);", temperature_sensor.value(0), acc_sensor.value(ACC_X_AXIS), acc_sensor.value(ACC_Y_AXIS), acc_sensor.value(ACC_Z_AXIS)); SENSORS_DEACTIVATE(acc_sensor); #elif CONTIKI_TARGET_REDBEE_ECONOTAG { uint8_t c; adc_reading[8]=0; adc_init(); while (adc_reading[8]==0) adc_service(); adc_disable(); numprinted = snprintf(buf, sizeof(buf),"b(%u);adc(%u,%u,%u,%u,%u,%u,%u,%u);", 1200*0xfff/adc_reading[8],adc_reading[0],adc_reading[1],adc_reading[2],adc_reading[3],adc_reading[4],adc_reading[5],adc_reading[6],adc_reading[7]); } #elif CONTIKI_TARGET_MINIMAL_NET static uint16_t c0=0x3ff,c1=0x3ff,c2=0x3ff,c3=0x3ff,c4=0x3ff,c5=0x3ff,c6=0x3ff,c7=0x3ff; numprinted = snprintf(buf, sizeof(buf), "t(%d);b(%u);v(%u);",273+(rand()&0x3f),3300-iter/10,iter); numprinted += snprintf(buf+numprinted, sizeof(buf)-numprinted,"adc(%u,%u,%u,%u,%u,%u,%u,%u);",c0,c1,c2,c3,c4,c5,c6,c7); c0+=(rand()&0xf)-8; c1+=(rand()&0xf)-8; c2+=(rand()&0xf)-7; c3+=(rand()&0x1f)-15; c4+=(rand()&0x3)-1; c5+=(rand()&0xf)-8; c6+=(rand()&0xf)-8; c7+=(rand()&0xf)-8; if (iter==1) { static const char httpd_cgi_ajax11[] HTTPD_STRING_ATTR = "wt('Minimal-net "; static const char httpd_cgi_ajax12[] HTTPD_STRING_ATTR = "');"; numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax11); #if WEBSERVER_CONF_PRINTADDR /* Note address table is filled from the end down */ {int i; for (i=0; i<UIP_DS6_ADDR_NB;i++) { if (uip_ds6_if.addr_list[i].isused) { numprinted += httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr, buf + numprinted); break; } } } #endif numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax12); } #elif CONTIKI_TARGET_AVR_ATMEGA128RFA1 { uint8_t i;int16_t tmp,bat; BATMON = 16; //give BATMON time to stabilize at highest range and lowest voltage /* Measure internal temperature sensor, see atmega128rfa1 datasheet */ /* This code disabled by default for safety. Selecting an internal reference will short it to anything connected to the AREF pin */ #if 1 ADCSRB|=1<<MUX5; //this bit buffered till ADMUX written to! ADMUX =0xc9; // Select internal 1.6 volt ref, temperature sensor ADC channel ADCSRA=0x85; //Enable ADC, not free running, interrupt disabled, clock divider 32 (250 KHz@ 8 MHz) // while ((ADCSRB&(1<<AVDDOK))==0); //wait for AVDD ok // while ((ADCSRB&(1<<REFOK))==0); //wait for ref ok ADCSRA|=1<<ADSC; //Start throwaway conversion while (ADCSRA&(1<<ADSC)); //Wait till done ADCSRA|=1<<ADSC; //Start another conversion while (ADCSRA&(1<<ADSC)); //Wait till done tmp=ADC; //Read adc tmp=11*tmp-2728+(tmp>>2); //Convert to celcius*10 (should be 11.3*h, approximate with 11.25*h) ADCSRA=0; //disable ADC ADMUX=0; //turn off internal vref #endif /* Bandgap can't be measured against supply voltage in this chip. */ /* Use BATMON register instead */ for ( i=16; i<31; i++) { BATMON = i; if ((BATMON&(1<<BATMON_OK))==0) break; } bat=2550-75*16-75+75*i; //-75 to take the floor of the 75 mv transition window static const char httpd_cgi_ajax10[] HTTPD_STRING_ATTR ="t(%u),b(%u);adc(%d,%d,%u,%u,%u,%u,%u,%lu);"; numprinted = httpd_snprintf(buf, sizeof(buf),httpd_cgi_ajax10,tmp,bat,iter,tmp,bat,sleepcount,OCR2A,0,clock_time(),clock_seconds()); if (iter==1) { static const char httpd_cgi_ajax11[] HTTPD_STRING_ATTR = "wt('128rfa1 ["; static const char httpd_cgi_ajax12[] HTTPD_STRING_ATTR = "]');"; numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax11); #if WEBSERVER_CONF_PRINTADDR /* Note address table is filled from the end down */ {int i; for (i=0; i<UIP_DS6_ADDR_NB;i++) { if (uip_ds6_if.addr_list[i].isused) { numprinted += httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr, buf + numprinted); break; } } } #endif numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax12); } } #elif CONTIKI_TARGET_AVR_RAVEN { int16_t tmp,bat; #if 1 /* Usual way to get AVR supply voltage, measure 1.1v bandgap using Vcc as reference. * This connects the bandgap to the AREF pin, so enable only if there is no external AREF! * A capacitor may be connected to this pin to reduce reference noise. */ ADMUX =0x5E; //Select AVCC as reference, measure 1.1 volt bandgap reference. ADCSRA=0x87; //Enable ADC, not free running, interrupt disabled, clock divider 128 (62 KHz@ 8 MHz) ADCSRA|=1<<ADSC; //Start throwaway conversion while (ADCSRA&(1<<ADSC)); //Wait till done ADCSRA|=1<<ADSC; //Start another conversion while (ADCSRA&(1<<ADSC)); //Wait till done //bat=1126400UL/ADC; //Get supply voltage (factor nominally 1100*1024) bat=1198070UL/ADC; //My Raven ADCSRA=0; //disable ADC ADMUX=0; //turn off internal vref #else bat=3300; #endif tmp=420; static const char httpd_cgi_ajax10[] HTTPD_STRING_ATTR ="t(%u),b(%u);adc(%d,%d,%u,%u,%u,%u,%u,%lu);"; numprinted = httpd_snprintf(buf, sizeof(buf),httpd_cgi_ajax10,tmp,bat,iter,tmp,bat,sleepcount,OCR2A,0,clock_time(),clock_seconds()); if (iter<3) { static const char httpd_cgi_ajax11[] HTTPD_STRING_ATTR = "wt('Raven ["; static const char httpd_cgi_ajax12[] HTTPD_STRING_ATTR = "]');"; numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax11); #if WEBSERVER_CONF_PRINTADDR /* Note address table is filled from the end down */ {int i; for (i=0; i<UIP_DS6_ADDR_NB;i++) { if (uip_ds6_if.addr_list[i].isused) { numprinted += httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr, buf + numprinted); break; } } } #endif numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax12); } } //#elif CONTIKI_TARGET_IS_SOMETHING_ELSE #else { static const char httpd_cgi_ajax10[] HTTPD_STRING_ATTR ="v(%u);"; numprinted = httpd_snprintf(buf, sizeof(buf),httpd_cgi_ajax10,iter); if (iter==1) { static const char httpd_cgi_ajax11[] HTTPD_STRING_ATTR = "wt('Contiki Ajax "; static const char httpd_cgi_ajax12[] HTTPD_STRING_ATTR = "');"; numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax11); #if WEBSERVER_CONF_PRINTADDR /* Note address table is filled from the end down */ {int i; for (i=0; i<UIP_DS6_ADDR_NB;i++) { if (uip_ds6_if.addr_list[i].isused) { numprinted += httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr, buf + numprinted); break; } } } #endif numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax12); } } #endif #if CONTIKIMAC_CONF_COMPOWER #include "sys/compower.h" { //sl=compower_idle_activity.transmit/RTIMER_ARCH_SECOND; //sl=compower_idle_activity.listen/RTIMER_ARCH_SECOND; } #endif #if RIMESTATS_CONF_ON #include "net/rime/rimestats.h" static const char httpd_cgi_ajaxr1[] HTTPD_STRING_ATTR ="rime(%lu,%lu,%lu,%lu);"; numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajaxr1, rimestats.tx,rimestats.rx,rimestats.lltx-rimestats.tx,rimestats.llrx-rimestats.rx); #endif #if ENERGEST_CONF_ON { #if 1 /* Send on times in percent since last update. Handle 16 bit rtimer wraparound. */ /* Javascript must convert based on platform cpu, tx, rx power, e.g. 20ma*3v3=66mW*(% on time/100) */ static rtimer_clock_t last_send; rtimer_clock_t delta_time; static unsigned long last_cpu, last_lpm, last_listen, last_transmit; energest_flush(); delta_time=RTIMER_NOW()-last_send; if (RTIMER_CLOCK_LT(RTIMER_NOW(),last_send)) delta_time+=RTIMER_ARCH_SECOND; last_send=RTIMER_NOW(); static const char httpd_cgi_ajaxe1[] HTTPD_STRING_ATTR = "p(%lu,%lu,%lu,%lu);"; numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajaxe1, (100UL*(energest_total_time[ENERGEST_TYPE_CPU].current - last_cpu))/delta_time, (100UL*(energest_total_time[ENERGEST_TYPE_LPM].current - last_lpm))/delta_time, (100UL*(energest_total_time[ENERGEST_TYPE_TRANSMIT].current - last_transmit))/delta_time, (100UL*(energest_total_time[ENERGEST_TYPE_LISTEN].current - last_listen))/delta_time); last_cpu = energest_total_time[ENERGEST_TYPE_CPU].current; last_lpm = energest_total_time[ENERGEST_TYPE_LPM].current; last_transmit = energest_total_time[ENERGEST_TYPE_TRANSMIT].current; last_listen = energest_total_time[ENERGEST_TYPE_LISTEN].current; #endif #if 1 /* Send cumulative on times in percent*100 */ uint16_t cpp,txp,rxp; uint32_t sl,clockseconds=clock_seconds(); // energest_flush(); // sl=((10000UL*energest_total_time[ENERGEST_TYPE_CPU].current)/RTIMER_ARCH_SECOND)/clockseconds; sl=energest_total_time[ENERGEST_TYPE_CPU].current/RTIMER_ARCH_SECOND; cpp=(10000UL*sl)/clockseconds; // txp=((10000UL*energest_total_time[ENERGEST_TYPE_TRANSMIT].current)/RTIMER_ARCH_SECOND)/clockseconds; sl=energest_total_time[ENERGEST_TYPE_TRANSMIT].current/RTIMER_ARCH_SECOND; txp=(10000UL*sl)/clockseconds; // rxp=((10000UL*energest_total_time[ENERGEST_TYPE_LISTEN].current)/RTIMER_ARCH_SECOND)/clockseconds; sl=energest_total_time[ENERGEST_TYPE_LISTEN].current/RTIMER_ARCH_SECOND; rxp=(10000UL*sl)/clockseconds; static const char httpd_cgi_ajaxe2[] HTTPD_STRING_ATTR = "ener(%u,%u,%u);"; numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajaxe2,cpp,txp,rxp); #endif } #endif /* ENERGEST_CONF_ON */ PSOCK_SEND_STR(&s->sout, buf); timer_restart(&t); PSOCK_WAIT_UNTIL(&s->sout, timer_expired(&t)); } PSOCK_END(&s->sout); }
/*---------------------------------------------------------------------------*/ void uip_ds6_periodic(void) { /* This flag signals whether we allow or not to send a packet in the current * invocation. */ u8_t allow_output = 1; /* minimum lifetime */ min_lifetime = 0xFFFFFFFF; /* router with minimum lifetime */ min_defrt = NULL; /* Periodic processing on registrations */ for(locreg = uip_ds6_reg_list; locreg < uip_ds6_reg_list + UIP_DS6_REG_LIST_SIZE; locreg++) { if (locreg->isused) { if (stimer_expired(&locreg->reg_lifetime)) { uip_ds6_reg_rm(locreg); } else if (allow_output) { /* If no output is allowed, it is pointless to enter here in this invocation */ if (uip_ds6_if.registration_in_progress) { /* There is a registration in progress */ if ((locreg == uip_ds6_if.registration_in_progress) && (timer_expired(&locreg->registration_timer))) { /* We already sent a NS message for this address but there has been no response */ if(locreg->reg_count >= UIP_ND6_MAX_UNICAST_SOLICIT) { /* NUD failed. Signal the need for next-hop determination by deleting the * NCE (RFC 4861) */ uip_ds6_reg_rm(locreg); /* And then, delete neighbor and corresponding router (as hosts only keep * NCEs for routers in 6lowpan-nd) */ locnbr = uip_ds6_nbr_lookup(&locreg->defrt->ipaddr); uip_ds6_nbr_rm(locnbr); uip_ds6_defrt_rm(locreg->defrt); /* Since we are deleting a default router, we must delete also all * registrations with that router. * Be careful here, uip_ds6_reg_cleanup_defrt() modifies the value of locreg!*/ uip_ds6_reg_cleanup_defrt(locreg->defrt); /* We will also need to start sending RS, as specified in I-D.ietf-6lowpan-nd * for NUD failure case */ uip_ds6_send_rs(NULL); uip_ds6_if.registration_in_progress = NULL; } else { locreg->reg_count++; timer_restart(&locreg->registration_timer); uip_nd6_ns_output(&locreg->addr->ipaddr, &locreg->defrt->ipaddr, &locreg->defrt->ipaddr, 1, UIP_ND6_REGISTRATION_LIFETIME); } allow_output = 0; /* Prevent this invocation from sending anything else */ } } else { /* There are no registrations in progress, let's see this entry needs (re)registration * or deletion */ if ((locreg->state == REG_GARBAGE_COLLECTIBLE) || (locreg->state == REG_TO_BE_UNREGISTERED) || ((locreg->state == REG_REGISTERED) && (stimer_remaining(&locreg->reg_lifetime) < stimer_elapsed(&locreg->reg_lifetime)))) { /* Issue (re)registration */ uip_ds6_if.registration_in_progress = locreg; locreg->reg_count++; timer_set(&locreg->registration_timer, (uip_ds6_if.retrans_timer / 1000) * (CLOCK_SECOND /* FIXME @@@jwg!!!!*/+250)); if (locreg->state == REG_TO_BE_UNREGISTERED) { uip_nd6_ns_output(&locreg->addr->ipaddr, &locreg->defrt->ipaddr, &locreg->defrt->ipaddr, 1, 0); } else { uip_nd6_ns_output(&locreg->addr->ipaddr, &locreg->defrt->ipaddr, &locreg->defrt->ipaddr, 1, UIP_ND6_REGISTRATION_LIFETIME); } allow_output = 0; /* Prevent this invocation from sending anything else */ } } } } } /* Periodic processing on unicast addresses */ for(locaddr = uip_ds6_if.addr_list; locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) { if(locaddr->isused) { if((!locaddr->isinfinite) && (stimer_expired(&locaddr->vlifetime))) { uip_ds6_addr_rm(locaddr); } else if (allow_output) { if (stimer_remaining(&locaddr->vlifetime) < min_lifetime) { min_lifetime = stimer_remaining(&locaddr->vlifetime); min_defrt = locaddr->defrt; } } } } /* Periodic processing on default routers */ if (uip_ds6_defrt_choose() == NULL) { if (allow_output) { /* If default router list is empty, start sending RS */ uip_ds6_send_rs(NULL); allow_output = 0; /* Prevent this invocation from sending anything else */ } } else { for(locdefrt = uip_ds6_defrt_list; locdefrt < uip_ds6_defrt_list + UIP_DS6_DEFRT_NB; locdefrt++) { if((locdefrt->isused) && (!locdefrt->isinfinite)) { if (stimer_expired(&(locdefrt->lifetime))) { uip_ds6_defrt_rm(locdefrt); /* If default router list is empty, we will start sending RS in * the next invocation of ds6_periodic() */ } else { if (allow_output) { if (stimer_remaining(&locdefrt->lifetime) < min_lifetime) { min_lifetime = stimer_remaining(&locdefrt->lifetime); min_defrt = locdefrt; } } } } } } #if !UIP_CONF_ROUTER /* Periodic processing on prefixes */ for (locprefix = uip_ds6_prefix_list; locprefix < uip_ds6_prefix_list + UIP_DS6_PREFIX_NB; locprefix++) { if((locprefix->isused) && (!locprefix->isinfinite)) { if (stimer_expired(&locprefix->vlifetime)) { uip_ds6_prefix_rm(locprefix); } else if (allow_output) { if (stimer_remaining(&locprefix->vlifetime) < min_lifetime) { min_lifetime = stimer_remaining(&locprefix->vlifetime); min_defrt = locprefix->defrt; } } } } #endif /* !UIP_CONF_ROUTER */ #if CONF_6LOWPAN_ND_6CO /* Periodic processing on contexts */ for(loccontext = uip_ds6_addr_context_table; loccontext < uip_ds6_addr_context_table + SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS; loccontext++) { if(loccontext->state != NOT_IN_USE) { if (stimer_expired(&loccontext->vlifetime)) { if (loccontext->state != EXPIRED) { loccontext->state = IN_USE_UNCOMPRESS_ONLY; stimer_set(&loccontext->vlifetime, 2 * loccontext->defrt_lifetime); } else { uip_ds6_context_rm(loccontext); } } else if (allow_output) { if (stimer_remaining(&loccontext->vlifetime) < min_lifetime) { min_lifetime = stimer_remaining(&loccontext->vlifetime); min_defrt = loccontext->defrt; } } } } #endif /* CONF_6LOWPAN_ND_6CO */ /* Start sending RS well before the minimum of the lifetimes (def. router, * context, or prefix) expires */ if ((allow_output) && (min_lifetime < UIP_DS6_LIFETIME_THRESHOLD)) { /* Start sending RSs to the router with minimum lifetime (if possible) */ uip_ds6_send_rs(min_defrt); allow_output = 0; } /* Periodic processing on neighbors */ for(locnbr = uip_ds6_nbr_cache; locnbr < uip_ds6_nbr_cache + UIP_DS6_NBR_NB; locnbr++) { if(locnbr->isused) { switch (locnbr->state) { #if UIP_CONF_ROUTER /* There can not be INCOMPLETE NCEs in a host in 6lowpan-nd */ case NBR_INCOMPLETE: if (allow_output) { if(locnbr->nscount >= UIP_ND6_MAX_MULTICAST_SOLICIT) { uip_ds6_nbr_rm(locnbr); } else if(stimer_expired(&(locnbr->sendns))) { locnbr->nscount++; PRINTF("NBR_INCOMPLETE: NS %u\n", locnbr->nscount); uip_nd6_ns_output(NULL, NULL, &locnbr->ipaddr); stimer_set(&(locnbr->sendns), uip_ds6_if.retrans_timer / 1000); allow_output = 0; } } break; #endif /* UIP_CONF_ROUTER */ case NBR_REACHABLE: if(stimer_expired(&(locnbr->reachable))) { PRINTF("REACHABLE: moving to STALE ("); PRINT6ADDR(&locnbr->ipaddr); PRINTF(")\n"); locnbr->state = NBR_STALE; NEIGHBOR_STATE_CHANGED(locnbr); } break; case NBR_DELAY: if (allow_output) { if(stimer_expired(&(locnbr->reachable))) { locnbr->state = NBR_PROBE; locnbr->nscount = 1; NEIGHBOR_STATE_CHANGED(locnbr); PRINTF("DELAY: moving to PROBE + NS %u\n", locnbr->nscount); uip_nd6_ns_output(NULL, &locnbr->ipaddr, &locnbr->ipaddr, 0, 0); stimer_set(&(locnbr->sendns), uip_ds6_if.retrans_timer / 1000); allow_output = 0; } } break; case NBR_PROBE: if (allow_output) { if(locnbr->nscount >= UIP_ND6_MAX_UNICAST_SOLICIT) { PRINTF("PROBE END \n"); if((locdefrt = uip_ds6_defrt_lookup(&locnbr->ipaddr)) != NULL) { uip_ds6_defrt_rm(locdefrt); } uip_ds6_nbr_rm(locnbr); } else if(stimer_expired(&(locnbr->sendns))) { locnbr->nscount++; PRINTF("PROBE: NS %u\n", locnbr->nscount); uip_nd6_ns_output(NULL, &locnbr->ipaddr, &locnbr->ipaddr, 0, 0); stimer_set(&(locnbr->sendns), uip_ds6_if.retrans_timer / 1000); allow_output = 0; } } break; default: break; } } } #if UIP_CONF_ROUTER & UIP_ND6_SEND_RA /* Periodic RA sending */ if(stimer_expired(&uip_ds6_timer_ra)) { uip_ds6_send_ra_periodic(); } #endif /* UIP_CONF_ROUTER & UIP_ND6_SEND_RA */ etimer_reset(&uip_ds6_timer_periodic); return; }
/*---------------------------------------------------------------------------*/ void httpd_appcall(void *state) { #if DEBUGLOGIC struct httpd_state *s; //Enter here for debugging with output directed to TCPBUF s = sg = (struct httpd_state *)memb_alloc(&conns); //put ram watch on sg if (1) { #else struct httpd_state *s = (struct httpd_state *)state; if(uip_closed() || uip_aborted() || uip_timedout()) { if(s != NULL) { s->script = NULL; memb_free(&conns, s); } } else if(uip_connected()) { s = (struct httpd_state *)memb_alloc(&conns); if(s == NULL) { uip_abort(); webserver_log_file(&uip_conn->ripaddr, "reset (no memory block)"); return; } #endif tcp_markconn(uip_conn, s); PSOCK_INIT(&s->sin, (uint8_t *)s->inputbuf, sizeof(s->inputbuf) - 1); PSOCK_INIT(&s->sout, (uint8_t *)s->inputbuf, sizeof(s->inputbuf) - 1); PT_INIT(&s->outputpt); s->script = NULL; s->state = STATE_WAITING; timer_set(&s->timer, CLOCK_SECOND * 10); handle_connection(s); } else if(s != NULL) { if(uip_poll()) { if(timer_expired(&s->timer)) { uip_abort(); s->script = NULL; memb_free(&conns, s); webserver_log_file(&uip_conn->ripaddr, "reset (timeout)"); } } else { timer_restart(&s->timer); } handle_connection(s); } else { uip_abort(); } } /*---------------------------------------------------------------------------*/ PROCESS(httpd_process, "httpd"); PROCESS_THREAD(httpd_process, ev, data) { PROCESS_BEGIN(); httpd_init(); while(1) { PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); httpd_appcall(data); } PROCESS_END(); }
void serial_simulation(void) { timer serial_event_execution; timer serial_gvt_timer; msg_t *event; unsigned int completed = 0; #ifdef EXTRA_CHECKS unsigned long long hash1, hash2; hash1 = hash2 = 0; #endif timer_start(serial_gvt_timer); statistics_post_other_data(STAT_SIM_START, 0.0); while(!serial_simulation_complete) { event = (msg_t *)calqueue_get(); if(event == NULL) { rootsim_error(true, "No events to process!\n"); } #ifdef EXTRA_CHECKS if(event->size > 0) { hash1 = XXH64(event->event_content, event->size, current_lp); } #endif current_lp = event->receiver; current_lvt = event->timestamp; timer_start(serial_event_execution); ProcessEvent_light(current_lp, current_lvt, event->type, event->event_content, event->size, serial_states[current_lp]); statistics_post_lp_data(current_lp, STAT_EVENT, 1.0); statistics_post_lp_data(current_lp, STAT_EVENT_TIME, timer_value_seconds(serial_event_execution) ); #ifdef EXTRA_CHECKS if(event->size > 0) { hash2 = XXH64(event->event_content, event->size, current_lp); } if(hash1 != hash2) { printf("hash1 = %llu, hash2= %llu\n", hash1, hash2); rootsim_error(true, "Error, LP %d has modified the payload of event %d during its processing. Aborting...\n", current_lp, event->type); } #endif current_lp = IDLE_PROCESS; // Termination detection can happen only after the state is initialized if(serial_states[event->receiver] != NULL) { // Should we terminate the simulation? if(!serial_completed_simulation[event->receiver] && OnGVT_light(event->receiver, serial_states[event->receiver])) { completed++; serial_completed_simulation[event->receiver] = true; if(completed == n_prc_tot) { serial_simulation_complete = true; } } } // Termination detection on reached LVT value if(rootsim_config.simulation_time > 0 && event->timestamp >= rootsim_config.simulation_time) { serial_simulation_complete = true; } // Simulate the execution of GVT protocol if (timer_value_milli(serial_gvt_timer) > (int)rootsim_config.gvt_time_period) { timer_restart(serial_gvt_timer); printf("TIME BARRIER: %f\n", current_lvt); statistics_post_other_data(STAT_GVT, 0.0); statistics_post_other_data(STAT_GVT_TIME, current_lvt); } rsfree(event); } simulation_shutdown(EXIT_SUCCESS); }
void enc28j60_tick(ENC28J60 *enc28j60) { uip_len = _enc28j60_receivePacket(enc28j60, ((uint8_t *)uip_buf), UIP_BUFSIZE); if (uip_len > 0) { struct uip_eth_hdr *header = ((struct uip_eth_hdr *)&uip_buf[0]); uint16_t packetType = header->type; #ifdef ENC28J60_DEBUG printf("?receivePacket: len: %d, dest: %d.%d.%d.%d, src: %d.%d.%d.%d, type: %d\n", uip_len, header->dest.u8[0], header->dest.u8[1], header->dest.u8[2], header->dest.u8[3], header->src.u8[0], header->src.u8[1], header->src.u8[2], header->src.u8[3], packetType ); for (int i = 0; i < uip_len; i++) { printf("%02x ", uip_buf[i]); } printf("\n"); #endif if (packetType == UIP_HTONS(UIP_ETHTYPE_IP)) { #ifdef ENC28J60_DEBUG printf("?readPacket type IP\n"); #endif uip_arp_ipin(); uip_input(); if (uip_len > 0) { uip_arp_out(); enc28j60_send(enc28j60); } } else if (packetType == UIP_HTONS(UIP_ETHTYPE_ARP)) { #ifdef ENC28J60_DEBUG printf("?readPacket type ARP\n"); #endif uip_arp_arpin(); if (uip_len > 0) { enc28j60_send(enc28j60); } } } if (timer_expired(&enc28j60->_enc28j60_periodicTimer)) { timer_restart(&enc28j60->_enc28j60_periodicTimer); for (int i = 0; i < UIP_CONNS; i++) { uip_periodic(i); // If the above function invocation resulted in data that // should be sent out on the Enc28J60Network, the global variable // uip_len is set to a value > 0. if (uip_len > 0) { uip_arp_out(); enc28j60_send(enc28j60); } } #if UIP_UDP for (int i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); // If the above function invocation resulted in data that // should be sent out on the Enc28J60Network, the global variable // uip_len is set to a value > 0. */ if (uip_len > 0) { uip_arp_out(); enc28j60_send(enc28j60); } } #endif /* UIP_UDP */ } }