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.

IPC例子工程全局变量共享问题



大家好,

      我在论去中找到的IPC例子工程,仅仅在IPC.c 文件里加了一个变量 int  g_flag = 3;在ISR里面让全局变量加1,然后打印出来。但是全局变量仅仅加一了次,打印出的结果全部都是4,请问这是为什么?打印的结果如下:

Set interrupt from Core 0 to Core 1, cycle = 1053673622
Interrupt Info 0
[TMS320C66x_1] Receive interrupt from Core 0 with info 0x0, cycle = 1057016594
g_flag = 4
Set interrupt from Core 1 to Core 2, cycle = 1057033058
Interrupt Info 8
[TMS320C66x_2] Receive interrupt from Core 1 with info 0x0, cycle = 1059235265
g_flag = 4
Set interrupt from Core 2 to Core 3, cycle = 1059251792
Interrupt Info 16
[TMS320C66x_3] Receive interrupt from Core 2 with info 0x10, cycle = 1057523984
g_flag = 4
Set interrupt from Core 3 to Core 4, cycle = 1057540624
Interrupt Info 24
[TMS320C66x_4] Receive interrupt from Core 3 with info 0x10, cycle = 1060312891
g_flag = 4
Set interrupt from Core 4 to Core 5, cycle = 1060329531
Interrupt Info 32
[TMS320C66x_5] Receive interrupt from Core 4 with info 0x20, cycle = 1060791800
g_flag = 4
Set interrupt from Core 5 to Core 6, cycle = 1060808440
Interrupt Info 40
[TMS320C66x_6] Receive interrupt from Core 5 with info 0x20, cycle = 1066910801
g_flag = 4
Set interrupt from Core 6 to Core 7, cycle = 1066927441
Interrupt Info 48
[TMS320C66x_7] Receive interrupt from Core 6 with info 0x30, cycle = 1070451703
g_flag = 4
Set interrupt from Core 7 to Core 0, cycle = 1070468343
Interrupt Info 56
[TMS320C66x_0] Receive interrupt from Core 7 with info 0x30, cycle = 1065998385
g_flag = 4
IPC test passed!

  • 没有DSP芯片,这个工程的运行是simulator下运行的。

  • 你这个变量应该是每个core上独有的变量,并非多核共享全局变量,所以每个core分别累加,互不影响。只产生一次中断是因为代码只触发一次。

  • 那怎么才能让全局变量,被8个核都可以操作呢??

  • 你好,教你一个方法。

    (1)比如要共享变量share_variable,在每个核的代码中都声明:

    ///////////////////////////////////////////////////////////////////////////////////////////////

    #pragma DATA_SECTION (share_variable, ".global_shared");
    static unsigned int share_variable;

    ///////////////////////////////////////////////////////////////////////////////////////////////

    (2)在link文件*.cmd中加入段定义

    //////////////////////////////////////////////////////////////////////////////

    MEMORY {

    .....
    VAR_SHARED_RAM: origin = 0x0C3E0000 length=0x00020000

    .....
    }

    ....

    .global_shared: type=NOINIT > VAR_SHARED_RAM

    ///////////////////////////////////////////////////////////////////////////////////////////////

    这样每个核上的变量share_variable,都对应与M3中的同一个内存,这就达到了类似全局变量的效果。

    另外,记得在访问核间共享内存时,用spin_lock互斥(C6678有64个硬件信号量)。

    BTW:Enea提供针对C66的商用平台软件,如果有兴趣可以联系。

    Br

    William.dong@enea.com

  • 您好:

    已经安装您的方法修改了CMD文件,但是还是打印出下面信息。
    已经定义变量g_flag , 核0给核1 ,发中断,核1在中断里把g_flag加1.然后给核0发中断,核0在中断里把变量g_flag又加1。
    g_flag 被加了两次,应该打印出4, 为什么还是打印出3?  附件是我的CCS工程, 麻烦看哪里错了,谢谢。


    [TMS320C66x_0] Set interrupt from Core 0 to Core 1, cycle = 15622 Interrupt Info 0
    [TMS320C66x_1] Receive interrupt from Core 0 with info 0x0, cycle = 687498
    Core1 output :g_flag = 3,address =c3e0000
    Set interrupt from Core 1 to Core 0, cycle = 709011
    Interrupt Info 8
    [TMS320C66x_0] Receive interrupt from Core 1 with info 0x0, cycle = 1131531
    core0:g_flag = 3, address =c3e0000
    IPC test passed!

    twoCoreExamp.rar