在我使用zynq7000开发板进行开发时候,用到microbalze软核,配置该软核使用M_AXI_DC接口。且该接口数据宽度如图为128位。
我希望能在进行软件开发的时候,能定义一个数组,把该数据的128位数据一次性 通过mb的AXI_DC接口写入到block design的ip核中。
现在问题是mb的AXI_DC接口写的数据宽度是128位,但是只能一次性写32为。然后再配合字节
有效通道(strob)进行数据传输。
这是用于测试的c语言代码。
#include <stdio.h>
#include "xil_printf.h"
#include "string.h"
#include "xil_io.h"
#include "xil_cache.h"
#include "xbasic_types.h"
typedef unsigned int u32_t;
#define word_length 8
//#define buf_len 4
#define axi_data_baseaddr ((u32_t *) 0x77000000 )
u32_t sent_data_buf[]={0x0011,0x2233,0x4455,0x6677,0x8899,0xaabb,0xccdd,0xeeff};
int main()
{
while (1){
memcpy(axi_data_baseaddr,sent_data_buf,word_length);
}
return 0;
}
这是观察到的现象。
MicroBlaze最小系统+UART/CAN/GPIO
可以借鉴下
https://blog.csdn.net/liuhandd/article/details/123899620
以下内容由CHATGPT及阿里嘎多学长共同生成、有用望采纳:
问题在于使用memcpy函数将整个数组传递给AXI接口时,实际上只会传递32位数据,因为AXI接口只能一次性传输32位数据。要实现一次性传输128位数据,可以使用循环遍历数组,并将每个32位数据分别传输到AXI接口。此外,还需要注意字节序问题,以确保传输的数据是按照正确的顺序传输的。
以下是修改后的示例代码:
#include <stdio.h>
#include "xil_printf.h"
#include "string.h"
#include "xil_io.h"
#include "xil_cache.h"
#include "xbasic_types.h"
typedef unsigned int u32_t;
#define word_length 8
#define axi_data_baseaddr ((u32_t *) 0x77000000 )
u32_t sent_data_buf[]={0x0011,0x2233,0x4455,0x6677,0x8899,0xaabb,0xccdd,0xeeff};
int main()
{
u32_t i;
u32_t temp_data;
while (1){
for(i=0; i<word_length; i++){
temp_data = sent_data_buf[i];
temp_data = (((temp_data & 0x000000ff) << 24) |
((temp_data & 0x0000ff00) << 8) |
((temp_data & 0x00ff0000) >> 8) |
((temp_data & 0xff000000) >> 24));
Xil_Out32((u32_t)axi_data_baseaddr + i*sizeof(u32_t), temp_data);
}
}
return 0;
}
在循环中,首先将要传输的32位数据进行字节序转换,然后将其传输到AXI接口中。这样,就能够实现一次性传输128位数据到AXI接口了。
以下答案由GPT-3.5大模型与博主波罗歌共同编写:
您好,根据您的描述,您需要将一个128位的数据一次写入M_AXI_DC接口中。实际上,M_AXI_DC接口的数据传输宽度由IP核中的数据总线决定,用8位字节为例,数据通道是8位的,即一次只能传输一个8位字节(或称一个word)。在这种情况下,我们需要将一个128位的数据分为4个32位的数据,每个32位的数据分别写入4个8位字节的数据通道中。以下是示例代码:
#include <stdio.h>
#include "xil_printf.h"
#include "string.h"
#include "xil_io.h"
#include "xil_cache.h"
#include "xbasic_types.h"
typedef unsigned int u32_t;
typedef unsigned char u8_t;
#define word_length 8
#define axi_data_baseaddr ((u32_t *) 0x77000000 )
u32_t sent_data_buf[]={0x00112233,0x44556677,0x8899aabb,0xccddeeff};
u8_t *sent_data_buf_ptr;
int main()
{
int i, j;
sent_data_buf_ptr = (u8_t *)sent_data_buf;
while (1){
// Write 128-bit data
for (i = 0; i < 4; i++){
// Write 32-bit data
for (j = 0; j < word_length; j++){
Xil_Out8((u32_t)axi_data_baseaddr + i*word_length + j, sent_data_buf_ptr[i*word_length+j]);
}
}
}
return 0;
}
代码中,先将128位的数据按照32位的大小分成4段,然后再将每段数据按照字节写入M_AXI_DC接口。具体来说,用sent_data_buf指向一个存储128位数据的32位数组,用sent_data_buf_ptr指向sent_data_buf的起始地址。然后循环4次,对于每个32位数据,利用内层循环将其拆分成4个8位字节,分别写入M_AXI_DC接口中。
注意:由于您在使用memcpy将数据写入内存时,可能会出现高低字节乱序的现象,请您在写入M_AXI_DC接口时注意数据的字节序。
如果我的回答解决了您的问题,请采纳!
首先,让我们解决高低字节乱序的问题。这可能是由于字节序导致的,可以使用 Xilinx 提供的函数 Xil_EndianSwap32() 进行字节序转换。将数据复制到 AXI_DC 接口之前,可以对每个单词进行字节序转换,确保数据以正确的顺序传输。另外,您还提到 AXI_DC 接口一次只能写入 32 位数据。如果您希望一次性传输完整的 128 位数据,您可以对数据进行分割,并分别写入四个连续的 AXI_DC 接口地址。下面是修改后的代码示例:
#include <stdio.h>
#include "xil_printf.h"
#include "string.h"
#include "xil_io.h"
#include "xil_cache.h"
#include "xbasic_types.h"
typedef unsigned int u32_t;
#define word_length 8
//#define buf_len 4
#define axi_data_baseaddr ((u32_t *)0x77000000)
u32_t sent_data_buf[] = {0x0011, 0x2233, 0x4455, 0x6677, 0x8899, 0xaabb, 0xccdd, 0xeeff};
void write_data_to_axi_dc(u32_t* data_buf)
{
// Split the 128-bit data into four 32-bit words and write to AXI_DC interface
for (int i = 0; i < 4; i++) {
u32_t word = data_buf[i];
u32_t swapped_word = Xil_EndianSwap32(word); // Swap endianess if necessary
Xil_Out32(axi_data_baseaddr + i, swapped_word);
}
}
int main()
{
while (1) {
write_data_to_axi_dc(sent_data_buf);
}
return 0;
}
这样,每次循环将会一次性传输 sent_data_buf 的完整 128 位数据。请注意,函数 Xil_EndianSwap32() 可用于字节序转换,确保数据按正确顺序传输。