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.14 2009/02/13 14:47:12 haraldkipp 00079 * memory alignment macros added. 00080 * 00081 * Revision 1.13 2008/08/11 07:00:28 haraldkipp 00082 * BSD types replaced by stdint types (feature request #1282721). 00083 * 00084 * Revision 1.12 2006/10/08 16:48:22 haraldkipp 00085 * Documentation fixed 00086 * 00087 * Revision 1.11 2006/03/27 09:34:05 freckle 00088 * added u_longlong and longlong for emulation 00089 * 00090 * Revision 1.10 2006/03/02 20:04:11 haraldkipp 00091 * ICCARM doesn't know __PTRDIFF_TYPE__. 00092 * 00093 * Revision 1.9 2005/07/26 15:49:59 haraldkipp 00094 * Cygwin support added. 00095 * 00096 * Revision 1.8 2005/04/08 12:46:46 freckle 00097 * removed htons, htonl, ntohs, ntohs, ntohl, from unix emulation as 00098 * provided by system headers somewhere 00099 * 00100 * Revision 1.7 2005/02/10 07:06:48 hwmaier 00101 * Changes to incorporate support for AT90CAN128 CPU 00102 * 00103 * Revision 1.6 2004/06/08 15:04:24 freckle 00104 * changed #include "types_orig.h" to <sys/types_orig.h> 00105 * to allow this file to be in $MODDIR. Relevant only for *nix emulation 00106 * 00107 * Revision 1.5 2004/04/20 07:58:32 drsung 00108 * Use __GNUC__ instead of __GCC__ 00109 * 00110 * Revision 1.4 2004/04/07 12:13:57 haraldkipp 00111 * Matthias Ringwald's *nix emulation added 00112 * 00113 * Revision 1.3 2004/03/18 15:40:55 haraldkipp 00114 * ICCAVR failed to compile 00115 * 00116 * Revision 1.2 2004/03/16 16:48:44 haraldkipp 00117 * Added Jan Dubiec's H8/300 port. 00118 * 00119 * Revision 1.1.1.1 2003/05/09 14:41:23 haraldkipp 00120 * Initial using 3.2.1 00121 * 00122 * Revision 1.8 2003/02/04 18:00:54 harald 00123 * Version 3 released 00124 * 00125 * Revision 1.7 2002/08/08 17:25:12 harald 00126 * *** empty log message *** 00127 * 00128 * Revision 1.6 2002/06/26 17:29:30 harald 00129 * First pre-release with 2.4 stack 00130 * 00131 */ 00132 00133 #ifndef _SYS_TYPES_H_ 00134 00135 #ifndef _SYS_VIRTUAL_TYPES_H_ 00136 #define _SYS_VIRTUAL_TYPES_H_ 00137 00138 00139 #if defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__) 00140 // on an emulation platform, we need to have both 00141 // a) the native types headers and libs and 00142 #include <sys/types_orig.h> 00143 // b) the additional nut os header and implementation 00144 00146 typedef unsigned long long u_longlong; 00147 typedef long long longlong; 00148 00149 #endif 00150 00151 #ifndef _SYS_TYPES_H 00152 #define _SYS_TYPES_H_ 00153 #endif 00154 00160 #ifdef __cplusplus 00161 extern "C" { 00162 #endif 00163 00164 #include <compiler.h> 00165 00166 00171 00172 #ifndef NUTMEM_ALIGNMENT 00173 #if defined(__avr__) 00174 #define NUTMEM_ALIGNMENT 1 00175 #elif defined(__ARM__) 00176 #define NUTMEM_ALIGNMENT 4 00177 #else 00178 #define NUTMEM_ALIGNMENT sizeof(int) 00179 #endif 00180 #endif 00181 00185 #define NUTMEM_BOTTOM_ALIGN(s) ((s) & ~(NUTMEM_ALIGNMENT - 1)) 00186 00190 #define NUTMEM_TOP_ALIGN(s) NUTMEM_BOTTOM_ALIGN((s + (NUTMEM_ALIGNMENT - 1))) 00191 00192 00193 #if !defined(__linux__) && !defined(__APPLE__) && !defined(__CYGWIN__) 00194 00200 typedef unsigned char u_char; 00201 00203 typedef unsigned short u_short; 00204 00206 /* Warning: size is highly architecture/compiler dependant! */ 00207 typedef unsigned int u_int; 00208 00210 typedef unsigned long u_long; 00211 00213 typedef unsigned long long u_longlong; 00214 00215 #endif /* unix emulation */ 00216 00218 typedef void *HANDLE; 00219 00230 #if defined(__AVR__) 00231 typedef unsigned char ureg_t; 00232 #elif defined(__arm__) 00233 typedef unsigned short ureg_t; 00234 #elif defined(__H8300__) || defined(__H8300H__) || defined(__H8300S__) 00235 typedef unsigned short ureg_t; 00236 #elif defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__) 00237 typedef unsigned short ureg_t; 00238 #elif defined(__m68k__) 00239 typedef unsigned short ureg_t; 00240 #endif 00241 00247 #if defined(__AVR__) 00248 typedef unsigned char reg_t; 00249 #elif defined(__arm__) 00250 typedef unsigned short reg_t; 00251 #elif defined(__H8300__) || defined(__H8300H__) || defined(__H8300S__) 00252 typedef unsigned short reg_t; 00253 #elif defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__) 00254 typedef unsigned short reg_t; 00255 #elif defined(__m68k__) 00256 typedef unsigned short reg_t; 00257 #endif 00258 00265 #if defined(__AVR__) 00266 typedef unsigned short uptr_t; 00267 #elif defined(__GNUC__) 00268 /* 00269 * For remaining MCUs GCC is assumed where __PTRDIFF_TYPE__ macro is defined 00270 */ 00271 typedef unsigned __PTRDIFF_TYPE__ uptr_t; 00272 #else 00273 typedef unsigned int uptr_t; 00274 #endif 00275 00276 #define __byte_swap2(val) \ 00277 ((((val) & 0xff) << 8) | \ 00278 (((val) & 0xff00) >> 8)) 00279 00280 #define __byte_swap4(val) \ 00281 ((((val) & 0xff) << 24) | \ 00282 (((val) & 0xff00) << 8) | \ 00283 (((val) & 0xff0000) >> 8) | \ 00284 (((val) & 0xff000000) >> 24)) 00285 00286 #if defined(__GNUC__) && defined(__AVR__) 00287 /* 00288 * Conversion of 16 bit value to network order. 00289 */ 00290 #undef __byte_swap2 00291 static inline uint16_t __byte_swap2(uint16_t val) { 00292 asm volatile ("mov __tmp_reg__, %A0\n\t" "mov %A0, %B0\n\t" "mov %B0, __tmp_reg__\n\t":"=r" (val) 00293 :"0"(val) 00294 ); 00295 return val; 00296 } 00297 /* 00298 * Conversion of 32 bit value to network order. 00299 */ 00300 #undef __byte_swap4 00301 static inline uint32_t __byte_swap4(uint32_t val) { 00302 asm volatile ("mov __tmp_reg__, %A0\n\t" 00303 "mov %A0, %D0\n\t" 00304 "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) 00305 :"0"(val) 00306 ); 00307 return val; 00308 } 00309 #endif /* #if defined(__GCC__) && defined(__AVR__) */ 00310 00311 00312 #if !defined(__linux__) && !defined(__APPLE__) && !defined(__CYGWIN__) /* provided by system libraries */ 00313 00317 #ifndef __BIG_ENDIAN__ 00318 #define htons(x) __byte_swap2(x) 00319 #else 00320 #define htons(x) (x) 00321 #endif 00322 00326 #ifndef __BIG_ENDIAN__ 00327 #define htonl(x) __byte_swap4(x) 00328 #else 00329 #define htonl(x) (x) 00330 #endif 00331 00335 #ifndef __BIG_ENDIAN__ 00336 #define ntohs(x) __byte_swap2(x) 00337 #else 00338 #define ntohs(x) (x) 00339 #endif 00340 00344 #ifndef __BIG_ENDIAN__ 00345 #define ntohl(x) __byte_swap4(x) 00346 #else 00347 #define ntohl(x) (x) 00348 #endif 00349 00350 #endif /* network to host byte conversion */ 00351 00354 #ifdef __cplusplus 00355 } 00356 #endif 00357 00358 #endif /* #ifndef _SYS_VIRTUAL_TYPES_H_ */ 00359 00360 #endif /* #ifndef _SYS_TYPES_H_ */