设为首页 加入收藏

TOP

[ZigBee] 16、Zigbee协议栈应用(二)——基于OSAL的无线控制LED闪烁分析(下)(一)
2017-10-11 16:39:42 】 浏览:2710
Tags:ZigBee Zigbee 协议 应用 基于 OSAL 无线 控制 LED 闪烁 分析

 

 

说在前面:上一篇介绍了无线LED闪烁实现的OSAL部分,本篇介绍如何实现无线数据收发及数据处理:

 

上一篇是用SI跟着流程查看源码,我个人认为以架构的思维去了解代码能让人更清晰

 

 

::ZMain.c程序入口文件

这里chipcon_cstartup.s51是汇编的启动文件,ZMain.c相当于main文件,里面有main函数:

 1 int main( void )
 2 {
 3 osal_int_disable( INTS_ALL );// Turn off interrupts 关中断  4     HAL_BOARD_INIT();// Initialization for board related stuff such as LEDs
 5     zmain_vdd_check();// Make sure supply voltage is high enough to run   检查芯片是否上电正常
 6     InitBoard( OB_COLD );// Initialize board I/O  初始化I/O,LED,Timer等
 7     HalDriverInit();// Initialze HAL drivers 初始化硬件抽象层驱动模块
 8     osal_nv_init( NULL );// Initialize NV System 初始化flash存储器
 9     znpTestRF();// Initialize and check the ZNP RF Test Mode NV items. 
10     ZMacInit();// Initialize the MAC  初始化MAC层
11     zmain_ext_addr();// Determine the extended address  确定IEEE64位地址
12 
13 #if defined ZCL_KEY_ESTABLISH
14     zmain_cert_init();// Initialize the Certicom certificate information.
15 #endif
16 
17     zgInit();// Initialize basic NV items  初始化非易失变量
18 
19 #ifndef NONWK
20     afInit();// Since the AF isn't a task, call it's initialization routine
21 #endif
22 
23 osal_init_system();// Initialize the operating system 初始化OS(重点介绍1)
24 osal_int_enable( INTS_ALL );// Allow interrupts 使能中断
25     InitBoard( OB_READY );// Final board initialization      最终板载初始化
26     zmain_dev_info();// Display information about this device     显示设备信息(这里有LCD屏幕)
27 
28 #ifdef LCD_SUPPORTED/* Display the device info on the LCD 将信息显示在LCD上*/
29     zmain_lcd_init();      
30 #endif
31 
32 #ifdef WDT_IN_PM1
33     WatchDogEnable( WDTIMX );/* If WDT is used, this is a good place to enable it. */
34 #endif
35 
36 osal_start_znp(); // No Return from here 执行操作系统(重点介绍2)
37 
38     return 0;  // Shouldn't get here.
39 } // main()

main主要是初始化,然后启动OS,进入大循环,根据任务优先级处理相应任务。

 

::OSAL_SampleApp.c任务数组及任务初始化文件

上篇讲到main函数核心有:

 

初始化最核心的是OSAL任务初始化:(这里的tasksArr是所有任务的索引,后文还会介绍)

 1 /*********************************************************************
 2  * GLOBAL VARIABLES
 3  */
 4 
 5 // The order in this table must be identical to the task initialization calls below in osalInitTask.
 6 const pTaskEventHandlerFn tasksArr[] =
 7 {
 8     macEventLoop,
 9     nwk_event_loop,
10     Hal_ProcessEvent,
11 #if defined( MT_TASK )
12     MT_ProcessEvent,
13 #endif
14     APS_event_loop,
15 #if defined ( ZIGBEE_FRAGMENTATION )
16     APSF_ProcessEvent,
17 #endif
18     ZDApp_event_loop,
19 #if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )
20     ZDNwkMgr_event_loop,
21 #endif
22 SampleApp_ProcessEvent 23 };
24 
25 const uint8 tasksCnt = sizeof( tasksArr ) / sizeof( tasksArr[0] );
26 uint16 *tasksEvents;
27 
28 /*********************************************************************
29  * FUNCTIONS
30  *********************************************************************/
31 
32 /*********************************************************************
33  * @fn      osalInitTasks
34  *
35  * @brief   This function invokes the initialization function for each task.
36  *
37  * @param   void
38  *
39  * @return  none
40  */
41 void osalInitTasks( void )
42 {
43     uint8 taskID = 0;
44 
45     // 分配内存,返回指向缓冲区的指针
46     tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt);
47     // 设置所分配的内存空间单元值为0
48     osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt));
49 
50     // 任务优先级由高向低依次排列,高优先级对应taskID 的值反而小
首页 上一页 1 2 3 4 下一页 尾页 1/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇curses.h: No such file or direc.. 下一篇Arduino舵机控制

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目