LPCOpen Platform
v1.03
LPCOpen Platform for NXP LPC Microcontrollers
Main Page
Modules
Data Structures
Files
Related Pages
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
lib_def.h
Go to the documentation of this file.
1
/*
2
*********************************************************************************************************
3
* uC/LIB
4
* CUSTOM LIBRARY MODULES
5
*
6
* (c) Copyright 2004-2011; Micrium, Inc.; Weston, FL
7
*
8
* All rights reserved. Protected by international copyright laws.
9
*
10
* uC/LIB is provided in source form to registered licensees ONLY. It is
11
* illegal to distribute this source code to any third party unless you receive
12
* written permission by an authorized Micrium representative. Knowledge of
13
* the source code may NOT be used to develop a similar product.
14
*
15
* Please help us continue to provide the Embedded community with the finest
16
* software available. Your honesty is greatly appreciated.
17
*
18
* You can contact us at www.micrium.com.
19
*********************************************************************************************************
20
*/
21
22
/*
23
*********************************************************************************************************
24
*
25
* CORE CUSTOM LIBRARY MODULE
26
*
27
* Filename : lib_def.h
28
* Version : V1.35.00
29
* Programmer(s) : ITJ
30
*********************************************************************************************************
31
* Note(s) : (1) NO compiler-supplied standard library functions are used in library or product software.
32
*
33
* (a) ALL standard library functions are implemented in the custom library modules :
34
*
35
* (1) <Custom Library Directory>\lib_*.*
36
*
37
* (2) <Custom Library Directory>\Ports<cpu><compiler>\lib*_a.*
38
*
39
* where
40
* <Custom Library Directory> directory path for custom library software
41
* <cpu> directory name for specific processor (CPU)
42
* <compiler> directory name for specific compiler
43
*
44
* (b) Product-specific library functions are implemented in individual products.
45
*********************************************************************************************************
46
*/
47
48
49
/*
50
*********************************************************************************************************
51
* MODULE
52
*********************************************************************************************************
53
*/
54
55
#ifndef LIB_DEF_MODULE_PRESENT
56
#define LIB_DEF_MODULE_PRESENT
57
58
59
/*$PAGE*/
60
/*
61
*********************************************************************************************************
62
* CUSTOM LIBRARY MODULE VERSION NUMBER
63
*
64
* Note(s) : (1) (a) The custom library module software version is denoted as follows :
65
*
66
* Vx.yy.zz
67
*
68
* where
69
* V denotes 'Version' label
70
* x denotes major software version revision number
71
* yy denotes minor software version revision number
72
* zz denotes sub-minor software version revision number
73
*
74
* (b) The software version label #define is formatted as follows :
75
*
76
* ver = x.yyzz * 100 * 100
77
*
78
* where
79
* ver denotes software version number scaled as an integer value
80
* x.yyzz denotes software version number, where the unscaled integer
81
* portion denotes the major version number & the unscaled
82
* fractional portion denotes the (concatenated) minor
83
* version numbers
84
*********************************************************************************************************
85
*/
86
87
#define LIB_VERSION 13500u
/* See Note #1. */
88
89
90
/*
91
*********************************************************************************************************
92
* INCLUDE FILES
93
*
94
* Note(s) : (1) The custom library software files are located in the following directories :
95
*
96
* (a) <Custom Library Directory>\lib_*.*
97
*
98
* where
99
* <Custom Library Directory> directory path for custom library software
100
*
101
* (2) CPU-configuration software files are located in the following directories :
102
*
103
* (a) <CPU-Compiler Directory>\cpu_*.*
104
* (b) <CPU-Compiler Directory><cpu><compiler>\cpu*.*
105
*
106
* where
107
* <CPU-Compiler Directory> directory path for common CPU-compiler software
108
* <cpu> directory name for specific processor (CPU)
109
* <compiler> directory name for specific compiler
110
*
111
* (3) Compiler MUST be configured to include as additional include path directories :
112
*
113
* (a) '<Custom Library Directory>\' directory See Note #1a
114
*
115
* (b) (1) '<CPU-Compiler Directory>\' directory See Note #2a
116
* (2) '<CPU-Compiler Directory><cpu><compiler>\' directory See Note #2b
117
*********************************************************************************************************
118
*/
119
120
#include <cpu.h>
121
122
123
/*$PAGE*/
124
/*
125
*********************************************************************************************************
126
* STANDARD DEFINES
127
*********************************************************************************************************
128
*/
129
130
/* ----------------- BOOLEAN DEFINES ------------------ */
131
#define DEF_FALSE 0
132
#define DEF_TRUE 1
133
134
#define DEF_NO 0
135
#define DEF_YES 1
136
137
#define DEF_DISABLED 0
138
#define DEF_ENABLED 1
139
140
#define DEF_INACTIVE 0
141
#define DEF_ACTIVE 1
142
143
#define DEF_INVALID 0
144
#define DEF_VALID 1
145
146
#define DEF_OFF 0
147
#define DEF_ON 1
148
149
#define DEF_CLR 0
150
#define DEF_SET 1
151
152
#define DEF_FAIL 0
153
#define DEF_OK 1
154
155
156
/* ------------------- BIT DEFINES -------------------- */
157
#define DEF_BIT_NONE 0x00uL
158
159
#define DEF_BIT_00 0x01uL
160
#define DEF_BIT_01 0x02uL
161
#define DEF_BIT_02 0x04uL
162
#define DEF_BIT_03 0x08uL
163
#define DEF_BIT_04 0x10uL
164
#define DEF_BIT_05 0x20uL
165
#define DEF_BIT_06 0x40uL
166
#define DEF_BIT_07 0x80uL
167
168
#define DEF_BIT_08 0x0100uL
169
#define DEF_BIT_09 0x0200uL
170
#define DEF_BIT_10 0x0400uL
171
#define DEF_BIT_11 0x0800uL
172
#define DEF_BIT_12 0x1000uL
173
#define DEF_BIT_13 0x2000uL
174
#define DEF_BIT_14 0x4000uL
175
#define DEF_BIT_15 0x8000uL
176
177
#define DEF_BIT_16 0x00010000uL
178
#define DEF_BIT_17 0x00020000uL
179
#define DEF_BIT_18 0x00040000uL
180
#define DEF_BIT_19 0x00080000uL
181
#define DEF_BIT_20 0x00100000uL
182
#define DEF_BIT_21 0x00200000uL
183
#define DEF_BIT_22 0x00400000uL
184
#define DEF_BIT_23 0x00800000uL
185
186
#define DEF_BIT_24 0x01000000uL
187
#define DEF_BIT_25 0x02000000uL
188
#define DEF_BIT_26 0x04000000uL
189
#define DEF_BIT_27 0x08000000uL
190
#define DEF_BIT_28 0x10000000uL
191
#define DEF_BIT_29 0x20000000uL
192
#define DEF_BIT_30 0x40000000uL
193
#define DEF_BIT_31 0x80000000uL
194
/*$PAGE*/
195
#define DEF_BIT_32 0x0000000100000000uL
196
#define DEF_BIT_33 0x0000000200000000uL
197
#define DEF_BIT_34 0x0000000400000000uL
198
#define DEF_BIT_35 0x0000000800000000uL
199
#define DEF_BIT_36 0x0000001000000000uL
200
#define DEF_BIT_37 0x0000002000000000uL
201
#define DEF_BIT_38 0x0000004000000000uL
202
#define DEF_BIT_39 0x0000008000000000uL
203
204
#define DEF_BIT_40 0x0000010000000000uL
205
#define DEF_BIT_41 0x0000020000000000uL
206
#define DEF_BIT_42 0x0000040000000000uL
207
#define DEF_BIT_43 0x0000080000000000uL
208
#define DEF_BIT_44 0x0000100000000000uL
209
#define DEF_BIT_45 0x0000200000000000uL
210
#define DEF_BIT_46 0x0000400000000000uL
211
#define DEF_BIT_47 0x0000800000000000uL
212
213
#define DEF_BIT_48 0x0001000000000000uL
214
#define DEF_BIT_49 0x0002000000000000uL
215
#define DEF_BIT_50 0x0004000000000000uL
216
#define DEF_BIT_51 0x0008000000000000uL
217
#define DEF_BIT_52 0x0010000000000000uL
218
#define DEF_BIT_53 0x0020000000000000uL
219
#define DEF_BIT_54 0x0040000000000000uL
220
#define DEF_BIT_55 0x0080000000000000uL
221
222
#define DEF_BIT_56 0x0100000000000000uL
223
#define DEF_BIT_57 0x0200000000000000uL
224
#define DEF_BIT_58 0x0400000000000000uL
225
#define DEF_BIT_59 0x0800000000000000uL
226
#define DEF_BIT_60 0x1000000000000000uL
227
#define DEF_BIT_61 0x2000000000000000uL
228
#define DEF_BIT_62 0x4000000000000000uL
229
#define DEF_BIT_63 0x8000000000000000uL
230
231
232
/* ------------------ OCTET DEFINES ------------------- */
233
#define DEF_OCTET_NBR_BITS 8
234
#define DEF_OCTET_MASK 0xFFuL
235
236
#define DEF_NIBBLE_NBR_BITS 4
237
#define DEF_NIBBLE_MASK 0x0FuL
238
239
240
/* --------------- NUMBER BASE DEFINES ---------------- */
241
#define DEF_NBR_BASE_BIN 2
242
#define DEF_NBR_BASE_OCT 8
243
#define DEF_NBR_BASE_DEC 10
244
#define DEF_NBR_BASE_HEX 16
245
246
247
/*$PAGE*/
248
/* ----------------- INTEGER DEFINES ------------------ */
249
#define DEF_INT_08_NBR_BITS 8L
250
#define DEF_INT_08_MASK 0xFFuL
251
252
#define DEF_INT_08U_MIN_VAL 0u
253
#define DEF_INT_08U_MAX_VAL 255u
254
255
#define DEF_INT_08S_MIN_VAL_ONES_CPL (-127)
256
#define DEF_INT_08S_MAX_VAL_ONES_CPL 127
257
258
#define DEF_INT_08S_MIN_VAL (DEF_INT_08S_MIN_VAL_ONES_CPL - 1)
259
#define DEF_INT_08S_MAX_VAL DEF_INT_08S_MAX_VAL_ONES_CPL
260
261
#define DEF_INT_08U_NBR_DIG_MIN 1
262
#define DEF_INT_08U_NBR_DIG_MAX 3
263
264
#define DEF_INT_08S_NBR_DIG_MIN 3
265
#define DEF_INT_08S_NBR_DIG_MAX 3
266
267
268
269
#define DEF_INT_16_NBR_BITS 16L
270
#define DEF_INT_16_MASK 0xFFFFuL
271
272
#define DEF_INT_16U_MIN_VAL 0uL
273
#define DEF_INT_16U_MAX_VAL 65535uL
274
275
#define DEF_INT_16S_MIN_VAL_ONES_CPL (-32767L)
276
#define DEF_INT_16S_MAX_VAL_ONES_CPL 32767L
277
278
#define DEF_INT_16S_MIN_VAL (DEF_INT_16S_MIN_VAL_ONES_CPL - 1)
279
#define DEF_INT_16S_MAX_VAL DEF_INT_16S_MAX_VAL_ONES_CPL
280
281
#define DEF_INT_16U_NBR_DIG_MIN 1
282
#define DEF_INT_16U_NBR_DIG_MAX 5
283
284
#define DEF_INT_16S_NBR_DIG_MIN 5
285
#define DEF_INT_16S_NBR_DIG_MAX 5
286
287
288
289
#define DEF_INT_32_NBR_BITS 32L
290
#define DEF_INT_32_MASK 0xFFFFFFFFuL
291
292
#define DEF_INT_32U_MIN_VAL 0uL
293
#define DEF_INT_32U_MAX_VAL 4294967295uL
294
295
#define DEF_INT_32S_MIN_VAL_ONES_CPL (-2147483647L)
296
#define DEF_INT_32S_MAX_VAL_ONES_CPL 2147483647L
297
298
#define DEF_INT_32S_MIN_VAL (DEF_INT_32S_MIN_VAL_ONES_CPL - 1)
299
#define DEF_INT_32S_MAX_VAL DEF_INT_32S_MAX_VAL_ONES_CPL
300
301
#define DEF_INT_32U_NBR_DIG_MIN 1
302
#define DEF_INT_32U_NBR_DIG_MAX 10
303
304
#define DEF_INT_32S_NBR_DIG_MIN 10
305
#define DEF_INT_32S_NBR_DIG_MAX 10
306
307
308
309
#define DEF_INT_64_NBR_BITS 64L
310
#define DEF_INT_64_MASK 0xFFFFFFFFFFFFFFFFuL
311
312
#define DEF_INT_64U_MIN_VAL 0uL
313
#define DEF_INT_64U_MAX_VAL 18446744073709551615uL
314
315
#define DEF_INT_64S_MIN_VAL_ONES_CPL (-9223372036854775807L)
316
#define DEF_INT_64S_MAX_VAL_ONES_CPL 9223372036854775807L
317
318
#define DEF_INT_64S_MIN_VAL (DEF_INT_64S_MIN_VAL_ONES_CPL - 1)
319
#define DEF_INT_64S_MAX_VAL DEF_INT_64S_MAX_VAL_ONES_CPL
320
321
#define DEF_INT_64U_NBR_DIG_MIN 1
322
#define DEF_INT_64U_NBR_DIG_MAX 20
323
324
#define DEF_INT_64S_NBR_DIG_MIN 19
325
#define DEF_INT_64S_NBR_DIG_MAX 19
326
327
328
329
/*$PAGE*/
330
/* --------------- CPU INTEGER DEFINES ---------------- */
331
#define DEF_INT_CPU_NBR_BITS (CPU_CFG_DATA_SIZE * DEF_OCTET_NBR_BITS)
332
333
334
#if (DEF_INT_CPU_NBR_BITS == DEF_INT_08_NBR_BITS)
335
336
337
#define DEF_INT_CPU_MASK DEF_INT_08_MASK
338
339
#define DEF_INT_CPU_U_MIN_VAL DEF_INT_08U_MIN_VAL
340
#define DEF_INT_CPU_U_MAX_VAL DEF_INT_08U_MAX_VAL
341
342
#define DEF_INT_CPU_S_MIN_VAL DEF_INT_08S_MIN_VAL
343
#define DEF_INT_CPU_S_MAX_VAL DEF_INT_08S_MAX_VAL
344
345
#define DEF_INT_CPU_S_MIN_VAL_ONES_CPL DEF_INT_08S_MIN_VAL_ONES_CPL
346
#define DEF_INT_CPU_S_MAX_VAL_ONES_CPL DEF_INT_08S_MAX_VAL_ONES_CPL
347
348
349
350
#elif (DEF_INT_CPU_NBR_BITS == DEF_INT_16_NBR_BITS)
351
352
353
#define DEF_INT_CPU_MASK DEF_INT_16_MASK
354
355
#define DEF_INT_CPU_U_MIN_VAL DEF_INT_16U_MIN_VAL
356
#define DEF_INT_CPU_U_MAX_VAL DEF_INT_16U_MAX_VAL
357
358
#define DEF_INT_CPU_S_MIN_VAL DEF_INT_16S_MIN_VAL
359
#define DEF_INT_CPU_S_MAX_VAL DEF_INT_16S_MAX_VAL
360
361
#define DEF_INT_CPU_S_MIN_VAL_ONES_CPL DEF_INT_16S_MIN_VAL_ONES_CPL
362
#define DEF_INT_CPU_S_MAX_VAL_ONES_CPL DEF_INT_16S_MAX_VAL_ONES_CPL
363
364
365
366
#elif (DEF_INT_CPU_NBR_BITS == DEF_INT_32_NBR_BITS)
367
368
369
#define DEF_INT_CPU_MASK DEF_INT_32_MASK
370
371
#define DEF_INT_CPU_U_MIN_VAL DEF_INT_32U_MIN_VAL
372
#define DEF_INT_CPU_U_MAX_VAL DEF_INT_32U_MAX_VAL
373
374
#define DEF_INT_CPU_S_MIN_VAL DEF_INT_32S_MIN_VAL
375
#define DEF_INT_CPU_S_MAX_VAL DEF_INT_32S_MAX_VAL
376
377
#define DEF_INT_CPU_S_MIN_VAL_ONES_CPL DEF_INT_32S_MIN_VAL_ONES_CPL
378
#define DEF_INT_CPU_S_MAX_VAL_ONES_CPL DEF_INT_32S_MAX_VAL_ONES_CPL
379
380
381
382
#elif (DEF_INT_CPU_NBR_BITS == DEF_INT_64_NBR_BITS)
383
384
385
#define DEF_INT_CPU_MASK DEF_INT_64_MASK
386
387
#define DEF_INT_CPU_U_MIN_VAL DEF_INT_64U_MIN_VAL
388
#define DEF_INT_CPU_U_MAX_VAL DEF_INT_64U_MAX_VAL
389
390
#define DEF_INT_CPU_S_MIN_VAL DEF_INT_64S_MIN_VAL
391
#define DEF_INT_CPU_S_MAX_VAL DEF_INT_64S_MAX_VAL
392
393
#define DEF_INT_CPU_S_MIN_VAL_ONES_CPL DEF_INT_64S_MIN_VAL_ONES_CPL
394
#define DEF_INT_CPU_S_MAX_VAL_ONES_CPL DEF_INT_64S_MAX_VAL_ONES_CPL
395
396
397
398
#else
399
400
#error "CPU_CFG_DATA_SIZE illegally #defined in 'cpu.h' "
401
#error " [See 'cpu.h CONFIGURATION ERRORS']"
402
403
#endif
404
405
406
407
/*$PAGE*/
408
/* ------------------- TIME DEFINES ------------------- */
409
#define DEF_TIME_NBR_DAY_PER_WK 7uL
410
#define DEF_TIME_NBR_DAY_PER_YR 365uL
411
#define DEF_TIME_NBR_DAY_PER_YR_LEAP 366uL
412
413
#define DEF_TIME_NBR_HR_PER_DAY 24uL
414
#define DEF_TIME_NBR_HR_PER_WK (DEF_TIME_NBR_HR_PER_DAY * DEF_TIME_NBR_DAY_PER_WK )
415
#define DEF_TIME_NBR_HR_PER_YR (DEF_TIME_NBR_HR_PER_DAY * DEF_TIME_NBR_DAY_PER_YR )
416
#define DEF_TIME_NBR_HR_PER_YR_LEAP (DEF_TIME_NBR_HR_PER_DAY * DEF_TIME_NBR_DAY_PER_YR_LEAP)
417
418
#define DEF_TIME_NBR_MIN_PER_HR 60uL
419
#define DEF_TIME_NBR_MIN_PER_DAY (DEF_TIME_NBR_MIN_PER_HR * DEF_TIME_NBR_HR_PER_DAY )
420
#define DEF_TIME_NBR_MIN_PER_WK (DEF_TIME_NBR_MIN_PER_DAY * DEF_TIME_NBR_DAY_PER_WK )
421
#define DEF_TIME_NBR_MIN_PER_YR (DEF_TIME_NBR_MIN_PER_DAY * DEF_TIME_NBR_DAY_PER_YR )
422
#define DEF_TIME_NBR_MIN_PER_YR_LEAP (DEF_TIME_NBR_MIN_PER_DAY * DEF_TIME_NBR_DAY_PER_YR_LEAP)
423
424
#define DEF_TIME_NBR_SEC_PER_MIN 60uL
425
#define DEF_TIME_NBR_SEC_PER_HR (DEF_TIME_NBR_SEC_PER_MIN * DEF_TIME_NBR_MIN_PER_HR )
426
#define DEF_TIME_NBR_SEC_PER_DAY (DEF_TIME_NBR_SEC_PER_HR * DEF_TIME_NBR_HR_PER_DAY )
427
#define DEF_TIME_NBR_SEC_PER_WK (DEF_TIME_NBR_SEC_PER_DAY * DEF_TIME_NBR_DAY_PER_WK )
428
#define DEF_TIME_NBR_SEC_PER_YR (DEF_TIME_NBR_SEC_PER_DAY * DEF_TIME_NBR_DAY_PER_YR )
429
#define DEF_TIME_NBR_SEC_PER_YR_LEAP (DEF_TIME_NBR_SEC_PER_DAY * DEF_TIME_NBR_DAY_PER_YR_LEAP)
430
431
#define DEF_TIME_NBR_mS_PER_SEC 1000uL
432
#define DEF_TIME_NBR_uS_PER_SEC 1000000uL
433
#define DEF_TIME_NBR_nS_PER_SEC 1000000000uL
434
435
436
/*$PAGE*/
437
/*
438
*********************************************************************************************************
439
* ERROR CODES
440
*
441
* Note(s) : (1) All generic library error codes are #define'd in 'lib_def.h';
442
* Any module-specific error codes are #define'd in library module header files.
443
*********************************************************************************************************
444
*/
445
446
#define LIB_ERR_NONE 0u
447
448
449
/*$PAGE*/
450
/*
451
*********************************************************************************************************
452
* DATA TYPES
453
*********************************************************************************************************
454
*/
455
456
/*
457
*********************************************************************************************************
458
* LIBRARY ERROR CODES DATA TYPE
459
*********************************************************************************************************
460
*/
461
462
typedef
CPU_INT16U
LIB_ERR
;
463
464
465
/*
466
*********************************************************************************************************
467
* GLOBAL VARIABLES
468
*********************************************************************************************************
469
*/
470
471
472
/*$PAGE*/
473
/*
474
*********************************************************************************************************
475
* BIT MACRO'S
476
*********************************************************************************************************
477
*/
478
479
/*
480
*********************************************************************************************************
481
* DEF_BIT()
482
*
483
* Description : Create bit mask with single, specified bit set.
484
*
485
* Argument(s) : bit Bit number of bit to set.
486
*
487
* Return(s) : Bit mask with single, specified bit set.
488
*
489
* Caller(s) : Application.
490
*
491
* Note(s) : (1) (a) 'bit' values that overflow the target CPU &/or compiler environment (e.g. negative
492
* or greater-than-CPU-data-size values) MAY generate compiler warnings &/or errors.
493
*
494
* (b) To avoid overflowing any target CPU &/or compiler's integer data type, unsigned
495
* bit constant '1' is suffixed with 'L'ong integer modifier.
496
*
497
* This may still be insufficient for CPUs &/or compilers that support 'long long'
498
* integer data types, in which case 'LL' integer modifier should be suffixed.
499
* However, since almost all 16- & 32-bit CPUs & compilers support 'long' integer
500
* data types but many may NOT support 'long long' integer data types, only 'long'
501
* integer data types & modifiers are supported.
502
*********************************************************************************************************
503
*/
504
505
#define DEF_BIT(bit) (1uL << (bit))
506
507
508
/*$PAGE*/
509
/*
510
*********************************************************************************************************
511
* DEF_BIT_MASK()
512
*
513
* Description : Shift a bit mask.
514
*
515
* Argument(s) : bit_mask Bit mask to shift.
516
*
517
* bit_shift Number of bit positions to left-shift bit mask.
518
*
519
* Return(s) : Shifted bit mask.
520
*
521
* Caller(s) : Application.
522
*
523
* Note(s) : (1) 'bit_shift' values that overflow the target CPU &/or compiler environment (e.g. negative
524
* or greater-than-CPU-data-size values) MAY generate compiler warnings &/or errors.
525
*********************************************************************************************************
526
*/
527
528
#define DEF_BIT_MASK(bit_mask, bit_shift) ((bit_mask) << (bit_shift))
529
530
531
/*
532
*********************************************************************************************************
533
* DEF_BIT_FIELD()
534
*
535
* Description : Create & shift a contiguous bit field.
536
*
537
* Argument(s) : bit_field Number of contiguous bits to set in the bit field.
538
*
539
* bit_shift Number of bit positions to left-shift bit field.
540
*
541
* Return(s) : Shifted bit field.
542
*
543
* Caller(s) : Application.
544
*
545
* Note(s) : (1) (a) 'bit_field'/'bit_shift' values that overflow the target CPU &/or compiler
546
* environment (e.g. negative or greater-than-CPU-data-size values) MAY generate
547
* compiler warnings &/or errors.
548
*
549
* (b) To avoid overflowing any target CPU &/or compiler's integer data type, unsigned
550
* bit constant '1' is suffixed with 'L'ong integer modifier.
551
*
552
* This may still be insufficient for CPUs &/or compilers that support 'long long'
553
* integer data types, in which case 'LL' integer modifier should be suffixed.
554
* However, since almost all 16- & 32-bit CPUs & compilers support 'long' integer
555
* data types but many may NOT support 'long long' integer data types, only 'long'
556
* integer data types & modifiers are supported.
557
*********************************************************************************************************
558
*/
559
560
#define DEF_BIT_FIELD(bit_field, bit_shift) ((((bit_field) >= DEF_INT_CPU_NBR_BITS) ? (DEF_INT_CPU_U_MAX_VAL) \
561
: (DEF_BIT(bit_field) - 1uL)) \
562
<< (bit_shift))
563
564
565
/*$PAGE*/
566
/*
567
*********************************************************************************************************
568
* DEF_BIT_SET()
569
*
570
* Description : Set specified bit(s) in a value.
571
*
572
* Argument(s) : val Value to modify by setting specified bit(s).
573
*
574
* mask Mask of bits to set.
575
*
576
* Return(s) : Modified value with specified bit(s) set.
577
*
578
* Caller(s) : Application.
579
*
580
* Note(s) : none.
581
*********************************************************************************************************
582
*/
583
584
#define DEF_BIT_SET(val, mask) ((val) |= (mask))
585
586
587
/*
588
*********************************************************************************************************
589
* DEF_BIT_CLR()
590
*
591
* Description : Clear specified bit(s) in a value.
592
*
593
* Argument(s) : val Value to modify by clearing specified bit(s).
594
*
595
* mask Mask of bits to clear.
596
*
597
* Return(s) : Modified value with specified bit(s) clear.
598
*
599
* Caller(s) : Application.
600
*
601
* Note(s) : none.
602
*********************************************************************************************************
603
*/
604
605
#define DEF_BIT_CLR(val, mask) ((val) &= ~(mask))
606
607
608
/*$PAGE*/
609
/*
610
*********************************************************************************************************
611
* DEF_BIT_IS_SET()
612
*
613
* Description : Determine if specified bit(s) in a value are set.
614
*
615
* Argument(s) : val Value to check for specified bit(s) set.
616
*
617
* mask Mask of bits to check if set.
618
*
619
* Return(s) : DEF_YES, if ALL specified bit(s) are set in value.
620
*
621
* DEF_NO, if ALL specified bit(s) are NOT set in value.
622
*
623
* Caller(s) : Application.
624
*
625
* Note(s) : none.
626
*********************************************************************************************************
627
*/
628
629
#define DEF_BIT_IS_SET(val, mask) ((((val) & (mask)) == (mask)) ? (DEF_YES) : (DEF_NO ))
630
631
632
/*
633
*********************************************************************************************************
634
* DEF_BIT_IS_CLR()
635
*
636
* Description : Determine if specified bit(s) in a value are clear.
637
*
638
* Argument(s) : val Value to check for specified bit(s) clear.
639
*
640
* mask Mask of bits to check if clear.
641
*
642
* Return(s) : DEF_YES, if ALL specified bit(s) are clear in value.
643
*
644
* DEF_NO, if ALL specified bit(s) are NOT clear in value.
645
*
646
* Caller(s) : Application.
647
*
648
* Note(s) : none.
649
*********************************************************************************************************
650
*/
651
652
#define DEF_BIT_IS_CLR(val, mask) (((val) & (mask)) ? (DEF_NO ) : (DEF_YES))
653
654
655
/*$PAGE*/
656
/*
657
*********************************************************************************************************
658
* DEF_BIT_IS_SET_ANY()
659
*
660
* Description : Determine if any specified bit(s) in a value are set.
661
*
662
* Argument(s) : val Value to check for specified bit(s) set.
663
*
664
* mask Mask of bits to check if set.
665
*
666
* Return(s) : DEF_YES, if ANY specified bit(s) are set in value.
667
*
668
* DEF_NO, if ALL specified bit(s) are NOT set in value.
669
*
670
* Caller(s) : Application.
671
*
672
* Note(s) : none.
673
*********************************************************************************************************
674
*/
675
676
#define DEF_BIT_IS_SET_ANY(val, mask) (((val) & (mask)) ? (DEF_YES) : (DEF_NO ))
677
678
679
/*
680
*********************************************************************************************************
681
* DEF_BIT_IS_CLR_ANY()
682
*
683
* Description : Determine if any specified bit(s) in a value are clear.
684
*
685
* Argument(s) : val Value to check for specified bit(s) clear.
686
*
687
* mask Mask of bits to check if clear.
688
*
689
* Return(s) : DEF_YES, if ANY specified bit(s) are clear in value.
690
*
691
* DEF_NO, if ALL specified bit(s) are NOT clear in value.
692
*
693
* Note(s) : none.
694
*********************************************************************************************************
695
*/
696
697
#define DEF_BIT_IS_CLR_ANY(val, mask) ((((val) & (mask)) != (mask)) ? (DEF_YES) : (DEF_NO ))
698
699
700
/*$PAGE*/
701
/*
702
*********************************************************************************************************
703
* DEF_CHK_VAL_MIN()
704
*
705
* Description : Validate a value as greater than or equal to a specified minimum value.
706
*
707
* Argument(s) : val Value to validate.
708
*
709
* val_min Minimum value to test.
710
*
711
* Return(s) : DEF_OK, Value is greater than or equal to minimum value.
712
*
713
* DEF_FAIL, otherwise.
714
*
715
* Caller(s) : Application.
716
*
717
* Note(s) : (1) DEF_CHK_VAL_MIN() avoids directly comparing any two values if only one of the values
718
* is negative since the negative value might be incorrectly promoted to an arbitrary
719
* unsigned value if the other value to compare is unsigned.
720
*
721
* (2) Validation of values is limited to the range supported by the compiler &/or target
722
* environment. All other values that underflow/overflow the supported range will
723
* modulo/wrap into the supported range as arbitrary signed or unsigned values.
724
*
725
* Therefore, any values that underflow the most negative signed value or overflow
726
* the most positive unsigned value supported by the compiler &/or target environment
727
* cannot be validated :
728
*
729
* ( N-1 N ]
730
* ( -(2 ) , 2 - 1 ]
731
* ( ]
732
*
733
* where
734
* N Number of data word bits supported by the compiler
735
* &/or target environment
736
*
737
* (a) Note that the most negative value, -2^(N-1), is NOT included in the supported
738
* range since many compilers do NOT always correctly handle this value.
739
*********************************************************************************************************
740
*/
741
742
#define DEF_CHK_VAL_MIN(val, val_min) (((!(((val) >= 0) && ((val_min) < 0))) && \
743
((((val_min) >= 0) && ((val) < 0)) || \
744
((val) < (val_min)))) ? DEF_FAIL : DEF_OK)
745
746
747
/*$PAGE*/
748
/*
749
*********************************************************************************************************
750
* DEF_CHK_VAL_MAX()
751
*
752
* Description : Validate a value as less than or equal to a specified maximum value.
753
*
754
* Argument(s) : val Value to validate.
755
*
756
* val_max Maximum value to test.
757
*
758
* Return(s) : DEF_OK, Value is less than or equal to maximum value.
759
*
760
* DEF_FAIL, otherwise.
761
*
762
* Caller(s) : Application.
763
*
764
* Note(s) : (1) DEF_CHK_VAL_MAX() avoids directly comparing any two values if only one of the values
765
* is negative since the negative value might be incorrectly promoted to an arbitrary
766
* unsigned value if the other value to compare is unsigned.
767
*
768
* (2) Validation of values is limited to the range supported by the compiler &/or target
769
* environment. All other values that underflow/overflow the supported range will
770
* modulo/wrap into the supported range as arbitrary signed or unsigned values.
771
*
772
* Therefore, any values that underflow the most negative signed value or overflow
773
* the most positive unsigned value supported by the compiler &/or target environment
774
* cannot be validated :
775
*
776
* ( N-1 N ]
777
* ( -(2 ) , 2 - 1 ]
778
* ( ]
779
*
780
* where
781
* N Number of data word bits supported by the compiler
782
* &/or target environment
783
*
784
* (a) Note that the most negative value, -2^(N-1), is NOT included in the supported
785
* range since many compilers do NOT always correctly handle this value.
786
*********************************************************************************************************
787
*/
788
789
#define DEF_CHK_VAL_MAX(val, val_max) (((!(((val_max) >= 0) && ((val) < 0))) && \
790
((((val) >= 0) && ((val_max) < 0)) || \
791
((val) > (val_max)))) ? DEF_FAIL : DEF_OK)
792
793
794
/*$PAGE*/
795
/*
796
*********************************************************************************************************
797
* DEF_CHK_VAL()
798
*
799
* Description : Validate a value as greater than or equal to a specified minimum value & less than or
800
* equal to a specified maximum value.
801
*
802
* Argument(s) : val Value to validate.
803
*
804
* val_min Minimum value to test.
805
*
806
* val_max Maximum value to test.
807
*
808
* Return(s) : DEF_OK, Value is greater than or equal to minimum value AND
809
* less than or equal to maximum value.
810
*
811
* DEF_FAIL, otherwise.
812
*
813
* Caller(s) : Application.
814
*
815
* Note(s) : (1) DEF_CHK_VAL() avoids directly comparing any two values if only one of the values
816
* is negative since the negative value might be incorrectly promoted to an arbitrary
817
* unsigned value if the other value to compare is unsigned.
818
*
819
* (2) Validation of values is limited to the range supported by the compiler &/or target
820
* environment. All other values that underflow/overflow the supported range will
821
* modulo/wrap into the supported range as arbitrary signed or unsigned values.
822
*
823
* Therefore, any values that underflow the most negative signed value or overflow
824
* the most positive unsigned value supported by the compiler &/or target environment
825
* cannot be validated :
826
*
827
* ( N-1 N ]
828
* ( -(2 ) , 2 - 1 ]
829
* ( ]
830
*
831
* where
832
* N Number of data word bits supported by the compiler
833
* &/or target environment
834
*
835
* (a) Note that the most negative value, -2^(N-1), is NOT included in the supported
836
* range since many compilers do NOT always correctly handle this value.
837
*
838
* (3) DEF_CHK_VAL() does NOT validate that maximum value ('val_max') is greater than or
839
* equal to the minimum value ('val_min').
840
*********************************************************************************************************
841
*/
842
843
#define DEF_CHK_VAL(val, val_min, val_max) (((DEF_CHK_VAL_MIN(val, val_min) == DEF_FAIL) || \
844
(DEF_CHK_VAL_MAX(val, val_max) == DEF_FAIL)) ? DEF_FAIL : DEF_OK)
845
846
847
/*$PAGE*/
848
/*
849
*********************************************************************************************************
850
* MATH MACRO'S
851
*
852
* Note(s) : (1) Ideally, ALL mathematical macro's & functions SHOULD be defined in the custom mathematics
853
* library ('lib_math.*'). #### However, to maintain backwards compatibility with previously-
854
* released modules, mathematical macro & function definitions should only be moved to the
855
* custom mathematics library once all previously-released modules are updated to include the
856
* custom mathematics library.
857
*********************************************************************************************************
858
*/
859
860
/*
861
*********************************************************************************************************
862
* DEF_MIN()
863
*
864
* Description : Determine the minimum of two values.
865
*
866
* Argument(s) : a First value.
867
*
868
* b Second value.
869
*
870
* Return(s) : Minimum of the two values.
871
*
872
* Caller(s) : Application.
873
*
874
* Note(s) : none.
875
*********************************************************************************************************
876
*/
877
878
#define DEF_MIN(a, b) (((a) < (b)) ? (a) : (b))
879
880
881
/*
882
*********************************************************************************************************
883
* DEF_MAX()
884
*
885
* Description : Determine the maximum of two values.
886
*
887
* Argument(s) : a First value.
888
*
889
* b Second value.
890
*
891
* Return(s) : Maximum of the two values.
892
*
893
* Note(s) : none.
894
*********************************************************************************************************
895
*/
896
897
#define DEF_MAX(a, b) (((a) > (b)) ? (a) : (b))
898
899
900
/*$PAGE*/
901
/*
902
*********************************************************************************************************
903
* DEF_ABS()
904
*
905
* Description : Determine the absolute value of a value.
906
*
907
* Argument(s) : a Value to calculate absolute value.
908
*
909
* Return(s) : Absolute value of the value.
910
*
911
* Caller(s) : Application.
912
*
913
* Note(s) : none.
914
*********************************************************************************************************
915
*/
916
917
#define DEF_ABS(a) (((a) < 0) ? (-(a)) : (a))
918
919
920
/*$PAGE*/
921
/*
922
*********************************************************************************************************
923
* FUNCTION PROTOTYPES
924
*********************************************************************************************************
925
*/
926
927
928
/*
929
*********************************************************************************************************
930
* CONFIGURATION ERRORS
931
*********************************************************************************************************
932
*/
933
934
935
/*
936
*********************************************************************************************************
937
* MODULE END
938
*********************************************************************************************************
939
*/
940
941
#endif
/* End of lib def module include. */
942
software
ucos_iii
Micrium
Software
uC-LIB
lib_def.h
Generated on Fri May 10 2013 10:42:26 for LPCOpen Platform by
1.8.2