mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-06 21:54:15 +01:00
uavobjectmanager: remove linked list for UAVOs
This commit is contained in:
parent
e5c54cca00
commit
c1fc605696
@ -41,6 +41,17 @@
|
|||||||
// Macros
|
// Macros
|
||||||
#define SET_BITS(var, shift, value, mask) var = (var & ~(mask << shift)) | (value << shift);
|
#define SET_BITS(var, shift, value, mask) var = (var & ~(mask << shift)) | (value << shift);
|
||||||
|
|
||||||
|
/* Table of UAVO handles registered at compile time */
|
||||||
|
extern struct UAVOData * __start__uavo_handles __attribute__((weak));
|
||||||
|
extern struct UAVOData * __stop__uavo_handles __attribute__((weak));
|
||||||
|
|
||||||
|
#define UAVO_LIST_ITERATE(_item) \
|
||||||
|
for (struct UAVOData ** _uavo_slot = &__start__uavo_handles; \
|
||||||
|
_uavo_slot <= &__stop__uavo_handles; \
|
||||||
|
_uavo_slot++) { \
|
||||||
|
struct UAVOData * _item = *_uavo_slot; \
|
||||||
|
if (_item == NULL) continue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of event queues and the eventmask associated with the queue.
|
* List of event queues and the eventmask associated with the queue.
|
||||||
*/
|
*/
|
||||||
@ -98,7 +109,6 @@ struct UAVOData {
|
|||||||
* inside the payload for this UAVO.
|
* inside the payload for this UAVO.
|
||||||
*/
|
*/
|
||||||
struct UAVOMeta metaObj;
|
struct UAVOMeta metaObj;
|
||||||
struct UAVOData * next;
|
|
||||||
uint16_t instance_size;
|
uint16_t instance_size;
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
@ -164,7 +174,6 @@ static void customSPrintf(uint8_t * buffer, uint8_t * format, ...);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Private variables
|
// Private variables
|
||||||
static struct UAVOData * uavo_list;
|
|
||||||
static xSemaphoreHandle mutex;
|
static xSemaphoreHandle mutex;
|
||||||
static const UAVObjMetadata defMetadata = {
|
static const UAVObjMetadata defMetadata = {
|
||||||
.flags = (ACCESS_READWRITE << UAVOBJ_ACCESS_SHIFT |
|
.flags = (ACCESS_READWRITE << UAVOBJ_ACCESS_SHIFT |
|
||||||
@ -188,7 +197,6 @@ static UAVObjStats stats;
|
|||||||
int32_t UAVObjInitialize()
|
int32_t UAVObjInitialize()
|
||||||
{
|
{
|
||||||
// Initialize variables
|
// Initialize variables
|
||||||
uavo_list = NULL;
|
|
||||||
memset(&stats, 0, sizeof(UAVObjStats));
|
memset(&stats, 0, sizeof(UAVObjStats));
|
||||||
|
|
||||||
// Create mutex
|
// Create mutex
|
||||||
@ -338,9 +346,6 @@ UAVObjHandle UAVObjRegister(uint32_t id,
|
|||||||
/* Initialize the embedded meta UAVO */
|
/* Initialize the embedded meta UAVO */
|
||||||
UAVObjInitMetaData (&uavo_data->metaObj);
|
UAVObjInitMetaData (&uavo_data->metaObj);
|
||||||
|
|
||||||
/* Add the newly created object to the global list of objects */
|
|
||||||
LL_APPEND(uavo_list, uavo_data);
|
|
||||||
|
|
||||||
/* Initialize object fields and metadata to default values */
|
/* Initialize object fields and metadata to default values */
|
||||||
if (initCb)
|
if (initCb)
|
||||||
initCb((UAVObjHandle) uavo_data, 0);
|
initCb((UAVObjHandle) uavo_data, 0);
|
||||||
@ -374,8 +379,7 @@ UAVObjHandle UAVObjGetByID(uint32_t id)
|
|||||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||||
|
|
||||||
// Look for object
|
// Look for object
|
||||||
struct UAVOData * tmp_obj;
|
UAVO_LIST_ITERATE(tmp_obj)
|
||||||
LL_FOREACH(uavo_list, tmp_obj) {
|
|
||||||
if (tmp_obj->id == id) {
|
if (tmp_obj->id == id) {
|
||||||
found_obj = (UAVObjHandle *)tmp_obj;
|
found_obj = (UAVObjHandle *)tmp_obj;
|
||||||
goto unlock_exit;
|
goto unlock_exit;
|
||||||
@ -1019,15 +1023,13 @@ int32_t UAVObjDelete(UAVObjHandle obj_handle, uint16_t instId)
|
|||||||
*/
|
*/
|
||||||
int32_t UAVObjSaveSettings()
|
int32_t UAVObjSaveSettings()
|
||||||
{
|
{
|
||||||
struct UAVOData *obj;
|
|
||||||
|
|
||||||
// Get lock
|
// Get lock
|
||||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||||
|
|
||||||
int32_t rc = -1;
|
int32_t rc = -1;
|
||||||
|
|
||||||
// Save all settings objects
|
// Save all settings objects
|
||||||
LL_FOREACH(uavo_list, obj) {
|
UAVO_LIST_ITERATE(obj)
|
||||||
// Check if this is a settings object
|
// Check if this is a settings object
|
||||||
if (UAVObjIsSettings(obj)) {
|
if (UAVObjIsSettings(obj)) {
|
||||||
// Save object
|
// Save object
|
||||||
@ -1051,15 +1053,13 @@ unlock_exit:
|
|||||||
*/
|
*/
|
||||||
int32_t UAVObjLoadSettings()
|
int32_t UAVObjLoadSettings()
|
||||||
{
|
{
|
||||||
struct UAVOData *obj;
|
|
||||||
|
|
||||||
// Get lock
|
// Get lock
|
||||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||||
|
|
||||||
int32_t rc = -1;
|
int32_t rc = -1;
|
||||||
|
|
||||||
// Load all settings objects
|
// Load all settings objects
|
||||||
LL_FOREACH(uavo_list, obj) {
|
UAVO_LIST_ITERATE(obj)
|
||||||
// Check if this is a settings object
|
// Check if this is a settings object
|
||||||
if (UAVObjIsSettings(obj)) {
|
if (UAVObjIsSettings(obj)) {
|
||||||
// Load object
|
// Load object
|
||||||
@ -1083,15 +1083,13 @@ unlock_exit:
|
|||||||
*/
|
*/
|
||||||
int32_t UAVObjDeleteSettings()
|
int32_t UAVObjDeleteSettings()
|
||||||
{
|
{
|
||||||
struct UAVOData *obj;
|
|
||||||
|
|
||||||
// Get lock
|
// Get lock
|
||||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||||
|
|
||||||
int32_t rc = -1;
|
int32_t rc = -1;
|
||||||
|
|
||||||
// Save all settings objects
|
// Save all settings objects
|
||||||
LL_FOREACH(uavo_list, obj) {
|
UAVO_LIST_ITERATE(obj)
|
||||||
// Check if this is a settings object
|
// Check if this is a settings object
|
||||||
if (UAVObjIsSettings(obj)) {
|
if (UAVObjIsSettings(obj)) {
|
||||||
// Save object
|
// Save object
|
||||||
@ -1115,15 +1113,13 @@ unlock_exit:
|
|||||||
*/
|
*/
|
||||||
int32_t UAVObjSaveMetaobjects()
|
int32_t UAVObjSaveMetaobjects()
|
||||||
{
|
{
|
||||||
struct UAVOData *obj;
|
|
||||||
|
|
||||||
// Get lock
|
// Get lock
|
||||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||||
|
|
||||||
int32_t rc = -1;
|
int32_t rc = -1;
|
||||||
|
|
||||||
// Save all settings objects
|
// Save all settings objects
|
||||||
LL_FOREACH(uavo_list, obj) {
|
UAVO_LIST_ITERATE(obj)
|
||||||
// Save object
|
// Save object
|
||||||
if (UAVObjSave( (UAVObjHandle) MetaObjectPtr(obj), 0) ==
|
if (UAVObjSave( (UAVObjHandle) MetaObjectPtr(obj), 0) ==
|
||||||
-1) {
|
-1) {
|
||||||
@ -1144,15 +1140,13 @@ unlock_exit:
|
|||||||
*/
|
*/
|
||||||
int32_t UAVObjLoadMetaobjects()
|
int32_t UAVObjLoadMetaobjects()
|
||||||
{
|
{
|
||||||
struct UAVOData *obj;
|
|
||||||
|
|
||||||
// Get lock
|
// Get lock
|
||||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||||
|
|
||||||
int32_t rc = -1;
|
int32_t rc = -1;
|
||||||
|
|
||||||
// Load all settings objects
|
// Load all settings objects
|
||||||
LL_FOREACH(uavo_list, obj) {
|
UAVO_LIST_ITERATE(obj)
|
||||||
// Load object
|
// Load object
|
||||||
if (UAVObjLoad((UAVObjHandle) MetaObjectPtr(obj), 0) ==
|
if (UAVObjLoad((UAVObjHandle) MetaObjectPtr(obj), 0) ==
|
||||||
-1) {
|
-1) {
|
||||||
@ -1173,15 +1167,13 @@ unlock_exit:
|
|||||||
*/
|
*/
|
||||||
int32_t UAVObjDeleteMetaobjects()
|
int32_t UAVObjDeleteMetaobjects()
|
||||||
{
|
{
|
||||||
struct UAVOData *obj;
|
|
||||||
|
|
||||||
// Get lock
|
// Get lock
|
||||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||||
|
|
||||||
int32_t rc = -1;
|
int32_t rc = -1;
|
||||||
|
|
||||||
// Load all settings objects
|
// Load all settings objects
|
||||||
LL_FOREACH(uavo_list, obj) {
|
UAVO_LIST_ITERATE(obj)
|
||||||
// Load object
|
// Load object
|
||||||
if (UAVObjDelete((UAVObjHandle) MetaObjectPtr(obj), 0)
|
if (UAVObjDelete((UAVObjHandle) MetaObjectPtr(obj), 0)
|
||||||
== -1) {
|
== -1) {
|
||||||
@ -1787,8 +1779,7 @@ void UAVObjIterate(void (*iterator) (UAVObjHandle obj))
|
|||||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||||
|
|
||||||
// Iterate through the list and invoke iterator for each object
|
// Iterate through the list and invoke iterator for each object
|
||||||
struct UAVOData *obj;
|
UAVO_LIST_ITERATE(obj)
|
||||||
LL_FOREACH(uavo_list, obj) {
|
|
||||||
(*iterator) ((UAVObjHandle) obj);
|
(*iterator) ((UAVObjHandle) obj);
|
||||||
(*iterator) ((UAVObjHandle) &obj->metaObj);
|
(*iterator) ((UAVObjHandle) &obj->metaObj);
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
#include "$(NAMELC).h"
|
#include "$(NAMELC).h"
|
||||||
|
|
||||||
// Private variables
|
// Private variables
|
||||||
static UAVObjHandle handle = NULL;
|
static UAVObjHandle handle __attribute__((section("_uavo_handles")));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize object.
|
* Initialize object.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user