void xtalcalibration(void)
{
	int i;
	uint8 chan = 2 ;
	uint8 prf = DWT_PRF_16M ;
	dwt_txconfig_t  configTx ;
	uint8 pow ;
	
	//NOTE: SPI frequency must be < 3MHz
	//reduce the SPI speed before switching to XTAL
	//
	//	reset device 
	//
	dwt_softreset();

	//
	//	configure TX channel parameters
	//

	configTx.PGdly = txSpectrumConfig[chan].PGdelay ;

	//Assume smart power is disabled - not relevant for XTAL trimming as CW mode
    pow = txSpectrumConfig[chan].txPwr[prf - DWT_PRF_16M] & 0xFF ;
	configTx.power = (pow | (pow << 8) | (pow << 16) | (pow << 24));

	dwt_configuretxrf(&configTx);

	dwt_configcwmode(chan);

	for(i=0; i<=0x1F; i++)
	{
		dwt_xtaltrim(i);
		//measure the frequency
		//Spectrum Analyser set:
		//FREQ to be channel default e.g. 3.9936 GHz for channel 2
		//SPAN to 10MHz
		//PEAK SEARCH
	}

	return;
}
int powertest(void)
{
	dwt_config_t    configData ;
	dwt_txconfig_t  configTx ;
	uint8 pow;
	uint8 msg[127] = "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the l"; 
	
	//NOTE: SPI frequency must be < 3MHz
	//reduce the SPI speed before switching to XTAL
	//
	//	reset device 
	//
	dwt_softreset();

	//
	//	configure channel paramters
	//
    configData.chan = 2 ;
    configData.rxCode =  9 ;
	configData.txCode = 9 ;
    configData.prf = DWT_PRF_64M ;
    configData.dataRate = DWT_BR_110K ;
    configData.txPreambLength = DWT_PLEN_2048 ;
    configData.rxPAC = DWT_PAC64 ;
    configData.nsSFD = 1 ;
	configData.smartPowerEn = 0;

	dwt_configure(&configData, DWT_LOADANTDLY | DWT_LOADXTALTRIM) ;

	configTx.PGdly = txSpectrumConfig[configData.chan].PGdelay ;

	if(configData.smartPowerEn == 0)
	{
		pow = txSpectrumConfig[configData.chan].txPwr[configData.prf - DWT_PRF_16M] & 0xFF ;
		configTx.power = (pow | (pow << 8) | (pow << 16) | (pow << 24));
	}
	else
	{
		configTx.power = txSpectrumConfig[configData.chan].txPwr[configData.prf - DWT_PRF_16M];
	}

	dwt_configuretxrf(&configTx);

	// the value here 0x1000 gives a period of 32.82 �s
	//this is setting 0x1000 as frame period (125MHz clock cycles) (time from Tx en - to next - Tx en)
	dwt_configcontinuousframemode(0x1000);

	dwt_writetxdata(127, (uint8 *)  msg, 0) ;
	dwt_writetxfctrl(127, 0);

    //to start the first frame - set TXSTRT
	dwt_starttx(DWT_START_TX_IMMEDIATE); 

	//measure the power 
	//Spectrum Analyser set:
	//FREQ to be channel default e.g. 3.9936 GHz for channel 2
	//SPAN to 1GHz
	//SWEEP TIME 1s
	//RBW and VBW 1MHz
	//measure channel power

	return DWT_SUCCESS ;
}
Exemple #3
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;
}
Exemple #4
0
uint32 inittestapplication(void) {
	uint32 devID;
	instanceConfig_t instConfig;
	int i, result;

	SPI_ConfigFastRate(SPI_BaudRatePrescaler_16);  //max SPI before PLLs configured is ~4M

	i = 10;

	//this is called here to wake up the device (i.e. if it was in sleep mode before the restart)
	devID = instancereaddeviceid();
	printf("devID %08X\r\n", devID);
	//if the read of devide ID fails, the DW1000 could be asleep
	if (DWT_DEVICE_ID != devID) {
//		port_SPIx_clear_chip_select();  //CS low
//		Sleep(1);   //200 us to wake up then waits 5ms for DW1000 XTAL to stabilise
//		port_SPIx_set_chip_select();  //CS high
//		Sleep(7);

		printf("asleep...wakeup!\r\n");
		pio_set_pin_high(DW_WAKEUP_PIO_IDX);
		Sleep(1);
		pio_set_pin_low(DW_WAKEUP_PIO_IDX);
		Sleep(7);

		devID = instancereaddeviceid();
		printf("devID %08X\r\n", devID);
		// SPI not working or Unsupported Device ID
		if (DWT_DEVICE_ID != devID) {
			return (-1);
		}
		//clear the sleep bit - so that after the hard reset below the DW does not go into sleep
		dwt_softreset();
	}

	//reset the DW1000 by driving the RSTn line low
	reset_DW1000();

	result = instance_init();
	if (0 > result)
		return (-2); // Some failure has occurred

	SPI_ConfigFastRate(SPI_BaudRatePrescaler_4); //increase SPI to max
	devID = instancereaddeviceid();
	printf("devID %08X\r\n", devID);

	if (DWT_DEVICE_ID != devID)   // Means it is NOT MP device
			{
		// SPI not working or Unsupported Device ID
		return (-3);
	}

	if (is_tag) {
		instance_mode = TAG;
		led_on(LED_PC7);
	} else {
		instance_mode = ANCHOR;
#if (DR_DISCOVERY == 1)
		led_on(LED_PC6);
#else
		if(instance_anchaddr & 0x1)
		led_on(LED_PC6);

		if(instance_anchaddr & 0x2)
		led_on(LED_PC7);
#endif
	}

	instancesetrole(instance_mode);     // Set this instance role

	if (use_fast2wr) //if fast ranging then initialise instance for fast ranging application
	{
		instance_init_f(instance_mode); //initialise Fast 2WR specific data
		//when using fast ranging the channel config is either mode 2 or mode 6
		//default is mode 2
		dr_mode = decarangingmode();

		if ((dr_mode & 0x1) == 0)
			dr_mode = 1;
	} else {
		instance_init_s(instance_mode);
		dr_mode = decarangingmode();
	}

	instConfig.channelNumber = chConfig[dr_mode].channel;
	instConfig.preambleCode = chConfig[dr_mode].preambleCode;
	instConfig.pulseRepFreq = chConfig[dr_mode].prf;
	instConfig.pacSize = chConfig[dr_mode].pacSize;
	instConfig.nsSFD = chConfig[dr_mode].nsSFD;
	instConfig.sfdTO = chConfig[dr_mode].sfdTO;
	instConfig.dataRate = chConfig[dr_mode].datarate;
	instConfig.preambleLen = chConfig[dr_mode].preambleLength;

	instance_config(&instConfig);                  // Set operating channel etc

#if (DR_DISCOVERY == 0)
	addressconfigure();                            // set up initial payload configuration
#endif
	instancesettagsleepdelay(POLL_SLEEP_DELAY, BLINK_SLEEP_DELAY); //set the Tag sleep time

	//if TA_SW1_2 is on use fast ranging (fast 2wr)
	if (use_fast2wr) {
		//Fast 2WR specific config
		//configure the delays/timeouts
		instance_config_f();
	} else //use default ranging modes
	{
		// NOTE: this is the delay between receiving the blink and sending the ranging init message
		// The anchor ranging init response delay has to match the delay the tag expects
		// the tag will then use the ranging response delay as specified in the ranging init message
		// use this to set the long blink response delay (e.g. when ranging with a PC anchor that wants to use the long response times != 150ms)
		if (use_long_blink_delay) {
			instancesetblinkreplydelay(FIXED_LONG_BLINK_RESPONSE_DELAY);
		} else //this is for ARM to ARM tag/anchor (using normal response times 150ms)
		{
			instancesetblinkreplydelay(FIXED_REPLY_DELAY);
		}

		//set the default response delays
		instancesetreplydelay(FIXED_REPLY_DELAY, 0);
	}

//    return devID;
	return 0;
}
Exemple #5
0
uint32 inittestapplication(uint8 s1switch)
{
    uint32 devID ;
    instanceConfig_t instConfig;
    int result;

    SPI_ConfigFastRate(SPI_BaudRatePrescaler_32);  //max SPI before PLLs configured is ~4M

    //this is called here to wake up the device (i.e. if it was in sleep mode before the restart)
    devID = instancereaddeviceid() ;
    if(DWT_DEVICE_ID != devID) //if the read of device ID fails, the DW1000 could be asleep
    {
        port_SPIx_clear_chip_select();  //CS low
        Sleep(1);   //200 us to wake up then waits 5ms for DW1000 XTAL to stabilise
        port_SPIx_set_chip_select();  //CS high
        Sleep(7);
        devID = instancereaddeviceid() ;
        // SPI not working or Unsupported Device ID
        if(DWT_DEVICE_ID != devID)
            return(-1) ;
        //clear the sleep bit - so that after the hard reset below the DW does not go into sleep
        dwt_softreset();
    }

    //reset the DW1000 by driving the RSTn line low
    reset_DW1000();

    result = instance_init() ;
    if (0 > result) return(-1) ; // Some failure has occurred

    SPI_ConfigFastRate(SPI_BaudRatePrescaler_4); //increase SPI to max
    devID = instancereaddeviceid() ;

    if (DWT_DEVICE_ID != devID)   // Means it is NOT MP device
    {
        // SPI not working or Unsupported Device ID
        return(-1) ;
    }


    if(s1switch & SWS1_ANC_MODE)
    {
        instance_mode = ANCHOR;

        led_on(LED_PC6);

    }
    else
    {
        instance_mode = TAG;
        led_on(LED_PC7);
    }

    instancesetrole(instance_mode) ;     // Set this instance role

    instance_init_s(instance_mode);
    dr_mode = decarangingmode(s1switch);

    instConfig.channelNumber = chConfig[dr_mode].channel ;
    instConfig.preambleCode = chConfig[dr_mode].preambleCode ;
    instConfig.pulseRepFreq = chConfig[dr_mode].prf ;
    instConfig.pacSize = chConfig[dr_mode].pacSize ;
    instConfig.nsSFD = chConfig[dr_mode].nsSFD ;
    instConfig.sfdTO = chConfig[dr_mode].sfdTO ;
    instConfig.dataRate = chConfig[dr_mode].datarate ;
    instConfig.preambleLen = chConfig[dr_mode].preambleLength ;


    instance_config(&instConfig) ;                  // Set operating channel etc

    instancesettagsleepdelay(POLL_SLEEP_DELAY, BLINK_SLEEP_DELAY); //set the Tag sleep time

    instance_init_timings();

    return devID;
}
Exemple #6
0
/*
*********************************************************************************************************
*
*  loca_status dwt_config(eCHAN channel, ePRF prf, ePLEN PreambleLength, eCODE code, uint8_t nsSFD, DataRate db)
*
* 描     述 : 配置DW1000
*
* 输入参数 : 
*       channel:DW1000通道
        prf:
        PreambleLength:
        code:
        nsSFD:
        db:
*
* 输出参数 : DW1000状态
*********************************************************************************************************
*/
static loca_status dwt_config(eCHAN channel, ePRF prf, ePLEN PreambleLength, eCODE code, uint8_t nsSFD, DataRate db)
{
  dwt_config_t  config;
  dwt_txconfig_t txconfig;
  uint8_t buf[2];
  uint64_t      eui64;
  uint16_t      panid;
  
  eui64 = LOC_CFG_EUI;
  panid = LOC_CFG_PANID;
  
  config.chan   = channel;
  config.prf    = prf;
  
  config.txPreambLength = PreambleLength;
  
  switch (PreambleLength)
  {
  case PLEN_64:
  case PLEN_128:
    config.rxPAC        = DWT_PAC8;
    break;
  case PLEN_256:
  case PLEN_512:
    config.rxPAC	= DWT_PAC16;
    break;
  case PLEN_1024:
    config.rxPAC	= DWT_PAC32;
    break;
  default:
    config.rxPAC	= DWT_PAC64;
    break;
  }
  
  config.rxCode		= code;
  config.txCode		= code;
  config.nsSFD		= nsSFD;
  config.dataRate       = db;
  config.smartPowerEn	= 0;
  config.phrMode	= 0;
  
  txconfig.PGdly        = dwt_pgdelay[channel];
  txconfig.power	= dwt_manualpwr[prf - 1][channel];
  
  BSP_ChangeSPIRate(SPI_SLOW);
  dwt_softreset();
  if (dwt_initialise(DWT_LOADNONE) != DWT_SUCCESS)
  {
    BSP_ChangeSPIRate(SPI_FAST);
    return LOCA_FAULT;
  }
   
  BSP_ChangeSPIRate(SPI_FAST);
  
  if (dwt_readdevid() != DWT_DEVICE_ID)
  {
    return LOCA_FAULT;
  }
  
  buf[0] = 0x10;
  dwt_writetodevice(GPIO_CTRL_ID,0x02,1,&buf[0]);

  buf[0] = 0xf0;
  buf[1] = 0xf0;
  dwt_writetodevice(GPIO_CTRL_ID,0x08,2,&buf[0]);
  
  dwt_configure(&config, 0);
  dwt_xtaltrim(LOC_CFG_XTALRIM);
  dwt_setrxantennadelay(0);
  dwt_settxantennadelay(0);
  dwt_setsmarttxpower(0);
  dwt_configuretxrf(&txconfig);
  
  dwt_enableframefilter(DWT_FF_NOTYPE_EN);
  dwt_seteui((uint8_t *)&eui64);
  dwt_setpanid(panid);
  //开启硬件中断
  //BSP_DWTIntEnable();
  
 // dwt_setinterrupt( DWT_INT_TFRS, 1);
  dwt_setrxmode(DWT_RX_NORMAL,0,0);
  return LOCA_OK;
}