[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / application / itopo / evmk2g / edma_cfg.c
2 /*
3 Copyright (c) 2018, 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 #include <ti/drv/uart/src/v0/UART_v0.h>
47 #endif
51 /** @brief EDMA3 Driver Instance specific Semaphore handle */
52 extern EDMA3_OS_Sem_Handle semHandle[];
54 /** To Register the ISRs with the underlying OS, if required. */
55 extern void registerEdma3Interrupts (unsigned int edma3Id);
56 /** To Unregister the ISRs with the underlying OS, if previously registered. */
57 extern void unregisterEdma3Interrupts (unsigned int edma3Id);
59 /* To find out the DSP# */
60 extern unsigned short determineProcId();
62 /**
63 * To check whether the global EDMA3 configuration is required or not.
64 * It should be done ONCE by any of the masters present in the system.
65 * This function checks whether the global configuration is required by the
66 * current master or not. In case of many masters, it should be done only
67 * by one of the masters. Hence this function will return TRUE only once
68 * and FALSE for all other masters.
69 */
70 extern unsigned short isGblConfigRequired(unsigned int dspNum);
72 /**
73 * DSP instance number on which the executable is running. Its value is
74 * determined by reading the processor specific register DNUM.
75 */
76 unsigned int dsp_num;
78 /**
79 * Shadow Region on which the executable is running. Its value is populated
80 * with the DSP Instance Number here in this case.
81 */
82 unsigned int region_id;
84 /* Number of EDMA3 controllers present in the system */
85 extern const unsigned int numEdma3Instances;
87 /* External Global Configuration Structure */
88 extern EDMA3_DRV_GblConfigParams sampleEdma3GblCfgParams[];
90 /* External Instance Specific Configuration Structure */
91 extern EDMA3_DRV_InstanceInitConfig sampleInstInitConfig[][EDMA3_MAX_REGIONS];
93 EDMA3_DRV_Handle hEdma0;
94 EDMA3_DRV_Handle hEdma1;
96 #ifdef DCS7_UART_EDMA_ENABLE
97 extern UART_HwAttrs uartInitCfg[];
98 #endif
100 /**
101 * \brief Configures eDMA module
102 *
103 * \return Platform_EOK on Success or error code
104 */
105 Aud_STATUS eDmaConfig(void)
106 {
107 EDMA3_DRV_Result edmaResult = 0;
109 /* Initialize eDMA 0 */
110 hEdma0 = edma3init(CSL_EDMACC_0, &edmaResult);
111 if((hEdma0 == NULL) || (edmaResult != 0))
112 {
113 IFPRINT(aud_write("eDMA instance 0 Initialization Failed\n"));
114 return (Aud_EFAIL);
115 }
116 #ifdef DCS7_UART_EDMA_ENABLE
117 uartInitCfg[0].edmaHandle = hEdma0;
118 #endif
119 /* Initialize eDMA 1 */
120 hEdma1 = edma3init(CSL_EDMACC_1, &edmaResult);
121 if((hEdma1 == NULL) || (edmaResult != 0))
122 {
123 IFPRINT(aud_write("eDMA instance 1 Initialization Failed\n"));
124 return (Aud_EFAIL);
125 }
127 return (Aud_EOK);
128 }
130 /**
131 * \brief EDMA3 Initialization
132 *
133 * This function initializes the EDMA3 Driver and registers the
134 * interrupt handlers.
135 *
136 * \return EDMA3_DRV_SOK if success, else error code
137 */
138 EDMA3_DRV_Handle edma3init (unsigned int edma3Id, EDMA3_DRV_Result *errorCode)
139 {
140 EDMA3_DRV_Result edma3Result = EDMA3_DRV_E_INVALID_PARAM;
141 Semaphore_Params semParams;
142 EDMA3_DRV_GblConfigParams *globalConfig = NULL;
143 EDMA3_DRV_InitConfig initCfg;
144 EDMA3_RM_MiscParam miscParam;
145 EDMA3_DRV_Handle hEdma = NULL;
147 if ((edma3Id >= numEdma3Instances) || (errorCode == NULL))
148 return hEdma;
150 /* DSP instance number */
151 dsp_num = determineProcId();
153 globalConfig = &sampleEdma3GblCfgParams[edma3Id];
155 /* Configure it as master, if required */
156 miscParam.isSlave = isGblConfigRequired(dsp_num);
157 edma3Result = EDMA3_DRV_create (edma3Id, globalConfig ,
158 (void *)&miscParam);
160 if (edma3Result == EDMA3_DRV_SOK)
161 {
162 /**
163 * Driver Object created successfully.
164 * Create a semaphore now for driver instance.
165 */
166 Semaphore_Params_init(&semParams);
168 initCfg.drvSemHandle = NULL;
169 edma3Result = edma3OsSemCreate(1, &semParams, &initCfg.drvSemHandle);
170 }
172 if (edma3Result == EDMA3_DRV_SOK)
173 {
174 /* Save the semaphore handle for future use */
175 semHandle[edma3Id] = initCfg.drvSemHandle;
177 /* Driver instance specific config NULL */
178 initCfg.drvInstInitConfig = NULL;
180 #ifndef EDMA3_DRV_USE_DEF_RM_CFG
181 /* Hook for running examples with default RM config */
182 /* configuration structure for the Driver */
183 initCfg.drvInstInitConfig = &sampleInstInitConfig[edma3Id][dsp_num];
184 #endif
186 initCfg.isMaster = TRUE;
187 /* Choose shadow region according to the DSP# */
188 initCfg.regionId = (EDMA3_RM_RegionId)dsp_num;
189 /*Saving the regionId for using it in the sample_cs.c file */
190 region_id = (EDMA3_RM_RegionId)dsp_num;
191 /* Driver instance specific config NULL */
193 initCfg.gblerrCb = NULL;
194 initCfg.gblerrData = NULL;
196 /* Open the Driver Instance */
197 hEdma = EDMA3_DRV_open (edma3Id, (void *) &initCfg, &edma3Result);
198 }
200 if(hEdma && (edma3Result == EDMA3_DRV_SOK))
201 {
202 /**
203 * Register Interrupt Handlers for various interrupts
204 * like transfer completion interrupt, CC error
205 * interrupt, TC error interrupts etc, if required.
206 */
207 registerEdma3Interrupts(edma3Id);
208 }
210 *errorCode = edma3Result;
212 return (hEdma);
213 }
216 /**
217 * \brief EDMA3 De-initialization
218 *
219 * This function removes the EDMA3 Driver instance and unregisters the
220 * interrupt handlers.
221 *
222 * \return EDMA3_DRV_SOK if success, else error code
223 */
224 EDMA3_DRV_Result edma3deinit (unsigned int edma3Id, EDMA3_DRV_Handle hEdma)
225 {
226 EDMA3_DRV_Result edma3Result = EDMA3_DRV_E_INVALID_PARAM;
228 /* Unregister Interrupt Handlers first */
229 unregisterEdma3Interrupts(edma3Id);
231 /* Delete the semaphore */
232 edma3Result = edma3OsSemDelete(semHandle[edma3Id]);
234 if (EDMA3_DRV_SOK == edma3Result )
235 {
236 /* Make the semaphore handle as NULL. */
237 semHandle[edma3Id] = NULL;
239 /* Now, close the EDMA3 Driver Instance */
240 edma3Result = EDMA3_DRV_close (hEdma, NULL);
241 }
243 if (EDMA3_DRV_SOK == edma3Result )
244 {
245 /* Now, delete the EDMA3 Driver Object */
246 edma3Result = EDMA3_DRV_delete (edma3Id, NULL);
247 }
249 return (edma3Result);
250 }
252 /* Nothing past this point */