Altera_Forum
Honored Contributor
10 years agoNios problem with interfacing custom component
Hi,
I am a newbie to Altera/Nios and have followed some tutorial to build a Nios2 system. Now I am trying to build a custom component with interface to the Nios2, but I am having some trouble to get it work properly. The purpose of the component code is only to light up some leds (works standalone with hard coded values), but I am not able to get it work with data send from the Nios processor (all leds are turned on independent of the value send from the Nios2 processor). Hope someone can give me some tip on what I am doing wrong in my code. Here is my code: component: module light_avalon(clock, resetn, D, byteenable, Q); input clock, resetn; input [1:0] byteenable; input [15:0] D; output reg [7:0] Q; always @(posedge clock) begin Q[7:0] <= D[7:0]; end endmodule module light_avalon_interface(clock, resetn, writedata, readdata, write, read, byteenable, chipselect, Q_export); ///Signals for connecting to Avalon fabric input clock, resetn, read, write, chipselect; input [1:0] byteenable; input [15:0] writedata; output [15:0] readdata; ///Signals for exporting reg. contents outside system output [7:0] Q_export; wire [1:0] local_byteenable; wire [15:0] to_reg; wire [7:0] from_reg; assign to_reg = writedata; //assign to_reg = 8'hAA; //Test module code light_avalon(.clock(clock), .resetn(resetn), .D(to_reg), .byteenable(local_byteenable), .Q(from_reg)); //assign readdata[7:0] = from_reg[7:0]; assign Q_export = from_reg; endmodule nios2:From system.h: # define ALT_MODULE_CLASS_light_avalon_0 light_avalon # define LIGHT_AVALON_0_BASE 0x8c20 # define LIGHT_AVALON_0_IRQ -1 # define LIGHT_AVALON_0_IRQ_INTERRUPT_CONTROLLER_ID -1 # define LIGHT_AVALON_0_NAME "/dev/light_avalon_0" # define LIGHT_AVALON_0_SPAN 2 # define LIGHT_AVALON_0_TYPE "light_avalon"From Main: while( 1 ) { usleep(1000000); IOWR_16DIRECT(LIGHT_AVALON_0_BASE, 0, 0x00AA); }