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 ("short-enums")
42#pragma GCC optimize ("pack-struct")
43#endif
44
45// Check CPU clock rate
46#ifndef F_CPU
47#define F_CPU 16000000UL
48#pragma message ("CPU frequency defaults now to 16 MHz")
49#elif F_CPU == 1000000UL
50#pragma message ("You are using 1 MHz CPU frequency - please make sure that the libspicboard you are using was built for this frequency!")
51#elif F_CPU != 16000000UL
52#error The CPU Frequency is not supported!
53#endif
54
55// Check unsigned char
56#if ! defined(__CHAR_UNSIGNED__) || CHAR_MIN < 0
57#error chars are signed - you should use unsigned for the SPiCboard (-funsigned-char)
58#endif
59
60// Check unallowed imports
61#if defined(_COM_H) && defined(_CONSOLE_H)
62#error serial communication and serial console cannot be used together!
63#endif
64
65
66/**
67 * \def CHECK_ENUM_SIZE(VAR, LEN)
68 *
69 * Aborts compilation if the size of VAR is not euqal LEN
70 */
71#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)");
72
73/** @}*/
74
75#endif