1 #include <string.h> // for memset
2 #include <xdc/std.h>
3 #include <xdc/cfg/global.h>
4 #include <xdc/runtime/Error.h>
5 #include <xdc/runtime/Log.h>
6 #include <xdc/runtime/Memory.h>
8 #include <ti/sysbios/BIOS.h>
9 #include <ti/sysbios/knl/Semaphore.h>
11 #include "sio.h"
13 #include "inpbuf.h"
14 #include "outbuf.h"
16 #include "pafsio.h"
18 #include "paftyp.h"
19 #include "pafdec.h"
21 #include "paf_heapMgr.h"
23 #include "fwkPort.h"
24 #include "dbgDib.h"
25 #include "dbgDob.h"
27 #ifdef SIMULATE_SIO
28 static PAF_InpBufConfig *gpInpBufConfig;
29 static PAF_OutBufConfig *gpOutBufConfig;
31 static Int8 gPafSampRate=PAF_SAMPLERATE_48000HZ;
32 static Int16 gIbPcmFrameLength=0;
34 #endif // SIMULATE_SIO
36 // stub for SIO create()
37 SIO_Handle SIO_create(
38 String name,
39 Int mode,
40 size_t size,
41 SIO_Attrs *attrs
42 )
43 {
44 SIO_Handle stream;
45 #ifdef SIMULATE_SIO
46 DEV_Handle device; /* == stream */
47 Error_Block eb;
48 #endif // SIMULATE_SIO
50 Log_info2("SIO_create():mode=%d, size=%d", mode, size);
51 #ifdef SIMULATE_SIO
52 Error_init(&eb);
53 stream = (SIO_Handle)Memory_calloc(NULL, sizeof(SIO_Obj), 0, &eb);
55 /* first field in SIO_Obj is a DEV_Obj */
56 device = (DEV_Handle)stream;
58 /* fill in device object fields */
59 device->mode = mode; /* DEV_INPUT or DEV_OUTPUT */
61 Log_info1("SIO_create():stream=0x%x", (IArg)stream);
62 #else // SIMULATE_SIO
63 SIO2_Attrs attrs2;
64 attrs2.nbufs = attrs->nbufs;
65 attrs2.bufSeg = (IHeap_Handle)pafHeapMgr_readHeapHandle(attrs->segid);
66 attrs2.align = attrs->align;
67 attrs2.flush = attrs->flush;
68 attrs2.model = attrs->model;
69 attrs2.timeout = attrs->timeout;
70 attrs2.callback = attrs->callback;
71 stream = SIO2_create(name, mode, size, &attrs2);
72 #endif // SIMULATE_SIO
74 return stream;
75 }
77 // stub for SIO_ctrl()
78 SIO_ctrl(
79 SIO_Handle stream,
80 Uns cmd,
81 Arg arg
82 )
83 {
84 #ifdef SIMULATE_SIO
85 PAF_SIO_InputStatus *pInputStatus;
86 XDAS_Int8 *pSourceProgram;
87 #endif // SIMULATE_SIO
89 #ifdef SIMULATE_SIO
90 // Set values to same values from I-topo PCM, 48 kHz from DA830 EVM
91 switch (cmd)
92 {
93 case PAF_SIO_CONTROL_GET_INPUT_STATUS:
94 //Log_info3("SIO_ctrl():stream=0x%x, cmd=0x%x, arg=%d", (IArg)stream, cmd, arg);
95 pInputStatus = (PAF_SIO_InputStatus *)arg;
96 pInputStatus->lock = 0x01;
97 pInputStatus->nonaudio = 0x01;
98 pInputStatus->emphasis = 0x01;
99 pInputStatus->sampleRateMeasured = gPafSampRate;
100 pInputStatus->sampleRateData = gPafSampRate;
101 break;
102 case PAF_SIO_CONTROL_GET_SOURCEPROGRAM:
103 //Log_info3("SIO_ctrl():stream=0x%x, cmd=0x%x, arg=%d", (IArg)stream, cmd, arg);
104 pSourceProgram = (XDAS_Int8 *)arg;
105 *pSourceProgram = PAF_SOURCE_PCM;
106 break;
107 case PAF_SIO_CONTROL_SET_PCMFRAMELENGTH:
108 //Log_info3("SIO_ctrl():stream=0x%x, cmd=0x%x, arg=%d", (IArg)stream, cmd, arg);
109 gIbPcmFrameLength = arg;
110 break;
111 default:
112 //Log_info3("SIO_ctrl():unsupported command, stream=0x%x, cmd=0x%x, arg=%d", (IArg)stream, cmd, arg);
114 break;
115 }
117 return SYS_OK;
118 #else
119 return SIO2_ctrl(stream, cmd, arg);
120 #endif
121 }
123 // stub for _SIO_idle
124 Int _SIO_idle(
125 SIO_Handle stream,
126 Bool flush
127 )
128 {
129 #ifdef SIMULATE_SIO
130 Log_info2("SIO_idle():stream=0x%x, flush=%d,arg=%d", (IArg)stream, flush);
131 #endif // SIMULATE_SIO
133 #ifndef SIMULATE_SIO
134 return _SIO2_idle(stream, flush);
135 #else // SIMULATE_SIO
136 return SYS_OK;
137 #endif // SIMULATE_SIO
138 }
140 // stub for SIO_issue()
141 Int SIO_issue(
142 SIO_Handle stream,
143 Ptr pbuf,
144 size_t nbytes,
145 Arg arg
146 )
147 {
148 #ifdef SIMULATE_SIO
149 switch (arg)
150 {
151 case 0:
152 //Log_info4("SIO_issue():Tx stream=0x%x, pbuf=0x%x, nbytes=%d, arg=0x%x", (IArg)stream, (IArg)pbuf, nbytes, arg);
154 //
155 // Send full buffer to Tx SIO driver
156 //
158 // Capture Tx data here.
159 // Get data in pbuf->pntr.pSmInt.
160 gpOutBufConfig = (PAF_OutBufConfig *)pbuf;
161 gpOutBufConfig->stride = 8;
162 gpOutBufConfig->sizeofElement = 3;
163 gpOutBufConfig->precision = 24;
164 gpOutBufConfig->sizeofBuffer = gpOutBufConfig->allocation;
166 capOb(gpOutBufConfig);
168 break;
169 case PAF_SIO_REQUEST_SYNC:
170 case PAF_SIO_REQUEST_NEWFRAME:
171 //Log_info4("SIO_issue():Rx stream=0x%x, pbuf=0x%x, nbytes=%d, arg=0x%x", (IArg)stream, (IArg)pbuf, nbytes, arg);
173 //
174 // Send empty buffer to Rx SIO driver
175 //
176 gpInpBufConfig = (PAF_InpBufConfig *)pbuf;
177 break;
178 default:
179 //Log_info4("SIO_issue():unsupported arg, stream=0x%x, pbuf=0x%x, nbytes=%d, arg=0x%x", (IArg)stream, (IArg)pbuf, nbytes, arg);
180 break;
181 }
183 return SYS_OK;
184 #else // SIMULATE_SIO
185 return SIO2_issue(stream, pbuf, nbytes, arg);
186 #endif // SIMULATE_SIO
187 }
189 // stub for SIO_reclaim()
190 Int SIO_reclaim(
191 SIO_Handle stream,
192 Ptr *ppbuf,
193 Arg *parg
194 )
195 {
196 #ifdef SIMULATE_SIO
197 DEV_Handle device; /* == stream */
199 /* first field in SIO_Obj is a DEV_Obj */
200 device = (DEV_Handle)stream;
202 if (device->mode == 0) // Rx
203 {
204 Log_info4("SIO_reclaim():Rx stream=0x%x, ppbuf=0x%x, parg=0x%x, mode=%d", (IArg)stream, (IArg)ppbuf, (IArg)parg, device->mode);
206 //
207 // Receive full buffer from Rx SIO driver.
208 //
209 gpInpBufConfig->sizeofBuffer = 180224;
210 gpInpBufConfig->sizeofElement = 4;
211 gpInpBufConfig->stride = 8;
212 //gpInpBufConfig->deliverZeros = 1;
213 gpInpBufConfig->frameLength = 2048; // = stride * PCM frame length = 8 ch * 256 samp/ch = 2048 samp
214 gpInpBufConfig->lengthofData = 2048;
216 // Generate Rx data here.
217 // Put data in gpInpBufConfig->pntr.pLgInt.
218 memset(gpInpBufConfig->pntr.pSmInt, 0,
219 gpInpBufConfig->frameLength*gpInpBufConfig->sizeofElement);
220 genSinIb(gpInpBufConfig);
222 *ppbuf = gpInpBufConfig;
224 // Simulate Rx SIO_reclaim() pend
225 Semaphore_pend(semaphoreRxAudio, BIOS_WAIT_FOREVER);
227 return sizeof(PAF_InpBufConfig);
228 }
229 else if (device->mode == 1) // Tx
230 {
231 Log_info4("SIO_reclaim():Tx stream=0x%x, ppbuf=0x%x, parg=0x%x, mode=%d", (IArg)stream, (IArg)ppbuf, (IArg)parg, device->mode);
233 //
234 // Receive empty buffer from Tx SIO driver
235 //
236 *ppbuf = gpOutBufConfig;
238 // Simulate Tx SIO_reclaim() pend
239 Semaphore_pend(semaphoreTxAudio, BIOS_WAIT_FOREVER);
241 return sizeof(PAF_OutBufConfig);
242 }
243 else
244 {
245 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);
246 return -1;
247 }
248 #else // SIMULATE_SIO
249 DEV2_Handle device; /* == stream */
251 /* first field in SIO_Obj is a DEV_Obj */
252 device = (DEV2_Handle)stream;
253 Log_info4("SIO_reclaim:stream=0x%x, ppbuf=0x%x, parg=0x%x, mode=%d", (IArg)stream, (IArg)ppbuf, (IArg)parg, device->mode);
255 return SIO2_reclaim(stream, ppbuf, parg);
256 #endif // SIMULATE_SIO
257 }