This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MessageQ传递的信息到底在哪个变量里?



还是想做核间的数据传递,Semaphore 不能核间传递,Notify应该可以,但是写的程序就是传递不起来,现在在看MessageQ,IPC自带的例子C:\ti\ipc_3_50_04_08\examples\C6678_bios_elf\ex11_ping里文件太多,看着头大,看了2天也没理出到底传递的是啥信息。

通读software-dl.ti.com/processor-sdk-rtos/esd/docs/06_03_00_106/AM437X/rtos/index_Foundational_Components.html#messageq-module里的4.4.6.3 MessageQ Module 后有一个 疑问,这章讲了如何创建,打开,分配内存,存放信息,读取信息,释放内存,可是我翻来翻去也没找到到底信息在哪里? 

整理一下

1.接收方 创建:
MessageQ_Handle   messageQ;
MessageQ_Params   messageQParams;
SyncSem_Handle    syncSemHandle;
syncSemHandle = SyncSem_create(NULL, NULL);
MessageQ_Params_init(&messageQParams);
messageQParams.synchronizer = SyncSem_Handle_upCast(syncSemHandle);
messageQ = MessageQ_create(CORE0_MESSAGEQNAME, &messageQParams);



2.发送方 打开:
do {
   status = MessageQ_open(CORE0_MESSAGEQNAME, &remoteQueueId);
}
while (status < 0);

3.发送方 注册一个Heap:
status = MessageQ_registerHeap( HeapBufMP_Handle_upCast(heapHandle), HEAPID);

4.发送方 分配内存:
msg = MessageQ_alloc(HEAPID, sizeof(MessageQ_MsgHeader)); if (msg == NULL) { System_abort("MessageQ_alloc failed\n"); }

5.发送方写入信息:
status = MessageQ_put(remoteQueueId, msg);

6.接收方 读取信息:
status = MessageQ_get(messageQ, &msg, MessageQ_FOREVER);
if (status < 0) {
     System_abort("Should not happen; timeout is forever\n");
}

7.后续操作,至少到这里没有看到哪里表示 信息 在哪里,比如我要传递一个 123456给 接收方,我这信息往哪里装啊?

只看到一个结构体:

typedef struct MyMsg {
    MessageQ_MsgHeader header;     // Required
    SomeEnumType       type        // Can be any field
    ...                            // ...
} MyMsg;

这个结构体 在讲解中也没有使用啊?那么到底传递的什么啊?这个结构体怎么用呢?我传递了半天传递了个寂寞?

这是一个小白的问题,但是确实不理解信息到底放在哪里了。

  • 应该就是是通过MyMsg这个结构体传递的,下面的部分代码截取自其他型号的ex02_messageq例程,可以参考试一下:

    /* notify commands 00 - FF */
    #define App_CMD_MASK 0xFF000000
    #define App_CMD_NOP 0x00000000 /* cc------ */
    #define App_CMD_SHUTDOWN 0x02000000 /* cc------ */


    typedef struct {
    MessageQ_MsgHeader reserved;
    UInt32 cmd;
    } App_Msg;

    Int App_exec(Void)
    {
    Int status;
    Int i;
    App_Msg * msg;

    printf("--> App_exec:\n");

    /* fill process pipeline */
    for (i = 1; i <= 3; i++) {
    printf("App_exec: sending message %d\n", i);

    /* allocate message */
    msg = (App_Msg *)MessageQ_alloc(Module.heapId, Module.msgSize);

    if (msg == NULL) {
    status = -1;
    goto leave;
    }

    /* set the return address in the message header */
    MessageQ_setReplyQueue(Module.hostQue, (MessageQ_Msg)msg);

    /* fill in message payload */
    msg->cmd = App_CMD_NOP;

    /* send message */
    MessageQ_put(Module.slaveQue, (MessageQ_Msg)msg);
    }

    Int Server_exec()
    {
    Int status;
    Bool running = TRUE;
    App_Msg * msg;
    MessageQ_QueueId queId;

    Log_print0(Diags_ENTRY | Diags_INFO, "--> Server_exec:");

    while (running) {

    /* wait for inbound message */
    status = MessageQ_get(Module.slaveQue, (MessageQ_Msg *)&msg,
    MessageQ_FOREVER);

    if (status < 0) {
    goto leave;
    }

    if (msg->cmd == App_CMD_SHUTDOWN) {
    running = FALSE;
    }

    /* process the message */
    Log_print1(Diags_INFO, "Server_exec: processed cmd=0x%x", msg->cmd);

    /* send message back */
    queId = MessageQ_getReplyQueue(msg); /* type-cast not needed */
    MessageQ_put(queId, (MessageQ_Msg)msg);
    } /* while (running) */

    这个帖子也可以参考看一下。

    e2e.ti.com/.../2730346

     

  • Nancy,
    Thanks.虽然例子没看懂,但是至少知道了信息是存放在结构体里的,你给的代码里用App_Msg * msg 定义了msg,然后给msg里存入信息
    0x00000000(App_CMD_NOP) ,然后将该信息put,至于put里的Module.slaveQue是啥暂时还不明白,先自己写个代码在板上跑跑试试了,再次感谢。