SAMV71 Xplained Ultra Software Package 1.4

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 unsigned long long ee_ptr_int;
00092 /* align an offset to point to a 32b value */
00093 #define align_mem(x) (void *)(4 + (((ee_ptr_int)(x) - 1) & ~3))
00094 
00095 /* Configuration: SEED_METHOD
00096     Defines method to get seed values that cannot be computed at compile time.
00097     
00098     Valid values:
00099     SEED_ARG - from command line.
00100     SEED_FUNC - from a system function.
00101     SEED_VOLATILE - from volatile variables.
00102 */
00103 #ifndef SEED_METHOD
00104 #define SEED_METHOD SEED_ARG
00105 #endif
00106 
00107 /* Configuration: MEM_METHOD
00108     Defines method to get a block of memry.
00109     
00110     Valid values:
00111     MEM_MALLOC - for platforms that implement malloc and have malloc.h.
00112     MEM_STATIC - to use a static memory array.
00113     MEM_STACK - to allocate the data block on the stack (NYI).
00114 */
00115 #ifndef MEM_METHOD
00116 #define MEM_METHOD MEM_MALLOC
00117 #endif
00118 
00119 /* Configuration: MULTITHREAD
00120     Define for parallel execution 
00121     
00122     Valid values:
00123     1 - only one context (default).
00124     N>1 - will execute N copies in parallel.
00125     
00126     Note: 
00127     If this flag is defined to more then 1, an implementation for launching parallel contexts must be defined.
00128     
00129     Two sample implementations are provided. Use <USE_PTHREAD> or <USE_FORK> to enable them.
00130     
00131     It is valid to have a different implementation of <core_start_parallel> and <core_end_parallel> in <core_portme.c>,
00132     to fit a particular architecture. 
00133 */
00134 #ifndef MULTITHREAD
00135 #define MULTITHREAD 1
00136 #endif
00137 
00138 /* Configuration: USE_PTHREAD
00139     Sample implementation for launching parallel contexts 
00140     This implementation uses pthread_thread_create and pthread_join.
00141     
00142     Valid values:
00143     0 - Do not use pthreads API.
00144     1 - Use pthreads API
00145     
00146     Note: 
00147     This flag only matters if MULTITHREAD has been defined to a value greater then 1.
00148 */
00149 #ifndef USE_PTHREAD
00150 #define USE_PTHREAD 0
00151 #endif
00152 
00153 /* Configuration: USE_FORK
00154     Sample implementation for launching parallel contexts 
00155     This implementation uses fork, waitpid, shmget,shmat and shmdt.
00156     
00157     Valid values:
00158     0 - Do not use fork API.
00159     1 - Use fork API
00160     
00161     Note: 
00162     This flag only matters if MULTITHREAD has been defined to a value greater then 1.
00163 */
00164 #ifndef USE_FORK
00165 #define USE_FORK 0
00166 #endif
00167 
00168 /* Configuration: USE_SOCKET
00169     Sample implementation for launching parallel contexts 
00170     This implementation uses fork, socket, sendto and recvfrom
00171     
00172     Valid values:
00173     0 - Do not use fork and sockets API.
00174     1 - Use fork and sockets API
00175     
00176     Note: 
00177     This flag only matters if MULTITHREAD has been defined to a value greater then 1.
00178 */
00179 #ifndef USE_SOCKET
00180 #define USE_SOCKET 0
00181 #endif
00182 
00183 /* Configuration: MAIN_HAS_NOARGC
00184     Needed if platform does not support getting arguments to main. 
00185     
00186     Valid values:
00187     0 - argc/argv to main is supported
00188     1 - argc/argv to main is not supported
00189 */
00190 #ifndef MAIN_HAS_NOARGC 
00191 #define MAIN_HAS_NOARGC 0
00192 #endif
00193 
00194 /* Configuration: MAIN_HAS_NORETURN
00195     Needed if platform does not support returning a value from main. 
00196     
00197     Valid values:
00198     0 - main returns an int, and return value will be 0.
00199     1 - platform does not support returning a value from main
00200 */
00201 #ifndef MAIN_HAS_NORETURN
00202 #define MAIN_HAS_NORETURN 0
00203 #endif
00204 
00205 /* Variable: default_num_contexts
00206     Number of contexts to spawn in multicore context.
00207     Override this global value to change number of contexts used.
00208     
00209     Note:
00210     This value may not be set higher then the <MULTITHREAD> define.
00211     
00212     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.
00213 */
00214 extern ee_u32 default_num_contexts;
00215 
00216 #if (MULTITHREAD>1)
00217 #if USE_PTHREAD
00218     #include <pthread.h>
00219     #define PARALLEL_METHOD "PThreads"
00220 #elif USE_FORK
00221     #include <unistd.h>
00222     #include <errno.h>
00223     #include <sys/wait.h>
00224     #include <sys/shm.h>
00225     #include <string.h> /* for memcpy */
00226     #define PARALLEL_METHOD "Fork"
00227 #elif USE_SOCKET
00228     #include <sys/types.h>
00229     #include <sys/socket.h>
00230     #include <netinet/in.h>
00231     #include <arpa/inet.h>
00232     #include <sys/wait.h>
00233     #include <stdio.h>
00234     #include <stdlib.h>
00235     #include <string.h>
00236     #include <unistd.h>
00237     #include <errno.h>
00238     #define PARALLEL_METHOD "Sockets"
00239 #else
00240     #define PARALLEL_METHOD "Proprietary"
00241     #error "Please implement multicore functionality in core_portme.c to use multiple contexts."
00242 #endif /* Method for multithreading */
00243 #endif /* MULTITHREAD > 1 */
00244 
00245 typedef struct CORE_PORTABLE_S {
00246 #if (MULTITHREAD>1)
00247     #if USE_PTHREAD
00248     pthread_t thread;
00249     #elif USE_FORK
00250     pid_t pid;
00251     int shmid;
00252     void *shm;
00253     #elif USE_SOCKET
00254     pid_t pid;
00255     int sock;
00256     struct sockaddr_in sa;
00257     #endif /* Method for multithreading */
00258 #endif /* MULTITHREAD>1 */
00259     ee_u8   portable_id;
00260 } core_portable;
00261 
00262 /* target specific init/fini */
00263 void portable_init(core_portable *p, int *argc, char *argv[]);
00264 void portable_fini(core_portable *p);
00265 
00266 #if (SEED_METHOD==SEED_VOLATILE)
00267  #if (VALIDATION_RUN || PERFORMANCE_RUN || PROFILE_RUN)
00268   #define RUN_TYPE_FLAG 1
00269  #else
00270   #if (TOTAL_DATA_SIZE==1200)
00271    #define PROFILE_RUN 1
00272   #else
00273    #define PERFORMANCE_RUN 1
00274   #endif
00275  #endif
00276 #endif /* SEED_METHOD==SEED_VOLATILE */
00277 
00278 #endif /* CORE_PORTME_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines