]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/edma3_lld.git/blob - packages/ti/sdo/edma3/rm/edma3_common.h
Misra C Fixes
[keystone-rtos/edma3_lld.git] / packages / ti / sdo / edma3 / rm / edma3_common.h
1 /*
2  * edma3_common.h
3  *
4  * EDMA3 common header providing generic defines/typedefs and debugging info.
5  *
6  * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
7  *
8  *
9  *  Redistribution and use in source and binary forms, with or without
10  *  modification, are permitted provided that the following conditions
11  *  are met:
12  *
13  *    Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  *
16  *    Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the
19  *    distribution.
20  *
21  *    Neither the name of Texas Instruments Incorporated nor the names of
22  *    its contributors may be used to endorse or promote products derived
23  *    from this software without specific prior written permission.
24  *
25  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  *
37 */
39 #ifndef EDMA3_COMMON_H_
40 #define EDMA3_COMMON_H_
42 /***************************************************************\
43 * Standard Definition Header File For Null Definition *
44 \***************************************************************/
45 #include <stddef.h>
47 /***************************************************************\
48 * Standard Definition Header File For Bool Datatype *
49 \***************************************************************/
50 #include <stdbool.h>
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
56 /** define to enable/disable Resource Manager debug messages*/
57 /* #define EDMA3_RM_DEBUG */
59 /** define to enable/disable EDMA3 Driver debug messages*/
60 /* #define EDMA3_DRV_DEBUG */
62 /** Debug mechanism used for Resource Manager */
63 #ifdef EDMA3_RM_DEBUG
64 #include <stdio.h>
65 #define EDMA3_RM_PRINTF printf
66 #endif
68 /** Debug mechanism used for EDMA Driver */
69 #ifdef EDMA3_DRV_DEBUG
70 #include <stdio.h>
71 #define EDMA3_DRV_PRINTF printf
72 #endif
74 /** Defines for boolean variables */
75 #ifndef TRUE
76   /** TRUE */
77   #define TRUE  (1U)
78   /** FALSE */
79   #define FALSE (0U)
80 #endif
82 /** EDMA3_RM Result - return value of a function  */
83 typedef int32_t             EDMA3_RM_Result;
84 /** EDMA3_DRV Result - return value of a function  */
85 typedef int32_t             EDMA3_DRV_Result;
86 /** EDMA3_Result - return value of a function for common functions of DRV and RM */
87 typedef int32_t             EDMA3_Result;
89 /** EDMA3 Resource Manager Result OK */
90 #define EDMA3_RM_SOK             (0)
91 /** EDMA3 Driver Result OK */
92 #define EDMA3_DRV_SOK            (0)
94 /**
95  * EDMA3 Resource Manager Handle.
96  * It will be returned from EDMA3_RM_open() and will be used to call
97  * other Resource Manager APIs.
98  */
99 typedef void    *EDMA3_RM_Handle;
100 /**
101  * EDMA3 Driver Handle.
102  * It will be returned from EDMA3_DRV_open() and will be used to call
103  * other EDMA3 Driver APIs.
104  */
105 typedef void    *EDMA3_DRV_Handle;
107 /**
108  * OS specific Semaphore Handle.
109  * Used to acquire/free the semaphore, used for sharing of resources
110  * among multiple users.
111  */
112 typedef void    *EDMA3_OS_Sem_Handle;
114 /** Blocking call without timeout */
115 #define EDMA3_OSSEM_NO_TIMEOUT    (-1)
117 /**
118  * Defines used to support the maximum resources supported
119  * by the EDMA3 controller. These are used to allocate the maximum
120  * memory for different data structures of the EDMA3 Driver and Resource
121  * Manager.
122  */
123 /** Maximum EDMA3 Controllers on the SoC */
124 #define EDMA3_MAX_EDMA3_INSTANCES               (5U)
125 /** Maximum DMA channels supported by the EDMA3 Controller */
126 #define EDMA3_MAX_DMA_CH                        (64U)
127 /** Maximum QDMA channels supported by the EDMA3 Controller */
128 #define EDMA3_MAX_QDMA_CH                       (8U)
129 /** Maximum PaRAM Sets supported by the EDMA3 Controller */
130 #define EDMA3_MAX_PARAM_SETS                    (512U)
131 /** Maximum Logical channels supported by the EDMA3 Package */
132 #define EDMA3_MAX_LOGICAL_CH                    (EDMA3_MAX_DMA_CH + \
133                                                  EDMA3_MAX_PARAM_SETS + \
134                                                  EDMA3_MAX_QDMA_CH)
135 /** Maximum TCCs (Interrupt Channels) supported by the EDMA3 Controller */
136 #define EDMA3_MAX_TCC                           (64U)
137 /** Maximum Event Queues supported by the EDMA3 Controller */
138 #define EDMA3_MAX_EVT_QUE                       (8U)
139 /** Maximum Transfer Controllers supported by the EDMA3 Controller */
140 #define EDMA3_MAX_TC                            (8U)
141 /** Maximum Shadow Regions supported by the EDMA3 Controller */
142 #define EDMA3_MAX_REGIONS                       (8U)
144 /**
145  * Maximum Words (4-bytes region) required for the book-keeping information
146  * specific to the maximum possible DMA channels.
147  */
148 #define EDMA3_MAX_DMA_CHAN_DWRDS                (EDMA3_MAX_DMA_CH / 32U)
150 /**
151  * Maximum Words (4-bytes region) required for the book-keeping information
152  * specific to the maximum possible QDMA channels.
153  */
154 #define EDMA3_MAX_QDMA_CHAN_DWRDS               (1U)
156 /**
157  * Maximum Words (4-bytes region) required for the book-keeping information
158  * specific to the maximum possible PaRAM Sets.
159  */
160 #define EDMA3_MAX_PARAM_DWRDS                   (EDMA3_MAX_PARAM_SETS / 32U)
162 /**
163  * Maximum Words (4-bytes region) required for the book-keeping information
164  * specific to the maximum possible TCCs.
165  */
166 #define EDMA3_MAX_TCC_DWRDS                     (EDMA3_MAX_TCC / 32U)
168 /**
169  * EDMA3 ISRs which need to be registered with the underlying OS by the user
170  * (Not all TC error ISRs need to be registered, register only for the
171  * available Transfer Controllers).
172  */
173 /**  EDMA3 Completion Handler ISR Routine */
174 extern void lisrEdma3ComplHandler0 (uint32_t edma3InstanceId);
176 /**  EDMA3 CC Error Interrupt Handler ISR Routine */
177 extern void lisrEdma3CCErrHandler0 (uint32_t edma3InstanceId);
179 /**  EDMA3 TC0 Error Interrupt Handler ISR Routine */
180 extern void lisrEdma3TC0ErrHandler0(uint32_t edma3InstanceId);
181 /**  EDMA3 TC1 Error Interrupt Handler ISR Routine */
182 extern void lisrEdma3TC1ErrHandler0(uint32_t edma3InstanceId);
183 /**  EDMA3 TC2 Error Interrupt Handler ISR Routine */
184 extern void lisrEdma3TC2ErrHandler0(uint32_t edma3InstanceId);
185 /**  EDMA3 TC3 Error Interrupt Handler ISR Routine */
186 extern void lisrEdma3TC3ErrHandler0(uint32_t edma3InstanceId);
187 /**  EDMA3 TC4 Error Interrupt Handler ISR Routine */
188 extern void lisrEdma3TC4ErrHandler0(uint32_t edma3InstanceId);
189 /**  EDMA3 TC5 Error Interrupt Handler ISR Routine */
190 extern void lisrEdma3TC5ErrHandler0(uint32_t edma3InstanceId);
191 /**  EDMA3 TC6 Error Interrupt Handler ISR Routine */
192 extern void lisrEdma3TC6ErrHandler0(uint32_t edma3InstanceId);
193 /**  EDMA3 TC7 Error Interrupt Handler ISR Routine */
194 extern void lisrEdma3TC7ErrHandler0(uint32_t edma3InstanceId);
196 /**
197  * Defines for the level of OS protection needed when calling
198  * edma3OsProtectEntry()
199  */
200 /** Protection from All Interrupts required */
201 #define EDMA3_OS_PROTECT_INTERRUPT                          1
202 /** Protection from scheduling required */
203 #define EDMA3_OS_PROTECT_SCHEDULER                          2
204 /** Protection from EDMA3 Transfer Completion Interrupt required */
205 #define EDMA3_OS_PROTECT_INTERRUPT_XFER_COMPLETION          3
206 /** Protection from EDMA3 CC Error Interrupt required */
207 #define EDMA3_OS_PROTECT_INTERRUPT_CC_ERROR                 4
208 /** Protection from EDMA3 TC Error Interrupt required */
209 #define EDMA3_OS_PROTECT_INTERRUPT_TC_ERROR                 5
211 /**
212  * Critical section entry and exit functions (OS dependent) should be
213  * implemented by the application for proper linking with the EDMA3 Driver
214  * and/or EDMA3 Resource Manager. Without the definitions being provided,
215  * the image won\92t get linked properly.
216  *
217  * It is possible that for some regions of code, user needs ultimate
218  * degree of protection where some or all external interrupts are blocked,
219  * essentially locking out the CPU exclusively for the critical
220  * section of code. On the other hand, user may wish to merely avoid
221  * thread or task switch from occuring inside said region of code,
222  * but he may wish to entertain ISRs to run if so required.
223  *
224  * Depending on the underlying OS, the number of levels of protection
225  * offered may vary. At the least, these basic levels of protection are
226  * supported --
227  * - EDMA3_OS_PROTECT_INTERRUPT - Mask interrupts globally. This has
228  *   real-time implications and must be used with descretion.
230  * - EDMA3_OS_PROTECT_SCHEDULER - Only turns off Kernel scheduler
231  *   completely, but still allows h/w interrupts from being serviced.
233  * - EDMA3_OS_PROTECT_INTERRUPT_XFER_COMPLETION - Mask EDMA3 Transfer
234       Completion Interrupt.
236  * - EDMA3_OS_PROTECT_INTERRUPT_CC_ERROR - Mask EDMA3 CC Error Interrupt.
238  * - EDMA3_OS_PROTECT_INTERRUPT_TC_ERROR - Mask EDMA3 TC Error Interrupt.
240  * These APIs should be mandatorily implemented ONCE by the global
241  * initialization routine or by the user itself.
242  */
244 /**
245  *  \brief  EDMA3 OS Protect Entry
246  *
247  *      This function saves the current state of protection in 'intState'
248  *      variable passed by caller, if the protection level is
249  *      EDMA3_OS_PROTECT_INTERRUPT. It then applies the requested level of
250  *      protection.
251  *      For EDMA3_OS_PROTECT_INTERRUPT_XFER_COMPLETION and
252  *      EDMA3_OS_PROTECT_INTERRUPT_CC_ERROR, variable 'intState' is ignored,
253  *      and the requested interrupt is disabled.
254  *      For EDMA3_OS_PROTECT_INTERRUPT_TC_ERROR, '*intState' specifies the
255  *      Transfer Controller number whose interrupt needs to be disabled.
256  *
257  * \param   edma3InstanceId is EDMA3 hardware instance id.
258  * \param   level is numeric identifier of the desired degree of protection.
259  * \param   intState is memory location where current state of protection is
260  *      saved for future use while restoring it via edma3OsProtectExit() (Only
261  *      for EDMA3_OS_PROTECT_INTERRUPT protection level).
262  *
263  * \return  None
264  */
265 extern void edma3OsProtectEntry (uint32_t edma3InstanceId,
266                                                                                 int32_t level,
267                                                                                 uint32_t *intState);
269 /**
270  *  \brief  EDMA3 OS Protect Exit
271  *
272  *      This function undoes the protection enforced to original state
273  *      as is specified by the variable 'intState' passed, if the protection
274  *      level is EDMA3_OS_PROTECT_INTERRUPT.
275  *      For EDMA3_OS_PROTECT_INTERRUPT_XFER_COMPLETION and
276  *      EDMA3_OS_PROTECT_INTERRUPT_CC_ERROR, variable 'intState' is ignored,
277  *      and the requested interrupt is enabled.
278  *      For EDMA3_OS_PROTECT_INTERRUPT_TC_ERROR, 'intState' specifies the
279  *      Transfer Controller number whose interrupt needs to be enabled.
280  *
281  * \param   edma3InstanceId is EDMA3 hardware instance id.
282  * \param   level is numeric identifier of the desired degree of protection.
283  * \param   intState is original state of protection at time when the
284  *      corresponding edma3OsProtectEntry() was called (Only
285  *      for EDMA3_OS_PROTECT_INTERRUPT protection level).
286  *
287  * \return  None
288  */
289 extern void edma3OsProtectExit (uint32_t edma3InstanceId,
290                                                                                 int32_t level,
291                                                                                 uint32_t intState);
293 /**
294  * Counting Semaphore related functions (OS dependent) should be
295  * implemented by the application for proper linking with the EDMA3
296  * Driver and Resource Manager. The EDMA3 Resource Manager
297  * uses these functions for proper sharing of resources (among various users)
298  * and assume the implementation of these functions
299  * to be provided by the application. Without the definitions being provided,
300  * the image won\92t get linked properly.
301  */
303 /**
304  *  \brief  EDMA3 OS Semaphore Take
305  *
306  *      This function takes a semaphore token if available.
307  *      If a semaphore is unavailable, it blocks currently
308  *      running thread in wait (for specified duration) for
309  *      a free semaphore.
310  *
311  * \param   hSem [IN] is the handle of the specified semaphore
312  * \param   mSecTimeout [IN] is wait time in milliseconds
313  *
314  * \return  EDMA3_DRV_Result if successful else a suitable error code
315  */
316 extern EDMA3_Result edma3OsSemTake (EDMA3_OS_Sem_Handle hSem,
317                                         int32_t mSecTimeout);
319 /**
320  *  \brief  EDMA3 OS Semaphore Give
321  *
322  *      This function gives or relinquishes an already
323  *      acquired semaphore token
324  *
325  * \param   hSem [IN] is the handle of the specified semaphore
326  *
327  * \return  EDMA3_DRV_Result if successful else a suitable error code
328  */
329 extern EDMA3_Result edma3OsSemGive(EDMA3_OS_Sem_Handle hSem);
331 #ifdef __cplusplus
333 #endif /* extern "C" */
335 #endif  /* _EDMA3_COMMON_H_ */