1 /*! \page License
2  * Copyright (C) 2009, H&D Wireless AB All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * 3. The name of H&D Wireless AB may not be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY H&D WIRELESS AB ``AS IS'' AND ANY EXPRESS OR IMPLIED
18  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
20  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
21  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 #ifndef _TOP_DEFS_H
29 #define _TOP_DEFS_H
30 
31 #include <stdlib.h>
32 #include <stdint.h>
33 
34 #define ARRAY_SIZE(a) sizeof(a) / sizeof((a)[0])
35 
36 #ifndef UNREF
37 #define UNREF(x) x = x
38 #endif
39 
40 #if __GNUC__
41 #ifdef __KERNEL__
42 #define WEAK_DECL
43 #else
44 #define WEAK_DECL __attribute__ ((__weak__))
45 #endif
46 #define PACKED __attribute__ ((__packed__))
47 #define USED __attribute__ ((__used__))
48 #else
49  #error "Unsupported compiler"
50 #endif
51 
52 #ifndef TRUE
53 #define TRUE 1
54 #endif
55 
56 #ifndef FALSE
57 #define FALSE 0
58 #endif
59 
60 
61 #if 0
62 #include <stdio.h>
63 /*
64  * These functions should _NOT_ be used, call iprintf, sniprintf, iscanf, siscanf etc
65  * instead. Those functions do not have support for floating point formats.
66  * Not using these functions saves 27kB of code.
67  */
68 extern int printf(const char *format, ...) __attribute__ ((deprecated));
69 extern int sprintf(char *str, const char *format, ...) __attribute__ ((deprecated));
70 extern int snprintf(char *str, size_t size, const char *format, ...)  __attribute__ ((deprecated));
71 
72 int vprintf(const char *format, va_list ap) __attribute__ ((deprecated));
73 int vfprintf(FILE *stream, const char *format, va_list ap) __attribute__ ((deprecated));
74 int vsprintf(char *str, const char *format, va_list ap) __attribute__ ((deprecated));
75 int vsnprintf(char *str, size_t size, const char *format, va_list ap) __attribute__ ((deprecated));
76 
77 int scanf(const char *format, ...) __attribute__ ((deprecated));
78 int fscanf(FILE *stream, const char *format, ...) __attribute__ ((deprecated));
79 int sscanf(const char *str, const char *format, ...) __attribute__ ((deprecated));
80 
81 int vscanf(const char *format, va_list ap) __attribute__ ((deprecated));
82 int vsscanf(const char *str, const char *format, va_list ap) __attribute__ ((deprecated));
83 int vfscanf(FILE *stream, const char *format, va_list ap) __attribute__ ((deprecated));
84 #endif
85 
86 #endif
87 
88 
89 
90 #if defined(__linux__) || defined(__APPLE__)
91  #include <stdint.h>
92  #include <assert.h>
93  #define sniprintf snprintf
94  #define asiprintf asprintf
95  #define printk printf
96  #define siscanf sscanf
97 
98  #define WL_ASSERT(x) assert(x)
99  #define WL_DEBUG(args...) printf(args)
100 
101  #ifdef NO_LWIP
102   /* IP address representation from lwIP */
103   struct ip_addr {
104          uint32_t addr;
105   } PACKED;
106  #endif
107 
108  #define FEAT_SOCKETS
109 
110 #else
111  #define WL_ASSERT(cond) do {                                    \
112                 if (!(cond)) {                                  \
113                         printk("%s:%d\n", __FILE__, __LINE__);  \
114                         for(;;);                                \
115                 }                                               \
116         } while(0)
117  #define WL_DEBUG(args...) printk(args)
118 
119 
120 #endif
121