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

Subversion Repositories qspiflash

[/] [qspiflash/] [trunk/] [bench/] [cpp/] [eqspiflashsim.h] - Blame information for rev 13

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

Line No. Rev Author Line
1 12 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    eqspiflashsim.h
4
//
5
// Project:     OpenArty, an entirely open SoC based upon the Arty platform
6
//
7
// Purpose:     This library simulates the operation of an Extended Quad-SPI
8
//              commanded flash, such as the N25Q128A used on the Arty
9
//              development board by Digilent.  As such, it is defined by
10
//              16 MBytes of memory (4 MWords).
11
//
12
// Creator:     Dan Gisselquist, Ph.D.
13
//              Gisselquist Technology, LLC
14
//
15
////////////////////////////////////////////////////////////////////////////////
16
//
17
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
18
//
19
// This program is free software (firmware): you can redistribute it and/or
20
// modify it under the terms of  the GNU General Public License as published
21
// by the Free Software Foundation, either version 3 of the License, or (at
22
// your option) any later version.
23
//
24
// This program is distributed in the hope that it will be useful, but WITHOUT
25
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
26
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
27
// for more details.
28
//
29
// You should have received a copy of the GNU General Public License along
30
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
31
// target there if the PDF file isn't present.)  If not, see
32
// <http://www.gnu.org/licenses/> for a copy.
33
//
34
// License:     GPL, v3, as defined and found on www.gnu.org,
35
//              http://www.gnu.org/licenses/gpl.html
36
//
37
//
38
////////////////////////////////////////////////////////////////////////////////
39
//
40
//
41
#ifndef EQSPIFLASHSIM_H
42
#define EQSPIFLASHSIM_H
43
 
44
#define EQSPIF_WIP_FLAG                 0x0001
45
#define EQSPIF_WEL_FLAG                 0x0002
46
#define EQSPIF_DEEP_POWER_DOWN_FLAG     0x0200
47
class   EQSPIFLASHSIM {
48
        typedef enum {
49
                EQSPIF_IDLE,
50
                EQSPIF_XIP,
51
                EQSPIF_RDSR,
52
                EQSPIF_RDCR,
53
                EQSPIF_RDNVCONFIG,
54
                EQSPIF_RDEVCONFIG,
55
                EQSPIF_WRSR,
56
                EQSPIF_WRCR,
57
                EQSPIF_WRNVCONFIG,
58
                EQSPIF_WREVCONFIG,
59
                EQSPIF_RDFLAGS,
60
                EQSPIF_CLRFLAGS,
61
                EQSPIF_RDLOCK,
62
                EQSPIF_WRLOCK,
63
                EQSPIF_RDID,
64
                EQSPIF_RELEASE,
65
                EQSPIF_FAST_READ,
66
                EQSPIF_QUAD_READ_CMD,
67
                EQSPIF_QUAD_READ,
68
                EQSPIF_PP,
69
                EQSPIF_QPP,
70
        // Erase states
71
                EQSPIF_SUBSECTOR_ERASE,
72
                EQSPIF_SECTOR_ERASE,
73
                EQSPIF_BULK_ERASE,
74
        // OTP memory
75
                EQSPIF_PROGRAM_OTP,
76
                EQSPIF_READ_OTP,
77
        //
78
                EQSPIF_INVALID
79
        } EQSPIF_STATE;
80
 
81
        EQSPIF_STATE    m_state;
82
        char            *m_mem, *m_pmem, *m_otp, *m_lockregs;
83
        int             m_last_sck;
84
        unsigned        m_write_count, m_ireg, m_oreg, m_sreg, m_addr,
85
                        m_count, m_config, m_mode_byte, m_creg,
86
                        m_nvconfig, m_evconfig, m_flagreg, m_nxtout[4];
87
        bool            m_quad_mode, m_debug, m_otp_wp;
88
 
89
public:
90
        EQSPIFLASHSIM(void);
91
        void    load(const char *fname) { load(0, fname); }
92
        void    load(const unsigned addr, const char *fname);
93
        void    debug(const bool dbg) { m_debug = dbg; }
94
        bool    debug(void) const { return m_debug; }
95
        bool    write_enabled(void) const { return m_debug; }
96
        unsigned counts_till_idle(void) const {
97
                return m_write_count; }
98
        unsigned operator[](const int index) {
99
                unsigned char   *cptr = (unsigned char *)&m_mem[index<<2];
100
                unsigned        v;
101
                v = (*cptr++);
102
                v = (v<<8)|(*cptr++);
103
                v = (v<<8)|(*cptr++);
104
                v = (v<<8)|(*cptr);
105
 
106
                return v; }
107
        void set(const unsigned addr, const unsigned val) {
108
                unsigned char   *cptr = (unsigned char *)&m_mem[addr<<2];
109
                *cptr++ = (val>>24);
110
                *cptr++ = (val>>16);
111
                *cptr++ = (val>> 8);
112
                *cptr   = (val);
113
                return;}
114
        int     operator()(const int csn, const int sck, const int dat);
115
};
116
 
117
#endif

powered by: WebSVN 2.1.0

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