Initial Commit
[apps/agl-service-unicens.git] / ucs2-lib / inc / ucs_amsallocator.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 AMS Allocator Interface
25  *
26  * \cond UCS_INTERNAL_DOC
27  * \addtogroup G_AMSC
28  * @{
29  */
30
31 #ifndef UCS_AMSALLOCATOR_H
32 #define UCS_AMSALLOCATOR_H
33
34 /*------------------------------------------------------------------------------------------------*/
35 /* Includes                                                                                       */
36 /*------------------------------------------------------------------------------------------------*/
37 #include "ucs_types_cfg.h"
38
39 #ifdef __cplusplus
40 extern "C"
41 {
42 #endif
43
44 /*------------------------------------------------------------------------------------------------*/
45 /* Types                                                                                          */
46 /*------------------------------------------------------------------------------------------------*/
47 /*! \brief  Defines the usage of a requested memory chunk */
48 typedef enum Ams_MemUsage_
49 {
50     AMS_MU_RX_OBJECT,            /*!< \brief  Memory is required to allocate an Rx message object */
51     AMS_MU_RX_PAYLOAD,           /*!< \brief  Memory is required to allocate Rx message payload */
52     AMS_MU_TX_OBJECT,            /*!< \brief  Memory is required to allocate a Tx message object */
53     AMS_MU_TX_PAYLOAD            /*!< \brief  Memory is required to allocate Tx message payload */
54
55 } Ams_MemUsage_t;
56
57 /*! \brief  Callback function type that is invoked to allocate external payload for a segmented Rx message
58  *  \param  inst_ptr            Reference to the (external) memory management
59  *  \param  mem_size            Reference to the required memory size in bytes. Valid values: 0..65535.
60  *  \param  type                Declares how the memory is used by UNICENS
61  *  \param  custom_info_pptr    Reference which is related to the memory chunk and can be set by 
62  *                              the application.
63  *  \return Pointer to the provided memory chunk. The application has to guarantee that the memory size
64  *          is equal or greater than \c mem_size. The application has to return \c NULL if it is not able 
65  *          to allocate the required memory at this moment.
66  */
67 typedef void* (*Ams_AllocMemCb_t)(void *inst_ptr, uint16_t mem_size, Ams_MemUsage_t type, void** custom_info_pptr);
68
69 /*! \brief  Callback function type that is invoked to free external payload for a segmented Rx message
70  *  \param  inst_ptr        Reference to the (external) memory management
71  *  \param  mem_ptr         Reference to the external payload memory
72  *  \param  type            Declares how the memory is used by UNICENS
73  *  \param  custom_info_ptr Reference to memory related information which was set by the application 
74  *                          during memory allocation
75  */
76 typedef void (*Ams_FreeMemCb_t)(void *inst_ptr, void *mem_ptr, Ams_MemUsage_t type, void* custom_info_ptr);
77
78 /*------------------------------------------------------------------------------------------------*/
79 /* Allocator interface                                                                            */
80 /*------------------------------------------------------------------------------------------------*/
81 /*! \brief Keeps callback functions to an external memory management for Rx payload  */
82 typedef struct Ams_MemAllocator_
83 {
84     void *inst_ptr;                /*!< \brief The instance of the (external) memory management */
85     Ams_AllocMemCb_t alloc_fptr;   /*!< \brief This function is invoked to allocate Rx user payload */
86     Ams_FreeMemCb_t  free_fptr;    /*!< \brief This function is invoked to free Rx user payload */
87
88 } Ams_MemAllocator_t;
89
90 #ifdef __cplusplus
91 }               /* extern "C" */
92 #endif
93
94 #endif          /* UCS_AMSALLOCATOR_H */
95
96 /*!
97  * @}
98  * \endcond
99  */
100
101 /*------------------------------------------------------------------------------------------------*/
102 /* End of file                                                                                    */
103 /*------------------------------------------------------------------------------------------------*/
104