]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/edma3_lld.git/blob - packages/ti/sdo/edma3/drv/sample/src/sample_arm_init.c
Fixed C++ build warning for vayu libs
[keystone-rtos/edma3_lld.git] / packages / ti / sdo / edma3 / drv / sample / src / sample_arm_init.c
1 /*
2  * sample_init.c
3  *
4  * Sample Initialization for the EDMA3 Driver for BIOS 6 based applications.
5  * It 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>
42 #ifdef __TMS470__
43 #else
44 #include <ti/sysbios/family/c64p/EventCombiner.h>
45 #endif
47 #include <ti/sdo/edma3/drv/sample/bios6_edma3_drv_sample.h>
49 /** @brief EDMA3 Driver Instance specific Semaphore handle */
50 extern EDMA3_OS_Sem_Handle semHandle[];
52 /**  To Register the ISRs with the underlying OS, if required. */
53 extern void registerEdma3Interrupts (unsigned int edma3Id);
54 /**  To Unregister the ISRs with the underlying OS, if previously registered. */
55 extern void unregisterEdma3Interrupts (unsigned int edma3Id);
57 /* To find out the DSP# */
58 extern unsigned short determineProcId();
60 /**
61  * To check whether the global EDMA3 configuration is required or not.
62  * It should be done ONCE by any of the masters present in the system.
63  * This function checks whether the global configuration is required by the
64  * current master or not. In case of many masters, it should be done only
65  * by one of the masters. Hence this function will return TRUE only once
66  * and FALSE for all other masters. 
67  */
68 extern unsigned short isGblConfigRequired(unsigned int dspNum);
70 /**
71  * DSP instance number on which the executable is running. Its value is
72  * determined by reading the processor specific register DNUM.
73  */
74 unsigned int dsp_num;
76 /**
77  * Shadow Region on which the executable is runnig. Its value is populated
78  * with the DSP Instance Number here in this case.
79  */
80 unsigned int region_id;
82 /* Number of EDMA3 controllers present in the system */
83 extern const unsigned int numEdma3Instances;
85 /* External Global Configuration Structure */
86 extern EDMA3_DRV_GblConfigParams sampleEdma3GblCfgParams[];
88 /* External Instance Specific Configuration Structure */
89 extern EDMA3_DRV_InstanceInitConfig sampleInstInitConfig[][EDMA3_MAX_REGIONS];
91 #if (defined (CHIP_TI814X)||defined (CHIP_C6A811X))
92 extern EDMA3_DRV_Result sampleInitXbarEvt(EDMA3_DRV_Handle hEdma, unsigned int edma3Id);
93 #endif
95 /**
96  * \brief   EDMA3 Initialization
97  *
98  * This function initializes the EDMA3 Driver and registers the
99  * interrupt handlers.
100  *
101   * \return  EDMA3_DRV_SOK if success, else error code
102  */
103 EDMA3_DRV_Handle edma3init (unsigned int edma3Id, EDMA3_DRV_Result *errorCode)
104     {
105     EDMA3_DRV_Result edma3Result = EDMA3_DRV_E_INVALID_PARAM;
106     Semaphore_Params semParams;
107     EDMA3_DRV_GblConfigParams *globalConfig = NULL;
108     EDMA3_DRV_InstanceInitConfig *instanceConfig = NULL;
109         EDMA3_DRV_InitConfig initCfg;
110         EDMA3_RM_MiscParam miscParam;
111         EDMA3_DRV_Handle hEdma = NULL;
113         if ((edma3Id >= numEdma3Instances) || (errorCode == NULL))
114                 return hEdma;
116     /* DSP instance number */
117     dsp_num = determineProcId();
119         globalConfig = &sampleEdma3GblCfgParams[edma3Id];
121         /* Configure it as master, if required */
122         miscParam.isSlave = isGblConfigRequired(dsp_num);
123         edma3Result = EDMA3_DRV_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                 initCfg.drvSemHandle = NULL;
135                 edma3Result = edma3OsSemCreate(1, &semParams, &initCfg.drvSemHandle);
136                 }
138         if (edma3Result == EDMA3_DRV_SOK)
139                 {
140                 /* Save the semaphore handle for future use */
141                 semHandle[edma3Id] = initCfg.drvSemHandle;
143                 /* configuration structure for the Driver */
144                 instanceConfig = &sampleInstInitConfig[edma3Id][dsp_num];
146                 initCfg.isMaster = TRUE;
147                 /* Choose shadow region according to the DSP# */
148                 initCfg.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                 initCfg.drvInstInitConfig = instanceConfig;
154                 initCfg.gblerrCb = NULL;
155                 initCfg.gblerrData = NULL;
157                 /* Open the Driver Instance */
158                 hEdma = EDMA3_DRV_open (edma3Id, (const EDMA3_DRV_InitConfig *) &initCfg, &edma3Result);
159                 }
161 #if (defined (CHIP_TI814X)||defined (CHIP_C6A811X))
162         {
163         if(hEdma && (edma3Result == EDMA3_DRV_SOK))
164                 {
165                 edma3Result = sampleInitXbarEvt(hEdma, edma3Id);
166                 }
167         }
168 #endif
169         if(hEdma && (edma3Result == EDMA3_DRV_SOK))
170                 {
171                 /**
172                 * Register Interrupt Handlers for various interrupts
173                 * like transfer completion interrupt, CC error
174                 * interrupt, TC error interrupts etc, if required.
175                 */
176                 registerEdma3Interrupts(edma3Id);
177                 }
179         *errorCode = edma3Result;       
180         return hEdma;
181     }
184 /**
185  * \brief   EDMA3 De-initialization
186  *
187  * This function removes the EDMA3 Driver instance and unregisters the
188  * interrupt handlers.
189  *
190   * \return  EDMA3_DRV_SOK if success, else error code
191  */
192 EDMA3_DRV_Result edma3deinit (unsigned int edma3Id, EDMA3_DRV_Handle hEdma)
193     {
194     EDMA3_DRV_Result edma3Result = EDMA3_DRV_E_INVALID_PARAM;
196     /* Unregister Interrupt Handlers first */
197     unregisterEdma3Interrupts(edma3Id);
199     /* Delete the semaphore */
200     edma3Result = edma3OsSemDelete(semHandle[edma3Id]);
202     if (EDMA3_DRV_SOK == edma3Result )
203         {
204         /* Make the semaphore handle as NULL. */
205         semHandle[edma3Id] = NULL;
207         /* Now, close the EDMA3 Driver Instance */
208         edma3Result = EDMA3_DRV_close (hEdma, NULL);
209         }
211         if (EDMA3_DRV_SOK == edma3Result )
212         {
213         /* Now, delete the EDMA3 Driver Object */
214         edma3Result = EDMA3_DRV_delete (edma3Id, NULL);
215         }
217     return edma3Result;
218     }
220 /* End of File */