日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ZigBee协议栈工作原理

發(fā)布時間:2024/8/1 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ZigBee协议栈工作原理 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

??ZigBee的任務(wù)輪詢?nèi)缦聢D:

??打開協(xié)議棧文件夾Texas Instruments\Projects\zstack,里面包含了TI公司的例程和工具。再打開Samples文件夾:

??Samples文件夾里面有三個例子,即GenericApp、SampleApp、SimpleApp。在這里我們選擇SampleApp對協(xié)議棧的工作流程進(jìn)行講解。打開SampleApp\CC2530DB下的工程文件SampleApp.eww,留意左邊的工程目錄,我們暫時只需要關(guān)注Zmain文件夾和App文件夾。

??任何程序都在main函數(shù)開始運(yùn)行,Z-STACK也不例外。打開Zmain.C,找到main函數(shù)。大概瀏覽一下main函數(shù)的代碼:

int main ( void ) {osal_int_disable ( INTS_ALL ); /* Turn off interrupts 關(guān)閉所有中斷 */HAL_BOARD_INIT(); /* Initialization for board related stuff such as LEDs */zmain_vdd_check(); /* Make sure supply voltage is high enough to run 檢查芯片電壓是否正常 */InitBoard ( OB_COLD ); /* Initialize board I/O 初始化I/O、LED、Timer等 */HalDriverInit(); /* Initialze HAL drivers 初始化芯片各硬件模塊 */osal_nv_init ( NULL ); /* Initialize NV System 初始化Flash存儲器 */ZmacInit(); /* Initialize the MAC 初始化MAC層 */zmain_ext_addr(); /* Determine the extended address 確定“IEEE 64”位地址 */zgInit(); /* Initialize basic NV items 初始化非易失變量 */ #ifndef NONWKafInit(); /* Since the AF isn't a task, call it's initialization routine */ #endifosal_init_system(); /* Initialize the operating system 初始化操作系統(tǒng) */osal_int_enable ( INTS_ALL ); /* Allow interrupts 使能全部中斷 */InitBoard ( OB_READY ); /* Final board initialization 初始化按鍵 */zmain_dev_info(); /* Display information about this device 顯示設(shè)備信息 */ #ifdef LCD_SUPPORTED /* Display the device info on the LCD */zmain_lcd_init(); #endif #ifdef WDT_IN_PM1WatchDogEnable ( WDTIMX ); /* If WDT is used, this is a good place to enable it. */ #endifosal_start_system(); /* No Return from here 執(zhí)行操作系統(tǒng),進(jìn)去后不會返回 */return 0; /* Shouldn't get here. */ }

??我們重點(diǎn)了解2個函數(shù):初始化操作系統(tǒng)osal_init_system,運(yùn)行操作系統(tǒng)osal_start_system。先來看osal_init_system系統(tǒng)初始化函數(shù)。進(jìn)入該函數(shù),發(fā)現(xiàn)里面有6個初始化函數(shù),這里只關(guān)心osalInitTasks任務(wù)初始化函數(shù):

void osalInitTasks ( void ) {uint8 taskID = 0;tasksEvents = ( uint16 * ) osal_mem_alloc ( sizeof ( uint16 ) * tasksCnt ); /* 分配內(nèi)存,返回指向緩沖區(qū)的指針 */osal_memset ( tasksEvents, 0, ( sizeof ( uint16 ) * tasksCnt ) ); /* 設(shè)置所分配的內(nèi)存空間單元值為0 *//* 任務(wù)優(yōu)先級由高向低依次排列,高優(yōu)先級對應(yīng)taskID的值反而小 */macTaskInit ( taskID++ ); /* macTaskInit(0),用戶不需考慮 */nwk_init ( taskID++ ); /* nwk_init(1),用戶不需考慮 */Hal_Init ( taskID++ ); /* Hal_Init(2),用戶需考慮 */ #if defined( MT_TASK )MT_TaskInit ( taskID++ ); #endifAPS_Init ( taskID++ ); /* APS_Init(3),用戶不需考慮 */ #if defined ( ZIGBEE_FRAGMENTATION )APSF_Init ( taskID++ ); #endifZDApp_Init ( taskID++ ); /* ZDApp_Init(4),用戶需考慮 */ #if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )ZDNwkMgr_Init ( taskID ++ ); #endifSampleApp_Init ( taskID ); /* SampleApp_Init(5),用戶需考慮 */ }

??我們可以這樣理解,函數(shù)對taskID這個東西進(jìn)行初始化,每初始化一個任務(wù),taskID加一。大家看到了注釋后面有些寫著用戶需要考慮,有些則寫著用戶不需考慮。寫著需要考慮的,用戶可以根據(jù)自己的硬件平臺進(jìn)行設(shè)置;寫著不需考慮的,則是不能修改的。
??我們再來看第二個函數(shù)osal_start_system運(yùn)行操作系統(tǒng)。TI對該函數(shù)的描述為This function is the main loop function of the task system. It will look through all task events and call the task_event_processor() function for the task with the event. If there are no events (for all tasks), this function puts the processor into Sleep. This Function doesn't return.,翻譯成中文是這個是任務(wù)系統(tǒng)輪詢的主要函數(shù),它會查找發(fā)生的事件,然后調(diào)用相應(yīng)的事件執(zhí)行函數(shù)。如果沒有事件登記要發(fā)生,那么就進(jìn)入睡眠模式。這個函數(shù)是永遠(yuǎn)不會返回的。

void osal_start_system ( void ) { #if !defined ( ZBIT ) && !defined ( UBIT )for ( ;; ) /* Forever Loop */ #endif{uint8 idx = 0;osalTimeUpdate(); /* 這里是在掃描哪個事件被觸發(fā)了,然后置相應(yīng)的標(biāo)志位 */Hal_ProcessPoll(); /* This replaces MT_SerialPoll() and osal_check_timer(). */Do {if ( tasksEvents[idx] ) { /* Task is highest priority that is ready. */break; /* 得到待處理的最高優(yōu)先級任務(wù)索引號idx */}} while ( ++idx < tasksCnt );if ( idx < tasksCnt ) {uint16 events;halIntState_t intState;HAL_ENTER_CRITICAL_SECTION ( intState ); /* 進(jìn)入臨界區(qū),保護(hù) */events = tasksEvents[idx]; /* 提取需要處理的任務(wù)中的事件 */tasksEvents[idx] = 0; /* Clear the Events for this task. 清除本次任務(wù)的事件 */HAL_EXIT_CRITICAL_SECTION ( intState ); /* 退出臨界區(qū) */events = ( tasksArr[idx] ) ( idx, events ); /* 通過指針調(diào)用任務(wù)處理函數(shù),關(guān)鍵 */HAL_ENTER_CRITICAL_SECTION ( intState ); /* 進(jìn)入臨界區(qū) */tasksEvents[idx] |= events; /* Add back unprocessed events to the current task. 保存未處理的事件 */HAL_EXIT_CRITICAL_SECTION ( intState ); /* 退出臨界區(qū) */} #if defined( POWER_SAVING )else { /* Complete pass through all task events with no activity? */osal_pwrmgr_powerconserve(); /* Put the processor/system into sleep */} #endif} }

總結(jié)

以上是生活随笔為你收集整理的ZigBee协议栈工作原理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。