diff --git a/software/module/firmware/app_standard_common.c b/software/module/firmware/app_standard_common.c index e7e246a8..a2e0f6b7 100644 --- a/software/module/firmware/app_standard_common.c +++ b/software/module/firmware/app_standard_common.c @@ -54,7 +54,7 @@ void standard_configure (module_config_t* config) { // Set EUI dw1000_read_eui(_config.my_EUI); // FIXME: Load actual EUI to FLASH - _config.my_EUI[0] = 0xF0; + _config.my_EUI[0] = APP_EUI_FIRST_BYTE; // Now init based on role _config.init_active = FALSE; @@ -123,7 +123,7 @@ void standard_start () { // Make sure the SPI speed is slow for this function dw1000_spi_slow(); - // Setup callbacks to this ANCHOR + // Setup general callbacks dwt_setcallbacks(common_txcallback, common_rxcallback, common_rxcallback, common_rxcallback); // Make sure the radio starts off @@ -133,6 +133,7 @@ void standard_start () { dwt_enableframefilter(DWT_FF_DATA_EN | DWT_FF_ACK_EN); // Don't use these + dwt_setdblrxbuffmode(FALSE); dwt_setrxtimeout(FALSE); // Make SPI fast now that everything has been setup diff --git a/software/module/firmware/app_standard_init.c b/software/module/firmware/app_standard_init.c index 256fe10e..1a9a2bb4 100644 --- a/software/module/firmware/app_standard_init.c +++ b/software/module/firmware/app_standard_init.c @@ -37,7 +37,7 @@ void standard_initiator_init (standard_init_scratchspace_struct *app_scratchspac // Initialize important variables inside scratchspace si_scratch->pp_tag_poll_pkt = (struct pp_tag_poll) { - { // 802.15.4 HEADER + .header = { // 802.15.4 HEADER { 0x41, // FCF[0]: data frame, panid compression 0xC8 // FCF[1]: ext source address, compressed destination @@ -54,18 +54,21 @@ void standard_initiator_init (standard_init_scratchspace_struct *app_scratchspac { 0 } // Source (blank for now) }, // PACKET BODY - MSG_TYPE_PP_NOSLOTS_TAG_POLL, // Message type - 0, // Sub Sequence number - NUM_RANGING_BROADCASTS-1, - RANGING_LISTENING_WINDOW_US, - RANGING_LISTENING_SLOT_US, - { { 0 } } + .message_type = MSG_TYPE_PP_NOSLOTS_TAG_POLL, // Message type + .subsequence = 0, // Sub Sequence number + .reply_after_subsequence = NUM_RANGING_BROADCASTS-1, + .anchor_reply_window_in_us = RANGING_LISTENING_WINDOW_US, + .anchor_reply_slot_time_in_us = RANGING_LISTENING_SLOT_US, + .footer = { + { 0 } + } }; // Make sure the SPI speed is slow for this function dw1000_spi_slow(); - dwt_setdblrxbuffmode(TRUE);//FALSE); + // FIXME: Is the double receiver buffer necessary / useful? + //dwt_setdblrxbuffmode(TRUE);//FALSE); dwt_enableautoack(DW1000_ACK_RESPONSE_TIME); // Make SPI fast now that everything has been setup diff --git a/software/module/firmware/app_standard_resp.c b/software/module/firmware/app_standard_resp.c index 4828738d..67e0d7d4 100644 --- a/software/module/firmware/app_standard_resp.c +++ b/software/module/firmware/app_standard_resp.c @@ -328,19 +328,20 @@ void resp_rxcallback (const dwt_cb_data_t *rxd, uint8_t * buf, uint64_t dw_rx_ti // Record the EUI of the tag so that we don't get mixed up memcpy(sr_scratch->pp_anc_final_pkt.ieee154_header_unicast.destAddr, rx_poll_pkt->header.sourceAddr, 8); + // Record which ranging subsequence the tag is on sr_scratch->ranging_broadcast_ss_num = rx_poll_pkt->subsequence; - // Record the timestamp. Need to subtract off the TX+RX delay from each recorded - // timestamp. + + // Record the timestamp. Need to subtract off the TX+RX delay from each recorded timestamp. sr_scratch->pp_anc_final_pkt.first_rxd_toa = dw_rx_timestamp - standard_get_rxdelay_from_subsequence(sr_scratch->ranging_broadcast_ss_num); sr_scratch->pp_anc_final_pkt.first_rxd_idx = sr_scratch->ranging_broadcast_ss_num; - sr_scratch->pp_anc_final_pkt.TOAs[sr_scratch->ranging_broadcast_ss_num] = - (dw_rx_timestamp - standard_get_rxdelay_from_subsequence(sr_scratch->ranging_broadcast_ss_num)) & 0xFFFF; - // Also record parameters the tag has sent us about how to respond - // (or other operational parameters). - sr_scratch->ranging_operation_config.reply_after_subsequence = rx_poll_pkt->reply_after_subsequence; - sr_scratch->ranging_operation_config.resp_reply_window_in_us = rx_poll_pkt->anchor_reply_window_in_us; - sr_scratch->ranging_operation_config.resp_reply_slot_time_in_us = rx_poll_pkt->anchor_reply_slot_time_in_us; + + sr_scratch->pp_anc_final_pkt.TOAs[sr_scratch->ranging_broadcast_ss_num] = (dw_rx_timestamp - standard_get_rxdelay_from_subsequence(sr_scratch->ranging_broadcast_ss_num)) & 0xFFFF; + + // Also record parameters the tag has sent us about how to respond (or other operational parameters). + sr_scratch->ranging_operation_config.reply_after_subsequence = NUM_RANGING_BROADCASTS - 1; //rx_poll_pkt->reply_after_subsequence; + sr_scratch->ranging_operation_config.resp_reply_window_in_us = RANGING_LISTENING_WINDOW_US; //rx_poll_pkt->anchor_reply_window_in_us; + sr_scratch->ranging_operation_config.resp_reply_slot_time_in_us = RANGING_LISTENING_SLOT_US; //rx_poll_pkt->anchor_reply_slot_time_in_us; // Update the statistics we keep about which antenna // receives the most packets from the tag diff --git a/software/module/firmware/dw1000.c b/software/module/firmware/dw1000.c index 6639d61b..ae5c3606 100644 --- a/software/module/firmware/dw1000.c +++ b/software/module/firmware/dw1000.c @@ -861,6 +861,10 @@ dw1000_err_e dw1000_configure_settings () { // Set this node's ID and the PAN ID for our DW1000 ranging system uint8_t eui_array[8]; dw1000_read_eui(eui_array); + + // FIXME: Set EUI in Flash directly + eui_array[0] = APP_EUI_FIRST_BYTE; + dwt_seteui(eui_array); dwt_setpanid(MODULE_PANID); diff --git a/software/module/firmware/firmware.h b/software/module/firmware/firmware.h index 5c31803c..fb055d4d 100644 --- a/software/module/firmware/firmware.h +++ b/software/module/firmware/firmware.h @@ -35,6 +35,9 @@ typedef enum { /******************************************************************************/ #define MODULE_PANID 0x6611 +// FIXME: Put correct EUI in Flash +#define APP_EUI_FIRST_BYTE 0x01 + /******************************************************************************/ // I2C for the application /******************************************************************************/ diff --git a/software/module/firmware/module_conf.h b/software/module/firmware/module_conf.h index 2fb7fddf..02ed08ee 100644 --- a/software/module/firmware/module_conf.h +++ b/software/module/firmware/module_conf.h @@ -31,7 +31,7 @@ #define DW1000_SFD_TO (64 + 1 + 8 - 8) /* (Preamble length + 1 + SFD length - PAC size) */ #define RANGING_BROADCASTS_PERIOD_US 1000 #define RANGING_LISTENING_WINDOW_US 8000 - #define RANGING_LISTENING_WINDOW_PADDING_US 2000 // This must be large enough so that setup can always occur, even for small EUIs (which influence the random state of the app) + #define RANGING_LISTENING_WINDOW_PADDING_US 1100 #endif // Protocol adaptation -------------------------------------------------------------------------------------------------