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  {
121  vxSetNodeTarget(node0, VX_TARGET_STRING, TIVX_TARGET_MCU1_0);
122  }
123  #elif defined(SOC_J722S)
124  /* Note: defining this for compatibility sake */
125  if (vx_true_e == use_mcu3_core)
126  {
127  if(tivxIsTargetEnabled(TIVX_TARGET_MCU2_0))
128  {
129  vxSetNodeTarget(node0, VX_TARGET_STRING, TIVX_TARGET_MCU2_0);
130  }
131  }
132  #else
133  if (vx_true_e == use_mcu3_core)
134  {
135  if(tivxIsTargetEnabled(TIVX_TARGET_MCU3_0))
136  {
137  vxSetNodeTarget(node0, VX_TARGET_STRING, TIVX_TARGET_MCU3_0);
138  }
139  else
140  {
141  vxSetNodeTarget(node0, VX_TARGET_STRING, TIVX_TARGET_MCU3_1);
142  }
143  }
144  #endif
145  #if defined(SOC_J784S4)
146  else
147  {
148  if(tivxIsTargetEnabled(TIVX_TARGET_MCU4_0))
149  {
150  vxSetNodeTarget(node0, VX_TARGET_STRING, TIVX_TARGET_MCU4_0);
151  }
152  else
153  {
154  vxSetNodeTarget(node0, VX_TARGET_STRING, TIVX_TARGET_MCU4_1);
155  }
156  }
157  #endif
158 
159  node1 = tivxScalarIntermediateNode(graph, scalar, scalar_out);
160  vxSetReferenceName((vx_reference)node1, "Scalar_Source 2");
161  #if defined(SOC_AM62A)
162  if (vx_true_e == use_mcu1_core)
163  {
164  vxSetNodeTarget(node1, VX_TARGET_STRING, TIVX_TARGET_MCU1_0);
165  }
166  #elif defined(SOC_J722S)
167  /* Note: defining this for compatibility sake */
168  if (vx_true_e == use_mcu3_core)
169  {
170  if(tivxIsTargetEnabled(TIVX_TARGET_MCU2_0))
171  {
172  vxSetNodeTarget(node1, VX_TARGET_STRING, TIVX_TARGET_MCU2_0);
173  }
174  }
175  #else
176  if (vx_true_e == use_mcu3_core)
177  {
178  if(tivxIsTargetEnabled(TIVX_TARGET_MCU3_0))
179  {
180  vxSetNodeTarget(node1, VX_TARGET_STRING, TIVX_TARGET_MCU3_0);
181  }
182  else
183  {
184  vxSetNodeTarget(node1, VX_TARGET_STRING, TIVX_TARGET_MCU3_1);
185  }
186  }
187  #endif
188  #if defined(SOC_J784S4)
189  else
190  {
191  if(tivxIsTargetEnabled(TIVX_TARGET_MCU4_0))
192  {
193  vxSetNodeTarget(node1, VX_TARGET_STRING, TIVX_TARGET_MCU4_0);
194  }
195  else
196  {
197  vxSetNodeTarget(node1, VX_TARGET_STRING, TIVX_TARGET_MCU4_1);
198  }
199  }
200  #endif
201 
204  status = vxEnableGraphStreaming(graph, node0);
212  status = vxVerifyGraph(graph);
222  show_graph_attributes(graph);
232  show_node_attributes(node0);
233  show_node_attributes(node1);
234 
235  printf("Input scalar value = %d\n", scalar_val);
236 
237  if(status==(vx_status)VX_SUCCESS)
238  {
239  printf(" Executing graph ...\n");
240 
241  vxStartGraphStreaming(graph);
242 
243  tivxTaskWaitMsecs(50);
244 
245  vxStopGraphStreaming(graph);
246 
247  printf(" Executing graph ... Done !!!\n");
248 
256  show_graph_attributes(graph);
266  show_node_attributes(node0);
267  show_node_attributes(node1);
270  vxQueryGraph(graph, TIVX_GRAPH_STREAM_EXECUTIONS, &num_streams, sizeof(num_streams));
271 
272  if (num_streams != 0)
273  {
274  golden_output = num_streams % 256;
276  printf("Output scalar value = %d\n", output);
277  if(output!=golden_output)
278  {
279  printf("ERROR: %d != %d\n", output, golden_output);
280  }
281  else
282  {
283  printf("RUN SUCCESS!!!\n");
284  }
285  }
286  }
287 
294  vxReleaseScalar(&scalar);
295  vxReleaseScalar(&scalar_out);
296  vxReleaseNode(&node0);
297  vxReleaseNode(&node1);
298 
305  vxReleaseGraph(&graph);
308  tivxTestKernelsUnLoadKernels(context);
309 
318  vxReleaseContext(&context);
321  printf(" vx_tutorial_mcu_demo: Tutorial Done !!! \n");
322  printf(" \n");
323 }
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.
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)
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:241
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