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

Subversion Repositories utosnet

[/] [utosnet/] [trunk/] [gateware/] [uTosNet_example/] [uTosNet_controller/] [UTNX_top.vhd] - Blame information for rev 10

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 10 sonicwave
----------------------------------------------------------------------------------
2
-- Company:             University of Southern Denmark
3
-- Engineer:            Anders Sørensen
4
-- 
5
-- Create Date:         30/11/2009 
6
-- Design Name:         uTosNet
7
-- Module Name:         uTosNet_top - Behavioral 
8
-- File Name:           uTosNet_top.vhd
9
-- Project Name:        uTosNet
10
-- Target Devices:      SDU XC3S50AN Board
11
-- Tool versions:       Xilinx ISE 11.4
12
-- Description:         SDU/TEK/Embedix Spartan-3 50AN experimentation board +
13
--                                      Expansion board with: USB + Ethernet + VGA.
14
--                                      Example uTosNet application (over USB UART)
15
--                                      Use serial port setting: 115200 bps 8N1
16
--
17
-- Revision: 
18
-- Revision 0.10 -      Initial release
19
--
20
-- Copyright 2010
21
--
22
-- This module is free software: you can redistribute it and/or modify
23
-- it under the terms of the GNU Lesser General Public License as published by
24
-- the Free Software Foundation, either version 3 of the License, or
25
-- (at your option) any later version.
26
--
27
-- This module is distributed in the hope that it will be useful,
28
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
29
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30
-- GNU Lesser General Public License for more details.
31
--
32
-- You should have received a copy of the GNU Lesser General Public License
33
-- along with this module.  If not, see <http://www.gnu.org/licenses/>.
34
----------------------------------------------------------------------------------
35
 
36
library IEEE;
37
use IEEE.STD_LOGIC_1164.ALL;
38
use IEEE.STD_LOGIC_ARITH.ALL;
39
use IEEE.STD_LOGIC_UNSIGNED.ALL;
40
 
41
-- Here we define the I/O connections from the example
42
-- Since this is the top level, the connections all go to the outside world
43
entity UTNX_top is
44
        Port (  CLK_50M_I               : in    STD_LOGIC;                                              -- 50 MHz from onboard oscillator
45
                        LEDS_O                  : out   STD_LOGIC_VECTOR(1 downto 0);    -- Two onboard LED's
46
                        XB_SERIAL_O             : out   STD_LOGIC;                                              -- Serial stream to PC
47
                        XB_SERIAL_I             : in    STD_LOGIC;                                              -- Serial stream from PC
48
                        XB_LEDS_O               : out   STD_LOGIC_VECTOR(2 downto 0);    -- 3 LED's on expansion board
49
                        XB_DIPSW_I              : in    STD_LOGIC_VECTOR(3 downto 0);    -- 4 dip switches
50
                        BB_OUT_O                : out   STD_LOGIC_VECTOR(2 downto 0);    -- 3 outputs on breadboard
51
                        BB_LEDS_O               : out   STD_LOGIC_VECTOR(7 downto 0));   -- 8 LED's on breadboard
52
end UTNX_top;
53
 
54
architecture Behavioral of UTNX_top is
55
 
56
-- Here we define the components we want to include in our design (there is only one)
57
-- The Port description is just copied from the components own source file
58
        COMPONENT uTosNet_ctrl is
59
        Port (  T_clk_50M                                               : in    STD_LOGIC;
60
                        T_serial_out                                    : out   STD_LOGIC;
61
                        T_serial_in                                             : in    STD_LOGIC;
62
                        T_reg_ptr                                               : out   std_logic_vector(2 downto 0);
63
                        T_word_ptr                                              : out   std_logic_vector(1 downto 0);
64
                        T_data_to_mem                                   : in    std_logic_vector(31 downto 0);
65
                        T_data_from_mem                                 : out   std_logic_vector(31 downto 0);
66
                        T_data_from_mem_latch                   : out   std_logic);
67
        END COMPONENT;
68
 
69
-- Here we define the signals used by the top level design
70
        signal clk_50M                                  : std_logic;
71
        signal sys_cnt                                  : std_logic_vector(31 downto 0) := (others => '0');
72
        signal freq_gen                                 : std_logic_vector(31 downto 0) := (others => '0');
73
        signal freq_out                                 : std_logic := '0';
74
        signal bb_leds                                  : std_logic_vector(7 downto 0);  -- register for 8 leds
75
        signal dipsw                                    : std_logic_vector(3 downto 0);
76
        signal frq,flsh,pwm                             : std_logic;
77
 
78
-- The signals below is used to hold data for our I/O application
79
        signal pwm_value                                : std_logic_vector(15 downto 0); -- 16 bit register for pwm value
80
        signal period                                   : std_logic_vector(31 downto 0); -- 32 bit register for freq generator
81
        signal flash                                    : std_logic_vector(7 downto 0); -- 8 bit register for flash duration
82
        signal v_leds                                   : std_logic_vector(31 downto 0); -- 32 bit register to hold status for variable leds 
83
 
84
-- Signals below is used to connect to the uTosNet Controller component  
85
        signal T_reg_ptr                                : std_logic_vector(2 downto 0);
86
        signal T_word_ptr                               : std_logic_vector(1 downto 0);
87
        signal T_data_to_mem                    : std_logic_vector(31 downto 0);
88
        signal T_data_from_mem                  : std_logic_vector(31 downto 0);
89
        signal T_data_from_mem_latch    : std_logic;
90
 
91
 
92
begin
93
 
94
-- Here we instantiate the uTosNet Controller component, and connect its ports to signals       
95
        uTosNet_ctrlInst : uTosNet_ctrl
96
        Port map (      T_clk_50M => clk_50M,
97
                                T_serial_out => XB_SERIAL_O,
98
                                T_serial_in => XB_SERIAL_I,
99
                                T_reg_ptr => T_reg_ptr,
100
                                T_word_ptr => T_word_ptr,
101
                                T_data_to_mem => T_data_to_mem,
102
                                T_data_from_mem => T_data_from_mem,
103
                                T_data_from_mem_latch => T_data_from_mem_latch);
104
 
105
-- It's not necessary to transfer these ports to signals, we just think it makes the syntax nicer
106
-- to avoid referring to ports in the body of the code. The compiler will optimize identical signals away
107
        clk_50M <= CLK_50M_I;
108
        BB_LEDS_O <= bb_leds;
109
        dipsw <= XB_DIPSW_I;
110
 
111
-- here we define 3 signals used for output
112
        frq  <= freq_out;
113
        pwm  <= '1' when pwm_value > sys_cnt(15 downto 0) else '0';
114
        flsh <= '1' when (sys_cnt(25 downto 24) = 0) and (sys_cnt(23 downto 16) < flash) else '0';
115
 
116
-- here we map the above 3 sigals to both breadboard outputs, and expansion board LED's 
117
        BB_OUT_O(0) <= frq;
118
        BB_OUT_O(1) <= pwm;
119
        BB_OUT_O(2) <= flsh;
120
 
121
        XB_LEDS_O(0) <= frq;
122
        XB_LEDS_O(1) <= pwm;
123
        XB_LEDS_O(2) <= flsh;
124
 
125
-- Here we map some bits from the system counter to onboard LED's, as an 'alive' marker
126
        LEDS_O <= sys_cnt(25 downto 24);
127
 
128
---------------------------------------------------------
129
-- Clocked process, to take data off the controller bus 
130
----------------------------------------------------------
131
        DatFromTosNet:
132
        process(clk_50M)
133
        begin -- process
134
                if (clk_50M'event and clk_50M='1' and T_data_from_mem_latch='1') then
135
                        case (T_reg_ptr & T_word_ptr) is                        -- The addresses are concatenated for compact code
136
                                when "00000" => period          <= T_data_from_mem;               -- Register 0, word 0 - all 32 bits
137
                                when "00001" => pwm_value       <= T_data_from_mem(15 downto 0);  -- Register 0, word 1 - low 16 bits
138
                                                                flash           <= T_data_from_mem(31 downto 24); --                      high 8 bits
139
                                when "00100" => v_leds          <= T_data_from_mem;               -- Register 1, word 0 - all 32 bits
140
                                when others =>
141
                        end case;
142
                end if;
143
        end process;
144
 
145
----------------------------------------------------------
146
-- Unclocked process, to place data on the controller bus
147
----------------------------------------------------------
148
        DatToTosNet:
149
        process(T_reg_ptr,T_word_ptr)
150
        begin
151
                T_data_to_mem<="00000000000000000000000000000000";      -- default data
152
                case (T_reg_ptr & T_word_ptr) is                   -- The addresses are concatenated for compact code
153
                        -- Register 0, word 0-3 are hard coded to these values for test/demo purposes
154
                        when "00000" => T_data_to_mem <= "00000000000000000000000000000001"; -- 1
155
                        when "00001" => T_data_to_mem <= "00000000000000000000000000000010"; -- 2
156
                        when "00010" => T_data_to_mem <= "00000000000000000000000000000100"; -- 3
157
                        when "00011" => T_data_to_mem <= "00000000000000000000000000001000"; -- 4
158
                        -- Register 1
159
                        when "00100" => T_data_to_mem <= sys_cnt;  -- Word 0 gives the value of the system counter
160
                        when "00101" => T_data_to_mem <= freq_gen; -- Word 1 gives the value of the frequency generator
161
                        -- register 2
162
                        when "01000" => T_data_to_mem <= "0000000000000000000000000000" & dipsw;
163
                        --       Etc. etc. etc.
164
                        when others =>
165
                end case;
166
        end process;
167
 
168
---------------------------------------------------------------------
169
-- Clocked process, that counts clk_50M edges
170
---------------------------------------------------------------------
171
        SystemCounter:
172
        process(clk_50M)
173
        begin -- process
174
                if(clk_50M'event and clk_50M='1') then
175
                        sys_cnt<=sys_cnt+1;
176
        end if;
177
        end process;
178
 
179
-----------------------------------------------------------------
180
-- Clocked process to generate a square wave with variable period
181
-----------------------------------------------------------------
182
        FreqGen:
183
        process(clk_50M)
184
        begin -- process
185
                if (clk_50M'event and clk_50M='1') then
186
                        if period = 0 then
187
                                freq_gen <= (others => '0');
188
                                freq_out <= '0';
189
                        elsif freq_gen > period then
190
                                freq_gen <= (others => '0');
191
                                freq_out <= not freq_out;
192
                        else
193
                                freq_gen <= freq_gen +1;
194
                        end if;
195
                end if;
196
        end process;
197
 
198
-------------------------------------------------------
199
-- Unclocked proces to generate 8 pwm outputs for LEDS
200
-------------------------------------------------------
201
        process(sys_cnt)
202
                variable i : integer range 1 to 8;
203
        begin -- process
204
                for i in 1 to 8 loop
205
                        if(v_leds((i*4)-1 downto (i-1)*4) > sys_cnt(13 downto 10)) then
206
                                bb_leds(i-1) <= '1';
207
                        else
208
                                bb_leds(i-1) <='0';
209
                        end if;
210
                end loop;
211
        end process;
212
 
213
 
214
end Behavioral;
215
 

powered by: WebSVN 2.1.0

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