RPM: Zigbee/z-stack CC2530 Introduction to Configuration for low-power operation

Source: Internet
Author: User

RPM: Zigbee/z-stack CC2530 Introduction to Configuration for low-power operation
Http://bbs.elecfans.com/jishu_914377_1_1.html
(Source: China Electronic Technology Forum)

Device support low-power operation is a major feature of ZigBee network, this feature with the help of CC2530 chip can be well reflected. The CC2530 chip has five modes of operation, namely active mode, idle mode, PM1, PM2, and PM3. The active mode is the general operating mode, while the idle mode is the same as the active mode except that the CPU core is stopped, the PM1, PM2, PM3 are low-power operation modes, and the CC2530 achieves low power by turning off unnecessary parts and adjusting the system clock.

PM1: The digital part of the regulator is turned on, and the Mhzxosc and the Rcosc are not running. Up to Rcosc or up to khz XOSC operation. The system will go to active mode when the reset, external interrupt, or sleep timer overflows.
PM2: The digital core of the regulator is off. Both the Mhzxosc and the MHz Rcosc do not run. 32kHz Rcosc or up to khz XOSC operation. The system goes to active mode when the reset, external interrupt, or sleep timer expires.

PM3: The digital core of the regulator is off. All the oscillators are not running. The system will go to active mode when reset or external interrupt.
The comparison of several operating modes is shown in the following table:


PM2 mode is also called Lite sleep mode, its power consumption in the MA level, more used in the occasion of the need to wake up periodically, such as the periodic wake-up sensor for data collection.
PM3 mode is also called deep sleep mode, in several modes of operation, the lowest power consumption, in the micro-security level, more for remote control occasions, such as the use of CC2530 to do a remote control, when there is no key press, you can make it into PM3 mode to reduce power consumption.

The Z-stack offers two low-power operating modes, PM2 and PM3. PM2 mode can be awakened by sleep timer, external interrupt and reset, PM3 mode can be awakened by external interrupt and reset.

In the Z-stack documentation, the following conditions must be met in order for the device to enter sleep mode:
1. Power_saving to enable sleep mode by adding pre-compiled items
2. The ZdO node descriptor specifies that the Send function is off when idle and is implemented by setting the rfd_rcvc_always_on to False in the F8wconfig.cfg file.
3, all the Z-stack Mission Support powersaving
4. There are no scheduled events for each task of Z-stack
5. There are no scheduled event events for Mac
Before setting it up, let's take a look at the flow of z-stack into sleep mode.

First, z-stack into the sleep mode of the flow analysis
At the end of the main function, the program enters the Osal_start_system function to start the polling mechanism, and at the end of the Osal_start_system function, the program determines whether power management is performed by judging the macro, as follows:
#if defined (power_saving)
else/complete pass through all tasks events with no activity?
{
Osal_pwrmgr_powerconserve (); Put the Processor/system into sleep
}
#endif


[Color=rgb (Wuyi, 102, 153)!important] Copy code

It can be seen that if we define the macro power_saving at precompilation and satisfy the else condition, the program will osal_pwrmgr_powerconserve the function, and the IF condition of the else corresponds to the IF (idx< taskscnt). The analysis shows that if is used to determine whether the current system has to perform tasks, that is, to enter power management, you must also meet the system does not currently perform tasks or will be performed.

Enter the Osal_pwrmgr_powerconserve function first to make two judgments, the first time to determine whether the device is battery equipment: pwrmgr_attribute.pwrmgr_device!=pwrmgr_always_ On where PWRMGR_ALWAYS_ON macros are defined in Osal_pwrmgr.h, battery-powered devices are represented by a macro pwrmgr_battery.
/* With pwrmgr_always_on selection, there is no power savings and the
* Device is very likely on mains power. The Pwrmgr_battery selection allows
* The HAL Sleep Manager to enter a sleep LITE state or a sleep deep state.
*/
#define PWRMGR_ALWAYS_ON 0
#define Pwrmgr_battery 1


[Color=rgb (Wuyi, 102, 153)!important] Copy code
The second judgment is to determine whether all tasks support power saving:
if (pwrmgr_attribute.pwrmgr_task_state = = 0)

   Verify that both conditions are met before closing interrupt hal_enter_critical_section (intstate), and then get the time of the next task deadline, Next = Osal_next_timeout (); Then enable interrupt hal_exit_critical_section (intstate); When the next task deadline is obtained, the interrupt is closed in order to not affect the acquisition of time, get an accurate time, and finally call the macro Osal_set_cpu_into_sleep (next); Trace found that the macro is actually called the function Halsleep, the function in the file hal_sleep.c, in the Hal_sleep function, first to get z-stack the next task deadline and the next time the MAC task deadline, using the following statement:
if (timeout = 0)//z-stack The next task deadline is 0, that is, there is no scheduled z-stack task
  {
    Timeout = mac_ Pwrnexttimeout ();//Get Mac The deadline for next task
  }
  else//have scheduled Z-stack tasks
  {
   /* Get next Mac Timer expiration */
    mactimeout = Mac_pwrnexttimeout ();/Get Mac deadline for next task
/ * Get lesser of timeouts */
//Get Z-stack the next task deadline and the next deadline for Mac tasks
    if ((mactimeout! = 0) && (Mactimeout < timeout))
    {
      timeout = mactimeout;//The minimum value as sleep time
   }
   }


[Color=rgb (Wuyi, 102, 153)!important] Copy code
After getting timeout, and then deciding whether to enter PM2 or PM3 mode by judging timeout, Halpwrmgtmode = (timeout = 0)? Hal_sleep_deep:hal_sleep_timer; If timeout is 0, and Z-stack and Mac do not have scheduled tasks, the system enters PM3 mode, and if not 0, it enters PM2 mode.

Power management concepts are usually adopted by battery-powered devices, and in order to maintain the integrity and stability of the network, the coordinator and routers are generally not battery-powered, that is, only the terminal equipment is often battery-powered, so when used to avoid the coordinator and the router to turn on the power_saving option.
After understanding the general process, the next step is to introduce the method of opening PM2, PM3 in Z-stack.

Second, z-stack to open PM2, PM3 method

First step: Add the precompiled item power_saving.
Right-click the project name, select the Options->c/c++compiler/preprocessor option, and add power_saving in the defined symbols box.


Step Two: Modify the F8wconfig.cfg file.

Locate-drfd_rcvc_always_on to change the value to-drfd_rcvc_always_on=false
Change-dpoll_rate=1000 to-dpoll_rate=0
Change-dqueued_poll_rate=0 to-dqueued_poll_rate=0
Change-dresponse_poll_rate=100 to-dresponse_poll_rate=0

The above settings are described below.
Enddevice in Z-stack engineering is not power-managed by default, so the automatic polling message mechanism is turned on. There are three polling options in the project, each one has a timed delay time, so each polling will affect the sleep mechanism, the timing of the time delay can not make the device into the PM3 mode, which to a certain extent increased the consumption of electricity. The descriptions of the three polling options are as follows:
1, data request Polling, periodically sends the database requests to the parent node to poll the message queue. The polling interval is set by the Nlme_setpollrate function or zgpollrate, and if it was previously forbidden, polling is started immediately when the Nlme_setpollrate function is called.
2, Queued data Polling, after receiving the information instruction, will request the message to the parent node, this time interval can be set by the function nlme_setqueuedpollrate or the zgqueuedpollrate parameter.
3, Response datapolling, after receiving the data confirmation instruction, will request the response message to the parent node, this time interval can be set by the Nlme_setresponsepollrate function or the zgresponsepollrate parameter.
The above three parameters and functions are only terminal equipment available, in Zstack, the default method of specifying parameter values to set the polling time, in ZGLOBALS.C can be seen:
Polling values
UInt16 zgpollrate= poll_rate;
Uint16zgqueuedpollrate = queued_poll_rate;
Uint16zgresponsepollrate = response_poll_rate;
UInt16 zgrejoinpollrate =rejoin_poll_rate;
The Poll_rate, Queued_poll_rate, response_poll_rate three parameters are set in the file F8wconfig.cfg, as described above. For the above three parameters, if you only use the default settings, you can only enter the PM2 mode, to be able to enter the PM3 mode, you must set the value of the above three parameters to 0.
At the end of the f8wconfig.cfg file, there is a polling parameter--re-join the parameter, that is, when joining the network is not successful when the set time to re-request to join the network,-drejoin_poll_rate. If you want to experiment with low power only if the end node does not have a coordinator, you can set this parameter to 0 so that the device does not enter the PM2 mode once every 440 milliseconds (the default value is 440).
Step Three: Configure a program that has polling, that is, a task that has scheduled activities.

The above-mentioned tasks of scheduled activities will allow the system to enter PM2 mode only, these scheduled interactions include Z-stack and Mac, and in Z-stack where the function Osal_start_timerex is used to generate scheduled task activities. In Z-stack, there are two places to use the Osal_start_timerex function, one is to use the polling method to scan the button, the other is in the application layer of some user-defined timing tasks, so in order to enable the device to enter the PM3 mode, it is necessary to block out these two places. The first is to change the mechanism of the key to interrupt mode, in the Else branch of the Initboard function will onboardkeyintenable = hal_key_interrupt_disable; change to onboardkeyintenable= Hal_ Key_interrupt_enable, and then block all the applications in the application layer where the Osal_start_timerex function is used.
Fourth Step:

It is mentioned above that after entering the Osal_pwrmgr_powerconserve function, the power management properties are judged two times to determine that the device is a battery-powered device, while all tasks support powersaving, and this part is set in the function osal_pwrmgr_ In init, modify the function to the following:
void Osal_pwrmgr_init (void)
{
Pwrmgr_attribute.pwrmgr_device = pwrmgr_always_on; Default to no power//conservation.
Pwrmgr_attribute.pwrmgr_device = Pwrmgr_battery;
pwrmgr_attribute.pwrmgr_task_state = 0;  Cleared. All set to conserve

Go: Zigbee/z-stack CC2530 Configuration introduction for low-power operation

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.