您好!我现在使用CC2538DK开发板进行试验,想要使用CC2538中的MAC Timer定时器。现在我使用contiki-3.0中的example-collect例子进行测试,在\cpu\cc2538\dev\cc2538-rf.c文件的init函数中return 1之前加入一段自己的代码。其中MAC timer的使用参照datasheet的350页介绍来做:
// *******************************************************************
rtimer_clock_t test_count = 0;
unsigned char test_low = 0;
unsigned char test_high = 0;
unsigned int test_int = 0;
test_low = REG(RFCORE_SFR_MTM0) & RFCORE_SFR_MTM0_MTM0;
test_high = REG(RFCORE_SFR_MTM1) & RFCORE_SFR_MTM1_MTM1;
test_count = test_low | (test_high << 8);
REG(RFCORE_SFR_MTMSEL) &= (~RFCORE_SFR_MTMSEL_MTMSEL); //let RFCORE_SFR_MTM0 can be read
printf("REG(RFCORE_SFR_MTMSEL) - %d\n",REG(RFCORE_SFR_MTMSEL));
printf("init test time1 : %d, high : %d, low : %d\n", test_count,test_high,test_low);
//开始计时
REG(RFCORE_SFR_MTCTRL) &= (~RFCORE_SFR_MTCTRL_RUN);
REG(RFCORE_SFR_MTCTRL) |= RFCORE_SFR_MTCTRL_RUN;
for (int iii=0;iii<1000000;iii++)
{
test_int++;
}
test_low = REG(RFCORE_SFR_MTM0) & RFCORE_SFR_MTM0_MTM0;
test_high = REG(RFCORE_SFR_MTM1) & RFCORE_SFR_MTM1_MTM1;
test_count = test_low | (test_high << 8);
test_count &= 0x0000FFFF;
//读出计时时长
printf("init test time2 : %d, high : %d, low : %d\n", test_count,test_high,test_low);
printf("count : %d\n", test_int);
// *******************************************************************
计算机读到的值为:
init test time1 : 0, high : 0, low : 0
init test time2 : 0, high : 0, low : 0
count : 1000000
如果将for循环改为clock_delay(50)或是printf一个东西,则第2次printf可以有读数,但是每次复位后读数差异巨大,毫无规律
init test time2 : 6465, high : 25, low : 65
init test time2 : 202, high : 0, low : 202
init test time2 : 14054, high : 54, low : 230
init test time2 : 20206, high : 78, low : 238
这到底是什么原因呢?
另外,\cpu\cc2538\clock.c中的clock_isr函数是每次和时钟有关的中断的时候都会进入吗?
望不吝赐教,感谢!!!