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: types.h,v $ 00078 * Revision 1.13 2008/08/11 07:00:28 haraldkipp 00079 * BSD types replaced by stdint types (feature request #1282721). 00080 * 00081 * Revision 1.12 2006/10/08 16:48:22 haraldkipp 00082 * Documentation fixed 00083 * 00084 * Revision 1.11 2006/03/27 09:34:05 freckle 00085 * added u_longlong and longlong for emulation 00086 * 00087 * Revision 1.10 2006/03/02 20:04:11 haraldkipp 00088 * ICCARM doesn't know __PTRDIFF_TYPE__. 00089 * 00090 * Revision 1.9 2005/07/26 15:49:59 haraldkipp 00091 * Cygwin support added. 00092 * 00093 * Revision 1.8 2005/04/08 12:46:46 freckle 00094 * removed htons, htonl, ntohs, ntohs, ntohl, from unix emulation as 00095 * provided by system headers somewhere 00096 * 00097 * Revision 1.7 2005/02/10 07:06:48 hwmaier 00098 * Changes to incorporate support for AT90CAN128 CPU 00099 * 00100 * Revision 1.6 2004/06/08 15:04:24 freckle 00101 * changed #include "types_orig.h" to <sys/types_orig.h> 00102 * to allow this file to be in $MODDIR. Relevant only for *nix emulation 00103 * 00104 * Revision 1.5 2004/04/20 07:58:32 drsung 00105 * Use __GNUC__ instead of __GCC__ 00106 * 00107 * Revision 1.4 2004/04/07 12:13:57 haraldkipp 00108 * Matthias Ringwald's *nix emulation added 00109 * 00110 * Revision 1.3 2004/03/18 15:40:55 haraldkipp 00111 * ICCAVR failed to compile 00112 * 00113 * Revision 1.2 2004/03/16 16:48:44 haraldkipp 00114 * Added Jan Dubiec's H8/300 port. 00115 * 00116 * Revision 1.1.1.1 2003/05/09 14:41:23 haraldkipp 00117 * Initial using 3.2.1 00118 * 00119 * Revision 1.8 2003/02/04 18:00:54 harald 00120 * Version 3 released 00121 * 00122 * Revision 1.7 2002/08/08 17:25:12 harald 00123 * *** empty log message *** 00124 * 00125 * Revision 1.6 2002/06/26 17:29:30 harald 00126 * First pre-release with 2.4 stack 00127 * 00128 */ 00129 00130 #ifndef _SYS_TYPES_H_ 00131 00132 #ifndef _SYS_VIRTUAL_TYPES_H_ 00133 #define _SYS_VIRTUAL_TYPES_H_ 00134 00135 00136 #if defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__) 00137 // on an emulation platform, we need to have both 00138 // a) the native types headers and libs and 00139 #include <sys/types_orig.h> 00140 // b) the additional nut os header and implementation 00141 00143 typedef unsigned long long u_longlong; 00144 typedef long long longlong; 00145 00146 #endif 00147 00148 #ifndef _SYS_TYPES_H 00149 #define _SYS_TYPES_H_ 00150 #endif 00151 00157 #ifdef __cplusplus 00158 extern "C" { 00159 #endif 00160 00161 #include <compiler.h> 00162 00163 00168 00169 #if !defined(__linux__) && !defined(__APPLE__) && !defined(__CYGWIN__) 00170 00176 typedef unsigned char u_char; 00177 00179 typedef unsigned short u_short; 00180 00182 /* Warning: size is highly architecture/compiler dependant! */ 00183 typedef unsigned int u_int; 00184 00186 typedef unsigned long u_long; 00187 00189 typedef unsigned long long u_longlong; 00190 00191 #endif /* unix emulation */ 00192 00194 typedef void *HANDLE; 00195 00206 #if defined(__AVR__) 00207 typedef unsigned char ureg_t; 00208 #elif defined(__arm__) 00209 typedef unsigned short ureg_t; 00210 #elif defined(__H8300__) || defined(__H8300H__) || defined(__H8300S__) 00211 typedef unsigned short ureg_t; 00212 #elif defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__) 00213 typedef unsigned short ureg_t; 00214 #elif defined(__m68k__) 00215 typedef unsigned short ureg_t; 00216 #endif 00217 00223 #if defined(__AVR__) 00224 typedef unsigned char reg_t; 00225 #elif defined(__arm__) 00226 typedef unsigned short reg_t; 00227 #elif defined(__H8300__) || defined(__H8300H__) || defined(__H8300S__) 00228 typedef unsigned short reg_t; 00229 #elif defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__) 00230 typedef unsigned short reg_t; 00231 #elif defined(__m68k__) 00232 typedef unsigned short reg_t; 00233 #endif 00234 00241 #if defined(__AVR__) 00242 typedef unsigned short uptr_t; 00243 #elif defined(__GNUC__) 00244 /* 00245 * For remaining MCUs GCC is assumed where __PTRDIFF_TYPE__ macro is defined 00246 */ 00247 typedef unsigned __PTRDIFF_TYPE__ uptr_t; 00248 #else 00249 typedef unsigned int uptr_t; 00250 #endif 00251 00252 #define __byte_swap2(val) \ 00253 ((((val) & 0xff) << 8) | \ 00254 (((val) & 0xff00) >> 8)) 00255 00256 #define __byte_swap4(val) \ 00257 ((((val) & 0xff) << 24) | \ 00258 (((val) & 0xff00) << 8) | \ 00259 (((val) & 0xff0000) >> 8) | \ 00260 (((val) & 0xff000000) >> 24)) 00261 00262 #if defined(__GNUC__) && defined(__AVR__) 00263 /* 00264 * Conversion of 16 bit value to network order. 00265 */ 00266 #undef __byte_swap2 00267 static inline uint16_t __byte_swap2(uint16_t val) { 00268 asm volatile ("mov __tmp_reg__, %A0\n\t" "mov %A0, %B0\n\t" "mov %B0, __tmp_reg__\n\t":"=r" (val) 00269 :"0"(val) 00270 ); 00271 return val; 00272 } 00273 /* 00274 * Conversion of 32 bit value to network order. 00275 */ 00276 #undef __byte_swap4 00277 static inline uint32_t __byte_swap4(uint32_t val) { 00278 asm volatile ("mov __tmp_reg__, %A0\n\t" 00279 "mov %A0, %D0\n\t" 00280 "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) 00281 :"0"(val) 00282 ); 00283 return val; 00284 } 00285 #endif /* #if defined(__GCC__) && defined(__AVR__) */ 00286 00287 00288 #if !defined(__linux__) && !defined(__APPLE__) && !defined(__CYGWIN__) /* provided by system libraries */ 00289 00293 #ifndef __BIG_ENDIAN__ 00294 #define htons(x) __byte_swap2(x) 00295 #else 00296 #define htons(x) (x) 00297 #endif 00298 00302 #ifndef __BIG_ENDIAN__ 00303 #define htonl(x) __byte_swap4(x) 00304 #else 00305 #define htonl(x) (x) 00306 #endif 00307 00311 #ifndef __BIG_ENDIAN__ 00312 #define ntohs(x) __byte_swap2(x) 00313 #else 00314 #define ntohs(x) (x) 00315 #endif 00316 00320 #ifndef __BIG_ENDIAN__ 00321 #define ntohl(x) __byte_swap4(x) 00322 #else 00323 #define ntohl(x) (x) 00324 #endif 00325 00326 #endif /* network to host byte conversion */ 00327 00330 #ifdef __cplusplus 00331 } 00332 #endif 00333 00334 #endif /* #ifndef _SYS_VIRTUAL_TYPES_H_ */ 00335 00336 #endif /* #ifndef _SYS_TYPES_H_ */