API naming convention cleanup, switch to strncpy, renamed resourceNode allocatedTo...
[keystone-rtos/rm-lld.git] / test / rm_test.c
1 /* 
2  * Copyright (c) 2012, 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  *  ======== rm_test.c ========
34  *  RM multicore test example
35  *
36  *  This is an example program that uses MessageQ to pass a message
37  *  from one processor to another.
38  *
39  *  Each processor creates its own MessageQ first and then will try to open
40  *  a remote processor's MessageQ.  
41  *
42  *  See message_multicore.k file for expected output.
43  */
45 #include <c6x.h>
46 #include <xdc/std.h>
47 #include <stdio.h>
48 #include <string.h>
49 #include <stdbool.h>
51 /*  -----------------------------------XDC.RUNTIME module Headers    */
52 #include <xdc/runtime/System.h>
53 #include <xdc/runtime/IHeap.h>
55 /*  ----------------------------------- IPC module Headers           */
56 #include <ti/ipc/Ipc.h>
57 #include <ti/ipc/MessageQ.h>
58 #include <ti/ipc/HeapBufMP.h>
59 #include <ti/ipc/MultiProc.h>
61 /*  ----------------------------------- BIOS6 module Headers         */
62 #include <ti/sysbios/BIOS.h>
63 #include <ti/sysbios/knl/Task.h>
65 /*  ----------------------------------- Resource Manager Headers         */
66 #include <ti/drv/rm/rm.h>
67 #include <ti/drv/rm/rm_osal.h>
68 #include <ti/drv/rm/rm_transport.h>
69 #include <ti/drv/rm/rm_services.h>
71 /* ======== Task Handles ======== */
72 Task_Handle startupRmTskHandle;
73 Task_Handle testReceiveTskHandle;
74 Task_Handle testRmTskHandle;
76 /* ======== Application Heaps ======== */
77 #define RM_PKT_HEAP_NAME   "rmHeapBuf"
78 HeapBufMP_Handle rmPktHeapHandle = NULL;
80 #define MSGQ_HEAP_NAME   "msgQHeapBuf"
81 #define MSGQ_HEAP_ID      0
83 /* ======== RM Instance Names ======== */
84 Char rmServerName[RM_INSTANCE_NAME_MAX_CHARS] = "RM_Server";
85 Char rmClientDelegateName[RM_INSTANCE_NAME_MAX_CHARS] = "RM_Client_Delegate";
86 Char rmClientName[RM_INSTANCE_NAME_MAX_CHARS] = "RM_Client";
88 /* ======== RM IPC MessageQ Names ======== */
89 Char serverCdQueueName[30] = "RM_Server_CD_Queue";
90 Char cdServerQueueName[30] = "RM_CD_Server_Queue";
91 Char cdClientQueueName[30] = "RM_CD_Client_Queue";
92 Char clientCdQueueName[30] = "RM_Client_CD_Queue";
94 /* ======== RM Instance Handles ======== */
95 Rm_Handle rmServerHandle = NULL;
96 Rm_Handle rmClientDelegateHandle = NULL;
97 Rm_Handle rmClientHandle = NULL;
99 /* ======== RM Instance Service Ports ======== */
100 Rm_ServicePort *rmServerServicePort = NULL;
101 Rm_ServicePort *rmClientDelegateServicePort = NULL;
102 Rm_ServicePort *rmClientServicePort = NULL;
104 /* ======== RM Transport Packet Definition ======== */
105 typedef struct {
106   MessageQ_MsgHeader msgQHeader;
107   /* Pointer to packet provided by RM */
108   Rm_Packet *rmPkt;
109 } MsgQ_RmPacket;
111 /* ======== RM Transport Mapping Tables for Application ======== */
112 /* Core 0 Map Entry Indices */
113 #define SERVER_TO_CD_MAP_ENTRY 0
114 /* Core 1 Map Entry Indicies */
115 #define CD_TO_SERVER_MAP_ENTRY 0
116 #define CD_TO_CLIENT_MAP_ENTRY 1
117 #define CLIENT_TO_CD_MAP_ENTRY 2
119 /* Max map entries across all cores */
120 #define MAX_MAPPING_ENTRIES 3
122 typedef struct {
123     Rm_TransportHandle transportHandle;
124     MessageQ_Handle receiveMsgQ;
125     MessageQ_QueueId remoteMsgQId;
126 } Transport_MapEntry;
128 /* Core 1 will have three mapping entries
129  * Two map entries for the Client Delegate
130  * One map entry for the Client */
131 Transport_MapEntry rmTransportMap[MAX_MAPPING_ENTRIES];
133 uint32_t waitForBlockingOperation = 0;
134 Rm_ServiceRespInfo responseInfo;
136 /* ======== RM Application Sync APIs ======== */
138 typedef struct {
139     uint32_t sem;
140     uint32_t pad[31];
141 } syncObj;
143 #pragma DATA_SECTION (testSyncObj, ".syncObj");
144 #pragma DATA_ALIGN (testSyncObj, 16)
145 syncObj testSyncObj;
147 void initSyncObj(void)
149     Rm_osalBeginMemAccess((void *) &testSyncObj, sizeof(syncObj));    
150     testSyncObj.sem = 0;
151     Rm_osalEndMemAccess((void *) &testSyncObj, sizeof(syncObj));
154 void takeSyncObj(void)
156     Rm_osalBeginMemAccess((void *) &testSyncObj, sizeof(syncObj));    
157     testSyncObj.sem = 1;
158     Rm_osalEndMemAccess((void *) &testSyncObj, sizeof(syncObj));
161 void waitOnSyncObj(void)
163     do
164     {
165         /* Yield for other tasks */
166         Task_yield();
167         Rm_osalBeginMemAccess((void *) &testSyncObj, sizeof(syncObj));    
168     } while (testSyncObj.sem == 1);
171 void releaseSyncObj(void)
173     Rm_osalBeginMemAccess((void *) &testSyncObj, sizeof(syncObj));    
174     testSyncObj.sem = 0;
175     Rm_osalEndMemAccess((void *) &testSyncObj, sizeof(syncObj));
178 /* ======== RM Application Transport APIs ======== */
180 Rm_Packet *TransportAlloc (Rm_TransportHandle transportHandle, uint32_t pktSize)
182     Rm_Packet *pkt = NULL;
184     /* All transports will allocate from the same heap */
185     
186     pkt = HeapBufMP_alloc(rmPktHeapHandle, pktSize, 0);
188     if (pkt != NULL)
189     {
190        pkt->pktLenBytes = pktSize;
191     }
193     return (pkt);
196 int32_t TransportFree (Rm_TransportHandle transportHandle, Rm_Packet *pkt)
198     uint32_t pktSize = pkt->pktLenBytes;
200     /* All transports will free to the same heap */
201     
202     HeapBufMP_free(rmPktHeapHandle, pkt, pktSize);
204     return (0);    
207 int32_t TransportSend (Rm_TransportHandle transportHandle, Rm_Packet *pkt)
209     MsgQ_RmPacket *rmMsg = NULL;
210     MessageQ_QueueId remoteQueueId;
211     bool handleValid = false;
212     int32_t status, i;    
214     /* Get the remoteQueueId based on the transportHandle */
215     for (i = 0; i < MAX_MAPPING_ENTRIES; i++)
216     {
217         /* transportHandle found in mapping table.  Get the remoteQueueId associated
218          * with it */
219         if (rmTransportMap[i].transportHandle == transportHandle)
220         {
221             remoteQueueId = rmTransportMap[i].remoteMsgQId;
222             /* Break out of the search loop */
223             handleValid = true;
224             break;
225         }
226     }
228     if (handleValid)
229     {
230         /* Allocate a messageQ message for containing the RM packet */
231         rmMsg = (MsgQ_RmPacket *)MessageQ_alloc(MSGQ_HEAP_ID, sizeof(MsgQ_RmPacket));
232         if (rmMsg == NULL) 
233         {
234             System_printf("Core %d: MessageQ_alloc failed in TransportSend\n", MultiProc_self());
235         }
237         /* Attach the RM packet to the MessageQ message */
238         Rm_osalEndMemAccess((void *) pkt, pkt->pktLenBytes);
239         rmMsg->rmPkt = pkt;
240         /* Send the message to the remote side */
241         status = MessageQ_put(remoteQueueId, (MessageQ_Msg)rmMsg);
242         if (status < 0) 
243         { 
244             System_printf("Core %d: MessageQ_put had a failure/error in TransportSend\n", MultiProc_self());
245         }
246     }
247     else
248     {   
249         /* Could not find a registered transport handle that matched the handle provided by RM.
250          * Return an error to RM. */
251         System_printf("Core %d: TransportSend couldn't find transportHandle in transport map\n", MultiProc_self());
252         status = -1;
253     }
254     
255     return (status);
258 void *TransportReceive (Rm_TransportHandle transportHandle)
260     MessageQ_Handle receiveQ;
261     MessageQ_Msg rmMsg = NULL;
262     Rm_Packet *rmPkt = NULL;
263     bool queueValid = false;
264     int32_t status, i;    
266     /* Get the receiveQ based on the transportHandle */
267     for (i = 0; i < MAX_MAPPING_ENTRIES; i++)
268     {
269         /* transportHandle found in mapping table.  Get the receiveQ associated
270          * with it */
271         if (rmTransportMap[i].transportHandle == transportHandle)
272         {
273             receiveQ = rmTransportMap[i].receiveMsgQ;
274             /* Break out of the search loop */
275             queueValid = true;
276             break;
277         }
278     }
280     if (queueValid)
281     {
282         /* Get the next message from the receiveQ */
283         status = (int32_t) MessageQ_get(receiveQ, &rmMsg, MessageQ_FOREVER);
284         if (status < 0) 
285         {
286             System_abort("This should not happen since timeout is forever\n");
287         }
288         if (rmMsg == NULL) 
289         {
290             System_printf("Core %d: MessageQ_get failed returning a null packet in TransportReceive\n", MultiProc_self());
291         }
293         /* Extract the Rm_Packet from the RM msg */
294         rmPkt = ((MsgQ_RmPacket *)rmMsg)->rmPkt;
295         Rm_osalBeginMemAccess((void *) rmPkt, rmPkt->pktLenBytes); 
297         /* Free the messageQ message now that RM packet pointer has been extracted */
298         status = MessageQ_free(rmMsg);
299         if (status < 0) 
300         { 
301             System_printf("Core %d: MessageQ_free had a failure/error in TransportReceive\n", MultiProc_self());
302         }
303     }
304     else
305     {   
306         /* Could not find a registered transport handle that matched the handle provided by RM.
307          * Return an error to RM. */
308         System_printf("Core %d: TransportReceive couldn't find transportHandle in transport map\n", MultiProc_self());
309     }
311     /* Pass the RM packet back to RM */
312     return ((void *)rmPkt);
315 int32_t TransportNumPktsReceived (Rm_TransportHandle transportHandle)
317     MessageQ_Handle receiveQ;
318     bool queueValid = false;
319     int32_t numPkts, i;    
321     /* Get the receiveQ based on the transportHandle */
322     for (i = 0; i < MAX_MAPPING_ENTRIES; i++)
323     {
324         /* transportHandle found in mapping table.  Get the receiveQ associated
325          * with it */
326         if (rmTransportMap[i].transportHandle == transportHandle)
327         {
328             receiveQ = rmTransportMap[i].receiveMsgQ;
329             /* Break out of the search loop */
330             queueValid = true;
331             break;
332         }
333     }
335     if (queueValid)
336     {
337         /* Get the number of messages in the receiveQ */
338         numPkts = (int32_t) MessageQ_count(receiveQ);
339     }
340     else
341     {   
342         /* Could not find a registered transport handle that matched the handle provided by RM.
343          * Return an error to RM. */
344         System_printf("Core %d: TransportNumPktsReceived couldn't find transportHandle in transport map\n", MultiProc_self());
345         numPkts = -1;
346     }
347     
348     return (numPkts);
351 /*
352  *  ======== testServiceCallback ========
353  *  Application's callback function given to RM on service requests
354  */
355 void testServiceCallback(Rm_ServiceRespInfo *serviceResponse)
357     if (serviceResponse->serviceId == waitForBlockingOperation)
358     {
359         waitForBlockingOperation = 0;
360         strcpy(responseInfo.resourceName, serviceResponse->resourceName);
361         responseInfo.resourceBase = serviceResponse->resourceBase;
362         responseInfo.resourceLength = serviceResponse->resourceLength;
363         responseInfo.serviceState = serviceResponse->serviceState;
364     }
367 bool blockForResponse(Rm_ServiceRespInfo *respInfo)
369     waitForBlockingOperation = respInfo->serviceId;
370     /* Block and wait for the response if the RM needed to perform a blocking operation
371      * to complete the request */
372     while(waitForBlockingOperation)
373     {
374         /* Yield to receive task to see if there are any packets for RM instance */
375         Task_yield();
376     }       
378     if ((respInfo->serviceState != RM_SERVICE_PROCESSING) &&
379         (respInfo->serviceState != RM_SERVICE_APPROVED_AND_COMPLETED))
380     {
381         System_printf("Core %d: Service request encountered error or denial: %d\n", MultiProc_self(),
382                                                                                     respInfo->serviceState);
383         return(FALSE);
384     }
386     return(TRUE);
389 /*
390  *  ======== testRmTsk ========
391  *  RM cleanup task
392  */
393 void cleanupRmTsk(UArg arg0, UArg arg1)
395     /* Delete the RM test task */
396     System_printf("Core %d: Deleting RM test task...\n", MultiProc_self());
397     if (testRmTskHandle)
398     {
399         Task_delete(&testRmTskHandle);
400         /* Set the task handle to be NULL so that the delete only occurs once */
401         testRmTskHandle = NULL;
402     }
403     /* Delete the RM receive task */
404     System_printf("Core %d: Deleting RM receive task...\n", MultiProc_self());
405     if (testReceiveTskHandle)
406     {
407         Task_delete(&testReceiveTskHandle);
408         /* Set the task handle to be NULL so that the delete only occurs once */
409         testReceiveTskHandle = NULL;
410     }
412     
414     /* Cleanup all service ports, transport handles, RM instances, and IPC constructs */
416     BIOS_exit(0);
419 /*
420  *  ======== testRmTsk ========
421  *  RM test task
422  */
423 void testReceiveTsk(UArg arg0, UArg arg1)
425     int32_t retVal;
427     while(1)
428     {
430         /* Run the RM polling functions for each RM instance. */
431         if (MultiProc_self() == 0)
432         {
433             retVal = Rm_receivePktPolling(rmTransportMap[SERVER_TO_CD_MAP_ENTRY].transportHandle);
434             if (retVal != RM_TRANSPORT_SUCCESSFUL)
435             {
436                 System_printf("Core %d: %s to %s transport receive error %d\n", MultiProc_self(), 
437                                                                                 rmServerName,
438                                                                                 rmClientDelegateName,
439                                                                                 retVal);
440             }
441         }
442         else if (MultiProc_self() == 1)
443         {
444             retVal = Rm_receivePktPolling(rmTransportMap[CD_TO_SERVER_MAP_ENTRY].transportHandle);
445             if (retVal != RM_TRANSPORT_SUCCESSFUL)
446             {
447                 System_printf("Core %d: %s to %s transport receive error %d\n", MultiProc_self(), 
448                                                                                 rmClientDelegateName,
449                                                                                 rmServerName,
450                                                                                 retVal);
451             }
453             retVal = Rm_receivePktPolling(rmTransportMap[CD_TO_CLIENT_MAP_ENTRY].transportHandle);
454             if (retVal != RM_TRANSPORT_SUCCESSFUL)
455             {
456                 System_printf("Core %d: %s to %s transport receive error %d\n", MultiProc_self(),
457                                                                                 rmClientDelegateName,
458                                                                                 rmClientName,
459                                                                                 retVal);
460             }
462             retVal = Rm_receivePktPolling(rmTransportMap[CLIENT_TO_CD_MAP_ENTRY].transportHandle);
463             if (retVal != RM_TRANSPORT_SUCCESSFUL)
464             {
465                 System_printf("Core %d: %s to %s transport receive error %d\n", MultiProc_self(), 
466                                                                                 rmClientName,
467                                                                                 rmClientDelegateName,
468                                                                                 retVal);
469             }
470         }
472         /* Yield for main test task */
473         Task_yield();
474     }
477 /*
478  *  ======== testRmTsk ========
479  *  RM test task
480  */
481 void testRmTsk(UArg arg0, UArg arg1)
483     Rm_ServiceReqInfo requestInfo;
484     Task_Params taskParams;    
485        
486     /* Delete the RM startup task */
487     System_printf("Core %d: Deleting RM startup task...\n", MultiProc_self());
488     if (startupRmTskHandle)
489     {
490         Task_delete(&startupRmTskHandle);
491         /* Set the task handle to be NULL so that the delete only occurs once */
492         startupRmTskHandle = NULL;
493     }
495     /* Open service ports on all the RM instances to test service requests from the different
496      * RM instances */
497     if (MultiProc_self() == 0)
498     {
499         rmServerServicePort = Rm_serviceGetPort(rmServerHandle);
500     }
501     else if (MultiProc_self() == 1)
502     {
503         rmClientDelegateServicePort = Rm_serviceGetPort(rmClientDelegateHandle);
504         rmClientServicePort = Rm_serviceGetPort(rmClientHandle);
505     }
507     memset((void *)&requestInfo, 0, sizeof(Rm_ServiceReqInfo));
508     memset((void *)&responseInfo, 0, sizeof(Rm_ServiceRespInfo));
510     System_printf("Core %d: Testing NameServer features...\n", MultiProc_self());
512     /* Use the service ports to test the service requests */
513     if (MultiProc_self() == 0)
514     {
515         char resourceName[RM_RESOURCE_NAME_MAX_CHARS] = "gp-queue";
516         char resourceNsName[RM_RESOURCE_NAME_MAX_CHARS] = "My_Favorite_Queue";
518         char aifName[RM_RESOURCE_NAME_MAX_CHARS] = "aif-rx-ch";
519         char memRegionName[RM_RESOURCE_NAME_MAX_CHARS] = "memory-regions";
523         /* Issue the service request create a new NameServer object via the service port */                
524         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
525         requestInfo.resourceName = resourceName;
526         requestInfo.resourceBase = RM_RESOURCE_BASE_UNSPECIFIED;
527         requestInfo.resourceLength = 1;
528         requestInfo.resourceAlignment = 0;
529         requestInfo.callback.serviceCallback = testServiceCallback;
530         
531         System_printf("Core %d: %s Allocating resource...\n", MultiProc_self(), rmServerName);
532         rmServerServicePort->Rm_serviceHandler(rmServerServicePort->rmHandle, &requestInfo, &responseInfo);
533         if (blockForResponse(&responseInfo))
534         {
535             System_printf("Core %d: %s allocated resource: %s base: %d length: %d\n", MultiProc_self(),
536                                                                                       rmServerName,
537                                                                                       responseInfo.resourceName, 
538                                                                                       responseInfo.resourceBase,
539                                                                                       responseInfo.resourceLength);            
540         }   
542         /* Issue the service request create a new NameServer object via the service port */                
543         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
544         requestInfo.resourceName = resourceName;
545         requestInfo.resourceBase = RM_RESOURCE_BASE_UNSPECIFIED;
546         requestInfo.resourceLength = 1;
547         requestInfo.resourceAlignment = RM_RESOURCE_ALIGNMENT_UNSPECIFIED;
548         requestInfo.callback.serviceCallback = testServiceCallback;
549         
550         System_printf("Core %d: %s Allocating resource...\n", MultiProc_self(), rmServerName);
551         rmServerServicePort->Rm_serviceHandler(rmServerServicePort->rmHandle, &requestInfo, &responseInfo);
552         if (blockForResponse(&responseInfo))
553         {
554             System_printf("Core %d: %s allocated resource: %s base: %d length: %d\n", MultiProc_self(),
555                                                                                       rmServerName,
556                                                                                       responseInfo.resourceName, 
557                                                                                       responseInfo.resourceBase,
558                                                                                       responseInfo.resourceLength);            
559         }         
561         /* Issue the service request create a new NameServer object via the service port */                
562         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
563         requestInfo.resourceName = resourceName;
564         requestInfo.resourceBase = RM_RESOURCE_BASE_UNSPECIFIED;
565         requestInfo.resourceLength = 1;
566         requestInfo.resourceAlignment = 200;
567         requestInfo.callback.serviceCallback = testServiceCallback;
568         
569         System_printf("Core %d: %s Allocating resource...\n", MultiProc_self(), rmServerName);
570         rmServerServicePort->Rm_serviceHandler(rmServerServicePort->rmHandle, &requestInfo, &responseInfo);
571         if (blockForResponse(&responseInfo))
572         {
573             System_printf("Core %d: %s allocated resource: %s base: %d length: %d\n", MultiProc_self(),
574                                                                                       rmServerName,
575                                                                                       responseInfo.resourceName, 
576                                                                                       responseInfo.resourceBase,
577                                                                                       responseInfo.resourceLength);            
578         }   
580         Rm_printResourceStatus(rmServerHandle);
583         /* Issue the service request create a new NameServer object via the service port */                
584         requestInfo.type = Rm_service_RESOURCE_MAP_TO_NAME;
585         requestInfo.resourceName = resourceName;
586         requestInfo.resourceBase = 1002;
587         requestInfo.resourceLength = 1;
588         requestInfo.resourceNsName = resourceNsName;
589         requestInfo.callback.serviceCallback = testServiceCallback;
590         
591         System_printf("Core %d: %s creating NameServer object...\n", MultiProc_self(), rmServerName);
592         rmServerServicePort->Rm_serviceHandler(rmServerServicePort->rmHandle, &requestInfo, &responseInfo);
593         if (blockForResponse(&responseInfo))
594         {
595             System_printf("Core %d: %s created NameServer object: %s base: %d length: %d\n", MultiProc_self(),
596                                                                                              rmServerName,
597                                                                                              resourceNsName, 
598                                                                                              requestInfo.resourceBase,
599                                                                                              requestInfo.resourceLength);            
600         }
602         /* Wait for Client Delegate and Client to retrieve resource via the name and allocate it */
603         waitOnSyncObj();
605         Rm_printResourceStatus(rmServerHandle);
607         /* Wait for Client to free resource via the NameServer and delete the NameServer object. */
608         waitOnSyncObj();
610         Rm_printResourceStatus(rmServerHandle);
612         /* Try to allocate the memory region taken by the Linux Kernel */
613         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
614         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
615         requestInfo.resourceName = memRegionName;
616         requestInfo.resourceBase = 12;
617         requestInfo.resourceLength = 1;
618         requestInfo.callback.serviceCallback = testServiceCallback;
619         
620         System_printf("Core %d: %s Trying to reserve memory region taken by Linux...\n", MultiProc_self(), rmServerName);
621         rmServerServicePort->Rm_serviceHandler(rmServerServicePort->rmHandle, &requestInfo, &responseInfo);
622         if (blockForResponse(&responseInfo))
623         {
624             System_printf("Core %d: %s allocated resource (SHOULD NOT HAPPEN): %s base: %d length: %d\n", MultiProc_self(),
625                                                                                                           rmServerName,
626                                                                                                           requestInfo.resourceName, 
627                                                                                                           requestInfo.resourceBase,
628                                                                                                           requestInfo.resourceLength);            
629         }  
631         /* Allocate some resources for testing tree interaction with multiple allocations from different instances */
632         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
633         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
634         requestInfo.resourceName = aifName;
635         requestInfo.resourceBase = 14;
636         requestInfo.resourceLength = 5;
637         requestInfo.callback.serviceCallback = testServiceCallback;
638         
639         System_printf("Core %d: %s Allocating resource...\n", MultiProc_self(), rmServerName);
640         rmServerServicePort->Rm_serviceHandler(rmServerServicePort->rmHandle, &requestInfo, &responseInfo);
641         if (blockForResponse(&responseInfo))
642         {
643             System_printf("Core %d: %s allocated resource: %s base: %d length: %d\n", MultiProc_self(),
644                                                                                       rmServerName,
645                                                                                       requestInfo.resourceName, 
646                                                                                       requestInfo.resourceBase,
647                                                                                       requestInfo.resourceLength);            
648         }    
649         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
650         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
651         requestInfo.resourceName = aifName;
652         requestInfo.resourceBase = 19;
653         requestInfo.resourceLength = 31;
654         requestInfo.callback.serviceCallback = testServiceCallback;
655         
656         System_printf("Core %d: %s Allocating resource...\n", MultiProc_self(), rmServerName);
657         rmServerServicePort->Rm_serviceHandler(rmServerServicePort->rmHandle, &requestInfo, &responseInfo);
658         if (blockForResponse(&responseInfo))
659         {
660             System_printf("Core %d: %s allocated resource: %s base: %d length: %d\n", MultiProc_self(),
661                                                                                       rmServerName,
662                                                                                       requestInfo.resourceName, 
663                                                                                       requestInfo.resourceBase,
664                                                                                       requestInfo.resourceLength);            
665         }            
666         
667         /* Wait for Client and Client Delegate to do their allocates */
668         waitOnSyncObj();
670         Rm_printResourceStatus(rmServerHandle);        
672         /* Free resources to show tree handling of different frees */
673         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
674         requestInfo.type = Rm_service_RESOURCE_FREE;
675         requestInfo.resourceName = aifName;
676         requestInfo.resourceBase = 25;
677         requestInfo.resourceLength = 3;
678         requestInfo.callback.serviceCallback = testServiceCallback;
679         
680         System_printf("Core %d: %s freeing resource...\n", MultiProc_self(), rmServerName);
681         rmServerServicePort->Rm_serviceHandler(rmServerServicePort->rmHandle, &requestInfo, &responseInfo);
682         if (blockForResponse(&responseInfo))
683         {
684             System_printf("Core %d: %s freed resource: %s base: %d length: %d\n", MultiProc_self(),
685                                                                                       rmServerName,
686                                                                                       requestInfo.resourceName, 
687                                                                                       requestInfo.resourceBase,
688                                                                                       requestInfo.resourceLength);            
689         }            
690         
691         Rm_printResourceStatus(rmServerHandle);   
692         
693         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
694         requestInfo.type = Rm_service_RESOURCE_FREE;
695         requestInfo.resourceName = aifName;
696         requestInfo.resourceBase = 34;
697         requestInfo.resourceLength = 3;
698         requestInfo.callback.serviceCallback = testServiceCallback;
699         
700         System_printf("Core %d: %s freeing resource...\n", MultiProc_self(), rmServerName);
701         rmServerServicePort->Rm_serviceHandler(rmServerServicePort->rmHandle, &requestInfo, &responseInfo);
702         if (blockForResponse(&responseInfo))
703         {
704             System_printf("Core %d: %s freed resource: %s base: %d length: %d\n", MultiProc_self(),
705                                                                                       rmServerName,
706                                                                                       requestInfo.resourceName, 
707                                                                                       requestInfo.resourceBase,
708                                                                                       requestInfo.resourceLength);            
709         }            
710         
711         Rm_printResourceStatus(rmServerHandle);           
712      
713         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
714         requestInfo.type = Rm_service_RESOURCE_FREE;
715         requestInfo.resourceName = aifName;
716         requestInfo.resourceBase = 28;
717         requestInfo.resourceLength = 6;
718         requestInfo.callback.serviceCallback = testServiceCallback;
719         
720         System_printf("Core %d: %s freeing resource...\n", MultiProc_self(), rmServerName);
721         rmServerServicePort->Rm_serviceHandler(rmServerServicePort->rmHandle, &requestInfo, &responseInfo);
722         if (blockForResponse(&responseInfo))
723         {
724             System_printf("Core %d: %s freed resource: %s base: %d length: %d\n", MultiProc_self(),
725                                                                                       rmServerName,
726                                                                                       requestInfo.resourceName, 
727                                                                                       requestInfo.resourceBase,
728                                                                                       requestInfo.resourceLength);            
729         }            
730         
731         Rm_printResourceStatus(rmServerHandle);     
733         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
734         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
735         requestInfo.resourceName = aifName;
736         requestInfo.resourceBase = 53;
737         requestInfo.resourceLength = 2;
738         requestInfo.callback.serviceCallback = testServiceCallback;
739         
740         System_printf("Core %d: %s freeing resource...\n", MultiProc_self(), rmServerName);
741         rmServerServicePort->Rm_serviceHandler(rmServerServicePort->rmHandle, &requestInfo, &responseInfo);
742         if (blockForResponse(&responseInfo))
743         {
744             System_printf("Core %d: %s allocate resource: %s base: %d length: %d\n", MultiProc_self(),
745                                                                                       rmServerName,
746                                                                                       requestInfo.resourceName, 
747                                                                                       requestInfo.resourceBase,
748                                                                                       requestInfo.resourceLength);            
749         }    
750         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
751         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
752         requestInfo.resourceName = aifName;
753         requestInfo.resourceBase = 2;
754         requestInfo.resourceLength = 2;
755         requestInfo.callback.serviceCallback = testServiceCallback;
756         
757         System_printf("Core %d: %s freeing resource...\n", MultiProc_self(), rmServerName);
758         rmServerServicePort->Rm_serviceHandler(rmServerServicePort->rmHandle, &requestInfo, &responseInfo);
759         if (blockForResponse(&responseInfo))
760         {
761             System_printf("Core %d: %s allocate resource: %s base: %d length: %d\n", MultiProc_self(),
762                                                                                       rmServerName,
763                                                                                       requestInfo.resourceName, 
764                                                                                       requestInfo.resourceBase,
765                                                                                       requestInfo.resourceLength);            
766         }           
767         
768         Rm_printResourceStatus(rmServerHandle); 
770         /* Wait for Client and Client Delegate to do their UNSPECIFIED allocates */
771         waitOnSyncObj();
773         Rm_printResourceStatus(rmServerHandle);      
774         
775     }
776     else if (MultiProc_self() == 1)
777     {    
778         char resourceNsName[RM_RESOURCE_NAME_MAX_CHARS] = "My_Favorite_Queue";
780         char aifName[RM_RESOURCE_NAME_MAX_CHARS] = "aif-rx-ch";    
781         char accumChName[RM_RESOURCE_NAME_MAX_CHARS] = "accumulator-ch";
783         /* Issue the service request for the resources tied to the name via the service port */                
784         requestInfo.type = Rm_service_RESOURCE_GET_BY_NAME;
785         requestInfo.resourceNsName = resourceNsName;
786         requestInfo.callback.serviceCallback = testServiceCallback;
787         
788         System_printf("Core %d: %s getting resources tied to NameServer object...\n", MultiProc_self(), 
789                                                                                       rmClientDelegateName);
790         rmClientDelegateServicePort->Rm_serviceHandler(rmClientDelegateServicePort->rmHandle, &requestInfo, &responseInfo);
791         if (blockForResponse(&responseInfo))
792         {
793             System_printf("Core %d: %s got Name: %s base: %d length: %d\n", MultiProc_self(),
794                                                                             rmClientDelegateName, 
795                                                                             resourceNsName, 
796                                                                             responseInfo.resourceBase,
797                                                                             responseInfo.resourceLength);
798         }
800         /* Allocate the resources via the service port from the Client */
801         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_INIT;
802         requestInfo.resourceName = responseInfo.resourceName;
803         requestInfo.resourceBase = responseInfo.resourceBase;
804         requestInfo.resourceLength = responseInfo.resourceLength;
805         requestInfo.resourceNsName = NULL;
806         requestInfo.callback.serviceCallback = testServiceCallback;
807         
808         System_printf("Core %d: %s allocating resources...\n", MultiProc_self(), rmClientName);
809         rmClientServicePort->Rm_serviceHandler(rmClientServicePort->rmHandle, &requestInfo, &responseInfo);
810         if (blockForResponse(&responseInfo))
811         {
812             System_printf("Core %d: %s allocated resources: %s base: %d length: %d\n", MultiProc_self(),
813                                                                                        rmClientName, 
814                                                                                        resourceNsName, 
815                                                                                        responseInfo.resourceBase,
816                                                                                        responseInfo.resourceLength);
817         }
819         /* Release the syncObj so Server can print results of NameServer object add and resource allocate */
820         releaseSyncObj();
822         /* Take the syncObj to free the name resource via the name, rather than the base+length */
823         takeSyncObj();
825         /* Free the named resource using the name via the service port from the Client */
826         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));
827         requestInfo.type = Rm_service_RESOURCE_FREE;
828         requestInfo.resourceNsName = resourceNsName;
829         requestInfo.callback.serviceCallback = testServiceCallback;
830         
831         System_printf("Core %d: %s freeing resource via name...\n", MultiProc_self(), rmClientName);
832         rmClientServicePort->Rm_serviceHandler(rmClientServicePort->rmHandle, &requestInfo, &responseInfo);
833         if (blockForResponse(&responseInfo))
834         {
835             System_printf("Core %d: %s freed resource with name: %s\n", MultiProc_self(),
836                                                                         rmClientName, 
837                                                                         resourceNsName);
838         }
840         /* Delete the name object from the NameServer */
841         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));
842         requestInfo.type = Rm_service_RESOURCE_UNMAP_NAME;
843         requestInfo.resourceNsName = resourceNsName;
844         requestInfo.callback.serviceCallback = testServiceCallback;
845         
846         System_printf("Core %d: %s Deleting NameServer object: %s...\n", MultiProc_self(), 
847                                                                          rmClientName,
848                                                                          resourceNsName);
849         rmClientServicePort->Rm_serviceHandler(rmClientServicePort->rmHandle, &requestInfo, &responseInfo);
850         if (blockForResponse(&responseInfo))
851         {
852             System_printf("Core %d: %s deleted NameServer object: %s\n", MultiProc_self(),
853                                                                          rmClientName, 
854                                                                          resourceNsName);
855         }
857         /* Release the syncObj so Server can print results of resource free and NameServer object delete. */
858         releaseSyncObj();   
860         /* Take the syncObj to allocate resources for testing resource tree interactions. */
861         takeSyncObj();
863         /* Allocate some resources for testing tree interaction with multiple allocations from different instances */
864         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
865         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
866         requestInfo.resourceName = aifName;
867         requestInfo.resourceBase = 0;
868         requestInfo.resourceLength = 6;
869         requestInfo.callback.serviceCallback = testServiceCallback;
870         
871         System_printf("Core %d: %s Allocating resource...\n", MultiProc_self(), rmClientName);
872         rmClientServicePort->Rm_serviceHandler(rmClientServicePort->rmHandle, &requestInfo, &responseInfo);
873         if (blockForResponse(&responseInfo))
874         {
875             System_printf("Core %d: %s allocated resource: %s base: %d length: %d\n", MultiProc_self(),
876                                                                                       rmClientName,
877                                                                                       requestInfo.resourceName, 
878                                                                                       requestInfo.resourceBase,
879                                                                                       requestInfo.resourceLength);            
880         }     
881         
882         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
883         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_INIT;
884         requestInfo.resourceName = aifName;
885         requestInfo.resourceBase = 50;
886         requestInfo.resourceLength = 7;
887         requestInfo.callback.serviceCallback = testServiceCallback;
888         
889         System_printf("Core %d: %s Allocating resource...\n", MultiProc_self(), rmClientDelegateName);
890         rmClientDelegateServicePort->Rm_serviceHandler(rmClientDelegateServicePort->rmHandle, &requestInfo, &responseInfo);
891         if (blockForResponse(&responseInfo))
892         {
893             System_printf("Core %d: %s allocated resource: %s base: %d length: %d\n", MultiProc_self(),
894                                                                                       rmClientDelegateName,
895                                                                                       requestInfo.resourceName, 
896                                                                                       requestInfo.resourceBase,
897                                                                                       requestInfo.resourceLength);            
898         }  
900         /* Release the syncObj so Server can print results of resource allocations */
901         releaseSyncObj();    
903         /* Take the syncObj to allocate resources using the UNSPECIFIED parameters. */
904         takeSyncObj();
906         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
907         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
908         requestInfo.resourceName = accumChName;
909         requestInfo.resourceBase = RM_RESOURCE_BASE_UNSPECIFIED;
910         requestInfo.resourceLength = 5;
911         requestInfo.resourceAlignment = 4;
912         requestInfo.callback.serviceCallback = testServiceCallback;
913         
914         System_printf("Core %d: %s Allocating resource...\n", MultiProc_self(), rmClientDelegateName);
915         rmClientDelegateServicePort->Rm_serviceHandler(rmClientDelegateServicePort->rmHandle, &requestInfo, &responseInfo);
916         if (blockForResponse(&responseInfo))
917         {
918             System_printf("Core %d: %s allocated resource: %s base: %d length: %d\n", MultiProc_self(),
919                                                                                       rmClientDelegateName,
920                                                                                       responseInfo.resourceName, 
921                                                                                       responseInfo.resourceBase,
922                                                                                       responseInfo.resourceLength);            
923         }    
925         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
926         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
927         requestInfo.resourceName = accumChName;
928         requestInfo.resourceBase = RM_RESOURCE_BASE_UNSPECIFIED;
929         requestInfo.resourceLength = 2;
930         requestInfo.resourceAlignment = 1;
931         requestInfo.callback.serviceCallback = testServiceCallback;
932         
933         System_printf("Core %d: %s Allocating resource...\n", MultiProc_self(), rmClientName);
934         rmClientServicePort->Rm_serviceHandler(rmClientServicePort->rmHandle, &requestInfo, &responseInfo);
935         if (blockForResponse(&responseInfo))
936         {
937             System_printf("Core %d: %s allocated resource: %s base: %d length: %d\n", MultiProc_self(),
938                                                                                       rmClientName,
939                                                                                       responseInfo.resourceName, 
940                                                                                       responseInfo.resourceBase,
941                                                                                       responseInfo.resourceLength);            
942         }    
944         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
945         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
946         requestInfo.resourceName = accumChName;
947         requestInfo.resourceBase = RM_RESOURCE_BASE_UNSPECIFIED;
948         requestInfo.resourceLength = 2;
949         requestInfo.resourceAlignment = RM_RESOURCE_ALIGNMENT_UNSPECIFIED;
950         requestInfo.callback.serviceCallback = testServiceCallback;
951         
952         System_printf("Core %d: %s Allocating resource...\n", MultiProc_self(), rmClientName);
953         rmClientServicePort->Rm_serviceHandler(rmClientServicePort->rmHandle, &requestInfo, &responseInfo);
954         if (blockForResponse(&responseInfo))
955         {
956             System_printf("Core %d: %s allocated resource: %s base: %d length: %d\n", MultiProc_self(),
957                                                                                       rmClientName,
958                                                                                       responseInfo.resourceName, 
959                                                                                       responseInfo.resourceBase,
960                                                                                       responseInfo.resourceLength);            
961         }           
963         /* Release the syncObj so Server can print results of resource allocations */
964         releaseSyncObj();           
965     }
967     System_printf("Core %d: Testing is complete\n", MultiProc_self());
968     
969     /* Create the RM cleanup task. */
970     System_printf("Core %d: Creating RM cleanup task...\n", MultiProc_self());
971     Task_Params_init (&taskParams);
972     Task_create (cleanupRmTsk, &taskParams, NULL);
975 /*
976  *  ======== startupRmTsk ========
977  *  Configures application transports and registers them with RM
978  */
979 Void startupRmTsk(UArg arg0, UArg arg1)
981     MessageQ_Handle  serverCdMsgQ, cdServerMsgQ, cdClientMsgQ, clientCdMsgQ;
982     MessageQ_QueueId serverCdQId, cdServerQId, cdClientQId, clientCdQId;    
983     Int              status, i;
984     HeapBufMP_Handle msgQHeapHandle;
985     HeapBufMP_Params heapBufParams;
986     Rm_TransportCfg rmTransportCfg;
987     int32_t result = 0;
988     Rm_TransportHandle serverCdHandle, cdServerHandle, cdClientHandle, clientCdHandle;
989     Task_Params taskParams;
991     if (MultiProc_self() == 1)
992     {
993         /* Take the syncObj on core 1, preparing for RM testing */
994         takeSyncObj();  
995     }
997     /* Initialize the transport map */
998     for (i = 0; i < MAX_MAPPING_ENTRIES; i++)
999     {
1000         rmTransportMap[i].transportHandle = NULL;
1001     }
1003     if (MultiProc_self() == 0)
1004     {
1005         /* Create the heap that will be used to allocate RM messages. This
1006          * heap is a multi-processor heap.  It will be shared amongst
1007          * all RM instances. */     
1008         HeapBufMP_Params_init(&heapBufParams);
1009         heapBufParams.regionId       = 0;
1010         heapBufParams.name           = RM_PKT_HEAP_NAME;
1011         heapBufParams.numBlocks      = 64;
1012         heapBufParams.blockSize      = sizeof(Rm_Packet);
1013         rmPktHeapHandle = HeapBufMP_create(&heapBufParams);
1014         if (rmPktHeapHandle == NULL) 
1015         {
1016             System_abort("HeapBufMP_create failed for RM packet heap\n" );
1017         }
1018         System_printf("Core %d: RM packet heap created\n", MultiProc_self());
1020         /* Create the heap that will be used to allocate messageQ messages. */     
1021         HeapBufMP_Params_init(&heapBufParams);
1022         heapBufParams.regionId       = 0;
1023         heapBufParams.name           = MSGQ_HEAP_NAME;
1024         heapBufParams.numBlocks      = 64;
1025         heapBufParams.blockSize      = sizeof(MsgQ_RmPacket);
1026         msgQHeapHandle = HeapBufMP_create(&heapBufParams);
1027         if (msgQHeapHandle == NULL) 
1028         {
1029             System_abort("HeapBufMP_create failed MessageQ message heap\n" );
1030         } 
1031         System_printf("Core %d: IPC MessageQ message heap created\n", MultiProc_self());
1032     }
1033     else 
1034     {
1035         /* Open the heaps created by the other processor. Loop until opened. */
1036         do 
1037         {
1038             status = HeapBufMP_open(RM_PKT_HEAP_NAME, &rmPktHeapHandle);
1039             /* 
1040              *  Sleep for 1 clock tick to avoid inundating remote processor
1041              *  with interrupts if open failed
1042              */
1043             if (status < 0)
1044             { 
1045                 Task_sleep(1);
1046             }
1047         } while (status < 0);
1048         System_printf("Core %d: RM packet heap opened\n", MultiProc_self());
1049         
1050         do 
1051         {
1052             status = HeapBufMP_open(MSGQ_HEAP_NAME, &msgQHeapHandle);
1053             /* 
1054              *  Sleep for 1 clock tick to avoid inundating remote processor
1055              *  with interrupts if open failed
1056              */
1057             if (status < 0)
1058             { 
1059                 Task_sleep(1);
1060             }
1061         } while (status < 0);
1062         System_printf("Core %d: IPC MessageQ message heap opened\n", MultiProc_self());
1063     }
1064     
1065     /* Register the MessageQ heap with MessageQ */
1066     MessageQ_registerHeap((IHeap_Handle)msgQHeapHandle, MSGQ_HEAP_ID);
1068     /* Create the messageQ's for each RM instance connection
1069      * Need four queues.  Topology will be:
1070      * RM Server <---> RM Client Delegate <---> RM Client 
1071      * 1 queue on RM Server
1072      * 2 queues on RM Client Delegate
1073      * 1 queue on RM Client */
1074     if (MultiProc_self() == 0)
1075     {
1076         /* Create the RM Server messageQ used by the RM Client Delegate */
1077         serverCdMsgQ = MessageQ_create(serverCdQueueName, NULL);
1078         if (serverCdMsgQ == NULL) 
1079         {
1080             System_abort("MessageQ_create failed for RM Server - Client Delegate queue\n" );
1081         }
1082         System_printf("Core %d: RM Server MessageQ created for receiving packets from RM CD\n", MultiProc_self());
1083     }
1084     else if (MultiProc_self() == 1)
1085     {
1086         /* Create the RM Client Delegate messageQ used by the RM Server */
1087         cdServerMsgQ = MessageQ_create(cdServerQueueName, NULL);
1088         if (cdServerMsgQ == NULL) 
1089         {
1090             System_abort("MessageQ_create failed for RM Client Delegate - Server queue\n" );
1091         }
1092         System_printf("Core %d: RM CD MessageQ created for receiving packets from RM Server\n", MultiProc_self());
1093         /* Create the RM Client Delegate messageQ used by the RM Client */
1094         cdClientMsgQ = MessageQ_create(cdClientQueueName, NULL);
1095         if (cdClientMsgQ == NULL) 
1096         {
1097             System_abort("MessageQ_create failed for RM Client Delegate - Client queue\n" );
1098         } 
1099         System_printf("Core %d: RM CD MessageQ created for receiving packets from RM Client\n", MultiProc_self());
1100         /* Create the RM Client messageQ used by the RM Client Delegate */
1101         clientCdMsgQ = MessageQ_create(clientCdQueueName, NULL);
1102         if (clientCdMsgQ == NULL) 
1103         {
1104             System_abort("MessageQ_create failed for RM Client - Client Delegate queue\n" );
1105         }
1106         System_printf("Core %d: RM Client MessageQ created for receiving packets from RM CD\n", MultiProc_self());
1107     }
1108     
1109     /* Open the remote message queues. Also register the RM transports with each RM instance */
1110     if (MultiProc_self() == 0)
1111     {
1112         /* Open the Client Delegate messageQ from the Server */
1113         do 
1114         {
1115             status = MessageQ_open(cdServerQueueName, &serverCdQId); 
1116             /* 
1117              *  Sleep for 1 clock tick to avoid inundating remote processor
1118              *  with interrupts if open failed
1119              */
1120             if (status < 0)
1121             { 
1122                 Task_sleep(1);
1123             }
1124         } while (status < 0);
1125         System_printf("Core %d: RM CD MessageQ opened from RM Server\n", MultiProc_self());
1127         /* Register the Client Delegate with the RM Server Instance */
1128         rmTransportCfg.remoteInstType = Rm_instType_CLIENT_DELEGATE;
1129         rmTransportCfg.remoteInstName = &rmClientDelegateName[0];
1130         /* Set the callouts as valid for the first transport configuration on Server instance */
1131         rmTransportCfg.rmHandle = rmServerHandle;
1132         rmTransportCfg.transportCalloutsValid = true;
1133         rmTransportCfg.transportCallouts.rmAllocPkt = TransportAlloc;
1134         rmTransportCfg.transportCallouts.rmFreePkt = TransportFree;
1135         rmTransportCfg.transportCallouts.rmSend = TransportSend;
1136         rmTransportCfg.transportCallouts.rmReceive = TransportReceive;        
1137         rmTransportCfg.transportCallouts.rmNumPktsReceived = TransportNumPktsReceived; 
1139         serverCdHandle = Rm_transportRegister(&rmTransportCfg, &result);
1141         /* Store the mapping information in the transport map */
1142         rmTransportMap[SERVER_TO_CD_MAP_ENTRY].transportHandle = serverCdHandle;
1143         rmTransportMap[SERVER_TO_CD_MAP_ENTRY].receiveMsgQ = serverCdMsgQ;
1144         rmTransportMap[SERVER_TO_CD_MAP_ENTRY].remoteMsgQId = serverCdQId;
1145         System_printf("Core %d: Registered RM Server <=> RM CD transport with RM Server instance\n", MultiProc_self());
1146         
1147     }
1148     else if (MultiProc_self() == 1)
1149     {
1150         /* Open the Server messageQ from the Client Delegate */
1151         do 
1152         {
1153             status = MessageQ_open(serverCdQueueName, &cdServerQId); 
1154             /* 
1155              *  Sleep for 1 clock tick to avoid inundating remote processor
1156              *  with interrupts if open failed
1157              */
1158             if (status < 0) 
1159             { 
1160                 Task_sleep(1);
1161             }
1162         } while (status < 0);
1163         System_printf("Core %d: RM Server MessageQ opened from RM CD\n", MultiProc_self());
1165         /* Register the Server with the RM Client Delegate Instance */
1166         rmTransportCfg.remoteInstType = Rm_instType_SERVER;
1167         rmTransportCfg.remoteInstName = &rmServerName[0];
1168         /* Set the callouts as valid for the first transport configuration on Client Delegate instance */
1169         rmTransportCfg.rmHandle = rmClientDelegateHandle;
1170         rmTransportCfg.transportCalloutsValid = true;
1171         rmTransportCfg.transportCallouts.rmAllocPkt = TransportAlloc;
1172         rmTransportCfg.transportCallouts.rmFreePkt = TransportFree;
1173         rmTransportCfg.transportCallouts.rmSend = TransportSend;
1174         rmTransportCfg.transportCallouts.rmReceive = TransportReceive;        
1175         rmTransportCfg.transportCallouts.rmNumPktsReceived = TransportNumPktsReceived; 
1177         cdServerHandle = Rm_transportRegister(&rmTransportCfg, &result);
1179         /* Store the mapping information in the transport map */
1180         rmTransportMap[CD_TO_SERVER_MAP_ENTRY].transportHandle = cdServerHandle;
1181         rmTransportMap[CD_TO_SERVER_MAP_ENTRY].receiveMsgQ = cdServerMsgQ;
1182         rmTransportMap[CD_TO_SERVER_MAP_ENTRY].remoteMsgQId = cdServerQId;
1183         System_printf("Core %d: Registered RM CD <=> RM Server transport with RM CD instance\n", MultiProc_self());
1184         
1185         /* Open the Client messageQ from the Client Delegate */
1186         do 
1187         {
1188             status = MessageQ_open(clientCdQueueName, &cdClientQId); 
1189             /* 
1190              *  Sleep for 1 clock tick to avoid inundating remote processor
1191              *  with interrupts if open failed
1192              */
1193             if (status < 0) 
1194             { 
1195                 Task_sleep(1);
1196             }
1197         } while (status < 0);
1198         System_printf("Core %d: RM Client MessageQ opened from RM CD\n", MultiProc_self());
1200         /* Register the Client with the RM Client Delegate Instance */
1201         rmTransportCfg.remoteInstType = Rm_instType_CLIENT;
1202         rmTransportCfg.remoteInstName = &rmClientName[0];
1203         /* Callouts already set on the Client Delegate so set them as invalid */
1204         rmTransportCfg.transportCalloutsValid = false;
1206         cdClientHandle = Rm_transportRegister(&rmTransportCfg, &result);
1208         /* Store the mapping information in the transport map */
1209         rmTransportMap[CD_TO_CLIENT_MAP_ENTRY].transportHandle = cdClientHandle;
1210         rmTransportMap[CD_TO_CLIENT_MAP_ENTRY].receiveMsgQ = cdClientMsgQ;
1211         rmTransportMap[CD_TO_CLIENT_MAP_ENTRY].remoteMsgQId = cdClientQId;
1212         System_printf("Core %d: Registered RM CD <=> RM Client transport with RM CD instance\n", MultiProc_self());
1214         /* Open the Client Delegate messageQ from the Client */        
1215         do 
1216         {
1217             status = MessageQ_open(cdClientQueueName, &clientCdQId); 
1218             /* 
1219              *  Sleep for 1 clock tick to avoid inundating remote processor
1220              *  with interrupts if open failed
1221              */
1222             if (status < 0) 
1223             { 
1224                 Task_sleep(1);
1225             }
1226         } while (status < 0);
1227         System_printf("Core %d: RM CD MessageQ opened from RM Client\n", MultiProc_self());
1229         /* Register the Client Delegate with the RM Client Instance */
1230         rmTransportCfg.remoteInstType = Rm_instType_CLIENT_DELEGATE;
1231         rmTransportCfg.remoteInstName = &rmClientDelegateName[0];
1232         /* Set the callouts as valid for the first transport configuration on Client instance */
1233         rmTransportCfg.rmHandle = rmClientHandle;
1234         rmTransportCfg.transportCalloutsValid = true;
1235         rmTransportCfg.transportCallouts.rmAllocPkt = TransportAlloc;
1236         rmTransportCfg.transportCallouts.rmFreePkt = TransportFree;
1237         rmTransportCfg.transportCallouts.rmSend = TransportSend;
1238         rmTransportCfg.transportCallouts.rmReceive = TransportReceive;        
1239         rmTransportCfg.transportCallouts.rmNumPktsReceived = TransportNumPktsReceived; 
1241         clientCdHandle = Rm_transportRegister(&rmTransportCfg, &result);
1243         /* Store the mapping information in the transport map */
1244         rmTransportMap[CLIENT_TO_CD_MAP_ENTRY].transportHandle = clientCdHandle;
1245         rmTransportMap[CLIENT_TO_CD_MAP_ENTRY].receiveMsgQ = clientCdMsgQ;
1246         rmTransportMap[CLIENT_TO_CD_MAP_ENTRY].remoteMsgQId = clientCdQId; 
1247         System_printf("Core %d: Registered RM Client <=> RM CD transport with RM Client instance\n", MultiProc_self());
1248     }
1250     /* Creat the RM receive task. */
1251     System_printf("Core %d: Creating RM receive task...\n", MultiProc_self());
1252     Task_Params_init (&taskParams);
1253     testReceiveTskHandle = Task_create (testReceiveTsk, &taskParams, NULL);
1254     
1255     
1256     /* Create the RM test task. */
1257     System_printf("Core %d: Creating RM test task...\n", MultiProc_self());
1258     Task_Params_init (&taskParams);
1259     testRmTskHandle = Task_create (testRmTsk, &taskParams, NULL);
1262 /*
1263  *  ======== main ========
1264  *  Synchronizes all processors (in Ipc_start) and calls BIOS_start
1265  */
1266 Int main(Int argc, Char* argv[])
1268     Rm_InitCfg   rmInitCfg;
1269     Task_Params  taskParams;
1270     FILE        *globalResourceFp;
1271     FILE        *linuxDtbFp;
1272     FILE        *globalPolicyFp;
1273     Int          globalResourceFileSize;
1274     Int          linuxDtbFileSize;
1275     Int          globalPolicyFileSize;
1276     void        *globalResourceList = NULL;
1277     void        *linuxDtb = NULL;
1278     void        *globalPolicy = NULL;
1279     Int          status;
1280     Int          readSize;
1281     int32_t      result;
1283     System_printf ("*********************************************************\n");
1284     System_printf ("********************** RM Testing ***********************\n");
1285     System_printf ("*********************************************************\n");
1287     System_printf ("RM Version : 0x%08x\nVersion String: %s\n", Rm_getVersion(), Rm_getVersionStr());
1289     /* Initialize the RM instances - RM must be initialized before anything else in the system
1290      * Core 0: 1 RM Instance - RM Server
1291      * Core 1: 2 RM Instances - RM Client Delegate
1292      *                          RM Client
1293      */
1294     if (MultiProc_self()== 0) {
1295         initSyncObj();
1296         
1297         globalResourceFp = fopen("C:\\ti\\pdk_tci6614_1_0_0_11\\packages\\ti\\drv\\rm\\device\\tci6614-global-resources.dtb", "rb");
1298         linuxDtbFp = fopen("C:\\ti\\pdk_tci6614_1_0_0_11\\packages\\ti\\drv\\rm\\device\\tci6614-linux-evm.dtb", "rb");
1299         globalPolicyFp = fopen("C:\\ti\\pdk_tci6614_1_0_0_11\\packages\\ti\\drv\\rm\\device\\tci6614-server-policy.dtb", "rb");
1301         fseek(globalResourceFp, 0, SEEK_END);
1302         globalResourceFileSize = ftell(globalResourceFp);
1303         rewind(globalResourceFp);
1305         fseek(linuxDtbFp, 0, SEEK_END);
1306         linuxDtbFileSize = ftell(linuxDtbFp);
1307         rewind(linuxDtbFp);
1309         fseek(globalPolicyFp, 0, SEEK_END);
1310         globalPolicyFileSize = ftell(globalPolicyFp);
1311         rewind(globalPolicyFp);      
1313         globalResourceList = Osal_rmMalloc(globalResourceFileSize);
1314         linuxDtb = Osal_rmMalloc(linuxDtbFileSize);
1315         globalPolicy = Osal_rmMalloc(globalPolicyFileSize);
1317         readSize = fread(globalResourceList, 1, globalResourceFileSize, globalResourceFp);
1318         System_printf("Read Size compared to file size: %d : %d\n", readSize, globalResourceFileSize);
1319         readSize = fread(linuxDtb, 1, linuxDtbFileSize, linuxDtbFp);
1320         System_printf("Read Size compared to file size: %d : %d\n", readSize, linuxDtbFileSize);        
1321         readSize = fread(globalPolicy, 1, globalPolicyFileSize, globalPolicyFp);
1322         System_printf("Read Size compared to file size: %d : %d\n", readSize, globalPolicyFileSize);
1324         /* Create the Server instance */
1325         rmInitCfg.instName = &rmServerName[0];
1326         rmInitCfg.instType = Rm_instType_SERVER;
1327         rmInitCfg.globalResourceList = globalResourceList;
1328         rmInitCfg.linuxDtb = linuxDtb;
1329         rmInitCfg.policy = globalPolicy;
1330         rmServerHandle = Rm_init(&rmInitCfg, &result);
1331         System_printf("Core %d: RM Server instance created. Result = %d\n", MultiProc_self(), result);
1333         Rm_printResourceStatus(rmServerHandle);
1334     }
1335     else if (MultiProc_self()== 1) {
1336         /* Create the RM Client Delegate instance */
1337         rmInitCfg.instName = &rmClientDelegateName[0];
1338         rmInitCfg.instType = Rm_instType_CLIENT_DELEGATE;
1339         rmInitCfg.globalResourceList = NULL;
1340         rmInitCfg.linuxDtb = NULL;
1341         rmInitCfg.policy = NULL;
1342         rmClientDelegateHandle = Rm_init(&rmInitCfg, &result);
1343         System_printf("Core %d: RM Client Delegate instance created. Result = %d\n", MultiProc_self(), result);
1345         /* Create the RM Client instance */
1346         rmInitCfg.instName = &rmClientName[0];
1347         rmInitCfg.instType = Rm_instType_CLIENT;
1348         rmInitCfg.globalResourceList = NULL;
1349         rmInitCfg.linuxDtb = NULL;        
1350         rmInitCfg.policy = NULL;
1351         rmClientHandle = Rm_init(&rmInitCfg, &result);
1352         System_printf("Core %d: RM Client instance created. Result = %d\n", MultiProc_self(), result);
1353     }
1355     System_printf("Core %d: Starting IPC...\n", MultiProc_self());
1356     status = Ipc_start();
1357     if (status < 0) {
1358         System_abort("Ipc_start failed\n");
1359     }
1361     /* Create the RM startup task */
1362     System_printf("Core %d: Creating RM startup task...\n", MultiProc_self());
1363     Task_Params_init (&taskParams);
1364     startupRmTskHandle = Task_create (startupRmTsk, &taskParams, NULL);
1366     System_printf("Core %d: Starting BIOS...\n", MultiProc_self());
1367     BIOS_start();
1369     return (0);