上面我們的代碼分析到ANCHOR 調用了一次testapprun_s,但是后面退出后發現還是滿足while 條件,逼不得已還得再次調用testapprun_s。testapprun_s 也就是這樣一點一點被消磨殆盡(分析完)(大部分代碼也是本人第一次看,分析的不妥的地方大家多擔待,后續發現問題我會及時更新)
好了,我們再看run 部分的代碼
while(done == INST_NOT_DONE_YET) { //int state = instance_data[instance].testAppState; done = instance_localdata[instance].testapprun_fn(&instance_data[instance], message) ; // run the communications application //we've processed message message = 0; }
其實這個就是DWM1000 定位代碼的core(加上上下幾句),此時調用testapprun_s 傳入的參數A 依然是結構體instace, B message, 此時message為0,我猜測估計還是用不到message。
我們再次進入testapprun_s 看看吧。
int testapprun_s(instance_data_t *inst, int message) { switch (inst->testAppState) {
ANCHOR在上次進入testapprun_s 的最后設定了testAppState
inst->testAppState = TA_RXE_WAIT ;
那我們直接找到這部分代碼
case TA_RXE_WAIT : //enable rx,and wait to recive a message // printf("TA_RXE_WAIT") ; { if(inst->wait4ack == 0) //if this is set the RX will turn on automatically after TX { //turn RX on instancerxon(inst, 0, 0) ; // turn RX on, with/without delay } else { inst->wait4ack = 0 ; //clear the flag, the next time we want to turn the RX on it might not be auto } if (inst->mode != LISTENER) { //we are going to use anchor/tag timeout inst->done = INST_DONE_WAIT_FOR_NEXT_EVENT; //using RX FWTO
} inst->testAppState = TA_RX_WAIT_DATA; // let this state handle it // end case TA_RXE_WAIT, don't break, but fall through into the TA_RX_WAIT_DATA state to process it immediately. if(message == 0) break; }
看標注為藍色的代碼,我們在初始化的時候有動過這個家伙
uint8 wait4ack ; instance_init 0 // if this is set to
那么就是打開接受器,具體代碼我們不看了,也是寄存器級別的代碼。
后面接着判斷
if (inst->mode != LISTENER)
是的,我們目前分析的流程是ANCHOR,滿足這個情況,那么接着執行
inst->done = INST_DONE_WAIT_FOR_NEXT_EVENT; //using RX FWTO
上一次最后遇到done這個變量打的我們措手不及,最后我們假定他是初始化值0,現在終於有個新值了,我記住你了!
if(message == 0) break;
失策了,以為message還不會用,但是這里用到了,我們傳入的確實是0, break了。 由上一節分析,后面return done,這次返回的是INST_DONE_WAIT_FOR_NEXT_EVENT;。
總結一下ANCHOR 二進宮的工作: 開啟接受器,沒錯,就這一件事。
這也就意味着等待其它設備發送數據了,我們估計后面要分析TAG了。 不過我們先返回去看看情況吧。 返回到int instance_run(void),可以知道不滿足while 條件了,我們可以往后執行了。
if(done == INST_DONE_WAIT_FOR_NEXT_EVENT_TO) //we are in RX and need to timeout (Tag needs to send another poll if no Rx frame) { …… }
不滿足條件,接着后面的代碼,有種int instance_run也能執行完的感覺
if((instance_data[instance].instancetimer_en == 1) && (instance_data[instance].stoptimer == 0)) { }
我們在看看這兩個家伙初始化是否有賦值,我們從剛才代碼分析中可以知道,至少在testapprun_s沒有修改過這兩個家伙
搜索初始化代碼,沒有發現修改過這兩個家伙,或者漏掉了,我們暫且認為初始化沒有修改過,那么兩個值應該都是0,所以不滿足,直接執行int instance_run(void)最后的return 0,高高興興的返回啦