1 -------------------------------------------------------------------------------
2 --! @file register_interface.vhd
3 --! @author Marc Kossmann
4 --! @author Michael Riedel
8 --! @brief Register component
9 --! @details Provides the `ctrlReg`, `speedReg`, `stepsReg` registers.
10 --! The `ctrlReg` can be set and cleared bitwise with the
11 --! `ctrlSetReg` and `ctrlClrReg`.
12 --! @details Addresses for register-access:
13 --! | address | register |
14 --! |:-------:|:-----------|
15 --! | `000` | `ctrlReg` |
16 --! | `001` |`ctrlSetReg`|
17 --! | `010` |`ctrlClrReg`|
18 --! | `011` |`speedReg` |
19 --! | `100` |`stepsReg` |
21 --! @details v0.1.0 06.11.2014 Kossmann
23 --! @details v0.1.1 07.11.2014 Kossmann
24 --! - finished reset_n task
25 --! @details v0.1.2 17.11.2014 Riedel
26 --! - corrected formatting
27 --! - improved documentation
28 --! @details v1.0.0 18.11.2014 Riedel & Kossmann
29 --! - verified functionality -> release MS2
30 --! @details v1.0.1 19.11.2014 Kossmann
31 --! - changed register write implementation to more save version
32 --! @details v1.0.2 21.11.2014 Riedel & Kossmann
33 --! - removed ctrlSetReg and ctrlClrReg signals
34 --! - added register access for mcu
35 --! @details v1.0.3 01.12.2014 Kossmann
36 --! - reacting to rising edge of ir signal
37 --! @details v1.0.4 05.12.2014 Riedel
38 --! - corrected formatting and indention
39 --! @details v2.0.0 05.12.2014 Riedel & Kossmann
40 --! - release milestone 3b
41 -------------------------------------------------------------------------------
43 --! Use Standard Library
45 --! Use Logic Elements
46 USE ieee.STD_LOGIC_1164.
all;
47 --! Use Conversion Functions
48 USE ieee.STD_LOGIC_signed.
all;
50 --! @brief Register Interface-Component
55 reset_n : IN ;
--! Avalon reset the component
56 ce_n : IN ;
--! Avalon chip enable
57 read_n : IN ;
--! Avalon set read-request
58 write_n : IN ;
--! Avalon set write-request
59 addr : IN (2 DOWNTO 0);
--! Avalon address bus (selects the register)
60 write_data : IN (31 DOWNTO 0);
--! Avalon write data to selected register
61 read_data : OUT (31 DOWNTO 0);
--! Avalon read data from selected register
62 irq : OUT ;
--! Avalon IRQ line
63 greenleds : OUT (7 DOWNTO 0);
--! external: green leds
64 redleds : OUT (7 DOWNTO 0);
--! external: red leds
65 run : OUT ;
--! enable signal for mcu
67 mode : OUT (3 DOWNTO 0);
--! output of Mode bits for mcu
68 speed : OUT (2 DOWNTO 0);
--! output of speedReg for mcu
69 steps : IN (31 DOWNTO 0);
--! input for stepsReg for mcu
70 ir : IN --! input request of mcu
72 END register_interface;
74 --! @brief Architecture of register_interface
75 --! @details realized components:
76 --! - all five registers
77 --! - 3 green LEDs showing speedReg with 0 .. 2
78 --! - 8 red LEDs showing ctrlReg
79 --! - generating motor interrupt
82 --! internal signal representing the registers
83 SIGNAL ctrlReg : (7 DOWNTO 0);
84 SIGNAL speedReg : (2 DOWNTO 0);
85 SIGNAL stepsReg : (31 DOWNTO 0);
88 --! @brief processing the tasks:
89 --! - interface to NIOS-processor
90 --! - writing registers
91 --! - reading registers
92 --! - implementing set and clear functionality
95 -- ctrlReg Register Write
97 ctrlReg <= (others => '0');
98 ELSIF (rising_edge(clock)) THEN
101 IF(ir = '1') THEN -- set IR-bit in ctrlReg
106 ctrlReg <= write_data(7 DOWNTO 0);
-- overwrite complete ctrlReg
108 ctrlReg <= ctrlReg or write_data(7 DOWNTO 0);
-- set ctrlReg bitwise
110 ctrlReg <= ctrlReg and (not write_data(7 DOWNTO 0));
-- clr ctrlReg
114 -- speedReg Register Write
116 speedReg <= (others => '0');
117 ELSIF (rising_edge(clock)) THEN
121 speedReg <= speedReg;
125 -- stepsReg Register Write
127 stepsReg <= (others => '0');
128 ELSIF (rising_edge(clock)) THEN
129 stepsReg <= stepsReg;
130 IF(CONV_INTEGER(steps) /= 0) THEN -- write stepsReg from mcu when mcu input is not '0'
138 -- Processor reads from Register
139 read_data <= (others => '0');
-- unused bits to 0
149 read_data(31 DOWNTO 0) <= (others => '0');
156 irq <= ctrlReg(6) and ctrlReg(7);
158 -- clone ctrlReg to red leds
161 -- clone speedReg to green leds
163 greenleds(7 DOWNTO 3) <= (others => '0');
168 mode <= ctrlReg(5 DOWNTO 2);
171 END my_register_interface;
in ce_nSTD_LOGIC
Avalon chip enable.
in read_nSTD_LOGIC
Avalon set read-request.
out redledsSTD_LOGIC_VECTOR(7 DOWNTO0)
external: red leds
Register Interface-Component.
_library_ ieeeieee
Use Standard Library.
in write_nSTD_LOGIC
Avalon set write-request.
out runSTD_LOGIC
enable signal for mcu
out speedSTD_LOGIC_VECTOR(2 DOWNTO0)
output of speedReg for mcu
in addrSTD_LOGIC_VECTOR(2 DOWNTO0)
Avalon address bus (selects the register)
out irqSTD_LOGIC
Avalon IRQ line.
out read_dataSTD_LOGIC_VECTOR(31 DOWNTO0)
Avalon read data from selected register.
in reset_nSTD_LOGIC
Avalon reset the component.
out greenledsSTD_LOGIC_VECTOR(7 DOWNTO0)
external: green leds
in write_dataSTD_LOGIC_VECTOR(31 DOWNTO0)
Avalon write data to selected register.
in clockSTD_LOGIC
Avalon clock.
in stepsSTD_LOGIC_VECTOR(31 DOWNTO0)
input for stepsReg for mcu
out directionSTD_LOGIC
direction signal for mcu
in irSTD_LOGIC
input request of mcu
out modeSTD_LOGIC_VECTOR(3 DOWNTO0)
output of Mode bits for mcu