Initial Commit
[apps/agl-service-unicens.git] / ucs2-lib / inc / ucs_smm.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 Header file of the class CStaticMemoryManager.
25  * \cond UCS_INTERNAL_DOC
26  * \addtogroup G_UCS_SMM_CLASS
27  * @{
28  */
29
30 #ifndef UCS_SMM_H
31 #define UCS_SMM_H
32
33 /*------------------------------------------------------------------------------------------------*/
34 /* Includes                                                                                       */
35 /*------------------------------------------------------------------------------------------------*/
36 #include "ucs_smm_pb.h"
37 #include "ucs_ret_pb.h"
38 #include "ucs_dl.h"
39 #include "ucs_amsmessage.h"
40 #include "ucs_amsallocator.h"
41
42 #ifdef __cplusplus
43 extern "C"
44 {
45 #endif
46
47 /*------------------------------------------------------------------------------------------------*/
48 /* Macros                                                                                         */
49 /*------------------------------------------------------------------------------------------------*/
50 #define SMM_NUM_TX_MSGS     ((uint16_t)UCS_AMS_NUM_TX_MSGS)
51 #define SMM_NUM_RX_MSGS     ((uint16_t)UCS_AMS_NUM_RX_MSGS)
52 #define SMM_SIZE_TX_MSG     ((uint16_t)UCS_AMS_SIZE_TX_MSG)
53 #define SMM_SIZE_RX_MSG     ((uint16_t)UCS_AMS_SIZE_RX_MSG)
54
55 /*------------------------------------------------------------------------------------------------*/
56 /* Type definitions                                                                               */
57 /*------------------------------------------------------------------------------------------------*/
58 /*! \brief Tx object allocation info */
59 typedef struct Smm_TxObject_
60 {
61     Amsg_IntMsgTx_t object;             /*!< \brief Tx object memory */
62     CDlNode node;                       /*!< \brief Node that enables listing */
63
64 } Smm_TxObject_t;
65
66 /*! \brief Rx object allocation info */
67 typedef struct Smm_RxObject_
68 {
69     Amsg_IntMsgRx_t object;             /*!< \brief Rx object memory */
70     CDlNode node;                       /*!< \brief Node that enables listing */
71
72 } Smm_RxObject_t;
73
74 /*! \brief Tx payload allocation info */
75 typedef struct Smm_TxPayload_
76 {
77     uint8_t data[SMM_SIZE_TX_MSG];      /*!< \brief Tx payload memory */
78     CDlNode node;                       /*!< \brief Node that enables listing */
79
80 } Smm_TxPayload_t;
81
82 /*! \brief Rx payload allocation info */
83 typedef struct Smm_RxPayload_
84 {
85     uint8_t data[SMM_SIZE_RX_MSG];      /*!< \brief Rx payload memory */
86     CDlNode node;                       /*!< \brief Node that enables listing */
87
88 } Smm_RxPayload_t;
89
90 /*! \brief Static memory allocation of objects and payload */
91 typedef struct Smm_Resources_
92 {
93     Smm_TxObject_t tx_objects[SMM_NUM_TX_MSGS];  /*!< \brief Statically allocated Tx objects */
94     Smm_RxObject_t rx_objects[SMM_NUM_RX_MSGS];  /*!< \brief Statically allocated Rx objects */
95
96     Smm_TxPayload_t tx_payload[SMM_NUM_TX_MSGS]; /*!< \brief Statically allocated Tx payload */
97     Smm_RxPayload_t rx_payload[SMM_NUM_RX_MSGS]; /*!< \brief Statically allocated Rx payload */
98
99 } Smm_Resources_t;
100
101 /*! \brief Descriptor which simplifies access to different memory types */
102 typedef struct Smm_Descriptor_
103 {
104     CDlList list;           /*!< \brief The list of available memory chunks */
105     uint16_t max_mem_size;  /*!< \brief The maximum size of one memory chunk */
106
107 } Smm_Descriptor_t;
108
109
110 /*------------------------------------------------------------------------------------------------*/
111 /* Class definitions                                                                              */
112 /*------------------------------------------------------------------------------------------------*/
113 /*! \brief Structure of the class CStaticMemoryManager. */
114 typedef struct CStaticMemoryManager_
115 {
116     Smm_Resources_t resources;          /*!< \brief Static allocation of memory */
117
118     Smm_Descriptor_t null_descr;        /*!< \brief Descriptor for unknown memory type. Performance measure. */
119     Smm_Descriptor_t tx_object_descr;   /*!< \brief Descriptor of Tx object type */
120     Smm_Descriptor_t tx_payload_descr;  /*!< \brief Descriptor of Tx payload type */
121     Smm_Descriptor_t rx_object_descr;   /*!< \brief Descriptor of Rx object type */
122     Smm_Descriptor_t rx_payload_descr;  /*!< \brief Descriptor of Rx payload type */
123
124     void *ucs_user_ptr;                /*!< \brief User reference that needs to be passed in every callback function */
125
126 } CStaticMemoryManager;
127
128 /*------------------------------------------------------------------------------------------------*/
129 /* Prototypes of class CStaticMemoryManager                                                     */
130 /*------------------------------------------------------------------------------------------------*/
131 extern void Smm_Ctor(CStaticMemoryManager *self, void *ucs_user_ptr);
132 extern Ucs_Return_t Smm_LoadPlugin(CStaticMemoryManager *self, Ams_MemAllocator_t *allocator_ptr, uint16_t rx_def_payload_size);
133 extern Ucs_Return_t Smm_GetFreeBufferCnt(CStaticMemoryManager *self, uint16_t *rx_cnt_ptr, uint16_t *tx_cnt_ptr);
134
135 #ifdef __cplusplus
136 }   /* extern "C" */
137 #endif
138
139 #endif  /* #ifndef UCS_SMM_H */
140
141 /*!
142  * @}
143  * \endcond
144  */
145
146 /*------------------------------------------------------------------------------------------------*/
147 /* End of file                                                                                    */
148 /*------------------------------------------------------------------------------------------------*/
149