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
70 #include "sap_mcasp.h"
71 #include <pafsio.h>
73 // This works to set a breakpoint
74 #define SW_BREAKPOINT asm( " SWBP 0" );
75 /* Software Breakpoint to Code Composer */
76 // SW_BREAKPOINT;
78 // global allocated in bios_edma3_drv_sample_init.c
79 extern EDMA3_DRV_Handle hEdma0;
80 extern EDMA3_DRV_Handle hEdma1;
82 int gStartError;
83 int gIsrInputCnt;
84 int gIsrOutputCnt;
85 int gIsrElseCnt;
86 int gIsrInErrCnt;
87 int gIsrOutErrCnt;
88 int gIsrRunCnt;
89 int gIsrNotRunCnt;
90 int gisrOutput;
91 int gSAPResetIn;
92 int gSAPResetOut;
94 typedef xdc_Short MdInt;
96 void swapHdmi(Ptr, int);
98 #define SAP_UNDER_LEN 8
100 int sap_UNDER[SAP_UNDER_LEN]; // used for underrun
101 int sap_OVER_1LANE = 0; // used for overrun
102 int sap_OVER_4LANE[4] = {0,0,0,0}; // used for overrun
104 #ifdef DEBUG
105 void SAP_EDMA_dumpParams(int tag_place)
106 {
107 //unsigned int *ptrPARAM_BASE = (unsigned int *)0x02704000;
108 unsigned int *ptrPARAM0x18 = (unsigned int *)0x02704300; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[24]
109 //unsigned int *ptrPARAM0x19 = (unsigned int *)0x02704320; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[24]
110 //unsigned int *ptrPARAM0x41 = (unsigned int *)0x027048A0; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[24]
111 //unsigned int *ptrPARAM0x42 = (unsigned int *)0x027048C0; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[24]
112 //unsigned int *ptrPARAM0x43 = (unsigned int *)0x027048E0; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[24]
113 //unsigned int *ptrPARAM0x48 = (unsigned int *)0x02704910; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[24]
114 unsigned int *ptrPARAM0x45 = (unsigned int *)0x027048A0; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[69]
115 unsigned int *ptrPARAM0x46 = (unsigned int *)0x027048C0; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[70]
116 unsigned int *ptrPARAM0x47 = (unsigned int *)0x027048E0; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[71]
117 unsigned int *ptrPARAM0x48 = (unsigned int *)0x02704900; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[72]
118 unsigned int *ptrPARAM0x49 = (unsigned int *)0x02704920; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[73]
119 unsigned int *ptrPARAM0x4A = (unsigned int *)0x02704940; // ((*((EDMA3_CCRL_Regs *) 0x02700000)).PARAMENTRY)[74]
121 //Log_info5("PARAM0x18a(%d): 0x%x 0x%x 0x%x 0x%x", tag_place, ptrPARAM0x18[0], ptrPARAM0x18[1], ptrPARAM0x18[2], ptrPARAM0x18[3]);
122 //Log_info5("PARAM0x18b(%d): 0x%x 0x%x 0x%x 0x%x", tag_place, ptrPARAM0x18[4], ptrPARAM0x18[5], ptrPARAM0x18[6], ptrPARAM0x18[7]);
124 /*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));
125 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]);
126 Log_info4("PARAM0x19b(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x19[5], ptrPARAM0x19[6], ptrPARAM0x19[7]);
128 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));
129 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]);
130 Log_info4("PARAM0x41b(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x41[5], ptrPARAM0x41[6], ptrPARAM0x41[7]);
132 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));
133 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]);
134 Log_info4("PARAM0x42b(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x42[5], ptrPARAM0x42[6], ptrPARAM0x42[7]);
136 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));
137 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]);
138 Log_info4("PARAM0x43b(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x43[5], ptrPARAM0x43[6], ptrPARAM0x43[7]);
140 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));
141 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]);
142 Log_info4("PARAM0x48b(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x48[5], ptrPARAM0x48[6], ptrPARAM0x48[7]);*/
144 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));
145 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]);
146 Log_info4("PARAM0x18c(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x18[5], ptrPARAM0x18[6], ptrPARAM0x18[7]);
148 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));
149 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]);
150 Log_info4("PARAM0x45c(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x45[5], ptrPARAM0x45[6], ptrPARAM0x45[7]);
152 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));
153 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]);
154 Log_info4("PARAM0x46c(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x46[5], ptrPARAM0x46[6], ptrPARAM0x46[7]);
156 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));
157 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]);
158 Log_info4("PARAM0x47c(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x47[5], ptrPARAM0x47[6], ptrPARAM0x47[7]);
160 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));
161 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]);
162 Log_info4("PARAM0x48c(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x48[5], ptrPARAM0x48[6], ptrPARAM0x48[7]);
164 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));
165 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]);
166 Log_info4("PARAM0x49c(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x49[5], ptrPARAM0x49[6], ptrPARAM0x49[7]);
168 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));
169 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]);
170 Log_info4("PARAM0x4Ac(%d): LINK_BCNTRLD: 0x%08x, SRC_DST_CIDX: 0x%08x, CCNT: 0x%08x", tag_place, ptrPARAM0x4A[5], ptrPARAM0x4A[6], ptrPARAM0x4A[7]);
172 Log_info1("TCC0: ERR reg %x", *((unsigned int *)0x02760120)); //DJDBG
173 }
174 #endif
175 // .............................................................................
176 // notes:
177 // . add control function to PORT table
178 // . how to handle DMA/PORT specifics in parameter entries
179 // can assume numSers = numChans is general and can be applied by DMA
180 // same for wordSize?
181 // . why are two idle stages needed (seems like 1 is enough)?
183 // .............................................................................
184 // only one global variable, not static so that DMA and port functions
185 // can access. We cant just store the address in devExt since the ISR has
186 // no context.
188 SAP_DriverObject sapDrv;
190 // needed since SAP_watchDog is called before SAP_init
191 Int SAP_initialized = 0;
193 //Int SAP_close(DEV2_Handle);
194 Int SAP_ctrl(DEV2_Handle, Uns, Arg);
195 Int SAP_idle(DEV2_Handle, Bool);
196 Int SAP_issue(DEV2_Handle);
197 Int SAP_open(DEV2_Handle, String);
198 void SAP_isrCallback (Uint32 tcc, EDMA3_RM_TccStatus status, Ptr context);
199 //Bool SAP_ready(DEV2_Handle, SEM_Handle);
200 Int SAP_reclaim(DEV2_Handle);
201 Int SAP_shutdown(DEV2_Handle);
202 Int SAP_start(DEV2_Handle);
203 Int SAP_config(DEV2_Handle device, const SAP_Params *pParams);
204 Int SAP_EDMA_setupParam (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32 childEdma, XDAS_UInt32 addr, XDAS_UInt32 size);
205 Int SAP_EDMA_setupXfer (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32 parentEdma, XDAS_UInt32 childEdma, DEV2_Frame *pFrame);
207 // .............................................................................
209 // .............................................................................
211 SAP_DMA_Fxns SAP_EDMA_FXNS =
212 {
213 SAP_EDMA_setupParam,
214 SAP_EDMA_setupXfer,
215 };
218 SAP_Fxns SAP_FXNS =
219 {
220 NULL, //SAP_close, -- remove for IROM since not using
221 SAP_ctrl,
222 SAP_idle,
223 SAP_issue,
224 SAP_open,
225 NULL, //SAP_ready, -- remove for IROM since not using
226 SAP_reclaim,
227 SAP_shutdown,
228 SAP_start,
229 SAP_config,
231 #ifdef SAP_PORT_MCASP
232 (SAP_PORT_Fxns *) &SAP_MCASP_FXNS,
233 #endif
234 #ifdef SAP_DMA_EDMA
235 (SAP_DMA_Fxns *) &SAP_EDMA_FXNS,
236 #endif
237 };
239 // -----------------------------------------------------------------------------
240 // This function is not in the driver function table.
241 // Must be pointed at in GUI config tool.
242 //
243 Void SAP_init (Void)
244 {
245 DEV2_Device *entry;
246 SAP_Fxns *pFxns;
248 //TRACE_GEN((&TR_MOD, "SAP_init.%d", __LINE__));
250 // find function table pointer (used by SAP_XX_FTABLE_init macros)
251 DEV2_match(SAP_NAME, &entry);
252 if (entry == NULL) {
253 Log_error1 ("SAP", SIO2_ENODEV);
254 return;
255 }
256 pFxns = (SAP_Fxns *) entry->fxns;
258 //SAP_DMA_FTABLE_init ();
259 SAP_PORT_FTABLE_init ();
261 sapDrv.numDevices = 0;
262 SAP_initialized = 1;
264 return;
265 } // SAP_init
267 // -----------------------------------------------------------------------------
269 int gSapInput_ControlOpen = 0;
270 int gSapOutput_ControlOpen = 0;
272 int gSapInput_ControlClose = 0;
273 int gSapOutput_ControlClose = 0;
275 Int SAP_ctrl (DEV2_Handle device, Uns code, Arg arg)
276 {
277 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
278 const SAP_Params *pParams;
279 Int i, result = SIO2_OK;
280 EDMA3_DRV_Handle hEdma;
281 //TRACE_GEN((&TR_MOD, "SAP_ctrl.%d (0x%x) code = 0x%x", __LINE__, device, code));
283 switch (code) {
285 /* .......................................................................... */
287 case PAF_SIO_CONTROL_MUTE:
288 case PAF_SIO_CONTROL_UNMUTE:
289 pParams = pDevExt->pParams;
290 if (pParams == NULL)
291 return SIO2_OK;
293 if (pParams->sio.control != NULL)
294 result = pParams->sio.control (device, (const PAF_SIO_Params *)pParams, code, arg);
295 break;
297 /* .......................................................................... */
299 case PAF_SIO_CONTROL_OPEN:
300 if (pDevExt->runState)
301 return SIO2_EBUSY;
303 if (!( pParams = (const SAP_Params *) arg ))
304 return SIO2_OK;
306 if(device->mode == DEV2_OUTPUT)
307 gSapOutput_ControlOpen++;
308 else
309 gSapInput_ControlOpen++;
311 if (result = SAP_FTABLE_config (device, pParams))
312 return result;
314 if (pParams->sio.control && (result = pParams->sio.control (device, (const PAF_SIO_Params *)pParams, code, arg)))
315 return result;
317 break;
319 /* .......................................................................... */
321 case PAF_SIO_CONTROL_CLOSE:
322 if (pDevExt->runState)
323 return SIO2_EBUSY;
325 if (pDevExt->pParams == NULL)
326 return SIO2_EINVAL;
328 pParams = pDevExt->pParams;
330 if (pParams->sio.moduleNum == 0)
331 hEdma = hEdma0;
332 else if (pParams->sio.moduleNum == 1 || pParams->sio.moduleNum == 2)
333 hEdma = hEdma1;
335 if (pDevExt->activeEdma != EDMA_HINV) {
336 EDMA3_DRV_freeChannel (hEdma, pDevExt->activeEdma);
337 pDevExt->activeEdma = EDMA_HINV;
338 }
340 if(device->mode == DEV2_INPUT)
341 gSapInput_ControlClose++;
342 else
343 gSapOutput_ControlClose++;
345 for (i=0; i < pDevExt->numEdmaParams; i++) {
346 if (pDevExt->edmaParams[i].hEdmaParam != EDMA_HINV)
347 {
348 EDMA3_DRV_freeChannel (hEdma, pDevExt->edmaParams[i].hEdmaParam);
349 pDevExt->edmaParams[i].hEdmaParam = EDMA_HINV;
350 }
351 }
353 if (pDevExt->errorEdma != EDMA_HINV) {
354 EDMA3_DRV_freeChannel (hEdma, pDevExt->errorEdma);
355 pDevExt->errorEdma = EDMA_HINV;
356 }
358 if (!(pParams = pDevExt->pParams))
359 return SIO2_OK;
361 if (pParams->sio.control && (result = pParams->sio.control (device, (const PAF_SIO_Params *)pParams, code, arg)))
362 return result;
364 result = SAP_PORT_FTABLE_close (device);
365 if (result)
366 return result;
368 pDevExt->pParams = NULL;
369 break;
371 /* .......................................................................... */
373 case PAF_SIO_CONTROL_GET_WORDSIZE:
374 if (!arg)
375 return SIO2_EINVAL;
376 *((int *) arg) = pDevExt->edmaWordSize;
377 break;
379 case PAF_SIO_CONTROL_SET_WORDSIZE:
380 // defer to DMA processing
381 // currently only supported for input
382 if (device->mode != DEV2_INPUT)
383 return SIO2_EINVAL;
385 // can't be running
386 if (pDevExt->runState)
387 return SIO2_EBUSY;
389 // driver only supports 2 or 4 bytes
390 if ((arg != 2) && (arg != 4))
391 return SIO2_EINVAL;
393 // return success for unconfigured devices?
394 if (!pDevExt->pParams)
395 return SIO2_OK;
397 // ask platform if size is supported
398 pParams = pDevExt->pParams;
399 if (pDevExt->pParams->sio.control && (result = pDevExt->pParams->sio.control (device, (const PAF_SIO_Params *)pParams, code, arg)))
400 return result;
402 pDevExt->edmaWordSize = arg;
403 break;
405 case PAF_SIO_CONTROL_GET_PRECISION:
406 if (arg == 0)
407 return SIO2_EINVAL;
409 pParams = pDevExt->pParams;
410 if (pParams == NULL)
411 return( SIO2_EINVAL );
413 *((int *) arg) = pParams->sio.precision;
414 break;
416 case PAF_SIO_CONTROL_GET_NUMCHANNELS:
417 if (arg == 0)
418 return SIO2_EINVAL;
420 *((int *) arg) = pDevExt->numSlots * pDevExt->numSers;
421 break;
423 case PAF_SIO_CONTROL_SET_RATEX:
424 pParams = pDevExt->pParams;
425 if (pParams == NULL)
426 return SIO2_OK ;
428 if (pParams->sio.control == NULL)
429 return SIO2_EINVAL;
431 result = pParams->sio.control( device, (const PAF_SIO_Params *)pParams, PAF_SIO_CONTROL_SET_RATEX, arg);
432 break;
434 /* .......................................................................... */
436 case PAF_SIO_CONTROL_IDLE:
437 pParams = pDevExt->pParams;
438 if (pParams == NULL)
439 return SIO2_OK ;
441 if (pParams->sio.control == NULL)
442 return SIO2_EINVAL;
444 result = pParams->sio.control( device, (const PAF_SIO_Params *)pParams, PAF_SIO_CONTROL_IDLE, arg);
445 break;
447 case PAF_SIO_CONTROL_IDLE_WITH_CLOCKS:
448 // 1. Here we are intentionally not using SIO_Idle() and
449 // leaving the Tx clock running. We need this to avoid DAC noise,
450 // as well as provide a DIT clock when using digital output.
451 if (device->mode != DEV2_OUTPUT || pDevExt->pParams == NULL)
452 return SIO2_EINVAL;
454 pParams = pDevExt->pParams;
456 if (pParams->sio.moduleNum == 0)
457 hEdma = hEdma0;
458 else if (pParams->sio.moduleNum == 1 || pParams->sio.moduleNum == 2)
459 hEdma = hEdma1;
461 result = SAP_FTABLE_shutdown (device);
462 if (result)
463 return result;
465 Log_info0 ("SAP PAF_SIO_CONTROL_IDLE_WITH_CLOCKS; PAF_SIO_ERROR_IDLE_STAGE1");
466 pDevExt->errorState = PAF_SIO_ERROR_IDLE_STAGE1;
468 #if 1
469 //DJDBG, if below enableTransfer() is commented, input side continuous working.
470 if (pDevExt->activeEdma != EDMA_HINV) {
471 //EDMA3_DRV_disableTransfer (hEdma0, pDevExt->activeEdma, EDMA3_DRV_TRIG_MODE_EVENT);
472 //if(*((unsigned int *)0x02701000) & 0x01000000) *((unsigned int *)0x02701008) = 0x01000000; //Clear pending even in bit 24! //DJDBG
473 EDMA3_DRV_enableTransfer (hEdma, pDevExt->activeEdma, EDMA3_DRV_TRIG_MODE_EVENT);
474 }
475 #endif
476 //TRACE_GEN((&TR_MOD, "SAP_ctrl.%d: (0x%x) errorState = PAF_SIO_ERROR_IDLE_STAGE1 0x%x.", __LINE__, device, PAF_SIO_ERROR_IDLE_STAGE1));
478 break;
480 /* .......................................................................... */
482 case PAF_SIO_CONTROL_GET_INPUT_STATUS:
483 // needs to be attached
484 pParams = pDevExt->pParams;
485 if (pParams == NULL)
486 return SIO2_OK;
488 if (pParams->sio.control == NULL)
489 return SIO2_EINVAL;
491 result = pParams->sio.control( device, (const PAF_SIO_Params *)pParams, code, arg );
492 break;
494 case PAF_SIO_CONTROL_WATCHDOG:
495 pParams = pDevExt->pParams;
496 if (pParams == NULL)
497 return SIO2_OK;
498 if (pParams->sio.control && (result = pParams->sio.control (device, (const PAF_SIO_Params *)pParams, code, arg)))
499 return result;
500 break;
502 /* .......................................................................... */
504 // Timing stats specific to DMA engine
505 case PAF_SIO_CONTROL_ENABLE_STATS:
506 case PAF_SIO_CONTROL_DISABLE_STATS:
507 case PAF_SIO_CONTROL_GET_STATS:
508 case PAF_SIO_CONTROL_GET_NUM_EVENTS:
509 case PAF_SIO_CONTROL_GET_NUM_REMAINING:
510 //result = SAP_DMA_FTABLE_ctrl (device, code, arg);
511 // TRACE_VERBOSE((&TR_MOD, "SAP_ctrl: (0x%x) code 0x%x. result 0x%x.", device, code, result));
512 break;
514 /* .......................................................................... */
516 case PAF_SIO_CONTROL_SET_DITSTATUS:
517 if(device->mode == DEV2_OUTPUT)
518 {
519 const SAP_Params *pParams = pDevExt->pParams;
520 MCASP_Handle hPort = sapMcaspDrv.hPort[pParams->sio.moduleNum];
521 volatile Uint32 *base = (volatile Uint32 *)(hPort->baseAddr);
522 MCASP_ConfigXmt *pTxConfig = (MCASP_ConfigXmt *)pParams->sio.pConfig;
523 int encSelect = *((int *) arg);
525 // HACK -- determine DIT need by FXWID
526 if (((pTxConfig->afsxctl & _MCASP_AFSXCTL_FXWID_MASK)>> _MCASP_AFSXCTL_FXWID_SHIFT) == MCASP_AFSXCTL_FXWID_BIT)
527 {
528 if ( (encSelect == 0x13) ||
529 (encSelect == 0xa) ||
530 (encSelect == 0x6)) // DTE, DDE, MPE
531 {
532 base[_MCASP_DITCSRA0_OFFSET] |= 2;
533 base[_MCASP_DITCSRB0_OFFSET] |= 2;
534 }
535 else
536 {
537 base[_MCASP_DITCSRA0_OFFSET] &= 0xfffffffd;
538 base[_MCASP_DITCSRB0_OFFSET] &= 0xfffffffd;
539 }
540 }
542 pParams = pDevExt->pParams;
543 if (pParams == NULL)
544 return SIO2_OK;
546 if (pParams->sio.control != NULL)
547 result = pParams->sio.control (device, (const PAF_SIO_Params *)pParams, code, arg);
548 }
549 break;
551 /* .......................................................................... */
553 }
555 return result;
556 } // SAP_ctrl
558 int gSAPIdleShutdownIn=0;
559 int gSAPIdleShutdownOut=0;
561 // -----------------------------------------------------------------------------
563 Int SAP_idle (DEV2_Handle device, Bool flush)
564 {
565 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
566 Int result = SIO2_OK;
567 EDMA3_DRV_Handle hEdma;
569 // do nothing if already idled or unattached
570 if ((!pDevExt->runState) || (pDevExt->pParams == NULL))
571 return result;
573 if (pDevExt->pParams->sio.moduleNum == 0)
574 hEdma = hEdma0;
575 else if (pDevExt->pParams->sio.moduleNum == 1 || pDevExt->pParams->sio.moduleNum == 2)
576 hEdma = hEdma1;
578 // reset serial port -- stop generating sync events
579 result = SAP_PORT_FTABLE_reset (device);
580 if(device->mode == DEV2_OUTPUT)
581 gSAPResetOut++;
582 else
583 gSAPResetIn++;
584 if (result)
585 {
586 //TRACE_VERBOSE((&TR_MOD, "%s.%d: SAP_PORT_FTABLE_reset returned %d.\n", __FUNCTION__, __LINE__, result));
587 return result;
588 }
590 pDevExt->shutDown = 0; // force shutdown to run
591 result = SAP_FTABLE_shutdown (device);
592 if(device->mode == DEV2_OUTPUT)
593 gSAPIdleShutdownOut++;
594 else
595 gSAPIdleShutdownIn++;
597 if (result)
598 {
599 //TRACE_VERBOSE((&TR_MOD, "%s.%d: SAP_FTABLE_shutdown returned %d.\n", __FUNCTION__, __LINE__, result));
600 return result;
601 }
603 Log_info0("SAP_idle:Before EDMA3_DRV_disableTransfer");
605 // disable interrupts and EDMA servicing
606 if (pDevExt->activeEdma != EDMA_HINV)
607 EDMA3_DRV_disableTransfer (hEdma, pDevExt->activeEdma, EDMA3_DRV_TRIG_MODE_EVENT);
609 pDevExt->numQueued = 0;
611 // signal stopped
612 pDevExt->runState = 0;
613 Log_info0("SAP_idle: runState = 0");
615 // reset errorState
616 pDevExt->errorState = PAF_SIO_ERROR_NONE;
617 //TRACE_VERBOSE((&TR_MOD, "SAP_ctrl.%d: errorState = PAF_SIO_ERROR_NONE 0x%x.", __LINE__, PAF_SIO_ERROR_NONE));
619 // place call to physical device
620 if ((pDevExt->pParams != NULL) && (pDevExt->pParams->sio.control != NULL))
621 result = pDevExt->pParams->sio.control(device, (const PAF_SIO_Params *)pDevExt->pParams, PAF_SIO_CONTROL_IDLE, 0);
623 return result;
624 } // SAP_idle
626 // -----------------------------------------------------------------------------
628 Int SAP_start (DEV2_Handle device)
629 {
630 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
631 DEV2_Frame *pFrame;
632 int result;
633 EDMA3_DRV_Handle hEdma;
635 Log_info2("SAP_start.%d (0x%x)", __LINE__, device);
637 // Assume todevice queue is not empty -- how else could we be here?
638 pFrame = (DEV2_Frame *) Queue_get (device->todevice);
640 // inidicate this xfer did not use param entry - just the active one
641 pFrame->misc = NULL;
642 if (pDevExt->pParams->sio.moduleNum == 0)
643 hEdma = hEdma0;
644 else if (pDevExt->pParams->sio.moduleNum == 1 || pDevExt->pParams->sio.moduleNum == 2)
645 hEdma = hEdma1;
647 // non-atomic functions since not running yet.
648 Queue_enqueue (Queue_handle(&pDevExt->xferQue), (Queue_Elem *)pFrame);
650 // initialize count
651 pDevExt->numQueued = 1;
653 result = SAP_PORT_FTABLE_reset (device);
654 if (result)
655 {
656 //TRACE_VERBOSE((&TR_MOD, "%s.%d: SAP_PORT_FTABLE_reset returned %d.\n", __FUNCTION__, __LINE__, result));
657 return result;
658 }
660 // enable DMA processing
661 if (device->mode == DEV2_OUTPUT)
662 Log_info3("SAP_start.%d, pDevExt->activeEdma 0x%x (pDevExt->errorEdma = 0x%x)",
663 __LINE__, pDevExt->activeEdma, pDevExt->errorEdma);
664 // config active xfer for this buffer
665 result = SAP_EDMA_setupXfer(device, pDevExt->activeEdma, EDMA_HINV, pDevExt->errorEdma, pFrame);
668 // signal we have started -- this must come before last enable to prevent a race
669 // condition where the initial EDMA transfer is very small (e.g. due to startClocks)
670 // and completes before any further instructions in this thread are executed.
671 // This comes before the EDMA enable since, if the # of samples is 1, then the EDMA
672 // will be serviced and generate an interrupt even before the McASP is enabled.
673 pDevExt->runState = 1;
674 pDevExt->shutDown = 0;
675 if (device->mode == DEV2_OUTPUT)
676 Log_info2 ("SAP: %d, SAP_start runState=1 & ENABLE TRANSFERS for activeEdma = 0x%x", __LINE__, pDevExt->activeEdma);
677 // enable interrupts and event servicing for this channel
678 EDMA3_DRV_enableTransfer (hEdma, pDevExt->activeEdma, EDMA3_DRV_TRIG_MODE_EVENT);
680 // enable peripheral
681 result = SAP_PORT_FTABLE_enable (device);
683 if (result)
684 {
685 //TRACE_VERBOSE((&TR_MOD, "%s.%d: SAP_PORT_FTABLE_enable returned %d.\n", __FUNCTION__, __LINE__, result));
686 return result;
687 }
689 return SIO2_OK;
690 } // SAP_start
692 int gDmaParamsarray[17][3];
693 int gDmaParamsidx=0, gSAPSpecialCase=0;
694 // -----------------------------------------------------------------------------
696 Int SAP_issue (DEV2_Handle device)
697 {
698 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
699 DEV2_Frame *pFrame;
700 Int result;
701 SAP_EDMA_Param *pParam;
702 XDAS_UInt32 parentEdma;
704 if (device->mode == DEV2_OUTPUT)
705 Log_info1("SAP_issue for output device with pDevExt->errorState = 0x%x", pDevExt->errorState);
707 if ((device->mode == DEV2_OUTPUT) && (pDevExt->errorState >= PAF_SIO_ERROR_ERRBUF_XFER))
708 {
709 /*TRACE_TERSE((&TR_MOD, "SAP_issue.%d, errorState 0x%x (PAF_SIO_ERROR_ERRBUF_XFER = 0x%x)",
710 __LINE__, pDevExt->errorState, PAF_SIO_ERROR_ERRBUF_XFER));*/
711 Log_info3("SAP_issue.%d, PAF_SIO_ERROR_ERRBUF_XFER = 0x%x, mode = 0x%x)",
712 __LINE__, PAF_SIO_ERROR_ERRBUF_XFER, device->mode );
713 return SIO2_EBADIO;
714 }
716 if ((device->mode == DEV2_INPUT) && pDevExt->errorState)
717 {
718 Log_info1("SAP_issue: Input Error Trap, with errorState = 0x%x", pDevExt->errorState);
719 return SIO2_EBADIO;
720 }
722 // if not yet running then configure active xfer and start
723 if (pDevExt->runState == 0)
724 return (SAP_FTABLE_start(device));
726 // .........................................................................
727 // here if running
729 // disable device interrupts
730 // TODO: is there an API to just disable the IER bit for this tcc?
731 unsigned int key = Hwi_disable ();
732 /* determine parent EDMA
733 if no xfers in queue and we are running then must be in the
734 error state so link to active channel otherwise link to last
735 transfer queued.
736 */
738 /* here we assume after Tx SIO_idle or overrun, the user
739 will issue, at least, back-to-back issue requests so
740 there should be no problem here.
741 */
742 if ((pDevExt->numQueued <= 1) && (pDevExt->errorState != 2))
743 parentEdma = pDevExt->activeEdma;
744 else {
745 // if here then xferQue has more than one element so ok to use tail
746 // last scheduled transfer must be queue->prev
747 DEV2_Frame *tail = (DEV2_Frame *) Queue_prev ((Queue_Elem *)&pDevExt->xferQue);
748 parentEdma = ((SAP_EDMA_Param *) tail->misc)->hEdmaParam;
749 }
751 //if (device->mode == DEV2_OUTPUT)
752 Log_info2("SAP_issue: Determined Parent = 0x%x for device = 0x%x", parentEdma, device->mode );
754 // get frame and parameter table to use; ints off => non-atomic OK
755 // dont need to check for empty queues since were here then todevice
756 // must have a frame placed there by the SIO_issue layer.
757 // paramQue must be valid since it is accessed the same as todevice.
758 // (indirectly -- isr places used items onto paramQue and fromdevice que
759 // at the same time)
760 // set misc argument to pParam so get enqueue later
761 //pFrame = (DEV2_Frame *) Queue_dequeue (device->todevice);
762 pFrame = Queue_dequeue (device->todevice);
763 pParam = (SAP_EDMA_Param *) Queue_dequeue (Queue_handle(&pDevExt->paramQue));
765 if (pParam->hEdmaParam == NULL)
766 Log_info1("SAP_issue: hEdma value is NULL for device = 0x%x", device->mode);
767 // set misc argument to pParam so get enqueue later
768 pFrame->misc = (Arg) pParam;
770 // place on holder queue, ints off => non-atomic OK
771 Queue_enqueue (Queue_handle(&pDevExt->xferQue), (Queue_Elem *) pFrame);
772 if (pFrame->addr) {
773 if (device->mode == DEV2_INPUT)
774 Cache_inv (pFrame->addr, pFrame->size, Cache_Type_ALL, TRUE);
775 else
776 Cache_wbInv (pFrame->addr, pFrame->size, Cache_Type_ALL, TRUE);
777 }
779 // increment count
780 pDevExt->numQueued += 1;
782 result = SAP_EDMA_setupXfer (device, pParam->hEdmaParam, parentEdma, pDevExt->errorEdma, pFrame);
783 if (device->mode == DEV2_OUTPUT)
784 {
785 Log_info4("SAP_issue.%d, EDMA_setupXfer: Target EDMA: 0x%x, Parent Edma: 0x%x Error Edma: 0x%x",
786 __LINE__, pParam->hEdmaParam, parentEdma, pDevExt->errorEdma);
787 }
790 /*if ((device->mode != DEV2_INPUT) && (gDmaParamsidx <=16))
791 {
792 gDmaParamsarray[gDmaParamsidx][0] = pParam->hEdma;
793 gDmaParamsarray[gDmaParamsidx][1] = parentEdma;
794 gDmaParamsarray[gDmaParamsidx++][2] = gisrOutput;
795 } */
797 if ((pDevExt->errorState == PAF_SIO_ERROR_IDLE_STAGE1) && (device->mode == DEV2_OUTPUT))
798 pDevExt->errorState = PAF_SIO_ERROR_NONE;
800 pDevExt->shutDown = 0;
802 //if (device->mode == DEV2_OUTPUT)
803 //SAP_EDMA_dumpParams(1);
805 // special case enables when not yet started
806 if (pDevExt->runState == 0) {
807 gSAPSpecialCase++;
808 result = SAP_FTABLE_start (device);
809 if (result) {
810 //SAP_DMA_FTABLE_unlock (device);
811 Hwi_restore (key);
812 return result;
813 }
814 }
815 Hwi_restore (key); //DJDBG
817 return result;
818 } // SAP_issue
820 // -----------------------------------------------------------------------------
822 void swapHdmi(Ptr Input, int size)
823 {
825 MdInt L0, L1, L2, L3, R0, R1, R2, R3 = 0;
826 MdInt *p1, *p2;
827 int i=0;
829 for (i=0; i< size; i+=16)
830 {
831 p1 = (MdInt *)&Input[i];
832 p2 = p1;
834 L0 = *p1++;
835 L1 = *p1++;
836 L2 = *p1++;
837 L3 = *p1++;
838 R0 = *p1++;
839 R1 = *p1++;
840 R2 = *p1++;
841 R3 = *p1++;
843 *p2++ = L0;
844 *p2++ = R0;
845 *p2++ = L1;
846 *p2++ = R1;
847 *p2++ = L2;
848 *p2++ = R2;
849 *p2++ = L3;
850 *p2++ = R3;
852 }
854 Log_info3("SAP: Exiting swapHdmi with Frame->Addr: 0x%x, p1->addr: 0x%x, p2->addr: 0x%x ", (xdc_IArg)Input, p1, p2);
856 return;
857 }
859 Int SAP_reclaim (DEV2_Handle device)
860 {
861 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)(device->object);
862 #ifdef SAP_CACHE_SUPPORT
863 DEV2_Frame *pFrame;
864 #endif
866 //TRACE_GEN((&TR_MOD, "SAP_reclaim.%d (0x%x)", __LINE__, device));
867 if (device->mode == DEV2_OUTPUT)
868 Log_info2("SAP_reclaim for output device with pDevExt->errorState = 0x%x & runState: 0x%x", pDevExt->errorState, pDevExt->runState);
869 // must be running and error free
870 if ((!pDevExt->runState) || (pDevExt->errorState))
871 {
872 Log_info3("SAP_reclaim.%d, not runState: 0x%x, mode = 0x%x", __LINE__, pDevExt->errorState, device->mode);
873 return SIO2_EBADIO;
874 }
876 // idle if necessary
877 if (pDevExt->errorState == PAF_SIO_ERROR_FATAL) {
878 Log_info1("SAP_reclaim: PAF_SIO_ERROR_FATAL, Before Idle for device 0x%x ", device->mode);
879 DEV2_idle (device, 1);
880 return SIO2_EBADIO;
881 }
883 Log_info1("SAP_reclaim: Before SEM Pend for mode: 0x%x", device->mode);
885 // wait for ISR to signal block completion
886 //TRACE_VERBOSE((&TR_MOD, "SAP_reclaim.%d wait for ISR to signal block completion", __LINE__));
887 if (!Semaphore_pend(pDevExt->sync, device->timeout))
888 {
889 Log_info0("SAP_reclaim, SYS_ETIMEOUT");
890 return SIO2_ETIMEOUT;
891 }
892 Log_info1("SAP_reclaim: After SEM Pend for mode: 0x%x", device->mode);
894 #if 1
895 // return error (owner must idle)
896 if (pDevExt->errorState == PAF_SIO_ERROR_FATAL)
897 {
898 DEV2_idle (device, 1);
899 Log_info2("SAP_reclaim.%d, PAF_SIO_ERROR_FATAL: 0x%x", __LINE__, pDevExt->errorState);
900 return PAF_SIO_ERROR_FATAL;
901 }
902 #endif
904 #ifdef SAP_CACHE_SUPPORT
905 // invalidate CACHE region if input -- use clean since
906 // Dont clean if was for fill.
907 // since pend returned we know that head of fromdevice is valid
908 pFrame = Queue_head (device->fromdevice);
909 Log_info2("SAP: Inside SAP_Reclaim with From Device Frame->Addr: 0x%x and Frame->Size: %d", pFrame->addr, pFrame->size);
910 if ((device->mode == DEV2_INPUT) && (pFrame->addr != NULL))
911 {
912 if(pDevExt->edmaWordSize == 2 && pDevExt->numSers == 4)
913 {
914 Cache_inv (pFrame->addr, pFrame->size, Cache_Type_ALL, 0);
915 Cache_wait();
917 // max HWI disable duration ~1ms observed
918 //unsigned int key = Hwi_disable (); // GJ: Revisit, along with other context protections here.
919 swapHdmi(pFrame->addr, pFrame->size);
920 //Hwi_restore(key);
922 Cache_wb (pFrame->addr, pFrame->size, Cache_Type_ALL, 0);
923 Cache_wait();
924 }
925 }
927 #endif
928 /*if ((device->mode == DEV2_OUTPUT) && (pFrame->addr == NULL))
929 SW_BREAKPOINT; */
931 Log_info1("SAP_reclaim: Exiting with SIO2_OK for device 0x%x ", device->mode);
932 //TRACE_VERBOSE((&TR_MOD, "SAP_reclaim.%d, exit SIO2_OK", __LINE__));
933 return SIO2_OK;
934 } // SAP_reclaim
937 // -----------------------------------------------------------------------------
939 Int SAP_open (DEV2_Handle device, String name)
940 {
941 SAP_DeviceExtension *pDevExt;
942 DEV2_Device *entry;
943 Int oldMask, result;
944 Error_Block eb;
945 //TRACE_GEN((&TR_MOD, "SAP_open.%d (0x%x)", __LINE__, device));
947 // check SIO mode
948 if ((device->mode != DEV2_INPUT) && (device->mode != DEV2_OUTPUT))
949 return SIO2_EMODE;
951 // allocate memory for device extension
952 device->object = NULL;
953 pDevExt = (SAP_DeviceExtension *) Memory_alloc (device->bufSeg, (sizeof(SAP_DeviceExtension)+3)/4*4, 4, &eb);
954 if (pDevExt == NULL)
955 {
956 printf("%s.%d: MEM_alloc failed.\n", __FUNCTION__, __LINE__);
957 //TRACE_TERSE((&TR_MOD, "%s.%d: MEM_alloc failed.\n", __FUNCTION__, __LINE__));
958 asm( " SWBP 0" ); // SW Breakpoint
959 return SIO2_EALLOC;
960 }
961 device->object = (Ptr)pDevExt;
963 // inits
964 pDevExt->device = device;
965 pDevExt->sync = NULL;
966 pDevExt->pParams = NULL;
967 pDevExt->runState = 0; // not yet started
968 pDevExt->errorState = PAF_SIO_ERROR_NONE;
969 pDevExt->shutDown = 1;
970 pDevExt->numQueued = 0;
971 pDevExt->activeEdma = EDMA_HINV;
972 pDevExt->errorEdma = EDMA_HINV;
973 pDevExt->firstTCC = 0;
974 pDevExt->optLevel = 0;
975 pDevExt->numParamSetup = 0;
976 pDevExt->numEdmaParams = 4;
978 // use dev match to fetch function table pointer for SAP
979 DEV2_match(SAP_NAME, &entry);
980 if (entry == NULL) {
981 Log_error1("SAP", SIO2_ENODEV);
982 return SIO2_ENODEV;
983 }
984 pDevExt->pFxns = (SAP_Fxns *) entry->fxns;
986 // create semaphore for device
987 pDevExt->sync = Semaphore_create (0, NULL, NULL);
988 if (pDevExt->sync == NULL)
989 {
990 //TRACE_TERSE((&TR_MOD, "%s.%d: create semaphore for device failed.\n", __FUNCTION__, __LINE__));
991 return SIO2_EALLOC;
992 }
994 // queue inits
995 Queue_construct (&pDevExt->xferQue, NULL);
996 Queue_construct (&pDevExt->paramQue, NULL);
998 // update driver global (need to protect context)
999 if (sapDrv.numDevices >= MAX_SAP_DEVICES)
1000 {
1001 /*TRACE_TERSE((&TR_MOD, "%s.%d: add device failure: no. of devices = %d; need to increase MAX_SAP_DEVICES.\n",
1002 __FUNCTION__, __LINE__, dapDrv.numDevices));*/
1003 SW_BREAKPOINT;
1004 }
1005 oldMask = Hwi_disable ();
1006 sapDrv.device[sapDrv.numDevices] = device;
1007 pDevExt->deviceNum = sapDrv.numDevices++;
1008 Hwi_restore (oldMask);
1010 // PORT init
1011 result = SAP_PORT_FTABLE_open (device);
1012 if (result)
1013 {
1014 //TRACE_TERSE((&TR_MOD, "%s.%d: SAP_PORT_FTABLE_open returned %d.\n", __FUNCTION__, __LINE__, result));
1015 return result;
1016 }
1018 return result;
1019 } // SAP_open
1021 // -----------------------------------------------------------------------------
1023 Int SAP_config (DEV2_Handle device, const SAP_Params *pParams)
1024 {
1025 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
1026 Int result, Que_num, i;
1027 EDMA3_DRV_Result edmaResult;
1028 Uint32 reqTcc;
1029 EDMA3_DRV_Handle hEdma;
1030 Log_info2("SAP_config.%d (0x%x)", __LINE__, device);
1032 // cannot configure if transfer started
1033 if (pDevExt->runState == 1)
1034 return SIO2_EBADIO;
1036 // save pointer to config structure in device extension. here so that
1037 // forthcoming functions can use/modify config structure.
1038 pDevExt->pParams = pParams;
1039 pDevExt->edmaWordSize = pParams->sio.wordSize;
1041 // allocate Port resources.
1042 // This must come before DMA configuration
1043 result = SAP_PORT_FTABLE_alloc (device);
1044 if (result)
1045 {
1046 Log_info3("%s.%d: SAP_PORT_FTABLE_alloc returned %d.\n", (xdc_IArg) __FUNCTION__, __LINE__, result);
1047 return result;
1048 }
1050 // .............................................................................
1051 // EDMA configuration
1053 // DA10x McASP0 Specific
1054 if (pParams->sio.moduleNum == 0)
1055 {
1056 hEdma = hEdma0;
1057 if (device->mode == DEV2_INPUT)
1058 {
1059 Que_num = 0;
1060 pDevExt->activeEdma = CSL_EDMACC_0_McASP_0_REVT;
1061 }
1062 else
1063 {
1064 Que_num = 0;
1065 pDevExt->activeEdma = CSL_EDMACC_0_McASP_0_XEVT;
1066 }
1067 }
1068 // DA10x McASP1 Specific
1069 else if (pParams->sio.moduleNum == 1)
1070 {
1071 hEdma = hEdma1;
1072 if (device->mode == DEV2_INPUT)
1073 {
1074 Que_num = 0;
1075 pDevExt->activeEdma = CSL_EDMACC_1_McASP_1_REVT;
1076 }
1077 else
1078 {
1079 Que_num = 0;
1080 pDevExt->activeEdma = CSL_EDMACC_1_McASP_1_XEVT;
1081 }
1082 }
1083 // DA10x McASP2 Specific
1084 else if (pParams->sio.moduleNum == 2)
1085 {
1086 hEdma = hEdma1;
1087 if (device->mode == DEV2_INPUT)
1088 {
1089 Que_num = 0;
1090 pDevExt->activeEdma = CSL_EDMACC_1_McASP_2_REVT;
1091 }
1092 else
1093 {
1094 Que_num = 0;
1095 pDevExt->activeEdma = CSL_EDMACC_1_McASP_2_XEVT;
1096 }
1097 }
1100 for (i=0; i < pDevExt->numEdmaParams; i++) {
1102 reqTcc = EDMA3_DRV_TCC_ANY;
1103 pDevExt->edmaParams[i].hEdmaParam = EDMA3_DRV_LINK_CHANNEL;
1104 edmaResult = EDMA3_DRV_requestChannel (
1105 hEdma,
1106 &pDevExt->edmaParams[i].hEdmaParam,
1107 &reqTcc,
1108 (EDMA3_RM_EventQueue) Que_num,
1109 SAP_isrCallback,
1110 (void *) device);
1112 if (edmaResult != EDMA3_DRV_SOK)
1113 return SIO2_EALLOC;
1115 //not running => can use non-atomic functions
1116 Queue_enqueue (Queue_handle(&pDevExt->paramQue), (Queue_Elem *)&pDevExt->edmaParams[i]);
1118 }
1120 reqTcc = EDMA3_DRV_TCC_ANY;
1121 pDevExt->errorEdma = EDMA3_DRV_LINK_CHANNEL;
1122 edmaResult = EDMA3_DRV_requestChannel (
1123 hEdma,
1124 &pDevExt->errorEdma,
1125 &reqTcc,
1126 (EDMA3_RM_EventQueue)Que_num,
1127 SAP_isrCallback,
1128 (void *) device);
1129 if (edmaResult != EDMA3_DRV_SOK)
1130 return SIO2_EALLOC;
1132 // allocate edma channel -- also disable and clear the interrupt
1135 pDevExt->firstTCC = pDevExt->activeEdma ;
1136 edmaResult = EDMA3_DRV_requestChannel (
1137 hEdma,
1138 &pDevExt->activeEdma,
1139 &pDevExt->firstTCC,
1140 (EDMA3_RM_EventQueue) 0,
1141 SAP_isrCallback,
1142 (void *) device);
1143 if (edmaResult != EDMA3_DRV_SOK)
1144 {
1145 Log_info3("%s.%d: SAP_DMA_FTABLE_alloc returned %d.\n", (xdc_IArg)__FUNCTION__, __LINE__, edmaResult);
1146 return SIO2_EALLOC;
1147 }
1149 // Configure error transfer
1150 // make cnt same as # of channels in order to maintain alignment
1151 // and the error transfer small so that we never have to wait
1152 // long for it to complete and trigger a linked transfer. This is
1153 // important for establishing output timing when we are idling with
1154 // clocks still running. Is fine for Rx as well.
1155 result = SAP_DMA_FTABLE_setupParam (device, pDevExt->errorEdma, pDevExt->errorEdma, NULL, pDevExt->edmaWordSize * pDevExt->numSers);
1157 Log_info3("%s.%d: Exiting SAP_alloc for %d.\n", (xdc_IArg)__FUNCTION__, __LINE__, pDevExt->activeEdma);
1159 return SIO2_OK;
1160 } // SAP_config
1162 // -----------------------------------------------------------------------------
1164 Int SAP_shutdown (DEV2_Handle device)
1165 {
1166 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)(device->object);
1167 SIO2_Handle stream = (SIO2_Handle) device;
1168 DEV2_Frame *pFrame;
1169 Int i;
1170 EDMA3_DRV_Handle hEdma;
1171 //TRACE_GEN((&TR_MOD, "SAP_shutdown.%d (0x%x)", __LINE__, device));
1173 if (pDevExt->shutDown)
1174 return SIO2_EBADIO;
1176 if (pDevExt->pParams == NULL)
1177 return SIO2_EINVAL;
1179 if (pDevExt->pParams->sio.moduleNum == 0)
1180 hEdma = hEdma0;
1181 else if (pDevExt->pParams->sio.moduleNum == 1 || pDevExt->pParams->sio.moduleNum == 2)
1182 hEdma = hEdma1;
1183 if (pDevExt->activeEdma != EDMA_HINV)
1184 EDMA3_DRV_disableTransfer (hEdma, pDevExt->activeEdma, EDMA3_DRV_TRIG_MODE_EVENT);
1186 // reset queues
1187 while (!Queue_empty(device->todevice)) {
1188 // place oustanding requests onto holding queue
1189 pFrame = (DEV2_Frame *) Queue_dequeue (device->todevice);
1190 Queue_enqueue (Queue_handle(&pDevExt->xferQue), (Queue_Elem *) pFrame);
1191 }
1193 while (!Queue_empty(Queue_handle(&pDevExt->xferQue))) {
1194 // pull frame from holding queue and place on user queue
1195 pFrame = (DEV2_Frame *) Queue_dequeue (Queue_handle(&pDevExt->xferQue));
1196 Queue_enqueue (device->fromdevice, (Queue_Elem *) pFrame);
1197 }
1200 while (!Queue_empty(Queue_handle(&pDevExt->paramQue)))
1201 Queue_dequeue (Queue_handle(&pDevExt->paramQue));
1203 // not running => can use non-atomic functions
1204 for (i=0; i < pDevExt->numEdmaParams; i++)
1205 Queue_enqueue (Queue_handle(&pDevExt->paramQue), (Queue_Elem *) &pDevExt->edmaParams[i]);
1207 // reset counter
1208 pDevExt->numQueued = 0;
1210 //DJDBG_SAP_EDMA_dumpParams(1);
1211 // make sure active is linked to error
1212 EDMA3_DRV_linkChannel (hEdma, pDevExt->activeEdma, pDevExt->errorEdma);
1214 // think this is better (from SIO_idle for standard model )
1215 // refill frame list -- so user needn't call reclaim, which may cause Rx underrun.
1216 while (!Queue_empty(device->fromdevice)) {
1217 /* place oustanding requests onto holding queue */
1218 pFrame = (DEV2_Frame *) Queue_dequeue (device->fromdevice);
1219 Queue_enqueue (Queue_handle(&stream->framelist), (Queue_Elem *) pFrame);
1220 }
1221 Semaphore_reset (pDevExt->sync, 0);
1223 pDevExt->shutDown = 1;
1224 pDevExt->numParamSetup = 0;
1226 /*result = SAP_DMA_FTABLE_unlock (device);
1227 if (result)
1228 {
1229 //TRACE_TERSE((&TR_MOD, "%s.%d: SAP_DMA_FTABLE_unlock returned %d.\n", __FUNCTION__, __LINE__, result));
1230 return result;
1231 } */
1233 return SIO2_OK;
1234 } // SAP_shutdown
1236 // -----------------------------------------------------------------------------
1237 int gSapWatchDogThrottle = 0; //DJDBG
1238 int gSapWatchDogIn =0;
1239 int gSapWatchDogOut = 0;
1240 int gSapWatchDogInSemPost = 0;
1241 int gSapWatchDogOutSemPost = 0;
1243 Void SAP_watchDog (Void)
1244 {
1245 DEV2_Handle device;
1246 SAP_DeviceExtension *pDevExt;
1247 int i, oldMask, result;
1249 //Log_info2("SAP_watchDog.%d (0x%x)", __LINE__, device);
1251 // do nothing if SAP_init not yet called
1252 if (!SAP_initialized)
1253 {
1254 Log_info2("%s.%d: SAP_init not yet called.\n", __FUNCTION__, __LINE__);
1255 return;
1256 }
1258 // protect context
1259 Task_disable (); // needed since we may call SEM_post
1260 //oldMask = Hwi_disable ();
1263 //Log_info3("%s.%d: devices loop, numDevices = %d", __FUNCTION__, __LINE__, sapDrv.numDevices);
1265 for (i=0; i < sapDrv.numDevices; i++) {
1266 device = sapDrv.device[i];
1268 //Log_info3("%s.%d, devices loop start, device = 0x%x", __FUNCTION__, __LINE__, device);
1270 pDevExt = (SAP_DeviceExtension *) device->object;
1272 // do nothing if not running
1273 if (!pDevExt->runState)
1274 continue;
1276 // call board specific watchdog
1277 // TODO: handle return value
1278 SIO2_ctrl (device, PAF_SIO_CONTROL_WATCHDOG, NULL);
1280 // if port layer returns error then must need to clean up
1281 result = SAP_PORT_FTABLE_watchDog (device);
1282 if (result) {
1283 // set errorState which will force owner thread
1284 // to clean up via SIO_idle()
1285 pDevExt->errorState = PAF_SIO_ERROR_FATAL;
1286 if(device->mode == DEV2_INPUT)
1287 gSapWatchDogIn++;
1288 else
1289 {
1290 //if (gSapWatchDogOut == 0)
1291 //SAP_EDMA_dumpParams(1);
1292 gSapWatchDogOut++;
1293 }
1295 //TRACE_TERSE((&TR_MOD, "SAP_watchDog.%d, PAF_SIO_ERROR_FATAL: 0x%x", __LINE__, pDevExt->errorState));
1296 /* if(gSapWatchDogThrottle == 0) //DJDBG
1297 {
1298 Log_info3("SAP_watchDog.%d (0x%x); THROTTLED result = 0x%x", __LINE__, device, result);
1299 }
1300 gSapWatchDogThrottle ++;
1301 if(gSapWatchDogThrottle > 10) gSapWatchDogThrottle = 0; */
1302 // if outstanding pend then post to free owner thead
1303 if (!Semaphore_pend(pDevExt->sync, 0))
1304 {
1305 if(device->mode == DEV2_INPUT)
1306 gSapWatchDogInSemPost++;
1307 else
1308 gSapWatchDogOutSemPost++;
1309 Semaphore_post (pDevExt->sync);
1310 }
1311 }
1312 }
1315 // renable interrupts and task manager.
1316 // If we posted to the semaphore then the TSK_enable call will lead to
1317 // an immediate task switch to the associated audio thread.
1318 //Hwi_restore (oldMask);
1319 Task_enable ();
1321 } // SAP_watchDog
1323 // -----------------------------------------------------------------------------
1324 // Assumes that EDMA3 dispatcher handles TCC clearing.
1326 void SAP_isrCallback (Uint32 tcc, EDMA3_RM_TccStatus status, Ptr context)
1327 {
1328 DEV2_Handle device;
1329 SAP_DeviceExtension *pDevExt;
1330 DEV2_Frame *pFrame;
1331 unsigned int opt;
1332 EDMA3_DRV_Handle hEdma;
1334 // could be here after Tx idle/overrun and this is the interrupt
1335 // for the last occuring error transfer so there is no transfer
1336 // to release, we just clear the int and exit.
1338 device = (DEV2_Handle) context;
1339 pDevExt = (SAP_DeviceExtension *)(device->object);
1340 //if (pDevExt->pParams == NULL)
1341 //return SIO2_EINVAL;
1343 if (pDevExt->pParams->sio.moduleNum == 0)
1344 hEdma = hEdma0;
1345 else if (pDevExt->pParams->sio.moduleNum == 1 || pDevExt->pParams->sio.moduleNum == 2)
1346 hEdma = hEdma1;
1348 if ((pDevExt->runState == 1) && !pDevExt->errorState) {
1349 // if here then an interrupt occured due to errorEdma or valid
1350 // transfer, we assume the xfer is long enough so it will not complete
1351 // before we are finished here.
1353 // if last transfer was valid then complete it
1354 if (!Queue_empty(Queue_handle(&pDevExt->xferQue))) {
1356 // pull frame from holding queue
1357 pFrame = (DEV2_Frame *) Queue_dequeue (Queue_handle(&pDevExt->xferQue));
1359 // if used param entry then return it to queue
1360 if (pFrame->misc != NULL)
1361 {
1362 Queue_enqueue (Queue_handle(&pDevExt->paramQue), (Ptr) pFrame->misc);
1363 if (device->mode == 1)
1364 gisrOutput+=100;
1365 }
1367 // decrement count
1368 pDevExt->numQueued -= 1;
1369 //gIsrCnt++;
1370 if (device->mode == 1)
1371 {
1372 gIsrOutputCnt++;
1373 //Log_info1("SAP isrCallback for 0x%x", pDevExt->activeEdma);
1374 }
1375 else
1376 gIsrInputCnt++;
1377 // place frame onto user queue and signal user thread
1378 Queue_enqueue (device->fromdevice, (Ptr) pFrame);
1380 //Log_info2("Before SEM_post for device: 0x%x gIsrOutput: %d", device->mode, gisrOutput);
1381 // signal user thread
1382 Semaphore_post (pDevExt->sync);
1383 #if 0
1384 if(gIsrCnt > 10) { //DJDBG
1385 Log_info1("SAP isrCallback enough interrupts! %d", gIsrCnt);
1387 }
1388 #endif
1389 }
1390 else
1391 gIsrElseCnt++;
1393 // determine if currently transferring buffer is valid based on interrupt enable bit
1394 // only valid transfers will generate interrupts
1395 EDMA3_DRV_getPaRAMEntry (hEdma, pDevExt->activeEdma, EDMA3_DRV_PARAM_ENTRY_OPT, &opt);
1397 if (!(opt & EDMA3_DRV_OPT_TCINTEN_SET_MASK (1)))
1398 {
1399 if (device->mode == 1)
1400 gIsrOutErrCnt++;
1401 else
1402 gIsrInErrCnt++;
1403 pDevExt->errorState = PAF_SIO_ERROR_ERRBUF_XFER;
1404 }
1406 } // runState
1407 else
1408 {
1409 if (pDevExt->runState != 1)
1410 gIsrRunCnt++;
1411 else
1412 gIsrNotRunCnt++;
1413 }
1415 return;
1416 } //SAP_isrCallback
1418 // -----------------------------------------------------------------------------
1420 Int SAP_EDMA_setupXfer (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32 parentEdma, XDAS_UInt32 childEdma, DEV2_Frame *pFrame)
1421 {
1422 EDMA3_DRV_Handle hEdma;
1423 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
1424 // int mcbspNum = pDevExt->pParams->sio.moduleNum;
1426 if (pDevExt->pParams == NULL)
1427 return SIO2_EINVAL;
1429 if (pDevExt->pParams->sio.moduleNum == 0)
1430 hEdma = hEdma0;
1431 else if (pDevExt->pParams->sio.moduleNum == 1 || pDevExt->pParams->sio.moduleNum == 2)
1432 hEdma = hEdma1;
1434 // TODO: shouldn't this just be tcc interrupt disable?
1435 // at least until linkage phase...
1436 unsigned int key = Hwi_disable (); //DJDBG
1438 if(targetEdma == NULL)
1439 {
1440 Log_info0("targetEdma is NULL");
1441 }
1442 // configure transfer
1443 if(pFrame->addr == NULL) //DJDBG
1444 {
1445 Log_info0("pFrame has NULL address?");
1446 }
1447 SAP_DMA_FTABLE_setupParam (device, targetEdma, childEdma, (XDAS_UInt32) pFrame->addr, pFrame->size);
1449 if (device->mode == DEV2_OUTPUT)
1450 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);
1452 if (parentEdma != EDMA_HINV)
1453 EDMA3_DRV_linkChannel (hEdma, parentEdma, targetEdma);
1455 if (device->mode == DEV2_OUTPUT)
1456 Log_info3("SAP: Inside SAP_EDMA_setupXfer linked targetEdma = 0x%x with parentEdma=0x%x on Edma=0x%x", targetEdma, parentEdma, hEdma);
1458 Hwi_restore (key); //DJDBG
1460 return SIO2_OK;
1461 } // SAP_setupXfer
1463 // -----------------------------------------------------------------------------
1464 // Configure EDMA3 parameter entry
1466 Int SAP_EDMA_setupParam (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32 childEdma, XDAS_UInt32 addr, XDAS_UInt32 size)
1467 {
1468 SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
1469 EDMA3_DRV_Handle hEdma;
1470 EDMA3_DRV_PaRAMRegs edmaConfig;
1472 if (pDevExt->pParams == NULL)
1473 return SIO2_EINVAL;
1475 if (pDevExt->pParams->sio.moduleNum == 0)
1476 hEdma = hEdma0;
1477 else if (pDevExt->pParams->sio.moduleNum == 1 || pDevExt->pParams->sio.moduleNum == 2)
1478 hEdma = hEdma1;
1479 MCASP_Handle hPort = sapMcaspDrv.hPort[pDevExt->pParams->sio.moduleNum];
1480 // volatile Uint32 *base = (volatile Uint32 *)(hPort->baseAddr);
1482 //Log_info3("%s.%d: Entered SAP_EDMA_setupParam for Target: 0x%x.\n", (xdc_IArg)__FUNCTION__, __LINE__, targetEdma);
1484 // Init opt parameter to 0 which, without being overriden, configures as:
1485 // A synchronized transfer (no FIFO mode on src or dst)
1486 // no chaining or intermediate interrupts
1487 // param is not static
1488 // normal completion
1489 // don't generate an interrupt (overriden below for regular xfers)
1490 edmaConfig.opt = 0;
1492 // not transferring blocks so c index is 0
1493 edmaConfig.destCIdx = 0;
1494 edmaConfig.srcCIdx = 0;
1496 edmaConfig.opt |= EDMA3_DRV_OPT_SYNCDIM_SET_MASK (EDMA3_DRV_SYNC_AB); //DJDBG!
1497 if (device->mode == DEV2_OUTPUT) {
1498 //edmaConfig.opt |= EDMA3_DRV_OPT_DAM_SET_MASK (EDMA3_DRV_ADDR_MODE_FIFO); //DJDBG!!!
1499 edmaConfig.opt |= 2;
1500 }
1501 else {
1502 //edmaConfig.opt |= EDMA3_DRV_OPT_SAM_SET_MASK (EDMA3_DRV_ADDR_MODE_FIFO); //DJDBG!!!
1503 edmaConfig.opt |= 1;
1504 }
1506 // if regular transfer then enable interrupt with tcc code
1507 if (targetEdma != pDevExt->errorEdma) {
1508 edmaConfig.opt |= EDMA3_DRV_OPT_SYNCDIM_SET_MASK (EDMA3_DRV_SYNC_AB);
1509 edmaConfig.opt |= EDMA3_DRV_OPT_TCINTEN_SET_MASK (1);
1510 edmaConfig.opt |= EDMA3_DRV_OPT_TCC_SET_MASK (pDevExt->firstTCC);
1511 }
1514 edmaConfig.aCnt = 4;
1515 edmaConfig.bCnt = pDevExt->numSers;
1516 edmaConfig.cCnt = size/(edmaConfig.aCnt * edmaConfig.bCnt);
1517 edmaConfig.bCntReload = edmaConfig.bCnt;
1520 // handle direction specific requirements
1521 if (device->mode == DEV2_INPUT) {
1522 edmaConfig.srcBIdx = 0;
1523 edmaConfig.srcAddr = (unsigned int) (hPort->rbufAddr);
1525 if (addr) {
1526 edmaConfig.destBIdx = pDevExt->edmaWordSize;
1527 edmaConfig.destAddr = addr;
1528 edmaConfig.destCIdx = pDevExt->edmaWordSize * pDevExt->numSers ;
1529 if(pDevExt->edmaWordSize == 2)
1530 edmaConfig.cCnt= (size)/((edmaConfig.aCnt * edmaConfig.bCnt)/2);
1531 }
1532 else {
1533 //if(pDevExt->edmaWordSize == 2)
1534 //edmaConfig.srcAddr= (unsigned int)edmaConfig.srcAddr+ 2;
1535 edmaConfig.destBIdx = 0;
1536 edmaConfig.destAddr = (unsigned int) &sap_OVER_4LANE;
1537 edmaConfig.cCnt = 1;
1538 }
1539 }
1540 else {
1541 edmaConfig.destBIdx = 0;
1542 edmaConfig.srcBIdx = pDevExt->edmaWordSize;
1543 edmaConfig.destAddr = (unsigned int) (hPort->xbufAddr);
1544 if (addr) {
1545 edmaConfig.srcCIdx = pDevExt->edmaWordSize * pDevExt->numSers ;
1546 edmaConfig.srcAddr = addr;
1547 //Edma3_CacheFlush ((unsigned int) addr, (size+3)/4);
1548 }
1549 else {
1550 edmaConfig.srcBIdx = 0;
1551 edmaConfig.srcAddr = (unsigned int) &sap_UNDER[0];
1552 #if 0
1553 //edmaConfig.cCnt = (SAP_UNDER_LEN * sizeof(int))/(edmaConfig.aCnt * edmaConfig.bCnt); //DJDBG
1554 edmaConfig.cCnt = SAP_UNDER_LEN; //DJDBG, if underrun have frame of silence
1555 #endif
1556 }
1557 }
1558 edmaConfig.srcAddr = (unsigned int) getGlobalAddr(edmaConfig.srcAddr);
1559 edmaConfig.destAddr = (unsigned int) getGlobalAddr(edmaConfig.destAddr);
1561 EDMA3_DRV_setPaRAM (hEdma, targetEdma, &edmaConfig);
1563 // link child xfer
1564 if (childEdma != EDMA_HINV)
1565 EDMA3_DRV_linkChannel (hEdma, targetEdma, childEdma);
1567 if (device->mode == DEV2_OUTPUT) {
1568 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);
1569 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 );
1570 }
1572 return SIO2_OK;
1573 } //SAP_setupParam