summaryrefslogtreecommitdiff
path: root/compiler.h
blob: faa518461914d8150294b66ff0ee17e57927390f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 *  XIOH power sequence
 *  Copyright (C) 2013  Avencall
 *
 *  compiler.h - compiler dependant defines
 *  Authors:
 *    Guillaume Knispel
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef COMPILER_H
#define COMPILER_H

/* MY_IAR, MY_TI, and MY_GCC are here to ease further compilation conditionals.
 * Remember that a lot of non-gcc compilers also define __GNUC__ so
 * directly testing against that is not a good idea.
 *
 * The SV() macro stands for "State Value".
 * It is used to create enum values latter used in switches with in_range.
 * in_range expands to __even_in_range when supported, in which case
 * the values should be even.
 * GCC seems happier with consecutive values.
 *
 * MASK_MISRA and UNMASK_MISRA are used to temporarily disable MISRA rules
 * checking that is provided by TI MSP430 Optimizing C compiler.
 */

#if defined(__IAR_SYSTEMS_ICC__)

# define MY_IAR
# define MASK_MISRA
# define UNMASK_MISRA
# define SV(v)			((v) * 2)
# define in_range		__even_in_range
# define out_range(v, mx)	((v) > (mx))

#elif defined(__TI_COMPILER_VERSION) || defined(__TI_COMPILER_VERSION__)

# define MY_TI
# define EMIT_PRAGMA(x)		_Pragma(#x)
# define MASK_MISRA		EMIT_PRAGMA(CHECK_MISRA ("none"))
# define UNMASK_MISRA		EMIT_PRAGMA(RESET_MISRA ("all"))
# define SV(v)			((v) * 2)
# define in_range		__even_in_range
# define out_range(v, mx)	(((v) & 1) || ((v) > (mx)))

#else /* GCC */

# define MY_GCC
# define MASK_MISRA
# define UNMASK_MISRA
# define in_range(v, mx)	(v)
# define out_range(v, mx)	((v) > (mx))
# define SV(v)			(v)

#endif /* IAR / TI / GCC */

#endif /* COMPILER_H */