Initial Commit
[apps/agl-service-unicens.git] / ucs2-lib / inc / ucs_rsm.h
1 /*------------------------------------------------------------------------------------------------*/
2 /* UNICENS V2.1.0-3491                                                                            */
3 /* Copyright (c) 2017 Microchip Technology Germany II GmbH & Co. KG.                              */
4 /*                                                                                                */
5 /* This program is free software: you can redistribute it and/or modify                           */
6 /* it under the terms of the GNU General Public License as published by                           */
7 /* the Free Software Foundation, either version 2 of the License, or                              */
8 /* (at your option) any later version.                                                            */
9 /*                                                                                                */
10 /* This program is distributed in the hope that it will be useful,                                */
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of                                 */
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                  */
13 /* GNU General Public License for more details.                                                   */
14 /*                                                                                                */
15 /* You should have received a copy of the GNU General Public License                              */
16 /* along with this program.  If not, see <http://www.gnu.org/licenses/>.                          */
17 /*                                                                                                */
18 /* You may also obtain this software under a propriety license from Microchip.                    */
19 /* Please contact Microchip for further information.                                              */
20 /*------------------------------------------------------------------------------------------------*/
21
22
23 /*!
24  * \file
25  * \brief Internal header file of the Remote Sync Manager.
26  *
27  * \cond UCS_INTERNAL_DOC
28  * \addtogroup G_RSM
29  * @{
30  */
31
32
33 #ifndef UCS_RSM_H
34 #define UCS_RSM_H
35
36 /*------------------------------------------------------------------------------------------------*/
37 /* Includes                                                                                       */
38 /*------------------------------------------------------------------------------------------------*/
39 #include "ucs_net.h"
40 #include "ucs_base.h"
41 #include "ucs_inic.h"
42 #include "ucs_ret_pb.h"
43 #include "ucs_obs.h"
44 #include "ucs_rsm_pv.h"
45
46 #ifdef __cplusplus
47 extern "C"
48 {
49 #endif
50
51
52 /*------------------------------------------------------------------------------------------------*/
53 /* Enumerations                                                                                   */
54 /*------------------------------------------------------------------------------------------------*/
55 /*! \brief  RSM internal state transitions */
56 typedef enum Rsm_StateTransition_
57 {
58     RSM_ST_IDLE,         /*!< \brief Transition to "Idle" state */
59     RSM_ST_SYNC_REQ,     /*!< \brief Transition to "Sync Request" state */
60     RSM_ST_NTF_REQ,      /*!< \brief Transition to "Notification Request" state */
61     RSM_ST_NTF_CLEAR,    /*!< \brief Transition to "Notification Clear" state */
62     RSM_ST_NTF_ALL,      /*!< \brief Transition to "All Notification" state */
63     RSM_ST_NTF_GPIO,     /*!< \brief Transition to "Gpio Notification" state */ 
64     RSM_ST_SYNC_SUCC,    /*!< \brief Transition to "Sync Success" state */
65     RSM_ST_SYNC_ERR      /*!< \brief Transition to "Sync Error" state */
66
67 } Rsm_StateTransition_t;
68
69 /*------------------------------------------------------------------------------------------------*/
70 /* Structures                                                                                     */
71 /*------------------------------------------------------------------------------------------------*/
72 /*! \brief  Stores data required by RSM during initialization. */
73 typedef struct Rsm_InitData_
74 {
75     CBase *base_ptr;                /*!< \brief Reference to base instance */
76     CInic *inic_ptr;                /*!< \brief Reference to INIC instance */
77     CNetworkManagement *net_ptr;    /*!< \brief Reference to Network instance */
78
79 } Rsm_InitData_t;
80
81 /*! \brief  Stores information required for a RSM device. */
82 typedef struct Rsm_DeviceInfos_
83 {
84     /*! \brief State of the device */
85     Rsm_DevSyncState_t sync_state;
86     /*! \brief next state transition */
87     Rsm_StateTransition_t next_st;
88     /*! \brief stores the current result */
89     Rsm_Result_t curr_result;
90     /*! \brief stores the current user data that'll be passes to curr_res_cb_fptr */
91     void * curr_user_data;
92     /*! \brief current result callback function ptr */
93     Rsm_ResultCb_t curr_res_cb_fptr;
94
95 } Rsm_DeviceInfos_t;
96
97 /*! \brief  Stores parameter used for signaling RSM event. */
98 typedef struct Rsm_EventParam_
99 {
100     /*! \brief own current device address */
101     uint16_t own_device_address;
102     /*! \brief max node position */
103     uint8_t max_node_pos;
104     /*! \brief Result observer used for sockets, ports and connections */
105     CSingleObserver stdresult_observer;
106     /*! \brief Observer used to monitor ICM or MCM Tx Message objects availability */
107     CObserver txavailability_observer;
108     /*! \brief Observer used to monitor MNS initialization result */
109     CMaskedObserver ucsinit_observer;
110     /*! \brief Observe MOST Network status in Net module */
111     CMaskedObserver nwstatus_observer;
112     /*! \brief Own subject to notify the SyncLost event */
113     CSubject subject;
114
115 } Rsm_EventParam_t;
116
117 /*! \brief  Class structure of the Remote Sync Management. */
118 typedef struct CRemoteSyncManagement_
119 {
120     /*! \brief Reference to an INIC instance */
121     CInic *inic_ptr;
122     /*! \brief Reference to a base instance */
123     CBase *base_ptr;
124     /*! \brief Reference to a network instance */
125     CNetworkManagement *net_ptr;
126     /*! \brief RSM DeviceInfos list */
127     Rsm_DeviceInfos_t dev_infos;
128     /*! \brief stores the last synclost cause */
129     Rsm_SyncLostCause_t last_synclost_cause;
130     /*! \brief Parameter object for the RSM Event */
131     Rsm_EventParam_t event_param;
132     /*! \brief Service instance for the scheduler */
133     CService rsm_srv;
134
135 } CRemoteSyncManagement;
136
137 /*------------------------------------------------------------------------------------------------*/
138 /* Prototypes of class CRemoteSyncManagement                                                      */
139 /*------------------------------------------------------------------------------------------------*/
140 extern void Rsm_Ctor(CRemoteSyncManagement * self, Rsm_InitData_t * init_ptr);
141 extern void Rsm_AddObserver(CRemoteSyncManagement * self, CObserver * obs);
142 extern void Rsm_DelObserver(CRemoteSyncManagement * self, CObserver * obs_ptr);
143 extern Ucs_Return_t Rsm_SyncDev(CRemoteSyncManagement * self, void* user_data, Rsm_ResultCb_t sync_complete_fptr);
144 extern Rsm_DevSyncState_t Rsm_GetDevState(CRemoteSyncManagement * self);
145 extern void Rsm_ReportSyncLost (CRemoteSyncManagement * self);
146
147 #ifdef __cplusplus
148 }   /* extern "C" */
149 #endif
150
151 #endif /* #ifndef UCS_RSM_H */
152
153 /*!
154  * @}
155  * \endcond
156  */
157
158 /*------------------------------------------------------------------------------------------------*/
159 /* End of file                                                                                    */
160 /*------------------------------------------------------------------------------------------------*/
161