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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [sim/] [SPI.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
#include "CPU.h"
20
#include <cassert>
21
#include <deque>
22
#include <stdint.h>
23
#include <fstream>
24
 
25
#include <boost/serialization/list.hpp>
26
#include <boost/serialization/deque.hpp>
27
#include <boost/serialization/vector.hpp>
28
#include <boost/serialization/string.hpp>
29
#include <boost/serialization/version.hpp>
30
 
31
// A dumb SPI mode SD card emulation.  Only supports basic block operations,
32
// standard capacity, no CRC checking or generation and no real errors, this
33
// is not a real SD card model!
34
//
35
// Blocklen is ignored and will always be 512 bytes.
36
// ACMD messages are ignored too.
37
class SPI : public IOPorts
38
{
39
private:
40
    enum SPIState {
41
        STATE_IDLE,
42
        STATE_RECEIVING,
43
        STATE_TRANSMITTING,
44
        STATE_WAIT_FOR_DATA,
45
        STATE_DO_WRITE_BLOCK,
46
    };
47
 
48
public:
49
    SPI(const std::string &disk_image_path);
50
    void write8(uint16_t port_num, unsigned offs, uint8_t v);
51
    void write16(uint16_t port_num, uint16_t v);
52
    uint8_t read8(uint16_t port_num, unsigned offs);
53
    uint16_t read16(uint16_t __unused port_num);
54
 
55
private:
56
    void transfer(uint8_t mosi_val);
57
    bool transmit_ready();
58
    void read_block();
59
    void write_block();
60
    uint16_t control_reg;
61
    uint8_t rx_val;
62
    SPIState state;
63
    std::vector<uint8_t> mosi_buf;
64
    std::deque<uint8_t> miso_buf;
65
    std::fstream disk_image;
66
    bool do_write;
67
    unsigned write_count;
68
 
69
    friend class boost::serialization::access;
70
    template <class Archive>
71
    void serialize(Archive &ar, const unsigned int __unused version)
72
    {
73
        // clang-format off
74
        ar & control_reg;
75
        ar & rx_val;
76
        ar & state;
77
        ar & mosi_buf;
78
        ar & miso_buf;
79
        ar & do_write;
80
        ar & write_count;
81
        // clang-format on
82
    }
83
};

powered by: WebSVN 2.1.0

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