mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sterl...@apache.org
Subject incubator-mynewt-core git commit: initial device infrastructure. holding commit for drivers
Date Thu, 16 Jun 2016 21:03:31 GMT
Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/drivers_hal_refactor [created] ec982935a


initial device infrastructure.  holding commit for drivers


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/ec982935
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ec982935
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ec982935

Branch: refs/heads/drivers_hal_refactor
Commit: ec982935a0f8209a44fc9bd3d344beaaabc612fa
Parents: 6ed23d2
Author: Sterling Hughes <sterling@apache.org>
Authored: Thu Jun 16 14:03:16 2016 -0700
Committer: Sterling Hughes <sterling@apache.org>
Committed: Thu Jun 16 14:03:16 2016 -0700

----------------------------------------------------------------------
 libs/os/include/os/os_dev.h | 57 ++++++++++++++++++++++++
 libs/os/src/os_dev.c        | 95 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 152 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ec982935/libs/os/include/os/os_dev.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_dev.h b/libs/os/include/os/os_dev.h
new file mode 100644
index 0000000..a06ff2c
--- /dev/null
+++ b/libs/os/include/os/os_dev.h
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _OS_DEV_H
+#define _OS_DEV_H
+
+#include "os/queue.h"
+
+/*
+ * Initialization order, defines when a device should be initialized
+ * by the Mynewt kernel.
+ *
+ */
+#define OS_DEV_INIT_PRIMARY   (1)
+#define OS_DEV_INIT_SECONDARY (2)
+#define OS_DEV_INIT_KERNEL    (3)
+
+typedef int (*os_dev_init_func_t)(void *arg);
+
+#define OS_DEV_INIT_F_CRITICAL (1 << 0)
+
+/*
+ * Device structure.
+ *
+ */
+struct os_dev {
+    char *od_name;
+    uint8_t od_stage;
+    uint8_t od_priority;
+    uint8_t od_init_flags;
+    uint8_t __pad1;
+    void *od_arg;
+    os_dev_init_func_t od_init;
+    STAILQ_ENTRY(os_dev) od_next;
+};
+
+int os_dev_add(struct os_dev *);
+int os_dev_init(uint8_t stage);
+struct os_dev *os_dev_lookup(char *name);
+
+#endif /* _OS_DEV_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ec982935/libs/os/src/os_dev.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_dev.c b/libs/os/src/os_dev.c
new file mode 100644
index 0000000..12b0aa8
--- /dev/null
+++ b/libs/os/src/os_dev.c
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "os/os.h"
+#include "os/queue.h"
+#include "os/os_dev.h"
+
+#include <string.h>
+
+static STAILQ_HEAD(, os_dev) g_os_dev_list;
+
+/**
+ * Add this device to the kernel.  This function adds the
+ * device to the OS
+ */
+int
+os_dev_add(struct os_dev *dev)
+{
+    struct os_dev *cur_dev;
+
+    /* Add devices to the list, sorted first by stage, then by
+     * priority.
+     */
+    cur_dev = NULL;
+    STAILQ_FOREACH(cur_dev, &g_os_dev_list, od_next) {
+        if (cur_dev->od_stage > dev->od_stage) {
+            continue;
+        }
+
+        if (dev->od_priority >= cur_dev->od_priority) {
+            break;
+        }
+    }
+
+    if (cur_dev) {
+        STAILQ_INSERT_AFTER(&g_os_dev_list, cur_dev, dev, od_next);
+    } else {
+        STAILQ_INSERT_TAIL(&g_os_dev_list, dev, od_next);
+    }
+
+    return (0);
+}
+
+int
+os_dev_init(uint8_t stage)
+{
+    struct os_dev *dev;
+    int rc;
+
+    STAILQ_FOREACH(dev, &g_os_dev_list, od_next) {
+        if (dev->od_stage == stage) {
+            rc = dev->od_init(dev->od_arg);
+            if (dev->od_init_flags & OS_DEV_INIT_F_CRITICAL &&
+                    rc != 0) {
+                goto err;
+            }
+        }
+    }
+
+    return (0);
+err:
+    return (rc);
+}
+
+struct os_dev *
+os_dev_lookup(char *name)
+{
+    struct os_dev *dev;
+
+    dev = NULL;
+    STAILQ_FOREACH(dev, &g_os_dev_list, od_next) {
+        if (!strcmp(dev->od_name, name)) {
+            break;
+        }
+    }
+    return (dev);
+}
+
+


Mime
View raw message