diff --git a/README.md b/README.md index d339099..26636f4 100644 --- a/README.md +++ b/README.md @@ -128,11 +128,11 @@ What is and is not allowed. ~~~ 4. All source files must be compiled with the same flags. 5. All data type sizes must match size in bits such that: - * `ee_u8` is an 8 bits datatype. - * `ee_s16` is a 16 bits datatype. - * `ee_u16` is a 16 bits datatype. - * `ee_s32` is a 32 bits datatype. - * `ee_u32` is a 32 bits datatype. + * `ee_u8` is an unsigned 8-bit datatype. + * `ee_s16` is a signed 16-bit datatype. + * `ee_u16` is an unsigned 16-bit datatype. + * `ee_s32` is a signed 32-bit datatype. + * `ee_u32` is an unsigned 32-bit datatype. ## Allowed diff --git a/barebones/ee_printf.c b/barebones/ee_printf.c index ce75052..b08f59d 100755 --- a/barebones/ee_printf.c +++ b/barebones/ee_printf.c @@ -29,9 +29,9 @@ limitations under the License. static char *digits = "0123456789abcdefghijklmnopqrstuvwxyz"; static char *upper_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -static size_t strnlen(const char *s, size_t count); +static ee_size_t strnlen(const char *s, ee_size_t count); -static size_t strnlen(const char *s, size_t count) +static ee_size_t strnlen(const char *s, ee_size_t count) { const char *sc; for (sc = s; *sc != '\0' && count--; ++sc); @@ -183,7 +183,7 @@ static char *iaddr(char *str, unsigned char *addr, int size, int precision, int return str; } -#ifdef HAS_FLOAT +#if HAS_FLOAT char *ecvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf); char *fcvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf); @@ -529,7 +529,7 @@ static int ee_vsprintf(char *buf, const char *fmt, va_list args) case 'u': break; -#ifdef HAS_FLOAT +#if HAS_FLOAT case 'f': str = flt(str, va_arg(args, double), field_width, precision, *fmt, flags | SIGN); diff --git a/freedom-metal/core_portme.c b/freedom-metal/core_portme.c index 202841c..aae8cdb 100755 --- a/freedom-metal/core_portme.c +++ b/freedom-metal/core_portme.c @@ -36,9 +36,11 @@ Original Author: Shay Gal-on #endif volatile ee_s32 seed4_volatile=ITERATIONS; volatile ee_s32 seed5_volatile=0; + + unsigned long long timebase = 0; /* Porting : Timing functions How to capture time and convert to seconds must be ported to whatever is supported by the platform. - e.g. Read value from on board RTC, read value from cpu clock cycles performance counter etc. + e.g. Read value from on board RTC, read value from cpu clock cycles performance counter etc. Sample implementation for standard time.h and windows.h definitions included. */ CORETIMETYPE barebones_clock() { @@ -54,7 +56,7 @@ CORETIMETYPE barebones_clock() { #define MYTIMEDIFF(fin,ini) ((fin)-(ini)) #define TIMER_RES_DIVIDER 1 #define SAMPLE_TIME_IMPLEMENTATION 1 -#define EE_TICKS_PER_SEC (CLOCKS_PER_SEC / TIMER_RES_DIVIDER) +#define EE_TICKS_PER_SEC (timebase/ TIMER_RES_DIVIDER) /** Define Host specific (POSIX), or target specific global time variables. */ static CORETIMETYPE start_time_val, stop_time_val; @@ -62,28 +64,28 @@ static CORETIMETYPE start_time_val, stop_time_val; /* Function : start_time This function will be called right before starting the timed portion of the benchmark. - Implementation may be capturing a system timer (as implemented in the example code) + Implementation may be capturing a system timer (as implemented in the example code) or zeroing some system parameters - e.g. setting the cpu clocks cycles to 0. */ void start_time(void) { - GETMYTIME(&start_time_val ); + GETMYTIME(&start_time_val ); } /* Function : stop_time This function will be called right after ending the timed portion of the benchmark. - Implementation may be capturing a system timer (as implemented in the example code) + Implementation may be capturing a system timer (as implemented in the example code) or other system parameters - e.g. reading the current value of cpu cycles counter. */ void stop_time(void) { - GETMYTIME(&stop_time_val ); + GETMYTIME(&stop_time_val ); } /* Function : get_time Return an abstract "ticks" number that signifies time on the system. - + Actual value returned may be cpu cycles, milliseconds or any other value, as long as it can be converted to seconds by . This methodology is taken to accomodate any hardware or simulated platform. - The sample implementation returns millisecs by default, + The sample implementation returns millisecs by default, and the resolution is controlled by */ CORE_TICKS get_time(void) { @@ -104,7 +106,7 @@ secs_ret time_in_secs(CORE_TICKS ticks) { ee_u32 default_num_contexts=1; /* Function : portable_init - Target specific initialization code + Target specific initialization code Test for some common mistakes. */ void portable_init(core_portable *p, int *argc, char *argv[]) @@ -115,10 +117,13 @@ void portable_init(core_portable *p, int *argc, char *argv[]) if (sizeof(ee_u32) != 4) { ee_printf("ERROR! Please define ee_u32 to a 32b unsigned type!\n"); } + //get timer frequency + metal_timer_get_timebase_frequency(0, &timebase); + p->portable_id=1; } /* Function : portable_fini - Target specific final code + Target specific final code */ void portable_fini(core_portable *p) { diff --git a/freedom-metal/core_portme.h b/freedom-metal/core_portme.h index 9d8d579..9491a5a 100755 --- a/freedom-metal/core_portme.h +++ b/freedom-metal/core_portme.h @@ -23,10 +23,10 @@ Original Author: Shay Gal-on /************************/ /* Data types and settings */ /************************/ -/* Configuration : HAS_FLOAT +/* Configuration : HAS_FLOAT Define to 1 if the platform supports floating point. */ -#ifndef HAS_FLOAT +#ifndef HAS_FLOAT #define HAS_FLOAT 1 #endif /* Configuration : HAS_TIME_H @@ -60,23 +60,23 @@ Original Author: Shay Gal-on /* Definitions : COMPILER_VERSION, COMPILER_FLAGS, MEM_LOCATION Initialize these strings per platform */ -#ifndef COMPILER_VERSION +#ifndef COMPILER_VERSION #ifdef __GNUC__ #define COMPILER_VERSION "GCC"__VERSION__ #else #define COMPILER_VERSION "Please put compiler version here (e.g. gcc 4.1)" #endif #endif -#ifndef COMPILER_FLAGS +#ifndef COMPILER_FLAGS #define COMPILER_FLAGS FLAGS_STR /* "Please put compiler flags here (e.g. -o3)" */ #endif -#ifndef MEM_LOCATION +#ifndef MEM_LOCATION #define MEM_LOCATION "STACK" #endif /* Data Types : To avoid compiler issues, define the data types that need ot be used for 8b, 16b and 32b in . - + *Imprtant* : ee_ptr_int needs to be the data type used to hold pointers, otherwise coremark may fail!!! */ @@ -85,7 +85,7 @@ typedef unsigned short ee_u16; typedef signed int ee_s32; typedef double ee_f32; typedef unsigned char ee_u8; -typedef unsigned int ee_u32; +typedef signed int ee_u32; typedef signed long ee_u64; #if __riscv_xlen == 32 typedef ee_u32 ee_ptr_int; @@ -102,12 +102,12 @@ typedef signed int ee_size_t; /* Configuration : CORE_TICKS Define type of return from the timing functions. */ -#define CORETIMETYPE ee_u32 +#define CORETIMETYPE ee_u32 typedef ee_u32 CORE_TICKS; /* Configuration : SEED_METHOD Defines method to get seed values that cannot be computed at compile time. - + Valid values : SEED_ARG - from command line. SEED_FUNC - from a system function. @@ -119,7 +119,7 @@ typedef ee_u32 CORE_TICKS; /* Configuration : MEM_METHOD Defines method to get a block of memry. - + Valid values : MEM_MALLOC - for platforms that implement malloc and have malloc.h. MEM_STATIC - to use a static memory array. @@ -130,19 +130,19 @@ typedef ee_u32 CORE_TICKS; #endif /* Configuration : MULTITHREAD - Define for parallel execution - + Define for parallel execution + Valid values : 1 - only one context (default). N>1 - will execute N copies in parallel. - - Note : + + Note : If this flag is defined to more then 1, an implementation for launching parallel contexts must be defined. - + Two sample implementations are provided. Use or to enable them. - + It is valid to have a different implementation of and in , - to fit a particular architecture. + to fit a particular architecture. */ #ifndef MULTITHREAD #define MULTITHREAD 1 @@ -152,22 +152,22 @@ typedef ee_u32 CORE_TICKS; #endif /* Configuration : MAIN_HAS_NOARGC - Needed if platform does not support getting arguments to main. - + Needed if platform does not support getting arguments to main. + Valid values : 0 - argc/argv to main is supported 1 - argc/argv to main is not supported - - Note : + + Note : This flag only matters if MULTITHREAD has been defined to a value greater then 1. */ -#ifndef MAIN_HAS_NOARGC +#ifndef MAIN_HAS_NOARGC #define MAIN_HAS_NOARGC 0 #endif /* Configuration : MAIN_HAS_NORETURN - Needed if platform does not support returning a value from main. - + Needed if platform does not support returning a value from main. + Valid values : 0 - main returns an int, and return value will be 0. 1 - platform does not support returning a value from main @@ -201,4 +201,5 @@ void portable_fini(core_portable *p); int ee_printf(const char *fmt, ...); +extern int metal_timer_get_timebase_frequency(int hartid, unsigned long long *timebase); #endif /* CORE_PORTME_H */ diff --git a/freedom-metal/core_portme.mak b/freedom-metal/core_portme.mak index f99dcba..1868e8e 100755 --- a/freedom-metal/core_portme.mak +++ b/freedom-metal/core_portme.mak @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# +# # Original Author: Shay Gal-on #File : core_portme.mak @@ -26,23 +26,23 @@ OUTFLAG= -o #CC = gcc # Flag : LD # Use this flag to define compiler to use -#LD = +#LD = # Flag : AS # Use this flag to define compiler to use #AS = gas # Flag : CFLAGS # Use this flag to define compiler options. Note, you can add compiler options from the command line using XCFLAGS="other flags" -PORT_CFLAGS = -specs=nano.specs -O3 -DITERATIONS=10000 -DPERFORMANCE_RUN=1 -DMAIN_HAS_NOARGC=1 -DMAIN_HAS_NORETURN=1 -DHAS_STDIO -DHAS_PRINTF -DHAS_TIME_H -DUSE_CLOCK +PORT_CFLAGS = -O3 -DITERATIONS=3000 -DPERFORMANCE_RUN=1 -DMAIN_HAS_NOARGC=1 -DMAIN_HAS_NORETURN=1 -DHAS_STDIO -DHAS_PRINTF -DHAS_TIME_H -DUSE_CLOCK FLAGS_STR = "$(PORT_CFLAGS) $(XCFLAGS) $(XLFLAGS) $(LFLAGS_END)" override CFLAGS += $(PORT_CFLAGS) -I$(PORT_DIR) -I. -DFLAGS_STR=\"$(FLAGS_STR)\" -Xlinker --defsym=__stack_size=0x1000 #Flag : LFLAGS_END -# Define any libraries needed for linking or other flags that should come at the end of the link line (e.g. linker scripts). +# Define any libraries needed for linking or other flags that should come at the end of the link line (e.g. linker scripts). # Note : On certain platforms, the default clock_gettime implementation is supported but requires linking of librt. SEPARATE_COMPILE = # Flag : SEPARATE_COMPILE # You must also define below how to create an object file, and how to link. OBJOUT = -o -LFLAGS = +LFLAGS = ASFLAGS = OFLAG = -o COUT = -c @@ -80,7 +80,7 @@ $(OPATH)$(PORT_DIR)/%$(OEXT) : %.s # For the purpose of this simple port, no pre or post steps needed. .PHONY : port_prebuild port_postbuild port_prerun port_postrun port_preload port_postload -port_pre% port_post% : +port_pre% port_post% : # FLAG : OPATH # Path to the output folder. Default - current folder. diff --git a/freedom-metal/ee_printf.c b/freedom-metal/ee_printf.c index 1380561..e0b18ed 100755 --- a/freedom-metal/ee_printf.c +++ b/freedom-metal/ee_printf.c @@ -54,7 +54,7 @@ static char *number(char *str, long num, int base, int size, int precision, int if (type & UPPERCASE) dig = upper_digits; if (type & LEFT) type &= ~ZEROPAD; if (base < 2 || base > 36) return 0; - + c = (type & ZEROPAD) ? '0' : ' '; sign = 0; if (type & SIGN) @@ -102,7 +102,7 @@ static char *number(char *str, long num, int base, int size, int precision, int size -= precision; if (!(type & (ZEROPAD | LEFT))) while (size-- > 0) *str++ = ' '; if (sign) *str++ = sign; - + if (type & HEX_PREP) { if (base == 8) @@ -154,19 +154,19 @@ static char *iaddr(char *str, unsigned char *addr, int size, int precision, int { if (i != 0) tmp[len++] = '.'; n = addr[i]; - + if (n == 0) tmp[len++] = digits[0]; else { - if (n >= 100) + if (n >= 100) { tmp[len++] = digits[n / 100]; n = n % 100; tmp[len++] = digits[n / 10]; n = n % 10; } - else if (n >= 10) + else if (n >= 10) { tmp[len++] = digits[n / 10]; n = n % 10; @@ -183,12 +183,12 @@ static char *iaddr(char *str, unsigned char *addr, int size, int precision, int return str; } -#ifdef HAS_FLOAT +#if HAS_FLOAT char *ecvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf); char *fcvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf); -static void ee_bufcpy(char *d, char *s, int count); - +static void ee_bufcpy(char *d, char *s, int count); + void ee_bufcpy(char *pd, char *ps, int count) { char *pe=ps+count; while (ps!=pe) @@ -310,7 +310,7 @@ static void decimal_point(char *buffer) if (*buffer) { int n = strnlen(buffer,256); - while (n > 0) + while (n > 0) { buffer[n + 1] = buffer[n]; n--; @@ -419,7 +419,7 @@ static int ee_vsprintf(char *buf, const char *fmt, va_list args) *str++ = *fmt; continue; } - + // Process flags flags = 0; repeat: @@ -432,7 +432,7 @@ static int ee_vsprintf(char *buf, const char *fmt, va_list args) case '#': flags |= HEX_PREP; goto repeat; case '0': flags |= ZEROPAD; goto repeat; } - + // Get field width field_width = -1; if (is_digit(*fmt)) @@ -452,7 +452,7 @@ static int ee_vsprintf(char *buf, const char *fmt, va_list args) precision = -1; if (*fmt == '.') { - ++fmt; + ++fmt; if (is_digit(*fmt)) precision = skip_atoi(&fmt); else if (*fmt == '*') @@ -529,7 +529,7 @@ static int ee_vsprintf(char *buf, const char *fmt, va_list args) case 'u': break; -#ifdef HAS_FLOAT +#if HAS_FLOAT case 'f': str = flt(str, va_arg(args, double), field_width, precision, *fmt, flags | SIGN); @@ -566,12 +566,12 @@ void uart_send_char(char c) { Wait until UART is ready Write char to UART Wait until UART is done - + Or in code: while (*UART_CONTROL_ADDRESS != UART_READY); *UART_DATA_ADDRESS = c; while (*UART_CONTROL_ADDRESS != UART_READY); - + Check the UART sample code on your platform or the board documentation. */ }