00001 /* 00002 * Copyright (C) 2001-2005 by egnite Software GmbH. All rights reserved. 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions 00006 * are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the copyright holders nor the names of 00014 * contributors may be used to endorse or promote products derived 00015 * from this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS 00018 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00019 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00020 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE 00021 * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00022 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00023 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 00024 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 00025 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00026 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 00027 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00028 * SUCH DAMAGE. 00029 * 00030 * For additional information see http://www.ethernut.de/ 00031 * 00032 * - 00033 * Portions Copyright (C) 2000 David J. Hudson <dave@humbug.demon.co.uk> 00034 * 00035 * This file is distributed in the hope that it will be useful, but WITHOUT 00036 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00037 * FITNESS FOR A PARTICULAR PURPOSE. 00038 * 00039 * You can redistribute this file and/or modify it under the terms of the GNU 00040 * General Public License (GPL) as published by the Free Software Foundation; 00041 * either version 2 of the License, or (at your discretion) any later version. 00042 * See the accompanying file "copying-gpl.txt" for more details. 00043 * 00044 * As a special exception to the GPL, permission is granted for additional 00045 * uses of the text contained in this file. See the accompanying file 00046 * "copying-liquorice.txt" for details. 00047 * - 00048 * Portions Copyright (c) 1983, 1993 by 00049 * The Regents of the University of California. All rights reserved. 00050 * 00051 * Redistribution and use in source and binary forms, with or without 00052 * modification, are permitted provided that the following conditions 00053 * are met: 00054 * 1. Redistributions of source code must retain the above copyright 00055 * notice, this list of conditions and the following disclaimer. 00056 * 2. Redistributions in binary form must reproduce the above copyright 00057 * notice, this list of conditions and the following disclaimer in the 00058 * documentation and/or other materials provided with the distribution. 00059 * 3. Neither the name of the University nor the names of its contributors 00060 * may be used to endorse or promote products derived from this software 00061 * without specific prior written permission. 00062 * 00063 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00064 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00065 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00066 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00067 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00068 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00069 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00070 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00071 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00072 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00073 * SUCH DAMAGE. 00074 */ 00075 00076 /* 00077 * $Log$ 00078 * Revision 1.15 2009/03/05 22:16:57 freckle 00079 * use __NUT_EMULATION instead of __APPLE__, __linux__, or __CYGWIN__ 00080 * 00081 * Revision 1.14 2009/02/13 14:47:12 haraldkipp 00082 * memory alignment macros added. 00083 * 00084 * Revision 1.13 2008/08/11 07:00:28 haraldkipp 00085 * BSD types replaced by stdint types (feature request #1282721). 00086 * 00087 * Revision 1.12 2006/10/08 16:48:22 haraldkipp 00088 * Documentation fixed 00089 * 00090 * Revision 1.11 2006/03/27 09:34:05 freckle 00091 * added u_longlong and longlong for emulation 00092 * 00093 * Revision 1.10 2006/03/02 20:04:11 haraldkipp 00094 * ICCARM doesn't know __PTRDIFF_TYPE__. 00095 * 00096 * Revision 1.9 2005/07/26 15:49:59 haraldkipp 00097 * Cygwin support added. 00098 * 00099 * Revision 1.8 2005/04/08 12:46:46 freckle 00100 * removed htons, htonl, ntohs, ntohs, ntohl, from unix emulation as 00101 * provided by system headers somewhere 00102 * 00103 * Revision 1.7 2005/02/10 07:06:48 hwmaier 00104 * Changes to incorporate support for AT90CAN128 CPU 00105 * 00106 * Revision 1.6 2004/06/08 15:04:24 freckle 00107 * changed #include "types_orig.h" to <sys/types_orig.h> 00108 * to allow this file to be in $MODDIR. Relevant only for *nix emulation 00109 * 00110 * Revision 1.5 2004/04/20 07:58:32 drsung 00111 * Use __GNUC__ instead of __GCC__ 00112 * 00113 * Revision 1.4 2004/04/07 12:13:57 haraldkipp 00114 * Matthias Ringwald's *nix emulation added 00115 * 00116 * Revision 1.3 2004/03/18 15:40:55 haraldkipp 00117 * ICCAVR failed to compile 00118 * 00119 * Revision 1.2 2004/03/16 16:48:44 haraldkipp 00120 * Added Jan Dubiec's H8/300 port. 00121 * 00122 * Revision 1.1.1.1 2003/05/09 14:41:23 haraldkipp 00123 * Initial using 3.2.1 00124 * 00125 * Revision 1.8 2003/02/04 18:00:54 harald 00126 * Version 3 released 00127 * 00128 * Revision 1.7 2002/08/08 17:25:12 harald 00129 * *** empty log message *** 00130 * 00131 * Revision 1.6 2002/06/26 17:29:30 harald 00132 * First pre-release with 2.4 stack 00133 * 00134 */ 00135 00136 #ifndef _SYS_TYPES_H_ 00137 00138 #ifndef _SYS_VIRTUAL_TYPES_H_ 00139 #define _SYS_VIRTUAL_TYPES_H_ 00140 00141 00142 #ifdef __NUT_EMULATION__ 00143 // on an emulation platform, we need to have both 00144 // a) the native types headers and libs and 00145 #include <sys/types_orig.h> 00146 // b) the additional nut os header and implementation 00147 00149 typedef unsigned long long u_longlong; 00150 typedef long long longlong; 00151 00152 #endif 00153 00154 #ifndef _SYS_TYPES_H 00155 #define _SYS_TYPES_H_ 00156 #endif 00157 00163 #include <compiler.h> 00164 00165 __BEGIN_DECLS 00166 00167 // Definition of size_t 00168 #ifdef __cplusplus 00169 #include <cstddef> 00170 #else 00171 #include <stddef.h> 00172 #endif 00173 00178 00179 #ifndef NUTMEM_ALIGNMENT 00180 #if defined(__avr__) 00181 #define NUTMEM_ALIGNMENT 1 00182 #elif defined(__ARM__) 00183 #define NUTMEM_ALIGNMENT 4 00184 #elif defined(__AVR32__) 00185 #define NUTMEM_ALIGNMENT 4 00186 #else 00187 #define NUTMEM_ALIGNMENT sizeof(int) 00188 #endif 00189 #endif 00190 00194 #define NUTMEM_BOTTOM_ALIGN(s) ((s) & ~(NUTMEM_ALIGNMENT - 1)) 00195 00199 #define NUTMEM_TOP_ALIGN(s) NUTMEM_BOTTOM_ALIGN((s + (NUTMEM_ALIGNMENT - 1))) 00200 00201 00202 #ifndef __NUT_EMULATION__ 00203 00209 typedef unsigned char u_char; 00210 00212 typedef unsigned short u_short; 00213 00215 /* Warning: size is highly architecture/compiler dependant! */ 00216 typedef unsigned int u_int; 00217 00219 typedef unsigned long u_long; 00220 00222 typedef unsigned long long u_longlong; 00223 00224 #endif /* unix emulation */ 00225 00227 typedef void *HANDLE; 00228 00239 #if defined(__AVR__) 00240 typedef unsigned char ureg_t; 00241 #elif defined(__arm__) 00242 typedef unsigned short ureg_t; 00243 #elif defined(__AVR32__) 00244 typedef unsigned long ureg_t; 00245 #elif defined(__H8300__) || defined(__H8300H__) || defined(__H8300S__) 00246 typedef unsigned short ureg_t; 00247 #elif defined(__m68k__) 00248 typedef unsigned short ureg_t; 00249 #else 00250 typedef unsigned short ureg_t; 00251 #endif 00252 00258 #if defined(__AVR__) 00259 typedef unsigned char reg_t; 00260 #elif defined(__arm__) 00261 typedef unsigned short reg_t; 00262 #elif defined(__AVR32__) 00263 typedef unsigned short reg_t; 00264 #elif defined(__H8300__) || defined(__H8300H__) || defined(__H8300S__) 00265 typedef unsigned short reg_t; 00266 #elif defined(__m68k__) 00267 typedef unsigned short reg_t; 00268 #else 00269 typedef unsigned short reg_t; 00270 #endif 00271 00278 #if defined(__AVR__) 00279 typedef unsigned short uptr_t; 00280 #elif defined(__GNUC__) 00281 /* 00282 * For remaining MCUs GCC is assumed where __PTRDIFF_TYPE__ macro is defined 00283 */ 00284 typedef unsigned __PTRDIFF_TYPE__ uptr_t; 00285 #else 00286 typedef unsigned int uptr_t; 00287 #endif 00288 00289 #define __byte_swap2(val) \ 00290 ((((val) & 0xff) << 8) | \ 00291 (((val) & 0xff00) >> 8)) 00292 00293 #define __byte_swap4(val) \ 00294 ((((val) & 0xff) << 24) | \ 00295 (((val) & 0xff00) << 8) | \ 00296 (((val) & 0xff0000) >> 8) | \ 00297 (((val) & 0xff000000) >> 24)) 00298 00299 #if defined(__GNUC__) && defined(__AVR__) 00300 /* 00301 * Conversion of 16 bit value to network order. 00302 */ 00303 #undef __byte_swap2 00304 static inline uint16_t __byte_swap2(uint16_t val) { 00305 asm volatile ("mov __tmp_reg__, %A0\n\t" "mov %A0, %B0\n\t" "mov %B0, __tmp_reg__\n\t":"=r" (val) 00306 :"0"(val) 00307 ); 00308 return val; 00309 } 00310 /* 00311 * Conversion of 32 bit value to network order. 00312 */ 00313 #undef __byte_swap4 00314 static inline uint32_t __byte_swap4(uint32_t val) { 00315 asm volatile ("mov __tmp_reg__, %A0\n\t" 00316 "mov %A0, %D0\n\t" 00317 "mov %D0, __tmp_reg__\n\t" "mov __tmp_reg__, %B0\n\t" "mov %B0, %C0\n\t" "mov %C0, __tmp_reg__\n\t":"=r" (val) 00318 :"0"(val) 00319 ); 00320 return val; 00321 } 00322 #endif /* #if defined(__GCC__) && defined(__AVR__) */ 00323 00324 00325 #ifndef __NUT_EMULATION__ 00326 00330 #ifndef __BIG_ENDIAN__ 00331 #define htons(x) __byte_swap2(x) 00332 #else 00333 #define htons(x) (x) 00334 #endif 00335 00339 #ifndef __BIG_ENDIAN__ 00340 #define htonl(x) __byte_swap4(x) 00341 #else 00342 #define htonl(x) (x) 00343 #endif 00344 00348 #ifndef __BIG_ENDIAN__ 00349 #define ntohs(x) __byte_swap2(x) 00350 #else 00351 #define ntohs(x) (x) 00352 #endif 00353 00357 #ifndef __BIG_ENDIAN__ 00358 #define ntohl(x) __byte_swap4(x) 00359 #else 00360 #define ntohl(x) (x) 00361 #endif 00362 00363 #endif /* network to host byte conversion */ 00364 00367 __END_DECLS 00368 /* */ 00369 #endif /* #ifndef _SYS_VIRTUAL_TYPES_H_ */ 00370 00371 #endif /* #ifndef _SYS_TYPES_H_ */