summaryrefslogtreecommitdiffstats
path: root/ucs2-lib/src/ucs_rsm.c
blob: bb407430e8d261da2e6f2acf96e1ec7d73e82e00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
/*------------------------------------------------------------------------------------------------*/
/* UNICENS V2.1.0-3491                                                                            */
/* Copyright (c) 2017 Microchip Technology Germany II GmbH & Co. KG.                              */
/*                                                                                                */
/* This program is free software: you can redistribute it and/or modify                           */
/* it under the terms of the GNU General Public License as published by                           */
/* the Free Software Foundation, either version 2 of the License, or                              */
/* (at your option) any later version.                                                            */
/*                                                                                                */
/* This program is distributed in the hope that it will be useful,                                */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of                                 */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                  */
/* GNU General Public License for more details.                                                   */
/*                                                                                                */
/* You should have received a copy of the GNU General Public License                              */
/* along with this program.  If not, see <http://www.gnu.org/licenses/>.                          */
/*                                                                                                */
/* You may also obtain this software under a propriety license from Microchip.                    */
/* Please contact Microchip for further information.                                              */
/*------------------------------------------------------------------------------------------------*/

/*!
 * \file
 * \brief Implementation of the Sync Management.
 *
 * \cond UCS_INTERNAL_DOC
 * \addtogroup G_RSM
 * @{
 */

/*------------------------------------------------------------------------------------------------*/
/* Includes                                                                                       */
/*------------------------------------------------------------------------------------------------*/
#include "ucs_rsm.h"

/*------------------------------------------------------------------------------------------------*/
/* Service parameters                                                                             */
/*------------------------------------------------------------------------------------------------*/
/*! Priority of the RSM service used by scheduler */
static const uint8_t RSM_SRV_PRIO = 250U;   /* parasoft-suppress  MISRA2004-8_7 "Value shall be part of the module, not part of a function." */
/*! \brief Event for processing one of the below tasks */
static const Srv_Event_t RSM_EVENT_PROCESS_DEV           = 0x01U;
/*! \brief Event for signaling the SyncLost event */
static const Srv_Event_t RSM_EVENT_SIG_SYNCLOST          = 0x02U;

/*------------------------------------------------------------------------------------------------*/
/* Internal Constants                                                                             */
/*------------------------------------------------------------------------------------------------*/
/*! \brief Mask for the Network Availability Info */
static const uint32_t RSM_MASK_NETWORK_AVAILABILITY = 0x0002U;
/*! \brief Mask for the Network NodeAddress Info */
static const uint32_t RSM_MASK_NETWORK_NODE_ADDRESS = 0x0010U;
/*! \brief Mask for the Network MaxPosition Info */
static const uint32_t RSM_MASK_NETWORK_MAX_POSITION = 0x0040U;

/*! \brief Invalid device node address */
static const uint16_t RSM_INVALID_NODE_ADDRESS = 0x0000U;

/*------------------------------------------------------------------------------------------------*/
/* Internal prototypes                                                                            */
/*------------------------------------------------------------------------------------------------*/
static void Rsm_Service (void *self);
static void Rsm_ProcessJob (CRemoteSyncManagement *self);
static Ucs_Return_t Rsm_SendSync (CRemoteSyncManagement *self);
static Ucs_Return_t Rsm_RequestNtfDevId (CRemoteSyncManagement *self);
static Ucs_Return_t Rsm_ClearLastNtfDevId (CRemoteSyncManagement *self);
static Ucs_Return_t Rsm_SetNotificationAll (CRemoteSyncManagement * self);
static Ucs_Return_t Rsm_SetNotificationGpio (CRemoteSyncManagement * self);
static Ucs_Return_t Rsm_ProcessDeviceJob (CRemoteSyncManagement *self);
static bool Rsm_IsLocal (CRemoteSyncManagement * self);
static void Rsm_MnsInitSucceededCb(void *self, void *event_ptr);
static void Rsm_MnsNwStatusInfosCb(void *self, void *event_ptr);
static void Rsm_SyncResultCb(void *self, void *result_ptr);
static void Rsm_MsgObjAvailCb(void *self, void *result_ptr);
static void Rsm_SignalSyncCompleted (CRemoteSyncManagement * self);
static void Rsm_SignalSyncError (CRemoteSyncManagement * self);
static void Rsm_SignalSyncLost (CRemoteSyncManagement * self);

/*------------------------------------------------------------------------------------------------*/
/* Implementation of class CRemoteSyncManager                                                     */
/*------------------------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------------------------*/
/* Initialization Methods                                                                         */
/*------------------------------------------------------------------------------------------------*/
/*! \brief Constructor of the Remote Sync Manager class.
 *  \param self        Instance pointer
 *  \param init_ptr    init data_ptr
 */
void Rsm_Ctor(CRemoteSyncManagement *self, Rsm_InitData_t *init_ptr)
{
    MISC_MEM_SET(self, 0, sizeof(CRemoteSyncManagement));

    /* Init all instances */
    self->base_ptr = init_ptr->base_ptr;
    self->inic_ptr = init_ptr->inic_ptr;
    self->net_ptr  = init_ptr->net_ptr;

    /* Init observer */
    Mobs_Ctor(&self->event_param.ucsinit_observer, self, EH_E_INIT_SUCCEEDED, &Rsm_MnsInitSucceededCb);
    Sobs_Ctor(&self->event_param.stdresult_observer, self, &Rsm_SyncResultCb);
    Obs_Ctor(&self->event_param.txavailability_observer, self, &Rsm_MsgObjAvailCb);

    /* Init event_param variables */
    self->event_param.own_device_address = RSM_INVALID_NODE_ADDRESS;

    /* Initialize Sync Management service */
    Srv_Ctor(&self->rsm_srv, RSM_SRV_PRIO, self, &Rsm_Service);
    /* Add RSM service to scheduler */
    (void)Scd_AddService(&self->base_ptr->scd, &self->rsm_srv);
    /* Add Observer for MNS initialization Result */
    Eh_AddObsrvInternalEvent(&self->base_ptr->eh, &self->event_param.ucsinit_observer);
}

/*------------------------------------------------------------------------------------------------*/
/* Service                                                                                        */
/*------------------------------------------------------------------------------------------------*/
/*! \brief Add an observer to the SyncLost Event subject
 *  \param self   Instance pointer
 *  \param obs    init data_ptr
 */
void Rsm_AddObserver(CRemoteSyncManagement * self, CObserver * obs)
{
    (void)Sub_AddObserver(&self->event_param.subject, obs);   
}

/*! \brief Removes an observer registered by Rsm_AddObserver
 *  \param self       Instance pointer
 *  \param obs_ptr    observer to be removed
 */
void Rsm_DelObserver(CRemoteSyncManagement * self, CObserver * obs_ptr)
{
    (void)Sub_RemoveObserver(&self->event_param.subject, obs_ptr);  
}

/*! \brief Synchronizes to the given device
 *  \param self                  Instance pointer
 *  \param user_data             reference to the user data that'll be attached in the sync_complete_fptr callback function 
 *  \param sync_complete_fptr    result callback function to the device to be synchronized
 *  \return Possible return values are
 *          - \c UCS_RET_ERR_API_LOCKED the API is locked. 
 *          - \c UCS_RET_SUCCESS if the transmission was started successfully
 *          - \c UCS_RET_ERR_BUFFER_OVERFLOW if no TxHandles available
 *          - \c UCS_RET_ERR_PARAM parameter exceeds its admissible range
 */
Ucs_Return_t Rsm_SyncDev(CRemoteSyncManagement * self, void* user_data, Rsm_ResultCb_t sync_complete_fptr)
{
    Ucs_Return_t result = UCS_RET_ERR_API_LOCKED;

    if (self->dev_infos.sync_state != RSM_DEV_SYNCING)
    {
        self->dev_infos.curr_user_data   = user_data;
        self->dev_infos.curr_res_cb_fptr = sync_complete_fptr;
        if (self->dev_infos.sync_state == RSM_DEV_SYNCED)
        {
            self->dev_infos.next_st = RSM_ST_SYNC_SUCC;
            Srv_SetEvent(&self->rsm_srv, RSM_EVENT_PROCESS_DEV);
            result = UCS_RET_SUCCESS;
        }
        else
        {
            if (Rsm_IsLocal(self))
            {
                self->dev_infos.next_st = RSM_ST_NTF_GPIO;
            }
            else
            {
                self->dev_infos.next_st = RSM_ST_SYNC_REQ;
            }
            result = Rsm_ProcessDeviceJob (self);
        }
    }

    return result;
}

/*! \brief Returns the state (ready or busy) of the given device.
 *  \param self   Instance pointer.
 *  \return state of the given device.
 */
Rsm_DevSyncState_t Rsm_GetDevState(CRemoteSyncManagement * self)
{
    return self->dev_infos.sync_state;
}

/*! \brief Reports SyncLost for the given RSM instance.
 *  \param self     Reference to the instance ptr
 */
void Rsm_ReportSyncLost (CRemoteSyncManagement * self)
{
    self->last_synclost_cause = RSM_SLC_CFGNOTOK;
    Srv_SetEvent(&self->rsm_srv, RSM_EVENT_SIG_SYNCLOST);
}

/*------------------------------------------------------------------------------------------------*/
/* Private Methods                                                                                */
/*------------------------------------------------------------------------------------------------*/
/*! \brief Service function of the Sync management.
 *  \param self    Instance pointer
 */
static void Rsm_Service (void *self)
{
    CRemoteSyncManagement *self_ = (CRemoteSyncManagement *)self;
    Srv_Event_t event_mask;
    Srv_GetEvent(&self_->rsm_srv, &event_mask);

    /* Handle event to process jobs within devices */
    if((event_mask & RSM_EVENT_PROCESS_DEV) == RSM_EVENT_PROCESS_DEV)
    {
        Srv_ClearEvent(&self_->rsm_srv, RSM_EVENT_PROCESS_DEV);
        Rsm_ProcessJob(self_);
    }

    /* Handle event to signal "SyncLost" */
    if((event_mask & RSM_EVENT_SIG_SYNCLOST) == RSM_EVENT_SIG_SYNCLOST)
    {
        Srv_ClearEvent(&self_->rsm_srv, RSM_EVENT_SIG_SYNCLOST);
        Rsm_SignalSyncLost(self_);
    }
}

/*! \brief  Processes the next job, if available, in a device.
 *  \param  self        Instance pointer
 */
static void Rsm_ProcessJob (CRemoteSyncManagement *self)
{
    if (self->dev_infos.next_st != RSM_ST_IDLE)
    {
        (void)Rsm_ProcessDeviceJob(self);
    }
}

/*! \brief  Processes the next job for the given device.
 *  \param  self       Instance pointer
 *  \return Possible return values are
 *          - \c UCS_RET_SUCCESS if the transmission was started successfully
 *          - \c UCS_RET_ERR_BUFFER_OVERFLOW if no TxHandles available
 *          - \c UCS_RET_ERR_API_LOCKED The INIC API is locked
 *          - \c UCS_RET_ERR_PARAM parameter exceeds its admissible range
 */
static Ucs_Return_t Rsm_ProcessDeviceJob (CRemoteSyncManagement *self)
{
    Ucs_Return_t result = UCS_RET_SUCCESS;

    switch (self->dev_infos.next_st)
    {
        case RSM_ST_SYNC_REQ:
            result = Rsm_SendSync (self);
            break;

        case RSM_ST_NTF_REQ:
            result = Rsm_RequestNtfDevId (self);
            break;

        case RSM_ST_NTF_CLEAR:
            result = Rsm_ClearLastNtfDevId (self);
            break;

        case RSM_ST_NTF_ALL:
            result = Rsm_SetNotificationAll (self);
            break;

        case RSM_ST_NTF_GPIO:
            result = Rsm_SetNotificationGpio (self);
            break;

        case RSM_ST_SYNC_SUCC:
            Rsm_SignalSyncCompleted (self);
            break;

        case RSM_ST_SYNC_ERR:
            Rsm_SignalSyncError (self);
            break;

        default:
            TR_ERROR((self->base_ptr->ucs_user_ptr, "[RSM]", "Unexpected State Transition: 0x%02X", 1U, (Rsm_StateTransition_t)(self->dev_infos.next_st)));
            break;
    }

    return result;
}

/*! \brief  Sends a Sync command to the given device.
 *  \param  self    Instance pointer
 *  \return Possible return values are
 *          - \c UCS_RET_SUCCESS if the transmission was started successfully
 *          - \c UCS_RET_ERR_BUFFER_OVERFLOW if no TxHandles available
 */
static Ucs_Return_t Rsm_SendSync (CRemoteSyncManagement *self)
{
    Ucs_Return_t result;

    result = Inic_DeviceSync (self->inic_ptr,
                              &self->event_param.stdresult_observer);

    if(result == UCS_RET_SUCCESS)
    {
        self->dev_infos.sync_state = RSM_DEV_SYNCING;
        TR_INFO((self->base_ptr->ucs_user_ptr, "[RSM]", "Start synchronization to remote device", 0U));
    }
    else if(result == UCS_RET_ERR_BUFFER_OVERFLOW)
    {
        Inic_AddObsrvOnTxMsgObjAvail(self->inic_ptr, &self->event_param.txavailability_observer);
    }

    return result;
}

/*! \brief  Retrieves the ID of the device that has notified to the INIC.DeviceStatus() FktIDs on the given remote device.
 *  \param  self    Instance pointer
 *  \return Possible return values are
 *          - \c UCS_RET_SUCCESS if the transmission was started successfully
 *          - \c UCS_RET_ERR_BUFFER_OVERFLOW if no TxHandles available
 *          - \c UCS_RET_ERR_API_LOCKED The INIC API is locked
 */
static Ucs_Return_t Rsm_RequestNtfDevId (CRemoteSyncManagement *self)
{
    Ucs_Return_t result;
    uint16_t funcid_devstatus = (uint16_t)0x0220;

    result = Inic_Notification_Get(self->inic_ptr, funcid_devstatus, &self->event_param.stdresult_observer);
    if(result == UCS_RET_SUCCESS)
    {
        TR_INFO((self->base_ptr->ucs_user_ptr, "[RSM]", "DeviceId Request for INIC.DeviceStatus() succeeded", 0U));
    }
    else if (result == UCS_RET_ERR_BUFFER_OVERFLOW)
    {
        Inic_AddObsrvOnTxMsgObjAvail(self->inic_ptr, &self->event_param.txavailability_observer);
    }
    else
    {
        Srv_SetEvent(&self->rsm_srv, RSM_EVENT_PROCESS_DEV);
    }

    return result;
}

/*! \brief  Clears the current DevId of all remote functions on the given remote device.
 *  \param  self    Instance pointer
 *  \return Possible return values are
 *          - \c UCS_RET_SUCCESS if the transmission was started successfully
 *          - \c UCS_RET_ERR_BUFFER_OVERFLOW if no TxHandles available
 *          - \c UCS_RET_ERR_PARAM parameter exceeds its admissible range
 */
static Ucs_Return_t Rsm_ClearLastNtfDevId (CRemoteSyncManagement *self)
{
    Ucs_Return_t result;
    Ucs_Inic_NotificationCtrl_t control = UCS_INIC_NTF_CLEAR_ALL;
    Inic_FktIdList_t rm_fktid_list;
    rm_fktid_list.fktids_ptr = NULL;
    rm_fktid_list.num_fktids = 0U;

    result = Inic_Notification_Set(self->inic_ptr, control, self->event_param.own_device_address, rm_fktid_list);
    if(result == UCS_RET_SUCCESS)
    {
        self->dev_infos.next_st = RSM_ST_NTF_ALL;
        Srv_SetEvent(&self->rsm_srv, RSM_EVENT_PROCESS_DEV);
        TR_INFO((self->base_ptr->ucs_user_ptr, "[RSM]", "Clear DevId for all Remote functions succeeded", 0U));
    }
    else if (result == UCS_RET_ERR_BUFFER_OVERFLOW)
    {
        Inic_AddObsrvOnTxMsgObjAvail(self->inic_ptr, &self->event_param.txavailability_observer);
    }

    return result;
}

/*! \brief  Sets all notification for the given remote device.
 *  \param  self          Instance pointer
 *  \return Possible return values are
 *          - \c UCS_RET_SUCCESS if the transmission was started successfully
 *          - \c UCS_RET_ERR_BUFFER_OVERFLOW if no TxHandles available
 *          - \c UCS_RET_ERR_PARAM parameter exceeds its admissible range
 */
static Ucs_Return_t Rsm_SetNotificationAll (CRemoteSyncManagement * self)
{
    Ucs_Return_t result;
    Ucs_Inic_NotificationCtrl_t control = UCS_INIC_NTF_SET_FUNC;

    uint16_t funcid_list[2] = {0x0705U, 0x0802U};
    Inic_FktIdList_t rm_fktid_list;
    rm_fktid_list.fktids_ptr = &funcid_list[0];
    rm_fktid_list.num_fktids = 2U;

    result = Inic_Notification_Set(self->inic_ptr, control, self->event_param.own_device_address, rm_fktid_list);
    if(result == UCS_RET_SUCCESS)
    {
        self->dev_infos.next_st = RSM_ST_SYNC_SUCC;
        Srv_SetEvent(&self->rsm_srv, RSM_EVENT_PROCESS_DEV);
        TR_INFO((self->base_ptr->ucs_user_ptr, "[RSM]", "Set Notification for All Remote functions succeeded", 0U));
    }
    else if (result == UCS_RET_ERR_BUFFER_OVERFLOW)
    {
        Inic_AddObsrvOnTxMsgObjAvail(self->inic_ptr, &self->event_param.txavailability_observer);
    }

    return result;
}

/*! \brief  Sets Gpio notification for the local device.
 *  \param  self          Instance pointer
 *  \return Possible return values are
 *          - \c UCS_RET_SUCCESS if the transmission was started successfully
 *          - \c UCS_RET_ERR_BUFFER_OVERFLOW if no TxHandles available
 */
static Ucs_Return_t Rsm_SetNotificationGpio (CRemoteSyncManagement * self)
{
    Ucs_Return_t result;
    /*! \brief GPIO TriggerEvent function id */
    uint16_t RSM_GPIOTREVENT_FUNCID = 0x0705U;
    /*! \brief Local EHC address */
    uint16_t RSM_EHC_ADDRESS = 0x0002U;

    Ucs_Inic_NotificationCtrl_t control = UCS_INIC_NTF_SET_FUNC;
    uint16_t funcid_resmonitor = RSM_GPIOTREVENT_FUNCID;
    Inic_FktIdList_t rm_fktid_list;
    rm_fktid_list.fktids_ptr = &funcid_resmonitor;
    rm_fktid_list.num_fktids = 1U;

    result = Inic_Notification_Set(self->inic_ptr, control, RSM_EHC_ADDRESS, rm_fktid_list);
    if(result == UCS_RET_SUCCESS)
    {
        self->dev_infos.next_st = RSM_ST_SYNC_SUCC;
        Srv_SetEvent(&self->rsm_srv, RSM_EVENT_PROCESS_DEV);
    }
    else if (result == UCS_RET_ERR_BUFFER_OVERFLOW)
    {
        Inic_AddObsrvOnTxMsgObjAvail(self->inic_ptr, &self->event_param.txavailability_observer);
    }

    return result;
}

/*! \brief  Check whether the given device is local or remote.
 *  \param  self          Instance pointer
 *  \return Returns \c true if the device is local, otherwise \c false.
 */
static bool Rsm_IsLocal (CRemoteSyncManagement *self)
{
    return (Inic_GetTargetAddress(self->inic_ptr) == UCS_ADDR_LOCAL_DEV);
}

/*------------------------------------------------------------------------------------------------*/
/* Callback Functions                                                                             */
/*------------------------------------------------------------------------------------------------*/
/*! \brief  Called if MNS initialization has been succeeded.
 *  \param  self        Instance pointer
 *  \param  event_ptr  Reference to reported event
 */
static void Rsm_MnsInitSucceededCb(void *self, void *event_ptr)
{
    CRemoteSyncManagement *self_ = (CRemoteSyncManagement *)self;
    MISC_UNUSED(event_ptr);

    /* Remove ucsinit_observer */
    Eh_DelObsrvInternalEvent(&self_->base_ptr->eh, &self_->event_param.ucsinit_observer);

    /* Add network status observer */
    Mobs_Ctor(&self_->event_param.nwstatus_observer, self, RSM_MASK_NETWORK_NODE_ADDRESS, &Rsm_MnsNwStatusInfosCb);
    Net_AddObserverNetworkStatus(self_->net_ptr, &self_->event_param.nwstatus_observer);
}

/*! \brief  Result callback for the "Sync Request".
 *  \param  self               Instance pointer
 *  \param  result_ptr         Reference to the result.
 */
static void Rsm_SyncResultCb(void *self, void *result_ptr)
{
    CRemoteSyncManagement *self_ = (CRemoteSyncManagement *)self;
    Inic_StdResult_t *result_ptr_ = (Inic_StdResult_t *)result_ptr;
    Inic_NotificationResult_t * res_inf = NULL;

    if(result_ptr_->result.code == UCS_RES_SUCCESS)
    {
        if (self_->dev_infos.sync_state == RSM_DEV_SYNCING)
        {
            switch (self_->dev_infos.next_st)
            {
                case RSM_ST_SYNC_REQ:
                    self_->dev_infos.next_st = RSM_ST_NTF_REQ;
                    TR_INFO((self_->base_ptr->ucs_user_ptr, "[RSM]", "Remote DeviceSync has been successfully created.", 0U));
                    break;

                case RSM_ST_NTF_REQ:
                    res_inf = (Inic_NotificationResult_t *)result_ptr_->data_info;
                    if (res_inf != NULL)
                    {
                        if (res_inf->device_id == RSM_INVALID_NODE_ADDRESS)
                        {
                            self_->dev_infos.next_st = RSM_ST_NTF_ALL;
                        }
                        else
                        {
                            self_->dev_infos.next_st = RSM_ST_NTF_CLEAR;
                        }
                    }
                    break;

                default:
                    break;
            }
            Srv_SetEvent(&self_->rsm_srv, RSM_EVENT_PROCESS_DEV);
        }
    }
    else
    {
        self_->dev_infos.next_st = RSM_ST_SYNC_ERR;
        self_->dev_infos.curr_result.code = RSM_RES_ERR_SYNC;
        self_->dev_infos.curr_result.details.inic_result = result_ptr_->result;
        if (result_ptr_->result.code == UCS_RES_ERR_TRANSMISSION)
        {
            self_->dev_infos.curr_result.details.tx_result = *(Ucs_MsgTxStatus_t *)(result_ptr_->data_info);
        }
        else
        {
            self_->dev_infos.curr_result.details.tx_result = UCS_MSG_STAT_OK;
        }

        Srv_SetEvent(&self_->rsm_srv, RSM_EVENT_PROCESS_DEV);
        TR_ERROR((self_->base_ptr->ucs_user_ptr, "[RSM]", "Synchronization to the remote device failed. Result code: 0x%02X", 1U, result_ptr_->result.code));
        if (result_ptr_->result.info_ptr != NULL)
        {
            TR_ERROR_INIC_RESULT(self_->base_ptr->ucs_user_ptr, "[RSM]", result_ptr_->result.info_ptr, result_ptr_->result.info_size);
        }
    }
}

/*! \brief  Event Callback function for the network status.
 *  \param  self          Instance pointer
 *  \param  event_ptr     Reference to the events
 */
static void Rsm_MnsNwStatusInfosCb(void *self, void *event_ptr)
{
    CRemoteSyncManagement *self_ = (CRemoteSyncManagement *)self;
    Net_NetworkStatusParam_t *result_ptr_ = (Net_NetworkStatusParam_t *)event_ptr;
    bool signal_synclost = false;

    if ((RSM_MASK_NETWORK_NODE_ADDRESS & result_ptr_->change_mask) == RSM_MASK_NETWORK_NODE_ADDRESS)
    {
        if (result_ptr_->node_address != 0xFFFFU)
        {
            if ((self_->event_param.own_device_address != RSM_INVALID_NODE_ADDRESS)  && 
                (result_ptr_->node_address != self_->event_param.own_device_address))
            {
                self_->last_synclost_cause = RSM_SLC_SYSMODIF;
                signal_synclost = true;
            }

            self_->event_param.own_device_address = result_ptr_->node_address;
        }
    }

    if (signal_synclost)
    {
        Srv_SetEvent(&self_->rsm_srv, RSM_EVENT_SIG_SYNCLOST);
    }
}

/*! \brief  Event Callback function that signals that a TxMsgObj is now available.
 *  \param  self          Instance pointer
 *  \param  result_ptr    Reference to the results
 */
static void Rsm_MsgObjAvailCb(void *self, void *result_ptr)
{
    CRemoteSyncManagement *self_ = (CRemoteSyncManagement *)self;
    MISC_UNUSED(result_ptr);

    Srv_SetEvent(&self_->rsm_srv, RSM_EVENT_PROCESS_DEV);

    /* delete observer */
    Inic_DelObsrvOnTxMsgObjAvail(self_->inic_ptr, &self_->event_param.txavailability_observer);
}

/*------------------------------------------------------------------------------------------------*/
/* Notification Functions                                                                         */
/*------------------------------------------------------------------------------------------------*/
/*! \brief  Signals the successful synchronization to a remote device.
 *  \param  self        Instance pointer
 */
static void Rsm_SignalSyncCompleted (CRemoteSyncManagement * self)
{
    Rsm_ResultCb_t tmp_res_cb = self->dev_infos.curr_res_cb_fptr;
    void * data = self->dev_infos.curr_user_data;
    Rsm_Result_t res = {RSM_RES_SUCCESS, {UCS_MSG_STAT_OK, {UCS_RES_SUCCESS, NULL, 0}}};

    self->dev_infos.sync_state = RSM_DEV_SYNCED;
    self->dev_infos.next_st    = RSM_ST_IDLE;
    self->dev_infos.curr_res_cb_fptr = NULL;
    self->dev_infos.curr_user_data   = NULL;

    if (tmp_res_cb != NULL)
    {
        tmp_res_cb(data, res);
    }
}

/*! \brief  Signals that the synchronization to a remote device failed.
 *  \param  self        Instance pointer
 */
static void Rsm_SignalSyncError (CRemoteSyncManagement * self)
{
    Rsm_ResultCb_t tmp_res_cb = self->dev_infos.curr_res_cb_fptr;
    void * data = self->dev_infos.curr_user_data;

    self->dev_infos.sync_state = RSM_DEV_UNSYNCED;
    self->dev_infos.next_st    = RSM_ST_IDLE;
    self->dev_infos.curr_res_cb_fptr = NULL;
    self->dev_infos.curr_user_data   = NULL;

    if (tmp_res_cb != NULL)
    {
        tmp_res_cb(data, self->dev_infos.curr_result);
    }
}

/*! \brief  Signals that the synchronization to a remote device has been lost.
 *  \param  self        Instance pointer
 */
static void Rsm_SignalSyncLost (CRemoteSyncManagement * self)
{
    if ((self->dev_infos.sync_state == RSM_DEV_SYNCED) &&
        (!Rsm_IsLocal(self)))
    {
        self->dev_infos.sync_state = RSM_DEV_UNSYNCED;
        if(Sub_GetNumObservers(&self->event_param.subject) > 0U)
        {
            Sub_Notify(&self->event_param.subject, &self->last_synclost_cause);
        }
    }
}

/*!
 * @}
 * \endcond
 */

/*------------------------------------------------------------------------------------------------*/
/* End of file                                                                                    */
/*------------------------------------------------------------------------------------------------*/