blob: 7ed63083f1d815d621b339d9daca8cde449781b2 [file] [log] [blame]
Ranjani Sridharan46704022018-05-31 19:29:05 -07001/*
2 * Copyright (c) 2018, Intel Corporation
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the Intel Corporation nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Author(s): Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
29 * Liam Girdwood <liam.r.girdwood@linux.intel.com>
30 * Keyon Jie <yang.jie@linux.intel.com>
31 * Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
32 */
33
34#include <stdint.h>
35#include <stddef.h>
36#include <time.h>
37#include <stdio.h>
38#include <stdlib.h>
39#include <string.h>
40#include <math.h>
41#include <sof/task.h>
42#include <sof/alloc.h>
43#include <sof/ipc.h>
44#include <sof/dai.h>
45#include <sof/dma.h>
46#include <sof/work.h>
47#include <sof/wait.h>
48#include <sof/intel-ipc.h>
49#include <sof/audio/pipeline.h>
50#include "host/common_test.h"
51#include "host/topology.h"
52
53/* print debug messages */
54void debug_print(char *message)
55{
56 if (debug)
57 printf("debug: %s", message);
58}
59
60/* testbench helper functions for pipeline setup and trigger */
61
62int tb_pipeline_setup(struct sof *sof)
63{
64 /* init components */
65 sys_comp_init();
66
67 /* init IPC */
68 if (ipc_init(sof) < 0) {
69 fprintf(stderr, "error: IPC init\n");
70 return -EINVAL;
71 }
72
73 /* init scheduler */
74 if (scheduler_init(sof) < 0) {
75 fprintf(stderr, "error: scheduler init\n");
76 return -EINVAL;
77 }
78
79 debug_print("ipc and scheduler initialized\n");
80
81 return 0;
82}
83
84/* set up pcm params, prepare and trigger pipeline */
85int tb_pipeline_start(struct ipc *ipc, int nch, char *bits_in,
86 struct sof_ipc_pipe_new *ipc_pipe)
87{
88 struct ipc_comp_dev *pcm_dev;
89 struct pipeline *p;
90 struct comp_dev *cd;
91 int ret;
92
93 /* set up pipeline params */
94 ret = tb_pipeline_params(ipc, nch, bits_in, ipc_pipe);
95 if (ret < 0) {
96 fprintf(stderr, "error: pipeline params\n");
97 return -EINVAL;
98 }
99
100 /* Get IPC component device for pipeline */
101 pcm_dev = ipc_get_comp(ipc, ipc_pipe->sched_id);
102 if (!pcm_dev) {
103 fprintf(stderr, "error: ipc get comp\n");
104 return -EINVAL;
105 }
106
107 /* Point to pipeline */
108 cd = pcm_dev->cd;
109 p = pcm_dev->cd->pipeline;
110
111 /* Component prepare */
112 ret = pipeline_prepare(p, cd);
113
114 /* Start the pipeline */
115 ret = pipeline_trigger(p, cd, COMP_TRIGGER_START);
116 if (ret < 0)
117 printf("Warning: Failed start pipeline command.\n");
118
119 return ret;
120}
121
122/* pipeline pcm params */
123int tb_pipeline_params(struct ipc *ipc, int nch, char *bits_in,
124 struct sof_ipc_pipe_new *ipc_pipe)
125{
126 int fs_period, ret = 0;
127 struct ipc_comp_dev *pcm_dev;
128 struct pipeline *p;
129 struct comp_dev *cd;
130 struct sof_ipc_pcm_params params;
131 int fs, deadline;
132 char message[DEBUG_MSG_LEN];
133
134 deadline = ipc_pipe->deadline;
135 fs = deadline * ipc_pipe->frames_per_sched;
136
137 /* Compute period from sample rates */
138 fs_period = (int)(0.9999 + fs * deadline / 1e6);
139 sprintf(message, "period sample count %d\n", fs_period);
140 debug_print(message);
141
142 /* set pcm params */
143 params.comp_id = ipc_pipe->comp_id;
144 params.params.buffer_fmt = SOF_IPC_BUFFER_INTERLEAVED;
145 params.params.frame_fmt = find_format(bits_in);
146 params.params.direction = SOF_IPC_STREAM_PLAYBACK;
147 params.params.rate = fs;
148 params.params.channels = nch;
149 switch (params.params.frame_fmt) {
150 case(SOF_IPC_FRAME_S16_LE):
151 params.params.sample_container_bytes = 2;
152 params.params.sample_valid_bytes = 2;
153 params.params.host_period_bytes = fs_period * nch *
154 params.params.sample_container_bytes;
155 break;
156 case(SOF_IPC_FRAME_S24_4LE):
157 params.params.sample_container_bytes = 4;
158 params.params.sample_valid_bytes = 3;
159 params.params.host_period_bytes = fs_period * nch *
160 params.params.sample_container_bytes;
161 break;
162 case(SOF_IPC_FRAME_S32_LE):
163 params.params.sample_container_bytes = 4;
164 params.params.sample_valid_bytes = 4;
165 params.params.host_period_bytes = fs_period * nch *
166 params.params.sample_container_bytes;
167 break;
168 default:
169 fprintf(stderr, "error: invalid frame format\n");
170 return -EINVAL;
171 }
172
173 /* get scheduling component device for pipeline*/
174 pcm_dev = ipc_get_comp(ipc, ipc_pipe->sched_id);
175 if (!pcm_dev) {
176 fprintf(stderr, "error: ipc get comp\n");
177 return -EINVAL;
178 }
179
180 /* point to pipeline */
181 cd = pcm_dev->cd;
182 p = pcm_dev->cd->pipeline;
183 if (!p) {
184 fprintf(stderr, "error: pipeline NULL\n");
185 return -EINVAL;
186 }
187
188 /* pipeline params */
189 ret = pipeline_params(p, cd, &params);
190 if (ret < 0)
191 fprintf(stderr, "error: pipeline_params\n");
192
193 return ret;
194}
195
Ranjani Sridharan03067c62018-06-27 15:09:25 -0700196/* getindex of shared library from table */
197int get_index_by_name(char *comp_type,
198 struct shared_lib_table *lib_table)
199{
200 int i;
201
202 for (i = 0; i < NUM_WIDGETS_SUPPORTED; i++) {
203 if (!strcmp(comp_type, lib_table[i].comp_name))
204 return i;
205 }
206
207 return -EINVAL;
208}
209
210/* getindex of shared library from table by widget type*/
211int get_index_by_type(uint32_t comp_type,
212 struct shared_lib_table *lib_table)
213{
214 int i;
215
216 for (i = 0; i < NUM_WIDGETS_SUPPORTED; i++) {
217 if (comp_type == lib_table[i].widget_type)
218 return i;
219 }
220
221 return -EINVAL;
222}
223
Ranjani Sridharan46704022018-05-31 19:29:05 -0700224/* The following definitions are to satisfy libsof linker errors */
225
226struct dai *dai_get(uint32_t type, uint32_t index)
227{
228 return NULL;
229}
230
Ranjani Sridharan700197d2018-06-11 20:37:14 -0700231struct dma *dma_get(uint32_t dir, uint32_t caps, uint32_t dev, uint32_t flags)
Ranjani Sridharan46704022018-05-31 19:29:05 -0700232{
233 return NULL;
234}