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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [bench/] [cpp/] [sdspisim.h] - Blame information for rev 116

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 75 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    sdspisim.h
4
//
5
// Project:     Wishbone Controlled SD-Card Controller over SPI port
6
//
7
// Purpose:     This library simulates the operation of a SPI commanded SD-Card,
8
//              such as might be found on a XuLA2-LX25 board made by xess.com.
9
//
10
//      This simulator is for testing use in a Verilator/C++ environment, where
11
//      it would be used in place of the actual hardware.
12
//
13
// Creator:     Dan Gisselquist, Ph.D.
14
//              Gisselquist Technology, LLC
15
//
16
////////////////////////////////////////////////////////////////////////////////
17
//
18
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
19
//
20
// This program is free software (firmware): you can redistribute it and/or
21
// modify it under the terms of  the GNU General Public License as published
22
// by the Free Software Foundation, either version 3 of the License, or (at
23
// your option) any later version.
24
//
25
// This program is distributed in the hope that it will be useful, but WITHOUT
26
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
27
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
28
// for more details.
29
//
30
// You should have received a copy of the GNU General Public License along
31
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
32
// target there if the PDF file isn't present.)  If not, see
33
// <http://www.gnu.org/licenses/> for a copy.
34
//
35
// License:     GPL, v3, as defined and found on www.gnu.org,
36
//              http://www.gnu.org/licenses/gpl.html
37
//
38
//
39
////////////////////////////////////////////////////////////////////////////////
40
//
41
//
42
#ifndef SDSPISIM_H
43
#define SDSPISIM_H
44
 
45
typedef enum    eRESET_STATES {
46
        SDSPI_POWERUP_RESET,
47
        SDSPI_CMD0_IDLE,
48
        SDSPI_RCVD_CMD8,
49
        SDSPI_RCVD_ACMD41,
50
        SDSPI_RESET_COMPLETE,
51
        SDSPI_IN_OPERATION
52
} RESET_STATES;
53
 
54
#define SDSPI_RSPLEN    8
55
#define SDSPI_MAXBLKLEN (1+2048+2)
56
#define SDSPI_CSDLEN    (16)
57
#define SDSPI_CIDLEN    (16)
58
class   SDSPISIM {
59
        FILE            *m_dev;
60
        unsigned long   m_devblocks;
61
 
62
        int             m_last_sck, m_delay, m_mosi;
63
        bool            m_busy, m_debug, m_block_address, m_altcmd_flag,
64 95 dgisselq
                        m_syncd, m_host_supports_high_capacity, m_reading_data,
65
                        m_have_token;
66 75 dgisselq
 
67
        RESET_STATES    m_reset_state;
68
 
69
        int             m_cmdidx, m_bitpos, m_rspidx, m_rspdly, m_blkdly,
70 95 dgisselq
                                m_blklen, m_blkidx, m_last_miso, m_powerup_busy,
71
                                m_rxloc;
72 75 dgisselq
        char            m_cmdbuf[8], m_dat_out, m_dat_in;
73
        char            m_rspbuf[SDSPI_RSPLEN];
74
        char            m_block_buf[SDSPI_MAXBLKLEN];
75
        char            m_csd[SDSPI_CSDLEN], m_cid[SDSPI_CIDLEN];
76
 
77
public:
78
        SDSPISIM(void);
79
        void    load(const char *fname);
80
        void    debug(const bool dbg) { m_debug = dbg; }
81
        bool    debug(void) const { return m_debug; }
82
        int     operator()(const int csn, const int sck, const int dat);
83
        unsigned cmdcrc(int ln, char *buf) const;
84
        bool    check_cmdcrc(char *buf) const;
85 95 dgisselq
        unsigned blockcrc(int ln, char *buf) const;
86 75 dgisselq
        void    add_block_crc(int ln, char *buf) const;
87
};
88
 
89
#endif

powered by: WebSVN 2.1.0

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