Various fixes around Companion trainer mode (#7116)
[opentx.git] / radio / src / definitions.h
blob4a7244faa4d04a6b708b27d3f6cd46d85154f1a3
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #ifndef _DEFINITIONS_H_
22 #define _DEFINITIONS_H_
24 #include <inttypes.h>
25 #include <stdbool.h>
26 #include <stddef.h>
28 #if !defined(UNUSED)
29 #define UNUSED(x) ((void)(x)) /* to avoid warnings */
30 #endif
32 #if defined(SIMU)
33 #define __ALIGNED(x)
34 #define __SECTION_USED(s)
35 #else
36 #define __ALIGNED(x) __attribute__((aligned(x)))
37 #define __SECTION_USED(s) __attribute__((section(s), used))
38 #endif
40 #if defined(SIMU)
41 #define __DMA
42 #elif (defined(STM32F4) && !defined(BOOT)) || defined(SDRAM)
43 #define __DMA __attribute__((section(".ram"), aligned(4)))
44 #else
45 #define __DMA __ALIGNED(4)
46 #endif
48 #if defined(SDRAM) && !defined(SIMU)
49 #define __SDRAM __attribute__((section(".sdram"), aligned(4)))
50 #define __NOINIT __attribute__((section(".noinit")))
51 #else
52 #define __SDRAM __DMA
53 #define __NOINIT
54 #endif
56 #if __GNUC__
57 #define PACK( __Declaration__ ) __Declaration__ __attribute__((__packed__))
58 #else
59 #define PACK( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) )
60 #endif
62 #if defined(SIMU)
63 #define CONVERT_PTR_UINT(x) ((uint32_t)(uint64_t)(x))
64 #define CONVERT_UINT_PTR(x) ((uint32_t*)(uint64_t)(x))
65 #else
66 #define CONVERT_PTR_UINT(x) ((uint32_t)(x))
67 #define CONVERT_UINT_PTR(x) ((uint32_t *)(x))
68 #endif
70 #if !defined(DIM)
71 #define DIM(__arr) (sizeof((__arr)) / sizeof((__arr)[0]))
72 #endif
74 #endif // _DEFINITIONS_H_