Simon Cooksey / mbed-os
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arch.h Source File

arch.h

Go to the documentation of this file.
00001 /**
00002  * @file
00003  * Support for different processor and compiler architectures
00004  */
00005 
00006 /*
00007  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
00008  * All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without modification,
00011  * are permitted provided that the following conditions are met:
00012  *
00013  * 1. Redistributions of source code must retain the above copyright notice,
00014  *    this list of conditions and the following disclaimer.
00015  * 2. Redistributions in binary form must reproduce the above copyright notice,
00016  *    this list of conditions and the following disclaimer in the documentation
00017  *    and/or other materials provided with the distribution.
00018  * 3. The name of the author may not be used to endorse or promote products
00019  *    derived from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00022  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00023  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00024  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00025  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00026  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00028  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00029  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00030  * OF SUCH DAMAGE.
00031  *
00032  * This file is part of the lwIP TCP/IP stack.
00033  *
00034  * Author: Adam Dunkels <adam@sics.se>
00035  *
00036  */
00037 #ifndef LWIP_HDR_ARCH_H
00038 #define LWIP_HDR_ARCH_H
00039 
00040 #ifndef LITTLE_ENDIAN
00041 #define LITTLE_ENDIAN 1234
00042 #endif
00043 
00044 #ifndef BIG_ENDIAN
00045 #define BIG_ENDIAN 4321
00046 #endif
00047 
00048 #include "arch/cc.h"
00049 
00050 /** Define this to 1 in arch/cc.h of your port if your compiler does not provide
00051  * the stdint.h header. This cannot be \#defined in lwipopts.h since 
00052  * this is not an option of lwIP itself, but an option of the lwIP port
00053  * to your system.
00054  * Additionally, this header is meant to be \#included in lwipopts.h
00055  * (you may need to declare function prototypes in there).
00056  */
00057 #ifndef LWIP_NO_STDINT_H
00058 #define LWIP_NO_STDINT_H 0
00059 #endif
00060 
00061 /* Define generic types used in lwIP */
00062 #if !LWIP_NO_STDINT_H
00063 #include <stdint.h>
00064 typedef uint8_t   u8_t;
00065 typedef int8_t    s8_t;
00066 typedef uint16_t  u16_t;
00067 typedef int16_t   s16_t;
00068 typedef uint32_t  u32_t;
00069 typedef int32_t   s32_t;
00070 typedef uintptr_t mem_ptr_t;
00071 #endif
00072 
00073 /** Define this to 1 in arch/cc.h of your port if your compiler does not provide
00074  * the inttypes.h header. This cannot be \#defined in lwipopts.h since 
00075  * this is not an option of lwIP itself, but an option of the lwIP port
00076  * to your system.
00077  * Additionally, this header is meant to be \#included in lwipopts.h
00078  * (you may need to declare function prototypes in there).
00079  */
00080 #ifndef LWIP_NO_INTTYPES_H
00081 #define LWIP_NO_INTTYPES_H 0
00082 #endif
00083 
00084 /* Define (sn)printf formatters for these lwIP types */
00085 #if !LWIP_NO_INTTYPES_H
00086 #include <inttypes.h>
00087 #ifndef X8_F
00088 #define X8_F  "02"PRIx8
00089 #endif
00090 #ifndef U16_F
00091 #define U16_F PRIu16
00092 #endif
00093 #ifndef S16_F
00094 #define S16_F PRId16
00095 #endif
00096 #ifndef X16_F
00097 #define X16_F PRIx16
00098 #endif
00099 #ifndef U32_F
00100 #define U32_F PRIu32
00101 #endif
00102 #ifndef S32_F
00103 #define S32_F PRId32
00104 #endif
00105 #ifndef X32_F
00106 #define X32_F PRIx32
00107 #endif
00108 #ifndef SZT_F
00109 #define SZT_F PRIuPTR
00110 #endif
00111 #endif
00112 
00113 /** Allocates a memory buffer of specified size that is of sufficient size to align
00114  * its start address using LWIP_MEM_ALIGN.
00115  * You can declare your own version here e.g. to enforce alignment without adding
00116  * trailing padding bytes (see LWIP_MEM_ALIGN_BUFFER) or your own section placement
00117  * requirements.
00118  * e.g. if you use gcc and need 32 bit alignment:
00119  * \#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[size] __attribute__((aligned(4)))
00120  * or more portable:
00121  * \#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u32_t variable_name[(size + sizeof(u32_t) - 1) / sizeof(u32_t)]
00122  */
00123 #ifndef LWIP_DECLARE_MEMORY_ALIGNED
00124 #define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[LWIP_MEM_ALIGN_BUFFER(size)]
00125 #endif
00126 
00127 /** Calculate memory size for an aligned buffer - returns the next highest
00128  * multiple of MEM_ALIGNMENT (e.g. LWIP_MEM_ALIGN_SIZE(3) and
00129  * LWIP_MEM_ALIGN_SIZE(4) will both yield 4 for MEM_ALIGNMENT == 4).
00130  */
00131 #ifndef LWIP_MEM_ALIGN_SIZE
00132 #define LWIP_MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1U) & ~(MEM_ALIGNMENT-1U))
00133 #endif
00134 
00135 /** Calculate safe memory size for an aligned buffer when using an unaligned
00136  * type as storage. This includes a safety-margin on (MEM_ALIGNMENT - 1) at the
00137  * start (e.g. if buffer is u8_t[] and actual data will be u32_t*)
00138  */
00139 #ifndef LWIP_MEM_ALIGN_BUFFER
00140 #define LWIP_MEM_ALIGN_BUFFER(size) (((size) + MEM_ALIGNMENT - 1U))
00141 #endif
00142 
00143 /** Align a memory pointer to the alignment defined by MEM_ALIGNMENT
00144  * so that ADDR % MEM_ALIGNMENT == 0
00145  */
00146 #ifndef LWIP_MEM_ALIGN
00147 #define LWIP_MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1)))
00148 #endif
00149 
00150 #ifdef __cplusplus
00151 extern "C" {
00152 #endif
00153 
00154 #ifndef PACK_STRUCT_BEGIN
00155 #define PACK_STRUCT_BEGIN
00156 #endif /* PACK_STRUCT_BEGIN */
00157 
00158 #ifndef PACK_STRUCT_END
00159 #define PACK_STRUCT_END
00160 #endif /* PACK_STRUCT_END */
00161 
00162 #ifndef PACK_STRUCT_STRUCT
00163 #define PACK_STRUCT_STRUCT
00164 #endif /* PACK_STRUCT_STRUCT */
00165 
00166 #ifndef PACK_STRUCT_FIELD
00167 #define PACK_STRUCT_FIELD(x) x
00168 #endif /* PACK_STRUCT_FIELD */
00169 
00170 /* Used for struct fields of u8_t,
00171  * where some compilers warn that packing is not necessary */
00172 #ifndef PACK_STRUCT_FLD_8
00173 #define PACK_STRUCT_FLD_8(x) PACK_STRUCT_FIELD(x)
00174 #endif /* PACK_STRUCT_FLD_8 */
00175 
00176 /* Used for struct fields of that are packed structs themself,
00177  * where some compilers warn that packing is not necessary */
00178 #ifndef PACK_STRUCT_FLD_S
00179 #define PACK_STRUCT_FLD_S(x) PACK_STRUCT_FIELD(x)
00180 #endif /* PACK_STRUCT_FLD_S */
00181 
00182 
00183 #ifndef LWIP_UNUSED_ARG
00184 #define LWIP_UNUSED_ARG(x) (void)x
00185 #endif /* LWIP_UNUSED_ARG */
00186 
00187 
00188 #ifdef LWIP_PROVIDE_ERRNO
00189 
00190 #define  EPERM         1  /* Operation not permitted */
00191 #define  ENOENT        2  /* No such file or directory */
00192 #define  ESRCH         3  /* No such process */
00193 #define  EINTR         4  /* Interrupted system call */
00194 #define  EIO           5  /* I/O error */
00195 #define  ENXIO         6  /* No such device or address */
00196 #define  E2BIG         7  /* Arg list too long */
00197 #define  ENOEXEC       8  /* Exec format error */
00198 #define  EBADF         9  /* Bad file number */
00199 #define  ECHILD       10  /* No child processes */
00200 #define  EAGAIN       11  /* Try again */
00201 #define  ENOMEM       12  /* Out of memory */
00202 #define  EACCES       13  /* Permission denied */
00203 #define  EFAULT       14  /* Bad address */
00204 #define  ENOTBLK      15  /* Block device required */
00205 #define  EBUSY        16  /* Device or resource busy */
00206 #define  EEXIST       17  /* File exists */
00207 #define  EXDEV        18  /* Cross-device link */
00208 #define  ENODEV       19  /* No such device */
00209 #define  ENOTDIR      20  /* Not a directory */
00210 #define  EISDIR       21  /* Is a directory */
00211 #define  EINVAL       22  /* Invalid argument */
00212 #define  ENFILE       23  /* File table overflow */
00213 #define  EMFILE       24  /* Too many open files */
00214 #define  ENOTTY       25  /* Not a typewriter */
00215 #define  ETXTBSY      26  /* Text file busy */
00216 #define  EFBIG        27  /* File too large */
00217 #define  ENOSPC       28  /* No space left on device */
00218 #define  ESPIPE       29  /* Illegal seek */
00219 #define  EROFS        30  /* Read-only file system */
00220 #define  EMLINK       31  /* Too many links */
00221 #define  EPIPE        32  /* Broken pipe */
00222 #define  EDOM         33  /* Math argument out of domain of func */
00223 #define  ERANGE       34  /* Math result not representable */
00224 #define  EDEADLK      35  /* Resource deadlock would occur */
00225 #define  ENAMETOOLONG 36  /* File name too long */
00226 #define  ENOLCK       37  /* No record locks available */
00227 #define  ENOSYS       38  /* Function not implemented */
00228 #define  ENOTEMPTY    39  /* Directory not empty */
00229 #define  ELOOP        40  /* Too many symbolic links encountered */
00230 #define  EWOULDBLOCK  EAGAIN  /* Operation would block */
00231 #define  ENOMSG       42  /* No message of desired type */
00232 #define  EIDRM        43  /* Identifier removed */
00233 #define  ECHRNG       44  /* Channel number out of range */
00234 #define  EL2NSYNC     45  /* Level 2 not synchronized */
00235 #define  EL3HLT       46  /* Level 3 halted */
00236 #define  EL3RST       47  /* Level 3 reset */
00237 #define  ELNRNG       48  /* Link number out of range */
00238 #define  EUNATCH      49  /* Protocol driver not attached */
00239 #define  ENOCSI       50  /* No CSI structure available */
00240 #define  EL2HLT       51  /* Level 2 halted */
00241 #define  EBADE        52  /* Invalid exchange */
00242 #define  EBADR        53  /* Invalid request descriptor */
00243 #define  EXFULL       54  /* Exchange full */
00244 #define  ENOANO       55  /* No anode */
00245 #define  EBADRQC      56  /* Invalid request code */
00246 #define  EBADSLT      57  /* Invalid slot */
00247 
00248 #define  EDEADLOCK    EDEADLK
00249 
00250 #define  EBFONT       59  /* Bad font file format */
00251 #define  ENOSTR       60  /* Device not a stream */
00252 #define  ENODATA      61  /* No data available */
00253 #define  ETIME        62  /* Timer expired */
00254 #define  ENOSR        63  /* Out of streams resources */
00255 #define  ENONET       64  /* Machine is not on the network */
00256 #define  ENOPKG       65  /* Package not installed */
00257 #define  EREMOTE      66  /* Object is remote */
00258 #define  ENOLINK      67  /* Link has been severed */
00259 #define  EADV         68  /* Advertise error */
00260 #define  ESRMNT       69  /* Srmount error */
00261 #define  ECOMM        70  /* Communication error on send */
00262 #define  EPROTO       71  /* Protocol error */
00263 #define  EMULTIHOP    72  /* Multihop attempted */
00264 #define  EDOTDOT      73  /* RFS specific error */
00265 #define  EBADMSG      74  /* Not a data message */
00266 #define  EOVERFLOW    75  /* Value too large for defined data type */
00267 #define  ENOTUNIQ     76  /* Name not unique on network */
00268 #define  EBADFD       77  /* File descriptor in bad state */
00269 #define  EREMCHG      78  /* Remote address changed */
00270 #define  ELIBACC      79  /* Can not access a needed shared library */
00271 #define  ELIBBAD      80  /* Accessing a corrupted shared library */
00272 #define  ELIBSCN      81  /* .lib section in a.out corrupted */
00273 #define  ELIBMAX      82  /* Attempting to link in too many shared libraries */
00274 #define  ELIBEXEC     83  /* Cannot exec a shared library directly */
00275 #define  EILSEQ       84  /* Illegal byte sequence */
00276 #define  ERESTART     85  /* Interrupted system call should be restarted */
00277 #define  ESTRPIPE     86  /* Streams pipe error */
00278 #define  EUSERS       87  /* Too many users */
00279 #define  ENOTSOCK     88  /* Socket operation on non-socket */
00280 #define  EDESTADDRREQ 89  /* Destination address required */
00281 #define  EMSGSIZE     90  /* Message too long */
00282 #define  EPROTOTYPE   91  /* Protocol wrong type for socket */
00283 #define  ENOPROTOOPT  92  /* Protocol not available */
00284 #define  EPROTONOSUPPORT 93  /* Protocol not supported */
00285 #define  ESOCKTNOSUPPORT 94  /* Socket type not supported */
00286 #define  EOPNOTSUPP      95  /* Operation not supported on transport endpoint */
00287 #define  EPFNOSUPPORT    96  /* Protocol family not supported */
00288 #define  EAFNOSUPPORT    97  /* Address family not supported by protocol */
00289 #define  EADDRINUSE      98  /* Address already in use */
00290 #define  EADDRNOTAVAIL   99  /* Cannot assign requested address */
00291 #define  ENETDOWN       100  /* Network is down */
00292 #define  ENETUNREACH    101  /* Network is unreachable */
00293 #define  ENETRESET      102  /* Network dropped connection because of reset */
00294 #define  ECONNABORTED   103  /* Software caused connection abort */
00295 #define  ECONNRESET     104  /* Connection reset by peer */
00296 #define  ENOBUFS        105  /* No buffer space available */
00297 #define  EISCONN        106  /* Transport endpoint is already connected */
00298 #define  ENOTCONN       107  /* Transport endpoint is not connected */
00299 #define  ESHUTDOWN      108  /* Cannot send after transport endpoint shutdown */
00300 #define  ETOOMANYREFS   109  /* Too many references: cannot splice */
00301 #define  ETIMEDOUT      110  /* Connection timed out */
00302 #define  ECONNREFUSED   111  /* Connection refused */
00303 #define  EHOSTDOWN      112  /* Host is down */
00304 #define  EHOSTUNREACH   113  /* No route to host */
00305 #define  EALREADY       114  /* Operation already in progress */
00306 #define  EINPROGRESS    115  /* Operation now in progress */
00307 #define  ESTALE         116  /* Stale NFS file handle */
00308 #define  EUCLEAN        117  /* Structure needs cleaning */
00309 #define  ENOTNAM        118  /* Not a XENIX named type file */
00310 #define  ENAVAIL        119  /* No XENIX semaphores available */
00311 #define  EISNAM         120  /* Is a named type file */
00312 #define  EREMOTEIO      121  /* Remote I/O error */
00313 #define  EDQUOT         122  /* Quota exceeded */
00314 
00315 #define  ENOMEDIUM      123  /* No medium found */
00316 #define  EMEDIUMTYPE    124  /* Wrong medium type */
00317 
00318 #ifndef errno
00319 extern int errno;
00320 #endif
00321 
00322 #endif /* LWIP_PROVIDE_ERRNO */
00323 
00324 #ifdef __cplusplus
00325 }
00326 #endif
00327 
00328 #endif /* LWIP_HDR_ARCH_H */