DSP

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

2019-07-13 11:30发布

    一、创建 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 " ); } 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 " );     } 创建的为master messageQ,用于接收处理完毕的数据 三、打开8个从核创建的slave messageQ,准备发送msg for(i = 0;i 四、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 "); 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 ", msgId, slaveQueueName[i]); /* 发送messageQ 从核创建的messageQ */ status = MessageQ_put(remoteQueueId[i], msg[i]); if (status < 0) { System_abort("MessageQ_put had a failure/error "); } } } 七、接收处理完毕之后的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 "); } //System_printf("recieve a message #%d from %s ", 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功能      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~ ======================================================================= 最近新开的公众号,文章正在一篇篇的更新, 公众号名称:玩转电子世界 各位朋友有什么问题了可以直接在上面提问,我会一一进行解答的。 跟着阳光非宅男,一步步走进电子的世界。 关注之后回复  资料下载  关键词可以获得免费海量视频学习资料下载~~! 已共享的学习视频资料,共享资料正在不断更新中。。。 =======================================================================