00001 #ifndef __PLATFORM_H_INCLUDED_SW__
00002 #define __PLATFORM_H_INCLUDED_SW__
00003
00004
00005
00006
00007
00008
00009
00010 #include "nq_system.h"
00011
00012 #ifdef SYSTEM_SUN
00013 #include <stdio.h>
00014 #include <stdlib.h>
00015 #include <errno.h>
00016 #include <string.h>
00017 #include <ctype.h>
00018 #include <termios.h>
00019
00020 #include <stdarg.h>
00021
00022 #include <sys/timeb.h>
00023 #include <sys/times.h>
00024 #include <sys/types.h>
00025 #include <unistd.h>
00026 #include <pthread.h>
00027 #include <sys/resource.h>
00028 #include <sys/file.h>
00029 #define PLF_MAX_FDSETS 64 // taken from Phil, project.def, LINUX
00030 #define PLF_ENDIANCHANGE
00031 #define PLF_USING_PTHREAD
00032 #define PLF_SYSTEM_SOLARIS
00033
00034 #define PLF_UNIX_TCPIPSTACK
00035 #define INADDR_NONE 0xffffffff // for solaris only
00036 #endif
00037
00038 #ifdef SYSTEM_LINUX
00039 #include <stdio.h>
00040 #include <stdlib.h>
00041 #include <errno.h>
00042 #include <string.h>
00043 #include <ctype.h>
00044 #include <termios.h>
00045
00046 #include <stdarg.h>
00047
00048 #include <sys/timeb.h>
00049 #include <sys/times.h>
00050 #include <sys/types.h>
00051 #include <unistd.h>
00052 #include <pthread.h>
00053 #include <sys/resource.h>
00054 #include <sys/ioctl.h>
00055 #define PLF_MAX_FDSETS 64 // taken from Phil, project.def, LINUX
00056 #define PLF_USING_PTHREAD
00057
00058 #undef PLF_ENDIANCHANGE
00059 #define PLF_SYSTEM_LINUX
00060
00061 #define PLF_UNIX_TCPIPSTACK
00062 #endif
00063
00064 #ifdef SYSTEM_WINDOWS
00065 #include <stdio.h>
00066 #include <windows.h>
00067 #include <conio.h>
00068 #include <time.h>
00069
00070 #define SO_SENDBUF_SIZE 40960
00071 #define SO_RECVBUF_SIZE 81920
00072
00073 #define PLF_SYSTEM_WINNT
00074 #define PLF_MAX_FDSETS FD_SETSIZE
00075 #undef PLF_ENDIANCHANGE
00076 #define PLF_WINNT_TCPIPSTACK
00077 #endif
00078
00079 #ifdef SYSTEM_NIOS2_LWIP
00080
00081 #include <unistd.h>
00082 #include <stdio.h>
00083 #include <stdlib.h>
00084 #include <errno.h>
00085 #include <string.h>
00086 #include <ctype.h>
00087
00088 #include <stdarg.h>
00089
00090 #include <sys/timeb.h>
00091 #include <sys/times.h>
00092 #include <sys/types.h>
00093 #include <sys/resource.h>
00094
00095
00096 #include <sys/ioctl.h>
00097 #include <time.h>
00098 #include <fcntl.h>
00099
00100 #ifdef __cplusplus
00101 extern "C" {
00102 #endif
00103
00104 #include "includes.h"
00105 #include "alt_lwip_dev.h"
00106 #include "lwip/sys.h"
00107 #include "lwip/sockets.h"
00108 #include "user.h"
00109
00110 #ifdef __cplusplus
00111 }
00112 #endif
00113
00114 #define PLF_SYSTEM_NIOS2
00115 #define PLF_MAX_FDSETS FD_SETSIZE
00116
00117 #define PLF_LWIP_TCPIPSTACK
00118 #define BINLOCK_SEM_TIMEOUT 100
00119 #undef PLF_ENDIANCHANGE
00120
00121
00122 #define TASK_STACK_SIZE_SW 32768
00123
00124 #define TASK_STACK_CHECKING_SW 0
00125
00126 #define SENDTASK_PRIO_SW 8
00127 #define RECVTASK_PRIO_SW 7
00128 #define ETHER_PRIO_SW 5
00129 #define TCPIP_PRIO_SW 6
00130
00131 #define MAIN_PRIO_SW 9
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 #endif
00142
00143 #ifdef SYSTEM_NIOS2_NICHE
00144
00145 #include <unistd.h>
00146 #include <stdio.h>
00147 #include <stdlib.h>
00148 #include <errno.h>
00149 #include <string.h>
00150 #include <ctype.h>
00151
00152 #include <sys/timeb.h>
00153 #include <sys/times.h>
00154 #include <sys/types.h>
00155 #include <sys/resource.h>
00156
00157
00158 #include <sys/ioctl.h>
00159 #include <time.h>
00160 #include <fcntl.h>
00161
00162 #ifdef __cplusplus
00163 extern "C" {
00164 #endif
00165
00166 #include "includes.h"
00167 #include <unistd.h>
00168 #include "system.h"
00169
00170
00171 #include "ipport.h"
00172 #include "libport.h"
00173 #include "osport.h"
00174 #include "tcpport.h"
00175 #include "bsdsock.h"
00176
00177 #ifdef __cplusplus
00178 }
00179 #endif
00180
00181
00182 #define PLF_SYSTEM_NIOS2
00183 #define PLF_MAX_FDSETS FD_SETSIZE
00184
00185 #define PLF_NICHE_TCPIPSTACK
00186 #define BINLOCK_SEM_TIMEOUT 100
00187 #undef PLF_ENDIANCHANGE
00188
00189
00190 #define TASK_STACK_SIZE_SW 32768
00191
00192 #define TASK_STACK_CHECKING_SW 0
00193
00194 #define INITIAL_TASK_PRIO 1 // niche SW! May 10, 2007
00195
00196
00197 #define SENDTASK_PRIO_SW 8
00198 #define RECVTASK_PRIO_SW 7
00199
00200
00201
00202 #define MAIN_PRIO_SW 9
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 #ifndef INADDR_NONE
00213 #define INADDR_NONE 0xffffffff // for solaris only
00214 #endif
00215 #ifndef AF_UNSPEC
00216 #define AF_UNSPEC 0
00217 #endif
00218
00219 #endif
00220
00221 #include "TypesSW.h"
00222
00223 #ifdef __NQ_INTERNAL_SW__
00224
00225 #ifndef PLF_SYSTEM_WINNT
00226 #ifdef _SW_RELEASE_
00227 #define NDEBUG
00228 #endif
00229 #endif
00230
00231
00232 #define __NEED_SOCKET_FUNCTIONS_SW__
00233 #define __NEED_SEMAPHORE_SW__
00234 #define __NEED_MUTEX_SW__
00235 #define __CREATE_TASK_THREAD__
00236
00237
00238 #ifdef __NEED_SOCKET_FUNCTIONS_SW__
00239 #ifdef PLF_UNIX_TCPIPSTACK
00240 #include <sys/socket.h>
00241 #include <sys/types.h>
00242 #include <arpa/inet.h>
00243 #include <netinet/in.h>
00244 #include <netdb.h>
00245 #include <fcntl.h>
00246 #endif
00247 #endif // #ifdef __NEED_SOCKET_FUNCTIONS_SW__
00248
00249
00250 #if defined(PLF_LWIP_TCPIPSTACK) || defined(PLF_UNIX_TCPIPSTACK)
00251
00252 extern const INT32 SOCKET_ERROR;
00253 extern const INT32 INVALID_SOCKET;
00254 #endif
00255
00256 #ifdef PLF_WINNT_TCPIPSTACK
00257 #define EADDRNOTAVAIL -3
00258 #define EAFNOSUPPORT -4
00259 #define EALREADY -5
00260 #define ECONNREFUSED -7
00261 #define EINPROGRESS -8
00262
00263 #define EISCONN -10
00264 #define ENETUNREACH -11
00265 #define ENOTSOCK -12
00266 #define EPROTOTYPE -13
00267 #define ETIMEDOUT -14
00268 #define EADDRINUSE -15
00269 #define ECONNRESET -16
00270 #define EHOSTUNREACH -17
00271 #define ENETDOWN -20
00272 #define EUNKNOWN -22
00273 #define EHOSTDOWN -23
00274
00275
00276 #ifndef EBADF
00277 #define EBADF -6
00278 #define EAGAIN -21
00279 #define EINVAL -18
00280 #define ENAMETOOLONG -19
00281 #define EINTR -9
00282 #endif
00283
00284 #endif
00285
00286 #ifdef __NEED_SOCKET_FUNCTIONS_SW__
00287
00288
00289
00290 extern void platformInitializeSocketSubsystem();
00291 extern void platformDeinitializeSocketSubsystem();
00292
00293 extern INT32 platformSocketGetLastError();
00294 extern socktype platformSocketCreateInet( INT32 type );
00295
00296
00297
00298
00299 extern INT32 platformSocketReceiveFromFunction( socktype s, UINT8 *buf, UINT32 buflen, UINT32 *ip_hostorder, UINT16 *port_hostorder);
00300 extern INT32 platformSocketSendToFunction( socktype s, const UINT8 *buf, UINT32 buflen, UINT32 ip_hostorder, UINT16 port_hostorder );
00301
00302 extern INT32 platformSocketClose( socktype s);
00303 extern INT32 platformSocketConnect(socktype s, const struct sockaddr * Saddr, size_t size_sockaddr);
00304 extern INT32 platformSocketBind( socktype s, const struct sockaddr * Saddr, size_t size_sockaddr);
00305 extern INT32 platformSocketSetNonblocking ( socktype s );
00306 extern UINT32 platformIPAddrConvert( const ONECHAR *ip_addr_dotted_string);
00307 extern ONECHAR *platformIPAddrConvert( const UINT32 ip_hostorder );
00308 extern INT32 platformSocketDisconnectUDP( socktype s);
00309 extern INT32 platformSocketSelect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
00310
00311 extern const INT32 platformMaxFdSets;
00312
00313 #endif // #ifdef __NEED_SOCKET_FUNCTIONS_SW__
00314
00315 extern HANDLE platformCreateSemaphore( UINT16 maximum_count );
00316 extern bool platformDeleteSemaphore( HANDLE semaph );
00317 extern bool platformWaitForSemaphore( HANDLE semaph, UINT32 timeout_msec );
00318 extern bool platformSignalSemaphore( HANDLE semaphore );
00319
00320 extern HANDLE platformCreateMutex();
00321 extern bool platformDeleteMutex( HANDLE mutex );
00322 extern bool platformWaitForMutex( HANDLE mutex, UINT32 timeout_msec );
00323 extern bool platformSignalMutex( HANDLE mutex );
00324 extern bool platformIsSemaphoreSignalled( HANDLE semaph );
00325
00326 #define SW_THREAD_PRIORITY_ABOVE_NORMAL 1
00327 #define SW_THREAD_PRIORITY_NORMAL 2
00328 #define SW_THREAD_PRIORITY_BELOW_NORMAL 3
00329
00330 extern HANDLE platformCreateThread( bool sendthread, VOIDP parameter, UINT32 thread_prio_sw);
00331 extern bool platformDeleteThread( HANDLE threadhandle );
00332
00333 #ifndef PLF_SYSTEM_WINNT
00334 extern int _strnicmp( const char *string1, const char *string2, size_t count);
00335 #endif // NO PLF_SYSTEM_WINNT
00336
00337 extern VOID platformSleepMilliseconds(UINT32 milliseconds);
00338 extern UINT32 platformGetTickCount();
00339
00340 extern UINT32 platformGetLastError();
00341 extern ONECHAR *platformGetOSErrorString( UINT32 intOSLastError, ONECHAR *lasterrorstr, UINT32 maxlength_lasterrorstr);
00342
00343 extern void platformInitializeConsoleInput();
00344 extern void platformDeinitializeConsoleInput();
00345 extern INT32 platformgetch();
00346 extern INT32 platformkbhit();
00347
00348 #ifdef PLF_ENDIANCHANGE
00349 extern void platform_put_double_at( UINT8 *bufpos, DOUBLE data );
00350 extern void platform_put_float_at( UINT8 *bufpos, FLOAT data );
00351 extern void platform_put_uint32_at( UINT8 *bufpos, UINT32 data );
00352 extern void platform_put_uint16_at( UINT8 *bufpos, UINT16 data );
00353 extern void platform_put_uint8_at( UINT8 *bufpos, UINT8 data );
00354 extern void platform_put_int32_at( UINT8 *bufpos, INT32 data );
00355 extern void platform_put_int16_at( UINT8 *bufpos, INT16 data );
00356 extern void platform_put_int8_at( UINT8 *bufpos, INT8 data );
00357 extern FLOAT platform_get_float_at( UINT8 *bufpos );
00358 extern DOUBLE platform_get_double_at( UINT8 *bufpos );
00359 extern UINT32 platform_get_uint32_at( UINT8 *bufpos );
00360 extern UINT16 platform_get_uint16_at( UINT8 *bufpos );
00361 extern UINT8 platform_get_uint8_at( UINT8 *bufpos );
00362 extern INT32 platform_get_int32_at( UINT8 *bufpos );
00363 extern INT16 platform_get_int16_at( UINT8 *bufpos );
00364 extern INT8 platform_get_int8_at( UINT8 *bufpos );
00365 #else
00366
00367
00368 #define platform_put_double_at(a,b) *((DOUBLE *) (a)) = (DOUBLE) (b)
00369
00370 #define platform_put_float_at(a,b) *((FLOAT *) (a)) = (FLOAT) (b)
00371
00372 #define platform_put_uint32_at(a,b) *((UINT32 *) (a)) = (UINT32) (b)
00373
00374 #define platform_put_uint16_at(a,b) *((UINT16 *) (a)) = (UINT16) (b)
00375
00376 #define platform_put_uint8_at(a,b) *((UINT8 *) (a)) = (UINT8) (b)
00377
00378 #define platform_put_int32_at(a,b) *((INT32 *) (a)) =(INT32) (b)
00379
00380 #define platform_put_int16_at(a,b) *((INT16 *) (a)) = (INT16) (b)
00381
00382 #define platform_put_int8_at(a,b) *((INT8 *) (a)) = (INT8) (b)
00383
00384
00385 #define platform_get_float_at(a) *((FLOAT *) (a))
00386
00387 #define platform_get_double_at(a) *((DOUBLE *) (a))
00388
00389 #define platform_get_uint32_at(a) *((UINT32 *) (a))
00390
00391 #define platform_get_uint16_at(a) *((UINT16 *) (a))
00392
00393 #define platform_get_uint8_at(a) *((UINT8 *) (a))
00394
00395 #define platform_get_int32_at(a) *((INT32 *) (a))
00396
00397 #define platform_get_int16_at(a) *((INT16 *) (a))
00398
00399 #define platform_get_int8_at(a) *((INT8 *) (a))
00400 #endif
00401
00402 #endif //__NQ_INTERNAL_SW__
00403
00404 #endif //__PLATFORM_H_INCLUDED_SW__