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

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [host/] [ttybus.h] - Blame information for rev 31

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    ttybus.h
4
//
5
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
6
//
7
// Purpose:     This is the C++ program on the command side that will interact
8
//              with a serial port (through DEPP) on an FPGA, to command the
9
//      WISHBONE on that same FPGA to ... whatever we wish to command it to do.
10
//
11
//      This code does not run on an FPGA, is not a test bench, neither is it
12
//      a simulator.  It is a portion of a command program for commanding an
13
//      FPGA from an attached host computer.
14
//
15
// Creator:     Dan Gisselquist, Ph.D.
16
//              Gisselquist Technology, LLC
17
//
18
////////////////////////////////////////////////////////////////////////////////
19
//
20
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
21
//
22
// This program is free software (firmware): you can redistribute it and/or
23
// modify it under the terms of  the GNU General Public License as published
24
// by the Free Software Foundation, either version 3 of the License, or (at
25
// your option) any later version.
26
//
27
// This program is distributed in the hope that it will be useful, but WITHOUT
28
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
29
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
30
// for more details.
31
//
32
// You should have received a copy of the GNU General Public License along
33
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
34
// target there if the PDF file isn't present.)  If not, see
35
// <http://www.gnu.org/licenses/> for a copy.
36
//
37
// License:     GPL, v3, as defined and found on www.gnu.org,
38
//              http://www.gnu.org/licenses/gpl.html
39
//
40
//
41
////////////////////////////////////////////////////////////////////////////////
42
//
43
//
44
//
45
#ifndef TTYBUS_H
46
#define TTYBUS_H
47
 
48
#include "llcomms.h"
49
#include "devbus.h"
50
 
51
#define RDBUFLN 2048
52
 
53
class   TTYBUS : public DEVBUS {
54
public:
55
        unsigned long   m_total_nread;
56
private:
57
        LLCOMMSI        *m_dev;
58
        static  const   unsigned MAXRDLEN, MAXWRLEN;
59
 
60
        bool    m_interrupt_flag, m_decode_err, m_addr_set, m_bus_err;
61
        unsigned int    m_lastaddr;
62
 
63
        int     m_buflen, m_rdfirst, m_rdlast;
64
        char    *m_buf, *m_rdbuf;
65
 
66
        bool    m_wrloaded;
67
        int     m_rdaddr, m_wraddr;
68
        BUSW    m_readtbl[1024], m_writetbl[512];
69
 
70
        void    init(void) {
71
                m_interrupt_flag = false;
72
                m_buflen = 0; m_buf = NULL;
73
                m_addr_set = false;
74
                bufalloc(64);
75
                m_bus_err = false;
76
                m_decode_err = false;
77
                m_wrloaded = false;
78
 
79
                m_rdfirst = m_rdlast = 0;
80
                m_rdbuf = new char[RDBUFLN];
81
 
82
                m_rdaddr = m_wraddr = 0;
83
        }
84
 
85
        char    charenc(const int sixbitval) const;
86
        unsigned chardec(const char b) const;
87
        void    encode(const int fbits, const BUSW v, char *buf) const;
88
        unsigned decodestr(const char *buf) const;
89
        int     decodehex(const char hx) const;
90
        void    bufalloc(int len);
91
        BUSW    readword(void); // Reads a word value from the bus
92
        void    readv(const BUSW a, const int inc, const int len, BUSW *buf);
93
        void    writev(const BUSW a, const int p, const int len, const BUSW *buf);
94
 
95
        int     lclread(char *buf, int len);
96
        int     lclreadcode(char *buf, int len);
97
        char    *encode_address(const BUSW a);
98
        char    *readcmd(const int inc, const int len, char *buf);
99
public:
100
        TTYBUS(LLCOMMSI *comms) : m_dev(comms) { init(); }
101
        virtual ~TTYBUS(void) {
102
                m_dev->close();
103
                if (m_buf) delete[] m_buf; m_buf = NULL;
104
                delete m_rdbuf; m_rdbuf = NULL;
105
                delete  m_dev;
106
        }
107
 
108
        void    kill(void) { m_dev->close(); }
109
        void    close(void) {   m_dev->close(); }
110
        void    writeio(const BUSW a, const BUSW v);
111
        BUSW    readio(const BUSW a);
112
        void    readi(const BUSW a, const int len, BUSW *buf);
113
        void    readz(const BUSW a, const int len, BUSW *buf);
114
        void    writei(const BUSW a, const int len, const BUSW *buf);
115
        void    writez(const BUSW a, const int len, const BUSW *buf);
116
        bool    poll(void) { return m_interrupt_flag; };
117
        void    usleep(unsigned msec); // Sleep until interrupt
118
        void    wait(void); // Sleep until interrupt
119
        bool    bus_err(void) const { return m_bus_err; };
120
        void    reset_err(void) { m_bus_err = false; }
121
        void    clear(void) { m_interrupt_flag = false; }
122
};
123
 
124
#endif

powered by: WebSVN 2.1.0

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