mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject [1/2] incubator-mynewt-core git commit: slinky_oic; test app with oicmgr instead of newtmgr.
Date Wed, 26 Oct 2016 18:21:26 GMT
Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop bc9a74c44 -> 101703211


slinky_oic; test app with oicmgr instead of newtmgr.


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/10170321
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/10170321
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/10170321

Branch: refs/heads/develop
Commit: 1017032116e37c4556a2367c83fd8ce0f27b5b3f
Parents: 5cb17fa
Author: Marko Kiiskila <marko@runtime.io>
Authored: Wed Oct 26 11:20:25 2016 -0700
Committer: Marko Kiiskila <marko@runtime.io>
Committed: Wed Oct 26 11:21:13 2016 -0700

----------------------------------------------------------------------
 apps/slinky_oic/pkg.yml    |  44 ++++++
 apps/slinky_oic/src/main.c | 299 ++++++++++++++++++++++++++++++++++++++++
 apps/slinky_oic/syscfg.yml |  25 ++++
 3 files changed, 368 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/10170321/apps/slinky_oic/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/slinky_oic/pkg.yml b/apps/slinky_oic/pkg.yml
new file mode 100644
index 0000000..3a66a89
--- /dev/null
+++ b/apps/slinky_oic/pkg.yml
@@ -0,0 +1,44 @@
+#
+# 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: apps/slinky_oic
+pkg.type: app
+pkg.description: "Example application which uses a variety of mynewt features."
+pkg.author: "Apache Mynewt <dev@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps:
+    - sys/console/full
+    - mgmt/imgmgr
+    - mgmt/oicmgr
+    - kernel/os
+    - boot/bootutil
+    - sys/shell
+    - sys/config
+    - sys/id
+    - sys/log
+    - sys/stats
+    - boot/split
+
+pkg.deps.CONFIG_NFFS:
+    - fs/nffs
+
+pkg.deps.CONFIG_FCB:
+    - fs/fcb

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/10170321/apps/slinky_oic/src/main.c
----------------------------------------------------------------------
diff --git a/apps/slinky_oic/src/main.c b/apps/slinky_oic/src/main.c
new file mode 100755
index 0000000..ca27d6c
--- /dev/null
+++ b/apps/slinky_oic/src/main.c
@@ -0,0 +1,299 @@
+/**
+ * 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 <syscfg/syscfg.h>
+#include <sysinit/sysinit.h>
+
+#include <os/os.h>
+#include <bsp/bsp.h>
+#include <hal/hal_gpio.h>
+#include <hal/hal_flash.h>
+#include <console/console.h>
+#include <log/log.h>
+#include <stats/stats.h>
+#include <config/config.h>
+#if MYNEWT_VAL(SPLIT_LOADER)
+#include "split/split.h"
+#endif
+#include <bootutil/image.h>
+#include <imgmgr/imgmgr.h>
+#include <assert.h>
+#include <string.h>
+#include <json/json.h>
+#include <reboot/log_reboot.h>
+#include <os/os_time.h>
+
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
+#include <mn_socket/arch/sim/native_sock.h>
+#endif
+
+#ifdef ARCH_sim
+#include <mcu/mcu_sim.h>
+#endif
+
+/* Init all tasks */
+static volatile int tasks_initialized;
+int init_tasks(void);
+
+/* Task 1 */
+#define TASK1_PRIO (8)
+#define TASK1_STACK_SIZE    OS_STACK_ALIGN(192)
+#define MAX_CBMEM_BUF 600
+static struct os_task task1;
+static volatile int g_task1_loops;
+
+/* Task 2 */
+#define TASK2_PRIO (9)
+#define TASK2_STACK_SIZE    OS_STACK_ALIGN(128)
+static struct os_task task2;
+
+static struct log my_log;
+
+static volatile int g_task2_loops;
+
+/* Global test semaphore */
+static struct os_sem g_test_sem;
+
+/* For LED toggling */
+static int g_led_pin;
+
+STATS_SECT_START(gpio_stats)
+STATS_SECT_ENTRY(toggles)
+STATS_SECT_END
+
+static STATS_SECT_DECL(gpio_stats) g_stats_gpio_toggle;
+
+static STATS_NAME_START(gpio_stats)
+STATS_NAME(gpio_stats, toggles)
+STATS_NAME_END(gpio_stats)
+
+static char *test_conf_get(int argc, char **argv, char *val, int max_len);
+static int test_conf_set(int argc, char **argv, char *val);
+static int test_conf_commit(void);
+static int test_conf_export(void (*export_func)(char *name, char *val),
+  enum conf_export_tgt tgt);
+
+static struct conf_handler test_conf_handler = {
+    .ch_name = "test",
+    .ch_get = test_conf_get,
+    .ch_set = test_conf_set,
+    .ch_commit = test_conf_commit,
+    .ch_export = test_conf_export
+};
+
+static uint8_t test8;
+static uint8_t test8_shadow;
+static char test_str[32];
+static uint32_t cbmem_buf[MAX_CBMEM_BUF];
+static struct cbmem cbmem;
+
+static char *
+test_conf_get(int argc, char **argv, char *buf, int max_len)
+{
+    if (argc == 1) {
+        if (!strcmp(argv[0], "8")) {
+            return conf_str_from_value(CONF_INT8, &test8, buf, max_len);
+        } else if (!strcmp(argv[0], "str")) {
+            return test_str;
+        }
+    }
+    return NULL;
+}
+
+static int
+test_conf_set(int argc, char **argv, char *val)
+{
+    if (argc == 1) {
+        if (!strcmp(argv[0], "8")) {
+            return CONF_VALUE_SET(val, CONF_INT8, test8_shadow);
+        } else if (!strcmp(argv[0], "str")) {
+            return CONF_VALUE_SET(val, CONF_STRING, test_str);
+        }
+    }
+    return OS_ENOENT;
+}
+
+static int
+test_conf_commit(void)
+{
+    test8 = test8_shadow;
+
+    return 0;
+}
+
+static int
+test_conf_export(void (*func)(char *name, char *val), enum conf_export_tgt tgt)
+{
+    char buf[4];
+
+    conf_str_from_value(CONF_INT8, &test8, buf, sizeof(buf));
+    func("test/8", buf);
+    func("test/str", test_str);
+    return 0;
+}
+
+void
+task1_handler(void *arg)
+{
+    struct os_task *t;
+    int prev_pin_state, curr_pin_state;
+    struct image_version ver;
+
+    /* Set the led pin for the E407 devboard */
+    g_led_pin = LED_BLINK_PIN;
+    hal_gpio_init_out(g_led_pin, 1);
+
+    if (imgr_my_version(&ver) == 0) {
+        console_printf("\nSlinky_OIC %u.%u.%u.%u\n",
+          ver.iv_major, ver.iv_minor, ver.iv_revision,
+          (unsigned int)ver.iv_build_num);
+    } else {
+        console_printf("\nSlinky\n");
+    }
+
+    while (1) {
+        t = os_sched_get_current_task();
+        assert(t->t_func == task1_handler);
+
+        ++g_task1_loops;
+
+        /* Wait one second */
+        os_time_delay(OS_TICKS_PER_SEC);
+
+        /* Toggle the LED */
+        prev_pin_state = hal_gpio_read(g_led_pin);
+        curr_pin_state = hal_gpio_toggle(g_led_pin);
+        LOG_INFO(&my_log, LOG_MODULE_DEFAULT, "GPIO toggle from %u to %u",
+            prev_pin_state, curr_pin_state);
+        STATS_INC(g_stats_gpio_toggle, toggles);
+
+        /* Release semaphore to task 2 */
+        os_sem_release(&g_test_sem);
+    }
+}
+
+void
+task2_handler(void *arg)
+{
+    struct os_task *t;
+
+    while (1) {
+        /* just for debug; task 2 should be the running task */
+        t = os_sched_get_current_task();
+        assert(t->t_func == task2_handler);
+
+        /* Increment # of times we went through task loop */
+        ++g_task2_loops;
+
+        /* Wait for semaphore from ISR */
+        os_sem_pend(&g_test_sem, OS_TIMEOUT_NEVER);
+    }
+}
+
+/**
+ * init_tasks
+ *
+ * Called by main.c after sysinit(). This function performs initializations
+ * that are required before tasks are running.
+ *
+ * @return int 0 success; error otherwise.
+ */
+int
+init_tasks(void)
+{
+    os_stack_t *pstack;
+    /* Initialize global test semaphore */
+    os_sem_init(&g_test_sem, 0);
+
+    pstack = malloc(sizeof(os_stack_t)*TASK1_STACK_SIZE);
+    assert(pstack);
+
+    os_task_init(&task1, "task1", task1_handler, NULL,
+            TASK1_PRIO, OS_WAIT_FOREVER, pstack, TASK1_STACK_SIZE);
+
+    pstack = malloc(sizeof(os_stack_t)*TASK2_STACK_SIZE);
+    assert(pstack);
+
+    os_task_init(&task2, "task2", task2_handler, NULL,
+            TASK2_PRIO, OS_WAIT_FOREVER, pstack, TASK2_STACK_SIZE);
+
+    tasks_initialized = 1;
+    return 0;
+}
+
+/**
+ * main
+ *
+ * The main function for the project. This function initializes the os, calls
+ * init_tasks to initialize tasks (and possibly other objects), then starts the
+ * OS. We should not return from os start.
+ *
+ * @return int NOTE: this function should never return!
+ */
+int
+main(int argc, char **argv)
+{
+    int rc;
+
+#ifdef ARCH_sim
+    mcu_sim_parse_args(argc, argv);
+#endif
+
+    sysinit();
+
+    rc = conf_register(&test_conf_handler);
+    assert(rc == 0);
+
+    cbmem_init(&cbmem, cbmem_buf, MAX_CBMEM_BUF);
+    log_register("log", &my_log, &log_cbmem_handler, &cbmem, LOG_SYSLEVEL);
+
+    stats_init(STATS_HDR(g_stats_gpio_toggle),
+               STATS_SIZE_INIT_PARMS(g_stats_gpio_toggle, STATS_SIZE_32),
+               STATS_NAME_INIT_PARMS(gpio_stats));
+
+    stats_register("gpio_toggle", STATS_HDR(g_stats_gpio_toggle));
+
+    conf_load();
+
+    log_reboot(HARD_REBOOT);
+
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
+    rc = native_sock_init();
+    assert(rc == 0);
+#endif
+
+#if MYNEWT_VAL(SPLIT_LOADER)
+    {
+        void *entry;
+        rc = split_app_go(&entry, true);
+        if(rc == 0) {
+            system_start(entry);
+        }
+    }
+#endif
+
+    rc = init_tasks();
+
+    os_start();
+
+    /* os start should never return. If it does, this should be an error */
+    assert(0);
+
+    return rc;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/10170321/apps/slinky_oic/syscfg.yml
----------------------------------------------------------------------
diff --git a/apps/slinky_oic/syscfg.yml b/apps/slinky_oic/syscfg.yml
new file mode 100644
index 0000000..896a777
--- /dev/null
+++ b/apps/slinky_oic/syscfg.yml
@@ -0,0 +1,25 @@
+# Package: apps/slinky
+
+syscfg.vals:
+    # Enable the shell task.
+    SHELL_TASK: 1
+
+    # Include names for statistics.
+    STATS_NAMES: 1
+
+    # Log reboot messages to a flash circular buffer.
+    REBOOT_LOG_FCB: 1
+    LOG_FCB: 1
+
+    CONFIG_FCB: 1
+
+    # Enable shell commands.
+    STATS_CLI: 1
+    LOG_CLI: 1
+
+    # Enable newtmgr commands.
+    STATS_NEWTMGR: 1
+    LOG_NEWTMGR: 1
+    OC_SERVER: 1
+    OC_TRANSPORT_IP: 1
+    OC_TRANSPORT_SERIAL: 1


Mime
View raw message