summaryrefslogtreecommitdiff
path: root/lcmodule/source/legacy_compatibility/r_basicdefinitions.h
blob: 35bf0bc5fd51a8c4f42f7bd4593eca40bc5086b8 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/******************************************************************************
* $Workfile: r_basicdefinitions.h $
*
* Copyright (C) ST-Ericsson SA 2011
* License terms: 3-clause BSD license
*
* DESCRIPTION:
*
*     Portable types used for a consistent target platform.
*     The name should make it totally clear as to what they are used for.
*
*
*/

#ifndef _R_BASICDEFINITIONS_H
#define _R_BASICDEFINITIONS_H

#include "t_basicdefinitions.h"

/********************
* General macro's
* These should be moved to a utility header when we have a good file name put it in.
*********************/
/**
 * Returns the smallest value of x and y.
 *
 * @param [in] x Value of any scalar type
 * @param [in] y Value of any scalar type
 *
 * @return The return type obeys the rules regarding binary conversion of the
 *         programming language C.
 *
 * @sigbased No - Macro, parameters expand more than one time
 */
#ifndef MIN
#define MIN(val1, val2) (((val1) < (val2)) ? (val1) : (val2))
#endif

/**
 * Returns the largest value of x and y.
 *
 * @param [in] x Value of any scalar type
 * @param [in] y Value of any scalar type
 *
 * @return The return type obeys the rules regarding binary conversion of the
 *         programming language C.
 *
 * @sigbased No - Macro, parameters expand more than one time
 */
#ifndef MAX
#define MAX(val1, val2) (((val1) > (val2)) ? (val1) : (val2))
#endif

/**
 * The return value is evaluated at compile time, not at run-time. The return
 * value can be used as dimension parameter in other declarations of other
 * arrays. The return value can however not be used in expressions evaluated in
 * pre-processor directives (e.g. #if (ElementsOf(a) > 10)) since it is based on
 * the sizeof() operator.
 *
 * @param [in] a Must be an array variable or array type
 *
 * @return Number of elements in the array passed as parameter.
 *
 * @sigbased No - Macro, parameters expand more than one time
 */
#ifndef ElementsOf
#define ElementsOf(array) (sizeof(array) / sizeof(array[0]))
#endif


/*****************************
* Macro's to extract bytes from uint16 or sint16
******************************/
/**
 * Used to retrieve the least significant 8 bits of a 16 bit word.
 *
 * @param [in] w A value of type uint16
 *
 * @return Returns value of type uint8 representing the low byte of the value
 *         passed as parameter.
 *
 * @sigbased No - Macro
 */
#define INT16_LBYTE(i) (uint8)((i) & 0xFF)

/**
 * Used to retrieve the most significant 8 bits of a 16 bit word.
 *
 * @param [in] w A value of type uint16
 *
 * @return Returns value of type uint8 representing the high byte of the value
 *         passed as parameter.
 *
 * @sigbased No - Macro
 */
#define INT16_HBYTE(i) (uint8)((i) >> 8)

/*****************************
* Macro's to build int16 from two bytes (low & high)
******************************/
/**
 * Used to form a 16 bit signed value from two 8 bit values. The result will
 * be negative if the most significant bit (MSB) of the HighByte parameter is
 * a one, otherwise positive.
 *
 * @param [in] LowByte  Defines the value that will be in the low byte of the
 *                      returned sint16 value.
 * @param [in] HighByte Defines the value that will be in the high byte of the
 *                      returned sint16 value.
 *
 * @return Returns value of type sint16 constructed from two byte values.
 *
 * @sigbased No - Macro
 */
#define BYTES_TO_SINT16(l,h) (sint16)((h << 8) + l)

/**
 * Used to form a 16 bit unsigned value from two 8 bit values.
 *
 * @param [in] LowByte  Defines the value that will be in the low byte of the
 *                      returned sint16 value.
 * @param [in] HighByte Defines the value that will be in the high byte of the
 *                      returned sint16 value.
 *
 * @return Returns value of type uint16 constructed from two byte values.
 *
 * @sigbased No - Macro
 */
#define BYTES_TO_UINT16(l,h) (uint16)((h << 8) + l)

/*
**========================================================================
**
** MACRO TO AVOID WARNINGS FOR UNUSED PARAMETERS OR VARIABLE
**
** Example of use:
**
** int MyFunc(int p)
** {
**   int a = 42;
**   NOT_USED(p); // This line must be placed after declaration of local variables.
**
**   return a;
** }
**
**========================================================================
*/


#ifdef IDENTIFIER_NOT_USED
#undef IDENTIFIER_NOT_USED
#endif

//#define IDENTIFIER_NOT_USED(p) if (sizeof(&p)) {}
// this seems to work better under lint:
/**
 * Should be used to "touch" a variable or a formal parameter that is intentionally
 * not used and thereby avoid compiler warnings.
 *
 * @param [in] Id A symbol that represents a variable that is not used, usually a
 *                formal parameter.
 *
 * @sigbased No - Macro
 */
#define IDENTIFIER_NOT_USED(P) (void)(P);

#endif //_R_BASICDEFINITIONS_H