LP-500 HoTT Telemetry added device definitions
[librepilot.git] / flight / uavobjects / inc / uavobjectprivate.h
blob88229f44ec7498553ea5ecdc8ef50c916158ec0c
1 /**
2 ******************************************************************************
4 * @file uavobjectprivate.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
6 * @brief Private declarations for uavobject manager and persistence handler.
7 * --
8 * @see The GNU Public License (GPL) Version 3
10 *****************************************************************************/
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #ifndef UAVOBJECTPRIVATE_H_
27 #define UAVOBJECTPRIVATE_H_
30 #if (defined(__MACH__) && defined(__APPLE__))
31 #include <mach-o/getsect.h>
32 #endif
34 // Constants
36 // Private types
38 // Macros
39 #define SET_BITS(var, shift, value, mask) var = (var & ~(mask << shift)) | (value << shift);
41 // Mach-o: dummy segment to calculate ASLR offset in sim_osx
42 #if (defined(__MACH__) && defined(__APPLE__))
43 static long _aslr_offset __attribute__((section("__DATA,_aslr")));
44 #endif
46 /* Table of UAVO handles */
47 #if (defined(__MACH__) && defined(__APPLE__))
48 /* Mach-o format */
49 static struct UAVOData * *__start__uavo_handles;
50 static struct UAVOData * *__stop__uavo_handles;
51 #else
52 /* ELF format: automagically defined at compile time */
53 extern struct UAVOData *__start__uavo_handles[] __attribute__((weak));
54 extern struct UAVOData *__stop__uavo_handles[] __attribute__((weak));
55 #endif
57 #define UAVO_LIST_ITERATE(_item) \
58 for (struct UAVOData * *_uavo_slot = __start__uavo_handles; \
59 _uavo_slot && _uavo_slot < __stop__uavo_handles; \
60 _uavo_slot++) { \
61 struct UAVOData *_item = *_uavo_slot; \
62 if (_item == NULL) { continue; }
64 /**
65 * List of event queues and the eventmask associated with the queue.
68 /** opaque type for instances **/
69 typedef void *InstanceHandle;
71 struct ObjectEventEntry {
72 struct ObjectEventEntry *next;
73 xQueueHandle queue;
74 UAVObjEventCallback cb;
75 uint8_t eventMask;
76 bool fast;
80 MetaInstance == [UAVOBase [UAVObjMetadata]]
81 SingleInstance == [UAVOBase [UAVOData [InstanceData]]]
82 MultiInstance == [UAVOBase [UAVOData [NumInstances [InstanceData0 [next]]]]
83 ____________________/
84 \-->[InstanceData1 [next]]
85 _________...________/
86 \-->[InstanceDataN [next]]
90 * UAVO Base Type
91 * - All Types of UAVObjects are of this base type
92 * - The flags determine what type(s) this object
94 struct UAVOBase {
95 /* Let these objects be added to an event queue */
96 struct ObjectEventEntry *next_event;
98 /* Describe the type of object that follows this header */
99 struct UAVOInfo {
100 bool isMeta : 1;
101 bool isSingle : 1;
102 bool isSettings : 1;
103 bool isPriority : 1;
104 } flags;
105 } __attribute__((packed));
107 /* Augmented type for Meta UAVO */
108 struct UAVOMeta {
109 struct UAVOBase base;
110 UAVObjMetadata instance0;
111 } __attribute__((packed));
113 /* Shared data structure for all data-carrying UAVObjects (UAVOSingle and UAVOMulti) */
114 struct UAVOData {
115 struct UAVOBase base;
116 uint32_t id;
118 * Embed the Meta object as another complete UAVO
119 * inside the payload for this UAVO.
121 struct UAVOMeta metaObj;
122 uint16_t instance_size;
123 } __attribute__((packed, aligned(4)));
125 /* Augmented type for Single Instance Data UAVO */
126 struct UAVOSingle {
127 struct UAVOData uavo;
129 uint8_t instance0[];
131 * Additional space will be malloc'd here to hold the
132 * the data for this instance.
134 } __attribute__((packed));
136 /* Part of a linked list of instances chained off of a multi instance UAVO. */
137 struct UAVOMultiInst {
138 struct UAVOMultiInst *next;
139 uint8_t instance[];
141 * Additional space will be malloc'd here to hold the
142 * the data for this instance.
144 } __attribute__((packed));
146 /* Augmented type for Multi Instance Data UAVO */
147 struct UAVOMulti {
148 struct UAVOData uavo;
149 uint16_t num_instances;
150 struct UAVOMultiInst instance0 __attribute__((aligned(4)));
152 * Additional space will be malloc'd here to hold the
153 * the data for instance 0.
155 } __attribute__((packed));
157 /** all information about a metaobject are hardcoded constants **/
158 #define MetaNumBytes sizeof(UAVObjMetadata)
159 #define MetaBaseObjectPtr(obj) ((struct UAVOData *)((obj) - offsetof(struct UAVOData, metaObj)))
160 #define MetaObjectPtr(obj) ((struct UAVODataMeta *)&((obj)->metaObj))
161 #define MetaDataPtr(obj) ((UAVObjMetadata *)&((obj)->instance0))
162 #define LinkedMetaDataPtr(obj) ((UAVObjMetadata *)&((obj)->metaObj.instance0))
164 /** all information about instances are dependant on object type **/
165 #define ObjSingleInstanceDataOffset(obj) ((void *)(&(((struct UAVOSingle *)obj)->instance0)))
166 #define InstanceDataOffset(inst) ((void *)&(((struct UAVOMultiInst *)inst)->instance))
167 #define InstanceData(instance) ((void *)instance)
169 // Private functions
170 int32_t sendEvent(struct UAVOBase *obj, uint16_t instId, UAVObjEventType event);
171 InstanceHandle getInstance(struct UAVOData *obj, uint16_t instId);
173 #endif /* UAVOBJECTPRIVATE_H_ */