////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
// Filename: ttybus.h
|
// Filename: ttybus.h
|
//
|
//
|
// Project: XuLA2 board
|
// Project: XuLA2 board
|
//
|
//
|
// 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 UART on an FPGA, to command the WISHBONE on that same
|
// with a UART on an FPGA, to command the WISHBONE on that same
|
// FPGA to ... whatever we wish to command it to do.
|
// FPGA to ... whatever we wish to command it to do.
|
//
|
//
|
// This code does not run on an FPGA, is not a test bench, neither
|
// 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
|
// is it a simulator. It is a portion of a command program
|
// for commanding an FPGA.
|
// for commanding an FPGA.
|
//
|
//
|
// This particular implementation is a complete rewrite of the
|
// This particular implementation is a complete rewrite of the
|
// last implementation, adding compression into the interface that
|
// last implementation, adding compression into the interface that
|
// wasn't there before.
|
// wasn't there before.
|
//
|
//
|
//
|
//
|
// Creator: Dan Gisselquist, Ph.D.
|
// Creator: Dan Gisselquist, Ph.D.
|
// Gisselquist Technology, LLC
|
// Gisselquist Technology, LLC
|
//
|
//
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
// Copyright (C) 2015, Gisselquist Technology, LLC
|
// Copyright (C) 2015, 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.
|
//
|
//
|
// 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);
|
char charenc(const int sixbitval) const;
|
unsigned chardec(const char b);
|
unsigned chardec(const char b) const;
|
void encode(const int fbits, const BUSW v, char *buf);
|
void encode(const int fbits, const BUSW v, char *buf) const;
|
unsigned decodestr(const char *buf);
|
unsigned decodestr(const char *buf) const;
|
int decodehex(const char hx);
|
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);
|
|
|
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
|
|
|