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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [status_led.vhd] - Blame information for rev 287

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 249 jshamlet
-- Copyright (c)2020 Jeremy Seth Henry
2
-- All rights reserved.
3
--
4
-- Redistribution and use in source and binary forms, with or without
5
-- modification, are permitted provided that the following conditions are met:
6
--     * Redistributions of source code must retain the above copyright
7
--       notice, this list of conditions and the following disclaimer.
8
--     * Redistributions in binary form must reproduce the above copyright
9
--       notice, this list of conditions and the following disclaimer in the
10
--       documentation and/or other materials provided with the distribution,
11
--       where applicable (as part of a user interface, debugging port, etc.)
12
--
13
-- THIS SOFTWARE IS PROVIDED BY JEREMY SETH HENRY ``AS IS'' AND ANY
14
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
-- DISCLAIMED. IN NO EVENT SHALL JEREMY SETH HENRY BE LIABLE FOR ANY
17
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
--
24
-- VHDL Units :  status_led
25
-- Description:  Provides a multi-state status LED controller
26
--
27
-- LED Modes:
28 251 jshamlet
-- 0x0 - LED is fully off
29
-- 0x1 - LED is fully on
30
-- 0x2 - LED is dimmed to 50%
31
-- 0x3 - LED Toggles at 1Hz
32
-- 0x4 - LED fades in and out
33 249 jshamlet
--
34
-- Revision History
35
-- Author          Date     Change
36
------------------ -------- ---------------------------------------------------
37
-- Seth Henry      05/24/20 Created as a separate sub-component
38
 
39
library ieee;
40
  use ieee.std_logic_1164.all;
41
  use ieee.std_logic_unsigned.all;
42
  use ieee.std_logic_arith.all;
43
  use ieee.std_logic_misc.all;
44
 
45
entity status_led is
46
generic(
47
  Reset_Level                : std_logic
48
);
49
port(
50
  Clock                      : in  std_logic;
51
  Reset                      : in  std_logic;
52
  LED_Mode                   : in  std_logic_vector(2 downto 0);
53
  LED_Out                    : out std_logic
54
);
55
end entity;
56
 
57
architecture behave of status_led is
58
 
59 251 jshamlet
  --  hold the supplied integer.
60
  function ceil_log2 (x : in natural) return natural is
61
    variable retval          : natural;
62
  begin
63
    retval                   := 1;
64
    while ((2**retval) - 1) < x loop
65
      retval                 := retval + 1;
66
    end loop;
67
    return retval;
68
  end function;
69 249 jshamlet
 
70 251 jshamlet
  signal Dim50Pct_Out        : std_logic := '0';
71 249 jshamlet
 
72 251 jshamlet
  constant TAP1              : integer := 16;
73
  constant TAP2              : integer := 21;
74
  constant TAP3              : integer := 22;
75
  constant TAP4              : integer := 23;
76
 
77
  constant Init_Seed         : std_logic_vector(23 downto 0) := x"000001";
78
 
79
  signal d0                  : std_logic := '0';
80
  signal LFSR_poly           : std_logic_vector(23 downto 0) := (others => '0');
81
 
82
  signal Cycle_Toggle        : std_logic;
83
 
84 249 jshamlet
  constant TIMER_MSB         : integer range 9 to 20 := 18;
85
 
86 251 jshamlet
  signal Fade_Timer1         : std_logic_vector(TIMER_MSB downto 0) :=
87
                                (others => '0');
88
  signal Fade_Timer2         : std_logic_vector(TIMER_MSB downto 0) :=
89
                                (others => '0');
90
  signal Fade_Out            : std_logic := '0';
91 249 jshamlet
 
92
begin
93
 
94
  Output_FF: process( Clock, Reset )
95
  begin
96
    if( Reset = Reset_Level )then
97
      LED_Out                <= '0';
98
    elsif( rising_edge(Clock) )then
99
      LED_Out                <= '0';
100
      case( LED_Mode )is
101
        when "001" =>
102
          LED_Out            <= '1';
103
        when "010" =>
104
          LED_Out            <= Dim50Pct_Out;
105
        when "011" =>
106 251 jshamlet
          LED_Out            <= Cycle_Toggle;
107 249 jshamlet
        when "100" =>
108
          LED_Out            <= Fade_out;
109
        when others => null;
110
      end case;
111
    end if;
112
  end process;
113
 
114 251 jshamlet
  d0                         <= LFSR_poly(TAP4) xnor LFSR_poly(TAP3) xnor
115
                                LFSR_poly(TAP2) xnor LFSR_poly(TAP1);
116
 
117 249 jshamlet
  Timer_proc: process( Clock, Reset )
118
  begin
119
    if( Reset = Reset_Level )then
120
      Dim50Pct_Out           <= '0';
121 251 jshamlet
      LFSR_poly              <= Init_Seed;
122
      Cycle_Toggle           <= '0';
123 249 jshamlet
      Fade_Timer1            <= (others => '0');
124
      Fade_Timer2            <= (others => '0');
125
      Fade_out               <= '0';
126
    elsif( rising_edge(Clock) )then
127
      Dim50Pct_Out           <= not Dim50Pct_Out;
128
 
129 251 jshamlet
      LFSR_poly              <= LFSR_poly(22 downto 0) & d0;
130
      if( LFSR_poly = Init_Seed )then
131
        Cycle_Toggle         <= not Cycle_Toggle;
132 249 jshamlet
      end if;
133
 
134
      Fade_Timer1            <= Fade_Timer1 - 1;
135
      Fade_Timer2            <= Fade_Timer2 - 1;
136
      if( or_reduce(Fade_Timer2) = '0' )then
137
        Fade_Timer2(TIMER_MSB downto TIMER_MSB - 8) <= (others => '1');
138
        Fade_Timer2(TIMER_MSB - 9 downto 0 )        <= (others => '0');
139
      end if;
140
      Fade_out               <= Fade_Timer1(TIMER_MSB) xor
141
                                Fade_Timer2(TIMER_MSB);
142
    end if;
143
  end process;
144
 
145
end architecture;

powered by: WebSVN 2.1.0

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