Skip to content

Commit 92fa2e0

Browse files
committed
Adicionando ee_printf
1 parent 33d5706 commit 92fa2e0

File tree

5 files changed

+1048
-2
lines changed

5 files changed

+1048
-2
lines changed

benchmarks/core_portme.c

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*
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 <stdio.h>
20+
#include <stdlib.h>
21+
#include "coremark.h"
22+
23+
#if VALIDATION_RUN
24+
volatile ee_s32 seed1_volatile = 0x3415;
25+
volatile ee_s32 seed2_volatile = 0x3415;
26+
volatile ee_s32 seed3_volatile = 0x66;
27+
#endif
28+
#if PERFORMANCE_RUN
29+
volatile ee_s32 seed1_volatile = 0x0;
30+
volatile ee_s32 seed2_volatile = 0x0;
31+
volatile ee_s32 seed3_volatile = 0x66;
32+
#endif
33+
#if PROFILE_RUN
34+
volatile ee_s32 seed1_volatile = 0x8;
35+
volatile ee_s32 seed2_volatile = 0x8;
36+
volatile ee_s32 seed3_volatile = 0x8;
37+
#endif
38+
volatile ee_s32 seed4_volatile = ITERATIONS;
39+
volatile ee_s32 seed5_volatile = 0;
40+
/* Porting : Timing functions
41+
How to capture time and convert to seconds must be ported to whatever is
42+
supported by the platform. e.g. Read value from on board RTC, read value from
43+
cpu clock cycles performance counter etc. Sample implementation for standard
44+
time.h and windows.h definitions included.
45+
*/
46+
/* Define : TIMER_RES_DIVIDER
47+
Divider to trade off timer resolution and total time that can be
48+
measured.
49+
50+
Use lower values to increase resolution, but make sure that overflow
51+
does not occur. If there are issues with the return value overflowing,
52+
increase this value.
53+
*/
54+
#define NSECS_PER_SEC CLOCKS_PER_SEC
55+
#define CORETIMETYPE clock_t
56+
#define GETMYTIME(_t) (*_t = clock())
57+
#define MYTIMEDIFF(fin, ini) ((fin) - (ini))
58+
#define TIMER_RES_DIVIDER 1
59+
#define SAMPLE_TIME_IMPLEMENTATION 1
60+
#define EE_TICKS_PER_SEC (NSECS_PER_SEC / TIMER_RES_DIVIDER)
61+
62+
/** Define Host specific (POSIX), or target specific global time variables. */
63+
static CORETIMETYPE start_time_val, stop_time_val;
64+
65+
/* Function : start_time
66+
This function will be called right before starting the timed portion of
67+
the benchmark.
68+
69+
Implementation may be capturing a system timer (as implemented in the
70+
example code) or zeroing some system parameters - e.g. setting the cpu clocks
71+
cycles to 0.
72+
*/
73+
void
74+
start_time(void)
75+
{
76+
GETMYTIME(&start_time_val);
77+
}
78+
/* Function : stop_time
79+
This function will be called right after ending the timed portion of the
80+
benchmark.
81+
82+
Implementation may be capturing a system timer (as implemented in the
83+
example code) or other system parameters - e.g. reading the current value of
84+
cpu cycles counter.
85+
*/
86+
void
87+
stop_time(void)
88+
{
89+
GETMYTIME(&stop_time_val);
90+
}
91+
/* Function : get_time
92+
Return an abstract "ticks" number that signifies time on the system.
93+
94+
Actual value returned may be cpu cycles, milliseconds or any other
95+
value, as long as it can be converted to seconds by <time_in_secs>. This
96+
methodology is taken to accommodate any hardware or simulated platform. The
97+
sample implementation returns millisecs by default, and the resolution is
98+
controlled by <TIMER_RES_DIVIDER>
99+
*/
100+
CORE_TICKS
101+
get_time(void)
102+
{
103+
CORE_TICKS elapsed
104+
= (CORE_TICKS)(MYTIMEDIFF(stop_time_val, start_time_val));
105+
return elapsed;
106+
}
107+
/* Function : time_in_secs
108+
Convert the value returned by get_time to seconds.
109+
110+
The <secs_ret> type is used to accommodate systems with no support for
111+
floating point. Default implementation implemented by the EE_TICKS_PER_SEC
112+
macro above.
113+
*/
114+
secs_ret
115+
time_in_secs(CORE_TICKS ticks)
116+
{
117+
secs_ret retval = ((secs_ret)ticks) / (secs_ret)EE_TICKS_PER_SEC;
118+
return retval;
119+
}
120+
121+
ee_u32 default_num_contexts = 1;
122+
123+
/* Function : portable_init
124+
Target specific initialization code
125+
Test for some common mistakes.
126+
*/
127+
void
128+
portable_init(core_portable *p, int *argc, char *argv[])
129+
{
130+
131+
(void)argc; // prevent unused warning
132+
(void)argv; // prevent unused warning
133+
134+
if (sizeof(ee_ptr_int) != sizeof(ee_u8 *))
135+
{
136+
ee_printf(
137+
"ERROR! Please define ee_ptr_int to a type that holds a "
138+
"pointer!\n");
139+
}
140+
if (sizeof(ee_u32) != 4)
141+
{
142+
ee_printf("ERROR! Please define ee_u32 to a 32b unsigned type!\n");
143+
}
144+
p->portable_id = 1;
145+
}
146+
/* Function : portable_fini
147+
Target specific final code
148+
*/
149+
void
150+
portable_fini(core_portable *p)
151+
{
152+
p->portable_id = 0;
153+
}

benchmarks/core_portme.h

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
/*
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+
/* Topic : Description
20+
This file contains configuration constants required to execute on
21+
different platforms
22+
*/
23+
#ifndef CORE_PORTME_H
24+
#define CORE_PORTME_H
25+
/************************/
26+
/* Data types and settings */
27+
/************************/
28+
/* Configuration : HAS_FLOAT
29+
Define to 1 if the platform supports floating point.
30+
*/
31+
#ifndef HAS_FLOAT
32+
#define HAS_FLOAT 1
33+
#endif
34+
/* Configuration : HAS_TIME_H
35+
Define to 1 if platform has the time.h header file,
36+
and implementation of functions thereof.
37+
*/
38+
#ifndef HAS_TIME_H
39+
#define HAS_TIME_H 1
40+
#endif
41+
/* Configuration : USE_CLOCK
42+
Define to 1 if platform has the time.h header file,
43+
and implementation of functions thereof.
44+
*/
45+
#ifndef USE_CLOCK
46+
#define USE_CLOCK 1
47+
#endif
48+
/* Configuration : HAS_STDIO
49+
Define to 1 if the platform has stdio.h.
50+
*/
51+
#ifndef HAS_STDIO
52+
#define HAS_STDIO 1
53+
#endif
54+
/* Configuration : HAS_PRINTF
55+
Define to 1 if the platform has stdio.h and implements the printf
56+
function.
57+
*/
58+
#ifndef HAS_PRINTF
59+
#define HAS_PRINTF 1
60+
#endif
61+
62+
/* Configuration : CORE_TICKS
63+
Define type of return from the timing functions.
64+
*/
65+
#include <time.h>
66+
typedef clock_t CORE_TICKS;
67+
68+
/* Definitions : COMPILER_VERSION, COMPILER_FLAGS, MEM_LOCATION
69+
Initialize these strings per platform
70+
*/
71+
#ifndef COMPILER_VERSION
72+
#ifdef __GNUC__
73+
#define COMPILER_VERSION "GCC"__VERSION__
74+
#else
75+
#define COMPILER_VERSION "Please put compiler version here (e.g. gcc 4.1)"
76+
#endif
77+
#endif
78+
#ifndef COMPILER_FLAGS
79+
#define COMPILER_FLAGS \
80+
FLAGS_STR /* "Please put compiler flags here (e.g. -o3)" */
81+
#endif
82+
#ifndef MEM_LOCATION
83+
#define MEM_LOCATION "STACK"
84+
#endif
85+
86+
/* Data Types :
87+
To avoid compiler issues, define the data types that need ot be used for
88+
8b, 16b and 32b in <core_portme.h>.
89+
90+
*Imprtant* :
91+
ee_ptr_int needs to be the data type used to hold pointers, otherwise
92+
coremark may fail!!!
93+
*/
94+
typedef signed short ee_s16;
95+
typedef unsigned short ee_u16;
96+
typedef signed int ee_s32;
97+
typedef double ee_f32;
98+
typedef unsigned char ee_u8;
99+
typedef unsigned int ee_u32;
100+
typedef ee_u32 ee_ptr_int;
101+
typedef size_t ee_size_t;
102+
/* align_mem :
103+
This macro is used to align an offset to point to a 32b value. It is
104+
used in the Matrix algorithm to initialize the input memory blocks.
105+
*/
106+
#define align_mem(x) (void *)(4 + (((ee_ptr_int)(x)-1) & ~3))
107+
108+
/* Configuration : SEED_METHOD
109+
Defines method to get seed values that cannot be computed at compile
110+
time.
111+
112+
Valid values :
113+
SEED_ARG - from command line.
114+
SEED_FUNC - from a system function.
115+
SEED_VOLATILE - from volatile variables.
116+
*/
117+
#ifndef SEED_METHOD
118+
#define SEED_METHOD SEED_VOLATILE
119+
#endif
120+
121+
/* Configuration : MEM_METHOD
122+
Defines method to get a block of memry.
123+
124+
Valid values :
125+
MEM_MALLOC - for platforms that implement malloc and have malloc.h.
126+
MEM_STATIC - to use a static memory array.
127+
MEM_STACK - to allocate the data block on the stack (NYI).
128+
*/
129+
#ifndef MEM_METHOD
130+
#define MEM_METHOD MEM_STACK
131+
#endif
132+
133+
/* Configuration : MULTITHREAD
134+
Define for parallel execution
135+
136+
Valid values :
137+
1 - only one context (default).
138+
N>1 - will execute N copies in parallel.
139+
140+
Note :
141+
If this flag is defined to more then 1, an implementation for launching
142+
parallel contexts must be defined.
143+
144+
Two sample implementations are provided. Use <USE_PTHREAD> or <USE_FORK>
145+
to enable them.
146+
147+
It is valid to have a different implementation of <core_start_parallel>
148+
and <core_end_parallel> in <core_portme.c>, to fit a particular architecture.
149+
*/
150+
#ifndef MULTITHREAD
151+
#define MULTITHREAD 1
152+
#define USE_PTHREAD 0
153+
#define USE_FORK 0
154+
#define USE_SOCKET 0
155+
#endif
156+
157+
/* Configuration : MAIN_HAS_NOARGC
158+
Needed if platform does not support getting arguments to main.
159+
160+
Valid values :
161+
0 - argc/argv to main is supported
162+
1 - argc/argv to main is not supported
163+
164+
Note :
165+
This flag only matters if MULTITHREAD has been defined to a value
166+
greater then 1.
167+
*/
168+
#ifndef MAIN_HAS_NOARGC
169+
#define MAIN_HAS_NOARGC 0
170+
#endif
171+
172+
/* Configuration : MAIN_HAS_NORETURN
173+
Needed if platform does not support returning a value from main.
174+
175+
Valid values :
176+
0 - main returns an int, and return value will be 0.
177+
1 - platform does not support returning a value from main
178+
*/
179+
#ifndef MAIN_HAS_NORETURN
180+
#define MAIN_HAS_NORETURN 0
181+
#endif
182+
183+
/* Variable : default_num_contexts
184+
Not used for this simple port, must contain the value 1.
185+
*/
186+
extern ee_u32 default_num_contexts;
187+
188+
typedef struct CORE_PORTABLE_S
189+
{
190+
ee_u8 portable_id;
191+
} core_portable;
192+
193+
/* target specific init/fini */
194+
void portable_init(core_portable *p, int *argc, char *argv[]);
195+
void portable_fini(core_portable *p);
196+
197+
#if !defined(PROFILE_RUN) && !defined(PERFORMANCE_RUN) \
198+
&& !defined(VALIDATION_RUN)
199+
#if (TOTAL_DATA_SIZE == 1200)
200+
#define PROFILE_RUN 1
201+
#elif (TOTAL_DATA_SIZE == 2000)
202+
#define PERFORMANCE_RUN 1
203+
#else
204+
#define VALIDATION_RUN 1
205+
#endif
206+
#endif
207+
208+
#endif /* CORE_PORTME_H */

firmware/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ HEXDUMP = hexdump
1212
# Configuração de arquitetura
1313
MARCH = rv32im_zicsr
1414
MABI = ilp32
15-
BUILD_FLAGS = -nostartfiles -nostdinc -nostdlib -static -O2
15+
BUILD_FLAGS = -nostartfiles -nostdlib -static -O2 -Wimplicit-function-declaration
1616
INCLUDES = -Ilib
1717

1818
# Diretórios
@@ -22,7 +22,7 @@ SRC_DIR = src
2222
LD_FILE = utils/link64k.ld
2323

2424
# Definição dos arquivos-fonte
25-
C_SOURCES = main.c $(SRC_DIR)/pwm.c $(SRC_DIR)/risco5.c $(SRC_DIR)/uart.c $(SRC_DIR)/conversion.c
25+
C_SOURCES = main.c $(SRC_DIR)/pwm.c $(SRC_DIR)/risco5.c $(SRC_DIR)/uart.c $(SRC_DIR)/conversion.c $(SRC_DIR)/ee_printf.c
2626
ASM_SOURCES = $(SRC_DIR)/boot.s $(SRC_DIR)/risco5_lib.s $(SRC_DIR)/uart_primitives.s $(SRC_DIR)/gpio.s $(SRC_DIR)/interruption.s
2727

2828
# Geração dos arquivos-objeto correspondentes

firmware/lib/risco5.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ typedef short int16_t;
2727
typedef char int8_t;
2828

2929
typedef unsigned int size_t;
30+
typedef unsigned int ee_size_t;
3031

3132
void *memset (void *dest, int val, size_t len);
3233

@@ -52,4 +53,6 @@ void delay_s (uint32_t s);
5253
void delay_ms(uint32_t ms);
5354
void delay_us(uint32_t us);
5455

56+
int ee_printf(const char *fmt, ...);
57+
5558
#endif // __RISCO_5_H__

0 commit comments

Comments
 (0)