[processor-sdk/performance-audio-sr.git] / processor_audio_sdk_1_00_00_00 / pasdk / test_dsp / sap / edma_cfg.c
1 /*
2 * Copyright (c) 2015, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
34 /**
35 * \file edma_config.c
36 *
37 * \brief Initializes eDMA module
38 *
39 */
41 #include "edma_cfg.h"
45 /** @brief EDMA3 Driver Instance specific Semaphore handle */
46 extern EDMA3_OS_Sem_Handle semHandle[];
48 /** To Register the ISRs with the underlying OS, if required. */
49 extern void registerEdma3Interrupts (unsigned int edma3Id);
50 /** To Unregister the ISRs with the underlying OS, if previously registered. */
51 extern void unregisterEdma3Interrupts (unsigned int edma3Id);
53 /* To find out the DSP# */
54 extern unsigned short determineProcId();
56 /**
57 * To check whether the global EDMA3 configuration is required or not.
58 * It should be done ONCE by any of the masters present in the system.
59 * This function checks whether the global configuration is required by the
60 * current master or not. In case of many masters, it should be done only
61 * by one of the masters. Hence this function will return TRUE only once
62 * and FALSE for all other masters.
63 */
64 extern unsigned short isGblConfigRequired(unsigned int dspNum);
66 /**
67 * DSP instance number on which the executable is running. Its value is
68 * determined by reading the processor specific register DNUM.
69 */
70 unsigned int dsp_num;
72 /**
73 * Shadow Region on which the executable is running. Its value is populated
74 * with the DSP Instance Number here in this case.
75 */
76 unsigned int region_id;
78 /* Number of EDMA3 controllers present in the system */
79 extern const unsigned int numEdma3Instances;
81 /* External Global Configuration Structure */
82 extern EDMA3_DRV_GblConfigParams sampleEdma3GblCfgParams[];
84 /* External Instance Specific Configuration Structure */
85 extern EDMA3_DRV_InstanceInitConfig sampleInstInitConfig[][EDMA3_MAX_REGIONS];
87 EDMA3_DRV_Handle hEdma0;
88 EDMA3_DRV_Handle hEdma1;
90 /**
91 * \brief Configures eDMA module
92 *
93 * \return Platform_EOK on Success or error code
94 */
95 Platform_STATUS eDmaConfig(void)
96 {
97 EDMA3_DRV_Result edmaResult = 0;
99 /* Initialize eDMA 0 */
100 hEdma0 = edma3init(CSL_EDMACC_0, &edmaResult);
101 if((hEdma0 == NULL) || (edmaResult != 0))
102 {
103 IFPRINT(platform_write("eDMA instance 0 Initialization Failed\n"));
104 return (Platform_EFAIL);
105 }
107 /* Initialize eDMA 1 */
108 hEdma1 = edma3init(CSL_EDMACC_1, &edmaResult);
109 if((hEdma1 == NULL) || (edmaResult != 0))
110 {
111 IFPRINT(platform_write("eDMA instance 1 Initialization Failed\n"));
112 return (Platform_EFAIL);
113 }
115 return (Platform_EOK);
116 }
118 /**
119 * \brief EDMA3 Initialization
120 *
121 * This function initializes the EDMA3 Driver and registers the
122 * interrupt handlers.
123 *
124 * \return EDMA3_DRV_SOK if success, else error code
125 */
126 EDMA3_DRV_Handle edma3init (unsigned int edma3Id, EDMA3_DRV_Result *errorCode)
127 {
128 EDMA3_DRV_Result edma3Result = EDMA3_DRV_E_INVALID_PARAM;
129 Semaphore_Params semParams;
130 EDMA3_DRV_GblConfigParams *globalConfig = NULL;
131 EDMA3_DRV_InitConfig initCfg;
132 EDMA3_RM_MiscParam miscParam;
133 EDMA3_DRV_Handle hEdma = NULL;
135 if ((edma3Id >= numEdma3Instances) || (errorCode == NULL))
136 return hEdma;
138 /* DSP instance number */
139 dsp_num = determineProcId();
141 globalConfig = &sampleEdma3GblCfgParams[edma3Id];
143 /* Configure it as master, if required */
144 miscParam.isSlave = isGblConfigRequired(dsp_num);
145 edma3Result = EDMA3_DRV_create (edma3Id, globalConfig ,
146 (void *)&miscParam);
148 if (edma3Result == EDMA3_DRV_SOK)
149 {
150 /**
151 * Driver Object created successfully.
152 * Create a semaphore now for driver instance.
153 */
154 Semaphore_Params_init(&semParams);
156 initCfg.drvSemHandle = NULL;
157 edma3Result = edma3OsSemCreate(1, &semParams, &initCfg.drvSemHandle);
158 }
160 if (edma3Result == EDMA3_DRV_SOK)
161 {
162 /* Save the semaphore handle for future use */
163 semHandle[edma3Id] = initCfg.drvSemHandle;
165 /* Driver instance specific config NULL */
166 initCfg.drvInstInitConfig = NULL;
168 #ifndef EDMA3_DRV_USE_DEF_RM_CFG
169 /* Hook for running examples with default RM config */
170 /* configuration structure for the Driver */
171 initCfg.drvInstInitConfig = &sampleInstInitConfig[edma3Id][dsp_num];
172 #endif
174 initCfg.isMaster = TRUE;
175 /* Choose shadow region according to the DSP# */
176 initCfg.regionId = (EDMA3_RM_RegionId)dsp_num;
177 /*Saving the regionId for using it in the sample_cs.c file */
178 region_id = (EDMA3_RM_RegionId)dsp_num;
179 /* Driver instance specific config NULL */
181 initCfg.gblerrCb = NULL;
182 initCfg.gblerrData = NULL;
184 /* Open the Driver Instance */
185 hEdma = EDMA3_DRV_open (edma3Id, (void *) &initCfg, &edma3Result);
186 }
188 if(hEdma && (edma3Result == EDMA3_DRV_SOK))
189 {
190 /**
191 * Register Interrupt Handlers for various interrupts
192 * like transfer completion interrupt, CC error
193 * interrupt, TC error interrupts etc, if required.
194 */
195 registerEdma3Interrupts(edma3Id);
196 }
198 *errorCode = edma3Result;
200 return (hEdma);
201 }
204 /**
205 * \brief EDMA3 De-initialization
206 *
207 * This function removes the EDMA3 Driver instance and unregisters the
208 * interrupt handlers.
209 *
210 * \return EDMA3_DRV_SOK if success, else error code
211 */
212 EDMA3_DRV_Result edma3deinit (unsigned int edma3Id, EDMA3_DRV_Handle hEdma)
213 {
214 EDMA3_DRV_Result edma3Result = EDMA3_DRV_E_INVALID_PARAM;
216 /* Unregister Interrupt Handlers first */
217 unregisterEdma3Interrupts(edma3Id);
219 /* Delete the semaphore */
220 edma3Result = edma3OsSemDelete(semHandle[edma3Id]);
222 if (EDMA3_DRV_SOK == edma3Result )
223 {
224 /* Make the semaphore handle as NULL. */
225 semHandle[edma3Id] = NULL;
227 /* Now, close the EDMA3 Driver Instance */
228 edma3Result = EDMA3_DRV_close (hEdma, NULL);
229 }
231 if (EDMA3_DRV_SOK == edma3Result )
232 {
233 /* Now, delete the EDMA3 Driver Object */
234 edma3Result = EDMA3_DRV_delete (edma3Id, NULL);
235 }
237 return (edma3Result);
238 }
240 /* Nothing past this point */