[ZigBee] 15, ZigBee protocol stack Application (i)--zigbee protocol stack introduction and simple examples (long wen, osal and ZigBee introduction knowledge)

Source: Internet
Author: User
Tags network function

1. Introduction to ZigBee protocol stack

Protocol is a series of communication standards, both sides of the communication need to follow this standard for normal data transmission and reception. Protocol stack is a concrete implementation of the Protocol, the popular protocol stack is a protocol and the interface between users, developers through the use of protocol stack to use this protocol, to achieve wireless data transmission.

1: The ZigBee protocol is divided into two parts, IEEE 802.15.4 defines the PHY (physical layer) and Mac (media access layer) technical specifications; The ZigBee Alliance defines the NWK (network layer), the APS (Application support layer), and the APL (application layer) technical specifications. The ZigBee protocol stack is a combination of the protocols defined by each layer, implemented in the form of functions, and provides the user with an API (application layer) that the user can call directly.

Figure 1 Architecture diagram of ZigBee Wireless network protocol layer

2. How to understand the ZigBee protocol stack

Protocol stack is the implementation of the Protocol, can be understood as code, library functions for the upper application call, the protocol is the lower layer and the application is independent of each other. The commercial protocol stack only provides you with the interface (in fact, the Internet industry's API model is very similar). Just as you do not need to worry about how the underlying map is plotted based on location or coordinates when you invoke the map API, you do not have to care about the underlying implementation of the protocol stack unless you want to do protocol research. Each manufacturer's protocol stack is different, such as TI's BLE protocol stack and Nordic BLE protocol stack there is a big difference (say a little, TI's ble stack is more like the BLE structure of Android, so the Android Bluetooth may be able to read the code of TI).

3. How to use ZigBee protocol stack

In the case of simple wireless data communication, the general steps are:

① Network: Call the protocol stack network function, join the network function, realize the establishment of networks and join the nodes

② Send: Send node call protocol stack send function, to achieve data wireless transmission

③ Receive: Receive node calls the protocol stack wireless receive function, realizes the wireless data receives

Since the protocol stack encapsulates these functions, it is convenient for us to use them. Here is the protocol stack wireless send function:

A better application of the protocol stack requires a detailed understanding of the specific role and significance of these functions and their parameters provided by the protocol stack, which is described in detail in the next step.

4. Install ZigBee protocol stack

Download 004 from all of this series of information I share from Baidu and install:

               Figure 2 ZigBee protocol stack download path

After installation, the following file structure will be available under the Win7 Start button:

Figure 3 The file structure after the ZigBee protocol installation is complete

  which

5. Protocol stack based Wireless transceiver control LED engineering explanation (a)

Download zstack-2.3.1a compressed files from the network disk:

Figure 4 The project source of the Cloud disk directory

  

Open with IAR. Engineering documents under the \ZSTACK-2.5.1A\PROJECTS\ZSTACK\SAMPLES\SAMPLEAPP\CC2530DB directory, Be careful not to put the 001stack-2.5.1a in the deeper folder, otherwise the IAR open the project may have been stuck, it is best not to have Chinese! Open after the project and structure as follows: (A little dazzled, does not matter, the following will be combined with the source code step-by-step analysis)

Figure 5 Overall architecture of the project

6. Protocol stack based Wireless transceiver control LED Engineering explanation (b)

  In the IAR select Xxxxeb, the first time to rebuild all, download the coordinator, and then switch to Enddeviceeb compile download to another board to do terminal equipment:

          Figure 6 Compiling the project

Two node program download good after the power will see: After the success of the network D1 flashing.

Fig. 7 Experimental phenomena

7. Protocol stack based Wireless transceiver control LED engineering explanation (c)

Main code:

1 intMainvoid )2 { 3 osal_int_disable (Ints_all); // Turn off interrupts off interrupt 4Hal_board_init ();//initialization for board related stuff such as LEDs5Zmain_vdd_check ();//Make sure supply voltage are high enough to run check that the chip is up and running 6Initboard (Ob_cold);//Initialize Board I/O initialization i/o,led,timer, etc. 7Haldriverinit ();//Initialze HAL Drivers Initializing the hardware abstraction Layer driver module 8Osal_nv_init (NULL);//Initialize NV System initialize flash memory 9ZNPTESTRF ();//Initialize and check the ZNP RF Test Mode NV items.TenZmacinit ();//Initialize the Mac initializes the MAC layer  OneZmain_ext_addr ();//determine the extended address determine IEEE64  location A  - #ifDefined Zcl_key_establish -Zmain_cert_init ();//Initialize the Certicom certificate information. the #endif -  -Zginit ();//Initialize Basic NV Items initialize non-volatile variables  -  + #ifndef Nonwk -Afinit ();//Since the AF isn ' t a task, call it ' s initialization routine + #endif A  Osal_init_system ();//Initialize The operating system initializes the OS (highlights 1) Osal_int_ena BLE (ints_all); // allow interrupts to interrupt   -Initboard (Ob_ready);//Final Board initialization Ultimate onboard initialization  -Zmain_dev_info ();//Display Information The device information (there is an LCD screen) about the This  device   - -#ifdef lcd_supported/*Display the device info on the LCD displays information on the LCD*/ in Zmain_lcd_init ();  - #endif to  + #ifdef WDT_IN_PM1 -Watchdogenable (WDTIMX);/*If WDT is used, the is a good place to enable it.*/ the #endif * OSAL_START_ZNP ();//No Return from here Execution operating system (highlights 2)Panax Notoginseng  -     return 0;//shouldn ' t get here. the}//Main ()

Code is a bit difficult to understand, the core is to perform initialization work, including hardware abstraction layer, network layer, task and so on. It then executes OSAL_START_ZNP (), enters a dead loop, and constantly traverses the task . Here we need to focus on about two functions:

① Operating System initialization function

In operating system initialization, it is important to focus on the operating system task initialization osalinittasks function, the operating system initialization function mainly to create tasks , TaskID is the task ID, each additional task id++, while A smaller ID indicates that the task has a higher priority ! Where the function in the blue box is to be based on the system want to complete the task to make changes in the place, the other is officially provided by the basic do not change the task.

② Operating system startup function

The function that executes the OS is a cycle , constantly taking out the highest priority pending event for processing, the core idea of processing is inside the Osal_run_task function: invoking a function pointer to call an event handler remotely !

8. Summary

At this point, we talk about how the task is set up, how to deal with it, and one of them is not-how to relate the event handler function from events= (tasksarr[idx]) (idx,event) to each specific task? In fact, I have cc2540/cc2541 in the first two articles in detail: [Next will be for the specific communication carding process!] ]

1, CC2541 Bluetooth 4.0 Chip Intermediate Tutorial--based on osal operating system Operation process Understanding + timers and serial port routines

2, CC2541 Chip Intermediate tutorial-osal operating system (learn more about-oled && normal keys and 5-directional buttons-Interrupt!!!) This system drive layer is not the same as the application layer ~

3, CC2541 Chip Intermediate tutorial-osal operating System (ADC Photoresistors and modified serial port baud rate)

4, CC2541 Chip Intermediate tutorial-osal operating system (simple at instruction implementation +IIC software and hardware implementation drive MPU6050)

5, CC2541 Chip Intermediate tutorial-osal operating system (pwm+ watchdog)

ZigBee Series Articles:

[ZigBee] 1, ZigBee introduction

[ZigBee] 2, ZigBee development environment construction

[ZigBee] 3, ZigBee basic experiment--gpio Output control experiment-control LED light off

[ZigBee] 4, ZigBee basic experiment--interrupt

[ZigBee] 5, ZigBee basic Experiment--graphics and code detailed timer 1 (16-bit timer) (long text)

[ZigBee] 6, ZigBee basic Experiment--timer 3 and Timer 4 (8-bit timer)

[ZigBee] 7, ZigBee analysis of the UART (only serial transmission)

[ZigBee] 8, ZigBee of the UART analysis • Two (serial transceiver)

[ZigBee] 9, ZigBee AD Analysis--ad collection CC2530 temperature serial display

[ZigBee] 10, ZigBee sleep Timer

[ZigBee] 11, ZigBee Sleep Timer two

[ZigBee] 12, ZigBee watchdog timer--Bite the good dog when hungry

[ZigBee] 13, ZigBee Foundation Stage Review and deepen understanding-with timer 1 to generate PWM to control the LED brightness (seven-color lamp)

[ZigBee] 14, ZigBee wireless communication Prelude--BASICRF Simple Wireless Point-to-point transmission protocol

PS: If you feel good, click a praise, let more people benefit ~

@beautifulzzzz 2016-07-31 continue~
e-mail:[email protected]
Sina:http://weibo.com/beautifulzzzz?is_all=1

  

[ZigBee] 15, ZigBee protocol stack Application (i)--zigbee protocol stack introduction and simple examples (long wen, osal and ZigBee introduction knowledge)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.