Vision Apps User Guide
app_udma_utils.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2018 Texas Instruments Incorporated
4  *
5  * All rights reserved not granted herein.
6  *
7  * Limited License.
8  *
9  * Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive
10  * license under copyrights and patents it now or hereafter owns or controls to make,
11  * have made, use, import, offer to sell and sell ("Utilize") this software subject to the
12  * terms herein. With respect to the foregoing patent license, such license is granted
13  * solely to the extent that any such patent is necessary to Utilize the software alone.
14  * The patent license shall not apply to any combinations which include this software,
15  * other than combinations with devices manufactured by or for TI ("TI Devices").
16  * No hardware patent is licensed hereunder.
17  *
18  * Redistributions must preserve existing copyright notices and reproduce this license
19  * (including the above copyright notice and the disclaimer and (if applicable) source
20  * code license limitations below) in the documentation and/or other materials provided
21  * with the distribution
22  *
23  * Redistribution and use in binary form, without modification, are permitted provided
24  * that the following conditions are met:
25  *
26  * * No reverse engineering, decompilation, or disassembly of this software is
27  * permitted with respect to any software provided in binary form.
28  *
29  * * any redistribution and use are licensed by TI for use only with TI Devices.
30  *
31  * * Nothing shall obligate TI to provide you with source code for the software
32  * licensed and provided to you in object code.
33  *
34  * If software source code is provided to you, modification and redistribution of the
35  * source code are permitted provided that the following conditions are met:
36  *
37  * * any redistribution and use of the source code, including any resulting derivative
38  * works, are licensed by TI for use only with TI Devices.
39  *
40  * * any redistribution and use of any object code compiled from the source code
41  * and any resulting derivative works, are licensed by TI for use only with TI Devices.
42  *
43  * Neither the name of Texas Instruments Incorporated nor the names of its suppliers
44  *
45  * may be used to endorse or promote products derived from this software without
46  * specific prior written permission.
47  *
48  * DISCLAIMER.
49  *
50  * THIS SOFTWARE IS PROVIDED BY TI AND TI'S LICENSORS "AS IS" AND ANY EXPRESS
51  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
52  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
53  * IN NO EVENT SHALL TI AND TI'S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT,
54  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
55  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
57  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
58  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
59  * OF THE POSSIBILITY OF SUCH DAMAGE.
60  *
61  */
62 
63 #ifndef APP_UDMA_UTILS_H_
64 #define APP_UDMA_UTILS_H_
65 
83 #include <stdint.h>
84 #include <stdlib.h>
85 
86 #ifndef x86_64
87 #include "app_udma.h"
88 #endif
89 
90 #ifdef __cplusplus
91 extern "C" {
92 #endif
93 
94 /* ========================================================================== */
95 /* Macros & Typedefs */
96 /* ========================================================================== */
97 
99 #define APP_UDMA_ND_CHANNELS_MAX (16U)
100 
102 typedef void *app_udma_ch_handle_t;
103 
104 /* ========================================================================== */
105 /* Structure Declarations */
106 /* ========================================================================== */
107 
113 typedef struct
114 {
115  uint32_t enable_intr;
117  uint32_t use_dru;
119  uint32_t use_ring;
121  uint32_t use_nd_copy;
124 
126 typedef struct
127 {
128  uint64_t dest_addr;
131  uint64_t src_addr;
134  uint32_t length;
137 
139 typedef struct
140 {
141  uint16_t width;
144  uint16_t height;
146  uint64_t dest_addr;
149  uint32_t dest_pitch;
153  uint64_t src_addr;
166  uint32_t src_pitch;
175 
177 typedef struct
178 {
179  uint32_t copy_mode;
186  uint32_t eltype;
194  uint16_t icnt0;
197  uint16_t icnt1;
200  uint16_t icnt2;
203  uint16_t icnt3;
207  int32_t dim1;
210  int32_t dim2;
213  int32_t dim3;
217  uint16_t dicnt0;
220  uint16_t dicnt1;
223  uint16_t dicnt2;
226  uint16_t dicnt3;
230  int32_t ddim1;
233  int32_t ddim2;
236  int32_t ddim3;
240  uint64_t dest_addr;
244  uint64_t src_addr;
249 
250 /* ========================================================================== */
251 /* Function Declarations */
252 /* ========================================================================== */
253 
263 int32_t appUdmaCopyInit(void);
264 
272 int32_t appUdmaCopyDeinit(void);
273 
292 
303 int32_t appUdmaCopyDelete(app_udma_ch_handle_t ch_handle);
304 
317 int32_t appUdmaCopy1D(
318  app_udma_ch_handle_t ch_handle,
319  const app_udma_copy_1d_prms_t *prms_1d);
320 
337 int32_t appUdmaCopy2D(
338  app_udma_ch_handle_t ch_handle,
339  const app_udma_copy_2d_prms_t *prms_2d,
340  uint32_t num_transfers);
341 
362 int32_t appUdmaFill2D(
363  app_udma_ch_handle_t ch_handle,
364  const app_udma_copy_2d_prms_t *prms_2d,
365  uint32_t num_transfers);
366 
375 
383 int32_t appUdmaCopyNDReleaseHandle(uint32_t ch_idx);
384 
398 int32_t appUdmaCopyNDInit(
399  app_udma_ch_handle_t ch_handle,
400  const app_udma_copy_nd_prms_t *prms_nd);
401 
414 int32_t appUdmaCopyNDDeinit(
415  app_udma_ch_handle_t ch_handle);
416 
429 int32_t appUdmaCopyNDTrigger(
430  app_udma_ch_handle_t ch_handle);
431 
432 
445 int32_t appUdmaCopyNDWait(
446  app_udma_ch_handle_t ch_handle);
447 
448 
452 void appUdmaCopyNDPrmsPrint(app_udma_copy_nd_prms_t *prm, char *name);
453 
459 static inline void appUdmaCreatePrms_Init(app_udma_create_prms_t *prms);
465 static inline void appUdmaCopy1DPrms_Init(app_udma_copy_1d_prms_t *prms_1d);
471 static inline void appUdmaCopy2DPrms_Init(app_udma_copy_2d_prms_t *prms_2d);
477 static inline void appUdmaCopyNDPrms_Init(app_udma_copy_nd_prms_t *prms_nd);
478 
479 /* ========================================================================== */
480 /* Static Function Definitions */
481 /* ========================================================================== */
482 
484 {
485  if(NULL != prms)
486  {
487  /* Interrupt mode not yet supported for C7x - use polling */
488 #if defined(__C7100__) || defined(__C7120__)
489  prms->enable_intr = 0;
490 #else
491  prms->enable_intr = 1;
492 #endif
493  prms->use_dru = 0;
494  prms->use_ring = 1;
495  prms->use_nd_copy = 0; /* Transfer to completion */
496  }
497 }
498 
500 {
501  if(NULL != prms_1d)
502  {
503  prms_1d->dest_addr = 0U;
504  prms_1d->src_addr = 0U;
505  prms_1d->length = 0U;
506  }
507 }
508 
510 {
511  if(NULL != prms_2d)
512  {
513  prms_2d->width = 0U;
514  prms_2d->height = 0U;
515  prms_2d->dest_addr = 0U;
516  prms_2d->dest_pitch = 0U;
517  prms_2d->src_addr = 0U;
518  prms_2d->src_pitch = 0U;
519  }
520 }
521 
523 {
524  if(NULL != prms_nd)
525  {
526  prms_nd->copy_mode = 2;
527  prms_nd->icnt0 = 0U;
528  prms_nd->icnt1 = 0U;
529  prms_nd->icnt2 = 0U;
530  prms_nd->icnt3 = 0U;
531  prms_nd->dim1 = 0U;
532  prms_nd->dim2 = 0U;
533  prms_nd->dim3 = 0U;
534  prms_nd->dest_addr = 0U;
535  prms_nd->src_addr = 0U;
536  }
537 }
538 
539 #ifdef __cplusplus
540 }
541 #endif /* __cplusplus */
542 
543 /* @} */
544 
545 #endif
uint16_t dicnt1
Definition: app_udma_utils.h:220
uint32_t src_pitch
Definition: app_udma_utils.h:166
static void appUdmaCreatePrms_Init(app_udma_create_prms_t *prms)
Set defaults for app_udma_create_prms_t structure.
Definition: app_udma_utils.h:483
uint16_t height
Definition: app_udma_utils.h:144
uint16_t dicnt0
Definition: app_udma_utils.h:217
int32_t appUdmaCopy1D(app_udma_ch_handle_t ch_handle, const app_udma_copy_1d_prms_t *prms_1d)
DMA copy 1D DMA copy function.
uint32_t copy_mode
Definition: app_udma_utils.h:179
int32_t appUdmaCopyDelete(app_udma_ch_handle_t ch_handle)
DMA copy delete channel function.
uint16_t width
Definition: app_udma_utils.h:141
void * app_udma_ch_handle_t
App UDMA channel handle.
Definition: app_udma_utils.h:102
uint64_t src_addr
Definition: app_udma_utils.h:131
uint32_t use_ring
Definition: app_udma_utils.h:119
int32_t dim1
Definition: app_udma_utils.h:207
int32_t appUdmaCopyNDReleaseHandle(uint32_t ch_idx)
Releases reference to channel handle, if found to be last reference deletes the handle.
Parameter to use when creating a logical DMA channel To avoid compatibility issues, user should called appUdmaCreatePrms_Init() to set default values for all params in this structure.
Definition: app_udma_utils.h:113
uint16_t icnt2
Definition: app_udma_utils.h:200
int32_t dim3
Definition: app_udma_utils.h:213
int32_t appUdmaCopy2D(app_udma_ch_handle_t ch_handle, const app_udma_copy_2d_prms_t *prms_2d, uint32_t num_transfers)
DMA copy 2D DMA copy function.
app_udma_ch_handle_t appUdmaCopyCreate(const app_udma_create_prms_t *prms)
DMA copy create channel function.
int32_t ddim1
Definition: app_udma_utils.h:230
static void appUdmaCopyNDPrms_Init(app_udma_copy_nd_prms_t *prms_nd)
Set defaults for app_udma_copy_nd_prms_t structure.
Definition: app_udma_utils.h:522
void appUdmaCopyNDPrmsPrint(app_udma_copy_nd_prms_t *prm, char *name)
Prints params values.
int32_t appUdmaCopyInit(void)
DMA copy init function.
int32_t ddim3
Definition: app_udma_utils.h:236
uint32_t enable_intr
Definition: app_udma_utils.h:115
int32_t appUdmaCopyNDInit(app_udma_ch_handle_t ch_handle, const app_udma_copy_nd_prms_t *prms_nd)
DMA copy ND init function.
app_udma_ch_handle_t appUdmaCopyNDGetHandle(uint32_t ch_idx)
Return handle to ND copy channel, if not already created, CH is created here.
1D transfer request parameters
Definition: app_udma_utils.h:126
int32_t appUdmaCopyNDDeinit(app_udma_ch_handle_t ch_handle)
DMA copy ND de-init function.
uint32_t use_nd_copy
Definition: app_udma_utils.h:121
uint32_t length
Definition: app_udma_utils.h:134
uint16_t dicnt3
Definition: app_udma_utils.h:226
uint16_t icnt0
Definition: app_udma_utils.h:194
uint64_t src_addr
Definition: app_udma_utils.h:244
int32_t appUdmaCopyNDTrigger(app_udma_ch_handle_t ch_handle)
DMA copy ND trigger function.
uint16_t icnt3
Definition: app_udma_utils.h:203
uint32_t use_dru
Definition: app_udma_utils.h:117
uint16_t dicnt2
Definition: app_udma_utils.h:223
uint64_t dest_addr
Definition: app_udma_utils.h:128
uint16_t icnt1
Definition: app_udma_utils.h:197
int32_t appUdmaCopyDeinit(void)
DMA copy deinit function.
static void appUdmaCopy2DPrms_Init(app_udma_copy_2d_prms_t *prms_2d)
Set defaults for app_udma_copy_2d_prms_t structure.
Definition: app_udma_utils.h:509
uint32_t eltype
Definition: app_udma_utils.h:186
int32_t ddim2
Definition: app_udma_utils.h:233
uint64_t dest_addr
Definition: app_udma_utils.h:146
2D transfer request parameters
Definition: app_udma_utils.h:139
int32_t appUdmaCopyNDWait(app_udma_ch_handle_t ch_handle)
DMA copy ND wait function.
uint64_t src_addr
Definition: app_udma_utils.h:153
static void appUdmaCopy1DPrms_Init(app_udma_copy_1d_prms_t *prms_1d)
Set defaults for app_udma_copy_1d_prms_t structure.
Definition: app_udma_utils.h:499
uint64_t dest_addr
Definition: app_udma_utils.h:240
int32_t appUdmaFill2D(app_udma_ch_handle_t ch_handle, const app_udma_copy_2d_prms_t *prms_2d, uint32_t num_transfers)
DMA copy 2D DMA memfill function.
ND transfer request parameters.
Definition: app_udma_utils.h:177
int32_t dim2
Definition: app_udma_utils.h:210
uint32_t dest_pitch
Definition: app_udma_utils.h:149