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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [sw/] [host/] [ttybus.h] - Blame information for rev 32

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

Line No. Rev Author Line
1 4 dgisselq
//
2
//
3
// Filename:    ttybus.h
4
//
5
// Project:     UART to WISHBONE FPGA library
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
// Creator:     Dan Gisselquist
20
//              Gisselquist Tecnology, LLC
21
//
22
// Copyright:   2015
23
//
24
//
25
#ifndef TTYBUS_H
26
#define TTYBUS_H
27
 
28
#include "llcomms.h"
29
#include "devbus.h"
30
 
31
#define RDBUFLN 2048
32
 
33
class   TTYBUS : public DEVBUS {
34
public:
35
        unsigned long   m_total_nread;
36
private:
37
        LLCOMMSI        *m_dev;
38
        static  const   unsigned MAXRDLEN, MAXWRLEN;
39
 
40
        bool    m_interrupt_flag, m_decode_err, m_addr_set, m_bus_err;
41
        unsigned int    m_lastaddr;
42
 
43
        int     m_buflen, m_rdfirst, m_rdlast;
44
        char    *m_buf, *m_rdbuf;
45
 
46
        bool    m_wrloaded;
47
        int     m_rdaddr, m_wraddr;
48
        BUSW    m_readtbl[1024], m_writetbl[512];
49
 
50
        void    init(void) {
51
                m_interrupt_flag = false;
52
                m_buflen = 0; m_buf = NULL;
53
                m_addr_set = false;
54
                bufalloc(64);
55
                m_bus_err = false;
56
                m_decode_err = false;
57
                m_wrloaded = false;
58
 
59
                m_rdfirst = m_rdlast = 0;
60
                m_rdbuf = new char[RDBUFLN];
61
 
62
                m_rdaddr = m_wraddr = 0;
63
        }
64
 
65
        char    charenc(const int sixbitval) const;
66
        unsigned chardec(const char b) const;
67
        void    encode(const int fbits, const BUSW v, char *buf) const;
68
        unsigned decodestr(const char *buf) const;
69
        int     decodehex(const char hx) const;
70
        void    bufalloc(int len);
71
        BUSW    readword(void); // Reads a word value from the bus
72
        void    readv(const BUSW a, const int inc, const int len, BUSW *buf);
73
        void    writev(const BUSW a, const int p, const int len, const BUSW *buf);
74
        void    readidle(void);
75
 
76
        int     lclread(char *buf, int len);
77
        int     lclreadcode(char *buf, int len);
78
        char    *encode_address(const BUSW a);
79
        char    *readcmd(const int inc, const int len, char *buf);
80
public:
81
        TTYBUS(LLCOMMSI *comms) : m_dev(comms) { init(); }
82
        virtual ~TTYBUS(void) {
83
                m_dev->close();
84
                if (m_buf) delete[] m_buf; m_buf = NULL;
85
                delete m_rdbuf; m_rdbuf = NULL;
86
                delete  m_dev;
87
        }
88
 
89
        void    kill(void) { m_dev->close(); }
90
        void    close(void) {   m_dev->close(); }
91
        void    writeio(const BUSW a, const BUSW v);
92
        BUSW    readio(const BUSW a);
93
        void    readi(const BUSW a, const int len, BUSW *buf);
94
        void    readz(const BUSW a, const int len, BUSW *buf);
95
        void    writei(const BUSW a, const int len, const BUSW *buf);
96
        void    writez(const BUSW a, const int len, const BUSW *buf);
97
        bool    poll(void) { return m_interrupt_flag; };
98
        void    usleep(unsigned msec); // Sleep until interrupt
99
        void    wait(void); // Sleep until interrupt
100
        bool    bus_err(void) const { return m_bus_err; };
101
        void    reset_err(void) { m_bus_err = false; }
102
        void    clear(void) { m_interrupt_flag = false; }
103
};
104
 
105
#endif

powered by: WebSVN 2.1.0

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