SAMV71 Xplained Ultra Software Package 1.3

core_portme.h

00001 /* File: core_portme.h */
00002 
00003 /*
00004     Author : Shay Gal-On, EEMBC
00005     Legal : TODO!
00006 */ 
00007 /* Topic: Description
00008     This file contains configuration constants required to execute on different platforms
00009 */
00010 #ifndef CORE_PORTME_H
00011 #define CORE_PORTME_H
00012 /************************/
00013 /* Data types and settings */
00014 /************************/
00015 /* Configuration: HAS_FLOAT 
00016     Define to 1 if the platform supports floating point.
00017 */
00018 #ifndef HAS_FLOAT 
00019 #define HAS_FLOAT 1
00020 #endif
00021 /* Configuration: HAS_TIME_H
00022     Define to 1 if platform has the time.h header file,
00023     and implementation of functions thereof.
00024 */
00025 #ifndef HAS_TIME_H
00026 #define HAS_TIME_H 1
00027 #endif
00028 /* Configuration: USE_CLOCK
00029     Define to 1 if platform has the time.h header file,
00030     and implementation of functions thereof.
00031 */
00032 #ifndef USE_CLOCK
00033 #define USE_CLOCK 0
00034 #endif
00035 /* Configuration: HAS_STDIO
00036     Define to 1 if the platform has stdio.h.
00037 */
00038 #ifndef HAS_STDIO
00039 #define HAS_STDIO 1
00040 #endif
00041 /* Configuration: HAS_PRINTF
00042     Define to 1 if the platform has stdio.h and implements the printf function.
00043 */
00044 #ifndef HAS_PRINTF
00045 #define HAS_PRINTF 1
00046 #endif
00047 
00048 /* Configuration: CORE_TICKS
00049     Define type of return from the timing functions.
00050  */
00051 #if defined(_MSC_VER)
00052 #include <windows.h>
00053 typedef size_t CORE_TICKS;
00054 #elif HAS_TIME_H
00055 #include <time.h>
00056 typedef clock_t CORE_TICKS;
00057 #else
00058 #error "Please define type of CORE_TICKS and implement start_time, end_time get_time and time_in_secs functions!"
00059 #endif
00060 
00061 /* Definitions: COMPILER_VERSION, COMPILER_FLAGS, MEM_LOCATION
00062     Initialize these strings per platform
00063 */
00064 #ifndef COMPILER_VERSION 
00065  #ifdef __GNUC__
00066  #define COMPILER_VERSION "GCC"__VERSION__
00067  #else
00068  #define COMPILER_VERSION "Please put compiler version here (e.g. gcc 4.1)"
00069  #endif
00070 #endif
00071 #ifndef COMPILER_FLAGS 
00072  #define COMPILER_FLAGS FLAGS_STR /* "Please put compiler flags here (e.g. -o3)" */
00073 #endif
00074 #ifndef MEM_LOCATION 
00075  #define MEM_LOCATION "Please put data memory location here\n\t\t\t(e.g. code in flash, data on heap etc)"
00076  #define MEM_LOCATION_UNSPEC 1
00077 #endif
00078 
00079 /* Data Types:
00080     To avoid compiler issues, define the data types that need ot be used for 8b, 16b and 32b in <core_portme.h>.
00081     
00082     *Imprtant*:
00083     ee_ptr_int needs to be the data type used to hold pointers, otherwise coremark may fail!!!
00084 */
00085 typedef signed short ee_s16;
00086 typedef unsigned short ee_u16;
00087 typedef signed int ee_s32;
00088 typedef double ee_f32;
00089 typedef unsigned char ee_u8;
00090 typedef unsigned int ee_u32;
00091 typedef ee_u32 ee_ptr_int;
00092 /* align_mem:
00093     This macro is used to align an offset to point to a 32b value. It is used in the Matrix algorithm to initialize the input memory blocks.
00094 */
00095 #define align_mem(x) (void *)(4 + (((ee_ptr_int)(x) - 1) & ~3))
00096 
00097 /* Configuration: SEED_METHOD
00098     Defines method to get seed values that cannot be computed at compile time.
00099     
00100     Valid values:
00101     SEED_ARG - from command line.
00102     SEED_FUNC - from a system function.
00103     SEED_VOLATILE - from volatile variables.
00104 */
00105 #ifndef SEED_METHOD
00106 #define SEED_METHOD SEED_ARG
00107 #endif
00108 
00109 /* Configuration: MEM_METHOD
00110     Defines method to get a block of memry.
00111     
00112     Valid values:
00113     MEM_MALLOC - for platforms that implement malloc and have malloc.h.
00114     MEM_STATIC - to use a static memory array.
00115     MEM_STACK - to allocate the data block on the stack (NYI).
00116 */
00117 #ifndef MEM_METHOD
00118 #define MEM_METHOD MEM_MALLOC
00119 #endif
00120 
00121 /* Configuration: MULTITHREAD
00122     Define for parallel execution 
00123     
00124     Valid values:
00125     1 - only one context (default).
00126     N>1 - will execute N copies in parallel.
00127     
00128     Note: 
00129     If this flag is defined to more then 1, an implementation for launching parallel contexts must be defined.
00130     
00131     Two sample implementations are provided. Use <USE_PTHREAD> or <USE_FORK> to enable them.
00132     
00133     It is valid to have a different implementation of <core_start_parallel> and <core_end_parallel> in <core_portme.c>,
00134     to fit a particular architecture. 
00135 */
00136 #ifndef MULTITHREAD
00137 #define MULTITHREAD 1
00138 #endif
00139 
00140 /* Configuration: USE_PTHREAD
00141     Sample implementation for launching parallel contexts 
00142     This implementation uses pthread_thread_create and pthread_join.
00143     
00144     Valid values:
00145     0 - Do not use pthreads API.
00146     1 - Use pthreads API
00147     
00148     Note: 
00149     This flag only matters if MULTITHREAD has been defined to a value greater then 1.
00150 */
00151 #ifndef USE_PTHREAD
00152 #define USE_PTHREAD 0
00153 #endif
00154 
00155 /* Configuration: USE_FORK
00156     Sample implementation for launching parallel contexts 
00157     This implementation uses fork, waitpid, shmget,shmat and shmdt.
00158     
00159     Valid values:
00160     0 - Do not use fork API.
00161     1 - Use fork API
00162     
00163     Note: 
00164     This flag only matters if MULTITHREAD has been defined to a value greater then 1.
00165 */
00166 #ifndef USE_FORK
00167 #define USE_FORK 0
00168 #endif
00169 
00170 /* Configuration: USE_SOCKET
00171     Sample implementation for launching parallel contexts 
00172     This implementation uses fork, socket, sendto and recvfrom
00173     
00174     Valid values:
00175     0 - Do not use fork and sockets API.
00176     1 - Use fork and sockets API
00177     
00178     Note: 
00179     This flag only matters if MULTITHREAD has been defined to a value greater then 1.
00180 */
00181 #ifndef USE_SOCKET
00182 #define USE_SOCKET 0
00183 #endif
00184 
00185 /* Configuration: MAIN_HAS_NOARGC
00186     Needed if platform does not support getting arguments to main. 
00187     
00188     Valid values:
00189     0 - argc/argv to main is supported
00190     1 - argc/argv to main is not supported
00191 */
00192 #ifndef MAIN_HAS_NOARGC 
00193 #define MAIN_HAS_NOARGC 0
00194 #endif
00195 
00196 /* Configuration: MAIN_HAS_NORETURN
00197     Needed if platform does not support returning a value from main. 
00198     
00199     Valid values:
00200     0 - main returns an int, and return value will be 0.
00201     1 - platform does not support returning a value from main
00202 */
00203 #ifndef MAIN_HAS_NORETURN
00204 #define MAIN_HAS_NORETURN 0
00205 #endif
00206 
00207 /* Variable: default_num_contexts
00208     Number of contexts to spawn in multicore context.
00209     Override this global value to change number of contexts used.
00210     
00211     Note:
00212     This value may not be set higher then the <MULTITHREAD> define.
00213     
00214     To experiment, you can set the <MULTITHREAD> define to the highest value expected, and use argc/argv in the <portable_init> to set this value from the command line.
00215 */
00216 extern ee_u32 default_num_contexts;
00217 
00218 #if (MULTITHREAD>1)
00219 #if USE_PTHREAD
00220     #include <pthread.h>
00221     #define PARALLEL_METHOD "PThreads"
00222 #elif USE_FORK
00223     #include <unistd.h>
00224     #include <errno.h>
00225     #include <sys/wait.h>
00226     #include <sys/shm.h>
00227     #include <string.h> /* for memcpy */
00228     #define PARALLEL_METHOD "Fork"
00229 #elif USE_SOCKET
00230     #include <sys/types.h>
00231     #include <sys/socket.h>
00232     #include <netinet/in.h>
00233     #include <arpa/inet.h>
00234     #include <sys/wait.h>
00235     #include <stdio.h>
00236     #include <stdlib.h>
00237     #include <string.h>
00238     #include <unistd.h>
00239     #include <errno.h>
00240     #define PARALLEL_METHOD "Sockets"
00241 #else
00242     #define PARALLEL_METHOD "Proprietary"
00243     #error "Please implement multicore functionality in core_portme.c to use multiple contexts."
00244 #endif /* Method for multithreading */
00245 #endif /* MULTITHREAD > 1 */
00246 
00247 typedef struct CORE_PORTABLE_S {
00248 #if (MULTITHREAD>1)
00249     #if USE_PTHREAD
00250     pthread_t thread;
00251     #elif USE_FORK
00252     pid_t pid;
00253     int shmid;
00254     void *shm;
00255     #elif USE_SOCKET
00256     pid_t pid;
00257     int sock;
00258     struct sockaddr_in sa;
00259     #endif /* Method for multithreading */
00260 #endif /* MULTITHREAD>1 */
00261     ee_u8   portable_id;
00262 } core_portable;
00263 
00264 /* target specific init/fini */
00265 void portable_init(core_portable *p, int *argc, char *argv[]);
00266 void portable_fini(core_portable *p);
00267 
00268 #if (SEED_METHOD==SEED_VOLATILE)
00269  #if (VALIDATION_RUN || PERFORMANCE_RUN || PROFILE_RUN)
00270   #define RUN_TYPE_FLAG 1
00271  #else
00272   #if (TOTAL_DATA_SIZE==1200)
00273    #define PROFILE_RUN 1
00274   #else
00275    #define PERFORMANCE_RUN 1
00276   #endif
00277  #endif
00278 #endif /* SEED_METHOD==SEED_VOLATILE */
00279 
00280 #endif /* CORE_PORTME_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines