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