Minor fixes in default configuration files in RM
[keystone-rtos/edma3_lld.git] / packages / ti / sdo / edma3 / rm / sample / src / bios6_edma3_rm_sample_init.c
1 /*******************************************************************************
2 **+--------------------------------------------------------------------------+**
3 **|                            ****                                          |**
4 **|                            ****                                          |**
5 **|                            ******o***                                    |**
6 **|                      ********_///_****                                   |**
7 **|                      ***** /_//_/ ****                                   |**
8 **|                       ** ** (__/ ****                                    |**
9 **|                           *********                                      |**
10 **|                            ****                                          |**
11 **|                            ***                                           |**
12 **|                                                                          |**
13 **|         Copyright (c) 1998-2006 Texas Instruments Incorporated           |**
14 **|                        ALL RIGHTS RESERVED                               |**
15 **|                                                                          |**
16 **| Permission is hereby granted to licensees of Texas Instruments           |**
17 **| Incorporated (TI) products to use this computer program for the sole     |**
18 **| purpose of implementing a licensee product based on TI products.         |**
19 **| No other rights to reproduce, use, or disseminate this computer          |**
20 **| program, whether in part or in whole, are granted.                       |**
21 **|                                                                          |**
22 **| TI makes no representation or warranties with respect to the             |**
23 **| performance of this computer program, and specifically disclaims         |**
24 **| any responsibility for any damages, special or consequential,            |**
25 **| connected with the use of this program.                                  |**
26 **|                                                                          |**
27 **+--------------------------------------------------------------------------+**
28 *******************************************************************************/
30 /** \file   bios6_edma3_rm_sample_init.c
32     \brief  Sample Initialization for the EDMA3 RM for BIOS 6 based
33                 applications. It should be MANDATORILY done once before EDMA3 usage.
35     (C) Copyright 2006, Texas Instruments, Inc
37     \version    1.0   Anuj Aggarwal         - Created
39  */
41 #include <ti/sysbios/hal/Hwi.h>
42 #include <ti/sysbios/ipc/Semaphore.h>
43 #include <ti/sysbios/family/c64p/EventCombiner.h>
45 #include <ti/sdo/edma3/rm/sample/bios6_edma3_rm_sample.h>
47 /** @brief EDMA3 RM Handle, used to call all the RM APIs */
48 EDMA3_RM_Handle hEdmaResMgr = NULL;
50 /** @brief EDMA3 RM Instance specific Semaphore handle */
51 static EDMA3_OS_Sem_Handle rmSemHandle = NULL;
54 /**
55   * EDMA3 TC ISRs which need to be registered with the underlying OS by the user
56   * (Not all TC error ISRs need to be registered, register only for the
57   * available Transfer Controllers).
58   */
59 void (*ptrEdma3TcIsrHandler[EDMA3_MAX_TC])(unsigned int arg) =
60                                                 {
61                                                 &lisrEdma3TC0ErrHandler0,
62                                                 &lisrEdma3TC1ErrHandler0,
63                                                 &lisrEdma3TC2ErrHandler0,
64                                                 &lisrEdma3TC3ErrHandler0,
65                                                 &lisrEdma3TC4ErrHandler0,
66                                                 &lisrEdma3TC5ErrHandler0,
67                                                 &lisrEdma3TC6ErrHandler0,
68                                                 &lisrEdma3TC7ErrHandler0,
69                                                 };
72 /**  To Register the ISRs with the underlying OS, if required. */
73 static void registerEdma3Interrupts (void);
74 /**  To Unregister the ISRs with the underlying OS, if previously registered. */
75 static void unregisterEdma3Interrupts (void);
77 /* External Global Configuration Structure */
78 extern EDMA3_RM_GblConfigParams sampleEdma3GblCfgParams;
80 /* External Instance Specific Configuration Structure */
81 extern EDMA3_RM_InstanceInitConfig sampleInstInitConfig;
84 /**
85  * \brief   EDMA3 Initialization
86  *
87  * This function initializes the EDMA3 RM and registers the
88  * interrupt handlers.
89  *
90   * \return  EDMA3_RM_SOK if success, else error code
91  */
92  EDMA3_RM_Result edma3init (void)
93     {
94     unsigned int edma3InstanceId = 0;
95     EDMA3_RM_Param initParam;
96     EDMA3_RM_Result    edma3Result = EDMA3_RM_SOK;
97     Semaphore_Params semParams;
98     EDMA3_RM_MiscParam miscParam;
100     if (NULL == hEdmaResMgr)
101         {
102         /* Configuration structure for the RM */
103         initParam.regionId              = (EDMA3_RM_RegionId)1u;
104         initParam.isMaster = TRUE;
105         initParam.rmInstInitConfig = &sampleInstInitConfig;
106         initParam.rmSemHandle = NULL;
107         initParam.regionInitEnable      = TRUE;
108         initParam.gblerrCbParams.gblerrCb   = (EDMA3_RM_GblErrCallback)NULL;
109         initParam.gblerrCbParams.gblerrData = (void *)NULL;
111         miscParam.isSlave = FALSE;
113         /* Create EDMA3 RM Object first. */
114         edma3Result = EDMA3_RM_create(edma3InstanceId,
115                                         (EDMA3_RM_GblConfigParams *)&sampleEdma3GblCfgParams,
116                                         (void *)&miscParam);
118         if (edma3Result != EDMA3_RM_SOK)
119             {
120 #ifdef EDMA3_RM_DEBUG
121             EDMA3_RM_PRINTF("edma3init: EDMA3_RM_create FAILED\r\n");
122 #endif
123             }
124         else
125             {
126             /**
127               * RM Object created successfully.
128               * Create a semaphore now for RM instance.
129               */
130                         Semaphore_Params_init(&semParams);
132             edma3Result = edma3OsSemCreate(1, &semParams, &initParam.rmSemHandle );
133             if (edma3Result != EDMA3_RM_SOK)
134                 {
135 #ifdef EDMA3_RM_DEBUG
136                 EDMA3_RM_PRINTF("edma3init: edma3OsSemCreate FAILED\r\n");
137 #endif
138                 }
139             else
140                 {
141                 /* Save the semaphore handle for future use */
142                 rmSemHandle = initParam.rmSemHandle;
144                 /* Open the RM Instance */
145                 hEdmaResMgr = EDMA3_RM_open (edma3InstanceId, (EDMA3_RM_Param *)&initParam, &edma3Result);
147                 if(NULL == hEdmaResMgr)
148                     {
149 #ifdef EDMA3_RM_DEBUG
150                     EDMA3_RM_PRINTF("edma3init: EDMA3_RM_open FAILED\r\n");
151 #endif
152                     }
153                 else
154                     {
155                     /**
156                      * Register Interrupt Handlers for various interrupts
157                      * like transfer completion interrupt, CC error
158                      * interrupt, TC error interrupts etc, if required.
159                      */
160                     registerEdma3Interrupts();
161                     }
162                 }
163             }
164         }
165     else
166         {
167         /* EDMA3 RM already initialized, no need to do that again. */
168 #ifdef EDMA3_RM_DEBUG
169         EDMA3_RM_PRINTF("edma3init: EDMA3 RM Already Initialized...Init failed\r\n");
170 #endif
171         edma3Result = EDMA3_RM_E_INVALID_STATE;
172         }
174      return edma3Result;
175     }
178 /**  To Register the ISRs with the underlying OS, if required. */
179 static void registerEdma3Interrupts (void)
180     {
181         static UInt32 cookie = 0;
182     unsigned int numTc = 0;
184     /* Disabling the global interrupts */
185     cookie = Hwi_disable();
187     /* Enable the Xfer Completion Event Interrupt */
188     EventCombiner_dispatchPlug(ccXferCompInt, (EventCombiner_FuncPtr)(&lisrEdma3ComplHandler0),
189                                                 NULL, 0);
190     EventCombiner_enableEvent(ccXferCompInt);
192     /* Enable the CC Error Event Interrupt */
193     EventCombiner_dispatchPlug(ccErrorInt, (EventCombiner_FuncPtr)(&lisrEdma3CCErrHandler0),
194                                                                 NULL, 0);
195     EventCombiner_enableEvent(ccErrorInt);
197     /* Enable the TC Error Event Interrupt, according to the number of TCs. */
198     while (numTc < numEdma3Tc)
199             {
200         EventCombiner_dispatchPlug(tcErrorInt[numTc],
201                             (EventCombiner_FuncPtr)(ptrEdma3TcIsrHandler[numTc]),
202                             NULL, 0);
203         EventCombiner_enableEvent(tcErrorInt[numTc]);
204         numTc++;
205         }
208    /**
209     * Enabling the HWI_ID.
210     * EDMA3 interrupts (transfer completion, CC error etc.)
211     * correspond to different ECM events (SoC specific). These ECM events come
212     * under ECM block XXX (handling those specific ECM events). Normally, block
213     * 0 handles events 4-31 (events 0-3 are reserved), block 1 handles events
214     * 32-63 and so on. This ECM block XXX (or interrupt selection number XXX)
215     * is mapped to a specific HWI_INT YYY in the tcf file. So to enable this
216     * mapped HWI_INT YYY, one should use the corresponding bitmask in the
217     * API C64_enableIER(), in which the YYY bit is SET.
218     */
219         Hwi_enableInterrupt(hwIntXferComp);
220         Hwi_enableInterrupt(hwIntCcErr);
221         Hwi_enableInterrupt(hwIntTcErr);
223     /* Restore interrupts */
224     Hwi_restore(cookie);
225     }
228 /**
229  * \brief   EDMA3 De-initialization
230  *
231  * This function removes the EDMA3 RM Instance and unregisters the
232  * interrupt handlers. It also deletes the RM  Object.
233  *
234   * \return  EDMA3_RM_SOK if success, else error code
235  */
236  EDMA3_RM_Result edma3deinit (void)
237     {
238     unsigned int edmaInstanceId = 0;
239     EDMA3_RM_Result    edma3Result = EDMA3_RM_SOK;
241     /* Unregister Interrupt Handlers first */
242     unregisterEdma3Interrupts();
244     /* Delete the semaphore */
245     edma3Result = edma3OsSemDelete (rmSemHandle);
246     if (EDMA3_RM_SOK != edma3Result )
247         {
248 #ifdef EDMA3_RM_DEBUG
249         EDMA3_RM_PRINTF("edma3deinit: edma3OsSemDelete FAILED\r\n");
250 #endif
251         }
252     else
253         {
254         /* Make the semaphore handle as NULL. */
255         rmSemHandle = NULL;
257         /* Now, close the EDMA3 RM Instance */
258         edma3Result = EDMA3_RM_close (hEdmaResMgr, NULL);
259         if (EDMA3_RM_SOK != edma3Result )
260             {
261 #ifdef EDMA3_RM_DEBUG
262             EDMA3_RM_PRINTF("edma3deinit: EDMA3_RM_close FAILED\r\n");
263 #endif
264             }
265         else
266             {
267             /* Make the RM handle as NULL. */
268             hEdmaResMgr = NULL;
270             /* Now, delete the EDMA3 RM Object */
271             edma3Result = EDMA3_RM_delete (edmaInstanceId, NULL);
272             if (EDMA3_RM_SOK != edma3Result )
273                 {
274 #ifdef EDMA3_RM_DEBUG
275                 EDMA3_RM_PRINTF("edma3deinit: EDMA3_RM_delete FAILED\r\n");
276 #endif
277                 }
278             else
279                 {
280 #ifdef EDMA3_RM_DEBUG
281                 EDMA3_RM_PRINTF("edma3deinit: EDMA3 Deinitialization" \
282                                     " Completed...\r\n");
283 #endif
284                 }
285             }
286         }
288     return edma3Result;
289     }
292 /**  To Unregister the ISRs with the underlying OS, if previously registered. */
293 static void unregisterEdma3Interrupts (void)
294     {
295         static UInt32 cookie = 0;
296     unsigned int numTc = 0;
298     /* Disabling the global interrupts */
299     cookie = Hwi_disable();
301     /* Disable the Xfer Completion Event Interrupt */
302         EventCombiner_disableEvent(ccXferCompInt);
304     /* Disable the CC Error Event Interrupt */
305         EventCombiner_disableEvent(ccErrorInt);
307     /* Enable the TC Error Event Interrupt, according to the number of TCs. */
308     while (numTc < numEdma3Tc)
309     {
310         EventCombiner_disableEvent(tcErrorInt[numTc]);
311         numTc++;
312     }
314     /* Restore interrupts */
315     Hwi_restore(cookie);
316     }
318 /* End of File */