nRF5 SDK for Mesh v4.1.0
Data Structures | Macros | Typedefs | Enumerations | Functions
Common APIs for models.

Contains common defines, structures, and functions used by the Mesh Models. More...

Data Structures

struct  model_transition_t
 Generic Transition parameters for the model messages. More...
 
struct  tid_tracker_t
 Structure for tracking TID expiry for the models. More...
 
struct  model_timer_t
 Structure for model timers. More...
 

Macros

#define LIGHT_LIGHTNESS_SETUP_SERVER_INSTANCES_MAX   (0)
 The number of the Light Lightness Setup Server instances used by the application.
 
#define LIGHT_LC_SETUP_SERVER_INSTANCES_MAX   (0)
 The number of the Light LC Setup Server instances used by the application.
 
#define LIGHT_CTL_SETUP_SERVER_INSTANCES_MAX   (0)
 The number of the Light CTL Setup Server instances used by the application.
 
#define MESH_APP_MODEL_COMMON_ID   (0x0001)
 Model common record entry ID.
 
#define MESH_APP_MODEL_LIGHT_LIGHTNESS_ID_START   (0x1000)
 Start of Light Lightness Setup Server record entry IDs.
 
#define MESH_APP_MODEL_LIGHT_LIGHTNESS_ID_END   (0x10FF)
 End of Light Lightness Setup Server record entry IDs.
 
#define MESH_APP_MODEL_LIGHT_LC_SERVER_ID_START   (0x1100)
 Start of LC Setup Server record entry IDs.
 
#define MESH_APP_MODEL_LIGHT_LC_SERVER_ID_END   (0x12FF)
 End of Light LC Setup Server record entry IDs.
 
#define MESH_APP_MODEL_LIGHT_CTL_SERVER_ID_START   (0x1300)
 Start of Light CTL Setup Server record entry IDs.
 
#define MESH_APP_MODEL_LIGHT_CTL_SERVER_ID_END   (0x13FF)
 End of Light CTL Setup Server record entry IDs.
 
#define MODEL_TRANSITION_TIME_UNKNOWN   (UINT32_MAX)
 Transition time value to indicate unknown transition time.
 
#define MODEL_ACKNOWLEDGED_TRANSACTION_TIMEOUT   (SEC_TO_US(30))
 Transition time value to indicate the default transition time should be used.
 
#define TRANSITION_STEP_MIN_MS   (45)
 Product-specific transition limitations to align transition data regarding product abilities. More...
 
#define TRANSITION_TIME_STEP_100MS_MAX   (6200ul)
 Maximum value of transition time (in ms) possible in steps of 100 ms.
 
#define TRANSITION_TIME_STEP_1S_MAX   (SEC_TO_MS(62ul))
 Maximum value of transition time (in ms) possible in steps of 1 s.
 
#define TRANSITION_TIME_STEP_10S_MAX   (SEC_TO_MS(620ul))
 Maximum value of transition time (in ms) possible in steps of 10 s.
 
#define TRANSITION_TIME_STEP_10M_MAX   (MIN_TO_MS(620ul))
 Maximum value of transition time (in ms) possible in steps of 10 min.
 
#define TRANSITION_TIME_MAX   (0x3E)
 Max value of encoded transition time step value.
 
#define TRANSITION_TIME_UNKNOWN   (0x3F)
 Unknown encoded transition time value.
 
#define TRANSITION_TIME_MAX_MS   (TRANSITION_TIME_STEP_10M_MAX)
 Maximum permissible transition time in milliseconds.
 
#define DELAY_TIME_STEP_FACTOR_MS   (5)
 Delay field step factor in milliseconds.
 
#define DELAY_TIME_STEP_MAX   (0xFF)
 Maximum encoded value of the delay field.
 
#define DELAY_TIME_MAX_MS   (DELAY_TIME_STEP_MAX * DELAY_TIME_STEP_FACTOR_MS)
 Maximum permisible delay time in milliseconds.
 
#define MODEL_TIMER_TIMEOUT_MIN_TICKS   (APP_TIMER_TICKS(1))
 Minimum permissible timeout (1 ms) in RTC ticks for model timer.
 
#define MODEL_TIMER_TIMEOUT_MIN_US   (MODEL_TIMER_PERIOD_US_GET(MODEL_TIMER_TIMEOUT_MIN_TICKS))
 Minimum permissible timeout in milliseconds for model timer.
 
#define MODEL_TIMER_MAX_TIMEOUT_TICKS   (APP_TIMER_MAX_CNT_VAL)
 Maximum timout ticks, as per app_timer.h.
 
#define MODEL_TIMER_PERIOD_MS_GET(TICKS)   ((1000ul * (TICKS)) / APP_TIMER_CLOCK_FREQ)
 Get period in milliseconds for given number of ticks.
 
#define MODEL_TIMER_PERIOD_US_GET(TICKS)   ((1000ul * 1000ul * (TICKS)) / APP_TIMER_CLOCK_FREQ)
 Get period in microseconds for given number of ticks.
 
#define MODEL_TIMER_TICKS_GET_MS(MS_TIME)
 Get number of model timer ticks for the given time period in milliseconds. More...
 
#define MODEL_TIMER_TICKS_GET_US(US_TIME)
 Get number of model timer ticks for the given time period in microseconds. More...
 

Typedefs

typedef void(* model_timer_cb_t) (void *p_context)
 

Enumerations

enum  model_timer_mode_t { MODEL_TIMER_MODE_SINGLE_SHOT, MODEL_TIMER_MODE_REPEATED }
 Timer modes. More...
 

Functions

uint32_t model_transition_time_decode (uint8_t enc_transition_time)
 Gets the decoded value of the transition time in milliseconds. More...
 
uint8_t model_transition_time_encode (uint32_t transition_time)
 Gets the encoded value of the transition time as specified in the Mesh Model Specification (MshMDLv1.0.1) Note that the provided value will be rounded down to the nearest possible representation. More...
 
bool model_transition_time_is_valid (uint8_t enc_transition_time)
 Validates the given transition time value. More...
 
uint32_t model_delay_decode (uint8_t enc_delay)
 Gets the decoded value of the delay time in milliseconds. More...
 
uint8_t model_delay_encode (uint32_t delay)
 Gets the encoded value of the delay time as specified in the Mesh Model Specification (MshMDLv1.0.1). More...
 
bool model_tid_validate (tid_tracker_t *p_tid_tracker, const access_message_rx_meta_t *p_meta, uint32_t message_id, uint8_t tid)
 Checks if the given message parameters represents a new transaction. More...
 
bool model_transaction_is_new (tid_tracker_t *p_tid_tracker)
 Checks if given TID tracker instance has recorded a new transaction. More...
 
uint32_t model_timer_schedule (model_timer_t *p_timer)
 Schedules a model timer for a given interval. More...
 
void model_timer_abort (model_timer_t *p_timer)
 Aborts the currently scheduled timer. More...
 
uint64_t model_timer_elapsed_ticks_get (model_timer_t *p_timer)
 Returns the total elapsed rtc ticks since the last call to model_timer_schedule() API. More...
 
uint32_t model_timer_create (model_timer_t *p_timer)
 Creates a model timer. More...
 
void model_common_init (void)
 Initialize persistent memory of all models used. More...
 
uint32_t model_common_config_apply (void)
 Apply data loaded from the mesh configuration system into persistent memory structures. More...
 

Detailed Description

Contains common defines, structures, and functions used by the Mesh Models.

Macro Definition Documentation

◆ TRANSITION_STEP_MIN_MS

#define TRANSITION_STEP_MIN_MS   (45)

Product-specific transition limitations to align transition data regarding product abilities.

Definition at line 103 of file model_common.h.

◆ MODEL_TIMER_TICKS_GET_MS

#define MODEL_TIMER_TICKS_GET_MS (   MS_TIME)
Value:
((uint64_t)ROUNDED_DIV((MS_TIME) * (uint64_t)APP_TIMER_CLOCK_FREQ, \
1000 * (APP_TIMER_CONFIG_RTC_FREQUENCY + 1)))

Get number of model timer ticks for the given time period in milliseconds.

Definition at line 138 of file model_common.h.

◆ MODEL_TIMER_TICKS_GET_US

#define MODEL_TIMER_TICKS_GET_US (   US_TIME)
Value:
((uint64_t)ROUNDED_DIV( \
(US_TIME) * (uint64_t)APP_TIMER_CLOCK_FREQ, \
1000 * 1000 * (APP_TIMER_CONFIG_RTC_FREQUENCY + 1)))

Get number of model timer ticks for the given time period in microseconds.

Definition at line 142 of file model_common.h.

Enumeration Type Documentation

◆ model_timer_mode_t

Timer modes.

Enumerator
MODEL_TIMER_MODE_SINGLE_SHOT 

The timer will expire only once.

MODEL_TIMER_MODE_REPEATED 

The timer will restart each time it expires.

Definition at line 172 of file model_common.h.

Function Documentation

◆ model_transition_time_decode()

uint32_t model_transition_time_decode ( uint8_t  enc_transition_time)

Gets the decoded value of the transition time in milliseconds.

Parameters
[in]enc_transition_timeEncoded value of the transition time as specified in the Mesh Model Specification (MshMDLv1.0.1).
Returns
Transition time in milliseconds.

◆ model_transition_time_encode()

uint8_t model_transition_time_encode ( uint32_t  transition_time)

Gets the encoded value of the transition time as specified in the Mesh Model Specification (MshMDLv1.0.1) Note that the provided value will be rounded down to the nearest possible representation.

Parameters
[in]transition_timeTransition time in milliseconds.
Returns
Encoded value of the transition time as specified in the Mesh Model Specification (MshMDLv1.0.1).

◆ model_transition_time_is_valid()

bool model_transition_time_is_valid ( uint8_t  enc_transition_time)

Validates the given transition time value.

Parameters
[in]enc_transition_timeEncoded transition time value
Return values
TrueIf encoded transition time is a valid value for the models.
FalseIf encoded transition time is invalid for the models and cannot be set.

◆ model_delay_decode()

uint32_t model_delay_decode ( uint8_t  enc_delay)

Gets the decoded value of the delay time in milliseconds.

Parameters
[in]enc_delayEncoded value of the delay time as specified in the Mesh Model Specification (MshMDLv1.0.1).
Returns
delay time in milliseconds.

◆ model_delay_encode()

uint8_t model_delay_encode ( uint32_t  delay)

Gets the encoded value of the delay time as specified in the Mesh Model Specification (MshMDLv1.0.1).

Note that the provided value will be rounded down to the nearest possible representation.

Parameters
[in]delayDelay time in milliseconds.
Returns
Encoded value of the delay time as specified in the Mesh Model Specification (MshMDLv1.0.1).

◆ model_tid_validate()

bool model_tid_validate ( tid_tracker_t p_tid_tracker,
const access_message_rx_meta_t p_meta,
uint32_t  message_id,
uint8_t  tid 
)

Checks if the given message parameters represents a new transaction.

The transaction is considered either new or same as previous in the context of a given message ID, TID, access meta data (source address and destination address) and timeout of 6 seconds as specified by Mesh Model Specification (MshMDLv1.0.1). This API is used by the model interfaces to reject duplicate transactions.

Note
User application should use model_transaction_is_new() API to check is the received message callback represents a new transaction.
Parameters
[in]p_tid_trackerPointer to the tid tracker structure.
[in]p_metaAccess message metadata containing source and destination addresses.
[in]message_idAny kind of unique identifier (e.g opcode) for a given type of message.
[in]tidReceived TID value.
Return values
TrueIf transaction is new.
FalseIf transaction is same as the previous transaction.

◆ model_transaction_is_new()

bool model_transaction_is_new ( tid_tracker_t p_tid_tracker)

Checks if given TID tracker instance has recorded a new transaction.

This API can be used by the user application to determine if the received message callback represents a new transaction.

Note
The model_tid_validate API is always called by the model interface internally to keep tid_tracker_t context updated.
Parameters
[in]p_tid_trackerPointer to the tid tracker structure.
Return values
TrueIf transaction is new.
FalseIf transaction is same as the previous transaction.

◆ model_timer_schedule()

uint32_t model_timer_schedule ( model_timer_t p_timer)

Schedules a model timer for a given interval.

This API uses APP_TIMER internally for the managing timeouts. The timing resolution is equal to the resolution offered by period corresponding to APP_TIMER_CLOCK_FREQ. The minimum allowed timeout in ticks is specified by MODEL_TIMER_TIMEOUT_MIN_TICKS.

Parameters
[in]p_timerPointer to the model_timer_t structure.
Return values
NRF_ERROR_NULLIf p_timer or the timer callback is null.
NRF_ERROR_INVALID_PARAMIf specified timout is too short.

◆ model_timer_abort()

void model_timer_abort ( model_timer_t p_timer)

Aborts the currently scheduled timer.

Parameters
[in]p_timerPointer to the model_timer_t structure

◆ model_timer_elapsed_ticks_get()

uint64_t model_timer_elapsed_ticks_get ( model_timer_t p_timer)

Returns the total elapsed rtc ticks since the last call to model_timer_schedule() API.

Parameters
[in]p_timerPointer to the model_timer_t structure.
Return values
0If timer is not running.
ticksTotal elapsed rtc ticks, since the last call to model_timer_schedule() API.

◆ model_timer_create()

uint32_t model_timer_create ( model_timer_t p_timer)

Creates a model timer.

This model timer implementation uses App Timer which is based on RTC. The timing parameters of this model timer are specified in number of ticks.

Parameters
[in]p_timerPointer to model_timer_t structure.
Return values
NRF_ERROR_NULLIf p_timer is NULL.
NRF_SUCCESSIf the timer was successfully created.
NRF_ERROR_INVALID_PARAMIf a parameter was invalid.
NRF_ERROR_INVALID_STATEIf the application timer module has not been initialized or the timer is running.

◆ model_common_init()

void model_common_init ( void  )

Initialize persistent memory of all models used.

Note
If models are not linked in the model will not be initialized and this function will call a a dummy funcion for those models.

◆ model_common_config_apply()

uint32_t model_common_config_apply ( void  )

Apply data loaded from the mesh configuration system into persistent memory structures.

Note
Actual metadata is restored automatically if it was not found or if read out data is not equal configuration parameters.
Return values
NRF_ERROR_NOT_FOUNDPersistent memory metadata was not found, stored default values.
NRF_ERROR_INVALID_DATAData stored in the persistent memory was corrupted, old data was cleared and restored with default values.
NRF_SUCCESSPresistent memory data applied successfully.

Documentation feedback | Developer Zone | Subscribe | Updated