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

Subversion Repositories layer2

[/] [layer2/] [trunk/] [vhdl/] [pit/] [rtl/] [pit.vhd] - Blame information for rev 5

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

Line No. Rev Author Line
1 2 idiolatrie
--------------------------------------------------------------------------------
2
-- Programmable Interval Timer                                                --
3
--------------------------------------------------------------------------------
4
-- Copyright (C)2011  Mathias Hörtnagl <mathias.hoertnagl@gmail.comt>         --
5
--                                                                            --
6
-- This program is free software: you can redistribute it and/or modify       --
7
-- it under the terms of the GNU General Public License as published by       --
8
-- the Free Software Foundation, either version 3 of the License, or          --
9
-- (at your option) any later version.                                        --
10
--                                                                            --
11
-- This program is distributed in the hope that it will be useful,            --
12
-- but WITHOUT ANY WARRANTY; without even the implied warranty of             --
13
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              --
14
-- GNU General Public License for more details.                               --
15
--                                                                            --
16
-- You should have received a copy of the GNU General Public License          --
17
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.      --
18
--------------------------------------------------------------------------------
19
library ieee;
20
use ieee.std_logic_1164.all;
21
use ieee.numeric_std.all;
22
 
23
 
24
library work;
25
use work.iwb.all;
26
 
27
entity pit is
28
   port(
29
      si   : in  slave_in_t;
30
      so   : out slave_out_t;
31
   -- Non-Wishbone Signals
32
      intr : out std_logic
33
   );
34
end pit;
35
 
36
architecture rtl of pit is
37
 
38
   type state_t is (Idle, Count, Ack, Ack2);
39
   signal s, sin : state_t;
40
 
41
   signal n, nin : unsigned(31 downto 0);    -- Counter.
42
   signal l, lin : unsigned(31 downto 0);    -- Count limit set by the user.
43
begin
44
 
45
   -----------------------------------------------------------------------------
46
   -- PIT Control                                                             --
47
   -----------------------------------------------------------------------------
48
   nsl : process(s, l, n, si.stb, si.we, si.dat, si)
49
   begin
50
 
51
      sin  <= s;
52
      lin  <= l;
53
      nin  <= n;
54
 
55
      intr <= '0';
56
 
57
      case s is
58
 
59
         -- Wait for a WB write operation to trigger a new timer loop. The
60
         -- timer starts at 1 to count in the Idle state cycle.
61
         when Idle =>
62
            if wb_write(si) then
63
               nin <= x"00000000";
64
               lin <= unsigned(si.dat);
65
               sin <= Count;
66
            end if;
67
 
68
         when Count =>
69
            if n = l then
70
               sin <= Ack;
71
            else
72
               nin <= n + 1;
73
            end if;
74
 
75
         -- Set interrupt signal and wait for a WB write operation to reset.
76
         when Ack =>
77
            intr <= '1';
78
            if wb_read(si) then
79
               sin <= Ack2;
80
            end if;
81
 
82
         when Ack2 =>
83
            intr <= '1';
84
            if si.stb = '0' then
85
               sin <= Idle;
86
            end if;
87
 
88
      end case;
89
   end process;
90
 
91
   -- Reading while still counting returns the progress.
92
   so.dat <= std_logic_vector(n);
93
   so.ack <= si.stb;
94
 
95
   -----------------------------------------------------------------------------
96
   -- Registers                                                               --
97
   -----------------------------------------------------------------------------
98
   reg : process(si.clk)
99
   begin
100
      if rising_edge(si.clk) then
101
         s <= sin;
102
         n <= nin;
103
         l <= lin;
104
 
105
         if si.rst = '1' then
106
            s <= Idle;
107
         end if;
108
      end if;
109
   end process;
110
end rtl;

powered by: WebSVN 2.1.0

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