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

Subversion Repositories simpcon

[/] [simpcon/] [trunk/] [vhdl/] [sc_control_channel.vhd] - Blame information for rev 29

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 29 martin
--
2
--
3
--  This file is a part of JOP, the Java Optimized Processor
4
--
5
--  Copyright (C) 2008, Jack Whitham
6
--
7
--  This program is free software: you can redistribute it and/or modify
8
--  it under the terms of the GNU General Public License as published by
9
--  the Free Software Foundation, either version 3 of the License, or
10
--  (at your option) any later version.
11
--
12
--  This program is distributed in the hope that it will be useful,
13
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
--  GNU General Public License for more details.
16
--
17
--  You should have received a copy of the GNU General Public License
18
--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
--
20
 
21
 
22
--
23
--      sc_control_channel.vhd
24
--
25
--  32 bit parallel interface for the control channel;
26
--  mimics a serial port UART device. Data is sent in a packet
27
--  form (with a header word and zero or more payload words).
28
--
29
 
30
 
31
library ieee;
32
use ieee.std_logic_1164.all;
33
use ieee.std_logic_unsigned."+";
34
use ieee.numeric_std.all;
35
 
36
entity sc_control_channel is
37
generic (addr_bits : integer);
38
port (
39
        clk             : in std_logic;
40
        reset   : in std_logic;
41
 
42
-- SimpCon interface
43
 
44
        address         : in std_logic_vector(addr_bits-1 downto 0);
45
        wr_data         : in std_logic_vector(31 downto 0);
46
        rd, wr          : in std_logic;
47
        rd_data         : out std_logic_vector(31 downto 0);
48
        rdy_cnt         : out unsigned(1 downto 0);
49
 
50
    cc_out_data : out std_logic_vector(31 downto 0);
51
    cc_out_wr   : out std_logic;
52
    cc_out_rdy  : in std_logic;
53
 
54
    cc_in_data  : in std_logic_vector(31 downto 0);
55
    cc_in_wr    : in std_logic;
56
    cc_in_rdy   : out std_logic
57
);
58
end sc_control_channel;
59
 
60
architecture rtl of sc_control_channel is
61
 
62
        signal incoming_message     : std_logic_vector(31 downto 0);
63
        signal outgoing_message     : std_logic_vector(31 downto 0);
64
        signal send_ack, send_flag  : std_logic;
65
 
66
    type StateType is ( IDLE, RELAY, SEND, AWAIT_REPLY, AWAIT_REPLY_RELAY );
67
 
68
    signal state                : StateType;
69
 
70
begin
71
 
72
    process ( clk , reset ) is
73
    begin
74
        if ( reset = '1' )
75
        then
76
            send_flag <= '0';
77
 
78
        elsif ( clk = '1' )
79
        and ( clk'event )
80
        then
81
            if ( send_ack = '1' )
82
            then
83
                send_flag <= '0';
84
            end if;
85
 
86
            if ( rd = '1' )
87
            then
88
                null;
89
            elsif ( wr = '1' )
90
            then
91
                outgoing_message <= wr_data;
92
                send_flag <= '1';
93
            end if;
94
        end if;
95
    end process;
96
 
97
    rdy_cnt <= "00" when (( state = IDLE ) and ( send_flag = '0' )) else "11";
98
    rd_data <= incoming_message;
99
 
100
    process ( clk , reset ) is
101
    begin
102
        if ( reset = '1' )
103
        then
104
            state <= IDLE;
105
            cc_in_rdy <= '0';
106
            cc_out_wr <= '0';
107
            send_ack <= '0';
108
 
109
        elsif ( clk = '1' )
110
        and ( clk'event )
111
        then
112
            cc_in_rdy <= '0';
113
            cc_out_wr <= '0';
114
            send_ack <= '0';
115
 
116
            case state is
117
            when IDLE =>
118
                if ( send_flag = '1' )
119
                then
120
                    -- A message to be sent
121
                    cc_out_data <= outgoing_message;
122
                    send_ack <= '1';
123
                    state <= SEND;
124
                elsif ( cc_in_wr = '1' )
125
                then
126
                    -- Relay incoming message since we are not
127
                    -- waiting for a message
128
                    cc_out_data <= cc_in_data;
129
                    state <= RELAY;
130
                else
131
                    -- Ready for CC data 
132
                    cc_in_rdy <= '1';
133
                end if;
134
 
135
            when RELAY =>
136
                if ( cc_out_rdy = '1' )
137
                then
138
                    cc_out_wr <= '1';
139
                    state <= IDLE;
140
                end if;
141
 
142
            when SEND =>
143
                if ( cc_out_rdy = '1' )
144
                then
145
                    cc_out_wr <= '1';
146
                    state <= AWAIT_REPLY;
147
                end if;
148
 
149
            when AWAIT_REPLY =>
150
                if ( cc_in_wr = '1' )
151
                then
152
                    -- Examine incoming message
153
                    if ( cc_in_data ( 30 downto 16 ) = outgoing_message ( 30 downto 16 ) )
154
                    then
155
                        -- Correct message
156
                        incoming_message <= cc_in_data;
157
                        state <= IDLE;
158
                    else
159
                        -- Wrong message (for someone else)
160
                        cc_out_data <= cc_in_data;
161
                        state <= AWAIT_REPLY_RELAY;
162
                    end if;
163
                else
164
                    -- Ready for CC data 
165
                    cc_in_rdy <= '1';
166
                end if;
167
 
168
            when AWAIT_REPLY_RELAY =>
169
                if ( cc_out_rdy = '1' )
170
                then
171
                    cc_out_wr <= '1';
172
                    state <= AWAIT_REPLY;
173
                end if;
174
            end case;
175
        end if;
176
    end process;
177
 
178
end rtl;
179
 

powered by: WebSVN 2.1.0

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