diff --git a/test/rm_test.c b/test/rm_test.c
index a57dbfc06f3344a6033382686fb746e5a285149a..916408433543ee848c07e36edb8f14ec5e8398a2 100644 (file)
--- a/test/rm_test.c
+++ b/test/rm_test.c
#include <c6x.h>
#include <xdc/std.h>
+#include <stdio.h>
#include <string.h>
#include <stdbool.h>
/* ----------------------------------- Resource Manager Headers */
#include <ti/drv/rm/rm.h>
+#include <ti/drv/rm/rm_osal.h>
#include <ti/drv/rm/rm_transport.h>
#include <ti/drv/rm/rm_services.h>
/* ======== Task Handles ======== */
Task_Handle startupRmTskHandle;
+Task_Handle testReceiveTskHandle;
+Task_Handle testRmTskHandle;
/* ======== Application Heaps ======== */
#define RM_PKT_HEAP_NAME "rmHeapBuf"
* One map entry for the Client */
Transport_MapEntry rmTransportMap[MAX_MAPPING_ENTRIES];
+uint32_t waitForBlockingOperation = 0;
+Rm_ServiceRespInfo responseInfo;
+
+/* ======== RM Application Sync APIs ======== */
+
+typedef struct {
+ uint32_t sem;
+ uint32_t pad[31];
+} syncObj;
+
+#pragma DATA_SECTION (testSyncObj, ".syncObj");
+#pragma DATA_ALIGN (testSyncObj, 16)
+syncObj testSyncObj;
+
+void initSyncObj(void)
+{
+ Rm_osalBeginMemAccess((void *) &testSyncObj, sizeof(syncObj));
+ testSyncObj.sem = 0;
+ Rm_osalEndMemAccess((void *) &testSyncObj, sizeof(syncObj));
+}
+
+void takeSyncObj(void)
+{
+ Rm_osalBeginMemAccess((void *) &testSyncObj, sizeof(syncObj));
+ testSyncObj.sem = 1;
+ Rm_osalEndMemAccess((void *) &testSyncObj, sizeof(syncObj));
+}
+
+void waitOnSyncObj(void)
+{
+ do
+ {
+ /* Yield for other tasks */
+ Task_yield();
+ Rm_osalBeginMemAccess((void *) &testSyncObj, sizeof(syncObj));
+ } while (testSyncObj.sem == 1);
+}
+
+void releaseSyncObj(void)
+{
+ Rm_osalBeginMemAccess((void *) &testSyncObj, sizeof(syncObj));
+ testSyncObj.sem = 0;
+ Rm_osalEndMemAccess((void *) &testSyncObj, sizeof(syncObj));
+}
+
/* ======== RM Application Transport APIs ======== */
Rm_Packet *TransportAlloc (Rm_TransportHandle transportHandle, uint32_t pktSize)
@@ -134,7 +183,7 @@ Rm_Packet *TransportAlloc (Rm_TransportHandle transportHandle, uint32_t pktSize)
/* All transports will allocate from the same heap */
- HeapBufMP_alloc(rmPktHeapHandle, pktSize, 0);
+ pkt = HeapBufMP_alloc(rmPktHeapHandle, pktSize, 0);
if (pkt != NULL)
{
}
/* Attach the RM packet to the MessageQ message */
+ Rm_osalEndMemAccess((void *) pkt, pkt->pktLenBytes);
rmMsg->rmPkt = pkt;
/* Send the message to the remote side */
status = MessageQ_put(remoteQueueId, (MessageQ_Msg)rmMsg);
return (status);
}
-void * TransportReceive (Rm_TransportHandle transportHandle)
+void *TransportReceive (Rm_TransportHandle transportHandle)
{
MessageQ_Handle receiveQ;
MessageQ_Msg rmMsg = NULL;
/* Extract the Rm_Packet from the RM msg */
rmPkt = ((MsgQ_RmPacket *)rmMsg)->rmPkt;
+ Rm_osalBeginMemAccess((void *) rmPkt, rmPkt->pktLenBytes);
/* Free the messageQ message now that RM packet pointer has been extracted */
status = MessageQ_free(rmMsg);
* ======== testServiceCallback ========
* Application's callback function given to RM on service requests
*/
-Void testServiceCallback(Rm_ServiceRespInfo *serviceResponse)
+void testServiceCallback(Rm_ServiceRespInfo *serviceResponse)
+{
+ if (serviceResponse->serviceId == waitForBlockingOperation)
+ {
+ waitForBlockingOperation = 0;
+ responseInfo.resourceBase = serviceResponse->resourceBase;
+ responseInfo.resourceLength = serviceResponse->resourceLength;
+ responseInfo.serviceState = serviceResponse->serviceState;
+ }
+}
+
+bool blockForResponse(Rm_ServiceRespInfo *respInfo)
{
+ waitForBlockingOperation = respInfo->serviceId;
+ /* Block and wait for the response if the RM needed to perform a blocking operation
+ * to complete the request */
+ while(waitForBlockingOperation)
+ {
+ /* Yield to receive task to see if there are any packets for RM instance */
+ Task_yield();
+ }
+
+ if ((respInfo->serviceState != RM_SERVICE_PROCESSING) &&
+ (respInfo->serviceState != RM_SERVICE_APPROVED_AND_COMPLETED))
+ {
+ System_printf("Core %d: Service request encountered error or denial: %d\n", MultiProc_self(),
+ respInfo->serviceState);
+ return(FALSE);
+ }
+
+ return(TRUE);
+}
+
+/*
+ * ======== testRmTsk ========
+ * RM cleanup task
+ */
+void cleanupRmTsk(UArg arg0, UArg arg1)
+{
+ /* Delete the RM test task */
+ System_printf("Core %d: Deleting RM test task...\n", MultiProc_self());
+ if (testRmTskHandle)
+ {
+ Task_delete(&testRmTskHandle);
+ /* Set the task handle to be NULL so that the delete only occurs once */
+ testRmTskHandle = NULL;
+ }
+ /* Delete the RM receive task */
+ System_printf("Core %d: Deleting RM receive task...\n", MultiProc_self());
+ if (testReceiveTskHandle)
+ {
+ Task_delete(&testReceiveTskHandle);
+ /* Set the task handle to be NULL so that the delete only occurs once */
+ testReceiveTskHandle = NULL;
+ }
+
+
+
+ /* Cleanup all service ports, transport handles, RM instances, and IPC constructs */
+
+ BIOS_exit(0);
+}
+
+/*
+ * ======== testRmTsk ========
+ * RM test task
+ */
+void testReceiveTsk(UArg arg0, UArg arg1)
+{
+ int32_t retVal;
+
+ while(1)
+ {
+
+ /* Run the RM polling functions for each RM instance. */
+ if (MultiProc_self() == 0)
+ {
+ retVal = Rm_receivePktPolling(rmTransportMap[SERVER_TO_CD_MAP_ENTRY].transportHandle);
+ if (retVal != RM_TRANSPORT_SUCCESSFUL)
+ {
+ System_printf("Core %d: %s to %s transport receive error %d\n", MultiProc_self(),
+ rmServerName,
+ rmClientDelegateName,
+ retVal);
+ }
+ }
+ else if (MultiProc_self() == 1)
+ {
+ retVal = Rm_receivePktPolling(rmTransportMap[CD_TO_SERVER_MAP_ENTRY].transportHandle);
+ if (retVal != RM_TRANSPORT_SUCCESSFUL)
+ {
+ System_printf("Core %d: %s to %s transport receive error %d\n", MultiProc_self(),
+ rmClientDelegateName,
+ rmServerName,
+ retVal);
+ }
+
+ retVal = Rm_receivePktPolling(rmTransportMap[CD_TO_CLIENT_MAP_ENTRY].transportHandle);
+ if (retVal != RM_TRANSPORT_SUCCESSFUL)
+ {
+ System_printf("Core %d: %s to %s transport receive error %d\n", MultiProc_self(),
+ rmClientDelegateName,
+ rmClientName,
+ retVal);
+ }
+ retVal = Rm_receivePktPolling(rmTransportMap[CLIENT_TO_CD_MAP_ENTRY].transportHandle);
+ if (retVal != RM_TRANSPORT_SUCCESSFUL)
+ {
+ System_printf("Core %d: %s to %s transport receive error %d\n", MultiProc_self(),
+ rmClientName,
+ rmClientDelegateName,
+ retVal);
+ }
+ }
+
+ /* Yield for main test task */
+ Task_yield();
+ }
}
/*
* ======== testRmTsk ========
* RM test task
*/
-Void testRmTsk(UArg arg0, UArg arg1)
+void testRmTsk(UArg arg0, UArg arg1)
{
Rm_ServiceReqInfo requestInfo;
- Rm_ServiceRespInfo responseInfo;
+ Task_Params taskParams;
/* Delete the RM startup task */
System_printf("Core %d: Deleting RM startup task...\n", MultiProc_self());
memset((void *)&requestInfo, 0, sizeof(Rm_ServiceReqInfo));
memset((void *)&responseInfo, 0, sizeof(Rm_ServiceRespInfo));
+ System_printf("Core %d: Testing NameServer features...\n", MultiProc_self());
+
/* Use the service ports to test the service requests */
if (MultiProc_self() == 0)
{
- char resourceName[RM_RESOURCE_NAME_MAX_CHARS] = "hw_semaphore";
- char resourceNsName[RM_RESOURCE_NAME_MAX_CHARS] = "dsp_core_lock";
-
- /* TEMP: Try mapping a resource in Name Server */
+ char resourceName[RM_RESOURCE_NAME_MAX_CHARS] = "gp-queue";
+ char resourceNsName[RM_RESOURCE_NAME_MAX_CHARS] = "My_Favorite_Queue";
+
+ /* Issue the service request create a new NameServer object via the service port */
requestInfo.type = Rm_service_RESOURCE_MAP_TO_NAME;
- requestInfo.resourceName = &resourceName[0];
- requestInfo.resourceBase = 0;
- requestInfo.resourceRange = 1;
- requestInfo.resourceNsName = &resourceNsName[0];
+ requestInfo.resourceName = resourceName;
+ requestInfo.resourceBase = 1002;
+ requestInfo.resourceLength = 1;
+ requestInfo.resourceNsName = resourceNsName;
requestInfo.callback.serviceCallback = testServiceCallback;
- /* Issue the service request via the service port */
+ System_printf("Core %d: %s creating NameServer object...\n", MultiProc_self(), rmServerName);
rmServerServicePort->rmService(rmServerServicePort->rmHandle, &requestInfo, &responseInfo);
+ if (blockForResponse(&responseInfo))
+ {
+ System_printf("Core %d: %s created Name: %s base: %d length: %d\n", MultiProc_self(),
+ rmServerName,
+ resourceNsName,
+ requestInfo.resourceBase,
+ requestInfo.resourceLength);
+ }
+
+ /* Wait for Client Delegate and Client to retrieve resource via the name and allocate it */
+ waitOnSyncObj();
+
+ Rm_printResourceStatus(rmServerHandle);
+
}
else if (MultiProc_self() == 1)
- {
+ {
+ char resourceName[RM_RESOURCE_NAME_MAX_CHARS] = "gp-queue";
+ char resourceNsName[RM_RESOURCE_NAME_MAX_CHARS] = "My_Favorite_Queue";
+
+ /* Take the sync obj preparing for NameServer testing */
+ takeSyncObj();
+ /* Issue the service request for the resources tied to the name via the service port */
+ requestInfo.type = Rm_service_RESOURCE_GET_BY_NAME;
+ requestInfo.resourceNsName = &resourceNsName[0];
+ requestInfo.callback.serviceCallback = testServiceCallback;
+
+ System_printf("Core %d: %s getting NameServer object...\n", MultiProc_self(), rmClientDelegateName);
+ rmClientDelegateServicePort->rmService(rmClientDelegateServicePort->rmHandle, &requestInfo, &responseInfo);
+ if (blockForResponse(&responseInfo))
+ {
+ System_printf("Core %d: %s got Name: %s base: %d length: %d\n", MultiProc_self(),
+ rmClientDelegateName,
+ resourceNsName,
+ responseInfo.resourceBase,
+ responseInfo.resourceLength);
+ }
+
+ /* Allocate the resources via the service port from the Client */
+ requestInfo.type = Rm_service_RESOURCE_ALLOCATE;
+ requestInfo.resourceName = resourceName;
+ requestInfo.resourceBase = responseInfo.resourceBase;
+ requestInfo.resourceLength = responseInfo.resourceLength;
+ requestInfo.resourceNsName = NULL;
+ requestInfo.callback.serviceCallback = testServiceCallback;
+
+ System_printf("Core %d: %s allocating resources...\n", MultiProc_self(), rmClientName);
+ rmClientServicePort->rmService(rmClientServicePort->rmHandle, &requestInfo, &responseInfo);
+ if (blockForResponse(&responseInfo))
+ {
+ System_printf("Core %d: %s allocated resources: %s base: %d length: %d\n", MultiProc_self(),
+ rmClientName,
+ resourceNsName,
+ responseInfo.resourceBase,
+ responseInfo.resourceLength);
+ }
+
+ /* Release the syncObj so Server can move forward with NameServer object testing */
+ releaseSyncObj();
}
- System_printf("The test is complete\n");
- BIOS_exit(0);
+ System_printf("Core %d: Testing is complete\n", MultiProc_self());
+
+ /* Create the RM cleanup task. */
+ System_printf("Core %d: Creating RM cleanup task...\n", MultiProc_self());
+ Task_Params_init (&taskParams);
+ Task_create (cleanupRmTsk, &taskParams, NULL);
}
/*
/* Register the Client Delegate with the RM Server Instance */
rmTransportCfg.remoteInstType = Rm_instType_CLIENT_DELEGATE;
rmTransportCfg.remoteInstName = &rmClientDelegateName[0];
+ /* Set the callouts as valid for the first transport configuration on Server instance */
rmTransportCfg.transportCalloutsValid = true;
rmTransportCfg.transportCallouts.rmAllocPkt = TransportAlloc;
rmTransportCfg.transportCallouts.rmFreePkt = TransportFree;
/* Register the Server with the RM Client Delegate Instance */
rmTransportCfg.remoteInstType = Rm_instType_SERVER;
rmTransportCfg.remoteInstName = &rmServerName[0];
- /* Set the callouts as valid for the first transport configuration on this core */
+ /* Set the callouts as valid for the first transport configuration on Client Delegate instance */
rmTransportCfg.transportCalloutsValid = true;
rmTransportCfg.transportCallouts.rmAllocPkt = TransportAlloc;
rmTransportCfg.transportCallouts.rmFreePkt = TransportFree;
/* Register the Client with the RM Client Delegate Instance */
rmTransportCfg.remoteInstType = Rm_instType_CLIENT;
rmTransportCfg.remoteInstName = &rmClientName[0];
- /* Callouts already set so set them as invalid */
+ /* Callouts already set on the Client Delegate so set them as invalid */
rmTransportCfg.transportCalloutsValid = false;
cdClientHandle = Rm_transportRegister(rmClientDelegateHandle, &rmTransportCfg);
rmTransportMap[CD_TO_CLIENT_MAP_ENTRY].receiveMsgQ = cdClientMsgQ;
rmTransportMap[CD_TO_CLIENT_MAP_ENTRY].remoteMsgQId = cdClientQId;
System_printf("Core %d: Registered RM CD <=> RM Client transport with RM CD instance\n", MultiProc_self());
-
+
/* Open the Client Delegate messageQ from the Client */
do
{
/* Register the Client Delegate with the RM Client Instance */
rmTransportCfg.remoteInstType = Rm_instType_CLIENT_DELEGATE;
rmTransportCfg.remoteInstName = &rmClientDelegateName[0];
- /* Callouts already set so set them as invalid */
- rmTransportCfg.transportCalloutsValid = false;
+ /* Set the callouts as valid for the first transport configuration on Client instance */
+ rmTransportCfg.transportCalloutsValid = true;
+ rmTransportCfg.transportCallouts.rmAllocPkt = TransportAlloc;
+ rmTransportCfg.transportCallouts.rmFreePkt = TransportFree;
+ rmTransportCfg.transportCallouts.rmSend = TransportSend;
+ rmTransportCfg.transportCallouts.rmReceive = TransportReceive;
+ rmTransportCfg.transportCallouts.rmNumPktsReceived = TransportNumPktsReceived;
clientCdHandle = Rm_transportRegister(rmClientHandle, &rmTransportCfg);
rmTransportMap[CLIENT_TO_CD_MAP_ENTRY].remoteMsgQId = clientCdQId;
System_printf("Core %d: Registered RM Client <=> RM CD transport with RM Client instance\n", MultiProc_self());
}
+
+ /* Creat the RM receive task. */
+ System_printf("Core %d: Creating RM receive task...\n", MultiProc_self());
+ Task_Params_init (&taskParams);
+ testReceiveTskHandle = Task_create (testReceiveTsk, &taskParams, NULL);
+
/* Create the RM test task. */
System_printf("Core %d: Creating RM test task...\n", MultiProc_self());
Task_Params_init (&taskParams);
- Task_create (testRmTsk, &taskParams, NULL);
+ testRmTskHandle = Task_create (testRmTsk, &taskParams, NULL);
}
/*
{
Rm_InitCfg rmInitCfg;
Task_Params taskParams;
+ FILE *globalResourceFp;
+ FILE *linuxDtbFp;
+ FILE *globalPolicyFp;
+ Int globalResourceFileSize;
+ Int linuxDtbFileSize;
+ Int globalPolicyFileSize;
+ void *globalResourceList = NULL;
+ void *linuxDtb = NULL;
+ void *globalPolicy = NULL;
Int status;
+ Int readSize;
System_printf ("*********************************************************\n");
System_printf ("********************** RM Testing ***********************\n");
*/
if (MultiProc_self()== 0)
{
+ initSyncObj();
+
+ /* Open the Global Resource and Policy DTB files */
+ globalResourceFp = fopen("C:\\ti\\pdk_tci6614_1_0_0_11\\packages\\ti\\drv\\rm\\device\\tci6614-global-resources.dtb", "rb");
+ linuxDtbFp = fopen("C:\\ti\\pdk_tci6614_1_0_0_11\\packages\\ti\\drv\\rm\\device\\tci6614-linux-evm.dtb", "rb");
+ globalPolicyFp = fopen("C:\\ti\\pdk_tci6614_1_0_0_11\\packages\\ti\\drv\\rm\\device\\global-policy.dtb", "rb");
+
+ /* Get the size of the Global Resource List, Linux DTB, and Global Policy */
+ fseek(globalResourceFp, 0, SEEK_END);
+ globalResourceFileSize = ftell(globalResourceFp);
+ rewind(globalResourceFp);
+
+ fseek(linuxDtbFp, 0, SEEK_END);
+ linuxDtbFileSize = ftell(linuxDtbFp);
+ rewind(linuxDtbFp);
+
+ fseek(globalPolicyFp, 0, SEEK_END);
+ globalPolicyFileSize = ftell(globalPolicyFp);
+ rewind(globalPolicyFp);
+
+ /* Allocate buffers to hold the Global Resource List, Linux DTB, and Global Policy */
+ globalResourceList = Osal_rmMalloc(globalResourceFileSize);
+ linuxDtb = Osal_rmMalloc(linuxDtbFileSize);
+ globalPolicy = Osal_rmMalloc(globalPolicyFileSize);
+
+ /* Read the file data into the allocated buffers */
+ readSize = fread(globalResourceList, 1, globalResourceFileSize, globalResourceFp);
+ System_printf("Read Size compared to file size: %d : %d\n", readSize, globalResourceFileSize);
+ readSize = fread(linuxDtb, 1, linuxDtbFileSize, linuxDtbFp);
+ System_printf("Read Size compared to file size: %d : %d\n", readSize, linuxDtbFileSize);
+ readSize = fread(globalPolicy, 1, globalPolicyFileSize, globalPolicyFp);
+ System_printf("Read Size compared to file size: %d : %d\n", readSize, globalPolicyFileSize);
+
+ System_printf("Core %d: RM Server instance created\n", MultiProc_self());
+
/* Create the RM Server instance */
rmInitCfg.instName = &rmServerName[0];
rmInitCfg.instType = Rm_instType_SERVER;
- /* SET TO NULL - FEATURES NOT ADDED YET */
- rmInitCfg.globalResourceList = NULL;
- rmInitCfg.startupPolicy = NULL;
+ /* Provide the DTBs to the RM Server */
+ rmInitCfg.globalResourceList = globalResourceList;
+ rmInitCfg.linuxDtb = linuxDtb;
+ rmInitCfg.startupPolicy = globalPolicy;
/* Get the RM Server handle */
rmServerHandle = Rm_init(&rmInitCfg);
System_printf("Core %d: RM Server instance created\n", MultiProc_self());
+
+ // Rm_printResourceStatus(rmServerHandle);
}
else if (MultiProc_self()== 1)
{