AM263x Motor Control SDK  09.02.00
dcl_macro.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2024 Texas Instruments Incorporated - https://www.ti.com/
3  *
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the
15  * distribution.
16  *
17  * * Neither the name of Texas Instruments Incorporated nor the names of
18  * its contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef _DCL_MACRO_H_
35 #define _DCL_MACRO_H_
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
49 #ifndef NULL
50 #define NULL 0
51 #endif
52 
55 #define CONST_PI 3.14159265358979323846f
56 #define CONST_2PI 2.0f * CONST_PI
57 #define CONST_PI_F64 3.1415926535897932384626433832795028841971693993751058209749445923078164062L
58 #define CONST_2PI_F64 2.0L * CONST_PI_F64
59 
62 #define DCL_FPU32_TOL 1.0e-06f
63 #define DCL_FPU64_TOL 1.0e-10L
64 
67 #define DCL_DEFAULT_PERIOD_S 100.0e-06f
68 #define DCL_DEFAULT_PERIODF64_S 100.0e-06L
69 
72 #define DCL_isValue(x,y) (((x < (y + DCL_FPU32_TOL)) && (x > (y - DCL_FPU32_TOL))) ? 1U : 0U)
73 #define DCL_isValueF64(x,y) (((x < (y + DCL_FPU64_TOL)) && (x > (y - DCL_FPU64_TOL))) ? 1U : 0U)
74 
77 #define DCL_isZero(x) DCL_isValue(x,0.0f)
78 #define DCL_isZeroF64(x) DCL_isValueF64(x,0.0L)
79 
87 #define DCL_rand(a) (a * ((float32_t) rand() / (float32_t) (RAND_MAX >> 1) - 1.0f))
88 #define DCL_randF64(a) (a * ((float64_t) rand() / (float64_t) (RAND_MAX >> 1) - 1.0L))
89 
93 #define DCL_c2Limit ((2.0f - CONST_PI) / (2.0f + CONST_PI))
94 #define DCL_c2LimitF64 ((2.0L - CONST_PI_F64) / (2.0L + CONST_PI_F64))
95 
98 #ifdef __cplusplus
99 }
100 #endif // extern "C"
101 
102 #endif // _DCL_MACRO_H_