]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blob - linux/src/tests/nano_test.c
09fd9b3f10fac9f8a332a80e9b365e0f5b2197d4
[ipc/ipcdev.git] / linux / src / tests / nano_test.c
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  *  @file   nano_test.c
34  *
35  *  @brief  Customer use case test application.
36  *
37  *  Usage:  See etc/omapl138/nano_test.sh
38  *
39  *  Notes:  There is an overrun reported by arecord in the very begining of
40  *          the test.  This does not appear to be due to DSP communication,
41  *          as there are no overruns once the test gets past initialization.
42  *          One possible cause is a startup effect of using the shell
43  *          pipe command.
44  *
45  *  ============================================================================
46  */
48 /* Standard headers */
49 #include <stdio.h>
51 /* IPC headers */
52 #include <Std.h>
53 #include <ti/ipc/Ipc.h>
54 #include <ti/ipc/MessageQ.h>
56 #include <ti/sdo/linuxutils/cmem/include/cmem.h>
58 typedef struct MyMsg {
59     MessageQ_MsgHeader header;
60     unsigned long bufPhys;
61 } MyMsg;
63 #define VERBOSE 0
65 /* App defines:  Must match on remote proc side: */
66 #define NUM_SLAVE_MSGS_PER_HOST_MSG   4
67 #define PAYLOADSIZE         (8192)
69 #define MSGSIZE             (sizeof(MyMsg))
71 #define HEAPID              0u
72 #define CORE0_MESSAGEQNAME  "SLAVE"
73 #define MPU_MESSAGEQNAME    "HOST"
75 Int
76 Nanotest_execute ()
77 {
78     Int32                    status     = 0;
79     MessageQ_Msg             msg        = NULL;
80     MessageQ_Params          msgParams;
81     MessageQ_QueueId         queueId = MessageQ_INVALIDMESSAGEQ;
82     MessageQ_Handle          msgqHandle;
83     int                      i, j;
84     int                      ret;
85     void                     *payload;
86     unsigned long            payloadPhys;
87     CMEM_AllocParams         cmemAttrs;
88     MyMsg                    *myMsgPtr;
90     printf ("Entered Nanotest_execute\n");
92     /* Create the local Message Queue for receiving. */
93     MessageQ_Params_init (&msgParams);
94     msgqHandle = MessageQ_create (MPU_MESSAGEQNAME, &msgParams);
95     if (msgqHandle == NULL) {
96         printf ("Error in MessageQ_create\n");
97         goto exit;
98     }
99     else {
100         printf ("Local MessageQId: 0x%x\n",
101             MessageQ_getQueueId(msgqHandle));
102     }
104     /* Poll until remote side has it's messageQ created before we send: */
105     do {
106         status = MessageQ_open (CORE0_MESSAGEQNAME, &queueId);
107         sleep (1);
108     } while (status == MessageQ_E_NOTFOUND);
109     if (status < 0) {
110         printf ("Error in MessageQ_open [%d]\n", status);
111         goto cleanup_create;
112     }
113     else {
114         printf ("Remote queueId  [0x%x]\n", queueId);
115     }
117     cmemAttrs.type = CMEM_HEAP;
118     cmemAttrs.flags = CMEM_NONCACHED;
119     cmemAttrs.alignment = 0;
120     payload = CMEM_alloc(PAYLOADSIZE, &cmemAttrs);
121     if (payload == NULL) {
122         printf("CMEM_alloc() failed (returned NULL)\n");
123         goto cleanup_close;
124     }
125     payloadPhys = CMEM_getPhys(payload);
127     printf ("\nExchanging messages with remote processor...\n");
128     for (i = 0 ; ; i++) {
130         /* read a block of data from stdin */
131         ret = fread(payload, 1, PAYLOADSIZE, stdin);
132         if (ret < PAYLOADSIZE) {
133             printf ("EOS: Exiting without sending remaining %d bytes\n", ret);
134             break;
135         }
137         /* Allocate message. */
138         msg = MessageQ_alloc (HEAPID, MSGSIZE);
139         if (msg == NULL) {
140             printf ("Error in MessageQ_alloc\n");
141             goto cleanup_cmem;
142         }
144         MessageQ_setMsgId (msg, i);
146         /* Have the remote proc reply to this message queue */
147         MessageQ_setReplyQueue (msgqHandle, msg);
149         myMsgPtr = (MyMsg *)msg;
150         myMsgPtr->bufPhys = payloadPhys;
152         printf("Sending msgId: %d, size: %d, *msg: 0x%lx\n", i,
153                MessageQ_getMsgSize(msg), myMsgPtr->bufPhys);
155         status = MessageQ_put(queueId, msg);
156         if (status < 0) {
157             printf ("Error in MessageQ_put [%d]\n", status);
158             break;
159         }
161         for (j = 0 ; j < NUM_SLAVE_MSGS_PER_HOST_MSG; j++) {
162            status = MessageQ_get(msgqHandle, &msg, MessageQ_FOREVER);
163            if (status < 0) {
164                printf ("Error in MessageQ_get [%d]\n", status);
165                status = MessageQ_free(msg);
166                goto cleanup_close;
167            }
168            else {
169                myMsgPtr = (MyMsg *)msg;
170 #if  VERBOSE
171                printf ("Received msgId: %d, size: %d, *msg: 0x%lx\n",
172                        MessageQ_getMsgId(msg), MessageQ_getMsgSize(msg),
173                        myMsgPtr->bufPhys);
174 #endif
176                /* Validate the returned message. */
177                if ((msg != NULL) && (MessageQ_getMsgId(msg) != j)) {
178                    printf ("Data integrity failure:\n"
179                         "    Expected %d\n"
180                         "    Received %d\n",
181                         j, MessageQ_getMsgId (msg));
182                    MessageQ_free(msg);
183                    goto cleanup_close;
184                }
185                status = MessageQ_free(msg);
186                if (status < 0) {
187                    printf ("Error in MessageQ_free [%d]\n", status);
188                }
189            }
190         }
191     }
193     printf ("Exchanged messages: tx %d, rx %d\n",
194              i, i*NUM_SLAVE_MSGS_PER_HOST_MSG);
195     printf ("Transferred %d KB\n", (i * PAYLOADSIZE) / 1024);
197     if (status >= 0) {
198         printf ("Sample application successfully completed!\n");
199     }
201 cleanup_cmem:
202     CMEM_free(payload, &cmemAttrs);
204 cleanup_close:
205     MessageQ_close (&queueId);
207 cleanup_create:
208     /* Clean-up */
209     status = MessageQ_delete (&msgqHandle);
210     if (status < 0) {
211         printf ("Error in MessageQ_delete [%d]\n", status);
212     }
214 exit:
215     printf ("Leaving Nanotest_execute\n\n");
217     return (status);
220 int main (int argc, char ** argv)
222     Int32   status = 0;
224     if (CMEM_init() < 0) {
225         printf("CMEM_init failed\n");
227         return(-1);
228     }
230     status = Ipc_start();
232     if (status >= 0) {
233         Nanotest_execute();
234         Ipc_stop();
235     }
236     else {
237         printf ("Ipc_start failed: status = 0x%x\n", status);
238     }
240     return(0);