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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [sw/] [ttybus.h] - Blame information for rev 88

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

Line No. Rev Author Line
1 5 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    ttybus.h
4
//
5
// Project:     XuLA2 board
6
//
7
// Purpose:     This is the C++ program on the command side that will interact
8
//              with a UART on an FPGA, to command the WISHBONE on that same
9
//              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
12
//              is it a simulator.  It is a portion of a command program
13
//              for commanding an FPGA.
14
//
15
//              This particular implementation is a complete rewrite of the
16
//              last implementation, adding compression into the interface that
17
//              wasn't there before.
18
//
19
//
20
// Creator:     Dan Gisselquist, Ph.D.
21
//              Gisselquist Technology, LLC
22
//
23
////////////////////////////////////////////////////////////////////////////////
24
//
25
// Copyright (C) 2015, Gisselquist Technology, LLC
26
//
27
// This program is free software (firmware): you can redistribute it and/or
28
// modify it under the terms of  the GNU General Public License as published
29
// by the Free Software Foundation, either version 3 of the License, or (at
30
// your option) any later version.
31
//
32
// This program is distributed in the hope that it will be useful, but WITHOUT
33
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
34
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
35
// for more details.
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 46 dgisselq
        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 5 dgisselq
        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.