One system initialization
1Uint8 Osal_init_system (void )2 {3 //Initialize the Memory Allocation System4 osal_mem_init ();5 6 //Initialize the message queue7Osal_qhead =NULL;8 9 //Initialize The TimersTen osaltimerinit (); One A //Initialize the Power Management System - osal_pwrmgr_init (); - the //Initialize the system tasks. - osalinittasks (); - - //Setup Efficient Search for the first free block of heap. + Osal_mem_kick (); - + return(SUCCESS); A}
Two-task initialization
1 voidOsalinittasks (void )2 {3Uint8 TaskID =0;4 5Tasksevents = (UInt16 *) Osal_mem_alloc (sizeof(uint16) *taskscnt);6Osal_memset (Tasksevents,0, (sizeof(uint16) *taskscnt));7 8Mactaskinit (taskid++ );9Nwk_init (taskid++ );TenHal_init (taskid++ ); One #ifDefined (mt_task) AMt_taskinit (taskid++ ); - #endif -Aps_init (taskid++ ); the #ifDefined (zigbee_fragmentation) -Apsf_init (taskid++ ); - #endif -Zdapp_init (taskid++ ); + #ifDefined (zigbee_freq_agility) | | Defined (zigbee_panid_conflict) -Zdnwkmgr_init (taskid++ ); + #endif A Sampleapp_init (TaskID); at}
3 Application Initialization
1 voidsampleapp_init (uint8 task_id)2 {3Sampleapp_taskid =task_id;4Sampleapp_nwkstate =Dev_init;5Sampleapp_transid =0;6 7 //Device Hardware initialization can is added here or in Main () (ZMAIN.C).8 //If The hardware is application Specific-add it 's here.9 //If the hardware is and other parts of the device, add it in Main ().Ten One #ifDefined (build_all_devices) A //the "Demo" target is a setup to has build_all_devices and Hold_auto_start - //We is looking at a jumper (defined in sampleapphw.c) to be jumpered - //Together-if They are-we would start up a coordinator. Otherwise, the //The device would start as a router. - if(Readcoordinatorjumper ()) -Zgdevicelogicaltype =Zg_devicetype_coordinator; - Else +Zgdevicelogicaltype =Zg_devicetype_router; - #endif //build_all_devices + A #ifDefined (Hold_auto_start) at //Hold_auto_start is a compile option that would surpress Zdapp - //From starting the device and wait for the application to - //start the device. -Zdoinitdevice (0); - #endif - in //Setup for the periodic message ' s destination address - //Broadcast to everyone toSampleapp_periodic_dstaddr.addrmode =(afaddrmode_t) addrbroadcast; +Sampleapp_periodic_dstaddr.endpoint =Sampleapp_endpoint; -SAMPLEAPP_PERIODIC_DSTADDR.ADDR.SHORTADDR =0xFFFF; the * //Setup for the flash command ' s destination address-group 1 $Sampleapp_flash_dstaddr.addrmode =(afaddrmode_t) afaddrgroup;Panax NotoginsengSampleapp_flash_dstaddr.endpoint =Sampleapp_endpoint; -SAMPLEAPP_FLASH_DSTADDR.ADDR.SHORTADDR =Sampleapp_flash_group; the + //Fill out the endpoint description. ASampleapp_epdesc.endpoint =Sampleapp_endpoint; thesampleapp_epdesc.task_id = &Sampleapp_taskid; + Sampleapp_epdesc.simpledesc -= (simpledescriptionformat_t *) &Sampleapp_simpledesc; $Sampleapp_epdesc.latencyreq =Nolatencyreqs; $ - //Register The endpoint description with the AF -Afregister (&sampleapp_epdesc); the - //Register for all key Events-this app would handle all key eventsWuyi Registerforkeys (sampleapp_taskid); the - //By default, all devices start out in Group 1 WuSampleapp_group.id =0x0001; -osal_memcpy (Sampleapp_group.name,"Group 1",7 ); AboutAps_addgroup (Sampleapp_endpoint, &sampleapp_group); $ - #ifDefined (lcd_supported) -Hallcdwritestring ("SampleApp", hal_lcd_line_1); - #endif A}
Ztack Study Notes (2)-System initialization analysis