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

Subversion Repositories tinyvliw8

[/] [tinyvliw8/] [trunk/] [src/] [vhdl/] [ioport.vhd] - Blame information for rev 8

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

Line No. Rev Author Line
1 2 steckol
-- ************************************************************************
2
-- * This is a RTL Model of the MSP430 IO ports without interrupt 
3
-- * functionality
4
-- *
5
-- * This io-port fits the behavior of the msp430 io-port. The functionality 
6
-- * of the in- and output lines(the output value is also written to the 
7
-- * input) is provided by the sgb25v io-pads
8
-- *
9
-- * author: g.panic - IHP, date: 2011-02-07
10
-- * version: 1.1
11
-- *
12
-- * Revision:
13
-- * changed clock behavior, clock used only in connection with mdbwr_n 
14
-- *
15
-- ************************************************************************
16
 
17
library ieee;
18
use ieee.std_logic_1164.all;
19
 
20
ENTITY ioport IS
21
        PORT (
22
                cs_n     : IN  STD_LOGIC;                                   -- chip select signal
23
 
24
                        clk      : IN  STD_LOGIC;
25
 
26
                        -- memory interface
27
                mdbwr_n  : IN  STD_LOGIC;                    -- write enable signal    
28
                mdb_i           : IN  STD_LOGIC_VECTOR(7 DOWNTO 0); -- data from data bus
29
                mdb_o           : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); -- data to data bus    
30
                mab     : IN  STD_LOGIC_VECTOR(2 downto 0);      -- address registers 
31
 
32
                        -- interrupt interface
33
                        irq      : out std_logic;
34
                        irqAck   : in std_logic;
35
 
36
                -- port interface
37
                PnIN    : IN  STD_LOGIC_VECTOR(7 DOWNTO 0); -- data from pad (gpio in)
38
                PnOUT           : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); -- data to pad (gpio out)
39
                PnOEN   : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); -- port direction (low active)
40
 
41
                -- MODxIN   : IN  STD_LOGIC_VECTOR(7 DOWNTO 0);         -- data to peripheral
42
                -- MODxDIR  : IN  STD_LOGIC_VECTOR(7 DOWNTO 0);         -- direction
43
                -- MODxOUT  : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);         -- data from peripheral 
44
 
45
                rst_n           : IN STD_LOGIC
46
                );
47
END ioport;
48
 
49
ARCHITECTURE beh OF ioport IS
50
 
51
        SIGNAL PxIN  : STD_LOGIC_VECTOR(7 DOWNTO 0);
52
        SIGNAL PxOUT : STD_LOGIC_VECTOR(7 DOWNTO 0);
53
        SIGNAL PxDIR : STD_LOGIC_VECTOR(7 DOWNTO 0);
54
        SIGNAL PxSEL : STD_LOGIC_VECTOR(7 DOWNTO 0);
55
 
56
        SIGNAL PxIES : STD_LOGIC_VECTOR(7 DOWNTO 0);
57
        SIGNAL PxIE  : STD_LOGIC_VECTOR(7 DOWNTO 0);
58
        SIGNAL PxIFG : STD_LOGIC_VECTOR(7 DOWNTO 0);
59
 
60
        SIGNAL IRQ_S : STD_LOGIC;
61
   SIGNAL CLK_S : STD_LOGIC;
62
 
63
        SIGNAL ifg_clk : std_logic_vector(7 downto 0);
64
        SIGNAL int     : std_logic_vector(7 downto 0);
65
 
66
BEGIN
67
 
68
        CLK_S <= clk;
69
 
70
-------------------------------------------------------------------------------------
71
-- INTERRUPTS
72
-------------------------------------------------------------------------------------
73
 
74
        int_edge_gen: for i in 0 to 7 generate
75
        begin
76
                process (PxIN(i), PxSEL(i), PxIES(i))
77
                begin
78
                        if PxSEL(i) = '0' then
79
                                if PxIES(i) = '0' then
80
                                        int(i) <= PxIN(i);
81
                                else
82
                                        int(i) <= not(PxIN(i));
83
                                end if;
84
                        else
85
                                int(i) <= '0';
86
                        end if;
87
                end process;
88
        end generate;
89
 
90
        -- generate access clocks to PxIFG, CPU acces has priority
91
        ifg_clk_gen: for i in 0 to 7 generate
92
        begin
93
                ifg_clk(i) <= not(mdbwr_n) when (cs_n = '0' and mab = "110") else int(i);
94
        end generate;
95
 
96
        -- write PxIFG
97
        PxIFG_gen: for i in 0 to 7 generate
98
        begin
99
        write_ifg : PROCESS (rst_n, ifg_clk(i))
100
        BEGIN
101
                IF rst_n = '0' THEN
102
                        PxIFG(i) <= '0';
103
                ELSE
104
                   IF (ifg_clk(i)'event and ifg_clk(i) = '1') THEN
105
                                IF cs_n = '0' and mab = "110" THEN
106
                                        IF mdbwr_n = '0' THEN
107
                                                PxIFG(i) <= PxIFG(i) and not(mdb_i(i));
108
                                        END IF;
109
                                ELSE
110
                                        PxIFG (i) <= '1';
111
                                END IF;
112
                        END IF;
113
                END IF;
114
        END PROCESS;
115
        end generate;
116
 
117
-------------------------------------------------------------------------------------
118
-- REGISTERS
119
-------------------------------------------------------------------------------------
120
 
121
 
122
        -------------------------------------------------------------------------------------
123
        -- write registers
124
        -------------------------------------------------------------------------------------
125
 
126
        -- PxDIR
127
        write_l_proc : PROCESS(rst_n, mdbwr_n)
128
        BEGIN
129
                IF rst_n = '0' THEN
130
                        PxDIR <= (OTHERS => '0');
131
                        PxOUT <= (OTHERS => '0');
132
                        PxSEL <= (OTHERS => '0');
133
                        PxIES <= (OTHERS => '0');
134
                        PxIE  <= (OTHERS => '0');
135
                ELSE
136
                        if (mdbwr_n'event and mdbwr_n = '0') then
137
                                IF cs_n = '0' THEN
138
                                        CASE mab IS
139
                                                WHEN "000" => PxDIR <= mdb_i;
140
                                                WHEN "001" => PxOUT <= mdb_i;
141
                                                WHEN "011" => PxSEL <= mdb_i;
142
                                                WHEN "100" => PxIES <= mdb_i;
143
                                                WHEN "101" => PxIE <= mdb_i;
144
                                                WHEN others => null;
145
                                        END CASE;
146
                                end if;
147
                        end if;
148
                END IF;
149
        END PROCESS;
150
 
151
        -------------------------------------------------------------------------------------
152
        -- read registers
153
        -------------------------------------------------------------------------------------
154
 
155
        mdb_o <= PxDIR when cs_n = '0' and mab = "000" else
156
                 PxOUT when cs_n = '0' and mab = "001" else
157
                                PxIN  when cs_n = '0' and mab = "010" else
158
                                PxSEL when cs_n = '0' and mab = "011" else
159
                                PxIES when cs_n = '0' and mab = "100" else
160
                                PxIE  when cs_n = '0' and mab = "101" else
161
                                PxIFG when cs_n = '0' and mab = "110" else
162
                                (others => '0');
163
 
164
-------------------------------------------------------------------------------------
165
-- EXTERNAL PORTS
166
-------------------------------------------------------------------------------------
167
 
168
        -- PnOEN
169
        gen_PnOEN: for i in 0 to 7 generate
170
        begin
171
                -- PnOEN(i) <= NOT (MODxDIR(i)) when PxSEL(i) = '1' else NOT (PxDIR(i));
172
                PnOEN(i) <= PxDIR(i);
173
        end generate;
174
 
175
        -- PnOUT
176
        gen_PnOUT: for i in 0 to 7 generate
177
        begin
178
                -- PnOUT (i) <= MODxIN(i) when PxSEL(i) = '1' else PxOUT(i);
179
                PnOUT(i) <= PxOUT(i);
180
        end generate;
181
 
182
        -- PxIN
183
        PxIN <= PnIN;
184
 
185
        -- MODxOUT
186
--      gen_MODxOUT: for i in 0 to 7 generate
187
--      begin
188
--              MODxOUT_proc: process (rst_n, PxIN, PxSEL)
189
--              begin
190
--                      if rst_n = '0' then
191
--                              MODxOUT(i) <= '0';
192
--                      elsif PxSEL(i) = '1' then
193
--                              MODxOUT(i) <= PxIN(i);
194
--                      end if;
195
--              end process;
196
--      end generate;
197
 
198
        irq_en : process(rst_n, clk_s)
199
        begin
200
                IF (rst_n = '0') THEN
201
                         IRQ_S <= '0';
202
                ELSE
203
                        if (clk_s'EVENT AND clk_s = '0') THEN    -- falling SCKL edge
204
                                if (irqAck = '1') then
205
                                        IRQ_S <= '0';
206
                                else
207
                                        if ((PxIE(0) = '1' and PxIFG(0) = '1') or (PxIE(1) = '1' and PxIFG(1) = '1') or (PxIE(2) = '1' and PxIFG(2) = '1') or (PxIE(3) = '1' and PxIFG(3) = '1') or
208
                        (PxIE(4) = '1' and PxIFG(4) = '1') or (PxIE(5) = '1' and PxIFG(5) = '1') or (PxIE(6) = '1' and PxIFG(6) = '1') or (PxIE(7) = '1' and PxIFG(7) = '1')) then
209
 
210
                                                IRQ_S <= '1';
211
                                        end if;
212
                                end if;
213
                        end if;
214
                end if;
215
        end process;
216
 
217
        irq <= IRQ_S;
218
END beh;
219
 
220
 
221
 

powered by: WebSVN 2.1.0

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