summaryrefslogtreecommitdiffstats
path: root/ucs2-lib/inc/ucs_amsallocator.h
blob: b22db9dd5edcf843831be97eb65902ce4bcdba80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*------------------------------------------------------------------------------------------------*/
/* UNICENS V2.1.0-3491                                                                            */
/* Copyright (c) 2017 Microchip Technology Germany II GmbH & Co. KG.                              */
/*                                                                                                */
/* This program is free software: you can redistribute it and/or modify                           */
/* it under the terms of the GNU General Public License as published by                           */
/* the Free Software Foundation, either version 2 of the License, or                              */
/* (at your option) any later version.                                                            */
/*                                                                                                */
/* This program is distributed in the hope that it will be useful,                                */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of                                 */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                  */
/* GNU General Public License for more details.                                                   */
/*                                                                                                */
/* You should have received a copy of the GNU General Public License                              */
/* along with this program.  If not, see <http://www.gnu.org/licenses/>.                          */
/*                                                                                                */
/* You may also obtain this software under a propriety license from Microchip.                    */
/* Please contact Microchip for further information.                                              */
/*------------------------------------------------------------------------------------------------*/

/*!
 * \file
 * \brief Internal header file of AMS Allocator Interface
 *
 * \cond UCS_INTERNAL_DOC
 * \addtogroup G_AMSC
 * @{
 */

#ifndef UCS_AMSALLOCATOR_H
#define UCS_AMSALLOCATOR_H

/*------------------------------------------------------------------------------------------------*/
/* Includes                                                                                       */
/*------------------------------------------------------------------------------------------------*/
#include "ucs_types_cfg.h"

#ifdef __cplusplus
extern "C"
{
#endif

/*------------------------------------------------------------------------------------------------*/
/* Types                                                                                          */
/*------------------------------------------------------------------------------------------------*/
/*! \brief  Defines the usage of a requested memory chunk */
typedef enum Ams_MemUsage_
{
    AMS_MU_RX_OBJECT,            /*!< \brief  Memory is required to allocate an Rx message object */
    AMS_MU_RX_PAYLOAD,           /*!< \brief  Memory is required to allocate Rx message payload */
    AMS_MU_TX_OBJECT,            /*!< \brief  Memory is required to allocate a Tx message object */
    AMS_MU_TX_PAYLOAD            /*!< \brief  Memory is required to allocate Tx message payload */

} Ams_MemUsage_t;

/*! \brief  Callback function type that is invoked to allocate external payload for a segmented Rx message
 *  \param  inst_ptr            Reference to the (external) memory management
 *  \param  mem_size            Reference to the required memory size in bytes. Valid values: 0..65535.
 *  \param  type                Declares how the memory is used by UNICENS
 *  \param  custom_info_pptr    Reference which is related to the memory chunk and can be set by 
 *                              the application.
 *  \return Pointer to the provided memory chunk. The application has to guarantee that the memory size
 *          is equal or greater than \c mem_size. The application has to return \c NULL if it is not able 
 *          to allocate the required memory at this moment.
 */
typedef void* (*Ams_AllocMemCb_t)(void *inst_ptr, uint16_t mem_size, Ams_MemUsage_t type, void** custom_info_pptr);

/*! \brief  Callback function type that is invoked to free external payload for a segmented Rx message
 *  \param  inst_ptr        Reference to the (external) memory management
 *  \param  mem_ptr         Reference to the external payload memory
 *  \param  type            Declares how the memory is used by UNICENS
 *  \param  custom_info_ptr Reference to memory related information which was set by the application 
 *                          during memory allocation
 */
typedef void (*Ams_FreeMemCb_t)(void *inst_ptr, void *mem_ptr, Ams_MemUsage_t type, void* custom_info_ptr);

/*------------------------------------------------------------------------------------------------*/
/* Allocator interface                                                                            */
/*------------------------------------------------------------------------------------------------*/
/*! \brief Keeps callback functions to an external memory management for Rx payload  */
typedef struct Ams_MemAllocator_
{
    void *inst_ptr;                /*!< \brief The instance of the (external) memory management */
    Ams_AllocMemCb_t alloc_fptr;   /*!< \brief This function is invoked to allocate Rx user payload */
    Ams_FreeMemCb_t  free_fptr;    /*!< \brief This function is invoked to free Rx user payload */

} Ams_MemAllocator_t;

#ifdef __cplusplus
}               /* extern "C" */
#endif

#endif          /* UCS_AMSALLOCATOR_H */

/*!
 * @}
 * \endcond
 */

/*------------------------------------------------------------------------------------------------*/
/* End of file                                                                                    */
/*------------------------------------------------------------------------------------------------*/