38 #ifndef MODEL_COMMON_H__ 39 #define MODEL_COMMON_H__ 43 #include "nrf_mesh_config_core.h" 45 #include "app_timer.h" 46 #include "timer_scheduler.h" 59 #ifndef LIGHT_LIGHTNESS_SETUP_SERVER_INSTANCES_MAX 60 #define LIGHT_LIGHTNESS_SETUP_SERVER_INSTANCES_MAX (0) 66 #ifndef LIGHT_LC_SETUP_SERVER_INSTANCES_MAX 67 #define LIGHT_LC_SETUP_SERVER_INSTANCES_MAX (0) 73 #ifndef LIGHT_CTL_SETUP_SERVER_INSTANCES_MAX 74 #define LIGHT_CTL_SETUP_SERVER_INSTANCES_MAX (0) 78 #define MESH_APP_MODEL_COMMON_ID (0x0001) 80 #define MESH_APP_MODEL_LIGHT_LIGHTNESS_ID_START (0x1000) 82 #define MESH_APP_MODEL_LIGHT_LIGHTNESS_ID_END (0x10FF) 84 #define MESH_APP_MODEL_LIGHT_LC_SERVER_ID_START (0x1100) 86 #define MESH_APP_MODEL_LIGHT_LC_SERVER_ID_END (0x12FF) 88 #define MESH_APP_MODEL_LIGHT_CTL_SERVER_ID_START (0x1300) 90 #define MESH_APP_MODEL_LIGHT_CTL_SERVER_ID_END (0x13FF) 93 #define MODEL_TRANSITION_TIME_UNKNOWN (UINT32_MAX) 97 #ifndef MODEL_ACKNOWLEDGED_TRANSACTION_TIMEOUT 98 #define MODEL_ACKNOWLEDGED_TRANSACTION_TIMEOUT (SEC_TO_US(30)) 102 #ifndef TRANSITION_STEP_MIN_MS 103 #define TRANSITION_STEP_MIN_MS (45) 106 #define TRANSITION_TIME_STEP_100MS_MAX (6200ul) 108 #define TRANSITION_TIME_STEP_1S_MAX (SEC_TO_MS(62ul)) 110 #define TRANSITION_TIME_STEP_10S_MAX (SEC_TO_MS(620ul)) 112 #define TRANSITION_TIME_STEP_10M_MAX (MIN_TO_MS(620ul)) 114 #define TRANSITION_TIME_MAX (0x3E) 116 #define TRANSITION_TIME_UNKNOWN (0x3F) 118 #define TRANSITION_TIME_MAX_MS (TRANSITION_TIME_STEP_10M_MAX) 121 #define DELAY_TIME_STEP_FACTOR_MS (5) 123 #define DELAY_TIME_STEP_MAX (0xFF) 125 #define DELAY_TIME_MAX_MS (DELAY_TIME_STEP_MAX * DELAY_TIME_STEP_FACTOR_MS) 128 #define MODEL_TIMER_TIMEOUT_MIN_TICKS (APP_TIMER_TICKS(1)) 130 #define MODEL_TIMER_TIMEOUT_MIN_US (MODEL_TIMER_PERIOD_US_GET(MODEL_TIMER_TIMEOUT_MIN_TICKS)) 132 #define MODEL_TIMER_MAX_TIMEOUT_TICKS (APP_TIMER_MAX_CNT_VAL) 134 #define MODEL_TIMER_PERIOD_MS_GET(TICKS) ((1000ul * (TICKS)) / APP_TIMER_CLOCK_FREQ) 136 #define MODEL_TIMER_PERIOD_US_GET(TICKS) ((1000ul * 1000ul * (TICKS)) / APP_TIMER_CLOCK_FREQ) 138 #define MODEL_TIMER_TICKS_GET_MS(MS_TIME) \ 139 ((uint64_t)ROUNDED_DIV((MS_TIME) * (uint64_t)APP_TIMER_CLOCK_FREQ, \ 140 1000 * (APP_TIMER_CONFIG_RTC_FREQUENCY + 1))) 142 #define MODEL_TIMER_TICKS_GET_US(US_TIME) \ 143 ((uint64_t)ROUNDED_DIV( \ 144 (US_TIME) * (uint64_t)APP_TIMER_CLOCK_FREQ, \ 145 1000 * 1000 * (APP_TIMER_CONFIG_RTC_FREQUENCY + 1))) 180 typedef void(*model_timer_cb_t)(
void * p_context);
277 uint32_t message_id, uint8_t tid);
uint32_t transition_time_ms
Transition time value in milliseconds.
uint32_t model_transition_time_decode(uint8_t enc_transition_time)
Gets the decoded value of the transition time in milliseconds.
Structure for tracking TID expiry for the models.
uint32_t delay_ms
Message execution delay in milliseconds.
uint8_t model_delay_encode(uint32_t delay)
Gets the encoded value of the delay time as specified in the Mesh Model Specification (MshMDLv1...
bool model_transaction_is_new(tid_tracker_t *p_tid_tracker)
Checks if given TID tracker instance has recorded a new transaction.
The timer will restart each time it expires.
Structure for model timers.
void model_common_init(void)
Initialize persistent memory of all models used.
The timer will expire only once.
bool cb_active
Internal variable.
uint32_t message_id
Previously received Opcode.
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...
uint32_t model_delay_decode(uint8_t enc_delay)
Gets the decoded value of the delay time in milliseconds.
uint8_t old_tid
Previously received TID.
timer_event_t tid_expiry_timer
Expiration timer instance.
uint32_t model_common_config_apply(void)
Apply data loaded from the mesh configuration system into persistent memory structures.
app_timer_id_t const * p_timer_id
APP timer instance pointer.
uint16_t src
Source address.
void * p_context
context pointer for the timer callback
uint32_t model_timer_create(model_timer_t *p_timer)
Creates a model timer.
bool new_transaction
New transaction indicator flag.
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...
uint32_t last_rtc_stamp
Internal variable.
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.
model_timer_mode_t mode
Timer mode : Single shot, repeated.
bool model_transition_time_is_valid(uint8_t enc_transition_time)
Validates the given transition time value.
uint64_t timeout_rtc_ticks
Timeout in number of RTC ticks.
uint64_t total_rtc_ticks
Total rtc ticks since beginning of the timer.
Generic Transition parameters for the model messages.
uint32_t model_timer_schedule(model_timer_t *p_timer)
Schedules a model timer for a given interval.
uint64_t remaining_ticks
Internal variable.
model_timer_mode_t
Timer modes.
void model_timer_abort(model_timer_t *p_timer)
Aborts the currently scheduled timer.
uint16_t dst
Destination address.