This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Power supply in Zig bee end device

Hi all,

Can i enable  the power saving feature in end device during run time. My idea is like that i am having an end device running on mains supply and just by pressing a button(say on my development board ) i will be able to switch to power saving mode.So is that could be implemented like that.

In the Zstack ,they are using pre-processors to set the power supply type.

So how to make it work in run time instead of compile time.

Thanks

Amit Kumar 

  • You can use API osal_pwrmgr_device( PWRMGR_ALWAYS_ON ) and osal_pwrmgr_device( PWRMGR_BATTERY ) to enable/disable POWER_SAVING in the run time.

  • Hi Y.Chen

    Thanks for reply ,this method will work but i am facing problems with functions invoked through pre processor directives.I am attaching the snapshot of the functions invoked through macros.

    #if defined( POWER_SAVING )
    /* Allow sleep before the next OSAL event loop */
    ALLOW_SLEEP_MODE();
    # endif

    As theses functions are called in stack layers i am unable to make changes.So i cant make change to these functions.

    Thanks
    Amit Kumar
  • Since you want to control power mode by yourself, you shouldn't define POWER_SAVING in your project.
  • Hi Y.Chen,

    So just calling the api osal_pwrmgr_device( PWRMGR_ALWAYS_ON ) and osal_pwrmgr_device( PWRMGR_BATTERY ) the power mode could be changed.But there are certain functions which are needed to be called during the power saving state.

    Thanks
    Amit Kumar
  • Since you want to change it in the run time, you have to take care of those by yourself in the applcation.
  • Hi Y.Chen,

    Can i convert the pre-processor macros to variables in stack.Is this allowed?
    The below given code snap is from
    /****************************hal_drivers.c******************************/
    #if defined( POWER_SAVING )
    /* Allow sleep before the next OSAL event loop */
    ALLOW_SLEEP_MODE();
    #endif
    /**********************************************************************/
    /*****************************hal_mcu.h******************************/
    #ifdef POWER_SAVING
    extern volatile __data uint8 halSleepPconValue;

    /* Any ISR that is used to wake up the chip shall call this macro. This prevents the race condition
    * when the PCON IDLE bit is set after such a critical ISR fires during the prep for sleep.
    */
    #define CLEAR_SLEEP_MODE() st( halSleepPconValue = 0; )
    #define ALLOW_SLEEP_MODE() st( halSleepPconValue = PCON_IDLE; )
    #else
    #define CLEAR_SLEEP_MODE()
    #define ALLOW_SLEEP_MODE()
    #endif

    /************************************************************************/
    So can i convert these pre defined macros to if-else statement?Is this change allowed in Zstack.

    Thanks
    Amit
  • I don't think it's good to do that. You should manipulate API osal_pwrmgr_device( PWRMGR_ALWAYS_ON ) and osal_pwrmgr_device( PWRMGR_BATTERY ) in your application to change power mode.
  • Hi Y.Chen ,

    Thanks for the reply.
    So i will not change anything in the Zstack but there are certain code part which we cannot access from the application files if we are completely relying on macros in stack.We are able to access variables in the stack from application files but there are certain functions (related to power management configuration) which cannot be accessed from the application files.So is there any other way to access these functions.
    For example..
    /****************************hal_drivers.c******************************/
    #if defined( POWER_SAVING )
    /* Allow sleep before the next OSAL event loop */
    ALLOW_SLEEP_MODE();
    #endif
    /**********************************************************************/

    Thanks
    Amit Kumar
  • Can you elaborate why you have to use ALLOW_SLEEP_MODE?
  • Hi Y.Chen,

    The thing is that when power saving is not enabled then no sleeping (ALLOW_SLEEP_MODE) occurs before each event loop.But as per the example code they have given if power saving is enabled sleeping((ALLOW_SLEEP_MODE()) will be executed before each event loop occurs.As this sleeping function ((ALLOW_SLEEP_MODE()) is a part of stack and is defined with macros as i gave in the previous discussion I am not able to access this as per my requirement.

    Thanks
    Amit Kumar
  • I have told you that you can call osal_pwrmgr_device( PWRMGR_ALWAYS_ON ) to disable POWER_SAVING and call osal_pwrmgr_device( PWRMGR_BATTERY ) when you want to enable POWER_SAVING again.