source: trunk/soclib/soclib/communication/vci/caba/source/include/vci_param.h @ 2200

Revision 2152, 5.2 KB checked in by becoulet, 4 months ago (diff)

obfuscated bytes-enable mask computation

Line 
1/* -*- c++ -*-
2 *
3 * SOCLIB_LGPL_HEADER_BEGIN
4 *
5 * This file is part of SoCLib, GNU LGPLv2.1.
6 *
7 * SoCLib is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published
9 * by the Free Software Foundation; version 2.1 of the License.
10 *
11 * SoCLib is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with SoCLib; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 * SOCLIB_LGPL_HEADER_END
22 *
23 * Copyright (c) UPMC, Lip6, Asim
24 *         Nicolas Pouillon <nipo@ssji.net>, 2007
25 *
26 * Maintainers: nipo joel.porquet@lip6.fr
27 */
28#ifndef SOCLIB_CABA_SIGNAL_VCI_PARAM_H_
29#define SOCLIB_CABA_SIGNAL_VCI_PARAM_H_
30
31#include <systemc>
32#include <sstream>
33#include <inttypes.h>
34#include "static_assert.h"
35#include "static_fast_int.h"
36
37namespace soclib { namespace caba {
38
39using namespace sc_core;
40
41static std::string VciParamsString(
42    int b, int k, int n, int e, int q,
43    int f, int s, int p, int t, int w )
44{
45    std::ostringstream o;
46    o << "vci_param<"
47      << b << ',' << k << ',' << n << ',' << e << ','
48      << q << ',' << f << ',' << s << ',' << p << ','
49      << t << ',' << w << '>';
50    return o.str();
51}
52
53/**
54 * VCI parameters grouped in a single class
55 */
56template<
57    int cell_size,
58    int plen_size,
59    int addr_size,
60    int rerror_size,
61    int clen_size,
62    int rflag_size,
63    int srcid_size,
64    int pktid_size,
65    int trdid_size,
66        int wrplen_size
67    >
68class VciParams
69{
70        /* Obey standart */
71
72        // This is a check for a pow of 2
73    soclib_static_assert(!((cell_size)&(cell_size-1)));
74        soclib_static_assert(plen_size <= 9);
75    // We need more than 32 bits for addr, so we dont check
76    //soclib_static_assert(addr_size <= 32);
77        soclib_static_assert(rerror_size <= 3);
78        soclib_static_assert(clen_size <= 8);
79    // We need more than 5 bits for srcid, so we dont check
80    //soclib_static_assert(srcid_size <= 5);
81        soclib_static_assert(pktid_size <= 8);
82        soclib_static_assert(wrplen_size <= 5);
83
84public:
85    /* Standart's constants, may be used by some modules */
86    static const int B = cell_size;
87    static const int K = plen_size;
88    static const int N = addr_size;
89    static const int E = rerror_size;
90    static const int Q = clen_size;
91    static const int F = rflag_size;
92    static const int S = srcid_size;
93    static const int P = pktid_size;
94    static const int T = trdid_size;
95    static const int W = wrplen_size;
96
97    /* The basic signal types */
98        /* Handshake */
99        typedef bool ack_t;
100        typedef bool val_t;
101        /* Request content */
102        typedef sc_dt::sc_uint<N> addr_t;
103        typedef sc_dt::sc_uint<B> be_t;
104        typedef bool cfixed_t;
105        typedef sc_dt::sc_uint<Q> clen_t;
106        typedef sc_dt::sc_uint<2> cmd_t;
107        typedef bool contig_t;
108        typedef sc_dt::sc_uint<B*8> data_t;
109        typedef bool eop_t;
110        typedef bool const_t;
111        typedef sc_dt::sc_uint<K> plen_t;
112        typedef bool wrap_t;
113        /* Response content */
114        typedef sc_dt::sc_uint<E> rerror_t;
115
116        /* The advanced signal types */
117        /* Request content */
118        typedef bool defd_t;
119        typedef sc_dt::sc_uint<W> wrplen_t;
120        /* Response content */
121        typedef sc_dt::sc_uint<F> rflag_t;
122        /* Threading */
123        typedef sc_dt::sc_uint<S> srcid_t;
124        typedef sc_dt::sc_uint<T> trdid_t;
125        typedef sc_dt::sc_uint<P> pktid_t;
126
127    typedef typename ::soclib::common::fast_int_t<addr_size>::int_t fast_addr_t;
128    typedef typename ::soclib::common::fast_int_t<cell_size*8>::int_t fast_data_t;
129    typedef typename ::soclib::common::fast_int_t<trdid_size>::int_t fast_trdid_t;
130
131    enum {
132        CMD_NOP,
133        CMD_READ,
134        CMD_WRITE,
135        CMD_LOCKED_READ,
136        CMD_STORE_COND = CMD_NOP,
137    };
138
139    static const unsigned int _err_mask = (1<<rerror_size)-1;
140    typedef enum {
141        ERR_NORMAL = 0 & _err_mask,
142        ERR_GENERAL_DATA_ERROR = 1 & _err_mask,
143        ERR_BAD_DATA = 5 & _err_mask,
144        ERR_ABORT_DISCONNECT = 7 & _err_mask,
145    } vci_error_e;
146
147    enum {
148        STORE_COND_ATOMIC = 0,
149        STORE_COND_NOT_ATOMIC = 1,
150    };
151
152    static std::string string( const std::string &name = "" )
153    {
154        std::string vp = VciParamsString(B,K,N,E,Q,F,S,P,T,W);
155        if ( name == "" )
156            return vp;
157        return name+'<'+vp+'>';
158    }
159
160    static inline fast_data_t be2mask( fast_data_t be )
161    {
162        fast_data_t ret = (be * 0x0100040010004000ULL | be * 0x0002000800200080ULL) & 0x8080808080808080ULL;
163        ret |= ret >> 1; ret |= ret >> 2; ret |= ret >> 4;
164#if 0
165        fast_data_t ret = 0;
166        const fast_data_t be_up = 1 << (B - 1);
167
168        for (size_t i = 0; i < (size_t)B; ++i) {
169            ret <<= 8;
170            if ( be_up & be )
171                ret |= 0xff;
172            be <<= 1;
173        }
174#endif
175        return ret;
176    }
177};
178
179}}
180
181#endif /* SOCLIB_CABA_SIGNAL_VCI_PARAM_H_ */
182
183// Local Variables:
184// tab-width: 4
185// c-basic-offset: 4
186// c-file-offsets:((innamespace . 0)(inline-open . 0))
187// indent-tabs-mode: nil
188// End:
189
190// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
191
Note: See TracBrowser for help on using the repository browser.