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

Subversion Repositories openverifla

[/] [openverifla/] [trunk/] [openverifla_2.4/] [vhdl/] [verifla/] [u_rec_of_verifla.vhd] - Blame information for rev 46

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 46 laurentiud
-- date: 20180816_1740
2
-- author: Laurentiu Duca
3
-- license: GNU GPL
4
-----------------------------------------------------
5
 
6
library IEEE;
7
use IEEE.STD_LOGIC_1164.ALL;
8
use IEEE.NUMERIC_STD.ALL;
9
--use ieee.std_logic_arith.all;  
10
--use ieee.std_logic_unsigned.all;
11
 
12
-----------------------------------------------------
13
 
14
 
15
entity u_rec_of_verifla is
16
port(   clk_i, rst_i, baud_clk_posedge: in std_logic;
17
                rxd_i: in std_logic; -- serial data in
18
                rdy_o: out std_logic;
19
                data_o:out std_logic_vector(7 downto 0)
20
);
21
end u_rec_of_verifla;
22
 
23
-----------------------------------------------------
24
 
25
architecture u_rec_of_verifla_arch of u_rec_of_verifla is
26
 
27
        type state_type is (STA_IDLE, STA_CHECK_START_BIT, STA_RECEIVE);
28
        signal rdy_o_reg: std_logic;
29
        signal data_o_reg: std_logic_vector(7 downto 0);
30
        signal rsr: std_logic_vector(7 downto 0); -- receiving shift reg
31
        signal num_of_rec: std_logic_vector(3 downto 0);
32
   signal reg_sta: state_type;
33
        signal count: std_logic_vector(4 downto 0); -- the counter to count the clk in
34
        --signal count_c: std_logic; -- the carry of count
35
 
36
begin
37
 
38
        rdy_o <= rdy_o_reg;
39
        data_o <= data_o_reg;
40
 
41
   state_reg: process(clk_i, rst_i)
42
   begin
43
                if (rst_i='1') then
44
                        data_o_reg     <= x"00";
45
                        rdy_o_reg      <= '0';
46
                        rsr        <= x"00";
47
                        num_of_rec <= "0000";
48
                        count      <= "00000";
49
                        --count_c    <= '0';
50
                        reg_sta    <= STA_IDLE;
51
                elsif (rising_edge(clk_i)) then
52
                        if(baud_clk_posedge = '1') then
53
                                case reg_sta is
54
                                when STA_IDLE =>
55
                                        num_of_rec <= x"0";
56
                                        count <= "00000";
57
                                        if(rxd_i = '0') then
58
                                                reg_sta <= STA_CHECK_START_BIT;
59
                                        else
60
                                                reg_sta <= STA_IDLE;
61
                                        end if;
62
                                when STA_CHECK_START_BIT =>
63
                                        if(count >= "00111") then
64
                                                count <= "00000";
65
                                                if(rxd_i = '0') then
66
                                                        -- has passed 8 clk and rxd_i is still zero,then start bit has been confirmed
67
                                                        rdy_o_reg <= '0';
68
                                                        reg_sta <= STA_RECEIVE;
69
                                                else
70
                                                        reg_sta <= STA_IDLE;
71
                                                end if;
72
                                        else
73
                                                reg_sta <= STA_CHECK_START_BIT;
74
                                                count   <= std_logic_vector(unsigned(count)+"00001");
75
                                        end if;
76
                                when STA_RECEIVE =>
77
                                        count <= std_logic_vector(unsigned('0' & count(3 downto 0))+"00001");
78
                                        if(count(4) = '1') then
79
                                                -- has passed 16 clk after the last bit has been checked,sampling a bit
80
                                                if(num_of_rec <= x"7") then
81
                                                        -- sampling the received bit
82
                                                        rsr <= rxd_i & rsr(7 downto 1);
83
                                                        num_of_rec <= std_logic_vector(unsigned(num_of_rec)+"0001");
84
                                                        reg_sta <= STA_RECEIVE;
85
                                                else
86
                                                        -- sample the stop bit
87
                                                        data_o_reg <= rsr;
88
                                                        rdy_o_reg <= '1';
89
                                                        reg_sta <= STA_IDLE;
90
                                                end if;
91
                                        end if;
92
                                when others =>
93
                                        -- this is forced by the vhdl compiler
94
                                end case;
95
                        end if;
96
                end if;
97
        end process;
98
end u_rec_of_verifla_arch;

powered by: WebSVN 2.1.0

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