e25564bebea9a819ca5dae49875c5c023c237c02
1 /*
2 * sample_init.c
3 *
4 * Sample Initialization for the EDMA3 RM for BIOS 6 based applications. It
5 * should be MANDATORILY done once before EDMA3 usage.
6 *
7 * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
8 *
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the
20 * distribution.
21 *
22 * Neither the name of Texas Instruments Incorporated nor the names of
23 * its contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 *
38 */
40 #include <ti/sysbios/hal/Hwi.h>
41 #include <ti/sysbios/knl/Semaphore.h>
43 #include <ti/sdo/edma3/rm/sample/bios6_edma3_rm_sample.h>
45 /** @brief EDMA3 Driver Instance specific Semaphore handle */
46 extern EDMA3_OS_Sem_Handle rmSemHandle[EDMA3_MAX_EDMA3_INSTANCES];
48 /** To Register the ISRs with the underlying OS, if required. */
49 extern void registerEdma3Interrupts (uint32_t edma3Id);
50 /** To Unregister the ISRs with the underlying OS, if previously registered. */
51 extern void unregisterEdma3Interrupts (uint32_t edma3Id);
53 /* To find out the DSP# */
54 extern uint16_t determineProcId(void);
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 uint16_t isGblConfigRequired(uint32_t 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 uint32_t dsp_num;
72 /**
73 * Shadow Region on which the executable is runnig. Its value is populated
74 * with the dsp_num here in this case.
75 */
76 uint32_t region_id;
78 /* Number of EDMA3 controllers present in the system */
79 extern const uint32_t numEdma3Instances;
81 /* External Global Configuration Structure */
82 extern EDMA3_RM_GblConfigParams sampleEdma3GblCfgParams[EDMA3_MAX_EDMA3_INSTANCES];
84 /* External Instance Specific Configuration Structure */
85 extern EDMA3_RM_InstanceInitConfig sampleInstInitConfig[EDMA3_MAX_EDMA3_INSTANCES][EDMA3_MAX_REGIONS];
87 #ifdef DMA_XBAR_AVAILABLE
88 extern EDMA3_DRV_Result sampleInitXbarEvt(EDMA3_DRV_Handle hEdma, uint32_t edma3Id);
89 #endif
91 /**
92 * \brief EDMA3 Initialization
93 *
94 * This function initializes the EDMA3 RM and registers the
95 * interrupt handlers.
96 *
97 * \return EDMA3_RM_SOK if success, else error code
98 */
99 EDMA3_RM_Handle edma3init (uint32_t edma3Id, EDMA3_RM_Result *errorCode)
100 {
101 EDMA3_RM_Param initParam;
102 EDMA3_RM_Result edma3Result = EDMA3_RM_SOK;
103 Semaphore_Params semParams;
104 EDMA3_RM_MiscParam miscParam;
105 EDMA3_RM_GblConfigParams *globalConfig = NULL;
106 EDMA3_RM_InstanceInitConfig *instanceConfig = NULL;
107 EDMA3_RM_Handle hEdmaResMgr = NULL;
109 if ((edma3Id >= numEdma3Instances) || (errorCode == NULL))
110 {
111 hEdmaResMgr = NULL;
112 }
113 else
114 {
115 /* DSP instance number */
116 dsp_num = determineProcId();
118 globalConfig = &sampleEdma3GblCfgParams[edma3Id];
120 /* Configure it as master, if required */
121 miscParam.isSlave = isGblConfigRequired(dsp_num);
123 edma3Result = EDMA3_RM_create (edma3Id, globalConfig ,
124 (void *)&miscParam);
126 if (edma3Result == EDMA3_DRV_SOK)
127 {
128 /**
129 * Driver Object created successfully.
130 * Create a semaphore now for driver instance.
131 */
132 Semaphore_Params_init(&semParams);
134 initParam.rmSemHandle = NULL;
135 edma3Result = edma3OsSemCreate((int32_t)1, &semParams, &initParam.rmSemHandle);
136 }
138 if (edma3Result == EDMA3_DRV_SOK)
139 {
140 /* Save the semaphore handle for future use */
141 rmSemHandle[edma3Id] = initParam.rmSemHandle;
143 /* configuration structure for the Driver */
144 instanceConfig = &sampleInstInitConfig[edma3Id][dsp_num];
146 initParam.isMaster = TRUE;
147 /* Choose shadow region according to the DSP# */
148 initParam.regionId = (EDMA3_RM_RegionId)dsp_num;
149 /*Saving the regionId for using it in the sample_cs.c file */
150 region_id = (EDMA3_RM_RegionId)dsp_num;
151 /* Driver instance specific config NULL */
152 initParam.rmInstInitConfig = instanceConfig;
154 initParam.regionInitEnable = TRUE;
155 initParam.gblerrCbParams.gblerrCb = (EDMA3_RM_GblErrCallback)NULL;
156 initParam.gblerrCbParams.gblerrData = (void *)NULL;
158 /* Open the Driver Instance */
159 hEdmaResMgr = EDMA3_RM_open (edma3Id, (EDMA3_RM_Param *)&initParam,
160 &edma3Result);
161 }
163 #ifdef DMA_XBAR_AVAILABLE
164 {
165 if((hEdmaResMgr != NULL) && (edma3Result == EDMA3_RM_SOK))
166 {
167 edma3Result = sampleInitXbarEvt(hEdmaResMgr, edma3Id);
168 }
169 }
170 #endif
171 if((hEdmaResMgr != NULL) && (edma3Result == EDMA3_DRV_SOK))
172 {
173 /**
174 * Register Interrupt Handlers for various interrupts
175 * like transfer completion interrupt, CC error
176 * interrupt, TC error interrupts etc, if required.
177 */
178 registerEdma3Interrupts(edma3Id);
179 }
181 *errorCode = edma3Result;
182 }
183 return hEdmaResMgr;
184 }
186 /**
187 * \brief EDMA3 De-initialization
188 *
189 * This function removes the EDMA3 RM Instance and unregisters the
190 * interrupt handlers. It also deletes the RM Object.
191 *
192 * \return EDMA3_RM_SOK if success, else error code
193 */
194 EDMA3_RM_Result edma3deinit (uint32_t edma3Id, EDMA3_RM_Handle hEdma)
195 {
196 EDMA3_RM_Result edma3Result = EDMA3_RM_SOK;
198 /* Unregister Interrupt Handlers first */
199 unregisterEdma3Interrupts(edma3Id);
201 /* Delete the semaphore */
202 edma3Result = edma3OsSemDelete (rmSemHandle[edma3Id]);
204 if (EDMA3_RM_SOK == edma3Result)
205 {
206 /* Make the semaphore handle as NULL. */
207 rmSemHandle[edma3Id] = NULL;
209 /* Now, close the EDMA3 RM Instance */
210 edma3Result = EDMA3_RM_close (hEdma, NULL);
211 }
213 if (EDMA3_RM_SOK == edma3Result)
214 {
215 /* Now, delete the EDMA3 RM Object */
216 edma3Result = EDMA3_RM_delete (edma3Id, NULL);
217 }
219 return edma3Result;
220 }
222 /* End of File */