]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/mcbsp-lld.git/blob - example/k2g/MCBSPDigLpbk/sample_init.c
PRSDK-3513 Removed Driver source files refernece from Examples
[keystone-rtos/mcbsp-lld.git] / example / k2g / MCBSPDigLpbk / sample_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-2012 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 #include <ti/sysbios/family/c64p/EventCombiner.h>
44 #include "bios6_edma3_drv_sample.h"
46 /** @brief EDMA3 Driver Instance specific Semaphore handle */
47 extern EDMA3_OS_Sem_Handle semHandle[];
49 /**  To Register the ISRs with the underlying OS, if required. */
50 extern void registerEdma3Interrupts (unsigned int edma3Id);
51 /**  To Unregister the ISRs with the underlying OS, if previously registered. */
52 extern void unregisterEdma3Interrupts (unsigned int edma3Id);
54 /* To find out the DSP# */
55 extern unsigned short determineProcId();
57 /**
58  * To check whether the global EDMA3 configuration is required or not.
59  * It should be done ONCE by any of the masters present in the system.
60  * This function checks whether the global configuration is required by the
61  * current master or not. In case of many masters, it should be done only
62  * by one of the masters. Hence this function will return TRUE only once
63  * and FALSE for all other masters. 
64  */
65 extern unsigned short isGblConfigRequired(unsigned int dspNum);
67 /**
68  * DSP instance number on which the executable is running. Its value is
69  * determined by reading the processor specific register DNUM.
70  */
71 unsigned int dsp_num;
73 /**
74  * Shadow Region on which the executable is runnig. Its value is populated
75  * with the DSP Instance Number here in this case.
76  */
77 unsigned int region_id;
79 /* Number of EDMA3 controllers present in the system */
80 extern const unsigned int numEdma3Instances;
82 /* External Global Configuration Structure */
83 extern EDMA3_DRV_GblConfigParams sampleEdma3GblCfgParams[];
85 /* External Instance Specific Configuration Structure */
86 extern EDMA3_DRV_InstanceInitConfig sampleInstInitConfig[][EDMA3_MAX_REGIONS];
88 #if defined (CHIP_TI814X)
89 extern EDMA3_DRV_Result sampleInitXbarEvt(EDMA3_DRV_Handle hEdma, unsigned int edma3Id);
90 #endif
92 /**
93  * \brief   EDMA3 Initialization
94  *
95  * This function initializes the EDMA3 Driver and registers the
96  * interrupt handlers.
97  *
98   * \return  EDMA3_DRV_SOK if success, else error code
99  */
100 EDMA3_DRV_Handle edma3init (unsigned int edma3Id, EDMA3_DRV_Result *errorCode)
101     {
102     EDMA3_DRV_Result edma3Result = EDMA3_DRV_E_INVALID_PARAM;
103     Semaphore_Params semParams;
104     EDMA3_DRV_GblConfigParams *globalConfig = NULL;
105         EDMA3_DRV_InitConfig initCfg;
106         EDMA3_RM_MiscParam miscParam;
107         EDMA3_DRV_Handle hEdma = NULL;
109         if ((edma3Id >= numEdma3Instances) || (errorCode == NULL))
110                 return hEdma;
112     /* DSP instance number */
113     dsp_num = determineProcId();
114 //    dsp_num = 0; /* selection of region ID */
116         globalConfig = &sampleEdma3GblCfgParams[edma3Id];
118         /* Configure it as master, if required */
119         miscParam.isSlave = isGblConfigRequired(dsp_num);
120         edma3Result = EDMA3_DRV_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                 initCfg.drvSemHandle = NULL;
132                 edma3Result = edma3OsSemCreate(1, &semParams, &initCfg.drvSemHandle);
133                 }
135         if (edma3Result == EDMA3_DRV_SOK)
136                 {
137                 /* Save the semaphore handle for future use */
138                 semHandle[edma3Id] = initCfg.drvSemHandle;
140         /* Driver instance specific config NULL */
141                 initCfg.drvInstInitConfig = NULL;
143 #ifndef EDMA3_DRV_USE_DEF_RM_CFG
144         /* Hook for running examples with default RM config */
145                 /* configuration structure for the Driver */
146                 initCfg.drvInstInitConfig = &sampleInstInitConfig[edma3Id][dsp_num];
147 #endif
149                 initCfg.isMaster = TRUE;
150                 /* Choose shadow region according to the DSP# */
151                 initCfg.regionId = (EDMA3_RM_RegionId)dsp_num;
152                 /*Saving the regionId for using it in the sample_cs.c file */
153                 region_id = (EDMA3_RM_RegionId)dsp_num;
154                 /* Driver instance specific config NULL */
156                 initCfg.gblerrCb = NULL;
157                 initCfg.gblerrData = NULL;
159                 /* Open the Driver Instance */
160                 hEdma = EDMA3_DRV_open (edma3Id, (void *) &initCfg, &edma3Result);
161                 }
163 #if defined (CHIP_TI814X)
164         {
165         if(hEdma && (edma3Result == EDMA3_DRV_SOK))
166                 {
167                 edma3Result = sampleInitXbarEvt(hEdma, edma3Id);
168                 }
169         }
170 #endif
171         if(hEdma && (edma3Result == EDMA3_DRV_SOK))
172                 {
173                 /**
174                 * Register Interrupt Handlers for various interrupts
175                 * like transfer completion interrupt, CC error
176                 * interrupt, TC error interrupts etc, if required.
177                 */
178                 registerEdma3Interrupts(edma3Id);
179                 }
181         *errorCode = edma3Result;       
182         return hEdma;
183     }
186 /**
187  * \brief   EDMA3 De-initialization
188  *
189  * This function removes the EDMA3 Driver instance and unregisters the
190  * interrupt handlers.
191  *
192   * \return  EDMA3_DRV_SOK if success, else error code
193  */
194 EDMA3_DRV_Result edma3deinit (unsigned int edma3Id, EDMA3_DRV_Handle hEdma)
195     {
196     EDMA3_DRV_Result edma3Result = EDMA3_DRV_E_INVALID_PARAM;
198     /* Unregister Interrupt Handlers first */
199     unregisterEdma3Interrupts(edma3Id);
201     /* Delete the semaphore */
202     edma3Result = edma3OsSemDelete(semHandle[edma3Id]);
204     if (EDMA3_DRV_SOK == edma3Result )
205         {
206         /* Make the semaphore handle as NULL. */
207         semHandle[edma3Id] = NULL;
209         /* Now, close the EDMA3 Driver Instance */
210         edma3Result = EDMA3_DRV_close (hEdma, NULL);
211         }
213         if (EDMA3_DRV_SOK == edma3Result )
214         {
215         /* Now, delete the EDMA3 Driver Object */
216         edma3Result = EDMA3_DRV_delete (edma3Id, NULL);
217         }
219     return edma3Result;
220     }
222 /* End of File */