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.

【期待您的回复】c6678 SharedRegion 用从核改写共享内存数据,在主核上数据为什么没有刷新

运行结果如下:

主要代码:

Void tsk0_func(UArg arg0, UArg arg1)
{
Int status;
Int i;

int coreId=MultiProc_self();

// 分配内存
if (coreId == 0) {

inBuf = (unsigned char*)Memory_alloc(SharedRegion_getHeap(0), dateNum, 128, NULL);

if(inBuf==NULL)
{
System_printf("malloc Buf failed\n");
BIOS_exit(0);
}

for(i=0;i<dateNum;i++){ // 写入数据
inBuf[i]=i*3+5;
}

inBuf_srptr = SharedRegion_getSRPtr(inBuf, 0);

System_printf("inBuf address 0x%x\n",inBuf);
System_printf("outBuf date is ");
for(i=0;i<dateNum;i++)
System_printf("%d ",inBuf[i]);
System_printf("\n");

Cache_wbAll();// Write back all caches();

for(i=1;i<8;i++)
status = Notify_sendEvent(i, INTERRUPT_LINE, BufEVENT, (UInt32)inBuf_srptr, TRUE);
/* Wait to be released by the cbFxn posting the semaphore */
Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); // 主核等待所有从核完成其工作返回
Cache_wbAll();// Write back all caches();
System_printf("MasterCore Received Event from All SloverCores,Data:\n");
for(i=0;i<dateNum;i++)
System_printf("%d ",inBuf[i]);
System_printf("\n");

}else{

Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); // 等待从核完成全部任务

Cache_disable(Cache_Type_ALL);

inBuf=SharedRegion_getPtr(inBuf_srptr);
inBuf[coreId ]=coreId*coreId ;
Cache_wbAll();// Write back all caches();

System_printf("inBuf address 0x%x\n",inBuf);
System_printf("regionId is %d\n",SharedRegion_getId(inBuf)); // 打印当前共享区域ID
System_printf("outBuf date is ");
for(i=0;i<dateNum;i++)
System_printf("%d ",inBuf[i]);
System_printf("\n");


/* Send an event to the next processor */
status = Notify_sendEvent(masterProc, INTERRUPT_LINE, BufEVENT, (UInt32)inBuf_srptr, TRUE);
}
// 各核完成任务后可以退出了
System_printf("SharedMem is finished\n");
BIOS_exit(0);
}

想用从核改写共享内存中的数据之后,主核利用改写过的数据继续执行。现在主核的数据并没有刷新,还是原来写进去的。

非常希望收到回复,感谢各位指教。谢谢

  • shared region数据类型改成double型怎么改?我把指针和memory_alloc改了之后所有数据都不对了?

  • 写方是做cache writeback,读端在使用完数据之后要做cache invalidate。

  • 您好,我把共享内存的数据类型改成double之后,主核申请24个double型数据作为共享内存。然后用从核改写共享内存里的数据,加上了:

    Cache_inv(inBuf,sizeof(inBuf),Cache_Type_ALL,TRUE);
    Cache_wait();

    Cache_wbAll();

    不知道为什么主核只能接收到前8个数据,下面是我的代码和运行结果,麻烦您指教,非常感谢,非常感谢。

    代码:

    #include<xdc/std.h>
    #include<stdio.h>
    #include<stdlib.h>
    
    /*  -----------------------------------XDC.RUNTIME module Headers    */
    #include <xdc/runtime/System.h>
    #include <ti/sysbios/hal/Cache.h>
    
    /*  ----------------------------------- IPC module Headers           */
    #include <ti/ipc/MultiProc.h>
    #include <ti/ipc/Notify.h>
    #include <xdc/runtime/IHeap.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>
    #include <xdc/runtime/Memory.h>
    #include <ti/ipc/SharedRegion.h>
    
    #define INTERRUPT_LINE  0
    #define BufEVENT 10
    
    #define dateNum 24 //数据个数
    double *inBuf=NULL;//double型指针
    SharedRegion_SRPtr inBuf_srptr;
    
    UInt16 recvnumes = 0;
    #define masterProc 0
    #define sloverNum 7
    /*
     *  ======== cbFxn ========
     *  这是Notify模块的注册函数
     *  procId表示激动注册函数的核ID,或者说该事件是从哪个核来的
     */
    Void cbFxn(UInt16 procId, UInt16 lineId,
               UInt32 eventId, UArg arg, UInt32 payload)
    {
    	inBuf_srptr=(SharedRegion_SRPtr)payload;
    
    	if(procId!=masterProc) // 主核注册函数
    		{
    			recvnumes++;  // 接收从核的数目
    	    	if(recvnumes==sloverNum) // 当收到全部从核回复的信息
    	    	{
    	    		recvnumes=0;
    	    		Semaphore_post(semHandle);
    	    	}
    		}
    		else{
    	
    			Semaphore_post(semHandle);
    		}
    }
    
    /*
     *  ======== 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;
        Int i;
    
        int coreId=MultiProc_self();
    
        // 分配内存
        if (coreId == 0) {
    
        	inBuf = Memory_alloc(SharedRegion_getHeap(0), dateNum*sizeof(double), 128, NULL);//主核分配内存
    
        	if(inBuf==NULL)
        	{
        		System_printf("malloc Buf failed\n");
        		BIOS_exit(0);
        	}
    
        	for(i=0;i<dateNum;i++){  // 写入数据
        		inBuf[i]=0;
        	}
    
        	inBuf_srptr = SharedRegion_getSRPtr(inBuf, 0);
    
        	System_printf("inBuf address 0x%x\n",inBuf);
        	System_printf("outBuf date is ");
        	for(i=0;i<dateNum;i++)
        		printf("%f ",inBuf[i]);
        	System_printf("\n");
    
        	inBuf[3*coreId ]=coreId*coreId +0.5;
            inBuf[3*coreId+1 ]=coreId*coreId +0.5;
    	inBuf[3*coreId+2 ]=coreId*coreId +0.5;
    
        	Cache_wbAll();// Write back all caches();
    
        	for(i=1;i<8;i++)
        		status = Notify_sendEvent(i, INTERRUPT_LINE, BufEVENT, (UInt32)inBuf_srptr, TRUE);
        	   /* Wait to be released by the cbFxn posting the semaphore */
    		Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); // 主核等待所有从核完成其工作返回
    
    
        	System_printf("MasterCore Received Event from All SloverCores,Data:\n");
        	Cache_inv(inBuf,sizeof(inBuf),Cache_Type_ALL,TRUE);//Cache_inv
    Cache_wait();
    
        	for(i=0;i<dateNum;i++)
        	    		printf("%f ",inBuf[i]);
        	    	System_printf("\n");//打印显示主核共享内存数据
    
    
    
        }else{
    
        	Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); // 等待从核完成全部任务
    
        	Cache_disable(Cache_Type_ALL);//cache失效
    
        	inBuf=SharedRegion_getPtr(inBuf_srptr);
        	inBuf[3*coreId ]=coreId*coreId +0.5;//从核改写共享内存数据
        	inBuf[3*coreId+1 ]=coreId*coreId +0.5;
        	inBuf[3*coreId+2 ]=coreId*coreId +0.5;
    
        	Cache_wbAll();//  caches回写;
    
        	System_printf("inBuf address 0x%x\n",inBuf);
        	System_printf("regionId is %d\n",SharedRegion_getId(inBuf));  // 打印当前共享区域ID
        	System_printf("outBuf date is ");
        	for(i=0;i<dateNum;i++)//打印显示从核共享内存数据
        		printf("%f ",inBuf[i]);
        	System_printf("\n");
    
    
        	 /* Send an event to the next processor */
        	status = Notify_sendEvent(masterProc, INTERRUPT_LINE, BufEVENT, (UInt32)inBuf_srptr, TRUE);
        }
        // 各核完成任务后可以退出了
        System_printf("SharedMem is finished\n");
        BIOS_exit(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;
    
        /*
         *  Ipc_start() calls Ipc_attach() to synchronize all remote processors
         *  because 'Ipc.procSync' is set to 'Ipc.ProcSync_ALL' in *.cfg
         */
        status = Ipc_start();
        if (status < 0) {
            System_abort("Ipc_start failed\n");
        }
    
        if (MultiProc_self() == 0) {
        	Int i;
        	for(i=1;i<8;i++)
        		status = Notify_registerEvent(i, INTERRUPT_LINE, BufEVENT,
        	    	    				(Notify_FnNotifyCbck)cbFxn, NULL);
        }else{
        	// 从核完成事件注册
        	status = Notify_registerEvent(0, INTERRUPT_LINE, BufEVENT,
        	    				(Notify_FnNotifyCbck)cbFxn, NULL);
        }
    
        BIOS_start();
    
        return (0);
    }
    
    
    

    下面是运行结果:

    [C66xx_0] inBuf address 0xc02d980
    outBuf date is 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 
    [C66xx_6] inBuf address 0xc02d980
    regionId is 0
    outBuf date is 0.500000 0.500000 0.500000 1.500000 1.500000 1.500000 4.500000 4.500000 4.500000 9.500000 9.500000 9.500000 16.500000 16.500000 16.500000 25.500000 25.500000 25.500000 36.500000 36.500000 36.500000 49.500000 49.500000 49.500000 
    SharedMem is finished
    [C66xx_2] inBuf address 0xc02d980
    regionId is 0
    outBuf date is 0.500000 0.500000 0.500000 1.500000 1.500000 1.500000 4.500000 4.500000 4.500000 9.500000 9.500000 9.500000 16.500000 16.500000 16.500000 25.500000 25.500000 25.500000 36.500000 36.500000 36.500000 49.500000 49.500000 49.500000 
    SharedMem is finished
    [C66xx_7] inBuf address 0xc02d980
    regionId is 0
    outBuf date is 0.500000 0.500000 0.500000 1.500000 1.500000 1.500000 4.500000 4.500000 4.500000 9.500000 9.500000 9.500000 16.500000 16.500000 16.500000 25.500000 25.500000 25.500000 36.500000 36.500000 36.500000 49.500000 49.500000 49.500000 
    SharedMem is finished
    [C66xx_1] inBuf address 0xc02d980
    [C66xx_3] inBuf address 0xc02d980
    [C66xx_4] inBuf address 0xc02d980
    [C66xx_5] inBuf address 0xc02d980
    [C66xx_1] regionId is 0
    [C66xx_3] regionId is 0
    [C66xx_4] regionId is 0
    [C66xx_5] regionId is 0
    [C66xx_1] outBuf date is 0.500000 0.500000 0.500000 1.500000 1.500000 1.500000 4.500000 4.500000 4.500000 9.500000 9.500000 9.500000 16.500000 16.500000 16.500000 25.500000 25.500000 25.500000 36.500000 36.500000 36.500000 49.500000 49.500000 49.500000 
    [C66xx_3] outBuf date is 0.500000 0.500000 0.500000 1.500000 1.500000 1.500000 4.500000 4.500000 4.500000 9.500000 9.500000 9.500000 16.500000 16.500000 16.500000 25.500000 25.500000 25.500000 36.500000 36.500000 36.500000 49.500000 49.500000 49.500000 
    [C66xx_4] outBuf date is 0.500000 0.500000 0.500000 1.500000 1.500000 1.500000 4.500000 4.500000 4.500000 9.500000 9.500000 9.500000 16.500000 16.500000 16.500000 25.500000 25.500000 25.500000 36.500000 36.500000 36.500000 49.500000 49.500000 49.500000 
    [C66xx_5] outBuf date is 0.500000 0.500000 0.500000 1.500000 1.500000 1.500000 4.500000 4.500000 4.500000 9.500000 9.500000 9.500000 16.500000 16.500000 16.500000 25.500000 25.500000 25.500000 36.500000 36.500000 36.500000 49.500000 49.500000 49.500000 
    [C66xx_1] SharedMem is finished
    [C66xx_3] SharedMem is finished
    [C66xx_4] SharedMem is finished
    [C66xx_5] SharedMem is finished
    [C66xx_0] MasterCore Received Event from All SloverCores,Data:
    0.500000 0.500000 0.500000 1.500000 1.500000 1.500000 4.500000 4.500000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 
    //??主核从第八个数据以后就全部为0 了
    //??主核从第八个数据以后就全部为0 了
    SharedMem is finished
    

    非常期待收到您的回复!!!非常感谢!!

    另:System_printf打印double型数据的语法是什么样的?查了好几天,试了好多都不对?

    为什么不是System_printf(“data = %f”,data),我这样打印出来就显示一个f。

    再次感谢您的回复,祝您开心。期待收到您的回复

  • 你好。你可以在ccs-help里面输入System_printf,会有解答。

    System_printf()  // module-wide

    A smaller faster printf

    C synopsis target-domain
    Int System_printf(CString fmt, ...);
     
    ARGUMENTS
    fmt — a 'printf-style' format string
    DETAILS
    This function behaves much like the ANSI C Standard printf but does not support the full range of format strings specified by the C Standard. In addition, several non-standard format specifiers are recognized.
    FORMAT STRINGS
    The format string is a character string composed of zero or more directives: ordinary characters (not %), which are copied unchanged to the output stream; and conversion specifications, each of which results in fetching zero or more subsequent arguments. Each conversion specification is introduced by the character %, and ends with a conversion specifier. In between there may be (in this order) zero or more flags, an optional minimum field width, an optional precision and an optional length modifier.
    FLAGS
    The following flags are supported:
    -
    The converted value is to be left adjusted on the field boundary (the default is right justification.)
    0
    The value should be zero padded. For d, i, o, u, and x conversions, the converted value is padded on the left with zeros rather than blanks.
    FIELD WIDTH
    The optional field width specifier is a decimal digit string (with nonzero first digit) specifying a minimum field width. If the converted value has fewer characters than the field width, it will be padded with spaces on the left (or right, if the left-adjustment flag has been given). Instead of a decimal digit string one may write * to specify that the field width is given in the next argument. A negative field width is taken as a '-' flag followed by a positive field width.
    PRECISION
    The optional precision specifier is a period ('.') followed by an optional decimal digit string. Instead of a decimal digit string one may write * to specify that the precision is given in the next argument which must be of type int.
    If the precision is given as just '.', or the precision is negative, the precision is taken to be zero. This gives the minimum number of digits to appear for d, i, o, u, and x conversions, or the maximum number of characters to be printed from a string for s conversions.
    LENGTH MODIFIERS
    The optional length modifier is a single character from the following list.
    l
    A following integer conversion corresponds to a long int or unsigned long int argument
    CONVERSION SPECIFIERS
    The following conversion specifiers are supported.
    d, i
    signed integer
    u
    unsigned decimal
    x
    unsigned hex
    o
    unsigned octal
    p
    pointer (@ + hex num)
    c
    character
    s
    string
    EXTENDED CONVERSION SPECIFIERS
    The following conversion specifiers are optionally supported. See the extendedFormats configuration parameter for more information about how to enable these conversion specifiers.
    f
    decimal floating point.
    $
    non-ANSI conversion prefix. This prefix indicates that the next character identifies a non-ANSI standard conversion. See the next section for details.  


  • 您好,请问您用的是哪个例程,感谢您的回复,期待收到您的回复。

  • http://blog.csdn.net/tostq/article/details/51334961

    这是别人的博客地址,有比较详细的说明和程序下载地址,你看下能不能用得上吧