Quantcast
Channel: 蓝牙论坛 - 最近的话题
Viewing all articles
Browse latest Browse all 7513

CC2540 OSAL获取毫秒级的时间戳

$
0
0

  进来因为项目需求,需要记录获取广播包获取的时间,毫秒级别的。查询了OSAL的一些接口但大部分是秒级的时间。

  在查看底层文件OSAL_Clock.C后,在void osalTimeUpdate( void )中找到了

// Get the free-running count of 625us timer ticks
tmp = ll_McuPrecisionCount();

这个会获取625us级别的时间片数,符合我的要求,我就在OSAL_Clock.C文件首部定义了

//This is deigned by user

然后在simpleBLEObserver.h文件中定义了

extern uint32 myTimeStamp;

但是在simpleBLEObserver.C文件中使用myTimeStamp时,却提示没有定义

Error[e46]: Undefined external "myTimeStamp" referred in simpleBLEObserver

下面是

void osalTimeUpdate( void )
{
  uint16 tmp;
  uint16 ticks625us;
  uint16 elapsedMSec = 0;

  // Get the free-running count of 625us timer ticks
  tmp = ll_McuPrecisionCount();

//--------------------------
  myTimeStamp += tmp;
//--------------------------

  if ( tmp != previousLLTimerTick )
  {
    // Calculate the elapsed ticks of the free-running timer.
    ticks625us = tmp - previousLLTimerTick;

    // Store the LL Timer tick count for the next time through this function.
    previousLLTimerTick = tmp;

    /* It is necessary to loop to convert the usecs to msecs in increments so as
     * not to overflow the 16-bit variables.
     */
    while ( ticks625us > MAXCALCTICKS )
    {
      ticks625us -= MAXCALCTICKS;
      elapsedMSec += MAXCALCTICKS * 5 / 8;
      remUsTicks += MAXCALCTICKS * 5 % 8;
    }

    // update converted number with remaining ticks from loop and the
    // accumulated remainder from loop
    tmp = (ticks625us * 5) + remUsTicks;

    // Convert the 625 us ticks into milliseconds and a remainder
    elapsedMSec += tmp / 8;
    remUsTicks = tmp % 8;

    // Update OSAL Clock and Timers
    if ( elapsedMSec )
    {
      osalClockUpdate( elapsedMSec );
      osalTimerUpdate( elapsedMSec );
    }
  }
}

Viewing all articles
Browse latest Browse all 7513

Trending Articles