写一个microblaze软核 在DDR上运行 精确的微秒级延时函数
时间: 2023-11-18 11:04:15 浏览: 38
下面是一个基于MicroBlaze软核,在DDR上运行的精确微秒级延时函数的示例代码:
```c
#include <xbasic_types.h>
#include <xil_cache.h>
#define DDR_BASEADDR XPAR_PS7_DDR_0_S_AXI_BASEADDR
#define TIMER_BASEADDR XPAR_AXI_TIMER_0_BASEADDR
#define TIMER_FREQ XPAR_AXI_TIMER_0_CLOCK_FREQ_HZ
void delay_us(u32 us) {
u32 delay_ticks = TIMER_FREQ / 1000000 * us;
Xil_DCacheFlush();
Xil_Out32(TIMER_BASEADDR + 0x04, 0x0); // Reset timer
Xil_Out32(TIMER_BASEADDR + 0x00, 0x20); // Enable timer, down counting mode
Xil_Out32(TIMER_BASEADDR + 0x08, delay_ticks);
while ((Xil_In32(TIMER_BASEADDR + 0x0C) & 0x01) == 0);
Xil_Out32(TIMER_BASEADDR + 0x00, 0x00); // Disable timer
}
```
和上面的例子一样,这个函数也使用了Xilinx提供的AXI Timer IP核。不同之处在于,我们现在需要在运行程序时将数据存储到DDR中。为了避免DDR中的数据与CPU缓存中的数据不同步,我们使用了Xil_DCacheFlush函数将CPU缓存中的数据刷新到DDR中。这样,我们就可以确保Timer的Load寄存器中的值与我们计算的值一致。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)