AnsweredAssumed Answered

problem with mcc_recv_nocopy

Question asked by Christian Edhofer on Jul 22, 2014
Latest reply on Aug 5, 2014 by Timesys Support

Hi,

 

I'm working with the PHYTEC Cosmic+ Board and I just want to send data from the A5 core to the M4 core and vice versa. Additionally, I would like to save the message from the M4 core to a textfile.

With the function "mcc_recv_copy" everything works fine, but when I'm trying to use "mcc_recv_nocopy" it doesn't.

 

This is what I've got for the A5 core:

 

int main()

{

    int             ret_value;        // Variable ob Funktionen richtig ausgeführt wurden

    int             u = 0;            // Zählvariable

    float             senddata = 1.2345;        // Sendenachricht

    void*            recv_buffer_ptr;

    void*            app_buffer_ptr[255];

 

    // Endpoint-Definition

    MCC_ENDPOINT    linux_endpoint_a5 = {0,0,1};

    MCC_ENDPOINT    mqx_endpoint_m4 = {1,0,2};

 

    MCC_MEM_SIZE    num_available_msgs;

    MCC_MEM_SIZE    num_of_received_bytes;

 

    printf("Hello, I'm A5.\n");

 

    // MCC-Init

    ret_value = mcc_initialize(MCC_MQX_NODE_A5);

    if(0==ret_value)printf("MCCinit check\n");

    else printf("MCCinit fail\n\n");

 

    // Endpoint-Create

    ret_value = mcc_create_endpoint(&linux_endpoint_a5, 1);

    if(0==ret_value)printf("endpoint create check\n");

    else printf("create fail\n\n");

 

    // Textdatei fuer Zugriff oeffnen

    txt = fopen("mcc_float_nocopy.txt", "a+");    // oeffnet txt

        if (txt == NULL)                        // ueberprueft ob txt geoeffnet werden kann

        {

            printf("Fehler beim Oeffnen der Datei.");

            return 1;

        }

 

    while(u<10)                                // 10 x

        {

 

            // send msg to M4

            ret_value = mcc_send(&mqx_endpoint_m4, &senddata, sizeof(senddata)+1, 0xFFFFFF);

            if(0==ret_value)printf("send check\n");

            else printf("send fail\n\n");

 

            // wait for msg

            mcc_msgs_available(&linux_endpoint_a5, &num_available_msgs);

                while(num_available_msgs==0)

                {

                    mcc_msgs_available(&linux_endpoint_a5, &num_available_msgs);

                }

 

            // get msg

            ret_value = mcc_recv_nocopy(&linux_endpoint_a5, (void**)&recv_buffer_ptr, &num_of_received_bytes, 0xFFFFFF);

            if(0==ret_value)printf("receive check\n");

            else printf("receive fail\n\n");

 

            // copy msg

            memcpy((void*)app_buffer_ptr, (void*)recv_buffer_ptr, num_of_received_bytes);

            printf("%f\n", *((float*)app_buffer_ptr));

 

            // free buffer

            ret_value = mcc_free_buffer(recv_buffer_ptr);

            if(0==ret_value)printf("free check\n");

            else printf("free fail\n\n");

 

            // Zeit + Nachricht von M4 in Textdatei schreiben

            fprintf(txt, "%f\n", *((float*)app_buffer_ptr));

 

            u++;

        }

 

        fclose(txt);

        printf("Finish!!\n");

        return 0;

    }

 

 

And this for the M4 core:

 

void main_task(uint_32 node_num)

{

    int         ret_value;

    float        senddata = 1.2345;

    void*        recv_buffer_ptr;

    void*        app_buffer_ptr[255];

 

 

    MCC_MEM_SIZE    num_available_msgs;

    MCC_MEM_SIZE    num_of_received_bytes;

 

    printf("Hello, I'm M4!\n\n");

 

    // MCC Init & Endpoint Init

    ret_value = mcc_initialize(MCC_MQX_NODE_M4);

    if(0==ret_value)printf("MCCinit check\n");

    else printf("MCCinit fail\n\n");

 

    ret_value = mcc_create_endpoint(&mqx_endpoint_m4, 2);

    if(0==ret_value)printf("endpoint create check\n");

    else printf("create fail\n\n");

 

    while(1)

    {

        // wait for msg

    mcc_msgs_available(&mqx_endpoint_m4, &num_available_msgs);

        while(num_available_msgs==0)

        {

            mcc_msgs_available(&mqx_endpoint_m4, &num_available_msgs);

        }

       

    // get msg

    ret_value = mcc_recv_nocopy(&mqx_endpoint_m4, (void**)&recv_buffer_ptr, &num_of_received_bytes, 5000000);

    if(0==ret_value)printf("receive check\n");

    else printf("receive fail\n\n");

 

    // copy msg

    memcpy((void*)app_buffer_ptr, (void*)recv_buffer_ptr, num_of_received_bytes);

    printf("%f\n", *((float*)app_buffer_ptr));

 

    // free buffer

    ret_value = mcc_free_buffer(recv_buffer_ptr);

    if(0==ret_value)printf("free check\n");

    else printf("free fail\n\n");

 

    // send msg to A5

    ret_value = mcc_send(&linux_endpoint_a5, &senddata, sizeof(senddata)+1, 5000000);

    if(0==ret_value)printf("send check\n");

    else printf("send fail\n\n");

    }

}

 

I can free the buffer on the A5, but it doesn't free the buffer on the M4. And the message from the M4 doesn't get saved to the textfile.

Did I use the function "mcc_recv_nocopy" correct?

 

Best regards,

Christian

Outcomes