码迷,mamicode.com
首页 > 其他好文 > 详细

Ztack学习笔记(2)-系统初始化分析

时间:2015-05-10 23:59:03      阅读:425      评论:0      收藏:0      [点我收藏+]

标签:

 

一 系统初始化

 1 uint8 osal_init_system( void )
 2 {
 3   // Initialize the Memory Allocation System
 4   osal_mem_init();
 5 
 6   // Initialize the message queue
 7   osal_qHead = NULL;
 8 
 9   // Initialize the timers
10   osalTimerInit();
11 
12   // Initialize the Power Management System
13   osal_pwrmgr_init();
14 
15   // Initialize the system tasks.
16   osalInitTasks();
17 
18   // Setup efficient search for the first free block of heap.
19   osal_mem_kick();
20 
21   return ( SUCCESS );
22 }

 

二 任务初始化

 1 void osalInitTasks( void )
 2 {
 3   uint8 taskID = 0;
 4 
 5   tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt);
 6   osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt));
 7 
 8   macTaskInit( taskID++ );
 9   nwk_init( taskID++ );
10   Hal_Init( taskID++ );
11 #if defined( MT_TASK )
12   MT_TaskInit( taskID++ );
13 #endif
14   APS_Init( taskID++ );
15 #if defined ( ZIGBEE_FRAGMENTATION )
16   APSF_Init( taskID++ );
17 #endif
18   ZDApp_Init( taskID++ );
19 #if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )
20   ZDNwkMgr_Init( taskID++ );
21 #endif
22   SampleApp_Init( taskID );
23 }

 

3 应用初始化

 1 void SampleApp_Init( uint8 task_id )
 2 {
 3   SampleApp_TaskID = task_id;
 4   SampleApp_NwkState = DEV_INIT;
 5   SampleApp_TransID = 0;
 6 
 7   // Device hardware initialization can be added here or in main() (Zmain.c).
 8   // If the hardware is application specific - add it here.
 9   // If the hardware is other parts of the device add it in main().
10 
11  #if defined ( BUILD_ALL_DEVICES )
12   // The "Demo" target is setup to have BUILD_ALL_DEVICES and HOLD_AUTO_START
13   // We are looking at a jumper (defined in SampleAppHw.c) to be jumpered
14   // together - if they are - we will start up a coordinator. Otherwise,
15   // the device will start as a router.
16   if ( readCoordinatorJumper() )
17     zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR;
18   else
19     zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER;
20 #endif // BUILD_ALL_DEVICES
21 
22 #if defined ( HOLD_AUTO_START )
23   // HOLD_AUTO_START is a compile option that will surpress ZDApp
24   //  from starting the device and wait for the application to
25   //  start the device.
26   ZDOInitDevice(0);
27 #endif
28 
29   // Setup for the periodic message‘s destination address
30   // Broadcast to everyone
31   SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast;
32   SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
33   SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF;
34 
35   // Setup for the flash command‘s destination address - Group 1
36   SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)afAddrGroup;
37   SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
38   SampleApp_Flash_DstAddr.addr.shortAddr = SAMPLEAPP_FLASH_GROUP;
39 
40   // Fill out the endpoint description.
41   SampleApp_epDesc.endPoint = SAMPLEAPP_ENDPOINT;
42   SampleApp_epDesc.task_id = &SampleApp_TaskID;
43   SampleApp_epDesc.simpleDesc
44             = (SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc;
45   SampleApp_epDesc.latencyReq = noLatencyReqs;
46 
47   // Register the endpoint description with the AF
48   afRegister( &SampleApp_epDesc );
49 
50   // Register for all key events - This app will handle all key events
51   RegisterForKeys( SampleApp_TaskID );
52 
53   // By default, all devices start out in Group 1
54   SampleApp_Group.ID = 0x0001;
55   osal_memcpy( SampleApp_Group.name, "Group 1", 7  );
56   aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group );
57 
58 #if defined ( LCD_SUPPORTED )
59   HalLcdWriteString( "SampleApp", HAL_LCD_LINE_1 );
60 #endif
61 }

 

Ztack学习笔记(2)-系统初始化分析

标签:

原文地址:http://www.cnblogs.com/gjianw217/p/4493337.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!