1 /*
2 * Copyright (c) 2011-2013, 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 /* Turn on/off printf's */
63 #define CHATTER 0
65 /* Legacy function to allow Linux side rpmsg sample tests to work: */
66 extern void start_ping_tasks();
67 extern void start_resmgr_task();
68 extern void start_hwSpinlock_task();
70 /*
71 * OMX packet expected to have its data payload start with a payload of
72 * this value. Need to export this properly in a meaningful header file on
73 * both HLOS and RTOS sides
74 */
75 typedef enum {
76 RPC_OMX_MAP_INFO_NONE = 0,
77 RPC_OMX_MAP_INFO_ONE_BUF = 1,
78 RPC_OMX_MAP_INFO_TWO_BUF = 2,
79 RPC_OMX_MAP_INFO_THREE_BUF = 3,
80 RPC_OMX_MAP_INFO_MAX = 0x7FFFFFFF
81 } map_info_type;
83 /*
84 * ======== fxnDouble used by omx_benchmark test app ========
85 */
86 typedef struct {
87 Int a;
88 } FxnDoubleArgs;
90 static Int32 fxnDouble(UInt32 size, UInt32 *data);
92 /* ==========================================================================
93 * OMX Fxns, adapted from rpc_omx_skel.c.
94 *
95 * These defines are to illustrate reuse of RPC_SKEL fxns with ServiceMgr.
96 *===========================================================================*/
98 #define H264_DECODER_NAME "H264_decoder"
100 #define OMX_VIDEO_THREAD_PRIORITY 5
102 typedef Int32 RPC_OMX_ERRORTYPE;
103 typedef UInt32 OMX_HANDLETYPE;
105 static RPC_OMX_ERRORTYPE RPC_SKEL_GetHandle(Void *, UInt32 size, UInt32 *data);
106 static RPC_OMX_ERRORTYPE RPC_SKEL_SetParameter(UInt32 size, UInt32 *data);
107 static RPC_OMX_ERRORTYPE RPC_SKEL_GetParameter(UInt32 size, UInt32 *data);
111 /* RcmServer static function table */
112 static RcmServer_FxnDesc OMXServerFxnAry[] = {
113 {"RPC_SKEL_GetHandle" , NULL}, /* Set at runtime to RPC_SKEL_GetHandle */
114 {"RPC_SKEL_SetParameter", RPC_SKEL_SetParameter},
115 {"RPC_SKEL_GetParameter", RPC_SKEL_GetParameter},
116 {"fxnDouble", fxnDouble },
117 };
119 #define OMXServerFxnAryLen (sizeof OMXServerFxnAry / sizeof OMXServerFxnAry[0])
121 static const RcmServer_FxnDescAry OMXServer_fxnTab = {
122 OMXServerFxnAryLen,
123 OMXServerFxnAry
124 };
127 static RPC_OMX_ERRORTYPE RPC_SKEL_SetParameter(UInt32 size, UInt32 *data)
128 {
129 #if CHATTER
130 System_printf("RPC_SKEL_SetParameter: Called\n");
131 #endif
133 return(0);
134 }
136 static RPC_OMX_ERRORTYPE RPC_SKEL_GetParameter(UInt32 size, UInt32 *data)
137 {
138 #if CHATTER
139 System_printf("RPC_SKEL_GetParameter: Called\n");
140 #endif
142 return(0);
143 }
145 #define CALLBACK_DATA "OMX_Callback"
146 #define PAYLOAD_SIZE sizeof(CALLBACK_DATA)
147 #define CALLBACK_DATA_SIZE (HDRSIZE + OMXPACKETSIZE + PAYLOAD_SIZE)
149 static RPC_OMX_ERRORTYPE RPC_SKEL_GetHandle(Void *srvc, UInt32 size,
150 UInt32 *data)
151 {
152 char cComponentName[128] = {0};
153 OMX_HANDLETYPE hComp;
154 Char cb_data[HDRSIZE + OMXPACKETSIZE + PAYLOAD_SIZE] = {0};
156 /*
157 * Note: Currently, rpmsg_omx linux driver expects an omx_msg_hdr in front
158 * of the omx_packet data, so we allow space for this:
159 */
160 struct omx_msg_hdr * hdr = (struct omx_msg_hdr *)cb_data;
161 struct omx_packet * packet = (struct omx_packet *)hdr->data;
164 /*
165 * Marshalled:[>offset(cParameterName)|>pAppData|>offset(RcmServerName)|>pid|
166 * >--cComponentName--|>--CallingCorercmServerName--|
167 * <hComp]
168 */
170 strcpy(cComponentName, (char *)data + sizeof(map_info_type));
172 #if CHATTER
173 System_printf("RPC_SKEL_GetHandle: Component Name received: %s\n",
174 cComponentName);
175 #endif
177 /* Simulate sending an async OMX callback message, passing an omx_packet
178 * structure.
179 */
180 packet->msg_id = 99; /* Indicates callback instance, buffer id, etc. */
181 packet->fxn_idx = 5; /* Indicate callback fxn */
182 packet->data_size = PAYLOAD_SIZE;
183 strcpy((char *)packet->data, CALLBACK_DATA);
185 #if CHATTER
186 System_printf("RPC_SKEL_GetHandle: Sending callback message id: %d, "
187 "fxn_id: %d, data: %s\n",
188 packet->msg_id, packet->fxn_idx, packet->data);
189 #endif
190 ServiceMgr_send(srvc, cb_data, CALLBACK_DATA_SIZE);
192 /* Call OMX_Get_Handle() and return handle for future calls. */
193 /*eCompReturn = OMX_GetHandle(&hComp, (OMX_STRING)&cComponentName[0], pAppData,&rpcCallBackInfo); */
194 hComp = 0x5C0FFEE5;
195 data[0] = hComp;
197 #if CHATTER
198 System_printf("RPC_SKEL_GetHandle: returning hComp: 0x%x\n", hComp);
199 #endif
201 return(0);
202 }
204 /*
205 * ======== fxnDouble ========
206 */
207 Int32 fxnDouble(UInt32 size, UInt32 *data)
208 {
209 FxnDoubleArgs *args;
210 Int a;
212 #if CHATTER
213 System_printf("fxnDouble: Executing fxnDouble \n");
214 #endif
216 args = (FxnDoubleArgs *)((UInt32)data + sizeof(map_info_type));
217 a = args->a;
219 return a * 2;
220 }
222 Int main(Int argc, char* argv[])
223 {
224 RcmServer_Params rcmServerParams;
226 System_printf("%s starting..\n", MultiProc_getName(MultiProc_self()));
228 /*
229 * Enable use of runtime Diags_setMask per module:
230 *
231 * Codes: E = ENTRY, X = EXIT, L = LIFECYCLE, F = INFO, S = STATUS
232 */
233 Diags_setMask("ti.ipc.rpmsg.RPMessage=EXLFS");
235 /* Setup the table of services, so clients can create and connect to
236 * new service instances:
237 */
238 ServiceMgr_init();
240 /* initialize RcmServer create params */
241 RcmServer_Params_init(&rcmServerParams);
243 /* The first function, at index 0, is a special create function, which
244 * gets passed a Service_Handle argument.
245 * We set this at run time as our C compiler is not allowing named union
246 * field initialization:
247 */
248 OMXServer_fxnTab.elem[0].addr.createFxn = RPC_SKEL_GetHandle;
250 rcmServerParams.priority = Thread_Priority_ABOVE_NORMAL;
251 rcmServerParams.stackSize = 0x1000;
252 rcmServerParams.fxns.length = OMXServer_fxnTab.length;
253 rcmServerParams.fxns.elem = OMXServer_fxnTab.elem;
255 /* Register an OMX service to create and call new OMX components: */
256 ServiceMgr_register("OMX", &rcmServerParams);
258 /* Some background ping testing tasks, used by rpmsg samples: */
259 start_ping_tasks();
261 #if 0 /* DSP or CORE0 or IPU */
262 /* Run a background task to test rpmsg_resmgr service */
263 start_resmgr_task();
264 #endif
266 #if 0 /* DSP or CORE0 or IPU */
267 /* Run a background task to test hwspinlock */
268 start_hwSpinlock_task();
269 #endif
271 /* Start the ServiceMgr services */
272 ServiceMgr_start(0);
274 BIOS_start();
276 return (0);
277 }