source: trunk/modules/sdmmc/caba/source/include/sdmmc.h @ 1052

Last change on this file since 1052 was 1052, checked in by alain, 7 years ago

few bugs

File size: 3.7 KB
Line 
1
2/* -*- c++ -*-
3 *
4 * SOCLIB_LGPL_HEADER_BEGIN
5 *
6 * This file is part of SoCLib, GNU LGPLv2.1.
7 *
8 * SoCLib is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published
10 * by the Free Software Foundation; version 2.1 of the License.
11 *
12 * SoCLib is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with SoCLib; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 * SOCLIB_LGPL_HEADER_END
23 *
24 * Copyright (c) UPMC, Lip6, SoC
25 *         manuel.bouyer@lip6.fr october 2013
26 *
27 * Maintainers: bouyer
28 */
29
30//////////////////////////////////////////////////////////////////////////////////////
31// This component is a SD/MMC block device.
32//
33// This component can perform data transfers between one single file belonging
34// to the host system and a SPI controller.
35// The file name is an argument of the constructor.
36//
37
38#ifndef SOCLIB_SDMMC_H
39#define SOCLIB_SDMMC_H
40
41#include <stdint.h>
42#include <systemc>
43#include <unistd.h>
44#include "caba_base_module.h"
45
46namespace soclib {
47namespace caba {
48
49using namespace sc_core;
50
51class SdMMC
52        : public caba::BaseModule
53{
54private:
55
56    // Registers
57    int               spi_fsm;               // SPI state register
58    int                   spi_shiftreg;      // data shift in/out
59    int                   spi_bitcount;
60    int                   spi_clk;
61    int                   spi_mosi_previous; // sampled MOSI value
62
63    uint8_t               command;
64    uint32_t          args;
65    uint8_t               cmdcrc;
66
67    int               m_fd;              // File descriptor
68    uint64_t          m_device_size;     // Total number of blocks
69    const uint32_t    m_latency;         // device latency
70
71    uint8_t               m_databuf[1    /* reponse */ + 
72                                1    /* data tocken */ + 
73                                512  /* data block */ + 
74                                2    /* CRC */ ];
75
76    uint32_t          m_datalen_snd;     // data size to be sent to host
77    uint32_t          m_datalen_rcv;     // data size expected from host
78    uint32_t          m_data_idx;
79    bool                  m_acmd;            // next command will be acmd
80    int                   m_sdstate;         // sdcard internal state
81
82    // sd states
83    enum 
84    {
85            SD_IDLE = 0,
86            SD_READY = 1,
87    };
88
89    // methods
90    void genMealy();
91
92    void handle_sdmmc_cmd(uint8_t, uint32_t);
93    void handle_sdmmc_write(uint8_t, uint32_t);
94
95    //  Master FSM states
96    enum 
97    {
98    S_IDLE               = 0,
99    S_RECEIVE_CMD        = 1,
100    S_RECEIVE_ARGS_START = 2,
101    S_RECEIVE_ARGS       = 3,
102    S_RECEIVE_CRC        = 4,
103    S_RECEIVE_DATA_WAIT  = 5,
104    S_RECEIVE_DATA       = 6,
105    S_SEND_DATA          = 7,
106    };
107
108protected:
109
110    SC_HAS_PROCESS(SdMMC);
111
112public:
113
114    // ports
115    sc_in<bool>                                               p_clk;
116    sc_in<bool>                                               p_resetn;
117    sc_in<bool>                                               p_spi_ss;
118    sc_in<bool>                                               p_spi_clk;
119    sc_in<bool>                                               p_spi_mosi;
120    sc_out<bool>                                              p_spi_miso;
121
122    void print_trace();
123
124    // Constructor   
125    SdMMC(
126        sc_module_name                      name,
127        const std::string                   &filename,
128        const uint32_t                      latency = 0);
129
130    ~SdMMC();
131
132};
133
134}}
135
136#endif /* SOCLIB_SDMMC_H */
137
138// Local Variables:
139// tab-width: 4
140// c-basic-offset: 4
141// c-file-offsets:((innamespace . 0)(inline-open . 0))
142// indent-tabs-mode: nil
143// End:
144
145// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
Note: See TracBrowser for help on using the repository browser.