This section describes the programming interface of the Notifier driver.
Notifier Overview
The Notifier provides a configuration dynamic change service. Based on this service, applications can switch between pre-defined configurations. The Notifier enables drivers and applications to register callback functions to this framework. Each time that the configuration is changed, drivers and applications receive a notification and change their settings. To simplify, the Notifier only supports the static callback registration. This means that, for applications, all callback functions are collected into a static table and passed to the Notifier.
These are the steps for the configuration transition.
- Before configuration transition, the Notifier sends a "BEFORE" message to the callback table. When this message is received, IP drivers should check whether any current processes can be stopped and stop them. If the processes cannot be stopped, the callback function returns an error.
The Notifier supports two types of transition policies, a graceful policy and a forceful policy. When the graceful policy is used, if some callbacks return an error while sending a "BEFORE" message, the configuration transition stops and the Notifier sends a "RECOVER" message to all drivers that have stopped. Then, these drivers can recover the previous status and continue to work. When the forceful policy is used, drivers are stopped forcefully.
- After the "BEFORE" message is processed successfully, the system switches to the new configuration.
- After the configuration changes, the Notifier sends an "AFTER" message to the callback table to notify drivers that the configuration transition is finished.
This example shows how to use the Notifier in the Power Manager application.
#include "fsl_notifier.h"
{
...
...
...
return ret;
}
{
...
...
...
}
...
...
...
...
...
int main(void)
{
user_callback_data_t callbackData0;
(void *)&callbackData0};
power_user_config_t vlprConfig;
power_user_config_t stopConfig;
vlprConfig.mode = kAPP_PowerModeVlpr;
vlprConfig.enableLowPowerWakeUpOnInterrupt = false;
stopConfig = vlprConfig;
stopConfig.mode = kAPP_PowerModeStop;
...
...
}
struct notifier_notification_block_t |
struct notifier_callback_config_t |
This structure holds the configuration of callbacks. Callbacks of this type are expected to be statically allocated. This structure contains the following application-defined data. callback - pointer to the callback function callbackType - specifies when the callback is called callbackData - pointer to the data passed to the callback.
void* notifier_callback_config_t::callbackData |
Notifier handle structure. Contains data necessary for the Notifier proper function. Stores references to registered configurations, callbacks, information about their numbers, user function, user data, and other internal data. NOTIFIER_CreateHandle() must be called to initialize this handle.
uint8_t notifier_handle_t::configsNumber |
uint8_t notifier_handle_t::callbacksNumber |
uint8_t notifier_handle_t::errorCallbackIndex |
uint8_t notifier_handle_t::currentConfigIndex |
void* notifier_handle_t::userData |
Reference of the user defined configuration is stored in an array; the notifier switches between these configurations based on this array.
Before and after this function execution, different notification is sent to registered callbacks. If this function returns any error code, NOTIFIER_SwitchConfig() exits.
- Parameters
-
targetConfig | target Configuration. |
userData | Refers to other specific data passed to user function. |
- Returns
- An error code or kStatus_Success.
Declaration of a callback. It is common for registered callbacks. Reference to function of this type is part of the notifier_callback_config_t callback configuration structure. Depending on callback type, function of this prototype is called (see NOTIFIER_SwitchConfig()) before configuration switch, after it or in both use cases to notify about the switch progress (see notifier_callback_type_t). When called, the type of the notification is passed as a parameter along with the reference to the target configuration structure (see notifier_notification_block_t) and any data passed during the callback registration. When notified before the configuration switch, depending on the configuration switch policy (see notifier_policy_t), the callback may deny the execution of the user function by returning an error code different than kStatus_Success (see NOTIFIER_SwitchConfig()).
- Parameters
-
notify | Notification block. |
data | Callback data. Refers to the data passed during callback registration. Intended to pass any driver or application data such as internal state information. |
- Returns
- An error code or kStatus_Success.
Used as return value of Notifier functions.
Enumerator |
---|
kStatus_NOTIFIER_ErrorNotificationBefore |
An error occurs during send "BEFORE" notification.
|
kStatus_NOTIFIER_ErrorNotificationAfter |
An error occurs during send "AFTER" notification.
|
Defines whether the user function execution is forced or not. For kNOTIFIER_PolicyForcible, the user function is executed regardless of the callback results, while kNOTIFIER_PolicyAgreement policy is used to exit NOTIFIER_SwitchConfig() when any of the callbacks returns error code. See also NOTIFIER_SwitchConfig() description.
Enumerator |
---|
kNOTIFIER_PolicyAgreement |
NOTIFIER_SwitchConfig() method is exited when any of the callbacks returns error code.
|
kNOTIFIER_PolicyForcible |
The user function is executed regardless of the results.
|
Used to notify registered callbacks
Enumerator |
---|
kNOTIFIER_NotifyRecover |
Notify IP to recover to previous work state.
|
kNOTIFIER_NotifyBefore |
Notify IP that configuration setting is going to change.
|
kNOTIFIER_NotifyAfter |
Notify IP that configuration setting has been changed.
|
Used in the callback configuration structure (notifier_callback_config_t) to specify when the registered callback is called during configuration switch initiated by the NOTIFIER_SwitchConfig(). Callback can be invoked in following situations.
- Before the configuration switch (Callback return value can affect NOTIFIER_SwitchConfig() execution. See the NOTIFIER_SwitchConfig() and notifier_policy_t documentation).
- After an unsuccessful attempt to switch configuration
- After a successful configuration switch
Enumerator |
---|
kNOTIFIER_CallbackBefore |
Callback handles BEFORE notification.
|
kNOTIFIER_CallbackAfter |
Callback handles AFTER notification.
|
kNOTIFIER_CallbackBeforeAfter |
Callback handles BEFORE and AFTER notification.
|
- Parameters
-
notifierHandle | A pointer to the notifier handle. |
configs | A pointer to an array with references to all configurations which is handled by the Notifier. |
configsNumber | Number of configurations. Size of the configuration array. |
callbacks | A pointer to an array of callback configurations. If there are no callbacks to register during Notifier initialization, use NULL value. |
callbacksNumber | Number of registered callbacks. Size of the callbacks array. |
userFunction | User function. |
userData | User data passed to user function. |
- Returns
- An error Code or kStatus_Success.
This function sets the system to the target configuration. Before transition, the Notifier sends notifications to all callbacks registered to the callback table. Callbacks are invoked in the following order: All registered callbacks are notified ordered by index in the callbacks array. The same order is used for before and after switch notifications. The notifications before the configuration switch can be used to obtain confirmation about the change from registered callbacks. If any registered callback denies the configuration change, further execution of this function depends on the notifier policy: the configuration change is either forced (kNOTIFIER_PolicyForcible) or exited (kNOTIFIER_PolicyAgreement). When configuration change is forced, the result of the before switch notifications are ignored. If an agreement is required, if any callback returns an error code, further notifications before switch notifications are cancelled and all already notified callbacks are re-invoked. The index of the callback which returned error code during pre-switch notifications is stored (any error codes during callbacks re-invocation are ignored) and NOTIFIER_GetErrorCallback() can be used to get it. Regardless of the policies, if any callback returns an error code, an error code indicating in which phase the error occurred is returned when NOTIFIER_SwitchConfig() exits.
- Parameters
-
notifierHandle | pointer to notifier handle |
configIndex | Index of the target configuration. |
policy | Transaction policy, kNOTIFIER_PolicyAgreement or kNOTIFIER_PolicyForcible. |
- Returns
- An error code or kStatus_Success.
This function returns an index of the last callback that failed during the configuration switch while the last NOTIFIER_SwitchConfig() was called. If the last NOTIFIER_SwitchConfig() call ended successfully value equal to callbacks number is returned. The returned value represents an index in the array of static call-backs.
- Parameters
-
notifierHandle | Pointer to the notifier handle |
- Returns
- Callback Index of the last failed callback or value equal to callbacks count.