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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_status_led.vhd] - Blame information for rev 180

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

Line No. Rev Author Line
1 180 jshamlet
-- Copyright (c)2006, 2016, 2019 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 THIS
22
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
--
24
-- VHDL Units :  o8_status_led
25
-- Description:  Provides a multi-state status LED controller
26
--
27
-- Register Map:
28
-- Offset  Bitfield Description                        Read/Write
29
--   0x00  -----AAA LED Mode (2:0)                     (RW)
30
--
31
-- LED Modes:
32
-- 0x00 - LED is fully off
33
-- 0x01 - LED is fully on
34
-- 0x02 - LED is dimmed to 50%
35
-- 0x03 - LED Toggles at 1Hz
36
-- 0x04 - LED fades in and out
37
--
38
-- Revision History
39
-- Author          Date     Change
40
------------------ -------- ---------------------------------------------------
41
-- Seth Henry      12/20/19 Design Start
42
 
43
library ieee;
44
  use ieee.std_logic_1164.all;
45
  use ieee.std_logic_unsigned.all;
46
  use ieee.std_logic_arith.all;
47
  use ieee.std_logic_misc.all;
48
 
49
library work;
50
  use work.open8_pkg.all;
51
 
52
entity o8_status_led is
53
generic(
54
  Reset_Level           : std_logic;
55
  Address               : ADDRESS_TYPE
56
);
57
port(
58
  Clock                 : in  std_logic;
59
  Reset                 : in  std_logic;
60
  --
61
  Bus_Address           : in  ADDRESS_TYPE;
62
  Wr_Enable             : in  std_logic;
63
  Wr_Data               : in  DATA_TYPE;
64
  Rd_Enable             : in  std_logic;
65
  Rd_Data               : out DATA_TYPE;
66
  --
67
  LED_Out               : out std_logic
68
);
69
end entity;
70
 
71
architecture behave of o8_status_led is
72
 
73
  function ceil_log2 (x : in natural) return natural is
74
    variable retval     : natural;
75
  begin
76
    retval              := 1;
77
    while ((2**retval) - 1) < x loop
78
      retval            := retval + 1;
79
    end loop;
80
    return retval;
81
  end function;
82
 
83
  constant User_Addr    : std_logic_vector(15 downto 0)
84
                          := Address(15 downto 0);
85
  alias  Comp_Addr      is Bus_Address(15 downto 0);
86
  signal Addr_Match     : std_logic;
87
  signal Wr_En          : std_logic;
88
  signal Wr_Data_q      : std_logic_vector(2 downto 0);
89
  signal LED_Mode       : std_logic_vector(2 downto 0);
90
  signal Rd_En          : std_logic;
91
 
92
  signal Dim50Pct_Out   : std_logic;
93
 
94
  signal Half_Hz_Timer  : std_logic_vector(15 downto 0);
95
  constant HALF_HZ_PRD  : std_logic_vector(15 downto 0) :=
96
                           conv_std_logic_vector(500000,16);
97
  signal One_Hz_Out     : std_logic;
98
 
99
  constant TIMER_MSB    : integer range 9 to 20 := 18;
100
 
101
  signal Fade_Timer1    : std_logic_vector(TIMER_MSB downto 0);
102
  signal Fade_Timer2    : std_logic_vector(TIMER_MSB downto 0);
103
  signal Fade_Out       : std_logic;
104
 
105
begin
106
 
107
  Addr_Match            <= '1' when Comp_Addr = User_Addr else '0';
108
 
109
  io_reg: process( Clock, Reset )
110
  begin
111
    if( Reset = Reset_Level )then
112
      Wr_En             <= '0';
113
      Wr_Data_q         <= (others => '0');
114
      LED_Mode          <= (others => '0');
115
      Rd_En             <= '0';
116
      Rd_Data           <= x"00";
117
    elsif( rising_edge( Clock ) )then
118
      Wr_En             <= Addr_Match and Wr_Enable;
119
      Wr_Data_q         <= Wr_Data(2 downto 0);
120
      if( Wr_En = '1' )then
121
        LED_Mode        <= Wr_Data_q;
122
      end if;
123
 
124
      Rd_Data           <= (others => '0');
125
      Rd_En             <= Addr_Match and Rd_Enable;
126
      if( Rd_En = '1' )then
127
        Rd_Data         <= "00000" & LED_Mode;
128
      end if;
129
 
130
    end if;
131
  end process;
132
 
133
  Output_FF: process( Clock, Reset )
134
  begin
135
    if( Reset = Reset_Level )then
136
      LED_Out           <= '0';
137
    elsif( rising_edge(Clock) )then
138
      LED_Out           <= '0';
139
      case( LED_Mode )is
140
        when "001" =>
141
          LED_Out       <= '1';
142
        when "010" =>
143
          LED_Out       <= Dim50Pct_Out;
144
        when "011" =>
145
          LED_Out       <= One_Hz_Out;
146
        when "100" =>
147
          LED_Out       <= Fade_out;
148
        when others => null;
149
      end case;
150
    end if;
151
  end process;
152
 
153
  Timer_proc: process( Clock, Reset )
154
  begin
155
    if( Reset = Reset_Level )then
156
      Dim50Pct_Out      <= '0';
157
      Half_Hz_Timer     <= (others => '0');
158
      One_Hz_Out        <= '0';
159
      Fade_Timer1       <= (others => '0');
160
      Fade_Timer2       <= (others => '0');
161
      Fade_out          <= '0';
162
    elsif( rising_edge(Clock) )then
163
      Dim50Pct_Out      <= not Dim50Pct_Out;
164
 
165
      Half_Hz_Timer     <= Half_Hz_Timer - 1;
166
      if( Half_Hz_Timer = 0 )then
167
        Half_Hz_Timer   <= HALF_HZ_PRD;
168
        One_Hz_Out      <= not One_Hz_Out;
169
      end if;
170
 
171
      Fade_Timer1       <= Fade_Timer1 - 1;
172
      Fade_Timer2       <= Fade_Timer2 - 1;
173
      if( or_reduce(Fade_Timer2) = '0' )then
174
        Fade_Timer2(TIMER_MSB downto TIMER_MSB - 8) <= (others => '1');
175
        Fade_Timer2(TIMER_MSB - 9 downto 0 )        <= (others => '0');
176
      end if;
177
      Fade_out          <= Fade_Timer1(TIMER_MSB) xor Fade_Timer2(TIMER_MSB);
178
    end if;
179
  end process;
180
 
181
end architecture;

powered by: WebSVN 2.1.0

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