1 /*
2 * Copyright (c) 2012-2013, Texas Instruments Incorporated
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * * Neither the name of Texas Instruments Incorporated nor the names of
16 * its contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31 /*
32 * ======== nano_test.c ========
33 *
34 * Test for a particular customer use case.
35 *
36 * See <syslink3_repo>/src/tests/nano_test.c for usage.
37 *
38 */
40 #include <xdc/std.h>
41 #include <xdc/runtime/Assert.h>
42 #include <xdc/runtime/System.h>
44 #include <ti/sysbios/BIOS.h>
45 #include <ti/sysbios/knl/Task.h>
46 #include <ti/sysbios/knl/Clock.h>
48 #include <ti/ipc/MessageQ.h>
50 #define NUM_SLAVE_MSGS_PER_HOST_MSG 4
52 #define SLAVE_MESSAGEQNAME "SLAVE"
54 #define INPUT_MSG_DATASIZE (8192)
55 #define OUTPUT_MSG_DATASIZE (INPUT_MSG_DATASIZE / NUM_SLAVE_MSGS_PER_HOST_MSG)
57 /* Application message structures: */
58 typedef struct {
59 MessageQ_MsgHeader hdr;
60 Char *inBuf;
61 } InputMsg;
63 typedef struct {
64 MessageQ_MsgHeader hdr;
65 Char *outBuf;
66 } OutputMsg;
68 static OutputMsg outMsg;
70 /*
71 * ======== tsk1Fxn ========
72 * Receive and return messages
73 */
74 Void tsk1Fxn(UArg arg0, UArg arg1)
75 {
76 InputMsg *inMsg;
77 MessageQ_Handle messageQ;
78 MessageQ_QueueId remoteQueueId;
79 Int status;
80 int i;
82 /* Create a message queue. */
83 messageQ = MessageQ_create(SLAVE_MESSAGEQNAME, NULL);
84 if (messageQ == NULL) {
85 System_abort("MessageQ_create failed\n" );
86 }
88 System_printf("tsk1Fxn: created MessageQ: %s; QueueID: 0x%x\n",
89 SLAVE_MESSAGEQNAME, MessageQ_getQueueId(messageQ));
91 /* Use a static message for outMsg: no need to call MessageQ_alloc(): */
92 MessageQ_staticMsgInit((MessageQ_Msg)&outMsg, sizeof(OutputMsg));
94 System_printf("Start the main loop\n");
95 while (1) {
96 /* Get one block (8Kb) of data passed as a pointer to shared memory */
97 status = MessageQ_get(messageQ, (MessageQ_Msg *)&inMsg,
98 MessageQ_FOREVER);
99 if (status != MessageQ_S_SUCCESS) {
100 System_abort("This should not happen since timeout is forever\n");
101 }
102 remoteQueueId = MessageQ_getReplyQueue(inMsg);
104 for (i = 0; i < NUM_SLAVE_MSGS_PER_HOST_MSG; i++) {
105 /* Send back the data in 4 chunks: */
106 MessageQ_setMsgId ((MessageQ_Msg)&outMsg, i);
108 /* Return pointer to ith chunk of data: */
109 outMsg.outBuf = inMsg->inBuf + i * OUTPUT_MSG_DATASIZE;
111 status = MessageQ_put(remoteQueueId, (MessageQ_Msg)&outMsg);
112 if (status != MessageQ_S_SUCCESS) {
113 System_abort("MessageQ_put had a failure/error\n");
114 }
115 }
116 MessageQ_free ((MessageQ_Msg)inMsg);
117 }
118 }
120 /*
121 * ======== main ========
122 */
123 Int main(Int argc, Char* argv[])
124 {
125 System_printf("%s:main: MultiProc id = %d\n", __FILE__, MultiProc_self());
127 Task_create(tsk1Fxn, NULL, NULL);
129 BIOS_start();
131 return (0);
132 }