zb_osif_sleep() return value

In the Zigbee framework, what is the purpose of the return variable from zb_osif_sleep() ? The "documentation" for Zigbee seems to implement a "guess and figure it out for yourself" model when it comes to parameters and return variables for many of its functions... Unfortunately, while I can guess that this is a success/failure type return, the meaning of those return values remains a mystery. (Documenting the parameter for zb_osif_sleep() would also be useful...)

Thanks.

  • To follow up on this... does anything actually need to be done with zb_osif_sleep()? The ZBOSS for Zigbee documentation states

    "After calling zb_sleep_now(), the stack prepares its peripherals for sleep, and informs the application that it is ready to go to sleep with a call to zb_osif_sleep()."

    This suggests to me that the developer needs to do something with zb_osif_sleep() to catch that notification. However, there's no code like this in the Zigbee light switch example.

    To be honest, the requirements for going into sleep modes with Zigbee and Zephyr are a bit vague. The ZBOSS for Zigbee documentation clearly states

    "To switch to the sleep mode, the application must call the zb_sleep_now() function."

    However, this isn't done in the Zigbee light switch example.

  • Hello Chris,

    It returns the duration that the device has slept in ms. You can find this in the implementation of the function here

    The sleep routine is roughly explained here. Application receives CAN_SLEEP signal when stack has nothing to for a given amount of time. Application can call zb_sleep_now() in this signal's handler to tell the stack to "go to sleep". As a result, stack invokes zb_osif_sleep() with the amount of time it can sleep for and this zb_osif_sleep() is responsible for switching device and/or its peripherals to low power mode, actually "sleeping" and returning the amount of time the device has slept for (note that the device can be waken up prematurely):

    In nRF5 SDK we actually called WFE/WFI to stop the CPU. In NCS we don't stop the CPU, Zigbee has its own independent thread and it is move to blocked state for the amount of time received in the zb_osif_sleep(), then the Zephyr scheduler decided when to enter IDLE state - basically when all other threads are suspended/blocked.

    Regards,

    Elfving

Related