07fe9716dfa3151faf42f821fc7c20718a9aea0e
[processor-sdk/pdk.git] / packages / ti / drv / ipc / examples / ex05_bios_multicore_echo_negative_test / ipc_neg_testsetup.c
1 /*
2  *  Copyright (c) Texas Instruments Incorporated 2020
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
15  *    distribution.
16  *
17  *    Neither the name of Texas Instruments Incorporated nor the names of
18  *    its contributors may be used to endorse or promote products derived
19  *    from this software without specific prior written permission.
20  *
21  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
34 /**
35  *  \file ipc_neg_testsetup.c
36  *
37  *  \brief IPC  example code
38  *
39  */
41 /* ========================================================================== */
42 /*                             Include Files                                  */
43 /* ========================================================================== */
45 #include <stdio.h>
46 #include <stdint.h>
47 #include <string.h>
49 /* XDCtools Header files */
50 #include <xdc/std.h>
51 #include <xdc/runtime/Error.h>
52 #include <xdc/runtime/System.h>
53 #include <xdc/runtime/Memory.h>
55 /* BIOS Header files */
56 #include <ti/sysbios/BIOS.h>
57 #include <ti/sysbios/knl/Task.h>
59 #include <ti/drv/ipc/ipc.h>
60 #include <ti/drv/ipc/ipcver.h>
61 #include <ti/drv/ipc/examples/common/src/ipc_setup.h>
62 #include <ti/drv/ipc/examples/ex05_bios_multicore_echo_negative_test/ipc_neg_setup.h>
63 #include <ti/osal/osal.h>
65 #define MSGSIZE  256U
66 #define SERVICE  "ti.ipc4.ping-pong"
67 #define ENDPT1   13U
68 #define ENDPT2   14U
69 #define NUMMSGS  10000 /* number of message sent per task */
70 //#define NUMMSGS  1000000   /* number of message sent per task */
72 extern uint8_t  *pCntrlBuf;
73 extern uint8_t  *pTaskBuf;
74 extern uint8_t  *pSendTaskBuf;
75 extern uint8_t  *pRecvTaskBuf;
76 extern uint8_t  *pTimeoutBuf;
77 extern uint8_t  *pSysVqBuf;
79 extern uint32_t  selfProcId;
80 extern uint32_t *pRemoteProcArray;
81 extern uint32_t  gNumRemoteProc;
83 uint32_t rpmsgNegDataSize = RPMSG_DATA_SIZE;
85 /* ========================================================================== */
86 /*                           Macros & Typedefs                                */
87 /* ========================================================================== */
89 #define RP_MSG_TEST_BUF_SIZE     (512 + 2)
90 /* ========================================================================== */
91 /*                         Structure Declarations                             */
92 /* ========================================================================== */
94 /* None */
96 /* ========================================================================== */
97 /*                          Function Declarations                             */
98 /* ========================================================================== */
101 /* ========================================================================== */
102 /*                            Global Variables                                */
103 /* ========================================================================== */
104 #if !defined(BUILD_MPU1_0) && defined(A72_LINUX_OS) && defined(A72_LINUX_OS_IPC_ATTACH)
105 static uint32_t        RecvEndPt = 0;
106 #endif
108 static bool test_rpmsg_pkt_large_than_vring_buf_flag = 0;
109 static bool test_virtio_init_param_null_flag = 0;
110 static bool test_rpmsg_init_param_null_flag = 0;
111 static bool test_rpmsg_create_null_endpnt_flag = 0;
112 static bool test_rpmsg_snd_null_data_flag = 0;
113 static bool test_rpmsg_snd_unpair_core_flag = 0;
114 static bool test_rpmsg_rcv_hndl_null_flag = 0;
115 static bool test_rpmsg_snd_hndl_null_flag = 0;
116 static bool test_virtio_param_vqbuf_size_zero_flag = 0;
117 static bool test_virtio_param_vringbuf_size_zero_flag = 0;
118 static bool test_rpmsg_param_buf_null_flag = 0;
119 static bool test_rpmsg_param_buf_size_zero_flag = 0;
120 static bool test_rpmsg_param_stkbuf_null_flag = 0;
121 static bool test_rpmsg_param_stk_size_zero_flag = 0;
122 static bool test_rpmsg_rcv_timeout_flag = 0;
123 static bool test_rpmsg_remote_end_timeout_flag = 0;
125 //#define DEBUG_PRINT
127 bool g_neg_exitRespTsk = 0;
129 void rpmsg_neg_exit_responseTask()
131     g_neg_exitRespTsk = 1;
134 /*
135  * This "Task" waits for a "ping" message from any processor
136  * then replies with a "pong" message.
137  */
138 void rpmsg_neg_responderFxn(UArg arg0, UArg arg1)
140     RPMessage_Handle    handle;
141     RPMessage_Handle    handleTimeout;
142     RPMessage_Params    params;
143     uint32_t        myEndPt = 0;
144     uint32_t        myTimeoutEndPt = 0;
145     uint32_t        remoteEndPt;
146     uint32_t        remoteProcId;
147     uint16_t        len;
148     int32_t         n;
149     int32_t         status = 0;
150     void            *buf;
151     void            *buf2;
153     uint32_t            bufSize = rpmsgNegDataSize;
154     char                str[MSGSIZE];
156     buf = pRecvTaskBuf;
157     if(buf == NULL)
158     {
159         System_printf("RecvTask: buffer allocation failed\n");
160         return;
161     }
163     RPMessageParams_init(&params);
164     params.requestedEndpt = ENDPT1;
165     params.buf = buf;
166     params.bufSize = bufSize;
168     handle = RPMessage_create(&params, &myEndPt);
169     if(!handle)
170     {
171         System_printf("RecvTask: Failed to create endpoint\n");
172         return;
173     }
174     buf2 = pTimeoutBuf;
175     params.requestedEndpt = ENDPT2;
176     params.buf = buf2;
177     params.bufSize = bufSize;
178     handleTimeout = RPMessage_create(&params, &myTimeoutEndPt);
179     if (!handleTimeout)
180     {
181         System_printf("RecvTask: Failed to create timeout endpoint\n");
182         return;
183     }
185 #if !defined(BUILD_MPU1_0) && defined(A72_LINUX_OS) && defined(A72_LINUX_OS_IPC_ATTACH)
186     RecvEndPt = myEndPt;
187 #endif
189     if(test_rpmsg_snd_hndl_null_flag || test_rpmsg_rcv_hndl_null_flag ||
190             test_rpmsg_pkt_large_than_vring_buf_flag || test_rpmsg_snd_null_data_flag
191             || test_rpmsg_snd_unpair_core_flag || test_rpmsg_remote_end_timeout_flag)
192     {
194     }
195     else
196     {
197         status = RPMessage_announce(RPMESSAGE_ALL, myEndPt, SERVICE);
198         if(status != IPC_SOK)
199         {
200             System_printf("RecvTask: RPMessage_announce() failed\n");
201             return;
202         }
203     }
205     while(!g_neg_exitRespTsk)
206     {
208         if(test_rpmsg_rcv_hndl_null_flag)
209         {
210             test_rpmsg_rcv_hndl_null_flag = 0;
211             status = RPMessage_recv(NULL, (Ptr)str, &len, &remoteEndPt, &remoteProcId,
212                     IPC_RPMESSAGE_TIMEOUT_FOREVER);
213             if(status != IPC_SOK)
214             {
215                 System_printf("[%s] [test_rpmsg_rcv_hndl_null_flag] : [TEST_PASS]\n", Ipc_mpGetSelfName());
216                 return;
217             }
218             else
219             {
220                 System_printf("[%s] [test_rpmsg_rcv_hndl_null_flag] : [TEST_FAIL]\n", Ipc_mpGetSelfName());
221                 return;
222             }
223         }
224         else if(test_rpmsg_rcv_timeout_flag)
225         {
226             test_rpmsg_rcv_timeout_flag = 0;
227             System_printf("[%s] calling RPMessage_recv with timeout 100...\n", Ipc_mpGetSelfName());
228             status = RPMessage_recv(handleTimeout, (Ptr)str, &len, &remoteEndPt, &remoteProcId, 100);
229             if(status != IPC_ETIMEOUT)
230             {
231                 System_printf("[%s] [test_rpmsg_rcv_timeout_flag] : [TEST_FAIL]\n", Ipc_mpGetSelfName());
232                 return;
233             }
234             else
235             {
236                 System_printf("[%s] [test_rpmsg_rcv_timeout_flag] : [TEST_PASS]\n", Ipc_mpGetSelfName());
237                 return;
238             }
239         }
240         else
241         {
242             status = RPMessage_recv(handle, (Ptr)str, &len, &remoteEndPt, &remoteProcId,
243                     IPC_RPMESSAGE_TIMEOUT_FOREVER);
244         }
245         if(status != IPC_SOK)
246         {
247             System_printf("RecvTask: failed with code %d\n", status);
248         }
249         else
250         {
251             /* NULL terminated string */
252             str[len] = '\0';
253 #ifdef DEBUG_PRINT
254             System_printf("RecvTask: Revcvd msg \"%s\" len %d from %s\n",
255                     str, len, Ipc_mpGetName(remoteProcId));
256 #endif
257         }
259         status = sscanf(str, "ping %d", &n);
260         if(status == 1)
261         {
262             memset(str, 0, MSGSIZE);
263             len = snprintf(str, 255, "pong %d", n);
264             if(len > 255)
265             {
266                 System_printf("RecvTask: snprintf failed, len %d\n", len);
267                 len = 255;
268             }
269             str[len++] = '\0';
270         }
271         else
272         {
273             /* If this is not ping/pong message, just print the message */
274             System_printf("%s <--> %s : %s recvd\n",
275                     Ipc_mpGetSelfName(),
276                     Ipc_mpGetName(remoteProcId),
277                     str);
278         }
279 #ifdef DEBUG_PRINT
280         System_printf("RecvTask: Sending msg \"%s\" len %d from %s to %s\n",
281                 str, len, Ipc_mpGetSelfName(),
282                 Ipc_mpGetName(remoteProcId));
283 #endif
284         status = RPMessage_send(handle, remoteProcId, remoteEndPt, myEndPt, str, len);
285         if (status != IPC_SOK)
286         {
287             System_printf("RecvTask: Sending msg \"%s\" len %d from %s to %s failed!!!\n",
288                 str, len, Ipc_mpGetSelfName(),
289                 Ipc_mpGetName(remoteProcId));
290         }
291     }
293     System_printf("%s responder task exiting ...\n",
294                     Ipc_mpGetSelfName());
297 void rpmsg_neg_senderFxn(UArg arg0, UArg arg1)
299     RPMessage_Handle    handle;
300     RPMessage_Params    params;
301     uint32_t            myEndPt = 0;
302     uint32_t            remoteEndPt;
303     uint32_t            remoteProcId;
304     uint16_t            dstProc;
305     uint16_t            len;
306     int32_t             i;
307     int32_t             status = 0;
308     char                test_buf[RP_MSG_TEST_BUF_SIZE + 1];
309     char                buf[256];
310     uint8_t            *buf1;
312     uint32_t            cntPing = 0;
313     uint32_t            cntPong = 0;
315     buf1 = &pSendTaskBuf[rpmsgNegDataSize * arg1];
316     dstProc = arg0;
318     /* Create the endpoint for receiving. */
319     RPMessageParams_init(&params);
320     params.numBufs = 2;
321     params.buf = buf1;
322     params.bufSize = rpmsgNegDataSize;
324     if(test_rpmsg_create_null_endpnt_flag)
325     {
326         test_rpmsg_create_null_endpnt_flag = 0;
327         handle = RPMessage_create(&params, NULL);
328         if(!handle)
329         {
330             System_printf("[%s] [test_rpmsg_create_null_endpnt_flag] : [TEST_PASS]\n", Ipc_mpGetSelfName());
331             return;
332         }
333         else
334         {
335             System_printf("[%s] [test_rpmsg_create_null_endpnt_flag] : [TEST_FAIL]\n", Ipc_mpGetSelfName());
336             return;
337         }
338     }
339     else
340     {
341         handle = RPMessage_create(&params, &myEndPt);
342     }
344     if(!handle)
345     {
346         System_printf("SendTas %d: Failed to create message endpoint\n",
347                 dstProc);
348         return;
349     }
351     if(test_rpmsg_remote_end_timeout_flag)
352     {
353         test_rpmsg_remote_end_timeout_flag = 0;
354         status = RPMessage_getRemoteEndPt(dstProc, SERVICE, &remoteProcId,
355                 &remoteEndPt, 1000);
356         if(status != IPC_SOK)
357         {
358             System_printf("[%s] [test_rpmsg_remote_end_timeout_flag] : [TEST_PASS]\n", Ipc_mpGetSelfName());
359             return;
360         }
361         else
362         {
363             System_printf("[%s] [test_rpmsg_remote_end_timeout_flag] : [TEST_FAIL]\n", Ipc_mpGetSelfName());
364             return;
365         }
366     }
367     else
368     {
369         if(test_rpmsg_pkt_large_than_vring_buf_flag || test_rpmsg_snd_null_data_flag
370                 || test_rpmsg_snd_unpair_core_flag || test_rpmsg_snd_hndl_null_flag)
371         {
373         }
374         else
375         {
376             status = RPMessage_getRemoteEndPt(dstProc, SERVICE, &remoteProcId,
377                     &remoteEndPt, BIOS_WAIT_FOREVER);
378             if(dstProc != remoteProcId)
379             {
380                 System_printf("SendTask%d: RPMessage_getRemoteEndPt() malfunctioned, status %d\n",
381                         dstProc, status);
382                 return;
383             }
384         }
385     }
387     for (i = 0; i < NUMMSGS; i++)
388     {
390         if(test_rpmsg_pkt_large_than_vring_buf_flag)
391         {
393             test_rpmsg_pkt_large_than_vring_buf_flag = 0;
394             /* Send data to remote endPt: */
395             memset(test_buf, 0, RP_MSG_TEST_BUF_SIZE);
397             len = snprintf(test_buf, RP_MSG_TEST_BUF_SIZE, "ping %d", i);
399             if(len > RP_MSG_TEST_BUF_SIZE)
400             {
401                 System_printf("SendTask%d: snprintf failed, len %d\n", dstProc, len);
402                 len = RP_MSG_TEST_BUF_SIZE;
403             }
405             len = RP_MSG_TEST_BUF_SIZE;
406             test_buf[len++] = '\0';
408             /* Increase the Ping Counter */
409             cntPing++;
411             status = RPMessage_send(handle, dstProc, ENDPT1, myEndPt, (Ptr)test_buf, len);
412             if (status != IPC_SOK)
413             {
414                 System_printf("[%s] [test_rpmsg_pkt_large_than_vring_buf_flag] : [TEST_PASS]\n", Ipc_mpGetSelfName());
416                 /* Delete the RPMesg object now */
417                 RPMessage_delete(&handle);
418                 return;
419             }
420             else
421             {
422                 System_printf("[%s] [test_rpmsg_pkt_large_than_vring_buf_flag] : [TEST_FAIL]\n", Ipc_mpGetSelfName());
424                 /* Delete the RPMesg object now */
425                 RPMessage_delete(&handle);
426                 return;
427             }
428         }
429         else
430         {
431             /* Send data to remote endPt: */
432             memset(buf, 0, 256);
434             len = snprintf(buf, 255, "ping %d", i);
436             if(len > 255)
437             {
438                 System_printf("SendTask%d: snprintf failed, len %d\n", dstProc, len);
439                 len = 255;
440             }
442             buf[len++] = '\0';
444 #ifdef DEBUG_PRINT
445             System_printf("SendTask%d: Sending \"%s\" from %s to %s...\n", dstProc,
446                     buf, Ipc_mpGetSelfName(),
447                     Ipc_mpGetName(dstProc));
448 #endif
449             /* Increase the Ping Counter */
450             cntPing++;
452             if(test_rpmsg_snd_null_data_flag)
453             {
454                 test_rpmsg_snd_null_data_flag = 0;
455                 status = RPMessage_send(handle, dstProc, ENDPT1, myEndPt, NULL, len);
456                 if (status != IPC_SOK)
457                 {
458                     System_printf("[%s] [test_rpmsg_snd_null_data_flag] : [TEST_PASS]\n", Ipc_mpGetSelfName());
459                     /* Delete the RPMesg object now */
460                     RPMessage_delete(&handle);
461                     return;
462                 }
463                 else
464                 {
465                     System_printf("[%s] [test_rpmsg_snd_null_data_flag] : [TEST_FAIL]\n", Ipc_mpGetSelfName());
466                     /* Delete the RPMesg object now */
467                     RPMessage_delete(&handle);
468                     return;
469                 }
470             }
471             else if(test_rpmsg_snd_unpair_core_flag)
472             {
473                 test_rpmsg_snd_unpair_core_flag = 0;
474 #ifdef BUILD_C66X_1
475                 dstProc = IPC_C66X_1;
476 #endif
477                 status = RPMessage_send(handle, dstProc, ENDPT1, myEndPt, (Ptr)buf, len);
478                 if (status != IPC_SOK)
479                 {
480                     System_printf("[%s] [test_rpmsg_snd_unpair_core_flag] : [TEST_PASS]\n", Ipc_mpGetSelfName());
481                     /* Delete the RPMesg object now */
482                     RPMessage_delete(&handle);
483                     return;
484                 }
485                 else
486                 {
487                     System_printf("[%s] [test_rpmsg_snd_unpair_core_flag] : [TEST_FAIL]\n", Ipc_mpGetSelfName());
488                     /* Delete the RPMesg object now */
489                     RPMessage_delete(&handle);
490                     return;
491                 }
492             }
493             else if(test_rpmsg_snd_hndl_null_flag)
494             {
495                 test_rpmsg_snd_hndl_null_flag = 0;
496                 status = RPMessage_send(NULL, dstProc, ENDPT1, myEndPt, (Ptr)buf, len);
497                 if (status != IPC_SOK)
498                 {
499                     System_printf("[%s] [test_rpmsg_snd_hndl_null_flag] : [TEST_PASS]\n", Ipc_mpGetSelfName());
500                     /* Delete the RPMesg object now */
501                     RPMessage_delete(&handle);
502                     return;
503                 }
504                 else
505                 {
506                     System_printf("[%s] [test_rpmsg_snd_hndl_null_flag] : [TEST_FAIL]\n", Ipc_mpGetSelfName());
507                     /* Delete the RPMesg object now */
508                     RPMessage_delete(&handle);
509                     return;
510                 }
511             }
512             else
513             {
514                 status = RPMessage_send(handle, dstProc, ENDPT1, myEndPt, (Ptr)buf, len);
515                 if (status != IPC_SOK)
516                 {
517                     System_printf("SendTask%d: RPMessage_send Failed Msg-> \"%s\" from %s to %s...\n",
518                             dstProc,
519                             buf, Ipc_mpGetSelfName(),
520                             Ipc_mpGetName(dstProc));
521                     break;
522                 }
523             }
524         }
526         /* wait a for a response message: */
527         status = RPMessage_recv(handle, (Ptr)buf, &len, &remoteEndPt,
528                 &remoteProcId, IPC_RPMESSAGE_TIMEOUT_FOREVER);
530         if(status != IPC_SOK)
531         {
532             System_printf("SendTask%d: RPMessage_recv failed with code %d\n",
533                     dstProc, status);
534             break;
535         }
537         /* Make it NULL terminated string */
538         if(len >= MSGSIZE)
539         {
540             buf[MSGSIZE-1] = '\0';
541         }
542         else
543         {
544             buf[len] = '\0';
545         }
546 #ifdef DEBUG_PRINT
547         System_printf("SendTask%d: Received \"%s\" len %d from %s endPt %d \n",
548                 dstProc, buf, len, Ipc_mpGetName(remoteProcId),
549                 remoteEndPt);
550 #endif
551         cntPong++;
552         if((i+1)%50 == 0)
553         {
554             //System_printf("%s <--> %s, ping/pong iteration %d ...\n",
555             //        Ipc_mpGetSelfName(), Ipc_mpGetName(dstProc), i);
556         }
557     }
559     System_printf("%s <--> %s, Ping- %d, pong - %d completed\n",
560             Ipc_mpGetSelfName(),
561             Ipc_mpGetName(dstProc),
562             cntPing, cntPong);
564     /* Delete the RPMesg object now */
565     RPMessage_delete(&handle);
568 /*
569  * This "Task" waits for Linux vdev ready, and late create the vrings
570  *
571  */
572 #if !defined(BUILD_MPU1_0) && defined(A72_LINUX_OS) && defined(A72_LINUX_OS_IPC_ATTACH)
573 void rpmsg_neg_vdevMonitorFxn(UArg arg0, UArg arg1)
575     int32_t status;
577     /* Wait for Linux VDev ready... */
578     while(!Ipc_isRemoteReady(IPC_MPU1_0))
579     {
580         Task_sleep(10);
581     }
583     /* Create the VRing now ... */
584     status = Ipc_lateVirtioCreate(IPC_MPU1_0);
585     if(status != IPC_SOK)
586     {
587         System_printf("%s: Ipc_lateVirtioCreate failed\n", __func__);
588         return;
589     }
591     status = RPMessage_lateInit(IPC_MPU1_0);
592     if(status != IPC_SOK)
593     {
594         System_printf("%s: RPMessage_lateInit failed\n", __func__);
595         return;
596     }
598     status = RPMessage_announce(IPC_MPU1_0, RecvEndPt, SERVICE);
599     if(status != IPC_SOK)
600     {
601         System_printf("rpmsg_neg_vdevMonitorFxn: RPMessage_announce() failed\n");
602     }
604 #endif /* !defined(BUILD_MPU1_0) && defined(A72_LINUX_OS) && defined(A72_LINUX_OS_IPC_ATTACH)*/
608 void clear_all_test_flags(void)
610     test_rpmsg_pkt_large_than_vring_buf_flag = 0;
611     test_virtio_init_param_null_flag = 0;
612     test_rpmsg_init_param_null_flag = 0;
613     test_rpmsg_create_null_endpnt_flag = 0;
614     test_rpmsg_snd_null_data_flag = 0;
615     test_rpmsg_snd_unpair_core_flag = 0;
616     test_rpmsg_rcv_hndl_null_flag = 0;
617     test_rpmsg_snd_hndl_null_flag = 0;
618     test_virtio_param_vqbuf_size_zero_flag = 0;
619     test_virtio_param_vringbuf_size_zero_flag = 0;
620     test_rpmsg_param_buf_null_flag = 0;
621     test_rpmsg_param_buf_size_zero_flag = 0;
622     test_rpmsg_param_stkbuf_null_flag = 0;
623     test_rpmsg_param_stk_size_zero_flag = 0;
624     test_rpmsg_rcv_timeout_flag = 0;
625     test_rpmsg_remote_end_timeout_flag = 0;
627 int32_t ipc_neg_test(void)
629     uint32_t          t;
630     Task_Params       params;
631     uint32_t          numProc = gNumRemoteProc;
632     Ipc_VirtIoParams  vqParam;
633     uint32_t          index = 0;
634     int32_t           status;
636     /* Step1 : Initialize the multiproc */
637     Ipc_mpSetConfig(selfProcId, numProc, pRemoteProcArray);
639     System_printf("IPC_echo_test (core : %s) .....\r\n%s\r\n",
640             Ipc_mpGetSelfName(), IPC_DRV_VERSION_STR);
642     Ipc_init(NULL);
644     //System_printf("Required Local memory for Virtio_Object = %d\r\n",
645     //   numProc * Ipc_getVqObjMemoryRequiredPerCore());
647 #if !defined(BUILD_MPU1_0) && defined(A72_LINUX_OS)
648     /* If A72 remote core is running Linux OS, then
649      * load resource table
650      */
652     Ipc_loadResourceTable((void*)&ti_ipc_remoteproc_ResourceTable);
654 #if !defined(A72_LINUX_OS_IPC_ATTACH)
655     /* Wait for Linux VDev ready... */
656     for(t = 0; t < numProc; t++)
657     {
658         while(!Ipc_isRemoteReady(pRemoteProcArray[t]))
659         {
660             Task_sleep(10);
661         }
662     }
663     //System_printf("Linux VDEV ready now .....\n");
664 #endif
665 #endif
667     /* Step2 : Initialize Virtio */
668     vqParam.vqObjBaseAddr = (void*)pSysVqBuf;
669     vqParam.vqBufSize     = numProc * Ipc_getVqObjMemoryRequiredPerCore();
670     vqParam.vringBaseAddr = (void*)VRING_BASE_ADDRESS;
671     vqParam.vringBufSize  = IPC_VRING_BUFFER_SIZE;
672     vqParam.timeoutCnt    = 100;  /* Wait for counts */
674     if(test_virtio_init_param_null_flag)
675     {
676         memset(&vqParam, 0, sizeof(vqParam));
677         status = Ipc_initVirtIO( NULL );
678         if(status != IPC_SOK)
679         {
680             System_printf("[%s] [test_virtio_init_param_null_flag] : [TEST_PASS]\n", Ipc_mpGetSelfName());
681             return IPC_EFAIL;
682         }
683         else
684         {
685             System_printf("[%s] [test_virtio_init_param_null_flag] : [TEST_FAIL]\n", Ipc_mpGetSelfName());
686             return IPC_EFAIL;
687         }
688     }
689     else if(test_virtio_param_vqbuf_size_zero_flag)
690     {
691         vqParam.vqBufSize     = 0;
693         status = Ipc_initVirtIO(&vqParam);
694         if(status != IPC_SOK)
695         {
696             System_printf("[%s] [test_virtio_param_vqbuf_size_zero_flag] : [TEST_PASS]\n", Ipc_mpGetSelfName());
697             return IPC_EFAIL;
698         }
699         else
700         {
701             System_printf("[%s] [test_virtio_param_vqbuf_size_zero_flag] : [TEST_FAIL]\n", Ipc_mpGetSelfName());
702             return IPC_EFAIL;
703         }
704     }
705     else if(test_virtio_param_vringbuf_size_zero_flag)
706     {
707         vqParam.vringBufSize  = 0;
709         status = Ipc_initVirtIO(&vqParam);
710         if(status != IPC_SOK)
711         {
712             System_printf("[%s] [test_virtio_param_vringbuf_size_zero_flag] : [TEST_PASS]\n", Ipc_mpGetSelfName());
713             return IPC_EFAIL;
714         }
715         else
716         {
717             System_printf("[%s] [test_virtio_param_vringbuf_size_zero_flag] : [TEST_FAIL]\n", Ipc_mpGetSelfName());
718             return IPC_EFAIL;
719         }
720     }
721     else
722     {
723         status = Ipc_initVirtIO(&vqParam);
724         if (status != IPC_SOK)
725         {
726             System_printf("[%s] Ipc_initVirtIO failed\n");
727             return IPC_EFAIL;
728         }
729     }
730     /* Step 3: Initialize RPMessage */
731     RPMessage_Params cntrlParam;
733     //System_printf("Required Local memory for RPMessage Object = %d\n",
734     //   RPMessage_getObjMemRequired());
736     /* Initialize the param */
737     RPMessageParams_init(&cntrlParam);
739     /* Set memory for HeapMemory for control task */
740     cntrlParam.buf         = pCntrlBuf;
741     cntrlParam.bufSize     = rpmsgNegDataSize;
742     cntrlParam.stackBuffer = &pTaskBuf[index++ * IPC_TASK_STACKSIZE];
743     cntrlParam.stackSize   = IPC_TASK_STACKSIZE;
745     if(test_rpmsg_init_param_null_flag)
746     {
747         status = RPMessage_init(NULL);
748         if(status != IPC_SOK)
749         {
750             System_printf("[%s] [test_rpmsg_init_param_null_flag] : [TEST_PASS]\n", Ipc_mpGetSelfName());
751             return IPC_EFAIL;
752         }
753         else
754         {
755             System_printf("[%s] [test_rpmsg_init_param_null_flag] : [TEST_FAIL]\n", Ipc_mpGetSelfName());
756             return IPC_EFAIL;
757         }
758     }
759     else if(test_rpmsg_param_buf_null_flag)
760     {
761         cntrlParam.buf =  NULL;
763         status = RPMessage_init(&cntrlParam);
764         if(status != IPC_SOK)
765         {
766             System_printf("[%s] [test_rpmsg_param_buf_null_flag] : [TEST_PASS]\n", Ipc_mpGetSelfName());
767             return IPC_EFAIL;
768         }
769         else
770         {
771             System_printf("[%s] [test_rpmsg_param_buf_null_flag] : [TEST_FAIL]\n", Ipc_mpGetSelfName());
772             return IPC_EFAIL;
773         }
774     }
775     else if(test_rpmsg_param_buf_size_zero_flag)
776     {
777         cntrlParam.bufSize = 0;
779         status = RPMessage_init(&cntrlParam);
780         if(status != IPC_SOK)
781         {
782             System_printf("[%s] [test_rpmsg_param_buf_size_zero_flag] : [TEST_PASS]\n", Ipc_mpGetSelfName());
783             return IPC_EFAIL;
784         }
785         else
786         {
787             System_printf("[%s] [test_rpmsg_param_buf_size_zero_flag] : [TEST_FAIL]\n", Ipc_mpGetSelfName());
788             return IPC_EFAIL;
789         }
790     }
791 #ifndef IPC_EXCLUDE_CTRL_TASKS
792     else if(test_rpmsg_param_stkbuf_null_flag)
793     {
794         cntrlParam.stackBuffer = NULL;
796         status = RPMessage_init(&cntrlParam);
797         if(status != IPC_SOK)
798         {
799             System_printf("[%s] [test_rpmsg_param_stkbuf_null_flag] : [TEST_PASS]\n", Ipc_mpGetSelfName());
800             return IPC_EFAIL;
801         }
802         else
803         {
804             System_printf("[%s] [test_rpmsg_param_stkbuf_null_flag] : [TEST_FAIL]\n", Ipc_mpGetSelfName());
805             return IPC_EFAIL;
806         }
807     }
808     else if(test_rpmsg_param_stk_size_zero_flag)
809     {
810         cntrlParam.stackSize = 0;
812         status = RPMessage_init(&cntrlParam);
813         if(status != IPC_SOK)
814         {
815             System_printf("[%s] [test_rpmsg_param_stk_size_zero_flag] : [TEST_PASS]\n", Ipc_mpGetSelfName());
816             return IPC_EFAIL;
817         }
818         else
819         {
820             System_printf("[%s] [test_rpmsg_param_stk_size_zero_flag] : [TEST_FAIL]\n", Ipc_mpGetSelfName());
821             return IPC_EFAIL;
822         }
823     }
824 #endif /* IPC_EXCLUDE_CTRL_TASKS */
825     else
826     {
827         status = RPMessage_init(&cntrlParam);
828         if (status != IPC_SOK)
829         {
830             System_printf("[%s] RPMessage_init failed\n", Ipc_mpGetSelfName());
831             return IPC_EFAIL;
832         }
833     }
835     /* Respond to messages coming in to endPt ENDPT1 */
836     Task_Params_init(&params);
837     params.priority   = 3;
838     params.stack      = &pTaskBuf[index++ * IPC_TASK_STACKSIZE];
839     params.stackSize  = IPC_TASK_STACKSIZE;
840     params.arg0       = 0;
841     Task_create(rpmsg_neg_responderFxn, &params, NULL);
843     for(t = 0; t < numProc; t++, index++)
844     {
845 #if !defined(BUILD_MPU1_0) && defined(A72_LINUX_OS)
846         /* Linux does not have a responder func running */
847         if(pRemoteProcArray[t] == IPC_MPU1_0)
848             continue;
849 #endif
850         /* send messages to peer(s) on ENDPT1 */
851         Task_Params_init(&params);
852         params.priority  = 3;
853         params.stack     = &pTaskBuf[index * IPC_TASK_STACKSIZE];
854         params.stackSize = IPC_TASK_STACKSIZE;
855         params.arg0      = pRemoteProcArray[t];
856         params.arg1      = t;
857         Task_create(rpmsg_neg_senderFxn, &params, NULL);
859     }
861 #if !defined(BUILD_MPU1_0) && defined(A72_LINUX_OS) && defined(A72_LINUX_OS_IPC_ATTACH)
862     /* Respond to messages coming in to endPt ENDPT1 */
863     Task_Params_init(&params);
864     params.priority = 3;
865     params.stackSize = 0x1000;
866     params.arg0 = 0;
867     Task_create(rpmsg_neg_vdevMonitorFxn, &params, NULL);
868 #endif /* !defined(BUILD_MPU1_0) && defined(A72_LINUX_OS) && defined(A72_LINUX_OS_IPC_ATTACH) */
870     return 1;
873 int32_t Ipc_echo_neg_test(void)
875     /* RPMessage_Recv timeout set to 1ms for timeout test */
876     g_neg_exitRespTsk = 0;
877     clear_all_test_flags();
878     test_rpmsg_rcv_timeout_flag = 1;
879     ipc_neg_test();
880     rpmsg_neg_exit_responseTask();
882     Task_sleep(20000);
884     /* set vqBufSize to zero as init param for virtIO */
885     g_neg_exitRespTsk = 0;
886     clear_all_test_flags();
887     test_virtio_param_vqbuf_size_zero_flag = 1;
888     ipc_neg_test();
889     rpmsg_neg_exit_responseTask();
891     Task_sleep(20000);
893     /* set vringBufSize to zero as init param for virtIO */
894     g_neg_exitRespTsk = 0;
895     clear_all_test_flags();
896     test_virtio_param_vringbuf_size_zero_flag = 1;
897     ipc_neg_test();
898     rpmsg_neg_exit_responseTask();
900     Task_sleep(20000);
902     /* set bufSize to zero as init param for RPmessage */
903     g_neg_exitRespTsk = 0;
904     clear_all_test_flags();
905     test_rpmsg_param_buf_size_zero_flag = 1;
906     ipc_neg_test();
907     rpmsg_neg_exit_responseTask();
909     Task_sleep(20000);
911     /* set buf to NULL as init param for RPmessage */
912     g_neg_exitRespTsk = 0;
913     clear_all_test_flags();
914     test_rpmsg_param_buf_null_flag = 1;
915     ipc_neg_test();
916     rpmsg_neg_exit_responseTask();
918     Task_sleep(20000);
920 #ifndef IPC_EXCLUDE_CTRL_TASKS
921     /* set stackSize to zero as init param for RPmessage */
922     g_neg_exitRespTsk = 0;
923     clear_all_test_flags();
924     test_rpmsg_param_stk_size_zero_flag = 1;
925     ipc_neg_test();
926     rpmsg_neg_exit_responseTask();
928     Task_sleep(20000);
930     /* set stackBuffer to NULL as init param for RPmessage */
931     g_neg_exitRespTsk = 0;
932     clear_all_test_flags();
933     test_rpmsg_param_stkbuf_null_flag = 1;
934     ipc_neg_test();
935     rpmsg_neg_exit_responseTask();
937     Task_sleep(20000);
938 #endif /* IPC_EXCLUDE_CTRL_TASKS */
940     /* send NULL params as part of init virtIO */
941     g_neg_exitRespTsk = 0;
942     clear_all_test_flags();
943     test_virtio_init_param_null_flag = 1;
944     ipc_neg_test();
945     rpmsg_neg_exit_responseTask();
947     Task_sleep(20000);
949     /* send NULL params as part of init RPMessage */
950     g_neg_exitRespTsk = 0;
951     clear_all_test_flags();
952     test_rpmsg_init_param_null_flag = 1;
953     ipc_neg_test();
954     rpmsg_neg_exit_responseTask();
956     Task_sleep(20000);
958     /* send RPmessage packet size larger than vring buffer size */
959     g_neg_exitRespTsk = 0;
960     clear_all_test_flags();
961     test_rpmsg_pkt_large_than_vring_buf_flag = 1;
962     ipc_neg_test();
963     rpmsg_neg_exit_responseTask();
965     Task_sleep(20000);
967     /* send NULL handle as part of RPMessag receive */
968     g_neg_exitRespTsk = 0;
969     clear_all_test_flags();
970     test_rpmsg_rcv_hndl_null_flag = 1;
971     ipc_neg_test();
972     rpmsg_neg_exit_responseTask();
974     Task_sleep(20000);
976     /* RPMessage_getRemoteEndPt timeout set to 1000 ticks for timeout */
977     g_neg_exitRespTsk = 0;
978     clear_all_test_flags();
979     test_rpmsg_remote_end_timeout_flag = 1;
980     ipc_neg_test();
981     rpmsg_neg_exit_responseTask();
983     Task_sleep(20000);
985     /* send RPMessage create end point as NULL */
986     g_neg_exitRespTsk = 0;
987     clear_all_test_flags();
988     test_rpmsg_create_null_endpnt_flag = 1;
989     ipc_neg_test();
990     rpmsg_neg_exit_responseTask();
992     Task_sleep(20000);
994     /* send NULL handle as part of RPMessag send */
995     g_neg_exitRespTsk = 0;
996     clear_all_test_flags();
997     test_rpmsg_snd_hndl_null_flag = 1;
998     ipc_neg_test();
999     rpmsg_neg_exit_responseTask();
1001     Task_sleep(20000);
1003     /* send NULL data as part of RPMessag send */
1004     g_neg_exitRespTsk = 0;
1005     clear_all_test_flags();
1006     test_rpmsg_snd_null_data_flag = 1;
1007     ipc_neg_test();
1008     rpmsg_neg_exit_responseTask();
1010     Task_sleep(20000);
1012     /* send NULL data as part of RPMessag send */
1013     g_neg_exitRespTsk = 0;
1014     clear_all_test_flags();
1015     test_rpmsg_snd_unpair_core_flag = 1;
1016     ipc_neg_test();
1017     rpmsg_neg_exit_responseTask();
1019     return 0;