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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [coremark/] [core_util.c] - Blame information for rev 863

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

Line No. Rev Author Line
1 355 julius
/*
2
Author : Shay Gal-On, EEMBC
3
 
4
This file is part of  EEMBC(R) and CoreMark(TM), which are Copyright (C) 2009
5
All rights reserved.
6
 
7
EEMBC CoreMark Software is a product of EEMBC and is provided under the terms of the
8
CoreMark License that is distributed with the official EEMBC COREMARK Software release.
9
If you received this EEMBC CoreMark Software without the accompanying CoreMark License,
10
you must discontinue use and download the official release from www.coremark.org.
11
 
12
Also, if you are publicly displaying scores generated from the EEMBC CoreMark software,
13
make sure that you are in compliance with Run and Reporting rules specified in the accompanying readme.txt file.
14
 
15
EEMBC
16
4354 Town Center Blvd. Suite 114-200
17
El Dorado Hills, CA, 95762
18 406 julius
*/
19 355 julius
#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 methods are provided:
24
        1 - Using a volatile variable. This method is only valid if the compiler is forced to generate code that
25
        reads the value of a volatile variable from memory at run time.
26
        Please note, if using this method, you would need to modify core_portme.c to generate training profile.
27
        2 - Command line arguments. This is the preferred method if command line arguments are supported.
28
        3 - System function. If none of the first 2 methods is available on the platform,
29
        a system function which is not a stub can be used.
30
 
31
        e.g. read the value on GPIO pins connected to switches, or invoke special simulator functions.
32
*/
33
#if (SEED_METHOD==SEED_VOLATILE)
34 406 julius
extern volatile ee_s32 seed1_volatile;
35
extern volatile ee_s32 seed2_volatile;
36
extern volatile ee_s32 seed3_volatile;
37
extern volatile ee_s32 seed4_volatile;
38
extern volatile ee_s32 seed5_volatile;
39
ee_s32 get_seed_32(int i)
40
{
41
        ee_s32 retval;
42
        switch (i) {
43
        case 1:
44
                retval = seed1_volatile;
45
                break;
46
        case 2:
47
                retval = seed2_volatile;
48
                break;
49
        case 3:
50
                retval = seed3_volatile;
51
                break;
52
        case 4:
53
                retval = seed4_volatile;
54
                break;
55
        case 5:
56
                retval = seed5_volatile;
57
                break;
58
        default:
59
                retval = 0;
60
                break;
61 355 julius
        }
62 406 julius
        return retval;
63
}
64 355 julius
#elif (SEED_METHOD==SEED_ARG)
65 406 julius
ee_s32 parseval(char *valstring)
66
{
67
        ee_s32 retval = 0;
68
        ee_s32 neg = 1;
69
        int hexmode = 0;
70 355 julius
        if (*valstring == '-') {
71 406 julius
                neg = -1;
72 355 julius
                valstring++;
73
        }
74
        if ((valstring[0] == '0') && (valstring[1] == 'x')) {
75 406 julius
                hexmode = 1;
76
                valstring += 2;
77 355 julius
        }
78 406 julius
        /* first look for digits */
79 355 julius
        if (hexmode) {
80 406 julius
                while (((*valstring >= '0') && (*valstring <= '9'))
81
                       || ((*valstring >= 'a') && (*valstring <= 'f'))) {
82
                        ee_s32 digit = *valstring - '0';
83
                        if (digit > 9)
84
                                digit = 10 + *valstring - 'a';
85
                        retval *= 16;
86
                        retval += digit;
87 355 julius
                        valstring++;
88
                }
89
        } else {
90
                while ((*valstring >= '0') && (*valstring <= '9')) {
91 406 julius
                        ee_s32 digit = *valstring - '0';
92
                        retval *= 10;
93
                        retval += digit;
94 355 julius
                        valstring++;
95
                }
96
        }
97
        /* now add qualifiers */
98 406 julius
        if (*valstring == 'K')
99
                retval *= 1024;
100
        if (*valstring == 'M')
101
                retval *= 1024 * 1024;
102 355 julius
 
103 406 julius
        retval *= neg;
104 355 julius
        return retval;
105
}
106
 
107 406 julius
ee_s32 get_seed_args(int i, int argc, char *argv[])
108
{
109
        if (argc > i)
110 355 julius
                return parseval(argv[i]);
111
        return 0;
112
}
113
 
114
#elif (SEED_METHOD==SEED_FUNC)
115
/* If using OS based function, you must define and implement the functions below in core_portme.h and core_portme.c ! */
116 406 julius
ee_s32 get_seed_32(int i)
117
{
118 355 julius
        ee_s32 retval;
119
        switch (i) {
120 406 julius
        case 1:
121
                retval = portme_sys1();
122
                break;
123
        case 2:
124
                retval = portme_sys2();
125
                break;
126
        case 3:
127
                retval = portme_sys3();
128
                break;
129
        case 4:
130
                retval = portme_sys4();
131
                break;
132
        case 5:
133
                retval = portme_sys5();
134
                break;
135
        default:
136
                retval = 0;
137
                break;
138 355 julius
        }
139
        return retval;
140
}
141
#endif
142
 
143
/* Function: crc*
144
        Service functions to calculate 16b CRC code.
145
 
146
*/
147 406 julius
ee_u16 crcu8(ee_u8 data, ee_u16 crc)
148 355 julius
{
149 406 julius
        ee_u8 i = 0, x16 = 0, carry = 0;
150 355 julius
 
151 406 julius
        for (i = 0; i < 8; i++) {
152
                x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1));
153 355 julius
                data >>= 1;
154
 
155 406 julius
                if (x16 == 1) {
156
                        crc ^= 0x4002;
157
                        carry = 1;
158
                } else
159 355 julius
                        carry = 0;
160
                crc >>= 1;
161
                if (carry)
162 406 julius
                        crc |= 0x8000;
163 355 julius
                else
164 406 julius
                        crc &= 0x7fff;
165
        }
166 355 julius
        return crc;
167 406 julius
}
168
 
169
ee_u16 crcu16(ee_u16 newval, ee_u16 crc)
170
{
171
        crc = crcu8((ee_u8) (newval), crc);
172
        crc = crcu8((ee_u8) ((newval) >> 8), crc);
173 355 julius
        return crc;
174
}
175 406 julius
 
176
ee_u16 crcu32(ee_u32 newval, ee_u16 crc)
177
{
178
        crc = crc16((ee_s16) newval, crc);
179
        crc = crc16((ee_s16) (newval >> 16), crc);
180 355 julius
        return crc;
181
}
182 406 julius
 
183
ee_u16 crc16(ee_s16 newval, ee_u16 crc)
184
{
185
        return crcu16((ee_u16) newval, crc);
186 355 julius
}
187
 
188 406 julius
ee_u8 check_data_types()
189
{
190
        ee_u8 retval = 0;
191 355 julius
        if (sizeof(ee_u8) != 1) {
192
                ee_printf("ERROR: ee_u8 is not an 8b datatype!\n");
193
                retval++;
194
        }
195
        if (sizeof(ee_u16) != 2) {
196
                ee_printf("ERROR: ee_u16 is not a 16b datatype!\n");
197
                retval++;
198
        }
199
        if (sizeof(ee_s16) != 2) {
200
                ee_printf("ERROR: ee_s16 is not a 16b datatype!\n");
201
                retval++;
202
        }
203
        if (sizeof(ee_s32) != 4) {
204
                ee_printf("ERROR: ee_s32 is not a 32b datatype!\n");
205
                retval++;
206
        }
207
        if (sizeof(ee_u32) != 4) {
208
                ee_printf("ERROR: ee_u32 is not a 32b datatype!\n");
209
                retval++;
210
        }
211
        if (sizeof(ee_ptr_int) != sizeof(int *)) {
212 406 julius
                ee_printf
213
                    ("ERROR: ee_ptr_int is not a datatype that holds an int pointer!\n");
214 355 julius
                retval++;
215
        }
216 406 julius
        if (retval > 0) {
217
                ee_printf
218
                    ("ERROR: Please modify the datatypes in core_portme.h!\n");
219 355 julius
        }
220
        return retval;
221
}

powered by: WebSVN 2.1.0

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