// Restart and re-configure void restartinstance(void) { instance_close() ; //shut down instance, PHY, SPI close, etc. spi_peripheral_init(); //re initialise SPI... inittestapplication(s1switch) ; //re-initialise instance/device } // end restartinstance()
portTASK_FUNCTION(task_decawave, pvParameters) { UNUSED(pvParameters); peripherals_init(); spi = spi_peripheral_init(); if (spi != NULL) { printf("FreeRTOS SPI master init success.\r\n"); } else { printf("FreeRTOS SPI master init ERROR.\r\n"); for (;;) { } } Sleep(1000); // initialize DW if (dwt_initialise(DWT_LOADNONE) == DWT_SUCCESS) { printf("dwt_initialize success.\r\n"); } else { printf("dwt_initialize ERROR.\r\n"); for (;;) { } } // get eui64 dwt_seteui(eui64); Sleep(1); dwt_geteui(eui64); printf("eui: "); printf("%02X ", eui64[0]); printf("%02X ", eui64[1]); printf("%02X ", eui64[2]); printf("%02X ", eui64[3]); printf("%02X ", eui64[4]); printf("%02X ", eui64[5]); printf("%02X ", eui64[6]); printf("%02X ", eui64[7]); printf("\r\n"); // enter polling loop for (;;) { } }
portTASK_FUNCTION(task_decawave, pvParameters) { UNUSED(pvParameters); int i = 0; int toggle = 1; int ranging = 0; uint8 dataseq[40]; double range_result = 0; double avg_result = 0; uint8 dataseq1[40]; uint8 command = 0x0; led_off(LED_ALL); //turn off all the LEDs peripherals_init(); spi_peripheral_init(); Sleep(1000); //wait for LCD to power on printf("DECAWAVE \r\n"); printf(SOFTWARE_VER_STRING); printf("\r\n"); Sleep(1000); port_DisableEXT_IRQ(); //disable ScenSor IRQ until we configure the device printf("DECAWAVE RANGE\r\n"); led_off(LED_ALL); int testresult = inittestapplication(); if (testresult < 0) { led_on(LED_ALL); //to display error.... printf("ERROR\r\n"); printf("INIT FAIL %d\r\n", testresult); for (;;) { } } //sleep for 5 seconds displaying "Decawave" i = 30; while (i--) { if (i & 1) led_off(LED_ALL); else led_on(LED_ALL); Sleep(200); } i = 0; led_off(LED_ALL); if (is_tag) { instance_mode = TAG; printf("TAG\r\n"); } else { instance_mode = ANCHOR; printf("ANCHOR\r\n"); #if (DR_DISCOVERY == 1) printf("DR_DISCOVER == 1\r\n"); #else printf("DR_DISCOVER == 0\r\n"); #endif } if (instance_mode == TAG) { //if TA_SW1_2 is on use fast ranging (fast 2wr) if (use_fast2wr) { printf("Fast Tag Ranging\r\n"); } else { printf("TAG BLINK %llX\r\n", instance_get_addr()); } } else { printf("AWAITING POLL\r\n"); } port_EnableEXT_IRQ(); //enable ScenSor IRQ before starting // main loop while (1) { //ERIC: Delay irq handling...will this work? uint32_t bail = 0; if (irq_set) { do { if (bail++ > 2000) { printf("BAIL!\r\n"); Sleep(10); for (;;) { } } instance_process_irq(0); } while (port_CheckEXT_IRQ() == 1); irq_set = 0x00; } instance_run(); if (instancenewrange()) { ranging = 1; //send the new range information to LCD and/or USB range_result = instance_get_idist(); #if (DR_DISCOVERY == 0) if(instance_mode == ANCHOR) #endif avg_result = instance_get_adist(); //set_rangeresult(range_result); printf("LAST: %4.2f m ", range_result); #if (DR_DISCOVERY == 0) if(instance_mode == ANCHOR) printf("AVG8: %4.2f m", avg_result); else printf("%llx", instance_get_anchaddr()); #else printf("AVG8: %4.2f m\r\n", avg_result); #endif } if (ranging == 0) { if (instance_mode != ANCHOR) { if (instancesleeping()) { if (toggle) { printf("AWAITING RESPONSE\r\n"); } else { toggle = 1; printf("TAG BLINK %llX\r\n", instance_get_addr()); } } if (instanceanchorwaiting() == 2) { ranging = 1; printf("RANGING WITH %016llX\r\n", instance_get_anchaddr()); } } else { if (instanceanchorwaiting()) { toggle += 2; if (toggle > 300000) { if (toggle & 0x1) { toggle = 0; printf("AWAITING POLL\r\n"); } else { toggle = 1; #if (DR_DISCOVERY == 1) printf("DISCOVERY MODE "); #else printf("NON DISCOVERY "); #endif printf("%llX\r\n", instance_get_addr()); } // print_status(); } } else if (instanceanchorwaiting() == 2) { printf("RANGING WITH %llX", instance_get_tagaddr()); } } } } }
/** * 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(); } }