instance_init 函数追下去,绝大多数的代码都在初始化如下结构体

  1. typedef struct
  2. {
  3. INST_MODE mode; instance_init -ANCHOR //instance mode (tag or anchor)
  4. INST_STATES testAppState ; int instance_init_s(int mode) TA_INIT //state machine - current state
  5. INST_STATES nextState ; //state machine - next state
  6. INST_STATES previousState ; //state machine - previous state
  7. int done ; //done with the current event/wait for next event to arrive

  8. //configuration structures
  9. dwt_config_t configData ; //DW1000 channel configuration
  10. dwt_txconfig_t configTX ; //DW1000 TX power configuration
  11. uint16 txantennaDelay ; //DW1000 TX antenna delay
  12. uint16 rxantennaDelay ; //DW1000 RX antenna delay
  13. uint8 antennaDelayChanged;
  14. // "MAC" features
  15. uint8 frameFilteringEnabled ; //frame filtering is enabled
  16. // Is sleeping between frames enabled?
  17. uint8 sleep_en; instance_init 1
  18.  
  19. //timeouts and delays
  20. int tagSleepTime_ms; instancesettagsleepdelay 500//in milliseconds
  21. int tagBlinkSleepTime_ms; instancesettagsleepdelay 1000
  22. //this is the delay used for the delayed transmit (when sending the ranging init, response, and final messages)
  23. uint64 rnginitReplyDelay ;
  24. uint64 finalReplyDelay ;
  25. uint64 responseReplyDelay ;
  26. int finalReplyDelay_ms ;
  27.  
  28. // xx_sy the units are 1.0256 us
  29. uint32 txToRxDelayAnc_sy ; // this is the delay used after sending a response and turning on the receiver to receive final
  30. uint32 txToRxDelayTag_sy ; // this is the delay used after sending a poll and turning on the receiver to receive response
  31. int rnginitW4Rdelay_sy ; // this is the delay used after sending a blink and turning on the receiver to receive the ranging init message
  32. int fwtoTime_sy ; //this is final message duration (longest out of ranging messages)
  33. int fwtoTimeB_sy ; //this is the ranging init message duration
  34. uint32 delayedReplyTime; // delayed reply time of delayed TX message - high 32 bits
  35. uint32 rxTimeouts ; instanceclearcounts 0
  36.  
  37. // - not used in the ARM code uint32 responseTimeouts ;
  38. // Pre-computed frame lengths for frames involved in the ranging process,
  39. // in microseconds.
  40. uint32 fl_us[FRAME_TYPE_NB];
  41. //message structures used for transmitted messages
  42. #if (USING_64BIT_ADDR == 1)
  43. srd_msg_dlsl rng_initmsg ; // ranging init message (destination long, source long)
  44. srd_msg_dlsl msg ; // simple 802.15.4 frame structure (used for tx message) - using long addresses
  45. #else
  46. srd_msg_dlss rng_initmsg ; // ranging init message (destination long, source short)
  47. srd_msg_dsss msg ; // simple 802.15.4 frame structure (used for tx message) - using short addresses
  48. #endif
  49. iso_IEEE_EUI64_blink_msg blinkmsg ; // frame structure (used for tx blink message)
  50. //messages used in "fast" ranging ...
  51. srd_msg_dlss rnmsg ; // ranging init message structure
  52. srd_msg_dsss msg_f ; // ranging message with 16-bit addresses - used for "fast" ranging
  53.  
  54. //Tag function address/message configuration
  55. uint8 eui64[8]; // devices EUI 64-bit address
  56. uint16 tagShortAdd ; // Tag's short address (16-bit) used when USING_64BIT_ADDR == 0
  57. uint16 psduLength ; // used for storing the frame length
  58. uint8 frame_sn; instanceclearcounts 0 // modulo 256 frame sequence number - it is incremented for each new frame transmittion
  59. uint16 panid ; instance_init 0 xdeca // panid used in the frames
  60. uint8 relpyAddress[8] ; // address of the anchor the tag is ranging with
  61. //64 bit timestamps
  62. //union of TX timestamps
  63. union {
  64. uint64 txTimeStamp ; // last tx timestamp
  65. uint64 tagPollTxTime ; // tag's poll tx timestamp
  66. uint64 anchorRespTxTime ; // anchor's reponse tx timestamp
  67. }txu;
  68. uint64 anchorRespRxTime ; // receive time of response message
  69. uint64 tagPollRxTime ; // receive time of poll message
  70.  
  71. //32 bit timestamps (when "fast" ranging is used)
  72. uint32 tagPollTxTime32l ; // poll tx time - low 32 bits
  73. uint32 tagPollRxTime32l ; // poll rx time - low 32 bits
  74. uint32 anchorRespTxTime32l ; // response tx time - low 32 bits
  75. uint32 anchResp1RxTime32l ; // response 1 rx time - low 32 bits
  76.  
  77. //application control parameters
  78. uint8 wait4ack ; instance_init 0 // if this is set to DWT_RESPONSE_EXPECTED, then the receiver will turn on automatically after TX completion
  79. uint8 instToSleep; instance_init 0 // if set the instance will go to sleep before sending the blink/poll message
  80. uint8 stoptimer; instance_init 0 // stop/disable an active timer
  81. uint8 instancetimer_en; instance_init 0 // enable/start a timer
  82. uint32 instancetimer; // e.g. this timer is used to timeout Tag when in deep sleep so it can send the next poll message
  83. uint32 instancetimer_saved;
  84. // - not used in the ARM code
  85. //uint8 deviceissleeping; // this disabled reading/writing to DW1000 while it is in sleep mode
  86.  
  87. // (DW1000 will wake on chip select so need to disable and chip select line activity)
  88. uint8 gotTO; // got timeout event
  89. uint8 responseRxNum; // response number
  90.  
  91. //diagnostic counters/data, results and logging
  92. int32 tof32 ;
  93. int64 tof ; instance_init 0
  94. double clockOffset ; instance_init 0
  95. uint32 blinkRXcount ; instcleartaglist 0
  96. int txmsgcount; instanceclearcounts 0
  97. int rxmsgcount; instanceclearcounts 0
  98. int lateTX; instanceclearcounts 0
  99. int lateRX; instanceclearcounts 0
  100. double adist[RTD_MED_SZ] ;
  101. double adist4[4] ;
  102. double longTermRangeSum ; instanceclearcounts 0
  103. int longTermRangeCount ; instanceclearcounts 0
  104. int tofindex ; instance_init 0 instanceclearcounts 0
  105. int tofcount ; instance_init 0 instanceclearcounts 0
  106. int last_update ; // detect changes to status report
  107. double idistmax; instanceclearcounts 0
  108. double idistmin; instanceclearcounts 1000
  109. double idistance ; // instantaneous distance
  110. int newrange;
  111. int norange;
  112. int newrangeancaddress; //last 4 bytes of anchor address
  113. int newrangetagaddress; //last 4 bytes of tag address
  114. // - not used in the ARM code uint32 lastReportTime;
  115. int respPSC;
  116. //if set to 1 then it means that DW1000 is in DEEP_SLEEP
  117. //so the ranging has finished and micro can output on USB/LCD
  118. //if sending data to LCD during ranging this limits the speed of ranging
  119. uint8 canprintinfo ;
  120. //devicelogdata_t devicelogdata;
  121. uint8 tagToRangeWith; instcleartaglist 0//it is the index of the tagList array which contains the address of the Tag we are ranging with
  122. uint8 tagListLen ; instcleartaglist 0
  123. uint8 anchorListIndex ; int instance_init_s(int mode) 0
  124. uint8 tagList[TAG_LIST_SIZE][8]; instcleartaglist 0
  125. //event queue - used to store DW1000 events as they are processed by the dw_isr/callback functions
  126. event_data_t dwevent[MAX_EVENT_NUMBER]; instance_clearevents 0 //this holds any TX/RX events and associated message data
  127. event_data_t saved_dwevent; //holds an RX event while the ACK is being sent
  128. uint8 dweventIdxOut; instance_clearevents 0
  129. uint8 dweventIdxIn; instance_clearevents 0
  130. uint8 dweventPeek; instance_clearevents 0
  131. uint8 monitor; instance_init 0
  132. uint32 timeofTx ;
  133. int dwIDLE;
  134. } instance_data_t ;

上述默认初始化设别为,但是后面接着会根据拨码开关再次决定设备类型

  1. if(s1switch & SWS1_ANC_MODE)
  2. {
  3. instance_mode = ANCHOR;
  4. led_on(LED_PC6);
  5. }
  6. else
  7. {
  8. instance_mode = TAG;
  9. led_on(LED_PC7);
    }

并再次调用函数设置设备类型

  1. //Set this instance role as the Tag, Anchor or Listener
  2. void instancesetrole(int inst_mode)
  3. {
  4. // assume instance 0, for this
  5. instance_data[0].mode = inst_mode; // set the role
  6. }

注意:设置全部都保存在结果体instance_data中,如果我们想扩充设备,那就需要修改这个家伙的数组了。

后面是初始化init 结构体

  1. int instance_init_s(int mode)
  2. {
  3. int instance = 0 ;
  4. instance_data[instance].mode = mode; //上面已经设定过了 // assume anchor,
  5. instance_data[instance].testAppState = TA_INIT ; //后面状态机会用到这个。
  6.  
  7. // if using auto CRC check (DWT_INT_RFCG and DWT_INT_RFCE) are used instead of DWT_INT_RDFR flag
  8. // other errors which need to be checked (as they disable receiver) are
  9. //dwt_setinterrupt(DWT_INT_TFRS | DWT_INT_RFCG | (DWT_INT_SFDT | DWT_INT_RFTO /*| DWT_INT_RXPTO*/), 1);
  10. //暂时不看具体寄存器设定
  11. dwt_setinterrupt(DWT_INT_TFRS | DWT_INT_RFCG | (DWT_INT_ARFE | DWT_INT_RFSL | DWT_INT_SFDT | DWT_INT_RPHE | DWT_INT_RFCE | DWT_INT_RFTO /*| DWT_INT_RXPTO*/), 1);
  12.  
  13. //this is platform dependent - only program if DW EVK/EVB
  14. dwt_setleds(3) ; //configure the GPIOs which control the LEDs on EVBs
  15. //非常重要,这个是两个回调函数
  16. dwt_setcallbacks(instance_txcallback, instance_rxcallback);
  17. //非常重要,这个应用层主要函数
  18. instance_setapprun(testapprun_s);
  19. instance_data[instance].anchorListIndex = 0 ;
  20. //sample test calibration functions
  21. //xtalcalibration();
  22. //powertest();
  23. return 0 ;
  24. }

回调函数设定

  1. void dwt_setcallbacks(void (*txcallback)(const dwt_callback_data_t *), void (*rxcallback)(const dwt_callback_data_t *))
  2. {
  3. dw1000local.dwt_txcallback = txcallback;
  4. dw1000local.dwt_rxcallback = rxcallback;
  5. }

应用层函数设定

  1. void instance_setapprun(int (*apprun_fn)(instance_data_t *inst, int message))
  2. {
  3. int instance = 0 ;
  4. instance_localdata[instance].testapprun_fn = apprun_fn;
  5. }

设定这些函数,只是提供入口,此时还不会执行。但是RX TX 回调函数是通过中断触发的,设定后可能会立马执行,这个我们后续看代码分析。 接着返回函数上层追踪

  1. instance_init_s(instance_mode);
  2. dr_mode = decarangingmode(s1switch);
  3. //NOTE: Channel 5 is not supported for the non-discovery mode
  4. int decarangingmode(uint8 s1switch)
  5. {
  6. int mode = 0;
  7. if(s1switch & SWS1_SHF_MODE)
  8. {
  9. mode = 1;
  10. }
  11. if(s1switch & SWS1_64M_MODE)
  12. {
  13. mode = mode + 2;
  14. }
  15. if(s1switch & SWS1_CH5_MODE)
  16. {
  17. mode = mode + 4;
  18. }
  19. return mode;
  20. }

我们暂时还不确定目前sw组合,看代码不难理解,后续我们再分析这一块。

  1. instConfig.channelNumber = chConfig[dr_mode].channel ;
  2. instConfig.preambleCode = chConfig[dr_mode].preambleCode ;
  3. instConfig.pulseRepFreq = chConfig[dr_mode].prf ;
  4. instConfig.pacSize = chConfig[dr_mode].pacSize ;
  5. instConfig.nsSFD = chConfig[dr_mode].nsSFD ;
  6. instConfig.sfdTO = chConfig[dr_mode].sfdTO ;
  7. instConfig.dataRate = chConfig[dr_mode].datarate ;
  8. instConfig.preambleLen = chConfig[dr_mode].preambleLength ;
  9. instance_config(&instConfig) ; // Set operating channel etc

根据上面按键sw 确定某一种模式,然后将chConfig 全局变量的一部分提取出来,放到instConfig中,然后调用instance_config配置,这些都是DWM1000 工作必须配置,需要配合datasheet 查看,具体我们这里就不解释了,我们注重的逻辑

调用instance_config我们就认为RF 相关的参数已经正确配置到DWM1000了。

  1. instancesettagsleepdelay(POLL_SLEEP_DELAY, BLINK_SLEEP_DELAY); //set the Tag sleep time(500,1000)

其实从函数内容来看,还是在初始化结构体instace_data。

  1. // -------------------------------------------------------------------------------------------------------------------
  2. // function to set the tag sleep time (in ms)
  3. //
  4. void instancesettagsleepdelay(int sleepdelay, int blinksleepdelay) //sleep in ms
  5. {
  6. int instance = 0 ;
  7. instance_data[instance].tagSleepTime_ms = sleepdelay ;
  8. instance_data[instance].tagBlinkSleepTime_ms = blinksleepdelay ;
  9. }

Inittestapplication 最后一个函数instance_init_timings

从下面的解释可以看出还是初始化相关,这个函数稍微复杂点,我们暂时先不看。

  1. // Pre-compute frame lengths, timeouts and delays needed in ranging process.
  2. // /!\ This function assumes that there is no user payload in the frame.
  3. void instance_init_timings(void)  

现在我们就基本分析完了inittestapplication, 正如它的名字一样,这个主要是init, 一些关键参数的值我们在上面的结构体中也有标注

【DWM1000】 code 解密2一 工程初始化代码分析的更多相关文章

  1. RT-thread组件初始化代码分析

    RT-thread提供了组件化功能,具体实现是在components/init文件夹下components.c文件中实现的.应用组件化功能首先在rtconfig.h中添加宏定义#define RT_U ...

  2. openstack学习之neutron ml2初始化代码分析

    这里没有 去详细考虑neutron server怎么初始化的,而是直接从加载插件的地方开始分析.首先我们看下下面这个文件. Neutron/api/v2/router.py class APIRout ...

  3. Linux时间子系统之(十七):ARM generic timer驱动代码分析

    专题文档汇总目录 Notes:ARM平台Clock/Timer架构:System counter.Timer以及两者之间关系:Per cpu timer通过CP15访问,System counter通 ...

  4. Linux kernel的中断子系统之(七):GIC代码分析

    返回目录:<ARM-Linux中断系统>. 总结: 原文地址:<linux kernel的中断子系统之(七):GIC代码分析> 参考代码:http://elixir.free- ...

  5. Linux中断 - GIC代码分析

    一.前言 GIC(Generic Interrupt Controller)是ARM公司提供的一个通用的中断控制器,其architecture specification目前有四个版本,V1-V4(V ...

  6. Linux时间子系统(十七) ARM generic timer驱动代码分析

    一.前言 关注ARM平台上timer driver(clocksource chip driver和clockevent chip driver)的驱动工程师应该会注意到timer硬件的演化过程.在单 ...

  7. 【DWM1000】 code 解密7一ANCHOR接收到BLINK

    接着之前ANCHOR的代码分析,但接收到无线数据,应该执行如下代码 case TA_RX_WAIT_DATA :   //already recive a message                ...

  8. 【DWM1000】 code 解密6一TAG 状态机第一步

    我们前面分析过,不论ANCHOR 还是TAG,前面变量的初始化基本都是一样的,只是状态机必须明确区分不同的设备类型.我们从开始看TAG.由于初始化TAG的 testAppState一样初始化为TA_I ...

  9. 【DWM1000】 code 解密4一 ANCHOR 二进宫testapprun_s

    上面我们的代码分析到ANCHOR 调用了一次testapprun_s,但是后面退出后发现还是满足while 条件,逼不得已还得再次调用testapprun_s.testapprun_s 也就是这样一点 ...

随机推荐

  1. Pycharm同步本地代码至GitHub

    注册github账号 github地址,进入注册账号 安装git Windows下载地址1 Windows下载地址2 在官方下载完后,双击exe文件进行安装,安装到Windows Explorer i ...

  2. requests中get和post传参

    get请求 get(url, params=None, **kwargs) requests实现get请求传参的两种方式 方式一: import requests url = 'http://www. ...

  3. Jmeter中使用外部的java文件

    感觉在Jmeter中使用外部的Java文件比较方便,语法一样,而且可以直接引用,所以个人觉得这个功能还是蛮重要的,特别是在使用Jmeter的过程中,可能需要结合一定的业务场景进行判断等,那使用Jmet ...

  4. resources中添加配置文件

  5. 修改Linux服务器的ttl值

    [root@test_android_client_download ~]# cat /etc/sysctl.conf |grep net.ipv4.ip_default_ttlnet.ipv4.ip ...

  6. Scrapy 框架 安装

    Scrapy 框架 Scrapy是用纯Python实现一个为了爬取网站数据.提取结构性数据而编写的应用框架,用途非常广泛. 框架的力量,用户只需要定制开发几个模块就可以轻松的实现一个爬虫,用来抓取网页 ...

  7. Java枚举类使用和总结

    1.枚举类使用情况一: package com.bie.util; import java.util.HashMap; import java.util.Map; /** * * @author bi ...

  8. WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable Exception in thread "main" java.io.IOException: No FileSystem for sc F

    1.执行脚本程序报如下所示的错误: [hadoop@slaver1 script_hadoop]$ hadoop jar web_click_mr_hive.jar com.bie.hive.mr.C ...

  9. 【BZOJ2298】[HAOI2011]problem a

    题解: 虽然也是个可以过得做法...但又没有挖掘到最简单的做法... 正解是发现这个东西等价于求不相交区间个数 直接按照右端点排序,然后贪心就可以O(n)过了 而我的做法是按照a排序(其实我是在模拟这 ...

  10. linux服务器查看tcp链接shell

    netstat -nt |awk '{++S[$NF]} END {for (a in S ) print a,S[a]}'