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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [sim/] [UART.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jamieiles
// Copyright Jamie Iles, 2017
2
//
3
// This file is part of s80x86.
4
//
5
// s80x86 is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// s80x86 is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with s80x86.  If not, see <http://www.gnu.org/licenses/>.
17
 
18
#pragma once
19
 
20
#include <deque>
21
#include <iostream>
22
#include <termios.h>
23
#include <unistd.h>
24
#include <stdexcept>
25
 
26
#include <boost/serialization/list.hpp>
27
#include <boost/serialization/deque.hpp>
28
#include <boost/serialization/string.hpp>
29
#include <boost/serialization/version.hpp>
30
 
31
#include "UART.h"
32
#include "CPU.h"
33
 
34
class RawTTY
35
{
36
public:
37
    RawTTY()
38
    {
39
        if (tcgetattr(STDIN_FILENO, &old_termios))
40
            throw std::runtime_error("Failed to get termios");
41
 
42
        auto termios = old_termios;
43
        cfmakeraw(&termios);
44
        termios.c_cc[VMIN] = 0;
45
        termios.c_cc[VTIME] = 0;
46
        if (tcsetattr(STDIN_FILENO, TCSANOW, &termios))
47
            throw std::runtime_error("Failed to set new termios");
48
    }
49
 
50
    ~RawTTY()
51
    {
52
        tcsetattr(STDIN_FILENO, TCSANOW, &old_termios);
53
    }
54
 
55
private:
56
    struct termios old_termios;
57
};
58
 
59
class UART : public IOPorts
60
{
61
public:
62
    UART();
63
    void write8(uint16_t port_num, unsigned offs, uint8_t v);
64
    void write16(uint16_t port_num, uint16_t v);
65
    uint8_t read8(uint16_t port_num, unsigned offs);
66
    uint16_t read16(uint16_t port_num);
67
    void add_char(int c);
68
 
69
private:
70
    RawTTY raw_tty;
71
    std::deque<uint8_t> charbuf;
72
 
73
    friend class boost::serialization::access;
74
    template <class Archive>
75
    void serialize(Archive &ar, const unsigned int __unused version)
76
    {
77
        // clang-format off
78
        ar & charbuf;
79
        // clang-format on
80
    }
81
};

powered by: WebSVN 2.1.0

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