1 /*
2 * Copyright (c) 2013-2015 Texas Instruments Incorporated - http://www.ti.com
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 * ======== main_host.c ========
35 *
36 */
38 /* cstdlib header files */
39 #include <stdio.h>
40 #include <stdlib.h>
42 /* package header files */
43 #include <ti/ipc/Std.h>
44 #include <ti/ipc/Ipc.h>
45 #include <ti/ipc/MultiProc.h>
46 #include <ti/ipc/transports/TransportRpmsg.h>
48 #include <ti/cmem.h>
50 /* local header files */
51 #include "GateMPApp.h"
53 /* private functions */
54 static Int Main_main(Void);
55 static Int Main_parseArgs(Int argc, Char *argv[]);
58 #define Main_USAGE "\
59 Usage:\n\
60 GateMPApp [options]\n\
61 \n\
62 Options:\n\
63 h : print this help message\n\
64 \n\
65 Examples:\n\
66 GateMPApp\n\
67 GateMPApp -h\n\
68 \n"
71 /*
72 * ======== main ========
73 */
74 Int main(Int argc, Char* argv[])
75 {
76 Int status;
78 printf("--> main:\n");
80 /* parse command line */
81 status = Main_parseArgs(argc, argv);
83 if (status < 0) {
84 goto leave;
85 }
87 status = CMEM_init();
88 if (status < 0) {
89 printf("CMEM_init failed\n");
90 goto leave;
91 }
92 else {
93 printf("CMEM_init success\n");
94 }
96 /* configure the transport factory */
97 Ipc_transportConfig(&TransportRpmsg_Factory);
99 /* IPC initialization */
100 status = Ipc_start();
102 if (status >= 0) {
103 /* application create, exec, delete */
104 status = Main_main();
106 /* Ipc finalization */
107 Ipc_stop();
108 }
109 else {
110 printf("Ipc_start failed: status = %d\n", status);
111 goto leave;
112 }
114 leave:
115 printf("<-- main:\n");
116 status = (status >= 0 ? 0 : status);
118 return (status);
119 }
122 /*
123 * ======== Main_main ========
124 */
125 Int Main_main(Void)
126 {
127 Int status = 0;
129 printf("--> Main_main:\n");
131 /* BEGIN application phase */
133 /* application create phase */
134 status = GateMPApp_create();
136 if (status < 0) {
137 goto leave;
138 }
140 /* application execute phase */
141 status = GateMPApp_exec();
143 if (status < 0) {
144 goto leave;
145 }
147 /* application delete phase */
148 status = GateMPApp_delete();
150 if (status < 0) {
151 goto leave;
152 }
154 leave:
155 printf("<-- Main_main:\n");
157 status = (status >= 0 ? 0 : status);
158 return (status);
159 }
162 /*
163 * ======== Main_parseArgs ========
164 */
165 Int Main_parseArgs(Int argc, Char *argv[])
166 {
167 Int x, cp, opt;
168 Int status = 0;
171 /* parse the command line options */
172 for (opt = 1; (opt < argc) && (argv[opt][0] == '-'); opt++) {
173 for (x = 0, cp = 1; argv[opt][cp] != '\0'; cp++) {
174 x = (x << 8) | (int)argv[opt][cp];
175 }
177 switch (x) {
178 case 'h': /* -h */
179 printf("%s", Main_USAGE);
180 exit(0);
181 break;
183 default:
184 printf(
185 "Error: %s, line %d: invalid option, %c\n",
186 __FILE__, __LINE__, (Char)x);
187 printf("%s", Main_USAGE);
188 status = -1;
189 goto leave;
190 }
191 }
193 /* parse the command line arguments */
194 if (opt < argc) {
195 printf(
196 "Error: %s, line %d: too many arguments\n",
197 __FILE__, __LINE__);
198 printf("%s", Main_USAGE);
199 status = -1;
200 goto leave;
201 }
203 leave:
204 return(status);
205 }