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

Subversion Repositories uart_block

[/] [uart_block/] [trunk/] [hdl/] [iseProject/] [SERIALMASTER.vhd] - Blame information for rev 36

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 36 leonardoar
--! @file
2
--! @brief Top wishbone Master to test the uart_wishbone_slave
3 27 leonardoar
library ieee;
4
USE ieee.std_logic_1164.ALL;
5
use ieee.std_logic_unsigned.all;
6
use ieee.std_logic_arith.all;
7
 
8
--! Use CPU Definitions package
9
use work.pkgDefinitions.all;
10
 
11
entity SERIALMASTER is
12
        port(
13
            -- WISHBONE Signals
14 36 leonardoar
            ACK_I:  in  std_logic;                                                              --! Ack input
15
            ADR_O:  out std_logic_vector( 1 downto 0 );  --! Address output
16
            CLK_I:  in  std_logic;                                                              --! Clock input
17
            CYC_O:  out std_logic;                                                              --! Cycle output
18
            DAT_I:  in  std_logic_vector( 31 downto 0 ); --! Data input
19
            DAT_O:  out std_logic_vector( 31 downto 0 ); --! Data output
20
            RST_I:  in  std_logic;                                                              --! Reset input
21
            SEL_O:  out std_logic;                                                              --! Select output
22
            STB_O:  out std_logic;                                                              --! Strobe output (Works like a chip select)
23
            WE_O:   out std_logic;                                                              --! Write enable
24 27 leonardoar
 
25
                                -- NON-WISHBONE Signals
26 36 leonardoar
                                byte_rec : out std_logic_vector(7 downto 0)      --! Signal byte received (Used to debug on the out leds)        
27 27 leonardoar
         );
28
 
29
end SERIALMASTER;
30
 
31 36 leonardoar
--! @brief Test the uart_wishbone_slave
32
--! @details Configure the core then, send the received data back to the PC
33 27 leonardoar
architecture Behavioral of SERIALMASTER is
34
signal masterSerialStates : testMaster;
35
signal byteIncome : std_logic_vector(7 downto 0);
36
begin
37
 
38
        process (CLK_I)
39
        variable contWait : integer range 0 to 50000000;
40 28 leonardoar
        variable cycles2Wait : integer range 0 to 50000000;
41 27 leonardoar
        variable nextState: testMaster;
42
        begin
43
                if rising_edge(CLK_I) then
44
                        if RST_I = '1' then
45
                                masterSerialStates <= idle;
46
                                nextState := idle;
47
                                contWait := 0;
48 28 leonardoar
                                cycles2Wait := 25000000;
49
                                byteIncome <= conv_std_logic_vector(64, (nBitsLarge));  --Send the '@';
50 27 leonardoar
                        else
51
                                case masterSerialStates is
52
                                        when idle =>
53
                                                masterSerialStates <= config_clock;
54
                                                nextState := idle;
55
 
56
                                        when config_clock =>
57
                                                nextState := config_baud;
58
                                                ADR_O <= "00";
59
                                                WE_O <= '1';
60
                                                STB_O <= '1';
61
                                                DAT_O <= conv_std_logic_vector(50000000, (nBitsLarge));         -- 50Mhz
62
                                                if ACK_I = '1' then
63
                                                        -- Byte received wait some cycles to continue                                           
64
                                                        masterSerialStates <= wait_cycles;
65
                                                        byte_rec        <= "00000001";
66
                                                end if;
67
 
68
                                        when config_baud =>
69
                                                nextState := send_byte;
70
                                                ADR_O <= "01";
71
                                                WE_O <= '1';
72
                                                STB_O <= '1';
73
                                                DAT_O <= conv_std_logic_vector(115200, (nBitsLarge));   --115200 bps
74
                                                if ACK_I = '1' then
75
                                                        -- Byte received wait some cycles to continue
76
                                                        masterSerialStates <= wait_cycles;
77
                                                        byte_rec        <= "00000010";
78
                                                end if;
79
 
80
                                        when send_byte =>
81
                                                nextState := receive_byte;
82
                                                ADR_O <= "10";
83
                                                WE_O <= '1';
84
                                                STB_O <= '1';
85
                                                --DAT_O <= conv_std_logic_vector(64, (nBitsLarge));     --Send the '@'
86
                                                DAT_O <= conv_std_logic_vector(0, (nBitsLarge-8)) & byteIncome;  --Send the '@'
87
                                                if ACK_I = '1' then
88
                                                        -- Byte received wait some cycles to continue
89 28 leonardoar
                                                        masterSerialStates <= wait_cycles;
90
                                                        cycles2Wait     := 7000000;
91 27 leonardoar
                                                end if;
92
 
93
                                        when receive_byte =>
94
                                                nextState := send_byte;
95
                                                ADR_O <= "11";
96
                                                WE_O <= '0';
97
                                                STB_O <= '1';
98
                                                if ACK_I = '1' then
99
                                                        -- Byte received wait some cycles to continue
100
                                                        masterSerialStates <= wait_cycles;
101
                                                        byte_rec        <= DAT_I(7 downto 0);
102
                                                        byteIncome <= DAT_I(7 downto 0);
103 28 leonardoar
                                                        cycles2Wait     := 7000000;
104 27 leonardoar
                                                end if;
105
 
106
                                        when wait_cycles =>
107 36 leonardoar
                                                -- wait some cycles 
108 28 leonardoar
                                                if contWait < cycles2Wait then
109 27 leonardoar
                                                        contWait := contWait + 1;
110
                                                        STB_O <= '0';
111
                                                else
112
                                                        contWait := 0;
113
                                                        masterSerialStates <= nextState;
114
                                                end if;
115
                                end case;
116
                        end if;
117
                end if;
118
        end process;
119
 
120
 
121
end Behavioral;
122
 

powered by: WebSVN 2.1.0

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