1 /*------------------------------------------------------------------------------------------------*/
2 /* UNICENS V2.1.0-3491 */
3 /* Copyright (c) 2017 Microchip Technology Germany II GmbH & Co. KG. */
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. */
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. */
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/>. */
18 /* You may also obtain this software under a propriety license from Microchip. */
19 /* Please contact Microchip for further information. */
20 /*------------------------------------------------------------------------------------------------*/
24 * \brief Header file of the class CStaticMemoryManager.
25 * \cond UCS_INTERNAL_DOC
26 * \addtogroup G_UCS_SMM_CLASS
33 /*------------------------------------------------------------------------------------------------*/
35 /*------------------------------------------------------------------------------------------------*/
36 #include "ucs_smm_pb.h"
37 #include "ucs_ret_pb.h"
39 #include "ucs_amsmessage.h"
40 #include "ucs_amsallocator.h"
47 /*------------------------------------------------------------------------------------------------*/
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)
55 /*------------------------------------------------------------------------------------------------*/
56 /* Type definitions */
57 /*------------------------------------------------------------------------------------------------*/
58 /*! \brief Tx object allocation info */
59 typedef struct Smm_TxObject_
61 Amsg_IntMsgTx_t object; /*!< \brief Tx object memory */
62 CDlNode node; /*!< \brief Node that enables listing */
66 /*! \brief Rx object allocation info */
67 typedef struct Smm_RxObject_
69 Amsg_IntMsgRx_t object; /*!< \brief Rx object memory */
70 CDlNode node; /*!< \brief Node that enables listing */
74 /*! \brief Tx payload allocation info */
75 typedef struct Smm_TxPayload_
77 uint8_t data[SMM_SIZE_TX_MSG]; /*!< \brief Tx payload memory */
78 CDlNode node; /*!< \brief Node that enables listing */
82 /*! \brief Rx payload allocation info */
83 typedef struct Smm_RxPayload_
85 uint8_t data[SMM_SIZE_RX_MSG]; /*!< \brief Rx payload memory */
86 CDlNode node; /*!< \brief Node that enables listing */
90 /*! \brief Static memory allocation of objects and payload */
91 typedef struct Smm_Resources_
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 */
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 */
101 /*! \brief Descriptor which simplifies access to different memory types */
102 typedef struct Smm_Descriptor_
104 CDlList list; /*!< \brief The list of available memory chunks */
105 uint16_t max_mem_size; /*!< \brief The maximum size of one memory chunk */
110 /*------------------------------------------------------------------------------------------------*/
111 /* Class definitions */
112 /*------------------------------------------------------------------------------------------------*/
113 /*! \brief Structure of the class CStaticMemoryManager. */
114 typedef struct CStaticMemoryManager_
116 Smm_Resources_t resources; /*!< \brief Static allocation of memory */
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 */
124 void *ucs_user_ptr; /*!< \brief User reference that needs to be passed in every callback function */
126 } CStaticMemoryManager;
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);
139 #endif /* #ifndef UCS_SMM_H */
146 /*------------------------------------------------------------------------------------------------*/
148 /*------------------------------------------------------------------------------------------------*/