Пример #1
1
void set_subsequence_settings(uint8_t subseq_num, int role){
#ifdef DW_DEBUG
	printf("radio conf -> %u\r\n", subseq_num);
#endif

	//Change the channel depending on what subsequence number we're at
	uint32_t chan = (uint32_t)(subseq_num_to_chan(subseq_num, false));
	global_ranging_config.chan = (uint8_t)chan;
	dwt_configure(&global_ranging_config, 0);//(DWT_LOADANTDLY | DWT_LOADXTALTRIM));
	dwt_setsmarttxpower(global_ranging_config.smartPowerEn);
	global_tx_config.PGdly = pgDelay[global_ranging_config.chan];
	global_tx_config.power = txPower[global_ranging_config.chan];
	dwt_configuretxrf(&global_tx_config);
	dwt_setrxantennadelay(0);
	dwt_settxantennadelay(0);


	//Change what antenna we're listening on
	uint8_t ant_sel;
	if (role == ANCHOR) {
		ant_sel = subseq_num_to_anchor_sel(subseq_num);
	} else { // (role == TAG)
		ant_sel = subseq_num_to_tag_sel(subseq_num);
	}
	dw1000_choose_antenna(ant_sel);
}
Пример #2
0
int app_dw1000_init (
		int HACK_role,
		int HACK_EUI,
		void (*txcallback)(const dwt_callback_data_t *),
		void (*rxcallback)(const dwt_callback_data_t *)
		) {
	uint32_t devID;
	int err;

	// Start off DW1000 comms slow
	REG(SSI0_BASE + SSI_CR1) = 0;
	REG(SSI0_BASE + SSI_CPSR) = 8;
	REG(SSI0_BASE + SSI_CR1) |= SSI_CR1_SSE;

	// Reset the DW1000...for some reason
	dw1000_reset();

	// Make sure we can talk to the DW1000
	devID = dwt_readdevid();
	if (devID != DWT_DEVICE_ID) {
#ifdef DW_DEBUG
		printf("Could not read Device ID from the DW1000\r\n");
		printf("Possible the chip is asleep...\r\n");
#endif
		return -1;
	}

	// Select which of the three antennas on the board to use
	dw1000_choose_antenna(0);

	// Init the dw1000 hardware
	err = dwt_initialise(DWT_LOADUCODE    |
			DWT_LOADLDO      |
			DWT_LOADTXCONFIG |
			DWT_LOADXTALTRIM);
	if (err != DWT_SUCCESS) {
		return -1;
	}

	// Setup interrupts
	// Note: using auto rx re-enable so don't need to trigger on error frames
	dwt_setinterrupt(DWT_INT_TFRS |
			DWT_INT_RFCG |
			DWT_INT_SFDT |
			DWT_INT_RFTO |
			DWT_INT_RPHE |
			DWT_INT_RFCE |
			DWT_INT_RFSL |
			DWT_INT_RXPTO |
			DWT_INT_SFDT, 1);

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

	// Set the parameters of ranging and channel and whatnot
	global_ranging_config.chan           = 2;
	global_ranging_config.prf            = DWT_PRF_64M;
	global_ranging_config.txPreambLength = DWT_PLEN_64;//DWT_PLEN_4096
	// global_ranging_config.txPreambLength = DWT_PLEN_256;
	global_ranging_config.rxPAC          = DWT_PAC8;
	global_ranging_config.txCode         = 9;  // preamble code
	global_ranging_config.rxCode         = 9;  // preamble code
	global_ranging_config.nsSFD          = 0;
	global_ranging_config.dataRate       = DWT_BR_6M8;
	global_ranging_config.phrMode        = DWT_PHRMODE_EXT; //Enable extended PHR mode (up to 1024-byte packets)
	global_ranging_config.smartPowerEn   = 1;
	global_ranging_config.sfdTO          = 64+8+1;//(1025 + 64 - 32);
	dwt_configure(&global_ranging_config, 0);//(DWT_LOADANTDLY | DWT_LOADXTALTRIM));
	dwt_setsmarttxpower(global_ranging_config.smartPowerEn);

	// Configure TX power
	{
		global_tx_config.PGdly = pgDelay[global_ranging_config.chan];
		global_tx_config.power = txPower[global_ranging_config.chan];
		dwt_configuretxrf(&global_tx_config);
	}

	/* All constants same anyway
	if(DW1000_ROLE_TYPE == TAG)
		dwt_xtaltrim(xtaltrim[0]);
	else
		dwt_xtaltrim(xtaltrim[ANCHOR_EUI]);
	*/
	dwt_xtaltrim(xtaltrim[0]);

	////TEST 1: XTAL trim calibration
	//dwt_configcwmode(global_ranging_config.chan);
	//dwt_xtaltrim(8);
	//while(1);

	//{
	//    //TEST 2: TX Power level calibration
	//    uint8_t 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";
	//    dwt_configcontinuousframemode(0x1000);
	//    dwt_writetxdata(127, (uint8 *)  msg, 0) ;
	//    dwt_writetxfctrl(127, 0);
	//    dwt_starttx(DWT_START_TX_IMMEDIATE);
	//    while(1);
	//}

	// Configure the antenna delay settings
	{
		uint16_t antenna_delay;

		//Antenna delay not really necessary if we're doing an end-to-end calibration
		antenna_delay = 0;
		dwt_setrxantennadelay(antenna_delay);
		dwt_settxantennadelay(antenna_delay);
		//global_tx_antenna_delay = antenna_delay;

		//// Shift this over a bit for some reason. Who knows.
		//// instance_common.c:508
		//antenna_delay = dwt_readantennadelay(global_ranging_config.prf) >> 1;
		//if (antenna_delay == 0) {
		//    printf("resetting antenna delay\r\n");
		//    // If it's not in the OTP, use a magic value from instance_calib.c
		//    antenna_delay = ((DWT_PRF_64M_RFDLY/ 2.0) * 1e-9 / DWT_TIME_UNITS);
		//    dwt_setrxantennadelay(antenna_delay);
		//    dwt_settxantennadelay(antenna_delay);
		//}
		//global_tx_antenna_delay = antenna_delay;
		//printf("tx antenna delay: %u\r\n", antenna_delay);
	}

	// // Set the sleep delay. Not sure what this does actually.
	// instancesettagsleepdelay(POLL_SLEEP_DELAY, BLINK_SLEEP_DELAY);


	// Configure as either a tag or anchor

	if (HACK_role == ANCHOR) {
		uint8_t eui_array[8];

		// Enable frame filtering
		dwt_enableframefilter(DWT_FF_DATA_EN | DWT_FF_ACK_EN);

		dw1000_populate_eui(eui_array, HACK_EUI);
		dwt_seteui(eui_array);
		dwt_setpanid(DW1000_PANID);

		// We do want to enable auto RX
		dwt_setautorxreenable(1);
		// Let's do double buffering
		dwt_setdblrxbuffmode(0);
		// Disable RX timeout by setting to 0
		dwt_setrxtimeout(0);

		// Go for receiving
		dwt_rxenable(0);

	} else if (HACK_role == TAG) {
		uint8_t eui_array[8];

		// Allow data and ack frames
		dwt_enableframefilter(DWT_FF_DATA_EN | DWT_FF_ACK_EN);

		dw1000_populate_eui(eui_array, HACK_EUI);
		dwt_seteui(eui_array);
		dwt_setpanid(DW1000_PANID);

		// Do this for the tag too
		dwt_setautorxreenable(1);
		dwt_setdblrxbuffmode(1);
		dwt_enableautoack(5 /*ACK_RESPONSE_TIME*/);

		// Configure sleep
		{
			int mode = DWT_LOADUCODE    |
				DWT_PRESRV_SLEEP |
				DWT_CONFIG       |
				DWT_TANDV;
			if (dwt_getldotune() != 0) {
				// If we need to use LDO tune value from OTP kick it after sleep
				mode |= DWT_LOADLDO;
			}
			// NOTE: on the EVK1000 the DEEPSLEEP is not actually putting the
			// DW1000 into full DEEPSLEEP mode as XTAL is kept on
			dwt_configuresleep(mode, DWT_WAKE_CS | DWT_SLP_EN);
		}

	}

	// Make it fast
	REG(SSI0_BASE + SSI_CR1) = 0;
	REG(SSI0_BASE + SSI_CPSR) = 2;
	REG(SSI0_BASE + SSI_CR1) |= SSI_CR1_SSE;

	return 0;
}
Пример #3
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;
}
Пример #4
0
// First (generic) init of the DW1000
dw1000_err_e dw1000_init () {

	// Do the STM setup that initializes pin and peripherals and whatnot.
	if (!_stm_dw1000_interface_setup) {
		setup();
	}

	// Reset the dw1000...for some reason
	dw1000_reset();
	uDelay(100);

	// Make sure we can talk to the DW1000
	uint32_t devID;
	devID = dwt_readdevid();
	if (devID != DWT_DEVICE_ID) {
		//if we can't talk to dw1000, return with an error
		uDelay(1000);
		return DW1000_COMM_ERR;
	}

	GPIO_WriteBit(STM_GPIO3_PORT, STM_GPIO3_PIN, Bit_SET);
	uDelay(1000);
	GPIO_WriteBit(STM_GPIO3_PORT, STM_GPIO3_PIN, Bit_RESET);

	// Choose antenna 0 as a default
	dw1000_choose_antenna(0);

	// Initialize the dw1000 hardware
	uint32_t err;
	err = dwt_initialise(DWT_LOADUCODE |
	                     DWT_LOADLDO |
	                     DWT_LOADTXCONFIG |
	                     DWT_LOADXTALTRIM);

	if (err != DWT_SUCCESS) {
		return DW1000_COMM_ERR;
	}

	// Configure interrupts and callbacks
	dwt_setinterrupt(0xFFFFFFFF, 0);
	dwt_setinterrupt(DWT_INT_TFRS |
	                 DWT_INT_RFCG |
	                 DWT_INT_RPHE |
	                 DWT_INT_RFCE |
	                 DWT_INT_RFSL |
	                 DWT_INT_RFTO |
	                 DWT_INT_RXPTO |
	                 DWT_INT_SFDT |
	                 DWT_INT_ARFE, 1);

	dwt_setcallbacks(txcallback, rxcallback);

	// Set the parameters of ranging and channel and whatnot
	global_ranging_config.chan           = 2;
	global_ranging_config.prf            = DWT_PRF_64M;
	global_ranging_config.txPreambLength = DWT_PLEN_64;
	global_ranging_config.rxPAC          = DWT_PAC8;
	global_ranging_config.txCode         = 9;  // preamble code
	global_ranging_config.rxCode         = 9;  // preamble code
	global_ranging_config.nsSFD          = 0;
	global_ranging_config.dataRate       = DWT_BR_6M8;
	global_ranging_config.phrMode        = DWT_PHRMODE_EXT; //Enable extended PHR mode (up to 1024-byte packets)
	global_ranging_config.smartPowerEn   = 1;
	global_ranging_config.sfdTO          = 64+8+1;//(1025 + 64 - 32);
#if DW1000_USE_OTP
	dwt_configure(&global_ranging_config, (DWT_LOADANTDLY | DWT_LOADXTALTRIM));
#else
	dwt_configure(&global_ranging_config, 0);
#endif
	dwt_setsmarttxpower(global_ranging_config.smartPowerEn);

	// Configure TX power based on the channel used
	global_tx_config.PGdly = pgDelay[global_ranging_config.chan];
	global_tx_config.power = txPower[global_ranging_config.chan];
	dwt_configuretxrf(&global_tx_config);

	// Need to set some radio properties. Ideally these would come from the
	// OTP memory on the DW1000
#if DW1000_USE_OTP == 0

	// This defaults to 8. Don't know why.
	dwt_xtaltrim(8);

	// Antenna delay we don't really care about so we just use 0
	dwt_setrxantennadelay(DW1000_ANTENNA_DELAY_RX);
	dwt_settxantennadelay(DW1000_ANTENNA_DELAY_TX);
#endif

	return DW1000_NO_ERR;
}
Пример #5
0
void config_data(data_t *data)
{
    int use_otpdata = DWT_LOADANTDLY | DWT_LOADXTALTRIM;
    uint32 power = 0;

    data->configData.chan = 5 ;
    data->configData.rxCode =  9;
    data->configData.txCode = 9 ;
    data->configData.prf = DWT_PRF_64M ;
    data->configData.dataRate = DWT_BR_6M8 ;
    data->configData.txPreambLength = DWT_PLEN_128 ;
    data->configData.rxPAC = DWT_PAC8 ;
    data->configData.nsSFD = 0 ;
    data->configData.phrMode = DWT_PHRMODE_STD ;
    data->configData.sfdTO = (129 + 8 - 8);

    //enable gating gain for 6.81Mbps data rate
    if(data->configData.dataRate == DWT_BR_6M8)
        data->configData.smartPowerEn = 1;
    else
        data->configData.smartPowerEn = 0;

    //configure the channel parameters
    dwt_configure(&data->configData, use_otpdata) ;

    data->configTX.PGdly = txSpectrumConfig[data->configData.chan].PGdelay ;

    //firstly check if there are calibrated TX power value in the DW1000 OTP
    power = dwt_getotptxpower(data->configData.prf, data->configData.chan);

    if((power == 0x0) || (power == 0xFFFFFFFF)) //if there are no calibrated values... need to use defaults
    {
        power = txSpectrumConfig[data->configData.chan].txPwr[data->configData.prf- DWT_PRF_16M];
    }

    //Configure TX power
    //if smart power is used then the value as read from OTP is used directly
    //if smart power is used the user needs to make sure to transmit only one frame per 1ms or TX spectrum power will be violated
    if(data->configData.smartPowerEn == 1)
    {
        data->configTX.power = power;
    }
	else //if the smart power is not used, then the low byte value (repeated) is used for the whole TX power register
    {
        uint8 pow = power & 0xFF ;
        data->configTX.power = (pow | (pow << 8) | (pow << 16) | (pow << 24));
    }
    dwt_setsmarttxpower(data->configData.smartPowerEn);

    //configure the tx spectrum parameters (power and PG delay)
    dwt_configuretxrf(&data->configTX);

    //check if to use the antenna delay calibration values as read from the OTP
    if((use_otpdata & DWT_LOADANTDLY) == 0)
    {
        data->txantennaDelay = rfDelays[data->configData.prf - DWT_PRF_16M];
        // -------------------------------------------------------------------------------------------------------------------
        // set the antenna delay, we assume that the RX is the same as TX.
        dwt_setrxantennadelay(data->txantennaDelay);
        dwt_settxantennadelay(data->txantennaDelay);
    }
    else
    {
        //get the antenna delay that was read from the OTP calibration area
        data->txantennaDelay = dwt_readantennadelay(data->configData.prf) >> 1;

        // if nothing was actually programmed then set a reasonable value anyway
        if (data->txantennaDelay == 0)
        {
            data->txantennaDelay = rfDelays[data->configData.prf - DWT_PRF_16M];
            // -------------------------------------------------------------------------------------------------------------------
            // set the antenna delay, we assume that the RX is the same as TX.
            dwt_setrxantennadelay(data->txantennaDelay);
            dwt_settxantennadelay(data->txantennaDelay);
        }


    }

    if(data->configData.txPreambLength == DWT_PLEN_64) //if preamble length is 64
	{
    	SPI_ConfigFastRate(SPI_BaudRatePrescaler_16); //reduce SPI to < 3MHz

		dwt_loadopsettabfromotp(0);

		SPI_ConfigFastRate(SPI_BaudRatePrescaler_4); //increase SPI to max
    }

	//config is needed before reply delays are configured

}