# Utilities

## Assert

Abort the program is the expression evaluates to false.

Defines

- SNS\_VERBOSE\_ASSERT(value, msg, ...)

    - Abort the program if the expression evaluates to true.

Note

This macro should be used for debugging purposes only. It will print a message on stderr and then call abort().

- Parameters:

    - - **value** – **[in]** The boolean condition that must evaluate to false in order to trigger an error.
- **msg** – **[in]** A printf-style format string describing what went wrong.

## Attribute

Utility functions provided by Qualcomm for use by Sensors to handle and publish attributes. All utilities in this file can be used in island mode.

Defines

- SNS\_ATTR

    - 

- SNS\_DEFAULT\_MIN\_RATE

    - 

- SNS\_DEFAULT\_MAX\_RATE

    -

- struct sns\_sensor\_util\_attrib

    - Public Members

- struct [sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*sensor

    - Pointer to the sensor

- int32\_t attr\_id

    - Attribute ID.

- int32\_t attr\_value

    - Int Attribute value.

- float flt\_attr\_value

    - Float Attribute value.

- char attr\_string[32]

    - String Attribute value.

- struct sns\_sensor\_util\_generic\_attrib

    - Structure containing attributes and their associated compare function to be used in the generic\_lookup\_cb.

Public Members

- [sns\_sensor\_util\_attrib](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv422sns_sensor_util_attrib) \*attrib

    - Pointer to the attribute.

- sns\_attr\_comp\_fcn attr\_comp\_fcn

    - Compare function pointer.

Functions

- bool sns\_sensor\_util\_decode\_attr(pb\_istream\_t \*stream, const pb\_field\_t \*field, void \*\*arg)

    - Decode sensor attribute.

- Parameters:

    - - **stream** – **[inout]** The stream to decode attribute value from.
- **field** – **[in]** The format of the attribute value.
- **arg** – **[in]** The argument defined by caller.

- Returns:

    - bool

- True if decoded successfully.
- False if fail to decode.

- bool sns\_sensor\_util\_decode\_attr\_list(pb\_istream\_t \*stream, const pb\_field\_t \*field, void \*\*arg)

    - 

- bool sns\_pb\_encode\_attr\_cb(pb\_ostream\_t \*stream, const pb\_field\_t \*field, void \*const \*arg)

    - Encode an array of attribute values into an attribute. This function is intended to be used when publishing attributes.

See also

pb\_callback\_s::encode

- Parameters:

    - - **stream** – **[inout]** The stream to encode attribute value to.
- **field** – **[in]** The format of the attribute value.
- **arg** – **[in]** Type [pb\_buffer\_arg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structpb__buffer__arg) (.buf = array, .buf\_len = array length).

- Returns:

    - bool

- True if encoded successfully.
- False if fail to encode.

- void sns\_publish\_attribute(struct [sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*const sensor, uint32\_t attribute\_id, struct \_sns\_std\_attr\_value\_data const \*values, uint32\_t values\_len, bool completed)

    - Publish a simple attribute using the Attribute Service.

- Parameters:

    - - **sensor** – **[in]** Whose attributes to publish.
- **attribute\_id** – **[in]** ID corresponding to attribute.
- **values** – **[in]** Array of decoded attribute values.
- **values\_len** – **[in]** Number of entries in values array.
- **completed** – **[in]** Whether this is the last attribute in this publish set.

- Returns:

    - None

## Calibration

Calibration Utility functions for use by Sensor Developers.

Functions

- static inline [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv47vector3) sns\_apply\_calibration\_correction\_3([vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv47vector3) sample\_raw, [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv47vector3) bias, [matrix3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv47matrix3) compensation\_matrix)

    - Calculates calibrated value of a sample for tri-axial sensors based on following equation.

Sc = C \* (Sr - B) where,

- Sc = calibrated sample (3x1 vector (x, y, z)).
- Sr = raw sample (3x1 vector (x, y, z)).
- C = compensation matrix (3x3) B = bias (3x1 vector (x, y, z)).

- Parameters:

    - - **sample\_raw** – **[in]** [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structvector3) of the raw sample.
- **bias** – **[in]** [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structvector3) of the bias.
- **compensation\_matrix** – **[in]** [matrix3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structmatrix3) containing the compensation values.

- Returns:

    - - [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structvector3) - 3x1 column vector calibrated sample.

## Diagnostic Print

Print utility for diag messages.

Defines

- SNS\_PRINT\_MESSAGE\_MAX\_LEN

    - Define the Max string length.

Functions

- void sns\_diag\_print\_buf(uint32\_t ssid, [sns\_message\_priority](https://docs.qualcomm.com/doc/80-P9361-100/topic/service.html#_CPPv420sns_message_priority) prio, const char \*file, uint32\_t line, const char \*buf)

    - Print the buffer to diag.

Note

Please don’t use this function directly. Public API is provided by diag service using the sensor\_printf() and sensor\_inst\_printf() functions in sns\_diag\_service.h.

- Parameters:

    - - **ssid** – **[in]** Diag subsystem ID.
- **prio** – **[in]** Message priority.
- **file** – **[in]** File name string.
- **line** – **[in]** File line number.
- **buf** – **[in]** Buffer to print.

- Returns:

    - - None.

- void sns\_diag\_vprintf\_v2(struct [sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*sensor, struct [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*instance, struct sns\_msg\_const\_type const \*msg\_struct, uint32\_t nargs, va\_list args)

    - This function sends all messages to diag.

- Parameters:

    - - **sensor** – **[in]** Sensor Pointer (either this or instance may be NULL).
- **instance** – **[in]** Instance Pointer (either this or sensor may be NULL).
- **msg\_struct** – **[in]** Diag defined debug structure.
- **nargs** – **[in]** Number of arguments.
- **args** – **[in]** va\_list of arguments.

- Returns:

    - - None.

- void sns\_diag\_vprintf\_v2\_err\_fatal\_only(struct [sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*sensor, struct [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*instance, struct sns\_msg\_const\_type const \*msg\_struct, uint32\_t nargs, va\_list args)

    - This function sends only error and fatal messages to diag.

- Parameters:

    - - **sensor** – **[in]** Sensor Pointer (either this or instance may be NULL).
- **instance** – **[in]** Instance Pointer (either this or sensor may be NULL).
- **msg\_struct** – **[in]** Diag defined debug structure.
- **nargs** – **[in]** Number of arguments.
- **args** – **[in]** va\_list of arguments.

- Returns:

    - - None.

## Double Link List

A simple linked list implementation for use by the Sensors Framework. Iterators (and their associated API functions) are required for all access and modifications to the list. Any number of iterators may be simultaneously active for a list. Adding items to a list is guaranteed synchronous and thread-safe. Removing items from a list may block if the item is in-use by another iterator.

- struct sns\_list\_item

    - Public Members

- void \*item

    - Pointer to current selected item on the list.

- struct [sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_item) \*next

    - Pointer to subsequent item on the list; nullptr if the head.

- struct [sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_item) \*prev

    - Pointer to previous item on the list; nullptr if the tail.

- struct [sns\_list](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv48sns_list) \*list

    - Reference to the containing list; nullptr if not on any list.

- struct sns\_list

    - Public Members

- [sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_item) item

    - Contains head (item::next) and tail (item::prev) of the list; item::item always NULL.

- uint32\_t cnt

    -

- struct sns\_list\_iter

    - An accessor class for the List. All mutator and accessor actions must be done through the Iterator interface.

Public Members

- struct [sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_item) \*list\_entry

    - Entry is used by the list to manage this iterator.

- struct [sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_item) \*curr

    - Current Entry of this iterator. May be NULL.

- struct [sns\_list](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv48sns_list) \*list

    - List over which this iterates.

Functions

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_list\_init(struct [sns\_list](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv48sns_list) \*list)

    - Initialize a list to its empty state.

- Parameters:

    - **list** – **[in]** This List.

- Returns:

    - - sns\_rc SNS\_RC\_SUCCESS

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_list\_item\_init([sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_item) \*item, void \*data)

    - Initialize a list item.

- Parameters:

    - - **item** – **[in]** Item in this List.
- **data** – **[in]** Item initialization data.

- Returns:

    - - sns\_rc SNS\_RC\_SUCCESS.
- Any other value Failure.

- void sns\_list\_item\_remove([sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_item) \*item)

    - Remove an item from a list.

- Parameters:

    - **item** – **[in]** List item to be removed if present on a list.

- Returns:

    - - None.

- void \*sns\_list\_item\_get\_data(struct [sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_item) \*item)

    - Return a pointer to the data associated with this list item.

- Parameters:

    - **item** – **[in]** Item in this List.

- Returns:

    - - void \*ptr - Data associated with this List Item.

- bool sns\_list\_item\_present(struct [sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_item) const \*item)

    - Check whether this item is presently on any list.

- Parameters:

    - **item** – **[in]** Item whose list presence to check.

- Returns:

    - - bool - True if on any list; false otherwise.

- [sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_item) \*sns\_list\_iter\_init([sns\_list\_iter](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_iter) \*iter, struct [sns\_list](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv48sns_list) \*list, bool head)

    - Create an iterator for this List.

- Parameters:

    - - **iter** – **[in]** Iterator for this list.
- **list** – **[in]** This list.
- **head** – **[in]** Initialize iterator to first item in the list; otherwise last.

- Returns:

    - - [sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structsns__list__item) \*ptr - First item if head is True. Last Item if head is false.
- NULL if list is empty.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_list\_iter\_insert([sns\_list\_iter](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_iter) \*iter, struct [sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_item) \*item, bool after)

    - Add this item to the specified List; advance iterator only if the List was previously empty.

- Parameters:

    - - **iter** – **[in]** Iterator for this list.
- **item** – **[in]** Item to be inserted in this list.
- **after** – **[in]** If true insert after current item, false enter before.

- Returns:

    - - SNS\_RC\_SUCCESS - Added item to list sucessfully.
- SNS\_RC\_FAILED - Item is already present in list.

- [sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_item) \*sns\_list\_iter\_remove([sns\_list\_iter](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_iter) \*iter)

    - Remove the current Entry. Advance iterator to next; if next is NULL, advance to prev.

- Parameters:

    - **iter** – **[in]** Iterator for this list.

- Returns:

    - - [sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structsns__list__item) \*ptr - Item removed from this list.

- uint32\_t sns\_list\_iter\_len([sns\_list\_iter](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_iter) \*iter)

    - Return the current length of the associated list.

- Parameters:

    - **iter** – **[in]** Iterator for this list.

- Returns:

    - - uint32\_t - Length of this list.

- struct [sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_item) \*sns\_list\_iter\_curr([sns\_list\_iter](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_iter) \*iter)

    - Return the current list\_item. Will be NULL if current item is invalid. E.g. If the list is empty, or has iterated past the head/tail.

- Parameters:

    - **iter** – **[in]** Iterator for this list.

- Returns:

    - - struct [sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structsns__list__item) \*ptr - Current item in this list.

- struct [sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_item) \*sns\_list\_iter\_advance([sns\_list\_iter](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_iter) \*iter)

    - Advance the iterator to the next item in the list.

- Parameters:

    - **iter** – **[in]** Iterator for this list.

- Returns:

    - - struct [sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structsns__list__item) \*ptr - Next item in this list.

- struct [sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_item) \*sns\_list\_iter\_return([sns\_list\_iter](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_iter) \*iter)

    - Return the iterator to the previous item in the list.

- Parameters:

    - **iter** – **[in]** Iterator for this list.

- Returns:

    - Previous item in this list.

- struct [sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structsns__list__item) \*ptr - Previous item in this list.

- void \*sns\_list\_iter\_get\_curr\_data([sns\_list\_iter](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_iter) \*iter)

    - Return a pointer to the data associated with the current list item. This is equivalent to the operation: sns\_list\_item\_get\_data(sns\_list\_iter\_curr(iter)).

- Parameters:

    - **iter** – **[in]** Iterator for this list.

- Returns:

    - - void \*ptr - Data pointer to the current item in this list.

## Dynamic Loader

Functions used by dynamically loaded sensors.

Defines

- SNS\_DL\_MAX\_REMOTE\_CLIENTS

    - Maximum number of clients that can be connected to the dynamic loader.

- struct sns\_note\_type

    - Definition for note\_type to include version note in shared object.

Public Members

- int32\_t sizename

    - Size of the NOTE section.

- int32\_t sizedesc

    - Size of the descriptor(unused).

- int32\_t type

    - Type of section(unused).

- char name[100]

    - Name of NOTE section(version of shared object).

Functions

- void \*sns\_pram\_acquire\_partition(char \*name, uint32\_t \*size)

    - Exported wrapper function around pram\_acquire\_partition().

- Parameters:

    - - **name** – **[in]** PRAM name.
- **size** – **[in]** PRAM size.

- Returns:

    - - None.

- bool sns\_load\_shared\_object([sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*const this)

    - Load shared object in sns\_dllib\_list.

- Parameters:

    - **this** – **[in]** Sensor pointer.

- Returns:

    - - None.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_dynamic\_loader\_init(void)

    - Initializes dynamic loader.

- Returns:

    - - SNS\_RC\_SUCCESS Success.
- SNS\_RC\_FAILED Failed to initialize.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_dl\_add\_sensor\_library(uint64\_t h, const struct [sns\_dl\_entry](https://docs.qualcomm.com/doc/80-P9361-100/topic/skel.html#_CPPv412sns_dl_entry) \*dl\_entry)

    - Adds the sensor library specified in dl\_entry.

- Parameters:

    - - **h** – **[in]** Remote handle.
- **dl\_entry** – **[in]** dl entry to add.

- Returns:

    - - SNS\_RC\_SUCCESS Success.
- SNS\_RC\_FAILED Failed to add.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_dl\_add\_generic\_library(uint64\_t h, const struct [load\_library\_config](https://docs.qualcomm.com/doc/80-P9361-100/topic/skel.html#_CPPv419load_library_config) \*load\_config)

    - Adds the generic library specified in load\_config.

- Parameters:

    - - **h** – **[in]** Remote handle.
- **load\_config** – **[in]** Library to add.

- Returns:

    - - SNS\_RC\_SUCCESS Success.
- SNS\_RC\_FAILED Failed to add.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_dl\_remove\_library(uint64\_t h, const struct [sns\_dl\_handle](https://docs.qualcomm.com/doc/80-P9361-100/topic/skel.html#_CPPv413sns_dl_handle) \*dl\_handle)

    - Removes the library specified in dl\_handle.

- Parameters:

    - - **h** – **[in]** Remote Handle.
- **dl\_handle** – **[in]** dl handle.

- Returns:

    - - SNS\_RC\_SUCCESS Success.
- SNS\_RC\_FAILED Failed to remove.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_dl\_get\_free\_client\_handle(uint64\_t \*active\_handles, uint64\_t \*h)

    - Returns a free handle, one not found in active handles.

- Parameters:

    - - **active\_handles** – **[in]** active remote Handles.
- **h** – **[out]** dl handle.

- Returns:

    - - SNS\_RC\_SUCCESS Success.
- SNS\_RC\_NOT\_AVAILABLE Failed to find handle.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_dl\_validate\_client\_handle(uint64\_t handle, uint64\_t \*active\_handles, bool release)

    - Validates whether the given handle is one of the active handles, and optionally release it to free handle pool.

- Parameters:

    - - **handle** – **[in]** Remote Handles.
- **active\_handles** – **[in]** Active remote handle.
- **release** – **[in]** Release handle bool.

- Returns:

    - - SNS\_RC\_SUCCESS Success.
- SNS\_RC\_INVALID\_VALUE Failed to find handle.

- void sns\_dynamic\_sensor\_update\_lib\_status(void const \*library, bool is\_available)

    - Update dynamic library status.

- Parameters:

    - - **library** – **[in]** Pointer to the dynamically loaded library.
- **is\_available** – **[in]** True: if library sensors are available to FW.

- Returns:

    - - None.

- void sns\_dynl\_heap\_mgr\_init(void)

    - Intialize island dynamic heap.

- Returns:

    - - None.

## Island

Island control for Sensors.

Defines

- SNS\_ISLAND\_EXIT()

    - Exit island mode.

Note

The system will enter island mode at a later time after current thread has returned to IDLE

- SNS\_SECTION(name)

    - [SNS\_SECTION( name )](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#sns__island_8h_1a13799b29555fa606f5c847a179d19a06)

- This macro can be used to place code and variables into a section called name.
- To move code or variables into island mode on supported targets, first tag the item using this macro, next use the same sections in addIslandLibrary() method in the scons file to inform the linker that a section must be made available in island memory.

Functions

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_island\_exit\_internal(void)

    - Internal call to exit island mode.

Note

Do not call this function directly. Use the [SNS\_ISLAND\_EXIT()](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#sns__island_8h_1abef2428268e7c5a1e7901b849fcba5ac) macro instead.

- Returns:

    - - SNS\_RC\_SUCCESS: Island exit was successful.
- SNS\_RC\_NOT\_AVAILABLE: Island exit transition did not happen. This could be due to:

    - Island mode not supported on target/disabled.
    - System is not in island mode when exit was requested.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_island\_log\_trace(uint64\_t user\_defined\_id)

    - Generates a log packet of the sns\_island\_trace\_log type and commits it.

- Parameters:

    - **user\_defined\_id** – **[in]** The value to be added to the cookie field in the log packet.

- Returns:

    - - SNS\_RC\_SUCCESS: Log packet operation was successful.
- SNS\_RC\_NOT\_SUPPORTED: Log packet not supported.

- [sns\_service](https://docs.qualcomm.com/doc/80-P9361-100/topic/service.html#_CPPv411sns_service) \*sns\_island\_service\_init(void)

    - Initialize the island service.

- Returns:

    - - [sns\_service](https://docs.qualcomm.com/doc/80-P9361-100/topic/service.html#structsns__service): Pointer to island service.

Island control for Sensors.

Defines

- SNS\_USLEEP\_ISLAND\_CB\_ENTER\_LATENCY\_TICKS

    - Time in ticks taken to execute the CB when entering uImage.

- SNS\_USLEEP\_ISLAND\_CB\_EXIT\_LATENCY\_TICKS

    - Time in ticks taken to execute the CB when exiting uImage.

Enums

- enum qsh\_island\_vote

    - Island mode enable/disable request values.

*Values:*

- enumerator QSH\_ISLAND\_DISABLE

    - Island mode disable request.

- enumerator QSH\_ISLAND\_ENABLE

    - Island mode enable request.

- enumerator QSH\_ISLAND\_UNKNOWN

    - Uninitialized state.

- enum sns\_ssc\_island\_vote

    - Island mode enable/disable request values.

*Values:*

- enumerator SNS\_ISLAND\_DISABLE

    - Island mode disable request.

- enumerator SNS\_ISLAND\_ENABLE

    - Island mode enable request

- enumerator SNS\_ISLAND\_UNKNOWN

    - Uninitialized state

- enum sns\_island\_state

    - Island mode states.

*Values:*

- enumerator SNS\_ISLAND\_STATE\_ISLAND\_DISABLED

    - Island mode is disabled. It might be enabled later

- enumerator SNS\_ISLAND\_STATE\_IN\_ISLAND

    - Island mode is available.

- enumerator SNS\_ISLAND\_STATE\_NOT\_IN\_ISLAND

    - Island mode is not available and will not be available in the future.

- struct sns\_island\_config

    - Island configuration.

Public Members

- bool enable\_island

    - Island enable flag

- bool enable\_island\_debug

    - Island debug enable flag

- bool enable\_island\_test

    - Island test enable flag

Functions

- \_\_attribute\_\_((section(".text.sns"))) static inline bool sns\_island\_is\_island\_ptr(intptr\_t ptr)

    - Checks if a pointer can be safely dereferenced when in island mode. Consider NULL to be a valid island pointer.

- Parameters:

    - **ptr** – **[in]** Pointer to be checked.

- Returns:

    - - True: Pointer can be safely dereferenced when in island mode.
- False: Otherwise.

- bool sns\_is\_in\_pram\_region(uint32\_t ptr)

    - This function checks whether an address falls inside PRAM region.

- Parameters:

    - **ptr** – **[in]** Address which needs to be checked.

- Returns:

    - - True: Address falls in PRAM.
- False: Otherwise

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_island\_init(void)

    - The API to initialize sns\_island utility. This API should be called by framework only once at the bootup.

Note

SNS island mode is disabled by default at the end of sns\_island\_init.

- Returns:

    - - SNS\_RC\_SUCCESS: Init was successful.
- SNS\_RC\_NOT\_SUPPORTED: Island mode not supported.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) ssc\_island\_memory\_vote([sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*const sensor, bool enable)

    - Sensor Island memory pool vote callback function. This API votes for ssc memory pool if atleast one island sensor is active.This API removes ssc memory pool vote if there are no island sensors active.

- Parameters:

    - - **sensor** – **[in]** Sensor pointer.
- **enable** – **[in]** True: Add vote for sensor island memory pool; False: Remove vote for sensor island memory pool.

- Returns:

    - - SNS\_RC\_SUCCESS: No error occurred; success.
- SNS\_RC\_FAILED: Internal error occurred.
- SNS\_RC\_NOT\_SUPPORTED: This API is not supported or is not implemented.

- bool is\_ssc\_island\_usecase\_active(void)

    - The API to query if ssc island use case is active or not.

- Returns:

    - - True: If ssc island use case is active.
- False: Otherwise.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) qsh\_island\_init(void)

    - The API to initialize qsh\_island utility. This API should be called by framework only once at the bootup.

- Returns:

    - - SNS\_RC\_SUCCESS: Init was successful.
- SNS\_RC\_NOT\_SUPPORTED: Island mode not supported.

- bool qsh\_island\_allow (\_Atomic unsigned int \*active\_threads\_count)

    - The API to Vote to allow island through qsh node. This API will vote to allow ALL islands.

- Parameters:

    - **active\_threads\_count** – **[in]** Atomic osa active threads counter.

- Returns:

    - - True: If island mode was allowed.
- False: Otherwise.

- sns\_island\_client\_handle sns\_island\_aggregator\_register\_client(const char \*client\_name)

    - The API to Register a client for the island vote aggregator.

- Parameters:

    - **client\_name** – **[in]** Name of the client that is registering.

- Returns:

    - - client\_handle: Client handle used to block or unblock island mode.

- void sns\_island\_aggregator\_deregister\_client(sns\_island\_client\_handle client\_handle)

    - The API to Deregister a client from the island vote aggregator.

- Parameters:

    - **client\_handle** – **[in]** Client handle to be deregistered.

- Returns:

    - None.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_island\_block(sns\_island\_client\_handle client\_handle)

    - The API to Exit island mode and block re-entry to island mode.

- Parameters:

    - **client\_handle** – **[in]** client\_handle returned by sns\_island\_aggregator\_register\_client.

- Returns:

    - - SNS\_RC\_SUCCESS: Operation successful.
- SNS\_RC\_INVALID\_TYPE: Client\_handle parameter is bad.
- SNS\_RC\_NOT\_SUPPORTED: Island mode is not supported.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_island\_unblock(sns\_island\_client\_handle client\_handle)

    - The API to unblock re-entry to island mode.

- Parameters:

    - **client\_handle** – **[in]** Handle returned in registration.

- Returns:

    - - SNS\_RC\_SUCCESS: Operation successful.
- SNS\_RC\_INVALID\_TYPE: Client\_handle parameter is bad.
- SNS\_RC\_NOT\_SUPPORTED: Island mode is not supported.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_island\_generate\_and\_commit\_state\_log(uint64\_t req\_id)

    - The API to generates and commits an sns\_island\_state\_log log packet.

- Parameters:

    - **req\_id** – **[in]** Request ID to be used in log packet.

- Returns:

    - - SNS\_RC\_SUCCESS : Log packet operation was successful.
- SNS\_RC\_NOT\_SUPPORTED : Island mode not supported.

- void sns\_island\_configure\_island\_transition\_debug(bool enable\_island\_debug)

    - The API to Configure island transition debug structure based on registry setting.

- Parameters:

    - **enable\_island\_debug** – **[in]** Enable or disable island transition debug

- Returns:

    - None.

- void sns\_island\_configure\_island\_test\_debug(bool enable\_island\_test)

    - The API to get the current island mode state.

- Parameters:

    - **enable\_island\_test** – **[in]** Enable or disable island test validation.

- Returns:

    - None.

- [sns\_island\_state](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv416sns_island_state) sns\_island\_get\_island\_state(void)

    - The API to configure island test debug structure based on registry setting.

- Returns:

    - - SNS\_ISLAND\_STATE\_IN\_ISLAND: When system is in island mode.
- SNS\_ISLAND\_STATE\_NOT\_IN\_ISLAND: When system is not in island mode.
- SNS\_ISLAND\_STATE\_ISLAND\_DISABLED: When island mode is disabled.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) qsh\_island\_memory\_vote([sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*const sensor, bool enable)

    - Qsh sensor Island memory pool vote function.This API votes for QSH memory pool if atleast one island sensor is active.This API removes QSH memory pool vote if there are no island sensors active.

- Parameters:

    - - **sensor** – **[in]** Sensor pointer.
- **enable** – **[in]** True: Add vote for sensor island memory pool; False: Remove vote for sensor island memory pool.

- Returns:

    - - SNS\_RC\_SUCCESS : No error occurred; success.
- SNS\_RC\_FAILED : Internal error occurred.
- SNS\_RC\_NOT\_SUPPORTED: This API is not supported or is not implemented.

- void qsh\_island\_transition\_logging(bool force)

    - This function will loop over the island\_transition\_debug structure and publish the logs.

- Parameters:

    - **force** – **[in]** Force logging even if it’s already logged.

- Returns:

    - None.

## Logging

Debug service wrapper for sensors framework.

Defines

- SNS\_PACK(x)

    - Macro to packed tightly together members without any padding bytes, which can reduce the overall size of the structure.

Functions

- typedef SNS\_PACK (struct)

    - Logging header type.

- bool sns\_log\_status(sns\_log\_code\_type code)

    - This function returns whether a particular code is enabled for logging.

- Parameters:

    - **code** – **[in]** Specifies the code.

- Returns:

    - -True: If log mask is enabled. -False: If log mask is disabled.

- void sns\_log\_set\_length(void \*ptr, unsigned int length)

    - This function sets the length field in the given log record.

Note

‘’ptr’ must not point to a log entry that was allocated by log\_alloc(). Use with caution. It is possible to corrupt a log record using this command. It is intended for use only with accumulated log records, not buffers returned by log\_alloc().

- Parameters:

    - - **ptr** – **[in]** Pointer points to the log whose length field is being set.
- **length** – Length to be set in the log header.

- Returns:

    - - None.

- void sns\_log\_set\_code(void \*ptr, sns\_log\_code\_type code)

    - This function sets the log code.

- Parameters:

    - - **ptr** – **[in]** Pointer points to the log whose log code field is being set.
- **code** – **[in]** Specifies the code.

- Returns:

    - - None.

- void sns\_log\_set\_timestamp(void \*ptr)

    - This function captures the system time and stores it in the given log record.

- Parameters:

    - **ptr** – **[in]** Pointer points to the log whose timestamp field is being set.

- Returns:

    - - None.

- bool sns\_log\_submit(void \*ptr)

    - This function is called to log an accumulated log entry. If logging is enabled for the entry by the external device, then the entry is copied into the diag allocation manager and commited immediately.

Note

Header contents must be assigned by the caller prior to calling this function. Therefore, sns\_log\_set code(), [sns\_log\_set\_length()](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#sns__log_8h_1a418c13adba04e25504069048f2f37290), and [sns\_log\_set\_timestamp()](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#sns__log_8h_1a7a2da2ac15058b33152566b0c6be0044) must be used prior to this call.

- Parameters:

    - **ptr** – **[in]** Pointer points to the log which is to be submitted.

- Returns:

    - - True: If log is submitted successfully into diag buffers.
- False: If there is no space left in the buffers.

## Math

### Checksum

Contains a wrapper for crc calculation function from core services.

Functions

- uint32\_t sns\_crc\_32\_calc(uint8\_t \*data, size\_t length)

    - CRC (Cyclic Redundancy Check) calculation function interface.

- Parameters:

    - - **data** – **[in]** Pointer to input data.
- **length** – **[in]** Length of input data in bytes.

- Returns:

    - - uint32\_t: Calculated CRC (Cyclic Redundancy Check) value.

### Circular Buffer

Circular buffer utility header file.

Defines

- BUF\_INDEX(index, buf\_size)

    - Define macro to calculate index into circular buffer.This macro calculates the index into the circular buffer based on the current index and the size of the buffer.

- struct buffer\_type

    - Circular buffer data structure.

Public Members

- [matrix\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411matrix_type) data

    - Matrix data for storing the values.

- int32\_t end

    - End index of the circular buffer.

- int32\_t window\_size

    - The number of samples to store in the buffer.

- int32\_t count

    - The number of samples currently stored in the buffer.

- struct buffer\_type\_64

    - Circular buffer data structure for 64-bit data.

Public Members

- [matrix\_type\_64](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv414matrix_type_64) data

    - Matrix data uint64 for storing the values.

- int32\_t end

    - End index of the circular buffer.

- int32\_t window\_size

    - The number of samples to store in the buffer.

- int32\_t count

    - The number of samples currently stored in the buffer.

Functions

- int32\_t buffer\_mem\_req(int32\_t window\_size, int32\_t cols)

    - Size of memory for the buffer. The buffer may contain more data than just the window size and columns.

Note

Not that it does, but the user doesn’t need to know that

- Parameters:

    - - **window\_size** – **[in]** The number of samples to store in the buffer.
- **cols** – **[in]** The number of columns in each sample.

- Returns:

    - - int32\_t: Size in bytes required to allocate memory.

- void buffer\_reset([buffer\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411buffer_type) \*buffer, int32\_t window\_size, int32\_t cols, void \*mem)

    - Initialize circular buffer structure.

- Parameters:

    - - **buffer** – **[inout]** Pointer to the circular buffer structure.
- **window\_size** – **[in]** The number of samples to store in the buffer.
- **cols** – **[in]** The number of columns in each sample.
- **mem** – **[in]** Memory address where the circular buffer resides.

- Returns:

    - - None.

- void buffer\_insert([buffer\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411buffer_type) \*buffer, int32\_t const \*new\_data)

    - Inserts the data at the end of index in circular buffer.

- Parameters:

    - - **buffer** – **[inout]** Pointer to the circular buffer structure.
- **new\_data** – **[in]** Data to insert into the circular buffer.

- Returns:

    - - None.

- int32\_t buffer\_mem\_req\_64(int32\_t window\_size, int32\_t cols)

    - Calculates size of memory for window size and columns.

- Parameters:

    - - **window\_size** – **[in]** The number of samples to store in the buffer.
- **cols** – **[in]** The number of columns in each sample.

- Returns:

    - - int32\_t: Size in bytes required to allocate memory.

- void buffer\_reset\_64([buffer\_type\_64](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv414buffer_type_64) \*buffer, int32\_t window\_size, int32\_t cols, void \*mem)

    - Initialize circular buffer structure.

- Parameters:

    - - **buffer** – **[inout]** Pointer to the circular buffer structure.
- **window\_size** – **[in]** The number of samples to store in the buffer.
- **cols** – **[in]** The number of columns in each sample.
- **mem** – **[in]** Memory address where the circular buffer resides.

- Returns:

    - - None.

- void buffer\_insert\_64([buffer\_type\_64](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv414buffer_type_64) \*buffer, uint64\_t const \*new\_data)

    - Inserts the data at the end of index in circular buffer.

- Parameters:

    - - **buffer** – **[inout]** Pointer to the circular buffer structure.
- **new\_data** – **[in]** Data to insert into the circular buffer.

- Returns:

    - - None.

- void buffer\_sprd([buffer\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411buffer_type) \*buffer, int32\_t \*sprd\_data)

    - Calculate the maximum peak to minimum peak spread of the buffer.

- Parameters:

    - - **buffer** – **[in]** Input buffer.
- **sprd\_data** – **[out]** Pointer to the spread value.

- Returns:

    - - None.

- void buffer\_sum([buffer\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411buffer_type) \*buffer, int32\_t \*sum\_data)

    - Calculate sum of the buffer provided.

- Parameters:

    - - **buffer** – **[in]** Input buffer
- **sum\_data** – **[out]** Pointer to output variable containing summation.

- Returns:

    - - None.

- void buffer\_sum\_sq([buffer\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411buffer_type) \*buffer, int32\_t \*sum\_sq\_data, int32\_t q\_format)

    - Calculate sum of the buffer provided.

- Parameters:

    - - **buffer** – **[in]** Input buffer.
- **sum\_sq\_data** – **[out]** Sum of square of input buffer.
- **q\_format** – **[in]** FX\_QFACTOR or SPI\_QFACTOR.

- Returns:

    - - None.

- int32\_t buffer\_full([buffer\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411buffer_type) \*buffer)

    - Check if the buffer is full.

- Parameters:

    - **buffer** – **[in]** Input buffer.

- Returns:

    - - True: If buffer is full.
- False: Otherwise.

- uint8\_t buffer\_num\_samples([buffer\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411buffer_type) \*buffer)

    - Function to get number of samples in the buffer.

- Parameters:

    - **buffer** – **[in]** Input buffer.

- Returns:

    - - uint8\_t: Number of samples in the buffer.

- void buffer\_sum\_and\_sum\_sq([buffer\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411buffer_type) \*buffer, int32\_t \*sum\_data, int32\_t \*sum\_sq\_data, int32\_t q\_format)

    - Calculate sum and sum of square root of the buffer provided.

- Parameters:

    - - **buffer** – **[in]** Input buffer.
- **sum\_sq\_data** – **[out]** Sum of square of input buffer.
- **sum\_data** – **[out]** Sum of input buffer.
- **q\_format** – **[in]** FX\_QFACTOR or SPI\_QFACTOR..

- Returns:

    - - None.

- int32\_t buffer\_size(int32\_t window\_size)

    - Round up to the nearest power of 2.

Note

we need at least one empty spot in the buffer.

- Parameters:

    - **window\_size** – **[in]** Value to round up.

- Returns:

    - - int32\_t: Rounded up value.

- int32\_t buffer\_partial\_compute\_num\_data\_rows([buffer\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411buffer_type) const \*buffer, int32\_t start\_index, int32\_t end\_index)

    - Get number of data row in the buffer from a given starting index.

- Parameters:

    - - **buffer** – **[in]** Input buffer.
- **start\_index** – **[in]** Start Index.
- **end\_index** – **[in]** End Index

- Returns:

    - -int32\_t: Number of rows in the buffer.

- void buffer\_partial\_sum([buffer\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411buffer_type) const \*buffer, int32\_t start\_index, int32\_t end\_index, int32\_t \*sum\_data)

    - Get partial sum of the buffer from start index to end index.

- Parameters:

    - - **buffer** – **[in]** Input buffer.
- **start\_index** – **[in]** Start Index.
- **end\_index** – **[in]** End Index.
- **sum\_data** – **[out]** Output pointer to hold sum of the buffer.

- Returns:

    - - None.

- void buffer\_partial\_sum\_sq([buffer\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411buffer_type) const \*buffer, int32\_t start\_index, int32\_t end\_index, int32\_t \*sum\_sq\_data)

    - Get partial sum of square of the buffer from start index to end index.

- Parameters:

    - - **buffer** – **[in]** Input buffer.
- **start\_index** – **[in]** Start Index.
- **end\_index** – **[in]** End Index.
- **sum\_sq\_data** – **[out]** Output pointer to hold sum of square of the buffer.

- Returns:

    - - None.

- void buffer\_partial\_min\_max\_sprd\_one\_column([buffer\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411buffer_type) const \*buffer, int32\_t start\_index, int32\_t stop\_index, int32\_t col, int32\_t \*min\_data, int32\_t \*max\_data, int32\_t \*sprd\_data)

    - Get partial max of the buffer from start index to end index.

- Parameters:

    - - **buffer** – **[in]** Input buffer.
- **start\_index** – **[in]** Start index.
- **stop\_index** – **[in]** Stop index.
- **col** – **[in]** Column index.
- **max\_data** – **[out]** Output pointer to hold max of the buffer.
- **min\_data** – **[out]** Output pointer to hold min of the buffer.
- **sprd\_data** – **[out]** Output pointer to hold spread of the buffer.

- Returns:

    - - None.

### Common

Mathematical Utility functions for use by Sensor Developers.

Defines

- G

    - Value for gravity (m/s^2).

- PI

    - Value for PI.

- SNS\_MAX(a, b)

    - SNS\_MAX finds and returns the max of two values provided.

- Parameters:

    - - **a** – **[in]** First input of comparison.
- **b** – **[in]** Second input of comparison.

- SNS\_MIN(a, b)

    - SNS\_MIN finds and returns the min of two values provided.

- Parameters:

    - - **a** – **[in]** First input of comparison.
- **b** – **[in]** Second input of comparison.

- struct vector3

    - 

- struct matrix3

    - 

Functions

- static inline [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv47vector3) make\_vector3(float x, float y, float z)

    - Creates [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structvector3) from three numbers.

- Parameters:

    - - **x** – **[in]** First number.
- **y** – **[in]** Second number.
- **z** – **[in]** Third number.

- Returns:

    - - [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structvector3) Created by input three parameters.

- static inline [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv47vector3) make\_vector3\_from\_array(const float \*data)

    - Creates [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structvector3) from an array.

- Parameters:

    - **data** – **[in]** Input array pointer with three numbers that need to be converted into [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structvector3).

- Returns:

    - - [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structvector3) Created by input array.

- static inline [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv47vector3) vector3\_add([vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv47vector3) a, [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv47vector3) b)

    - Adds one 3D vector to another.

- Parameters:

    - - **a** – **[in]** First [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structvector3) that need to be added.
- **b** – **[in]** Second [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structvector3) that need to be added.

- Returns:

    - - [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structvector3) Result of two [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structvector3) addition (a + b).

- static inline [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv47vector3) vector3\_sub([vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv47vector3) a, [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv47vector3) b)

    - Subtracts one 3D vector from another.

- Parameters:

    - - **a** – **[in]** Vector3 from which another [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structvector3) gets subtracted.
- **b** – **[in]** Vector3 that get subtracted.

- Returns:

    - - [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structvector3) Result of two [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structvector3) subtraction (a - b).

- static inline [matrix3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv47matrix3) matrix3\_multiply([matrix3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv47matrix3) a, [matrix3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv47matrix3) b)

    - Multiply two 3x3 matrices.

- Parameters:

    - - **a** – **[in]** First matrix.
- **b** – **[in]** Second matrix.

- Returns:

    - - [matrix3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structmatrix3) Result of matric multiplication.

- static inline [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv47vector3) matrix3\_mul\_vector3([matrix3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv47matrix3) m, [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv47vector3) v)

    - Muliply a 3x3 matrix to a 3x1 vector.

- Parameters:

    - - **m** – **[in]** 3x3 Matrix.
- **v** – **[in]** 3x1 vector.

- Returns:

    - - [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structvector3) Result of 3x3 Matrix multiplication with 3x1 vector.

### Fast Fourier Transform (FFT)

Functions

- void sfpFFT(cfloat \*Input, int points, cfloat \*twiddles, cfloat \*Output)

    - Floating-point implementation of radix-4 FFT.

- Parameters:

    - - **Input** – **[in]** Pointer to input array.
- **points** – **[in]** N point FFT twiddle.
- **twiddles** – **[inout]** Pointer to twiddle factor array.
- **Output** – **[inout]** Pointer to output array.

- Returns:

    - - None.

- void gentwiddle(cfloat \*twiddle, uint32\_t NP, uint32\_t log2NP, cfloat \*x, cfloat \*y)

    - Generate interleave & bit-reverse order twiddle factor array for radix-4 floating-point implementation of FFT.

- Parameters:

    - - **twiddle** – **[out]** Pointer to twiddle factor array.
- **NP** – **[inout]** N point FFT twiddle.
- **log2NP** – **[inout]** LOG2( NP ).
- **x** – **[inout]** Pointer to scratch array of size NP/2.
- **y** – **[inout]** Pointer to scratch array of size NP/4.

- Returns:

    - - None.

### Fixed Point

Fixed point utility header file.

Defines

- FX\_ABS(x)

    - compute the absolute value of a 32-bit integer

- FX\_MIN(x, y)

    - compute the minimum of two values

- FX\_MAX(x, y)

    - compute the maximum of two values

- FX\_BOUND(y, x, z)

    - bound a value between two limits

- FX\_NEG(x, flag)

    - negate a value based on a flag

- FX\_ONE(q)

    - compute the fixed-point representation of 1

- FX\_HALF(q)

    - compute the fixed-point representation of 0.5

- FX\_SIGN32(x)

    - extract the sign bit of a 32-bit integer

- FX\_FLTTOFIX(f, q)

    - convert a floating-point number to fixed-point

- FX\_FIXTOFLT(i, q)

    - convert a fixed-point number to double

- FX\_FIXTOFLT\_SP(i, q)

    - convert a fixed-point number to float (single precision)

Single Precision

- FX\_FLOOR(a, q)

    - compute the floor of a fixed-point number

- FX\_ROUND(a, q)

    - round a fixed-point number

- FX\_CEIL(a, q)

    - compute the ceiling of a fixed-point number

- FX\_CONV(a, q1, q2)

    - convert a fixed-point number from one format to another

- FX\_ADD(a, b, q1, q2, q3)

    - add two fixed-point numbers

- FX\_SUB(a, b, q1, q2, q3)

    - subtract two fixed-point numbers

- FX\_MUL(a, b, q1, q2, q3)

    - multiply two fixed-point numbers

- FX\_DIV(a, b, q1, q2, q3)

    - divide two fixed-point numbers

- FX\_FLTTOFIX\_Q16(d)

    - a floating-point number to Q16 fixed-point

- FX\_FIXTOFLT\_Q16(a)

    - convert a Q16 fixed-point number to double

- FX\_FIXTOFLT\_Q16\_SP(a)

    - convert a Q16 fixed-point number to float (single precision)

- FX\_FLOOR\_Q16(a)

    - compute the floor of a Q16 fixed-point number

- FX\_ROUND\_Q16(a)

    - round a Q16 fixed-point number

- FX\_CEIL\_Q16(a)

    - compute the ceiling of a Q16 fixed-point number

- FX\_CONV\_Q16(a, q1)

    - convert a fixed-point number to Q16 format

- FX\_MUL\_Q16(a, b)

    - multiply two Q16 fixed-point numbers

- FX\_DIV\_Q16(a, b)

    - divide two Q16 fixed-point numbers

- PI

    - 

- FX\_G\_Q16

    -

Functions

- uint32\_t sqrtFxQ16(uint32\_t val)

    - Computes the square root.

- Parameters:

    - **val** – **[in]** Q16 value of which to compute the square root.

- Returns:

    - - uint32\_t: Q16 representation of the square root.

- void sinCosTanFxQ16(int32\_t theta, int32\_t \*sin, int32\_t \*cos, int32\_t \*tan)

    - Computes sine, cosine and tangent for an angle in radians.

- Parameters:

    - - **theta** – **[in]** Angle in radians.
- **sin** – **[out]** Sin output.
- **cos** – **[out]** Cos output.
- **tan** – **[out]** Tan output.

- Returns:

    - - None.

- int32\_t arcTan2FxQ16(int32\_t num, int32\_t den)

    - Converts tanagent to Q16.

- Parameters:

    - - **num** – **[in]** Numerator.
- **den** – **[in]** Denominator.

- Returns:

    - - int32\_t: Arc tangent2 of num/dem.

- int32\_t arcCosFxQ16(int32\_t cosTheta)

    - Converts Cosine to Q16.

- Parameters:

    - **cosTheta** – **[in]** Angle in radians.

- Returns:

    - - int32\_t: Arc cos.

- int32\_t arcSinFxQ16(int32\_t sinTheta)

    - Converts Sine to Q16.

- Parameters:

    - **sinTheta** – **[in]** Angle in radians.

- Returns:

    - -int32\_t: Arc sine.

### Infinite Impulse Response (IIR) filter

Infinite Impulse Response(IIR) filter utility header file.

Defines

- FX\_IIR\_FILTER\_ORDER

    -

- struct fx\_iir\_config\_s

    - Infinite Impulse Response(IIR) filter configuration structure.

Public Members

- int32\_t fc

    - LPF cutoff frequency (Q16)

- int32\_t fs

    - sample frequency (Q16)

- int32\_t channels

    - Number of channels

- struct fx\_iir\_input\_s

    - Infinite Impulse Response(IIR) filter input structure.

Public Members

- int32\_t \*filter\_input

    - pointer to an array of length channels

- struct fx\_iir\_output\_s

    - Infinite Impulse Response(IIR) filter output structure.

Public Members

- int32\_t \*filter\_output

    - pointer to an array of length channels

- struct fx\_iir\_state\_s

    - Infinite Impulse Response(IIR) filter state structure.

Public Members

- [fx\_iir\_config\_s](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv415fx_iir_config_s) config

    - Filter configuration data.

- int32\_t num[FX\_IIR\_FILTER\_ORDER + 1]

    - numerator coefficients.

- int32\_t den[FX\_IIR\_FILTER\_ORDER + 1]

    - denominator coefficients.

- [matrix\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411matrix_type) input

    - input matrix for the IIR filter.

- [matrix\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411matrix_type) output

    - output matrix for the IIR filter.

- int32\_t settling\_samples

    - number of samples required to settle down.

- int32\_t filter\_count

    - number of samples processed

Functions

- int32\_t fx\_iir\_lpf\_mem\_req([fx\_iir\_config\_s](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv415fx_iir_config_s) \*config\_data)

    - Computes memory requirement for the IIR filter.

- Parameters:

    - **config\_data** – **[in]** Pointer to a IIR filter configuration structure.

- Returns:

    - -int32\_t: Memory requirement in bytes.

- [fx\_iir\_state\_s](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv414fx_iir_state_s) \*fx\_iir\_lpf\_state\_reset([fx\_iir\_config\_s](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv415fx_iir_config_s) \*config\_data, void \*mem)

    - Initializes the IIR filter with default values.

- Parameters:

    - - **config\_data** – **[in]** Pointer to a IIR filter configuration structure.
- **mem** – **[in]** Pointer to allocated memory block.

- Returns:

    - - [fx\_iir\_state\_s](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structfx__iir__state__s): Pointer to IIR filter state structure.

- void fx\_iir\_lpf\_update([fx\_iir\_state\_s](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv414fx_iir_state_s) \*fx\_iir, [fx\_iir\_input\_s](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv414fx_iir_input_s) \*input, [fx\_iir\_output\_s](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv415fx_iir_output_s) \*output)

    - Updates the IIR filter.

- Parameters:

    - - **fx\_iir** – **[in]** Pointer to a IIR filter state structure.
- **input** – **[in]** Pointer to a IIR filter input structure.
- **output** – **[out]** Pointer to a IIR filter output structure.

- Returns:

    - - None.

- int32\_t filter\_settled([fx\_iir\_state\_s](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv414fx_iir_state_s) \*fx\_iir)

    - Computes whether the filter is settled or not.

- Parameters:

    - **fx\_iir** – **[in]** Pointer to a IIR filter state structure.

- Returns:

    - - 0: If settled.
- 1: Otherwise.

### Matrix

Matrix utility header file.

Defines

- MATRIX\_ELEM(circular\_buffer, row, col)

    - Get an element from the matrix.

- Parameters:

    - - **circular\_buffer** – **[in]** Circular buffer containing the matrix.
- **row** – **[in]** Row index of the desired element.
- **col** – **[in]** Column index of the desired element.

- Returns:

    - Element at the specified location.

- MATRIX\_ROW(circular\_buffer, row)

    - Get a row from the matrix.

- Parameters:

    - - **circular\_buffer** – **[in]** Circular buffer containing the matrix.
- **row** – **[in]** Row index of the desired element.

- Returns:

    - Pointer to the start of the requested row.

- struct matrix\_type

    - Matrix structure.

Public Members

- int32\_t \*matrix

    - Data of the matrix.

- int32\_t rows

    - Number of rows in the matrix.

- int32\_t cols

    - Number of column in the matrix.

- struct matrix\_type\_64

    - Matrix structure - 64 bit.

Public Members

- uint64\_t \*matrix

    - Data of the matrix.

- int32\_t rows

    - Number of rows in the matrix.

- int32\_t cols

    - Number of column in the matrix.

Functions

- int32\_t matrix\_mem\_req(int32\_t rows, int32\_t cols)

    - Calculates size of memory for a rows x cols matrix.

- Parameters:

    - - **rows** – **[in]** Rows of the matrix.
- **cols** – **[in]** Columns of the matrix.

- Returns:

    - - int32\_t: Size (in bytes) of a rows x cols matrix.

- void matrix\_reset([matrix\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411matrix_type) \*m, int32\_t rows, int32\_t cols, void \*mem)

    - Initializes a matrix.

- Parameters:

    - - **m** – **[in]** The matrix.
- **rows** – **[in]** Rows of the matrix.
- **cols** – **[in]** Columns of the matrix.
- **mem** – **[in]** Pointer to memory for matrix.

- Returns:

    - -None.

- void matrix\_zero([matrix\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411matrix_type) \*m)

    - Sets a matrix’s values to zero.

- Parameters:

    - **m** – **[in]** The matrix.

- Returns:

    - - None.

- int32\_t matrix\_mem\_req\_64(int32\_t rows, int32\_t cols)

    - Calculates size of memory for a rows x cols matrix.

- Parameters:

    - - **rows** – **[in]** Rows of the matrix.
- **cols** – **[in]** Columns of the matrix.

- Returns:

    - -int32\_t: Size (in bytes) of a rows x cols matrix.

- void matrix\_reset\_64([matrix\_type\_64](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv414matrix_type_64) \*m, int32\_t rows, int32\_t cols, void \*mem)

    - Initializes a matrix.

- Parameters:

    - - **m** – **[in]** The matrix.
- **rows** – **[in]** Rows of the matrix.
- **cols** – **[in]** Columns of the matrix.
- **mem** – **[in]** Pointer to memory for matrix.

- Returns:

    - - None.

- void matrix\_zero\_64([matrix\_type\_64](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv414matrix_type_64) \*m)

    - Sets a matrix’s values to zero.

- Parameters:

    - **m** – **[in]** The matrix.

- Returns:

    - - None.

- void matrix\_multiply([matrix\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411matrix_type) \*result, [matrix\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411matrix_type) \*A, [matrix\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411matrix_type) \*B)

    - Multiplies two matrices together.

Note

“result” must be allocated before calling this function.

- Parameters:

    - - **result** – **[inout]** The resultant, A \* B.
- **A** – **[in]** First matrix.
- **B** – **[in]** Second matrix.

- Returns:

    - - None.

- void matrix\_copy([matrix\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411matrix_type) \*to, [matrix\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411matrix_type) \*from)

    - Copies a matrix.

Note

“to” must be allocated before calling..

- Parameters:

    - - **to** – **[inout]** The destination.
- **from** – **[in]** The source.

- Returns:

    - - None.

- int32\_t vector\_norm([matrix\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411matrix_type) \*m)

    - Calculates the norm of a vector.

- Parameters:

    - **m** – **[inout]** Matrix (vector) to normalize.

- Returns:

    - -int32\_t: The sqrt of the sum of squares in the vector.

- void vector\_normalize([matrix\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411matrix_type) \*m)

    - Normalizes a vector.

- Parameters:

    - **m** – **[inout]** Matrix (vector) to normalize.

- Returns:

    - - None.

### Stationary Position Indicator (SPI)

Stationary position indicator header file.

Defines

- SPI\_ACCEL\_COLS

    -

Enums

- enum SPI\_STATES

    - Stationary position indicator states.

*Values:*

- enumerator SPI\_UNKNOWN

    - 

- enumerator SPI\_REST

    - 

- enumerator SPI\_MOVING

    -

- struct spi\_config\_s

    - Stationary position indicator configuration.

Public Members

- int32\_t sample\_rate

    - 

- int32\_t detect\_threshold

    - 

- int32\_t accel\_window\_time

    - 

- int32\_t op\_interval\_time

    - 

- int32\_t filter\_enabled

    - 

- int32\_t fc

    -

- struct spi\_input\_s

    - Stationary position indicator input.

Public Members

- int32\_t a[SPI\_ACCEL\_COLS]

    - accel, m/s/s, (Q16)

- struct spi\_output\_s

    - Stationary position indicator output.

Public Members

- int32\_t spi\_state

    - 

- int32\_t event

    -

- struct spi\_state\_s

    - Stationary position indicator state.

Public Members

- [spi\_config\_s](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv412spi_config_s) config

    - 

- [buffer\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411buffer_type) buf

    - 

- int32\_t buf\_sum[SPI\_ACCEL\_COLS]

    - 

- int32\_t buf\_sum\_sq[SPI\_ACCEL\_COLS]

    - 

- int32\_t spi\_state

    - 

- [fx\_iir\_state\_s](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv414fx_iir_state_s) \*fx\_iir\_lpf

    - 

- int32\_t motion\_timer

    - 

- int32\_t op\_interval\_samples

    - 

- int32\_t detect\_threshold

    -

Functions

- int32\_t spi\_mem\_req([spi\_config\_s](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv412spi_config_s) \*config\_data)

    - Calculates size of memory.

- Parameters:

    - **config\_data** – **[in]** Pointer to the algorithm’s configuration data.

- Returns:

    - -int32\_t: Size (in bytes) for stationary position indicator.

- [spi\_state\_s](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411spi_state_s) \*spi\_state\_reset([spi\_config\_s](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv412spi_config_s) \*config\_data, void \*mem)

    - Initializes the stationary position indicator.

- Parameters:

    - - **mem** – **[in]** Pointer to the algorithm’s memory.
- **config\_data** – **[in]** Pointer to the algorithm’s configuration data.

- Returns:

    - - [spi\_state\_s](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structspi__state__s): Pointer to the initialized algorithm’s internal state structure.

- void spi\_update([spi\_state\_s](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411spi_state_s) \*spi\_algo, [spi\_input\_s](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411spi_input_s) \*input, [spi\_output\_s](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv412spi_output_s) \*output)

    - Updates the stationary position indicator with new inputs.

- Parameters:

    - - **spi\_algo** – **[in]** Pointer to the algorithm’s internal state structure.
- **input** – **[in]** Pointer to the algorithm’s input structure.
- **output** – **[out]** Pointer to the algorithm’s output structure.

- Returns:

    - - None.

## Memory

Memory manager abstraction layer for Sensors.

Enums

- enum sns\_mem\_heap\_id

    - Heap Ids.

*Values:*

- enumerator SNS\_HEAP\_MAIN

    - Main heap.

- enumerator SNS\_HEAP\_BATCH

    - Batch heap.

- enumerator SNS\_CLIENT\_BATCH

    - Client batch heap.

- enumerator SNS\_HEAP\_ISLAND

    - Island heap.

- enumerator SNS\_HEAP\_PRAM

    - PRAM heap.

- enumerator SNS\_ISLAND\_BATCH

    - Island batch heap.

- enumerator SNS\_HEAP\_ISLAND\_SSC

    - Island SSC heap.

- enumerator SNS\_HEAP\_ISLAND\_QSHTECH

    - Island QSHTECH heap.

- enumerator SNS\_HEAP\_MAX

    -

Functions

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_heap\_init(void)

    - Initializes all the heaps.

- Returns:

    - - SNS\_RC\_SUCCESS:
- SNS\_RC\_FAILED:

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_heap\_init\_delayed(void)

    - Perform delayed heap initialization. Must be called after *both* sns\_heap\_init and sns\_osa\_init.

- Returns:

    - - SNS\_RC\_SUCCESS:
- SNS\_RC\_FAILED:

- uint16\_t sns\_free\_client\_ptr\_instances(const [sns\_mem\_heap\_id](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv415sns_mem_heap_id) heap\_id, void \*caller\_ptr, uint16\_t alloc\_cnt)

    - Searches the heap for a caller pointer matching instance and frees the block.

- Parameters:

    - - **heap\_id** – **[in]** Pointer to the heap which to search and free memory.
- **caller\_ptr** – **[in]** Pointer to the sensor instance which allocated the memory.
- **alloc\_cnt** – **[in]** Number of allocations by the caller\_ptr.

- Returns:

    - - uint16\_t: Count of freed allocations for client ptr instance.

- void \*sns\_malloc([sns\_mem\_heap\_id](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv415sns_mem_heap_id) heap\_id, size\_t size)

    - Allocates memory from the heap and returns a pointer to the newly allocated memory block.

Note

The memory is always zeroed out internally.

- Parameters:

    - - **heap\_id** – **[in]** Heap to allocate from.
- **size** – **[in]** Number of bytes required.

- Returns:

    - - Pointer to the block of memory if successful.
- NULL if alloc failed

- void \*sns\_malloc\_debug([sns\_mem\_heap\_id](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv415sns_mem_heap_id) heap\_id, size\_t size, void \*debug\_caller\_ptr)

    - Allocates memory from the heap and returns a pointer to the newly allocated memory block.

Note

The memory is always zeroed out internally.

- Parameters:

    - - **heap\_id** – **[in]** Heap to allocate from.
- **size** – **[in]** Number of bytes required.
- **debug\_caller\_ptr** – **[in]** Optional debug such as caller [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__instance) ptr If set to NULL, defaults to using the caller .text address.

- Returns:

    - - Pointer to the block of memory if successful.
- NULL if alloc failed.

- void \*sns\_malloc\_island\_or\_main(size\_t size)

    - Allocates memory from ISLAND heap, or MAIN heap if ISLAND heap is exhausted, and returns a pointer to the newly allocated memory block.

Note

The memory is always zeroed out internally.

- Parameters:

    - **size** – **[in]** Number of bytes required.

- Returns:

    - - Pointer to the block of memory if successful.
- NULL if alloc failed.

- void \*sns\_malloc\_island\_ssc\_or\_main(size\_t size)

    - Allocates memory from ISLAND\_SSC heap, or MAIN heap if ISLAND\_SSC heap is exhausted,and returns a pointer to the newly allocated memory block.

Note

The memory is always zeroed out internally.

- Parameters:

    - **size** – **[in]** Number of bytes required

- Returns:

    - - Pointer to the block of memory if successful.
- NULL if alloc failed.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_free(void \*ptr)

    - Frees a block of memory.

Note

The memory is not zeroed out in [sns\_free()](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#sns__memmgr_8h_1a85153a862159b1e0b1515328ec189784).

- Parameters:

    - **ptr** – **[in]** Pointer to memory block to be freed.

- Returns:

    - - SNS\_RC\_SUCCESS: If operation success.
- SNS\_RC\_FAILED: If ptr does not belong to any valid heap.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_mem\_heap\_register\_lowmem\_cb([sns\_mem\_heap\_id](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv415sns_mem_heap_id) heap\_id, uint32\_t limit, sns\_mem\_heap\_lowmem\_cb callback, intptr\_t args)

    - Register to be notified of low memory.

- Parameters:

    - - **heap\_id** – **[in]** The heap to be monitored.
- **limit** – **[in]** Amount of free memory below which to trigger callback.
- **callback** – **[in]** The callback function to be registered.
- **args** – **[in]** Pointer that will be returned as a parameter to the callback

- Returns:

    - - SNS\_RC\_SUCCESS:
- SNS\_RC\_FAILED:

- void sns\_mem\_heap\_deregister\_lowmem\_cb(sns\_mem\_heap\_lowmem\_cb callback)

    - De-registers the given low mem callback.

- Parameters:

    - **callback** – **[in]** The callback function to be de-registered.

- Returns:

    - - None.

- [sns\_mem\_heap\_id](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv415sns_mem_heap_id) sns\_memmgr\_get\_heap\_id(void const \*ptr)

    - Get the heap ID for a pointer.

- Parameters:

    - **ptr** – **[in]** Pointer to be checked.

- Returns:

    - - Heap id of the ptr if it belongs to a heap managed by sns\_memmgr.
- SNS\_HEAP\_MAX otherwise

- void sns\_memmgr\_log\_heap\_usage(uint64\_t cookie)

    - Generate and submit heap usage log packet.

- Parameters:

    - **cookie** – **[in]** Cookie that is used to populate the user\_defiend field in the log packet.

- Returns:

    - - None.

- size\_t sns\_memmgr\_get\_heap\_usage([sns\_mem\_heap\_id](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv415sns_mem_heap_id) heap\_id)

    - Get the current heap usage.

- Parameters:

    - **heap\_id** – **[in]** Heap whose usage is to be measured.

- Returns:

    - - size\_t: Number of bytes malloc’d in the heap.

- size\_t sns\_memmgr\_get\_heap\_size([sns\_mem\_heap\_id](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv415sns_mem_heap_id) heap\_id)

    - Get total heap size.

- Parameters:

    - **heap\_id** – **[in]** Heap whose size is to be measured.

- Returns:

    - - size\_t: Number of bytes available at maximum in the heap.

- [sns\_mem\_heap\_id](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv415sns_mem_heap_id) sns\_memmgr\_get\_sensor\_heap\_id(sns\_mem\_segment mem\_segment)

    - Get heap id from memory segment.

- Parameters:

    - **mem\_segment** – **[in]** Memory segment information such as QSH, SSC and QSHTECH

- Returns:

    - - sns\_mem\_heap\_id: Memory heap ID.

- bool sns\_memmgr\_block\_available([sns\_mem\_heap\_id](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv415sns_mem_heap_id) heap\_id, size\_t block\_size)

    - Check if memory block of a given size is available in the given heap.

- Parameters:

    - - **heap\_id** – **[in]** Heap ID.
- **block\_size** – **[in]** Size of the block.

- Returns:

    - - True: If the block is found.
- False: Otherwise.

## Protocol Buffer

Utility functions provided by Qualcomm for use by Sensors in association with nanoPB. All utilities in this file can be used in island mode.

Defines

- SNS\_PB\_DECODE\_VARINT(shifter, buf, val, idx)

    - Optimized macro for decoding a encoded varint.

- Parameters:

    - - **shifter** – **[out]** Provided the final shifter offset used by the decoder. Starts at 0x00 and shifts by +0x07 until the end of the varint is found. This is used for correctly constructing the final value.
- **buf** – **[in]** buffer with the encoded payload containing the varint to be decoded.
- **val** – **[out]** Will provided back the decoded varint.
- **idx** – **[inout]** Provide the starting position in the buffer where the varint begins. This index will then be overwritten to to reflect the final index that was read to get the full varint. Each Index in a buffer is equivalent to a byte. Detection of the continuation bit triggers the reading of the next byte in the buffer.

- SNS\_PB\_DECODE\_FIXED32(buf, idx, val)

    - Optimized macro for decoding a encoded fixed32.

- Parameters:

    - - **buf** – **[in]** buffer with the encoded payload containing the fixed32 to be decoded.
- **idx** – **[in]** Provide the starting position in the buffer where the fixed32 value begins.
- **val** – **[out]** Will provided back the decoded fixed32.

- SNS\_PB\_UTIL\_HAS\_DAE\_DECODE

    -

- struct pb\_simple\_cb\_arg

    - Structure to be used with pb\_decode\_simple\_cb.

Public Members

- void \*decoded\_struct

    - Where to place the decoded message.

- const pb\_msgdesc\_t \*fields

    -

- struct pb\_uint\_32\_arr\_arg

    - Structure to be used with pb\_encode\_uint32\_arr\_cb & pb\_decode\_uint32\_arr\_cb.

Public Members

- uint32\_t \*arr

    - Where to place the decoded uint32 array.

- uint8\_t arr\_len

    - Length of the uint32 array.

- uint8\_t \*arr\_index

    - Array index used for decoding. Must be initialized to 0 prior to calling pb\_decode\_uint32\_arr\_cb.

- struct pb\_float\_arr\_arg

    - Structure to be used with pb\_encode\_float\_arr\_cb & pb\_decode\_float\_arr\_cb.

Public Members

- float \*arr

    - Where to place the decoded float array.

- uint8\_t arr\_len

    - Length of the float array.

- uint8\_t \*arr\_index

    - Array index used for decoding. Must be initialized to 0 prior to calling pb\_decode\_float\_arr\_cb.

- struct pb\_buffer\_arg

    - Callback structure for decode\_string and encode\_string.

Public Members

- void const \*buf

    - Buffer to be written, or reference to read buffer.

- size\_t buf\_len

    - Length of buf.

- struct pb\_string\_arr\_arg

    - Callback structure for decode string array and encode string array.

Public Members

- uint8\_t \*\*buf\_arr

    - Where to place the decoded string array

- uint8\_t arr\_len

    - Length of string array

- uint8\_t \*arr\_index

    - Array index used for decoding. Must be initialized to 0 prior to calling pb\_decode\_string\_arr\_cb

- size\_t max\_str\_len

    - Max size of a single string, including null terminator

Functions

- bool pb\_decode\_simple\_cb(pb\_istream\_t \*stream, const pb\_field\_t \*field, void \*\*arg)

    - Decode a nested message. This function is intended to be used as a callback function during the decode process. This utility function can only be used for simple messages without nested structures or arrays.

See also

pb\_callback\_s::decode

- Parameters:

    - - **stream** – **[in]** The stream from which to decode nested message from.
- **field** – **[in]** The format of the nested message value.
- **arg** – **[in]** The argument defined by caller.

- Returns:

    - - True Successfully decode the message.
- False Fail to decode the message.

- bool pb\_encode\_uint\_32\_arr\_cb(pb\_ostream\_t \*stream, const pb\_field\_t \*field, void \*const \*arg)

    - Encode a nested array of uint32. This function is intended to be used as a callback function during the encode process.

See also

pb\_callback\_s::encode.

- Parameters:

    - - **stream** – **[in]** The stream to encode nested message.
- **field** – **[in]** The format of the nested message value.
- **arg** – **[in]** The argument defined by caller.

- Returns:

    - - True Successfully encode the message.
- False Fail to encode the message.

- bool pb\_decode\_uint\_32\_arr\_cb(pb\_istream\_t \*stream, const pb\_field\_t \*field, void \*\*arg)

    - Decode a nested array of uint32. This function is intended to be used as a callback function during the decode process.

See also

pb\_callback\_s::decode.

- Parameters:

    - - **stream** – **[in]** The stream from which to decode nested array of uint32 from.
- **field** – **[in]** The format of the nested array of uint32 value.
- **arg** – **[in]** The argument defined by caller.

- Returns:

    - - True Successfully decode the message.
- False Fail to decode the message.

- bool pb\_encode\_float\_arr\_cb(pb\_ostream\_t \*stream, const pb\_field\_t \*field, void \*const \*arg)

    - Encode a nested array of floats This function is intended to be used as a callback function during the encode process.

See also

pb\_callback\_s::encode.

- Parameters:

    - - **stream** – **[in]** The stream to encode nested array of floats.
- **field** – **[in]** The format of the nested array of floats value.
- **arg** – **[in]** The argument defined by caller.

- Returns:

    - - True Successfully encode the message.
- False Fail to encode the message.

- bool pb\_decode\_float\_arr\_cb(pb\_istream\_t \*stream, const pb\_field\_t \*field, void \*\*arg)

    - Decode a nested array of floats This function is intended to be used as a callback function during the decode process.

See also

pb\_callback\_s::decode

- Parameters:

    - - **stream** – **[in]** The stream from which to decode nested array of float from.
- **field** – **[in]** The format of the nested array of float value.
- **arg** – **[in]** The argument defined by caller.

- Returns:

    - - True Successfully decode the message.
- False Fail to decode the message.

- bool pb\_encode\_string\_arr\_cb(pb\_ostream\_t \*stream, const pb\_field\_t \*field, void \*const \*arg)

    - Encode an array of string. This function is intended to be used as a callback function during encode process.

See also

pb\_callback\_s::encode

- Parameters:

    - - **stream** – **[in]** The stream to encode nested array of strings.
- **field** – **[in]** The format of the nested array of strings value.
- **arg** – **[in]** The argument defined by caller.

- Returns:

    - - True Successfully encode the message.
- False Fail to encode the message.

- bool pb\_decode\_string\_arr\_cb(pb\_istream\_t \*stream, const pb\_field\_t \*field, void \*\*arg)

    - Decode an array of strings. This function is intended to be used as a callback function during the decode process.

See also

pb\_callback\_s::decode

- Parameters:

    - - **stream** – **[in]** The stream from which to decode nested array of string from.
- **field** – **[in]** The format of the nested array of string value.
- **arg** – **[in]** The argument defined by caller.

- Returns:

    - - True Successfully encode the message.
- False Fail to encode the message.

- bool pb\_encode\_string\_cb(pb\_ostream\_t \*stream, const pb\_field\_t \*field, void \*const \*arg)

    - Encode a string into a field. This function is intended to be used as a callback function during the encode process.

See also

pb\_callback\_s::encode.

- Parameters:

    - - **stream** – **[in]** The stream to encode string.
- **field** – **[in]** The format of the string.
- **arg** – **[in]** The argument defined by caller.

- Returns:

    - - True Successfully encode the message.
- False Fail to encode the message.

- bool pb\_decode\_string\_cb(pb\_istream\_t \*stream, const pb\_field\_t \*field, void \*\*arg)

    - Decode a string from a field. This function is intended to be used as a callback function during the decode process.

See also

pb\_callback\_s::decode.

- Parameters:

    - - **stream** – **[in]** The stream to decode string.
- **field** – **[in]** The format of the string.
- **arg** – **[in]** The argument defined by caller.

- Returns:

    - - True Successfully decode the message.
- False Fail to decode the message.

- size\_t pb\_encode\_request(void \*buffer, size\_t buffer\_len, void const \*request\_payload, pb\_msgdesc\_t const \*payload\_fields, sns\_std\_request \*request)

    - Encode a sns\_std\_request and its Sensor-specific payload onto the given buffer.

- Parameters:

    - - **buffer** – **[in]** Where the encoded sns\_std\_request shall be placed.
- **buffer\_len** – **[in]** Size of buffer.
- **request\_payload** – **[in]** The decoded structure to be encoded and placed within sns\_std\_request::payload.
- **payload\_fields** – **[in]** Message definition associated with request\_payload.
- **request** – **[in]** sns\_std\_request configuration, NULL to use default values.

- Returns:

    - - size\_t of encoded message.

- bool pb\_decode\_request(struct [sns\_request](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv411sns_request) const \*req, pb\_msgdesc\_t const \*payload\_fields, sns\_std\_request \*request, void \*decoded\_req)

    - Decodes a request message.

- Parameters:

    - - **req** – **[in]** Request to decode.
- **payload\_fields** – **[in]** Message definition associated with request\_payload.
- **request** – **[out]** sns\_std\_request configuration; NULL to use default values.
- **decoded\_req** – **[out]** Destination for the decoded request; This will be ignored if request argument is provided.

- Returns:

    - - True Successfully decode the message.
- False Fail to decode the message.

- bool pb\_send\_event(struct [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*instance, pb\_msgdesc\_t const \*fields, void const \*c\_struct, sns\_time timestamp, uint32\_t message\_id, struct [sns\_sensor\_uid](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv414sns_sensor_uid) const \*sensor\_uid)

    - Encode an outgoing Event message; then publish that Event. This utility function can only be used for simple events without.

- Parameters:

    - - **instance** – **[in]** Source of the event.
- **fields** – **[in]** Message definition.
- **c\_struct** – **[in]** Decoded Event to send.
- **timestamp** – **[in]** Timestamp of the Event.
- **message\_id** – **[in]** Message ID of the Event.
- **sensor\_uid** – **[in]** Sensor UID of the published event. This can be NULL if Instance is not shared between Sensors.

- Returns:

    - - True Upon success.
- False Otherwise.

- size\_t pb\_get\_encoded\_size\_sensor\_stream\_event(float const \*data, uint8\_t data\_len)

    - Determine encoded size of sns\_std\_sensor\_event with variable length floating point data payload. Construct, sns\_std\_sensor\_event message is as defined in sns\_std\_sensor.proto.

- Parameters:

    - - **data** – **[in]** Data array of floats to be used as the data payload as defined in sns\_std\_sensor.proto.
- **data\_len** – **[in]** Length of the data array.

- Returns:

    - - size\_t Size of the encoded message.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) pb\_send\_sensor\_stream\_event(struct [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*instance, struct [sns\_sensor\_uid](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv414sns_sensor_uid) const \*sensor\_uid, sns\_time timestamp, uint32\_t message\_id, sns\_std\_sensor\_sample\_status sample\_status, float const \*data, uint8\_t data\_len, size\_t encoded\_len)

    - Construct, Encode and Publish an outgoing sns\_std\_sensor\_event as defined in sns\_std\_sensor.proto.

- Parameters:

    - - **instance** – **[in]** Source of the event.
- **sensor\_uid** – **[in]** Sensor UID of the published event.
- **timestamp** – **[in]** Timestamp of the published event.
- **message\_id** – **[in]** Message ID of the published event.
- **sample\_status** – **[in]** The sample status of the published event as defined in sns\_std\_sensor.proto.
- **data** – **[in]** Data array of floats to be used as the data payload as defined in sns\_std\_sensor.proto.
- **data\_len** – **[in]** Length of the data array.
- **encoded\_len** – **[in]** Length of the encoded message as determined by pb\_get\_encoded\_size\_sensor\_stream\_event.

- Returns:

    - - sns\_rc SNS\_RC\_SUCCESS on successfully sending event.
- All other values are equal to failure.

- bool pb\_decode\_suid\_event(pb\_istream\_t \*stream, const pb\_field\_t \*field, void \*\*arg)

    - Decode an [sns\_suid\_event](https://docs.qualcomm.com/doc/80-P9361-100/topic/platform_sensors.html#structsns__suid__event) with variable number of SUIDs.

See also

pb\_callback\_s::decode.

- Parameters:

    - - **stream** – **[in]** nanopb input stream.
- **field** – **[in]** nanopb field for decoding.
- **arg** – **[in]** type [sns\_suid\_search](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structsns__suid__search).

- Returns:

    - - True On success.
- False On failure.

- bool pb\_decode\_std\_sensor\_event(struct [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*instance, const char \*encoded\_event, size\_t encoded\_event\_len, float \*float\_array, size\_t float\_array\_len, size\_t \*decoded\_array\_size, sns\_std\_sensor\_event \*decoded\_event)

    - Optimized function for decoding a std\_sensor\_event.

- Parameters:

    - - **instance** – **[in]** Instance calling this function
- **encoded\_event** – **[in]** encoded event data buffer. ( E.g: ([sns\_sensor\_event](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__event) \*)event-&gt;event ).
- **encoded\_event\_len** – **[in]** Length of the event being encoded.
- **float\_array\_len** – **[in]** Available space in the float array.
- **float\_array** – **[out]** Will contain the decoded floats.
- **decoded\_array\_size** – **[out]** Will contain the number of decoded floats.
- **decoded\_event** – **[out]** Will contain decoded fields.

- Returns:

    - - True On success.
- False On failure.

- bool pb\_decode\_interrupt\_event(struct [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*instance, void const \*encoded\_event, void \*decoded\_event)

    - Optimized function for decoding a interrupt event. It is recommended that clients use the v2\_version of this utility.

- Parameters:

    - - **instance** – **[in]** Instance calling this function.
- **encoded\_event** – **[in]** Pointer with encoded event ([sns\_sensor\_event](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__event)).
- **decoded\_event** – **[out]** Pointer provided for outputing the decoded event ([sns\_interrupt\_event](https://docs.qualcomm.com/doc/80-P9361-100/topic/platform_sensors.html#structsns__interrupt__event)).

- Returns:

    - - True On success.
- False On failure.

- bool pb\_decode\_timer\_event(struct [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*instance, void const \*event, void \*decoded\_event)

    - Optimized function for decoding a [sns\_timer\_sensor\_event](https://docs.qualcomm.com/doc/80-P9361-100/topic/platform_sensors.html#structsns__timer__sensor__event). It is recommended that clients use the v2\_version of this utility.

- Parameters:

    - - **instance** – **[in]** Instance calling this function.
- **event** – **[in]** pointer of event to be encoded of type: ([sns\_sensor\_event](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__event) \*).
- **decoded\_event** – **[out]** Pointer provided for outputing the decoded event of type: ([sns\_timer\_sensor\_event](https://docs.qualcomm.com/doc/80-P9361-100/topic/platform_sensors.html#structsns__timer__sensor__event) \*).

- Returns:

    - - True On success.
- False On failure.

- bool sns\_pb\_encode\_varint(uint8\_t \*buf, size\_t buf\_size, uint64\_t value, size\_t \*bytes\_written)

    - Optimized function for encoding a varint into a buffer.

- Parameters:

    - - **buf** – **[out]** buffer for encoding pb data.
- **buf\_size** – **[in]** size of buffer.
- **value** – **[in]** Value to encode.
- **bytes\_written** – **[out]** Number of bytes encoded into buffer.

- Returns:

    - - True On success.
- False On failure.

- bool sns\_pb\_encode\_fixed32(uint8\_t \*buf, size\_t buf\_size, const uint32\_t val)

    - Optimized function for encoding a fixed32 into a buffer.

- Parameters:

    - - **buf** – **[out]** Buffer for encoding pb data.
- **buf\_size** – **[in]** Size of buffer.
- **val** – **[in]** value to encode.

- Returns:

    - - True On success.
- False On failure.

- bool sns\_pb\_encode\_fixed64(uint8\_t \*buf, size\_t buf\_size, const uint64\_t val)

    - Optimized function for encoding a fixed64 into a buffer.

- Parameters:

    - - **buf** – **[out]** Buffer for encoding pb data.
- **buf\_size** – **[in]** Size of buffer.
- **val** – **[in]** value to encode.

- Returns:

    - - True On success.
- False On failure.

- bool pb\_encode\_dae\_data\_event(sns\_time timestamp, uint8\_t ts\_type, uint16\_t data\_size, uint8\_t \*sensor\_data, size\_t buf\_size, uint8\_t \*encoded\_event, size\_t \*bytes\_written)

    - Optimized function for encoding a dae data event into a buffer.

- Parameters:

    - - **timestamp** – **[in]** timestamp
- **ts\_type** – **[in]** timestamp type
- **data\_size** – **[in]** size of sensor data
- **sensor\_data** – **[in]** sensor data buffer
- **buf\_size** – **[in]** size of encoded event buffer
- **encoded\_event** – **[out]** Buffer for encoding pb data
- **bytes\_written** – **[out]** Bytes written to encoded\_event

- Returns:

    - - True On success.
- False On failure.

- bool pb\_decode\_dae\_data\_event(struct [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*instance, const pb\_msgdesc\_t \*fields, void const \*event, void \*decoded\_event, uint32\_t pb\_proto\_header\_version)

    - Optimized function for decoding a dae data event.

- Parameters:

    - - **instance** – **[in]** Instance calling this function.
- **fields** – **[in]** Message descriptor of type sns\_dae\_data\_event\_fields
- **event** – **[in]** pointer of event to be decoded of type: ([sns\_sensor\_event](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__event) \*).
- **decoded\_event** – **[out]** Pointer provided for outputing the decoded event of type: (sns\_dae\_data\_event \*).
- **pb\_proto\_header\_version** – **[in]** Version of generated header file used. Should be set to PB\_PROTO\_HEADER\_VERSION

- Returns:

    - - True On success.
- False On failure.

- bool pb\_decode\_timer\_event\_v2(struct [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*instance, const pb\_msgdesc\_t \*fields, void const \*encoded\_event, void \*decoded\_event, uint32\_t pb\_proto\_header\_version)

    - Optimized function for decoding a [sns\_timer\_sensor\_event](https://docs.qualcomm.com/doc/80-P9361-100/topic/platform_sensors.html#structsns__timer__sensor__event).

- Parameters:

    - - **instance** – **[in]** Instance calling this function.
- **fields** – **[in]** Message descriptor of type sns\_timer\_sensor\_event\_fields
- **encoded\_event** – **[in]** pointer of event to be encoded of type: ([sns\_sensor\_event](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__event) \*).
- **decoded\_event** – **[out]** Pointer provided for outputing the decoded event of type: ([sns\_timer\_sensor\_event](https://docs.qualcomm.com/doc/80-P9361-100/topic/platform_sensors.html#structsns__timer__sensor__event) \*).
- **pb\_proto\_header\_version** – **[in]** Version of generated header file used. Should be set to PB\_PROTO\_HEADER\_VERSION

- Returns:

    - - True On success.
- False On failure.

- bool pb\_decode\_interrupt\_event\_v2(struct [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*instance, const pb\_msgdesc\_t \*fields, void const \*encoded\_event, void \*decoded\_event, uint32\_t pb\_proto\_header\_version)

    - Optimized function for decoding a interrupt event.

- Parameters:

    - - **instance** – **[in]** Instance calling this function.
- **fields** – **[in]** Message descriptor of type sns\_interrupt\_event\_fields
- **encoded\_event** – **[in]** Pointer with encoded event ([sns\_sensor\_event](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__event)).
- **decoded\_event** – **[out]** Pointer provided for outputing the decoded event ([sns\_interrupt\_event](https://docs.qualcomm.com/doc/80-P9361-100/topic/platform_sensors.html#structsns__interrupt__event)).
- **pb\_proto\_header\_version** – **[in]** Version of generated header file used. Should be set to PB\_PROTO\_HEADER\_VERSION

- Returns:

    - - True On success.
- False On failure.

## Registry

Utilities used in conjunction with registry. All utilities in this file are intended for physical sensor dirvers and can be used in island mode.

Defines

- SNS\_REGISTRY\_MAX\_NAME\_LEN

    - maximum length of registry name

- SNS\_REGISTRY\_MAX\_PARSE\_GROUP

    - maximum number of parse groups

- SNS\_REGISTRY\_MAX\_PID\_LEN

    - maximum length of PID

- SNS\_REGISTRY\_WRITE\_SIGNAL

    - signal for registry write operation

- SNS\_REGISTRY\_DL\_LOAD\_SIGNAL

    - signal for download load operation

- SNS\_REGISTRY\_RPCD\_UP\_SIGNAL

    - signal for RPCD up operation

- SNS\_REGISTRY\_RPCD\_DN\_SIGNAL

    - signal for RPCD down operation

- SNS\_REGISTRY\_THRD\_UP\_SIGNAL

    - signal for thread up operation

- SNS\_REGISTRY\_PWR\_RAIL\_OFF\_SIGNAL

    - signal for power rail off operation

- SNS\_REGISTRY\_LIB\_DELETE\_SIGNAL

    - signal for library delete operation

- SNS\_REGISTRY\_SECURE\_FILE\_WRITE\_SIGNAL

    - signal for secure file write operation

- SNS\_MAX\_DATATYPE\_LEN

    - maximum length of dataype in dependency json

Enums

- enum triaxis

    - Triaxial sensor axis indexing convention.

*Values:*

- enumerator TRIAXIS\_X

    - X axis.

- enumerator TRIAXIS\_Y

    - Y axis.

- enumerator TRIAXIS\_Z

    - Z axis.

- enumerator TRIAXIS\_NUM

    - Number of axes.

- struct sns\_registry\_group\_parse\_info

    - Registry Group Parsing information used in [sns\_registry\_decode\_arg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structsns__registry__decode__arg). Defines how to parse registry items belonging to a given registry group.

Public Members

- char group\_name[SNS\_REGISTRY\_MAX\_NAME\_LEN]

    - Name of the registry group.

- sns\_registry\_parse\_group parse\_func

    - The function that must be called when items of the above mentioned group are found.

- void \*parsed\_buffer

    - The pointer to buffer that must be passed to the parse\_func where parsed output will be stored.

- struct sns\_registry\_decode\_arg

    - PB Decode argument used with sns\_registry\_item\_decode\_cb.

Public Members

- uint8\_t parse\_info\_len

    - The length of the parse\_info array

- [sns\_registry\_group\_parse\_info](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv429sns_registry_group_parse_info) parse\_info[SNS\_REGISTRY\_MAX\_PARSE\_GROUP]

    - Parsing information for each registry group present in the registry read event.

- struct [pb\_buffer\_arg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413pb_buffer_arg) \*item\_group\_name

    - The registry group that currently decoded item belongs to.

- uint32\_t version

    - The registry item version number.

- struct triaxis\_conversion

    - Triaxial sensor input to output axis conversion.

Public Members

- [triaxis](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv47triaxis) ipaxis

    - Input axis index.

- [triaxis](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv47triaxis) opaxis

    - Output axis index the above input axis maps to.

- bool invert

    - Whether the input needs to be negated when translating to the output axis.

- struct sns\_registry\_phy\_sensor\_cfg

    - Registry items supported as part of physical sensor configuration registry group.

Public Members

- int64\_t hw\_id

    - Hardware ID

- uint8\_t is\_dri

    - Whether the devices supports DRI mode

- uint8\_t res\_idx

    - Resolution index

- bool sync\_stream

    - Sync stream supported?

- struct sns\_registry\_phy\_sensor\_pf\_cfg

    - Registry items supported as part of physical sensor platform configuration registry group.

Public Members

- uint32\_t slave\_config

    - 

- uint32\_t min\_bus\_speed\_khz

    - Minimum bus speed in kHz (deprecated, set to 0)

- uint32\_t max\_bus\_speed\_khz

    - Maximum bus speed in kHz

- uint32\_t dri\_irq\_num

    - Data ready interrupt number

- uint16\_t max\_odr

    - Maximum output data rate

- uint8\_t min\_odr

    - Minimum output data rate

- uint8\_t bus\_type

    - Type of bus (e.g., I2C, SPI)

- uint8\_t bus\_instance

    - Instance of the bus

- uint8\_t reg\_addr\_type

    - Type of register address

- uint8\_t irq\_pull\_type

    - Interrupt pull type (e.g., pull-up, pull-down)

- uint8\_t irq\_drive\_strength

    - Interrupt drive strength

- uint8\_t irq\_trigger\_type

    - Interrupt trigger type (e.g., edge, level)

- uint8\_t num\_rail

    - Number of power rails

- uint8\_t rail\_on\_state

    - State of the rail when on

- uint8\_t rigid\_body\_type

    - Type of rigid body

- uint8\_t i3c\_address

    - I3C address

- uint8\_t sub\_sys\_type

    - Subsystem type

- bool irq\_is\_chip\_pin

    - Indicates if IRQ is a chip pin

- char vddio\_rail[SNS\_REGISTRY\_MAX\_NAME\_LEN]

    - VDDIO rail name

- char vdd\_rail[SNS\_REGISTRY\_MAX\_NAME\_LEN]

    - VDD rail name

- char clk\_in\_rail[SNS\_REGISTRY\_MAX\_NAME\_LEN]

    - Clock input rail name

- uint8\_t qup\_type

    - QUP type

- uint8\_t qup\_instance

    - QUP instance

- uint32\_t manufacturer\_id

    - Manufacturer ID

- uint32\_t provisional\_id

    - Provisional ID

- struct sns\_registry\_md\_cfg

    - Registry items supported as part of MD configuration registry group.

Public Members

- float thresh

    - threshold in m/s2

- float win

    - window in sec

- bool disable

    - disable

- struct sns\_dep\_sensor\_attr

    - Structure to be used in sns\_registry\_parse\_dependency\_cb.

Public Members

- [sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_item) list\_entry

    - 

- sns\_attribute\_id attr\_id

    - attribute id

- size\_t attr\_val\_size

    - attribute value’s size

- void \*attr\_val

    - attribute value

- struct sns\_dep\_sensor\_info

    - Structure to be used in sns\_registry\_parse\_dependency\_cb.

Public Members

- [sns\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413sns_list_item) list\_entry

    - 

- [sns\_list](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv48sns_list) attr\_list

    - List of attributes. List item type : [sns\_dep\_sensor\_attr](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structsns__dep__sensor__attr)

- char datatype[SNS\_MAX\_DATATYPE\_LEN]

    - datatype of dependency

Functions

- bool sns\_registry\_item\_decode\_cb(pb\_istream\_t \*stream, const pb\_field\_t \*field, void \*\*arg)

    - Callback function used to decode [sns\_registry\_read\_event](https://docs.qualcomm.com/doc/80-P9361-100/topic/platform_sensors.html#structsns__registry__read__event) Function will extract each item within the read event including items within subgroups and will optionally run a parsing function on the item passed.

- Parameters:

    - - **stream** – **[in]** Refer pb\_callback\_s::decode.
- **field** – **[in]** Refer pb\_callback\_s::decode.
- **arg** – **[in]** [sns\_registry\_decode\_arg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structsns__registry__decode__arg) type.

- Returns:

    - - True Successfully decoded registry item.
- False Fail to decode registry item.

- bool sns\_registry\_parse\_phy\_sensor\_cfg(sns\_registry\_data\_item \*reg\_item, struct [pb\_buffer\_arg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413pb_buffer_arg) \*item\_name, struct [pb\_buffer\_arg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413pb_buffer_arg) \*item\_str\_val, void \*parsed\_buffer)

    - Function used to parse items belonging to physical sensor configuration registry group.

- Parameters:

    - - **reg\_item** – **[in]** Pointer to sns\_registry\_data\_item.
- **item\_name** – **[in]** Pointer to decoded registry item name as defined in sns\_registry\_data\_item.
- **item\_str\_val** – **[in]** Pointer to decoded registry item string value as defined in sns\_registry\_data\_item.
- **parsed\_buffer** – **[out]** [sns\_registry\_phy\_sensor\_cfg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structsns__registry__phy__sensor__cfg) type where parsed items are stored.

- Returns:

    - - True Successfully parsed registry physical sensor config.
- False Failure to parse registry physical sensor config.

- bool sns\_registry\_parse\_phy\_sensor\_pf\_cfg(sns\_registry\_data\_item \*reg\_item, struct [pb\_buffer\_arg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413pb_buffer_arg) \*item\_name, struct [pb\_buffer\_arg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413pb_buffer_arg) \*item\_str\_val, void \*parsed\_buffer)

    - Function used to parse items belonging to physical sensor platform configuration registry group.

- Parameters:

    - - **reg\_item** – **[in]** Pointer to sns\_registry\_data\_item
- **item\_name** – **[in]** Pointer to decoded registry item name as defined in sns\_registry\_data\_item.
- **item\_str\_val** – **[in]** Pointer to decoded registry item string value as defined in sns\_registry\_data\_item.
- **parsed\_buffer** – **[out]** Of type [sns\_registry\_phy\_sensor\_pf\_cfg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structsns__registry__phy__sensor__pf__cfg), where parsed items are stored.

- Returns:

    - - True Successfully parsed registry physical sensor platform config.
- False Fail to parse registry physical sensor platform config.

- bool sns\_registry\_parse\_axis\_orientation(sns\_registry\_data\_item \*reg\_item, struct [pb\_buffer\_arg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413pb_buffer_arg) \*item\_name, struct [pb\_buffer\_arg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413pb_buffer_arg) \*item\_str\_val, void \*parsed\_buffer)

    - Function used to parse items belonging to physical sensor platform configuration registry group.

- Parameters:

    - - **reg\_item** – **[in]** Pointer to sns\_registry\_data\_item
- **item\_name** – **[in]** Pointer to decoded registry item name as defined in sns\_registry\_data\_item.
- **item\_str\_val** – **[in]** Pointer to decoded registry item string value as defined in sns\_registry\_data\_item.
- **parsed\_buffer** – **[out]** Of type [sns\_registry\_phy\_sensor\_pf\_cfg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structsns__registry__phy__sensor__pf__cfg) where parsed items are stored.

- Returns:

    - - True Successfully parse item.
- False Fail to parse item.

- bool sns\_registry\_parse\_float\_arr(sns\_registry\_data\_item \*reg\_item, struct [pb\_buffer\_arg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413pb_buffer_arg) \*item\_name, struct [pb\_buffer\_arg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413pb_buffer_arg) \*item\_str\_val, void \*parsed\_buffer)

    - Function used to parse N dimensional float array.

- Parameters:

    - - **reg\_item** – **[in]** Pointer to sns\_registry\_data\_item.
- **item\_name** – **[in]** Pointer to decoded registry item name as defined in sns\_registry\_data\_item.
- **item\_str\_val** – **[in]** Pointer to decoded registry item string value as defined in sns\_registry\_data\_item.
- **parsed\_buffer** – **[out]** Of type [vector3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structvector3) where parsed items are stored.

- Returns:

    - - True Successfully parsed N dimensional float array.
- False Fail to parsed N dimensional float array.

- bool sns\_registry\_parse\_scale(sns\_registry\_data\_item \*reg\_item, struct [pb\_buffer\_arg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413pb_buffer_arg) \*item\_name, struct [pb\_buffer\_arg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413pb_buffer_arg) \*item\_str\_val, void \*parsed\_buffer)

    - Function used to parse items belonging to factory calibration scale registry group.

- Parameters:

    - - **reg\_item** – **[in]** Pointer to sns\_registry\_data\_item.
- **item\_name** – **[in]** Pointer to decoded registry item name as defined in sns\_registry\_data\_item.
- **item\_str\_val** – **[in]** Pointer to decoded registry item string value as defined in sns\_registry\_data\_item.
- **parsed\_buffer** – **[out]** Of type [matrix3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structmatrix3) where parsed items are stored.

- Returns:

    - - True Successfully parse item.
- False Fail to parse item.

- bool sns\_registry\_parse\_corr\_matrix\_3(sns\_registry\_data\_item \*reg\_item, struct [pb\_buffer\_arg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413pb_buffer_arg) \*item\_name, struct [pb\_buffer\_arg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413pb_buffer_arg) \*item\_str\_val, void \*parsed\_buffer)

    - Function used to parse items belonging to factory calibration 3 \* 3 correction matrix registry group.

- Parameters:

    - - **reg\_item** – **[in]** Pointer to sns\_registry\_data\_item.
- **item\_name** – **[in]** Pointer to decoded registry item name as defined in sns\_registry\_data\_item.
- **item\_str\_val** – **[in]** Pointer to decoded registry item string value as defined in sns\_registry\_data\_item.
- **parsed\_buffer** – **[out]** Of type [matrix3](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structmatrix3) where parsed items are stored.

- Returns:

    - - True Successfully parse item.
- False Fail to parse item.

- bool sns\_registry\_parse\_md\_cfg(sns\_registry\_data\_item \*reg\_item, struct [pb\_buffer\_arg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413pb_buffer_arg) \*item\_name, struct [pb\_buffer\_arg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv413pb_buffer_arg) \*item\_str\_val, void \*parsed\_buffer)

    - Function used to parse items belonging to Motion Detect Config registry group.

- Parameters:

    - - **reg\_item** – **[in]** Pointer to sns\_registry\_data\_item.
- **item\_name** – **[in]** Pointer to decoded registry item name as defined in sns\_registry\_data\_item.
- **item\_str\_val** – **[in]** Pointer to decoded registry item string value as defined in sns\_registry\_data\_item.
- **parsed\_buffer** – **[out]** Of type [sns\_registry\_md\_cfg](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structsns__registry__md__cfg) where parsed items are stored.

- Returns:

    - - True Successfully parse item.
- False Fail to parse item.

- bool sns\_registry\_parse\_dependency\_cb(pb\_istream\_t \*stream, const pb\_field\_t \*field, void \*\*arg)

    - Function for decoding the registry event for dependency info.

- Parameters:

    - - **stream** – **[in]** The stream from which to decode dependency info from.
- **field** – **[in]** The format of the nested message value.
- **arg** – **[out]** [sns\_list](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structsns__list) that gets populated. list item type : [sns\_dep\_sensor\_info](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structsns__dep__sensor__info)

- Returns:

    - - True On success.
- False On failure.

- void sns\_sensor\_signal\_registry\_task(unsigned int sig)

    - Function to get signal Registry task.

- Parameters:

    - **sig** – **[in]** Signal to registry task.

## SUID

A simple utility to look-up dependent SUIDs. Intended for use by Sensors; is a replacement for/wrapper around sending requests to the SUID Lookup Sensor directly. The Sensor developer should add SNS\_SUID\_LOOKUP\_DATA as field to their Sensor state structure, specifying the number of data types they intend to look-up; this should correspond to the number of times they plan to call [sns\_suid\_lookup\_add()](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#sns__suid__util_8h_1a7631a8076b31fc26e80fab3357bfcb8b). Number should be chosen precisely: larger than necessary will result in wasted memory; if smaller the requested data types will not be discovered. If the Sensor is expected to choose amongst multiple SUIDs of the same data type, they may register a sns\_suid\_lookup\_cb within SNS\_SUID\_LOOKUP\_INIT or SNS\_SUID\_LOOKUP\_INIT\_V2 if using the generic\_lookup\_cb defined in this utiliy. If so they will receive one callback per SUID discovered, and be given the attributes event for it. The Sensor must return true/false whether it wishes to store and use this SUID.

Defines

- SNS\_SUID\_LOOKUP\_DATA(cnt)

    - Anonymous structure definition generator.

- Parameters:

    - - **cnt** – **[in]** Number of data types to look-up.

- SNS\_SUID\_LOOKUP\_DATA\_V3(cnt)

    - Anonymous structure definition generator with modified suid\_cb type.

- Parameters:

    - - **cnt** – **[in]** Number of data types to look-up.

- SNS\_SUID\_LOOKUP\_ANY

    - Wild Card based lookup (will return all SUIDs).

- SNS\_SUID\_END\_OF\_DATA\_TYPES

    - 

- SNS\_SUID\_LOOKUP\_INIT(suid\_lookup\_data, cb)

    - Initialize the data created by SNS\_SUID\_LOOKUP\_DATA.

- Parameters:

    - - **suid\_lookup\_data** – **[in]** Data created by SNS\_SUID\_LOOKUP\_DATA.
- **cb** – **[in]** Optional callback function; see sns\_suid\_lookup\_cb.

- SNS\_SUID\_LOOKUP\_INIT\_V3(suid\_lookup\_data\_v3, cb)

    - Initialize the data created by SNS\_SUID\_LOOKUP\_DATA.

- Parameters:

    - - **suid\_lookup\_data\_v3** – **[in]** Data created by SNS\_SUID\_LOOKUP\_DATA.
- **cb** – **[in]** Optional callback function; see sns\_suid\_lookup\_cb.

- struct sns\_sensor\_attribute\_data

    - Structure containing sensor name and list of desired attributes.

Public Members

- char data\_type[32]

    - 

- [sns\_sensor\_util\_generic\_attrib](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv430sns_sensor_util_generic_attrib) \*generic\_attrib\_list

    -

Functions

- bool sns\_attr\_string\_comp\_fcn (const sns\_sensor\_util\_attrib \*restrict attrib\_decoded, const sns\_sensor\_util\_attrib \*restrict attrib\_match)

    - Compare decoded attr string against desired attr string.

- Parameters:

    - - **attrib\_decoded** – **[in]** attr decoded from suid event
- **attrib\_match** – **[in]** desired attribute to match sensor during cb

- Returns:

    - - True if strings match
- False otherwise

- bool sns\_attr\_value\_comp\_fcn (const sns\_sensor\_util\_attrib \*restrict attrib\_decoded, const sns\_sensor\_util\_attrib \*restrict attrib\_match)

    - Compare decoded attr value against desired attr value.

- Parameters:

    - - **attrib\_decoded** – **[in]** attr decoded from suid event
- **attrib\_match** – **[in]** desired attribute to match sensor during cb

- Returns:

    - - True if values match
- False otherwise

- bool sns\_generic\_suid\_lookup\_cb(struct [sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*const sensor, struct [sns\_sensor\_event](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv416sns_sensor_event) const \*event, const [sns\_sensor\_util\_generic\_attrib](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv430sns_sensor_util_generic_attrib) \*generic\_attrib\_list)

    - 

- void sns\_suid\_lookup\_deinit(struct [sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*sensor, void \*suid\_lookup\_data)

    - Deinitialize the data initialized by SNS\_SUID\_LOOKUP\_INIT. Closes all data streams but leaves all retrieved SUIDs accessible. Should not be called if Sensor is required to act upon subsequently missing dependencies (i.e. a dependency goes away). Causes island mode exit.

- Parameters:

    - - **sensor** – **[in]** Use same Sensor as provided in sns\_suid\_lookup\_add.
- **suid\_lookup\_data** – **[in]** Data created by SNS\_SUID\_LOOKUP\_DATA.

- Returns:

    - - None.

- void sns\_suid\_lookup\_deinit\_v3(struct [sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*sensor, void \*suid\_lookup\_data)

    - Deinitialize the data initialized by SNS\_SUID\_LOOKUP\_INIT. Closes all data streams but leaves all retrieved SUIDs accessible. Should not be called if Sensor is required to act upon subsequently missing dependencies (i.e. a dependency goes away). Causes island mode exit.

- Parameters:

    - - **sensor** – **[in]** Use same Sensor as provided in sns\_suid\_lookup\_add.
- **suid\_lookup\_data** – **[in]** Data created by SNS\_SUID\_LOOKUP\_DATA.

- Returns:

    - - None.

- void sns\_suid\_lookup\_add(struct [sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*sensor, void \*suid\_lookup\_data, char \*data\_type)

    - Initiate SUID lookup for a data type. The SUIDs will be discovered according to the parameters set in SNS\_SUID\_LOOKUP\_INIT. Causes island mode exit.

- Parameters:

    - - **sensor** – **[in]** Use same Sensor as provided in sns\_suid\_lookup\_add.
- **suid\_lookup\_data** – **[in]** Lookup data initialized by SNS\_SUID\_LOOKUP\_INIT.
- **data\_type** – **[in]** Null-terminated data type string to lookup.

- Returns:

    - None.

- void sns\_suid\_lookup\_add\_v2(struct [sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*sensor, void \*suid\_lookup\_data, char \*data\_type, bool register\_updates)

    - Initiate SUID lookup for a data type. The SUIDs will be discovered according to the parameters set in SNS\_SUID\_LOOKUP\_INIT. Causes island mode exit.

- Parameters:

    - - **sensor** – **[in]** Use same Sensor as provided in sns\_suid\_lookup\_add.
- **suid\_lookup\_data** – **[in]** Lookup data initialized by SNS\_SUID\_LOOKUP\_INIT.
- **data\_type** – **[in]** Null-terminated data type string to lookup.
- **register\_updates** – **[in]** Register for updates to the list of SUIDs for the given data\_type.

- Returns:

    - None.

- void sns\_suid\_lookup\_add\_v3(struct [sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*sensor, void \*suid\_lookup\_data\_v3, char \*data\_type)

    - Initiate SUID lookup for a data type. The SUIDs will be discovered according to the parameters set in SNS\_SUID\_LOOKUP\_INIT. Causes island mode exit.

- Parameters:

    - - **sensor** – **[in]** Use same Sensor as provided in sns\_suid\_lookup\_add.
- **suid\_lookup\_data\_v3** – **[in]** Lookup data initialized by SNS\_SUID\_LOOKUP\_INIT.
- **data\_type** – **[in]** Null-terminated data type string to lookup.

- Returns:

    - None.

- bool sns\_suid\_lookup\_peek(void \*suid\_lookup\_data, char const \*data\_type, [sns\_sensor\_uid](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv414sns_sensor_uid) \*suid)

    - Peek the SUID being looked-up and associated with data type. Causes island mode exit.

- Parameters:

    - - **suid\_lookup\_data** – **[in]** Data on which sns\_suid\_lookup\_add was called.
- **data\_type** – **[in]** Null-terminated data type string to lookup.
- **suid** – **[out]** Sensor UID if found (optional).

- Returns:

    - - True If SUID has been found.
- False Otherwise.

- bool sns\_suid\_lookup\_get(void \*suid\_lookup\_data, char const \*data\_type, [sns\_sensor\_uid](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv414sns_sensor_uid) \*suid)

    - Get the SUID already looked-up and associated with data type. Causes island mode exit.

- Parameters:

    - - **suid\_lookup\_data** – **[in]** Data on which sns\_suid\_lookup\_add was called.
- **data\_type** – **[in]** Null-terminated data type string to lookup.
- **suid** – **[out]** Sensor UID if found (optional).

- Returns:

    - - True if SUID has been found and valid.
- False otherwise.

- bool sns\_suid\_lookup\_get\_v3(void \*suid\_lookup\_data\_v3, char const \*data\_type, [sns\_sensor\_uid](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv414sns_sensor_uid) \*suid)

    - Get the SUID already looked-up and associated with data type. Causes island mode exit.

- Parameters:

    - - **suid\_lookup\_data\_v3** – **[in]** Data on which sns\_suid\_lookup\_add was called.
- **data\_type** – **[in]** Null-terminated data type string to lookup.
- **suid** – **[out]** Sensor UID if found (optional).

- Returns:

    - - True if SUID has been found and valid.
- False otherwise.

- bool sns\_suid\_lookup\_complete(void \*suid\_lookup\_data)

    - Whether the SUID lookup process has completed successfully.

- Parameters:

    - **suid\_lookup\_data** – **[in]** Data on which sns\_suid\_lookup\_add was called.

- Returns:

    - -True if all requested data\_type SUIDs were found. -False otherwise.

- bool sns\_suid\_lookup\_complete\_v3(void \*suid\_lookup\_data)

    - Whether the SUID lookup process has completed successfully.

- Parameters:

    - **suid\_lookup\_data** – **[in]** Data on which sns\_suid\_lookup\_add was called.

- Returns:

    - -True if all requested data\_type SUIDs were found. -False otherwise.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_suid\_lookup\_handle(struct [sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*sensor, void \*suid\_lookup\_data)

    - Handle a SUID or attribute event. Must be called within the Sensor’s notify\_event function. Causes island mode exit.

- Parameters:

    - - **sensor** – **[in]** Use same Sensor as provided in sns\_suid\_lookup\_add.
- **suid\_lookup\_data** – **[in]** Lookup data initialized by SNS\_SUID\_LOOKUP\_INIT.

- Returns:

    - sns\_rc SNS\_RC\_SUCCESS if successful.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_suid\_lookup\_handle\_v3(struct [sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*sensor, void \*suid\_lookup\_data\_v3, [sns\_sensor\_attribute\_data](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv425sns_sensor_attribute_data) \*sensor\_dep\_list)

    - Handle a SUID or attribute event. Must be called within the Sensor’s notify\_event function. Causes island mode exit.

- Parameters:

    - - **sensor** – **[in]** Use same Sensor as provided in sns\_suid\_lookup\_add.
- **suid\_lookup\_data\_v3** – **[in]** Lookup data initialized by SNS\_SUID\_LOOKUP\_INIT.
- **sensor\_dep\_list** – **[in]** Structure containing sensor name and list of desired attributes

- Returns:

    - sns\_rc SNS\_RC\_SUCCESS if successful.

- void sns\_sensor\_util\_generate\_random\_suid([sns\_sensor\_uid](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv414sns_sensor_uid) \*const uid)

    - Generate a random SUID.

- Parameters:

    - **uid** – **[inout]** SUID to be populated.

- Returns:

    - - None.

## Sensor Util

Utility functions for use by Sensor Developers. All utilities in this file can be used in island mode.

- struct sns\_suid\_search

    - Public Members

- char \*data\_type\_str

    - input to SUID sensor

- [sns\_sensor\_uid](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv414sns_sensor_uid) \*suid

    - list of SUIDs returned from SUID sensor

- uint32\_t num\_of\_suids

    - number of items in suid list

- struct sns\_timesync\_event\_info

    - Public Members

- [sns\_sensor\_event](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv416sns_sensor_event) \*event

    - 

- int stream\_index

    - 

- bool pending

    -

Functions

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_sensor\_util\_remove\_sensor\_stream([sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*sensor, [sns\_data\_stream](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv415sns_data_stream) \*\*stream)

    - Removes a particular stream for a sensor and marks the stream as a NULL.

- Parameters:

    - - **sensor** – **[in]** The Sensor for which the stream is to be removed
- **stream** – **[in]** The stream to be removed

- Returns:

    - sns\_rc SNS\_RC\_SUCCESS == If stream removed successfully, any other value == Failure.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_sensor\_util\_remove\_sensor\_instance\_stream([sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*instance, [sns\_data\_stream](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv415sns_data_stream) \*\*stream)

    - Removes a particular stream for a sensor instance and marks the stream as NULL.

- Parameters:

    - - **instance** – **[in]** The sensor instance for which the stream is to be removed.
- **stream** – **[in]** The stream to be removed.

- Returns:

    - sns\_rc SNS\_RC\_SUCCESS == If stream removed successfully, any other value == Failure.

- struct [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*sns\_sensor\_util\_find\_instance(struct [sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) const \*sensor, struct [sns\_request](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv411sns_request) const \*request, [sns\_sensor\_uid](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv414sns_sensor_uid) const \*suid)

    - Find the instance (if any) which is presently servicing this request.

- Parameters:

    - - **sensor** – **[in]** The Sensor from which to search through
- **request** – **[in]** The request to search for
- **suid** – **[in]** The specific suid for which clients are being searched.

- Returns:

    - [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__instance) Return instance pointer if found the Sensor Instance currently servicing this request; or NULL.

- struct [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*sns\_sensor\_util\_get\_shared\_instance(struct [sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*sensor)

    - Find the shared instance for a Sensor. Many physical drivers share a single Instance across all associated Sensors. This function finds and returns that single Instance if it exists.

- Parameters:

    - **sensor** – **[in]** A Sensor which shares a single Instance.

- Returns:

    - [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__instance) Return the Shared Instance, or NULL.

- struct [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*sns\_sensor\_util\_find\_instance\_match(struct [sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) const \*sensor, struct [sns\_request](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv411sns_request) const \*request, sns\_sensor\_util\_instance\_match\_cb cb)

    - Find an existing instance that can handle this new request.

- Parameters:

    - - **sensor** – **[in]** Sensor which received the request.
- **request** – **[in]** New incoming request from [sns\_sensor\_api::set\_client\_request](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__api_1a663d0f9512b85e8b34ce71a34a886f98).
- **cb** – **[in]** Callback function for each existing Instance.

- Returns:

    - [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__instance) Instance reference if found, otherwise NULL.

- [sns\_sensor\_uid](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv414sns_sensor_uid) sns\_get\_suid\_lookup(void)

    - Return the SUID of the SUID Lookup Sensor.

- **Parameters**
    - None.

- Returns:

    - [sns\_sensor\_uid](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__uid) SUID of the SUID lookup sensor.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_process\_streams\_in\_timesync([sns\_data\_stream](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv415sns_data_stream) \*\*streams, [sns\_timesync\_event\_info](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv423sns_timesync_event_info) \*info, int num\_streams, process\_stream\_event process\_event\_cb, void \*userdata)

    - Process data from the given streams in synchronized chronological order.

- Non-data events will be processed as soon as they are available
- Data events on the stream will be processed only when there is at least one data event available on all streams
- Data events across streams will be processed in chronological order

- Parameters:

    - - **streams** – **[in]** Pointer to array of data streams.
- **info** – **[in]** TODO.
- **num\_streams** – **[in]** Number of data streams.
- **process\_event\_cb** – **[in]** Callback function for processing one event from a data stream.
- **userdata** – Userdata to be supplied to each callback.

- Returns:

    - sns\_rc SNS\_RC\_SUCCESS == if everything went fine, error status otherwise.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_sensor\_util\_find\_min\_batch\_period([sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*instance, [sns\_sensor\_uid](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv414sns_sensor_uid) const \*suid, uint32\_t \*min\_batch\_period, uint32\_t \*max\_flush\_period, bool \*max\_batch)

    - Find the minimum batch period from among the clients of an instance.

- Parameters:

    - - **instance** – **[in]** The Sensor instance being evaluated.
- **suid** – **[in]** The specific suid for which clients are being evaluated.
- **min\_batch\_period** – **[in]** The min period of batching.
- **max\_flush\_period** – **[in]** The max period of flushing.
- **max\_batch** – **[in]** The max batch flag.

- Returns:

    - sns\_rc

- SNS\_RC\_SUCCESS if a minimum batch period and minimum flush period was successfully determined.
- SNS\_RC\_FAILED if there was an error in determining the batch period or flush period.
- SNS\_RC\_INVALID\_STATE if there are no clients for the instance for this suid.

- bool sns\_sensor\_util\_decide\_max\_batch([sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*instance, [sns\_sensor\_uid](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv414sns_sensor_uid) const \*suid)

    - Decide if all requests have max batch set to true.

- Parameters:

    - - **instance** – **[in]** The Sensor instance being evaluated.
- **suid** – **[in]** The specific suid for which clients are being evaluated.

- Returns:

    - - True If all requests have the max batch set to true.
- False If there is a request which does not have max batch set to true.

- void sns\_sensor\_util\_send\_flush\_event([sns\_sensor\_uid](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv414sns_sensor_uid) const \*uid, [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*instance)

    - Send a flush event.

- Parameters:

    - - **uid** – **[in]** UID of the Sensor.
- **instance** – **[in]** Reference to the instance of the Sensor.

- Returns:

    - Returns Nothing.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_sensor\_util\_update\_std\_sensor\_batching([sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*const sensor, [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*curr\_inst)

    - Update batching requests to sensor instances. This function is for sensors using sns\_std\_request and sns\_std\_sensor\_config, and it should be called when removing/adding new sensor instances. It will call the curr\_inst’s set\_client\_config function using the request with the smallest batch and flush period among all the requests of the instance.

- Parameters:

    - - **sensor** – **[in]** Sensor whose instances are to be updated.
- **curr\_inst** – **[in]** A instance of the current sensor.

- Returns:

    - sns\_rc

- SNS\_RC\_SUCCESS if instance is successfully updated with new batching parameters.
- SNS\_RC\_FAILED if decode or encode fails.
- SNS\_RC\_INVALID\_VALUE if no request in the instance request queue.

- bool sns\_sensor\_util\_instance\_match(float const \*sample\_rate, struct [sns\_request](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv411sns_request) const \*new\_req, struct [sns\_request](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv411sns_request) const \*exist\_req)

    - Compare if new request can reuse existing instance. If a instance has the same sample\_rate, same flag for flush\_only and max\_batch, it can be reused.

- Parameters:

    - - **sample\_rate** – **[in]** Sample rate.
- **new\_req** – **[in]** The new request received
- **exist\_req** – **[in]** The existing request being serviced by the instance

- Return values:

    - **-True** – New request can be serviced by the existing instance. -False Otherwise.

- void sns\_sensor\_util\_remove\_all\_client\_req([sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*instance, [sns\_sensor\_uid](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv414sns_sensor_uid) const \*uid)

    - Remove all client requests from the client request list in the sensor instance for the provided suid.

- Parameters:

    - - **instance** – **[in]** reference to the instance.
- **uid** – **[in]** SUID of the sensor.

- Returns:

    - Returns None

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_sensor\_util\_send\_event\_without\_payload([sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*instance, [sns\_sensor\_uid](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv414sns_sensor_uid) const \*uid, uint32\_t event\_message\_id)

    - Send an event with the given message id without any payload.

- Parameters:

    - - **instance** – **[in]** reference to the instance generating this event.
- **uid** – **[in]** SUID of the sensor.
- **event\_message\_id** – **[in]** message id of the event to be sent.

- Returns:

    - sns\_rc SNS\_RC\_SUCCESS == If successfully send the event, any other value == Failure.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_sensor\_util\_do\_for\_all\_instances([sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*const this, sns\_do\_for\_all\_instances\_cb\_func user\_cb\_func, void \*const arg)

    - Iterates through the list of all instances for the sensor of this input instance and calls the user-provided callback function with the arguments and instances as input, iterating from instance 1 to N.

Note

: This callback will include the input instance itself. This function should not be called directly from a multithreaded library.

- Parameters:

    - - **this** – **[in]** Pointer to current instance
- **user\_cb\_func** – **[in]** Callback function that will be called for each instance
- **arg** – **[in]** Argument passed to the callback

- Returns:

    - - SNS\_RC\_SUCCESS: If successful
- SNS\_RC\_FAILED: Otherwise

- bool sns\_dep\_sensor\_match\_attributes(struct [sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*const sensor, struct [sns\_list](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv48sns_list) \*const list, const char \*const data\_type, const struct [sns\_sensor\_event](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv416sns_sensor_event) \*const event, [sns\_dep\_sensor\_info](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv419sns_dep_sensor_info) \*\*const item)

    - Match the attributes of the data\_type with the attributes in the dep\_sensor\_list.

- Parameters:

    - - **sensor** – **[in]** reference to the sensor getting the suid\_lookup\_cb().
- **list** – **[in]** reference to the dep\_sensor\_list stored in sensor state
- **data\_type** – **[in]** data\_type for which suid\_lookup\_up() came
- **event** – **[in]** event containing the attributes for data\_type
- **item** – **[out]** [sns\_dep\_sensor\_info](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structsns__dep__sensor__info) item type for list indicating if dep\_sensor\_list had the data\_type or not

- Returns:

    - - True If data\_type was present in dep\_sensor\_list and all attributes matched.
- False Otherwise

## Signal

Provides internal signal service that can spawn an internal thread to handle asynchronous events.

Defines

- \_\_SIZEOF\_ATTR\_SIG

    -

- union sns\_signal\_attr

    - Signal Attribute structure client supposed to pass during signal registration.

Public Members

- char \_\_size[\_\_SIZEOF\_ATTR\_SIG]

    - 

- long int \_\_alignment

    -

Functions

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_signal\_util\_init(void)

    - The API to initialize Signal utility state. This API should be called only in the big image.

- Returns:

    - - SNS\_RC\_SUCCESS: Signal registered initialized successfully.
- !SNS\_RC\_SUCCESS: An error occurred.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_signal\_attr\_init([sns\_signal\_attr](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv415sns_signal_attr) \*signal\_attr)

    - The API to initialize signal attributes to default values. This API should be called only in big image.

- Parameters:

    - **signal\_attr** – **[inout]** Pointer to Signal Attribute structure.

- Returns:

    - - SNS\_RC\_SUCCESS: Signal Attributes initialized to defaults successfully.
- !SNS\_RC\_SUCCESS: An error occurred.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_signal\_attr\_set([sns\_signal\_attr](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv415sns_signal_attr) \*signal\_attr, [sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*sensor, sns\_handle\_signal\_cb cb, void \*user\_arg)

    - The API to set the signal attributes. This API should be called only in big image.

- Parameters:

    - - **signal\_attr** – **[inout]** Pointer to Signal Attributes passed by the client.
- **sensor** – **[in]** Client Sensor pointer.
- **cb** – **[in]** Callback function to be called when signal is set.
- **user\_arg** – **[in]** Pointer to user argument.

- Returns:

    - - SNS\_RC\_SUCCESS: Signal attributes set successfully.
- !SNS\_RC\_SUCCESS: An error occurred.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_signal\_register([sns\_signal\_attr](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv415sns_signal_attr) \*signal\_attr, sns\_signal\_handle \*\*handle)

    - The API to register for the signal callback function This API should be called only in big image.

- Parameters:

    - - **signal\_attr** – **[in]** Initalized signal attribute structure pointer.
- **handle** – **[out]** Address of pointer to handle. Client should set the signal using this handle.

- Returns:

    - - SNS\_RC\_SUCCESS: Signal registered successfully.
- !SNS\_RC\_SUCCESS: An error occurred.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_signal\_unregister(sns\_signal\_handle \*\*handle)

    - The API to unregister signal. This API should be called only in big image.

- Parameters:

    - **handle** – **[in]** Address of pointer to registered handle.

- Returns:

    - - SNS\_RC\_SUCCESS: Signal unregistered successfully.
- !SNS\_RC\_SUCCESS: An error occurred.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_signal\_set(sns\_signal\_handle \*handle)

    - The API to set registered signal. When the signal is set, signal utility will call the registered cb function.

- Parameters:

    - **handle** – **[in]** Registered handle pointer.

- Returns:

    - - SNS\_RC\_SUCCESS: Signal set successfully.
- !SNS\_RC\_SUCCESS: An error occurred.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_signal\_get\_mask(sns\_signal\_handle \*handle, uint32\_t \*signal\_mask)

    - The API to get the registered signal mask.

- Parameters:

    - - **handle** – **[in]** Registered handle pointer.
- **signal\_mask** – **[out]** Buffer to store signal\_mask.

- Returns:

    - - SNS\_RC\_SUCCESS: Signal mask get successfully.
- !SNS\_RC\_SUCCESS: An error occurred.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_signal\_get\_thread\_signal(sns\_signal\_handle \*handle, [sns\_osa\_thread\_signal](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv421sns_osa_thread_signal) \*\*thread\_signal)

    - The API to get the pointer to the registered thread signal.

- Parameters:

    - - **handle** – **[in]** Registered handle pointer.
- **thread\_signal** – **[out]** Buffer to store pointer to thread\_signal.

- Returns:

    - - SNS\_RC\_SUCCESS: Thread signal pointer get successfully.
- !SNS\_RC\_SUCCESS: An error occurred.

## Single Link List

A single linked list interface.

- struct sns\_sl\_list\_item

    - List item consists of only a next pointer. Note that an item pointer is not added here to reduce memory footprint. Any structure that needs to be inserted into a sl\_list, is required to keep this [sns\_sl\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structsns__sl__list__item) as the first item in the structure.

Public Members

- struct [sns\_sl\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv416sns_sl_list_item) \*next

    - Pointer to next item on the list; nullptr if the tail

- struct sns\_sl\_list

    - Contains head tail and count of the singly linked list.

Public Members

- [sns\_sl\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv416sns_sl_list_item) \*head

    - Pointer to Head of the list; may be null

- [sns\_sl\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv416sns_sl_list_item) \*tail

    - Pointer to Tail of the list; may be null

- uint32\_t cnt

    - Number of entries presently collected within this list

- struct sns\_sl\_list\_iter

    - An accessor structure for the singly linked List. All mutator and accessor actions to a sl\_list must be done through the Iterator interface.

Public Members

- [sns\_sl\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv416sns_sl_list_item) \*curr

    - Current Entry of this iterator. May be NULL.

- [sns\_sl\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv416sns_sl_list_item) \*prev

    - Previous Entry of this iterator. May be NULL.

- [sns\_sl\_list](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411sns_sl_list) \*list

    - List over which this iterates

Functions

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_sl\_list\_init([sns\_sl\_list](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411sns_sl_list) \*list)

    - Initialize a list to its empty state.

- Parameters:

    - **list** – **[in]** This list.

- Returns:

    - - SNS\_RC\_SUCCESS:

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_sl\_list\_item\_init([sns\_sl\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv416sns_sl_list_item) \*item, void \*data)

    - Initialize a list item.

- Parameters:

    - - **item** – **[in]** List entry item in this list
- **data** – **[in]** Data in this list item

- Returns:

    - - SNS\_RC\_SUCCESS:

- [sns\_sl\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv416sns_sl_list_item) \*sns\_sl\_list\_iter\_init([sns\_sl\_list\_iter](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv416sns_sl_list_iter) \*iter, [sns\_sl\_list](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv411sns_sl_list) \*list, bool head)

    - Create an iterator for this List.

- Parameters:

    - - **iter** – **[in]** Iterator for this list.
- **list** – **[in]** This list.
- **head** – **[in]** Initialize iterator to first item in the list; otherwise last.

- Returns:

    - - First item: If head is True.
- Last Item: If head is False.
- NULL: If list is empty.

- [sns\_sl\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv416sns_sl_list_item) \*sns\_sl\_list\_iter\_advance([sns\_sl\_list\_iter](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv416sns_sl_list_iter) \*iter)

    - Advance the iterator to the next item in the list. Remain at NULL, if iterator already reached the end of list.

- Parameters:

    - **iter** – **[in]** Iterator for this list

- Returns:

    - - Next item in this list.
- NULL: If no more items are present in this list.

- [sns\_sl\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv416sns_sl_list_item) \*sns\_sl\_list\_iter\_curr([sns\_sl\_list\_iter](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv416sns_sl_list_iter) \*iter)

    - Return the current list\_item.Will be NULL if current item is invalid. E.g. If the list is empty, or has iterated past the head/tail.

- Parameters:

    - **iter** – **[in]** Iterator for this list.

- Returns:

    - - Current item in this list.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_sl\_list\_iter\_insert([sns\_sl\_list\_iter](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv416sns_sl_list_iter) \*iter, struct [sns\_sl\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv416sns_sl_list_item) \*item, bool after)

    - Add this item to the specified List; advance iterator only if the List was previously empty.

- Parameters:

    - - **iter** – **[in]** Iterator for this list.
- **item** – **[in]** Item to be inserted in this list.
- **after** – **[in]** If true insert after current item, false enter before.

- Returns:

    - - SNS\_RC\_SUCCESS

- [sns\_sl\_list\_item](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv416sns_sl_list_item) \*sns\_sl\_list\_iter\_remove([sns\_sl\_list\_iter](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv416sns_sl_list_iter) \*iter)

    - Remove the current Entry. Advance iterator to next; if end of list is reached, Stay at the end.Remove after the end of the list is ignored.

- Parameters:

    - **iter** – **[in]** Iterator for this list.

- Returns:

    - - Item removed from this List.

- uint32\_t sns\_sl\_list\_iter\_len([sns\_sl\_list\_iter](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv416sns_sl_list_iter) \*iter)

    - Return the current length of the associated List.

- Parameters:

    - **iter** – **[in]** Iterator for this list.

- Returns:

    - - uint32\_t: Length of this list.

- void \*sns\_sl\_list\_iter\_get\_curr\_data([sns\_sl\_list\_iter](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv416sns_sl_list_iter) \*iter)

    - Return a pointer to the data associated with the current list item.

Note

This is equivalent to the operation: sns\_sl\_list\_iter\_curr(iter)

- Parameters:

    - **iter** – **[in]** Iterator for this list.

- Returns:

    - - Data pointer: To the current item in this list.

## Thread utilization

This file contains the definitions of functions that are used to calculate thread utilization.

Enums

- enum sns\_thread\_util\_mode

    - Mode to control if we need to stop or start computation.

*Values:*

- enumerator STOP\_COMPUTE

    - 

- enumerator START\_COMPUTE

    -

- struct sns\_thread\_utilization

    - Structure containing information about a particular thread utilization.

Public Members

- sns\_time total\_time

    - Total (active + idle) time.

- sns\_time active\_time

    - Active time: used for thread utilization calculation.

- sns\_time start\_time

    - Start time.

- sns\_time prev\_start\_time

    - Previous start time.

- sns\_time start\_active\_time

    - start active time.

- uint32\_t thread\_utilization\_percent

    - Thread utilization in percent.

- bool is\_thread\_active

    - Flag indicating if thread is currently running.

- bool is\_thread\_monitored

    - Flag indicating if thread is being monitored.

Functions

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_thread\_utilization\_init(void)

    - The API to initialize Sensor thread utilization utility.

@ret

- **Parameters**
    - None.

- Return values:

    - - **SNS\_RC\_SUCCESS** – Success
- **SNS\_RC\_FAILED** – Failed

- void sns\_thread\_utilization\_compute(sns\_osa\_thread \*thread, [sns\_thread\_util\_mode](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv420sns_thread_util_mode) mode)

    - Compute per-thread utilization; used to determine appropriate frequency voting.

- Parameters:

    - - **thread** – **[in]** Pointer to OSA thread object.
- **mode** – **[in]** Stop or start computing thread utilization.

- Returns:

    - - None.

- void sns\_thread\_utilization\_set\_monitor\_flag(sns\_osa\_thread \*thread, bool value)

    - Update flag to indicate whether current thread should be monitored by other threads.

- Parameters:

    - - **thread** – **[in]** Pointer to OSA thread object.
- **value** – **[in]** Value to set is\_thread\_monitored flag.

- Returns:

    - - None.

- void sns\_thread\_utilization\_enable(bool enable)

    - The API to enable / disable thread utilization monitor.

- Parameters:

    - **enable** – **[in]** True: Enable thread utilization monitor False: Disable thread utilization monitor

- Returns:

    - - None.

## Watchdog

Watchdog API.

Defines

- SNS\_WATCHDOG\_TIMEOUT\_IN\_SEC

    - 

- SNS\_WATCHDOG\_INVALID\_INDEX

    -

- struct sns\_watchdog\_voter

    - Structure holding parameters required for watchdog index and time out by each thread.

Public Members

- int8\_t wd\_voter\_idx

    - Watchdog voter index.

- int16\_t wd\_timeout\_in\_sec

    - Watchdog timeout in seconds.

- struct sns\_watchdog\_info

    - Structure holding information about the watchdog.

Public Members

- int32\_t voter\_type

    - 

- int32\_t timeout\_in\_sec

    -

Functions

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_watchdog\_init(void)

    - Invoked once at boot to initialize watchdog operation.

- Returns:

    - - SNS\_RC\_SUCCESS: Initialized successfully.
- !SNS\_RC\_SUCCESS: An error occurred.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_watchdog\_register(int8\_t \*voter\_idx)

    - Registers the given thread as a watchdog voter.

- Parameters:

    - **voter\_idx** – **[out]** Voter’s index.

- Returns:

    - - SNS\_RC\_SUCCESS: Voter registered successfully.
- !SNS\_RC\_SUCCESS: An error occurred.

- void sns\_watchdog\_deregister(int8\_t \*voter\_idx)

    - Deregisters the given watchdog voter index.

- Parameters:

    - **voter\_idx** – **[in]** Pointer to watchdog voter index,

- Returns:

    - - None.

- void sns\_watchdog\_vote\_start(int8\_t voter\_idx, int16\_t wd\_timeout\_in\_sec)

    - The given voter is voting to start watchdog operation.

- Parameters:

    - - **voter\_idx** – **[in]** A watchdog voter index.
- **wd\_timeout\_in\_sec** – **[in]** Timeout period for this watchdog voter.

- Returns:

    - - None.

- void sns\_watchdog\_vote\_restart(int8\_t voter\_idx, int16\_t wd\_timeout\_in\_sec)

    - Restarts the given voter’s watchdog timeout.

- Parameters:

    - - **voter\_idx** – **[in]** A watchdog voter index.
- **wd\_timeout\_in\_sec** – **[in]** Timeout period for this watchdog voter.

- Returns:

    - - None.

- void sns\_watchdog\_vote\_stop(int8\_t voter\_idx)

    - The given voter is voting to stop watchdog operation.

- Parameters:

    - **voter\_idx** – **[in]** A watchdog voter index.

- Returns:

    - - None.

- void sns\_watchdog\_voter\_info(int8\_t voter\_idx, [sns\_watchdog\_info](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv417sns_watchdog_info) \*wd\_voter\_info)

    - Retrieves information about the given watchdog voter. This function provides the caller with the current state of the watchdog voter, including its type and timeout period.

- Parameters:

    - - **voter\_idx** – **[in]** A watchdog voter index.
- **wd\_voter\_info** – **[out]** A pointer to a [sns\_watchdog\_info](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structsns__watchdog__info) structure that will be populated with the voter’s information.

- Returns:

    - - None.

Last Published: Jul 14, 2025

[Previous Topic
Framework](https://docs.qualcomm.com/bundle/publicresource/80-P9361-100/topics/index_framework.md)