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 Internal header file of AMS Allocator Interface
26 * \cond UCS_INTERNAL_DOC
31 #ifndef UCS_AMSALLOCATOR_H
32 #define UCS_AMSALLOCATOR_H
34 /*------------------------------------------------------------------------------------------------*/
36 /*------------------------------------------------------------------------------------------------*/
37 #include "ucs_types_cfg.h"
44 /*------------------------------------------------------------------------------------------------*/
46 /*------------------------------------------------------------------------------------------------*/
47 /*! \brief Defines the usage of a requested memory chunk */
48 typedef enum Ams_MemUsage_
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 */
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
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.
67 typedef void* (*Ams_AllocMemCb_t)(void *inst_ptr, uint16_t mem_size, Ams_MemUsage_t type, void** custom_info_pptr);
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
76 typedef void (*Ams_FreeMemCb_t)(void *inst_ptr, void *mem_ptr, Ams_MemUsage_t type, void* custom_info_ptr);
78 /*------------------------------------------------------------------------------------------------*/
79 /* Allocator interface */
80 /*------------------------------------------------------------------------------------------------*/
81 /*! \brief Keeps callback functions to an external memory management for Rx payload */
82 typedef struct Ams_MemAllocator_
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 */
94 #endif /* UCS_AMSALLOCATOR_H */
101 /*------------------------------------------------------------------------------------------------*/
103 /*------------------------------------------------------------------------------------------------*/