summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBuddy Liong2017-01-10 12:54:50 -0600
committerBuddy Liong2017-01-10 12:57:09 -0600
commit0ec98f95028e6640e38e95e55edfdf5eb9514dca (patch)
tree3b358a5bbfed2e64849148aca56a5ac5d7da5cf6
downloadrvc-0ec98f95028e6640e38e95e55edfdf5eb9514dca.tar.gz
rvc-0ec98f95028e6640e38e95e55edfdf5eb9514dca.tar.xz
rvc-0ec98f95028e6640e38e95e55edfdf5eb9514dca.zip
Initial
Adding appA15HeartBeatHost client for A15 Heartbeat implementation for M4 to know the A15 status. Signed-off-by: Buddy Liong <a0270631@ti.com>
-rw-r--r--Android.mk26
-rw-r--r--appA15HeartBeatHost.c381
-rw-r--r--appA15HeartBeatHost.h86
3 files changed, 493 insertions, 0 deletions
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..c34195a
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,26 @@
1LOCAL_PATH:= $(call my-dir)
2
3#
4# appA15HeartBeatHost
5#
6
7##### appA15HeartBeatHost #####
8include $(CLEAR_VARS)
9
10IPC_ROOT := ../ipc/
11
12LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(IPC_ROOT)/linux/include \
13 $(LOCAL_PATH)/$(IPC_ROOT)/packages \
14 $(LOCAL_PATH)/hlos_common/include
15
16LOCAL_CFLAGS += -DIPC_BUILDOS_ANDROID
17
18LOCAL_MODULE_TAGS:= optional
19
20LOCAL_SRC_FILES:= appA15HeartBeatHost.c
21
22LOCAL_SHARED_LIBRARIES := \
23 liblog libtiipcutils libtiipc libtitransportrpmsg
24
25LOCAL_MODULE:= appA15HeartBeatHost
26include $(BUILD_EXECUTABLE)
diff --git a/appA15HeartBeatHost.c b/appA15HeartBeatHost.c
new file mode 100644
index 0000000..f2e6509
--- /dev/null
+++ b/appA15HeartBeatHost.c
@@ -0,0 +1,381 @@
1/*
2 * Copyright (c) 2016, 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/*
34 * ======== appA15HeartBeatHost.c ========
35 *
36 */
37
38/* host header files */
39#include <stdio.h>
40#include <unistd.h>
41#include <time.h>
42
43/* package header files */
44#include <ti/ipc/Std.h>
45#include <ti/ipc/Ipc.h>
46#include <ti/ipc/transports/TransportRpmsg.h>
47#include <ti/ipc/MessageQ.h>
48#include <ti/ipc/MultiProc.h>
49
50/* private functions */
51static Int Main_main(Void);
52static Int Main_parseArgs(Int argc, Char *argv[]);
53
54/* local header files */
55#include "appA15HeartBeatHost.h"
56
57/* module structure */
58typedef struct {
59 MessageQ_MsgHeader reserved;
60 UInt32 cmd;
61} App_Msg;
62
63typedef struct {
64 MessageQ_Handle hostQue; // created locally
65 MessageQ_QueueId slaveQue; // opened remotely
66 UInt16 heapId; // MessageQ heapId
67 UInt32 msgSize;
68} App_Module;
69
70/* private data */
71static App_Module Module;
72static String Main_remoteProcName = NULL;
73#ifdef DEBUG
74static UInt32 MessageCount = 0;
75#endif
76/*
77 * ======== App_create ========
78 */
79
80Int App_create(UInt16 remoteProcId)
81{
82 Int status = 0;
83 MessageQ_Params msgqParams;
84 char msgqName[32];
85
86 ALOGE("--> App_create:");
87
88 /* setting default values */
89 Module.hostQue = NULL;
90 Module.slaveQue = MessageQ_INVALIDMESSAGEQ;
91 Module.heapId = App_MsgHeapId;
92 Module.msgSize = sizeof(App_Msg);
93
94 /* create local message queue (inbound messages) */
95 MessageQ_Params_init(&msgqParams);
96
97 Module.hostQue = MessageQ_create(App_HostMsgQueName, &msgqParams);
98
99 if (Module.hostQue == NULL) {
100 ALOGE("App_create: Failed creating MessageQ");
101 status = -1;
102 goto leave;
103 }
104
105 /* open the remote message queue */
106 sprintf(msgqName, App_SlaveMsgQueName, MultiProc_getName(remoteProcId));
107
108 do {
109 status = MessageQ_open(msgqName, &Module.slaveQue);
110 sleep(1);
111 } while (status == MessageQ_E_NOTFOUND);
112
113 if (status < 0) {
114 ALOGE("App_create: Failed opening MessageQ");
115 goto leave;
116 }
117
118 ALOGE("App_create: Host is ready");
119
120leave:
121 ALOGE("<-- App_create:");
122 return(status);
123}
124
125
126/*
127 * ======== App_delete ========
128 */
129Int App_delete(Void)
130{
131 Int status;
132
133 ALOGE("--> App_delete:");
134
135 /* close remote resources */
136 status = MessageQ_close(&Module.slaveQue);
137
138 if (status < 0) {
139 goto leave;
140 }
141
142 /* delete the host message queue */
143 status = MessageQ_delete(&Module.hostQue);
144
145 if (status < 0) {
146 goto leave;
147 }
148
149leave:
150 ALOGE("<-- App_delete:");
151 return(status);
152}
153
154
155/*
156 * ======== App_exec ========
157 */
158Int App_exec(Void)
159{
160 Int status;
161 Int i;
162 App_Msg * msg;
163 Bool running = TRUE;
164 struct timeval tv;
165
166 ALOGE("--> App_exec:");
167
168 /* allocate message */
169 msg = (App_Msg *)MessageQ_alloc(Module.heapId, Module.msgSize);
170
171 if (msg == NULL) {
172 status = -1;
173 goto leave;
174 }
175
176 /* fill in message payload */
177 msg->cmd = App_CMD_START;
178#ifdef DEBUG
179 MessageCount++;
180 // Get current time of day
181 gettimeofday(&tv, NULL);
182 ALOGE("%ld us: App_exec: sending #%d message %d \n", (tv.tv_sec * 1000000) + tv.tv_usec, MessageCount, msg->cmd);
183#endif
184
185 while (running) {
186 /* send START 1st message */
187 MessageQ_put(Module.slaveQue, (MessageQ_Msg)msg);
188
189 // Sleep for Microseconds - 500ms
190 usleep(Microseconds);
191
192 /* allocate message */
193 msg = (App_Msg *)MessageQ_alloc(Module.heapId, Module.msgSize);
194
195 if (msg == NULL) {
196 ALOGE("--> App_exec: MessageQ_alloc FAILED");
197 status = -1;
198 goto leave;
199 }
200
201 /* fill in message payload */
202 msg->cmd = App_CMD_ALIVE;
203#ifdef DEBUG
204 MessageCount++;
205 gettimeofday(&tv, NULL);
206 ALOGE("%ld us: App_exec: sending #%d App_CMD_ALIVE \n", (tv.tv_sec * 1000000) + tv.tv_usec, MessageCount);
207#endif
208 }
209
210leave:
211 ALOGE("<-- App_exec: %d\n", status);
212 return(status);
213}
214
215/*
216 * ======== main ========
217 */
218Int main(Int argc, Char* argv[])
219{
220 Int status;
221
222 ALOGE("--> main:");
223
224 /* configure the transport factory */
225 Ipc_transportConfig(&TransportRpmsg_Factory);
226
227 /* parse command line */
228 status = Main_parseArgs(argc, argv);
229
230 if (status < 0) {
231 goto leave;
232 }
233
234 /* Ipc initialization */
235 status = Ipc_start();
236
237 if (status >= 0) {
238 /* application create, exec, delete */
239 status = Main_main();
240
241 /* Ipc finalization */
242 Ipc_stop();
243 }
244 else {
245 ALOGE("Ipc_start failed: status = %d\n", status);
246 goto leave;
247 }
248
249leave:
250 ALOGE("<-- main:\n");
251 status = (status >= 0 ? 0 : status);
252
253 return (status);
254}
255
256
257/*
258 * ======== Main_main ========
259 */
260Int Main_main(Void)
261{
262 UInt16 remoteProcId;
263 Int status = 0;
264
265 ALOGE("--> Main_main:\n");
266
267 remoteProcId = MultiProc_getId(Main_remoteProcName);
268
269 /* application create phase */
270 status = App_create(remoteProcId);
271
272 if (status < 0) {
273 goto leave;
274 }
275
276 /* application execute phase */
277 status = App_exec();
278
279 if (status < 0) {
280 goto leave;
281 }
282
283 /* application delete phase */
284 status = App_delete();
285
286 if (status < 0) {
287 goto leave;
288 }
289
290leave:
291 ALOGE("<-- Main_main:");
292
293 status = (status >= 0 ? 0 : status);
294 return (status);
295}
296
297
298/*
299 * ======== Main_parseArgs ========
300 */
301Int Main_parseArgs(Int argc, Char *argv[])
302{
303 Int x, cp, opt, argNum;
304 UInt16 i, numProcs;
305 String name;
306 Int status = 0;
307
308
309 /* parse the command line options */
310 for (opt = 1; (opt < argc) && (argv[opt][0] == '-'); opt++) {
311 for (x = 0, cp = 1; argv[opt][cp] != '\0'; cp++) {
312 x = (x << 8) | (int)argv[opt][cp];
313 }
314
315 switch (x) {
316 case 'h': /* -h */
317 ALOGE("%s", Main_USAGE);
318 exit(0);
319 break;
320
321 case 'l': /* -l */
322 //ALOGE("Processor List");
323 printf("Processor List\n");
324 status = Ipc_start();
325 if (status >= 0) {
326 numProcs = MultiProc_getNumProcessors();
327 for (i = 0; i < numProcs; i++) {
328 name = MultiProc_getName(i);
329 //ALOGE(" procId=%d, procName=%s", i, name);
330 printf(" procId=%d, procName=%s\n", i, name);
331 }
332 Ipc_stop();
333 }
334 else {
335 printf(
336 "Error: %s, line %d: Ipc_start failed status %d\n",
337 __FILE__, __LINE__, status);
338 goto leave;
339 }
340 exit(0);
341 break;
342
343 default:
344 printf(
345 "Error: %s, line %d: invalid option, %c\n",
346 __FILE__, __LINE__, (Char)x);
347 printf("%s", Main_USAGE);
348 status = -1;
349 goto leave;
350 }
351 }
352
353 /* parse the command line arguments */
354 for (argNum = 1; opt < argc; argNum++, opt++) {
355
356 switch (argNum) {
357 case 1: /* name of proc #1 */
358 Main_remoteProcName = argv[opt];
359 break;
360
361 default:
362 printf(
363 "Error: %s, line %d: too many arguments\n",
364 __FILE__, __LINE__);
365 printf("%s", Main_USAGE);
366 status = -1;
367 goto leave;
368 }
369 }
370
371 /* validate command line arguments */
372 if (Main_remoteProcName == NULL) {
373 printf("Error: missing procName argument\n");
374 printf("%s", Main_USAGE);
375 status = -1;
376 goto leave;
377 }
378
379leave:
380 return(status);
381}
diff --git a/appA15HeartBeatHost.h b/appA15HeartBeatHost.h
new file mode 100644
index 0000000..3104510
--- /dev/null
+++ b/appA15HeartBeatHost.h
@@ -0,0 +1,86 @@
1/*
2 * Copyright (c) 2016, 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/*
34 * ======== appA15HeartBeatHost.h ========
35 *
36 */
37
38#ifndef appA15HeartBeatHost__include
39#define appA15HeartBeatHost__include
40#if defined (__cplusplus)
41extern "C" {
42#endif
43
44#include <utils/Log.h>
45#define LOG_TAG "AppA15HeartBeatHost"
46
47/* notify commands 00 - FF */
48#define App_CMD_MASK 0xFF000000
49#define App_CMD_START 0x00000000
50#define App_CMD_ALIVE 0x01000000
51#define App_CMD_SHUTDOWN 0x02000000
52
53#define App_MsgHeapId 0
54#define App_HostMsgQueName "HOST:MsgQ:01"
55#define App_SlaveMsgQueName "%s:MsgQ:01" /* %s is each slave's Proc Name */
56
57#define Main_USAGE "\
58Usage:\n\
59 appA15HeartBeatHost [options] procName\n\
60\n\
61Arguments:\n\
62 procName : the name of the remote processor\n\
63\n\
64Options:\n\
65 h : print this help message\n\
66 l : list the available remote names\n\
67\n\
68Examples:\n\
69 appA15HeartBeatHost DSP\n\
70 appA15HeartBeatHost -l\n\
71 appA15HeartBeatHost -h\n\
72\n"
73
74//#define DEBUG
75
76#define Microseconds (500 * 1000)
77
78Int App_create(UInt16 remoteProcId);
79Int App_delete();
80Int App_exec();
81
82
83#if defined (__cplusplus)
84}
85#endif /* defined (__cplusplus) */
86#endif /* appA15HeartBeatHost__include */