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_ctrl - Behavioral
|
8 |
|
|
-- File Name: uTosNet_ctrl.vhd
|
9 |
|
|
-- Project Name: uTosNet
|
10 |
|
|
-- Target Devices: SDU XC3S50AN Board
|
11 |
|
|
-- Tool versions: Xilinx ISE 11.4
|
12 |
|
|
-- Description: This module implements a state machine for accessing the
|
13 |
|
|
-- uTosNet BlockRAM.
|
14 |
|
|
--
|
15 |
|
|
-- Revision:
|
16 |
|
|
-- Revision 0.10 - Initial release
|
17 |
|
|
--
|
18 |
|
|
-- Copyright 2010
|
19 |
|
|
--
|
20 |
|
|
-- This module is free software: you can redistribute it and/or modify
|
21 |
|
|
-- it under the terms of the GNU Lesser General Public License as published by
|
22 |
|
|
-- the Free Software Foundation, either version 3 of the License, or
|
23 |
|
|
-- (at your option) any later version.
|
24 |
|
|
--
|
25 |
|
|
-- This module is distributed in the hope that it will be useful,
|
26 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
27 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
28 |
|
|
-- GNU Lesser General Public License for more details.
|
29 |
|
|
--
|
30 |
|
|
-- You should have received a copy of the GNU Lesser General Public License
|
31 |
|
|
-- along with this module. If not, see <http://www.gnu.org/licenses/>.
|
32 |
|
|
----------------------------------------------------------------------------------
|
33 |
|
|
|
34 |
|
|
library IEEE;
|
35 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
36 |
|
|
use IEEE.STD_LOGIC_ARITH.ALL;
|
37 |
|
|
use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
38 |
|
|
|
39 |
|
|
entity uTosNet_ctrl is
|
40 |
|
|
Port ( T_clk_50M : in STD_LOGIC;
|
41 |
|
|
T_serial_out : out STD_LOGIC;
|
42 |
|
|
T_serial_in : in STD_LOGIC;
|
43 |
|
|
T_reg_ptr : out std_logic_vector(2 downto 0);
|
44 |
|
|
T_word_ptr : out std_logic_vector(1 downto 0);
|
45 |
|
|
T_data_to_mem : in std_logic_vector(31 downto 0);
|
46 |
|
|
T_data_from_mem : out std_logic_vector(31 downto 0);
|
47 |
|
|
T_data_from_mem_latch : out std_logic);
|
48 |
|
|
end uTosNet_ctrl;
|
49 |
|
|
|
50 |
|
|
-------------------------------------------------
|
51 |
|
|
|
52 |
|
|
architecture Behavioral of uTosNet_ctrl is
|
53 |
|
|
|
54 |
|
|
component uTosNet_uart is
|
55 |
|
|
Port ( clk_50M : in STD_LOGIC;
|
56 |
|
|
serial_out : out STD_LOGIC;
|
57 |
|
|
serial_in : in STD_LOGIC;
|
58 |
|
|
dataReg_addr : in STD_LOGIC_VECTOR(5 downto 0);
|
59 |
|
|
dataReg_dataIn : in STD_LOGIC_VECTOR(31 downto 0);
|
60 |
|
|
dataReg_dataOut : out STD_LOGIC_VECTOR(31 downto 0);
|
61 |
|
|
dataReg_clk : in STD_LOGIC;
|
62 |
|
|
dataReg_writeEnable : in STD_LOGIC);
|
63 |
|
|
end component;
|
64 |
|
|
|
65 |
|
|
type STATES is (IDLE, SETUP_1, CLK_1, DONE_1);
|
66 |
|
|
|
67 |
|
|
signal state : STATES := IDLE;
|
68 |
|
|
signal nextState : STATES := IDLE;
|
69 |
|
|
|
70 |
|
|
signal dataReg_addr : STD_LOGIC_VECTOR(5 downto 0);
|
71 |
|
|
signal dataReg_dataIn : STD_LOGIC_VECTOR(31 downto 0);
|
72 |
|
|
signal dataReg_dataOut : STD_LOGIC_VECTOR(31 downto 0);
|
73 |
|
|
signal dataReg_clk : STD_LOGIC;
|
74 |
|
|
signal dataReg_we : STD_LOGIC;
|
75 |
|
|
|
76 |
|
|
signal word_cnt : STD_LOGIC_VECTOR(5 downto 0) := (others => '0');
|
77 |
|
|
|
78 |
|
|
begin
|
79 |
|
|
|
80 |
|
|
uTosNet_uartInst : uTosNet_uart
|
81 |
|
|
Port map ( clk_50M => T_clk_50M,
|
82 |
|
|
serial_out => T_serial_out,
|
83 |
|
|
serial_in => T_serial_in,
|
84 |
|
|
dataReg_addr => dataReg_addr,
|
85 |
|
|
dataReg_dataIn => dataReg_dataIn,
|
86 |
|
|
dataReg_dataOut => dataReg_dataOut,
|
87 |
|
|
dataReg_clk => dataReg_clk,
|
88 |
|
|
dataReg_writeEnable => dataReg_we);
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
T_data_from_mem <= dataReg_dataOut;
|
92 |
|
|
dataReg_dataIn <= T_data_to_mem;
|
93 |
|
|
T_reg_ptr <= dataReg_addr(5 downto 3);
|
94 |
|
|
T_word_ptr <= dataReg_addr(1 downto 0);
|
95 |
|
|
|
96 |
|
|
process(T_clk_50M)
|
97 |
|
|
begin
|
98 |
|
|
if(T_clk_50M = '1' and T_clk_50M'event) then
|
99 |
|
|
state <= nextState;
|
100 |
|
|
|
101 |
|
|
case state is
|
102 |
|
|
when IDLE =>
|
103 |
|
|
when SETUP_1 =>
|
104 |
|
|
dataReg_addr <= word_cnt(5 downto 3) & word_cnt(0) & word_cnt(2 downto 1);
|
105 |
|
|
-- < register > | in/out area | word index
|
106 |
|
|
dataReg_clk <= '0';
|
107 |
|
|
T_data_from_mem_latch <= '0';
|
108 |
|
|
word_cnt <= word_cnt;
|
109 |
|
|
if word_cnt(0) = '0' then -- If we are looking at a slave output register
|
110 |
|
|
dataReg_we <= '1'; -- Prepare to copy data from bus to RAM block
|
111 |
|
|
else
|
112 |
|
|
dataReg_we <= '0';
|
113 |
|
|
end if;
|
114 |
|
|
when CLK_1 =>
|
115 |
|
|
dataReg_clk <= '1';
|
116 |
|
|
if word_cnt(0) = '1' then -- If we are looking at a slave_input register
|
117 |
|
|
T_data_from_mem_latch <= '1'; -- Signal bus-slave, that data can be copied from the bus
|
118 |
|
|
dataReg_we <= '0';
|
119 |
|
|
else
|
120 |
|
|
dataReg_we <= '1';
|
121 |
|
|
T_data_from_mem_latch <= '0';
|
122 |
|
|
end if;
|
123 |
|
|
word_cnt <= word_cnt;
|
124 |
|
|
when DONE_1 =>
|
125 |
|
|
dataReg_we <='0';
|
126 |
|
|
T_data_from_mem_latch <= '0';
|
127 |
|
|
word_cnt <= word_cnt + 1;
|
128 |
|
|
end case;
|
129 |
|
|
end if;
|
130 |
|
|
end process;
|
131 |
|
|
|
132 |
|
|
process(state)
|
133 |
|
|
begin
|
134 |
|
|
case state is
|
135 |
|
|
when IDLE =>
|
136 |
|
|
nextState <= SETUP_1;
|
137 |
|
|
when SETUP_1 =>
|
138 |
|
|
nextState <= CLK_1;
|
139 |
|
|
when CLK_1 =>
|
140 |
|
|
nextState <= DONE_1;
|
141 |
|
|
when DONE_1 =>
|
142 |
|
|
nextState <= IDLE;
|
143 |
|
|
end case;
|
144 |
|
|
end process;
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
end architecture;
|