DSP- 6678--------- SRIO通信(2)主核函数master_main


一、创建 heapBuf

	HeapBufMP_Params_init(&heapBufParams);
	heapBufParams.regionId       = 0;
	heapBufParams.name           = HEAP_NAME;
	heapBufParams.numBlocks      = 16;
	heapBufParams.align          = 128; //对齐方式
	heapBufParams.blockSize      = sizeof(MessageQ_MsgHeader);
	heapHandle = HeapBufMP_create(&heapBufParams);
	if (heapHandle == NULL)
	{
		System_abort("HeapBufMP_create failed\n" );
	}


	do {
		status = HeapBufMP_open(HEAP_NAME, &heapHandle);
		/*
		 *  Sleep for 1 clock tick to avoid inundating remote processor
		 *  with interrupts if open failed
		 */
		if (status < 0) {
			Task_sleep(1);
		}
	} while (status < 0);

二、创建messageQ(master)

     /* Register this heap with MessageQ */
    MessageQ_registerHeap((IHeap_Handle)heapHandle, HEAPID);

    /* Create the local message queue */
    messageQ = MessageQ_create(masterQueueName, NULL);
    if (messageQ == NULL)
    {
	System_abort("MessageQ_create failed\n" );
    }

创建的为master messageQ,用于接收处理完毕的数据

三、打开8个从核创建的slave messageQ,准备发送msg

	for(i = 0;i<NUMCORE;i++)
	{
		/* Open the remote message queue. Spin until it is ready. */
		do
		{
			status = MessageQ_open(slaveQueueName[i], &remoteQueueId[i]);
			    			/* 输入		  输出   */
			if (status < 0)
			{
				Task_sleep(1);
			}
		} while (status < 0);


		/* Allocate a message to be ping-ponged around the processors */
		msg[i] = MessageQ_alloc(HEAPID, sizeof(MessageQ_MsgHeader));//给头部分配空间
		if (msg[i] == NULL)
		{
		   System_abort("MessageQ_alloc failed\n" );
		}
	}

四、NWRITE模式发送起始标志位到FPGA

start_srio_to_fpga(0xFF); 

4.1 配置SRIO参数

        Int32  uiCompletionCode;
	static long long start_value = 0x0100000000000000; //要发送的数据
	Uint32 uilocalAddr  = GLOBAL_ADDR((uint32_t)&start_value);
	Uint32 uiremoteAddr = 0x0;

	Uint32 dstID        = dst_id;
	Uint32 dataSize     = sizeof(long long);  //start_value位8个字节

	/***************************************************************************
	Int32 srio_dio_nwrite(
		    Uint32 uiLocalAddress,    本地数据源地址   start_value的地址
		    Uint32 uiRemoteAddress,   远程数据地址        0
		    Uint32 uiDestID,          目的ID       0xFF
		    Uint32 uiLSUNo,           LSU号                       0
		    Uint32 uiByteCount);      字节个数 	  8

		          本函数实现SRIO NWRITE功能 (SRIO dio nwrite operation)
	***************************************************************************/
	uiCompletionCode = srio_dio_nwrite(uilocalAddr, uiremoteAddr, dstID, 0x0, dataSize);

4.2 NWRITE的实现

srio_dio_nwrite是将KeyStone_SRIO_DirectIO函数封装一层,

Int32 srio_dio_nwrite(Uint32 uiLocalAddress,Uint32 uiRemoteAddress,Uint32 uiDestID,Uint32 uiLSUNo,Uint32 uiByteCount)
{
   Int32 ret = KeyStone_SRIO_DirectIO(uiLocalAddress,uiRemoteAddress,uiDestID,uiByteCount,0x0,uiLSUNo,SRIO_PKT_TYPE_NWRITE);
   return ret;
}

五、等待信号量挂起

//信号量挂起
if (Semaphore_pend(sem_db, BIOS_WAIT_FOREVER) == FALSE)
{
   System_printf("main: Semaphore_pend returns error\n");
   return;
 }

六、广播messageQ(slave)

void BroadcastMessages(
		MessageQ_QueueId *remoteQueueId,
		MessageQ_Msg     *msg,
		const UInt16     msgId,
		const UInt16     number_of_cores )
{
	Int status;
	Int i;

    /* Send messages to process the cores */
	for(i = 0;i < number_of_cores;i++)
	{
		//设置msg中的msgId
		MessageQ_setMsgId(msg[i], msgId);
		//System_printf("Sending a message #%d to %s\n", msgId, slaveQueueName[i]);
		/* 发送messageQ    从核创建的messageQ */
		status = MessageQ_put(remoteQueueId[i], msg[i]);
		if (status < 0)
		{
		   System_abort("MessageQ_put had a failure/error\n");
		}
	}
}

七、接收处理完毕之后的messageQ(master)

void ReceiveMessages(
		MessageQ_Handle  messageQ,
		MessageQ_Msg     *msg,
		const UInt16     number_of_cores)
{
	Int status;
	Int i;

    /* Receive the result */
	for(i = 0;i < number_of_cores; i++)
	{
		/* Get a message 主核创建的messageQ */
		status = MessageQ_get(messageQ, &msg[i], MessageQ_FOREVER);
		if (status < 0)
		{
		   System_abort("This should not happen since timeout is forever\n");
		}
		//System_printf("recieve a message #%d from %s\n", MessageQ_getMsgId(msg[i]), slaveQueueName[i]);
	}
}

八、SWRITE发送处理完毕的数据到FPGA

srio_send_data_to_fpga(0xFF); 

8.1 SRIO参数的配置

	Int32  uiCompletionCode;
	Uint32 uilocalAddr  = GLOBAL_ADDR((uint32_t)&outFrame[0]);
	Uint32 uiremoteAddr = 0x1200000;


	Uint32 dstID        = dst_id;
	Uint32 dataSize     = OUTFRAME_DATA_LEN * sizeof(Uint8);


	/*****************************************************************************
		函数名:
		    Int32 srio_dio_swrite
		    	(Uint32 uiLocalAddress,			本地数据源地址     outFrame的地址
		    	Uint32 uiRemoteAddress,			远程数据地址          0x1200000
		    	Uint32 uiDestID,				目的ID		 dst_id   0xFF
		    	Uint32 uiLSUNo,					LSU号		 0
		    	Uint32 uiByteCount);			字节个数		 outFrame的长度


		          本函数实现SRIO SWRITE功能 (SRIO dio swrite operation)
	******************************************************************************/


	uiCompletionCode = srio_dio_swrite(uilocalAddr,uiremoteAddr,dstID,0x0,dataSize); // 实现SRIO SWRITE功能     

8.2 SWRITE模式的实现

srio_dio_swrite是封装了KeyStone_SRIO_DirectIO一层的结果

Int32 srio_dio_swrite(Uint32 uiLocalAddress,Uint32 uiRemoteAddress,Uint32 uiDestID,Uint32 uiLSUNo,Uint32 uiByteCount)
{
 Int32 ret = KeyStone_SRIO_DirectIO(uiLocalAddress,uiRemoteAddress,uiDestID,uiByteCount,0x0,uiLSUNo,SRIO_PKT_TYPE_SWRITE);
 return ret;
}

finish~


猜你喜欢

转载自blog.csdn.net/yunge812/article/details/80912753