e89cb0e9487abdcc04fe65f2bd736625d6683bf2
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[];
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 runnig. Its value is populated
74 * with the dsp_num 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_RM_GblConfigParams sampleEdma3GblCfgParams[];
84 /* External Instance Specific Configuration Structure */
85 extern EDMA3_RM_InstanceInitConfig sampleInstInitConfig[][EDMA3_MAX_REGIONS];
87 #ifdef DMA_XBAR_AVAILABLE
88 extern EDMA3_DRV_Result sampleInitXbarEvt(EDMA3_DRV_Handle hEdma, unsigned int 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 (unsigned int 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 return hEdmaResMgr;
112 /* DSP instance number */
113 dsp_num = determineProcId();
115 globalConfig = &sampleEdma3GblCfgParams[edma3Id];
117 /* Configure it as master, if required */
118 miscParam.isSlave = isGblConfigRequired(dsp_num);
120 edma3Result = EDMA3_RM_create (edma3Id, globalConfig ,
121 (void *)&miscParam);
123 if (edma3Result == EDMA3_DRV_SOK)
124 {
125 /**
126 * Driver Object created successfully.
127 * Create a semaphore now for driver instance.
128 */
129 Semaphore_Params_init(&semParams);
131 initParam.rmSemHandle = NULL;
132 edma3Result = edma3OsSemCreate(1, &semParams, &initParam.rmSemHandle);
133 }
135 if (edma3Result == EDMA3_DRV_SOK)
136 {
137 /* Save the semaphore handle for future use */
138 rmSemHandle[edma3Id] = initParam.rmSemHandle;
140 /* configuration structure for the Driver */
141 instanceConfig = &sampleInstInitConfig[edma3Id][dsp_num];
143 initParam.isMaster = TRUE;
144 /* Choose shadow region according to the DSP# */
145 initParam.regionId = (EDMA3_RM_RegionId)dsp_num;
146 /*Saving the regionId for using it in the sample_cs.c file */
147 region_id = (EDMA3_RM_RegionId)dsp_num;
148 /* Driver instance specific config NULL */
149 initParam.rmInstInitConfig = instanceConfig;
151 initParam.regionInitEnable = TRUE;
152 initParam.gblerrCbParams.gblerrCb = (EDMA3_RM_GblErrCallback)NULL;
153 initParam.gblerrCbParams.gblerrData = (void *)NULL;
155 /* Open the Driver Instance */
156 hEdmaResMgr = EDMA3_RM_open (edma3Id, (EDMA3_RM_Param *)&initParam,
157 &edma3Result);
158 }
160 #ifdef DMA_XBAR_AVAILABLE
161 {
162 if(hEdmaResMgr && (edma3Result == EDMA3_RM_SOK))
163 {
164 edma3Result = sampleInitXbarEvt(hEdmaResMgr, edma3Id);
165 }
166 }
167 #endif
168 if(hEdmaResMgr && (edma3Result == EDMA3_DRV_SOK))
169 {
170 /**
171 * Register Interrupt Handlers for various interrupts
172 * like transfer completion interrupt, CC error
173 * interrupt, TC error interrupts etc, if required.
174 */
175 registerEdma3Interrupts(edma3Id);
176 }
178 *errorCode = edma3Result;
179 return hEdmaResMgr;
180 }
182 /**
183 * \brief EDMA3 De-initialization
184 *
185 * This function removes the EDMA3 RM Instance and unregisters the
186 * interrupt handlers. It also deletes the RM Object.
187 *
188 * \return EDMA3_RM_SOK if success, else error code
189 */
190 EDMA3_RM_Result edma3deinit (unsigned int edma3Id, EDMA3_RM_Handle hEdmaResMgr)
191 {
192 EDMA3_RM_Result edma3Result = EDMA3_RM_SOK;
194 /* Unregister Interrupt Handlers first */
195 unregisterEdma3Interrupts(edma3Id);
197 /* Delete the semaphore */
198 edma3Result = edma3OsSemDelete (rmSemHandle[edma3Id]);
200 if (EDMA3_RM_SOK == edma3Result)
201 {
202 /* Make the semaphore handle as NULL. */
203 rmSemHandle[edma3Id] = NULL;
205 /* Now, close the EDMA3 RM Instance */
206 edma3Result = EDMA3_RM_close (hEdmaResMgr, NULL);
207 }
209 if (EDMA3_RM_SOK == edma3Result)
210 {
211 /* Now, delete the EDMA3 RM Object */
212 edma3Result = EDMA3_RM_delete (edma3Id, NULL);
213 }
215 return edma3Result;
216 }
218 /* End of File */