You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2015/11/19 03:02:46 UTC

[4/4] incubator-mynewt-larva git commit: Add test project which uses lua egg.

Add test project which uses lua egg.


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

Branch: refs/heads/master
Commit: 3289b68bc01cec1f0e0ef9a360eb87717e76449d
Parents: 1fbd70e
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 18 18:01:09 2015 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 18 18:01:09 2015 -0800

----------------------------------------------------------------------
 project/luatest/luatest.yml |   8 +++
 project/luatest/src/main.c  | 120 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 128 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3289b68b/project/luatest/luatest.yml
----------------------------------------------------------------------
diff --git a/project/luatest/luatest.yml b/project/luatest/luatest.yml
new file mode 100644
index 0000000..4513258
--- /dev/null
+++ b/project/luatest/luatest.yml
@@ -0,0 +1,8 @@
+project.name: luatest
+project.eggs:
+    - libs/os
+    - libs/elua/elua_base
+    - libs/shell
+    - libs/console/full
+    - libs/util
+    - libs/nffs

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3289b68b/project/luatest/src/main.c
----------------------------------------------------------------------
diff --git a/project/luatest/src/main.c b/project/luatest/src/main.c
new file mode 100755
index 0000000..44e0d10
--- /dev/null
+++ b/project/luatest/src/main.c
@@ -0,0 +1,120 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed 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 <assert.h>
+#include <string.h>
+#include <os/os.h>
+#include <hal/hal_flash.h>
+#include <console/console.h>
+#include <shell/shell.h>
+#include <elua_base/elua.h>
+#include <nffs/nffs.h>
+#include <util/flash_map.h>
+#ifdef ARCH_sim
+#include <mcu/mcu_sim.h>
+#endif
+
+/* Init all tasks */
+int init_tasks(void);
+
+/* Shell */
+#define SHELL_TASK_PRIO      (8)
+#define SHELL_TASK_STACK_SIZE (OS_STACK_ALIGN(8192))
+static os_stack_t shell_stack[SHELL_TASK_STACK_SIZE];
+static struct shell_cmd lua_shell_cmd;
+
+/* NFFS */
+#define NFFS_AREA_MAX		16
+
+static int
+lua_cmd(int argc, char **argv)
+{
+    lua_main(argc, argv);
+    return 0;
+}
+
+static void
+create_script_file(void)
+{
+    char filename[] = "/foobar";
+    char script[] = "print \"eat my shorts\"\n";
+    struct nffs_file *nf;
+    int rc;
+
+    rc = nffs_open(filename, NFFS_ACCESS_READ, &nf);
+    if (rc) {
+        rc = nffs_open(filename, NFFS_ACCESS_WRITE, &nf);
+        assert(rc == 0);
+        rc = nffs_write(nf, script, strlen(script));
+        assert(rc == 0);
+    }
+    nffs_close(nf);
+}
+
+/**
+ * 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;
+    struct nffs_area_desc descs[NFFS_AREA_MAX];
+    int cnt;
+
+#ifdef ARCH_sim
+    mcu_sim_parse_args(argc, argv);
+#endif
+
+    rc = hal_flash_init();
+    assert(rc == 0);
+
+    /* Initialize OS */
+    os_init();
+
+    /* Init tasks */
+    shell_task_init(SHELL_TASK_PRIO, shell_stack, SHELL_TASK_STACK_SIZE);
+    console_init(shell_console_rx_cb);
+
+    rc = shell_cmd_register(&lua_shell_cmd, "lua", lua_cmd);
+    assert(rc == 0);
+
+    nffs_init();
+
+    rc = flash_area_to_nffs_desc(FLASH_AREA_NFFS, &cnt, descs);
+    assert(rc == 0);
+
+    if (nffs_detect(descs) == NFFS_ECORRUPT) {
+        rc = nffs_format(descs);
+        assert(rc == 0);
+    }
+
+    create_script_file();
+
+    /* Start the OS */
+    os_start();
+
+    /* os start should never return. If it does, this should be an error */
+    assert(0);
+
+    return rc;
+}
+