Initial Commit
[apps/agl-service-unicens.git] / ucs2-lib / inc / ucs_xrm.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  * \file
24  * \brief      Include file of the Extended Resource Manager.
25  *
26  * \defgroup   G_UCS_XRM_STREAM Additional Streaming Port Functions
27  * \brief      Additional Streaming Port functions of the Extended Resource Manager.
28  * \ingroup    G_UCS_IRM
29  *
30  */
31
32 #ifndef UCS_XRM_H
33 #define UCS_XRM_H
34
35 /*------------------------------------------------------------------------------------------------*/
36 /* Includes                                                                                       */
37 /*------------------------------------------------------------------------------------------------*/
38 #include "ucs_net.h"
39 #include "ucs_rsm.h"
40 #include "ucs_inic.h"
41 #include "ucs_ret_pb.h"
42 #include "ucs_obs.h"
43 #include "ucs_xrmpool.h"
44 #include "ucs_class_pb.h"
45
46 #ifdef __cplusplus
47 extern "C"
48 {
49 #endif
50
51 /*!
52  * \cond UCS_INTERNAL_DOC
53  * \addtogroup G_UCS_XRM_INT
54  * @{
55  */
56
57 /*! \def XRM_NUM_RES_HDL_PER_ICM
58  *  \brief Maximum number of resource handles per ICM. Depends on the maximum payload of ICMs.
59  */
60 #define XRM_NUM_RES_HDL_PER_ICM     22U
61
62 /*------------------------------------------------------------------------------------------------*/
63 /* Structures                                                                                     */
64 /*------------------------------------------------------------------------------------------------*/
65 /*! \brief  Stores data required by XRM during initialization. */
66 typedef struct Xrm_InitData_
67 {                    
68     CBase *base_ptr;                                    /*!< \brief Reference to base instance */
69     CInic *inic_ptr;                                    /*!< \brief Reference to INIC instance */
70     CNetworkManagement *net_ptr;                        /*!< \brief Reference to Network instance */
71     CRemoteSyncManagement *rsm_ptr;                     /*!< \brief Reference to a RSM instance */
72     CXrmPool *xrmp_ptr;                                 /*!< \brief Reference to a xrm pool instance */
73     Ucs_Xrm_ResourceDebugCb_t res_debugging_fptr;       /*!< \brief Callback function pointer to monitor XRM resources from application */
74     Ucs_Xrm_CheckUnmuteCb_t check_unmute_fptr;          /*!< \brief Callback function pointer to signal unmute of devices */
75
76 } Xrm_InitData_t;
77
78 /*! \brief Structure that defines a XRM StreamPort configuration  */
79 typedef struct Xrm_StreamPort_Config_
80 {
81     uint8_t                         index;              /*!< \brief Streaming Port instance */
82     Ucs_Stream_PortOpMode_t         op_mode;            /*!< \brief Streaming Port Operation mode */
83     Ucs_Stream_PortOption_t         port_option;        /*!< \brief Streaming Port Options */
84     Ucs_Stream_PortClockMode_t      clock_mode;         /*!< \brief Stream Port Clock Mode */
85     Ucs_Stream_PortClockDataDelay_t clock_data_delay;   /*!< \brief Stream Port Clock Data Delay */
86     Ucs_Xrm_Stream_PortCfgResCb_t   result_fptr;        /*!< \brief Result callback */
87
88 } Xrm_StreamPort_Config_t;
89
90 /*! \brief Result observers used by FBlock INIC Resource Management functions */
91 typedef struct Xrm_Observers_
92 {
93     /*! \brief Observer used to monitor internal errors (e.g., INIC BIST Error) */
94     CMaskedObserver internal_error_obs;
95     /*! \brief Observer used to monitor network status infos */
96     CMaskedObserver nw_status_obs;
97     /*! \brief Observer used to monitor ICM tx message object availability */
98     CObserver tx_msg_obj_obs;
99     /*! \brief Observer used for the INIC resource monitor */
100     CObserver resource_monitor_obs;
101     /*! \brief Result observer used for destruction of INIC resources */
102     CSingleObserver resource_destroy_obs;
103     /*! \brief Result observer used for requests of invalid resource handles */
104     CSingleObserver resource_invalid_list_obs;
105     /*! \brief Result observer used for sockets, ports and connections */
106     CSingleObserver std_result_obs;
107     /*! \brief Application callback to signal unmute of devices */
108     Ucs_Xrm_CheckUnmuteCb_t check_unmute_fptr;
109     /*! \brief Callback function pointer used for streaming port configurations */
110     Ucs_Xrm_Stream_PortCfgResCb_t stream_port_config_fptr;
111     /*! \brief Observer to proxy callback stream_port_config_fptr() */
112     CSingleObserver stream_port_config_obs;
113     /*! \brief Callback function pointer used by operation that enables a MOST Port */
114     Ucs_StdResultCb_t most_port_enable_fptr;
115     /*! \brief Observer to proxy callback most_port_enable_port_fptr() */
116     CSingleObserver most_port_enable_obs;
117     /*! \brief Callback function pointer by operation that enables full streaming for a MOST Port*/
118     Ucs_StdResultCb_t most_port_en_full_str_fptr;
119     /*! \brief Observer to proxy callback most_port_en_full_str_fptr() */
120     CSingleObserver most_port_en_full_str_obs;
121     /*! \brief Observer to the SyncLost event in RSM */
122     CObserver rsm_sync_lost_obs;
123
124 } Xrm_Observers_t;
125
126 /*! \brief Structure of the Extended Resource Manager class. */
127 typedef struct CExtendedResourceManager_
128 {
129     /*!< \brief  Jobs list queue */
130     CDlList  job_list;
131     /*! \brief List to temporarily store invalid resource handles */
132     uint16_t inv_resource_handle_list[XRM_NUM_RES_HDL_PER_ICM];
133     /*! \brief Reference to an INIC instance */
134     CInic *inic_ptr;
135     /*! \brief Reference to a network instance */
136     CNetworkManagement *net_ptr;
137     /*! \brief Reference to a rsm instance */
138     CRemoteSyncManagement *rsm_ptr;
139     /*!< \brief Reference to base instance */
140     CBase *base_ptr;
141     /*!< \brief Reference to the xrm pool instance */
142     CXrmPool *xrmp_ptr;
143     /*! \brief Reference to the currently processed job */
144     Xrm_Job_t *current_job_ptr;
145     /*! \brief Reference to the currently processed resource object */
146     UCS_XRM_CONST Ucs_Xrm_ResObject_t **current_obj_pptr;
147     /*! \brief Number of invalid handles in list inv_resource_handle_list[] */
148     uint8_t inv_resource_handle_list_size;
149     /*! \brief Current number of destroyed handles in list inv_resource_handle_list[] */
150     uint8_t curr_dest_resource_handle_size;
151     /*! \brief Start index for the current invalid handles index in list inv_resource_handle_list[] */
152     uint8_t inv_resource_handle_index;
153     /*! \brief Service instance to add the Extended Resource Manager to the MNS scheduler */
154     CService xrm_srv;
155     /*! \brief Report result of the Extended Resource Manager. Used to reported status and error 
156      *         information to the application.
157      */
158     Ucs_Xrm_Result_t report_result;
159     /*! \brief Required result observers */
160     Xrm_Observers_t obs;
161     /*! \brief Mask that stores queued event */
162     Srv_Event_t queued_event_mask;
163     /*! \brief stores the currently stream port configuration (in process) */
164     Xrm_StreamPort_Config_t current_streamport_config;
165     /*!< \brief Callback function pointer to monitor XRM resources */
166     Ucs_Xrm_ResourceDebugCb_t res_debugging_fptr;
167     /*! \brief Flag to lock the API */
168     bool lock_api;
169     /*!< \brief Signal whether this instance is in Remote Control Mode */ 
170     bool IsInRemoteControlMode;
171
172 } CExtendedResourceManager;
173
174 /*------------------------------------------------------------------------------------------------*/
175 /* Prototypes of class CExtendedResourceManager                                                   */
176 /*------------------------------------------------------------------------------------------------*/
177 extern void Xrm_Ctor(CExtendedResourceManager *self, Xrm_InitData_t * data_ptr);
178 extern Ucs_Return_t Xrm_Process(CExtendedResourceManager *self,
179                                 UCS_XRM_CONST Ucs_Xrm_ResObject_t *resource_object_list[],
180                                 uint16_t most_network_connection_label,
181                                 void * user_arg,
182                                 Ucs_Xrm_ReportCb_t report_fptr);
183 extern Ucs_Return_t Xrm_Destroy(CExtendedResourceManager *self, 
184                                 UCS_XRM_CONST Ucs_Xrm_ResObject_t *resource_object_list[]);
185 extern Ucs_Return_t Xrm_Stream_SetPortConfig(CExtendedResourceManager *self, 
186                                              uint8_t index,
187                                              Ucs_Stream_PortOpMode_t op_mode,
188                                              Ucs_Stream_PortOption_t port_option,
189                                              Ucs_Stream_PortClockMode_t clock_mode,
190                                              Ucs_Stream_PortClockDataDelay_t clock_data_delay,
191                                              Ucs_Xrm_Stream_PortCfgResCb_t result_fptr);
192 extern Ucs_Return_t Xrm_Stream_GetPortConfig(CExtendedResourceManager *self, 
193                                              uint8_t index,
194                                              Ucs_Xrm_Stream_PortCfgResCb_t result_fptr);
195 extern Ucs_Return_t Xrm_Most_EnablePort(CExtendedResourceManager *self,
196                                         uint16_t most_port_handle, 
197                                         bool enabled, 
198                                         Ucs_StdResultCb_t result_fptr);
199 extern Ucs_Return_t Xrm_Most_PortEnFullStr(CExtendedResourceManager *self,
200                                            uint16_t most_port_handle, 
201                                            bool enabled, 
202                                            Ucs_StdResultCb_t result_fptr);
203 extern void Xrm_SetResourceDebugCbFn(CExtendedResourceManager *self, Ucs_Xrm_ResourceDebugCb_t dbg_cb_fn);
204
205 #ifdef __cplusplus
206 }   /* extern "C" */
207 #endif
208
209 #endif  /* #ifndef UCS_XRM_H */
210
211 /*!
212  * @}
213  * \endcond
214  */
215
216 /*------------------------------------------------------------------------------------------------*/
217 /* End of file                                                                                    */
218 /*------------------------------------------------------------------------------------------------*/
219