]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pasdk/test_dsp/sio/sio.c
Update test_arm and test_dsp projects for new locations of IPC and PDK eng
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / sio / sio.c
2 /*
3 Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
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 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 #include <string.h> // for memset
37 #include <xdc/std.h>
38 #include <xdc/cfg/global.h>
39 #include <xdc/runtime/Error.h>
40 #include <xdc/runtime/Log.h>
41 #include <xdc/runtime/Memory.h>
43 #include <ti/sysbios/BIOS.h>
44 #include <ti/sysbios/knl/Semaphore.h>
46 #include "sio.h"
48 #include "inpbuf.h"
49 #include "outbuf.h"
51 #include "pafsio.h"
53 #include "paftyp.h"
54 #include "pafdec.h"
56 #include "paf_heapMgr.h"
58 #include "fwkPort.h"
59 #include "dbgDib.h"
60 #include "dbgDob.h"
62 #ifdef SIMULATE_SIO
63 static PAF_InpBufConfig *gpInpBufConfig;
64 static PAF_OutBufConfig *gpOutBufConfig;
66 static Int8 gPafSampRate=PAF_SAMPLERATE_48000HZ;
67 static Int16 gIbPcmFrameLength=0;
69 #endif // SIMULATE_SIO
71 // stub for SIO create()
72 SIO_Handle SIO_create(
73     String name, 
74     Int mode, 
75     size_t size, 
76     SIO_Attrs *attrs
77 )
78 {
79     SIO_Handle  stream;
80 #ifdef SIMULATE_SIO
81     DEV_Handle  device;                 /* == stream */
82     Error_Block eb;
83 #endif // SIMULATE_SIO
85     Log_info2("SIO_create():mode=%d, size=%d", mode, size);
86 #ifdef SIMULATE_SIO    
87     Error_init(&eb);
88     stream = (SIO_Handle)Memory_calloc(NULL, sizeof(SIO_Obj), 0, &eb);
89     
90     /* first field in SIO_Obj is a DEV_Obj */
91     device = (DEV_Handle)stream;    
92     
93     /* fill in device object fields */
94     device->mode = mode;                /* DEV_INPUT or DEV_OUTPUT */
95     
96     Log_info1("SIO_create():stream=0x%x", (IArg)stream);
97 #else // SIMULATE_SIO
98     SIO2_Attrs attrs2;
99     attrs2.nbufs  = attrs->nbufs;
100     attrs2.bufSeg = (IHeap_Handle)pafHeapMgr_readHeapHandle(attrs->segid);
101     attrs2.align  = attrs->align;
102     attrs2.flush  = attrs->flush;
103     attrs2.model  = attrs->model;
104     attrs2.timeout = attrs->timeout;
105     attrs2.callback = attrs->callback;
106     stream = SIO2_create(name, mode, size, &attrs2);
107 #endif // SIMULATE_SIO
109     return stream;
112 // stub for SIO_ctrl()
113 SIO_ctrl(
114     SIO_Handle stream, 
115     Uns cmd, 
116     Arg arg
119 #ifdef SIMULATE_SIO
120     PAF_SIO_InputStatus *pInputStatus;
121     XDAS_Int8 *pSourceProgram;
122 #endif // SIMULATE_SIO
124 #ifdef SIMULATE_SIO    
125     // Set values to same values from I-topo PCM, 48 kHz from DA830 EVM
126     switch (cmd)
127     {
128         case PAF_SIO_CONTROL_GET_INPUT_STATUS:
129             //Log_info3("SIO_ctrl():stream=0x%x, cmd=0x%x, arg=%d", (IArg)stream, cmd, arg);    
130             pInputStatus = (PAF_SIO_InputStatus *)arg;
131             pInputStatus->lock = 0x01;
132             pInputStatus->nonaudio = 0x01;
133             pInputStatus->emphasis = 0x01;
134             pInputStatus->sampleRateMeasured = gPafSampRate;
135             pInputStatus->sampleRateData = gPafSampRate;
136             break;
137         case PAF_SIO_CONTROL_GET_SOURCEPROGRAM:
138             //Log_info3("SIO_ctrl():stream=0x%x, cmd=0x%x, arg=%d", (IArg)stream, cmd, arg);
139             pSourceProgram = (XDAS_Int8 *)arg;
140             *pSourceProgram = PAF_SOURCE_PCM;
141             break;
142         case PAF_SIO_CONTROL_SET_PCMFRAMELENGTH:
143             //Log_info3("SIO_ctrl():stream=0x%x, cmd=0x%x, arg=%d", (IArg)stream, cmd, arg);    
144             gIbPcmFrameLength = arg;
145             break;
146         default:
147             //Log_info3("SIO_ctrl():unsupported command, stream=0x%x, cmd=0x%x, arg=%d", (IArg)stream, cmd, arg);    
149             break;
150     }
151     
152     return SYS_OK;
153 #else
154     return SIO2_ctrl(stream, cmd, arg);
155 #endif
158 // stub for _SIO_idle
159 Int _SIO_idle(
160     SIO_Handle stream, 
161     Bool flush
164 #ifdef SIMULATE_SIO
165     Log_info2("SIO_idle():stream=0x%x, flush=%d,arg=%d", (IArg)stream, flush);
166 #endif // SIMULATE_SIO
167     
168 #ifndef SIMULATE_SIO
169     return _SIO2_idle(stream, flush);
170 #else // SIMULATE_SIO
171     return SYS_OK;
172 #endif // SIMULATE_SIO
175 // stub for SIO_issue()
176 Int SIO_issue(
177     SIO_Handle stream, 
178     Ptr pbuf, 
179     size_t nbytes, 
180     Arg arg
183 #ifdef SIMULATE_SIO        
184     switch (arg)
185     {
186         case 0:
187             //Log_info4("SIO_issue():Tx stream=0x%x, pbuf=0x%x, nbytes=%d, arg=0x%x", (IArg)stream, (IArg)pbuf, nbytes, arg);
188     
189             //
190             // Send full buffer to Tx SIO driver
191             //
192             
193             // Capture Tx data here.
194             // Get data in pbuf->pntr.pSmInt.
195             gpOutBufConfig = (PAF_OutBufConfig *)pbuf;
196             gpOutBufConfig->stride = 8;
197             gpOutBufConfig->sizeofElement = 3;
198             gpOutBufConfig->precision = 24;
199             gpOutBufConfig->sizeofBuffer = gpOutBufConfig->allocation;           
200             
201             capOb(gpOutBufConfig);
202             
203             break;
204         case PAF_SIO_REQUEST_SYNC:
205         case PAF_SIO_REQUEST_NEWFRAME:
206             //Log_info4("SIO_issue():Rx stream=0x%x, pbuf=0x%x, nbytes=%d, arg=0x%x", (IArg)stream, (IArg)pbuf, nbytes, arg);
207             
208             //
209             // Send empty buffer to Rx SIO driver
210             //
211             gpInpBufConfig = (PAF_InpBufConfig *)pbuf;
212             break;
213         default:
214             //Log_info4("SIO_issue():unsupported arg, stream=0x%x, pbuf=0x%x, nbytes=%d, arg=0x%x", (IArg)stream, (IArg)pbuf, nbytes, arg);
215             break;
216     }
217     
218     return SYS_OK;
219 #else // SIMULATE_SIO
220     return SIO2_issue(stream, pbuf, nbytes, arg);
221 #endif // SIMULATE_SIO
224 // stub for SIO_reclaim()
225 Int SIO_reclaim(
226     SIO_Handle stream, 
227     Ptr *ppbuf, 
228     Arg *parg
230 {    
231 #ifdef SIMULATE_SIO
232     DEV_Handle  device;                 /* == stream */
233     
234     /* first field in SIO_Obj is a DEV_Obj */
235     device = (DEV_Handle)stream;    
237     if (device->mode == 0) // Rx
238     {
239         Log_info4("SIO_reclaim():Rx stream=0x%x, ppbuf=0x%x, parg=0x%x, mode=%d", (IArg)stream, (IArg)ppbuf, (IArg)parg, device->mode);
240     
241         //
242         // Receive full buffer from Rx SIO driver.
243         //
244         gpInpBufConfig->sizeofBuffer = 180224;
245         gpInpBufConfig->sizeofElement = 4;
246         gpInpBufConfig->stride = 8;
247         //gpInpBufConfig->deliverZeros = 1;
248         gpInpBufConfig->frameLength = 2048; // = stride * PCM frame length = 8 ch * 256 samp/ch = 2048 samp
249         gpInpBufConfig->lengthofData = 2048;
251         // Generate Rx data here.
252         // Put data in gpInpBufConfig->pntr.pLgInt.
253         memset(gpInpBufConfig->pntr.pSmInt, 0, 
254             gpInpBufConfig->frameLength*gpInpBufConfig->sizeofElement);
255         genSinIb(gpInpBufConfig);
256         
257         *ppbuf = gpInpBufConfig;
258         
259         // Simulate Rx SIO_reclaim() pend
260         Semaphore_pend(semaphoreRxAudio, BIOS_WAIT_FOREVER); 
262         return sizeof(PAF_InpBufConfig);
263     }
264     else if (device->mode == 1) // Tx
265     {
266         Log_info4("SIO_reclaim():Tx stream=0x%x, ppbuf=0x%x, parg=0x%x, mode=%d", (IArg)stream, (IArg)ppbuf, (IArg)parg, device->mode);
267         
268         //
269         // Receive empty buffer from Tx SIO driver
270         //
271         *ppbuf = gpOutBufConfig;
272  
273         // Simulate Tx SIO_reclaim() pend
274         Semaphore_pend(semaphoreTxAudio, BIOS_WAIT_FOREVER); 
275  
276         return sizeof(PAF_OutBufConfig);
277     }
278     else
279     {
280         Log_info4("SIO_reclaim():unsupported device mode, stream=0x%x, ppbuf=0x%x, parg=0x%x, mode=%d", (IArg)stream, (IArg)ppbuf, (IArg)parg, device->mode);
281         return -1;
282     }
283 #else // SIMULATE_SIO
284     DEV2_Handle  device;                 /* == stream */
286     /* first field in SIO_Obj is a DEV_Obj */
287     device = (DEV2_Handle)stream;
288     Log_info4("SIO_reclaim:stream=0x%x, ppbuf=0x%x, parg=0x%x, mode=%d", (IArg)stream, (IArg)ppbuf, (IArg)parg, device->mode);
290     return SIO2_reclaim(stream, ppbuf, parg);
291 #endif // SIMULATE_SIO