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 * \file edma_config.c
38 *
39 * \brief Initializes eDMA module
40 *
41 */
43 #include "edma_cfg.h"
45 #ifdef DCS7_UART_EDMA_ENABLE
46 #if 0 // FL: PDK 1.0.1.2_eng
47 #include <ti/drv/uart/src/v0/UART_dma_v0.h>
48 #else // FL: PDK 1.0.6
49 #include <ti/drv/uart/src/v0/UART_v0.h>
50 #endif
51 #endif
55 /** @brief EDMA3 Driver Instance specific Semaphore handle */
56 extern EDMA3_OS_Sem_Handle semHandle[];
58 /** To Register the ISRs with the underlying OS, if required. */
59 extern void registerEdma3Interrupts (unsigned int edma3Id);
60 /** To Unregister the ISRs with the underlying OS, if previously registered. */
61 extern void unregisterEdma3Interrupts (unsigned int edma3Id);
63 /* To find out the DSP# */
64 extern unsigned short determineProcId();
66 /**
67 * To check whether the global EDMA3 configuration is required or not.
68 * It should be done ONCE by any of the masters present in the system.
69 * This function checks whether the global configuration is required by the
70 * current master or not. In case of many masters, it should be done only
71 * by one of the masters. Hence this function will return TRUE only once
72 * and FALSE for all other masters.
73 */
74 extern unsigned short isGblConfigRequired(unsigned int dspNum);
76 /**
77 * DSP instance number on which the executable is running. Its value is
78 * determined by reading the processor specific register DNUM.
79 */
80 unsigned int dsp_num;
82 /**
83 * Shadow Region on which the executable is running. Its value is populated
84 * with the DSP Instance Number here in this case.
85 */
86 unsigned int region_id;
88 /* Number of EDMA3 controllers present in the system */
89 extern const unsigned int numEdma3Instances;
91 /* External Global Configuration Structure */
92 extern EDMA3_DRV_GblConfigParams sampleEdma3GblCfgParams[];
94 /* External Instance Specific Configuration Structure */
95 extern EDMA3_DRV_InstanceInitConfig sampleInstInitConfig[][EDMA3_MAX_REGIONS];
97 EDMA3_DRV_Handle hEdma0;
98 EDMA3_DRV_Handle hEdma1;
100 #ifdef DCS7_UART_EDMA_ENABLE
101 #if 0 // FL: PDK 1.0.1.2_eng
102 extern UARTDMA_HwAttrs uartInitCfg[];
103 #else // FL: PDK 1.0.6
104 extern UART_HwAttrs uartInitCfg[];
105 #endif
106 #endif
108 /**
109 * \brief Configures eDMA module
110 *
111 * \return Platform_EOK on Success or error code
112 */
113 Audk2g_STATUS eDmaConfig(void)
114 {
115 EDMA3_DRV_Result edmaResult = 0;
117 /* Initialize eDMA 0 */
118 hEdma0 = edma3init(CSL_EDMACC_0, &edmaResult);
119 if((hEdma0 == NULL) || (edmaResult != 0))
120 {
121 IFPRINT(audk2g_write("eDMA instance 0 Initialization Failed\n"));
122 return (Audk2g_EFAIL);
123 }
124 #ifdef DCS7_UART_EDMA_ENABLE
125 uartInitCfg[0].edmaHandle = hEdma0;
126 #endif
127 /* Initialize eDMA 1 */
128 hEdma1 = edma3init(CSL_EDMACC_1, &edmaResult);
129 if((hEdma1 == NULL) || (edmaResult != 0))
130 {
131 IFPRINT(audk2g_write("eDMA instance 1 Initialization Failed\n"));
132 return (Audk2g_EFAIL);
133 }
135 return (Audk2g_EOK);
136 }
138 /**
139 * \brief EDMA3 Initialization
140 *
141 * This function initializes the EDMA3 Driver and registers the
142 * interrupt handlers.
143 *
144 * \return EDMA3_DRV_SOK if success, else error code
145 */
146 EDMA3_DRV_Handle edma3init (unsigned int edma3Id, EDMA3_DRV_Result *errorCode)
147 {
148 EDMA3_DRV_Result edma3Result = EDMA3_DRV_E_INVALID_PARAM;
149 Semaphore_Params semParams;
150 EDMA3_DRV_GblConfigParams *globalConfig = NULL;
151 EDMA3_DRV_InitConfig initCfg;
152 EDMA3_RM_MiscParam miscParam;
153 EDMA3_DRV_Handle hEdma = NULL;
155 if ((edma3Id >= numEdma3Instances) || (errorCode == NULL))
156 return hEdma;
158 /* DSP instance number */
159 dsp_num = determineProcId();
161 globalConfig = &sampleEdma3GblCfgParams[edma3Id];
163 /* Configure it as master, if required */
164 miscParam.isSlave = isGblConfigRequired(dsp_num);
165 edma3Result = EDMA3_DRV_create (edma3Id, globalConfig ,
166 (void *)&miscParam);
168 if (edma3Result == EDMA3_DRV_SOK)
169 {
170 /**
171 * Driver Object created successfully.
172 * Create a semaphore now for driver instance.
173 */
174 Semaphore_Params_init(&semParams);
176 initCfg.drvSemHandle = NULL;
177 edma3Result = edma3OsSemCreate(1, &semParams, &initCfg.drvSemHandle);
178 }
180 if (edma3Result == EDMA3_DRV_SOK)
181 {
182 /* Save the semaphore handle for future use */
183 semHandle[edma3Id] = initCfg.drvSemHandle;
185 /* Driver instance specific config NULL */
186 initCfg.drvInstInitConfig = NULL;
188 #ifndef EDMA3_DRV_USE_DEF_RM_CFG
189 /* Hook for running examples with default RM config */
190 /* configuration structure for the Driver */
191 initCfg.drvInstInitConfig = &sampleInstInitConfig[edma3Id][dsp_num];
192 #endif
194 initCfg.isMaster = TRUE;
195 /* Choose shadow region according to the DSP# */
196 initCfg.regionId = (EDMA3_RM_RegionId)dsp_num;
197 /*Saving the regionId for using it in the sample_cs.c file */
198 region_id = (EDMA3_RM_RegionId)dsp_num;
199 /* Driver instance specific config NULL */
201 initCfg.gblerrCb = NULL;
202 initCfg.gblerrData = NULL;
204 /* Open the Driver Instance */
205 hEdma = EDMA3_DRV_open (edma3Id, (void *) &initCfg, &edma3Result);
206 }
208 if(hEdma && (edma3Result == EDMA3_DRV_SOK))
209 {
210 /**
211 * Register Interrupt Handlers for various interrupts
212 * like transfer completion interrupt, CC error
213 * interrupt, TC error interrupts etc, if required.
214 */
215 registerEdma3Interrupts(edma3Id);
216 }
218 *errorCode = edma3Result;
220 return (hEdma);
221 }
224 /**
225 * \brief EDMA3 De-initialization
226 *
227 * This function removes the EDMA3 Driver instance and unregisters the
228 * interrupt handlers.
229 *
230 * \return EDMA3_DRV_SOK if success, else error code
231 */
232 EDMA3_DRV_Result edma3deinit (unsigned int edma3Id, EDMA3_DRV_Handle hEdma)
233 {
234 EDMA3_DRV_Result edma3Result = EDMA3_DRV_E_INVALID_PARAM;
236 /* Unregister Interrupt Handlers first */
237 unregisterEdma3Interrupts(edma3Id);
239 /* Delete the semaphore */
240 edma3Result = edma3OsSemDelete(semHandle[edma3Id]);
242 if (EDMA3_DRV_SOK == edma3Result )
243 {
244 /* Make the semaphore handle as NULL. */
245 semHandle[edma3Id] = NULL;
247 /* Now, close the EDMA3 Driver Instance */
248 edma3Result = EDMA3_DRV_close (hEdma, NULL);
249 }
251 if (EDMA3_DRV_SOK == edma3Result )
252 {
253 /* Now, delete the EDMA3 Driver Object */
254 edma3Result = EDMA3_DRV_delete (edma3Id, NULL);
255 }
257 return (edma3Result);
258 }
260 /* Nothing past this point */