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 244

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

Line No. Rev Author Line
1 194 jshamlet
-- Copyright (c)2006, 2016, 2019, 2020 Jeremy Seth Henry
2 180 jshamlet
-- 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 194 jshamlet
-- (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 180 jshamlet
--
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 224 jshamlet
-- Seth Henry      04/16/20 Modified to use Open8  bus record
43 244 jshamlet
-- Seth Henry      05/18/20 Added write qualification input
44 180 jshamlet
 
45
library ieee;
46
  use ieee.std_logic_1164.all;
47
  use ieee.std_logic_unsigned.all;
48
  use ieee.std_logic_arith.all;
49 191 jshamlet
  use ieee.std_logic_misc.all;
50 180 jshamlet
 
51
library work;
52
  use work.open8_pkg.all;
53
 
54
entity o8_status_led is
55
generic(
56 217 jshamlet
  Address                    : ADDRESS_TYPE
57 180 jshamlet
);
58
port(
59 223 jshamlet
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
60 244 jshamlet
  Write_Qual                 : in  std_logic := '1';
61 217 jshamlet
  Rd_Data                    : out DATA_TYPE;
62 180 jshamlet
  --
63 217 jshamlet
  LED_Out                    : out std_logic
64 180 jshamlet
);
65
end entity;
66
 
67
architecture behave of o8_status_led is
68
 
69 224 jshamlet
  alias Clock                is Open8_Bus.Clock;
70
  alias Reset                is Open8_Bus.Reset;
71
 
72 217 jshamlet
  constant User_Addr         : std_logic_vector(15 downto 0)
73
                               := Address(15 downto 0);
74 223 jshamlet
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 0);
75 217 jshamlet
  signal Addr_Match          : std_logic;
76 244 jshamlet
 
77
  signal Wr_En_d             : std_logic := '0';
78
  signal Wr_En_q             : std_logic := '0';
79
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
80
  signal Wr_Data_q           : DATA_TYPE := x"00";
81
  signal Rd_En_d             : std_logic := '0';
82
  signal Rd_En_q             : std_logic := '0';
83
 
84 217 jshamlet
  signal LED_Mode            : std_logic_vector(2 downto 0);
85 180 jshamlet
 
86 217 jshamlet
  signal Dim50Pct_Out        : std_logic;
87 180 jshamlet
 
88 217 jshamlet
  signal Half_Hz_Timer       : std_logic_vector(15 downto 0);
89
  constant HALF_HZ_PRD       : std_logic_vector(15 downto 0) :=
90
                                conv_std_logic_vector(500000,16);
91
  signal One_Hz_Out          : std_logic;
92 180 jshamlet
 
93 217 jshamlet
  constant TIMER_MSB         : integer range 9 to 20 := 18;
94 180 jshamlet
 
95 217 jshamlet
  signal Fade_Timer1         : std_logic_vector(TIMER_MSB downto 0);
96
  signal Fade_Timer2         : std_logic_vector(TIMER_MSB downto 0);
97
  signal Fade_Out            : std_logic;
98 180 jshamlet
 
99
begin
100
 
101 217 jshamlet
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
102 244 jshamlet
  Wr_En_d                    <= Addr_Match and Open8_Bus.Wr_En;
103
  Rd_En_d                    <= Addr_Match and Open8_Bus.Rd_En;
104 180 jshamlet
 
105
  io_reg: process( Clock, Reset )
106
  begin
107
    if( Reset = Reset_Level )then
108 244 jshamlet
      Wr_En_q                <= '0';
109
      Wr_Data_q              <= x"00";
110
      Rd_En_q                <= '0';
111
      Rd_Data                <= OPEN8_NULLBUS;
112 217 jshamlet
      LED_Mode               <= (others => '0');
113 180 jshamlet
    elsif( rising_edge( Clock ) )then
114 244 jshamlet
      Wr_En_q                <= Wr_En_d;
115
      Wr_Data_q              <= Wr_Data_d;
116
      if( Wr_En_q = '1' and Write_Qual = '1' )then
117
        LED_Mode             <= Wr_Data_q(2 downto 0);
118 180 jshamlet
      end if;
119
 
120 244 jshamlet
      Rd_En_q                <= Rd_En_d;
121 217 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
122 244 jshamlet
      if( Rd_En_q = '1' )then
123 217 jshamlet
        Rd_Data              <= "00000" & LED_Mode;
124 180 jshamlet
      end if;
125
 
126
    end if;
127
  end process;
128 191 jshamlet
 
129 180 jshamlet
  Output_FF: process( Clock, Reset )
130
  begin
131
    if( Reset = Reset_Level )then
132 217 jshamlet
      LED_Out                <= '0';
133 180 jshamlet
    elsif( rising_edge(Clock) )then
134 217 jshamlet
      LED_Out                <= '0';
135 180 jshamlet
      case( LED_Mode )is
136
        when "001" =>
137 217 jshamlet
          LED_Out            <= '1';
138 180 jshamlet
        when "010" =>
139 217 jshamlet
          LED_Out            <= Dim50Pct_Out;
140 180 jshamlet
        when "011" =>
141 217 jshamlet
          LED_Out            <= One_Hz_Out;
142 180 jshamlet
        when "100" =>
143 217 jshamlet
          LED_Out            <= Fade_out;
144 180 jshamlet
        when others => null;
145
      end case;
146
    end if;
147
  end process;
148
 
149
  Timer_proc: process( Clock, Reset )
150
  begin
151
    if( Reset = Reset_Level )then
152 217 jshamlet
      Dim50Pct_Out           <= '0';
153
      Half_Hz_Timer          <= (others => '0');
154
      One_Hz_Out             <= '0';
155
      Fade_Timer1            <= (others => '0');
156
      Fade_Timer2            <= (others => '0');
157
      Fade_out               <= '0';
158 180 jshamlet
    elsif( rising_edge(Clock) )then
159 217 jshamlet
      Dim50Pct_Out           <= not Dim50Pct_Out;
160 180 jshamlet
 
161 217 jshamlet
      Half_Hz_Timer          <= Half_Hz_Timer - 1;
162 180 jshamlet
      if( Half_Hz_Timer = 0 )then
163 217 jshamlet
        Half_Hz_Timer        <= HALF_HZ_PRD;
164
        One_Hz_Out           <= not One_Hz_Out;
165 180 jshamlet
      end if;
166
 
167 217 jshamlet
      Fade_Timer1            <= Fade_Timer1 - 1;
168
      Fade_Timer2            <= Fade_Timer2 - 1;
169 180 jshamlet
      if( or_reduce(Fade_Timer2) = '0' )then
170
        Fade_Timer2(TIMER_MSB downto TIMER_MSB - 8) <= (others => '1');
171
        Fade_Timer2(TIMER_MSB - 9 downto 0 )        <= (others => '0');
172
      end if;
173 217 jshamlet
      Fade_out               <= Fade_Timer1(TIMER_MSB) xor
174
                                Fade_Timer2(TIMER_MSB);
175 180 jshamlet
    end if;
176
  end process;
177
 
178
end architecture;

powered by: WebSVN 2.1.0

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