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

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [host/] [ttybus.h] - Diff between revs 11 and 45

Only display areas with differences | Details | Blame | View Log

Rev 11 Rev 45
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
// Filename:    ttybus.h
// Filename:    ttybus.h
//
//
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
//
//
// Purpose:     This is the C++ program on the command side that will interact
// Purpose:     This is the C++ program on the command side that will interact
//              with a serial port (through DEPP) on an FPGA, to command the
//              with a serial port (through DEPP) on an FPGA, to command the
//      WISHBONE on that same FPGA to ... whatever we wish to command it to do.
//      WISHBONE on that same FPGA to ... whatever we wish to command it to do.
//
//
//      This code does not run on an FPGA, is not a test bench, neither is it
//      This code does not run on an FPGA, is not a test bench, neither is it
//      a simulator.  It is a portion of a command program for commanding an
//      a simulator.  It is a portion of a command program for commanding an
//      FPGA from an attached host computer.
//      FPGA from an attached host computer.
//
//
// Creator:     Dan Gisselquist, Ph.D.
// Creator:     Dan Gisselquist, Ph.D.
//              Gisselquist Technology, LLC
//              Gisselquist Technology, LLC
//
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
// Copyright (C) 2015-2017, Gisselquist Technology, LLC
//
//
// This program is free software (firmware): you can redistribute it and/or
// This program is free software (firmware): you can redistribute it and/or
// modify it under the terms of  the GNU General Public License as published
// modify it under the terms of  the GNU General Public License as published
// by the Free Software Foundation, either version 3 of the License, or (at
// by the Free Software Foundation, either version 3 of the License, or (at
// your option) any later version.
// your option) any later version.
//
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// for more details.
//
//
// You should have received a copy of the GNU General Public License along
// 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
// 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
// target there if the PDF file isn't present.)  If not, see
// <http://www.gnu.org/licenses/> for a copy.
// <http://www.gnu.org/licenses/> for a copy.
//
//
// License:     GPL, v3, as defined and found on www.gnu.org,
// License:     GPL, v3, as defined and found on www.gnu.org,
//              http://www.gnu.org/licenses/gpl.html
//              http://www.gnu.org/licenses/gpl.html
//
//
//
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
//
//
//
//
#ifndef TTYBUS_H
#ifndef TTYBUS_H
#define TTYBUS_H
#define TTYBUS_H
 
 
#include "llcomms.h"
#include "llcomms.h"
#include "devbus.h"
#include "devbus.h"
 
 
#define RDBUFLN 2048
#define RDBUFLN 2048
 
 
class   TTYBUS : public DEVBUS {
class   TTYBUS : public DEVBUS {
public:
public:
        unsigned long   m_total_nread;
        unsigned long   m_total_nread;
private:
private:
        LLCOMMSI        *m_dev;
        LLCOMMSI        *m_dev;
        static  const   unsigned MAXRDLEN, MAXWRLEN;
        static  const   unsigned MAXRDLEN, MAXWRLEN;
 
 
        bool    m_interrupt_flag, m_decode_err, m_addr_set, m_bus_err;
        bool    m_interrupt_flag, m_decode_err, m_addr_set, m_bus_err;
        unsigned int    m_lastaddr;
        unsigned int    m_lastaddr;
 
 
        int     m_buflen, m_rdfirst, m_rdlast;
        int     m_buflen, m_rdfirst, m_rdlast;
        char    *m_buf, *m_rdbuf;
        char    *m_buf, *m_rdbuf;
 
 
        bool    m_wrloaded;
        bool    m_wrloaded;
        int     m_rdaddr, m_wraddr;
        int     m_rdaddr, m_wraddr;
        BUSW    m_readtbl[1024], m_writetbl[512];
        BUSW    m_readtbl[1024], m_writetbl[512];
 
 
        void    init(void) {
        void    init(void) {
                m_interrupt_flag = false;
                m_interrupt_flag = false;
                m_buflen = 0; m_buf = NULL;
                m_buflen = 0; m_buf = NULL;
                m_addr_set = false;
                m_addr_set = false;
                bufalloc(64);
                bufalloc(64);
                m_bus_err = false;
                m_bus_err = false;
                m_decode_err = false;
                m_decode_err = false;
                m_wrloaded = false;
                m_wrloaded = false;
 
 
                m_rdfirst = m_rdlast = 0;
                m_rdfirst = m_rdlast = 0;
                m_rdbuf = new char[RDBUFLN];
                m_rdbuf = new char[RDBUFLN];
 
 
                m_rdaddr = m_wraddr = 0;
                m_rdaddr = m_wraddr = 0;
        }
        }
 
 
        char    charenc(const int sixbitval) const;
        char    charenc(const int sixbitval) const;
        unsigned chardec(const char b) const;
        unsigned chardec(const char b) const;
        void    encode(const int fbits, const BUSW v, char *buf) const;
        void    encode(const int fbits, const BUSW v, char *buf) const;
        unsigned decodestr(const char *buf) const;
        unsigned decodestr(const char *buf) const;
        int     decodehex(const char hx) const;
        int     decodehex(const char hx) const;
        void    bufalloc(int len);
        void    bufalloc(int len);
        BUSW    readword(void); // Reads a word value from the bus
        BUSW    readword(void); // Reads a word value from the bus
        void    readv(const BUSW a, const int inc, const int len, BUSW *buf);
        void    readv(const BUSW a, const int inc, const int len, BUSW *buf);
        void    writev(const BUSW a, const int p, const int len, const BUSW *buf);
        void    writev(const BUSW a, const int p, const int len, const BUSW *buf);
 
        void    readidle(void);
 
 
        int     lclread(char *buf, int len);
        int     lclread(char *buf, int len);
        int     lclreadcode(char *buf, int len);
        int     lclreadcode(char *buf, int len);
        char    *encode_address(const BUSW a);
        char    *encode_address(const BUSW a);
        char    *readcmd(const int inc, const int len, char *buf);
        char    *readcmd(const int inc, const int len, char *buf);
public:
public:
        TTYBUS(LLCOMMSI *comms) : m_dev(comms) { init(); }
        TTYBUS(LLCOMMSI *comms) : m_dev(comms) { init(); }
        virtual ~TTYBUS(void) {
        virtual ~TTYBUS(void) {
                m_dev->close();
                m_dev->close();
                if (m_buf) delete[] m_buf; m_buf = NULL;
                if (m_buf) delete[] m_buf; m_buf = NULL;
                delete m_rdbuf; m_rdbuf = NULL;
                delete m_rdbuf; m_rdbuf = NULL;
                delete  m_dev;
                delete  m_dev;
        }
        }
 
 
        void    kill(void) { m_dev->close(); }
        void    kill(void) { m_dev->close(); }
        void    close(void) {   m_dev->close(); }
        void    close(void) {   m_dev->close(); }
        void    writeio(const BUSW a, const BUSW v);
        void    writeio(const BUSW a, const BUSW v);
        BUSW    readio(const BUSW a);
        BUSW    readio(const BUSW a);
        void    readi(const BUSW a, const int len, BUSW *buf);
        void    readi( const BUSW a, const int len, BUSW *buf);
        void    readz(const BUSW a, const int len, BUSW *buf);
        void    readz( const BUSW a, const int len, BUSW *buf);
        void    writei(const BUSW a, const int len, const BUSW *buf);
        void    writei(const BUSW a, const int len, const BUSW *buf);
        void    writez(const BUSW a, const int len, const BUSW *buf);
        void    writez(const BUSW a, const int len, const BUSW *buf);
        bool    poll(void) { return m_interrupt_flag; };
        bool    poll(void) { return m_interrupt_flag; };
        void    usleep(unsigned msec); // Sleep until interrupt
        void    usleep(unsigned msec); // Sleep until interrupt
        void    wait(void); // Sleep until interrupt
        void    wait(void); // Sleep until interrupt
        bool    bus_err(void) const { return m_bus_err; };
        bool    bus_err(void) const { return m_bus_err; };
        void    reset_err(void) { m_bus_err = false; }
        void    reset_err(void) { m_bus_err = false; }
        void    clear(void) { m_interrupt_flag = false; }
        void    clear(void) { m_interrupt_flag = false; }
};
};
 
 
#endif
#endif
 
 

powered by: WebSVN 2.1.0

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