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.

利用全局变量flag进行核间通信



自己写了一段小程序,想要实现core0和core1之间的数据通信。

其中使用了全局变量flag作为标志位,指示core0是否完成数据的操作。

软件:ccs5.4

6678仿真运行。

运行的步骤:先在core0中跑,然后手动切换到core1中跑相同的程序。

问题:当切换到core1中时,发现flag=0,但是data[100]中是core1执行完程序的数值0,1,2.......99。

            而且在ccs的变量查看窗口看到core0和core1的flag所在地址是相同的。

请问:为什么flag不能同步呢?

程序:

#include <stdio.h>
#include <c6x.h>


int data[100],i,flag;                      //两个core的flag都位于0X0C007BDC,但是当第一个核执行完成后flag=1,第二个核读取flag=0,而且data是可以同步

int main(void)
{
	if(DNUM == 0)
	{
		flag=0;
		for(i=0; i<100; i++)
		{
			data[i]=i+1;
			if(i==99)
			{
				printf("data has prepared!");
				flag=1;
			}
		}

	}
	if(DNUM==1 && flag==1)
	{
		for(i=0;i<100; i++)
		{
			data[i]=data[i]+DNUM;
		}
	}
	return 0;
}
CMD文件如下:
-heap  0x800
-stack 0x1000

MEMORY
{
	/* Local L2, 0.5~1MB*/
	VECTORS: 	o = 0x00800000  l = 0x00000200
	LL2: 	o = 0x00800200  l = (0x00080000-0x200)
	MSM:   o = 0x0c000000  l = 0x0c3fffff
}

SECTIONS
{
	vecs       	>    VECTORS
	GROUP
	{
		.stack
		.far
		.sysmem
	} > MSM
	
	GROUP
	{
		.text          
		.switch        
	} > MSM
	
	GROUP
	{
		.bss
		.neardata
		.rodata
	} > MSM
	
	GROUP
	{
		.fardata       
		.const         
	} > LL2
	
	GROUP
	{
		.cinit         
		.cio           
	} > MSM

}

 
  • 0x0C000000开始的地址属于SL2,Cache一致性不能自动维护,需要手动维护,所以在每次写完flag以后要writeback,每次读之前要invalidate

  • Allen Yin

    谢谢你的回答!

    在德仪社区看到了下面的方法:http://www.deyisupport.com/question_answer/dsp_arm/c6000_multicore/f/53/t/6338.aspx

    The operations on Core 0 are:

    Write Flag at shared memory

    If(Cache is enabled for access shared memory)

    {

     If(L2 Cache Size>0)

     {

       CACHE_wbL2(flag address, size of flag);

     }

     Else if(L1D Cache Size>0)

     {

       CACHE_wbL1D(flag address, size of flag);

     }

    }

    The operations on Core 1 are:

    If(Cache is enabled for access shared memory)

    {

     If(L2 Cache Size>0)

     {

       CACHE_invL2(flag address, size of flag);

     }

     Else if(L1D Cache Size>0)

     {

       CACHE_invL1D(flag address, size of flag);

     }

    }

    If(Prefetch buffer is enabled for access Core X’s L2 RAM)

    {

     Invalidate Prefetch Buffer;

    }

    Read Flag at shared memory