blob: 1065336082dac323f7f6f8243b358b194ab7a01a [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;
Ranjani Sridharane822cfa2018-06-27 20:40:18 -0700131 int deadline;
Ranjani Sridharan46704022018-05-31 19:29:05 -0700132 char message[DEBUG_MSG_LEN];
133
134 deadline = ipc_pipe->deadline;
Ranjani Sridharan46704022018-05-31 19:29:05 -0700135
136 /* Compute period from sample rates */
Ranjani Sridharane822cfa2018-06-27 20:40:18 -0700137 fs_period = (int)(0.9999 + fs_in * deadline / 1e6);
Ranjani Sridharan46704022018-05-31 19:29:05 -0700138 sprintf(message, "period sample count %d\n", fs_period);
139 debug_print(message);
140
141 /* set pcm params */
142 params.comp_id = ipc_pipe->comp_id;
143 params.params.buffer_fmt = SOF_IPC_BUFFER_INTERLEAVED;
144 params.params.frame_fmt = find_format(bits_in);
145 params.params.direction = SOF_IPC_STREAM_PLAYBACK;
Ranjani Sridharane822cfa2018-06-27 20:40:18 -0700146 params.params.rate = fs_in;
Ranjani Sridharan46704022018-05-31 19:29:05 -0700147 params.params.channels = nch;
148 switch (params.params.frame_fmt) {
149 case(SOF_IPC_FRAME_S16_LE):
150 params.params.sample_container_bytes = 2;
151 params.params.sample_valid_bytes = 2;
152 params.params.host_period_bytes = fs_period * nch *
153 params.params.sample_container_bytes;
154 break;
155 case(SOF_IPC_FRAME_S24_4LE):
156 params.params.sample_container_bytes = 4;
157 params.params.sample_valid_bytes = 3;
158 params.params.host_period_bytes = fs_period * nch *
159 params.params.sample_container_bytes;
160 break;
161 case(SOF_IPC_FRAME_S32_LE):
162 params.params.sample_container_bytes = 4;
163 params.params.sample_valid_bytes = 4;
164 params.params.host_period_bytes = fs_period * nch *
165 params.params.sample_container_bytes;
166 break;
167 default:
168 fprintf(stderr, "error: invalid frame format\n");
169 return -EINVAL;
170 }
171
172 /* get scheduling component device for pipeline*/
173 pcm_dev = ipc_get_comp(ipc, ipc_pipe->sched_id);
174 if (!pcm_dev) {
175 fprintf(stderr, "error: ipc get comp\n");
176 return -EINVAL;
177 }
178
179 /* point to pipeline */
180 cd = pcm_dev->cd;
181 p = pcm_dev->cd->pipeline;
182 if (!p) {
183 fprintf(stderr, "error: pipeline NULL\n");
184 return -EINVAL;
185 }
186
187 /* pipeline params */
188 ret = pipeline_params(p, cd, &params);
189 if (ret < 0)
190 fprintf(stderr, "error: pipeline_params\n");
191
192 return ret;
193}
194
Ranjani Sridharan03067c62018-06-27 15:09:25 -0700195/* getindex of shared library from table */
196int get_index_by_name(char *comp_type,
197 struct shared_lib_table *lib_table)
198{
199 int i;
200
201 for (i = 0; i < NUM_WIDGETS_SUPPORTED; i++) {
202 if (!strcmp(comp_type, lib_table[i].comp_name))
203 return i;
204 }
205
206 return -EINVAL;
207}
208
209/* getindex of shared library from table by widget type*/
210int get_index_by_type(uint32_t comp_type,
211 struct shared_lib_table *lib_table)
212{
213 int i;
214
215 for (i = 0; i < NUM_WIDGETS_SUPPORTED; i++) {
216 if (comp_type == lib_table[i].widget_type)
217 return i;
218 }
219
220 return -EINVAL;
221}
222
Ranjani Sridharan46704022018-05-31 19:29:05 -0700223/* The following definitions are to satisfy libsof linker errors */
224
225struct dai *dai_get(uint32_t type, uint32_t index)
226{
227 return NULL;
228}
229
Ranjani Sridharan700197d2018-06-11 20:37:14 -0700230struct dma *dma_get(uint32_t dir, uint32_t caps, uint32_t dev, uint32_t flags)
Ranjani Sridharan46704022018-05-31 19:29:05 -0700231{
232 return NULL;
233}