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

Subversion Repositories xulalx25soc

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

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
                        m_syncd, m_host_supports_high_capacity;
65
 
66
        RESET_STATES    m_reset_state;
67
 
68
        int             m_cmdidx, m_bitpos, m_rspidx, m_rspdly, m_blkdly,
69
                                m_blklen, m_blkidx, m_last_miso, m_powerup_busy;
70
        char            m_cmdbuf[8], m_dat_out, m_dat_in;
71
        char            m_rspbuf[SDSPI_RSPLEN];
72
        char            m_block_buf[SDSPI_MAXBLKLEN];
73
        char            m_csd[SDSPI_CSDLEN], m_cid[SDSPI_CIDLEN];
74
 
75
public:
76
        SDSPISIM(void);
77
        void    load(const char *fname);
78
        void    debug(const bool dbg) { m_debug = dbg; }
79
        bool    debug(void) const { return m_debug; }
80
        int     operator()(const int csn, const int sck, const int dat);
81
        unsigned cmdcrc(int ln, char *buf) const;
82
        bool    check_cmdcrc(char *buf) const;
83
        void    add_block_crc(int ln, char *buf) const;
84
};
85
 
86
#endif

powered by: WebSVN 2.1.0

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