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 File : core_portme.c
no2chem 0:b5d3bd64d2dc 3 */
no2chem 0:b5d3bd64d2dc 4 /*
no2chem 0:b5d3bd64d2dc 5 Author : Shay Gal-On, EEMBC
no2chem 0:b5d3bd64d2dc 6 Legal : TODO!
no2chem 0:b5d3bd64d2dc 7 */
no2chem 0:b5d3bd64d2dc 8 #include "coremark.h"
no2chem 0:b5d3bd64d2dc 9 #include "core_portme.h"
no2chem 0:b5d3bd64d2dc 10 #include "mbed.h"
no2chem 0:b5d3bd64d2dc 11
no2chem 0:b5d3bd64d2dc 12
no2chem 0:b5d3bd64d2dc 13 #if VALIDATION_RUN
no2chem 0:b5d3bd64d2dc 14 volatile ee_s32 seed1_volatile=0x3415;
no2chem 0:b5d3bd64d2dc 15 volatile ee_s32 seed2_volatile=0x3415;
no2chem 0:b5d3bd64d2dc 16 volatile ee_s32 seed3_volatile=0x66;
no2chem 0:b5d3bd64d2dc 17 #endif
no2chem 0:b5d3bd64d2dc 18 #if PERFORMANCE_RUN
no2chem 0:b5d3bd64d2dc 19 volatile ee_s32 seed1_volatile=0x0;
no2chem 0:b5d3bd64d2dc 20 volatile ee_s32 seed2_volatile=0x0;
no2chem 0:b5d3bd64d2dc 21 volatile ee_s32 seed3_volatile=0x66;
no2chem 0:b5d3bd64d2dc 22 #endif
no2chem 0:b5d3bd64d2dc 23 #if PROFILE_RUN
no2chem 0:b5d3bd64d2dc 24 volatile ee_s32 seed1_volatile=0x8;
no2chem 0:b5d3bd64d2dc 25 volatile ee_s32 seed2_volatile=0x8;
no2chem 0:b5d3bd64d2dc 26 volatile ee_s32 seed3_volatile=0x8;
no2chem 0:b5d3bd64d2dc 27 #endif
no2chem 0:b5d3bd64d2dc 28 volatile ee_s32 seed4_volatile=ITERATIONS;
no2chem 0:b5d3bd64d2dc 29 volatile ee_s32 seed5_volatile=0;
no2chem 0:b5d3bd64d2dc 30 /* Porting : Timing functions
no2chem 0:b5d3bd64d2dc 31 How to capture time and convert to seconds must be ported to whatever is supported by the platform.
no2chem 0:b5d3bd64d2dc 32 e.g. Read value from on board RTC, read value from cpu clock cycles performance counter etc.
no2chem 0:b5d3bd64d2dc 33 Sample implementation for standard time.h and windows.h definitions included.
no2chem 0:b5d3bd64d2dc 34 */
no2chem 0:b5d3bd64d2dc 35
no2chem 0:b5d3bd64d2dc 36 CORETIMETYPE barebones_clock() {
no2chem 0:b5d3bd64d2dc 37 return clock();
no2chem 0:b5d3bd64d2dc 38 }
no2chem 0:b5d3bd64d2dc 39 /* Define : TIMER_RES_DIVIDER
no2chem 0:b5d3bd64d2dc 40 Divider to trade off timer resolution and total time that can be measured.
no2chem 0:b5d3bd64d2dc 41
no2chem 0:b5d3bd64d2dc 42 Use lower values to increase resolution, but make sure that overflow does not occur.
no2chem 0:b5d3bd64d2dc 43 If there are issues with the return value overflowing, increase this value.
no2chem 0:b5d3bd64d2dc 44 */
no2chem 0:b5d3bd64d2dc 45 #define GETMYTIME(_t) (*_t=barebones_clock())
no2chem 0:b5d3bd64d2dc 46 #define MYTIMEDIFF(fin,ini) ((fin)-(ini))
no2chem 0:b5d3bd64d2dc 47 #define TIMER_RES_DIVIDER 1
no2chem 0:b5d3bd64d2dc 48 #define SAMPLE_TIME_IMPLEMENTATION 1
no2chem 0:b5d3bd64d2dc 49 #define EE_TICKS_PER_SEC (CLOCKS_PER_SEC / TIMER_RES_DIVIDER)
no2chem 0:b5d3bd64d2dc 50
no2chem 0:b5d3bd64d2dc 51 /** Define Host specific (POSIX), or target specific global time variables. */
no2chem 0:b5d3bd64d2dc 52 static CORETIMETYPE start_time_val, stop_time_val;
no2chem 0:b5d3bd64d2dc 53
no2chem 0:b5d3bd64d2dc 54 /* Function : start_time
no2chem 0:b5d3bd64d2dc 55 This function will be called right before starting the timed portion of the benchmark.
no2chem 0:b5d3bd64d2dc 56
no2chem 0:b5d3bd64d2dc 57 Implementation may be capturing a system timer (as implemented in the example code)
no2chem 0:b5d3bd64d2dc 58 or zeroing some system parameters - e.g. setting the cpu clocks cycles to 0.
no2chem 0:b5d3bd64d2dc 59 */
no2chem 0:b5d3bd64d2dc 60 void start_time(void) {
no2chem 0:b5d3bd64d2dc 61 GETMYTIME(&start_time_val );
no2chem 0:b5d3bd64d2dc 62 }
no2chem 0:b5d3bd64d2dc 63 /* Function : stop_time
no2chem 0:b5d3bd64d2dc 64 This function will be called right after ending the timed portion of the benchmark.
no2chem 0:b5d3bd64d2dc 65
no2chem 0:b5d3bd64d2dc 66 Implementation may be capturing a system timer (as implemented in the example code)
no2chem 0:b5d3bd64d2dc 67 or other system parameters - e.g. reading the current value of cpu cycles counter.
no2chem 0:b5d3bd64d2dc 68 */
no2chem 0:b5d3bd64d2dc 69 void stop_time(void) {
no2chem 0:b5d3bd64d2dc 70 GETMYTIME(&stop_time_val );
no2chem 0:b5d3bd64d2dc 71 }
no2chem 0:b5d3bd64d2dc 72 /* Function : get_time
no2chem 0:b5d3bd64d2dc 73 Return an abstract "ticks" number that signifies time on the system.
no2chem 0:b5d3bd64d2dc 74
no2chem 0:b5d3bd64d2dc 75 Actual value returned may be cpu cycles, milliseconds or any other value,
no2chem 0:b5d3bd64d2dc 76 as long as it can be converted to seconds by <time_in_secs>.
no2chem 0:b5d3bd64d2dc 77 This methodology is taken to accomodate any hardware or simulated platform.
no2chem 0:b5d3bd64d2dc 78 The sample implementation returns millisecs by default,
no2chem 0:b5d3bd64d2dc 79 and the resolution is controlled by <TIMER_RES_DIVIDER>
no2chem 0:b5d3bd64d2dc 80 */
no2chem 0:b5d3bd64d2dc 81 CORE_TICKS get_time(void) {
no2chem 0:b5d3bd64d2dc 82 CORE_TICKS elapsed=(CORE_TICKS)(MYTIMEDIFF(stop_time_val, start_time_val));
no2chem 0:b5d3bd64d2dc 83 return elapsed;
no2chem 0:b5d3bd64d2dc 84 }
no2chem 0:b5d3bd64d2dc 85 /* Function : time_in_secs
no2chem 0:b5d3bd64d2dc 86 Convert the value returned by get_time to seconds.
no2chem 0:b5d3bd64d2dc 87
no2chem 0:b5d3bd64d2dc 88 The <secs_ret> type is used to accomodate systems with no support for floating point.
no2chem 0:b5d3bd64d2dc 89 Default implementation implemented by the EE_TICKS_PER_SEC macro above.
no2chem 0:b5d3bd64d2dc 90 */
no2chem 0:b5d3bd64d2dc 91 secs_ret time_in_secs(CORE_TICKS ticks) {
no2chem 0:b5d3bd64d2dc 92 secs_ret retval=((secs_ret)ticks) / (secs_ret)EE_TICKS_PER_SEC;
no2chem 0:b5d3bd64d2dc 93 return retval;
no2chem 0:b5d3bd64d2dc 94 }
no2chem 0:b5d3bd64d2dc 95
no2chem 0:b5d3bd64d2dc 96 ee_u32 default_num_contexts=1;
no2chem 0:b5d3bd64d2dc 97
no2chem 0:b5d3bd64d2dc 98 /* Function : portable_init
no2chem 0:b5d3bd64d2dc 99 Target specific initialization code
no2chem 0:b5d3bd64d2dc 100 Test for some common mistakes.
no2chem 0:b5d3bd64d2dc 101 */
no2chem 0:b5d3bd64d2dc 102 void portable_init(core_portable *p, int *argc, char *argv[])
no2chem 0:b5d3bd64d2dc 103 {
no2chem 0:b5d3bd64d2dc 104 //#error "Call board initialization routines in portable init (if needed), in particular initialize UART!\n"
no2chem 0:b5d3bd64d2dc 105 if (sizeof(ee_ptr_int) != sizeof(ee_u8 *)) {
no2chem 0:b5d3bd64d2dc 106 ee_printf("ERROR! Please define ee_ptr_int to a type that holds a pointer!\n");
no2chem 0:b5d3bd64d2dc 107 }
no2chem 0:b5d3bd64d2dc 108 if (sizeof(ee_u32) != 4) {
no2chem 0:b5d3bd64d2dc 109 ee_printf("ERROR! Please define ee_u32 to a 32b unsigned type!\n");
no2chem 0:b5d3bd64d2dc 110 }
no2chem 0:b5d3bd64d2dc 111 p->portable_id=1;
no2chem 0:b5d3bd64d2dc 112 }
no2chem 0:b5d3bd64d2dc 113 /* Function : portable_fini
no2chem 0:b5d3bd64d2dc 114 Target specific final code
no2chem 0:b5d3bd64d2dc 115 */
no2chem 0:b5d3bd64d2dc 116 void portable_fini(core_portable *p)
no2chem 0:b5d3bd64d2dc 117 {
no2chem 0:b5d3bd64d2dc 118 p->portable_id=0;
no2chem 0:b5d3bd64d2dc 119 }
no2chem 0:b5d3bd64d2dc 120
no2chem 0:b5d3bd64d2dc 121