Example #1
0
void Task1()
{
nrk_time_t t;
uint16_t cnt;
cnt=0;
nrk_kprintf( PSTR("Nano-RK Version ") );
printf( "%d\r\n",NRK_VERSION );

printf( "My node's address is %u\r\n",NODE_ADDR );
  
printf( "Task1 PID=%u\r\n",nrk_get_pid());

  while(1) {
	nrk_led_toggle(ORANGE_LED);
	//nrk_gpio_toggle(NRK_DEBUG_0);
	printf( "Task1 cnt=%u\r\n",cnt );
	nrk_wait_until_next_period();
        // Uncomment this line to cause a stack overflow
	// if(cnt>20) kill_stack(10);

	// At time 50, the OS will halt and print statistics
	// This requires the NRK_STATS_TRACKER #define in nrk_cfg.h
	 if(cnt==50)  {
		nrk_stats_display_all();
		// This will induce a kernel panic on purpose	
		nrk_halt();
		}

        // This is an example of how to access the task execution data
	if( cnt==10 ) {
	nrk_stats_get(nrk_get_pid(), &my_stats);
	nrk_kprintf( PSTR( "\r\n   Total CPU: "));
	t=_nrk_ticks_to_time(my_stats.total_ticks);
	printf( "%lu secs %lu ms", t.secs, t.nano_secs/NANOS_PER_MS );
	nrk_kprintf( PSTR( "\r\n   Time [Min,Last,Max]: "));
	t=_nrk_ticks_to_time(my_stats.min_exec_ticks);
	printf( "%lu secs %lu ms, ", t.secs, t.nano_secs/NANOS_PER_MS );
	t=_nrk_ticks_to_time(my_stats.last_exec_ticks);
	printf( "%lu secs %lu ms, ", t.secs, t.nano_secs/NANOS_PER_MS );
	t=_nrk_ticks_to_time(my_stats.max_exec_ticks);
	printf( "%lu secs %lu ms", t.secs, t.nano_secs/NANOS_PER_MS );
	nrk_kprintf( PSTR( "\r\n   Swap-ins: "));
	printf( "%lu",my_stats.swapped_in );
	nrk_kprintf( PSTR( "\r\n   Preemptions: "));
	printf( "%lu",my_stats.preempted);
	nrk_kprintf( PSTR( "\r\n   Kernel Violations: "));
	printf( "%u",my_stats.violations);
	nrk_kprintf( PSTR( "\r\n   Overflow Error Status: "));
	printf( "%u",my_stats.overflow);
	nrk_kprintf( PSTR("\r\n") );
	}

	cnt++;
	}
}
Example #2
0
void Task1()
{
  nrk_time_t t;
  uint16_t cnt;
  uint8_t val;
  cnt=0;
  nrk_kprintf( PSTR("Nano-RK Version ") );
  printf("b");
  printf( "%d\r\n",NRK_VERSION );
  
  printf( "My node's address is %u\r\n",NODE_ADDR );
  
  printf( "Task1 PID=%u\r\n",nrk_get_pid());
  t.secs=30;
  t.nano_secs=0;
  
  // setup a software watch dog timer
 nrk_sw_wdt_init(0, &t, NULL);
 nrk_sw_wdt_start(0);
 
 nrk_gpio_direction(BUTTON, NRK_PIN_INPUT);
 
 while(1) {
   // Update watchdog timer
   nrk_sw_wdt_update(0);
   nrk_led_toggle(ORANGE_LED);
   val=nrk_gpio_get(BUTTON);
   
   // Button logic is inverter 0 means pressed, 1 not pressed
   printf( "Task1 cnt=%u button state=%u\r\n",cnt,val );
   nrk_wait_until_next_period();
   // Uncomment this line to cause a stack overflow
   // if(cnt>20) kill_stack(10);
   
   // At time 50, the OS will halt and print statistics
   // This requires the NRK_STATS_TRACKER #define in nrk_cfg.h
   if(cnt==50)  {
     nrk_stats_display_all();
     nrk_halt();
   }
   
   
   cnt++;
 }
}