1 |
3 |
jesus |
--
|
2 |
|
|
-- PIC16xx compatible microcontroller core
|
3 |
|
|
--
|
4 |
14 |
jesus |
-- Version : 0224
|
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 |
14 |
jesus |
-- http://www.opencores.org/cvsweb.shtml/ppx16/
|
42 |
3 |
jesus |
--
|
43 |
|
|
-- Limitations :
|
44 |
|
|
-- Registers implemented in this entity are INDF, PCL, STATUS, FSR, (PCLATH)
|
45 |
|
|
-- other registers must be implemented externally including GPR
|
46 |
|
|
--
|
47 |
|
|
-- File history :
|
48 |
|
|
--
|
49 |
|
|
|
50 |
|
|
library IEEE;
|
51 |
|
|
use IEEE.std_logic_1164.all;
|
52 |
|
|
|
53 |
|
|
entity PPX_Ctrl is
|
54 |
|
|
generic(
|
55 |
|
|
InstructionLength : integer
|
56 |
|
|
);
|
57 |
|
|
port(
|
58 |
11 |
jesus |
Clk : in std_logic;
|
59 |
14 |
jesus |
Reset_n : in std_logic;
|
60 |
11 |
jesus |
ROM_Data : in std_logic_vector(InstructionLength - 1 downto 0);
|
61 |
3 |
jesus |
Inst : in std_logic_vector(InstructionLength - 1 downto 0);
|
62 |
11 |
jesus |
Skip : in std_logic;
|
63 |
3 |
jesus |
File_Wr : out std_logic;
|
64 |
|
|
W_Wr : out std_logic;
|
65 |
|
|
Imm_Op : out std_logic;
|
66 |
11 |
jesus |
A2Res : out std_logic;
|
67 |
3 |
jesus |
B2Res : out std_logic;
|
68 |
|
|
Push : out std_logic;
|
69 |
|
|
Pop : out std_logic;
|
70 |
|
|
Goto : out std_logic;
|
71 |
|
|
IRet : out std_logic;
|
72 |
|
|
B_Skip : out std_logic;
|
73 |
|
|
Sleep : out std_logic
|
74 |
|
|
);
|
75 |
|
|
end PPX_Ctrl;
|
76 |
|
|
|
77 |
|
|
architecture rtl of PPX_Ctrl is
|
78 |
|
|
|
79 |
|
|
begin
|
80 |
|
|
|
81 |
|
|
Imm_Op <= Inst(InstructionLength - 1);
|
82 |
|
|
|
83 |
|
|
i12 : if InstructionLength = 12 generate
|
84 |
|
|
B_Skip <= '1' when Inst(11 downto 10) = "10" else '0';
|
85 |
11 |
jesus |
Sleep <= '1' when ROM_Data(11 downto 0) = "000000000011" else '0';
|
86 |
3 |
jesus |
W_Wr <= '1' when Inst(11 downto 8) = "1000" or
|
87 |
|
|
Inst(11 downto 10) = "11" or
|
88 |
|
|
(Inst(11 downto 10) = "00" and Inst(5) = '0' and Inst(9 downto 6) /= "0000") else '0';
|
89 |
|
|
IRet <= '0';
|
90 |
14 |
jesus |
process (Reset_n, Clk)
|
91 |
11 |
jesus |
begin
|
92 |
14 |
jesus |
if Reset_n = '0' then
|
93 |
11 |
jesus |
File_Wr <= '0';
|
94 |
|
|
Goto <= '0';
|
95 |
|
|
Push <= '0';
|
96 |
|
|
Pop <= '0';
|
97 |
|
|
A2Res <= '0';
|
98 |
|
|
B2Res <= '0';
|
99 |
14 |
jesus |
elsif Clk'event and Clk = '1' then
|
100 |
|
|
File_Wr <= '0';
|
101 |
|
|
Goto <= '0';
|
102 |
|
|
Push <= '0';
|
103 |
|
|
Pop <= '0';
|
104 |
|
|
A2Res <= '0';
|
105 |
|
|
B2Res <= '0';
|
106 |
11 |
jesus |
if Skip = '0' then
|
107 |
|
|
if (ROM_Data(InstructionLength - 1 downto InstructionLength - 2) = "00" and
|
108 |
|
|
ROM_Data(InstructionLength - 7) = '1') or
|
109 |
|
|
ROM_Data(InstructionLength - 1 downto InstructionLength - 3) = "010" then
|
110 |
|
|
File_Wr <= '1';
|
111 |
|
|
end if;
|
112 |
|
|
if ROM_Data(InstructionLength - 1 downto InstructionLength - 3) = "101" then
|
113 |
|
|
Goto <= '1';
|
114 |
|
|
end if;
|
115 |
|
|
if ROM_Data(11 downto 8) = "1001" then -- CALL
|
116 |
|
|
Push <= '1';
|
117 |
|
|
end if;
|
118 |
|
|
if ROM_Data(11 downto 8) = "1000" then -- RETLW
|
119 |
|
|
Pop <= '1';
|
120 |
|
|
end if;
|
121 |
|
|
if ROM_Data(11 downto 6) = "001000" then
|
122 |
|
|
-- MOVF
|
123 |
|
|
A2Res <= '1';
|
124 |
|
|
end if;
|
125 |
|
|
if ROM_Data(11 downto 8) = "1100" or -- MOVLW
|
126 |
|
|
ROM_Data(11 downto 8) = "1000" or -- RETLW
|
127 |
|
|
ROM_Data(11 downto 6) = "000000" then -- MOVWF/TRIS/OPTION and some others
|
128 |
|
|
B2Res <= '1';
|
129 |
|
|
end if;
|
130 |
|
|
end if;
|
131 |
|
|
end if;
|
132 |
|
|
end process;
|
133 |
3 |
jesus |
end generate;
|
134 |
|
|
|
135 |
|
|
i14 : if InstructionLength = 14 generate
|
136 |
|
|
B_Skip <= '1' when Inst(13 downto 12) = "10" or Inst(13 downto 10) = "1101" or
|
137 |
|
|
Inst(13 downto 1) = "0000000000100" else '0';
|
138 |
11 |
jesus |
Sleep <= '1' when ROM_Data(13 downto 0) = "00000001100011" else '0';
|
139 |
3 |
jesus |
W_Wr <= '1' when Inst(13 downto 12) = "11" or
|
140 |
|
|
(Inst(13 downto 12) = "00" and Inst(7) = '0' and Inst(11 downto 8) /= "0000") else '0';
|
141 |
|
|
IRet <= '1' when Inst(13 downto 0) = "00000000001001" else '0'; -- RETFIE
|
142 |
14 |
jesus |
process (Reset_n, Clk)
|
143 |
11 |
jesus |
begin
|
144 |
14 |
jesus |
if Reset_n = '0' then
|
145 |
11 |
jesus |
File_Wr <= '0';
|
146 |
|
|
Goto <= '0';
|
147 |
|
|
Push <= '0';
|
148 |
|
|
Pop <= '0';
|
149 |
|
|
A2Res <= '0';
|
150 |
|
|
B2Res <= '0';
|
151 |
14 |
jesus |
elsif Clk'event and Clk = '1' then
|
152 |
|
|
File_Wr <= '0';
|
153 |
|
|
Goto <= '0';
|
154 |
|
|
Push <= '0';
|
155 |
|
|
Pop <= '0';
|
156 |
|
|
A2Res <= '0';
|
157 |
|
|
B2Res <= '0';
|
158 |
11 |
jesus |
if Skip = '0' then
|
159 |
|
|
if (ROM_Data(InstructionLength - 1 downto InstructionLength - 2) = "00" and
|
160 |
|
|
ROM_Data(InstructionLength - 7) = '1') or
|
161 |
|
|
ROM_Data(InstructionLength - 1 downto InstructionLength - 3) = "010" then
|
162 |
|
|
File_Wr <= '1';
|
163 |
|
|
end if;
|
164 |
|
|
if ROM_Data(InstructionLength - 1 downto InstructionLength - 3) = "101" then
|
165 |
|
|
Goto <= '1';
|
166 |
|
|
end if;
|
167 |
|
|
if ROM_Data(13 downto 11) = "100" then
|
168 |
|
|
Push <= '1'; -- CALL
|
169 |
|
|
end if;
|
170 |
|
|
if ROM_Data(13 downto 10) = "1101" or -- RETLW
|
171 |
|
|
ROM_Data(13 downto 1) = "0000000000100" then -- RETURN, RETFIE
|
172 |
|
|
Pop <= '1';
|
173 |
|
|
end if;
|
174 |
|
|
if ROM_Data(13 downto 8) = "001000" then
|
175 |
|
|
-- MOVF
|
176 |
|
|
A2Res <= '1';
|
177 |
|
|
end if;
|
178 |
|
|
if ROM_Data(13 downto 10) = "1100" or -- MOVLW
|
179 |
|
|
ROM_Data(13 downto 10) = "1101" or -- RETLW
|
180 |
|
|
ROM_Data(13 downto 8) = "000000" then -- MOVWF/TRIS/OPTION and some others
|
181 |
|
|
B2Res <= '1';
|
182 |
|
|
end if;
|
183 |
|
|
end if;
|
184 |
|
|
end if;
|
185 |
|
|
end process;
|
186 |
3 |
jesus |
end generate;
|
187 |
|
|
|
188 |
|
|
end;
|