d8b1b1593cb08550cef451556daba417a604fb1a
2 /*
3 Copyright (c) 2016, 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"
47 /** @brief EDMA3 Driver Instance specific Semaphore handle */
48 extern EDMA3_OS_Sem_Handle semHandle[];
50 /** To Register the ISRs with the underlying OS, if required. */
51 extern void registerEdma3Interrupts (unsigned int edma3Id);
52 /** To Unregister the ISRs with the underlying OS, if previously registered. */
53 extern void unregisterEdma3Interrupts (unsigned int edma3Id);
55 /* To find out the DSP# */
56 extern unsigned short determineProcId();
58 /**
59 * To check whether the global EDMA3 configuration is required or not.
60 * It should be done ONCE by any of the masters present in the system.
61 * This function checks whether the global configuration is required by the
62 * current master or not. In case of many masters, it should be done only
63 * by one of the masters. Hence this function will return TRUE only once
64 * and FALSE for all other masters.
65 */
66 extern unsigned short isGblConfigRequired(unsigned int dspNum);
68 /**
69 * DSP instance number on which the executable is running. Its value is
70 * determined by reading the processor specific register DNUM.
71 */
72 unsigned int dsp_num;
74 /**
75 * Shadow Region on which the executable is running. Its value is populated
76 * with the DSP Instance Number here in this case.
77 */
78 unsigned int region_id;
80 /* Number of EDMA3 controllers present in the system */
81 extern const unsigned int numEdma3Instances;
83 /* External Global Configuration Structure */
84 extern EDMA3_DRV_GblConfigParams sampleEdma3GblCfgParams[];
86 /* External Instance Specific Configuration Structure */
87 extern EDMA3_DRV_InstanceInitConfig sampleInstInitConfig[][EDMA3_MAX_REGIONS];
89 EDMA3_DRV_Handle hEdma0;
90 EDMA3_DRV_Handle hEdma1;
92 /**
93 * \brief Configures eDMA module
94 *
95 * \return Platform_EOK on Success or error code
96 */
97 Platform_STATUS eDmaConfig(void)
98 {
99 EDMA3_DRV_Result edmaResult = 0;
101 /* Initialize eDMA 0 */
102 hEdma0 = edma3init(CSL_EDMACC_0, &edmaResult);
103 if((hEdma0 == NULL) || (edmaResult != 0))
104 {
105 IFPRINT(platform_write("eDMA instance 0 Initialization Failed\n"));
106 return (Platform_EFAIL);
107 }
109 /* Initialize eDMA 1 */
110 hEdma1 = edma3init(CSL_EDMACC_1, &edmaResult);
111 if((hEdma1 == NULL) || (edmaResult != 0))
112 {
113 IFPRINT(platform_write("eDMA instance 1 Initialization Failed\n"));
114 return (Platform_EFAIL);
115 }
117 return (Platform_EOK);
118 }
120 /**
121 * \brief EDMA3 Initialization
122 *
123 * This function initializes the EDMA3 Driver and registers the
124 * interrupt handlers.
125 *
126 * \return EDMA3_DRV_SOK if success, else error code
127 */
128 EDMA3_DRV_Handle edma3init (unsigned int edma3Id, EDMA3_DRV_Result *errorCode)
129 {
130 EDMA3_DRV_Result edma3Result = EDMA3_DRV_E_INVALID_PARAM;
131 Semaphore_Params semParams;
132 EDMA3_DRV_GblConfigParams *globalConfig = NULL;
133 EDMA3_DRV_InitConfig initCfg;
134 EDMA3_RM_MiscParam miscParam;
135 EDMA3_DRV_Handle hEdma = NULL;
137 if ((edma3Id >= numEdma3Instances) || (errorCode == NULL))
138 return hEdma;
140 /* DSP instance number */
141 dsp_num = determineProcId();
143 globalConfig = &sampleEdma3GblCfgParams[edma3Id];
145 /* Configure it as master, if required */
146 miscParam.isSlave = isGblConfigRequired(dsp_num);
147 edma3Result = EDMA3_DRV_create (edma3Id, globalConfig ,
148 (void *)&miscParam);
150 if (edma3Result == EDMA3_DRV_SOK)
151 {
152 /**
153 * Driver Object created successfully.
154 * Create a semaphore now for driver instance.
155 */
156 Semaphore_Params_init(&semParams);
158 initCfg.drvSemHandle = NULL;
159 edma3Result = edma3OsSemCreate(1, &semParams, &initCfg.drvSemHandle);
160 }
162 if (edma3Result == EDMA3_DRV_SOK)
163 {
164 /* Save the semaphore handle for future use */
165 semHandle[edma3Id] = initCfg.drvSemHandle;
167 /* Driver instance specific config NULL */
168 initCfg.drvInstInitConfig = NULL;
170 #ifndef EDMA3_DRV_USE_DEF_RM_CFG
171 /* Hook for running examples with default RM config */
172 /* configuration structure for the Driver */
173 initCfg.drvInstInitConfig = &sampleInstInitConfig[edma3Id][dsp_num];
174 #endif
176 initCfg.isMaster = TRUE;
177 /* Choose shadow region according to the DSP# */
178 initCfg.regionId = (EDMA3_RM_RegionId)dsp_num;
179 /*Saving the regionId for using it in the sample_cs.c file */
180 region_id = (EDMA3_RM_RegionId)dsp_num;
181 /* Driver instance specific config NULL */
183 initCfg.gblerrCb = NULL;
184 initCfg.gblerrData = NULL;
186 /* Open the Driver Instance */
187 hEdma = EDMA3_DRV_open (edma3Id, (void *) &initCfg, &edma3Result);
188 }
190 if(hEdma && (edma3Result == EDMA3_DRV_SOK))
191 {
192 /**
193 * Register Interrupt Handlers for various interrupts
194 * like transfer completion interrupt, CC error
195 * interrupt, TC error interrupts etc, if required.
196 */
197 registerEdma3Interrupts(edma3Id);
198 }
200 *errorCode = edma3Result;
202 return (hEdma);
203 }
206 /**
207 * \brief EDMA3 De-initialization
208 *
209 * This function removes the EDMA3 Driver instance and unregisters the
210 * interrupt handlers.
211 *
212 * \return EDMA3_DRV_SOK if success, else error code
213 */
214 EDMA3_DRV_Result edma3deinit (unsigned int edma3Id, EDMA3_DRV_Handle hEdma)
215 {
216 EDMA3_DRV_Result edma3Result = EDMA3_DRV_E_INVALID_PARAM;
218 /* Unregister Interrupt Handlers first */
219 unregisterEdma3Interrupts(edma3Id);
221 /* Delete the semaphore */
222 edma3Result = edma3OsSemDelete(semHandle[edma3Id]);
224 if (EDMA3_DRV_SOK == edma3Result )
225 {
226 /* Make the semaphore handle as NULL. */
227 semHandle[edma3Id] = NULL;
229 /* Now, close the EDMA3 Driver Instance */
230 edma3Result = EDMA3_DRV_close (hEdma, NULL);
231 }
233 if (EDMA3_DRV_SOK == edma3Result )
234 {
235 /* Now, delete the EDMA3 Driver Object */
236 edma3Result = EDMA3_DRV_delete (edma3Id, NULL);
237 }
239 return (edma3Result);
240 }
242 /* Nothing past this point */