/* * ======== MSGQ_locateAsync ======== * Get a reference to an existing message queue via its name * This is an asynchronous function. */ Int MSGQ_locateAsync(String queueName, MSGQ_Queue replyQueue, MSGQ_LocateAsyncAttrs *locateAsyncAttrs) { Uint16 i; Int status; MSGQ_TransportHandle mqtHandle; MSGQ_AsyncLocateMsg *msg; MSGQ_Queue tempQueue; /* assert(queueName != NULL); */ /* assert(replyQueue != MSGQ_INVALIDMSGQ); */ if (locateAsyncAttrs == NULL) { locateAsyncAttrs = (MSGQ_LocateAsyncAttrs *)&MSGQ_LOCATEASYNCATTRS; } /* Check the local message queue's first. */ status = MSGQ_locateLocal(queueName, &tempQueue); /* * There are 2 different variations: * 1. Asynchronous locate and message queue found * Action: Send the message and return success. * * 2. Asynchronous locate and message queue not found * Action: continue and search the remote transports. */ if (status == SYS_OK) { /* * The asynchronous case. * * Allocate the locator message from the allocator * specified in the locateAsyncAttrs. */ status = MSGQ_alloc(locateAsyncAttrs->poolId, (MSGQ_Msg *)&msg, sizeof(MSGQ_AsyncLocateMsg)); if (status != SYS_OK) { return (SYS_EALLOC); } /* Fill in the field of the message. */ msg->msgqQueue = tempQueue; msg->arg = locateAsyncAttrs->arg; MSGQ_setMsgId((MSGQ_Msg)msg, MSGQ_ASYNCLOCATEMSGID); status = MSGQ_put(replyQueue, (MSGQ_Msg)msg); if (status != SYS_OK) { /* * Sending the message failed. Free the message * and return the failure back. */ MSGQ_free((MSGQ_Msg)msg); } return (status); } /* * Loop through all the transports and see if a transport * can locate the message queue. */ for (i = 0; i < MSGQ->numProcessors; i++) { mqtHandle = &(MSGQ->transports[i]); /* * Do not try the local processor (which should have * mqtHandle->fxns == NULL!) and any transport that * has no interface functions. */ if (i == GBL_getProcId() || mqtHandle->fxns == NULL) { continue; } /* * Since the locate is async, the transport will * - return SYS_OK if async locate was initiated. * In this case, continue searching * - return a failure code if async located could not be initiated. * In this case, continue searching...It is up to the transport * to send an error message. */ mqtHandle->fxns->locate(mqtHandle, queueName, FALSE, &replyQueue, (Ptr)locateAsyncAttrs); } /* At this point of an async locate, just return. */ return (SYS_OK); }
/** ============================================================================ * @func helloDSP_Execute * * @desc This function implements the execute phase for this application. * * @modif None * ============================================================================ */ NORMAL_API DSP_STATUS helloDSP_Execute(IN Uint32 numIterations, Uint8 processorId) { DSP_STATUS status = DSP_SOK; Uint16 sequenceNumber = 0; Uint16 msgId = 0; Uint8 i,j,k, count; ControlMsg *msg; Uint16 A[SIZE][SIZE], B[SIZE][SIZE]; Uint8 step_select; step_select = SIZE % 2; SYSTEM_0Print("Entered helloDSP_Execute ()\n"); //Create Matrix for (j = 0; j < SIZE; j++) { for (k = 0; k < SIZE; k++) { A[j][k] = 1; B[j][k] = 2; } } #if defined (PROFILE) SYSTEM_GetStartTime(); #endif status = MSGQ_get(SampleGppMsgq, WAIT_FOREVER, (MsgqMsg *) &msg); if (DSP_FAILED(status)) { SYSTEM_1Print("MSGQ_get () failed. Status = [0x%x]\n", status); } #if defined (VERIFY_DATA) /* Verify correctness of data received. */ if (DSP_SUCCEEDED(status)) { status = helloDSP_VerifyData(msg, sequenceNumber); if (DSP_FAILED(status)) { MSGQ_free((MsgqMsg) msg); } } #endif SYSTEM_1Print("Message received: %s\n", (Uint32) msg->arg1); for (i = 1 ; ((numIterations == 0) || (i < (numIterations + 1))) && (DSP_SUCCEEDED (status)); i++) { count = 0; while(count < 2) { /* If the message received is the final one, free it. */ if ((numIterations != 0) && (i == (numIterations + 1))) { MSGQ_free((MsgqMsg) msg); } else { if(count == 0) { msg->row = SIZE/2; msg->col = SIZE; for (j = 0; j < SIZE/2; j++) { for (k = 0; k < SIZE; k++) { msg->mat[j+SIZE/2 + step_select][k] = A[j+ SIZE/2 + step_select][k]; } } } if(count == 1) { msg->row = SIZE; msg->col = SIZE; for (j = 0; j < SIZE; j++) { for (k = 0; k < SIZE; k++) { msg->mat[j][k] = B[j][k]; } } } /* Send the same message received in earlier MSGQ_get () call. */ if (DSP_SUCCEEDED(status)) { msgId = MSGQ_getMsgId(msg); MSGQ_setMsgId(msg, msgId); status = MSGQ_put(SampleDspMsgq, (MsgqMsg) msg); if (DSP_FAILED(status)) { MSGQ_free((MsgqMsg) msg); SYSTEM_1Print("MSGQ_put () failed. Status = [0x%x]\n", status); } } sequenceNumber++; /* Make sure that the sequenceNumber stays within the permitted * range for applications. */ if (sequenceNumber == MSGQ_INTERNALIDSSTART) { sequenceNumber = 0; } #if !defined (PROFILE) if (DSP_SUCCEEDED(status) && ((i % 100) == 0)) { SYSTEM_1Print("Transferred %ld messages\n", i); } #endif /* Receive the message. */ status = MSGQ_get(SampleGppMsgq, WAIT_FOREVER, (MsgqMsg *) &msg); if (DSP_FAILED(status)) { SYSTEM_1Print("MSGQ_get () failed. Status = [0x%x]\n", status); } #if defined (VERIFY_DATA) /* Verify correctness of data received. */ if (DSP_SUCCEEDED(status)) { status = helloDSP_VerifyData(msg, sequenceNumber); if (DSP_FAILED(status)) { MSGQ_free((MsgqMsg) msg); } } #endif if (msg->command == 0x02) { SYSTEM_1Print("Message received: %s\n", (Uint32) msg->arg1); if(count == 1) { for (j = 0; j < SIZE/2; j++) { for (k = 0; k < SIZE; k++) { printf("%d ", msg->mat[j+SIZE/2+step_select][k]); } printf("\n"); } } //printf("SIZE %d\n", SIZE); } } printf("%d\n", count); count++; }//while ends } #if defined (PROFILE) if (DSP_SUCCEEDED(status)) { SYSTEM_GetEndTime(); SYSTEM_GetProfileInfo(numIterations); } #endif SYSTEM_0Print("Leaving helloDSP_Execute ()\n"); return status; }
/** ============================================================================ * @func helloDSP_Execute * * @desc This function implements the execute phase for this application. * * @modif None * ============================================================================ */ NORMAL_API DSP_STATUS helloDSP_Execute(IN Uint32 numIterations, Uint8 processorId) { DSP_STATUS status = DSP_SOK; Uint16 sequenceNumber = 0; Uint16 msgId = 0; Uint32 i; ControlMsg *msg; SYSTEM_0Print("Entered helloDSP_Execute ()\n"); #if defined (PROFILE) SYSTEM_GetStartTime(); #endif for (i = 1 ; ((numIterations == 0) || (i <= (numIterations + 1))) && (DSP_SUCCEEDED (status)); i++) { /* Receive the message. */ status = MSGQ_get(SampleGppMsgq, WAIT_FOREVER, (MsgqMsg *) &msg); if (DSP_FAILED(status)) { SYSTEM_1Print("MSGQ_get () failed. Status = [0x%x]\n", status); } #if defined (VERIFY_DATA) /* Verify correctness of data received. */ if (DSP_SUCCEEDED(status)) { status = helloDSP_VerifyData(msg, sequenceNumber); if (DSP_FAILED(status)) { MSGQ_free((MsgqMsg) msg); } } #endif if (msg->command == 0x01) SYSTEM_1Print("Message received: %s\n", (Uint32) msg->arg1); else if (msg->command == 0x02) SYSTEM_1Print("Message received: %s\n", (Uint32) msg->arg1); /* If the message received is the final one, free it. */ if ((numIterations != 0) && (i == (numIterations + 1))) { MSGQ_free((MsgqMsg) msg); } else { /* Send the same message received in earlier MSGQ_get () call. */ if (DSP_SUCCEEDED(status)) { msgId = MSGQ_getMsgId(msg); MSGQ_setMsgId(msg, msgId); status = MSGQ_put(SampleDspMsgq, (MsgqMsg) msg); if (DSP_FAILED(status)) { MSGQ_free((MsgqMsg) msg); SYSTEM_1Print("MSGQ_put () failed. Status = [0x%x]\n", status); } } sequenceNumber++; /* Make sure that the sequenceNumber stays within the permitted * range for applications. */ if (sequenceNumber == MSGQ_INTERNALIDSSTART) { sequenceNumber = 0; } #if !defined (PROFILE) if (DSP_SUCCEEDED(status) && ((i % 100) == 0)) { SYSTEM_1Print("Transferred %ld messages\n", i); } #endif } } #if defined (PROFILE) if (DSP_SUCCEEDED(status)) { SYSTEM_GetEndTime(); SYSTEM_GetProfileInfo(numIterations); } #endif SYSTEM_0Print("Leaving helloDSP_Execute ()\n"); return status; }
// WARNING mxSize is the matrixSize here NORMAL_API DSP_STATUS helloDSP_Execute(IN Uint32 mxSize, Uint8 processorId, Uint32* matrixA, Uint32* matrixB, Uint32* matrixC) { DSP_STATUS status = DSP_SOK; Uint16 sequenceNumber = 0; Uint16 msgId = 0; Uint32 i, j; ControlMsg *msg; Uint8 flag = 0; Uint32 matrixD[mxSize * mxSize]; Uint32 numElements, numMessages, elementCount, messageCount; Uint32 sizeElements, numProdMessages, matrixCount, prodElements; Char8 ascii_string[STRING_SIZE + 1]; Char8 null_string[STRING_SIZE + 1] = {'\0','\0','\0','\0','\0','\0'}; myStrcpy(ascii_string, null_string); SYSTEM_0Print("Entered helloDSP_Execute ()\n"); // Wait for the first DSP is awake message status = MSGQ_get(SampleGppMsgq, WAIT_FOREVER, (MsgqMsg *) &msg); if (DSP_FAILED(status)) { SYSTEM_1Print("MSGQ_get () failed. Status = [0x%x]\n", status); } // TODO possibly verify the data? SYSTEM_1Print("Received message: %s\n", (Uint32) msg->arg1); SYSTEM_0Print("Generated matrices:\n"); // Generate the matrices after the DSPLink is established matrixGen(mxSize, matrixA, matrixB); // Have to translate the Int32 matrix elements to string elements // or the communication protocol prodElements = (mxSize * mxSize); numElements = (mxSize * mxSize * 2); sizeElements = numElements * STRING_SIZE; numMessages = ((sizeElements - 1) / ARG_MSG) + 1; numProdMessages = (((sizeElements / 2) - 1) / ARG_MSG) + 1; //SYSTEM_2Print("NumElements: %d, NumMessages: %d\n", numElements, numMessages); // WARNING Sending 5 Char8 each for loop // Start sending the matrices to the DSP which is not waiting for (messageCount = 0, elementCount = 0; messageCount < numMessages; messageCount++) { // First send a message, then receive //for ( ; (((elementCount - (messageCount * ARG_MSG)) * STRING_SIZE) < ARG_MSG ) && elementCount < numElements; elementCount++) #if defined (PROFILE) SYSTEM_GetStartTimeDspEnc(); #endif for (; (elementCount - (messageCount * ARG_MSG)) < ARG_MSG && elementCount < numElements; elementCount++) { //SYSTEM_0Print("Putting element in a message\n"); //itoa if(elementCount < prodElements) { SYSTEM_itoa(matrixA[elementCount], ascii_string, 10); //SYSTEM_1Print("Looping through string: %s in MatrixA\n", (Uint32) ascii_string); } else { SYSTEM_itoa(matrixB[elementCount - prodElements], ascii_string, 10); //SYSTEM_1Print("Looping through string: %s in MatrixB\n", (Uint32) ascii_string); } //SYSTEM_0Print("After SYSTEM_itoa\n"); // loop through characters of the string for (i = 0; i < STRING_SIZE; i++) { msg->arg1[((elementCount * STRING_SIZE) - (messageCount * ARG_MSG)) + i] = ascii_string[i]; //SYSTEM_sprintf(msg->arg1[(elementCount - (messageCount * ARG_MSG)) + i] = ascii_string[i]; } // clean the string myStrcpy(ascii_string, null_string); } #if defined (PROFILE) SYSTEM_GetEndTimeDspEnc(); #endif //SYSTEM_0Print("Filled a single message\n"); // After filling a single message, should send it to the DSP and wait for a reply // unless it is the last one if (DSP_SUCCEEDED(status)) { //SYSTEM_0Print("DSP succeeded after filling\n"); #if defined (PROFILE) SYSTEM_GetStartTimeDspMes(); #endif msgId = MSGQ_getMsgId(msg); MSGQ_setMsgId(msg, msgId); // TODO set the command flag of the msg to distinguish status = MSGQ_put(SampleDspMsgq, (MsgqMsg) msg); if (DSP_FAILED(status)) { MSGQ_free((MsgqMsg) msg); SYSTEM_1Print("MSGQ_put () failed. Status = [0x%x]\n", status); } #if defined (PROFILE) else { SYSTEM_GetEndTimeDspMes(); SYSTEM_GetStartTimeDspCalc(); } #endif } //SYSTEM_0Print("Message send\n"); sequenceNumber++; // Make sure that the sequenceNumber stays within the permitted // range for applications. if (sequenceNumber == MSGQ_INTERNALIDSSTART) { //SYSTEM_0Print("Something with sequences\n"); sequenceNumber = 0; } // If it is the last message, don't wait for an acknowledge if (messageCount + 1 < numMessages) { // Wait for a response of the DSP before sending a reply status = MSGQ_get(SampleGppMsgq, WAIT_FOREVER, (MsgqMsg *) &msg); if (DSP_FAILED(status)) { SYSTEM_1Print("MSGQ_get () failed. Status = [0x%x]\n", status); } //SYSTEM_1Print("Received: %s\n", (Uint32) msg->arg1); } } //SYSTEM_0Print("Sending completed..\n"); // TODO start receiving the product matrix // WARNING wait and acknowledge except for last loop for (messageCount = 0, elementCount = 0, matrixCount = 0; messageCount < numProdMessages; messageCount++) { status = MSGQ_get(SampleGppMsgq, WAIT_FOREVER, (MsgqMsg *) &msg); if (messageCount == 0) { #if defined (PROFILE) SYSTEM_GetEndTimeDspCalc(); #endif SYSTEM_0Print("\nProduct matrix on DSP:\n"); } //SYSTEM_1Print("Message received: %s\n", (Uint32) msg->arg1); if (DSP_FAILED(status)) { SYSTEM_1Print("MSGQ_get () failed. Status = [0x%x]\n", status); } // Put the received message in the matrixC for (; matrixCount < prodElements && (elementCount - (messageCount * ARG_MSG)) < ARG_MSG && elementCount < (prodElements * STRING_SIZE); matrixCount++, elementCount += STRING_SIZE) { // atoi for (i = 0; i < STRING_SIZE; i++) { ascii_string[i] = msg->arg1[elementCount + i]; } ascii_string[5] = '\0'; /* if (matrixCount >= 72) { SYSTEM_1Print("Ascii string received: %s\n", ascii_string); } */ // Put it in the matrixC matrixC[matrixCount] = atoi(ascii_string); // print the string if (matrixCount % mxSize == 0) { SYSTEM_0Print("\n"); } SYSTEM_1Print("%d ", matrixC[matrixCount]); // Clean the string myStrcpy(ascii_string, null_string); } // If this is not the last message, send an acknowledge if (messageCount + 1 < numProdMessages) { // Send the same message received in earlier MSGQ_get () call. if (DSP_SUCCEEDED(status)) { msgId = MSGQ_getMsgId(msg); MSGQ_setMsgId(msg, msgId); status = MSGQ_put(SampleDspMsgq, (MsgqMsg) msg); if (DSP_FAILED(status)) { MSGQ_free((MsgqMsg) msg); SYSTEM_1Print("MSGQ_put () failed. Status = [0x%x]\n", status); } } sequenceNumber++; // Make sure that the sequenceNumber stays within the permitted // range for applications. if (sequenceNumber == MSGQ_INTERNALIDSSTART) { sequenceNumber = 0; } } } SYSTEM_0Print("\n"); MSGQ_free((MsgqMsg) msg); //SYSTEM_0Print("After freeing the message..\n"); SYSTEM_0Print("\nProduct matrix on GPP:\n"); #if defined (PROFILE) SYSTEM_GetStartTimeGpp(); #endif matMult(matrixA, matrixB, matrixD, mxSize); #if defined (PROFILE) SYSTEM_GetEndTimeGpp(); #endif // compare the matrices for(i=0; i<mxSize; i++) { for(j=0; j<mxSize; j++) { if(matrixC[i * mxSize + j] != matrixD[i * mxSize + j]) { SYSTEM_2Print("Matrices are not equal row: %d, column: %d\n", i, j); flag = 1; break; } } } if (flag == 0) { SYSTEM_0Print("\nMatrix products are equal\n"); } SYSTEM_0Print("Leaving helloDSP_Execute ()\n"); #if defined (PROFILE) if (DSP_SUCCEEDED(status)) { SYSTEM_GetProfileInfoGpp(); SYSTEM_GetProfileInfoDsp(numMessages); //is numProdMessages interesting? } #endif return status; }