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 225

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

powered by: WebSVN 2.1.0

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