Altera_Forum
Honored Contributor
12 years agoHow to implement very basic custom QSys component
I know this question has to have been posted and answered, but I can't find it in a way I can understand and solve my problem.
My effort is very basic and I'm new to the QSys way of FPGAs. Basically, I'm attempting to flash the LEDs of a De0 Nano from 'C'. I've divided the 8 LEDs into 3. Led7 is a VHDL heartbeat Led6..4 is a software controlled LED set via the standard altera Qsys PIO. Led3..0 a software controlled LED set via a custom avalon slave VHDL Qsys module Every thing compiles and programs fine. Led7, the heartbeat, is working fine. Led6..4 is working fine. Led3..0, my custom Qsys component, is not working. What have I done wrong? What am I missing? I've added the following VHDL component. ENTITY LGLed IS PORT( clk : in std_logic; reset_n : in std_logic; write : in std_logic; writedata : in std_logic_vector(7 downto 0); leds : out std_logic_vector(3 downto 0) ); END LGLed; -- Architecture Body ARCHITECTURE synth OF LGLed IS signal myleds : std_logic_vector(3 downto 0); BEGIN process(clk, reset_n) begin if(reset_n = '0')then myleds <= to_stdlogicvector(x"0"); else if ((write = '1') and rising_edge(clk))then myleds <= writedata(3 downto 0); end if; end if; leds <= myleds; end process; end synth; My C code is as follows: # include <stdio.h># include "sys/alt_stdio.h"# include "alt_types.h"# include "system.h"# include "altera_avalon_pio_regs.h" # define LEDDELAY 125000 int main() { int n1; int cnt=0; unsigned char *my_register = (unsigned char*)alt_remap_uncached((void*)LGLED_BASE,sizeof(alt_8)); printf("Hello from Nios II!!!!\n"); while(1) { for (n1=0; n1 < LEDDELAY; n1++) {} IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_GREEN_BASE, (cnt) & 0xF); // IOWR_ALTERA_AVALON_PIO_DATA(LGLED_BASE, (cnt) & 0xF); *my_register = (cnt) & 0xF; cnt++; } return 0; }