| 1 |
51 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
| 2 |
4 |
dgisselq |
//
|
| 3 |
51 |
dgisselq |
// Filename: ttybus.h
|
| 4 |
4 |
dgisselq |
//
|
| 5 |
51 |
dgisselq |
// Project: OpenArty, an entirely open SoC based upon the Arty platform
|
| 6 |
4 |
dgisselq |
//
|
| 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 |
51 |
dgisselq |
// 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 |
4 |
dgisselq |
//
|
| 15 |
51 |
dgisselq |
// This particular implementation is a complete rewrite of the
|
| 16 |
|
|
// last implementation, adding compression into the interface that
|
| 17 |
|
|
// wasn't there before.
|
| 18 |
4 |
dgisselq |
//
|
| 19 |
|
|
//
|
| 20 |
51 |
dgisselq |
// Creator: Dan Gisselquist, Ph.D.
|
| 21 |
|
|
// Gisselquist Technology, LLC
|
| 22 |
4 |
dgisselq |
//
|
| 23 |
51 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
| 24 |
4 |
dgisselq |
//
|
| 25 |
51 |
dgisselq |
// Copyright (C) 2015-2017, 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 |
|
|
// You should have received a copy of the GNU General Public License along
|
| 38 |
|
|
// with this program. (It's in the $(ROOT)/doc directory. Run make with no
|
| 39 |
|
|
// target there if the PDF file isn't present.) If not, see
|
| 40 |
|
|
// <http://www.gnu.org/licenses/> for a copy.
|
| 41 |
|
|
//
|
| 42 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
| 43 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
| 44 |
|
|
//
|
| 45 |
|
|
//
|
| 46 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
| 47 |
|
|
//
|
| 48 |
|
|
//
|
| 49 |
|
|
//
|
| 50 |
4 |
dgisselq |
#ifndef TTYBUS_H
|
| 51 |
|
|
#define TTYBUS_H
|
| 52 |
|
|
|
| 53 |
|
|
#include "llcomms.h"
|
| 54 |
|
|
#include "devbus.h"
|
| 55 |
|
|
|
| 56 |
|
|
#define RDBUFLN 2048
|
| 57 |
|
|
|
| 58 |
|
|
class TTYBUS : public DEVBUS {
|
| 59 |
|
|
public:
|
| 60 |
|
|
unsigned long m_total_nread;
|
| 61 |
|
|
private:
|
| 62 |
|
|
LLCOMMSI *m_dev;
|
| 63 |
|
|
static const unsigned MAXRDLEN, MAXWRLEN;
|
| 64 |
|
|
|
| 65 |
|
|
bool m_interrupt_flag, m_decode_err, m_addr_set, m_bus_err;
|
| 66 |
|
|
unsigned int m_lastaddr;
|
| 67 |
|
|
|
| 68 |
|
|
int m_buflen, m_rdfirst, m_rdlast;
|
| 69 |
|
|
char *m_buf, *m_rdbuf;
|
| 70 |
|
|
|
| 71 |
|
|
bool m_wrloaded;
|
| 72 |
|
|
int m_rdaddr, m_wraddr;
|
| 73 |
|
|
BUSW m_readtbl[1024], m_writetbl[512];
|
| 74 |
|
|
|
| 75 |
|
|
void init(void) {
|
| 76 |
|
|
m_interrupt_flag = false;
|
| 77 |
|
|
m_buflen = 0; m_buf = NULL;
|
| 78 |
|
|
m_addr_set = false;
|
| 79 |
|
|
bufalloc(64);
|
| 80 |
|
|
m_bus_err = false;
|
| 81 |
|
|
m_decode_err = false;
|
| 82 |
|
|
m_wrloaded = false;
|
| 83 |
|
|
|
| 84 |
|
|
m_rdfirst = m_rdlast = 0;
|
| 85 |
|
|
m_rdbuf = new char[RDBUFLN];
|
| 86 |
|
|
|
| 87 |
|
|
m_rdaddr = m_wraddr = 0;
|
| 88 |
|
|
}
|
| 89 |
|
|
|
| 90 |
|
|
char charenc(const int sixbitval) const;
|
| 91 |
|
|
unsigned chardec(const char b) const;
|
| 92 |
|
|
void encode(const int fbits, const BUSW v, char *buf) const;
|
| 93 |
|
|
unsigned decodestr(const char *buf) const;
|
| 94 |
|
|
int decodehex(const char hx) const;
|
| 95 |
|
|
void bufalloc(int len);
|
| 96 |
|
|
BUSW readword(void); // Reads a word value from the bus
|
| 97 |
|
|
void readv(const BUSW a, const int inc, const int len, BUSW *buf);
|
| 98 |
|
|
void writev(const BUSW a, const int p, const int len, const BUSW *buf);
|
| 99 |
|
|
void readidle(void);
|
| 100 |
|
|
|
| 101 |
|
|
int lclread(char *buf, int len);
|
| 102 |
|
|
int lclreadcode(char *buf, int len);
|
| 103 |
|
|
char *encode_address(const BUSW a);
|
| 104 |
|
|
char *readcmd(const int inc, const int len, char *buf);
|
| 105 |
|
|
public:
|
| 106 |
|
|
TTYBUS(LLCOMMSI *comms) : m_dev(comms) { init(); }
|
| 107 |
|
|
virtual ~TTYBUS(void) {
|
| 108 |
|
|
m_dev->close();
|
| 109 |
|
|
if (m_buf) delete[] m_buf; m_buf = NULL;
|
| 110 |
|
|
delete m_rdbuf; m_rdbuf = NULL;
|
| 111 |
|
|
delete m_dev;
|
| 112 |
|
|
}
|
| 113 |
|
|
|
| 114 |
|
|
void kill(void) { m_dev->close(); }
|
| 115 |
|
|
void close(void) { m_dev->close(); }
|
| 116 |
|
|
void writeio(const BUSW a, const BUSW v);
|
| 117 |
|
|
BUSW readio(const BUSW a);
|
| 118 |
51 |
dgisselq |
void readi( const BUSW a, const int len, BUSW *buf);
|
| 119 |
|
|
void readz( const BUSW a, const int len, BUSW *buf);
|
| 120 |
4 |
dgisselq |
void writei(const BUSW a, const int len, const BUSW *buf);
|
| 121 |
|
|
void writez(const BUSW a, const int len, const BUSW *buf);
|
| 122 |
|
|
bool poll(void) { return m_interrupt_flag; };
|
| 123 |
|
|
void usleep(unsigned msec); // Sleep until interrupt
|
| 124 |
|
|
void wait(void); // Sleep until interrupt
|
| 125 |
|
|
bool bus_err(void) const { return m_bus_err; };
|
| 126 |
|
|
void reset_err(void) { m_bus_err = false; }
|
| 127 |
|
|
void clear(void) { m_interrupt_flag = false; }
|
| 128 |
|
|
};
|
| 129 |
|
|
|
| 130 |
|
|
#endif
|