TIOVX User Guide
vx_tutorial_mcu_demo.c
1 /*
2 *
3 * Copyright (c) 2017 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 #include <stdio.h>
64 #include <VX/vx.h>
65 #include <TI/tivx.h>
66 #include <TI/tivx_task.h>
67 #include <utility.h>
68 #include <TI/tivx_test_kernels.h>
69 #include <TI/tivx_capture.h>
70 #include "vx_tutorial_mcu_demo.h"
71 
72 #if defined(SOC_AM62A)
73 void vx_tutorial_mcu_demo(vx_bool use_mcu1_core)
74 #else
75 void vx_tutorial_mcu_demo(vx_bool use_mcu3_core)
76 #endif
77 {
78  vx_graph graph;
79  vx_context context;
80  vx_uint8 scalar_val = 0;
81  vx_scalar scalar, scalar_out;
82  vx_uint8 output = 0;
83  vx_uint32 num_streams = 0, golden_output = 0;
84  vx_node node0, node1;
85  vx_status status;
86 
87  printf(" vx_tutorial_mcu_demo: Tutorial Started !!! \n");
95  context = vxCreateContext();
98  tivxTestKernelsLoadKernels(context);
99 
105  graph = vxCreateGraph(context);
108  scalar = vxCreateScalar(context, VX_TYPE_UINT8, &scalar_val);
109  scalar_out = vxCreateScalar(context, VX_TYPE_UINT8, &scalar_val);
110 
116  node0 = tivxScalarSourceNode(graph, scalar);
117  vxSetReferenceName((vx_reference)node0, "Scalar_Source 1");
118  #if defined(SOC_AM62A)
119  if (vx_true_e == use_mcu1_core)
120  {
122  }
123  #else
124  if (vx_true_e == use_mcu3_core)
125  {
127  {
129  }
130  else
131  {
133  }
134  }
135  #endif
136  #if defined(SOC_J784S4)
137  else
138  {
139  if(tivxIsTargetEnabled(TIVX_TARGET_MCU4_0))
140  {
141  vxSetNodeTarget(node0, VX_TARGET_STRING, TIVX_TARGET_MCU4_0);
142  }
143  else
144  {
145  vxSetNodeTarget(node0, VX_TARGET_STRING, TIVX_TARGET_MCU4_1);
146  }
147  }
148  #endif
149 
150  node1 = tivxScalarIntermediateNode(graph, scalar, scalar_out);
151  vxSetReferenceName((vx_reference)node1, "Scalar_Source 2");
152  #if defined(SOC_AM62A)
153  if (vx_true_e == use_mcu1_core)
154  {
156  }
157  #else
158  if (vx_true_e == use_mcu3_core)
159  {
161  {
163  }
164  else
165  {
167  }
168  }
169  #endif
170  #if defined(SOC_J784S4)
171  else
172  {
173  if(tivxIsTargetEnabled(TIVX_TARGET_MCU4_0))
174  {
175  vxSetNodeTarget(node1, VX_TARGET_STRING, TIVX_TARGET_MCU4_0);
176  }
177  else
178  {
179  vxSetNodeTarget(node1, VX_TARGET_STRING, TIVX_TARGET_MCU4_1);
180  }
181  }
182  #endif
183 
186  status = vxEnableGraphStreaming(graph, node0);
194  status = vxVerifyGraph(graph);
204  show_graph_attributes(graph);
214  show_node_attributes(node0);
215  show_node_attributes(node1);
216 
217  printf("Input scalar value = %d\n", scalar_val);
218 
219  if(status==(vx_status)VX_SUCCESS)
220  {
221  printf(" Executing graph ...\n");
222 
223  vxStartGraphStreaming(graph);
224 
225  tivxTaskWaitMsecs(50);
226 
227  vxStopGraphStreaming(graph);
228 
229  printf(" Executing graph ... Done !!!\n");
230 
238  show_graph_attributes(graph);
248  show_node_attributes(node0);
249  show_node_attributes(node1);
252  vxQueryGraph(graph, TIVX_GRAPH_STREAM_EXECUTIONS, &num_streams, sizeof(num_streams));
253 
254  if (num_streams != 0)
255  {
256  golden_output = num_streams % 256;
258  printf("Output scalar value = %d\n", output);
259  if(output!=golden_output)
260  {
261  printf("ERROR: %d != %d\n", output, golden_output);
262  }
263  else
264  {
265  printf("RUN SUCCESS!!!\n");
266  }
267  }
268  }
269 
276  vxReleaseScalar(&scalar);
277  vxReleaseScalar(&scalar_out);
278  vxReleaseNode(&node0);
279  vxReleaseNode(&node1);
280 
287  vxReleaseGraph(&graph);
290  tivxTestKernelsUnLoadKernels(context);
291 
300  vxReleaseContext(&context);
303  printf(" vx_tutorial_mcu_demo: Tutorial Done !!! \n");
304  printf(" \n");
305 }
vx_bool
vx_scalar VX_API_CALL vxCreateScalar(vx_context context, vx_enum data_type, const void *ptr)
uint8_t vx_uint8
VX_MEMORY_TYPE_HOST
Interface to TI extension APIs.
void show_node_attributes(vx_node node)
Show attributes of previously created node.
int32_t vx_enum
VX_SUCCESS
vx_status VX_API_CALL vxQueryGraph(vx_graph graph, vx_enum attribute, void *ptr, vx_size size)
vx_status VX_API_CALL vxReleaseScalar(vx_scalar *scalar)
VX_API_ENTRY vx_status VX_API_CALL vxStopGraphStreaming(vx_graph graph)
Stop streaming mode of graph execution.
#define TIVX_TARGET_MCU3_0
Name for MCU3_0 target class, core 0.
void show_graph_attributes(vx_graph graph)
Show attributes of previously created graph.
vx_true_e
vx_bool tivxIsTargetEnabled(const char target_name[])
Utility function to know if target is enabled or not.
vx_status VX_API_CALL vxReleaseContext(vx_context *context)
vx_enum vx_status
void tivxTaskWaitMsecs(uint32_t msec)
waits/sleeps for given milliseconds
struct _vx_context * vx_context
vx_status VX_API_CALL vxCopyScalar(vx_scalar scalar, void *user_ptr, vx_enum usage, vx_enum user_mem_type)
vx_status VX_API_CALL vxSetNodeTarget(vx_node node, vx_enum target_enum, const char *target_string)
struct _vx_reference * vx_reference
VX_TARGET_STRING
VX_API_ENTRY vx_status VX_API_CALL vxStartGraphStreaming(vx_graph graph)
Start streaming mode of graph execution.
VX_READ_ONLY
vx_status VX_API_CALL vxReleaseGraph(vx_graph *graph)
vx_status VX_API_CALL vxSetReferenceName(vx_reference ref, const vx_char *name)
#define TIVX_TARGET_MCU3_1
Name for MCU3_1 target class, core 1.
#define TIVX_TARGET_MCU1_0
Name for MCU1 target class, core 0.
VX_API_ENTRY vx_status VX_API_CALL vxEnableGraphStreaming(vx_graph graph, vx_node trigger_node)
Enable streaming mode of graph execution.
uint32_t vx_uint32
vx_graph VX_API_CALL vxCreateGraph(vx_context context)
Interface to Task APIs.
vx_status VX_API_CALL vxVerifyGraph(vx_graph graph)
Returns the graph stream executions. Read-only. Use a vx_uint32 parameter.
Definition: tivx.h:231
vx_context VX_API_CALL vxCreateContext()
struct _vx_graph * vx_graph
vx_status VX_API_CALL vxReleaseNode(vx_node *node)
struct _vx_node * vx_node
struct _vx_scalar * vx_scalar
VX_TYPE_UINT8