ARMEBS4  revision-26.06.2015
utils.h
Go to the documentation of this file.
1 /**
2  * \file heivs/utils.h
3  * \brief Various utilities
4  * \author marc dot pignat at hevs dot ch
5  * \defgroup utils Utilities
6  * \ingroup libheivs_stm32
7  * @{
8  ***************************************************************************/
9 #ifndef HEIVS_UTILS_H
10 #define HEIVS_UTILS_H
11 
12 #include "heivs/config.h"
13 
14 /**
15  * \brief Number of elements in the array
16  *
17  * \param x the array
18  */
19 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
20 
21 /**
22  * \brief Maximum between a and b
23  *
24  * \param a
25  * \param b
26  */
27 #ifdef __GNUC__
28 #define max(a,b) \
29  ({ __typeof__ (a) _a = (a); \
30  __typeof__ (b) _b = (b); \
31  _a > _b ? _a : _b; })
32 #else
33 #define max(a,b) (a>b?a:b)
34 #endif
35 /**
36  * \brief Minimum between a and b
37  *
38  * \param a
39  * \param b
40  */
41 #ifdef __GNUC__
42 #define min(a,b) \
43  ({ __typeof__ (a) _a = (a); \
44  __typeof__ (b) _b = (b); \
45  _a < _b ? _a : _b; })
46 #else
47 #define max(a,b) (a>b?a:b)
48 #endif
49 
50 #ifdef __cplusplus
51  extern "C"
52  {
53 #endif
54 
55 #ifdef __cplusplus
56  }
57 #endif
58 
59 #include "stm32/stm32f4xx.h"
60 
61 /**
62  * \brief Detect is debugger is connected
63  *
64  * Our debug script enable debugging while in WFI (wait for interrupt), so we
65  * can detect if the debugger is connected by reading this flag.
66  */
67 #define debugger_is_connected() (DBGMCU->CR & DBGMCU_CR_DBG_SLEEP)
68 
69 /**
70  * \brief Breakpoint (from code)
71  *
72  * This breakpoint can't be disabled.
73  */
74 #define breakpoint() asm volatile("bkpt")
75 
76 /**
77  * @}
78  */
79 #endif /* HEIVS_UTILS_H */
libheivs configuration file
CMSIS Cortex-M4 Device Peripheral Access Layer Header File. This file contains all the peripheral reg...