Modules common API

The Modules common API provides the functionality to administer mechanisms in the application architecture, and consist of functions that are shared between modules. The API supports the following functionalities:

API documentation

Header file: asset_tracker_v2/src/modules/modules_common.h
Source files: asset_tracker_v2/src/modules_common.c
group modules_common

A Library that exposes generic functionality shared between modules.

Defines

IS_EVENT(_ptr, _mod, _evt)

Macro that checks if an event is of a certain type.

Parameters:
  • _ptr – Name of module message struct variable.

  • _mod – Name of module that the event corresponds to.

  • _evt – Name of the event.

Returns:

true if the event matches the event checked for, otherwise false.

SEND_EVENT(_mod, _type)

Macro used to submit an event.

Parameters:
  • _mod – Name of module that the event corresponds to.

  • _type – Name of the type of event.

SEND_ERROR(_mod, _type, _error_code)

Macro used to submit an error event.

Parameters:
  • _mod – Name of module that the event corresponds to.

  • _type – Name of the type of error event.

  • _error_code – Error code.

SEND_SHUTDOWN_ACK(_mod, _type, _id)

Macro used to submit a shutdown event.

Parameters:
  • _mod – Name of module that the event corresponds to.

  • _type – Name of the type of shutdown event.

  • _id – ID of the module that acknowledges the shutdown.

Functions

void module_purge_queue(struct module_data *module)

Purge a module’s queue.

Parameters:
  • module[in] Pointer to a structure containing module metadata.

Returns:

0 if successful, otherwise a negative error code.

int module_get_next_msg(struct module_data *module, void *msg)

Get the next message in a module’s queue.

Parameters:
  • module[in] Pointer to a structure containing module metadata.

  • msg[out] Pointer to a message buffer that the output will be written to.

Returns:

0 if successful, otherwise a negative error code.

int module_enqueue_msg(struct module_data *module, void *msg)

Enqueue message to a module’s queue.

Parameters:
  • module[in] Pointer to a structure containing module metadata.

  • msg[in] Pointer to a message that will be enqueued.

Returns:

0 if successful, otherwise a negative error code.

bool modules_shutdown_register(uint32_t id_reg)

Register that a module has performed a graceful shutdown.

Parameters:
  • id_reg[in] Identifier of module.

Returns:

true If this API has been called for all modules supporting graceful shutdown in the application.

int module_start(struct module_data *module)

Register and start a module.

Parameters:
  • module[in] Pointer to a structure containing module metadata.

Returns:

0 if successful, otherwise a negative error code.

uint32_t module_active_count_get(void)

Get the number of active modules in the application.

Returns:

Number of active modules in the application.

struct module_data
#include <modules_common.h>

Structure that contains module metadata.