--- /dev/null
+#include "../iext.hpp"
+
+class Cuart : public Iext {
+ public:
+ Cuart() : m_writeAddress(0), m_fetchCount(0), m_readCount(0), m_recRdy(0), m_txRdy(0), m_recVal(0), m_txVal(0) {};
+ void applyTick() {};
+ void loadData(const int address, CDat value);
+ CDat readData(const int);
+ void parseInput(const vector<string>& in);
+ private:
+ int m_writeAddress, m_fetchCount, m_readCount;
+ bool m_recRdy, m_txRdy;
+ CDat m_recVal, m_txVal;
+};
+
+
+void Cuart::parseInput(const vector<string>& in)
+{
+ if(in.size() > 1) {
+ if((in[1].compare("h") == 0)) {
+ cout << "UART:" << endl;
+ cout << "\textension uart r 0xXX \t -- to load the module with a value" << endl;
+ cout << "\textension uart f \t-- to load a value from the module" << endl;
+ }
+ }
+ if(in.size() < 2) {
+ return;
+ }
+ if(in[1].compare("uart") == 0) {
+ if(in[2].compare("r") == 0) {
+ if(in.size() < 3) {
+ return;
+ }
+ if(in[3].substr(0,2) == "0x") {
+ m_recVal = lexical_cast<uint32_from_hex>(in[3]);
+ }
+ else {
+ m_recVal = lexical_cast<unsigned int>(in[3]);
+ }
+ cout << "UART: loaded 0x" << std::hex << m_recVal << std::dec << endl;
+ m_recRdy = 1;
+ m_fetchCount = 0;
+ m_readCount = 0;
+ }
+ else if(in[2].compare("f") == 0) {
+ cout << "UART: sended 0x" << std::hex << m_txVal << std::dec << endl;
+ m_txRdy = 0;
+ m_fetchCount = 0;
+ m_readCount = 0;
+ }
+ else if(in[2].compare("s") == 0) {
+ cout << "UART:" << endl;
+ cout << "\ttx busy: " << m_txRdy << endl;
+ cout << "\trx_newdata: " << m_recRdy << endl;
+ }
+ }
+}
+
+CDat Cuart::readData(const int address)
+{
+ if(address == 0x2000) {
+ //status - r only
+/* cout << "rx: " << m_recRdy << endl;
+ cout << "tx: " << m_txRdy << endl;
+ CDat helpme = m_recRdy;
+ helpme <<= 1;
+ helpme |= m_txRdy;
+ cout << "rx<<1 | tx: " << helpme << endl;
+*/
+ if(m_txRdy == 1) {
+ m_fetchCount++;
+ }
+ if(m_recRdy == 0) {
+ m_readCount++;
+ }
+
+ if(m_fetchCount >= 5) {
+ m_fetchCount = 0;
+ m_readCount = 0;
+ m_txRdy = 0;
+ cout << "UART: force fetched 0x" << std::hex << m_txVal << std::dec << endl;
+ }
+ if(m_readCount >= 5) {
+ m_fetchCount = 0;
+ m_readCount = 0;
+ m_recRdy = 1;
+ cout << "UART: force inserted 0x48 ('H')" << endl;
+ m_recVal = 'H';
+ }
+ return (m_recRdy<<1)|(m_txRdy);
+ }
+ else if(address == 0x2008) {
+ //trans - w only
+ //data pointer
+ }
+ else if(address == 0x200c) {
+ //recv - r only
+ m_recRdy = 0;
+ m_fetchCount = 0;
+ m_readCount = 0;
+ return m_recVal;
+ }
+ return 0;
+}
+
+void Cuart::loadData(const int address, CDat value)
+{
+
+ if(address == 0x2000) {
+ //status - r only
+ }
+ else if(address == 0x2008) {
+ //trans - w only
+ cout << "UART: byte ready to fetch" << endl;
+ m_txVal = value;
+ m_txRdy = 1;
+ m_fetchCount = 0;
+ m_readCount = 0;
+ }
+ else if(address == 0x200c) {
+ //recv - r only
+ }
+}
#include "iext.hpp"
#include "extensions/cprog.hpp"
+#include "extensions/cuart.hpp"
#include "SReadline/SReadline.h"
using namespace swift;
global_cpu->setPerf(0);
}
+void applyToExtensions(const vector<string>& in)
+{
+ global_cpu->applyToExtensions(in);
+}
+
+
void printStatus(const vector<string>&)
{
CDat stackp = global_cpu->getStack();
Iext::setDisasm(&disasm);
global_cpu->registerExtension(new Cprog());
+ global_cpu->registerExtension(new Cuart());
vector<string> commentDefer;
vector<string> labelDefer;
Completers.push_back(CompleterElement("status",&printStatus, "Prints status of CPU."));
Completers.push_back(CompleterElement("getperf",&getPerf, "Prints performance counter."));
Completers.push_back(CompleterElement("resetperf",&resetPerf, "Resets performance counter to 0."));
-
+ Completers.push_back(CompleterElement("extension",&applyToExtensions, "Write to extensions."));
Reader.RegisterCompletions(Completers);
string UserInput;