OpenCores
URL https://opencores.org/ocsvn/tcp_ip_core_w_dhcp/tcp_ip_core_w_dhcp/trunk

Subversion Repositories tcp_ip_core_w_dhcp

[/] [tcp_ip_core_w_dhcp/] [trunk/] [led_mod.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 craighaywo
----------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer: 
4
-- 
5
-- Create Date:    22:48:34 12/08/2014 
6
-- Design Name: 
7
-- Module Name:    led_mod - Behavioral 
8
-- Project Name: 
9
-- Target Devices: 
10
-- Tool versions: 
11
-- Description: 
12
--
13
-- Dependencies: 
14
--
15
-- Revision: 
16
-- Revision 0.01 - File Created
17
-- Additional Comments: 
18
--
19
----------------------------------------------------------------------------------
20
library IEEE;
21
use IEEE.STD_LOGIC_1164.ALL;
22
use IEEE.NUMERIC_STD.ALL;
23
 
24
-- Uncomment the following library declaration if instantiating
25
-- any Xilinx primitives in this code.
26
--library UNISIM;
27
--use UNISIM.VComponents.all;
28
 
29
entity led_mod is
30
    Port ( CLK_IN                               : in  STD_LOGIC;
31
           LED_STATE_IN                 : in  STD_LOGIC_VECTOR (2 downto 0);
32
                          ERROR_CODE_IN         : in    STD_LOGIC_VECTOR (4 downto 0);
33
                          ERROR_CODE_EN_IN      : in    STD_LOGIC;
34
           LEDS_OUT                             : out  STD_LOGIC_VECTOR (1 downto 0);
35
 
36
                          CLK_1HZ_OUT                   : out STD_LOGIC);
37
end led_mod;
38
 
39
architecture Behavioral of led_mod is
40
 
41
subtype slv is std_logic_vector;
42
 
43
constant C_clk_div_1sec                 : std_logic_vector(27 downto 0) := X"5F5E100";
44
constant C_clk_div_1sec_test    : std_logic_vector(27 downto 0) := X"0000008";
45
constant C_heartbeat_first              : std_logic_vector(27 downto 0) := X"20583B0";
46
constant C_heartbeat_second     : std_logic_vector(27 downto 0) := X"16F5E10";
47
constant C_heartbeat_third              : std_logic_vector(27 downto 0) := X"10C4B40";
48
 
49
-- State info
50
constant C_off_state                    : std_logic_vector(2 downto 0) := "000";
51
constant C_heardbeat_state      : std_logic_vector(2 downto 0) := "001";
52
constant C_initializing_state : std_logic_vector(2 downto 0) := "010";
53
constant C_init_cmplt_state     : std_logic_vector(2 downto 0) := "011";
54
 
55
constant C_error_state                  : std_logic_vector(2 downto 0) := "111";
56
 
57
signal led_state                                        : std_logic_vector(2 downto 0) := "000";
58
signal leds                                             : std_logic_vector(1 downto 0) := "00";
59
 
60
signal clk_div_1sec_counter                                     : unsigned(27 downto 0) := (others => '0');
61
signal clk_div_1sec_en, led_error_mask          : std_logic := '0';
62
 
63
signal heartbeat : std_logic := '0';
64
 
65
signal error_code_buf, error_code_buf_inv : std_logic_vector(7 downto 0) := (others => '0');
66
 
67
begin
68
 
69
        LEDS_OUT <= leds;
70
        CLK_1HZ_OUT <= clk_div_1sec_en;
71
 
72
        process(CLK_IN)
73
        begin
74
                if rising_edge(CLK_IN) then
75
                        if clk_div_1sec_counter = X"0000000" then
76
                                clk_div_1sec_counter <= unsigned(C_clk_div_1sec);
77
                        else
78
                                clk_div_1sec_counter <= clk_div_1sec_counter - 1;
79
                        end if;
80
                        if clk_div_1sec_counter = X"0000000" then
81
                                clk_div_1sec_en <= '1';
82
                        else
83
                                clk_div_1sec_en <= '0';
84
                        end if;
85
                        if clk_div_1sec_en = '1' then
86
                                led_error_mask <= '1';
87
                        elsif clk_div_1sec_counter = unsigned('0' & C_clk_div_1sec(27 downto 1)) then
88
                                led_error_mask <= '0';
89
                        end if;
90
                        if clk_div_1sec_en = '1' then
91
                                heartbeat <= '0';
92
                        elsif clk_div_1sec_counter = unsigned(C_heartbeat_first) then
93
                                heartbeat <= '1';
94
                        elsif clk_div_1sec_counter = unsigned(C_heartbeat_second) then
95
                                heartbeat <= '0';
96
                        elsif clk_div_1sec_counter = unsigned(C_heartbeat_third) then
97
                                heartbeat <= '1';
98
                        end if;
99
                end if;
100
        end process;
101
 
102
        process(CLK_IN)
103
        begin
104
                if rising_edge(CLK_IN) then
105
                        led_state <= LED_STATE_IN;
106
 
107
                        case(led_state) is
108
                                when C_off_state =>
109
                                        leds(0) <= '0';
110
                                when C_heardbeat_state =>
111
                                        leds(0) <= heartbeat;
112
                                when C_error_state =>
113
                                        leds(0) <= error_code_buf(7) and led_error_mask;
114
 
115
                                when others =>
116
                                        leds(0) <= '0';
117
                        end case;
118
 
119
                        case(led_state) is
120
                                when C_off_state =>
121
                                        leds(1) <= '0';
122
                                when C_heardbeat_state =>
123
                                        leds(1) <= '0';
124
                                when C_error_state =>
125
                                        leds(1) <= error_code_buf_inv(7) and led_error_mask;
126
 
127
                                when others =>
128
                                        leds(1) <= '0';
129
                        end case;
130
                end if;
131
        end process;
132
 
133
        process(CLK_IN)
134
        begin
135
                if rising_edge(CLK_IN) then
136
                        if ERROR_CODE_EN_IN = '1' then
137
                                error_code_buf <= "000" & ERROR_CODE_IN;
138
                                error_code_buf_inv <= "000" & not(ERROR_CODE_IN);
139
                        elsif clk_div_1sec_en = '1' then
140
                                if led_state = C_error_state then
141
                                        error_code_buf(7 downto 1) <= error_code_buf(6 downto 0);
142
                                        error_code_buf(0) <= error_code_buf(7);
143
                                        error_code_buf_inv(7 downto 1) <= error_code_buf_inv(6 downto 0);
144
                                        error_code_buf_inv(0) <= error_code_buf_inv(7);
145
                                end if;
146
                        end if;
147
                end if;
148
        end process;
149
 
150
end Behavioral;
151
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.