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 217

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
 
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 191 jshamlet
  use ieee.std_logic_misc.all;
48 180 jshamlet
 
49
library work;
50
  use work.open8_pkg.all;
51
 
52
entity o8_status_led is
53
generic(
54 217 jshamlet
  Reset_Level                : std_logic;
55
  Address                    : ADDRESS_TYPE
56 180 jshamlet
);
57
port(
58 217 jshamlet
  Clock                      : in  std_logic;
59
  Reset                      : in  std_logic;
60 180 jshamlet
  --
61 217 jshamlet
  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 180 jshamlet
  --
67 217 jshamlet
  LED_Out                    : out std_logic
68 180 jshamlet
);
69
end entity;
70
 
71
architecture behave of o8_status_led is
72
 
73 217 jshamlet
  constant User_Addr         : std_logic_vector(15 downto 0)
74
                               := Address(15 downto 0);
75
  alias  Comp_Addr           is Bus_Address(15 downto 0);
76
  signal Addr_Match          : std_logic;
77
  signal Wr_En               : std_logic;
78
  signal Wr_Data_q           : std_logic_vector(2 downto 0);
79
  signal LED_Mode            : std_logic_vector(2 downto 0);
80
  signal Rd_En               : std_logic;
81 180 jshamlet
 
82 217 jshamlet
  signal Dim50Pct_Out        : std_logic;
83 180 jshamlet
 
84 217 jshamlet
  signal Half_Hz_Timer       : std_logic_vector(15 downto 0);
85
  constant HALF_HZ_PRD       : std_logic_vector(15 downto 0) :=
86
                                conv_std_logic_vector(500000,16);
87
  signal One_Hz_Out          : std_logic;
88 180 jshamlet
 
89 217 jshamlet
  constant TIMER_MSB         : integer range 9 to 20 := 18;
90 180 jshamlet
 
91 217 jshamlet
  signal Fade_Timer1         : std_logic_vector(TIMER_MSB downto 0);
92
  signal Fade_Timer2         : std_logic_vector(TIMER_MSB downto 0);
93
  signal Fade_Out            : std_logic;
94 180 jshamlet
 
95
begin
96
 
97 217 jshamlet
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
98 180 jshamlet
 
99
  io_reg: process( Clock, Reset )
100
  begin
101
    if( Reset = Reset_Level )then
102 217 jshamlet
      Wr_En                  <= '0';
103
      Wr_Data_q              <= (others => '0');
104
      LED_Mode               <= (others => '0');
105
      Rd_En                  <= '0';
106
      Rd_Data                <= OPEN8_NULLBUS;
107 180 jshamlet
    elsif( rising_edge( Clock ) )then
108 217 jshamlet
      Wr_En                  <= Addr_Match and Wr_Enable;
109
      Wr_Data_q              <= Wr_Data(2 downto 0);
110 180 jshamlet
      if( Wr_En = '1' )then
111 217 jshamlet
        LED_Mode             <= Wr_Data_q;
112 180 jshamlet
      end if;
113
 
114 217 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
115
      Rd_En                  <= Addr_Match and Rd_Enable;
116 180 jshamlet
      if( Rd_En = '1' )then
117 217 jshamlet
        Rd_Data              <= "00000" & LED_Mode;
118 180 jshamlet
      end if;
119
 
120
    end if;
121
  end process;
122 191 jshamlet
 
123 180 jshamlet
  Output_FF: process( Clock, Reset )
124
  begin
125
    if( Reset = Reset_Level )then
126 217 jshamlet
      LED_Out                <= '0';
127 180 jshamlet
    elsif( rising_edge(Clock) )then
128 217 jshamlet
      LED_Out                <= '0';
129 180 jshamlet
      case( LED_Mode )is
130
        when "001" =>
131 217 jshamlet
          LED_Out            <= '1';
132 180 jshamlet
        when "010" =>
133 217 jshamlet
          LED_Out            <= Dim50Pct_Out;
134 180 jshamlet
        when "011" =>
135 217 jshamlet
          LED_Out            <= One_Hz_Out;
136 180 jshamlet
        when "100" =>
137 217 jshamlet
          LED_Out            <= Fade_out;
138 180 jshamlet
        when others => null;
139
      end case;
140
    end if;
141
  end process;
142
 
143
  Timer_proc: process( Clock, Reset )
144
  begin
145
    if( Reset = Reset_Level )then
146 217 jshamlet
      Dim50Pct_Out           <= '0';
147
      Half_Hz_Timer          <= (others => '0');
148
      One_Hz_Out             <= '0';
149
      Fade_Timer1            <= (others => '0');
150
      Fade_Timer2            <= (others => '0');
151
      Fade_out               <= '0';
152 180 jshamlet
    elsif( rising_edge(Clock) )then
153 217 jshamlet
      Dim50Pct_Out           <= not Dim50Pct_Out;
154 180 jshamlet
 
155 217 jshamlet
      Half_Hz_Timer          <= Half_Hz_Timer - 1;
156 180 jshamlet
      if( Half_Hz_Timer = 0 )then
157 217 jshamlet
        Half_Hz_Timer        <= HALF_HZ_PRD;
158
        One_Hz_Out           <= not One_Hz_Out;
159 180 jshamlet
      end if;
160
 
161 217 jshamlet
      Fade_Timer1            <= Fade_Timer1 - 1;
162
      Fade_Timer2            <= Fade_Timer2 - 1;
163 180 jshamlet
      if( or_reduce(Fade_Timer2) = '0' )then
164
        Fade_Timer2(TIMER_MSB downto TIMER_MSB - 8) <= (others => '1');
165
        Fade_Timer2(TIMER_MSB - 9 downto 0 )        <= (others => '0');
166
      end if;
167 217 jshamlet
      Fade_out               <= Fade_Timer1(TIMER_MSB) xor
168
                                Fade_Timer2(TIMER_MSB);
169 180 jshamlet
    end if;
170
  end process;
171
 
172
end architecture;

powered by: WebSVN 2.1.0

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