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 * ======== Mx.c ========
35 */
36 #include <stdio.h>
38 #include <ti/ipc/mm/MmRpc.h>
40 #if defined(SYSLINK_BUILDOS_QNX)
41 #include <ti/shmemallocator/SharedMemoryAllocatorUsr.h>
42 #endif
44 #include "Mx.h"
46 /* hande used for remote communication */
47 static MmRpc_Handle Mx_rpcIpu = NULL;
49 /* static function indicies */
50 #define Mx_Fxn_triple (0x80000000 | 1)
51 #define Mx_Fxn_add (0x80000000 | 2)
52 #define Mx_Fxn_compute (0x80000000 | 5)
54 #define Mx_OFFSET(base, member) ((uint_t)(member) - (uint_t)(base))
56 /*
57 * ======== Mx_initialize ========
58 */
59 int Mx_initialize(void)
60 {
61 int status;
62 MmRpc_Params args;
64 /* create remote server insance */
65 MmRpc_Params_init(&args);
67 status = MmRpc_create("rpc_example", &args, &Mx_rpcIpu);
69 if (status < 0) {
70 printf("mmrpc_test: Error: MmRpc_create failed\n");
71 status = -1;
72 }
73 else {
74 status = 0;
75 }
77 return(status);
78 }
80 /*
81 * ======== Mx_finalize ========
82 */
83 void Mx_finalize(void)
84 {
85 /* delete remote server instance */
86 if (Mx_rpcIpu != NULL) {
87 MmRpc_delete(&Mx_rpcIpu);
88 }
89 }
91 /*
92 * ======== Mx_triple ========
93 */
94 int32_t Mx_triple(uint32_t a)
95 {
96 MmRpc_FxnCtx *fxnCtx;
97 int32_t fxnRet;
98 char send_buf[512] = {0};
99 int status;
101 /* marshall function arguments into the send buffer */
102 fxnCtx = (MmRpc_FxnCtx *)send_buf;
104 fxnCtx->fxn_id = Mx_Fxn_triple;
105 fxnCtx->num_params = 1;
106 fxnCtx->params[0].type = MmRpc_ParamType_Scalar;
107 fxnCtx->params[0].param.scalar.size = sizeof(int);
108 fxnCtx->params[0].param.scalar.data = a;
109 fxnCtx->num_xlts = 0;
110 fxnCtx->xltAry = NULL;
112 /* invoke the remote function call */
113 status = MmRpc_call(Mx_rpcIpu, fxnCtx, &fxnRet);
115 if (status < 0) {
116 printf("mmrpc_test: Error: MmRpc_call failed\n");
117 fxnRet = -1;
118 }
120 return(fxnRet);
121 }
123 /*
124 * ======== Mx_add ========
125 */
126 int32_t Mx_add(int32_t a, int32_t b)
127 {
128 MmRpc_FxnCtx *fxnCtx;
129 int32_t fxnRet;
130 char send_buf[512] = {0};
131 int status;
133 /* marshall function arguments into the send buffer */
134 fxnCtx = (MmRpc_FxnCtx *)send_buf;
136 fxnCtx->fxn_id = Mx_Fxn_add;
137 fxnCtx->num_params = 2;
138 fxnCtx->params[0].type = MmRpc_ParamType_Scalar;
139 fxnCtx->params[0].param.scalar.size = sizeof(int);
140 fxnCtx->params[0].param.scalar.data = a;
141 fxnCtx->params[1].type = MmRpc_ParamType_Scalar;
142 fxnCtx->params[1].param.scalar.size = sizeof(int);
143 fxnCtx->params[1].param.scalar.data = b;
144 fxnCtx->num_xlts = 0;
146 /* invoke the remote function call */
147 status = MmRpc_call(Mx_rpcIpu, fxnCtx, &fxnRet);
149 if (status < 0) {
150 printf("mmrpc_test: Error: MmRpc_call failed\n");
151 fxnRet = -1;
152 }
154 return(fxnRet);
155 }
157 /*
158 * ======== Mx_compute ========
159 */
160 int32_t Mx_compute(Mx_Compute *compute)
161 {
162 MmRpc_FxnCtx *fxnCtx;
163 MmRpc_Xlt xltAry[2];
164 int32_t fxnRet;
165 char send_buf[512] = {0};
166 int status;
168 /* marshall function arguments into the send buffer */
169 fxnCtx = (MmRpc_FxnCtx *)send_buf;
171 fxnCtx->fxn_id = Mx_Fxn_compute;
172 fxnCtx->num_params = 1;
173 fxnCtx->params[0].type = MmRpc_ParamType_Ptr;
174 fxnCtx->params[0].param.ptr.size = sizeof(Mx_Compute);
175 fxnCtx->params[0].param.ptr.addr = (size_t)compute;
176 #if defined(SYSLINK_BUILDOS_QNX)
177 fxnCtx->params[0].param.ptr.handle = NULL;
178 #else
179 /* fxnCtx->params[0].param.ptr.handle = ...; */
180 #endif
182 fxnCtx->num_xlts = 2;
183 fxnCtx->xltAry = xltAry;
185 fxnCtx->xltAry[0].index = 0;
186 fxnCtx->xltAry[0].offset = MmRpc_OFFSET(compute, &compute->inBuf);
187 fxnCtx->xltAry[0].base = (size_t)(compute->inBuf);
188 #if defined(SYSLINK_BUILDOS_QNX)
189 fxnCtx->xltAry[0].handle = NULL;
190 #else
191 /* fxnCtx->xltAry[0].handle = ...; */
192 #endif
194 fxnCtx->xltAry[1].index = 0;
195 fxnCtx->xltAry[1].offset = MmRpc_OFFSET(compute, &compute->outBuf);
196 fxnCtx->xltAry[1].base = (size_t)(compute->outBuf);
197 #if defined(SYSLINK_BUILDOS_QNX)
198 fxnCtx->xltAry[1].handle = NULL;
199 #else
200 /* fxnCtx->xltAry[1].handle = ...; */
201 #endif
203 /* invoke the remote function call */
204 status = MmRpc_call(Mx_rpcIpu, fxnCtx, &fxnRet);
206 if (status < 0) {
207 printf("mmrpc_test: Error: MmRpc_call failed\n");
208 fxnRet = -1;
209 }
211 return(fxnRet);
212 }