]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/blob - packages/ti/drv/dfe/src/dfefl/dfe_fl_cppDmaClose.c
dfe-lld: add to PDK
[processor-sdk/pdk.git] / packages / ti / drv / dfe / src / dfefl / dfe_fl_cppDmaClose.c
1 /********************************************************************
2 * Copyright (C) 2012-2013 Texas Instruments Incorporated.
3  * 
4  *  Redistribution and use in source and binary forms, with or without 
5  *  modification, are permitted provided that the following conditions 
6  *  are met:
7  *
8  *    Redistributions of source code must retain the above copyright 
9  *    notice, this list of conditions and the following disclaimer.
10  *
11  *    Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the 
13  *    documentation and/or other materials provided with the   
14  *    distribution.
15  *
16  *    Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
21  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
22  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
24  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
25  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
26  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
29  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
30  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32 */
33 /** @file dfe_fl_cppDmaClose.c
34  *
35  *  @path  $(CSLPATH)\src\ip\dfe
36  *
37  *  @brief 
38  *
39  *  Description
40  *  - 
41  *
42  */
44 #include <ti/drv/dfe/dfe_fl_cpp.h>
45 #include <ti/drv/dfe/dfe_fl_miscAux.h>
47 /** close prior opened dma */
48 /** ============================================================================
49  *   @n@b dfeFl_CppDmaClose
50  *
51  *   @b Description
52  *   @n Close prior opened Cpp/DMA channel, and free resources.
53  *
54  *   @b Arguments
55  *   @verbatim
56          hDma    CPP/DMA channel handle
57      @endverbatim
58  *
59  *   <b> Return Value </b>  None
60  *
61  *   <b> Pre Condition </b>
62  *   @n  valid CPP/DMA channel handle
63  *
64  *   <b> Post Condition </b>
65  *   @n  on-going DMA is aborted and the channel/trigger get freed.
66  *
67  *   @b Reads
68  *   @n  CPP/DMA resource manager table
69  *
70  *   @b Writes
71  *   @n  CPP/DMA resource manager table
72  *
73  *   @b Example
74  *   @verbatim
75         DfeFl_Status status;
76         DfeFl_CppDmaHandle hDma;
77         static DfeFl_CppResMgr myResMgr;
78         
79         memset(&myResMgr, 0, sizeof(myResMgr));
80         for(i = 0; i < DFE_FL_CPP_NUM_DISCRETE_TRIGGERS; i++)
81            myResMgr.discreteTrig[i] = DFE_FL_CPP_OPEN_ANY;
82            
83         hMisc = dfeFl_MiscOpen(...);
84         
85         // open channel#2 using EMBED mode, no triger destination.
86         hDma = dfeFl_CppDmaOpen(hMisc, 
87                    2,
88                    DFE_FL_CPP_DMA_MODE_EMBED,
89                    DFE_FL_CPP_OPEN_NONE,
90                    &myResMgr,
91                    &status);
92         if(status != DFE_FL_SOK)
93         {
94             printf("dfeFl_CppDmaOpen error %d\n", status);
95         }
97         // do DMA transfer here
98         
99         
100         // close
101         dfeFl_CppDmaClose(hDma);
102         
103      @endverbatim
104  * ===========================================================================
105  */
106 void dfeFl_CppDmaClose
108     DfeFl_CppDmaHandle hDma
111     if(hDma == NULL)
112         return;
113         
114     if(hDma->id < DFE_FL_CPP_NUM_DMA)
115     {
116         // make sure no more sync
117         dfeFl_CppDmaDismissSync(hDma);
118         
119         // make sure abort
120                 dfeFl_CppDmaAbort(hDma);
121             
122                 // wait till idle
123                 while(dfeFl_CppDmaGetBusy(hDma) > 0)
124                 {
125                         // spin
126                 }
127         
128         // disable DMA
129         dfeFl_MiscCppSetDmaMode(hDma->hMisc, hDma->id, DFE_FL_CPP_DMA_MODE_DISABLE);
130         // disable trigger 
131         if(hDma->iTrig < DFE_FL_CPP_NUM_DISCRETE_TRIGGERS)
132         {
133             dfeFl_MiscCppEnableDiscreteTrig(hDma->hMisc, hDma->iTrig, FALSE);
134            
135             // return trigger resource 
136             hDma->resMgr->discreteTrig[hDma->iTrig] = DFE_FL_CPP_OPEN_ANY;
137         }        
138         // return dma resource
139         CSL_FINSR(hDma->resMgr->dmaOpened, hDma->id, hDma->id, 0u);
140     }
141     
142     hDma->id = DFE_FL_CPP_OPEN_NONE;
143     hDma->mode = DFE_FL_CPP_DMA_MODE_DISABLE;
144     hDma->iTrig = DFE_FL_CPP_OPEN_NONE;
145     hDma->hMisc = NULL;
146     hDma->resMgr = NULL;