1 /*
2 * Copyright (c) 2013-2014, 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 * ======== 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>
46 #include <ti/ipc/MultiProc.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 /* Ipc initialization */
97 status = Ipc_start();
99 if (status >= 0) {
100 /* application create, exec, delete */
101 status = Main_main();
103 /* Ipc finalization */
104 Ipc_stop();
105 }
106 else {
107 printf("Ipc_start failed: status = %d\n", status);
108 goto leave;
109 }
111 leave:
112 printf("<-- main:\n");
113 status = (status >= 0 ? 0 : status);
115 return (status);
116 }
119 /*
120 * ======== Main_main ========
121 */
122 Int Main_main(Void)
123 {
124 Int status = 0;
126 printf("--> Main_main:\n");
128 /* BEGIN application phase */
130 /* application create phase */
131 status = GateMPApp_create();
133 if (status < 0) {
134 goto leave;
135 }
137 /* application execute phase */
138 status = GateMPApp_exec();
140 if (status < 0) {
141 goto leave;
142 }
144 /* application delete phase */
145 status = GateMPApp_delete();
147 if (status < 0) {
148 goto leave;
149 }
151 leave:
152 printf("<-- Main_main:\n");
154 status = (status >= 0 ? 0 : status);
155 return (status);
156 }
159 /*
160 * ======== Main_parseArgs ========
161 */
162 Int Main_parseArgs(Int argc, Char *argv[])
163 {
164 Int x, cp, opt;
165 Int status = 0;
168 /* parse the command line options */
169 for (opt = 1; (opt < argc) && (argv[opt][0] == '-'); opt++) {
170 for (x = 0, cp = 1; argv[opt][cp] != '\0'; cp++) {
171 x = (x << 8) | (int)argv[opt][cp];
172 }
174 switch (x) {
175 case 'h': /* -h */
176 printf("%s", Main_USAGE);
177 exit(0);
178 break;
180 default:
181 printf(
182 "Error: %s, line %d: invalid option, %c\n",
183 __FILE__, __LINE__, (Char)x);
184 printf("%s", Main_USAGE);
185 status = -1;
186 goto leave;
187 }
188 }
190 /* parse the command line arguments */
191 if (opt < argc) {
192 printf(
193 "Error: %s, line %d: too many arguments\n",
194 __FILE__, __LINE__);
195 printf("%s", Main_USAGE);
196 status = -1;
197 goto leave;
198 }
200 leave:
201 return(status);
202 }