Hi,
I just made the following qsys system where I just want to read and write data to my register.
Here is my verilog code for the 8 bit register (userdefined8bitreg) which I just simply want to write and read from
module userreg8bit(
input write,
input [7:0] writedata,
input read,
output [7:0] readdata,
input clk,
input reset
);
reg [7:0] Regreaddata;
assign readdata=Regreaddata;
always @ (posedge clk)
begin
if(reset)
begin
Regreaddata<=0;
end
else if(write)
begin
if(read)
begin
Regreaddata<=writedata;
end
end
end
endmodule
Now, I wrote simple C program for my HPS as
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "C:\altera\15.1\embedded\ip\altera\hps\altera_hps\hwlib\include\hwlib.h"
#include "C:\altera\15.1\embedded\ip\altera\hps\altera_hps\hwlib\include\soc_cv_av\socal\socal.h"
#include "C:\altera\15.1\embedded\ip\altera\hps\altera_hps\hwlib\include\soc_cv_av\socal\hps.h"
#include "C:\altera\15.1\embedded\ip\altera\hps\altera_hps\hwlib\include\soc_cv_av\socal\alt_gpio.h"
#include "D:\masterarbeit3\HPSFPGAFIFO\hps_0.h"
#define REG_BASE 0xFF200000 /*LWFPGA SLAVE Address*/
#define REG_SPAN 0x00200000 /*LWFPGA SLAVE SPAN*/
* volatile unsigned char *reg_addr; /*this is the pointer that writes to the register. This is our write input*/
void* virtual_base; /*pointer to open device memory file*/
int main ()
{
* int fd = EXIT_FAILURE;
int value; /*this is input value to the register*/
unsigned char regvalue;
* printf("Please enter a number from 1 to 15: ");
scanf("%d",&value);
printf("you entered the value :%d",value);
fd=open("/dev/mem",(O_RDWR|O_SYNC));
if (fd < 0) {
perror("open");
exit(EXIT_FAILURE);
}
* virtual_base=mmap(NULL,REG_SPAN,(PROT_READ|PROT_WRITE),MAP_SHARED,fd,REG_BASE);
* reg_addr = (unsigned char *) (virtual_base+USERREG8BIT_0_BASE);
* /*writing the value*/
*reg_addr=value;
/*reading the value back*/
regvalue=*reg_addr;
printf("%c\n",regvalue);
* return 0;
}
Here is my make file which i am using to compile my c code
#
TARGET = HPSFPGAFIFO
#
CROSS_COMPILE = arm-linux-gnueabihf-
ALT_DEVICE_FAMILY ?= soc_cv_av
CFLAGS := -g $(OFLAG) -Wall -Werror -std=c99 $(MULTILIBFLAGS) -I$(HWLIBS_ROOT)/include -I$(HWLIBS_ROOT)/include -D$(ALT_DEVICE_FAMILY)
ALL_HWLIBS_SRC = $(wildcard $(HWLIBS_ROOT)/src/hwmgr/*.c) $(wildcard $(HWLIBS_ROOT)/src/hwmgr/$(ALT_DEVICE_FAMILY)/*.c $(wildcard $(HWLIBS_ROOT)/src/utils/*.c))
LDFLAGS = -g -Wall
CC = $(CROSS_COMPILE)gcc
ARCH= arm
build: $(TARGET)
$(TARGET): HPSFPGAFIFO.o
$(CC) $(LDFLAGS) $^ -o $@
%.o : %.c
$(CC) $(CFLAGS) -c $< -o $@
.PHONY: clean
clean:
rm -f $(TARGET) *.a *.o *~
Now when I run this c program on my Arrow Socket board, it doesn’t give me back on written data. as you can also see in the figure below?
Any ideas? why i am not able to read back my written data?