Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A24EC200B2D for ; Thu, 16 Jun 2016 23:03:36 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id A0EE7160A51; Thu, 16 Jun 2016 21:03:36 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C12DB1602C5 for ; Thu, 16 Jun 2016 23:03:35 +0200 (CEST) Received: (qmail 731 invoked by uid 500); 16 Jun 2016 21:03:34 -0000 Mailing-List: contact commits-help@mynewt.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mynewt.incubator.apache.org Delivered-To: mailing list commits@mynewt.incubator.apache.org Received: (qmail 722 invoked by uid 99); 16 Jun 2016 21:03:34 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Jun 2016 21:03:34 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 7AA671A042F for ; Thu, 16 Jun 2016 21:03:34 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.646 X-Spam-Level: X-Spam-Status: No, score=-4.646 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id m4V4Y4QYAm6n for ; Thu, 16 Jun 2016 21:03:33 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 23FD75F297 for ; Thu, 16 Jun 2016 21:03:31 +0000 (UTC) Received: (qmail 715 invoked by uid 99); 16 Jun 2016 21:03:31 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Jun 2016 21:03:31 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1E28AE009D; Thu, 16 Jun 2016 21:03:31 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sterling@apache.org To: commits@mynewt.incubator.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: incubator-mynewt-core git commit: initial device infrastructure. holding commit for drivers Date: Thu, 16 Jun 2016 21:03:31 +0000 (UTC) archived-at: Thu, 16 Jun 2016 21:03:36 -0000 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 Authored: Thu Jun 16 14:03:16 2016 -0700 Committer: Sterling Hughes 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 + +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); +} + +