1aacce4f2a98bbed951764f03e0db6da18b90311
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 /**\r
89 * \brief EDMA3 Initialization\r
90 *\r
91 * This function initializes the EDMA3 RM and registers the\r
92 * interrupt handlers.\r
93 *\r
94 * \return EDMA3_RM_SOK if success, else error code\r
95 */\r
96 EDMA3_RM_Handle edma3init (unsigned int edma3Id, EDMA3_RM_Result *errorCode)\r
97 {\r
98 EDMA3_RM_Param initParam;\r
99 EDMA3_RM_Result edma3Result = EDMA3_RM_SOK;\r
100 Semaphore_Params semParams;\r
101 EDMA3_RM_MiscParam miscParam;\r
102 EDMA3_RM_GblConfigParams *globalConfig = NULL;\r
103 EDMA3_RM_InstanceInitConfig *instanceConfig = NULL;\r
104 EDMA3_RM_Handle hEdmaResMgr = NULL;\r
105 \r
106 if ((edma3Id >= numEdma3Instances) || (errorCode == NULL))\r
107 return hEdmaResMgr;\r
108 \r
109 /* DSP instance number */\r
110 dsp_num = determineProcId();\r
111 \r
112 globalConfig = &sampleEdma3GblCfgParams[edma3Id];\r
113 \r
114 /* Configure it as master, if required */\r
115 miscParam.isSlave = isGblConfigRequired(dsp_num);\r
116 \r
117 edma3Result = EDMA3_RM_create (edma3Id, globalConfig ,\r
118 (void *)&miscParam);\r
119 \r
120 if (edma3Result == EDMA3_DRV_SOK)\r
121 {\r
122 /**\r
123 * Driver Object created successfully.\r
124 * Create a semaphore now for driver instance.\r
125 */\r
126 Semaphore_Params_init(&semParams);\r
127 \r
128 initParam.rmSemHandle = NULL;\r
129 edma3Result = edma3OsSemCreate(1, &semParams, &initParam.rmSemHandle);\r
130 }\r
131 \r
132 if (edma3Result == EDMA3_DRV_SOK)\r
133 {\r
134 /* Save the semaphore handle for future use */\r
135 rmSemHandle[edma3Id] = initParam.rmSemHandle;\r
136 \r
137 /* configuration structure for the Driver */\r
138 instanceConfig = &sampleInstInitConfig[edma3Id][dsp_num];\r
139 \r
140 initParam.isMaster = TRUE;\r
141 /* Choose shadow region according to the DSP# */\r
142 initParam.regionId = (EDMA3_RM_RegionId)dsp_num;\r
143 /*Saving the regionId for using it in the sample_cs.c file */\r
144 region_id = (EDMA3_RM_RegionId)dsp_num;\r
145 /* Driver instance specific config NULL */\r
146 initParam.rmInstInitConfig = instanceConfig;\r
147 \r
148 initParam.regionInitEnable = TRUE;\r
149 initParam.gblerrCbParams.gblerrCb = (EDMA3_RM_GblErrCallback)NULL;\r
150 initParam.gblerrCbParams.gblerrData = (void *)NULL;\r
151 \r
152 /* Open the Driver Instance */\r
153 hEdmaResMgr = EDMA3_RM_open (edma3Id, (EDMA3_RM_Param *)&initParam, \r
154 &edma3Result);\r
155 }\r
156 \r
157 #if defined (CHIP_TI814X)\r
158 {\r
159 if(hEdmaResMgr && (edma3Result == EDMA3_RM_SOK))\r
160 {\r
161 edma3Result = sampleInitXbarEvt(hEdmaResMgr, edma3Id);\r
162 }\r
163 }\r
164 #endif \r
165 if(hEdmaResMgr && (edma3Result == EDMA3_DRV_SOK))\r
166 {\r
167 /**\r
168 * Register Interrupt Handlers for various interrupts\r
169 * like transfer completion interrupt, CC error\r
170 * interrupt, TC error interrupts etc, if required.\r
171 */\r
172 registerEdma3Interrupts(edma3Id);\r
173 }\r
174 \r
175 *errorCode = edma3Result; \r
176 return hEdmaResMgr;\r
177 }\r
178 \r
179 /**\r
180 * \brief EDMA3 De-initialization\r
181 *\r
182 * This function removes the EDMA3 RM Instance and unregisters the\r
183 * interrupt handlers. It also deletes the RM Object.\r
184 *\r
185 * \return EDMA3_RM_SOK if success, else error code\r
186 */\r
187 EDMA3_RM_Result edma3deinit (unsigned int edma3Id, EDMA3_RM_Handle hEdmaResMgr)\r
188 {\r
189 EDMA3_RM_Result edma3Result = EDMA3_RM_SOK;\r
190 \r
191 /* Unregister Interrupt Handlers first */\r
192 unregisterEdma3Interrupts(edma3Id);\r
193 \r
194 /* Delete the semaphore */\r
195 edma3Result = edma3OsSemDelete (rmSemHandle[edma3Id]);\r
196 \r
197 if (EDMA3_RM_SOK == edma3Result)\r
198 {\r
199 /* Make the semaphore handle as NULL. */\r
200 rmSemHandle[edma3Id] = NULL;\r
201 \r
202 /* Now, close the EDMA3 RM Instance */\r
203 edma3Result = EDMA3_RM_close (hEdmaResMgr, NULL);\r
204 }\r
205 \r
206 if (EDMA3_RM_SOK == edma3Result)\r
207 {\r
208 /* Now, delete the EDMA3 RM Object */\r
209 edma3Result = EDMA3_RM_delete (edma3Id, NULL);\r
210 }\r
211 \r
212 return edma3Result;\r
213 }\r
214 \r
215 /* End of File */\r
216 \r