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.

TMS320C6678: IPC 实现主核和 从核 notify出错

Part Number: TMS320C6678
Other Parts Discussed in Thread: SYSBIOS

console 输出为:[C66xx_1] Ipc_start successfully
[C66xx_2] Ipc_start successfully
[C66xx_0] Ipc_start successfully
[C66xx_1] Notify_registerEvent for masterCore0 successfully
[C66xx_2] Notify_registerEvent for masterCore0 successfully
[C66xx_1] ti.sysbios.gates.GateMutex: line 99: assertion failure: A_badContext: bad calling context. See GateMutex API doc for details.
[C66xx_2] ti.sysbios.gates.GateMutex: line 99: assertion failure: A_badContext: bad calling context. See GateMutex API doc for details.
[C66xx_1] xdc.runtime.Error.raise: terminating execution
[C66xx_2] xdc.runtime.Error.raise: terminating execution

代码:

/*
 * Copyright (c) 2012, Texas Instruments Incorporated
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * */
/*
 *  ======== notify_multicore.c ========
 *  Single-image version of Notify example
 *
 *  See notify_multicore.k file for expected output.
 */

#include <xdc/std.h>

/*  -----------------------------------XDC.RUNTIME module Headers    */
#include <xdc/runtime/System.h>
#include <xdc/runtime/Timestamp.h>
/*  ----------------------------------- IPC module Headers           */
#include <ti/ipc/MultiProc.h>
#include <ti/ipc/Notify.h>
#include <ti/ipc/Ipc.h>
/*  ----------------------------------- BIOS6 module Headers         */
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/BIOS.h>

/*  ----------------------------------- To get globals from .cfg Header */
#include <xdc/cfg/global.h>

#define INTERRUPT_LINE  0

/* Notify event number that the app uses */
#define EVENTID         10

/* Number of times to run the loop */
#define NUMLOOPS        10

UInt32 seq = 0;
UInt16 recvProcId;
int i = 0;
UInt16 srcProc, dstProc,localProc;

void sleep(int time){
    int start = Timestamp_get32();
    while(Timestamp_get32()-start<time);

}
/*
 *  ======== cbFxn ========
 *  This function was registered with Notify. It is called when any event is
 *  sent to this processor.
 */
Void cbFxn(UInt16 procId, UInt16 lineId,
           UInt32 eventId, UArg arg, UInt32 payload)
{
    /* The payload is a sequence number. */
    recvProcId = procId;
    seq = payload;
    System_printf("IPC ISR SUCCESS!");
    Semaphore_post(semHandle);
    //Semaphore_post(semHandle1);
    i++;

}

/*
 *  ======== tsk0_func ========
 *  Sends an event to the next processor then pends on a semaphore.
 *  The semaphore is posted by the callback function.
 */
Void tsk0_func(UArg arg0, UArg arg1)
{
    int status;

    if (MultiProc_self() == 0) {

            /* Send an event to the next processor */

            status = Notify_sendEvent(1, 0, 10, NULL, TRUE);

            if (status < 0) {

                System_abort("Notify_sendEvent for slaveCore1 failed\n");

            }

            /* Send an event to the next processor */

            status = Notify_sendEvent(2, 0, 10, NULL, TRUE);

            if (status < 0) {

                System_abort("Notify_sendEvent for slaveCore2 failed\n");

            }

            /* Send an event to the next processor */

            /* Wait to be released by the cbFxn posting the semaphore */

            Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); // 主核等待从核完成其工作返回

            System_printf("MasterCore0 Received Event from All SloverCores\n");

    }

    else {

            /* wait forever on a semaphore, semaphore is posted in callback */

            Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); // 等待主核通知开始执行任务

            System_printf("SlaverCore%d Received Event from MasterCore0\n", MultiProc_self());



            /* Send an event to the next processor */

            status = Notify_sendEvent(0, 0, 10, NULL, TRUE);

            if (status < 0) {

                System_abort("sendEvent to MasterCore0 failed\n");

            }

            System_printf("SlaverCore%d sent Event to MasterCore0 \n", MultiProc_self());

    }

    return (void*)0;
}

/*
 *  ======== main ========
 *  Synchronizes all processors (in Ipc_start), calls BIOS_start, and registers
 *  for an incoming event
 */
int main(Int argc, Char* argv[])
{

    int status;

    status = Ipc_start();

    if (status < 0) {

        System_abort("Ipc_start failed\n");

    }

    System_printf("Ipc_start successfully\n");

    if(MultiProc_self() == 0)//0是主核,1-7是从核

    {

           do{

                  status = Ipc_attach(1);

           }while(status < 0);// 完成从核1的连接

       do{

              status = Ipc_attach(2);

       }while(status < 0);// 完成从核2的连接

        status = Notify_registerEvent(1, 0, 10, (Notify_FnNotifyCbck)cbFxn, NULL);

        if (status < 0) {

            System_abort("Notify_registerEvent for slaveCore1 failed\n");

        }// 完成从核1的事件注册

        status = Notify_registerEvent(2, 0, 10, (Notify_FnNotifyCbck)cbFxn, NULL);

        if (status < 0) {

            System_abort("Notify_registerEvent for slaveCore2 failed\n");

        }// 完成从核2的事件注册

    }

    else{

           do{

                  status = Ipc_attach(0);

           }while(status < 0);// 完成主核0的连接



        status = Notify_registerEvent(0, 0, 10, (Notify_FnNotifyCbck)cbFxn, NULL);

        if (status < 0) {

            System_abort("Notify_registerEvent for masterCore0 failed\n");

        }// 完成主核0的事件注册

        System_printf("Notify_registerEvent for masterCore0 successfully\n");

    }

    BIOS_start();

    return 0;

}

cfg:

/*
* Copyright (c) 2012, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* */
var MultiProc = xdc.useModule('ti.sdo.utils.MultiProc');

/*
* Get the list of names that the build device supports.
* I.e. ["CORE0", "CORE1", "CORE2" ... ]
*/
var nameList = MultiProc.getDeviceProcNames();

/*
* Since this is a single-image example, we don't (at build-time) which
* processor we're building for. We therefore supply 'null'
* as the local procName and use MultiProc_setLocalId to set the procId
* at runtime.
*/
MultiProc.setConfig(null, nameList);

var System = xdc.useModule('xdc.runtime.System');
var SysStd = xdc.useModule('xdc.runtime.SysStd');
System.SupportProxy = SysStd;

/* Modules explicitly used in the application */
var Notify = xdc.useModule('ti.sdo.ipc.Notify');
var Ipc = xdc.useModule('ti.sdo.ipc.Ipc');
var BIOS = xdc.useModule('ti.sysbios.BIOS');
BIOS.heapSize = 0x8000;
var Task = xdc.useModule('ti.sysbios.knl.Task');
var TimeStamp = xdc.useModule('xdc.runtime.Timestamp');
var tsk0 = Task.create('&tsk0_func');
tsk0.instance.name = "tsk0";

/* To avoid wasting shared memory for MessageQ transports */
for (var i = 0; i < 3; i++) {
Ipc.setEntryMeta({
remoteProcId: i,
setupMessageQ: false,
setupNotify: true,
});
}

/* Synchronize all processors (this will be done in Ipc_start) */
Ipc.procSync = Ipc.ProcSync_PAIR;

/* Shared Memory base address and length */
var SHAREDMEM = 0x0C000000;
var SHAREDMEMSIZE = 0x00200000;

/*
* Need to define the shared region. The IPC modules use this
* to make portable pointers. All processors need to add this
* call with their base address of the shared memory region.
* If the processor cannot access the memory, do not add it.
*/
var SharedRegion = xdc.useModule('ti.sdo.ipc.SharedRegion');
SharedRegion.setEntryMeta(0,
{ base: SHAREDMEM,
len: SHAREDMEMSIZE,
ownerProcId: 0,
isValid: true,
name: "DDR2_RAM",
});

/* Create a semaphore with count 0 */
var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
Program.global.semHandle = Semaphore.create(0);
Program.global.semHandle1 = Semaphore.create(0);
/*
* @(#) ti.sdo.ipc.examples.multicore.evm667x; 1, 0, 0, 0,1; 5-22-2012 16:36:06; /db/vtree/library/trees/ipc/ipc-h32/src/ xlibrary

*/