Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
13 years ago

Need help to add my own IP to a Nios II system

Hi,

I'm a beginner in electronic design. I have a DE2 with cyclone II, on which i installed a working nios II system (hello world, Led blinking are functioning).

I try to add my own IP (a simple adder) and connect it via altera slave bus. So i wrote this VHDL file :

-- my_ip.vhd
-- This file was auto-generated as a prototype implementation of a module
-- created in component editor.  It ties off all outputs to ground and
-- ignores all inputs.  It needs to be edited to make it do something
-- useful.
-- 
-- This file will not be automatically regenerated.  You should check it in
-- to your version control system if you want to keep it.
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity my_ip is
    port(
        write_data                : in    std_logic_vector(31 downto 0);
        clk                : in    std_logic;
        reset                : in    std_logic;
        i_write_ctrl                    : in    std_logic;
        chipselect                : in    std_logic;
        sum                : out    std_logic_vector(31 downto 0)
    );
end entity my_ip;
architecture rtl of my_ip is
    signal result    :    std_logic_vector(31 downto 0);
begin
    -- TODO: Auto-generated HDL template
    add : process(clk, reset)
    begin
        if (clk'event and clk = '1') then
            if (chipselect = '1' AND i_write_ctrl ='0') then
                result(0)    <=    write_data(0) xor write_data(1);
                result(1)    <=    write_data(0) and write_data(1);
            end if;
        end if;
    end process add;
    send : process(clk, reset)
    begin
    if (reset = '0') then
        sum    <= "00000000000000000000000000000000";
    elsif (clk'event and clk = '1') then
                sum    <=    result;
    end if;
    end process send;
end architecture rtl; -- of my_ip

I add it to spoc builder with component editor, specified the signal type and the interface of each signals, connected it to my clock and my cpu, and generated the files.

Finally after programming my card, i created a nios II application in eclipse. The signal of the switches are send to my_IP (the adder), and the result of the adder is send to a led. here is the code :


/*
 * main.c
 *
 *  Created on: 20 mars 2013
 */
# include <stdio.h># include "system.h"# include "altera_avalon_pio_regs.h"
int main()
{
    int i;
    int val_switch;
    int result;
    int val;
    int result2;
    while(1)
    {
        i = 0;
        val_switch = IORD_ALTERA_AVALON_PIO_DATA(SWITCH_PIO_BASE);
        printf("val_switch = %d \n", val_switch);
        val = val_switch;
        IOWR_ALTERA_AVALON_PIO_DATA(MY_IP_0_BASE, val);
        result = IORD_ALTERA_AVALON_PIO_DATA(MY_IP_0_BASE);
        result2 = result;
        printf("result = %d \n", result2);
        IOWR_ALTERA_AVALON_PIO_DATA(LED_RED_BASE, result2);
        
        while(i < 500000)
        {
            i++;
        }
    }
    return 0;
}

When i send the application to my card via Jtag, i can see on the console that val_switch depend on the position of my switches, but result doesn't change (and so the led doesn't light on).

I'm not sure that i can use the command iord_altera_avalon_pio_data for my IP. Can anyone help me with this?

Thank you very much and have a good day!
No RepliesBe the first to reply