1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: PatternMgr.cpp
4 * Description: Pattern Manager
5 *
6 * The link between a pattern and a memory manager.
7 * Allow creation and initialization of patterns
8 *
9 * $Date: 20. June 2019
10 * $Revision: V1.0.0
11 *
12 * Target Processor: Cortex-M cores
13 * -------------------------------------------------------------------- */
14 /*
15 * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 *
19 * Licensed under the Apache License, Version 2.0 (the License); you may
20 * not use this file except in compliance with the License.
21 * You may obtain a copy of the License at
22 *
23 * www.apache.org/licenses/LICENSE-2.0
24 *
25 * Unless required by applicable law or agreed to in writing, software
26 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
27 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28 * See the License for the specific language governing permissions and
29 * limitations under the License.
30 */
31 #include "Test.h"
32 #include "arm_math_types.h"
33 #include "arm_math_types_f16.h"
34
35 namespace Client
36 {
PatternMgr(IO * io,Memory * mem)37 PatternMgr::PatternMgr(IO* io, Memory *mem)
38 {
39 m_io = io;
40 m_mem = mem;
41 }
42
43 #define LOCAL(TYPE,EXT) \
44 TYPE *PatternMgr::local_##EXT(Testing::nbSamples_t nbSamples) \
45 { \
46 return((TYPE*)(m_mem->NewBuffer(sizeof(TYPE)*nbSamples))); \
47 }
48
LOCAL(float64_t,f64)49 LOCAL(float64_t,f64)
50 LOCAL(float32_t,f32)
51 #if !defined( __CC_ARM ) && defined(ARM_FLOAT16_SUPPORTED)
52 LOCAL(float16_t,f16)
53 #endif
54 LOCAL(q63_t,q63)
55 LOCAL(q31_t,q31)
56 LOCAL(q15_t,q15)
57 LOCAL(q7_t,q7)
58 LOCAL(uint64_t,u64)
59 LOCAL(uint32_t,u32)
60 LOCAL(uint16_t,u16)
61 LOCAL(uint8_t,u8)
62
63 float64_t *PatternMgr::load_f64(Testing::PatternID_t id,Testing::nbSamples_t& nbSamples,Testing::nbSamples_t maxSamples)
64 {
65
66 nbSamples=m_io->GetPatternSize(id);
67
68 if ((maxSamples != MAX_NB_SAMPLES) && (maxSamples < nbSamples))
69 {
70 nbSamples = maxSamples;
71 }
72
73 char *b = m_mem->NewBuffer(sizeof(float64_t)*nbSamples);
74 if (b != NULL)
75 {
76 m_io->ImportPattern_f64(id,b,nbSamples);
77 }
78 return((float64_t*)b);
79
80 }
81
load_f32(Testing::PatternID_t id,Testing::nbSamples_t & nbSamples,Testing::nbSamples_t maxSamples)82 float32_t *PatternMgr::load_f32(Testing::PatternID_t id,Testing::nbSamples_t& nbSamples,Testing::nbSamples_t maxSamples)
83 {
84 nbSamples=m_io->GetPatternSize(id);
85
86 if ((maxSamples != MAX_NB_SAMPLES) && (maxSamples < nbSamples))
87 {
88 nbSamples = maxSamples;
89 }
90
91 char *b = m_mem->NewBuffer(sizeof(float32_t)*nbSamples);
92 if (b != NULL)
93 {
94 m_io->ImportPattern_f32(id,b,nbSamples);
95 }
96 return((float32_t*)b);
97
98 }
99
100 #if !defined( __CC_ARM ) && defined(ARM_FLOAT16_SUPPORTED)
load_f16(Testing::PatternID_t id,Testing::nbSamples_t & nbSamples,Testing::nbSamples_t maxSamples)101 float16_t *PatternMgr::load_f16(Testing::PatternID_t id,Testing::nbSamples_t& nbSamples,Testing::nbSamples_t maxSamples)
102 {
103 nbSamples=m_io->GetPatternSize(id);
104
105 if ((maxSamples != MAX_NB_SAMPLES) && (maxSamples < nbSamples))
106 {
107 nbSamples = maxSamples;
108 }
109
110 char *b = m_mem->NewBuffer(sizeof(float16_t)*nbSamples);
111 if (b != NULL)
112 {
113 m_io->ImportPattern_f16(id,b,nbSamples);
114 }
115 return((float16_t*)b);
116
117 }
118 #endif
119
load_q63(Testing::PatternID_t id,Testing::nbSamples_t & nbSamples,Testing::nbSamples_t maxSamples)120 q63_t *PatternMgr::load_q63(Testing::PatternID_t id,Testing::nbSamples_t& nbSamples,Testing::nbSamples_t maxSamples)
121 {
122 nbSamples=m_io->GetPatternSize(id);
123
124 if ((maxSamples != MAX_NB_SAMPLES) && (maxSamples < nbSamples))
125 {
126 nbSamples = maxSamples;
127 }
128
129 char *b = m_mem->NewBuffer(sizeof(q63_t)*nbSamples);
130 if (b != NULL)
131 {
132 m_io->ImportPattern_q63(id,b,nbSamples);
133 }
134 return((q63_t*)b);
135 }
136
137
load_q31(Testing::PatternID_t id,Testing::nbSamples_t & nbSamples,Testing::nbSamples_t maxSamples)138 q31_t *PatternMgr::load_q31(Testing::PatternID_t id,Testing::nbSamples_t& nbSamples,Testing::nbSamples_t maxSamples)
139 {
140 nbSamples=m_io->GetPatternSize(id);
141
142 if ((maxSamples != MAX_NB_SAMPLES) && (maxSamples < nbSamples))
143 {
144 nbSamples = maxSamples;
145 }
146
147 char *b = m_mem->NewBuffer(sizeof(q31_t)*nbSamples);
148 if (b != NULL)
149 {
150 m_io->ImportPattern_q31(id,b,nbSamples);
151 }
152 return((q31_t*)b);
153 }
154
load_q15(Testing::PatternID_t id,Testing::nbSamples_t & nbSamples,Testing::nbSamples_t maxSamples)155 q15_t *PatternMgr::load_q15(Testing::PatternID_t id,Testing::nbSamples_t& nbSamples,Testing::nbSamples_t maxSamples)
156 {
157 nbSamples=m_io->GetPatternSize(id);
158
159 if ((maxSamples != MAX_NB_SAMPLES) && (maxSamples < nbSamples))
160 {
161 nbSamples = maxSamples;
162 }
163
164 char *b = m_mem->NewBuffer(sizeof(q15_t)*nbSamples);
165 if (b != NULL)
166 {
167 m_io->ImportPattern_q15(id,b,nbSamples);
168 }
169 return((q15_t*)b);
170 }
171
load_q7(Testing::PatternID_t id,Testing::nbSamples_t & nbSamples,Testing::nbSamples_t maxSamples)172 q7_t *PatternMgr::load_q7(Testing::PatternID_t id,Testing::nbSamples_t& nbSamples,Testing::nbSamples_t maxSamples)
173 {
174 nbSamples=m_io->GetPatternSize(id);
175
176 if ((maxSamples != MAX_NB_SAMPLES) && (maxSamples < nbSamples))
177 {
178 nbSamples = maxSamples;
179 }
180
181 char *b = m_mem->NewBuffer(sizeof(q7_t)*nbSamples);
182 if (b != NULL)
183 {
184 m_io->ImportPattern_q7(id,b,nbSamples);
185 }
186 return((q7_t*)b);
187 }
188
load_u64(Testing::PatternID_t id,Testing::nbSamples_t & nbSamples,Testing::nbSamples_t maxSamples)189 uint64_t *PatternMgr::load_u64(Testing::PatternID_t id,Testing::nbSamples_t& nbSamples,Testing::nbSamples_t maxSamples)
190 {
191 nbSamples=m_io->GetPatternSize(id);
192
193 if ((maxSamples != MAX_NB_SAMPLES) && (maxSamples < nbSamples))
194 {
195 nbSamples = maxSamples;
196 }
197
198 char *b = m_mem->NewBuffer(sizeof(uint64_t)*nbSamples);
199 if (b != NULL)
200 {
201 m_io->ImportPattern_u64(id,b,nbSamples);
202 }
203 return((uint64_t*)b);
204 }
205
load_u32(Testing::PatternID_t id,Testing::nbSamples_t & nbSamples,Testing::nbSamples_t maxSamples)206 uint32_t *PatternMgr::load_u32(Testing::PatternID_t id,Testing::nbSamples_t& nbSamples,Testing::nbSamples_t maxSamples)
207 {
208 nbSamples=m_io->GetPatternSize(id);
209
210 if ((maxSamples != MAX_NB_SAMPLES) && (maxSamples < nbSamples))
211 {
212 nbSamples = maxSamples;
213 }
214
215 char *b = m_mem->NewBuffer(sizeof(uint32_t)*nbSamples);
216 if (b != NULL)
217 {
218 m_io->ImportPattern_u32(id,b,nbSamples);
219 }
220 return((uint32_t*)b);
221 }
222
load_u16(Testing::PatternID_t id,Testing::nbSamples_t & nbSamples,Testing::nbSamples_t maxSamples)223 uint16_t *PatternMgr::load_u16(Testing::PatternID_t id,Testing::nbSamples_t& nbSamples,Testing::nbSamples_t maxSamples)
224 {
225 nbSamples=m_io->GetPatternSize(id);
226
227 if ((maxSamples != MAX_NB_SAMPLES) && (maxSamples < nbSamples))
228 {
229 nbSamples = maxSamples;
230 }
231
232 char *b = m_mem->NewBuffer(sizeof(uint16_t)*nbSamples);
233 if (b != NULL)
234 {
235 m_io->ImportPattern_u16(id,b,nbSamples);
236 }
237 return((uint16_t*)b);
238 }
239
load_u8(Testing::PatternID_t id,Testing::nbSamples_t & nbSamples,Testing::nbSamples_t maxSamples)240 uint8_t *PatternMgr::load_u8(Testing::PatternID_t id,Testing::nbSamples_t& nbSamples,Testing::nbSamples_t maxSamples)
241 {
242 nbSamples=m_io->GetPatternSize(id);
243
244 if ((maxSamples != MAX_NB_SAMPLES) && (maxSamples < nbSamples))
245 {
246 nbSamples = maxSamples;
247 }
248
249 char *b = m_mem->NewBuffer(sizeof(uint8_t)*nbSamples);
250 if (b != NULL)
251 {
252 m_io->ImportPattern_u8(id,b,nbSamples);
253 }
254 return((uint8_t*)b);
255 }
256
dumpPattern_f64(Testing::outputID_t id,Testing::nbSamples_t nbSamples,float64_t * data)257 void PatternMgr::dumpPattern_f64(Testing::outputID_t id,Testing::nbSamples_t nbSamples,float64_t* data)
258 {
259
260 m_io->DumpPattern_f64(id,nbSamples,data);
261 }
262
dumpPattern_f32(Testing::outputID_t id,Testing::nbSamples_t nbSamples,float32_t * data)263 void PatternMgr::dumpPattern_f32(Testing::outputID_t id,Testing::nbSamples_t nbSamples,float32_t* data)
264 {
265 m_io->DumpPattern_f32(id,nbSamples,data);
266 }
267
268 #if !defined( __CC_ARM ) && defined(ARM_FLOAT16_SUPPORTED)
dumpPattern_f16(Testing::outputID_t id,Testing::nbSamples_t nbSamples,float16_t * data)269 void PatternMgr::dumpPattern_f16(Testing::outputID_t id,Testing::nbSamples_t nbSamples,float16_t* data)
270 {
271 m_io->DumpPattern_f16(id,nbSamples,data);
272 }
273 #endif
274
dumpPattern_q63(Testing::outputID_t id,Testing::nbSamples_t nbSamples,q63_t * data)275 void PatternMgr::dumpPattern_q63(Testing::outputID_t id,Testing::nbSamples_t nbSamples,q63_t* data)
276 {
277 m_io->DumpPattern_q63(id,nbSamples,data);
278 }
279
dumpPattern_q31(Testing::outputID_t id,Testing::nbSamples_t nbSamples,q31_t * data)280 void PatternMgr::dumpPattern_q31(Testing::outputID_t id,Testing::nbSamples_t nbSamples,q31_t* data)
281 {
282 m_io->DumpPattern_q31(id,nbSamples,data);
283 }
284
dumpPattern_q15(Testing::outputID_t id,Testing::nbSamples_t nbSamples,q15_t * data)285 void PatternMgr::dumpPattern_q15(Testing::outputID_t id,Testing::nbSamples_t nbSamples,q15_t* data)
286 {
287 m_io->DumpPattern_q15(id,nbSamples,data);
288 }
289
dumpPattern_q7(Testing::outputID_t id,Testing::nbSamples_t nbSamples,q7_t * data)290 void PatternMgr::dumpPattern_q7(Testing::outputID_t id,Testing::nbSamples_t nbSamples,q7_t* data)
291 {
292 m_io->DumpPattern_q7(id,nbSamples,data);
293 }
294
dumpPattern_u64(Testing::outputID_t id,Testing::nbSamples_t nbSamples,uint64_t * data)295 void PatternMgr::dumpPattern_u64(Testing::outputID_t id,Testing::nbSamples_t nbSamples,uint64_t* data)
296 {
297 m_io->DumpPattern_u64(id,nbSamples,data);
298 }
299
dumpPattern_u32(Testing::outputID_t id,Testing::nbSamples_t nbSamples,uint32_t * data)300 void PatternMgr::dumpPattern_u32(Testing::outputID_t id,Testing::nbSamples_t nbSamples,uint32_t* data)
301 {
302 m_io->DumpPattern_u32(id,nbSamples,data);
303 }
304
dumpPattern_u16(Testing::outputID_t id,Testing::nbSamples_t nbSamples,uint16_t * data)305 void PatternMgr::dumpPattern_u16(Testing::outputID_t id,Testing::nbSamples_t nbSamples,uint16_t* data)
306 {
307 m_io->DumpPattern_u16(id,nbSamples,data);
308 }
309
dumpPattern_u8(Testing::outputID_t id,Testing::nbSamples_t nbSamples,uint8_t * data)310 void PatternMgr::dumpPattern_u8(Testing::outputID_t id,Testing::nbSamples_t nbSamples,uint8_t* data)
311 {
312 m_io->DumpPattern_u8(id,nbSamples,data);
313 }
314
freeAll()315 void PatternMgr::freeAll()
316 {
317 m_mem->FreeMemory();
318 }
319
320 }
321