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

Subversion Repositories steelcore

[/] [coremark/] [core_util.c] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 rafaelcalc
/*
2
Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC)
3
 
4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7
 
8
    http://www.apache.org/licenses/LICENSE-2.0
9
 
10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
 
16
Original Author: Shay Gal-on
17
*/
18
 
19
#include "coremark.h"
20
/* Function: get_seed
21
        Get a values that cannot be determined at compile time.
22
 
23
        Since different embedded systems and compilers are used, 3 different
24
   methods are provided: 1 - Using a volatile variable. This method is only
25
   valid if the compiler is forced to generate code that reads the value of a
26
   volatile variable from memory at run time. Please note, if using this method,
27
   you would need to modify core_portme.c to generate training profile. 2 -
28
   Command line arguments. This is the preferred method if command line
29
   arguments are supported. 3 - System function. If none of the first 2 methods
30
   is available on the platform, a system function which is not a stub can be
31
   used.
32
 
33
        e.g. read the value on GPIO pins connected to switches, or invoke
34
   special simulator functions.
35
*/
36
#if (SEED_METHOD == SEED_VOLATILE)
37
extern volatile ee_s32 seed1_volatile;
38
extern volatile ee_s32 seed2_volatile;
39
extern volatile ee_s32 seed3_volatile;
40
extern volatile ee_s32 seed4_volatile;
41
extern volatile ee_s32 seed5_volatile;
42
ee_s32
43
get_seed_32(int i)
44
{
45
    ee_s32 retval;
46
    switch (i)
47
    {
48
        case 1:
49
            retval = seed1_volatile;
50
            break;
51
        case 2:
52
            retval = seed2_volatile;
53
            break;
54
        case 3:
55
            retval = seed3_volatile;
56
            break;
57
        case 4:
58
            retval = seed4_volatile;
59
            break;
60
        case 5:
61
            retval = seed5_volatile;
62
            break;
63
        default:
64
            retval = 0;
65
            break;
66
    }
67
    return retval;
68
}
69
#elif (SEED_METHOD == SEED_ARG)
70
ee_s32
71
parseval(char *valstring)
72
{
73
    ee_s32 retval  = 0;
74
    ee_s32 neg     = 1;
75
    int    hexmode = 0;
76
    if (*valstring == '-')
77
    {
78
        neg = -1;
79
        valstring++;
80
    }
81
    if ((valstring[0] == '0') && (valstring[1] == 'x'))
82
    {
83
        hexmode = 1;
84
        valstring += 2;
85
    }
86
    /* first look for digits */
87
    if (hexmode)
88
    {
89
        while (((*valstring >= '0') && (*valstring <= '9'))
90
               || ((*valstring >= 'a') && (*valstring <= 'f')))
91
        {
92
            ee_s32 digit = *valstring - '0';
93
            if (digit > 9)
94
                digit = 10 + *valstring - 'a';
95
            retval *= 16;
96
            retval += digit;
97
            valstring++;
98
        }
99
    }
100
    else
101
    {
102
        while ((*valstring >= '0') && (*valstring <= '9'))
103
        {
104
            ee_s32 digit = *valstring - '0';
105
            retval *= 10;
106
            retval += digit;
107
            valstring++;
108
        }
109
    }
110
    /* now add qualifiers */
111
    if (*valstring == 'K')
112
        retval *= 1024;
113
    if (*valstring == 'M')
114
        retval *= 1024 * 1024;
115
 
116
    retval *= neg;
117
    return retval;
118
}
119
 
120
ee_s32
121
get_seed_args(int i, int argc, char *argv[])
122
{
123
    if (argc > i)
124
        return parseval(argv[i]);
125
    return 0;
126
}
127
 
128
#elif (SEED_METHOD == SEED_FUNC)
129
/* If using OS based function, you must define and implement the functions below
130
 * in core_portme.h and core_portme.c ! */
131
ee_s32
132
get_seed_32(int i)
133
{
134
    ee_s32 retval;
135
    switch (i)
136
    {
137
        case 1:
138
            retval = portme_sys1();
139
            break;
140
        case 2:
141
            retval = portme_sys2();
142
            break;
143
        case 3:
144
            retval = portme_sys3();
145
            break;
146
        case 4:
147
            retval = portme_sys4();
148
            break;
149
        case 5:
150
            retval = portme_sys5();
151
            break;
152
        default:
153
            retval = 0;
154
            break;
155
    }
156
    return retval;
157
}
158
#endif
159
 
160
/* Function: crc*
161
        Service functions to calculate 16b CRC code.
162
 
163
*/
164
ee_u16
165
crcu8(ee_u8 data, ee_u16 crc)
166
{
167
    ee_u8 i = 0, x16 = 0, carry = 0;
168
 
169
    for (i = 0; i < 8; i++)
170
    {
171
        x16 = (ee_u8)((data & 1) ^ ((ee_u8)crc & 1));
172
        data >>= 1;
173
 
174
        if (x16 == 1)
175
        {
176
            crc ^= 0x4002;
177
            carry = 1;
178
        }
179
        else
180
            carry = 0;
181
        crc >>= 1;
182
        if (carry)
183
            crc |= 0x8000;
184
        else
185
            crc &= 0x7fff;
186
    }
187
    return crc;
188
}
189
ee_u16
190
crcu16(ee_u16 newval, ee_u16 crc)
191
{
192
    crc = crcu8((ee_u8)(newval), crc);
193
    crc = crcu8((ee_u8)((newval) >> 8), crc);
194
    return crc;
195
}
196
ee_u16
197
crcu32(ee_u32 newval, ee_u16 crc)
198
{
199
    crc = crc16((ee_s16)newval, crc);
200
    crc = crc16((ee_s16)(newval >> 16), crc);
201
    return crc;
202
}
203
ee_u16
204
crc16(ee_s16 newval, ee_u16 crc)
205
{
206
    return crcu16((ee_u16)newval, crc);
207
}
208
 
209
ee_u8
210
check_data_types()
211
{
212
    ee_u8 retval = 0;
213
    if (sizeof(ee_u8) != 1)
214
    {
215
        ee_printf("ERROR: ee_u8 is not an 8b datatype!\n");
216
        retval++;
217
    }
218
    if (sizeof(ee_u16) != 2)
219
    {
220
        ee_printf("ERROR: ee_u16 is not a 16b datatype!\n");
221
        retval++;
222
    }
223
    if (sizeof(ee_s16) != 2)
224
    {
225
        ee_printf("ERROR: ee_s16 is not a 16b datatype!\n");
226
        retval++;
227
    }
228
    if (sizeof(ee_s32) != 4)
229
    {
230
        ee_printf("ERROR: ee_s32 is not a 32b datatype!\n");
231
        retval++;
232
    }
233
    if (sizeof(ee_u32) != 4)
234
    {
235
        ee_printf("ERROR: ee_u32 is not a 32b datatype!\n");
236
        retval++;
237
    }
238
    if (sizeof(ee_ptr_int) != sizeof(int *))
239
    {
240
        ee_printf(
241
            "ERROR: ee_ptr_int is not a datatype that holds an int pointer!\n");
242
        retval++;
243
    }
244
    if (retval > 0)
245
    {
246
        ee_printf("ERROR: Please modify the datatypes in core_portme.h!\n");
247
    }
248
    return retval;
249
}

powered by: WebSVN 2.1.0

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