39 #include "pios_struct_helper.h"
53 #define SET_BITS(var, shift, value, mask) var = (var & ~(mask << shift)) | (value << shift);
163 #define MetaNumBytes sizeof(UAVObjMetadata)
166 #define MetaBaseObjectPtr(obj) ((struct UAVOData *)((obj)-offsetof(struct UAVOData, metaObj)))
168 #define MetaObjectPtr(obj) (&((obj)->metaObj.base))
169 #define MetaDataPtr(obj) ((UAVObjMetadata*)&((obj)->instance0))
170 #define LinkedMetaDataPtr(obj) ((UAVObjMetadata*)&((obj)->metaObj.instance0))
171 #define MetaObjectId(id) ((id)+1)
174 #define ObjSingleInstanceDataOffset(obj) ((void*)(&(( (struct UAVOSingle*)obj )->instance0)))
175 #define InstanceDataOffset(inst) ((void*)&(( (struct UAVOMultiInst*)inst )->instance))
176 #define InstanceData(instance) (void*)instance
201 .telemetryUpdatePeriod = 0,
202 .gcsTelemetryUpdatePeriod = 0,
203 .loggingUpdatePeriod = 0,
209 #define UAVO_CB_STACK_SIZE 512
222 events_unused = NULL;
223 events_unused_throttled = NULL;
276 memset(uavo_base, 0,
sizeof(*uavo_base));
288 uint32_t object_size =
sizeof(
struct UAVOSingle) + num_bytes;
297 memset(uavo_base, 0,
sizeof(*uavo_base));
302 memset(&(uavo_single->
instance0), 0, num_bytes);
305 return (&(uavo_single->
uavo));
311 uint32_t object_size =
sizeof(
struct UAVOMulti) + num_bytes;
320 memset(uavo_base, 0,
sizeof(*uavo_base));
332 return (&(uavo_multi->
uavo));
350 int32_t isSingleInstance, int32_t isSettings,
363 if (isSingleInstance) {
420 if (tmp_obj->
id ==
id) {
421 found_obj = &tmp_obj->
base;
456 return (uavo_data->
id);
483 return (instance_size);
554 if (instEntry == NULL) {
560 initCb(obj_handle, instId);
619 const uint8_t * dataIn)
644 obj = (
struct UAVOData *) obj_handle;
650 if (instEntry == NULL) {
652 if (instEntry == NULL) {
662 memcpy(target, dataIn, len);
701 obj = (
struct UAVOData *) obj_handle;
705 if (instEntry == NULL) {
719 #if defined(PIOS_INCLUDE_FASTHEAP)
726 static uint8_t uavobj_save_trampoline[256]
__attribute__((aligned(4)));
749 #if defined(PIOS_INCLUDE_FASTHEAP)
750 memcpy(uavobj_save_trampoline,
757 uavobj_save_trampoline,
772 if (instEntry == NULL)
780 #if defined(PIOS_INCLUDE_FASTHEAP)
781 memcpy(uavobj_save_trampoline,
788 uavobj_save_trampoline,
805 #if defined(PIOS_INCLUDE_FASTHEAP)
812 static uint8_t uavobj_load_trampoline[256]
__attribute__((aligned(4)));
840 if (instEntry == NULL)
849 #if defined(PIOS_INCLUDE_FASTHEAP)
853 uavobj_load_trampoline,
866 #if defined(PIOS_INCLUDE_FASTHEAP)
867 memcpy(target, uavobj_load_trampoline, len);
1114 #define INSTANCE_COPY_ALL 0xffffffff
1163 obj = (
struct UAVOData *)obj_handle;
1172 if (instEntry == NULL) {
1186 if ((size + offset) > obj_len) {
1192 memcpy(target + offset, dataIn, size);
1233 obj = (
struct UAVOData *) obj_handle;
1237 if (instEntry == NULL) {
1285 obj = (
struct UAVOData *)obj_handle;
1289 if (instEntry == NULL) {
1299 memcpy(dataOut,
InstanceData(instEntry) + offset, size);
1347 memcpy(dataOut, &defMetadata,
sizeof(UAVObjMetadata));
1519 res =
connectObj(obj_handle, queue, NULL, NULL, eventMask, interval);
1525 uint8_t eventMask) {
1562 volatile uint8_t *
flag = ctx;
1581 memcpy(ctx, obj, len);
1594 void *cbCtx, uint8_t eventMask, uint16_t interval)
1599 res =
connectObj(obj_handle, 0, cb, cbCtx, eventMask, interval);
1605 void *cbCtx, uint8_t eventMask)
1679 const
UAVObjEvent *msg,
void *obj_data,
int len) {
1680 event->cb(msg, event->cbInfo.cbCtx, obj_data, len);
1683 #if (!defined(FLIGHT_POSIX)) && defined(__arm__)
1685 const UAVObjEvent *msg,
void *obj_data,
int len) {
1691 register const UAVObjEvent *my_msg
asm(
"r1") = msg;
1692 register void *my_obj_data
asm(
"r2") = obj_data;
1693 register int my_len
asm(
"r3") = len;
1700 "bl realInvokeCallback\n\t"
1706 "+r" (my_event),
"+r" (my_msg),
"+r" (my_obj_data),
1715 "r4",
"r5",
"ip",
"lr"
1717 ,
"s0",
"s1",
"s2",
"s3",
"s4",
"s5",
"s6",
"s7",
1718 "s8",
"s9",
"s10",
"s11",
"s12",
"s13",
"s14",
"s15"
1722 #define invokeCallback realInvokeCallback
1789 void *obj_data,
int len)
1791 static uint8_t num_pending = 0;
1793 static struct PendEvent {
1797 } pending_events[3];
1821 if (num_pending >= 3) {
1829 static struct UAVOBase *in_progress = NULL;
1832 if (in_progress == obj) {
1841 .event = triggered_event,
1845 pending_events[num_pending].obj_data = obj_data;
1846 pending_events[num_pending].len = len;
1853 while (num_pending) {
1859 in_progress = pending_events[num_pending].msg.obj;
1863 pending_events[num_pending].obj_data,
1864 pending_events[num_pending].len);
1910 ( (
struct UAVOMulti*)obj )->num_instances++;
1916 if (newUavObjInstanceCB) {
1957 if (instance++ == instId) {
1989 obj = (
struct UAVOBase *) obj_handle;
1994 event->eventMask = eventMask;
1996 if (interval == 0) {
1997 event->hasThrottle = 0;
2006 if (interval == 0) {
2020 int mallocSize =
sizeof(*event);
2024 mallocSize =
sizeof(*throttled);
2029 if (*unused != NULL) {
2036 if (event == NULL) {
2043 memset(event, 0, mallocSize);
2047 event->cbInfo.queue =
queue;
2049 event->cbInfo.cbCtx =
cbCtx;
2053 event->hasThrottle = 0;
2056 event->hasThrottle = 1;
2083 obj = (
struct UAVOBase *) obj_handle;
2091 LL_APPEND(events_unused_throttled, event);
2120 obj = (
struct UAVOBase *) obj_handle;
2124 eventMask =
event->eventMask;
2196 newUavObjInstanceCB = callback;
int32_t UAVObjSaveMetaobjects()
void UAVObjSetTelemetryAcked(UAVObjMetadata *metadata, uint8_t val)
static int32_t sendEvent(struct UAVOBase *obj, uint16_t instId, UAVObjEventType event, void *obj_data, int len)
uint32_t UAVObjIDByIndex(uint8_t index)
#define LL_FOREACH(head, el)
uint32_t PIOS_Thread_Systime(void)
uint16_t UAVObjCreateInstance(UAVObjHandle obj_handle, UAVObjInitializeCallback initCb)
void UAVObjSetTelemetryUpdateMode(UAVObjMetadata *metadata, UAVObjUpdateMode val)
uint32_t lastCallbackErrorID
static struct UAVOData * uavo_list
struct pios_queue * queue
UAVObjHandle UAVObjGetByID(uint32_t id)
int32_t UAVObjSetInstanceData(UAVObjHandle obj_handle, uint16_t instId, const void *dataIn)
static int32_t disconnectObj(UAVObjHandle obj_handle, struct pios_queue *queue, UAVObjEventCallback cb, void *cbCtx)
bool UAVObjIsMetaobject(UAVObjHandle obj_handle)
int32_t UAVObjDisconnectQueue(UAVObjHandle obj_handle, struct pios_queue *queue)
static struct pios_recursive_mutex * mutex
UAVObjUpdateMode UAVObjGetGcsTelemetryUpdateMode(const UAVObjMetadata *metadata)
bool UAVObjIsSettings(UAVObjHandle obj_handle)
#define LinkedMetaDataPtr(obj)
struct UAVOBase::UAVOInfo flags
#define UAVOBJ_GCS_TELEMETRY_UPDATE_MODE_SHIFT
int32_t UAVObjLoadSettings()
int32_t UAVObjUnpack(UAVObjHandle obj_handle, uint16_t instId, const uint8_t *dataIn)
int32_t UAVObjSaveSettings()
uint32_t UAVObjGetNumBytes(UAVObjHandle obj)
#define UAVOBJ_ALL_INSTANCES
#define UAVO_CB_STACK_SIZE
int32_t UAVObjPack(UAVObjHandle obj_handle, uint16_t instId, uint8_t *dataOut)
int32_t UAVObjConnectCallbackThrottled(UAVObjHandle obj_handle, UAVObjEventCallback cb, void *cbCtx, uint8_t eventMask, uint16_t interval)
bool PIOS_Queue_Send(struct pios_queue *queuep, const void *itemp, uint32_t timeout_ms)
static void UAVObjInitMetaData(struct UAVOMeta *obj_meta)
uintptr_t pios_uavo_settings_fs_id
void UAVObjCbSetFlag(const UAVObjEvent *objEv, void *ctx, void *obj, int len)
UAVObjAccessType UAVObjGetGcsAccess(const UAVObjMetadata *metadata)
int32_t UAVObjSave(UAVObjHandle obj_handle, uint16_t instId)
int32_t UAVObjConnectQueueThrottled(UAVObjHandle obj_handle, struct pios_queue *queue, uint8_t eventMask, uint16_t interval)
uint32_t eventQueueErrors
static InstanceHandle getInstance(struct UAVOData *obj, uint16_t instId)
UAVObjAccessType UAVObjGetAccess(const UAVObjMetadata *metadata)
#define InstanceDataOffset(inst)
void * PIOS_malloc_no_dma(size_t size)
int32_t UAVObjSetDataField(UAVObjHandle obj_handle, const void *dataIn, uint32_t offset, uint32_t size)
uint32_t lastQueueErrorID
void UAVObjGetStats(UAVObjStats *statsOut)
uint8_t UAVObjGetTelemetryAcked(const UAVObjMetadata *metadata)
void UAVObjSetGcsTelemetryUpdateMode(UAVObjMetadata *metadata, UAVObjUpdateMode val)
int32_t UAVObjGetInstanceDataField(UAVObjHandle obj_handle, uint16_t instId, void *dataOut, uint32_t offset, uint32_t size)
struct pios_recursive_mutex * PIOS_Recursive_Mutex_Create(void)
static struct ObjectEventEntry * events_unused
uint8_t UAVObjGetGcsTelemetryAcked(const UAVObjMetadata *metadata)
struct UAVOMultiInst instance0
uint32_t UAVObjGetID(UAVObjHandle obj_handle)
int32_t PIOS_FLASHFS_ObjDelete(uintptr_t fs_id, uint32_t obj_id, uint16_t obj_inst_id)
Delete one instance of an object from the filesystem.
bool UAVObjIsSingleInstance(UAVObjHandle obj_handle)
#define UAVOBJ_GCS_ACCESS_SHIFT
#define SET_BITS(var, shift, value, mask)
bool PIOS_Recursive_Mutex_Lock(struct pios_recursive_mutex *mtx, uint32_t timeout_ms)
struct ObjectEventEntry entry
static struct UAVOData * UAVObjAllocSingle(uint32_t num_bytes)
static int32_t connectObj(UAVObjHandle obj_handle, struct pios_queue *queue, UAVObjEventCallback cb, void *cbCtx, uint8_t eventMask, uint16_t interval)
static struct ObjectEventEntry * events_unused_throttled
#define InstanceData(instance)
int32_t UAVObjGetInstanceData(UAVObjHandle obj_handle, uint16_t instId, void *dataOut)
#define LL_APPEND(head, add)
void UAVObjInstanceUpdated(UAVObjHandle obj_handle, uint16_t instId)
uint32_t randomize_int(uint32_t interval)
static struct UAVOData * UAVObjAllocMulti(uint32_t num_bytes)
void(* UAVObjInitializeCallback)(UAVObjHandle obj_handle, uint16_t instId)
UAVObjUpdateMode UAVObjGetTelemetryUpdateMode(const UAVObjMetadata *metadata)
int32_t UAVObjConnectCallback(UAVObjHandle obj_handle, UAVObjEventCallback cb, void *cbCtx, uint8_t eventMask)
int32_t UAVObjSetInstanceDataField(UAVObjHandle obj_handle, uint16_t instId, const void *dataIn, uint32_t offset, uint32_t size)
void UAVObjUnblockThrottle(struct ObjectEventEntryThrottled *throttled)
bool PIOS_Thread_Period_Elapsed(const uint32_t prev_systime, const uint32_t increment_ms)
Determine if a period has elapsed since a datum.
static int32_t pumpOneEvent(UAVObjEvent *msg, void *obj_data, int len)
struct UAVOMultiInst * next
struct UAVOBase * UAVObjHandle
int32_t UAVObjDeleteById(uint32_t obj_id, uint16_t inst_id)
static InstanceHandle createInstance(struct UAVOData *obj, uint16_t instId)
#define UAVOBJ_GCS_TELEMETRY_ACKED_SHIFT
int32_t UAVObjSetMetadata(UAVObjHandle obj_handle, const UAVObjMetadata *dataIn)
void(* UAVObjEventCallback)(const UAVObjEvent *ev, void *cb_ctx, void *uavo_data, int uavo_len)
void UAVObjCbCopyData(const UAVObjEvent *objEv, void *ctx, void *obj, int len)
#define container_of(ptr, type, member)
int32_t UAVObjConnectQueue(UAVObjHandle obj_handle, struct pios_queue *queue, uint8_t eventMask)
#define UAVOBJ_TELEMETRY_UPDATE_MODE_SHIFT
int32_t PIOS_FLASHFS_ObjSave(uintptr_t fs_id, uint32_t obj_id, uint16_t obj_inst_id, uint8_t *obj_data, uint16_t obj_size)
Saves one object instance to the filesystem.
int32_t getEventMask(UAVObjHandle obj_handle, struct pios_queue *queue)
int32_t UAVObjLoadMetaobjects()
int32_t UAVObjGetMetadata(UAVObjHandle obj_handle, UAVObjMetadata *dataOut)
int32_t PIOS_FLASHFS_ObjLoad(uintptr_t fs_id, uint32_t obj_id, uint16_t obj_inst_id, uint8_t *obj_data, uint16_t obj_size)
Load one object instance from the filesystem.
union ObjectEventEntry::@25 cbInfo
void UAVObjSetGcsTelemetryAcked(UAVObjMetadata *metadata, uint8_t val)
UAVObjHandle UAVObjGetLinkedObj(UAVObjHandle obj_handle)
uint32_t eventCallbackErrors
void UAVObjUpdated(UAVObjHandle obj_handle)
#define LL_DELETE(head, del)
#define UAVOBJ_TELEMETRY_ACKED_SHIFT
static const UAVObjMetadata defMetadata
Includes PiOS and core architecture components.
uint16_t UAVObjGetNumInstances(UAVObjHandle obj_handle)
int32_t UAVObjDeleteMetaobjects()
void(* new_uavo_instance_cb_t)(uint32_t, uint32_t)
#define UAVOBJ_UPDATE_MODE_MASK
volatile uint8_t inhibited
int8_t UAVObjReadOnly(UAVObjHandle obj_handle)
int32_t UAVObjLoad(UAVObjHandle obj_handle, uint16_t instId)
int32_t UAVObjSetData(UAVObjHandle obj_handle, const void *dataIn)
static struct pios_queue * queue
int32_t UAVObjInitialize()
int32_t UAVObjGetData(UAVObjHandle obj_handle, void *dataOut)
#define INSTANCE_COPY_ALL
#define UAVOBJ_ACCESS_SHIFT
static new_uavo_instance_cb_t newUavObjInstanceCB
UAVObjHandle UAVObjRegister(uint32_t id, int32_t isSingleInstance, int32_t isSettings, uint32_t num_bytes, UAVObjInitializeCallback initCb)
struct ObjectEventEntryThrottled * throttle
void UAVObjRegisterNewInstanceCB(new_uavo_instance_cb_t callback)
#define PIOS_Assert(test)
int32_t UAVObjGetDataField(UAVObjHandle obj_handle, void *dataOut, uint32_t offset, uint32_t size)
struct ObjectEventEntry * next
#define UAVOBJ_MAX_INSTANCES
bool PIOS_Recursive_Mutex_Unlock(struct pios_recursive_mutex *mtx)
struct UAVOBase __attribute__((packed))
#define MetaObjectPtr(obj)
void UAVObjSetGcsAccess(UAVObjMetadata *metadata, UAVObjAccessType mode)
struct ObjectEventEntry * next_event
#define PIOS_MUTEX_TIMEOUT_MAX
int32_t UAVObjDisconnectCallback(UAVObjHandle obj_handle, UAVObjEventCallback cb, void *cbCtx)
void UAVObjSetAccess(UAVObjMetadata *metadata, UAVObjAccessType mode)
void UAVObjIterate(void(*iterator)(UAVObjHandle obj))
int32_t UAVObjDeleteSettings()