Ejemplo n.º 1
0
void Task4()
{
uint16_t cnt;
uint8_t v;
uint8_t row;

  printf( "Task4 PID=%u\r\n",nrk_get_pid());
  oled_on();

  cnt=0;
  row=0;
  while(1) {
	v=hrm_get_value();
	sprintf(txt_str,"%d%d%d cnt=%d hrm=%d",nrk_gpio_get(NRK_MMC_9), nrk_gpio_get(NRK_MMC_10), nrk_gpio_get(NRK_MMC_11), cnt,v);
	oled_write_str( 2, row, 0, 0xFFFF, txt_str );
/*	oled_clear_screen();
	nrk_wait_until_ticks(50);
	sprintf(txt_str,"Neighbor List:");
	oled_write_str( 2, 3, 0, 0xFFFF, txt_str );
	nrk_wait_until_ticks(50);
	sprintf(txt_str,"   0x100002a  -27 4");
	oled_write_str( 2, 4, 0, 0xFFFF, txt_str );
	nrk_wait_until_ticks(50);
	sprintf(txt_str,"   0x1000012: -30 2");
	oled_write_str( 2, 5, 0, 0xFFFF, txt_str );
	nrk_wait_until_ticks(50);
	sprintf(txt_str,"   0x100000a: -5 3");
	oled_write_str( 2, 6, 0, 0xFFFF, txt_str );
	nrk_wait_until_ticks(50);
	sprintf(txt_str,"Round Trip Pkt:  93%%");
	oled_write_str( 2, 9, 0, 0xFFFF, txt_str );
	nrk_wait_until_ticks(50);
	//putc0(0x70);	
	//putc0(0x01);	
	//nrk_wait_until_ticks(50);
	oled_draw_square( 8, 83, 150, 92, 0x001F  );
	nrk_wait_until_ticks(50);
	//putc0(0x70);	
	//putc0(0x00);	
	//nrk_wait_until_ticks(50);
	oled_draw_square( 10, 85, 100, 90, 0x07e0  );
	nrk_wait_until_ticks(50);
  */
        cnt++;
	row++;
	if(row==15) {
		oled_clear_screen();
		row=0;
		}
	nrk_wait_until_next_period();
	}
}
Ejemplo n.º 2
0
void Task1()
{
uint16_t cnt;
int8_t fd;
nrk_kprintf( PSTR("Nano-RK Version ") );
printf( "%d\r\n",NRK_VERSION );

//while(1) nrk_wait_until_next_period();


nrk_gpio_direction(NRK_MMC_9,NRK_PIN_INPUT);
nrk_gpio_direction(NRK_MMC_10,NRK_PIN_INPUT);
nrk_gpio_direction(NRK_MMC_11,NRK_PIN_INPUT);

bpm_index=0;

nrk_gpio_pullups(1);

nrk_ext_int_configure(NRK_PC_INT_5, NULL, &button_press_int);
nrk_ext_int_configure(NRK_PC_INT_6, NULL, &button_press_int);
nrk_ext_int_configure(NRK_PC_INT_7, NULL, &button_press_int);
nrk_ext_int_enable(NRK_PC_INT_5);
nrk_ext_int_enable(NRK_PC_INT_6);
nrk_ext_int_enable(NRK_PC_INT_7);

nrk_ext_int_configure(NRK_EXT_INT_0, NRK_RISING_EDGE, &heart_rate_int);
nrk_ext_int_enable(NRK_EXT_INT_0);

cnt=0;
printf( "My node's address is %u\r\n",NODE_ADDR );
  
fd=nrk_open(FIREFLY_SENSOR_BASIC,READ);
        if(fd==NRK_ERROR) nrk_kprintf(PSTR("Failed to open sensor driver\r\n"));

printf( "Task1 PID=%u\r\n",nrk_get_pid());

  while(1) {
	//printf( "Task1 cnt=%u\r\n",cnt );
	nrk_wait_until_next_period();
	printf( "9=%d ",nrk_gpio_get(NRK_MMC_9));
	printf( "10=%d ",nrk_gpio_get(NRK_MMC_10));
	printf( "11=%d ",nrk_gpio_get(NRK_MMC_11));
	printf( "%d %d\r\n",cnt,hrm_get_value() );
	nrk_led_toggle(GREEN_LED);
        // Uncomment this line to cause a stack overflow
	cnt++;
	}
}
Ejemplo n.º 3
0
// This is an interrupts routine that handles the button press.
// It has a 300ms debounce
void button_handler()
{
    int8_t v;

// Make sure button is depressed for at least 50 us
    nrk_spin_wait_us(50);
    v=nrk_gpio_get(NRK_PORTD_0);
    if(v!=0) return;
    nrk_time_get(&button_cur_press);
    nrk_time_sub(&button_tmp_press, button_cur_press, button_last_press );
    if(button_tmp_press.secs>=1 || button_tmp_press.nano_secs>=(300*NANOS_PER_MS))
    {

// Reboot the node...

        socket_0_disable();
        power_socket_disable(0);
        nrk_int_disable();
        while(1);

        if(socket_0_active==1)
        {
            plug_led_green_clr();
            power_socket_disable(0);
        }
        else
        {
            plug_led_green_set();
            power_socket_enable(0);
        }
        button_last_press.secs=button_cur_press.secs;
        button_last_press.nano_secs=button_cur_press.nano_secs;
    }

}
Ejemplo n.º 4
0
void Task1()
{
uint16_t cnt;
int8_t fd,val,chan;
uint16_t sample;


   printf( "Task1 PID=%d\r\n",nrk_get_pid());

  nrk_gpio_direction(NRK_BUTTON, NRK_PIN_INPUT);
  nrk_gpio_direction(NRK_DEBUG_0, NRK_PIN_OUTPUT);

  nrk_led_set(RED_LED);
  do{} while(nrk_gpio_get(NRK_BUTTON)==1);
  nrk_led_clr(RED_LED);
  nrk_led_set(GREEN_LED);

   // Initialize values here
   ADC_INIT ();
   ADC_ENABLE ();
   ADC_SET_CHANNEL (2);

  while(1) {
	ADC_SAMPLE_SINGLE();
	ADC_GET_SAMPLE_10(sample);
  	// Send sync byte
  	putchar(0x55);
	putchar(sample>>8);
	putchar(sample&0xff);
  	}
}
Ejemplo n.º 5
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++;
 }
}
Ejemplo n.º 6
0
Archivo: main.c Proyecto: jnwu/nanork
void Task1()
{
nrk_time_t t;
uint8_t val;

nrk_kprintf( PSTR("Nano-RK Version ") );
printf( "%d\r\n",NRK_VERSION );

nrk_gpio_direction(NRK_BUTTON, NRK_PIN_INPUT);

  while(1) {
	// Update watchdog timer
	nrk_led_toggle(GREEN_LED);

	val=nrk_gpio_get(NRK_BUTTON);
	// Button logic is inverter 0 means pressed, 1 not pressed
	if(val==0) nrk_led_set(BLUE_LED);
	else nrk_led_clr(BLUE_LED);
	printf( "button state=%u\r\n",val );
	nrk_wait_until_next_period();

	}
}
Ejemplo n.º 7
0
void deep_sleep_button()
{
    int i,cnt;
    nrk_int_disable();
    nrk_eeprom_write_byte(EEPROM_SLEEP_STATE_ADDR,1);
    nrk_led_set(0);
    nrk_spin_wait_us(50000);
    nrk_led_clr(0);
    nrk_led_clr(1);
    nrk_led_clr(2);
    nrk_led_clr(3);
    nrk_watchdog_disable();
    nrk_int_disable();
    _nrk_os_timer_stop();
    nrk_gpio_direction(NRK_BUTTON, NRK_PIN_INPUT);
    rf_power_down();
    // Enable Pullup for button
    //PORTD = 0xff;
    nrk_gpio_set(NRK_BUTTON);
    nrk_ext_int_configure( NRK_EXT_INT_1,NRK_LEVEL_TRIGGER, &wakeup_func);
    EIFR=0xff;
    nrk_ext_int_enable( NRK_EXT_INT_1);
    nrk_int_enable();
    DDRA=0x0;
    DDRB=0x0;
    DDRC=0x0;
    ASSR=0;
    TRXPR = 1 << SLPTR;
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sleep_enable();
    sleep_cpu();
    // reboot
    while(1) {
        //printf( "awake!\r\n" );
        nrk_led_clr(0);
        nrk_led_clr(1);
        nrk_led_set(1);
        cnt=0;
        for(i=0; i<100; i++ )
        {
            //if((PIND & 0x2)==0x2)cnt++;
            if(nrk_gpio_get(NRK_BUTTON)==0)cnt++;
            nrk_spin_wait_us(10000);
        }
        printf( "cnt=%d\n",cnt );
        if(cnt>=50 ) {
            // reboot
            nrk_led_clr(1);
            nrk_led_set(0);
            nrk_eeprom_write_byte(EEPROM_SLEEP_STATE_ADDR,0);
            nrk_spin_wait_us(50000);
            nrk_spin_wait_us(50000);
            nrk_watchdog_enable();
            while(1);

        }
        nrk_led_clr(0);
        nrk_led_clr(1);
        TRXPR = 1 << SLPTR;
        set_sleep_mode(SLEEP_MODE_PWR_DOWN);
        sleep_enable();
        sleep_cpu();
    }
}
Ejemplo n.º 8
0
void tx_task ()
{
    uint8_t j, i, val, cnt;
    int8_t len;
    int8_t v,fd;
    nrk_sig_mask_t ret;
    nrk_time_t t;



    // Set Port D.0 as input
    // On the FireFly nodes we use this for motion or syntonistor input
    // It can be interrupt driven, but we don't do this with TDMA since updates are so fast anyway



    printf ("tx_task PID=%d\r\n", nrk_get_pid ());

    // setup a software watch dog timer
    t.secs=10;
    t.nano_secs=0;
    nrk_sw_wdt_init(0, &t, NULL);
    nrk_sw_wdt_start(0);

    while (!tdma_started ())
        nrk_wait_until_next_period ();

    // set port G as input for gpio
    nrk_gpio_direction(NRK_PORTG_0,NRK_PIN_INPUT );

    send_ack=0;

    while (1) {
        nrk_led_clr(RED_LED);

        tx_pkt.payload[0] = 1;  // ELEMENTS
        tx_pkt.payload[1] = 4;  // Key
        tx_pkt.payload[2] = nrk_gpio_get(NRK_PORTG_0);  // Key
        tx_pkt.payload_len=3;
        tx_pkt.src_mac=mac_address;
        tx_pkt.dst_mac=0;
        tx_pkt.type=APP;

        if(send_ack==1)
        {
            tx_pkt.type=ACK;
            tx_pkt.payload_len=0;
            send_ack=0;
        }


        len=pkt_to_buf(&tx_pkt,&tx_buf );

        if(len>0)
        {
            v = tdma_send (&tx_tdma_fd, &tx_buf, len, TDMA_BLOCKING);
            if (v == NRK_OK) {
            }
        } else {
            nrk_kprintf(PSTR("Pkt tx error\r\n"));
            nrk_wait_until_next_period();
        }


        nrk_sw_wdt_update(0);
    }



}
Ejemplo n.º 9
0
void rx_task ()
{
  uint8_t i, len;
  uint16_t j;
  int8_t rssi, val;
  int8_t data_ready, button_state;
  uint8_t *local_rx_buf;
  uint16_t seq_num;
  uint16_t pkt_cnt;
  nrk_time_t check_period;
  printf ("rx_task PID=%d\r\n", nrk_get_pid ());

  // init bmac on channel 25 
  bmac_init (15);

  // Enable AES 128 bit encryption
  // When encryption is active, messages from plaintext
  // source will still be received. 
  //bmac_encryption_set_key(aes_key,16);
  //bmac_encryption_enable();
  // bmac_encryption_disable();

  // By default the RX check rate is 100ms
  // below shows how to change that
  //check_period.secs=0;
  //check_period.nano_secs=200*NANOS_PER_MS;
  //val=bmac_set_rx_check_rate(check_period);

  // The default Clear Channel Assement RSSI threshold is -45
  // Setting this value higher means that you will only trigger
  // receive with a very strong signal.  Setting this lower means
  // bmac will try to receive fainter packets.  If the value is set
  // too high or too low performance will suffer greatly.
   bmac_set_cca_thresh(-50); 


  //if(val==NRK_ERROR) nrk_kprintf( PSTR("ERROR setting bmac rate\r\n" ));
  // This sets the next RX buffer.
  // This can be called at anytime before releaseing the packet
  // if you wish to do a zero-copy buffer switch
  bmac_rx_pkt_set_buffer (rx_buf, RF_MAX_PAYLOAD_SIZE);


  index=0;

  while (1) {

	nrk_led_clr(GREEN_LED);
	nrk_led_set(RED_LED);
  	do {
		nrk_led_toggle(BLUE_LED);
		printf( "\r\nTest Data\r\n" );
		for(j=0; j<index; j++ )
		{
			printf( "run: %u pkts: %u  rssi: %d\r\n",j, data[j],rssi_avg[j] );
		}
    		for(j=0; j<100; j++ ) nrk_wait_until_next_period ();
  	}while( nrk_gpio_get(NRK_BUTTON)==1 );


	nrk_led_clr(BLUE_LED);
	nrk_led_clr(RED_LED);
    		for(j=0; j<100; j++ ) nrk_wait_until_next_period ();
	nrk_led_set(GREEN_LED);

	pkt_cnt=0;
  	while(1) {
    		// Wait until an RX packet is received
		do {
			data_ready=bmac_rx_pkt_ready();	
			button_state=nrk_gpio_get(NRK_BUTTON);
			nrk_wait_until_next_period();
		} while(data_ready==0 && button_state==1 );
		if(button_state==0) break;
    		val = bmac_wait_until_rx_pkt ();
    		// Get the RX packet 
    		nrk_led_set (ORANGE_LED);
    		local_rx_buf = bmac_rx_pkt_get (&len, &rssi);
    		//if( bmac_rx_pkt_is_encrypted()==1 ) nrk_kprintf( PSTR( "Packet Encrypted\r\n" ));
    		//printf ("Got RX packet len=%d RSSI=%d [", len, rssi);
    		rssi_acc+=rssi;
		seq_num=local_rx_buf[1]<<8 | local_rx_buf[0];
    		printf ("cnt: %u seq num: %u\r\n",pkt_cnt, seq_num);
    		pkt_cnt++;
    		nrk_led_clr (ORANGE_LED);
    		// Release the RX buffer so future packets can arrive 
    		bmac_rx_pkt_release ();
  	}
	rssi_avg[index]=rssi_acc/pkt_cnt;
	data[index]=pkt_cnt;
	index++;

  }

}