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 int sap_UNDER[SAP_UNDER_LEN]; // used for underrun
102 int sap_OVER_1LANE = 0; // used for overrun
103 int sap_OVER_4LANE[4] = {0,0,0,0}; // used for overrun
105 #ifdef DEBUG
106 void SAP_EDMA_dumpParams(int tag_place)
107 {
108 //unsigned int *ptrPARAM_BASE = (unsigned int *)0x02704000;
109 unsigned int *ptrPARAM0x18 = (unsigned int *)0x02704300; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[24]
110 //unsigned int *ptrPARAM0x19 = (unsigned int *)0x02704320; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[24]
111 //unsigned int *ptrPARAM0x41 = (unsigned int *)0x027048A0; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[24]
112 //unsigned int *ptrPARAM0x42 = (unsigned int *)0x027048C0; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[24]
113 //unsigned int *ptrPARAM0x43 = (unsigned int *)0x027048E0; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[24]
114 //unsigned int *ptrPARAM0x48 = (unsigned int *)0x02704910; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[24]
115 unsigned int *ptrPARAM0x45 = (unsigned int *)0x027048A0; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[69]
116 unsigned int *ptrPARAM0x46 = (unsigned int *)0x027048C0; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[70]
117 unsigned int *ptrPARAM0x47 = (unsigned int *)0x027048E0; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[71]
118 unsigned int *ptrPARAM0x48 = (unsigned int *)0x02704900; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[72]
119 unsigned int *ptrPARAM0x49 = (unsigned int *)0x02704920; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[73]
120 unsigned int *ptrPARAM0x4A = (unsigned int *)0x02704940; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[74]
122 //Log_info5("PARAM0x18a(%d): 0x%x 0x%x 0x%x 0x%x", tag_place, ptrPARAM0x18[0], ptrPARAM0x18[1], ptrPARAM0x18[2], ptrPARAM0x18[3]);
123 //Log_info5("PARAM0x18b(%d): 0x%x 0x%x 0x%x 0x%x", tag_place, ptrPARAM0x18[4], ptrPARAM0x18[5], ptrPARAM0x18[6], ptrPARAM0x18[7]);
125 /*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));
126 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]);
127 Log_info4("PARAM0x19b(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x19[5], ptrPARAM0x19[6], ptrPARAM0x19[7]);
129 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));
130 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]);
131 Log_info4("PARAM0x41b(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x41[5], ptrPARAM0x41[6], ptrPARAM0x41[7]);
133 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));
134 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]);
135 Log_info4("PARAM0x42b(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x42[5], ptrPARAM0x42[6], ptrPARAM0x42[7]);
137 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));
138 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]);
139 Log_info4("PARAM0x43b(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x43[5], ptrPARAM0x43[6], ptrPARAM0x43[7]);
141 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));
142 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]);
143 Log_info4("PARAM0x48b(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x48[5], ptrPARAM0x48[6], ptrPARAM0x48[7]);*/
145 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));
146 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]);
147 Log_info4("PARAM0x18c(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x18[5], ptrPARAM0x18[6], ptrPARAM0x18[7]);
149 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));
150 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]);
151 Log_info4("PARAM0x45c(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x45[5], ptrPARAM0x45[6], ptrPARAM0x45[7]);
153 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));
154 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]);
155 Log_info4("PARAM0x46c(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x46[5], ptrPARAM0x46[6], ptrPARAM0x46[7]);
157 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));
158 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]);
159 Log_info4("PARAM0x47c(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x47[5], ptrPARAM0x47[6], ptrPARAM0x47[7]);
161 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));
162 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]);
163 Log_info4("PARAM0x48c(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x48[5], ptrPARAM0x48[6], ptrPARAM0x48[7]);
165 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));
166 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]);
167 Log_info4("PARAM0x49c(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x49[5], ptrPARAM0x49[6], ptrPARAM0x49[7]);
169 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));
170 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]);
171 Log_info4("PARAM0x4Ac(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x4A[5], ptrPARAM0x4A[6], ptrPARAM0x4A[7]);
173 Log_info1("TCC0: ERR reg %x", *((unsigned int *)0x02760120)); //DJDBG
174 }
175 #endif
176 // .............................................................................
177 // notes:
178 // . add control function to PORT table
179 // . how to handle DMA/PORT specifics in parameter entries
180 // can assume numSers = numChans is general and can be applied by DMA
181 // same for wordSize?
182 // . why are two idle stages needed (seems like 1 is enough)?
184 // .............................................................................
185 // only one global variable, not static so that DMA and port functions
186 // can access. We cant just store the address in devExt since the ISR has
187 // no context.
189 SAP_DriverObject sapDrv;
191 // needed since SAP_watchDog is called before SAP_init
192 Int SAP_initialized = 0;
194 //Int SAP_close(DEV2_Handle);
195 Int SAP_ctrl(DEV2_Handle, Uns, Arg);
196 Int SAP_idle(DEV2_Handle, Bool);
197 Int SAP_issue(DEV2_Handle);
198 Int SAP_open(DEV2_Handle, String);
199 void SAP_isrCallback (Uint32 tcc, EDMA3_RM_TccStatus status, Ptr context);
200 //Bool SAP_ready(DEV2_Handle, SEM_Handle);
201 Int SAP_reclaim(DEV2_Handle);
202 Int SAP_shutdown(DEV2_Handle);
203 Int SAP_start(DEV2_Handle);
204 Int SAP_config(DEV2_Handle device, const SAP_Params *pParams);
205 Int SAP_EDMA_setupParam (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32 childEdma, XDAS_UInt32 addr, XDAS_UInt32 size);
206 Int SAP_EDMA_setupXfer (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32 parentEdma, XDAS_UInt32 childEdma, DEV2_Frame *pFrame);
208 // .............................................................................
210 // .............................................................................
212 SAP_DMA_Fxns SAP_EDMA_FXNS =
213 {
214 SAP_EDMA_setupParam,
215 SAP_EDMA_setupXfer,
216 };
219 SAP_Fxns SAP_FXNS =
220 {
221 NULL, //SAP_close, -- remove for IROM since not using
222 SAP_ctrl,
223 SAP_idle,
224 SAP_issue,
225 SAP_open,
226 NULL, //SAP_ready, -- remove for IROM since not using
227 SAP_reclaim,
228 SAP_shutdown,
229 SAP_start,
230 SAP_config,
232 #ifdef SAP_PORT_MCASP
233 (SAP_PORT_Fxns *) &SAP_MCASP_FXNS,
234 #endif
235 #ifdef SAP_DMA_EDMA
236 (SAP_DMA_Fxns *) &SAP_EDMA_FXNS,
237 #endif
238 };
240 // -----------------------------------------------------------------------------
241 // This function is not in the driver function table.
242 // Must be pointed at in GUI config tool.
243 //
244 Void SAP_init (Void)
245 {
246 DEV2_Device *entry;
247 SAP_Fxns *pFxns;
249 //TRACE_GEN((&TR_MOD, "SAP_init.%d", __LINE__));
251 // find function table pointer (used by SAP_XX_FTABLE_init macros)
252 DEV2_match(SAP_NAME, &entry);
253 if (entry == NULL) {
254 Log_error1 ("SAP", SIO2_ENODEV);
255 return;
256 }
257 pFxns = (SAP_Fxns *) entry->fxns;
259 //SAP_DMA_FTABLE_init ();
260 SAP_PORT_FTABLE_init ();
262 sapDrv.numDevices = 0;
263 SAP_initialized = 1;
265 return;
266 } // SAP_init
268 // -----------------------------------------------------------------------------
270 int gSapInput_ControlOpen = 0;
271 int gSapOutput_ControlOpen = 0;
273 int gSapInput_ControlClose = 0;
274 int gSapOutput_ControlClose = 0;
276 Int SAP_ctrl (DEV2_Handle device, Uns code, Arg arg)
277 {
278 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
279 const SAP_Params *pParams;
280 Int i, result = SIO2_OK;
281 EDMA3_DRV_Handle hEdma;
282 //TRACE_GEN((&TR_MOD, "SAP_ctrl.%d (0x%x) code = 0x%x", __LINE__, device, code));
284 switch (code) {
286 /* .......................................................................... */
288 case PAF_SIO_CONTROL_MUTE:
289 case PAF_SIO_CONTROL_UNMUTE:
290 pParams = pDevExt->pParams;
291 if (pParams == NULL)
292 return SIO2_OK;
294 if (pParams->sio.control != NULL)
295 result = pParams->sio.control (device, (const PAF_SIO_Params *)pParams, code, arg);
296 break;
298 /* .......................................................................... */
300 case PAF_SIO_CONTROL_OPEN:
301 if (pDevExt->runState)
302 return SIO2_EBUSY;
304 if (!( pParams = (const SAP_Params *) arg ))
305 return SIO2_OK;
307 if(device->mode == DEV2_OUTPUT)
308 gSapOutput_ControlOpen++;
309 else
310 gSapInput_ControlOpen++;
312 if (result = SAP_FTABLE_config (device, pParams))
313 return result;
315 if (pParams->sio.control && (result = pParams->sio.control (device, (const PAF_SIO_Params *)pParams, code, arg)))
316 return result;
318 break;
320 /* .......................................................................... */
322 case PAF_SIO_CONTROL_CLOSE:
323 if (pDevExt->runState)
324 return SIO2_EBUSY;
326 if (pDevExt->pParams == NULL)
327 return SIO2_EINVAL;
329 pParams = pDevExt->pParams;
331 if (pParams->sio.moduleNum == 0)
332 hEdma = hEdma0;
333 else if (pParams->sio.moduleNum == 1 || pParams->sio.moduleNum == 2)
334 hEdma = hEdma1;
336 if (pDevExt->activeEdma != EDMA_HINV) {
337 EDMA3_DRV_freeChannel (hEdma, pDevExt->activeEdma);
338 pDevExt->activeEdma = EDMA_HINV;
339 }
341 if(device->mode == DEV2_INPUT)
342 gSapInput_ControlClose++;
343 else
344 gSapOutput_ControlClose++;
346 for (i=0; i < pDevExt->numEdmaParams; i++) {
347 if (pDevExt->edmaParams[i].hEdmaParam != EDMA_HINV)
348 {
349 EDMA3_DRV_freeChannel (hEdma, pDevExt->edmaParams[i].hEdmaParam);
350 pDevExt->edmaParams[i].hEdmaParam = EDMA_HINV;
351 }
352 }
354 if (pDevExt->errorEdma != EDMA_HINV) {
355 EDMA3_DRV_freeChannel (hEdma, pDevExt->errorEdma);
356 pDevExt->errorEdma = EDMA_HINV;
357 }
359 if (!(pParams = pDevExt->pParams))
360 return SIO2_OK;
362 if (pParams->sio.control && (result = pParams->sio.control (device, (const PAF_SIO_Params *)pParams, code, arg)))
363 return result;
365 result = SAP_PORT_FTABLE_close (device);
366 if (result)
367 return result;
369 pDevExt->pParams = NULL;
370 break;
372 /* .......................................................................... */
374 case PAF_SIO_CONTROL_GET_WORDSIZE:
375 if (!arg)
376 return SIO2_EINVAL;
377 *((int *) arg) = pDevExt->edmaWordSize;
378 break;
380 case PAF_SIO_CONTROL_SET_WORDSIZE:
381 // defer to DMA processing
382 // currently only supported for input
383 if (device->mode != DEV2_INPUT)
384 return SIO2_EINVAL;
386 // can't be running
387 if (pDevExt->runState)
388 return SIO2_EBUSY;
390 // driver only supports 2 or 4 bytes
391 if ((arg != 2) && (arg != 4))
392 return SIO2_EINVAL;
394 // return success for unconfigured devices?
395 if (!pDevExt->pParams)
396 return SIO2_OK;
398 // ask platform if size is supported
399 pParams = pDevExt->pParams;
400 if (pDevExt->pParams->sio.control && (result = pDevExt->pParams->sio.control (device, (const PAF_SIO_Params *)pParams, code, arg)))
401 return result;
403 pDevExt->edmaWordSize = arg;
404 break;
406 case PAF_SIO_CONTROL_GET_PRECISION:
407 if (arg == 0)
408 return SIO2_EINVAL;
410 pParams = pDevExt->pParams;
411 if (pParams == NULL)
412 return( SIO2_EINVAL );
414 *((int *) arg) = pParams->sio.precision;
415 break;
417 case PAF_SIO_CONTROL_GET_NUMCHANNELS:
418 if (arg == 0)
419 return SIO2_EINVAL;
421 *((int *) arg) = pDevExt->numSlots * pDevExt->numSers;
422 break;
424 case PAF_SIO_CONTROL_SET_RATEX:
425 pParams = pDevExt->pParams;
426 if (pParams == NULL)
427 return SIO2_OK ;
429 if (pParams->sio.control == NULL)
430 return SIO2_EINVAL;
432 result = pParams->sio.control( device, (const PAF_SIO_Params *)pParams, PAF_SIO_CONTROL_SET_RATEX, arg);
433 break;
435 /* .......................................................................... */
437 case PAF_SIO_CONTROL_IDLE:
438 pParams = pDevExt->pParams;
439 if (pParams == NULL)
440 return SIO2_OK ;
442 if (pParams->sio.control == NULL)
443 return SIO2_EINVAL;
445 result = pParams->sio.control( device, (const PAF_SIO_Params *)pParams, PAF_SIO_CONTROL_IDLE, arg);
446 break;
448 case PAF_SIO_CONTROL_IDLE_WITH_CLOCKS:
449 // 1. Here we are intentionally not using SIO_Idle() and
450 // leaving the Tx clock running. We need this to avoid DAC noise,
451 // as well as provide a DIT clock when using digital output.
452 if (device->mode != DEV2_OUTPUT || pDevExt->pParams == NULL)
453 return SIO2_EINVAL;
455 pParams = pDevExt->pParams;
457 if (pParams->sio.moduleNum == 0)
458 hEdma = hEdma0;
459 else if (pParams->sio.moduleNum == 1 || pParams->sio.moduleNum == 2)
460 hEdma = hEdma1;
462 result = SAP_FTABLE_shutdown (device);
463 if (result)
464 return result;
466 Log_info0 ("SAP PAF_SIO_CONTROL_IDLE_WITH_CLOCKS; PAF_SIO_ERROR_IDLE_STAGE1");
467 pDevExt->errorState = PAF_SIO_ERROR_IDLE_STAGE1;
469 #if 1
470 //DJDBG, if below enableTransfer() is commented, input side continuous working.
471 if (pDevExt->activeEdma != EDMA_HINV) {
472 //EDMA3_DRV_disableTransfer (hEdma0, pDevExt->activeEdma, EDMA3_DRV_TRIG_MODE_EVENT);
473 //if(*((unsigned int *)0x02701000) & 0x01000000) *((unsigned int *)0x02701008) = 0x01000000; //Clear pending even in bit 24! //DJDBG
474 EDMA3_DRV_enableTransfer (hEdma, pDevExt->activeEdma, EDMA3_DRV_TRIG_MODE_EVENT);
475 }
476 #endif
477 //TRACE_GEN((&TR_MOD, "SAP_ctrl.%d: (0x%x) errorState = PAF_SIO_ERROR_IDLE_STAGE1 0x%x.", __LINE__, device, PAF_SIO_ERROR_IDLE_STAGE1));
479 break;
481 /* .......................................................................... */
483 case PAF_SIO_CONTROL_GET_INPUT_STATUS:
484 // needs to be attached
485 pParams = pDevExt->pParams;
486 if (pParams == NULL)
487 return SIO2_OK;
489 if (pParams->sio.control == NULL)
490 return SIO2_EINVAL;
492 result = pParams->sio.control( device, (const PAF_SIO_Params *)pParams, code, arg );
493 break;
495 case PAF_SIO_CONTROL_WATCHDOG:
496 pParams = pDevExt->pParams;
497 if (pParams == NULL)
498 return SIO2_OK;
499 if (pParams->sio.control && (result = pParams->sio.control (device, (const PAF_SIO_Params *)pParams, code, arg)))
500 return result;
501 break;
503 /* .......................................................................... */
505 // Timing stats specific to DMA engine
506 case PAF_SIO_CONTROL_ENABLE_STATS:
507 case PAF_SIO_CONTROL_DISABLE_STATS:
508 case PAF_SIO_CONTROL_GET_STATS:
509 case PAF_SIO_CONTROL_GET_NUM_EVENTS:
510 case PAF_SIO_CONTROL_GET_NUM_REMAINING:
511 //result = SAP_DMA_FTABLE_ctrl (device, code, arg);
512 // TRACE_VERBOSE((&TR_MOD, "SAP_ctrl: (0x%x) code 0x%x. result 0x%x.", device, code, result));
513 break;
515 /* .......................................................................... */
517 case PAF_SIO_CONTROL_SET_DITSTATUS:
518 if(device->mode == DEV2_OUTPUT)
519 {
520 const SAP_Params *pParams = pDevExt->pParams;
521 MCASP_Handle hPort = sapMcaspDrv.hPort[pParams->sio.moduleNum];
522 volatile Uint32 *base = (volatile Uint32 *)(hPort->baseAddr);
523 MCASP_ConfigXmt *pTxConfig = (MCASP_ConfigXmt *)pParams->sio.pConfig;
524 int encSelect = *((int *) arg);
526 // HACK -- determine DIT need by FXWID
527 if (((pTxConfig->afsxctl & _MCASP_AFSXCTL_FXWID_MASK)>> _MCASP_AFSXCTL_FXWID_SHIFT) == MCASP_AFSXCTL_FXWID_BIT)
528 {
529 if ( (encSelect == 0x13) ||
530 (encSelect == 0xa) ||
531 (encSelect == 0x6)) // DTE, DDE, MPE
532 {
533 base[_MCASP_DITCSRA0_OFFSET] |= 2;
534 base[_MCASP_DITCSRB0_OFFSET] |= 2;
535 }
536 else
537 {
538 base[_MCASP_DITCSRA0_OFFSET] &= 0xfffffffd;
539 base[_MCASP_DITCSRB0_OFFSET] &= 0xfffffffd;
540 }
541 }
543 pParams = pDevExt->pParams;
544 if (pParams == NULL)
545 return SIO2_OK;
547 if (pParams->sio.control != NULL)
548 result = pParams->sio.control (device, (const PAF_SIO_Params *)pParams, code, arg);
549 }
550 break;
552 /* .......................................................................... */
554 }
556 return result;
557 } // SAP_ctrl
559 int gSAPIdleShutdownIn=0;
560 int gSAPIdleShutdownOut=0;
562 // -----------------------------------------------------------------------------
564 Int SAP_idle (DEV2_Handle device, Bool flush)
565 {
566 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
567 Int result = SIO2_OK;
568 EDMA3_DRV_Handle hEdma;
570 // do nothing if already idled or unattached
571 if ((!pDevExt->runState) || (pDevExt->pParams == NULL))
572 return result;
574 if (pDevExt->pParams->sio.moduleNum == 0)
575 hEdma = hEdma0;
576 else if (pDevExt->pParams->sio.moduleNum == 1 || pDevExt->pParams->sio.moduleNum == 2)
577 hEdma = hEdma1;
579 // reset serial port -- stop generating sync events
580 result = SAP_PORT_FTABLE_reset (device);
581 if(device->mode == DEV2_OUTPUT)
582 gSAPResetOut++;
583 else
584 gSAPResetIn++;
585 if (result)
586 {
587 //TRACE_VERBOSE((&TR_MOD, "%s.%d: SAP_PORT_FTABLE_reset returned %d.\n", __FUNCTION__, __LINE__, result));
588 return result;
589 }
591 pDevExt->shutDown = 0; // force shutdown to run
592 result = SAP_FTABLE_shutdown (device);
593 if(device->mode == DEV2_OUTPUT)
594 gSAPIdleShutdownOut++;
595 else
596 gSAPIdleShutdownIn++;
598 if (result)
599 {
600 //TRACE_VERBOSE((&TR_MOD, "%s.%d: SAP_FTABLE_shutdown returned %d.\n", __FUNCTION__, __LINE__, result));
601 return result;
602 }
604 Log_info0("SAP_idle:Before EDMA3_DRV_disableTransfer");
606 // disable interrupts and EDMA servicing
607 if (pDevExt->activeEdma != EDMA_HINV)
608 EDMA3_DRV_disableTransfer (hEdma, pDevExt->activeEdma, EDMA3_DRV_TRIG_MODE_EVENT);
610 pDevExt->numQueued = 0;
612 // signal stopped
613 pDevExt->runState = 0;
614 Log_info0("SAP_idle: runState = 0");
616 // reset errorState
617 pDevExt->errorState = PAF_SIO_ERROR_NONE;
618 //TRACE_VERBOSE((&TR_MOD, "SAP_ctrl.%d: errorState = PAF_SIO_ERROR_NONE 0x%x.", __LINE__, PAF_SIO_ERROR_NONE));
620 // place call to physical device
621 if ((pDevExt->pParams != NULL) && (pDevExt->pParams->sio.control != NULL))
622 result = pDevExt->pParams->sio.control(device, (const PAF_SIO_Params *)pDevExt->pParams, PAF_SIO_CONTROL_IDLE, 0);
624 return result;
625 } // SAP_idle
627 // -----------------------------------------------------------------------------
629 Int SAP_start (DEV2_Handle device)
630 {
631 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
632 DEV2_Frame *pFrame;
633 int result;
634 EDMA3_DRV_Handle hEdma;
636 Log_info2("SAP_start.%d (0x%x)", __LINE__, device);
638 // Assume todevice queue is not empty -- how else could we be here?
639 pFrame = (DEV2_Frame *) Queue_get (device->todevice);
641 // inidicate this xfer did not use param entry - just the active one
642 pFrame->misc = NULL;
643 if (pDevExt->pParams->sio.moduleNum == 0)
644 hEdma = hEdma0;
645 else if (pDevExt->pParams->sio.moduleNum == 1 || pDevExt->pParams->sio.moduleNum == 2)
646 hEdma = hEdma1;
648 // non-atomic functions since not running yet.
649 Queue_enqueue (Queue_handle(&pDevExt->xferQue), (Queue_Elem *)pFrame);
651 // initialize count
652 pDevExt->numQueued = 1;
654 result = SAP_PORT_FTABLE_reset (device);
655 if (result)
656 {
657 //TRACE_VERBOSE((&TR_MOD, "%s.%d: SAP_PORT_FTABLE_reset returned %d.\n", __FUNCTION__, __LINE__, result));
658 return result;
659 }
661 // enable DMA processing
662 if (device->mode == DEV2_OUTPUT)
663 Log_info3("SAP_start.%d, pDevExt->activeEdma 0x%x (pDevExt->errorEdma = 0x%x)",
664 __LINE__, pDevExt->activeEdma, pDevExt->errorEdma);
665 // config active xfer for this buffer
666 result = SAP_EDMA_setupXfer(device, pDevExt->activeEdma, EDMA_HINV, pDevExt->errorEdma, pFrame);
669 // signal we have started -- this must come before last enable to prevent a race
670 // condition where the initial EDMA transfer is very small (e.g. due to startClocks)
671 // and completes before any further instructions in this thread are executed.
672 // This comes before the EDMA enable since, if the # of samples is 1, then the EDMA
673 // will be serviced and generate an interrupt even before the McASP is enabled.
674 pDevExt->runState = 1;
675 pDevExt->shutDown = 0;
676 if (device->mode == DEV2_OUTPUT)
677 Log_info2 ("SAP: %d, SAP_start runState=1 & ENABLE TRANSFERS for activeEdma = 0x%x", __LINE__, pDevExt->activeEdma);
678 // enable interrupts and event servicing for this channel
679 EDMA3_DRV_enableTransfer (hEdma, pDevExt->activeEdma, EDMA3_DRV_TRIG_MODE_EVENT);
681 // enable peripheral
682 result = SAP_PORT_FTABLE_enable (device);
684 if (result)
685 {
686 //TRACE_VERBOSE((&TR_MOD, "%s.%d: SAP_PORT_FTABLE_enable returned %d.\n", __FUNCTION__, __LINE__, result));
687 return result;
688 }
690 return SIO2_OK;
691 } // SAP_start
693 int gDmaParamsarray[17][3];
694 int gDmaParamsidx=0, gSAPSpecialCase=0;
695 // -----------------------------------------------------------------------------
697 Int SAP_issue (DEV2_Handle device)
698 {
699 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
700 DEV2_Frame *pFrame;
701 Int result;
702 SAP_EDMA_Param *pParam;
703 XDAS_UInt32 parentEdma;
705 if (device->mode == DEV2_OUTPUT)
706 Log_info1("SAP_issue for output device with pDevExt->errorState = 0x%x", pDevExt->errorState);
708 if ((device->mode == DEV2_OUTPUT) && (pDevExt->errorState >= PAF_SIO_ERROR_ERRBUF_XFER))
709 {
710 /*TRACE_TERSE((&TR_MOD, "SAP_issue.%d, errorState 0x%x (PAF_SIO_ERROR_ERRBUF_XFER = 0x%x)",
711 __LINE__, pDevExt->errorState, PAF_SIO_ERROR_ERRBUF_XFER));*/
712 Log_info3("SAP_issue.%d, PAF_SIO_ERROR_ERRBUF_XFER = 0x%x, mode = 0x%x)",
713 __LINE__, PAF_SIO_ERROR_ERRBUF_XFER, device->mode );
714 return SIO2_EBADIO;
715 }
717 if ((device->mode == DEV2_INPUT) && pDevExt->errorState)
718 {
719 Log_info1("SAP_issue: Input Error Trap, with errorState = 0x%x", pDevExt->errorState);
720 return SIO2_EBADIO;
721 }
723 // if not yet running then configure active xfer and start
724 if (pDevExt->runState == 0)
725 return (SAP_FTABLE_start(device));
727 // .........................................................................
728 // here if running
730 // disable device interrupts
731 // TODO: is there an API to just disable the IER bit for this tcc?
732 unsigned int key = Hwi_disable ();
733 /* determine parent EDMA
734 if no xfers in queue and we are running then must be in the
735 error state so link to active channel otherwise link to last
736 transfer queued.
737 */
739 /* here we assume after Tx SIO_idle or overrun, the user
740 will issue, at least, back-to-back issue requests so
741 there should be no problem here.
742 */
743 if ((pDevExt->numQueued <= 1) && (pDevExt->errorState != 2))
744 parentEdma = pDevExt->activeEdma;
745 else {
746 // if here then xferQue has more than one element so ok to use tail
747 // last scheduled transfer must be queue->prev
748 DEV2_Frame *tail = (DEV2_Frame *) Queue_prev ((Queue_Elem *)&pDevExt->xferQue);
749 parentEdma = ((SAP_EDMA_Param *) tail->misc)->hEdmaParam;
750 }
752 //if (device->mode == DEV2_OUTPUT)
753 Log_info2("SAP_issue: Determined Parent = 0x%x for device = 0x%x", parentEdma, device->mode );
755 // get frame and parameter table to use; ints off => non-atomic OK
756 // dont need to check for empty queues since were here then todevice
757 // must have a frame placed there by the SIO_issue layer.
758 // paramQue must be valid since it is accessed the same as todevice.
759 // (indirectly -- isr places used items onto paramQue and fromdevice que
760 // at the same time)
761 // set misc argument to pParam so get enqueue later
762 //pFrame = (DEV2_Frame *) Queue_dequeue (device->todevice);
763 pFrame = Queue_dequeue (device->todevice);
764 pParam = (SAP_EDMA_Param *) Queue_dequeue (Queue_handle(&pDevExt->paramQue));
766 if (pParam->hEdmaParam == NULL)
767 Log_info1("SAP_issue: hEdma value is NULL for device = 0x%x", device->mode);
768 // set misc argument to pParam so get enqueue later
769 pFrame->misc = (Arg) pParam;
771 // place on holder queue, ints off => non-atomic OK
772 Queue_enqueue (Queue_handle(&pDevExt->xferQue), (Queue_Elem *) pFrame);
773 if (pFrame->addr) {
774 if (device->mode == DEV2_INPUT)
775 Cache_inv (pFrame->addr, pFrame->size, Cache_Type_ALL, TRUE);
776 else
777 Cache_wbInv (pFrame->addr, pFrame->size, Cache_Type_ALL, TRUE);
778 }
780 // increment count
781 pDevExt->numQueued += 1;
783 result = SAP_EDMA_setupXfer (device, pParam->hEdmaParam, parentEdma, pDevExt->errorEdma, pFrame);
784 if (device->mode == DEV2_OUTPUT)
785 {
786 Log_info4("SAP_issue.%d, EDMA_setupXfer: Target EDMA: 0x%x, Parent Edma: 0x%x Error Edma: 0x%x",
787 __LINE__, pParam->hEdmaParam, parentEdma, pDevExt->errorEdma);
788 }
791 /*if ((device->mode != DEV2_INPUT) && (gDmaParamsidx <=16))
792 {
793 gDmaParamsarray[gDmaParamsidx][0] = pParam->hEdma;
794 gDmaParamsarray[gDmaParamsidx][1] = parentEdma;
795 gDmaParamsarray[gDmaParamsidx++][2] = gisrOutput;
796 } */
798 if ((pDevExt->errorState == PAF_SIO_ERROR_IDLE_STAGE1) && (device->mode == DEV2_OUTPUT))
799 pDevExt->errorState = PAF_SIO_ERROR_NONE;
801 pDevExt->shutDown = 0;
803 //if (device->mode == DEV2_OUTPUT)
804 //SAP_EDMA_dumpParams(1);
806 // special case enables when not yet started
807 if (pDevExt->runState == 0) {
808 gSAPSpecialCase++;
809 result = SAP_FTABLE_start (device);
810 if (result) {
811 //SAP_DMA_FTABLE_unlock (device);
812 Hwi_restore (key);
813 return result;
814 }
815 }
816 Hwi_restore (key); //DJDBG
818 return result;
819 } // SAP_issue
821 // -----------------------------------------------------------------------------
823 void swapHdmi(Ptr Input, int size)
824 {
826 MdInt L0, L1, L2, L3, R0, R1, R2, R3 = 0;
827 MdInt *p1, *p2;
828 int i=0;
830 for (i=0; i< size; i+=16)
831 {
832 p1 = (MdInt *)&Input[i];
833 p2 = p1;
835 L0 = *p1++;
836 L1 = *p1++;
837 L2 = *p1++;
838 L3 = *p1++;
839 R0 = *p1++;
840 R1 = *p1++;
841 R2 = *p1++;
842 R3 = *p1++;
844 *p2++ = L0;
845 *p2++ = R0;
846 *p2++ = L1;
847 *p2++ = R1;
848 *p2++ = L2;
849 *p2++ = R2;
850 *p2++ = L3;
851 *p2++ = R3;
853 }
855 Log_info3("SAP: Exiting swapHdmi with Frame->Addr: 0x%x, p1->addr: 0x%x, p2->addr: 0x%x ", (xdc_IArg)Input, p1, p2);
857 return;
858 }
860 Int SAP_reclaim (DEV2_Handle device)
861 {
862 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)(device->object);
863 #ifdef SAP_CACHE_SUPPORT
864 DEV2_Frame *pFrame;
865 #endif
867 //TRACE_GEN((&TR_MOD, "SAP_reclaim.%d (0x%x)", __LINE__, device));
868 if (device->mode == DEV2_OUTPUT)
869 Log_info2("SAP_reclaim for output device with pDevExt->errorState = 0x%x & runState: 0x%x", pDevExt->errorState, pDevExt->runState);
870 // must be running and error free
871 if ((!pDevExt->runState) || (pDevExt->errorState))
872 {
873 Log_info3("SAP_reclaim.%d, not runState: 0x%x, mode = 0x%x", __LINE__, pDevExt->errorState, device->mode);
874 return SIO2_EBADIO;
875 }
877 // idle if necessary
878 if (pDevExt->errorState == PAF_SIO_ERROR_FATAL) {
879 Log_info1("SAP_reclaim: PAF_SIO_ERROR_FATAL, Before Idle for device 0x%x ", device->mode);
880 DEV2_idle (device, 1);
881 return SIO2_EBADIO;
882 }
884 Log_info1("SAP_reclaim: Before SEM Pend for mode: 0x%x", device->mode);
886 // wait for ISR to signal block completion
887 //TRACE_VERBOSE((&TR_MOD, "SAP_reclaim.%d wait for ISR to signal block completion", __LINE__));
888 if (!Semaphore_pend(pDevExt->sync, device->timeout))
889 {
890 Log_info0("SAP_reclaim, SYS_ETIMEOUT");
891 return SIO2_ETIMEOUT;
892 }
893 Log_info1("SAP_reclaim: After SEM Pend for mode: 0x%x", device->mode);
895 #if 1
896 // return error (owner must idle)
897 if (pDevExt->errorState == PAF_SIO_ERROR_FATAL)
898 {
899 DEV2_idle (device, 1);
900 Log_info2("SAP_reclaim.%d, PAF_SIO_ERROR_FATAL: 0x%x", __LINE__, pDevExt->errorState);
901 return PAF_SIO_ERROR_FATAL;
902 }
903 #endif
905 #ifdef SAP_CACHE_SUPPORT
906 // invalidate CACHE region if input -- use clean since
907 // Dont clean if was for fill.
908 // since pend returned we know that head of fromdevice is valid
909 pFrame = Queue_head (device->fromdevice);
910 Log_info2("SAP: Inside SAP_Reclaim with From Device Frame->Addr: 0x%x and Frame->Size: %d", pFrame->addr, pFrame->size);
911 if ((device->mode == DEV2_INPUT) && (pFrame->addr != NULL))
912 {
913 if(pDevExt->edmaWordSize == 2 && pDevExt->numSers == 4)
914 {
915 Cache_inv (pFrame->addr, pFrame->size, Cache_Type_ALL, 0);
916 Cache_wait();
918 // max HWI disable duration ~1ms observed
919 //unsigned int key = Hwi_disable (); // GJ: Revisit, along with other context protections here.
920 swapHdmi(pFrame->addr, pFrame->size);
921 //Hwi_restore(key);
923 Cache_wb (pFrame->addr, pFrame->size, Cache_Type_ALL, 0);
924 Cache_wait();
925 }
926 }
928 #endif
929 /*if ((device->mode == DEV2_OUTPUT) && (pFrame->addr == NULL))
930 SW_BREAKPOINT; */
932 Log_info1("SAP_reclaim: Exiting with SIO2_OK for device 0x%x ", device->mode);
933 //TRACE_VERBOSE((&TR_MOD, "SAP_reclaim.%d, exit SIO2_OK", __LINE__));
934 return SIO2_OK;
935 } // SAP_reclaim
938 // -----------------------------------------------------------------------------
940 Int SAP_open (DEV2_Handle device, String name)
941 {
942 SAP_DeviceExtension *pDevExt;
943 DEV2_Device *entry;
944 Int oldMask, result;
945 Error_Block eb;
946 //TRACE_GEN((&TR_MOD, "SAP_open.%d (0x%x)", __LINE__, device));
948 // check SIO mode
949 if ((device->mode != DEV2_INPUT) && (device->mode != DEV2_OUTPUT))
950 return SIO2_EMODE;
952 // allocate memory for device extension
953 device->object = NULL;
954 pDevExt = (SAP_DeviceExtension *) Memory_alloc (device->bufSeg, (sizeof(SAP_DeviceExtension)+3)/4*4, 4, &eb);
955 if (pDevExt == NULL)
956 {
957 printf("%s.%d: MEM_alloc failed.\n", __FUNCTION__, __LINE__);
958 //TRACE_TERSE((&TR_MOD, "%s.%d: MEM_alloc failed.\n", __FUNCTION__, __LINE__));
959 asm( " SWBP 0" ); // SW Breakpoint
960 return SIO2_EALLOC;
961 }
962 device->object = (Ptr)pDevExt;
964 // inits
965 pDevExt->device = device;
966 pDevExt->sync = NULL;
967 pDevExt->pParams = NULL;
968 pDevExt->runState = 0; // not yet started
969 pDevExt->errorState = PAF_SIO_ERROR_NONE;
970 pDevExt->shutDown = 1;
971 pDevExt->numQueued = 0;
972 pDevExt->activeEdma = EDMA_HINV;
973 pDevExt->errorEdma = EDMA_HINV;
974 pDevExt->firstTCC = 0;
975 pDevExt->optLevel = 0;
976 pDevExt->numParamSetup = 0;
977 pDevExt->numEdmaParams = EDMA_NUM_PARAMS; // We need more than 4 spare params to handle the immediate transition from Unknown
978 // to a Known program. Cheap resource to spend.
980 // use dev match to fetch function table pointer for SAP
981 DEV2_match(SAP_NAME, &entry);
982 if (entry == NULL) {
983 Log_error1("SAP", SIO2_ENODEV);
984 return SIO2_ENODEV;
985 }
986 pDevExt->pFxns = (SAP_Fxns *) entry->fxns;
988 // create semaphore for device
989 pDevExt->sync = Semaphore_create (0, NULL, NULL);
990 if (pDevExt->sync == NULL)
991 {
992 //TRACE_TERSE((&TR_MOD, "%s.%d: create semaphore for device failed.\n", __FUNCTION__, __LINE__));
993 return SIO2_EALLOC;
994 }
996 // queue inits
997 Queue_construct (&pDevExt->xferQue, NULL);
998 Queue_construct (&pDevExt->paramQue, NULL);
1000 // update driver global (need to protect context)
1001 if (sapDrv.numDevices >= MAX_SAP_DEVICES)
1002 {
1003 /*TRACE_TERSE((&TR_MOD, "%s.%d: add device failure: no. of devices = %d; need to increase MAX_SAP_DEVICES.\n",
1004 __FUNCTION__, __LINE__, dapDrv.numDevices));*/
1005 SW_BREAKPOINT;
1006 }
1007 oldMask = Hwi_disable ();
1008 sapDrv.device[sapDrv.numDevices] = device;
1009 pDevExt->deviceNum = sapDrv.numDevices++;
1010 Hwi_restore (oldMask);
1012 // PORT init
1013 result = SAP_PORT_FTABLE_open (device);
1014 if (result)
1015 {
1016 //TRACE_TERSE((&TR_MOD, "%s.%d: SAP_PORT_FTABLE_open returned %d.\n", __FUNCTION__, __LINE__, result));
1017 return result;
1018 }
1020 return result;
1021 } // SAP_open
1023 // -----------------------------------------------------------------------------
1025 Int SAP_config (DEV2_Handle device, const SAP_Params *pParams)
1026 {
1027 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
1028 Int result, Que_num, i;
1029 EDMA3_DRV_Result edmaResult;
1030 Uint32 reqTcc;
1031 EDMA3_DRV_Handle hEdma;
1032 Log_info2("SAP_config.%d (0x%x)", __LINE__, device);
1034 // cannot configure if transfer started
1035 if (pDevExt->runState == 1)
1036 return SIO2_EBADIO;
1038 // save pointer to config structure in device extension. here so that
1039 // forthcoming functions can use/modify config structure.
1040 pDevExt->pParams = pParams;
1041 pDevExt->edmaWordSize = pParams->sio.wordSize;
1043 // allocate Port resources.
1044 // This must come before DMA configuration
1045 result = SAP_PORT_FTABLE_alloc (device);
1046 if (result)
1047 {
1048 Log_info3("%s.%d: SAP_PORT_FTABLE_alloc returned %d.\n", (xdc_IArg) __FUNCTION__, __LINE__, result);
1049 return result;
1050 }
1052 // .............................................................................
1053 // EDMA configuration
1055 // DA10x McASP0 Specific
1056 if (pParams->sio.moduleNum == 0)
1057 {
1058 hEdma = hEdma0;
1059 if (device->mode == DEV2_INPUT)
1060 {
1061 Que_num = 0;
1062 pDevExt->activeEdma = CSL_EDMACC_0_McASP_0_REVT;
1063 }
1064 else
1065 {
1066 Que_num = 0;
1067 pDevExt->activeEdma = CSL_EDMACC_0_McASP_0_XEVT;
1068 }
1069 }
1070 // DA10x McASP1 Specific
1071 else if (pParams->sio.moduleNum == 1)
1072 {
1073 hEdma = hEdma1;
1074 if (device->mode == DEV2_INPUT)
1075 {
1076 Que_num = 0;
1077 pDevExt->activeEdma = CSL_EDMACC_1_McASP_1_REVT;
1078 }
1079 else
1080 {
1081 Que_num = 0;
1082 pDevExt->activeEdma = CSL_EDMACC_1_McASP_1_XEVT;
1083 }
1084 }
1085 // DA10x McASP2 Specific
1086 else if (pParams->sio.moduleNum == 2)
1087 {
1088 hEdma = hEdma1;
1089 if (device->mode == DEV2_INPUT)
1090 {
1091 Que_num = 0;
1092 pDevExt->activeEdma = CSL_EDMACC_1_McASP_2_REVT;
1093 }
1094 else
1095 {
1096 Que_num = 0;
1097 pDevExt->activeEdma = CSL_EDMACC_1_McASP_2_XEVT;
1098 }
1099 }
1102 for (i=0; i < pDevExt->numEdmaParams; i++) {
1104 reqTcc = EDMA3_DRV_TCC_ANY;
1105 pDevExt->edmaParams[i].hEdmaParam = EDMA3_DRV_LINK_CHANNEL;
1106 edmaResult = EDMA3_DRV_requestChannel (
1107 hEdma,
1108 &pDevExt->edmaParams[i].hEdmaParam,
1109 &reqTcc,
1110 (EDMA3_RM_EventQueue) Que_num,
1111 SAP_isrCallback,
1112 (void *) device);
1114 if (edmaResult != EDMA3_DRV_SOK)
1115 return SIO2_EALLOC;
1117 //not running => can use non-atomic functions
1118 Queue_enqueue (Queue_handle(&pDevExt->paramQue), (Queue_Elem *)&pDevExt->edmaParams[i]);
1120 }
1122 reqTcc = EDMA3_DRV_TCC_ANY;
1123 pDevExt->errorEdma = EDMA3_DRV_LINK_CHANNEL;
1124 edmaResult = EDMA3_DRV_requestChannel (
1125 hEdma,
1126 &pDevExt->errorEdma,
1127 &reqTcc,
1128 (EDMA3_RM_EventQueue)Que_num,
1129 SAP_isrCallback,
1130 (void *) device);
1131 if (edmaResult != EDMA3_DRV_SOK)
1132 return SIO2_EALLOC;
1134 // allocate edma channel -- also disable and clear the interrupt
1137 pDevExt->firstTCC = pDevExt->activeEdma ;
1138 edmaResult = EDMA3_DRV_requestChannel (
1139 hEdma,
1140 &pDevExt->activeEdma,
1141 &pDevExt->firstTCC,
1142 (EDMA3_RM_EventQueue) 0,
1143 SAP_isrCallback,
1144 (void *) device);
1145 if (edmaResult != EDMA3_DRV_SOK)
1146 {
1147 Log_info3("%s.%d: SAP_DMA_FTABLE_alloc returned %d.\n", (xdc_IArg)__FUNCTION__, __LINE__, edmaResult);
1148 return SIO2_EALLOC;
1149 }
1151 // Configure error transfer
1152 // make cnt same as # of channels in order to maintain alignment
1153 // and the error transfer small so that we never have to wait
1154 // long for it to complete and trigger a linked transfer. This is
1155 // important for establishing output timing when we are idling with
1156 // clocks still running. Is fine for Rx as well.
1157 result = SAP_DMA_FTABLE_setupParam (device, pDevExt->errorEdma, pDevExt->errorEdma, NULL, pDevExt->edmaWordSize * pDevExt->numSers);
1159 Log_info3("%s.%d: Exiting SAP_alloc for %d.\n", (xdc_IArg)__FUNCTION__, __LINE__, pDevExt->activeEdma);
1161 return SIO2_OK;
1162 } // SAP_config
1164 // -----------------------------------------------------------------------------
1166 Int SAP_shutdown (DEV2_Handle device)
1167 {
1168 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)(device->object);
1169 SIO2_Handle stream = (SIO2_Handle) device;
1170 DEV2_Frame *pFrame;
1171 Int i;
1172 EDMA3_DRV_Handle hEdma;
1173 //TRACE_GEN((&TR_MOD, "SAP_shutdown.%d (0x%x)", __LINE__, device));
1175 if (pDevExt->shutDown)
1176 return SIO2_EBADIO;
1178 if (pDevExt->pParams == NULL)
1179 return SIO2_EINVAL;
1181 if (pDevExt->pParams->sio.moduleNum == 0)
1182 hEdma = hEdma0;
1183 else if (pDevExt->pParams->sio.moduleNum == 1 || pDevExt->pParams->sio.moduleNum == 2)
1184 hEdma = hEdma1;
1185 if (pDevExt->activeEdma != EDMA_HINV)
1186 EDMA3_DRV_disableTransfer (hEdma, pDevExt->activeEdma, EDMA3_DRV_TRIG_MODE_EVENT);
1188 // reset queues
1189 while (!Queue_empty(device->todevice)) {
1190 // place oustanding requests onto holding queue
1191 pFrame = (DEV2_Frame *) Queue_dequeue (device->todevice);
1192 Queue_enqueue (Queue_handle(&pDevExt->xferQue), (Queue_Elem *) pFrame);
1193 }
1195 while (!Queue_empty(Queue_handle(&pDevExt->xferQue))) {
1196 // pull frame from holding queue and place on user queue
1197 pFrame = (DEV2_Frame *) Queue_dequeue (Queue_handle(&pDevExt->xferQue));
1198 Queue_enqueue (device->fromdevice, (Queue_Elem *) pFrame);
1199 }
1202 while (!Queue_empty(Queue_handle(&pDevExt->paramQue)))
1203 Queue_dequeue (Queue_handle(&pDevExt->paramQue));
1205 // not running => can use non-atomic functions
1206 for (i=0; i < pDevExt->numEdmaParams; i++)
1207 Queue_enqueue (Queue_handle(&pDevExt->paramQue), (Queue_Elem *) &pDevExt->edmaParams[i]);
1209 // reset counter
1210 pDevExt->numQueued = 0;
1212 //DJDBG_SAP_EDMA_dumpParams(1);
1213 // make sure active is linked to error
1214 EDMA3_DRV_linkChannel (hEdma, pDevExt->activeEdma, pDevExt->errorEdma);
1216 // think this is better (from SIO_idle for standard model )
1217 // refill frame list -- so user needn't call reclaim, which may cause Rx underrun.
1218 while (!Queue_empty(device->fromdevice)) {
1219 /* place oustanding requests onto holding queue */
1220 pFrame = (DEV2_Frame *) Queue_dequeue (device->fromdevice);
1221 Queue_enqueue (Queue_handle(&stream->framelist), (Queue_Elem *) pFrame);
1222 }
1223 Semaphore_reset (pDevExt->sync, 0);
1225 pDevExt->shutDown = 1;
1226 pDevExt->numParamSetup = 0;
1228 /*result = SAP_DMA_FTABLE_unlock (device);
1229 if (result)
1230 {
1231 //TRACE_TERSE((&TR_MOD, "%s.%d: SAP_DMA_FTABLE_unlock returned %d.\n", __FUNCTION__, __LINE__, result));
1232 return result;
1233 } */
1235 return SIO2_OK;
1236 } // SAP_shutdown
1238 // -----------------------------------------------------------------------------
1239 int gSapWatchDogThrottle = 0; //DJDBG
1240 int gSapWatchDogIn =0;
1241 int gSapWatchDogOut = 0;
1242 int gSapWatchDogInSemPost = 0;
1243 int gSapWatchDogOutSemPost = 0;
1245 Void SAP_watchDog (Void)
1246 {
1247 DEV2_Handle device;
1248 SAP_DeviceExtension *pDevExt;
1249 int i, oldMask, result;
1251 //Log_info2("SAP_watchDog.%d (0x%x)", __LINE__, device);
1253 // do nothing if SAP_init not yet called
1254 if (!SAP_initialized)
1255 {
1256 Log_info2("%s.%d: SAP_init not yet called.\n", __FUNCTION__, __LINE__);
1257 return;
1258 }
1260 // protect context
1261 Task_disable (); // needed since we may call SEM_post
1262 //oldMask = Hwi_disable ();
1265 //Log_info3("%s.%d: devices loop, numDevices = %d", __FUNCTION__, __LINE__, sapDrv.numDevices);
1267 for (i=0; i < sapDrv.numDevices; i++) {
1268 device = sapDrv.device[i];
1270 //Log_info3("%s.%d, devices loop start, device = 0x%x", __FUNCTION__, __LINE__, device);
1272 pDevExt = (SAP_DeviceExtension *) device->object;
1274 // do nothing if not running
1275 if (!pDevExt->runState)
1276 continue;
1278 // call board specific watchdog
1279 // TODO: handle return value
1280 SIO2_ctrl (device, PAF_SIO_CONTROL_WATCHDOG, NULL);
1282 // if port layer returns error then must need to clean up
1283 result = SAP_PORT_FTABLE_watchDog (device);
1284 if (result) {
1285 // set errorState which will force owner thread
1286 // to clean up via SIO_idle()
1287 pDevExt->errorState = PAF_SIO_ERROR_FATAL;
1288 if(device->mode == DEV2_INPUT)
1289 gSapWatchDogIn++;
1290 else
1291 {
1292 //if (gSapWatchDogOut == 0)
1293 //SAP_EDMA_dumpParams(1);
1294 gSapWatchDogOut++;
1295 }
1297 //TRACE_TERSE((&TR_MOD, "SAP_watchDog.%d, PAF_SIO_ERROR_FATAL: 0x%x", __LINE__, pDevExt->errorState));
1298 /* if(gSapWatchDogThrottle == 0) //DJDBG
1299 {
1300 Log_info3("SAP_watchDog.%d (0x%x); THROTTLED result = 0x%x", __LINE__, device, result);
1301 }
1302 gSapWatchDogThrottle ++;
1303 if(gSapWatchDogThrottle > 10) gSapWatchDogThrottle = 0; */
1304 // if outstanding pend then post to free owner thead
1305 if (!Semaphore_pend(pDevExt->sync, 0))
1306 {
1307 if(device->mode == DEV2_INPUT)
1308 gSapWatchDogInSemPost++;
1309 else
1310 gSapWatchDogOutSemPost++;
1311 Semaphore_post (pDevExt->sync);
1312 }
1313 }
1314 }
1317 // renable interrupts and task manager.
1318 // If we posted to the semaphore then the TSK_enable call will lead to
1319 // an immediate task switch to the associated audio thread.
1320 //Hwi_restore (oldMask);
1321 Task_enable ();
1323 } // SAP_watchDog
1325 // -----------------------------------------------------------------------------
1326 // Assumes that EDMA3 dispatcher handles TCC clearing.
1328 void SAP_isrCallback (Uint32 tcc, EDMA3_RM_TccStatus status, Ptr context)
1329 {
1330 DEV2_Handle device;
1331 SAP_DeviceExtension *pDevExt;
1332 DEV2_Frame *pFrame;
1333 unsigned int opt;
1334 EDMA3_DRV_Handle hEdma;
1336 // could be here after Tx idle/overrun and this is the interrupt
1337 // for the last occuring error transfer so there is no transfer
1338 // to release, we just clear the int and exit.
1340 device = (DEV2_Handle) context;
1341 pDevExt = (SAP_DeviceExtension *)(device->object);
1342 //if (pDevExt->pParams == NULL)
1343 //return SIO2_EINVAL;
1345 if (pDevExt->pParams->sio.moduleNum == 0)
1346 hEdma = hEdma0;
1347 else if (pDevExt->pParams->sio.moduleNum == 1 || pDevExt->pParams->sio.moduleNum == 2)
1348 hEdma = hEdma1;
1350 if ((pDevExt->runState == 1) && !pDevExt->errorState) {
1351 // if here then an interrupt occured due to errorEdma or valid
1352 // transfer, we assume the xfer is long enough so it will not complete
1353 // before we are finished here.
1355 // if last transfer was valid then complete it
1356 if (!Queue_empty(Queue_handle(&pDevExt->xferQue))) {
1358 // pull frame from holding queue
1359 pFrame = (DEV2_Frame *) Queue_dequeue (Queue_handle(&pDevExt->xferQue));
1361 // if used param entry then return it to queue
1362 if (pFrame->misc != NULL)
1363 {
1364 Queue_enqueue (Queue_handle(&pDevExt->paramQue), (Ptr) pFrame->misc);
1365 if (device->mode == 1)
1366 gisrOutput+=100;
1367 }
1369 // decrement count
1370 pDevExt->numQueued -= 1;
1371 //gIsrCnt++;
1372 if (device->mode == 1)
1373 {
1374 gIsrOutputCnt++;
1375 //Log_info1("SAP isrCallback for 0x%x", pDevExt->activeEdma);
1376 }
1377 else
1378 gIsrInputCnt++;
1379 // place frame onto user queue and signal user thread
1380 Queue_enqueue (device->fromdevice, (Ptr) pFrame);
1382 //Log_info2("Before SEM_post for device: 0x%x gIsrOutput: %d", device->mode, gisrOutput);
1383 // signal user thread
1384 Semaphore_post (pDevExt->sync);
1385 #if 0
1386 if(gIsrCnt > 10) { //DJDBG
1387 Log_info1("SAP isrCallback enough interrupts! %d", gIsrCnt);
1389 }
1390 #endif
1391 }
1392 else
1393 gIsrElseCnt++;
1395 // determine if currently transferring buffer is valid based on interrupt enable bit
1396 // only valid transfers will generate interrupts
1397 EDMA3_DRV_getPaRAMEntry (hEdma, pDevExt->activeEdma, EDMA3_DRV_PARAM_ENTRY_OPT, &opt);
1399 if (!(opt & EDMA3_DRV_OPT_TCINTEN_SET_MASK (1)))
1400 {
1401 if (device->mode == 1)
1402 gIsrOutErrCnt++;
1403 else
1404 gIsrInErrCnt++;
1405 pDevExt->errorState = PAF_SIO_ERROR_ERRBUF_XFER;
1406 }
1408 } // runState
1409 else
1410 {
1411 if (pDevExt->runState != 1)
1412 gIsrRunCnt++;
1413 else
1414 gIsrNotRunCnt++;
1415 }
1417 return;
1418 } //SAP_isrCallback
1420 // -----------------------------------------------------------------------------
1422 Int SAP_EDMA_setupXfer (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32 parentEdma, XDAS_UInt32 childEdma, DEV2_Frame *pFrame)
1423 {
1424 EDMA3_DRV_Handle hEdma;
1425 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
1426 // int mcbspNum = pDevExt->pParams->sio.moduleNum;
1428 if (pDevExt->pParams == NULL)
1429 return SIO2_EINVAL;
1431 if (pDevExt->pParams->sio.moduleNum == 0)
1432 hEdma = hEdma0;
1433 else if (pDevExt->pParams->sio.moduleNum == 1 || pDevExt->pParams->sio.moduleNum == 2)
1434 hEdma = hEdma1;
1436 // TODO: shouldn't this just be tcc interrupt disable?
1437 // at least until linkage phase...
1438 unsigned int key = Hwi_disable (); //DJDBG
1440 if(targetEdma == NULL)
1441 {
1442 Log_info0("targetEdma is NULL");
1443 }
1444 // configure transfer
1445 if(pFrame->addr == NULL) //DJDBG
1446 {
1447 Log_info0("pFrame has NULL address?");
1448 }
1449 SAP_DMA_FTABLE_setupParam (device, targetEdma, childEdma, (XDAS_UInt32) pFrame->addr, pFrame->size);
1451 if (device->mode == DEV2_OUTPUT)
1452 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);
1454 if (parentEdma != EDMA_HINV)
1455 EDMA3_DRV_linkChannel (hEdma, parentEdma, targetEdma);
1457 if (device->mode == DEV2_OUTPUT)
1458 Log_info3("SAP: Inside SAP_EDMA_setupXfer linked targetEdma = 0x%x with parentEdma=0x%x on Edma=0x%x", targetEdma, parentEdma, hEdma);
1460 Hwi_restore (key); //DJDBG
1462 return SIO2_OK;
1463 } // SAP_setupXfer
1465 // -----------------------------------------------------------------------------
1466 // Configure EDMA3 parameter entry
1468 Int SAP_EDMA_setupParam (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32 childEdma, XDAS_UInt32 addr, XDAS_UInt32 size)
1469 {
1470 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
1471 EDMA3_DRV_Handle hEdma;
1472 EDMA3_DRV_PaRAMRegs edmaConfig;
1474 if (pDevExt->pParams == NULL)
1475 return SIO2_EINVAL;
1477 if (pDevExt->pParams->sio.moduleNum == 0)
1478 hEdma = hEdma0;
1479 else if (pDevExt->pParams->sio.moduleNum == 1 || pDevExt->pParams->sio.moduleNum == 2)
1480 hEdma = hEdma1;
1481 MCASP_Handle hPort = sapMcaspDrv.hPort[pDevExt->pParams->sio.moduleNum];
1482 // volatile Uint32 *base = (volatile Uint32 *)(hPort->baseAddr);
1484 //Log_info3("%s.%d: Entered SAP_EDMA_setupParam for Target: 0x%x.\n", (xdc_IArg)__FUNCTION__, __LINE__, targetEdma);
1486 // Init opt parameter to 0 which, without being overriden, configures as:
1487 // A synchronized transfer (no FIFO mode on src or dst)
1488 // no chaining or intermediate interrupts
1489 // param is not static
1490 // normal completion
1491 // don't generate an interrupt (overriden below for regular xfers)
1492 edmaConfig.opt = 0;
1494 // not transferring blocks so c index is 0
1495 edmaConfig.destCIdx = 0;
1496 edmaConfig.srcCIdx = 0;
1498 edmaConfig.opt |= EDMA3_DRV_OPT_SYNCDIM_SET_MASK (EDMA3_DRV_SYNC_AB); //DJDBG!
1499 if (device->mode == DEV2_OUTPUT) {
1500 //edmaConfig.opt |= EDMA3_DRV_OPT_DAM_SET_MASK (EDMA3_DRV_ADDR_MODE_FIFO); //DJDBG!!!
1501 edmaConfig.opt |= 2;
1502 }
1503 else {
1504 //edmaConfig.opt |= EDMA3_DRV_OPT_SAM_SET_MASK (EDMA3_DRV_ADDR_MODE_FIFO); //DJDBG!!!
1505 edmaConfig.opt |= 1;
1506 }
1508 // if regular transfer then enable interrupt with tcc code
1509 if (targetEdma != pDevExt->errorEdma) {
1510 edmaConfig.opt |= EDMA3_DRV_OPT_SYNCDIM_SET_MASK (EDMA3_DRV_SYNC_AB);
1511 edmaConfig.opt |= EDMA3_DRV_OPT_TCINTEN_SET_MASK (1);
1512 edmaConfig.opt |= EDMA3_DRV_OPT_TCC_SET_MASK (pDevExt->firstTCC);
1513 }
1516 edmaConfig.aCnt = 4;
1517 edmaConfig.bCnt = pDevExt->numSers;
1518 edmaConfig.cCnt = size/(edmaConfig.aCnt * edmaConfig.bCnt);
1519 edmaConfig.bCntReload = edmaConfig.bCnt;
1522 // handle direction specific requirements
1523 if (device->mode == DEV2_INPUT) {
1524 edmaConfig.srcBIdx = 0;
1525 edmaConfig.srcAddr = (unsigned int) (hPort->rbufAddr);
1527 if (addr) {
1528 edmaConfig.destBIdx = pDevExt->edmaWordSize;
1529 edmaConfig.destAddr = addr;
1530 edmaConfig.destCIdx = pDevExt->edmaWordSize * pDevExt->numSers ;
1531 if(pDevExt->edmaWordSize == 2)
1532 edmaConfig.cCnt= (size)/((edmaConfig.aCnt * edmaConfig.bCnt)/2);
1533 }
1534 else {
1535 //if(pDevExt->edmaWordSize == 2)
1536 //edmaConfig.srcAddr= (unsigned int)edmaConfig.srcAddr+ 2;
1537 edmaConfig.destBIdx = 0;
1538 edmaConfig.destAddr = (unsigned int) &sap_OVER_4LANE;
1539 edmaConfig.cCnt = 1;
1540 }
1541 }
1542 else {
1543 edmaConfig.destBIdx = 0;
1544 edmaConfig.srcBIdx = pDevExt->edmaWordSize;
1545 edmaConfig.destAddr = (unsigned int) (hPort->xbufAddr);
1546 if (addr) {
1547 edmaConfig.srcCIdx = pDevExt->edmaWordSize * pDevExt->numSers ;
1548 edmaConfig.srcAddr = addr;
1549 //Edma3_CacheFlush ((unsigned int) addr, (size+3)/4);
1550 }
1551 else {
1552 edmaConfig.srcBIdx = 0;
1553 edmaConfig.srcAddr = (unsigned int) &sap_UNDER[0];
1554 #if 0
1555 //edmaConfig.cCnt = (SAP_UNDER_LEN * sizeof(int))/(edmaConfig.aCnt * edmaConfig.bCnt); //DJDBG
1556 edmaConfig.cCnt = SAP_UNDER_LEN; //DJDBG, if underrun have frame of silence
1557 #endif
1558 }
1559 }
1560 edmaConfig.srcAddr = (unsigned int) getGlobalAddr(edmaConfig.srcAddr);
1561 edmaConfig.destAddr = (unsigned int) getGlobalAddr(edmaConfig.destAddr);
1563 EDMA3_DRV_setPaRAM (hEdma, targetEdma, &edmaConfig);
1565 // link child xfer
1566 if (childEdma != EDMA_HINV)
1567 EDMA3_DRV_linkChannel (hEdma, targetEdma, childEdma);
1569 if (device->mode == DEV2_OUTPUT) {
1570 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);
1571 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 );
1572 }
1574 return SIO2_OK;
1575 } //SAP_setupParam