CC2640 软件定时器 Util_constructClock()

本文针对CC2640的Util_constructClock()使用中遇到的问题进行了详细解析,并给出了具体的解决步骤。主要涉及如何正确创建及重启定时器,以确保其能够周期性地触发应用程序的任务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转自 : http://blog.youkuaiyun.com/haozi0_0/article/details/50970268

最近有客户在使用 CC2640 的 Util_constructClock()过程中遇到问题,在帮助客户解决问题之后就想把解决方法记录一下,一是帮助自己记忆,而是帮助给遇到问题的朋友提供一个思路。

以 SimpleBLEPeripheral 工程为例:

1. 首先要在初始化函数中创建一个软件定时 Util_constructClock()

static void SimpleBLEPeripheral_init(void)
{
	// ******************************************************************
  // N0 STACK API CALLS CAN OCCUR BEFORE THIS CALL TO ICall_registerApp
  // ******************************************************************
  // Register the current thread as an ICall dispatcher application
  // so that the application can send and receive messages.
  ICall_registerApp(&selfEntity, &sem);

  // Hard code the BD Address till CC2650 board gets its own IEEE address
 // uint8 bdAddress[B_ADDR_LEN] = { 0xF0, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA };
 // HCI_EXT_SetBDADDRCmd(bdAddress);

  // Set device's Sleep Clock Accuracy
  //HCI_EXT_SetSCACmd(40);

  // Create an RTOS queue for message from profile to be sent to app.
  appMsgQueue = Util_constructQueue(&appMsg);

  // Create one-shot clocks for internal periodic events.
  Util_constructClock(&periodicClock, SimpleBLEPeripheral_clockHandler,
                      SBP_PERIODIC_EVT_PERIOD, 0, false, SBP_PERIODIC_EVT);  //创建定时

  Board_openLCD();


  // Setup the GAP
  GAP_SetParamValue(TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL);

先看一下 Util_constructClock()中定义的回调函数 SimpleBLEPeripheral_clockHandler(),这个函数就是当定时时间到了之后的处理函数。

static void SimpleBLEPeripheral_clockHandler(UArg arg)
{
  // Store the event.
  events |= arg;

  // Wake up the application.
  Semaphore_post(sem);
}

2. 第二步就是要启动这个定时器了,原例程中的代码如下:
static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1)
{
  // Initialize application
  SimpleBLEPeripheral_init();

  // Application main loop
  for (;;)
  {
    
      //....省略

    if (events & SBP_PERIODIC_EVT)
    {
      events &= ~SBP_PERIODIC_EVT;

      Util_startClock(&periodicClock);  //开启定时

      // Perform periodic application task
      SimpleBLEPeripheral_performPeriodicTask();
    }
   }
}

注意这个 Util_startClock()函数是放在 for 循环里的,说明他是重复执行的,当一次定时结束后,要重新开启 Util_startClock,这个很像 CC2541 中的定时功能。所以如果你的定时功能出了问题,只能执行一次,那就说明你在第一次定时结束后没有重新启动定时。也就是说在定时功能执行一次之后,需要再次调用 Util_startClock()函数来开启定时功能。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值