Zigebe3.0@学习笔记@TI ZSTACK@按键轮询/中断

本文详细介绍了在Zigebe3.0中如何进行TI ZSTACK的按键初始化、按键任务注册、按键配置(轮询与中断模式)、中断服务函数以及用户事件处理。重点讲解了从按键初始化到中断处理的整个流程,包括HalKeyInit(), RegisterForKeys(), HalKeyConfig(), HalKeyPoll()等关键函数的作用和工作原理。" 70862361,4431503,dnsmasq 2.72版本配置与解析流程,"['DNS服务', '网络配置', '域名解析', '开源软件', '系统管理']
摘要由CSDN通过智能技术生成

1.按键初始化函数
HalKeyInit()在HalDriverInit()函数中
HalDriverInit()函数位于hal_drivers.c中
HalKeyInit()函数位于hal_key.c中
配置P0SEL功能选择寄存器、P0DIR方向寄存器

/**************************************************************************************************
 * @fn      HalKeyInit
 *
 * @brief   Initilize Key Service
 *
 * @param   none
 *
 * @return  None
 **************************************************************************************************/
void HalKeyInit( void )
{
   
  /* Initialize previous key to 0 */
  halKeySavedKeys = 0;

  HAL_KEY_SW_6_SEL &= ~(HAL_KEY_SW_6_BIT);    /* Set pin function to GPIO */

#if ! defined ENABLE_LED4_DISABLE_S1
  HAL_KEY_SW_6_DIR &= ~(HAL_KEY_SW_6_BIT);    /* Set pin direction to Input */
#endif

  HAL_KEY_JOY_MOVE_SEL &= ~(HAL_KEY_JOY_MOVE_BIT); /* Set pin function to GPIO */
  HAL_KEY_JOY_MOVE_DIR &= ~(HAL_KEY_JOY_MOVE_BIT); /* Set pin direction to Input */


  /* Initialize callback function */
  pHalKeyProcessFunction  = NULL;                //初始化按键回调函数位NULL

  /* Start with key is not configured */
  HalKeyConfigured = FALSE;
}

1.1按键定义配置
位于hal_borad_cfg.h
按键PUSH1_SBIT的IO口为P0_1、按键PUSH2_SBIT的IO口为P2_0

/* ------------------------------------------------------------------------------------------------
 *                                    Push Button Configuration
 * ------------------------------------------------------------------------------------------------
 */

#define ACTIVE_LOW        !
#define ACTIVE_HIGH       !!    /* double negation forces result to be '1' */

/* S1 */
#define PUSH1_BV          BV(1)
#define PUSH1_SBIT        P0_1

#if defined (HAL_BOARD_CC2530EB_REV17)
  #define PUSH1_POLARITY    ACTIVE_HIGH
#elif defined (HAL_BOARD_CC2530EB_REV13)
  #define PUSH1_POLARITY    ACTIVE_LOW
#else
  #error Unknown Board Indentifier
#endif

/* Joystick Center Press */
#define PUSH2_BV          BV(0)
#define PUSH2_SBIT        P2_0
#define PUSH2_POLARITY    ACTIVE_HIGH


位于hal_key.c

/* SW_6 is at P0.1 */
#define HAL_KEY_SW_6_PORT   P0
#define HAL_KEY_SW_6_BIT    BV(1)
#define HAL_KEY_SW_6_SEL    P0SEL
#define HAL_KEY_SW_6_DIR    P0DIR

/* SW_6 interrupts */
#define HAL_KEY_SW_6_IEN      IEN1  /* CPU interrupt mask register */
#define HAL_KEY_SW_6_IENBIT   BV(5) /* Mask bit for all of Port_0 */
#define HAL_KEY_SW_6_ICTL     P0IEN /* Port Interrupt Control register */
#define HAL_KEY_SW_6_ICTLBIT  BV(1) /* P0IEN - P0.1 enable/disable bit */
#define HAL_KEY_SW_6_PXIFG    P0IFG /* Interrupt flag at source */

/* Joy stick move at P2.0 */
#define HAL_KEY_JOY_MOVE_PORT   P2
#define HAL_KEY_JOY_MOVE_BIT    BV(0)
#define HAL_KEY_JOY_MOVE_SEL    P2SEL
#define HAL_KEY_JOY_MOVE_DIR    P2DIR

2.初始化按键任务
osal_init_system()→osalInitTasks()→zcl_GenericApp_Init()中调用RegisterForKeys(zcl_GenericApp_TaskID )
按键注册函数RegisterForKeys()位于OnBoard.c中

/*********************************************************************
 * Keyboard Register function
 *
 * The keyboard handler is setup to send all keyboard changes to
 * one task (if a task is registered).
 *
 * If a task registers, it will get all the keys. You can change this
 * to register for individual keys.
 *********************************************************************/
uint8 RegisterForKeys( uint8 task_id )
{
   
  // Allow only the first task
  if ( registeredKeysTaskID == NO_TASK_ID )
  {
   
    registeredKeysTaskID = task_id;
    return ( true );
  }
  else
    return ( false );
}

3.配置按键
main()→InitBoard( OB_READY )→HalKeyConfig(HAL_KEY_INTERRUPT_DISABLE, OnBoard_KeyCallback)
InitBoard( OB_READY )位于OnBoard.c
配置按键函数HalKeyConfig(HAL_KEY_INTERRUPT_DISABLE, OnBoard_KeyCallback)位于OnBoard.c
配置按键模式:
HAL_KEY_INTERRUPT_DISABLE为轮询模式
HAL_KEY_INTERRUPT_ENABLE为中断模式

/*********************************************************************
 * @fn      InitBoard()
 * @brief   Initialize the CC2420DB Board Peripherals
 * @param   level: COLD,WARM,READY
 * @return  None
 */
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 */
    #if defined (ISR_KEYINTERRUPT)
    HalKeyConfig(HAL_KEY_INTERRUPT_ENABLE , OnBoard_KeyCallback);
    #else
    HalKeyConfig(HAL_KEY_INTERRUPT_DISABLE, OnBoard_KeyCallback);
    #endif
  }
}

3.1配置按键函数
HalKeyConfig(HAL_KEY_INTERRUPT_ENABLE , OnBoard_KeyCallback)位于hal_key.c
配置中断寄存器

/**************************************************************************************************
 * @fn      HalKeyConfig
 *
 * @brief   Configure the Key serivce
 *
 * @param   interruptEnable - TRUE/FALSE, enable/disable interrupt
 *          cback - pointer to the CallBack function
 *
 * @return  None
 **************************************************************************************************/
void HalKeyConfig (bool interruptEnable, halKeyCBack_t cback)
{
   
  /* Enable/Disable Interrupt or */
  Hal_KeyIntEnable = interruptEnable;

  /* Register the callback fucntion */
  pHalKeyProcessFunction = cback;   //指定按键回调函数为OnBoard_KeyCallback

  /* Determine if interrupt is enable or not */
  if (Hal_KeyIntEnable)   //中断设置
  {
   
    /* Rising/Falling edge configuratinn */

    PICTL &= ~(HAL_KEY_SW_6_EDGEBIT)
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值