Developer World
Spresense SDK Library v2.2.0-87f81d9
MemMgrTypes.h
Go to the documentation of this file.
1 /****************************************************************************
2  * modules/include/memutils/memory_manager/MemMgrTypes.h
3  *
4  * Copyright 2018 Sony Semiconductor Solutions Corporation
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * 3. Neither the name of Sony Semiconductor Solutions Corporation nor
17  * the names of its contributors may be used to endorse or promote
18  * products derived from this software without specific prior written
19  * permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  ****************************************************************************/
40 #ifndef MEMMGRTYPES_H_INCLUDED
41 #define MEMMGRTYPES_H_INCLUDED
42 
52 #include <stdio.h>
53 #include <sdk/config.h>
54 #include "memutils/common_utils/common_types.h" /* uintN_t */
55 #include "memutils/os_utils/cpp_util.h" /* CopyGuard class */
56 
57 /* The header depending on the configuration of mem_layout.h
58  * should be described after this.
59  */
60 
61 #ifdef USE_MEMMGR_MULTI_CORE
62 #include "SpinLockManager.h"
63 #endif
64 
65 #define MEMMGR_SIGNATURE "MML"
66 
67 class FastMemAlloc; /* This class is outside the namespace. */
68 
73 namespace MemMgrLite {
74 
75 class MemPool;
76 class MemHandleBase;
77 typedef uint32_t MemHandleProxy; /* For avoiding cross reference with
78  * MemHandleBase class.
79  */
80 
82 typedef uint8_t NumLayout; /* Number of memory layout(Max 255)/ */
83 typedef uint8_t NumSection; /* Number of memory section(Max 255)/ */
84 const NumLayout BadLayoutNo = 0xff; /* The layout number is 0 origin. */
85 const NumSection BadSectionNo = 0xff; /* The section number is 0 origin. */
86 
88 typedef struct {
89  uint8_t pool:6; /* Memory pool ID(1 origin. Max 63). */
90  uint8_t sec:2; /* Memory section ID(0 origin. Max 3). */
91 } PoolId;
92 const PoolId NullPoolId = {0,0}; /* Pool ID 0 is unused. */
93 
95 typedef uint8_t PoolType; /* Type of memory pool. */
96 
101 enum
102 {
103  /* enum has a compiler that will be 4 bytes. */
104 
107  RingBufType,
109  NumPoolTypes /* number of pool types */
110 };
111 
112 /* The address scheme use for the memory pool address depends on the project.
113  * For PoolAddr type, address 0 is valid,
114  * so 0xffffffff is used as an invalid address.
115  */
116 
117 typedef uint32_t PoolAddr;
118 const PoolAddr BadPoolAddr = 0xffffffff;
119 
120 typedef uint32_t PoolSize; /* Size of memory pool (byte order). */
121 
122 #ifdef USE_MEMMGR_OVER255_SEGMENTS
123 typedef uint16_t NumSeg; /* Number of memory segment(Max 65535). */
124 #else
125 typedef uint8_t NumSeg; /* Number of memory segment(Max 255). */
126 #endif
127 const NumSeg NullSegNo = 0; /* Segment number 0 is unused. */
128 
129 typedef uint8_t SegRefCnt; /* Segment reference count(Max 255). */
130 
131 #ifdef USE_MEMMGR_MULTI_CORE
132 /* InterCpuLock::SpinLockId is uint16_t,
133  * but it is defined as a different type for memory saving
134  */
135 
136 typedef uint8_t LockId; /* Spin lock id(1 origin. Max 255). */
137 const LockId NullLockId = 0; /* Spin lock id 0 is unused. */
138 
139 /* To fit in the flags field of MemHandle, make it less than 6 bits. */
140 
141 typedef uint8_t CpuId; /* CPU-ID (0 origin. Max 15). */
142 const CpuId MaskCpuId = 0x0f; /* Lower 4 bits are valid. */
143 const CpuId MaxCpuId = MaskCpuId;
144 #endif
145 
146 /*****************************************************************
147  * Memory Pool Attributes (12 or 16bytes)
148  *****************************************************************/
149 struct PoolAttr {
150  uint8_t id;
151  PoolType type; /* pool type */
152  NumSeg num_segs; /* number of memory segments */
153 #ifdef CONFIG_MEMUTILS_MEMORY_MANAGER_USE_FENCE
154  bool fence;
155 #endif
156 #ifdef USE_MEMMGR_MULTI_CORE
157  LockId spl_id;
158 #endif
159  PoolAddr addr; /* pool address */
160  PoolSize size; /* pool size (bytes) */
161 
162 #ifdef USE_MEMMGR_DEBUG_OUTPUT
163  void printInfo(bool newline = true) const {
164  printf("PoolId=%d Type=%d NumSegs=%3d Addr=%08x Size=%08x",
165  id, type, num_segs, addr, size);
166 #ifdef CONFIG_MEMUTILS_MEMORY_MANAGER_USE_FENCE
167  printf(" fence=%d", fence);
168 #endif
169 #ifdef USE_MEMMGR_MULTI_CORE
170  printf(" Spinlock=%d", spl_id);
171 #endif
172  if (newline) printf("\n");
173  }
174 #endif /* USE_MEMMGR_DEBUG_OUTPUT */
175 }; /* struct PoolAttr */
176 
178  PoolId id; /* pool ID */
179  PoolType type; /* pool type */
180  NumSeg num_segs; /* number of memory segments */
181 #ifdef CONFIG_MEMUTILS_MEMORY_MANAGER_USE_FENCE
182  bool fence;
183 #endif
184 #ifdef USE_MEMMGR_MULTI_CORE
185  LockId spl_id;
186 #endif
187  PoolAddr addr; /* pool address */
188  PoolSize size; /* pool size (bytes) */
189 
190 #ifdef USE_MEMMGR_DEBUG_OUTPUT
191  void printInfo(bool newline = true) const {
192  printf("PoolId=%d Type=%d NumSegs=%3d Addr=%08x Size=%08x",
193  id, type, num_segs, addr, size);
194 #ifdef CONFIG_MEMUTILS_MEMORY_MANAGER_USE_FENCE
195  printf(" fence=%d", fence);
196 #endif
197 #ifdef USE_MEMMGR_MULTI_CORE
198  printf(" Spinlock=%d", spl_id);
199 #endif
200  if (newline) printf("\n");
201  }
202 #endif /* USE_MEMMGR_DEBUG_OUTPUT */
203 }; /* struct PoolAttr */
204 
205 inline bool operator == (PoolId id1, PoolId id2)
206 {
207  return (id1.sec == id2.sec && id1.pool == id2.pool);
208 }
209 
210 inline bool operator != (PoolId id1, PoolId id2)
211 {
212  return !(id1.sec == id2.sec && id1.pool == id2.pool);
213 }
214 
215 } /* namespace MemMgrLite */
216 
225 #endif /* MEMMGRTYPES_H_INCLUDED */
uint16_t id
Definition: video.h:86
uint8_t NumLayout
Definition: MemMgrTypes.h:82
uint8_t PoolType
Definition: MemMgrTypes.h:95
Definition: MemMgrTypes.h:109
Definition: MemMgrTypes.h:88
Definition: MemMgrTypes.h:177
namespace for "Memory Manager".
Definition: MemMgrTypes.h:106
uint16_t size
Definition: video.h:86
Definition: MemMgrTypes.h:149