]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pasdk/common/dbgDib.c
PASDK-419:Update 3p-ip-dts submodule
[processor-sdk/performance-audio-sr.git] / pasdk / common / dbgDib.c
2 /*
3 Copyright (c) 2017, 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 memcpy
37 #include <xdc/std.h>
38 #include <xdc/runtime/Log.h>
40 #include <ti/sysbios/hal/Cache.h>
42 #include "common.h"
44 #ifndef _TMS320C6X
45 #include "c67x_cintrins.h"
46 #endif
48 #include "inpbuf.h"
49 #include "dbgDib.h"
51 // sinusoid generator parameters
52 /* Performs floating-point to 24-bit fixed point conversion.
53 Resulting fixed-point value is left-justified in 32-bit word. */
54 #define F2INT_SCALE     (float)0x7FFFFF
55 #define F2INT_ROUND(x)  _spint(x)
56 #define F2INT(x)        (((Int32)F2INT_ROUND(F2INT_SCALE * x) << 0x8) & 0xFFFFFF00)
58 #define TWO_PI          (6.283185307179586476925286766559L)
59 #define FS_48KHZ        (48000.0)
60 #define TWOPIOVERSRATE  ( TWO_PI / FS_48KHZ )
62 #define SINP_MAX_CHS    ( 8 )       // sin probe maximum number of channels
63 Int8 gSinPNumChs = SINP_MAX_CHS;    // sin probe number of channels 
64 Int8 gSinPChIdx = 0;                // sin probe channel index
65 // sinusoid data generated on these DIB channels
66 Int8 gSinPCh[SINP_MAX_CHS] = {0,1,2,3,4,5,6,7};
68 #define SINP_MAX_GEN ( 2 )      // sin probe maximum number of generators
69 // Configurable from CCS
70 Int8 gSinPNumGen = SINP_MAX_GEN;
71 float gSineProbeAmp[SINP_MAX_GEN]   = {0.0625, 0.125};  // sinusoid amplitudes
72 float gSineProbeFreq[SINP_MAX_GEN]  = {440.0, 1004.0};  // sinusoid frequencies (Hz)
74 static double gSineProbeArg[SINP_MAX_GEN] = {0.0, 0.0};  // sinusoid function arguments
76 #ifdef DBG_CAP_IP_PCM
77 // IB capture (PCM) buffer
78 #ifdef _TMS320C6X
79 #pragma DATA_SECTION(gCapIbPcmBuf, ".gCapIbPcmBuf");
80 Int32 gCapIbPcmBuf[CAP_IB_PCM_MAX_NUM_CH][CAP_IB_PCM_MAX_NUM_SAMP];
81 #else
82 Int32 gCapIbPcmBuf[CAP_IB_PCM_MAX_NUM_CH][CAP_IB_PCM_MAX_NUM_SAMP] __attribute__ ((section(".gCapIbPcmBuf")));
83 #endif
84 Int32 gCapIbPcmBufIdx=0;
85 Int32 gCapIbPcmBufWrapCnt=0;
86 static UInt32 capIbPcmStopCnt=5000;
87 #endif // DBG_CAP_IP_PCM
89 #ifdef DBG_CAP_IP
90 // IB capture buffer
91 #ifdef _TMS320C6X
92 #pragma DATA_SECTION(gCapIbBuf, ".gCapIbBuf");
93 Int8 gCapIbBuf[2][CAP_IB_BUF_SZ];
94 #else
95 Int8 gCapIbBuf[2][CAP_IB_BUF_SZ] __attribute__ ((section(".gCapIbBuf")));
96 //Int32 gCapIbBuf[CAP_IB_BUF_SZ] __attribute__ ((section(".noinit")));
97 #endif
98 Int32 gCapIbBufIdx[2]={0,0};
99 Int32 gCapIbBufWrapCnt[2]={0,0};
100 Int8 gCapIbBufPingPongSel=1;
101 Int32 gCapIbAccBytes=0;
102 Int32 gNumDiffFrame[2]={0,0};
103 #endif // DBG_CAP_IP
105 // Generate sinusoids in IB buffer
106 Void genSinIb(
107     PAF_InpBufConfig *pInpBufConfig
110     Int8 numCh;
111     Int16 numSamp;
112     Int8 genIdx;
113     double phaseInc, arg, amp;
114     Int32 *pCh;
115     Int16 i;
116     
117     numCh = pInpBufConfig->stride; // get number of channels
118     numSamp = pInpBufConfig->frameLength / numCh; // get number of samples to generate
120     for (genIdx=0; genIdx<gSinPNumGen; genIdx++)
121     {
122         // compute generator phase increment
123         phaseInc = (double)gSineProbeFreq[genIdx] * TWOPIOVERSRATE;
124         
125         arg = gSineProbeArg[genIdx]; // get generator arg
126         amp = gSineProbeAmp[genIdx]; // get generator amplitude
127         
128         // generate sinusoid on selected channel
129         pCh = &pInpBufConfig->pntr.pLgInt[gSinPCh[gSinPChIdx]];
130         for (i=0; i<numSamp; i++)
131         {
132             *pCh = F2INT(amp * sin(arg));
133             arg += phaseInc;
134             pCh += numCh; // skipped interleaved channels
135         }
136         
137         gSineProbeArg[genIdx] = arg; // save generator arg
138         
139         // update sin probe channel index
140         gSinPChIdx++;
141         if (gSinPChIdx >= gSinPNumChs)
142         {
143             gSinPChIdx = 0;
144         }
145     }
148 #ifdef DBG_CAP_IP_PCM
149 // Capture data in IB buffer to memory
150 Void capIbPcm(
151     PAF_InpBufConfig *pInpBufConfig
154     Int8 numCh;
155     Int16 numSamp;
156     Int8 sampSz;
157     Int32 samp;
158     Int8 *pCh;
159     Int16 i, j, k;
160     Int32 *pCapBuf;
162     if (--capIbPcmStopCnt == 0)
163     {
164         SW_BREAKPOINT;
165     }
167     numCh = pInpBufConfig->stride; // get number of channels
168     numSamp = pInpBufConfig->frameLength / numCh; // get number of samples to capture
169     sampSz = pInpBufConfig->sizeofElement; // get sample size (bytes)
170     
171     if ((CAP_IB_PCM_MAX_NUM_SAMP - gCapIbPcmBufIdx) < numSamp)
172     {
173         //return;
174         gCapIbPcmBufIdx = 0;
175         gCapIbPcmBufWrapCnt++;
176     }
177         
178     for (i=0; i<numCh; i++)
179     {
180         pCapBuf = &gCapIbPcmBuf[i][gCapIbPcmBufIdx];
181         pCh = &pInpBufConfig->pntr.pSmInt[i*sampSz];
182         for (j=0; j<numSamp; j++)
183         {
184             samp = (Int32)(*(pCh+sampSz-1));
185             for (k=sampSz-2; k>=0; k--)
186             {
187                 samp <<= 8;
188                 samp |= (UInt8)(*(pCh+k));
189             }
190             samp <<= 32-8*sampSz;
191             
192             *pCapBuf = samp;
193             pCapBuf++;
194             pCh += numCh * sampSz;
195         }
196     }
197     gCapIbPcmBufIdx += numSamp;
200 #endif // DBG_CAP_IP_PCM
202 #ifdef DBG_CAP_IP
203 // Reset IB capture buffer
204 Int capIbReset(Void)
206     gCapIbBufPingPongSel ^= 0x1;
207     gCapIbBufIdx[gCapIbBufPingPongSel] = 0;
208     gCapIbBufWrapCnt[gCapIbBufPingPongSel] = 0;
209     gNumDiffFrame[gCapIbBufPingPongSel] = 0;
210     gCapIbAccBytes=0;
212     return 0;
215 // Capture data in IB buffer to memory
216 Void capIb(
217     PAF_InpBufConfig *pInpBufConfig
220     UInt32 nBytes, bufEnd, currentBufSize, chunkSize, wrapSize;
221     
222     nBytes = pInpBufConfig->frameLength * pInpBufConfig->sizeofElement;
223     
224 #if 0
225     // FL: DDP debug
226     if (nBytes != 24576)
227     {
228         Log_info1("capIb(): nBytes=%d", nBytes);
229         gNumDiffFrame[gCapIbBufPingPongSel]++;
230     }
231 #endif    
232     
233     bufEnd = (Int) pInpBufConfig->base.pVoid + pInpBufConfig->sizeofBuffer;
234     currentBufSize = (bufEnd - (Int)pInpBufConfig->pntr.pSmInt);
236     if (currentBufSize >= nBytes)
237         chunkSize = nBytes;
238     else
239         chunkSize = currentBufSize;
241     wrapSize = nBytes - chunkSize;
243     if ((CAP_IB_BUF_SZ - gCapIbBufIdx[gCapIbBufPingPongSel]) < nBytes)
244     {
245             //return; // fixed buffer
246             gCapIbBufIdx[gCapIbBufPingPongSel] = 0;
247             gCapIbBufWrapCnt[gCapIbBufPingPongSel]++;
248     }
250     // invalidate input data
251     Cache_inv((Ptr)pInpBufConfig->pntr.pSmInt, chunkSize, Cache_Type_ALLD, 0);
252     Cache_wait();
254     memcpy(&gCapIbBuf[gCapIbBufPingPongSel][gCapIbBufIdx[gCapIbBufPingPongSel]], pInpBufConfig->pntr.pSmInt, chunkSize);
256     gCapIbBufIdx[gCapIbBufPingPongSel] += chunkSize;
257     gCapIbAccBytes += chunkSize;
259     if(wrapSize > 0)
260         {
261                 // invalidate input data
262                 Cache_inv((Ptr)pInpBufConfig->base.pSmInt, wrapSize, Cache_Type_ALLD, 0);
263                 Cache_wait();
264                 memcpy(&gCapIbBuf[gCapIbBufPingPongSel][gCapIbBufIdx[gCapIbBufPingPongSel]], pInpBufConfig->base.pSmInt, wrapSize);
265                 gCapIbBufIdx[gCapIbBufPingPongSel] += wrapSize;
266                 gCapIbAccBytes += wrapSize;
267         }
270 #endif // DBG_CAP_IP