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

Subversion Repositories ppx16

[/] [ppx16/] [trunk/] [rtl/] [vhdl/] [PPX_PCS.vhd] - Blame information for rev 22

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 jesus
--
2
-- PIC16xx compatible microcontroller core
3
--
4 11 jesus
-- Version : 0222
5 3 jesus
--
6
-- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
7
--
8
-- All rights reserved
9
--
10
-- Redistribution and use in source and synthezised forms, with or without
11
-- modification, are permitted provided that the following conditions are met:
12
--
13
-- Redistributions of source code must retain the above copyright notice,
14
-- this list of conditions and the following disclaimer.
15
--
16
-- Redistributions in synthesized form must reproduce the above copyright
17
-- notice, this list of conditions and the following disclaimer in the
18
-- documentation and/or other materials provided with the distribution.
19
--
20
-- Neither the name of the author nor the names of other contributors may
21
-- be used to endorse or promote products derived from this software without
22
-- specific prior written permission.
23
--
24
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
28
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
-- POSSIBILITY OF SUCH DAMAGE.
35
--
36
-- Please report bugs to the author, but before you do so, please
37
-- make sure that this is not a derivative work and that
38
-- you have the latest version of this file.
39
--
40
-- The latest version of this file can be found at:
41
--      http://www.opencores.org/cvsweb.shtml/t51/
42
--
43
-- Limitations :
44
--
45
-- File history :
46
--
47
 
48
library IEEE;
49
use IEEE.std_logic_1164.all;
50
use IEEE.numeric_std.all;
51
 
52
entity PPX_PCS is
53
        generic(
54
                PC_Width                : integer;
55
                StackAddrWidth  : integer;
56
                TopBoot                 : boolean
57
        );
58
        port(
59
                Clk                             : in std_logic;
60
                Reset_n                 : in std_logic;
61
                CS                              : in std_logic;
62
                Wr                              : in std_logic;
63
                Data_In                 : in std_logic_vector(7 downto 0);
64
                Addr_In                 : in std_logic_vector(PC_Width - 3 downto 0);
65
                PCLATH                  : in std_logic_vector(4 downto 0);
66
                STATUS                  : in std_logic_vector(6 downto 5);
67
                NPC                             : out std_logic_vector(PC_Width - 1 downto 0);
68
                Int                             : in std_logic;
69
                Sleep                   : in std_logic;
70
                Push                    : in std_logic;
71
                Pop                             : in std_logic;
72
                Goto                    : in std_logic
73
        );
74
end PPX_PCS;
75
 
76
architecture rtl of PPX_PCS is
77
 
78
        signal  PC_i    : unsigned(PC_Width - 1 downto 0);
79
        signal  NPC_i   : unsigned(PC_Width - 1 downto 0);
80
 
81
        type Stack_Image is array (2 ** StackAddrWidth - 1 downto 0) of unsigned(PC_Width - 1 downto 0);
82
        signal  Stack           : Stack_Image;
83
 
84
        signal  StackPtr        : unsigned(StackAddrWidth -1 downto 0);
85
 
86
begin
87
 
88
        NPC <= std_logic_vector(NPC_i);
89
 
90
        process (Clk)
91
        begin
92
                if Clk'event and Clk = '1' then
93 11 jesus
                        if Push = '1' then
94 3 jesus
                                Stack(to_integer(StackPtr)) <= PC_i;
95
                        end if;
96 11 jesus
                        if Int = '1' then
97
                                Stack(to_integer(StackPtr)) <= PC_i - 1;
98
                        end if;
99 3 jesus
                end if;
100
        end process;
101
 
102 11 jesus
        process (PC_i, Sleep, CS, Wr, PCLATH, STATUS, Push, Pop, Goto, Data_In, Addr_In, Int, Stack, StackPtr)
103 3 jesus
        begin
104
                NPC_i <= PC_i;
105
                if Sleep = '0' then
106
                        NPC_i <= PC_i + 1;
107
                end if;
108
                if CS = '1' and Wr = '1' then
109
                        if PC_Width = 13 then
110
                                NPC_i(7 downto 0) <= unsigned(Data_In);
111
                                NPC_i(PC_Width - 1 downto PC_Width - 5) <= unsigned(PCLATH);
112
                        end if;
113
                        if PC_Width = 11 then
114
                                NPC_i(7 downto 0) <= unsigned(Data_In);
115
                                NPC_i(8) <= '0';
116
                                NPC_i(10 downto 9) <= unsigned(STATUS);
117
                        end if;
118
                end if;
119
                if Push = '1' then
120
                        if PC_Width = 13 then
121
                                NPC_i(10 downto 0) <= unsigned(Addr_In);
122
                                NPC_i(PC_Width - 1 downto PC_Width - 2) <= unsigned(PCLATH(4 downto 3));
123
                        end if;
124
                        if PC_Width = 11 then
125
                                NPC_i(7 downto 0) <= unsigned(Addr_In(7 downto 0));
126
                                NPC_i(8) <= '0';
127
                                NPC_i(10 downto 9) <= unsigned(STATUS);
128
                        end if;
129
                end if;
130
                if Pop = '1' then
131
                        NPC_i <= Stack(to_integer(StackPtr - 1));
132
                end if;
133
                if Goto = '1' then
134
                        if PC_Width = 13 then
135
                                NPC_i(10 downto 0) <= unsigned(Addr_In);
136
                                NPC_i(PC_Width - 1 downto PC_Width - 2) <= unsigned(PCLATH(4 downto 3));
137
                        end if;
138
                        if PC_Width = 11 then
139
                                NPC_i(8 downto 0) <= unsigned(Addr_In);
140
                                NPC_i(10 downto 9) <= unsigned(STATUS);
141
                        end if;
142
                end if;
143
                if Int = '1' then
144
                        NPC_i <= (others => '0');
145
                        NPC_i(2) <= '1';
146
                end if;
147
        end process;
148
 
149
        process (Reset_n, Clk)
150
        begin
151
                if Reset_n = '0' then
152
                        PC_i <= (others => '1');
153
                        if TopBoot then
154
                                PC_i(0) <= '0';
155
                        end if;
156
                        StackPtr <= (others => '0');
157
                elsif Clk'event and Clk = '1' then
158
                        PC_i <= NPC_i;
159
                        if Push = '1' then
160
                                StackPtr <= StackPtr + 1;
161
                        end if;
162
                        if Pop = '1' then
163
                                StackPtr <= StackPtr - 1;
164
                        end if;
165
                        if Int = '1' then
166
                                StackPtr <= StackPtr + 1;
167
                        end if;
168
                end if;
169
        end process;
170
 
171
end;

powered by: WebSVN 2.1.0

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