check.h
Go to the documentation of this file.
1 #ifndef CHECK_H
2 #define CHECK_H
3
4 #include <limits.h>
5
6 /**
7 * \addtogroup Check
8 *
9 * \brief Check compiler settings
10 *
11 * Since GCC offers a bunch of different compiler settings, this header
12 * tries to help detecting possible bugs (during compile time) which would
13 * lead to incompatibility with the provided libspicboard.
14 *
15 * @{
16 * \file check.h
17 * \version \$Rev: 7715 $
18 */
19
20 #define XSTR(s) STR(s)
21 #define STR(s) #s
22
23 // Check C Standard
24 #ifdef __STDC__
25 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ < 201112L)
26 #if __STDC_VERSION__ >= 199901L
27 ##pragma message ("You are using C99 Standard. Thats okay, but we would suggest to use C11")
28 #else
29 #error The minimum support Standard is C99!
30 #endif
31 #endif
32 #else
33 #error You are using a non standard C compiler
34 #endif
35
36 // Check GNU Extensions
37 #ifndef __GNUC__
38 #pragma message ("GCC Extensions are not available - you wont be able to use __flash")
39 #else
40 // Set compiler options
41 #pragma GCC optimize ("unsigned-char")
42 #pragma GCC optimize ("unsigned-bitfields")
43 #pragma GCC optimize ("short-enums")
44 #pragma GCC optimize ("pack-struct")
45 #endif
46
47 // Check CPU clock rate
48 #ifndef F_CPU
49 #define F_CPU 16000000UL
50 #pragma message ("CPU frequency defaults now to 16 MHz")
51 #elif F_CPU == 1000000UL
52 #pragma message ("You are using 1 MHz CPU frequency - please make sure that the libspicboard you are using was built for this frequency!")
53 #elif F_CPU != 16000000UL
54 #error The CPU Frequency is not supported!
55 #endif
56
57 // Check unsigned char
58 #if ! defined(__CHAR_UNSIGNED__) || CHAR_MIN < 0
59 #error chars are signed - you should use unsigned for the SPiCboard (-funsigned-char)
60 #endif
61
62 // Check unallowed imports
63 #if defined(_COM_H) && defined(_CONSOLE_H)
64 #error serial communication and serial console cannot be used together!
65 #endif
66
67
68 /**
69 * \def CHECK_ENUM_SIZE(VAR, LEN)
70 *
71 * Aborts compilation if the size of VAR is not euqal LEN
72 */
73 #define CHECK_ENUM_SIZE(VAR, LEN) _Static_assert(sizeof(VAR) == (LEN), "enum " STR(VAR) " has the wrong size and therefore it is not compatible to the libspicboard; check your compiler flags (-fshort-enums)");
74
75 /** @}*/
76
77 #endif