找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 5596|回复: 3
打印 上一主题 下一主题
收起左侧

ZigBee实现的无线透传 CC2530 SerialApp源码与分析资料

[复制链接]
跳转到指定楼层
#
基于CC2530的SerialApp,实现的串口透传之前有项目使用过,可以在这个例程上稍作修改,就可以满足串口透传基本的使用了。
延时大概是30ms左右。
受限于ZigBee本身的特性,不适合用于大数量的传输。


全部资料51hei下载地址:
ZStack-2.5.1a.zip (6.68 MB, 下载次数: 100)
12.串口透传之无线QQ.pdf (804.18 KB, 下载次数: 51)
Z-STACK之cc2530串口驱动详解.pdf (422.36 KB, 下载次数: 49)
串口透明传输实验分析.pdf (194.4 KB, 下载次数: 50)



Zigbee 协议栈学习之串口透明传输实验(SerialApp)流程分析

第一个功能:协调器的组网,终端设备和路由设备发现网络以及加入网络
//第一步:Z-Stack  由 main()函数开始执行,main()函数共做了 2 件事:一是系统初始化,另外一件是开
始执行轮转查询式操作系统
int main( void )                           
{
  .......
  // Initialize the operating system
  osal_init_system();              //第二步,操作系统初始化
......
  osal_start_system();   //初始化完系统任务事件后,正式开始执行操作系统
  ......
}  

//第二步,进入 osal_init_system()函数,执行操作系统初始化
uint8 osal_init_system( void )      //初始化操作系统,其中最重要的是,初始化操作系统的任务
{
  // Initialize the Memory Allocation System
  osal_mem_init();
  // Initialize the message queue
  osal_qHead = NULL;
  // Initialize the timers
  osalTimerInit();
  // Initialize the Power Management System
  osal_pwrmgr_init();
  // Initialize the system tasks.
  osalInitTasks();                 //第三步,执行操作系统任务初始化函数
  // Setup efficient search for the first free block of heap.
  osal_mem_kick();
  return ( SUCCESS );
}

//第三步,进入 osalInitTasks()函数,执行操作系统任务初始化
void osalInitTasks( void )       //第三步,初始化操作系统任务
{
  uint8 taskID = 0;
  tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt);
  osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt));
  //任务优先级由高向低依次排列,高优先级对应 taskID 的值反而小
  macTaskInit( taskID++ ); //不需要用户考虑
  nwk_init( taskID++ );      //不需要用户考虑
  Hal_Init( taskID++ );      //硬件抽象层初始化,需要我们考虑   
#if defined( MT_TASK )        
  MT_TaskInit( taskID++ );
#endif
  APS_Init( taskID++ );       //不需要用户考虑
#if defined ( ZIGBEE_FRAGMENTATION )   
  APSF_Init( taskID++ );
#endif
  ZDApp_Init( taskID++ );   //第四步,ZDApp 层,初始化  ,执行 ZDApp_init 函数后,如果是协调器将建立网络,
如果是终端设备将加入网络。
#if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )   
  ZDNwkMgr_Init( taskID++ );
#endif
  SerialApp_Init( taskID );  //应用层 SerialApp 层初始化,需要用户考虑     在此处设置了一个按键触发事件,
                                         //当有按键按下的时候,产生一个系统消息
}                             
//第四步,进入 ZDApp_init()函数,执行 ZDApp 层初始化
//The first step
void ZDApp_Init( uint8 task_id )     //The first step,ZDApp 层初始化。
{
  // Save the task ID
  ZDAppTaskID = task_id;
  // Initialize the ZDO global device short address storage
  ZDAppNwkAddr.addrMode = Addr16Bit;
  ZDAppNwkAddr.addr.shortAddr = INVALID_NODE_ADDR;
  (void)NLME_GetExtAddr();  // Load the saveExtAddr pointer.

  // Check for manual "Hold Auto Start"
  ZDAppCheckForHoldKey();

  // Initialize ZDO items and setup the device - type of device to create.
  ZDO_Init();
   // Register the endpoint description with the AF
  // This task doesn't have a Simple description, but we still need
  // to register the endpoint.
  afRegister( (endPointDesc_t *)&ZDApp_epDesc );

#if defined( ZDO_USERDESC_RESPONSE )
  ZDApp_InitUserDesc();
#endif // ZDO_USERDESC_RESPONSE
  
  // Start the device?
  if ( devState != DEV_HOLD )        //devState 初值为 DEV_INIT , 所以在初始化 ZDA 层时,就执行该条件
语句
  {
    ZDOInitDevice( 0 );     //The second step, 接着转到 ZDOInitDevice()函数,执行 The third step;
  }
  else
  {
    // Blink LED to indicate HOLD_START
    HalLedBlink ( HAL_LED_4, 0, 50, 500 );
  }
  ZDApp_RegisterCBs();
} /* ZDApp_Init() */

//The third step,执行 ZDOInitDevice()函数,执行设备初始化
uint8 ZDOInitDevice( uint16 startDelay )  //The third step, ZDO层初始化设备,
{
   .......
// Trigger the network start
  ZDApp_NetworkInit( extendedDelay );   //网络初始化,跳到相应的函数里头,执行 The fourth step
   .......
}

//The fouth step,执行 ZDApp_NetWorkInit()函数
void ZDApp_NetworkInit( uint16 delay )  //The fourth step,网络初始化
{
  if ( delay )
  {
    // Wait awhile before starting the device
    osal_start_timerEx( ZDAppTaskID, ZDO_NETWORK_INIT, delay );    //发 送 ZDO_NETWORK_INIT(网络初始化)消息到 ZDApp 层,转到                                                                                                                  //ZDAp
p 层,执行 The fifth step  , ZDApp_event_loop() 函数
  }                                                               
  else
  {
    osal_set_event( ZDAppTaskID, ZDO_NETWORK_INIT );
  }
}

//The fifth step,转到 ZDApp_event_loop()函数
UINT16 ZDApp_event_loop( uint8 task_id, UINT16 events )
{
if ( events & ZDO_NETWORK_INIT )   //The fivth step,网络初始化事件处理
  {
    // Initialize apps and start the network
    devState = DEV_INIT;
    //设备逻辑类型,启动模式,信标时间,超帧长度,接着转到 The sixth step,去启动设备,接着执行 The sixth
step,转到 ZDO_StartDevice()
    ZDO_StartDevice( (uint8)ZDO_Config_Node_Descriptor.LogicalType, devStartMode,   
                     DEFAULT_BEACON_ORDER, DEFAULT_SUPERFRAME_ORDER );
…………
…………
…………限于本文篇幅 余下代码请从51黑下载附件…………
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享淘帖 顶 踩
回复

使用道具 举报

板凳
ID:936375 发表于 2021-6-12 18:36 | 只看该作者
作者还在吗
回复

使用道具 举报

沙发
ID:348319 发表于 2020-12-1 11:17 | 只看该作者
正在寻找例程,不知道有没有3.0版本的透传
回复

使用道具 举报

楼主
ID:152868 发表于 2018-12-27 14:48 | 只看该作者
不错,正好需要这个固件
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表