CC2640 软件定时器 Util_constructClock()

来源:互联网 发布:js获取父级节点 编辑:程序博客网 时间:2024/05/22 07:52

转自 : http://blog.csdn.net/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()函数来开启定时功能。



原创粉丝点击