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

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [bench/] [cpp/] [uartsim.h] - Diff between revs 2 and 49

Show entire file | Details | Blame | View Log

Rev 2 Rev 49
Line 1... Line 1...
//
////////////////////////////////////////////////////////////////////////////////
//
//
// Filename:    uartsim.h
// Filename:    uartsim.h
//
//
// Project:     FPGA library development (S6 development board)
// Project:     wbuart32, a full featured UART with simulator
 
//
 
// Purpose:     To forward a Verilator simulated UART link over a TCP/IP pipe.
 
//
 
//      This file provides the description of the interface between the UARTSIM
 
//      and the rest of the world.  See below for more detailed descriptions.
 
//
 
// Creator:     Dan Gisselquist, Ph.D.
 
//              Gisselquist Technology, LLC
 
//
 
////////////////////////////////////////////////////////////////////////////////
 
//
 
// Copyright (C) 2015-2017, Gisselquist Technology, LLC
//
//
// Purpose:     To emulate the external parameters of a UART device, providing
// This program is free software (firmware): you can redistribute it and/or
//              the UART output to, and input from, the command
// modify it under the terms of  the GNU General Public License as published
//              console/terminal while also providing the controller with
// by the Free Software Foundation, either version 3 of the License, or (at
//              appropriate busy lines as necessary.
// your option) any later version.
//
//
// Creator:     Dan Gisselquist
// This program is distributed in the hope that it will be useful, but WITHOUT
//              Gisselquist Tecnology, LLC
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
 
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 
// for more details.
//
//
// Copyright:   2016
// You should have received a copy of the GNU General Public License along
 
// with this program.  (It's in the $(ROOT)/doc directory.  Run make with no
 
// target there if the PDF file isn't present.)  If not, see
 
// <http://www.gnu.org/licenses/> for a copy.
//
//
 
// License:     GPL, v3, as defined and found on www.gnu.org,
 
//              http://www.gnu.org/licenses/gpl.html
//
//
 
//
 
////////////////////////////////////////////////////////////////////////////////
 
//
 
//
 
#ifndef UARTSIM_H
 
#define UARTSIM_H
 
 
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <string.h>
 
#include <sys/types.h>
 
#include <sys/socket.h>
 
#include <poll.h>
#include <unistd.h>
#include <unistd.h>
 
#include <arpa/inet.h>
 
#include <signal.h>
 
 
 
#define TXIDLE  0
 
#define TXDATA  1
 
#define RXIDLE  0
 
#define RXDATA  1
 
 
class   UARTSIM {
class   UARTSIM {
private:
        // The file descriptors:
        int     m_tx_busy_count, m_baud_counts, m_rx_busy_count;
        //      m_skt   is the socket/port we are listening on
        int     m_fdin, m_fdout;
        //      m_conrd is the file descriptor to read from
        char    m_rx_next, m_tx_data;
        //      m_conwr is the file descriptor to write to
 
        int     m_skt, m_conrd, m_conwr;
 
        //
 
        // The m_setup register is the 29'bit control register used within
 
        // the core.
 
        unsigned m_setup;
 
        // And the pieces of the setup register broken out.
 
        int     m_nparity, m_fixdp, m_evenp, m_nbits, m_nstop, m_baud_counts;
 
 
 
        // UART state
 
        int     m_rx_baudcounter, m_rx_state, m_rx_busy,
 
                m_rx_changectr, m_last_tx;
 
        int     m_tx_baudcounter, m_tx_state, m_tx_busy;
 
        unsigned        m_rx_data, m_tx_data;
 
 
 
        // setup_listener is an attempt to encapsulate all of the network
 
        // related setup stuff.
 
        void    setup_listener(const int port);
 
 
 
        // nettick() gets called if we are connected to a network, and
 
        int     nettick(const int i_tx);
 
        // fdtick() if we are not.
 
        int     fdtick(const int i_tx);
 
 
 
        // We'll use the file descriptor for the listener socket to determine
 
        // whether we are connected to the network or not.  If not connected
 
        // to the network, then we assume m_conrd and m_conwr refer to 
 
        // your more traditional file descriptors, and use them as such.
 
        int     tick(const int i_tx) {
 
                if (m_skt >= 0)
 
                        return nettick(i_tx);
 
                else
 
                        return fdtick(i_tx);
 
        }
 
 
public:
public:
        UARTSIM(int baud_counts, int fdin = STDIN_FILENO,
        //
                        int fdout=STDOUT_FILENO);
        // The UARTSIM constructor takes one argument: the port on the
        int     rx(unsigned char &data);
        // localhost to listen in on.  Once started, connections may be made
        int     tx(int stb, char data);
        // to this port to get the output from the port.
};
        UARTSIM(const int port);
 
 
 
        // kill() closes any active connection and the socket.  Once killed,
 
        // no further output will be sent to the port.
 
        void    kill(void);
 
 
 
        // setup() busts out the bits from isetup to the various internal
 
        // parameters.  It is ideally only called between bits at appropriate
 
        // transition intervals. 
 
        void    setup(unsigned isetup);
 
 
 
        // The operator() function is called on every tick.  The input is the
 
        // the output txuart transmit wire from the device.  The output is to
 
        // be connected to the the rxuart receive wire into the device.  This
 
        // makes hookup and operation very simple.
 
        //
 
        // This is the most appropriate simulation entry function if the 
 
        // setup register will never change.
 
        //
 
        int     operator()(int i_tx) {
 
                return tick(i_tx); }
 
 
 
        // If there is a possibility that the core might change the UART setup,
 
        // then it makes sense to include that current setup when calling the
 
        // tick operator.
 
        int     operator()(int i_tx, unsigned isetup) {
 
                setup(isetup); return tick(i_tx); }
 
};
 
 
 
#endif
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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