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

Subversion Repositories cpu_lecture

[/] [cpu_lecture/] [trunk/] [html/] [17_Listing_of_io.vhd.html] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jsauermann
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2
"http://www.w3.org/TR/html4/strict.dtd">
3
<HTML>
4
<HEAD>
5
<TITLE>html/Listing_of_io.vhd</TITLE>
6
<META NAME="generator" CONTENT="HTML::TextToHTML v2.46">
7
<LINK REL="stylesheet" TYPE="text/css" HREF="lecture.css">
8
</HEAD>
9
<BODY>
10
<P><table class="ttop"><th class="tpre"><a href="16_Listing_of_data_path.vhd.html">Previous Lesson</a></th><th class="ttop"><a href="toc.html">Table of Content</a></th><th class="tnxt"><a href="18_Listing_of_opc_deco.vhd.html">Next Lesson</a></th></table>
11
<hr>
12
 
13
<H1><A NAME="section_1">17 LISTING OF io.vhd</A></H1>
14
 
15
<pre class="vhdl">
16
 
17
  1     -------------------------------------------------------------------------------
18
  2     --
19
  3     -- Copyright (C) 2009, 2010 Dr. Juergen Sauermann
20
  4     --
21
  5     --  This code is free software: you can redistribute it and/or modify
22
  6     --  it under the terms of the GNU General Public License as published by
23
  7     --  the Free Software Foundation, either version 3 of the License, or
24
  8     --  (at your option) any later version.
25
  9     --
26
 10     --  This code is distributed in the hope that it will be useful,
27
 11     --  but WITHOUT ANY WARRANTY; without even the implied warranty of
28
 12     --  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
 13     --  GNU General Public License for more details.
30
 14     --
31
 15     --  You should have received a copy of the GNU General Public License
32
 16     --  along with this code (see the file named COPYING).
33
 17     --  If not, see http://www.gnu.org/licenses/.
34
 18     --
35
 19     -------------------------------------------------------------------------------
36
 20     -------------------------------------------------------------------------------
37
 21     --
38
 22     -- Module Name:    io - Behavioral
39
 23     -- Create Date:    13:59:36 11/07/2009
40
 24     -- Description:    the I/O of a CPU (uart and general purpose I/O lines).
41
 25     --
42
 26     -------------------------------------------------------------------------------
43
 27     --
44
 28     library IEEE;
45
 29     use IEEE.STD_LOGIC_1164.ALL;
46
 30     use IEEE.STD_LOGIC_ARITH.ALL;
47
 31     use IEEE.STD_LOGIC_UNSIGNED.ALL;
48
 32
49
 33     entity io is
50
 34         port (  I_CLK       : in  std_logic;
51
 35
52
 36                 I_CLR       : in  std_logic;
53
 37                 I_ADR_IO    : in  std_logic_vector( 7 downto 0);
54
 38                 I_DIN       : in  std_logic_vector( 7 downto 0);
55
 39                 I_SWITCH    : in  std_logic_vector( 7 downto 0);
56
 40                 I_RD_IO     : in  std_logic;
57
 41                 I_RX        : in  std_logic;
58
 42                 I_WE_IO     : in  std_logic;
59
 43
60
 44                 Q_7_SEGMENT : out std_logic_vector( 6 downto 0);
61
 45                 Q_DOUT      : out std_logic_vector( 7 downto 0);
62
 46                 Q_INTVEC    : out std_logic_vector( 5 downto 0);
63
 47                 Q_LEDS      : out std_logic_vector( 1 downto 0);
64
 48                 Q_TX        : out std_logic);
65
 49     end io;
66
 50
67
 51     architecture Behavioral of io is
68
 52
69
 53     component uart
70
 54         generic(CLOCK_FREQ  : std_logic_vector(31 downto 0);
71
 55                 BAUD_RATE   : std_logic_vector(27 downto 0));
72
 56         port(   I_CLK       : in  std_logic;
73
 57                 I_CLR       : in  std_logic;
74
 58                 I_RD        : in  std_logic;
75
 59                 I_WE        : in  std_logic;
76
 60                 I_RX        : in  std_logic;
77
 61                 I_TX_DATA   : in  std_logic_vector(7 downto 0);
78
 62
79
 63                 Q_RX_DATA   : out std_logic_vector(7 downto 0);
80
 64                 Q_RX_READY  : out std_logic;
81
 65                 Q_TX        : out std_logic;
82
 66                 Q_TX_BUSY   : out std_logic);
83
 67     end component;
84
 68
85
 69     signal U_RX_READY       : std_logic;
86
 70     signal U_TX_BUSY        : std_logic;
87
 71     signal U_RX_DATA        : std_logic_vector( 7 downto 0);
88
 72
89
 73     signal L_INTVEC         : std_logic_vector( 5 downto 0);
90
 74     signal L_LEDS           : std_logic;
91
 75     signal L_RD_UART        : std_logic;
92
 76     signal L_RX_INT_ENABLED : std_logic;
93
 77     signal L_TX_INT_ENABLED : std_logic;
94
 78     signal L_WE_UART        : std_logic;
95
 79
96
 80     begin
97
 81         urt: uart
98
 82         generic map(CLOCK_FREQ  => std_logic_vector(conv_unsigned(25000000, 32)),
99
 83                     BAUD_RATE   => std_logic_vector(conv_unsigned(   38400, 28)))
100
 84         port map(   I_CLK      => I_CLK,
101
 85                     I_CLR      => I_CLR,
102
 86                     I_RD       => L_RD_UART,
103
 87                     I_WE       => L_WE_UART,
104
 88                     I_TX_DATA  => I_DIN(7 downto 0),
105
 89                     I_RX       => I_RX,
106
 90
107
 91                     Q_TX       => Q_TX,
108
 92                     Q_RX_DATA  => U_RX_DATA,
109
 93                     Q_RX_READY => U_RX_READY,
110
 94                     Q_TX_BUSY  => U_TX_BUSY);
111
 95
112
 96         -- IO read process
113
 97         --
114
 98         iord: process(I_ADR_IO, I_SWITCH,
115
 99                       U_RX_DATA, U_RX_READY, L_RX_INT_ENABLED,
116
100                       U_TX_BUSY, L_TX_INT_ENABLED)
117
101         begin
118
102             -- addresses for mega8 device (use iom8.h or #define __AVR_ATmega8__).
119
103             --
120
104             case I_ADR_IO is
121
105                 when X"2A"  => Q_DOUT <=             -- UCSRB:
122
106                                    L_RX_INT_ENABLED  -- Rx complete int enabled.
123
107                                  & L_TX_INT_ENABLED  -- Tx complete int enabled.
124
108                                  & L_TX_INT_ENABLED  -- Tx empty int enabled.
125
109                                  & '1'               -- Rx enabled
126
110                                  & '1'               -- Tx enabled
127
111                                  & '0'               -- 8 bits/char
128
112                                  & '0'               -- Rx bit 8
129
113                                  & '0';              -- Tx bit 8
130
114                 when X"2B"  => Q_DOUT <=             -- UCSRA:
131
115                                    U_RX_READY       -- Rx complete
132
116                                  & not U_TX_BUSY    -- Tx complete
133
117                                  & not U_TX_BUSY    -- Tx ready
134
118                                  & '0'              -- frame error
135
119                                  & '0'              -- data overrun
136
120                                  & '0'              -- parity error
137
121                                  & '0'              -- double dpeed
138
122                                  & '0';             -- multiproc mode
139
123                 when X"2C"  => Q_DOUT <= U_RX_DATA; -- UDR
140
124                 when X"40"  => Q_DOUT <=            -- UCSRC
141
125                                    '1'              -- URSEL
142
126                                  & '0'              -- asynchronous
143
127                                  & "00"             -- no parity
144
128                                  & '1'              -- two stop bits
145
129                                  & "11"             -- 8 bits/char
146
130                                  & '0';             -- rising clock edge
147
131
148
132                 when X"36"  => Q_DOUT <= I_SWITCH;  -- PINB
149
133                 when others => Q_DOUT <= X"AA";
150
134             end case;
151
135         end process;
152
136
153
137         -- IO write process
154
138         --
155
139         iowr: process(I_CLK)
156
140         begin
157
141             if (rising_edge(I_CLK)) then
158
142                 if (I_CLR = '1') then
159
143                     L_RX_INT_ENABLED  <= '0';
160
144                     L_TX_INT_ENABLED  <= '0';
161
145                 elsif (I_WE_IO = '1') then
162
146                     case I_ADR_IO is
163
147                         when X"38"  => Q_7_SEGMENT <= I_DIN(6 downto 0);    -- PORTB
164
148                                        L_LEDS <= not L_LEDS;
165
149                         when X"40"  =>  -- handled by uart
166
150                         when X"41"  =>  -- handled by uart
167
151                         when X"43"  => L_RX_INT_ENABLED <= I_DIN(0);
168
152                                        L_TX_INT_ENABLED <= I_DIN(1);
169
153                         when others =>
170
154                     end case;
171
155                 end if;
172
156             end if;
173
157         end process;
174
158
175
159         -- interrupt process
176
160         --
177
161         ioint: process(I_CLK)
178
162         begin
179
163             if (rising_edge(I_CLK)) then
180
164                 if (I_CLR = '1') then
181
165                     L_RX_INT_ENABLED  <= '0';
182
166                     L_TX_INT_ENABLED  <= '0';
183
167                     L_INTVEC <= "000000";
184
168                 else
185
169                     if (L_RX_INT_ENABLED and U_RX_READY) = '1' then
186
170                         if (L_INTVEC(5) = '0') then     -- no interrupt pending
187
171                             L_INTVEC <= "101011";       -- _VECTOR(11)
188
172                         end if;
189
173                     elsif (L_TX_INT_ENABLED and not U_TX_BUSY) = '1' then
190
174                         if (L_INTVEC(5) = '0') then     -- no interrupt pending
191
175                             L_INTVEC <= "101100";       -- _VECTOR(12)
192
176                         end if;
193
177                     else                                -- no interrupt
194
178                         L_INTVEC <= "000000";
195
179                     end if;
196
180                 end if;
197
181             end if;
198
182         end process;
199
183
200
184         L_WE_UART <= I_WE_IO when (I_ADR_IO = X"2C") else '0'; -- write UART UDR
201
185         L_RD_UART <= I_RD_IO when (I_ADR_IO = X"2C") else '0'; -- read  UART UDR
202
186
203
187         Q_LEDS(1) <= L_LEDS;
204
188         Q_LEDS(0) <= not L_LEDS;
205
189         Q_INTVEC  <= L_INTVEC;
206
190
207
191     end Behavioral;
208
192
209
<pre class="filename">
210
src/io.vhd
211
</pre></pre>
212
<P>
213
 
214
<P><hr><BR>
215
<table class="ttop"><th class="tpre"><a href="16_Listing_of_data_path.vhd.html">Previous Lesson</a></th><th class="ttop"><a href="toc.html">Table of Content</a></th><th class="tnxt"><a href="18_Listing_of_opc_deco.vhd.html">Next Lesson</a></th></table>
216
</BODY>
217
</HTML>

powered by: WebSVN 2.1.0

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