1 /* `Deep Thought', a softcore CPU implemented on a FPGA
3 Copyright (C) 2010 Markus Hofstaetter <markus.manrow@gmx.at>
4 Copyright (C) 2010 Martin Perner <e0725782@student.tuwien.ac.at>
5 Copyright (C) 2010 Stefan Rebernig <stefan.rebernig@gmail.com>
6 Copyright (C) 2010 Manfred Schwarz <e0725898@student.tuwien.ac.at>
7 Copyright (C) 2010 Bernhard Urban <lewurm@gmail.com>
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "../iext.hpp"
24 class Cuart : public Iext {
26 Cuart() : m_writeAddress(0), m_fetchCount(0), m_readCount(0), m_recRdy(0), m_txRdy(0), m_recVal(0), m_txVal(0) {};
28 void loadData(const int address, CDat value);
29 CDat readData(const int);
30 void parseInput(const vector<string>& in);
32 int m_writeAddress, m_fetchCount, m_readCount;
33 bool m_recRdy, m_txRdy;
34 CDat m_recVal, m_txVal;
38 void Cuart::parseInput(const vector<string>& in)
41 if((in[1].compare("h") == 0)) {
42 cout << "UART:" << endl;
43 cout << "\textension uart r 0xXX \t -- to load the module with a value" << endl;
44 cout << "\textension uart f \t-- to load a value from the module" << endl;
50 if(in[1].compare("uart") == 0) {
51 if(in[2].compare("r") == 0) {
55 if(in[3].substr(0,2) == "0x") {
56 m_recVal = lexical_cast<uint32_from_hex>(in[3]);
59 m_recVal = lexical_cast<unsigned int>(in[3]);
61 cout << "UART: loaded 0x" << std::hex << m_recVal << std::dec << endl;
66 else if(in[2].compare("f") == 0) {
67 cout << "UART: sended 0x" << std::hex << m_txVal << std::dec << endl;
72 else if(in[2].compare("s") == 0) {
73 cout << "UART:" << endl;
74 cout << "\ttx busy: " << m_txRdy << endl;
75 cout << "\trx_newdata: " << m_recRdy << endl;
80 CDat Cuart::readData(const int address)
82 if(address == 0x2000) {
84 /* cout << "rx: " << m_recRdy << endl;
85 cout << "tx: " << m_txRdy << endl;
86 CDat helpme = m_recRdy;
89 cout << "rx<<1 | tx: " << helpme << endl;
98 if(m_fetchCount >= 5) {
102 cout << "UART: force fetched 0x" << std::hex << m_txVal << std::dec << endl;
104 if(m_readCount >= 5) {
108 cout << "UART: force inserted 0x48 ('H')" << endl;
111 return (m_recRdy<<1)|(m_txRdy);
113 else if(address == 0x2008) {
117 else if(address == 0x200c) {
127 void Cuart::loadData(const int address, CDat value)
130 if(address == 0x2000) {
133 else if(address == 0x2008) {
135 cout << "UART: byte ready to fetch" << endl;
141 else if(address == 0x200c) {