see http://mbed.org/users/no2chem/notebook/mbed-clock-control--benchmarks/

Dependencies:   mbed

Committer:
no2chem
Date:
Sun Jan 24 15:46:26 2010 +0000
Revision:
0:b5d3bd64d2dc

        

Who changed what in which revision?

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