Forum Discussion
Altera_Forum
Honored Contributor
9 years agoHi,
I am stuck with the same problem as well. I am able to write data from the HPS to the FPGA, but not able to read data back from the FPGA into the HPS. I am using the Lightweight HPS to FPGA bridge in Cyclone V. I have defined an Avalon-MM slave as follows: -module scratch_slave_one_byte(
input clk,
input reset,
input write,
input writedata,
input read,
output reg readdata,
output reg byte_from_hps,
output write_count_w,
input byte_into_hps
);
reg write_count = 0;
assign write_count_w = write_count;
always@(posedge clk) begin
if (write) begin
byte_from_hps <= writedata;
end
else if (read) readdata <= byte_into_hps ;
end
endmodule My C program running in the HPS is as follows: - #include <sys/mman.h>
# include <sys/types.h>
# include <sys/stat.h>
# include <fcntl.h>
# include <stdio.h>
# include <stdlib.h>
# include <unistd.h>
# include <stdint.h>
# include "hps.h"
# include <time.h>
# include "socal.h"
# define ALT_LWFPGASLVS_OFST 0xff200000
# define HW_REGS_BASE (0xfc000000)
# define HW_REGS_SPAN (0x04000000)
# define HW_REGS_MASK (HW_REGS_SPAN-1)
# define MY_MODULE_OFST 0x00000000
# define WRITE 0x00
# define READ 0x04
volatile unsigned char* custom_slave;
void *virtual_base;
int main()
{
int fd;
if( ( fd = open( "/dev/mem", ( O_RDWR | O_SYNC ) ) ) == -1 ) {
printf( "ERROR: could not open \"/dev/mem\"...\n" );
return( 1 );
}
virtual_base = mmap(NULL, HW_REGS_SPAN, (PROT_READ|PROT_WRITE), MAP_SHARED, fd, HW_REGS_BASE);
if( virtual_base == MAP_FAILED ) {
printf( "ERROR: mmap() failed...\n" );
close( fd );
return( 1 );
}
custom_slave = (unsigned char*)(virtual_base + ( (ALT_LWFPGASLVS_OFST + MY_MODULE_OFST + WRITE) & (HW_REGS_MASK)));
custom_slave = 0x06; //WRITE BYTE INTO FPGA
unsigned char value = custom_slave; //READ BYTE FROM FPGA
printf("%d\n",value);
//value = alt_read_word(virtual_base + ((ALT_LWFPGASLVS_OFST + MY_MODULE_OFST) & HW_REGS_MASK));
//printf("%d\n",value);
cleanup:
if( munmap( virtual_base, HW_REGS_SPAN ) != 0 ) {
printf( "ERROR: munmap() failed...\n" );
close( fd );
return( 1 );
}
close(fd);
return 0;
} I connect the readdata [7:0] inputs to 8'b00000011 in the top level module. However, the signal I read into the HPS is always zero. Any help would be great. Thanks! Akshay