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

Subversion Repositories image_component_labeling_and_feature_extraction

[/] [image_component_labeling_and_feature_extraction/] [trunk/] [UART_Component.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 malikpearl
------------------------------------------------------------------------
2
-- uartcomponent.vhd
3
------------------------------------------------------------------------
4
-- Author:  Dan Pederson
5
--          Copyright 2004 Digilent, Inc.
6
------------------------------------------------------------------------
7
-- Description: This file defines a UART which transfers data to and 
8
--                              from serial and parallel information.  It requires two 
9
--                              major processes:  receiving and transferring.  The 
10
--                              receiving portion reads serially transmitted data, and
11
--                              converts it into parallel data, while the transferring
12
--                              portion reads parallel data, and transmits it as serial 
13
--                              data.  There are three error signals provided with this 
14
--                              UART.  They are frame error, parity error, and overwrite 
15
--                              error signals.  This UART is configured to use an ODD 
16
--                              parity bit at a baud rate of 9600. 
17
--              
18
------------------------------------------------------------------------
19
-- Revision History:
20
--      07/15/04 (DanP) Created 
21
--              05/24/05 (DanP) Updated commenting style
22
--              06/06/05 (DanP) Synchronized state machines to fix timing bug           
23
------------------------------------------------------------------------
24
 
25
library IEEE;
26
use IEEE.STD_LOGIC_1164.ALL;
27
use IEEE.STD_LOGIC_ARITH.ALL;
28
use IEEE.STD_LOGIC_UNSIGNED.ALL;
29
 
30
-------------------------------------------------------------------------
31
--
32
--Title:        UARTcomponent entity
33
--
34
--Inputs:       7       :       RXD
35
--                                      CLK
36
--                                      DBIN
37
--                                      RDA
38
--                                      RD
39
--                                      WR
40
--                                      RST
41
--
42
--Outputs:      7       :       TXD
43
--                                      DBOUT
44
--                                      RDA
45
--                                      TBE
46
--                                      PE
47
--                                      FE
48
--                                      OE                                              
49
--
50
--Description:  This describes the UART component entity.  The inputs are
51
--                              the Pegasus 50 MHz clock, a reset button, The RXD from 
52
--                              the serial cable, an 8-bit data bus from the parallel 
53
--                              port, and Read Data Available (RDA)and Transfer Buffer 
54
--                              Empty(TBE) handshaking signals.  The outputs are the TXD 
55
--                              signal for the serial port, an 8-bit data bus for the
56
--                              parallel port, RDA and TBE handshaking signals, and three
57
--                              error signals for parity, frame, and overwrite errors.
58
--
59
-------------------------------------------------------------------------
60
entity UARTcomponent is
61
    Port (      TXD     : out   std_logic       := '1';                                 -- Transmitted serial data output
62
                RXD     : in    std_logic;                                                                      -- Received serial data input
63
                CLK     : in    std_logic;                                                                      -- Clock signal
64
                        DBIN    : in    std_logic_vector (7 downto 0);           -- Input parallel data to be transmitted
65
                        DBOUT   : out   std_logic_vector (7 downto 0);   -- Recevived parallel data output
66
                        RDA             : inout std_logic;                                                              -- Read Data Available
67
                        TBE             : out   std_logic       := '1';                            -- Transfer Buffer Emty
68
                        RD              : in    std_logic;
69
                        WR              : in    std_logic;
70
                        PE              : out   std_logic;                                                                      -- Parity error         
71
                        FE              : out   std_logic;                                                                      -- Frame error
72
                        OE              : out   std_logic;                                                                      -- Overwrite error
73
                        RST             : in    std_logic       := '0');                                 -- Reset signal
74
 
75
end UARTcomponent;
76
 
77
architecture Behavioral of UARTcomponent is
78
 
79
------------------------------------------------------------------------
80
-- Local Type and Signal Declarations
81
------------------------------------------------------------------------
82
 
83
-------------------------------------------------------------------------
84
--Title:        Local Type Declarations
85
--
86
--Description:  There are two state machines used in this entity.  The
87
--                              rstate is used to synchronize the receiving portion of 
88
--                              the UART, and the tstate is used to synchronize the 
89
--                              sending portion of the UART.
90
--
91
-------------------------------------------------------------------------
92
        type rstate is (
93
                strIdle,
94
                strEightDelay,
95
                strGetData,
96
                strWaitFor0,
97
                strWaitFor1,
98
                strCheckStop
99
        );
100
 
101
        type tstate is (
102
                sttIdle,
103
                sttTransfer,
104
                sttShift,
105
                sttDelay,
106
                sttWaitWrite
107
                );
108
 
109
-------------------------------------------------------------------------
110
--
111
--Title:  Local Signal Declarations
112
--
113
--Description:  The constants and signals used by this entity are 
114
--                              described below:
115
--
116
--                              -baudRate       :       This is the Baud Rate constant used to 
117
--                                                              synchronize the Pegasus 50 MHz clock with a 
118
--                                                              baud rate of 9600.  To get this number, divide 
119
--                                                              50MHz by 9600.
120
--                              -baudDivide     :       This is the Baud Rate divider used to safely
121
--                                                              read data transmitted at a baud rate of 9600.
122
--                                                              It is simply the above described baudRate
123
--                                                              constant divided by 16.
124
--
125
--                              -rdReg          :       this is the receive holding register
126
--                              -rdSReg         :       this is the receive shift register
127
--                              -tfReg          :       this is the transfer holding register
128
--                              -tfSReg         :       this is the transfer shifting register 
129
--                              -clkDiv         :       counter used to get rClk
130
--                              -ctr            :       used for delay times
131
--                              -tfCtr          :       used to delay in the transfer process
132
--                              -dataCtr        :       counts the number of read data bits
133
--                              -parError       :       parity error bit
134
--                              -frameError     :       frame error bit
135
--                              -CE                     :       clock enable bit for the writing latch
136
--                              -ctRst          :       reset for the ctr
137
--                              -load           :       load signal used to load the transfer shift
138
--                                                              register
139
--                              -shift          :       shift signal used to unload the transfer
140
--                                                              shift register
141
--                              -par            :       represents the parity in the transfer
142
--                                                              holding register
143
--                              -tClkRST        :       reset for the tfCtr     
144
--                              -rShift         :       shift signal used to load the receive shift
145
--                                                              register
146
--                              -dataRST        :       reset for the dataCtr
147
--                              -dataIncr       :       signal to increment the dataCtr
148
--                              -tfIncr         :       signal to increment the tfCtr
149
--                              -tDelayCtr      :       counter used to delay the transfer state 
150
--                                                              machine.
151
--                              -tDelayRst      :       reset signal for the tDelayCtr counter.
152
--                               
153
--                              The following signals are used by the two state machines
154
--                              for state control:
155
--                              -Receive State Machine  :       strCur, strNext
156
--                              -Transfer State Machine :       sttCur, sttNext
157
--      
158
-------------------------------------------------------------------------
159
 
160
--      constant baudRate       :       std_logic_vector(12 downto 0) := "1 0100 0101 1000";  
161
--      constant baudRate       :       std_logic_vector(12 downto 0) := conv_std_logic_vector(1406,13); --19200
162
   constant baudRate    :       std_logic_vector(12 downto 0) := conv_std_logic_vector(234,13);  -- 115 200
163
--      constant baudRate       :       std_logic_vector(12 downto 0) := conv_std_logic_vector(482,13);  -- 56 000
164
-- baudrate is set for 115 200 at 27MHz clock freq
165
        constant baudDivide     :       std_logic_vector(8 downto 0)     := conv_std_logic_vector(15,9);
166
 
167
        signal rdReg            :       std_logic_vector(7 downto 0)     := "00000000";
168
        signal rdSReg           :       std_logic_vector(9 downto 0)     := "1111111111";
169
        signal tfReg            :       std_logic_vector(7 downto 0);
170
        signal tfSReg           :       std_logic_vector(10 downto 0)    := "11111111111";
171
        signal clkDiv           :       std_logic_vector(9 downto 0)             := "0000000000";
172
        signal ctr                      :       std_logic_vector(3 downto 0)             := "0000";
173
        signal tfCtr            :       std_logic_vector(3 downto 0)             := "0000";
174
        signal dataCtr          :       std_logic_vector(3 downto 0)             := "0000";
175
        signal parError         :       std_logic;
176
        signal frameError       :       std_logic;
177
        signal CE                       :       std_logic;
178
        signal ctRst            :       std_logic       := '0';
179
        signal load                     :       std_logic       := '0';
180
        signal shift            :       std_logic       := '0';
181
        signal par                      :       std_logic;
182
        signal tClkRST          :       std_logic       := '0';
183
        signal rShift           :       std_logic       := '0';
184
        signal dataRST          :       std_logic       := '0';
185
        signal dataIncr         :       std_logic       := '0';
186
        signal tfIncr           :       std_logic       := '0';
187
        signal tDelayCtr        :       std_logic_vector (12 downto 0);
188
        signal tDelayRst        :       std_logic := '0';
189
 
190
        signal strCur           :  rstate       := strIdle;
191
        signal strNext          :  rstate;
192
        signal sttCur           :  tstate       := sttIdle;
193
        signal sttNext          :  tstate;
194
 
195
-------------------------------------------------------------------------
196
-- Module Implementation
197
-------------------------------------------------------------------------
198
begin
199
-------------------------------------------------------------------------
200
--
201
--Title:  Initial signal definitions
202
--
203
--Description:  The following lines of code define 4 internal and 1
204
--                              external signal.  The most significant bit of the rdSReg
205
--                              signifies the frame error bit, so frameError is tied to
206
--                              that signal.  The parError is high if there is a parity
207
--                              error, so it is set equal to the inverse of rdSReg(8) 
208
--                              XOR-ed with the data bits.  In this manner, it can 
209
--                              determine if the parity bit found in rdSReg(8) matches 
210
--                              the data bits.  The parallel information output is equal
211
--                              to rdReg, so DBOUT is set equal to rdReg.  Likewise, the 
212
--                              input parallel information is equal to DBIN, so tfReg is 
213
--                              set equal to DBIN.  Because the tfSReg is used to shift
214
--                              out transmitted data, the TXD port is set equal to the
215
--                              first bit of tfsReg.  Finally, the par signal represents 
216
--                              the parity of the data, so par is set to the inverse of 
217
--                              the data bits XOR-ed together.  This UART can be changed 
218
--                              to use EVEN parity if the "not" is omitted from the par 
219
--                              definition.
220
--
221
-------------------------------------------------------------------------
222
        frameError <= not rdSReg(9);
223
        parError <= not ( rdSReg(8) xor (((rdSReg(0) xor rdSReg(1)) xor
224
                (rdSReg(2) xor rdSReg(3))) xor ((rdSReg(4) xor rdSReg(5)) xor
225
                (rdSReg(6) xor rdSReg(7)))) );
226
        DBOUT <= rdReg;
227
        tfReg <= DBIN;
228
        TXD <= tfsReg(0);
229
        par <=  not ( ((tfReg(0) xor tfReg(1)) xor (tfReg(2) xor tfReg(3))) xor
230
                ((tfReg(4) xor tfReg(5)) xor (tfReg(6) xor tfReg(7))) );
231
-------------------------------------------------------------------------
232
--
233
--Title: Clock Divide counter 
234
--
235
--Description:  This process defines clkDiv as a signal that increments
236
--                              with the clock up until it is either reset by ctRst, or
237
--                              equals baudDivide.  This signal is used to define a 
238
--                              counter called ctr that increments at the rate of the 
239
--                              divided baud rate.
240
--
241
-------------------------------------------------------------------------
242
        process (CLK, clkDiv)
243
                begin
244
                        if (CLK = '1' and CLK'event) then
245
                                if (clkDiv = baudDivide or ctRst = '1') then
246
                                        clkDiv <= "0000000000";
247
                                else
248
                                        clkDiv <= clkDiv +1;
249
                                end if;
250
                        end if;
251
                end process;
252
-------------------------------------------------------------------------
253
--
254
--Title: Transfer delay counter 
255
--
256
--Description:  This process defines tDelayCtr as a counter that runs
257
--                              until it equals baudRate, or until it is reset by 
258
--                              tDelayRst.  This counter is used to measure delay times
259
--                              when sending data out on the TXD signal.  When the 
260
--                              counter is equal to baudRate, or is reset, it is set 
261
--                              equal to 0.
262
--
263
-------------------------------------------------------------------------
264
        process (CLK, tDelayCtr)
265
                begin
266
                        if (CLK = '1' and CLK'event) then
267
                                if (tDelayCtr = baudRate or tDelayRst = '1') then
268
                                        tDelayCtr <= "0000000000000";
269
                                else
270
                                        tDelayCtr <= tDelayCtr+1;
271
                                end if;
272
                        end if;
273
                end process;
274
-------------------------------------------------------------------------
275
--
276
--Title: ctr set up 
277
--
278
--Description:  This process sets up ctr, which uses clkDiv to count
279
--                              increase at a rate needed to properly receive data in
280
--                              from RXD.  If ctRst is strobed, the counter is reset.  If
281
--                              clkDiv is equal to baudDivide, then ctr is incremented
282
--                              once.  This signal is used by the receiving state machine
283
--                              to measure delay times between RXD reads.               
284
--
285
-------------------------------------------------------------------------
286
        process (CLK)
287
                begin
288
                        if CLK = '1' and CLK'Event then
289
                                if ctRst = '1' then
290
                                        ctr <= "0000";
291
                                elsif clkDiv = baudDivide then
292
                                        ctr <= ctr + 1;
293
                                else
294
                                        ctr <= ctr;
295
                                end if;
296
                        end if;
297
                end process;
298
-------------------------------------------------------------------------
299
--
300
--Title: transfer counter 
301
--
302
--Description:  This process makes tfCtr increment whenever the tfIncr
303
--                              signal is strobed high.  If the tClkRst signal is strobed
304
--                              high, the tfCtr is reset to "0000."  This counter is used
305
--                              to keep track of how many data bits have been 
306
--                              transmitted.
307
--
308
-------------------------------------------------------------------------
309
        process (CLK, tClkRST)
310
                begin
311
                        if (CLK = '1' and CLK'event) then
312
                                if tClkRST = '1' then
313
                                        tfCtr <= "0000";
314
                                elsif tfIncr = '1' then
315
                                        tfCtr <= tfCtr +1;
316
                                end if;
317
                        end if;
318
                end process;
319
-------------------------------------------------------------------------
320
--
321
--Title: Error and RDA flag controller 
322
--
323
--Description:  This process controls the error flags FE, OE, and PE, as
324
--                              well as the Read Data Available (RDA) flag.  When CE goes
325
--                              high, it means that data has been read into the rdSReg.
326
--                              This process then analyzes the read data for errors, sets
327
--                              rdReg equal to the eight data bits in rdSReg, and flags
328
--                              RDA to indicate that new data is present in rdReg.  FE 
329
--                              and PE are simply equal to the frameError and parError 
330
--                              signals.  OE is flagged high if RDA is already high when 
331
--                              CE is strobed.  This means that unread data was still in 
332
--                              the rdReg when it was written over with the new data.   
333
--
334
-------------------------------------------------------------------------
335
        process (CLK, RST, RD, CE)
336
                begin
337
                        if RD = '1' or RST = '1' then
338
                                FE <= '0';
339
                                OE <= '0';
340
                                RDA <= '0';
341
                                PE <= '0';
342
                        elsif CLK = '1' and CLK'event then
343
                                if CE = '1' then
344
                                        FE <= frameError;
345
                                        PE <= parError;
346
                                        rdReg(7 downto 0) <= rdSReg (7 downto 0);
347
                                        if RDA = '1' then
348
                                                OE <= '1';
349
                                        else
350
                                                OE <= '0';
351
                                                RDA <= '1';
352
                                        end if;
353
                                end if;
354
                        end if;
355
                end process;
356
-------------------------------------------------------------------------
357
--
358
--Title: Receiving shift register 
359
--
360
--Description:  This process controls the receiving shift register 
361
--                              (rdSReg).  Whenever rShift is high, implying that data 
362
--                              needs to be shifted in, rdSReg is shifts in RXD to the 
363
--                              most significant bit, while shifting its existing data 
364
--                              right.
365
--
366
-------------------------------------------------------------------------
367
        process (CLK, rShift)
368
                begin
369
                        if CLK = '1' and CLK'Event then
370
                                if rShift = '1' then
371
                                        rdSReg <= (RXD & rdSReg(9 downto 1));
372
                                end if;
373
                        end if;
374
                end process;
375
-------------------------------------------------------------------------
376
--
377
--Title: Incoming Data counter 
378
--
379
--Description:  This process controls the dataCtr to keep track of 
380
--                              shifted values into the rdSReg.  The dataCtr signal is 
381
--                              incremented once every time dataIncr is strobed high.
382
--                              
383
-------------------------------------------------------------------------
384
 
385
        process (CLK, dataRST)
386
                begin
387
                        if (CLK = '1' and CLK'event) then
388
                                if dataRST = '1' then
389
                                        dataCtr <= "0000";
390
                                elsif dataIncr = '1' then
391
                                        dataCtr <= dataCtr +1;
392
                                end if;
393
                        end if;
394
                end process;
395
-------------------------------------------------------------------------
396
--
397
--Title: Receiving State Machine controller 
398
--
399
--Description:  This process takes care of the Receiving state machine
400
--                              movement.  It causes the next state to be evaluated on
401
--                              each rising edge of CLK.  If the RST signal is strobed,
402
--                              the state is changed to the default starting state,
403
--                              which is strIdle
404
--
405
-------------------------------------------------------------------------
406
        process (CLK, RST)
407
                begin
408
                        if CLK = '1' and CLK'Event then
409
                                if RST = '1' then
410
                                        strCur <= strIdle;
411
                                else
412
                                        strCur <= strNext;
413
                                end if;
414
                        end if;
415
                end process;
416
-------------------------------------------------------------------------
417
--
418
--Title: Receiving State Machine  
419
--
420
--Description:  This process contains all of the next state logic for the
421
--                              Receiving state machine.
422
--
423
-------------------------------------------------------------------------                               
424
        process (strCur, ctr, RXD, dataCtr)
425
                begin
426
                        case strCur is
427
-------------------------------------------------------------------------
428
--
429
--Title: strIdle state 
430
--
431
--Description:  This state is the idle and startup default stage for the
432
--                              Receiving state machine.  The machine stays in this state
433
--                              until the RXD signal goes low.  When this occurs, the
434
--                              ctRst signal is strobed to reset ctr for the next state,
435
--                              which is strEightDelay.  
436
--
437
-------------------------------------------------------------------------
438
                                when strIdle =>
439
                                        dataIncr <= '0';
440
                                        rShift <= '0';
441
                                        dataRst <= '1';
442
                                        CE <= '0';
443
                                        ctRst <= '1';
444
 
445
                                        if RXD = '0' then
446
                                                strNext <= strEightDelay;
447
                                        else
448
                                                strNext <= strIdle;
449
                                        end if;
450
-------------------------------------------------------------------------
451
--
452
--Title: strEightDelay state 
453
--
454
--Description:  This state simply delays the state machine for eight clock
455
--                              cycles.  This is needed so that the incoming RXD data 
456
--                              signal is read in the middle of each data emission.  This
457
--                              ensures an accurate RXD signal reading.  ctr counts from 
458
--                              0 to 8 to keep track of rClk cycles.  When it equals 8 
459
--                              (1000) the next state, strWaitFor0, is loaded.  During 
460
--                              this state, the dataRst signal is strobed high to reset 
461
--                              the shift-in data counter (dataCtr).
462
--
463
-------------------------------------------------------------------------                       
464
                                when strEightDelay =>
465
                                        dataIncr <= '0';
466
                                        rShift <= '0';
467
                                        dataRst <= '1';
468
                                        CE <= '0';
469
                                        ctRst <= '0';
470
 
471
                                        if ctr(3 downto 0) = "1000" then
472
                                                strNext <= strWaitFor0;
473
                                        else
474
                                                strNext <= strEightDelay;
475
                                        end if;
476
-------------------------------------------------------------------------
477
--
478
--Title: strGetData state 
479
--
480
--Description:  In this state, the dataIncr and rShift signals are 
481
--                              strobed high for one clock cycle.  By doing this, the 
482
--                              rdSReg shift register shifts in RXD once, while the 
483
--                              dataCtr is incremented by one.  This state simply 
484
--                              captures the incoming data on RXD into the rdSReg shift 
485
--                              register.  The next state loaded is strWaitFor0, which 
486
--                              starts the two delay states needed between data shifts. 
487
--
488
-------------------------------------------------------------------------       
489
                                when strGetData =>
490
                                        CE <= '0';
491
                                        dataRst <= '0';
492
                                        ctRst <= '0';
493
                                        dataIncr <= '1';
494
                                        rShift <= '1';
495
 
496
                                        strNext <= strWaitFor0;
497
-------------------------------------------------------------------------
498
--
499
--Title: strWaitFor0 state 
500
--
501
--Description:  This state is a delay state, which delays the receive
502
--                              state machine if not all of the incoming serial data has
503
--                              not been shifted in yet.  If dataCtr does not equal 10
504
--                              (1010), the state is stayed in until the fourth bit of
505
--                              ctr is equal to 1.  When this happens, half of the delay
506
--                              has been achieved, and the second delay state is loaded, 
507
--                              which is strWaitFor1.  If dataCtr does equal 10 (1010),
508
--                              all of the needed data has been acquired, so the 
509
--                              strCheckStop state is loaded to check for errors and 
510
--                              reset the receive state machine.
511
--
512
-------------------------------------------------------------------------
513
                                when strWaitFor0 =>
514
                                        CE <= '0';
515
                                        dataRst <= '0';
516
                                        ctRst <= '0';
517
                                        dataIncr <= '0';
518
                                        rShift <= '0';
519
 
520
                                        if dataCtr = "1010" then
521
                                                strNext <= strCheckStop;
522
                                        elsif ctr(3) = '0' then
523
                                                strNext <= strWaitFor1;
524
                                        else
525
                                                strNext <= strWaitFor0;
526
                                        end if;
527
-------------------------------------------------------------------------
528
--
529
--Title: strEightDelay state 
530
--
531
--Description:  This state is much like strWaitFor0, except it waits for
532
--                              the fourth bit of ctr to equal 1.  Once this occurs, the
533
--                              strGetData state is loaded in order to shift in the next
534
--                              data bit from RXD.  Because strWaitFor0 is the only state
535
--                              that calls this state, no other signals need to be 
536
--                              checked.
537
--
538
-------------------------------------------------------------------------                               
539
                                when strWaitFor1 =>
540
                                        CE <= '0';
541
                                        dataRst <= '0';
542
                                        ctRst <= '0';
543
                                        dataIncr <=     '0';
544
                                        rShift <= '0';
545
 
546
                                        if ctr(3) = '0' then
547
                                                strNext <= strWaitFor1;
548
                                        else
549
                                                strNext <= strGetData;
550
                                        end if;
551
-------------------------------------------------------------------------
552
--
553
--Title: strCheckStop state 
554
--
555
--Description:  This state allows the newly acquired data to be checked
556
--                              for errors.  The CE flag is strobed to start the
557
--                              previously defined error checking process.  This state is
558
--                              passed straight through to the strIdle state.
559
--
560
-------------------------------------------------------------------------                       
561
                                when strCheckStop =>
562
                                        dataIncr <= '0';
563
                                        rShift <= '0';
564
                                        dataRst <= '0';
565
                                        ctRst <= '0';
566
                                        CE <= '1';
567
                                        strNext <= strIdle;
568
                        end case;
569
                end process;
570
-------------------------------------------------------------------------
571
--
572
--Title: Transfer shift register controller 
573
--
574
--Description:  This process uses the load, shift, and clk signals to 
575
--                              control the transfer shift register (tfSReg).  Once load
576
--                              is equal to '1', the tfSReg gets a '1', the parity bit,
577
--                              the data bits found in tfReg, and a '0'.  Under this
578
--                              format, the shift register can be used to shift out the
579
--                              appropriate signal to serially transfer the data.  The
580
--                              data is shifted out of the tfSReg whenever shift = '1'. 
581
--
582
-------------------------------------------------------------------------
583
        process (load, shift, CLK, tfSReg)
584
                begin
585
                        if CLK = '1' and CLK'Event then
586
                                if load = '1' then
587
                                        tfSReg (10 downto 0) <= ('1' & par & tfReg(7 downto 0) &'0');
588
                                elsif shift = '1' then
589
                                        tfSReg (10 downto 0) <= ('1' & tfSReg(10 downto 1));
590
                                end if;
591
                        end if;
592
                end process;
593
-------------------------------------------------------------------------
594
--
595
--Title: Transfer State Machine controller 
596
--
597
--Description:  This process takes care of the Transfer state machine
598
--                              movement.  It causes the next state to be evaluated on
599
--                              each rising edge of CLK.  If the RST signal is strobed,
600
--                              the state is changed to the default starting state, which
601
--                              is sttIdle.
602
--
603
-------------------------------------------------------------------------
604
        process (CLK, RST)
605
                begin
606
                        if (CLK = '1' and CLK'Event) then
607
                                if RST = '1' then
608
                                        sttCur <= sttIdle;
609
                                else
610
                                        sttCur <= sttNext;
611
                                end if;
612
                        end if;
613
                end process;
614
-------------------------------------------------------------------------
615
--
616
--Title: Transfer State Machine 
617
--
618
--Description:  This process controls the next state logic in the 
619
--                              transfer state machine.  The transfer state machine 
620
--                              controls the shift and load signals that are used to load 
621
--                              and transmit the parallel data in a serial form.  It also 
622
--                              controls the Transmit Buffer Empty (TBE) signal that 
623
--                              indicates if the transmit buffer (tfSReg) is in use or 
624
--                              not.
625
--
626
-------------------------------------------------------------------------       
627
        process (sttCur, tfCtr, WR, tDelayCtr)
628
                begin
629
                        case sttCur is
630
-------------------------------------------------------------------------
631
--
632
--Title: sttIdle state 
633
--
634
--Description:  This state is the idle and startup default stage for the 
635
--                              transfer state machine.  The state is stayed in until
636
--                              the WR signal goes high.  Once it goes high, the 
637
--                              sttTransfer state is loaded.  The load and shift signals
638
--                              are held low in the sttIdle state, while the TBE signal
639
--                              is held high to indicate that the transmit buffer is not
640
--                              currently in use.  Once the idle state is left, the TBE
641
--                              signal is held low to indicate that the transfer state
642
--                              machine is using the transmit buffer.
643
--
644
-------------------------------------------------------------------------               
645
                                when sttIdle =>
646
                                        TBE <= '1';
647
                                        tClkRST <= '0';
648
                                        tfIncr <= '0';
649
                                        shift <= '0';
650
                                        load <= '0';
651
                                        tDelayRst <= '1';
652
 
653
                                        if WR = '0' then
654
                                                sttNext <= sttIdle;
655
                                        else
656
                                                sttNext <= sttTransfer;
657
                                        end if;
658
-------------------------------------------------------------------------
659
--
660
--Title: sttTransfer state
661
--
662
--Description:  This state sets the load, tClkRST, and tDelayRst signals 
663
--                              high, while setting the TBE signal low.  The load signal 
664
--                              is set high to load the transfer shift register with the 
665
--                              appropriate data, while the tClkRST and tDelayRst signals 
666
--                              are strobed to reset the tfCtr and tDelayCtr.  The next
667
--                              state loaded is the sttDelay state.
668
--                      
669
-------------------------------------------------------------------------
670
                                when sttTransfer =>
671
                                        TBE <= '0';
672
                                        shift <= '0';
673
                                        load <= '1';
674
                                        tClkRST <= '1';
675
                                        tfIncr <= '0';
676
                                        tDelayRst <= '1';
677
 
678
                                        sttNext <= sttDelay;
679
-------------------------------------------------------------------------
680
--
681
--Title: sttShift state 
682
--
683
--Description:  This state strobes the shift and tfIncr signals high, and
684
--                              checks the tfCtr to see if enough data has been 
685
--                              transmitted.  By strobing the shift and tfIncr signals
686
--                              high, the tfSReg is shifted, and the tfCtr is incremented
687
--                              once.  If tfCtr does not equal 9 (1001), then not all of
688
--                              the bits have been transmitted, so the next state loaded 
689
--                              is the sttDelay state.  If tfCtr does equal 9, the final 
690
--                              state, sttWaitWrite, is loaded.
691
--
692
-------------------------------------------------------------------------
693
                                when sttShift =>
694
                                        TBE <= '0';
695
                                        shift <= '1';
696
                                        load <= '0';
697
                                        tfIncr <= '1';
698
                                        tClkRST <= '0';
699
                                        tDelayRst <= '0';
700
 
701
                                        if tfCtr = "1010" then
702
                                                sttNext <= sttWaitWrite;
703
                                        else
704
                                                sttNext <= sttDelay;
705
                                        end if;
706
-------------------------------------------------------------------------
707
--
708
--Title: sttDelay state
709
--
710
--Description:  This state is responsible for delaying the transfer state
711
--                              machine between transmissions.  All signals are held low
712
--                              while the tDelayCtr is tested.  Once tDelayCtr is equal 
713
--                              to baudRate, the sttShift state is loaded.  
714
--                      
715
-------------------------------------------------------------------------
716
                                when sttDelay =>
717
                                        TBE <= '0';
718
                                        shift <= '0';
719
                                        load <= '0';
720
                                        tClkRst <= '0';
721
                                        tfIncr <= '0';
722
                                        tDelayRst <= '0';
723
 
724
                                        if tDelayCtr = baudRate then
725
                                                sttNext <= sttShift;
726
                                        else
727
                                                sttNext <= sttDelay;
728
                                        end if;
729
-------------------------------------------------------------------------
730
--
731
--Title: sttWaitWrite state
732
--
733
--Description:  This state checks to make sure that the initial WR signal
734
--                              that triggered the transfer state machine has been 
735
--                              brought back low.  Without this state, a write signal 
736
--                              that is held high for a long time will result in multiple 
737
--                              transmissions.  Once the WR signal is low, the sttIdle 
738
--                              state is loaded to reset the transfer state machine.
739
--                      
740
-------------------------------------------------------------------------                                       
741
                                when sttWaitWrite =>
742
                                        TBE <= '0';
743
                                        shift <= '0';
744
                                        load <= '0';
745
                                        tClkRst <= '0';
746
                                        tfIncr <= '0';
747
                                        tDelayRst <= '0';
748
 
749
                                        if WR = '1' then
750
                                                sttNext <= sttWaitWrite;
751
                                        else
752
                                                sttNext <= sttIdle;
753
                                        end if;
754
                        end case;
755
                end process;
756
end Behavioral;

powered by: WebSVN 2.1.0

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