types.h

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

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/