固定連結網頁

2017年7月10日 星期一

tick 時間型態測試

想看看tick 作 timer 數值會不會出錯,可以簡單用下面函式看一下能否正常結束。
void tick_test(){
  static int hadRun=0;
  if(hadRun) return;
  hadRun++;

  int ticks=10;
  int i,loop;
  int startTick,sysTick = 0x7ffffffa;
  unsigned int ustartTick, usysTick;

  for(loop=0;loop<2;loop++){
    i=0;
    startTick = sysTick;
    while(sysTick - startTick < ticks){
        sysTick++;
        i++;
        printf("startTick=%d Tick=%d [%d]\r\n", startTick, sysTick,i);
    }
    printf("break!\r\n");
  
    sysTick = 0xfffffffa;
  }
  printf("\r\n");

  usysTick = 0x7ffffffa;
  for(loop=0;loop<2;loop++){
    i=0;
    ustartTick = usysTick;
    while(usysTick - ustartTick < ticks){
        usysTick++;
        i++;
        printf("startTick=%u Tick=%u [%u]\r\n", ustartTick, usysTick,i);
    }
    printf("break!\r\n");
  
    usysTick = 0xfffffffa;
  } 
}
Testlog
 ==== Stm32 Board ====
startTick=2147483642 Tick=2147483643 [1]
startTick=2147483642 Tick=2147483644 [2]
startTick=2147483642 Tick=2147483645 [3]
startTick=2147483642 Tick=2147483646 [4]
startTick=2147483642 Tick=2147483647 [5]
startTick=2147483642 Tick=-2147483648 [6]
startTick=2147483642 Tick=-2147483647 [7]
startTick=2147483642 Tick=-2147483646 [8]
startTick=2147483642 Tick=-2147483645 [9]
startTick=2147483642 Tick=-2147483644 [10]
break!
startTick=-6 Tick=-5 [1]
startTick=-6 Tick=-4 [2]
startTick=-6 Tick=-3 [3]
startTick=-6 Tick=-2 [4]
startTick=-6 Tick=-1 [5]
startTick=-6 Tick=0 [6]
startTick=-6 Tick=1 [7]
startTick=-6 Tick=2 [8]
startTick=-6 Tick=3 [9]
startTick=-6 Tick=4 [10]
break!

startTick=2147483642 Tick=2147483643 [1]
startTick=2147483642 Tick=2147483644 [2]
startTick=2147483642 Tick=2147483645 [3]
startTick=2147483642 Tick=2147483646 [4]
startTick=2147483642 Tick=2147483647 [5]
startTick=2147483642 Tick=2147483648 [6]
startTick=2147483642 Tick=2147483649 [7]
startTick=2147483642 Tick=2147483650 [8]
startTick=2147483642 Tick=2147483651 [9]
startTick=2147483642 Tick=2147483652 [10]
break!
startTick=4294967290 Tick=4294967291 [1]
startTick=4294967290 Tick=4294967292 [2]
startTick=4294967290 Tick=4294967293 [3]
startTick=4294967290 Tick=4294967294 [4]
startTick=4294967290 Tick=4294967295 [5]
startTick=4294967290 Tick=0 [6]
startTick=4294967290 Tick=1 [7]
startTick=4294967290 Tick=2 [8]
startTick=4294967290 Tick=3 [9]
startTick=4294967290 Tick=4 [10]
break!

沒有留言:

張貼留言

手機選擇帳號後,按下發布 要再點選一次發布哦