PL和 PS 的高效交互是 zynq soc 开发的重中之重,我们常常需要将 PL 端的大量数据实
时送到 PS 端处理,或者将 PS 端处理结果实时送到 PL 端处理,常规我们会想到使用 DMA 的
方式来进行,但是各种协议非常麻烦,灵活性也比较差,本节讲解如何Cache
来读写 PS 端 ddr 的数据。
PS与PL都是独立运行的,PS通过DDR控制器来对DDR存储器进行访问。为了加速,常常将32字节数据缓存到Cache中,而不是针对一个数据进行缓存,;Xilinx成为一行,即Line。优势:可以加速访问的速度。劣势:就是Cache中的数据发生了变化,不能迅速反应到DDR4中实际的数据。 同样当DDR4中的数据发成了更新也不能快速的反映到cache中。因此当PL或是PS不同的核通过DMA修改了DDR4数据时,PS端使用的CPU还不能及时获取发生的东西,拿到的数据仍然是Cache中没有修改过的数据。
#include “xil_cache.h”
void Xil_DCacheDisable(void);
xixlinx 默认在硬件平台层会把cache打开,若需禁用需调用上述的函数。这样CPU将直接访问内存,读写都是直接的。问题:这样极大的降低了CPU的性能,大大降低了读写速度。
Flush就是把Cache里的数据流放出去,清空Cache,也就是将Cache的内容推到DDR中去。
使用的示例:
#include “xil_cache.h”
/****************************************************************************
If the bytes specified by the address (adr) are cached by the
Data cache, the cacheline containing that byte is invalidated.
If the cacheline is modified (dirty), the written to system
memory first before the before the line is invalidated.
****************************************************************************/
Xil_DCacheFlushRange(Addr, Len)
注意事项:刷新必须是32b的整数倍。
Xil_DCacheFlushLine((INTPTR)&PCTransmit_RingBuffer_Acore);
Xil_DCacheFlushRange((INTPTR)pTransmitBuffer,sizeof(TransmitBuffer_Type));
Invalidate表示当场宣布Cache里的内容无效,需要从DDR中重新加载,即把数据从DDR中拉到Cache中来。
/****************************************************************************
*
If the bytes specified by the address (adr) are cached by the
Data cache, the cacheline containing that byte is invalidated.
If the cacheline is modified (dirty), the modified contents are
lost and are NOT written to system memory before the line is
invalidated.
****************************************************************************/
Xil_DCacheInvalidateLine((INTPTR)&PCTransmit_RingBuffer_Rcore);
Xil_DCacheInvalidateRange(Addr, Len)