summaryrefslogtreecommitdiffstats
path: root/ucs2-lib/inc/ucs_smm.h
blob: e129ff37aff614a82f28fdf7f6ccc122fda168ce (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*------------------------------------------------------------------------------------------------*/
/* 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 Header file of the class CStaticMemoryManager.
 * \cond UCS_INTERNAL_DOC
 * \addtogroup G_UCS_SMM_CLASS
 * @{
 */

#ifndef UCS_SMM_H
#define UCS_SMM_H

/*------------------------------------------------------------------------------------------------*/
/* Includes                                                                                       */
/*------------------------------------------------------------------------------------------------*/
#include "ucs_smm_pb.h"
#include "ucs_ret_pb.h"
#include "ucs_dl.h"
#include "ucs_amsmessage.h"
#include "ucs_amsallocator.h"

#ifdef __cplusplus
extern "C"
{
#endif

/*------------------------------------------------------------------------------------------------*/
/* Macros                                                                                         */
/*------------------------------------------------------------------------------------------------*/
#define SMM_NUM_TX_MSGS     ((uint16_t)UCS_AMS_NUM_TX_MSGS)
#define SMM_NUM_RX_MSGS     ((uint16_t)UCS_AMS_NUM_RX_MSGS)
#define SMM_SIZE_TX_MSG     ((uint16_t)UCS_AMS_SIZE_TX_MSG)
#define SMM_SIZE_RX_MSG     ((uint16_t)UCS_AMS_SIZE_RX_MSG)

/*------------------------------------------------------------------------------------------------*/
/* Type definitions                                                                               */
/*------------------------------------------------------------------------------------------------*/
/*! \brief Tx object allocation info */
typedef struct Smm_TxObject_
{
    Amsg_IntMsgTx_t object;             /*!< \brief Tx object memory */
    CDlNode node;                       /*!< \brief Node that enables listing */

} Smm_TxObject_t;

/*! \brief Rx object allocation info */
typedef struct Smm_RxObject_
{
    Amsg_IntMsgRx_t object;             /*!< \brief Rx object memory */
    CDlNode node;                       /*!< \brief Node that enables listing */

} Smm_RxObject_t;

/*! \brief Tx payload allocation info */
typedef struct Smm_TxPayload_
{
    uint8_t data[SMM_SIZE_TX_MSG];      /*!< \brief Tx payload memory */
    CDlNode node;                       /*!< \brief Node that enables listing */

} Smm_TxPayload_t;

/*! \brief Rx payload allocation info */
typedef struct Smm_RxPayload_
{
    uint8_t data[SMM_SIZE_RX_MSG];      /*!< \brief Rx payload memory */
    CDlNode node;                       /*!< \brief Node that enables listing */

} Smm_RxPayload_t;

/*! \brief Static memory allocation of objects and payload */
typedef struct Smm_Resources_
{
    Smm_TxObject_t tx_objects[SMM_NUM_TX_MSGS];  /*!< \brief Statically allocated Tx objects */
    Smm_RxObject_t rx_objects[SMM_NUM_RX_MSGS];  /*!< \brief Statically allocated Rx objects */

    Smm_TxPayload_t tx_payload[SMM_NUM_TX_MSGS]; /*!< \brief Statically allocated Tx payload */
    Smm_RxPayload_t rx_payload[SMM_NUM_RX_MSGS]; /*!< \brief Statically allocated Rx payload */

} Smm_Resources_t;

/*! \brief Descriptor which simplifies access to different memory types */
typedef struct Smm_Descriptor_
{
    CDlList list;           /*!< \brief The list of available memory chunks */
    uint16_t max_mem_size;  /*!< \brief The maximum size of one memory chunk */

} Smm_Descriptor_t;


/*------------------------------------------------------------------------------------------------*/
/* Class definitions                                                                              */
/*------------------------------------------------------------------------------------------------*/
/*! \brief Structure of the class CStaticMemoryManager. */
typedef struct CStaticMemoryManager_
{
    Smm_Resources_t resources;          /*!< \brief Static allocation of memory */

    Smm_Descriptor_t null_descr;        /*!< \brief Descriptor for unknown memory type. Performance measure. */
    Smm_Descriptor_t tx_object_descr;   /*!< \brief Descriptor of Tx object type */
    Smm_Descriptor_t tx_payload_descr;  /*!< \brief Descriptor of Tx payload type */
    Smm_Descriptor_t rx_object_descr;   /*!< \brief Descriptor of Rx object type */
    Smm_Descriptor_t rx_payload_descr;  /*!< \brief Descriptor of Rx payload type */

    void *ucs_user_ptr;                /*!< \brief User reference that needs to be passed in every callback function */

} CStaticMemoryManager;

/*------------------------------------------------------------------------------------------------*/
/* Prototypes of class CStaticMemoryManager                                                     */
/*------------------------------------------------------------------------------------------------*/
extern void Smm_Ctor(CStaticMemoryManager *self, void *ucs_user_ptr);
extern Ucs_Return_t Smm_LoadPlugin(CStaticMemoryManager *self, Ams_MemAllocator_t *allocator_ptr, uint16_t rx_def_payload_size);
extern Ucs_Return_t Smm_GetFreeBufferCnt(CStaticMemoryManager *self, uint16_t *rx_cnt_ptr, uint16_t *tx_cnt_ptr);

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

#endif  /* #ifndef UCS_SMM_H */

/*!
 * @}
 * \endcond
 */

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