Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

Concerto C28M35x How to pass data between cores with MessageQ?

$
0
0

Hello,

I use the following (on both C28 and M3):

ccs: 5.3.0.00090

xdc: 3.24.5.48

IPC:1.25.0.04

sys/bios: 6.34.2.18

I tried to modify the MessageQ example you get from "new project -> template -> concertoc28/ipc and io example/F28M35x examples/MessageQ" to pass two Integer along with the messages.

I ran into some strange behaviour, my biggest problem is this: I can get the MsgId on C28 side but not the correct MsgSize nor the data. (As a side note, if I change Int32 for int in the message structure, the whole program collapses at runtime, I suppose int is not the same size on both core?)

Since I could not easily get the debugger to put break point where I wanted and the code was not crashing, I put a lot of printf instead.

I have the impression that the data are transmitted but kind of loose coherence when viewed on c28 side. for example: i get the feeling that the second integer on c28 is the first on M3 and that the first on c28 is... bulls****.

Any help would be quite welcome!

thanks in advance

Laurent

ps: here are my code snippets: (.h file identical to both projects)

typedef struct{
    MessageQ_MsgHeader messageQ_MsgHeader;
    Int32 a0;
    Int32 a1;
} cmdMsgQ;

M3 code "settings":

// definition of variables
    cmdMsgQ* msg;
    //MessageQ_Msg msg;
    MessageQ_Handle  messageQ;
    MessageQ_QueueId remoteQueueId;    
    Int              status;
    UInt16           msgId = 0;
    Ptr              buf;
    HeapBuf_Handle   heapHandle;
    HeapBuf_Params   hbparams;
    SizeT            blockSize;
    UInt             numBlocks;

    //====================== setting the environment
    /* Compute the blockSize & numBlocks for the HeapBuf */
    numBlocks = 2;
    blockSize = sizeof(cmdMsgQ);

    /* Alloc a buffer from the default heap */
    buf = Memory_alloc(0, numBlocks * blockSize, 0, NULL);
    
    /*
     *  Create the heap that is used for allocating MessageQ messages.
     */     
    HeapBuf_Params_init(&hbparams);
    hbparams.align          = 0;
    hbparams.numBlocks      = numBlocks;
    hbparams.blockSize      = blockSize;
    hbparams.bufSize        = numBlocks * blockSize;
    hbparams.buf            = buf;
    heapHandle = HeapBuf_create(&hbparams, NULL);
    if (heapHandle == NULL) {
        System_abort("HeapBuf_create failed\n" );
    }
    
    /* Register default system heap with MessageQ */
    MessageQ_registerHeap((IHeap_Handle)(heapHandle), HEAPID);

    /* Create the local message queue */
    messageQ = MessageQ_create(localQueueName, NULL);    
    if (messageQ == NULL) {
        System_abort("MessageQ_create failed\n" );
    }
    
    /* Open the remote message queue. Spin until it is ready. */
    do {
        status = MessageQ_open(remoteQueueName, &remoteQueueId);
        /*
         *  Sleep for 1 clock tick to avoid inundating remote processor
         *  with interrupts if open failed
         */
        if (status < 0) {
            Task_sleep(1);
        }
    } while (status < 0);
    
    /* Allocate a message to be ping-ponged around the processors */
    msg = (cmdMsgQ*) MessageQ_alloc(HEAPID, sizeof(cmdMsgQ));
    if (msg == NULL) {
       System_abort("MessageQ_alloc failed\n" );
    }
    //====================== end of environment setting, ready to send and read messages:

    // now that the message is allocated, modify its intern data:
    msg->a0 = 0;
    msg->a1 = 11;

C28 code "settings":

//===============================  definition of variables
    cmdMsgQ* msg;
    // MessageQ_Msg msgB;
    MessageQ_Handle  messageQ;
    MessageQ_QueueId remoteQueueId;    
    Int              status;
    UInt16           msgId = 0;
    Ptr              buf;
    HeapBuf_Handle   heapHandle;
    HeapBuf_Params   hbparams;
    SizeT            blockSize;
    UInt             numBlocks;

    //===============================  setting of the environment
    /* Compute the blockSize & numBlocks for the HeapBuf */
    numBlocks = 2;
    blockSize = sizeof(cmdMsgQ);

    /* Alloc a buffer from the default heap */
    buf = Memory_alloc(0, numBlocks * blockSize, 0, NULL);
    
    /*
     *  Create the heap that is used for allocating MessageQ messages.
     */     
    HeapBuf_Params_init(&hbparams);
    hbparams.align          = 0;
    hbparams.numBlocks      = numBlocks;
    hbparams.blockSize      = blockSize;
    hbparams.bufSize        = numBlocks * blockSize;
    hbparams.buf            = buf;
    heapHandle = HeapBuf_create(&hbparams, NULL);
    if (heapHandle == NULL) {
        System_abort("HeapBuf_create failed\n" );
    }
    
    /* Register default system heap with MessageQ */
    MessageQ_registerHeap((IHeap_Handle)(heapHandle), HEAPID);

    /* Create the local message queue */
    messageQ = MessageQ_create(localQueueName, NULL);    
    if (messageQ == NULL) {
        System_abort("MessageQ_create failed\n" );
    }
    
    /* Open the remote message queue. Spin until it is ready. */
    do {
        status = MessageQ_open(remoteQueueName, &remoteQueueId);
        /*
         *  Sleep for 1 clock tick to avoid inundating remote processor
         *  with interrupts if open failed
         */
        if (status < 0) {
            Task_sleep(1);
        }
    } while (status < 0);
   

M3 code "ping-pong":

/*
     *  Send the message to the remote processor and wait for a message
     *  from the remote processor.
     */
    //System_printf("the length of the command message is : \n",sizeof(cmdMsgQ));
    System_printf("Start the main loop\n");
    while (msgId < NUMLOOPS) {
        /* Increment...the remote side will check this */
        msgId++;
        MessageQ_setMsgId(msg, msgId); //(MessageQ_Msg)
        msg->a0++;
        msg->a1--;

        System_printf("Sending message #%d to %s\n", msgId, remoteQueueName);
        /* send the message to the remote processor */
        status = MessageQ_put(remoteQueueId,  (MessageQ_Msg)msg);
        if (status < 0) {
           System_abort("MessageQ_put had a failure/error\n");
        }
        System_printf("[m3 speaking] M3 has sent the following data %d ; %d\n", msg->a0, msg->a1);
        System_printf("[m3 speaking] the message had the following length: %d \n", MessageQ_getMsgSize((MessageQ_Msg)msg));
        /* Get a message */
        status = MessageQ_get(messageQ, ((MessageQ_Msg*) &msg), MessageQ_FOREVER);//<== THIS DOES SEEM VERY STRANGE
        if (status < 0) {
           System_abort("This should not happen since timeout is forever\n");
        }
        System_printf("[m3 speaking] M3 has received the following data %d ; %d\n", msg->a0, msg->a1);
        System_printf("[m3 speaking] the message had the following length: %d \n", MessageQ_getMsgSize(msg));
    }

C28 code "ping-pong":

    System_printf("Start the main loop\n");
    while (TRUE) {
        /* Get a message */
        status = MessageQ_get(messageQ, ((MessageQ_Msg*) &msg), MessageQ_FOREVER); //<== THIS DOES SEEM VERY STRANGE

        if (status < 0) {
           System_abort("This should not happen since timeout is forever\n");
        }
        System_printf("[c28 speaking] C28 has received the following data: %d ; %d\n", msg->a0,
                                                           msg->a1);
        System_printf("[c28 speaking] the message had the following length: %d \n", MessageQ_getMsgSize(msg));
        System_printf("Sending a message #%d to %s\n", MessageQ_getMsgId(msg),
            remoteQueueName);



        /* Get the message id */
        msgId = MessageQ_getMsgId(msg);//(MessageQ_Msg)

        /* send the message to the remote processor */
        status = MessageQ_put(remoteQueueId, (MessageQ_Msg)msg);
        if (status < 0) {
           System_abort("MessageQ_put had a failure/error\n");
        }
        System_printf("[c28 speaking] C28 has sent the following data: %d ; %d\n", msg->a0,msg->a1);
        System_printf("[c28 speaking] the message had the following length: %d \n", MessageQ_getMsgSize(msg));
        /* test done */
        if (msgId >= NUMLOOPS) {
            break;
        }
    }

Console output:

[Cortex_M3_0] Start the main loop
Sending message #1 to C28_queue
[m3 speaking] M3 has sent the following data 1 ; 10
[m3 speaking] the message had the following length: 40
[C28xx_0] C28 speaking: local queue name is: C28_queueStart the main loop
[c28 speaking] C28 has received the following data: 0 ; 1
[c28 speaking] the message had the following length: 0
Sending a message #1 to M3_queue
[c28 speaking] C28 has sent the following data: 0 ; 1
[c28 speaking] the message had the following length: 0
[Cortex_M3_0] [m3 speaking] M3 has received the following data 1 ; 10
[m3 speaking] the message had the following length: 40
Sending message #2 to C28_queue
[m3 speaking] M3 has sent the following data 2 ; 9
[m3 speaking] the message had the following length: 40
[C28xx_0] [c28 speaking] C28 has received the following data: 0 ; 2
[c28 speaking] the message had the following length: 0
Sending a message #2 to M3_queue
[c28 speaking] C28 has sent the following data: 0 ; 2
[c28 speaking] the message had the following length: 0
[Cortex_M3_0] [m3 speaking] M3 has received the following data 2 ; 9
[m3 speaking] the message had the following length: 40
Sending message #3 to C28_queue
[m3 speaking] M3 has sent the following data 3 ; 8
[m3 speaking] the message had the following length: 40
[C28xx_0] [c28 speaking] C28 has received the following data: 0 ; 3
[c28 speaking] the message had the following length: 0
Sending a message #3 to M3_queue
[c28 speaking] C28 has sent the following data: 0 ; 3
[c28 speaking] the message had the following length: 0
[Cortex_M3_0] [m3 speaking] M3 has received the following data 3 ; 8
[m3 speaking] the message had the following length: 40
Sending message #4 to C28_queue
[m3 speaking] M3 has sent the following data 4 ; 7
[m3 speaking] the message had the following length: 40
[C28xx_0] [c28 speaking] C28 has received the following data: 0 ; 4
[c28 speaking] the message had the following length: 0
Sending a message #4 to M3_queue
[c28 speaking] C28 has sent the following data: 0 ; 4
[c28 speaking] the message had the following length: 0
[Cortex_M3_0] [m3 speaking] M3 has received the following data 4 ; 7
[m3 speaking] the message had the following length: 40
Sending message #5 to C28_queue
[m3 speaking] M3 has sent the following data 5 ; 6
[m3 speaking] the message had the following length: 40
[C28xx_0] [c28 speaking] C28 has received the following data: 0 ; 5
[c28 speaking] the message had the following length: 0
Sending a message #5 to M3_queue
[c28 speaking] C28 has sent the following data: 0 ; 5
[c28 speaking] the message had the following length: 0
[Cortex_M3_0] [m3 speaking] M3 has received the following data 5 ; 6
[m3 speaking] the message had the following length: 40
Sending message #6 to C28_queue
[m3 speaking] M3 has sent the following data 6 ; 5
[m3 speaking] the message had the following length: 40
[C28xx_0] [c28 speaking] C28 has received the following data: 0 ; 6
[c28 speaking] the message had the following length: 0
Sending a message #6 to M3_queue
[c28 speaking] C28 has sent the following data: 0 ; 6
[c28 speaking] the message had the following length: 0
[Cortex_M3_0] [m3 speaking] M3 has received the following data 6 ; 5
[m3 speaking] the message had the following length: 40
Sending message #7 to C28_queue
[m3 speaking] M3 has sent the following data 7 ; 4
[m3 speaking] the message had the following length: 40
[C28xx_0] [c28 speaking] C28 has received the following data: 0 ; 7
[c28 speaking] the message had the following length: 0
Sending a message #7 to M3_queue
[c28 speaking] C28 has sent the following data: 0 ; 7
[c28 speaking] the message had the following length: 0
[Cortex_M3_0] [m3 speaking] M3 has received the following data 7 ; 4
[m3 speaking] the message had the following length: 40
Sending message #8 to C28_queue
[m3 speaking] M3 has sent the following data 8 ; 3
[m3 speaking] the message had the following length: 40
[C28xx_0] [c28 speaking] C28 has received the following data: 0 ; 8
[c28 speaking] the message had the following length: 0
Sending a message #8 to M3_queue
[c28 speaking] C28 has sent the following data: 0 ; 8
[c28 speaking] the message had the following length: 0
[Cortex_M3_0] [m3 speaking] M3 has received the following data 8 ; 3
[m3 speaking] the message had the following length: 40
Sending message #9 to C28_queue
[m3 speaking] M3 has sent the following data 9 ; 2
[m3 speaking] the message had the following length: 40
[C28xx_0] [c28 speaking] C28 has received the following data: 0 ; 9
[c28 speaking] the message had the following length: 0
Sending a message #9 to M3_queue
[c28 speaking] C28 has sent the following data: 0 ; 9
[c28 speaking] the message had the following length: 0
[Cortex_M3_0] [m3 speaking] M3 has received the following data 9 ; 2
[m3 speaking] the message had the following length: 40
Sending message #10 to C28_queue
[m3 speaking] M3 has sent the following data 10 ; 1
[m3 speaking] the message had the following length: 40
[C28xx_0] [c28 speaking] C28 has received the following data: 0 ; 10
[c28 speaking] the message had the following length: 0
Sending a message #10 to M3_queue
[c28 speaking] C28 has sent the following data: 0 ; 10
[c28 speaking] the message had the following length: 0
The test is complete
[Cortex_M3_0] [m3 speaking] M3 has received the following data 10 ; 1
[m3 speaking] the message had the following length: 40
The test is complete

Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>