1 /*
2 * Copyright (c) 2011-2015, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the 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 "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 /*
33 * ======== test_omx.c ========
34 *
35 * Example of setting up an "OMX" service with the ServiceMgr, allowing clients
36 * to instantiate OMX instances.
37 *
38 * Works with the test_omx.c Linux user space application over the rpmsg_omx\
39 * driver.
40 */
42 #include <xdc/std.h>
43 #include <xdc/cfg/global.h>
44 #include <xdc/runtime/System.h>
45 #include <xdc/runtime/Diags.h>
47 #include <ti/ipc/MultiProc.h>
48 #include <ti/sysbios/BIOS.h>
49 #include <ti/sysbios/knl/Task.h>
51 #include <ti/grcm/RcmTypes.h>
52 #include <ti/grcm/RcmServer.h>
54 #include <stdio.h>
55 #include <string.h>
56 #include <stdlib.h>
58 #include <ti/srvmgr/ServiceMgr.h>
59 #include <ti/srvmgr/rpmsg_omx.h>
60 #include <ti/srvmgr/omx_packet.h>
62 /* Custom resource table with L2 RAM entry for silicon bug workaround */
63 #if (defined(DSP) && defined(VAYU))
64 #include "power_rsc_table_vayu_dsp.h"
65 #endif
67 /* Turn on/off printf's */
68 #define CHATTER 0
70 /* Legacy function to allow Linux side rpmsg sample tests to work: */
71 extern void start_ping_tasks();
72 extern void start_resmgr_task();
73 extern void start_hwSpinlock_task();
75 /*
76 * OMX packet expected to have its data payload start with a payload of
77 * this value. Need to export this properly in a meaningful header file on
78 * both HLOS and RTOS sides
79 */
80 typedef enum {
81 RPC_OMX_MAP_INFO_NONE = 0,
82 RPC_OMX_MAP_INFO_ONE_BUF = 1,
83 RPC_OMX_MAP_INFO_TWO_BUF = 2,
84 RPC_OMX_MAP_INFO_THREE_BUF = 3,
85 RPC_OMX_MAP_INFO_MAX = 0x7FFFFFFF
86 } map_info_type;
88 /*
89 * ======== fxnDouble used by omx_benchmark test app ========
90 */
91 typedef struct {
92 Int a;
93 } FxnDoubleArgs;
95 static Int32 fxnDouble(UInt32 size, UInt32 *data);
97 /* ==========================================================================
98 * OMX Fxns, adapted from rpc_omx_skel.c.
99 *
100 * These defines are to illustrate reuse of RPC_SKEL fxns with ServiceMgr.
101 *===========================================================================*/
103 #define H264_DECODER_NAME "H264_decoder"
105 #define OMX_VIDEO_THREAD_PRIORITY 5
107 typedef Int32 RPC_OMX_ERRORTYPE;
108 typedef UInt32 OMX_HANDLETYPE;
110 static RPC_OMX_ERRORTYPE RPC_SKEL_GetHandle(Void *, UInt32 size, UInt32 *data);
111 static RPC_OMX_ERRORTYPE RPC_SKEL_SetParameter(UInt32 size, UInt32 *data);
112 static RPC_OMX_ERRORTYPE RPC_SKEL_GetParameter(UInt32 size, UInt32 *data);
116 /* RcmServer static function table */
117 static RcmServer_FxnDesc OMXServerFxnAry[] = {
118 {"RPC_SKEL_GetHandle" , NULL}, /* Set at runtime to RPC_SKEL_GetHandle */
119 {"RPC_SKEL_SetParameter", RPC_SKEL_SetParameter},
120 {"RPC_SKEL_GetParameter", RPC_SKEL_GetParameter},
121 {"fxnDouble", fxnDouble },
122 };
124 #define OMXServerFxnAryLen (sizeof OMXServerFxnAry / sizeof OMXServerFxnAry[0])
126 static const RcmServer_FxnDescAry OMXServer_fxnTab = {
127 OMXServerFxnAryLen,
128 OMXServerFxnAry
129 };
132 static RPC_OMX_ERRORTYPE RPC_SKEL_SetParameter(UInt32 size, UInt32 *data)
133 {
134 #if CHATTER
135 System_printf("RPC_SKEL_SetParameter: Called\n");
136 #endif
138 return(0);
139 }
141 static RPC_OMX_ERRORTYPE RPC_SKEL_GetParameter(UInt32 size, UInt32 *data)
142 {
143 #if CHATTER
144 System_printf("RPC_SKEL_GetParameter: Called\n");
145 #endif
147 return(0);
148 }
150 #define CALLBACK_DATA "OMX_Callback"
151 #define PAYLOAD_SIZE sizeof(CALLBACK_DATA)
152 #define CALLBACK_DATA_SIZE (HDRSIZE + OMXPACKETSIZE + PAYLOAD_SIZE)
154 static RPC_OMX_ERRORTYPE RPC_SKEL_GetHandle(Void *srvc, UInt32 size,
155 UInt32 *data)
156 {
157 char cComponentName[128] = {0};
158 OMX_HANDLETYPE hComp;
159 Char cb_data[HDRSIZE + OMXPACKETSIZE + PAYLOAD_SIZE] = {0};
161 /*
162 * Note: Currently, rpmsg_omx linux driver expects an omx_msg_hdr in front
163 * of the omx_packet data, so we allow space for this:
164 */
165 struct omx_msg_hdr * hdr = (struct omx_msg_hdr *)cb_data;
166 struct omx_packet * packet = (struct omx_packet *)hdr->data;
169 /*
170 * Marshalled:[>offset(cParameterName)|>pAppData|>offset(RcmServerName)|>pid|
171 * >--cComponentName--|>--CallingCorercmServerName--|
172 * <hComp]
173 */
175 strcpy(cComponentName, (char *)data + sizeof(map_info_type));
177 #if CHATTER
178 System_printf("RPC_SKEL_GetHandle: Component Name received: %s\n",
179 cComponentName);
180 #endif
182 /* Simulate sending an async OMX callback message, passing an omx_packet
183 * structure.
184 */
185 packet->msg_id = 99; /* Indicates callback instance, buffer id, etc. */
186 packet->fxn_idx = 5; /* Indicate callback fxn */
187 packet->data_size = PAYLOAD_SIZE;
188 strcpy((char *)packet->data, CALLBACK_DATA);
190 #if CHATTER
191 System_printf("RPC_SKEL_GetHandle: Sending callback message id: %d, "
192 "fxn_id: %d, data: %s\n",
193 packet->msg_id, packet->fxn_idx, packet->data);
194 #endif
195 ServiceMgr_send(srvc, cb_data, CALLBACK_DATA_SIZE);
197 /* Call OMX_Get_Handle() and return handle for future calls. */
198 /*eCompReturn = OMX_GetHandle(&hComp, (OMX_STRING)&cComponentName[0], pAppData,&rpcCallBackInfo); */
199 hComp = 0x5C0FFEE5;
200 data[0] = hComp;
202 #if CHATTER
203 System_printf("RPC_SKEL_GetHandle: returning hComp: 0x%x\n", hComp);
204 #endif
206 return(0);
207 }
209 /*
210 * ======== fxnDouble ========
211 */
212 Int32 fxnDouble(UInt32 size, UInt32 *data)
213 {
214 FxnDoubleArgs *args;
215 Int a;
217 #if CHATTER
218 System_printf("fxnDouble: Executing fxnDouble \n");
219 #endif
221 args = (FxnDoubleArgs *)((UInt32)data + sizeof(map_info_type));
222 a = args->a;
224 return a * 2;
225 }
227 Int main(Int argc, char* argv[])
228 {
229 RcmServer_Params rcmServerParams;
231 System_printf("%s starting..\n", MultiProc_getName(MultiProc_self()));
233 /*
234 * Enable use of runtime Diags_setMask per module:
235 *
236 * Codes: E = ENTRY, X = EXIT, L = LIFECYCLE, F = INFO, S = STATUS
237 */
238 Diags_setMask("ti.ipc.rpmsg.RPMessage=EXLFS");
240 /* Setup the table of services, so clients can create and connect to
241 * new service instances:
242 */
243 ServiceMgr_init();
245 /* initialize RcmServer create params */
246 RcmServer_Params_init(&rcmServerParams);
248 /* The first function, at index 0, is a special create function, which
249 * gets passed a Service_Handle argument.
250 * We set this at run time as our C compiler is not allowing named union
251 * field initialization:
252 */
253 OMXServer_fxnTab.elem[0].addr.createFxn = RPC_SKEL_GetHandle;
255 rcmServerParams.priority = Thread_Priority_ABOVE_NORMAL;
256 rcmServerParams.stackSize = 0x1000;
257 rcmServerParams.fxns.length = OMXServer_fxnTab.length;
258 rcmServerParams.fxns.elem = OMXServer_fxnTab.elem;
260 /* Register an OMX service to create and call new OMX components: */
261 ServiceMgr_register("OMX", &rcmServerParams);
263 /* Some background ping testing tasks, used by rpmsg samples: */
264 start_ping_tasks();
266 #if 0 /* DSP or CORE0 or IPU */
267 /* Run a background task to test rpmsg_resmgr service */
268 start_resmgr_task();
269 #endif
271 #if 0 /* DSP or CORE0 or IPU */
272 /* Run a background task to test hwspinlock */
273 start_hwSpinlock_task();
274 #endif
276 /* Start the ServiceMgr services */
277 ServiceMgr_start(0);
279 BIOS_start();
281 return (0);
282 }