static void serial_interrupt_checkpoint() { int fd = 0; PAUSE_TIME(); if(SPI_IS_ENABLED()) { /* SPI is busy, abort */ PRINTF_COMMAND("CP:SPIBUSY\n"); RESUME_TIME(); return; } /* Open file */ cfs_remove("cp"); cfs_coffee_reserve("cp", checkpoint_arch_size()); fd = cfs_open("cp", CFS_WRITE); if(fd < 0) { printf("ERROR: No file access (cp)\n"); RESUME_TIME(); return; } /* Checkpoint */ preset_cmd = COMMAND_CHECKPOINT; preset_fd = fd; mt_exec(&checkpoint_thread); /* Close file */ cfs_close(fd); RESUME_TIME(); }
/*---------------------------------------------------------------------------*/ static void serial_interrupt_rollback() { int fd = 0; PAUSE_TIME(); if(SPI_IS_ENABLED()) { /* SPI is busy, abort */ PRINTF_COMMAND("RB:SPIBUSY\n"); RESUME_TIME(); return; } /* Open file */ fd = cfs_open("cp", CFS_READ); if(fd < 0) { printf("ERROR: No file access (rb)\n"); RESUME_TIME(); return; } /* Rollback */ preset_cmd = COMMAND_ROLLBACK; preset_fd = fd; mt_exec(&checkpoint_thread); /* Close file */ cfs_close(fd); RESUME_TIME(); }
/*---------------------------------------------------------------------------*/ static void serial_interrupt_metrics() { PAUSE_TIME(); preset_cmd = COMMAND_METRICS; preset_fd = -1; mt_exec(&checkpoint_thread); RESUME_TIME(); }
/*---------------------------------------------------------------------------*/ void checkpoint_arch_checkpoint(int fd) { PAUSE_TIME_INT(); preset_cmd = COMMAND_CHECKPOINT; preset_fd = fd; mt_exec(&checkpoint_thread); RESUME_TIME_INT(); }
/*---------------------------------------------------------------------------*/ void checkpoint_arch_rollback(int fd) { PAUSE_TIME_INT(); preset_cmd = COMMAND_ROLLBACK; preset_fd = fd; mt_exec(&checkpoint_thread); RESUME_TIME_INT(); }
/*---------------------------------------------------------------------------*/ void checkpoint_arch_rollback(int fd) { //STOP_TIMERS(); preset_cmd = COMMAND_ROLLBACK; preset_fd = fd; mt_exec(&checkpoint_thread); //START_TIMERS(); }
/*---------------------------------------------------------------------------*/ void checkpoint_arch_checkpoint(int fd) { // STOP_TIMERS(); preset_cmd = COMMAND_CHECKPOINT; preset_fd = fd; mt_exec(&checkpoint_thread); // START_TIMERS(); }
PROTOTYPES int main() { t_mt *mt = mt_create("ft_printf"); setbuf(stdout, NULL); setlocale(LC_ALL, "en_US.UTF-8"); ADD_TESTS mt_exec(mt); return(0); }
int main(void) { /* * GCC depends on register r1 set to 0. */ asm volatile ("clr r1"); /* Initialize hardware */ init_lowlevel(); /* Clock */ clock_init(); /* Process subsystem */ process_init(); /* Register initial processes */ procinit_init(); /* Perform rest of initializations */ process_start(&contiki_stk501_main_init_process, NULL); rs232_print_p (RS232_PORT_1, PSTR ("Initialized.\n")); #ifdef MT_DEMO mt_start (&threads[0], thread_handler1, &d1); mt_start (&threads[1], thread_handler2, &d2); mt_start (&threads[2], thread_handler2, &d3); uint8_t i; #endif /* Main scheduler loop */ while(1) { process_run(); #ifdef MT_DEMO for (i=0; i<3; ++i) { mt_exec (&threads[i]); } #endif } return 0; }
PROCESS_THREAD(udp_client_process, ev, data) { static struct etimer start_timer, send_timer; static int flag=1;int i=0; static struct mt_thread sending_thread, attackinit_thread; PROCESS_BEGIN(); SENSORS_ACTIVATE(button_sensor); SENSORS_ACTIVATE(radio_sensor); set_global_address(); printf("UDP client process started\n"); print_local_addresses(); myip=uip_ds6_get_link_local(ADDR_PREFERRED)->ipaddr; /* new connection with remote host */ client_conn = udp_new(NULL, NULL, NULL); if(client_conn == NULL) { printf("No UDP connection available, exiting the process!\n"); PROCESS_EXIT(); } udp_bind(client_conn, UIP_HTONS(10000+(int)myip.u8[15])); udp_bconn = udp_broadcast_new(UIP_HTONS(BROADCAST_PORT),tcpip_handler); //uip_create_unspecified(&udp_bconn->ripaddr); if(udp_bconn == NULL) { printf("No UDP broadcast connection available, exiting the process!\n"); PROCESS_EXIT(); } printf("Created a connection with the server "); PRINT6ADDR(&client_conn->ripaddr); printf(" local/remote port %u/%u\n", UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport)); etimer_set(&start_timer, 60 * CLOCK_SECOND);//network setting time etimer_set(&send_timer, CLOCK_SECOND * ((int)myip.u8[15]+60+40));//node check/send parent info char buf[3]="hi"; mt_init(); mt_start(&sending_thread, sendpacket, 0); mt_start(&attackinit_thread, attack_init, NULL); while(1) { PROCESS_YIELD(); //NETSTACK_RDC.off(0); //NETSTACK_MAC.off(0); //NETSTACK_RADIO.off(); //button_sensor::value(0); if(ev==tcpip_event) { tcpip_handler(); } if(rssi_stored==5)// if got 5 rssi value from parent or child { monitor=0; monitor_target=0; for(i=0;i<5;i++) printf("Monitered value %d \n",mrssi[i]); rssi_stored=0; } if((ev==sensors_event) && (data == &button_sensor)) { if(attack_flag) { printf("Attack deactivated\n"); attack_flag=0; attacker=0; attacker_set=0; dis_output(NULL); }else { printf("Attack activated\n"); mt_exec(&attackinit_thread); } } if((ev==sensors_event) && (data == &radio_sensor)) { printf("Radio value %d",radio_sensor.value(0)); } if(etimer_expired(&send_timer)) { //uip_udp_packet_sendto(client_conn, buf, sizeof(buf), &server_ipaddr, UIP_HTONS(2345)); //uip_create_unspecified(&client_conn->ripaddr); //if(myip.u8[15]==4) //sendpacket(0); etimer_set(&send_timer, CLOCK_SECOND*(myip.u8[15]+60)); if(parent_change) // send only at parent change event { if(!attack_flag) // this is not attacker and { mt_exec(&sending_thread); //sendpacket(0); // send nbr info by broadcast 0 for broadcast parent_change=0; printf("Thread initiated\n"); } } } if(etimer_expired(&start_timer) && flag==1) { flag=0; send_xy(); etimer_set(&start_timer, CLOCK_SECOND*(myip.u8[15]+1)); PROCESS_WAIT_UNTIL(etimer_expired(&start_timer)); send_broadcast("hi",sizeof("hi")); sendpacket(1); // 0 means send by unicast } } PROCESS_END(); }