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; }