Prusa MINI Firmware overview
def.h
Go to the documentation of this file.
1 /**
2  * @file
3  * various utility macros
4  */
5 
6 /*
7  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without modification,
11  * are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  * 3. The name of the author may not be used to endorse or promote products
19  * derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30  * OF SUCH DAMAGE.
31  *
32  * This file is part of the lwIP TCP/IP stack.
33  *
34  * Author: Adam Dunkels <adam@sics.se>
35  *
36  */
37 #ifndef LWIP_HDR_DEF_H
38 #define LWIP_HDR_DEF_H
39 
40 /* arch.h might define NULL already */
41 #include "lwip/arch.h"
42 #include "lwip/opt.h"
43 #if LWIP_PERF
44 #include "arch/perf.h"
45 #else /* LWIP_PERF */
46 #define PERF_START /* null definition */
47 #define PERF_STOP(x) /* null definition */
48 #endif /* LWIP_PERF */
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 #define LWIP_MAX(x , y) (((x) > (y)) ? (x) : (y))
55 #define LWIP_MIN(x , y) (((x) < (y)) ? (x) : (y))
56 
57 /* Get the number of entries in an array ('x' must NOT be a pointer!) */
58 #define LWIP_ARRAYSIZE(x) (sizeof(x)/sizeof((x)[0]))
59 
60 /** Create u32_t value from bytes */
61 #define LWIP_MAKEU32(a,b,c,d) (((u32_t)((a) & 0xff) << 24) | \
62  ((u32_t)((b) & 0xff) << 16) | \
63  ((u32_t)((c) & 0xff) << 8) | \
64  (u32_t)((d) & 0xff))
65 
66 #ifndef NULL
67 #ifdef __cplusplus
68 #define NULL 0
69 #else
70 #define NULL ((void *)0)
71 #endif
72 #endif
73 
74 #if BYTE_ORDER == BIG_ENDIAN
75 #define lwip_htons(x) (x)
76 #define lwip_ntohs(x) (x)
77 #define lwip_htonl(x) (x)
78 #define lwip_ntohl(x) (x)
79 #define PP_HTONS(x) (x)
80 #define PP_NTOHS(x) (x)
81 #define PP_HTONL(x) (x)
82 #define PP_NTOHL(x) (x)
83 #else /* BYTE_ORDER != BIG_ENDIAN */
84 #ifndef lwip_htons
86 #endif
87 #define lwip_ntohs(x) lwip_htons(x)
88 
89 #ifndef lwip_htonl
91 #endif
92 #define lwip_ntohl(x) lwip_htonl(x)
93 
94 /* These macros should be calculated by the preprocessor and are used
95  with compile-time constants only (so that there is no little-endian
96  overhead at runtime). */
97 #define PP_HTONS(x) ((((x) & 0x00ffUL) << 8) | (((x) & 0xff00UL) >> 8))
98 #define PP_NTOHS(x) PP_HTONS(x)
99 #define PP_HTONL(x) ((((x) & 0x000000ffUL) << 24) | \
100  (((x) & 0x0000ff00UL) << 8) | \
101  (((x) & 0x00ff0000UL) >> 8) | \
102  (((x) & 0xff000000UL) >> 24))
103 #define PP_NTOHL(x) PP_HTONL(x)
104 #endif /* BYTE_ORDER == BIG_ENDIAN */
105 
106 /* Provide usual function names as macros for users, but this can be turned off */
107 #ifndef LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS
108 #define htons(x) lwip_htons(x)
109 #define ntohs(x) lwip_ntohs(x)
110 #define htonl(x) lwip_htonl(x)
111 #define ntohl(x) lwip_ntohl(x)
112 #endif
113 
114 /* Functions that are not available as standard implementations.
115  * In cc.h, you can #define these to implementations available on
116  * your platform to save some code bytes if you use these functions
117  * in your application, too.
118  */
119 
120 #ifndef lwip_itoa
121 /* This can be #defined to itoa() or snprintf(result, bufsize, "%d", number) depending on your platform */
122 void lwip_itoa(char* result, size_t bufsize, int number);
123 #endif
124 #ifndef lwip_strnicmp
125 /* This can be #defined to strnicmp() or strncasecmp() depending on your platform */
126 int lwip_strnicmp(const char* str1, const char* str2, size_t len);
127 #endif
128 #ifndef lwip_stricmp
129 /* This can be #defined to stricmp() or strcasecmp() depending on your platform */
130 int lwip_stricmp(const char* str1, const char* str2);
131 #endif
132 #ifndef lwip_strnstr
133 /* This can be #defined to strnstr() depending on your platform */
134 char* lwip_strnstr(const char* buffer, const char* token, size_t n);
135 #endif
136 
137 #ifdef __cplusplus
138 }
139 #endif
140 
141 #endif /* LWIP_HDR_DEF_H */
lwip_strnicmp
int lwip_strnicmp(const char *str1, const char *str2, size_t len)
Definition: def.c:163
opt.h
lwip_htons
#define lwip_htons(x)
Definition: def.h:75
u16_t
uint16_t u16_t
Definition: arch.h:121
u32_t
uint32_t u32_t
Definition: arch.h:123
lwip_strnstr
char * lwip_strnstr(const char *buffer, const char *token, size_t n)
Definition: def.c:105
arch.h
lwip_itoa
void lwip_itoa(char *result, size_t bufsize, int number)
Definition: def.c:198
perf.h
lwip_stricmp
int lwip_stricmp(const char *str1, const char *str2)
Definition: def.c:128
lwip_htonl
#define lwip_htonl(x)
Definition: def.h:77