(1) OpenGLCode
/*************************************** *****************************
* Module name: crazy_key
* Author: crazy bingo
* Device: ep2c8q208c8
* Version: Quartus II 10.1
* Date: 2011-3-2
* Description:
**************************************** *****************************/
Module crazy_key
(
// Aveon clock
Input csi_clk,
Input csi_rst_n,
// Aveon-mm
Input avs_chipselect,
Input [1:0] avs_address, // multiple of 4
// Input [1:0] avs_byteenable_n, // 128
Input avs_read,
Output [31: 0] avs_readdata, // 32bit CPU
// Input avs_write,
// Output [31: 0] avs_writedata, // 32bit CPU
// Aveon conducting it
Input [1:0] coe_data // 2 bits key
);
// Read
Reg [1:0] avs_readdata_r;
Always @ (posedge csi_clk or negedge csi_rst_n)
Begin
If (! Csi_rst_n)
Avs_readdata_r [1:0] <= 0;
Else if (avs_chipselect & avs_read & (avs_address = 0 ))
Avs_readdata_r [1:0] <= coe_data;
End
Assign avs_readdata = avs_readdata_r;
// Write
// Reg [1:0] avs_readdata_r;
// Always @ (posedge csi_clk or negedge csi_rst_n)
// Begin
// If (! Csi_rst_n)
// Avs_readdata_r <= 0;
// Else if (avs_chipselect & avs_read & (avs_address = 0) // For steady state
// Avs_readdata_r <= coe_data;
// End
// Assign avs_readdata = avs_readdata_r;
Endmodule
(2) How to import IP addresses to a Linux instance
(3) create a US us Project
Module sram_test
(
// Global CLK
Input CLK,
Input rst_n,
// SRAM Interface
Inout [15:0] sram_data,
Output [18:0] sram_addr,
Output sram_ce_n,
Output sram_we_n,
Output sram_oe_n,
Output sram_ub_n,
Output sram_lb_n,
// User interface
Input [1:0] key_data,
Output [1:0] led_data
);
Sram_test_core sram_test_core_inst
(
. CLK (CLK ),
. Reset_n (rst_n ),
. Coe_sram_addr_from_the_sram (sram_addr ),
. Coe_sram_ce_n_from_the_sram (sram_ce_n ),
. Coe_sram_dq_to_and_from_the_sram (sram_data ),
. Coe_sram_lb_n_from_the_sram (sram_lb_n ),
. Coe_sram_oe_n_from_the_sram (sram_oe_n ),
. Coe_sram_ub_n_from_the_sram (sram_ub_n ),
. Coe_sram_we_n_from_the_sram (sram_we_n ),
. Coe_data_to_the_key_data (key_data ),
. Coe_data_from_the_led_data (led_data)
);
(4) Build a nios2 Project
//----------------------------------------------------------
File "my_sopc.h"
# Ifndef my_sopc_h _
# Define my_sopc_h _
# Include "alt_types.h"
# Include "system. H"
# Define crazy_led_data
# Define crazy_key_data
// # Define crazy_lcd1602
//---------------------------------------------------------
# Ifdef crazy_led_data
# Define led_data_addr (led_data_base | (1 <31 ))
# Define led_data (* (volatile unsigned int *) led_data_addr)
# Endif
//---------------------------------------------------------
# Ifdef crazy_key_data
# Define key_data_addr (key_data_base | (1 <31 ))
# Define key_data (* (volatile unsigned int *) key_data_addr)
# Endif
//----------------------------------------------------------
File "nios2_main.v"
# Include <stdio. h>
# Include "system. H"
# Include "unistd. H"
# Include "Io. H"
# Include "my_sopc.h"
Alt_u8 key_scan (void)
{
Alt_u8 key_value = key_data;
If (key_value = 3)
Return 3;
Else
{
If (key_data = key_value)
{
Usleep (5000 );
If (key_data = key_value)
{
// While (key_data! = Key_value );
// Usleep (5000 );
// While (key_data! = Key_value );
Return key_value;
}
Else
Return 3;
}
Else
Return 3;
}
}
Int main ()
{
Printf ("hello from NiO II! \ N ");
While (1)
{
Led_data = ~ Key_scan ();
}
Return 0;
}
Run handware OK