Exemplo n.º 1
0
    /** ============================================================================
     *  @func   helloDSP_VerifyData
     *
     *  @desc   This function verifies the data-integrity of given buffer.
     *
     *  @modif  None
     *  ============================================================================
     */
    STATIC NORMAL_API DSP_STATUS helloDSP_VerifyData(IN MSGQ_Msg msg, IN Uint16 sequenceNumber)
    {
        DSP_STATUS status = DSP_SOK;
        Uint16 msgId;

        /* Verify the message */
        msgId = MSGQ_getMsgId(msg.header);
        if (msgId != sequenceNumber)
        {
            status = DSP_EFAIL;
            SYSTEM_0Print("ERROR! Data integrity check failed\n");
        }

        return status;
    }
Exemplo n.º 2
0
    /** ============================================================================
     *  @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;
    }
Exemplo n.º 3
0
    /** ============================================================================
     *  @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;
    }
Exemplo n.º 4
0
// 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;
}