Contiki 3.x
Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
cpu
stm32w108
hal
micro
generic
compiler
platform-common.h
Go to the documentation of this file.
1
/**
2
* \brief Compiler and Platform specific definitions and typedefs common to
3
* all platforms.
4
*
5
* platform-common.h provides PLATFORM_HEADER defaults and common definitions.
6
* This head should never be included directly, it should only be included
7
* by the specific PLATFORM_HEADER used by your platform.
8
*
9
* See platform-common.h for source code.
10
*@{
11
*/
12
13
/**
14
* @addtogroup stm32w-cpu
15
* @{ */
16
17
/** \file hal/micro/generic/compiler/platform-common.h
18
* See \ref platform_common for detailed documentation.
19
*
20
* <!--(C) COPYRIGHT 2010 STMicroelectronics. All rights reserved. -->
21
*/
22
23
24
#ifndef PLATCOMMONOKTOINCLUDE
25
// This header should only be included by a PLATFORM_HEADER
26
#error platform-common.h should not be included directly
27
#endif
28
29
#ifndef PLATFORMCOMMON_H_
30
#define PLATFORMCOMMON_H_
31
////////////////////////////////////////////////////////////////////////////////
32
// Many of the common definitions must be explicitly enabled by the
33
// particular PLATFORM_HEADER being used
34
////////////////////////////////////////////////////////////////////////////////
35
36
37
////////////////////////////////////////////////////////////////////////////////
38
#ifdef _HAL_USE_COMMON_PGM_
39
/** \name Master Program Memory Declarations
40
* These are a set of defines for simple declarations of program memory.
41
*/
42
//@{
43
/**
44
* \brief Standard program memory delcaration.
45
*/
46
#define PGM const
47
48
/**
49
* \brief Char pointer to program memory declaration.
50
*/
51
#define PGM_P const char *
52
53
/**
54
* \brief Unsigned char pointer to program memory declaration.
55
*/
56
#define PGM_PU const unsigned char *
57
58
59
/**
60
* \brief Sometimes a second PGM is needed in a declaration. Having two
61
* 'const' declarations generates a warning so we have a second PGM that turns
62
* into nothing under gcc.
63
*/
64
#define PGM_NO_CONST
65
//@} \\END MASTER PROGRAM MEMORY DECLARATIONS
66
#endif //_HAL_USE_COMMON_PGM_
67
68
69
////////////////////////////////////////////////////////////////////////////////
70
#ifdef _HAL_USE_COMMON_DIVMOD_
71
/** \name Divide and Modulus Operations
72
* Some platforms can perform divide and modulus operations on 32 bit
73
* quantities more efficiently when the divisor is only a 16 bit quantity.
74
* C compilers will always promote the divisor to 32 bits before performing the
75
* operation, so the following utility functions are instead required to take
76
* advantage of this optimisation.
77
*/
78
//@{
79
/**
80
* \brief Provide a portable name for the uint32_t by uint16_t division
81
* library function (which can perform the division with only a single
82
* assembly instruction on some platforms)
83
*/
84
#define halCommonUDiv32By16(x, y) ((uint16_t) (((uint32_t) (x)) / ((uint16_t) (y))))
85
86
/**
87
* \brief Provide a portable name for the int32_t by int16_t division
88
* library function (which can perform the division with only a single
89
* assembly instruction on some platforms)
90
*/
91
#define halCommonSDiv32By16(x, y) ((int16_t) (((int32_t) (x)) / ((int16_t) (y))))
92
93
/**
94
* \brief Provide a portable name for the uint32_t by uint16_t modulo
95
* library function (which can perform the division with only a single
96
* assembly instruction on some platforms)
97
*/
98
#define halCommonUMod32By16(x, y) ((uint16_t) (((uint32_t) (x)) % ((uint16_t) (y))))
99
100
/**
101
* \brief Provide a portable name for the int32_t by int16_t modulo
102
* library function (which can perform the division with only a single
103
* assembly instruction on some platforms)
104
*/
105
#define halCommonSMod32By16(x, y) ((int16_t) (((int32_t) (x)) % ((int16_t) (y))))
106
//@} \\END DIVIDE and MODULUS OPERATIONS
107
#endif //_HAL_USE_COMMON_DIVMOD_
108
109
110
////////////////////////////////////////////////////////////////////////////////
111
#ifdef _HAL_USE_COMMON_MEMUTILS_
112
/** \name C Standard Library Memory Utilities
113
* These should be used in place of the standard library functions.
114
*
115
* These functions have the same parameters and expected results as their C
116
* Standard Library equivalents but may take advantage of certain implementation
117
* optimizations.
118
*
119
* Unless otherwise noted, these functions are utilized by the StStack and are
120
* therefore required to be implemented in the HAL. Additionally, unless otherwise
121
* noted, applications that find these functions useful may utilze them.
122
*/
123
//@{
124
125
/**
126
* \brief Refer to the C stdlib memcpy().
127
*/
128
void
halCommonMemCopy(
void
*dest,
const
void
*src, uint8_t bytes);
129
130
131
/**
132
* \brief Refer to the C stdlib memset().
133
*/
134
void
halCommonMemSet(
void
*dest, uint8_t val, uint16_t bytes);
135
136
137
/**
138
* \brief Refer to the C stdlib memcmp().
139
*/
140
int8_t halCommonMemCompare(
const
void
*source0,
const
void
*source1, uint8_t bytes);
141
142
143
/**
144
* \brief Friendly convenience macro pointing to the full HAL function.
145
*/
146
#define MEMSET(d,v,l) halCommonMemSet(d,v,l)
147
#define MEMCOPY(d,s,l) halCommonMemCopy(d,s,l)
148
#define MEMCOMPARE(s0,s1,l) halCommonMemCompare(s0, s1, l)
149
#define MEMPGMCOMPARE(s0,s1,l) halCommonMemPGMCompare(s0, s1, l)
150
151
//@} // end of C Standard Library Memory Utilities
152
#endif //_HAL_USE_COMMON_MEMUTILS_
153
154
155
156
157
158
159
160
161
162
////////////////////////////////////////////////////////////////////////////////
163
// The following sections are common on all platforms
164
////////////////////////////////////////////////////////////////////////////////
165
166
////////////////////////////////////////////////////////////////////////////////
167
/**
168
* @name Generic Types
169
*@{
170
*/
171
172
/**
173
* \brief An alias for one, used for clarity.
174
*/
175
#define TRUE 1
176
177
/**
178
* \brief An alias for zero, used for clarity.
179
*/
180
#define FALSE 0
181
182
#ifndef NULL
183
/**
184
* \brief The null pointer.
185
*/
186
#define NULL ((void *)0)
187
#endif
188
189
//@} \\END Generic Types
190
191
192
/**
193
* @name Bit Manipulation Macros
194
*/
195
//@{
196
197
/**
198
* \brief Useful to reference a single bit of a byte.
199
*/
200
#define BIT(x) (1U << (x)) // Unsigned avoids compiler warnings re BIT(15)
201
202
/**
203
* \brief Useful to reference a single bit of an uint32_t type.
204
*/
205
#define BIT32(x) (((uint32_t) 1) << (x))
206
207
/**
208
* \brief Sets \c bit in the \c reg register or byte.
209
* @note Assuming \c reg is an IO register, some platforms
210
* can implement this in a single atomic operation.
211
*/
212
#define SETBIT(reg, bit) reg |= BIT(bit)
213
214
/**
215
* \brief Sets the bits in the \c reg register or the byte
216
* as specified in the bitmask \c bits.
217
* @note This is never a single atomic operation.
218
*/
219
#define SETBITS(reg, bits) reg |= (bits)
220
221
/**
222
* \brief Clears a bit in the \c reg register or byte.
223
* @note Assuming \c reg is an IO register, some platforms (such as the AVR)
224
* can implement this in a single atomic operation.
225
*/
226
#define CLEARBIT(reg, bit) reg &= ~(BIT(bit))
227
228
/**
229
* \brief Clears the bits in the \c reg register or byte
230
* as specified in the bitmask \c bits.
231
* @note This is never a single atomic operation.
232
*/
233
#define CLEARBITS(reg, bits) reg &= ~(bits)
234
235
/**
236
* \brief Returns the value of \c bit within the register or byte \c reg.
237
*/
238
#define READBIT(reg, bit) (reg & (BIT(bit)))
239
240
/**
241
* \brief Returns the value of the bitmask \c bits within
242
* the register or byte \c reg.
243
*/
244
#define READBITS(reg, bits) (reg & (bits))
245
246
//@} \\END Bit Manipulation Macros
247
248
249
////////////////////////////////////////////////////////////////////////////////
250
/**
251
* @name Byte Manipulation Macros
252
*/
253
//@{
254
255
/**
256
* \brief Returns the low byte of the 16-bit value \c n as an \c uint8_t.
257
*/
258
#define LOW_BYTE(n) ((uint8_t)((n) & 0xFF))
259
260
/**
261
* \brief Returns the high byte of the 16-bit value \c n as an \c uint8_t.
262
*/
263
#define HIGH_BYTE(n) ((uint8_t)(LOW_BYTE((n) >> 8)))
264
265
/**
266
* \brief Returns the value built from the two \c uint8_t
267
* values \c high and \c low.
268
*/
269
#define HIGH_LOW_TO_INT(high, low) ( \
270
(( (uint16_t) (high) ) << 8) + \
271
( (uint16_t) ( (low) & 0xFF)) \
272
)
273
274
/**
275
* \brief Returns the low byte of the 32-bit value \c n as an \c uint8_t.
276
*/
277
#define BYTE_0(n) ((uint8_t)((n) & 0xFF))
278
279
/**
280
* \brief Returns the second byte of the 32-bit value \c n as an \c uint8_t.
281
*/
282
#define BYTE_1(n) ((uint8_t)(BYTE_0((n) >> 8)))
283
284
/**
285
* \brief Returns the third byte of the 32-bit value \c n as an \c uint8_t.
286
*/
287
#define BYTE_2(n) ((uint8_t)(BYTE_0((n) >> 16)))
288
289
/**
290
* \brief Returns the high byte of the 32-bit value \c n as an \c uint8_t.
291
*/
292
#define BYTE_3(n) ((uint8_t)(BYTE_0((n) >> 24)))
293
294
//@} \\END Byte manipulation macros
295
296
297
////////////////////////////////////////////////////////////////////////////////
298
/**
299
* @name Time Manipulation Macros
300
*/
301
//@{
302
303
/**
304
* \brief Returns the elapsed time between two 8 bit values.
305
* Result may not be valid if the time samples differ by more than 127
306
*/
307
#define elapsedTimeInt8u(oldTime, newTime) \
308
((uint8_t) ((uint8_t)(newTime) - (uint8_t)(oldTime)))
309
310
/**
311
* \brief Returns the elapsed time between two 16 bit values.
312
* Result may not be valid if the time samples differ by more than 32767
313
*/
314
#define elapsedTimeInt16u(oldTime, newTime) \
315
((uint16_t) ((uint16_t)(newTime) - (uint16_t)(oldTime)))
316
317
/**
318
* \brief Returns the elapsed time between two 32 bit values.
319
* Result may not be valid if the time samples differ by more than 2147483647
320
*/
321
#define elapsedTimeInt32u(oldTime, newTime) \
322
((uint32_t) ((uint32_t)(newTime) - (uint32_t)(oldTime)))
323
324
/**
325
* \brief Returns TRUE if t1 is greater than t2. Can only account for 1 wrap
326
* around of the variable before it is wrong.
327
*/
328
#define MAX_INT8U_VALUE 0xFF
329
#define timeGTorEqualInt8u(t1, t2) \
330
(elapsedTimeInt8u(t2, t1) <= ((MAX_INT8U_VALUE + 1) / 2))
331
332
/**
333
* \brief Returns TRUE if t1 is greater than t2. Can only account for 1 wrap
334
* around of the variable before it is wrong.
335
*/
336
#define MAX_INT16U_VALUE 0xFFFF
337
#define timeGTorEqualInt16u(t1, t2) \
338
(elapsedTimeInt16u(t2, t1) <= ((MAX_INT16U_VALUE + 1) / 2))
339
340
/**
341
* \brief Returns TRUE if t1 is greater than t2. Can only account for 1 wrap
342
* around of the variable before it is wrong.
343
*/
344
#define MAX_INT32U_VALUE 0xFFFFFFFF
345
#define timeGTorEqualInt32u(t1, t2) \
346
(elapsedTimeInt32u(t2, t1) <= ((MAX_INT32U_VALUE + 1) / 2))
347
348
//@} \\END Time manipulation macros
349
350
351
352
#endif //PLATFORMCOMMON_H_
353
354
/** @} END addtogroup */
355
/** @} */
356
Generated on Sun Nov 30 2014 09:58:59 for Contiki 3.x by
1.8.5