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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [sim/] [verilated/] [sdspisim.h] - Blame information for rev 58

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 58 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
#include <stdio.h>
46
 
47
typedef enum    eRESET_STATES {
48
        SDSPI_POWERUP_RESET,
49
        SDSPI_CMD0_IDLE,
50
        SDSPI_RCVD_CMD8,
51
        SDSPI_RCVD_ACMD41,
52
        SDSPI_RESET_COMPLETE,
53
        SDSPI_IN_OPERATION
54
} RESET_STATES;
55
 
56
#define SDSPI_RSPLEN    8
57
#define SDSPI_MAXBLKLEN (1+2048+2)
58
#define SDSPI_CSDLEN    (16)
59
#define SDSPI_CIDLEN    (16)
60
class   SDSPISIM {
61
        FILE            *m_dev;
62
        unsigned long   m_devblocks;
63
 
64
        int             m_last_sck, m_delay, m_mosi;
65
        bool            m_busy, m_debug, m_block_address, m_altcmd_flag,
66
                        m_syncd, m_host_supports_high_capacity, m_reading_data,
67
                        m_have_token;
68
 
69
        RESET_STATES    m_reset_state;
70
 
71
        int             m_cmdidx, m_bitpos, m_rspidx, m_rspdly, m_blkdly,
72
                                m_blklen, m_blkidx, m_last_miso, m_powerup_busy,
73
                                m_rxloc;
74
        char            m_cmdbuf[8], m_dat_out, m_dat_in;
75
        char            m_rspbuf[SDSPI_RSPLEN];
76
        char            m_block_buf[SDSPI_MAXBLKLEN];
77
        char            m_csd[SDSPI_CSDLEN], m_cid[SDSPI_CIDLEN];
78
 
79
public:
80
        SDSPISIM(const bool debug = false);
81
        void    load(const char *fname);
82
        void    debug(const bool dbg) { m_debug = dbg; }
83
        bool    debug(void) const { return m_debug; }
84
        int     operator()(const int csn, const int sck, const int dat);
85
        unsigned cmdcrc(int ln, char *buf) const;
86
        bool    check_cmdcrc(char *buf) const;
87
        unsigned blockcrc(int ln, char *buf) const;
88
        void    add_block_crc(int ln, char *buf) const;
89
};
90
 
91
#endif

powered by: WebSVN 2.1.0

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