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 #ifdef __cplusplus 00164 extern "C" { 00165 #endif 00166 00167 #include <compiler.h> 00168 00169 00174 00175 #ifndef NUTMEM_ALIGNMENT 00176 #if defined(__avr__) 00177 #define NUTMEM_ALIGNMENT 1 00178 #elif defined(__ARM__) 00179 #define NUTMEM_ALIGNMENT 4 00180 #else 00181 #define NUTMEM_ALIGNMENT sizeof(int) 00182 #endif 00183 #endif 00184 00188 #define NUTMEM_BOTTOM_ALIGN(s) ((s) & ~(NUTMEM_ALIGNMENT - 1)) 00189 00193 #define NUTMEM_TOP_ALIGN(s) NUTMEM_BOTTOM_ALIGN((s + (NUTMEM_ALIGNMENT - 1))) 00194 00195 00196 #ifndef __NUT_EMULATION__ 00197 00203 typedef unsigned char u_char; 00204 00206 typedef unsigned short u_short; 00207 00209 /* Warning: size is highly architecture/compiler dependant! */ 00210 typedef unsigned int u_int; 00211 00213 typedef unsigned long u_long; 00214 00216 typedef unsigned long long u_longlong; 00217 00218 #endif /* unix emulation */ 00219 00221 typedef void *HANDLE; 00222 00233 #if defined(__AVR__) 00234 typedef unsigned char ureg_t; 00235 #elif defined(__arm__) 00236 typedef unsigned short ureg_t; 00237 #elif defined(__H8300__) || defined(__H8300H__) || defined(__H8300S__) 00238 typedef unsigned short ureg_t; 00239 #elif defined(__m68k__) 00240 typedef unsigned short ureg_t; 00241 #else 00242 typedef unsigned short ureg_t; 00243 #endif 00244 00250 #if defined(__AVR__) 00251 typedef unsigned char reg_t; 00252 #elif defined(__arm__) 00253 typedef unsigned short reg_t; 00254 #elif defined(__H8300__) || defined(__H8300H__) || defined(__H8300S__) 00255 typedef unsigned short reg_t; 00256 #elif defined(__m68k__) 00257 typedef unsigned short reg_t; 00258 #else 00259 typedef unsigned short reg_t; 00260 #endif 00261 00268 #if defined(__AVR__) 00269 typedef unsigned short uptr_t; 00270 #elif defined(__GNUC__) 00271 /* 00272 * For remaining MCUs GCC is assumed where __PTRDIFF_TYPE__ macro is defined 00273 */ 00274 typedef unsigned __PTRDIFF_TYPE__ uptr_t; 00275 #else 00276 typedef unsigned int uptr_t; 00277 #endif 00278 00279 #define __byte_swap2(val) \ 00280 ((((val) & 0xff) << 8) | \ 00281 (((val) & 0xff00) >> 8)) 00282 00283 #define __byte_swap4(val) \ 00284 ((((val) & 0xff) << 24) | \ 00285 (((val) & 0xff00) << 8) | \ 00286 (((val) & 0xff0000) >> 8) | \ 00287 (((val) & 0xff000000) >> 24)) 00288 00289 #if defined(__GNUC__) && defined(__AVR__) 00290 /* 00291 * Conversion of 16 bit value to network order. 00292 */ 00293 #undef __byte_swap2 00294 static inline uint16_t __byte_swap2(uint16_t val) { 00295 asm volatile ("mov __tmp_reg__, %A0\n\t" "mov %A0, %B0\n\t" "mov %B0, __tmp_reg__\n\t":"=r" (val) 00296 :"0"(val) 00297 ); 00298 return val; 00299 } 00300 /* 00301 * Conversion of 32 bit value to network order. 00302 */ 00303 #undef __byte_swap4 00304 static inline uint32_t __byte_swap4(uint32_t val) { 00305 asm volatile ("mov __tmp_reg__, %A0\n\t" 00306 "mov %A0, %D0\n\t" 00307 "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) 00308 :"0"(val) 00309 ); 00310 return val; 00311 } 00312 #endif /* #if defined(__GCC__) && defined(__AVR__) */ 00313 00314 00315 #ifndef __NUT_EMULATION__ 00316 00320 #ifndef __BIG_ENDIAN__ 00321 #define htons(x) __byte_swap2(x) 00322 #else 00323 #define htons(x) (x) 00324 #endif 00325 00329 #ifndef __BIG_ENDIAN__ 00330 #define htonl(x) __byte_swap4(x) 00331 #else 00332 #define htonl(x) (x) 00333 #endif 00334 00338 #ifndef __BIG_ENDIAN__ 00339 #define ntohs(x) __byte_swap2(x) 00340 #else 00341 #define ntohs(x) (x) 00342 #endif 00343 00347 #ifndef __BIG_ENDIAN__ 00348 #define ntohl(x) __byte_swap4(x) 00349 #else 00350 #define ntohl(x) (x) 00351 #endif 00352 00353 #endif /* network to host byte conversion */ 00354 00357 #ifdef __cplusplus 00358 } 00359 #endif 00360 00361 #endif /* #ifndef _SYS_VIRTUAL_TYPES_H_ */ 00362 00363 #endif /* #ifndef _SYS_TYPES_H_ */