Merge pull request #2 from ronan22/master
[apps/agl-service-unicens.git] / ucs2-lib / inc / ucs_transceiver.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 Declaration of class CTransceiver
25  *
26  * \cond UCS_INTERNAL_DOC
27  * \addtogroup  G_TRCV
28  * @{
29  */
30
31 #ifndef UCS_TRANSCEIVER_H
32 #define UCS_TRANSCEIVER_H
33
34 /*------------------------------------------------------------------------------------------------*/
35 /* Includes                                                                                       */
36 /*------------------------------------------------------------------------------------------------*/
37 #include "ucs_message.h"
38 #include "ucs_pool.h"
39 #include "ucs_pmfifo.h"
40
41 #ifdef __cplusplus
42 extern "C"
43 {
44 #endif
45
46 /*------------------------------------------------------------------------------------------------*/
47 /* Types                                                                                          */
48 /*------------------------------------------------------------------------------------------------*/ 
49 /*! \brief   Assignable callback function which is invoked for message reception 
50  *  \param   self    The instance
51  *  \param   tel_ptr Reference to the message object
52  */
53 typedef void (*Trcv_RxCompleteCb_t)(void *self, Msg_MostTel_t *tel_ptr);
54
55 /*! \brief   Assignable callback function which is invoked to filter Rx messages
56  *  \details Filtering is a synchronous operation. Hence, it is not possible to keep a message
57  *           object for delayed processing. The invoked function has to decide whether a 
58  *           message shall be discarded and freed to the Rx pool. Therefore, it has to return 
59  *           \c true. By returning \ false, the message will be received in the usual way.
60  *  \param   self    The instance
61  *  \param   tel_ptr Reference to the message object
62  *  \return  Returns \c true to discard the message and free it to the pool (no-pass). Otherwise, returns 
63  *           \c false (pass).
64  */
65 typedef bool (*Trcv_RxFilterCb_t)(void *self, Msg_MostTel_t *tel_ptr);
66
67 /*------------------------------------------------------------------------------------------------*/
68 /* Macros                                                                                         */
69 /*------------------------------------------------------------------------------------------------*/
70 #define TRCV_SIZE_TX_POOL    10U                    /*!< \brief Number of messages in the message pool */
71
72 /*------------------------------------------------------------------------------------------------*/
73 /* Class CTransceiver                                                                             */
74 /*------------------------------------------------------------------------------------------------*/
75 /*! \brief   Class CTransceiver 
76  *  \details Provides MOST message objects and communication methods to further classes
77  */
78 typedef struct CTransceiver_
79 {
80     CMessage             tx_msgs[TRCV_SIZE_TX_POOL];/*!< \brief Messages in message pool */
81     CPool                tx_msg_pool;               /*!< \brief The message pool */
82     uint16_t             tx_def_src;                /*!< \brief Default source address for Tx message object */
83     void                *ucs_user_ptr;              /*!< \brief User reference that needs to be passed in every callback function */
84     uint8_t              own_id;                    /*!< \brief ID of the transceiver required for tracing */
85     CPmFifo             *fifo_ptr;                  /*!< \brief Reference to dedicated port message FIFO */
86
87     Trcv_RxCompleteCb_t  rx_complete_fptr;          /*!< \brief Callback function which is invoked on 
88                                                      *          message reception 
89                                                      */
90     void                *rx_complete_inst;          /*!< \brief Instance which is notified on 
91                                                      *          message reception 
92                                                      */
93     Trcv_RxFilterCb_t    rx_filter_fptr;            /*!< \brief Callback function which is invoked 
94                                                      *          to filter Rx messages
95                                                      */
96     void                *rx_filter_inst;            /*!< \brief Instance which is notified to
97                                                      *          filter Rx messages
98                                                      */
99 } CTransceiver;
100
101 /*------------------------------------------------------------------------------------------------*/
102 /* Methods                                                                                        */
103 /*------------------------------------------------------------------------------------------------*/
104 /* Constructor */
105 extern void Trcv_Ctor(CTransceiver *self, CPmFifo *fifo_ptr, uint16_t def_src_addr, void *ucs_user_ptr, uint8_t trace_id);
106 /* Tx */
107 extern Msg_MostTel_t* Trcv_TxAllocateMsg(CTransceiver *self, uint8_t size);
108 extern void Trcv_TxSendMsg(CTransceiver *self, Msg_MostTel_t *tel_ptr);
109 extern void Trcv_TxSendMsgExt(CTransceiver *self, Msg_MostTel_t *tel_ptr, Msg_TxStatusCb_t callback_fptr, void *inst_ptr);
110 extern void Trcv_TxSendMsgBypass(CTransceiver *self, Msg_MostTel_t *tel_ptr, Msg_TxStatusCb_t callback_fptr, void *inst_ptr);
111 extern void Trcv_TxReleaseMsg(Msg_MostTel_t *tel_ptr);
112 extern void Trcv_TxReuseMsg(Msg_MostTel_t *tel_ptr);
113 /* Rx */
114 extern void Trcv_RxAssignReceiver(CTransceiver *self, Trcv_RxCompleteCb_t callback_fptr, void *inst_ptr);
115 extern void Trcv_RxAssignFilter(CTransceiver *self, Trcv_RxFilterCb_t callback_fptr, void *inst_ptr);
116 extern void Trcv_RxReleaseMsg(CTransceiver *self, Msg_MostTel_t *tel_ptr);
117 extern void Trcv_RxOnMsgComplete(void *self, CMessage *tel_ptr);
118
119 #ifdef __cplusplus
120 }                                                   /* extern "C" */
121 #endif
122
123 #endif /* #ifndef UCS_TRANSCEIVER_H */
124
125 /*!
126  * @}
127  * \endcond
128  */
129
130 /*------------------------------------------------------------------------------------------------*/
131 /* End of file                                                                                    */
132 /*------------------------------------------------------------------------------------------------*/
133