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