Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 12ef82c64 -> 8dffea7d0


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/sys/reboot/src/log_reboot.c
----------------------------------------------------------------------
diff --git a/sys/reboot/src/log_reboot.c b/sys/reboot/src/log_reboot.c
index 470d300..c7c3bbe 100644
--- a/sys/reboot/src/log_reboot.c
+++ b/sys/reboot/src/log_reboot.c
@@ -17,23 +17,21 @@
  * under the License.
  */
 
-#include <os/os.h>
-#include <fcb/fcb.h>
-#include <console/console.h>
-#include "log/log.h"
-#include <bootutil/image.h>
-#include <bootutil/bootutil_misc.h>
-#include <imgmgr/imgmgr.h>
 #include <string.h>
-#include <config/config.h>
-#include <config/config_file.h>
-#include <reboot/log_reboot.h>
-#include <bsp/bsp.h>
 #include <assert.h>
-
-#ifdef SHELL_PRESENT
-#include <shell/shell.h>
-#endif
+#include "sysinit/sysinit.h"
+#include "syscfg/syscfg.h"
+#include "os/os.h"
+#include "fcb/fcb.h"
+#include "console/console.h"
+#include "log/log.h"
+#include "bootutil/image.h"
+#include "bootutil/bootutil_misc.h"
+#include "imgmgr/imgmgr.h"
+#include "config/config.h"
+#include "config/config_file.h"
+#include "reboot/log_reboot.h"
+#include "bsp/bsp.h"
 
 static struct log_handler reboot_log_handler;
 static struct fcb fcb;
@@ -202,3 +200,17 @@ reboot_cnt_set(int argc, char **argv, char *val)
 err:
     return OS_ENOENT;
 }
+
+void
+log_reboot_pkg_init(void)
+{
+    int rc;
+
+    (void)rc;
+
+#if MYNEWT_VAL(REBOOT_LOG_0_TYPE)
+    rc = reboot_init_handler(MYNEWT_VAL(REBOOT_LOG_0_TYPE),
+                             MYNEWT_VAL(REBOOT_LOG_0_ENTRY_COUNT));
+    SYSINIT_PANIC_ASSERT(rc == 0);
+#endif
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/sys/stats/include/stats/stats.h
----------------------------------------------------------------------
diff --git a/sys/stats/include/stats/stats.h b/sys/stats/include/stats/stats.h
index 078b99a..7e5811e 100644
--- a/sys/stats/include/stats/stats.h
+++ b/sys/stats/include/stats/stats.h
@@ -19,8 +19,9 @@
 #ifndef __UTIL_STATS_H__ 
 #define __UTIL_STATS_H__ 
 
-#include <os/queue.h>
 #include <stdint.h>
+#include "syscfg/syscfg.h"
+#include "os/queue.h"
 
 struct stats_name_map {
     uint16_t snm_off;
@@ -32,7 +33,7 @@ struct stats_hdr {
     uint8_t s_size;
     uint8_t s_cnt;
     uint16_t s_pad1;
-#ifdef STATS_NAME_ENABLE
+#if MYNEWT_VAL(STATS_NAMES)
     struct stats_name_map *s_map;
     int s_map_cnt;
 #endif
@@ -72,7 +73,7 @@ STATS_SECT_DECL(__name) {                   \
 #define STATS_INCN(__sectvarname, __var, __n)  \
     ((__sectvarname).STATS_SECT_VAR(__var) += (__n))
 
-#ifdef STATS_NAME_ENABLE
+#if MYNEWT_VAL(STATS_NAMES)
 
 #define STATS_NAME_MAP_NAME(__sectname) g_stats_map_ ## __sectname
 
@@ -90,17 +91,16 @@ struct stats_name_map STATS_NAME_MAP_NAME(__sectname)[] = {
     &(STATS_NAME_MAP_NAME(__name)[0]),                                      \
     (sizeof(STATS_NAME_MAP_NAME(__name)) / sizeof(struct stats_name_map))
 
-#else /* STATS_NAME_ENABLE */
+#else /* MYNEWT_VAL(STATS_NAME) */
 
 #define STATS_NAME_START(__name)
 #define STATS_NAME(__name, __entry)
 #define STATS_NAME_END(__name)
 #define STATS_NAME_INIT_PARMS(__name) NULL, 0
 
-#endif /* STATS_NAME_ENABLE */
+#endif /* MYNEWT_VAL(STATS_NAME) */
 
-int stats_module_init(void);
-void stats_module_reset(void);
+void stats_module_init(void);
 int stats_init(struct stats_hdr *shdr, uint8_t size, uint8_t cnt, 
     struct stats_name_map *map, uint8_t map_cnt);
 int stats_register(char *name, struct stats_hdr *shdr);
@@ -118,10 +118,10 @@ int stats_group_walk(stats_group_walk_func_t, void *);
 struct stats_hdr *stats_group_find(char *name);
 
 /* Private */
-#ifdef NEWTMGR_PRESENT 
+#if MYNEWT_VAL(STATS_NEWTMGR)
 int stats_nmgr_register_group(void);
 #endif 
-#ifdef SHELL_PRESENT
+#if MYNEWT_VAL(STATS_CLI)
 int stats_shell_register(void);
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/sys/stats/pkg.yml
----------------------------------------------------------------------
diff --git a/sys/stats/pkg.yml b/sys/stats/pkg.yml
index 309dbd6..c23bedc 100644
--- a/sys/stats/pkg.yml
+++ b/sys/stats/pkg.yml
@@ -27,12 +27,21 @@ pkg.keywords:
 pkg.deps:
     - libs/os
     - libs/util
-    - libs/testutil
-pkg.deps.SHELL:
+pkg.deps.STATS_CLI:
     - libs/shell
-pkg.deps.NEWTMGR:
+pkg.deps.STATS_NEWTMGR:
     - libs/newtmgr
-pkg.req_apis.SHELL:
-    - console
-pkg.cflags.SHELL: -DSHELL_PRESENT
-pkg.cflags.NEWTMGR: -DNEWTMGR_PRESENT 
+
+pkg.init_function: stats_module_init
+pkg.init_stage: 0
+
+pkg.syscfg_defs:
+    STATS_NAMES:
+        description: 'TBD'
+        value: 1
+    STATS_CLI:
+        description: 'TBD'
+        value: 'MYNEWT_PKG_LIBS_SHELL'
+    STATS_NEWTMGR:
+        description: 'TBD'
+        value: 'MYNEWT_PKG_LIBS_NEWTMGR'

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/sys/stats/src/stats.c
----------------------------------------------------------------------
diff --git a/sys/stats/src/stats.c b/sys/stats/src/stats.c
index a1f785c..d9dea44 100644
--- a/sys/stats/src/stats.c
+++ b/sys/stats/src/stats.c
@@ -17,14 +17,15 @@
  * under the License.
  */
 
-#include <os/os.h>
-
+#include <assert.h>
 #include <string.h>
+#include <stdio.h>
 
+#include "sysinit/sysinit.h"
+#include "syscfg/syscfg.h"
+#include "os/os.h"
 #include "stats/stats.h"
 
-#include <stdio.h>
-
 STATS_SECT_START(stats)
     STATS_SECT_ENTRY(num_registered)
 STATS_SECT_END
@@ -38,8 +39,6 @@ STATS_NAME_END(stats)
 STAILQ_HEAD(, stats_hdr) g_stats_registry =
     STAILQ_HEAD_INITIALIZER(g_stats_registry);
 
-static uint8_t stats_module_inited;
-
 int
 stats_walk(struct stats_hdr *hdr, stats_walk_func_t walk_func, void *arg)
 {
@@ -50,7 +49,7 @@ stats_walk(struct stats_hdr *hdr, stats_walk_func_t 
walk_func, void *arg)
     int ent_n;
     int len;
     int rc;
-#ifdef STATS_NAME_ENABLE
+#if MYNEWT_VAL(STATS_NAMES)
     int i;
 #endif
 
@@ -63,7 +62,7 @@ stats_walk(struct stats_hdr *hdr, stats_walk_func_t 
walk_func, void *arg)
          * walk function
          */
         name = NULL;
-#ifdef STATS_NAME_ENABLE
+#if MYNEWT_VAL(STATS_NAMES)
         for (i = 0; i < hdr->s_map_cnt; ++i) {
             if (hdr->s_map[i].snm_off == cur) {
                 name = hdr->s_map[i].snm_name;
@@ -92,57 +91,30 @@ err:
 }
 
 
-int
+void
 stats_module_init(void)
 {
     int rc;
 
-    if (stats_module_inited) {
-        return 0;
-    }
-    stats_module_inited = 1;
+    STAILQ_INIT(&g_stats_registry);
 
-#ifdef SHELL_PRESENT
+#if MYNEWT_VAL(STATS_CLI)
     rc = stats_shell_register();
-    if (rc != 0) {
-        goto err;
-    }
+    SYSINIT_PANIC_ASSERT(rc == 0);
 #endif
 
-#ifdef NEWTMGR_PRESENT
+#if MYNEWT_VAL(STATS_NEWTMGR)
     rc = stats_nmgr_register_group();
-    if (rc != 0) {
-        goto err;
-    }
+    SYSINIT_PANIC_ASSERT(rc == 0);
 #endif
 
     rc = stats_init(STATS_HDR(g_stats_stats),
                     STATS_SIZE_INIT_PARMS(g_stats_stats, STATS_SIZE_32),
                     STATS_NAME_INIT_PARMS(stats));
-    if (rc != 0) {
-        goto err;
-    }
+    SYSINIT_PANIC_ASSERT(rc == 0);
 
     rc = stats_register("stat", STATS_HDR(g_stats_stats));
-    if (rc != 0) {
-        goto err;
-    }
-
-    return (0);
-err:
-    return (rc);
-}
-
-/**
- * Uninitializes all statistic sections.  This is likely only useful for unit
- * tests that need to run in sequence.
- */
-void
-stats_module_reset(void)
-{
-    stats_module_inited = 0;
-
-    STAILQ_INIT(&g_stats_registry);
+    SYSINIT_PANIC_ASSERT(rc == 0);
 }
 
 int
@@ -153,7 +125,7 @@ stats_init(struct stats_hdr *shdr, uint8_t size, uint8_t 
cnt,
 
     shdr->s_size = size;
     shdr->s_cnt = cnt;
-#ifdef STATS_NAME_ENABLE
+#if MYNEWT_VAL(STATS_NAMES)
     shdr->s_map = map;
     shdr->s_map_cnt = map_cnt;
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/sys/stats/src/stats_nmgr.c
----------------------------------------------------------------------
diff --git a/sys/stats/src/stats_nmgr.c b/sys/stats/src/stats_nmgr.c
index c7b8dff..2ffdb8f 100644
--- a/sys/stats/src/stats_nmgr.c
+++ b/sys/stats/src/stats_nmgr.c
@@ -17,14 +17,14 @@
  * under the License.
  */
 
-#include <os/os.h>
-
 #include <string.h>
-
 #include <stdio.h>
 
-#ifdef NEWTMGR_PRESENT
+#include "syscfg/syscfg.h"
+
+#if MYNEWT_VAL(STATS_NEWTMGR)
 
+#include "os/os.h"
 #include "newtmgr/newtmgr.h"
 #include "json/json.h"
 #include "stats/stats.h"
@@ -180,4 +180,4 @@ err:
     return (rc);
 }
 
-#endif /* NEWTMGR_PRESENT */
+#endif /* MYNEWT_VAL(STATS_NEWTMGR) */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/sys/stats/src/stats_shell.c
----------------------------------------------------------------------
diff --git a/sys/stats/src/stats_shell.c b/sys/stats/src/stats_shell.c
index ebb5969..c44f52d 100644
--- a/sys/stats/src/stats_shell.c
+++ b/sys/stats/src/stats_shell.c
@@ -17,19 +17,18 @@
  * under the License.
  */
 
-#include <os/os.h>
-
-#include <string.h>
-
-#include "stats/stats.h"
+#include "syscfg/syscfg.h"
 
 /* Source code is only included if the shell library is enabled.  Otherwise
  * this file is compiled out for code size.
  */
-#ifdef SHELL_PRESENT
+#if MYNEWT_VAL(STATS_CLI)
 
-#include <shell/shell.h>
-#include <console/console.h>
+#include <string.h>
+#include "shell/shell.h"
+#include "console/console.h"
+#include "os/os.h"
+#include "stats/stats.h"
 
 static int shell_stats_display(int argc, char **argv);
 static struct shell_cmd shell_stats_cmd = {
@@ -117,4 +116,4 @@ stats_shell_register(void)
 }
 
 
-#endif /* SHELL_PRESENT */
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/sys/sysinit/include/sysinit/sysinit.h
----------------------------------------------------------------------
diff --git a/sys/sysinit/include/sysinit/sysinit.h 
b/sys/sysinit/include/sysinit/sysinit.h
new file mode 100644
index 0000000..fe86b78
--- /dev/null
+++ b/sys/sysinit/include/sysinit/sysinit.h
@@ -0,0 +1,42 @@
+/**
+ * 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 H_SYSINIT_
+#define H_SYSINIT_
+
+#include "syscfg/syscfg.h"
+
+typedef void sysinit_panic_fn(const char *file, int line);
+
+#if !MYNEWT_VAL(SYSINIT_PANIC_FN)
+#define SYSINIT_PANIC() assert(0)
+#else
+#define SYSINIT_PANIC() MYNEWT_VAL(SYSINIT_PANIC_FN)(__FILE__, __LINE__)
+#endif
+
+#define SYSINIT_PANIC_ASSERT(rc) do \
+{                                   \
+    if (!(rc)) {                    \
+        SYSINIT_PANIC();            \
+    }                               \
+} while (0)
+
+void sysinit(void);
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/sys/sysinit/pkg.yml
----------------------------------------------------------------------
diff --git a/sys/sysinit/pkg.yml b/sys/sysinit/pkg.yml
new file mode 100644
index 0000000..e728ccf
--- /dev/null
+++ b/sys/sysinit/pkg.yml
@@ -0,0 +1,34 @@
+#
+# 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.
+#
+
+pkg.name: sys/sysinit
+pkg.description: XXX
+pkg.author: "Apache Mynewt <d...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/";
+pkg.keywords:
+    - init
+
+pkg.deps:
+    - libs/os
+    - libs/util
+
+pkg.syscfg_defs:
+    SYSINIT_PANIC_FN:
+        description: 'TBD'
+        value:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/targets/unittest/pkg.yml
----------------------------------------------------------------------
diff --git a/targets/unittest/pkg.yml b/targets/unittest/pkg.yml
index c8b283b..30ad3f4 100644
--- a/targets/unittest/pkg.yml
+++ b/targets/unittest/pkg.yml
@@ -23,3 +23,5 @@ pkg.type: "target"
 pkg.description: "Used for unit tests by the \"newt test\" command."
 pkg.author: "Apache Mynewt <d...@mynewt.incubator.apache.org>"
 pkg.homepage: "http://mynewt.apache.org/";
+
+pkg.deps: sys/sysinit

Reply via email to