Chinaunix首页 | 论坛 | 博客
  • 博客访问: 64212
  • 博文数量: 16
  • 博客积分: 45
  • 博客等级: 民兵
  • 技术积分: 171
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-09 15:38
文章分类

全部博文(16)

文章存档

2014年(3)

2013年(7)

2012年(6)

我的朋友

分类: 嵌入式

2014-05-11 16:15:36

1.有关回调函数的基本概念和使用方法,请参考如下文章:

2.ZStack中回调函数的应用较多,下面就按键实现方式略作整理。
const pTaskEventHandlerFn tasksArr[] = {

  macEventLoop,
  nwk_event_loop,
  Hal_ProcessEvent,
#if defined( MT_TASK )
  MT_ProcessEvent,
#endif
  APS_event_loop,
#if defined ( ZIGBEE_FRAGMENTATION )
  APSF_ProcessEvent,
#endif
  ZDApp_event_loop,
#if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )
  ZDNwkMgr_event_loop,
#endif
  SampleApp_ProcessEvent
};
uint16 Hal_ProcessEvent( uint8 task_id, uint16 events )
{
...
  if (events & HAL_KEY_EVENT)
  {

#if (defined HAL_KEY) && (HAL_KEY == TRUE)
    /* Check for keys */
    HalKeyPoll();
    /* if interrupt disabled, do next polling */
    if (!Hal_KeyIntEnable)
    {
      osal_start_timerEx( Hal_TaskID, HAL_KEY_EVENT, 100);
    }
#endif // HAL_KEY
    return events ^ HAL_KEY_EVENT;
  }
...
}

void HalKeyPoll (void)
{
...
  /* Invoke Callback if new keys were depressed */
  if (keys && (pHalKeyProcessFunction))
  {
    (pHalKeyProcessFunction) (keys, HAL_KEY_STATE_NORMAL);
  }
}

pHalKeyProcessFunction 定义在hal_key.c中
static halKeyCBack_t pHalKeyProcessFunction;

hal_key.h中定义了函数指针
typedef void (*halKeyCBack_t) (uint8 keys, uint8 state);

回调函数的注册
void HalKeyConfig (bool interruptEnable, halKeyCBack_t cback)
{
... 
/* Register the callback fucntion */
 pHalKeyProcessFunction = cback;
...
}

在OnBoard.c中做了相关的初始化
void InitBoard( uint8 level )
{
  if ( level == OB_COLD )
  {
    // IAR does not zero-out this byte below the XSTACK.
    *(uint8 *)0x0 = 0;
    // Interrupts off
    osal_int_disable( INTS_ALL );
    // Check for Brown-Out reset
    ChkReset();
  }
  else  // !OB_COLD
  {
    /* Initialize Key stuff */
    HalKeyConfig(HAL_KEY_INTERRUPT_DISABLE, OnBoard_KeyCallback);
  }
}

void OnBoard_KeyCallback ( uint8 keys, uint8 state )
{
  uint8 shift;
  (void)state;
  shift = (keys & HAL_KEY_SW_6) ? true : false;
  if ( OnBoard_SendKeys( keys, shift ) != ZSuccess )
  {
    // Process SW1 here
    if ( keys & HAL_KEY_SW_1 )  // Switch 1
    {
    }
    // Process SW2 here
    if ( keys & HAL_KEY_SW_2 )  // Switch 2
    {
    }
    // Process SW3 here
    if ( keys & HAL_KEY_SW_3 )  // Switch 3
    {
    }
    // Process SW4 here
    if ( keys & HAL_KEY_SW_4 )  // Switch 4
    {
    }
    // Process SW5 here
    if ( keys & HAL_KEY_SW_5 )  // Switch 5
    {
    }
    // Process SW6 here
    if ( keys & HAL_KEY_SW_6 )  // Switch 6
    {
    }
  }
}

阅读(2821) | 评论(0) | 转发(0) |
0

上一篇:Arduino DMX

下一篇:SimpliciTI (FHSS 概念)

给主人留下些什么吧!~~