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 /* module 'Mx' functions */
42 int Mx_initialize(void);
43 void Mx_finalize(void);
45 int32_t Mx_triple(uint32_t a);
46 int32_t Mx_add(int32_t a, int32_t b);
48 MmRpc_Handle Mx_rpcDsp = NULL;
50 /* static function indicies */
51 #define Mx_Fxn_triple (0x80000000 | 1)
52 #define Mx_Fxn_add (0x80000000 | 2)
55 /*
56 * ======== main ========
57 */
58 int main(int argc, char **argv)
59 {
60 int status;
61 int32_t ret;
63 printf("mmrpc_test: --> main\n");
65 /* initialize Mx module (setup rpc connection) */
66 status = Mx_initialize();
68 if (status < 0) {
69 goto leave;
70 }
72 /* invoke Mx functions */
73 ret = Mx_triple(11);
74 printf("mmrpc_test: Mx_triple(11), ret=%d\n", ret);
76 if (ret < 0) {
77 status = -1;
78 goto leave;
79 }
81 ret = Mx_triple(111);
82 printf("mmrpc_test: Mx_triple(111), ret=%d\n", ret);
84 if (ret < 0) {
85 status = -1;
86 goto leave;
87 }
89 ret = Mx_add(44, 66);
90 printf("mmrpc_test: Mx_add(44, 66), ret=%d\n", ret);
92 if (ret < 0) {
93 status = -1;
94 goto leave;
95 }
97 leave:
98 /* finalize Mx module (destroy rpc connection) */
99 Mx_finalize();
101 if (status < 0) {
102 printf("mmrpc_test: FAILED\n");
103 }
104 else {
105 printf("mmrpc_test: PASSED\n");
106 }
107 return(0);
108 }
110 /*
111 * ======== Mx_initialize ========
112 */
113 int Mx_initialize(void)
114 {
115 int status;
116 MmRpc_Params params;
118 /* create remote server insance */
119 MmRpc_Params_init(¶ms);
121 status = MmRpc_create("DSP", "FooServer", ¶ms, &Mx_rpcDsp);
123 if (status < 0) {
124 printf("mmrpc_test: Error: MmRpc_create failed\n");
125 status = -1;
126 }
127 else {
128 status = 0;
129 }
131 return(status);
132 }
134 /*
135 * ======== Mx_finalize ========
136 */
137 void Mx_finalize(void)
138 {
139 /* delete remote server instance */
140 if (Mx_rpcDsp != NULL) {
141 MmRpc_delete(&Mx_rpcDsp);
142 }
143 }
145 /*
146 * ======== Mx_triple ========
147 */
148 int32_t Mx_triple(uint32_t a)
149 {
150 MmRpc_FxnCtx *fxnCtx;
151 int32_t fxnRet;
152 char send_buf[512] = {0};
153 int status;
155 /* marshall function arguments into the send buffer */
156 fxnCtx = (MmRpc_FxnCtx *)send_buf;
158 fxnCtx->fxn_id = Mx_Fxn_triple;
159 fxnCtx->num_params = 1;
160 fxnCtx->params[0].type = MmRpc_ParamType_Atomic;
161 fxnCtx->params[0].param.atomic.size = sizeof(int);
162 fxnCtx->params[0].param.atomic.data = a;
163 fxnCtx->num_translations = 0;
165 /* invoke the remote function call */
166 status = MmRpc_call(Mx_rpcDsp, fxnCtx, &fxnRet);
168 if (status < 0) {
169 printf("mmrpc_test: Error: MmRpc_call failed\n");
170 fxnRet = -1;
171 }
173 return(fxnRet);
174 }
176 /*
177 * ======== Mx_add ========
178 */
179 int32_t Mx_add(int32_t a, int32_t b)
180 {
181 MmRpc_FxnCtx *fxnCtx;
182 int32_t fxnRet;
183 char send_buf[512] = {0};
184 int status;
186 /* marshall function arguments into the send buffer */
187 fxnCtx = (MmRpc_FxnCtx *)send_buf;
189 fxnCtx->fxn_id = Mx_Fxn_add;
190 fxnCtx->num_params = 2;
191 fxnCtx->params[0].type = MmRpc_ParamType_Atomic;
192 fxnCtx->params[0].param.atomic.size = sizeof(int);
193 fxnCtx->params[0].param.atomic.data = a;
194 fxnCtx->params[1].type = MmRpc_ParamType_Atomic;
195 fxnCtx->params[1].param.atomic.size = sizeof(int);
196 fxnCtx->params[1].param.atomic.data = b;
197 fxnCtx->num_translations = 0;
199 /* invoke the remote function call */
200 status = MmRpc_call(Mx_rpcDsp, fxnCtx, &fxnRet);
202 if (status < 0) {
203 printf("mmrpc_test: Error: MmRpc_call failed\n");
204 fxnRet = -1;
205 }
207 return(fxnRet);
208 }