Esempio n. 1
0
void cca_test(){

   uint32_t rand_val;
   uint16_t send_val=0;
   while(1) {
      // generate a random backoff ammount
      rand_val = random () % initBackoff + 1;
      
      //get the current threads ID
      sendThread = mos_thread_current();

      // start the backoff alarm
      //mos_alarm(&backoff_alarm, rand_val);
      backoff_alarm.msecs = rand_val;
      backoff_alarm.reset_to = 0;
      mos_alarm(&backoff_alarm);
      
      try_send = true;
      //suspend this thread until backoff alarm wake's us
      mos_thread_suspend();

      //while(!sent_flag);
      sent_flag=false;
      printf("send [%d]\n",send_val++);
   }
}
void stack_check() {
   stk_chk_t = mos_thread_current();

   alarm_stk.func = wakeup_stk;
   mos_alarm(&alarm_stk, 1, 0);

   while(1) {
//	printf("ge: %d\n", mos_check_stack(main_t));
//	printf("nt: %d\n", mos_check_stack(net_t));
//	printf("ts: %d\n", mos_check_stack(stk_chk_t));

      mos_thread_suspend();
   }
}
Esempio n. 3
0
void stack_check() {
    stk_chk_t = mos_thread_current();
    
    alarm.func = wakeup;
    mos_alarm(&alarm, 1, 0);
	
    while(1) {
	printf("rc: %d\n", mos_check_stack(recv_thread));
//	printf("nt: %d\n", mos_check_stack(net_t));
	printf("ts: %d\n", mos_check_stack(stk_chk_t));

	mos_thread_suspend();
    }
}
Esempio n. 4
0
/** @brief preStart() is the function for the startup thread, which is the
 * one spawned by main().
 *
 * It does all the initialization that needs to happen after the
 * kernel is up and running, and then it calls the application start function.
 */
void pre_start(void)
{
    //TODO: this should somehow be auto-generated
#ifdef PLATFORM_LINUX
    mos_node_id_init();	// must be called before gevent_init ()
    gevent_init();

    serial_init();
    terminal_init();
    //udp_init();
    xmos_radio_init();	// gevent_init() must be called first
    xmos_flash_init();	// gevent_init() must be called first
    mos_thread_suspend(); //fixes threading issue with freebsd

#elif defined(ARCH_MICRO)
    uart_init();
    printf_init();
    plat_init();
    clock_init();
#if defined(PLATFORM_TELOSB)
    // clock_init() clobbers TimerA
    // re-initialize TimerA here as a kludge.
    kernel_timer_init();
#endif
    mos_node_id_init();

    //dev_loopback_init();
    //com_loopback_init();


    // seed the rng
    //srandom(mos_node_id_get());
#endif //if defined(ARCH_AVR)

#ifdef MOS_DEBUG
    mos_debug_post_init();
#endif

    start();
}
Esempio n. 5
0
void elf_netload (void) {
     int elfloader_err;
     uint32_t sleep_time = 4000;
     uint16_t packet_nr = 0;
     uint16_t packet_nrfake = 111;

	/* Store thread handle for later from com.c */
	elfthread = mos_thread_current();

	/* Make sure packets will not be dropped before comparison */
    com_mode(IFACE_RADIO, IF_LISTEN);

  printf("elf_netload started\n");

  while (1) {

	last_packet_nr = -1;
	received_termination = 0;
	
   while (!received_termination) {
	 /* Suspend thread waiting for radio data - similar to com_recv() */
	mos_thread_suspend();

   	  /* Analyze packet data */
   	  if (is_elf_packet(elfbuf)) {
   	      packet_nr = -1;

		// Check header for packet number
		memcpy(&packet_nr, &elfbuf->data[PACKET_NR_OFFSET], sizeof(uint16_t));
		
		if (last_packet_nr + 1 >= packet_nr) {
			if (elfbuf->size == DATA_OFFSET) {
				// Received termination packet...
			    printf("received termination packet: %d\n", packet_nr);
			    received_termination = 1;
			} else {
	   	  		last_packet_nr = packet_nr;
			    printf("writing data to elfstore: %d\n", packet_nr);
   				elfstore_write(&elfbuf->data[DATA_OFFSET], (DATASIZE)*packet_nr, DATASIZE);
   			}		    
		   
   	  	} else {
			// ignore out of synch packets
     	  printf("received out of sync elf packet %d\n", packet_nr);
   	  	}
    
   	  } else {
     	  printf("error, elf_netload() received non-ELF data\n");
   	  }

      com_free_buf(elfbuf);
      mos_led_toggle (2);
   }

  printf("loading elf now\n");
  
  /* Load and unload forever */
    if (elfloader_loaded_unload != NULL) {
      printf("shutting down already started application...\n");
      elfloader_loaded_unload();
      elfloader_loaded_unload == NULL;
    }
    
    printf("sleeping...\n");
    mos_thread_sleep (SLEEPTIME);

    /* Load ELF */
    printf("loading ELF now...");
    elfloader_err = elfloader_load();
    if (elfloader_err != ELFLOADER_OK) {
      printf("failed\n");
      printf("ELF loader returned error %C, elfloader_unknown = %s\n", elfloader_err, elfloader_unknown);
      printf("symbols size is %C\n", sizeof(symbols));
    } else {
      /* Start loaded application */
      printf("success\n");
      printf("sleeping...\n");
      mos_thread_sleep (SLEEPTIME);
      
      printf("starting loaded application now...\n");
      elfloader_loaded_load();
    }
    
    printf("waiting until duplicate packets gone\n");
    mos_thread_sleep (SLEEPTIME);
    
  }
}
void m_thread()
{
   mos_thread_suspend();
}