FPGA, SoC, And CPLD Boards And Kits
FPGA Evaluation and Development Kits
5925 Discussions

Write value on Register not shown


​​Hi, I just build a qsys system as shown below




where I just wana write and read data to a simple 8 bit register which I wrote and instantiated in qsys as usererg8bit. Here is the verilog HDL code for that

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 a C application for 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

# 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 *~

 My c code compiled successfully now when I run my C application on Cyclone V arrow sockit board, it takes data input from user but after that doesn't show me the output.  Any ideas where am I wrong?

0 Kudos
1 Reply


For writing, you don’t need to check ‘read’ signal.

So, ‘read’ signal on top is not necessary.