source: trunk/modules/vci_block_device_tsar_v4/caba/source/include/vci_block_device_tsar_v4.h @ 151

Last change on this file since 151 was 151, checked in by alain, 13 years ago

Introducing the vci_block_device_tsar_v4 component, that
respect the TSAR conventions for the VCI rerror field (2 bits).

File size: 7.4 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, Asim
25 *         alain.greiner@lip6.fr april 2011
26 *
27 * Maintainers: alain
28 */
29
30//////////////////////////////////////////////////////////////////////////////////////
31// This component is a simplified disk controller with a VCI interface.
32// This component can perform data transfers between one single file belonging
33// to the host system and a buffer in the memory of the virtual prototype.
34// The file name is an argument of the constructor,
35// as well as the block size (bytes), and the burst size (bytes).
36// This component has a DMA capability, and is both a target and an initiator.
37// Both read and write transfers are supported. An IRQ is optionally
38// asserted when the transfer is completed.
39//
40// As a target this block device controler contains 8 memory mapped registers,
41// taking 32 bytes in the address space.
42// - BLOCK_DEVICE_BUFFER        0x00 (read/write)    Memory buffer base address.
43// - BLOCK_DEVICE_COUNT         0x04 (read/write)    Number of blocks to be transfered.
44// - BLOCK_DEVICE_LBA           0x08 (read/write)    Index of first block in the file.
45// - BLOCK_DEVICE_OP            0x0C (write-only)    Writing here starts the operation.
46// - BLOCK_DEVICE_STATUS        0x10 (read-only)     Block Device status.
47// - BLOCK_DEVICE_IRQ_ENABLE    0x14 (read/write)    IRQ enabled if non zero.
48// - BLOCK_DEVICE_SIZE          0x18 (read-only)     Number of addressable blocks.
49// - BLOCK_DEVICE_BLOCK_SIZE    0x1C (read_only)     Block size in bytes.
50//
51// The following operations codes are supported:
52// - BLOCK_DEVICE_NOOP          No operation
53// - BLOCK_DEVICE_READ          From block device to memory
54// - BLOCK_DEVICE_WRITE         From memory to block device
55//
56// The BLOCK_DEVICE_STATUS is actually defined by the initiator FSM state.
57// The following values are defined for device status:
58// -BLOCK_DEVICE_IDLE           0
59// -BLOCK_DEVICE_BUSY           1
60// -BLOCK_DEVICE_READ_SUCCESS   2
61// -BLOCK_DEVICE_WRITE_SUCCESS  3
62// -BLOCK_DEVICE_READ_ERROR     4
63// -BLOCK_DEVICE_WRITE_ERROR    5
64//
65// In the 4 states READ_ERROR, READ_SUCCESS, WRITE_ERROR, WRITE_SUCCESS,
66// the IRQ is asserted (if it is enabled).
67// A read access to the BLOCK_DEVICE_STATUS in these 4 states reset
68// the initiator FSM state to IDLE, and acknowledge the IRQ.
69// Any write access to registers BUFFER, COUNT, LBA, OP is ignored
70// if the device is not IDLE.
71///////////////////////////////////////////////////////////////////////////
72
73#ifndef SOCLIB_VCI_BLOCK_DEVICE_TSAR_V4_H
74#define SOCLIB_VCI_BLOCK_DEVICE_TSAR_V4_H
75
76#include <stdint.h>
77#include <systemc>
78#include "caba_base_module.h"
79#include "mapping_table.h"
80
81namespace soclib {
82namespace caba {
83
84using namespace sc_core;
85
86template<typename vci_param>
87class VciBlockDeviceTsarV4
88        : public caba::BaseModule
89{
90private:
91
92    // Registers
93    sc_signal<int>                      r_target_fsm;           // target fsm state register
94    sc_signal<int>                      r_initiator_fsm;        // initiator fsm state register
95    sc_signal<bool>                     r_irq_enable;           // default value is true
96    sc_signal<uint32_t>                 r_nblocks;              // number of blocks to be transfered
97    sc_signal<uint32_t>                 r_buf_address;          // memory buffer address
98    sc_signal<uint32_t>                 r_lba;                  // first block index
99    sc_signal<bool>                     r_read;                 // requested operation
100    sc_signal<uint32_t>                 r_flit_count;           // flit counter (in a burst)
101    sc_signal<uint32_t>                 r_burst_count;          // burst counter (in a block)
102    sc_signal<uint32_t>                 r_block_count;          // block counter (in a transfer)
103    sc_signal<uint32_t>                 r_latency_count;        // latency access (for each block)
104    sc_signal<bool>                     r_go;                   // transmit command from T_FSM to M_FSM
105    sc_signal<sc_uint<vci_param::S> >   r_srcid;                // save srcid
106    sc_signal<sc_uint<vci_param::T> >   r_trdid;                // save trdid
107    sc_signal<sc_uint<vci_param::P> >   r_pktid;                // save pktid
108
109    uint32_t*                           m_local_buffer;         // capacity is one block (block_size bytes)
110
111    // structural parameters
112    soclib::common::Segment             m_segment;              // segment associated to target
113    uint32_t                            m_srcid;                // initiator index
114    int                                 m_fd;                   // File descriptor
115    uint64_t                            m_device_size;          // Total number of blocks
116    const uint32_t                      m_flits_per_block;      // number of flits in a block
117    const uint32_t                      m_flits_per_burst;      // number of flits in a burst
118    const uint32_t                      m_bursts_per_block;     // number of bursts in a block
119    const uint32_t                      m_latency;              // device latency
120
121    // methods
122    void transition();
123    void genMoore();
124
125    //  Master FSM states
126    enum {
127    M_IDLE              = 0,
128    M_READ_BLOCK        = 1,
129    M_READ_CMD          = 2,
130    M_READ_RSP          = 3,
131    M_READ_TEST         = 4,
132    M_READ_SUCCESS      = 5,
133    M_READ_ERROR        = 6,
134    M_WRITE_BLOCK       = 7,
135    M_WRITE_CMD         = 8,
136    M_WRITE_RSP         = 9,
137    M_WRITE_TEST        = 10,
138    M_WRITE_SUCCESS     = 11,
139    M_WRITE_ERROR       = 12,
140    };
141
142    // Target FSM states
143    enum {
144    T_IDLE              = 0,
145    T_WRITE_BUFFER      = 1,
146    T_READ_BUFFER       = 2,
147    T_WRITE_COUNT       = 3,
148    T_READ_COUNT        = 4,
149    T_WRITE_LBA         = 5,
150    T_READ_LBA          = 6,
151    T_WRITE_OP          = 7,
152    T_READ_STATUS       = 8,
153    T_WRITE_IRQEN       = 9,
154    T_READ_IRQEN        = 10,
155    T_READ_SIZE         = 11,
156    T_READ_BLOCK        = 12,
157    T_READ_ERROR        = 13,
158    T_WRITE_ERROR       = 14,
159    };
160
161    // Error codes values
162    enum {
163    VCI_READ_OK         = 0,
164    VCI_READ_ERROR      = 1,
165    VCI_WRITE_OK        = 2,
166    VCI_WRITE_ERROR     = 3,
167    };
168
169protected:
170
171    SC_HAS_PROCESS(VciBlockDeviceTsarV4);
172
173public:
174
175    // ports
176    sc_in<bool>                                         p_clk;
177    sc_in<bool>                                         p_resetn;
178    soclib::caba::VciInitiator<vci_param>               p_vci_initiator;
179    soclib::caba::VciTarget<vci_param>                  p_vci_target;
180    sc_out<bool>                                        p_irq;
181
182    void print_trace();
183
184    // Constructor   
185    VciBlockDeviceTsarV4(
186                sc_module_name                          name,
187                const soclib::common::MappingTable      &mt,
188                const soclib::common::IntTab            &srcid,
189                const soclib::common::IntTab            &tgtid,
190                const std::string                       &filename,
191                const uint32_t                          block_size = 512,
192                const uint32_t                          burst_size = 64,
193                const uint32_t                          latency = 0);
194};
195
196}}
197
198#endif /* SOCLIB_VCI_BLOCK_DEVICE_TSAR_V4_H */
199
200// Local Variables:
201// tab-width: 4
202// c-basic-offset: 4
203// c-file-offsets:((innamespace . 0)(inline-open . 0))
204// indent-tabs-mode: nil
205// End:
206
207// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
208
Note: See TracBrowser for help on using the repository browser.