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 * ======== Server.c ========
35 *
36 */
38 /* this define must precede inclusion of any xdc header file */
39 #define Registry_CURDESC Test__Desc
40 #define MODULE_NAME "Server"
42 /* xdctools header files */
43 #include <xdc/std.h>
44 #include <xdc/runtime/Assert.h>
45 #include <xdc/runtime/Diags.h>
46 #include <xdc/runtime/Log.h>
47 #include <xdc/runtime/Registry.h>
49 #include <stdio.h>
51 /* package header files */
52 #include <ti/ipc/MessageQ.h>
53 #include <ti/ipc/MultiProc.h>
55 #include <ti/sysbios/BIOS.h>
56 #include <ti/sysbios/knl/Task.h>
58 /* local header files */
59 #include "../shared/AppCommon.h"
61 /* module header file */
62 #include "Server.h"
64 /* module structure */
65 typedef struct {
66 UInt16 hostProcId; // host processor id
67 MessageQ_Handle slaveQue; // created locally
68 } Server_Module;
70 /* private data */
71 Registry_Desc Registry_CURDESC;
72 static Server_Module Module;
75 /*
76 * ======== Server_init ========
77 */
78 Void Server_init(Void)
79 {
80 Registry_Result result;
82 /* register with xdc.runtime to get a diags mask */
83 result = Registry_addModule(&Registry_CURDESC, MODULE_NAME);
84 Assert_isTrue(result == Registry_SUCCESS, (Assert_Id)NULL);
86 /* initialize module object state */
87 Module.hostProcId = MultiProc_getId("HOST");
88 }
91 /*
92 * ======== Server_create ========
93 */
94 Int Server_create()
95 {
96 Int status = 0;
97 MessageQ_Params msgqParams;
98 char msgqName[32];
100 /* enable some log events */
101 Diags_setMask(MODULE_NAME"+EXF");
103 /* create local message queue (inbound messages) */
104 MessageQ_Params_init(&msgqParams);
105 sprintf(msgqName, App_SlaveMsgQueName, MultiProc_getName(MultiProc_self()));
106 Module.slaveQue = MessageQ_create(msgqName, &msgqParams);
108 if (Module.slaveQue == NULL) {
109 status = -1;
110 goto leave;
111 }
113 Log_print0(Diags_INFO,"Server_create: server is ready");
115 leave:
116 Log_print1(Diags_EXIT, "<-- Server_create: %d", (IArg)status);
117 return (status);
118 }
123 /*
124 * ======== Server_exec ========
125 */
126 Int Server_exec()
127 {
128 Int status;
129 Bool running = TRUE;
130 App_Msg * msg;
131 MessageQ_QueueId queId;
133 Log_print0(Diags_ENTRY | Diags_INFO, "--> Server_exec:");
135 while (running) {
137 /* wait for inbound message */
138 status = MessageQ_get(Module.slaveQue, (MessageQ_Msg *)&msg,
139 MessageQ_FOREVER);
141 if (status < 0) {
142 goto leave;
143 }
145 if (msg->cmd == App_CMD_SHUTDOWN) {
146 running = FALSE;
147 }
149 /* process the message */
150 Log_print1(Diags_INFO, "Server_exec: processed cmd=0x%x", msg->cmd);
152 /* send message back */
153 queId = MessageQ_getReplyQueue(msg); /* type-cast not needed */
154 MessageQ_put(queId, (MessageQ_Msg)msg);
155 } /* while (running) */
157 leave:
158 Log_print1(Diags_EXIT, "<-- Server_exec: %d", (IArg)status);
159 return(status);
160 }
162 /*
163 * ======== Server_delete ========
164 */
166 Int Server_delete()
167 {
168 Int status;
170 Log_print0(Diags_ENTRY, "--> Server_delete:");
172 /* delete the video message queue */
173 status = MessageQ_delete(&Module.slaveQue);
175 if (status < 0) {
176 goto leave;
177 }
179 leave:
180 if (status < 0) {
181 Log_error1("Server_finish: error=0x%x", (IArg)status);
182 }
184 /* disable log events */
185 Log_print1(Diags_EXIT, "<-- Server_delete: %d", (IArg)status);
186 Diags_setMask(MODULE_NAME"-EXF");
188 return(status);
189 }
191 /*
192 * ======== Server_exit ========
193 */
195 Void Server_exit(Void)
196 {
197 /*
198 * Note that there isn't a Registry_removeModule() yet:
199 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=315448
200 *
201 * ... but this is where we'd call it.
202 */
203 }