Zpal-power-manager#
Defines a platform abstraction layer for the Z-Wave power manager.
The ZPAL power manager offers an API for registering power locks and for receiving events on power mode transitions. Power lock forces the chip to stay awake in a given power mode for a given time. An event handler is invoked every time the transition between power modes occurs.
Infinite lock example:
zpal_pm_lock(ZPAL_PM_TYPE_USE_RADIO, ZPAL_PM_DOMAIN_APP, 0, id); Keep the radio active forever, id is the lock ID find it in zpal_power_manager_ids.h
Other stuff
zpal_pm_lock_cancel(type, id); The chip may go to sleep now
Lock with timeout example:
zpal_pm_lock(ZPAL_PM_TYPE_USE_RADIO, ZPAL_PM_DOMAIN_APP, 2000, id); Keep the radio active for 2000 ms from now
Requirements:
The storage for power locks should be able to hold at least 20 items. Note that this number may change in the future.
Modules#
Enumerations#
Power manager type in which a lock can request an opearation to prevent the system from entering a sleep mode.
Power manager power levels, each level corresponds to physical power mode implementation.
For each lock, three states are defined:
A domain is a group of locks.
Functions#
Locks the power mode for a given time period.
Locks the power mode for a given time period.
Gets the maximum timeout value that can be set for a lock.
Return the state of a given lock.
Return the state of the given type of lock.
Registers a domain for power locks.
This function cancels an active power lock despite of the ongoing mode (permanent or timer).
Cancels all active power locks on both radio and deep sleep power locks.
Function to update stack logic (radio operations and configuration) before power mode transitions defined in zpal_pm_powerlevel_t.
Enumeration Documentation#
zpal_pm_type_t#
zpal_pm_type_t
Power manager type in which a lock can request an opearation to prevent the system from entering a sleep mode.
Enumerator | |
---|---|
ZPAL_PM_TYPE_USE_RADIO | |
ZPAL_PM_TYPE_USE_RADIO_TX | |
ZPAL_PM_TYPE_USE_RADIO_RX | |
ZPAL_PM_TYPE_DEEP_SLEEP | |
ZPAL_PM_TYPE_MAX |
zpal_pm_powerlevel_t#
zpal_pm_powerlevel_t
Power manager power levels, each level corresponds to physical power mode implementation.
Enumerator | |
---|---|
ZPAL_PM_ACTIVE | Processor is active. |
ZPAL_PM_LIGHT_SLEEP | Processor is sleeping, but all peripherals are enabled. |
ZPAL_PM_DEEP_SLEEP | Most peripherals are disabled, but the radio is in FLiRS mode. |
ZPAL_PM_HALTED | Chip is off and will boot from reset. Hence, no transition from this power mode will ever happen. |
zpal_pm_state_t#
zpal_pm_state_t
For each lock, three states are defined:
ZPAL_PM_STATE_ACTIVE_PERMANENT: The lock is active and will remain active until it is cancelled.
ZPAL_PM_STATE_ACTIVE_TIMER: The lock is active and will remain active until the timer expires.
ZPAL_PM_STATE_INACTIVE: The lock is inactive.
Enumerator | |
---|---|
ZPAL_PM_STATE_ACTIVE_PERMANENT | |
ZPAL_PM_STATE_ACTIVE_TIMER | |
ZPAL_PM_STATE_INACTIVE | |
ZPAL_PM_STATE_UNDEFINED |
zpal_pm_domain_t#
zpal_pm_domain_t
A domain is a group of locks.
They are stored in the same domain structure.
Enumerator | |
---|---|
ZPAL_PM_DOMAIN_APP | |
ZPAL_PM_DOMAIN_PAL | |
ZPAL_PM_DOMAIN_STACK | |
ZPAL_PM_DOMAIN_UNDEFINED |
Function Documentation#
zpal_pm_lock#
zpal_status_t zpal_pm_lock (zpal_pm_type_t type, zpal_pm_domain_t domain, uint32_t timeout_ms, uint8_t idx)
Locks the power mode for a given time period.
Type | Direction | Argument Name | Description |
---|---|---|---|
zpal_pm_type_t | N/A | type | The power manager type for the lock. If the lock is already active, this function does not overwrite the previous lock state. zpal_pm_relock can be used to overwrite the previous lock. |
zpal_pm_domain_t | N/A | domain | The domain in which the lock is registered. |
uint32_t | N/A | timeout_ms | The timeout duration in ms. If set to 0, the lock will be permanent. The maximum timeout value is defined by zpal_get_max_timeout. |
uint8_t | N/A | idx | The lock index |
Returns
true when the lock is successfully acquired
ZPAL_STATUS_BUSY if the lock is already in active state.
ZPAL_STATUS_INVALID_ARGUMENT when the type or idx are invalid or timeout is greater than the maximum timeout.
ZPAL_STATUS_OK if the lock is successfully acquired.
Note
to acquire by force, use zpal_pm_relock
zpal_pm_relock#
zpal_status_t zpal_pm_relock (zpal_pm_type_t type, zpal_pm_domain_t domain, uint32_t timeout_ms, uint8_t idx)
Locks the power mode for a given time period.
Type | Direction | Argument Name | Description |
---|---|---|---|
zpal_pm_type_t | N/A | type | The power manager type for the lock. |
zpal_pm_domain_t | N/A | domain | The domain in which the lock is registered. |
uint32_t | N/A | timeout_ms | The timeout duration in ms. If set to 0, the lock will be permanent. The maximum timeout is return by zpal_get_max_timeout. |
uint8_t | N/A | idx | The lock index |
If the lock is already active this function overwrites the previous lock. Use with caution. You can get the lock active state for the given id by calling zpal_pm_lock_is_activeReturns
true when the lock is successfully acquired, false otherwise (bad parameters).
ZPAL_STATUS_INVALID_ARGUMENT when the type or idx are invalid or timeout is greater than the maximum timeout.
ZPAL_STATUS_OK if the lock is successfully acquired.
zpal_get_max_timeout#
uint32_t zpal_get_max_timeout (void )
Gets the maximum timeout value that can be set for a lock.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Returns
The maximum timeout value in ms.
zpal_pm_lock_is_active#
bool zpal_pm_lock_is_active (zpal_pm_type_t type, zpal_pm_domain_t domain, uint8_t idx, zpal_pm_state_t * state)
Return the state of a given lock.
Type | Direction | Argument Name | Description |
---|---|---|---|
zpal_pm_type_t | [in] | type | The power manager type for the lock. |
zpal_pm_domain_t | [in] | domain | The domain of the lock. A domain is a group of locks that can be managed together. |
uint8_t | [in] | idx | The lock index |
zpal_pm_state_t * | [out] | state | (otional) More detailed state of the lock: INACTIVE, ACTIVE_PERMANENT, ACTIVE_TIMER. |
Returns
true is in active state, false if inactive.
Note
Similar to zpal_pm_lock_type_is_active but for an individual lock.
zpal_pm_lock_type_is_active#
bool zpal_pm_lock_type_is_active (zpal_pm_type_t pm_type, zpal_pm_state_t * state)
Return the state of the given type of lock.
Type | Direction | Argument Name | Description |
---|---|---|---|
zpal_pm_type_t | [in] | pm_type | The power manager type to be checked. |
zpal_pm_state_t * | [out] | state | (optional) More detailed state: INACTIVE, ACTIVE_PERMANENT, ACTIVE_TIMER. |
Resulted from all zwave locks operations on that type. Returns
true if the lock is active, false if inactive.
Note
: Similar to zpal_pm_lock_is_active but done at the type level which contains any locks operating on that type.
zpal_pm_register_domain#
zpal_status_t zpal_pm_register_domain (zpal_pm_domain_t domain, pm_domain_status_t * radio_domain_status, pm_domain_status_t * deep_sleep_domain_status)
Registers a domain for power locks.
Type | Direction | Argument Name | Description |
---|---|---|---|
zpal_pm_domain_t | N/A | domain | The domain to be registered. |
pm_domain_status_t * | [in] | radio_domain_status | Pointer to the radio domain status. If NULL, the domain will not be registered. |
pm_domain_status_t * | [in] | deep_sleep_domain_status | Pointer to the deep sleep domain status. If NULL, the domain will not be registered. |
Returns
ZPAL_STATUS_OK if one or two of the domains status are successfully registered, ZPAL_STATUS_FAIL otherwise.
zpal_pm_lock_cancel#
zpal_status_t zpal_pm_lock_cancel (zpal_pm_type_t type, zpal_pm_domain_t domain, uint8_t idx)
This function cancels an active power lock despite of the ongoing mode (permanent or timer).
Type | Direction | Argument Name | Description |
---|---|---|---|
zpal_pm_type_t | [in] | type | The lock type to cancel. |
zpal_pm_domain_t | N/A | domain | The domain in which the lock is associated. |
uint8_t | [in] | idx | The lock index to cancel. |
Note
If the specified type is not supported, this function will not perform any action.
Returns
ZPAL_STATUS_OK if the lock is successfully cancelled, ZPAL_STATUS_FAIL otherwise.
zpal_pm_lock_cancel_all#
void zpal_pm_lock_cancel_all (void )
Cancels all active power locks on both radio and deep sleep power locks.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Note
It cancels all power locks created during runtime, hence it can be used ONLY as a part of power down routine.
zpal_zw_pm_event_handler#
void zpal_zw_pm_event_handler (zpal_pm_powerlevel_t from, zpal_pm_powerlevel_t to)
Function to update stack logic (radio operations and configuration) before power mode transitions defined in zpal_pm_powerlevel_t.
Type | Direction | Argument Name | Description |
---|---|---|---|
zpal_pm_powerlevel_t | N/A | from | The power level from which the transition is happening. |
zpal_pm_powerlevel_t | N/A | to | The power level to which the transition is happening. |
Note
This function is called through app_pm_transition_event and is mapped onto power manager platform specific events.