d606e1712cb2e313dcc5a012467fe621ab0ce5c7
1 /*
2 * Copyright (c) 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 */
33 /*
34 * ======== mmrpc_test.c ========
35 */
36 #include <stdio.h>
38 #include <ti/ipc/mm/MmRpc.h>
41 /*
42 * module 'Mx' functions
43 */
45 /* compute structure */
46 typedef struct {
47 uint32_t coef;
48 int size;
49 uint32_t * inBuf;
50 uint32_t * outBuf;
51 } Mx_Compute;
53 int Mx_initialize(void);
54 void Mx_finalize(void);
56 int32_t Mx_triple(uint32_t a);
57 int32_t Mx_add(int32_t a, int32_t b);
58 int32_t Mx_compute(Mx_Compute *compute);
60 MmRpc_Handle Mx_rpcDsp = NULL;
62 /* static function indicies */
63 #define Mx_Fxn_triple (0x80000000 | 1)
64 #define Mx_Fxn_add (0x80000000 | 2)
65 #define Mx_Fxn_compute (0x80000000 | 3)
68 /*
69 * ======== main ========
70 */
71 int main(int argc, char **argv)
72 {
73 int status;
74 int32_t ret;
75 // int i;
76 // Mx_Compute *compute;
78 printf("mmrpc_test: --> main\n");
80 /* initialize Mx module (setup rpc connection) */
81 status = Mx_initialize();
83 if (status < 0) {
84 goto leave;
85 }
87 /* invoke Mx functions */
88 ret = Mx_triple(11);
89 printf("mmrpc_test: Mx_triple(11), ret=%d\n", ret);
91 if (ret < 0) {
92 status = -1;
93 goto leave;
94 }
96 ret = Mx_triple(111);
97 printf("mmrpc_test: Mx_triple(111), ret=%d\n", ret);
99 if (ret < 0) {
100 status = -1;
101 goto leave;
102 }
104 ret = Mx_add(44, 66);
105 printf("mmrpc_test: Mx_add(44, 66), ret=%d\n", ret);
107 if (ret < 0) {
108 status = -1;
109 goto leave;
110 }
112 #if 0
113 /* allocate a compute structure in shared memory */
114 // compute = ...;
115 compute->coef = 0x80400000;
116 compute->size = 0x1000;
118 /* allocate an input buffer in shared memory */
119 // compute->inBuf = ...;
121 for (i = 0; i < compute->size; i++) {
122 compute->inBuf[i] = 0x2010;
123 }
125 /* allocate an output buffer in shared memory */
126 // compute->outBuf = ...;
128 /* process the buffer */
129 ret = Mx_compute(compute);
131 if (ret < 0) {
132 status = -1;
133 goto leave;
134 }
136 /* free resources */
137 // free(compute->outBuf);
138 // free(compute->inBuf);
139 // free(compute);
140 #endif
142 leave:
143 /* finalize Mx module (destroy rpc connection) */
144 Mx_finalize();
146 if (status < 0) {
147 printf("mmrpc_test: FAILED\n");
148 }
149 else {
150 printf("mmrpc_test: PASSED\n");
151 }
152 return(0);
153 }
155 /*
156 * ======== Mx_initialize ========
157 */
158 int Mx_initialize(void)
159 {
160 int status;
161 MmRpc_Params params;
163 /* create remote server insance */
164 MmRpc_Params_init(¶ms);
166 status = MmRpc_create("DSP", "FooServer", ¶ms, &Mx_rpcDsp);
168 if (status < 0) {
169 printf("mmrpc_test: Error: MmRpc_create failed\n");
170 status = -1;
171 }
172 else {
173 status = 0;
174 }
176 return(status);
177 }
179 /*
180 * ======== Mx_finalize ========
181 */
182 void Mx_finalize(void)
183 {
184 /* delete remote server instance */
185 if (Mx_rpcDsp != NULL) {
186 MmRpc_delete(&Mx_rpcDsp);
187 }
188 }
190 /*
191 * ======== Mx_triple ========
192 */
193 int32_t Mx_triple(uint32_t a)
194 {
195 MmRpc_FxnCtx *fxnCtx;
196 int32_t fxnRet;
197 char send_buf[512] = {0};
198 int status;
200 /* marshall function arguments into the send buffer */
201 fxnCtx = (MmRpc_FxnCtx *)send_buf;
203 fxnCtx->fxn_id = Mx_Fxn_triple;
204 fxnCtx->num_params = 1;
205 fxnCtx->params[0].type = MmRpc_ParamType_Atomic;
206 fxnCtx->params[0].param.atomic.size = sizeof(int);
207 fxnCtx->params[0].param.atomic.data = a;
208 fxnCtx->num_translations = 0;
210 /* invoke the remote function call */
211 status = MmRpc_call(Mx_rpcDsp, fxnCtx, &fxnRet);
213 if (status < 0) {
214 printf("mmrpc_test: Error: MmRpc_call failed\n");
215 fxnRet = -1;
216 }
218 return(fxnRet);
219 }
221 /*
222 * ======== Mx_add ========
223 */
224 int32_t Mx_add(int32_t a, int32_t b)
225 {
226 MmRpc_FxnCtx *fxnCtx;
227 int32_t fxnRet;
228 char send_buf[512] = {0};
229 int status;
231 /* marshall function arguments into the send buffer */
232 fxnCtx = (MmRpc_FxnCtx *)send_buf;
234 fxnCtx->fxn_id = Mx_Fxn_add;
235 fxnCtx->num_params = 2;
236 fxnCtx->params[0].type = MmRpc_ParamType_Atomic;
237 fxnCtx->params[0].param.atomic.size = sizeof(int);
238 fxnCtx->params[0].param.atomic.data = a;
239 fxnCtx->params[1].type = MmRpc_ParamType_Atomic;
240 fxnCtx->params[1].param.atomic.size = sizeof(int);
241 fxnCtx->params[1].param.atomic.data = b;
242 fxnCtx->num_translations = 0;
244 /* invoke the remote function call */
245 status = MmRpc_call(Mx_rpcDsp, fxnCtx, &fxnRet);
247 if (status < 0) {
248 printf("mmrpc_test: Error: MmRpc_call failed\n");
249 fxnRet = -1;
250 }
252 return(fxnRet);
253 }
255 /*
256 * ======== Mx_compute ========
257 */
258 int32_t Mx_compute(Mx_Compute *compute)
259 {
260 MmRpc_FxnCtx *fxnCtx;
261 MmRpc_Txlt tlxtTable[2];
262 int32_t fxnRet;
263 char send_buf[512] = {0};
264 int status;
266 /* marshall function arguments into the send buffer */
267 fxnCtx = (MmRpc_FxnCtx *)send_buf;
269 fxnCtx->fxn_id = Mx_Fxn_compute;
270 fxnCtx->num_params = 1;
271 fxnCtx->params[0].type = MmRpc_ParamType_Ptr;
272 fxnCtx->params[0].param.ptr.size = sizeof(void *);
273 fxnCtx->params[0].param.ptr.addr = (size_t)compute;
274 // fxnCtx->params[0].param.ptr.handle = ...;
276 fxnCtx->num_translations = 2;
277 fxnCtx->translations = tlxtTable;
279 fxnCtx->translations[0].index = 0;
280 fxnCtx->translations[0].offset = 8;
281 fxnCtx->translations[1].index = 0;
282 fxnCtx->translations[1].offset = 12;
284 /* invoke the remote function call */
285 status = MmRpc_call(Mx_rpcDsp, fxnCtx, &fxnRet);
287 if (status < 0) {
288 printf("mmrpc_test: Error: MmRpc_call failed\n");
289 fxnRet = -1;
290 }
292 return(fxnRet);
293 }