void configSPIspeed(int high) { if(localSPIspeed != high) { localSPIspeed = high; if(high) SPI_ConfigFastRate(SPI_BaudRatePrescaler_4); //max SPI else SPI_ConfigFastRate(SPI_BaudRatePrescaler_32); //max SPI before PLLs configured is ~4M } }
int instance_starttxtest(int framePeriod) { //define some test data for the tx buffer 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 SPI_ConfigFastRate(SPI_BaudRatePrescaler_32); //max SPI before PLLs configured is ~4M // 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(framePeriod); 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 ; }
int instance_startcwmode(int chan) { //NOTE: SPI frequency must be < 3MHz //reduce the SPI speed before switching to XTAL SPI_ConfigFastRate(SPI_BaudRatePrescaler_16); //reduce SPI to < 3MHz dwt_configcwmode(chan); //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 DWT_SUCCESS ; }
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; }
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; }
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 }