Firmware
px4_defines.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2014 PX4 Development Team. All rights reserved.
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  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
40 #pragma once
41 
42 #include <px4_log.h>
43 
44 #if defined(__PX4_NUTTX) && !defined(CONFIG_ARCH_MATH_H)
45 #error CONFIG_ARCH_MATH_H is required to use math definitions and functions
46 #endif
47 
48 /****************************************************************************
49  * Defines for all platforms.
50  ****************************************************************************/
51 
52 /* Get the name of the default value fiven the param name */
53 #define PX4_PARAM_DEFAULT_VALUE_NAME(_name) PARAM_##_name##_DEFAULT
54 
55 /* Shortcuts to define parameters when the default value is defined according to PX4_PARAM_DEFAULT_VALUE_NAME */
56 #define PX4_PARAM_DEFINE_INT32(_name) PARAM_DEFINE_INT32(_name, PX4_PARAM_DEFAULT_VALUE_NAME(_name))
57 #define PX4_PARAM_DEFINE_FLOAT(_name) PARAM_DEFINE_FLOAT(_name, PX4_PARAM_DEFAULT_VALUE_NAME(_name))
58 
59 #define PX4_ERROR (-1)
60 #define PX4_OK 0
61 
62 /* Wrapper for 2d matrices */
63 #define PX4_ARRAY2D(_array, _ncols, _x, _y) (_array[_x * _ncols + _y])
64 
65 /* Wrapper for rotation matrices stored in arrays */
66 #define PX4_R(_array, _x, _y) PX4_ARRAY2D(_array, 3, _x, _y)
67 
68 /* Define PX4_ISFINITE */
69 #ifdef __cplusplus
70 constexpr bool PX4_ISFINITE(float x) { return __builtin_isfinite(x); }
71 constexpr bool PX4_ISFINITE(double x) { return __builtin_isfinite(x); }
72 #endif /* __cplusplus */
73 
74 #if defined(__PX4_NUTTX) || defined(__PX4_POSIX)
75 /****************************************************************************
76  * Building for NuttX or POSIX.
77  ****************************************************************************/
78 
79 /* Main entry point */
80 #define PX4_MAIN_FUNCTION(_prefix) int _prefix##_task_main(int argc, char *argv[])
81 
82 /* Parameter handle datatype */
83 #include <parameters/param.h>
84 typedef param_t px4_param_t;
85 
86 /* Get value of parameter by name */
87 #define PX4_PARAM_GET_BYNAME(_name, _destpt) param_get(param_find(_name), _destpt)
88 
89 #else // defined(__PX4_NUTTX) || defined(__PX4_POSIX)
90 /****************************************************************************/
91 #error "No target OS defined"
92 #endif
93 
94 #if defined(__PX4_NUTTX)
95 /****************************************************************************
96  * NuttX specific defines.
97  ****************************************************************************/
98 
99 #define PX4_ROOTFSDIR ""
100 #define PX4_STORAGEDIR PX4_ROOTFSDIR "/fs/microsd"
101 #define _PX4_IOC(x,y) _IOC(x,y)
102 
103 // mode for open with O_CREAT
104 #define PX4_O_MODE_777 0777
105 #define PX4_O_MODE_666 0666
106 #define PX4_O_MODE_600 0600
107 
108 #ifndef PRIu64
109 # define PRIu64 "llu"
110 #endif
111 #ifndef PRId64
112 # define PRId64 "lld"
113 #endif
114 
115 #ifndef offsetof
116 # define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
117 #endif
118 
119 #elif defined(__PX4_POSIX)
120 /****************************************************************************
121  * POSIX Specific defines
122  ****************************************************************************/
123 
124 // Flag is meaningless on Linux
125 #ifndef O_BINARY
126 #define O_BINARY 0
127 #endif
128 
129 // mode for open with O_CREAT
130 #define PX4_O_MODE_777 (S_IRWXU | S_IRWXG | S_IRWXO)
131 #define PX4_O_MODE_666 (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH )
132 #define PX4_O_MODE_600 (S_IRUSR | S_IWUSR)
133 
134 // NuttX _IOC is equivalent to Linux _IO
135 #define _PX4_IOC(x,y) _IO(x,y)
136 
137 /* FIXME - Used to satisfy build */
138 #define getreg32(a) (*(volatile uint32_t *)(a))
139 
140 #define USEC_PER_TICK (1000000/PX4_TICKS_PER_SEC)
141 #define USEC2TICK(x) (((x)+(USEC_PER_TICK/2))/USEC_PER_TICK)
142 
143 #ifdef __PX4_QURT
144 
145 // QURT specific
146 # include "dspal_math.h"
147 # define PX4_ROOTFSDIR "."
148 # define PX4_TICKS_PER_SEC 1000L
149 # define SIOCDEVPRIVATE 999999
150 
151 #else // __PX4_QURT
152 
153 // All POSIX except QURT.
154 
155 __BEGIN_DECLS
156 extern long PX4_TICKS_PER_SEC;
157 __END_DECLS
158 
159 # if defined(__PX4_POSIX_EAGLE) || defined(__PX4_POSIX_EXCELSIOR)
160 # define PX4_ROOTFSDIR "/home/linaro"
161 # elif defined(__PX4_POSIX_BEBOP)
162 # define PX4_ROOTFSDIR "/data/ftp/internal_000"
163 # else
164 # define PX4_ROOTFSDIR "."
165 # endif
166 
167 #endif // __PX4_QURT
168 
169 #define PX4_STORAGEDIR PX4_ROOTFSDIR
170 #endif // __PX4_POSIX
171 
172 #if defined(__PX4_POSIX)
173 /****************************************************************************
174  * Defines for POSIX and ROS
175  ****************************************************************************/
176 
177 #define OK 0
178 #define ERROR -1
179 #define MAX_RAND 32767
180 
181 /* Math macro's for float literals. Do not use M_PI et al as they aren't
182  * defined (neither C nor the C++ standard define math constants) */
183 #define M_E_F 2.71828183f
184 #define M_LOG2E_F 1.44269504f
185 #define M_LOG10E_F 0.43429448f
186 #define M_LN2_F 0.69314718f
187 #define M_LN10_F 2.30258509f
188 #define M_PI_F 3.14159265f
189 #define M_TWOPI_F 6.28318531f
190 #define M_PI_2_F 1.57079632f
191 #define M_PI_4_F 0.78539816f
192 #define M_3PI_4_F 2.35619449f
193 #define M_SQRTPI_F 1.77245385f
194 #define M_1_PI_F 0.31830989f
195 #define M_2_PI_F 0.63661977f
196 #define M_2_SQRTPI_F 1.12837917f
197 #define M_DEG_TO_RAD_F 0.0174532925f
198 #define M_RAD_TO_DEG_F 57.2957795f
199 #define M_SQRT2_F 1.41421356f
200 #define M_SQRT1_2_F 0.70710678f
201 #define M_LN2LO_F 1.90821484E-10f
202 #define M_LN2HI_F 0.69314718f
203 #define M_SQRT3_F 1.73205081f
204 #define M_IVLN10_F 0.43429448f // 1 / log(10)
205 #define M_LOG2_E_F 0.69314718f
206 #define M_INVLN2_F 1.44269504f // 1 / log(2)
207 
208 #define M_DEG_TO_RAD 0.017453292519943295
209 #define M_RAD_TO_DEG 57.295779513082323
210 
211 #endif // defined(__PX4_POSIX)
Global flash based parameter store.
Platform dependant logging/debug implementation.
uint32_t param_t
Parameter handle.
Definition: param.h:98