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

Subversion Repositories rtfsimpleuart

[/] [rtfsimpleuart/] [trunk/] [rtl/] [verilog/] [rtfSimpleUart.v] - Diff between revs 6 and 13

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 6 Rev 13
Line 1... Line 1...
/* ============================================================================
// ============================================================================
        2007,2011  Robert Finch
//      (C) 2007,2011,2013  Robert Finch
        robfinch@<remove>sympatico.ca
//  All rights reserved.
 
//      robfinch@<remove>finitron.ca
        rtfSimpleUart.v
//
                Basic uart with baud rate generator based on a harmonic
//      rtfSimpleUart.v
        frequency synthesizer.
//              Basic uart with baud rate generator based on a harmonic
 
//      frequency synthesizer.
    This source code is available for evaluation and validation purposes
//
    only. This copyright statement and disclaimer must remain present in
//
    the file.
// Redistribution and use in source and binary forms, with or without
 
// modification, are permitted provided that the following conditions are met:
 
//     * Redistributions of source code must retain the above copyright
        NO WARRANTY.
//       notice, this list of conditions and the following disclaimer.
    THIS Work, IS PROVIDEDED "AS IS" WITH NO WARRANTIES OF ANY KIND, WHETHER
//     * Redistributions in binary form must reproduce the above copyright
    EXPRESS OR IMPLIED. The user must assume the entire risk of using the
//       notice, this list of conditions and the following disclaimer in the
    Work.
//       documentation and/or other materials provided with the distribution.
 
//     * Neither the name of the <organization> nor the
    IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
//       names of its contributors may be used to endorse or promote products
    INCIDENTAL, CONSEQUENTIAL, OR PUNITIVE DAMAGES WHATSOEVER RELATING TO
//       derived from this software without specific prior written permission.
    THE USE OF THIS WORK, OR YOUR RELATIONSHIP WITH THE AUTHOR.
//
 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
    IN ADDITION, IN NO EVENT DOES THE AUTHOR AUTHORIZE YOU TO USE THE WORK
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    IN APPLICATIONS OR SYSTEMS WHERE THE WORK'S FAILURE TO PERFORM CAN
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    REASONABLY BE EXPECTED TO RESULT IN A SIGNIFICANT PHYSICAL INJURY, OR IN
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
    LOSS OF LIFE. ANY SUCH USE BY YOU IS ENTIRELY AT YOUR OWN RISK, AND YOU
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    AGREE TO HOLD THE AUTHOR AND CONTRIBUTORS HARMLESS FROM ANY CLAIMS OR
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSSES RELATING TO SUCH UNAUTHORIZED USE.
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
        To use:
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
//
        Set the pClkFreq parameter to the frequency of the system
//
        clock (clk_i). This can be done when the core is instanced.
//      To use:
 
// 
    1) set the baud rate value in the clock multiplier
//      Set the pClkFreq parameter to the frequency of the system
    registers (CM1,2,3). A default multiplier value may
//      clock (clk_i). This can be done when the core is instanced.
    be specified using the pClkMul parameter, so it
// 
    doesn't have to be programmed at run time. (Note the
//    1) set the baud rate value in the clock multiplier
    pBaud parameter may also be set, but it doesn't work
//    registers (CM1,2,3). A default multiplier value may
    in all cases due to arithmetic limitations).
//    be specified using the pClkMul parameter, so it
    2) enable communication by activating the rts, and
//    doesn't have to be programmed at run time. (Note the
    dtr signals in the modem control register. These
//    pBaud parameter may also be set, but it doesn't work
    signals are defaulted to be active on reset, so they
//    in all cases due to arithmetic limitations).
    may not need to be set. The pRts and pDtr parameters
//    2) enable communication by activating the rts, and
    may be used to change the default setting.
//    dtr signals in the modem control register. These
    3) use interrupts or poll the status register to
//    signals are defaulted to be active on reset, so they
    determine when to transmit or receive a byte of data
//    may not need to be set. The pRts and pDtr parameters
    4) read / write the transmit / recieve data buffer
//    may be used to change the default setting.
    for communication.
//    3) use interrupts or poll the status register to
 
//    determine when to transmit or receive a byte of data
    Notes:
//    4) read / write the transmit / recieve data buffer
        This core only supports a single transmission /
//    for communication.
    reception format: 1 start, 8 data, and 1 stop bit (no
//
    parity).
//    Notes:
        The baud rate generator uses a 24 bit harmonic
//      This core only supports a single transmission /
    frequency synthesizer. Compute the multiplier value
//    reception format: 1 start, 8 data, and 1 stop bit (no
    as if a 32 bit value was needed, then take the upper
//    parity).  
    24 bits of the value. (The number of significant bits
//      The baud rate generator uses a 24 bit harmonic
    in the value determine the minimum frequency
//    frequency synthesizer. Compute the multiplier value
    resolution or the precision of the value).
//    as if a 32 bit value was needed, then take the upper
 
//    24 bits of the value. (The number of significant bits
                                baud rate * 16
//    in the value determine the minimum frequency
        value = -----------------------
//    resolution or the precision of the value).
                        (clock frequency / 2^32)
//
 
//                              baud rate * 16
                eg                      38400 * 16
//      value = -----------------------
                value = -----------------------
//                      (clock frequency / 2^32)
                                (28.63636MHz / 2^32)
//  
 
//              eg                      38400 * 16
                                = 92149557.65
//              value = -----------------------
                                = 057E1736 (hex)
//                              (28.63636MHz / 2^32)
 
//                              
 
//                              = 92149557.65
                taking the upper 24 bits
//                              = 057E1736 (hex)
                                top 24 = 057E17
//                              
                                                = 359959
//                              
 
//              taking the upper 24 bits
                so the value needed to be programmed into the register
//                              top 24 = 057E17
        for 38.4k baud is 57E17 (hex)
//                                              = 359959
                eg      CM0 = 0 (not used)
//                              
                        CM1 = 17 hex
//              so the value needed to be programmed into the register
                        CM2 = 7E hex
//      for 38.4k baud is 57E17 (hex)
                        CM3 = 05 hex
//              eg      CM0 = 0 (not used)
 
//                      CM1 = 17 hex
 
//                      CM2 = 7E hex
        Register Description
//                      CM3 = 05 hex
 
//
        reg
//
        0        read / write (RW)
//      Register Description
                TRB - transmit / receive buffer
//
                transmit / receive buffer
//      reg
                write   - write to transmit buffer
//      0        read / write (RW)
                read    - read from receive buffer
//              TRB - transmit / receive buffer
 
//              transmit / receive buffer
        1       read only (RO)
//              write   - write to transmit buffer
                LS      - line status register
//              read    - read from receive buffer
                bit 0 = receiver not empty, this bit is set if there is
//
                                any data available in the receiver fifo
//      1       read only (RO)
                bit 1 = overrun, this bit is set if receiver overrun occurs
//              LS      - line status register
                bit 3 = framing error, this bit is set if there was a
//              bit 0 = receiver not empty, this bit is set if there is
                                framing error with the current byte in the receiver
//                              any data available in the receiver fifo
                                buffer.
//              bit 1 = overrun, this bit is set if receiver overrun occurs
                bit 5 = transmitter not full, this bit is set if the transmitter
//              bit 3 = framing error, this bit is set if there was a
                                can accept more data
//                              framing error with the current byte in the receiver
                bit 6 = transmitter empty, this bit is set if the transmitter is
//                              buffer.
                                completely empty
//              bit 5 = transmitter not full, this bit is set if the transmitter
 
//                              can accept more data
        2       MS      - modem status register (RO)
//              bit 6 = transmitter empty, this bit is set if the transmitter is
                writing to the modem status register clears the change
//                              completely empty
                indicators, which should clear a modem status interrupt
//
                bit 3 = change on dcd signal
//      2       MS      - modem status register (RO)
                bit 4 = cts signal level
//              writing to the modem status register clears the change
                bit 5 = dsr signal level
//              indicators, which should clear a modem status interrupt
                bit 6 = ri signal level
//              bit 3 = change on dcd signal
                bit 7 = dcd signal level
//              bit 4 = cts signal level
 
//              bit 5 = dsr signal level
        3       IS      - interrupt status register (RO)
//              bit 6 = ri signal level
                bit 0-4 = mailbox number
//              bit 7 = dcd signal level
                bit 0,1 = 00
//
                bit 2-4 = encoded interrupt value
//      3       IS      - interrupt status register (RO)
                bit 5-6 = not used, reserved
//              bit 0-4 = mailbox number
                bit 7 = 1 = interrupt pending, 0 = no interrupt
//              bit 0,1 = 00
 
//              bit 2-4 = encoded interrupt value
        4       IE      - interrupt enable register (RW)
//              bit 5-6 = not used, reserved
                bit 0 = receive interrupt (data present)
//              bit 7 = 1 = interrupt pending, 0 = no interrupt
                bit 1 = transmit interrupt (data empty)
//
                bit 3 = modem status (dcd) register change
//      4       IE      - interrupt enable register (RW)
                bit 5-7 = unused, reserved
//              bit 0 = receive interrupt (data present)
 
//              bit 1 = transmit interrupt (data empty)
        5       FF      - frame format register         (RW)
//              bit 3 = modem status (dcd) register change
                this register doesn't do anything in the simpleUart
//              bit 5-7 = unused, reserved
                but is reserved for compatiblity with the more
//
                advanced uart
//      5       FF      - frame format register         (RW)
 
//              this register doesn't do anything in the simpleUart
        6       MC      - modem control register (RW)
//              but is reserved for compatiblity with the more
                bit 0 = dtr signal level output
//              advanced uart
                bit 1 = rts signal level output
//
 
//      6       MC      - modem control register (RW)
        7       - control register
//              bit 0 = dtr signal level output
                bit 0 = hardware flow control,
//              bit 1 = rts signal level output
                        when this bit is set, the transmitter output is
//
                        controlled by the cts signal line automatically
//      7       - control register
 
//              bit 0 = hardware flow control,
 
//                      when this bit is set, the transmitter output is
                * Clock multiplier steps the 16xbaud clock frequency
//                      controlled by the cts signal line automatically
                in increments of 1/2^32 of the clk_i input using a
//
                harmonic frequency synthesizer
//
                eg. to get a 9600 baud 16x clock (153.6 kHz) with a
//              * Clock multiplier steps the 16xbaud clock frequency
                27.175 MHz clock input,
//              in increments of 1/2^32 of the clk_i input using a
                value  = upper24(9600 * 16  / (27.175MHz / 2^32))
//              harmonic frequency synthesizer
                Higher frequency baud rates will exhibit more jitter
//              eg. to get a 9600 baud 16x clock (153.6 kHz) with a
                on the 16x clock, but this will mostly be masked by the
//              27.175 MHz clock input,
                16x clock factor.
//              value  = upper24(9600 * 16  / (27.175MHz / 2^32))
 
//              Higher frequency baud rates will exhibit more jitter
        8       CM0     - Clock Multiplier byte 0 (RW)
//              on the 16x clock, but this will mostly be masked by the 
                this is the least significant byte
//              16x clock factor.
                of the clock multiplier value
//
                this register is not used unless the clock
//      8       CM0     - Clock Multiplier byte 0 (RW)
                multiplier is set to contain 32 bit values
//              this is the least significant byte
 
//              of the clock multiplier value
        9       CM1 - Clock Multiplier byte 1   (RW)
//              this register is not used unless the clock
                this is the third most significant byte
//              multiplier is set to contain 32 bit values
                of the clock multiplier value
//
                this register is not used unless the clock
//      9       CM1 - Clock Multiplier byte 1   (RW)
                multiplier is set to contain 24 or 32 bit values
//              this is the third most significant byte
 
//              of the clock multiplier value
        10      CM2 - Clock Multiplier byte 2   (RW)
//              this register is not used unless the clock
                this is the second most significant byte of the clock
//              multiplier is set to contain 24 or 32 bit values
                multiplier value
//
 
//      10      CM2 - Clock Multiplier byte 2   (RW)
        11      CM3     - Clock Multiplier byte 3       (RW)
//              this is the second most significant byte of the clock
                this is the most significant byte of the multiplier value
//              multiplier value
 
//
        12      FC      - Fifo control register         (RW)
//      11      CM3     - Clock Multiplier byte 3       (RW)
                this register doesnt' do anything in the simpleUart
//              this is the most significant byte of the multiplier value
                but is reserved for compatibility with the more
//
                advanced uart
//      12      FC      - Fifo control register         (RW)
 
//              this register doesnt' do anything in the simpleUart
        13-14   reserved registers
//              but is reserved for compatibility with the more
 
//              advanced uart
        15      SPR     - scratch pad register (RW)
//              
 
//      13-14   reserved registers
 
//
        +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//      15      SPR     - scratch pad register (RW)
        |WISHBONE Datasheet
//
        |WISHBONE SoC Architecture Specification, Revision B.3
//
        |
//      +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        |Description:                                           Specifications:
//      |WISHBONE Datasheet
        +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//      |WISHBONE SoC Architecture Specification, Revision B.3
        |General Description:                           simple UART core
//      |
        +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//      |Description:                                           Specifications:
        |Supported Cycles:                                      SLAVE,READ/WRITE
//      +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        |                                                                       SLAVE,BLOCK READ/WRITE
//      |General Description:                           simple UART core
        |                                                                       SLAVE,RMW
//      +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//      |Supported Cycles:                                      SLAVE,READ/WRITE
        |Data port, size:                                       8 bit
//      |                                                                       SLAVE,BLOCK READ/WRITE
        |Data port, granularity:                        8 bit
//      |                                                                       SLAVE,RMW
        |Data port, maximum operand size:       8 bit
//      +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        |Data transfer ordering:                        Undefined
//      |Data port, size:                                       8 bit
        |Data transfer sequencing:                      Undefined
//      |Data port, granularity:                        8 bit
        +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//      |Data port, maximum operand size:       8 bit
        |Clock frequency constraints:           none
//      |Data transfer ordering:                        Undefined
        +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//      |Data transfer sequencing:                      Undefined
        |Supported signal list and                      Signal Name             WISHBONE equiv.
//      +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        |cross reference to equivalent          ack_o                   ACK_O
//      |Clock frequency constraints:           none
        |WISHBONE signals                                       adr_i[3:0]              ADR_I()
//      +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        |                                                                       clk_i                   CLK_I
//      |Supported signal list and                      Signal Name             WISHBONE equiv.
        |                                   rst_i           RST_I()
//      |cross reference to equivalent          ack_o                   ACK_O
        |                                                                       dat_i(7:0)              DAT_I()
//      |WISHBONE signals                                       adr_i[3:0]              ADR_I()
        |                                                                       dat_o(7:0)              DAT_O()
//      |                                                                       clk_i                   CLK_I
        |                                                                       cyc_i                   CYC_I
//      |                                   rst_i           RST_I()
        |                                                                       stb_i                   STB_I
//      |                                                                       dat_i(7:0)              DAT_I()
        |                                                                       we_i                    WE_I
//      |                                                                       dat_o(7:0)              DAT_O()
        |
//      |                                                                       cyc_i                   CYC_I
        +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//      |                                                                       stb_i                   STB_I
        |Special requirements:
//      |                                                                       we_i                    WE_I
        +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//      |
 
//      +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
//      |Special requirements:
        Ref. Spartan3 -4
//      +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        117 LUTs / 87 slices / 133 MHz
//
============================================================================ */
//=============================================================================
 
 
`define UART_TRB    4'd0    // transmit/receive buffer
`define UART_TRB    4'd0    // transmit/receive buffer
`define UART_LS     4'd1    // line status register
`define UART_LS     4'd1    // line status register
`define UART_MS     4'd2    // modem status register
`define UART_MS     4'd2    // modem status register
`define UART_IS         4'd3    // interrupt status register
`define UART_IS         4'd3    // interrupt status register

powered by: WebSVN 2.1.0

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