update credits
[librepilot.git] / flight / uavobjects / inc / uavobjectprivate.h
blob2177539fddaaa74d1e374202957d9083bf7db61e
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 const UAVObjType *type; /* this contains id, instance_size and data initializer */
118 * Embed the Meta object as another complete UAVO
119 * inside the payload for this UAVO.
121 struct UAVOMeta metaObj;
122 } __attribute__((packed, aligned(4)));
124 /* Augmented type for Single Instance Data UAVO */
125 struct UAVOSingle {
126 struct UAVOData uavo;
128 uint8_t instance0[];
130 * Additional space will be malloc'd here to hold the
131 * the data for this instance.
133 } __attribute__((packed));
135 /* Part of a linked list of instances chained off of a multi instance UAVO. */
136 struct UAVOMultiInst {
137 struct UAVOMultiInst *next;
138 uint8_t instance[];
140 * Additional space will be malloc'd here to hold the
141 * the data for this instance.
143 } __attribute__((packed));
145 /* Augmented type for Multi Instance Data UAVO */
146 struct UAVOMulti {
147 struct UAVOData uavo;
148 uint16_t num_instances;
149 struct UAVOMultiInst instance0 __attribute__((aligned(4)));
151 * Additional space will be malloc'd here to hold the
152 * the data for instance 0.
154 } __attribute__((packed));
156 /** all information about a metaobject are hardcoded constants **/
157 #define MetaNumBytes sizeof(UAVObjMetadata)
158 #define MetaBaseObjectPtr(obj) ((struct UAVOData *)((obj) - offsetof(struct UAVOData, metaObj)))
159 #define MetaObjectPtr(obj) ((struct UAVODataMeta *)&((obj)->metaObj))
160 #define MetaDataPtr(obj) ((UAVObjMetadata *)&((obj)->instance0))
161 #define LinkedMetaDataPtr(obj) ((UAVObjMetadata *)&((obj)->metaObj.instance0))
163 /** all information about instances are dependant on object type **/
164 #define ObjSingleInstanceDataOffset(obj) ((void *)(&(((struct UAVOSingle *)obj)->instance0)))
165 #define InstanceDataOffset(inst) ((void *)&(((struct UAVOMultiInst *)inst)->instance))
166 #define InstanceData(instance) ((void *)instance)
168 // Private functions
169 int32_t sendEvent(struct UAVOBase *obj, uint16_t instId, UAVObjEventType event);
170 InstanceHandle getInstance(struct UAVOData *obj, uint16_t instId);
172 #endif /* UAVOBJECTPRIVATE_H_ */