Initial Commit
[apps/agl-service-unicens.git] / ucs2-lib / inc / ucs_amd.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 Internal header file of Application Message Distributor
25  *
26  * \cond UCS_INTERNAL_DOC
27  * \addtogroup G_AMD
28  * @{
29  */
30 #ifndef UCS_AMD_H
31 #define UCS_AMD_H
32
33 /*------------------------------------------------------------------------------------------------*/
34 /* Includes                                                                                       */
35 /*------------------------------------------------------------------------------------------------*/
36 #include "ucs_ams.h"
37 #include "ucs_base.h"
38 #include "ucs_amsmessage.h"
39
40 #ifdef __cplusplus
41 extern "C"
42 {
43 #endif
44
45 /*------------------------------------------------------------------------------------------------*/
46 /* Types                                                                                          */
47 /*------------------------------------------------------------------------------------------------*/
48 /*! \brief  Assignable function which is invoked as soon as an application message is received 
49  *          completely and available in the Rx message queue
50  *  \param  self    The instance
51  */
52 typedef void (*Amd_RxMsgCompleteCb_t)(void *self);
53
54 /*! \brief  Assignable callback function which is able to read and modify the Rx message
55  *  \param  self    The instance
56  *  \param  msg_ptr Reference to the Rx message object
57  */
58 typedef void (*Amd_RxModificationCb_t)(void *self, Ucs_AmsRx_Msg_t *msg_ptr);
59
60 /*------------------------------------------------------------------------------------------------*/
61 /* Class                                                                                          */
62 /*------------------------------------------------------------------------------------------------*/
63 /*! \brief      Application Message Service Class
64  *  \details    Allows transmission and reception of MOST Application Messages
65  */
66 typedef struct CAmd_
67 {
68     CBase                  *base_ptr;                   /*!< \brief  Reference to basic services */
69     CAms                   *ams_ptr;                    /*!< \brief  Reference to AMS */
70 #ifdef AMD_TX_DISTRIB
71     CAmsMsgPool            *pool_ptr;                   /*!< \brief  Reference to AMS message pool */
72     CInic                  *inic_ptr;                   /*!< \brief  Reference to INIC */
73     CNetworkManagement     *net_ptr;                    /*!< \brief  Reference to network management */
74 #endif
75     CService                service;                    /*!< \brief  Service object */
76     bool                    started;                    /*!< \brief  Is \c true if the AMD is allowed
77                                                          *           to distribute messages
78                                                          */
79     CMaskedObserver         event_observer;             /*!< \brief  Observes init complete event */
80     CMaskedObserver         terminate_observer;         /*!< \brief  Observes events leading to termination */
81
82     void                   *preprocess_inst_ptr;        /*!< \brief Reference to the message preprocessor */
83     Amd_RxMsgCompleteCb_t   preprocess_fptr;            /*!< \brief Callback function which is invoked first 
84                                                          *          on completed message reception 
85                                                          */
86
87     void                   *receive_inst_ptr;           /*!< \brief Reference to the message receiver */
88     Amd_RxMsgCompleteCb_t   receive_fptr;               /*!< \brief Callback function which is invoked after 
89                                                          *          the preprocessor has finished
90                                                          */
91 #ifdef AMD_TX_DISTRIB
92     CDlList                 tx_notify_queue;            /*!< \brief Queue to notify asynchronously a failed transmission */
93 #endif
94     CDlList                 pre_queue;                  /*!< \brief Queue of messages for the preprocessor */
95     CDlList                 rx_queue;                   /*!< \brief Queue of messages for the receiver */
96
97     CDlList                *first_q_ptr;                /*!< \brief Reference where to queue the messages first */
98     Amd_RxMsgCompleteCb_t   first_receive_fptr;         /*!< \brief Reference of the callback to be fired first */
99     void                   *first_receive_inst_ptr;     /*!< \brief Reference to the first receiver */
100
101     Amd_RxModificationCb_t  rx_modification_fptr;       /*!< \brief Callback function for message modification */
102     void                   *rx_modification_inst_ptr;   /*!< \brief Callback reference for message modification */
103
104 } CAmd;
105
106 /*------------------------------------------------------------------------------------------------*/
107 /* Methods                                                                                        */
108 /*------------------------------------------------------------------------------------------------*/
109 extern void Amd_Ctor(CAmd *self, CBase *base_ptr, CAms *ams_ptr);
110 extern void Amd_AssignPreprocessor(CAmd *self, Amd_RxMsgCompleteCb_t callback_fptr, void *inst_ptr);
111 extern void Amd_AssignReceiver(CAmd *self, Amd_RxMsgCompleteCb_t callback_fptr, void *inst_ptr);
112 extern void Amd_RxAssignModificator(CAmd *self, Amd_RxModificationCb_t callback_fptr, void *inst_ptr);
113
114 extern Ucs_AmsRx_Msg_t* Amd_PrePeekMsg(CAmd *self);
115 extern void Amd_PreReleaseMsg(CAmd *self);
116 extern void Amd_PreForwardMsg(CAmd *self);
117
118 extern Ucs_AmsRx_Msg_t* Amd_RxPeekMsg(CAmd *self);
119 extern void Amd_RxReleaseMsg(CAmd *self);
120 extern uint16_t Amd_RxGetMsgCnt(CAmd *self);
121
122 #ifdef AMD_TX_DISTRIB
123 Ucs_Return_t Amd_TxSendMsg(CAmd *self, Ucs_AmsTx_Msg_t *msg_ptr, Amsg_TxCompleteSiaCb_t tx_complete_sia_fptr, 
124                            Amsg_TxCompleteCb_t tx_complete_fptr, void* tx_complete_inst_ptr);
125 #endif
126
127 #ifdef __cplusplus
128 }               /* extern "C" */
129 #endif
130
131 #endif          /* UCS_AMD_H */
132
133 /*!
134  * @}
135  * \endcond
136  */
137
138 /*------------------------------------------------------------------------------------------------*/
139 /* End of file                                                                                    */
140 /*------------------------------------------------------------------------------------------------*/
141