OpenCores
URL https://opencores.org/ocsvn/sdhc-sc-core/sdhc-sc-core/trunk

Subversion Repositories sdhc-sc-core

[/] [sdhc-sc-core/] [trunk/] [grpRs232/] [unitRs232Tx/] [src/] [Rs232Tx-Rtl-ea.vhdl] - Blame information for rev 185

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 164 rkastl
-- SDHC-SC-Core
2
-- Secure Digital High Capacity Self Configuring Core
3 78 rkastl
-- 
4 170 rkastl
-- (C) Copyright 2010, Rainer Kastl
5
-- All rights reserved.
6 164 rkastl
-- 
7 170 rkastl
-- Redistribution and use in source and binary forms, with or without
8
-- modification, are permitted provided that the following conditions are met:
9
--     * Redistributions of source code must retain the above copyright
10
--       notice, this list of conditions and the following disclaimer.
11
--     * Redistributions in binary form must reproduce the above copyright
12
--       notice, this list of conditions and the following disclaimer in the
13
--       documentation and/or other materials provided with the distribution.
14
--     * Neither the name of the <organization> nor the
15
--       names of its contributors may be used to endorse or promote products
16
--       derived from this software without specific prior written permission.
17 164 rkastl
-- 
18 170 rkastl
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  "AS IS" AND
19
-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
-- DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
22
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 164 rkastl
-- 
29
-- File        : Rs232Tx-Rtl-ea.vhdl
30
-- Owner       : Rainer Kastl
31
-- Description : Rs232 Transmitter
32
-- Links       : 
33
-- 
34 78 rkastl
 
35
library ieee;
36
use ieee.std_logic_1164.all;
37
use ieee.numeric_std.all;
38
use work.Global.all;
39
use work.Rs232.all;
40
 
41
entity Rs232Tx is
42
        generic (
43
                gDataBitWidth : natural := 8
44
        );
45
        port (
46
                iClk         : in std_ulogic;
47
                inResetAsync : in std_ulogic;
48
                iRs232Tx     : in aiRs232Tx;
49
                oRs232Tx     : out aoRs232Tx
50
        );
51
end entity Rs232Tx;
52
 
53
architecture Rtl of Rs232Tx is
54
 
55
        type aDataInputState is (
56
        CanAcceptNewData,
57
        FreshDataArrived,
58
        DataBufferBusy);
59
 
60
        type aRegion is (
61
                StartBit,
62
                DataBits,
63
                ParityBit,
64
                StopBit,
65
                StopBitAndIdle);
66
 
67
 
68
        type aRegSet is record
69
                DataInputState : aDataInputState;
70
                Region         : aRegion;
71
                BitIdx         : natural range 0 to gDataBitWidth;
72
                DataWasRead    : std_ulogic;
73
                Data           : std_ulogic_vector(gDataBitWidth - 1 downto 0);
74
                Tx             : std_ulogic;
75
        end record aRegSet;
76
 
77
        constant cInitValR : aRegSet := (
78
                DataInputState => CanAcceptNewData,
79
                Region         => StopBitAndIdle,
80
                BitIdx         => 0,
81
                DataWasRead    => cInactivated,
82
                Data           => (others => '0'),
83
                Tx             => cTxLineStopBitVal
84
        );
85
 
86
        signal R, NextR : aRegSet;
87
 
88
begin
89
 
90
        Comb : process (R, iRs232Tx)
91
                variable parity : std_ulogic;
92
        begin
93
                NextR             <= R;
94
                NextR.DataWasRead <= cInactivated;
95
 
96
                -- Parallel data input
97
                case R.DataInputState is
98
                        when CanAcceptNewData =>
99
                                -- We are waiting for data to be transmitted
100
                                if (iRs232Tx.Transmit = cActivated and
101
                                iRs232Tx.DataAvailable = cActivated) then
102
                                        NextR.Data           <= iRs232Tx.Data;
103
                                        NextR.DataInputState <= FreshDataArrived;
104
                                        NextR.DataWasRead    <= cActivated;
105
                                end if;
106
 
107
                        when FreshDataArrived =>
108
                                -- We have loaded new data into the send register
109
                                if (R.Region = StartBit) then
110
                                        NextR.DataInputState <= DataBufferBusy;
111
                                end if;
112
 
113
                        when DataBufferBusy =>
114
                                -- The send register is still occupied.
115
                                if (R.Region = StopBitAndIdle) then
116
                                        NextR.DataInputState <= CanAcceptNewData;
117
                                end if;
118
                end case;
119
 
120
                -- Serial data output
121
                case R.Region is
122
                        when StartBit =>
123
                                NextR.Tx <= cTxLineStartBitVal;
124
                                if (iRs232Tx.BitStrobe = cActivated) then
125
                                        NextR.Region <= DataBits;
126
                                        NextR.BitIdx <= 0;
127
                                end if;
128
 
129
                        when DataBits =>
130
                                NextR.Tx <= R.Data(R.BitIdx);
131
                                if (iRs232Tx.BitStrobe = cActivated) then
132
                                        if (R.BitIdx = gDataBitWidth - 1) then
133
                                                -- All bits sent
134
                                                NextR.Region <= ParityBit;
135
                                        else
136
                                                -- Send next bit
137
                                                NextR.BitIdx <= R.BitIdx + 1;
138
                                        end if;
139
                                end if;
140
 
141
                        when ParityBit =>
142
                                -- Use even parity
143
                                parity := R.Data(0);
144 79 rkastl
                                for i in 1 to gDataBitWidth-1 loop
145 78 rkastl
                                        parity := parity xor R.Data(i);
146
                                end loop;
147
                                NextR.Tx <= parity;
148
 
149
                                if (iRs232Tx.BitStrobe = cActivated) then
150
                                        NextR.Region <= StopBit;
151
                                end if;
152
 
153
                        when StopBit =>
154
                                NextR.Tx <= cTxLineStopBitVal;
155
                                if (iRs232Tx.BitStrobe = cActivated) then
156
                                        NextR.Region <= StopBitAndIdle;
157
                                end if;
158
 
159
                        when StopBitAndIdle =>
160
                                NextR.Tx <= cTxLineStopBitVal;
161
                                if (iRs232Tx.BitStrobe = cActivated) then
162
                                        if (R.DataInputState = FreshDataArrived) then
163
                                                NextR.Region <= StartBit;
164
                                        end if;
165
                                end if;
166
                end case;
167
        end process Comb;
168
 
169
        Regs : process (iClk, inResetAsync)
170
        begin
171
                if (inResetAsync = cnActivated) then
172
                        R <= cInitValR;
173
                elsif (iClk'event and iClk = '1') then
174
                        R <= NextR;
175
                end if;
176
        end process Regs;
177
 
178
        -- Connect registers to ports
179
        oRs232Tx.DataWasRead <= R.DataWasRead;
180
        oRs232Tx.Tx          <= R.Tx;
181
 
182
end architecture Rtl;
183
 

powered by: WebSVN 2.1.0

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