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