Skip to content
Snippets Groups Projects
Select Git revision
  • eed065ce8873035cad3af627d2dfba22466828ef
  • master default protected
2 results

dw-range-tag.c

Blame
  • dw-range-tag.c 4.42 KiB
    /**
    * \file
     * 	Decawace uwb demo application
     * \author
     *	Kim Albertsson
     */
    
    // Tested with mulle board 145
    
    #include "contiki.h"
    
    #include <stdio.h> /* For printf() */
    #include <stdint.h>
    #include <stddef.h>
    
    #include "udelay.h"
    
    #include "dw1000-base.h"
    #include "dwFrameTypes.h"
    #include "dw-range.h"
    
    #define DEVICE_TIME_UNITS (1.0/499.2e6/128.0)
    #define ANTENNA_DELAY ((515.0 / 2.0) * 1e-9 / (1.0/499.2e6/128.0))
    
    typedef enum
    {
    	UNPAIRED = 0,
    	PAIRED
    } tag_state_t;
    
    extern struct process * interrupt_handler_callback;
    
    int error;
    
    /*---------------------------------------------------------------------------*/
    PROCESS(dw_main_process           , "Main process");
    PROCESS(dw_tag_process            , "Tag process (dw1000)");
    AUTOSTART_PROCESSES(&dw_main_process);
    /*---------------------------------------------------------------------------*/
    PROCESS_THREAD(dw_main_process, ev, data)
    {
    	PROCESS_BEGIN();
    
    	// Init dw1000
    	process_start(&dw_interrupt_callback_proc, NULL);
    
    	dw_init();
    	dw_conf_print();
    	interrupt_handler_callback = &dw_tag_process;
    	process_start(&dw_tag_process, NULL);
    
    	// Start code proper
    	while(1)
    	{
    		PROCESS_WAIT_EVENT();
    	}
     
      PROCESS_END();
    }
    /*---------------------------------------------------------------------------*/
    PROCESS_THREAD(dw_tag_process, ev, data)
    {
    	PROCESS_BEGIN();
    
    	static uint64_t dest_addr = 0ULL;
    	static uint16_t responseDelay;
    
    	static tag_state_t     tag_state     = UNPAIRED;
    	static ranging_state_t ranging_state = IDLE;