1 /*
2 * Copyright (c) 2012-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 */
32 /*
33 * ======== messageq_single.c ========
34 *
35 * Single threaded test of messageq over rpmsg.
36 *
37 * See:
38 * MessageQApp in Linux user space
39 *
40 */
41 #include <xdc/std.h>
42 #include <xdc/runtime/Assert.h>
43 #include <xdc/runtime/System.h>
45 #include <ti/sysbios/BIOS.h>
46 #include <ti/sysbios/knl/Task.h>
47 #include <ti/sysbios/knl/Clock.h>
49 #include <ti/ipc/MessageQ.h>
51 #define SLAVE_MESSAGEQNAME "SLAVE"
53 #define MessageQ_payload(m) ((void *)((char *)(m) + sizeof(MessageQ_MsgHeader)))
55 /*
56 * ======== tsk1Fxn ========
57 * Receive and return messages
58 */
59 Void tsk1Fxn(UArg arg0, UArg arg1)
60 {
61 MessageQ_Msg msg;
62 MessageQ_Handle messageQ;
63 MessageQ_QueueId remoteQueueId;
64 Char localQueueName[64];
65 UInt16 procId;
66 Int status;
67 UInt16 msgId;
68 UInt32 start;
69 UInt32 end;
70 Uint32 numLoops;
71 UInt32 print;
72 UInt32 *params;
74 /* Construct a MessageQ name adorned with core name: */
75 System_sprintf(localQueueName, "%s_%s", SLAVE_MESSAGEQNAME,
76 MultiProc_getName(MultiProc_self()));
78 messageQ = MessageQ_create(localQueueName, NULL);
79 if (messageQ == NULL) {
80 System_abort("MessageQ_create failed\n");
81 }
83 System_printf("tsk1Fxn: created MessageQ: %s; QueueID: 0x%x\n",
84 localQueueName, MessageQ_getQueueId(messageQ));
86 while (1) {
87 /* handshake with host to get starting parameters */
88 System_printf("Awaiting sync message from host...\n");
89 MessageQ_get(messageQ, &msg, MessageQ_FOREVER);
91 params = MessageQ_payload(msg);
92 numLoops = params[0];
93 print = params[1];
95 remoteQueueId = MessageQ_getReplyQueue(msg);
96 procId = MessageQ_getProcId(remoteQueueId);
98 System_printf("Received msg from (procId:remoteQueueId): 0x%x:0x%x\n"
99 "\tpayload: %d bytes; loops: %d %s printing.\n",
100 procId, remoteQueueId,
101 (MessageQ_getMsgSize(msg) - sizeof(MessageQ_MsgHeader)),
102 numLoops, print ? "with" : "without");
104 MessageQ_put(remoteQueueId, msg);
106 start = Clock_getTicks();
107 for (msgId = 0; msgId < numLoops; msgId++) {
108 status = MessageQ_get(messageQ, &msg, MessageQ_FOREVER);
109 Assert_isTrue(status == MessageQ_S_SUCCESS, NULL);
111 if (print) {
112 System_printf("Got msg #%d (%d bytes) from procId %d\n",
113 MessageQ_getMsgId(msg), MessageQ_getMsgSize(msg), procId);
114 }
116 Assert_isTrue(MessageQ_getMsgId(msg) == msgId, NULL);
118 if (print) {
119 System_printf("Sending msg Id #%d to procId %d\n", msgId,
120 procId);
121 }
123 status = MessageQ_put(remoteQueueId, msg);
124 Assert_isTrue(status == MessageQ_S_SUCCESS, NULL);
125 }
126 end = Clock_getTicks();
128 if (!print) {
129 System_printf("%d iterations took %d ticks or %d usecs/msg\n",
130 numLoops,
131 end - start, ((end - start) * Clock_tickPeriod) / numLoops);
132 }
133 }
134 }
136 /*
137 * ======== main ========
138 */
139 Int main(Int argc, Char* argv[])
140 {
141 System_printf("%s:main: MultiProc id = %d\n", __FILE__, MultiProc_self());
143 Task_create(tsk1Fxn, NULL, NULL);
145 BIOS_start();
147 return (0);
148 }