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

Subversion Repositories neo430

[/] [neo430/] [trunk/] [neo430/] [sw/] [example/] [coremark/] [core_util.c] - Blame information for rev 198

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 198 zero_gravi
/*
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 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
        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
                ee_s32 retval;
41
                switch (i) {
42
                        case 1:
43
                                retval=seed1_volatile;
44
                                break;
45
                        case 2:
46
                                retval=seed2_volatile;
47
                                break;
48
                        case 3:
49
                                retval=seed3_volatile;
50
                                break;
51
                        case 4:
52
                                retval=seed4_volatile;
53
                                break;
54
                        case 5:
55
                                retval=seed5_volatile;
56
                                break;
57
                        default:
58
                                retval=0;
59
                                break;
60
                }
61
                return retval;
62
        }
63
#elif (SEED_METHOD==SEED_ARG)
64
ee_s32 parseval(char *valstring) {
65
        ee_s32 retval=0;
66
        ee_s32 neg=1;
67
        int hexmode=0;
68
        if (*valstring == '-') {
69
                neg=-1;
70
                valstring++;
71
        }
72
        if ((valstring[0] == '0') && (valstring[1] == 'x')) {
73
                hexmode=1;
74
                valstring+=2;
75
        }
76
                /* first look for digits */
77
        if (hexmode) {
78
                while (((*valstring >= '0') && (*valstring <= '9')) || ((*valstring >= 'a') && (*valstring <= 'f'))) {
79
                        ee_s32 digit=*valstring-'0';
80
                        if (digit>9)
81
                                digit=10+*valstring-'a';
82
                        retval*=16;
83
                        retval+=digit;
84
                        valstring++;
85
                }
86
        } else {
87
                while ((*valstring >= '0') && (*valstring <= '9')) {
88
                        ee_s32 digit=*valstring-'0';
89
                        retval*=10;
90
                        retval+=digit;
91
                        valstring++;
92
                }
93
        }
94
        /* now add qualifiers */
95
        if (*valstring=='K')
96
                retval*=1024;
97
        if (*valstring=='M')
98
                retval*=1024*1024;
99
 
100
        retval*=neg;
101
        return retval;
102
}
103
 
104
ee_s32 get_seed_args(int i, int argc, char *argv[]) {
105
        if (argc>i)
106
                return parseval(argv[i]);
107
        return 0;
108
}
109
 
110
#elif (SEED_METHOD==SEED_FUNC)
111
/* If using OS based function, you must define and implement the functions below in core_portme.h and core_portme.c ! */
112
ee_s32 get_seed_32(int i) {
113
        ee_s32 retval;
114
        switch (i) {
115
                case 1:
116
                        retval=portme_sys1();
117
                        break;
118
                case 2:
119
                        retval=portme_sys2();
120
                        break;
121
                case 3:
122
                        retval=portme_sys3();
123
                        break;
124
                case 4:
125
                        retval=portme_sys4();
126
                        break;
127
                case 5:
128
                        retval=portme_sys5();
129
                        break;
130
                default:
131
                        retval=0;
132
                        break;
133
        }
134
        return retval;
135
}
136
#endif
137
 
138
/* Function: crc*
139
        Service functions to calculate 16b CRC code.
140
 
141
*/
142
ee_u16 crcu8(ee_u8 data, ee_u16 crc )
143
{
144
        ee_u8 i=0,x16=0,carry=0;
145
 
146
        for (i = 0; i < 8; i++)
147
    {
148
                x16 = (ee_u8)((data & 1) ^ ((ee_u8)crc & 1));
149
                data >>= 1;
150
 
151
                if (x16 == 1)
152
                {
153
                   crc ^= 0x4002;
154
                   carry = 1;
155
                }
156
                else
157
                        carry = 0;
158
                crc >>= 1;
159
                if (carry)
160
                   crc |= 0x8000;
161
                else
162
                   crc &= 0x7fff;
163
    }
164
        return crc;
165
}
166
ee_u16 crcu16(ee_u16 newval, ee_u16 crc) {
167
        crc=crcu8( (ee_u8) (newval)                             ,crc);
168
        crc=crcu8( (ee_u8) ((newval)>>8)        ,crc);
169
        return crc;
170
}
171
ee_u16 crcu32(ee_u32 newval, ee_u16 crc) {
172
        crc=crc16((ee_s16) newval               ,crc);
173
        crc=crc16((ee_s16) (newval>>16) ,crc);
174
        return crc;
175
}
176
ee_u16 crc16(ee_s16 newval, ee_u16 crc) {
177
        return crcu16((ee_u16)newval, crc);
178
}
179
 
180
ee_u8 check_data_types() {
181
        ee_u8 retval=0;
182
        if (sizeof(ee_u8) != 1) {
183
                ee_printf("ERROR: ee_u8 is not an 8b datatype!\n");
184
                retval++;
185
        }
186
        if (sizeof(ee_u16) != 2) {
187
                ee_printf("ERROR: ee_u16 is not a 16b datatype!\n");
188
                retval++;
189
        }
190
        if (sizeof(ee_s16) != 2) {
191
                ee_printf("ERROR: ee_s16 is not a 16b datatype!\n");
192
                retval++;
193
        }
194
        if (sizeof(ee_s32) != 4) {
195
                ee_printf("ERROR: ee_s32 is not a 32b datatype!\n");
196
                retval++;
197
        }
198
        if (sizeof(ee_u32) != 4) {
199
                ee_printf("ERROR: ee_u32 is not a 32b datatype!\n");
200
                retval++;
201
        }
202
        if (sizeof(ee_ptr_int) != sizeof(int *)) {
203
                ee_printf("ERROR: ee_ptr_int is not a datatype that holds an int pointer!\n");
204
                retval++;
205
        }
206
        if (retval>0) {
207
                ee_printf("ERROR: Please modify the datatypes in core_portme.h!\n");
208
        }
209
        return retval;
210
}

powered by: WebSVN 2.1.0

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