创建Zigbee Z-Stack 3.0.1 BSP(四)--移植UltraIot开发板LED

概述

UltraIot开发板LED开发板上有三个用户LED指示灯,这三个指示灯所使用的IO口与IT的评估板有所不同,所以需要根据UltraIot开发板底板的原理图来修改IO口。
UltraIot开发板LED原理图如下所示:
这里写图片描述
有图可以得到:
1、P1.0 ,P1.1,P1.4分别控制LED2,LED3,LED1
2、P1.0 ,P1.1,P1.4输出高电平时LED高亮,P1.0 ,P1.1,P1.4输出低电平时LED为灭。

协议栈相关文件

协议栈中于LED控制功能相关的几个文件分别是:
1.Z-Stack_3_0_1_UltraIot\Z-Stack 3.0.1_Template\Components\hal\common\hal_drivers.c
2.Z-Stack_3_0_1_UltraIot\Z-Stack 3.0.1_Template\Components\hal\include\hal_led.h
3.EZ-Stack_3_0_1_UltraIot\Z-Stack 3.0.1_Template\Components\hal\target\UltraIot\hal_led.c
4.Z-Stack_3_0_1_UltraIot\Z-Stack 3.0.1_Template\Components\hal\target\UltraIot\hal_board_cfg.h

hal_drivers.c:在该文件中定义了硬件层的事件任务。
hal_led.h:抽象出的LED控制接口定义
hal_led.c:LED控制功能的抽象实现。
hal_board_cfg.h:开发板相关的配置及资源会在这里定义。也是主要要修改的地方

协议栈修改

1、在hal_board_cfg.h修改LED定义
主要修改LEDx_BV,LEDx_SBIT,LEDx_DDR,LEDx_POLARITY.
由于IT的评估板也是3个LED灯,所以直接在上面修改就可以了。

/* LED1 */
#define LED1_BV           BV(4)
#define LED1_SBIT         P1_4
#define LED1_DDR          P1DIR
#define LED1_POLARITY     ACTIVE_HIGH

#if defined (HAL_BOARD_CC2530EB_REV17)
/* LED2 */
#define LED2_BV           BV(0)
#define LED2_SBIT         P1_0
#define LED2_DDR          P1DIR
#define LED2_POLARITY     ACTIVE_HIGH

/* LED3 */
#define LED3_BV           BV(1)
#define LED3_SBIT         P1_1
#define LED3_DDR          P1DIR
#define LED3_POLARITY     ACTIVE_HIGH

#ifdef ENABLE_LED4_DISABLE_S1
  /* 4 - Orange */
  #define LED4_BV             BV(1)
  #define LED4_SBIT           P0_1
  #define LED4_DDR            P0DIR
  #define LED4_POLARITY       ACTIVE_HIGH
  #define LED4_SET_DIR()      do {LED4_DDR |= LED4_BV;} while (0)
#else
  #define LED4_SET_DIR()
#endif
#endif

在IT评估板中还有一个LED4,在UltraIot中没有使用到,所以不用管,只要不要开启ENABLE_LED4_DISABLE_S1宏定义,就不会编译到代码里面。

2、LED控制宏定义

/* ----------- LED's ---------- */
#if defined (HAL_BOARD_CC2530EB_REV17) && !defined (HAL_PA_LNA) && \
    !defined (HAL_PA_LNA_CC2590) && !defined (HAL_PA_LNA_SE2431L) && \
    !defined (HAL_PA_LNA_CC2592)

  #define HAL_TURN_OFF_LED1()       st( LED1_SBIT = LED1_POLARITY (0); )
  #define HAL_TURN_OFF_LED2()       st( LED2_SBIT = LED2_POLARITY (0); )
  #define HAL_TURN_OFF_LED3()       st( LED3_SBIT = LED3_POLARITY (0); )
#ifdef ENABLE_LED4_DISABLE_S1
  #define HAL_TURN_OFF_LED4()       st( LED4_SBIT = LED4_POLARITY (0); )
#else
  #define HAL_TURN_OFF_LED4()       HAL_TURN_OFF_LED1()
#endif

  #define HAL_TURN_ON_LED1()        st( LED1_SBIT = LED1_POLARITY (1); )
  #define HAL_TURN_ON_LED2()        st( LED2_SBIT = LED2_POLARITY (1); )
  #define HAL_TURN_ON_LED3()        st( LED3_SBIT = LED3_POLARITY (1); )
#ifdef ENABLE_LED4_DISABLE_S1
  #define HAL_TURN_ON_LED4()        st( LED4_SBIT = LED4_POLARITY (1); )
#else
  #define HAL_TURN_ON_LED4()        HAL_TURN_ON_LED1()
#endif

  #define HAL_TOGGLE_LED1()         st( if (LED1_SBIT) { LED1_SBIT = 0; } else { LED1_SBIT = 1;} )
  #define HAL_TOGGLE_LED2()         st( if (LED2_SBIT) { LED2_SBIT = 0; } else { LED2_SBIT = 1;} )
  #define HAL_TOGGLE_LED3()         st( if (LED3_SBIT) { LED3_SBIT = 0; } else { LED3_SBIT = 1;} )
#ifdef ENABLE_LED4_DISABLE_S1
  #define HAL_TOGGLE_LED4()         st( if (LED4_SBIT) { LED4_SBIT = 0; } else { LED4_SBIT = 1;} )
#else
  #define HAL_TOGGLE_LED4()         HAL_TOGGLE_LED1()
#endif

  #define HAL_STATE_LED1()          (LED1_POLARITY (LED1_SBIT))
  #define HAL_STATE_LED2()          (LED2_POLARITY (LED2_SBIT))
  #define HAL_STATE_LED3()          (LED3_POLARITY (LED3_SBIT))
#ifdef ENABLE_LED4_DISABLE_S1
  #define HAL_STATE_LED4()          (LED4_POLARITY (LED4_SBIT))
#else
  #define HAL_STATE_LED4()          HAL_STATE_LED1()
#endif

在hal_board_cfg.h中定义了LED的控制宏。通过这些宏控制LED的亮/灭/翻转功能

代码分析

在协议栈中,当LED被初始化后,在应用层主要通过hal_led.h中提供的API来控制LED,其分别为:

/*
 * 控制LED 亮/灭/翻转
 */
extern uint8 HalLedSet( uint8 led, uint8 mode );

/*
 *控制LED闪烁
 * leds:那个LED灯要闪烁
 * cnt:闪烁次数,如果为0则一直闪烁
 * duty:亮灭占空比 0-100%
 * time:闪烁周期 单位ms
 */
extern void HalLedBlink( uint8 leds, uint8 cnt, uint8 duty, uint16 time );

但是这个函数最后会调用一个内部的函数:
void HalLedOnOff (uint8 leds, uint8 mode)

/***************************************************************************************************
 * @fn      HalLedOnOff
 *
 * @brief   Turns specified LED ON or OFF
 *
 * @param   leds - LED bit mask
 *          mode - LED_ON,LED_OFF,
 *
 * @return  none
 ***************************************************************************************************/
void HalLedOnOff (uint8 leds, uint8 mode)
{
  if (leds & HAL_LED_1)
  {
    if (mode == HAL_LED_MODE_ON)
    {
      HAL_TURN_ON_LED1();
    }
    else
    {
      HAL_TURN_OFF_LED1();
    }
  }

  if (leds & HAL_LED_2)
  {
    if (mode == HAL_LED_MODE_ON)
    {
      HAL_TURN_ON_LED2();
    }
    else
    {
      HAL_TURN_OFF_LED2();
    }
  }

  if (leds & HAL_LED_3)
  {
    if (mode == HAL_LED_MODE_ON)
    {
      HAL_TURN_ON_LED3();
    }
    else
    {
      HAL_TURN_OFF_LED3();
    }
  }

  if (leds & HAL_LED_4)
  {
    if (mode == HAL_LED_MODE_ON)
    {
      HAL_TURN_ON_LED4();
    }
    else
    {
      HAL_TURN_OFF_LED4();
    }
  }

  /* Remember current state */
  if (mode)
  {
    HalLedState |= leds;
  }
  else
  {
    HalLedState &= (leds ^ 0xFF);
  }
}

在HalLedOnOff 函数中最终实现LED控制的是在hal_board_cfg.h中定义的LED控制逻辑。

Z-Stack 3.0.x is TI's Zigbee 3.0 compliant protocol suite for the CC2530, CC2531, and CC2538 Wireless MCU. Supports the CC2592 and CC2590 RF front ends which extend up to +22dBm and +14dBm transmit power, respectively, and provide improved receiver sensitivity Z-Stack 3.0 combines multiple previous Zigbee profiles into one unified standard Incorporates the unified Zigbee Cluster Library which is at the foundation of dotdot, the universal language for IoT applications defining data objects, models and functionalities for embedded IoT applications Implements Zigbee Base Device Behavior specification, which defines a common set of mechanisms for network forming, discovering, and application provisioning to be used by all Zigbee devices Based on Zigbee PRO 2015 stack, it provides new and improved security modes, including Install Codes for out-of-band key exchange, and Distributed Security Networks for Coordinator-less network topology Supports Green Power Proxy, allowing energy-harvesting and ultra-low power devices to connect seamlessly to a Zigbee network Forwards and backwards compatibility with previous Zigbee PRO and application profiles is maintained Sample Applications included for quick prototyping, including door lock, thermostat, light and switch, and temperature sensor Zigbee Network Processor firmware, providing an abstracted access to the Zigbee Pro 2015 stack and Base Device Behavior functionality via a serial port for two-chip architectures Zigbee-based applications Over-the-air firmware upgrade and serial bootloader capability, allowing for future updates of deployed systems Compatible with TI's Z-Stack Linux Gateway, a reference implementation of an Ethernet-to-Zigbee gateway using a Linux-based platform as host processor, that makes it easy to integrate applications on top of an IP-based interface which abstracts Zigbee protocol functionality to the users.
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值