Esempio n. 1
0
void refresh_anchors(void) {

	init_anchors();

	// Discover anchors
	uint32_t anchor_refresh_ts = 0;
	while (anchors_status) {
		printf("Discovering anchors .. anchors_status:%02X\r\n", anchors_status);

		// Check for refresh of anchors
		uint32_t elapsed = cph_get_millis() - anchor_refresh_ts;
		if (elapsed > ANCHORS_REFRESH_INTERVAL) {
			printf("Anchors discovery timeout.  anchors_status:%02X\r\n", anchors_status);
			init_anchors();
			anchor_refresh_ts = cph_get_millis();
		}

		for (int i=0;i<ANCHORS_MIN;i++) {
			if (anchors_status & (1 << i)) {
				int result = discover(i);
				if (result == CPH_OK) {
					anchors_status &= (~(1 << i));
					printf("anchor[%d] %04X\r\n", i, anchors[i].shortid);
				}
				deca_sleep(RNG_DELAY_MS);
			}
		}
		deca_sleep(POLL_DELAY_MS);
	}

	printf("Anchors discovered. Moving to poll.  anchors_status:%02X\r\n", anchors_status);
}
Esempio n. 2
0
void push_over_usb(uint8 *string, int len)
{


	send_usbmessage(string,len);
	/* What does this do? Who knows really. */
	usb_run();

	deca_sleep(1000);

	}
Esempio n. 3
0
void toSendMsg1(uint8 niz[], int size){

	uint8 niz1[size];
	int rx_id;
	uint8 transmission_delay;


	memset(dataseq2,0,sizeof(dataseq1));
	sprintf((char*)&dataseq2[0],"%lx %lx send",

	niz1[1],niz1[2]);//,niz1[2],sizeof(niz1), size);
	writetoLCD(1, 0, 0x2);
	writetoLCD(40,1,dataseq2);
	memset(dataseq2,0,sizeof(dataseq2));



	 rx_id=niz[2];
	 if(rx_id==1){
	 for (int i=0;i<size;i++){
	      niz1[i]=niz[i];
	}
	 niz1[1]=rx_seq_num;
	 niz1[2]=3;					// ID of the end node/ second one in the line.


	                               /* Write frame data to DW1000 and prepare transmission. See NOTE 3 below.*/
	dwt_writetxdata(size, niz1, 0);
	dwt_writetxfctrl(size, 0);

	                                      /* Start transmission. */
	dwt_starttx(DWT_START_TX_IMMEDIATE);

	                                      /* Poll DW1000 until TX frame sent event set. See NOTE 4 below.
	                                       * STATUS register is 5 bytes long but, as the event we are looking at is in the first byte of the register, we can use this simplest API
	                                       * function to access it.*/
	while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS))
	{ };

	/* Clear TX frame sent event. */
	dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_TXFRS);

	/* Execute a delay between transmissions. */
	deca_sleep(TX_DELAY_MS);

	/* Increment the blink frame sequence number (modulo 256). */
	rx_seq_num++;

	 }
}
Esempio n. 4
0
void DWM1000_Anchor::init() {
	INFO("HSPI");
//_________________________________________________INIT SPI ESP8266

	resetChip();
	initSpi();
	enableIsr();

	uint64_t eui = 0xF1F2F3F4F5F6F7F;
	dwt_seteui((uint8_t*) &eui);
	dwt_geteui((uint8_t*) &eui);
	LOG<< HEX << "EUID : "<< eui <<FLUSH;
	dwt_seteui((uint8_t*) &eui);
	dwt_geteui((uint8_t*) &eui);
	LOG<< HEX << "EUID : "<< eui <<FLUSH;

//	dwt_softreset();
	deca_sleep(100);

	if (dwt_initialise(DWT_LOADUCODE)) {
		LOG<< " dwt_initialise failed " << FLUSH;
	} else
	LOG<< " dwt_initialise done." << FLUSH;
	if (dwt_configure(&config)) {
		LOG<< " dwt_configure failed " << FLUSH;
	} else
	LOG<< " dwt_configure done." << FLUSH;

	uint32_t device_id = dwt_readdevid();
	uint32_t part_id = dwt_getpartid();
	uint32_t lot_id = dwt_getlotid();

	LOG<< HEX << " device id : " << device_id << ", part id : " << part_id << ", lot_id :" << lot_id <<FLUSH;

	/* Apply default antenna delay value. See NOTE 1 below. */
	dwt_setrxantennadelay(RX_ANT_DLY);
	dwt_settxantennadelay(TX_ANT_DLY);

	/* Set expected response's delay and timeout. See NOTE 4 and 5 below.
	 * As this example only handles one incoming frame with always the same delay and timeout, those values can be set here once for all. */
	dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS);
	dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS);

	dwt_initialise(DWT_LOADUCODE);
	// Configure the callbacks from the dwt library
	dwt_setcallbacks(txcallback, rxcallback);

	_count = 0;
}
Esempio n. 5
0
void toSendMsg(uint8 niz[], int size){   // for relaing node, that does not change anything

     	uint8 niz1[size];
     	int rx_id;
     	uint8 transmission_delay;


     	memset(dataseq2,0,sizeof(dataseq1));
     	sprintf((char*)&dataseq2[0],"%lx send",

     	niz1[2]);//,niz1[2],sizeof(niz1), size);
     	writetoLCD(1, 0, 0x2);
     	writetoLCD(40,1,dataseq2);
     	memset(dataseq2,0,sizeof(dataseq2));



     	 rx_id=niz[2];

     	 for (int i=0;i<size;i++){
     	      niz1[i]=niz[i];
     	}



     	/* Write frame data to DW1000 and prepare transmission. See NOTE 3 below.*/
     	dwt_writetxdata(size, niz1, 0);
     	dwt_writetxfctrl(size, 0);

     	/* Start transmission. */
     	dwt_starttx(DWT_START_TX_IMMEDIATE);

     	/* Poll DW1000 until TX frame sent event set. See NOTE 4 below.
     	                                       * STATUS register is 5 bytes long but, as the event we are looking at is in the first byte of the register, we can use this simplest API
     	                                       * function to access it.*/
        while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS))
     	{ };

     	 /* Clear TX frame sent event. */
     	dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_TXFRS);

     	/* Execute a delay between transmissions. */
     	deca_sleep(TX_DELAY_MS);
     	 }
Esempio n. 6
0
/**
 * Application entry point.
 */
int simpleTx(void)
{
    /* Reset and initialise DW1000.
     * For initialisation, DW1000 clocks must be temporarily set to crystal speed. After initialisation SPI rate can be increased for optimum
     * performance. */
    reset_DW1000(); /* Target specific drive of RSTn line into DW1000 low for a period. */
    //spi_set_rate_low();
    dwt_initialise(DWT_LOADNONE);
    //spi_set_rate_high();

    /* Configure DW1000. See NOTE 2 below. */
    dwt_configure(&config);

    /* Loop forever sending frames periodically. */
    while(1)
    {
        /* Write frame data to DW1000 and prepare transmission. See NOTE 3 below.*/
        dwt_writetxdata(sizeof(tx_msg), tx_msg, 0);
        dwt_writetxfctrl(sizeof(tx_msg), 0);

        /* Start transmission. */
        dwt_starttx(DWT_START_TX_IMMEDIATE);

        /* Poll DW1000 until TX frame sent event set. See NOTE 4 below.
         * STATUS register is 5 bytes long but, as the event we are looking at is in the first byte of the register, we can use this simplest API
         * function to access it.*/
        while (!(status_reg = dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS))
        { };
        printf("Status reg now 0x%x\r\n",status_reg);

        /* Clear TX frame sent event. */
        dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_TXFRS);

        /* Execute a delay between transmissions. */
        deca_sleep(TX_DELAY_MS);

        // toggle led
		ledToggle();

        /* Increment the blink frame sequence number (modulo 256). */
        tx_msg[BLINK_FRAME_SN_IDX]++;
    }
}
Esempio n. 7
0
void reset_DW1000(void)
{
    u32 uwbIn;
    XGpio_Initialize(&uwbGpio,XPAR_AXI_GPIO_UWB_DEVICE_ID);
    XGpio_DiscreteWrite(&uwbGpio,1,0); // reset on
    uwbIn = XGpio_DiscreteRead(&uwbGpio,2);
    /*
	printf("UBW reset active. Inputs 0x%x. Press any key\r\n", uwbIn);
	getchar();
	*/
    XGpio_DiscreteWrite(&uwbGpio,1,0xff); // reset off
    uwbIn = XGpio_DiscreteRead(&uwbGpio,2);
    while(0 == (uwbIn & 0x4)){
		//printf("UBW reset inactive. Inputs 0x%x\r\n", uwbIn);
	    uwbIn = XGpio_DiscreteRead(&uwbGpio,2);
    }
	printf("UBW reset completed\r\n");

    deca_sleep(2);
}
Esempio n. 8
0
int main()
{
   Xil_ICacheEnable();
   Xil_DCacheEnable();
   
   
   print("---Entering main---\n\r");
   
   {
   	   printf("LEDs and switches\r\n");
   	    XGpio_Initialize(&inGpio,XPAR_AXI_GPIO_1_DEVICE_ID);
   	    XGpio_Initialize(&outGpio,XPAR_AXI_GPIO_0_DEVICE_ID);
   	    XGpio_DiscreteWrite(&outGpio,1,0); // leds off
      }

      {
   	   printf("Deca SPI test\r\n");

   	    if (0 != openspi()){
   	    	printf("Init SPI failed\r\n");
   	    } else {

   			// get switches
   			int sw = XGpio_DiscreteRead(&inGpio,1);
   			XGpio_DiscreteWrite(&outGpio,1,sw);
   			//printf("LED: %x\r\n",XGpio_DiscreteRead(&outGpio,1));

   			switch (sw & 0x7){

   			case 1:
   				printf("SS TWR INIT\r\n");
   				ssTwrInit();
   				break;
   			case 2:
   				printf("SS TWR RESP\r\n");
   				ssTwrResp();
   				break;
   			case 3:
   				printf("Simple TX\r\n");
   				simpleTx();
   				break;
   			case 4:
   				printf("Simple RX\r\n");
   				simpleRx();
   				break;
   			case 5:
   				printf("TX Wait\r\n");
   				txWait();
   				break;
   			case 6:
   				printf("RX Wait\r\n");
   				rxWait();
   				break;
   			default:

   			    /* Reset and initialise DW1000. */
   				reset_DW1000();
   				dwt_initialise(DWT_LOADNONE);
   				/* Configure DW1000. */
   				printf("UBW configuration sequence\r\n");
   				dwt_configure(&config);
   				dwt_configuretxrf(&txconfig);

   				/* Activate continuous wave mode. */
   				dwt_configcwmode(config.chan);

   				/* Wait for the wanted duration of the continuous wave transmission. */
   				printf("Waiting for UBW continuous wave transmission delay: %ds\r\n",CONT_WAVE_DURATION_MS/1000);
   				deca_sleep(CONT_WAVE_DURATION_MS);

   				/* Software reset of the DW1000 to deactivate continuous wave mode and go back to default state. Initialisation and configuration should be run
   				 * again if one wants to get the DW1000 back to normal operation. */
   				dwt_softreset();
   			}

   			printf("Deca test done. press any key\r\n");
   			getchar();
   	    }

      }


   print("---Exiting main---\n\r");
   Xil_DCacheDisable();
   Xil_ICacheDisable();
   return 0;
}
Esempio n. 9
0
/**
 * Application entry point.
 */
int main(void)
{
	int prijem=0;
	uint32 device_id;
    /* Start with board specific hardware init. */
    peripherals_init();

    spi_peripheral_init();

        Sleep(1000); //wait for LCD to power on

        initLCD();

    /* Display application name on LCD. */
    setLCDline1( 234);
   // Sleep(1000);
    usb_init();
    //Sleep(1000);
   // lcd_display_str("connected");
    /* Reset and initialise DW1000.
      * For initialisation, DW1000 clocks must be temporarily set to crystal speed. After initialisation SPI rate can be increased for optimum
      * performance. */
     reset_DW1000(); /* Target specific drive of RSTn line into DW1000 low for a period. */

     SPI_ChangeRate(SPI_BaudRatePrescaler_32);
    // spi_set_rate_low();
  //   uint32 temp = dwt_read32bitoffsetreg(AON_ID,AON_WCFG_OFFSET);
     dwt_initialise(DWT_LOADUCODE);


   //  dwt_configuresleepcnt(sleep16);  //needed for LPL
   //  dwt_configuresleep(DWT_LOADUCODE | DWT_LOADOPSET | DWT_PRESRV_SLEEP | DWT_CONFIG, DWT_WAKE_WK | DWT_SLP_EN); //needed for LPL
     SPI_ChangeRate(SPI_BaudRatePrescaler_4);
     //spi_set_rate_high();


   //  dwt_configure(&config);
     /* Loop forever receiving frames. */
       /* while (1)
        {
        	led_on(LED_ALL);
        	Sleep(100);
        	led_off(LED_ALL);
        	Sleep(100);

        	push_over_usb("nikola",6);
        	setLCDline1( 123);



        }*/

     s1switch = is_button_low(0) << 1 // is_switch_on(TA_SW1_2) << 2
     		| is_switch_on(TA_SW1_3) << 2
     		| is_switch_on(TA_SW1_4) << 3
     		| is_switch_on(TA_SW1_5) << 4
 		    | is_switch_on(TA_SW1_6) << 5
     		| is_switch_on(TA_SW1_7) << 6
     		| is_switch_on(TA_SW1_8) << 7;



     port_EnableEXT_IRQ();
     while(1){

    	 setLCDline1(123);
    	 deca_sleep(1000);

    	 device_id= inittestapplication(s1switch);
    	 setLCDline1(instance_data[0].mode);
    	 if(instance_mode == TAG){
    		 setLCDline1(1);
    	 }
    	 else if(instance_mode==ANCHOR){
    		 setLCDline1(2);
    	 }
    	 else {
    		 setLCDline1(3);
    	 }
    	 deca_sleep(1000);
    	// instance_run();

    	 //setLCDline1(message);
    	 instance_run();

     }





}
Esempio n. 10
0
/*! ------------------------------------------------------------------------------------------------------------------
 * @fn main()
 *
 * @brief Application entry point.
 *
 * @param  none
 *
 * @return none
 */
int ssTwrInit(void)
{

    /* Reset and initialise DW1000.
     * For initialisation, DW1000 clocks must be temporarily set to crystal speed. After initialisation SPI rate can be increased for optimum
     * performance. */
	int status;

	reset_DW1000(); /* Target specific drive of RSTn line into DW1000 low for a period. */
    //spi_set_rate_low();
    status = dwt_initialise(DWT_LOADUCODE);
    if (DWT_SUCCESS != status) printf("API error line %d\r\n",__LINE__);
    //spi_set_rate_high();

    /* Configure DW1000. See NOTE 6 below. */
    status = dwt_configure(&config);
    if (DWT_SUCCESS != status) printf("API error line %d\r\n",__LINE__);

    // read otp
    uint32_t otpVal[0x20];
    dwt_otpread(0,otpVal,0x20);
    printf("OTP   6: 0x%x\r\n",otpVal[6]);
    printf("OTP   7: 0x%x\r\n",otpVal[7]);
    printf("OTP x16: 0x%x\r\n",otpVal[0x16]);
    printf("OTP x17: 0x%x\r\n",otpVal[0x17]);

    /* Apply default antenna delay value. See NOTE 2 below. */
    printf("antenna delays: default TX: %d, default RX: %d, evk 16m: %d, evk 64m: %d\r\n",TX_ANT_DLY,RX_ANT_DLY,DWT_RF_DELAY_16M,DWT_RF_DELAY_64M);
    tx_delay = TX_ANT_DLY;
    rx_delay = RX_ANT_DLY;
    dwt_setrxantennadelay(rx_delay);
    dwt_settxantennadelay(tx_delay);

    /* Set expected response's delay and timeout. See NOTE 1 and 5 below.
     * As this example only handles one incoming frame with always the same delay and timeout, those values can be set here once for all. */
    dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS);
    dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS);

    btn = buttons();

    printf("%s entering main loop\r\n",__FUNCTION__);

    /* Loop forever initiating ranging exchanges. */
    while (1)
    {
        /* Write frame data to DW1000 and prepare transmission. See NOTE 7 below. */
        tx_poll_msg[ALL_MSG_SN_IDX] = frame_seq_nb;
        status = dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_TXFRS);
        if (DWT_SUCCESS != status) printf("API error line %d\r\n",__LINE__);
        status = dwt_writetxdata(sizeof(tx_poll_msg), tx_poll_msg, 0);
        if (DWT_SUCCESS != status) printf("API error line %d\r\n",__LINE__);
        status = dwt_writetxfctrl(sizeof(tx_poll_msg), 0);
        if (DWT_SUCCESS != status) printf("API error line %d\r\n",__LINE__);

        /* Start transmission, indicating that a response is expected so that reception is enabled automatically after the frame is sent and the delay
         * set by dwt_setrxaftertxdelay() has elapsed. */
        status = dwt_starttx(DWT_START_TX_IMMEDIATE | DWT_RESPONSE_EXPECTED);
        if (DWT_SUCCESS != status) printf("API error line %d\r\n",__LINE__);

        /* We assume that the transmission is achieved correctly, poll for reception of a frame or error/timeout. See NOTE 8 below. */
        while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))
        { } ; // printf("Waiting. status reg 0x%x\r\n",status_reg); };
        //printf("Status reg now 0x%x\r\n",status_reg);

        if (SYS_STATUS_RXRFTO & status_reg)
            printf("RX timeout\r\n");

        /* Increment frame sequence number after transmission of the poll message (modulo 256). */
        frame_seq_nb++;

        if (status_reg & SYS_STATUS_RXFCG)
        {
            uint32 frame_len;

            //printf("Check RX\r\n");
            /* Clear good RX frame event in the DW1000 status register. */
            dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RXFCG);

            /* A frame has been received, read it into the local buffer. */
            frame_len = dwt_read32bitreg(RX_FINFO_ID) & RX_FINFO_RXFLEN_MASK;
            if (frame_len <= RX_BUF_LEN)
            {
                dwt_readrxdata(rx_buffer, frame_len, 0);
            }

            /* Check that the frame is the expected response from the companion "SS TWR responder" example.
             * As the sequence number field of the frame is not relevant, it is cleared to simplify the validation of the frame. */
            rx_buffer[ALL_MSG_SN_IDX] = 0;
            if (memcmp(rx_buffer, rx_resp_msg, ALL_MSG_COMMON_LEN) == 0)
            {
                uint32 poll_tx_ts, resp_rx_ts, poll_rx_ts, resp_tx_ts;
                int32 rtd_init, rtd_resp;

                /* Retrieve poll transmission and response reception timestamps. See NOTE 9 below. */
                poll_tx_ts = dwt_readtxtimestamplo32();
                resp_rx_ts = dwt_readrxtimestamplo32();

                /* Get timestamps embedded in response message. */
                resp_msg_get_ts(&rx_buffer[RESP_MSG_POLL_RX_TS_IDX], &poll_rx_ts);
                resp_msg_get_ts(&rx_buffer[RESP_MSG_RESP_TX_TS_IDX], &resp_tx_ts);

                /* Compute time of flight and distance. */
                rtd_init = resp_rx_ts - poll_tx_ts;
                rtd_resp = resp_tx_ts - poll_rx_ts;

                tof = ((rtd_init - rtd_resp) / 2.0) * DWT_TIME_UNITS;
                distance = tof * SPEED_OF_LIGHT;

                /* Display computed distance on LCD. */
                //sprintf(dist_str, "DIST: %3.2f m", distance);
                sprintf(dist_str, "%3.2f", distance);
                printf("%s\r\n",dist_str);
                //lcd_display_str(dist_str);

            }
        }
        else
        {
            /* Clear RX error events in the DW1000 status register. */
            printf("Errors occured. Clearing up\r\n");
            dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR);
        }

        /* Execute a delay between ranging exchanges. */
        //printf("Delay %dms\r\n",RNG_DELAY_MS);
        deca_sleep(RNG_DELAY_MS);

        // toggle led
		ledToggle();
		// update antenna
		if (buttons() & 1) {
		    tx_delay -= 10; // >>= 1;
		    rx_delay -= 10; //>>= 1;
		    dwt_setrxantennadelay(rx_delay);
		    dwt_settxantennadelay(tx_delay);
		    printf("Decreased antenna delay to 0x%x\r\n",tx_delay);
		}
		if (buttons() & 2) {
			tx_delay += 10;
			rx_delay += 10;
		    dwt_setrxantennadelay(rx_delay);
		    dwt_settxantennadelay(tx_delay);
		    printf("Increased antenna delay to 0x%x\r\n",tx_delay);
		}

    }
}
Esempio n. 11
0
void tag_run(void) {

	// Setup DECAWAVE
	cph_deca_init_device();
	cph_deca_init_network(cph_config->panid, cph_config->shortid);

	// Set our short id in common messages
	tx_poll_msg.header.source = cph_config->shortid;
	tx_discover_msg.header.source = cph_config->shortid;
	tx_pair_msg.header.source = cph_config->shortid;
	tx_range_results_msg.header.source = cph_config->shortid;

	// First, discover anchors
	uint32_t anchor_refresh_ts = 0;
	refresh_anchors();
	anchor_refresh_ts = cph_get_millis();

	// Poll loop
	while (1) {

		int ranges_countdown = MAX_RANGES_BEFORE_POLL_TIMEOUT;
		anchors_status = ANCHORS_MASK;

		while (anchors_status && (--ranges_countdown)) {

			// Check for refresh of anchors
			uint32_t elapsed = cph_get_millis() - anchor_refresh_ts;
			if (elapsed > ANCHORS_REFRESH_INTERVAL) {
				printf("Anchors refresh timeout.  anchors_status:%02X\r\n", anchors_status);
				refresh_anchors();
				anchor_refresh_ts = cph_get_millis();
				// Since we refreshed the anchors, need to range again for ALL anchors during this poll
				anchors_status = ANCHORS_MASK;
			}

			// Range each anchor once during this poll
			for (int i = 0; i < ANCHORS_MIN; i++) {
				if (anchors_status & (1 << i)) {
					anchors[i].range = 0;
					int result = range(&anchors[i]);

					if (result == CPH_OK) {
						anchors_status &= (~(1 << i));
					}

					deca_sleep(RNG_DELAY_MS);
				}
			}

			deca_sleep(RNG_DELAY_MS);
		}

		if (ranges_countdown) {
			send_ranges(MAX_RANGES_BEFORE_POLL_TIMEOUT - ranges_countdown);
		}
		else {
			printf("ranges_countdown expired!\r\n");
		}

		// Execute a delay between ranging exchanges.
		deca_sleep(POLL_DELAY_MS);
	}
}