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 //
37 //
38 // SIO driver implementation for audio I/O using McASP.
39 //
40 //
41 //
43 #ifndef SAP_CACHE_SUPPORT
44 // if you rebuild dap.c in your project without this defined,
45 // the result is quite hard to find: Occasional glitches in the sound.
46 #define SAP_CACHE_SUPPORT // typically defined in the project
47 #endif
49 #ifdef SAP_CACHE_SUPPORT
50 #include <ti/sysbios/hal/Cache.h>
51 #endif
53 #include <stdlib.h>
54 #include <stdio.h>
55 #include <string.h> //memset
57 #include <xdc/std.h>
59 #include "sap.h"
61 #include <ti/sdo/edma3/drv/edma3_drv.h>
62 #include <ti/sdo/edma3/drv/src/edma3.h>
63 #include <ti/sdo/edma3/rm/edma3_rm.h>
64 #include <ti/sdo/edma3/drv/sample/bios6_edma3_drv_sample.h>
66 #include <ti/csl/cslr_device.h>
68 #define EDMA_HINV NULL
69 #define EDMA_NUM_PARAMS 6
71 #include "sap_mcasp.h"
72 #include <pafsio.h>
74 // This works to set a breakpoint
75 #define SW_BREAKPOINT asm( " SWBP 0" );
76 /* Software Breakpoint to Code Composer */
77 // SW_BREAKPOINT;
79 // global allocated in bios_edma3_drv_sample_init.c
80 extern EDMA3_DRV_Handle hEdma0;
81 extern EDMA3_DRV_Handle hEdma1;
83 int gStartError;
84 int gIsrInputCnt;
85 int gIsrOutputCnt;
86 int gIsrElseCnt;
87 int gIsrInErrCnt;
88 int gIsrOutErrCnt;
89 int gIsrRunCnt;
90 int gIsrNotRunCnt;
91 int gisrOutput;
92 int gSAPResetIn;
93 int gSAPResetOut;
95 typedef xdc_Short MdInt;
97 void swapHdmi(Ptr, int);
99 #define SAP_UNDER_LEN 8
101 #pragma DATA_SECTION(sap_UNDER, ".sap_UNDER");
102 int sap_UNDER[SAP_UNDER_LEN]; // used for underrun
103 int sap_OVER_1LANE = 0; // used for overrun
104 int sap_OVER_4LANE[4] = {0,0,0,0}; // used for overrun
106 #ifdef DEBUG
107 void SAP_EDMA_dumpParams(int tag_place)
108 {
109 //unsigned int *ptrPARAM_BASE = (unsigned int *)0x02704000;
110 unsigned int *ptrPARAM0x18 = (unsigned int *)0x02704300; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[24]
111 //unsigned int *ptrPARAM0x19 = (unsigned int *)0x02704320; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[24]
112 //unsigned int *ptrPARAM0x41 = (unsigned int *)0x027048A0; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[24]
113 //unsigned int *ptrPARAM0x42 = (unsigned int *)0x027048C0; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[24]
114 //unsigned int *ptrPARAM0x43 = (unsigned int *)0x027048E0; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[24]
115 //unsigned int *ptrPARAM0x48 = (unsigned int *)0x02704910; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[24]
116 unsigned int *ptrPARAM0x45 = (unsigned int *)0x027048A0; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[69]
117 unsigned int *ptrPARAM0x46 = (unsigned int *)0x027048C0; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[70]
118 unsigned int *ptrPARAM0x47 = (unsigned int *)0x027048E0; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[71]
119 unsigned int *ptrPARAM0x48 = (unsigned int *)0x02704900; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[72]
120 unsigned int *ptrPARAM0x49 = (unsigned int *)0x02704920; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[73]
121 unsigned int *ptrPARAM0x4A = (unsigned int *)0x02704940; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[74]
123 //Log_info5("PARAM0x18a(%d): 0x%x 0x%x 0x%x 0x%x", tag_place, ptrPARAM0x18[0], ptrPARAM0x18[1], ptrPARAM0x18[2], ptrPARAM0x18[3]);
124 //Log_info5("PARAM0x18b(%d): 0x%x 0x%x 0x%x 0x%x", tag_place, ptrPARAM0x18[4], ptrPARAM0x18[5], ptrPARAM0x18[6], ptrPARAM0x18[7]);
126 /*Log_info5("PARAM0x19a(%d): ITCINTEN: 0x%02x, TCINTEN: 0x%02x, TCC: 0x%02x, TCCMODE: %d", tag_place, ((ptrPARAM0x19[0] & 0x200000) >> 21), ((ptrPARAM0x19[0] & 0x100000) >> 20), ((ptrPARAM0x19[0] & 0x3F000) >> 12), ((ptrPARAM0x19[0] & 0x800) >> 11));
127 Log_info5("PARAM0x19b(%d): SRC: 0x%08x, A_B_CNT: 0x%08x, DST: 0x%08x, SRC_DST_BIDX: 0x%08x", tag_place, ptrPARAM0x19[1], ptrPARAM0x19[2], ptrPARAM0x19[3], ptrPARAM0x19[4]);
128 Log_info4("PARAM0x19b(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x19[5], ptrPARAM0x19[6], ptrPARAM0x19[7]);
130 Log_info5("PARAM0x41a(%d): ITCINTEN: 0x%02x, TCINTEN: 0x%02x, TCC: 0x%02x, TCCMODE: %d", tag_place, ((ptrPARAM0x41[0] & 0x200000) >> 21), ((ptrPARAM0x41[0] & 0x100000) >> 20), ((ptrPARAM0x41[0] & 0x3F000) >> 12), ((ptrPARAM0x41[0] & 0x800) >> 11));
131 Log_info5("PARAM0x41b(%d): SRC: 0x%08x, A_B_CNT: 0x%08x, DST: 0x%08x, SRC_DST_BIDX: 0x%08x", tag_place, ptrPARAM0x41[1], ptrPARAM0x41[2], ptrPARAM0x41[3], ptrPARAM0x41[4]);
132 Log_info4("PARAM0x41b(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x41[5], ptrPARAM0x41[6], ptrPARAM0x41[7]);
134 Log_info5("PARAM0x42a(%d): ITCINTEN: 0x%02x, TCINTEN: 0x%02x, TCC: 0x%02x, TCCMODE: %d", tag_place, ((ptrPARAM0x42[0] & 0x200000) >> 21), ((ptrPARAM0x42[0] & 0x100000) >> 20), ((ptrPARAM0x42[0] & 0x3F000) >> 12), ((ptrPARAM0x42[0] & 0x800) >> 11));
135 Log_info5("PARAM0x42b(%d): SRC: 0x%08x, A_B_CNT: 0x%08x, DST: 0x%08x, SRC_DST_BIDX: 0x%08x", tag_place, ptrPARAM0x42[1], ptrPARAM0x42[2], ptrPARAM0x42[3], ptrPARAM0x42[4]);
136 Log_info4("PARAM0x42b(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x42[5], ptrPARAM0x42[6], ptrPARAM0x42[7]);
138 Log_info5("PARAM0x43a(%d): ITCINTEN: 0x%02x, TCINTEN: 0x%02x, TCC: 0x%02x, TCCMODE: %d", tag_place, ((ptrPARAM0x43[0] & 0x200000) >> 21), ((ptrPARAM0x43[0] & 0x100000) >> 20), ((ptrPARAM0x43[0] & 0x3F000) >> 12), ((ptrPARAM0x43[0] & 0x800) >> 11));
139 Log_info5("PARAM0x43b(%d): SRC: 0x%08x, A_B_CNT: 0x%08x, DST: 0x%08x, SRC_DST_BIDX: 0x%08x", tag_place, ptrPARAM0x43[1], ptrPARAM0x43[2], ptrPARAM0x43[3], ptrPARAM0x43[4]);
140 Log_info4("PARAM0x43b(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x43[5], ptrPARAM0x43[6], ptrPARAM0x43[7]);
142 Log_info5("PARAM0x48a(%d): ITCINTEN: 0x%02x, TCINTEN: 0x%02x, TCC: 0x%02x, TCCMODE: %d", tag_place, ((ptrPARAM0x48[0] & 0x200000) >> 21), ((ptrPARAM0x48[0] & 0x100000) >> 20), ((ptrPARAM0x48[0] & 0x3F000) >> 12), ((ptrPARAM0x48[0] & 0x800) >> 11));
143 Log_info5("PARAM0x48b(%d): SRC: 0x%08x, A_B_CNT: 0x%08x, DST: 0x%08x, SRC_DST_BIDX: 0x%08x", tag_place, ptrPARAM0x48[1], ptrPARAM0x48[2], ptrPARAM0x48[3], ptrPARAM0x48[4]);
144 Log_info4("PARAM0x48b(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x48[5], ptrPARAM0x48[6], ptrPARAM0x48[7]);*/
146 Log_info5("PARAM0x18a(%d): ITCINTEN: 0x%02x, TCINTEN: 0x%02x, TCC: 0x%02x, TCCMODE: %d", tag_place, ((ptrPARAM0x18[0] & 0x200000) >> 21), ((ptrPARAM0x18[0] & 0x100000) >> 20), ((ptrPARAM0x18[0] & 0x3F000) >> 12), ((ptrPARAM0x18[0] & 0x800) >> 11));
147 Log_info5("PARAM0x18b(%d): SRC: 0x%08x, A_B_CNT: 0x%08x, DST: 0x%08x, SRC_DST_BIDX: 0x%08x", tag_place, ptrPARAM0x18[1], ptrPARAM0x18[2], ptrPARAM0x18[3], ptrPARAM0x18[4]);
148 Log_info4("PARAM0x18c(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x18[5], ptrPARAM0x18[6], ptrPARAM0x18[7]);
150 Log_info5("PARAM0x45a(%d): ITCINTEN: 0x%02x, TCINTEN: 0x%02x, TCC: 0x%02x, TCCMODE: %d", tag_place, ((ptrPARAM0x45[0] & 0x200000) >> 21), ((ptrPARAM0x45[0] & 0x100000) >> 20), ((ptrPARAM0x45[0] & 0x3F000) >> 12), ((ptrPARAM0x45[0] & 0x800) >> 11));
151 Log_info5("PARAM0x45b(%d): SRC: 0x%08x, A_B_CNT: 0x%08x, DST: 0x%08x, SRC_DST_BIDX: 0x%08x", tag_place, ptrPARAM0x45[1], ptrPARAM0x45[2], ptrPARAM0x45[3], ptrPARAM0x45[4]);
152 Log_info4("PARAM0x45c(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x45[5], ptrPARAM0x45[6], ptrPARAM0x45[7]);
154 Log_info5("PARAM0x46a(%d): ITCINTEN: 0x%02x, TCINTEN: 0x%02x, TCC: 0x%02x, TCCMODE: %d", tag_place, ((ptrPARAM0x46[0] & 0x200000) >> 21), ((ptrPARAM0x46[0] & 0x100000) >> 20), ((ptrPARAM0x46[0] & 0x3F000) >> 12), ((ptrPARAM0x46[0] & 0x800) >> 11));
155 Log_info5("PARAM0x46b(%d): SRC: 0x%08x, A_B_CNT: 0x%08x, DST: 0x%08x, SRC_DST_BIDX: 0x%08x", tag_place, ptrPARAM0x46[1], ptrPARAM0x46[2], ptrPARAM0x46[3], ptrPARAM0x46[4]);
156 Log_info4("PARAM0x46c(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x46[5], ptrPARAM0x46[6], ptrPARAM0x46[7]);
158 Log_info5("PARAM0x47a(%d): ITCINTEN: 0x%02x, TCINTEN: 0x%02x, TCC: 0x%02x, TCCMODE: %d", tag_place, ((ptrPARAM0x47[0] & 0x200000) >> 21), ((ptrPARAM0x47[0] & 0x100000) >> 20), ((ptrPARAM0x47[0] & 0x3F000) >> 12), ((ptrPARAM0x47[0] & 0x800) >> 11));
159 Log_info5("PARAM0x47b(%d): SRC: 0x%08x, A_B_CNT: 0x%08x, DST: 0x%08x, SRC_DST_BIDX: 0x%08x", tag_place, ptrPARAM0x47[1], ptrPARAM0x47[2], ptrPARAM0x47[3], ptrPARAM0x47[4]);
160 Log_info4("PARAM0x47c(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x47[5], ptrPARAM0x47[6], ptrPARAM0x47[7]);
162 Log_info5("PARAM0x48a(%d): ITCINTEN: 0x%02x, TCINTEN: 0x%02x, TCC: 0x%02x, TCCMODE: %d", tag_place, ((ptrPARAM0x48[0] & 0x200000) >> 21), ((ptrPARAM0x48[0] & 0x100000) >> 20), ((ptrPARAM0x48[0] & 0x3F000) >> 12), ((ptrPARAM0x48[0] & 0x800) >> 11));
163 Log_info5("PARAM0x48b(%d): SRC: 0x%08x, A_B_CNT: 0x%08x, DST: 0x%08x, SRC_DST_BIDX: 0x%08x", tag_place, ptrPARAM0x48[1], ptrPARAM0x48[2], ptrPARAM0x48[3], ptrPARAM0x48[4]);
164 Log_info4("PARAM0x48c(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x48[5], ptrPARAM0x48[6], ptrPARAM0x48[7]);
166 Log_info5("PARAM0x49a(%d): ITCINTEN: 0x%02x, TCINTEN: 0x%02x, TCC: 0x%02x, TCCMODE: %d", tag_place, ((ptrPARAM0x49[0] & 0x200000) >> 21), ((ptrPARAM0x49[0] & 0x100000) >> 20), ((ptrPARAM0x49[0] & 0x3F000) >> 12), ((ptrPARAM0x49[0] & 0x800) >> 11));
167 Log_info5("PARAM0x49b(%d): SRC: 0x%08x, A_B_CNT: 0x%08x, DST: 0x%08x, SRC_DST_BIDX: 0x%08x", tag_place, ptrPARAM0x49[1], ptrPARAM0x49[2], ptrPARAM0x49[3], ptrPARAM0x49[4]);
168 Log_info4("PARAM0x49c(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x49[5], ptrPARAM0x49[6], ptrPARAM0x49[7]);
170 Log_info5("PARAM0x4Aa(%d): ITCINTEN: 0x%02x, TCINTEN: 0x%02x, TCC: 0x%02x, TCCMODE: %d", tag_place, ((ptrPARAM0x4A[0] & 0x200000) >> 21), ((ptrPARAM0x4A[0] & 0x100000) >> 20), ((ptrPARAM0x4A[0] & 0x3F000) >> 12), ((ptrPARAM0x4A[0] & 0x800) >> 11));
171 Log_info5("PARAM0x4Ab(%d): SRC: 0x%08x, A_B_CNT: 0x%08x, DST: 0x%08x, SRC_DST_BIDX: 0x%08x", tag_place, ptrPARAM0x4A[1], ptrPARAM0x4A[2], ptrPARAM0x4A[3], ptrPARAM0x4A[4]);
172 Log_info4("PARAM0x4Ac(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x4A[5], ptrPARAM0x4A[6], ptrPARAM0x4A[7]);
174 Log_info1("TCC0: ERR reg %x", *((unsigned int *)0x02760120)); //DJDBG
175 }
176 #endif
177 // .............................................................................
178 // notes:
179 // . add control function to PORT table
180 // . how to handle DMA/PORT specifics in parameter entries
181 // can assume numSers = numChans is general and can be applied by DMA
182 // same for wordSize?
183 // . why are two idle stages needed (seems like 1 is enough)?
185 // .............................................................................
186 // only one global variable, not static so that DMA and port functions
187 // can access. We cant just store the address in devExt since the ISR has
188 // no context.
190 SAP_DriverObject sapDrv;
192 // needed since SAP_watchDog is called before SAP_init
193 Int SAP_initialized = 0;
195 //Int SAP_close(DEV2_Handle);
196 Int SAP_ctrl(DEV2_Handle, Uns, Arg);
197 Int SAP_idle(DEV2_Handle, Bool);
198 Int SAP_issue(DEV2_Handle);
199 Int SAP_open(DEV2_Handle, String);
200 void SAP_isrCallback (Uint32 tcc, EDMA3_RM_TccStatus status, Ptr context);
201 //Bool SAP_ready(DEV2_Handle, SEM_Handle);
202 Int SAP_reclaim(DEV2_Handle);
203 Int SAP_shutdown(DEV2_Handle);
204 Int SAP_start(DEV2_Handle);
205 Int SAP_config(DEV2_Handle device, const SAP_Params *pParams);
206 Int SAP_EDMA_setupParam (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32 childEdma, XDAS_UInt32 addr, XDAS_UInt32 size);
207 Int SAP_EDMA_setupXfer (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32 parentEdma, XDAS_UInt32 childEdma, DEV2_Frame *pFrame);
209 // .............................................................................
211 // .............................................................................
213 SAP_DMA_Fxns SAP_EDMA_FXNS =
214 {
215 SAP_EDMA_setupParam,
216 SAP_EDMA_setupXfer,
217 };
220 SAP_Fxns SAP_FXNS =
221 {
222 NULL, //SAP_close, -- remove for IROM since not using
223 SAP_ctrl,
224 SAP_idle,
225 SAP_issue,
226 SAP_open,
227 NULL, //SAP_ready, -- remove for IROM since not using
228 SAP_reclaim,
229 SAP_shutdown,
230 SAP_start,
231 SAP_config,
233 #ifdef SAP_PORT_MCASP
234 (SAP_PORT_Fxns *) &SAP_MCASP_FXNS,
235 #endif
236 #ifdef SAP_DMA_EDMA
237 (SAP_DMA_Fxns *) &SAP_EDMA_FXNS,
238 #endif
239 };
241 // -----------------------------------------------------------------------------
242 // This function is not in the driver function table.
243 // Must be pointed at in GUI config tool.
244 //
245 Void SAP_init (Void)
246 {
247 DEV2_Device *entry;
248 SAP_Fxns *pFxns;
250 //TRACE_GEN((&TR_MOD, "SAP_init.%d", __LINE__));
252 // find function table pointer (used by SAP_XX_FTABLE_init macros)
253 DEV2_match(SAP_NAME, &entry);
254 if (entry == NULL) {
255 Log_error1 ("SAP", SIO2_ENODEV);
256 return;
257 }
258 pFxns = (SAP_Fxns *) entry->fxns;
260 //SAP_DMA_FTABLE_init ();
261 SAP_PORT_FTABLE_init ();
263 sapDrv.numDevices = 0;
264 SAP_initialized = 1;
266 return;
267 } // SAP_init
269 // -----------------------------------------------------------------------------
271 int gSapInput_ControlOpen = 0;
272 int gSapOutput_ControlOpen = 0;
274 int gSapInput_ControlClose = 0;
275 int gSapOutput_ControlClose = 0;
277 Int SAP_ctrl (DEV2_Handle device, Uns code, Arg arg)
278 {
279 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
280 const SAP_Params *pParams;
281 Int i, result = SIO2_OK;
282 EDMA3_DRV_Handle hEdma;
283 //TRACE_GEN((&TR_MOD, "SAP_ctrl.%d (0x%x) code = 0x%x", __LINE__, device, code));
285 switch (code) {
287 /* .......................................................................... */
289 case PAF_SIO_CONTROL_MUTE:
290 case PAF_SIO_CONTROL_UNMUTE:
291 pParams = pDevExt->pParams;
292 if (pParams == NULL)
293 return SIO2_OK;
295 if (pParams->sio.control != NULL)
296 result = pParams->sio.control (device, (const PAF_SIO_Params *)pParams, code, arg);
297 break;
299 /* .......................................................................... */
301 case PAF_SIO_CONTROL_OPEN:
302 if (pDevExt->runState)
303 return SIO2_EBUSY;
305 if (!( pParams = (const SAP_Params *) arg ))
306 return SIO2_OK;
308 if(device->mode == DEV2_OUTPUT)
309 gSapOutput_ControlOpen++;
310 else
311 gSapInput_ControlOpen++;
313 if (result = SAP_FTABLE_config (device, pParams))
314 return result;
316 if (pParams->sio.control && (result = pParams->sio.control (device, (const PAF_SIO_Params *)pParams, code, arg)))
317 return result;
319 break;
321 /* .......................................................................... */
323 case PAF_SIO_CONTROL_CLOSE:
324 if (pDevExt->runState)
325 return SIO2_EBUSY;
327 if (pDevExt->pParams == NULL)
328 return SIO2_EINVAL;
330 pParams = pDevExt->pParams;
332 if (pParams->sio.moduleNum == 0)
333 hEdma = hEdma0;
334 else if (pParams->sio.moduleNum == 1 || pParams->sio.moduleNum == 2)
335 hEdma = hEdma1;
337 if (pDevExt->activeEdma != EDMA_HINV) {
338 EDMA3_DRV_freeChannel (hEdma, pDevExt->activeEdma);
339 pDevExt->activeEdma = EDMA_HINV;
340 }
342 if(device->mode == DEV2_INPUT)
343 gSapInput_ControlClose++;
344 else
345 gSapOutput_ControlClose++;
347 for (i=0; i < pDevExt->numEdmaParams; i++) {
348 if (pDevExt->edmaParams[i].hEdmaParam != EDMA_HINV)
349 {
350 EDMA3_DRV_freeChannel (hEdma, pDevExt->edmaParams[i].hEdmaParam);
351 pDevExt->edmaParams[i].hEdmaParam = EDMA_HINV;
352 }
353 }
355 if (pDevExt->errorEdma != EDMA_HINV) {
356 EDMA3_DRV_freeChannel (hEdma, pDevExt->errorEdma);
357 pDevExt->errorEdma = EDMA_HINV;
358 }
360 if (!(pParams = pDevExt->pParams))
361 return SIO2_OK;
363 if (pParams->sio.control && (result = pParams->sio.control (device, (const PAF_SIO_Params *)pParams, code, arg)))
364 return result;
366 result = SAP_PORT_FTABLE_close (device);
367 if (result)
368 return result;
370 pDevExt->pParams = NULL;
371 break;
373 /* .......................................................................... */
375 case PAF_SIO_CONTROL_GET_WORDSIZE:
376 if (!arg)
377 return SIO2_EINVAL;
378 *((int *) arg) = pDevExt->edmaWordSize;
379 break;
381 case PAF_SIO_CONTROL_SET_WORDSIZE:
382 // defer to DMA processing
383 // currently only supported for input
384 if (device->mode != DEV2_INPUT)
385 return SIO2_EINVAL;
387 // can't be running
388 if (pDevExt->runState)
389 return SIO2_EBUSY;
391 // driver only supports 2 or 4 bytes
392 if ((arg != 2) && (arg != 4))
393 return SIO2_EINVAL;
395 // return success for unconfigured devices?
396 if (!pDevExt->pParams)
397 return SIO2_OK;
399 // ask platform if size is supported
400 pParams = pDevExt->pParams;
401 if (pDevExt->pParams->sio.control && (result = pDevExt->pParams->sio.control (device, (const PAF_SIO_Params *)pParams, code, arg)))
402 return result;
404 pDevExt->edmaWordSize = arg;
405 break;
407 case PAF_SIO_CONTROL_GET_PRECISION:
408 if (arg == 0)
409 return SIO2_EINVAL;
411 pParams = pDevExt->pParams;
412 if (pParams == NULL)
413 return( SIO2_EINVAL );
415 *((int *) arg) = pParams->sio.precision;
416 break;
418 case PAF_SIO_CONTROL_GET_NUMCHANNELS:
419 if (arg == 0)
420 return SIO2_EINVAL;
422 *((int *) arg) = pDevExt->numSlots * pDevExt->numSers;
423 break;
425 case PAF_SIO_CONTROL_SET_RATEX:
426 pParams = pDevExt->pParams;
427 if (pParams == NULL)
428 return SIO2_OK ;
430 if (pParams->sio.control == NULL)
431 return SIO2_EINVAL;
433 result = pParams->sio.control( device, (const PAF_SIO_Params *)pParams, PAF_SIO_CONTROL_SET_RATEX, arg);
434 break;
436 /* .......................................................................... */
438 case PAF_SIO_CONTROL_IDLE:
439 pParams = pDevExt->pParams;
440 if (pParams == NULL)
441 return SIO2_OK ;
443 if (pParams->sio.control == NULL)
444 return SIO2_EINVAL;
446 result = pParams->sio.control( device, (const PAF_SIO_Params *)pParams, PAF_SIO_CONTROL_IDLE, arg);
447 break;
449 case PAF_SIO_CONTROL_IDLE_WITH_CLOCKS:
450 // 1. Here we are intentionally not using SIO_Idle() and
451 // leaving the Tx clock running. We need this to avoid DAC noise,
452 // as well as provide a DIT clock when using digital output.
453 if (device->mode != DEV2_OUTPUT || pDevExt->pParams == NULL)
454 return SIO2_EINVAL;
456 pParams = pDevExt->pParams;
458 if (pParams->sio.moduleNum == 0)
459 hEdma = hEdma0;
460 else if (pParams->sio.moduleNum == 1 || pParams->sio.moduleNum == 2)
461 hEdma = hEdma1;
463 result = SAP_FTABLE_shutdown (device);
464 if (result)
465 return result;
467 Log_info0 ("SAP PAF_SIO_CONTROL_IDLE_WITH_CLOCKS; PAF_SIO_ERROR_IDLE_STAGE1");
468 pDevExt->errorState = PAF_SIO_ERROR_IDLE_STAGE1;
470 #if 1
471 //DJDBG, if below enableTransfer() is commented, input side continuous working.
472 if (pDevExt->activeEdma != EDMA_HINV) {
473 //EDMA3_DRV_disableTransfer (hEdma0, pDevExt->activeEdma, EDMA3_DRV_TRIG_MODE_EVENT);
474 //if(*((unsigned int *)0x02701000) & 0x01000000) *((unsigned int *)0x02701008) = 0x01000000; //Clear pending even in bit 24! //DJDBG
475 EDMA3_DRV_enableTransfer (hEdma, pDevExt->activeEdma, EDMA3_DRV_TRIG_MODE_EVENT);
476 }
477 #endif
478 //TRACE_GEN((&TR_MOD, "SAP_ctrl.%d: (0x%x) errorState = PAF_SIO_ERROR_IDLE_STAGE1 0x%x.", __LINE__, device, PAF_SIO_ERROR_IDLE_STAGE1));
480 break;
482 /* .......................................................................... */
484 case PAF_SIO_CONTROL_GET_INPUT_STATUS:
485 // needs to be attached
486 pParams = pDevExt->pParams;
487 if (pParams == NULL)
488 return SIO2_OK;
490 if (pParams->sio.control == NULL)
491 return SIO2_EINVAL;
493 result = pParams->sio.control( device, (const PAF_SIO_Params *)pParams, code, arg );
494 break;
496 case PAF_SIO_CONTROL_WATCHDOG:
497 pParams = pDevExt->pParams;
498 if (pParams == NULL)
499 return SIO2_OK;
500 if (pParams->sio.control && (result = pParams->sio.control (device, (const PAF_SIO_Params *)pParams, code, arg)))
501 return result;
502 break;
504 /* .......................................................................... */
506 // Timing stats specific to DMA engine
507 case PAF_SIO_CONTROL_ENABLE_STATS:
508 case PAF_SIO_CONTROL_DISABLE_STATS:
509 case PAF_SIO_CONTROL_GET_STATS:
510 case PAF_SIO_CONTROL_GET_NUM_EVENTS:
511 case PAF_SIO_CONTROL_GET_NUM_REMAINING:
512 //result = SAP_DMA_FTABLE_ctrl (device, code, arg);
513 // TRACE_VERBOSE((&TR_MOD, "SAP_ctrl: (0x%x) code 0x%x. result 0x%x.", device, code, result));
514 break;
516 /* .......................................................................... */
518 case PAF_SIO_CONTROL_SET_DITSTATUS:
519 if(device->mode == DEV2_OUTPUT)
520 {
521 const SAP_Params *pParams = pDevExt->pParams;
522 MCASP_Handle hPort = sapMcaspDrv.hPort[pParams->sio.moduleNum];
523 volatile Uint32 *base = (volatile Uint32 *)(hPort->baseAddr);
524 MCASP_ConfigXmt *pTxConfig = (MCASP_ConfigXmt *)pParams->sio.pConfig;
525 int encSelect = *((int *) arg);
527 // HACK -- determine DIT need by FXWID
528 if (((pTxConfig->afsxctl & _MCASP_AFSXCTL_FXWID_MASK)>> _MCASP_AFSXCTL_FXWID_SHIFT) == MCASP_AFSXCTL_FXWID_BIT)
529 {
530 if ( (encSelect == 0x13) ||
531 (encSelect == 0xa) ||
532 (encSelect == 0x6)) // DTE, DDE, MPE
533 {
534 base[_MCASP_DITCSRA0_OFFSET] |= 2;
535 base[_MCASP_DITCSRB0_OFFSET] |= 2;
536 }
537 else
538 {
539 base[_MCASP_DITCSRA0_OFFSET] &= 0xfffffffd;
540 base[_MCASP_DITCSRB0_OFFSET] &= 0xfffffffd;
541 }
542 }
544 pParams = pDevExt->pParams;
545 if (pParams == NULL)
546 return SIO2_OK;
548 if (pParams->sio.control != NULL)
549 result = pParams->sio.control (device, (const PAF_SIO_Params *)pParams, code, arg);
550 }
551 break;
553 /* .......................................................................... */
555 }
557 return result;
558 } // SAP_ctrl
560 int gSAPIdleShutdownIn=0;
561 int gSAPIdleShutdownOut=0;
563 // -----------------------------------------------------------------------------
565 Int SAP_idle (DEV2_Handle device, Bool flush)
566 {
567 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
568 Int result = SIO2_OK;
569 EDMA3_DRV_Handle hEdma;
571 // do nothing if already idled or unattached
572 if ((!pDevExt->runState) || (pDevExt->pParams == NULL))
573 return result;
575 if (pDevExt->pParams->sio.moduleNum == 0)
576 hEdma = hEdma0;
577 else if (pDevExt->pParams->sio.moduleNum == 1 || pDevExt->pParams->sio.moduleNum == 2)
578 hEdma = hEdma1;
580 // reset serial port -- stop generating sync events
581 result = SAP_PORT_FTABLE_reset (device);
582 if(device->mode == DEV2_OUTPUT)
583 gSAPResetOut++;
584 else
585 gSAPResetIn++;
586 if (result)
587 {
588 //TRACE_VERBOSE((&TR_MOD, "%s.%d: SAP_PORT_FTABLE_reset returned %d.\n", __FUNCTION__, __LINE__, result));
589 return result;
590 }
592 pDevExt->shutDown = 0; // force shutdown to run
593 result = SAP_FTABLE_shutdown (device);
594 if(device->mode == DEV2_OUTPUT)
595 gSAPIdleShutdownOut++;
596 else
597 gSAPIdleShutdownIn++;
599 if (result)
600 {
601 //TRACE_VERBOSE((&TR_MOD, "%s.%d: SAP_FTABLE_shutdown returned %d.\n", __FUNCTION__, __LINE__, result));
602 return result;
603 }
605 Log_info0("SAP_idle:Before EDMA3_DRV_disableTransfer");
607 // disable interrupts and EDMA servicing
608 if (pDevExt->activeEdma != EDMA_HINV)
609 EDMA3_DRV_disableTransfer (hEdma, pDevExt->activeEdma, EDMA3_DRV_TRIG_MODE_EVENT);
611 Log_info0("SAP_idle:Before pDevExt->numQueued = 0");
612 pDevExt->numQueued = 0;
614 // signal stopped
615 pDevExt->runState = 0;
616 Log_info0("SAP_idle: runState = 0");
618 // reset errorState
619 pDevExt->errorState = PAF_SIO_ERROR_NONE;
620 //TRACE_VERBOSE((&TR_MOD, "SAP_ctrl.%d: errorState = PAF_SIO_ERROR_NONE 0x%x.", __LINE__, PAF_SIO_ERROR_NONE));
622 // place call to physical device
623 if ((pDevExt->pParams != NULL) && (pDevExt->pParams->sio.control != NULL))
624 result = pDevExt->pParams->sio.control(device, (const PAF_SIO_Params *)pDevExt->pParams, PAF_SIO_CONTROL_IDLE, 0);
626 return result;
627 } // SAP_idle
629 // -----------------------------------------------------------------------------
631 Int SAP_start (DEV2_Handle device)
632 {
633 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
634 DEV2_Frame *pFrame;
635 int result;
636 EDMA3_DRV_Handle hEdma;
638 Log_info2("SAP_start.%d (0x%x)", __LINE__, device);
640 // Assume todevice queue is not empty -- how else could we be here?
641 pFrame = (DEV2_Frame *) Queue_get (device->todevice);
643 // inidicate this xfer did not use param entry - just the active one
644 pFrame->misc = NULL;
645 if (pDevExt->pParams->sio.moduleNum == 0)
646 hEdma = hEdma0;
647 else if (pDevExt->pParams->sio.moduleNum == 1 || pDevExt->pParams->sio.moduleNum == 2)
648 hEdma = hEdma1;
650 // non-atomic functions since not running yet.
651 Queue_enqueue (Queue_handle(&pDevExt->xferQue), (Queue_Elem *)pFrame);
653 // initialize count
654 pDevExt->numQueued = 1;
656 result = SAP_PORT_FTABLE_reset (device);
657 if (result)
658 {
659 //TRACE_VERBOSE((&TR_MOD, "%s.%d: SAP_PORT_FTABLE_reset returned %d.\n", __FUNCTION__, __LINE__, result));
660 return result;
661 }
663 // enable DMA processing
664 if (device->mode == DEV2_OUTPUT)
665 Log_info3("SAP_start.%d, pDevExt->activeEdma 0x%x (pDevExt->errorEdma = 0x%x)",
666 __LINE__, pDevExt->activeEdma, pDevExt->errorEdma);
667 // config active xfer for this buffer
668 result = SAP_EDMA_setupXfer(device, pDevExt->activeEdma, EDMA_HINV, pDevExt->errorEdma, pFrame);
671 // signal we have started -- this must come before last enable to prevent a race
672 // condition where the initial EDMA transfer is very small (e.g. due to startClocks)
673 // and completes before any further instructions in this thread are executed.
674 // This comes before the EDMA enable since, if the # of samples is 1, then the EDMA
675 // will be serviced and generate an interrupt even before the McASP is enabled.
676 pDevExt->runState = 1;
677 pDevExt->shutDown = 0;
678 if (device->mode == DEV2_OUTPUT)
679 Log_info2 ("SAP: %d, SAP_start runState=1 & ENABLE TRANSFERS for activeEdma = 0x%x", __LINE__, pDevExt->activeEdma);
680 // enable interrupts and event servicing for this channel
681 EDMA3_DRV_enableTransfer (hEdma, pDevExt->activeEdma, EDMA3_DRV_TRIG_MODE_EVENT);
683 // enable peripheral
684 result = SAP_PORT_FTABLE_enable (device);
686 if (result)
687 {
688 //TRACE_VERBOSE((&TR_MOD, "%s.%d: SAP_PORT_FTABLE_enable returned %d.\n", __FUNCTION__, __LINE__, result));
689 return result;
690 }
692 return SIO2_OK;
693 } // SAP_start
695 int gDmaParamsarray[17][3];
696 int gDmaParamsidx=0, gSAPSpecialCase=0;
697 // -----------------------------------------------------------------------------
699 Int SAP_issue (DEV2_Handle device)
700 {
701 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
702 DEV2_Frame *pFrame;
703 Int result;
704 SAP_EDMA_Param *pParam;
705 XDAS_UInt32 parentEdma;
707 if (device->mode == DEV2_OUTPUT)
708 Log_info3("SAP_issue for output device with pDevExt->errorState = 0x%x, pDevExt->runState = 0x%x, pDevExt->numQueued = 0x%x", pDevExt->errorState, pDevExt->runState, pDevExt->numQueued);
710 if ((device->mode == DEV2_OUTPUT) && (pDevExt->errorState >= PAF_SIO_ERROR_ERRBUF_XFER))
711 {
712 /*TRACE_TERSE((&TR_MOD, "SAP_issue.%d, errorState 0x%x (PAF_SIO_ERROR_ERRBUF_XFER = 0x%x)",
713 __LINE__, pDevExt->errorState, PAF_SIO_ERROR_ERRBUF_XFER));*/
714 Log_info3("SAP_issue.%d, PAF_SIO_ERROR_ERRBUF_XFER = 0x%x, mode = 0x%x)",
715 __LINE__, PAF_SIO_ERROR_ERRBUF_XFER, device->mode );
716 return SIO2_EBADIO;
717 }
719 if ((device->mode == DEV2_INPUT) && pDevExt->errorState)
720 {
721 Log_info1("SAP_issue: Input Error Trap, with errorState = 0x%x", pDevExt->errorState);
722 return SIO2_EBADIO;
723 }
725 // if not yet running then configure active xfer and start
726 if (pDevExt->runState == 0)
727 return (SAP_FTABLE_start(device));
729 // .........................................................................
730 // here if running
732 // disable device interrupts
733 // TODO: is there an API to just disable the IER bit for this tcc?
734 unsigned int key = Hwi_disable ();
735 /* determine parent EDMA
736 if no xfers in queue and we are running then must be in the
737 error state so link to active channel otherwise link to last
738 transfer queued.
739 */
741 /* here we assume after Tx SIO_idle or overrun, the user
742 will issue, at least, back-to-back issue requests so
743 there should be no problem here.
744 */
745 if ((pDevExt->numQueued <= 1) && (pDevExt->errorState != 2))
746 parentEdma = pDevExt->activeEdma;
747 else {
748 // if here then xferQue has more than one element so ok to use tail
749 // last scheduled transfer must be queue->prev
750 DEV2_Frame *tail = (DEV2_Frame *) Queue_prev ((Queue_Elem *)&pDevExt->xferQue);
751 parentEdma = ((SAP_EDMA_Param *) tail->misc)->hEdmaParam;
752 }
754 //if (device->mode == DEV2_OUTPUT)
755 Log_info2("SAP_issue: Determined Parent = 0x%x for device = 0x%x", parentEdma, device->mode );
757 // get frame and parameter table to use; ints off => non-atomic OK
758 // dont need to check for empty queues since were here then todevice
759 // must have a frame placed there by the SIO_issue layer.
760 // paramQue must be valid since it is accessed the same as todevice.
761 // (indirectly -- isr places used items onto paramQue and fromdevice que
762 // at the same time)
763 // set misc argument to pParam so get enqueue later
764 //pFrame = (DEV2_Frame *) Queue_dequeue (device->todevice);
765 pFrame = Queue_dequeue (device->todevice);
766 pParam = (SAP_EDMA_Param *) Queue_dequeue (Queue_handle(&pDevExt->paramQue));
768 if (pParam->hEdmaParam == NULL)
769 Log_info1("SAP_issue: hEdma value is NULL for device = 0x%x", device->mode);
770 // set misc argument to pParam so get enqueue later
771 pFrame->misc = (Arg) pParam;
773 // place on holder queue, ints off => non-atomic OK
774 Queue_enqueue (Queue_handle(&pDevExt->xferQue), (Queue_Elem *) pFrame);
775 if (pFrame->addr) {
776 if (device->mode == DEV2_INPUT)
777 Cache_inv (pFrame->addr, pFrame->size, Cache_Type_ALL, TRUE);
778 else
779 Cache_wbInv (pFrame->addr, pFrame->size, Cache_Type_ALL, TRUE);
780 }
782 // increment count
783 pDevExt->numQueued += 1;
785 result = SAP_EDMA_setupXfer (device, pParam->hEdmaParam, parentEdma, pDevExt->errorEdma, pFrame);
786 if (device->mode == DEV2_OUTPUT)
787 {
788 Log_info4("SAP_issue.%d, EDMA_setupXfer: Target EDMA: 0x%x, Parent Edma: 0x%x Error Edma: 0x%x",
789 __LINE__, pParam->hEdmaParam, parentEdma, pDevExt->errorEdma);
790 }
793 /*if ((device->mode != DEV2_INPUT) && (gDmaParamsidx <=16))
794 {
795 gDmaParamsarray[gDmaParamsidx][0] = pParam->hEdma;
796 gDmaParamsarray[gDmaParamsidx][1] = parentEdma;
797 gDmaParamsarray[gDmaParamsidx++][2] = gisrOutput;
798 } */
800 if ((pDevExt->errorState == PAF_SIO_ERROR_IDLE_STAGE1) && (device->mode == DEV2_OUTPUT))
801 pDevExt->errorState = PAF_SIO_ERROR_NONE;
803 pDevExt->shutDown = 0;
805 //if (device->mode == DEV2_OUTPUT)
806 //SAP_EDMA_dumpParams(5);
808 // special case enables when not yet started
809 if (pDevExt->runState == 0) {
810 gSAPSpecialCase++;
811 result = SAP_FTABLE_start (device);
812 if (result) {
813 //SAP_DMA_FTABLE_unlock (device);
814 Hwi_restore (key);
815 return result;
816 }
817 }
818 Hwi_restore (key); //DJDBG
820 return result;
821 } // SAP_issue
823 // -----------------------------------------------------------------------------
825 void swapHdmi(Ptr Input, int size)
826 {
828 MdInt L0, L1, L2, L3, R0, R1, R2, R3 = 0;
829 MdInt *p1, *p2;
830 int i=0;
832 for (i=0; i< size; i+=16)
833 {
834 p1 = (MdInt *)&Input[i];
835 p2 = p1;
837 L0 = *p1++;
838 L1 = *p1++;
839 L2 = *p1++;
840 L3 = *p1++;
841 R0 = *p1++;
842 R1 = *p1++;
843 R2 = *p1++;
844 R3 = *p1++;
846 *p2++ = L0;
847 *p2++ = R0;
848 *p2++ = L1;
849 *p2++ = R1;
850 *p2++ = L2;
851 *p2++ = R2;
852 *p2++ = L3;
853 *p2++ = R3;
855 }
857 Log_info3("SAP: Exiting swapHdmi with Frame->Addr: 0x%x, p1->addr: 0x%x, p2->addr: 0x%x ", (xdc_IArg)Input, p1, p2);
859 return;
860 }
862 Int SAP_reclaim (DEV2_Handle device)
863 {
864 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)(device->object);
865 #ifdef SAP_CACHE_SUPPORT
866 DEV2_Frame *pFrame;
867 #endif
869 //TRACE_GEN((&TR_MOD, "SAP_reclaim.%d (0x%x)", __LINE__, device));
870 if (device->mode == DEV2_OUTPUT)
871 Log_info3("SAP_reclaim for output device with pDevExt->errorState = 0x%x, runState: 0x%x & pDevExt->numQueued = 0x%x", pDevExt->errorState, pDevExt->runState, pDevExt->numQueued);
872 // must be running and error free
873 if ((!pDevExt->runState) || (pDevExt->errorState))
874 {
875 Log_info3("SAP_reclaim.%d, error-state: 0x%x, mode = 0x%x", __LINE__, pDevExt->errorState, device->mode);
876 return SIO2_EBADIO;
877 }
879 // idle if necessary
880 if (pDevExt->errorState == PAF_SIO_ERROR_FATAL) {
881 Log_info1("SAP_reclaim: PAF_SIO_ERROR_FATAL, Before Idle for device 0x%x ", device->mode);
882 DEV2_idle (device, 1);
883 return SIO2_EBADIO;
884 }
886 Log_info1("SAP_reclaim: Before SEM Pend for mode: 0x%x", device->mode);
888 // wait for ISR to signal block completion
889 //TRACE_VERBOSE((&TR_MOD, "SAP_reclaim.%d wait for ISR to signal block completion", __LINE__));
890 if (!Semaphore_pend(pDevExt->sync, device->timeout))
891 {
892 Log_info0("SAP_reclaim, SYS_ETIMEOUT");
893 return SIO2_ETIMEOUT;
894 }
895 Log_info1("SAP_reclaim: After SEM Pend for mode: 0x%x", device->mode);
897 #if 1
898 // return error (owner must idle)
899 if (pDevExt->errorState == PAF_SIO_ERROR_FATAL)
900 {
901 DEV2_idle (device, 1);
902 Log_info2("SAP_reclaim.%d, PAF_SIO_ERROR_FATAL: 0x%x", __LINE__, pDevExt->errorState);
903 return PAF_SIO_ERROR_FATAL;
904 }
905 #endif
907 #ifdef SAP_CACHE_SUPPORT
908 // invalidate CACHE region if input -- use clean since
909 // Dont clean if was for fill.
910 // since pend returned we know that head of fromdevice is valid
911 pFrame = Queue_head (device->fromdevice);
912 Log_info2("SAP: Inside SAP_Reclaim with From Device Frame->Addr: 0x%x and Frame->Size: %d", pFrame->addr, pFrame->size);
913 if ((device->mode == DEV2_INPUT) && (pFrame->addr != NULL))
914 {
915 if(pDevExt->edmaWordSize == 2 && pDevExt->numSers == 4)
916 {
917 Cache_inv (pFrame->addr, pFrame->size, Cache_Type_ALL, 0);
918 Cache_wait();
920 // max HWI disable duration ~1ms observed
921 //unsigned int key = Hwi_disable (); // GJ: Revisit, along with other context protections here.
922 swapHdmi(pFrame->addr, pFrame->size);
923 //Hwi_restore(key);
925 Cache_wb (pFrame->addr, pFrame->size, Cache_Type_ALL, 0);
926 Cache_wait();
927 }
928 }
930 #endif
931 /*if ((device->mode == DEV2_OUTPUT) && (pFrame->addr == NULL))
932 SW_BREAKPOINT; */
934 Log_info1("SAP_reclaim: Exiting with SIO2_OK for device 0x%x ", device->mode);
935 //TRACE_VERBOSE((&TR_MOD, "SAP_reclaim.%d, exit SIO2_OK", __LINE__));
936 return SIO2_OK;
937 } // SAP_reclaim
940 // -----------------------------------------------------------------------------
942 Int SAP_open (DEV2_Handle device, String name)
943 {
944 SAP_DeviceExtension *pDevExt;
945 DEV2_Device *entry;
946 Int oldMask, result;
947 Error_Block eb;
948 //TRACE_GEN((&TR_MOD, "SAP_open.%d (0x%x)", __LINE__, device));
950 // check SIO mode
951 if ((device->mode != DEV2_INPUT) && (device->mode != DEV2_OUTPUT))
952 return SIO2_EMODE;
954 // allocate memory for device extension
955 device->object = NULL;
956 pDevExt = (SAP_DeviceExtension *) Memory_alloc (device->bufSeg, (sizeof(SAP_DeviceExtension)+3)/4*4, 4, &eb);
957 if (pDevExt == NULL)
958 {
959 printf("%s.%d: MEM_alloc failed.\n", __FUNCTION__, __LINE__);
960 //TRACE_TERSE((&TR_MOD, "%s.%d: MEM_alloc failed.\n", __FUNCTION__, __LINE__));
961 asm( " SWBP 0" ); // SW Breakpoint
962 return SIO2_EALLOC;
963 }
964 device->object = (Ptr)pDevExt;
966 // inits
967 pDevExt->device = device;
968 pDevExt->sync = NULL;
969 pDevExt->pParams = NULL;
970 pDevExt->runState = 0; // not yet started
971 pDevExt->errorState = PAF_SIO_ERROR_NONE;
972 pDevExt->shutDown = 1;
973 pDevExt->numQueued = 0;
974 pDevExt->activeEdma = EDMA_HINV;
975 pDevExt->errorEdma = EDMA_HINV;
976 pDevExt->firstTCC = 0;
977 pDevExt->optLevel = 0;
978 pDevExt->numParamSetup = 0;
979 pDevExt->numEdmaParams = EDMA_NUM_PARAMS; // We need more than 4 spare params to handle the immediate transition from Unknown
980 // to a Known program. Cheap resource to spend.
982 // use dev match to fetch function table pointer for SAP
983 DEV2_match(SAP_NAME, &entry);
984 if (entry == NULL) {
985 Log_error1("SAP", SIO2_ENODEV);
986 return SIO2_ENODEV;
987 }
988 pDevExt->pFxns = (SAP_Fxns *) entry->fxns;
990 // create semaphore for device
991 pDevExt->sync = Semaphore_create (0, NULL, NULL);
992 if (pDevExt->sync == NULL)
993 {
994 //TRACE_TERSE((&TR_MOD, "%s.%d: create semaphore for device failed.\n", __FUNCTION__, __LINE__));
995 return SIO2_EALLOC;
996 }
998 // queue inits
999 Queue_construct (&pDevExt->xferQue, NULL);
1000 Queue_construct (&pDevExt->paramQue, NULL);
1002 // update driver global (need to protect context)
1003 if (sapDrv.numDevices >= MAX_SAP_DEVICES)
1004 {
1005 /*TRACE_TERSE((&TR_MOD, "%s.%d: add device failure: no. of devices = %d; need to increase MAX_SAP_DEVICES.\n",
1006 __FUNCTION__, __LINE__, dapDrv.numDevices));*/
1007 SW_BREAKPOINT;
1008 }
1009 oldMask = Hwi_disable ();
1010 sapDrv.device[sapDrv.numDevices] = device;
1011 pDevExt->deviceNum = sapDrv.numDevices++;
1012 Hwi_restore (oldMask);
1014 // PORT init
1015 result = SAP_PORT_FTABLE_open (device);
1016 if (result)
1017 {
1018 //TRACE_TERSE((&TR_MOD, "%s.%d: SAP_PORT_FTABLE_open returned %d.\n", __FUNCTION__, __LINE__, result));
1019 return result;
1020 }
1022 return result;
1023 } // SAP_open
1025 // -----------------------------------------------------------------------------
1027 Int SAP_config (DEV2_Handle device, const SAP_Params *pParams)
1028 {
1029 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
1030 Int result, Que_num, i;
1031 EDMA3_DRV_Result edmaResult;
1032 Uint32 reqTcc;
1033 EDMA3_DRV_Handle hEdma;
1034 Log_info2("SAP_config.%d (0x%x)", __LINE__, device);
1036 // cannot configure if transfer started
1037 if (pDevExt->runState == 1)
1038 return SIO2_EBADIO;
1040 // save pointer to config structure in device extension. here so that
1041 // forthcoming functions can use/modify config structure.
1042 pDevExt->pParams = pParams;
1043 pDevExt->edmaWordSize = pParams->sio.wordSize;
1045 // allocate Port resources.
1046 // This must come before DMA configuration
1047 result = SAP_PORT_FTABLE_alloc (device);
1048 if (result)
1049 {
1050 Log_info3("%s.%d: SAP_PORT_FTABLE_alloc returned %d.\n", (xdc_IArg) __FUNCTION__, __LINE__, result);
1051 return result;
1052 }
1054 // .............................................................................
1055 // EDMA configuration
1057 // DA10x McASP0 Specific
1058 if (pParams->sio.moduleNum == 0)
1059 {
1060 hEdma = hEdma0;
1061 if (device->mode == DEV2_INPUT)
1062 {
1063 Que_num = 0;
1064 pDevExt->activeEdma = CSL_EDMACC_0_McASP_0_REVT;
1065 }
1066 else
1067 {
1068 Que_num = 0;
1069 pDevExt->activeEdma = CSL_EDMACC_0_McASP_0_XEVT;
1070 }
1071 }
1072 // DA10x McASP1 Specific
1073 else if (pParams->sio.moduleNum == 1)
1074 {
1075 hEdma = hEdma1;
1076 if (device->mode == DEV2_INPUT)
1077 {
1078 Que_num = 0;
1079 pDevExt->activeEdma = CSL_EDMACC_1_McASP_1_REVT;
1080 }
1081 else
1082 {
1083 Que_num = 0;
1084 pDevExt->activeEdma = CSL_EDMACC_1_McASP_1_XEVT;
1085 }
1086 }
1087 // DA10x McASP2 Specific
1088 else if (pParams->sio.moduleNum == 2)
1089 {
1090 hEdma = hEdma1;
1091 if (device->mode == DEV2_INPUT)
1092 {
1093 Que_num = 0;
1094 pDevExt->activeEdma = CSL_EDMACC_1_McASP_2_REVT;
1095 }
1096 else
1097 {
1098 Que_num = 0;
1099 pDevExt->activeEdma = CSL_EDMACC_1_McASP_2_XEVT;
1100 }
1101 }
1104 for (i=0; i < pDevExt->numEdmaParams; i++) {
1106 reqTcc = EDMA3_DRV_TCC_ANY;
1107 pDevExt->edmaParams[i].hEdmaParam = EDMA3_DRV_LINK_CHANNEL;
1108 edmaResult = EDMA3_DRV_requestChannel (
1109 hEdma,
1110 &pDevExt->edmaParams[i].hEdmaParam,
1111 &reqTcc,
1112 (EDMA3_RM_EventQueue) Que_num,
1113 SAP_isrCallback,
1114 (void *) device);
1116 if (edmaResult != EDMA3_DRV_SOK)
1117 return SIO2_EALLOC;
1119 //not running => can use non-atomic functions
1120 Queue_enqueue (Queue_handle(&pDevExt->paramQue), (Queue_Elem *)&pDevExt->edmaParams[i]);
1122 }
1124 reqTcc = EDMA3_DRV_TCC_ANY;
1125 pDevExt->errorEdma = EDMA3_DRV_LINK_CHANNEL;
1126 edmaResult = EDMA3_DRV_requestChannel (
1127 hEdma,
1128 &pDevExt->errorEdma,
1129 &reqTcc,
1130 (EDMA3_RM_EventQueue)Que_num,
1131 SAP_isrCallback,
1132 (void *) device);
1133 if (edmaResult != EDMA3_DRV_SOK)
1134 return SIO2_EALLOC;
1136 // allocate edma channel -- also disable and clear the interrupt
1139 pDevExt->firstTCC = pDevExt->activeEdma ;
1140 edmaResult = EDMA3_DRV_requestChannel (
1141 hEdma,
1142 &pDevExt->activeEdma,
1143 &pDevExt->firstTCC,
1144 (EDMA3_RM_EventQueue) 0,
1145 SAP_isrCallback,
1146 (void *) device);
1147 if (edmaResult != EDMA3_DRV_SOK)
1148 {
1149 Log_info3("%s.%d: SAP_DMA_FTABLE_alloc returned %d.\n", (xdc_IArg)__FUNCTION__, __LINE__, edmaResult);
1150 return SIO2_EALLOC;
1151 }
1153 // Configure error transfer
1154 // make cnt same as # of channels in order to maintain alignment
1155 // and the error transfer small so that we never have to wait
1156 // long for it to complete and trigger a linked transfer. This is
1157 // important for establishing output timing when we are idling with
1158 // clocks still running. Is fine for Rx as well.
1159 result = SAP_DMA_FTABLE_setupParam (device, pDevExt->errorEdma, pDevExt->errorEdma, NULL, pDevExt->edmaWordSize * pDevExt->numSers);
1161 Log_info3("%s.%d: Exiting SAP_alloc for %d.\n", (xdc_IArg)__FUNCTION__, __LINE__, pDevExt->activeEdma);
1163 return SIO2_OK;
1164 } // SAP_config
1166 // -----------------------------------------------------------------------------
1168 Int SAP_shutdown (DEV2_Handle device)
1169 {
1170 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)(device->object);
1171 SIO2_Handle stream = (SIO2_Handle) device;
1172 DEV2_Frame *pFrame;
1173 Int i;
1174 EDMA3_DRV_Handle hEdma;
1175 //TRACE_GEN((&TR_MOD, "SAP_shutdown.%d (0x%x)", __LINE__, device));
1177 if (pDevExt->shutDown)
1178 return SIO2_EBADIO;
1180 if (pDevExt->pParams == NULL)
1181 return SIO2_EINVAL;
1183 if (pDevExt->pParams->sio.moduleNum == 0)
1184 hEdma = hEdma0;
1185 else if (pDevExt->pParams->sio.moduleNum == 1 || pDevExt->pParams->sio.moduleNum == 2)
1186 hEdma = hEdma1;
1187 if (pDevExt->activeEdma != EDMA_HINV)
1188 EDMA3_DRV_disableTransfer (hEdma, pDevExt->activeEdma, EDMA3_DRV_TRIG_MODE_EVENT);
1190 // reset queues
1191 while (!Queue_empty(device->todevice)) {
1192 // place oustanding requests onto holding queue
1193 pFrame = (DEV2_Frame *) Queue_dequeue (device->todevice);
1194 Queue_enqueue (Queue_handle(&pDevExt->xferQue), (Queue_Elem *) pFrame);
1195 }
1197 while (!Queue_empty(Queue_handle(&pDevExt->xferQue))) {
1198 // pull frame from holding queue and place on user queue
1199 pFrame = (DEV2_Frame *) Queue_dequeue (Queue_handle(&pDevExt->xferQue));
1200 Queue_enqueue (device->fromdevice, (Queue_Elem *) pFrame);
1201 }
1204 while (!Queue_empty(Queue_handle(&pDevExt->paramQue)))
1205 Queue_dequeue (Queue_handle(&pDevExt->paramQue));
1207 // not running => can use non-atomic functions
1208 for (i=0; i < pDevExt->numEdmaParams; i++)
1209 Queue_enqueue (Queue_handle(&pDevExt->paramQue), (Queue_Elem *) &pDevExt->edmaParams[i]);
1211 // reset counter
1212 pDevExt->numQueued = 0;
1214 Log_info0("SAP_shutdown: After pDevExt->numQueued = 0 ");
1216 //SAP_EDMA_dumpParams(8);
1217 // make sure active is linked to error
1218 EDMA3_DRV_linkChannel (hEdma, pDevExt->activeEdma, pDevExt->errorEdma);
1220 // think this is better (from SIO_idle for standard model )
1221 // refill frame list -- so user needn't call reclaim, which may cause Rx underrun.
1222 while (!Queue_empty(device->fromdevice)) {
1223 /* place oustanding requests onto holding queue */
1224 pFrame = (DEV2_Frame *) Queue_dequeue (device->fromdevice);
1225 Queue_enqueue (Queue_handle(&stream->framelist), (Queue_Elem *) pFrame);
1226 }
1227 Semaphore_reset (pDevExt->sync, 0);
1229 pDevExt->shutDown = 1;
1230 pDevExt->numParamSetup = 0;
1232 /*result = SAP_DMA_FTABLE_unlock (device);
1233 if (result)
1234 {
1235 //TRACE_TERSE((&TR_MOD, "%s.%d: SAP_DMA_FTABLE_unlock returned %d.\n", __FUNCTION__, __LINE__, result));
1236 return result;
1237 } */
1239 return SIO2_OK;
1240 } // SAP_shutdown
1242 // -----------------------------------------------------------------------------
1243 int gSapWatchDogThrottle = 0; //DJDBG
1244 int gSapWatchDogIn =0;
1245 int gSapWatchDogOut = 0;
1246 int gSapWatchDogInSemPost = 0;
1247 int gSapWatchDogOutSemPost = 0;
1249 Void SAP_watchDog (Void)
1250 {
1251 DEV2_Handle device;
1252 SAP_DeviceExtension *pDevExt;
1253 int i, oldMask, result;
1255 //Log_info2("SAP_watchDog.%d (0x%x)", __LINE__, device);
1257 // do nothing if SAP_init not yet called
1258 if (!SAP_initialized)
1259 {
1260 Log_info2("%s.%d: SAP_init not yet called.\n", __FUNCTION__, __LINE__);
1261 return;
1262 }
1264 // protect context
1265 Task_disable (); // needed since we may call SEM_post
1266 //oldMask = Hwi_disable ();
1269 //Log_info3("%s.%d: devices loop, numDevices = %d", __FUNCTION__, __LINE__, sapDrv.numDevices);
1271 for (i=0; i < sapDrv.numDevices; i++) {
1272 device = sapDrv.device[i];
1274 //Log_info3("%s.%d, devices loop start, device = 0x%x", __FUNCTION__, __LINE__, device);
1276 pDevExt = (SAP_DeviceExtension *) device->object;
1278 // do nothing if not running
1279 if (!pDevExt->runState)
1280 continue;
1282 // call board specific watchdog
1283 // TODO: handle return value
1284 SIO2_ctrl (device, PAF_SIO_CONTROL_WATCHDOG, NULL);
1286 // if port layer returns error then must need to clean up
1287 result = SAP_PORT_FTABLE_watchDog (device);
1288 if (result) {
1289 // set errorState which will force owner thread
1290 // to clean up via SIO_idle()
1291 pDevExt->errorState = PAF_SIO_ERROR_FATAL;
1292 if(device->mode == DEV2_INPUT)
1293 gSapWatchDogIn++;
1294 else
1295 {
1296 //if (gSapWatchDogOut == 0)
1297 //SAP_EDMA_dumpParams(1);
1298 gSapWatchDogOut++;
1299 }
1301 //TRACE_TERSE((&TR_MOD, "SAP_watchDog.%d, PAF_SIO_ERROR_FATAL: 0x%x", __LINE__, pDevExt->errorState));
1302 /* if(gSapWatchDogThrottle == 0) //DJDBG
1303 {
1304 Log_info3("SAP_watchDog.%d (0x%x); THROTTLED result = 0x%x", __LINE__, device, result);
1305 }
1306 gSapWatchDogThrottle ++;
1307 if(gSapWatchDogThrottle > 10) gSapWatchDogThrottle = 0; */
1308 // if outstanding pend then post to free owner thead
1309 if (!Semaphore_pend(pDevExt->sync, 0))
1310 {
1311 if(device->mode == DEV2_INPUT)
1312 gSapWatchDogInSemPost++;
1313 else
1314 gSapWatchDogOutSemPost++;
1315 Semaphore_post (pDevExt->sync);
1316 }
1317 }
1318 }
1321 // renable interrupts and task manager.
1322 // If we posted to the semaphore then the TSK_enable call will lead to
1323 // an immediate task switch to the associated audio thread.
1324 //Hwi_restore (oldMask);
1325 Task_enable ();
1327 } // SAP_watchDog
1329 // -----------------------------------------------------------------------------
1330 // Assumes that EDMA3 dispatcher handles TCC clearing.
1332 void SAP_isrCallback (Uint32 tcc, EDMA3_RM_TccStatus status, Ptr context)
1333 {
1334 DEV2_Handle device;
1335 SAP_DeviceExtension *pDevExt;
1336 DEV2_Frame *pFrame;
1337 unsigned int opt;
1338 EDMA3_DRV_Handle hEdma;
1340 // could be here after Tx idle/overrun and this is the interrupt
1341 // for the last occuring error transfer so there is no transfer
1342 // to release, we just clear the int and exit.
1344 device = (DEV2_Handle) context;
1345 pDevExt = (SAP_DeviceExtension *)(device->object);
1346 //if (pDevExt->pParams == NULL)
1347 //return SIO2_EINVAL;
1349 if (pDevExt->pParams->sio.moduleNum == 0)
1350 hEdma = hEdma0;
1351 else if (pDevExt->pParams->sio.moduleNum == 1 || pDevExt->pParams->sio.moduleNum == 2)
1352 hEdma = hEdma1;
1354 if ((pDevExt->runState == 1) && !pDevExt->errorState) {
1355 // if here then an interrupt occured due to errorEdma or valid
1356 // transfer, we assume the xfer is long enough so it will not complete
1357 // before we are finished here.
1359 // if last transfer was valid then complete it
1360 if (!Queue_empty(Queue_handle(&pDevExt->xferQue))) {
1362 // pull frame from holding queue
1363 pFrame = (DEV2_Frame *) Queue_dequeue (Queue_handle(&pDevExt->xferQue));
1365 // if used param entry then return it to queue
1366 if (pFrame->misc != NULL)
1367 {
1368 Queue_enqueue (Queue_handle(&pDevExt->paramQue), (Ptr) pFrame->misc);
1369 if (device->mode == 1)
1370 gisrOutput+=100;
1371 }
1373 // decrement count
1374 pDevExt->numQueued -= 1;
1375 //gIsrCnt++;
1376 if (device->mode == 1)
1377 {
1378 gIsrOutputCnt++;
1379 //Log_info1("SAP isrCallback for 0x%x", pDevExt->activeEdma);
1380 }
1381 else
1382 gIsrInputCnt++;
1383 // place frame onto user queue and signal user thread
1384 Queue_enqueue (device->fromdevice, (Ptr) pFrame);
1386 //Log_info2("Before SEM_post for device: 0x%x gIsrOutput: %d", device->mode, gisrOutput);
1387 // signal user thread
1388 Semaphore_post (pDevExt->sync);
1389 #if 0
1390 if(gIsrCnt > 10) { //DJDBG
1391 Log_info1("SAP isrCallback enough interrupts! %d", gIsrCnt);
1393 }
1394 #endif
1395 }
1396 else
1397 gIsrElseCnt++;
1399 // determine if currently transferring buffer is valid based on interrupt enable bit
1400 // only valid transfers will generate interrupts
1401 EDMA3_DRV_getPaRAMEntry (hEdma, pDevExt->activeEdma, EDMA3_DRV_PARAM_ENTRY_OPT, &opt);
1403 if (!(opt & EDMA3_DRV_OPT_TCINTEN_SET_MASK (1)))
1404 {
1405 if (device->mode == 1)
1406 gIsrOutErrCnt++;
1407 else
1408 gIsrInErrCnt++;
1409 pDevExt->errorState = PAF_SIO_ERROR_ERRBUF_XFER;
1410 }
1412 } // runState
1413 else
1414 {
1415 if (pDevExt->runState != 1)
1416 gIsrRunCnt++;
1417 else
1418 gIsrNotRunCnt++;
1419 }
1421 return;
1422 } //SAP_isrCallback
1424 // -----------------------------------------------------------------------------
1426 Int SAP_EDMA_setupXfer (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32 parentEdma, XDAS_UInt32 childEdma, DEV2_Frame *pFrame)
1427 {
1428 EDMA3_DRV_Handle hEdma;
1429 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
1430 // int mcbspNum = pDevExt->pParams->sio.moduleNum;
1432 if (pDevExt->pParams == NULL)
1433 return SIO2_EINVAL;
1435 if (pDevExt->pParams->sio.moduleNum == 0)
1436 hEdma = hEdma0;
1437 else if (pDevExt->pParams->sio.moduleNum == 1 || pDevExt->pParams->sio.moduleNum == 2)
1438 hEdma = hEdma1;
1440 // TODO: shouldn't this just be tcc interrupt disable?
1441 // at least until linkage phase...
1442 unsigned int key = Hwi_disable (); //DJDBG
1444 if(targetEdma == NULL)
1445 {
1446 Log_info0("targetEdma is NULL");
1447 }
1448 // configure transfer
1449 if(pFrame->addr == NULL) //DJDBG
1450 {
1451 Log_info0("pFrame has NULL address?");
1452 }
1453 SAP_DMA_FTABLE_setupParam (device, targetEdma, childEdma, (XDAS_UInt32) pFrame->addr, pFrame->size);
1455 if (device->mode == DEV2_OUTPUT)
1456 Log_info4("SAP: Inside SAP_EDMA_setupXfer with childEdma=0x%x & targetEdma = 0x%x; pFrame->addr = 0x%x, pFrame->size=0x%x", childEdma, targetEdma, pFrame->addr, pFrame->size);
1458 if (parentEdma != EDMA_HINV)
1459 EDMA3_DRV_linkChannel (hEdma, parentEdma, targetEdma);
1461 if (device->mode == DEV2_OUTPUT)
1462 Log_info3("SAP: Inside SAP_EDMA_setupXfer linked targetEdma = 0x%x with parentEdma=0x%x on Edma=0x%x", targetEdma, parentEdma, hEdma);
1464 Hwi_restore (key); //DJDBG
1466 return SIO2_OK;
1467 } // SAP_setupXfer
1469 // -----------------------------------------------------------------------------
1470 // Configure EDMA3 parameter entry
1472 Int SAP_EDMA_setupParam (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32 childEdma, XDAS_UInt32 addr, XDAS_UInt32 size)
1473 {
1474 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
1475 EDMA3_DRV_Handle hEdma;
1476 EDMA3_DRV_PaRAMRegs edmaConfig;
1478 if (pDevExt->pParams == NULL)
1479 return SIO2_EINVAL;
1481 if (pDevExt->pParams->sio.moduleNum == 0)
1482 hEdma = hEdma0;
1483 else if (pDevExt->pParams->sio.moduleNum == 1 || pDevExt->pParams->sio.moduleNum == 2)
1484 hEdma = hEdma1;
1485 MCASP_Handle hPort = sapMcaspDrv.hPort[pDevExt->pParams->sio.moduleNum];
1486 // volatile Uint32 *base = (volatile Uint32 *)(hPort->baseAddr);
1488 //Log_info3("%s.%d: Entered SAP_EDMA_setupParam for Target: 0x%x.\n", (xdc_IArg)__FUNCTION__, __LINE__, targetEdma);
1490 // Init opt parameter to 0 which, without being overriden, configures as:
1491 // A synchronized transfer (no FIFO mode on src or dst)
1492 // no chaining or intermediate interrupts
1493 // param is not static
1494 // normal completion
1495 // don't generate an interrupt (overriden below for regular xfers)
1496 edmaConfig.opt = 0;
1498 // not transferring blocks so c index is 0
1499 edmaConfig.destCIdx = 0;
1500 edmaConfig.srcCIdx = 0;
1502 edmaConfig.opt |= EDMA3_DRV_OPT_SYNCDIM_SET_MASK (EDMA3_DRV_SYNC_AB); //DJDBG!
1503 if (device->mode == DEV2_OUTPUT) {
1504 //edmaConfig.opt |= EDMA3_DRV_OPT_DAM_SET_MASK (EDMA3_DRV_ADDR_MODE_FIFO); //DJDBG!!!
1505 edmaConfig.opt |= 2;
1506 }
1507 else {
1508 //edmaConfig.opt |= EDMA3_DRV_OPT_SAM_SET_MASK (EDMA3_DRV_ADDR_MODE_FIFO); //DJDBG!!!
1509 edmaConfig.opt |= 1;
1510 }
1512 // if regular transfer then enable interrupt with tcc code
1513 if (targetEdma != pDevExt->errorEdma) {
1514 edmaConfig.opt |= EDMA3_DRV_OPT_SYNCDIM_SET_MASK (EDMA3_DRV_SYNC_AB);
1515 edmaConfig.opt |= EDMA3_DRV_OPT_TCINTEN_SET_MASK (1);
1516 edmaConfig.opt |= EDMA3_DRV_OPT_TCC_SET_MASK (pDevExt->firstTCC);
1517 }
1520 edmaConfig.aCnt = 4;
1521 edmaConfig.bCnt = pDevExt->numSers;
1522 edmaConfig.cCnt = size/(edmaConfig.aCnt * edmaConfig.bCnt);
1523 edmaConfig.bCntReload = edmaConfig.bCnt;
1526 // handle direction specific requirements
1527 if (device->mode == DEV2_INPUT) {
1528 edmaConfig.srcBIdx = 0;
1529 edmaConfig.srcAddr = (unsigned int) (hPort->rbufAddr);
1531 if (addr) {
1532 edmaConfig.destBIdx = pDevExt->edmaWordSize;
1533 edmaConfig.destAddr = addr;
1534 edmaConfig.destCIdx = pDevExt->edmaWordSize * pDevExt->numSers ;
1535 if(pDevExt->edmaWordSize == 2)
1536 edmaConfig.cCnt= (size)/((edmaConfig.aCnt * edmaConfig.bCnt)/2);
1537 }
1538 else {
1539 //if(pDevExt->edmaWordSize == 2)
1540 //edmaConfig.srcAddr= (unsigned int)edmaConfig.srcAddr+ 2;
1541 edmaConfig.destBIdx = 0;
1542 edmaConfig.destAddr = (unsigned int) &sap_OVER_4LANE;
1543 edmaConfig.cCnt = 1;
1544 }
1545 }
1546 else {
1547 edmaConfig.destBIdx = 0;
1548 edmaConfig.srcBIdx = pDevExt->edmaWordSize;
1549 edmaConfig.destAddr = (unsigned int) (hPort->xbufAddr);
1550 if (addr) {
1551 edmaConfig.srcCIdx = pDevExt->edmaWordSize * pDevExt->numSers ;
1552 edmaConfig.srcAddr = addr;
1553 //Edma3_CacheFlush ((unsigned int) addr, (size+3)/4);
1554 }
1555 else {
1556 edmaConfig.srcBIdx = 0;
1557 edmaConfig.srcAddr = (unsigned int) &sap_UNDER[0];
1558 #if 0
1559 //edmaConfig.cCnt = (SAP_UNDER_LEN * sizeof(int))/(edmaConfig.aCnt * edmaConfig.bCnt); //DJDBG
1560 edmaConfig.cCnt = SAP_UNDER_LEN; //DJDBG, if underrun have frame of silence
1561 #endif
1562 }
1563 }
1564 edmaConfig.srcAddr = (unsigned int) getGlobalAddr(edmaConfig.srcAddr);
1565 edmaConfig.destAddr = (unsigned int) getGlobalAddr(edmaConfig.destAddr);
1567 EDMA3_DRV_setPaRAM (hEdma, targetEdma, &edmaConfig);
1569 // link child xfer
1570 if (childEdma != EDMA_HINV)
1571 EDMA3_DRV_linkChannel (hEdma, targetEdma, childEdma);
1573 if (device->mode == DEV2_OUTPUT) {
1574 Log_info5("SAP: Inside SAP_EDMA_setupParam: size=0x%x, targetEdma = 0x%x, CCNT = %d with dest-addr: 0x%x and OPT=0x%x", size, targetEdma, edmaConfig.cCnt, edmaConfig.destAddr, edmaConfig.opt);
1575 Log_info5("SAP: Inside SAP_EDMA_setupParam: aCnt=0x%x, bCnt = 0x%x; linked targetEdma = 0x%x with childEdma=0x%x on Edma=0x%x", edmaConfig.aCnt, edmaConfig.bCnt, targetEdma, childEdma, hEdma );
1576 }
1578 return SIO2_OK;
1579 } //SAP_setupParam