You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2015/11/05 02:59:13 UTC
[1/2] incubator-mynewt-larva git commit: add basic support for a
shell on top of the console. this will improve significantly over the next
day or two.
Repository: incubator-mynewt-larva
Updated Branches:
refs/heads/master f10a7e7b0 -> 329fd8a13
add basic support for a shell on top of the console. this will improve significantly over the next day or two.
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/3c7aef2e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/3c7aef2e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/3c7aef2e
Branch: refs/heads/master
Commit: 3c7aef2ee7f70094e763c7dad20dafd63a23b062
Parents: 99feb02
Author: Sterling Hughes <st...@apache.org>
Authored: Wed Nov 4 17:58:56 2015 -0800
Committer: Sterling Hughes <st...@apache.org>
Committed: Wed Nov 4 17:58:56 2015 -0800
----------------------------------------------------------------------
hw/mcu/native/src/hal_uart.c | 41 ++++--
libs/console/full/src/cons_tty.c | 4 +-
libs/shell/egg.yml | 5 +
libs/shell/include/shell/shell.h | 31 ++++
libs/shell/src/.shell.c.swp | Bin 0 -> 20480 bytes
libs/shell/src/shell.c | 262 ++++++++++++++++++++++++++++++++++
project/blinky/blinky.yml | 3 +-
project/blinky/egg.yml | 2 +
project/blinky/src/main.c | 11 ++
9 files changed, 343 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3c7aef2e/hw/mcu/native/src/hal_uart.c
----------------------------------------------------------------------
diff --git a/hw/mcu/native/src/hal_uart.c b/hw/mcu/native/src/hal_uart.c
index 8a99a46..b4c2497 100644
--- a/hw/mcu/native/src/hal_uart.c
+++ b/hw/mcu/native/src/hal_uart.c
@@ -31,7 +31,7 @@
#include <string.h>
#define UART_MAX_BYTES_PER_POLL 64
-#define UART_POLLER_STACK_SZ 1024
+#define UART_POLLER_STACK_SZ (1024)
#define UART_POLLER_PRIO 0
struct uart {
@@ -123,12 +123,28 @@ uart_poller(void *arg)
}
}
+static void
+set_nonblock(int fd)
+{
+ int flags;
+
+ flags = fcntl(fd, F_GETFL);
+ if (flags == -1) {
+ perror("fcntl(F_GETFL) fail");
+ return;
+ }
+ if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
+ perror("fcntl(F_SETFL) fail");
+ return;
+ }
+}
+
+
static int
uart_pty(void)
{
int fd;
int loop_slave;
- int flags;
struct termios tios;
char pty_name[32];
@@ -152,16 +168,6 @@ uart_pty(void)
goto err;
}
- flags = fcntl(fd, F_GETFL);
- if (flags == -1) {
- perror("fcntl(F_GETFL) fail");
- goto err;
- }
- if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
- perror("fcntl(F_SETFL) fail");
- goto err;
- }
-
printf("console at %s\n", pty_name);
return fd;
err:
@@ -192,7 +198,12 @@ hal_uart_start_rx(int port)
void
hal_uart_blocking_tx(int port, uint8_t data)
{
- /* XXXX fill this in */
+ if (port >= UART_CNT || uarts[port].u_open == 0) {
+ return;
+ }
+
+ /* XXX: Count statistics and add error checking here. */
+ (void) write(uarts[port].u_fd, &data, sizeof(data));
}
int
@@ -240,10 +251,14 @@ hal_uart_config(int port, int32_t baudrate, uint8_t databits, uint8_t stopbits,
if (uart->u_open) {
return -1;
}
+
uart->u_fd = uart_pty();
+
if (uart->u_fd < 0) {
return -1;
}
+ set_nonblock(uart->u_fd);
+
uart->u_open = 1;
return 0;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3c7aef2e/libs/console/full/src/cons_tty.c
----------------------------------------------------------------------
diff --git a/libs/console/full/src/cons_tty.c b/libs/console/full/src/cons_tty.c
index d5e23a9..8e24d8f 100644
--- a/libs/console/full/src/cons_tty.c
+++ b/libs/console/full/src/cons_tty.c
@@ -231,8 +231,8 @@ console_init(console_rx_cb rx_cb)
struct console_tty *ct = &console_tty;
int rc;
- rc = hal_uart_init_cbs(CONSOLE_UART, console_tx_char, NULL, console_rx_char,
- ct);
+ rc = hal_uart_init_cbs(CONSOLE_UART, console_tx_char, NULL,
+ console_rx_char, ct);
if (rc) {
return rc;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3c7aef2e/libs/shell/egg.yml
----------------------------------------------------------------------
diff --git a/libs/shell/egg.yml b/libs/shell/egg.yml
new file mode 100644
index 0000000..7c5af65
--- /dev/null
+++ b/libs/shell/egg.yml
@@ -0,0 +1,5 @@
+egg.name: libs/shell
+egg.vers: 0.1
+egg.deps:
+ - libs/console/full
+ - libs/os
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3c7aef2e/libs/shell/include/shell/shell.h
----------------------------------------------------------------------
diff --git a/libs/shell/include/shell/shell.h b/libs/shell/include/shell/shell.h
new file mode 100644
index 0000000..b7d5dd3
--- /dev/null
+++ b/libs/shell/include/shell/shell.h
@@ -0,0 +1,31 @@
+/**
+ * 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.
+ */
+#ifndef __SHELL_H__
+#define __SHELL_H__
+
+typedef int (*shell_cmd_func_t)(char **argv, int argc);
+struct shell_cmd {
+ char *sc_cmd;
+ shell_cmd_func_t sc_cmd_func;
+ STAILQ_ENTRY(shell_cmd) sc_next;
+};
+
+int shell_cmd_register(struct shell_cmd *sc, char *cmd,
+ shell_cmd_func_t func);
+void shell_console_rx_cb(int full_line);
+int shell_task_init(uint8_t prio, os_stack_t *stack, uint16_t stack_size);
+
+#endif /* __SHELL_H__ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3c7aef2e/libs/shell/src/.shell.c.swp
----------------------------------------------------------------------
diff --git a/libs/shell/src/.shell.c.swp b/libs/shell/src/.shell.c.swp
new file mode 100644
index 0000000..72af037
Binary files /dev/null and b/libs/shell/src/.shell.c.swp differ
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3c7aef2e/libs/shell/src/shell.c
----------------------------------------------------------------------
diff --git a/libs/shell/src/shell.c b/libs/shell/src/shell.c
new file mode 100644
index 0000000..56f99a5
--- /dev/null
+++ b/libs/shell/src/shell.c
@@ -0,0 +1,262 @@
+/**
+ * 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 <os/os.h>
+
+#include <console/console.h>
+
+#include "shell/shell.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#define OS_EVENT_T_CONSOLE_RDY (OS_EVENT_T_PERUSER)
+
+static struct shell_cmd g_shell_echo_cmd;
+
+static struct os_task shell_task;
+static struct os_eventq shell_evq;
+static struct os_event console_rdy_ev;
+
+static struct os_mutex g_shell_cmd_list_lock;
+
+char shell_line[128];
+char *argv[20];
+
+static STAILQ_HEAD(, shell_cmd) g_shell_cmd_list =
+ STAILQ_HEAD_INITIALIZER(g_shell_cmd_list);
+
+static int
+shell_cmd_list_lock(void)
+{
+ int rc;
+
+ if (!os_started()) {
+ return (0);
+ }
+
+ rc = os_mutex_pend(&g_shell_cmd_list_lock, OS_WAIT_FOREVER);
+ if (rc != 0) {
+ goto err;
+ }
+ return (0);
+err:
+ return (rc);
+}
+
+static int
+shell_cmd_list_unlock(void)
+{
+ int rc;
+
+ if (!os_started()) {
+ return (0);
+ }
+
+ rc = os_mutex_release(&g_shell_cmd_list_lock);
+ if (rc != 0) {
+ goto err;
+ }
+ return (0);
+err:
+ return (rc);
+}
+
+int
+shell_cmd_register(struct shell_cmd *sc, char *cmd, shell_cmd_func_t func)
+{
+ int rc;
+
+ /* Create the command that is being registered. */
+ sc->sc_cmd = cmd;
+ sc->sc_cmd_func = func;
+ STAILQ_NEXT(sc, sc_next) = NULL;
+
+ rc = shell_cmd_list_lock();
+ if (rc != 0) {
+ goto err;
+ }
+
+ STAILQ_INSERT_TAIL(&g_shell_cmd_list, sc, sc_next);
+
+ rc = shell_cmd_list_unlock();
+ if (rc != 0) {
+ goto err;
+ }
+
+ return (0);
+err:
+ return (rc);
+}
+
+static int
+shell_cmd(char *cmd, char **argv, int argc)
+{
+ struct shell_cmd *sc;
+ int rc;
+
+ rc = shell_cmd_list_lock();
+ if (rc != 0) {
+ goto err;
+ }
+
+ STAILQ_FOREACH(sc, &g_shell_cmd_list, sc_next) {
+ if (!strcmp(sc->sc_cmd, cmd)) {
+ break;
+ }
+ }
+
+ rc = shell_cmd_list_unlock();
+ if (rc != 0) {
+ goto err;
+ }
+
+ if (sc) {
+ sc->sc_cmd_func(argv, argc);
+ } else {
+ console_printf("Unknown command %s\n", cmd);
+ }
+
+ return (0);
+err:
+ return (rc);
+}
+
+static int
+shell_process_command(char *line, int len)
+{
+ char *tok;
+ char *tok_ptr;
+ int argc;
+
+ tok_ptr = NULL;
+ tok = strtok_r(line, " ", &tok_ptr);
+ argc = 0;
+ while (tok != NULL) {
+ argv[argc++] = tok;
+
+ tok = strtok_r(NULL, " ", &tok_ptr);
+ }
+
+ (void) shell_cmd(argv[0], argv, argc);
+
+ return (0);
+}
+
+static int
+shell_read_console(void)
+{
+ int rc;
+
+ while (1) {
+ rc = console_read(shell_line, sizeof(shell_line));
+ if (rc < 0) {
+ goto err;
+ }
+ if (rc == 0) {
+ break;
+ }
+
+ rc = shell_process_command(shell_line, rc);
+ if (rc != 0) {
+ goto err;
+ }
+ }
+
+ return (0);
+err:
+ return (rc);
+}
+
+static void
+shell_task_func(void *arg)
+{
+ struct os_event *ev;
+
+ os_eventq_init(&shell_evq);
+
+ console_rdy_ev.ev_type = OS_EVENT_T_CONSOLE_RDY;
+
+ while (1) {
+ ev = os_eventq_get(&shell_evq);
+ assert(ev != NULL);
+
+ switch (ev->ev_type) {
+ case OS_EVENT_T_CONSOLE_RDY:
+ // Read and process all available lines on the console.
+ (void) shell_read_console();
+ break;
+ }
+ }
+}
+
+/**
+ * This function is called from the console APIs when data is available
+ * to be read. This is either a full line (full_line = 1), or when the
+ * console buffer (default = 128) is full. At the moment, we assert()
+ * when the buffer is filled to avoid double buffering this data.
+ */
+void
+shell_console_rx_cb(int full_line)
+{
+ assert(full_line);
+
+ os_eventq_put(&shell_evq, &console_rdy_ev);
+}
+
+static int
+shell_echo_cmd(char **argv, int argc)
+{
+ int i;
+
+ for (i = 1; i < argc; i++) {
+ console_write(argv[i], strlen(argv[i]));
+ console_write(" ", sizeof(" ")-1);
+ }
+ console_write("\n", sizeof("\n")-1);
+
+ return (0);
+}
+
+
+int
+shell_task_init(uint8_t prio, os_stack_t *stack, uint16_t stack_size)
+{
+ int rc;
+
+ rc = os_mutex_init(&g_shell_cmd_list_lock);
+ if (rc != 0) {
+ goto err;
+ }
+
+ rc = shell_cmd_register(&g_shell_echo_cmd, "echo", shell_echo_cmd);
+ if (rc != 0) {
+ goto err;
+ }
+
+ rc = os_task_init(&shell_task, "shell", shell_task_func,
+ NULL, prio, OS_WAIT_FOREVER, stack, stack_size);
+ if (rc != 0) {
+ goto err;
+ }
+
+
+ return (0);
+err:
+ return (rc);
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3c7aef2e/project/blinky/blinky.yml
----------------------------------------------------------------------
diff --git a/project/blinky/blinky.yml b/project/blinky/blinky.yml
index 685449d..1093f92 100644
--- a/project/blinky/blinky.yml
+++ b/project/blinky/blinky.yml
@@ -1,4 +1,5 @@
project.name: blinky
project.eggs:
- - libs/console/stub
+ - libs/console/full
+ - libs/shell
- libs/os
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3c7aef2e/project/blinky/egg.yml
----------------------------------------------------------------------
diff --git a/project/blinky/egg.yml b/project/blinky/egg.yml
index 0e6443d..1a4dad7 100644
--- a/project/blinky/egg.yml
+++ b/project/blinky/egg.yml
@@ -2,4 +2,6 @@ egg.name: project/blinky
egg.vers: 0.1
egg.deps:
- libs/os
+ - libs/console/full
+ - libs/shell
- hw/hal
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3c7aef2e/project/blinky/src/main.c
----------------------------------------------------------------------
diff --git a/project/blinky/src/main.c b/project/blinky/src/main.c
index 65d5493..3e8ead9 100755
--- a/project/blinky/src/main.c
+++ b/project/blinky/src/main.c
@@ -16,6 +16,8 @@
#include "os/os.h"
#include "bsp/bsp.h"
#include "hal/hal_gpio.h"
+#include "console/console.h"
+#include "shell/shell.h"
#include <assert.h>
#include <string.h>
@@ -35,6 +37,11 @@ static volatile int g_task1_loops;
#define TASK2_STACK_SIZE OS_STACK_ALIGN(1024)
struct os_task task2;
os_stack_t stack2[TASK2_STACK_SIZE];
+
+#define SHELL_TASK_PRIO (3)
+#define SHELL_TASK_STACK_SIZE (OS_STACK_ALIGN(1024))
+os_stack_t shell_stack[SHELL_TASK_STACK_SIZE];
+
static volatile int g_task2_loops;
/* Global test semaphore */
@@ -126,6 +133,10 @@ main(void)
int rc;
os_init();
+
+ shell_task_init(SHELL_TASK_PRIO, shell_stack, SHELL_TASK_STACK_SIZE);
+
+ (void) console_init(shell_console_rx_cb);
rc = init_tasks();
os_start();
[2/2] incubator-mynewt-larva git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva
Posted by st...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva
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/329fd8a1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/329fd8a1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/329fd8a1
Branch: refs/heads/master
Commit: 329fd8a13f0929ba9d0e7a9526ede9afdd5710da
Parents: 3c7aef2 f10a7e7
Author: Sterling Hughes <st...@apache.org>
Authored: Wed Nov 4 17:59:06 2015 -0800
Committer: Sterling Hughes <st...@apache.org>
Committed: Wed Nov 4 17:59:06 2015 -0800
----------------------------------------------------------------------
hw/bsp/nrf52pdk/egg.yml | 2 +
hw/bsp/nrf52pdk/nrf52pdk_debug.sh | 26 ++
hw/bsp/nrf52pdk/nrf52pdk_download.sh | 48 +++
hw/mcu/nordic/nrf52xxx/src/hal_uart.c | 26 +-
libs/os/include/os/os_mbuf.h | 3 +
libs/os/src/os_mbuf.c | 37 +++
.../controller/include/controller/ble_hw.h | 2 +-
.../controller/include/controller/ble_ll.h | 2 +-
.../controller/include/controller/ble_ll_adv.h | 4 +-
.../controller/include/controller/ble_ll_hci.h | 4 +-
.../controller/include/controller/ble_ll_scan.h | 2 +-
.../include/controller/ble_ll_sched.h | 2 +-
.../include/controller/ble_ll_whitelist.h | 2 +-
.../controller/include/controller/ble_phy.h | 2 +-
net/nimble/controller/src/ble_hw.c | 3 +-
net/nimble/controller/src/ble_ll.c | 1 +
net/nimble/controller/src/ble_ll_scan.c | 1 +
net/nimble/controller/src/ble_phy.c | 3 +-
net/nimble/host/include/host/host_hci.h | 4 +-
net/nimble/host/include/host/host_task.h | 16 -
net/nimble/host/src/arch/sim/itf.c | 98 +++---
net/nimble/host/src/attr.c | 249 ---------------
net/nimble/host/src/ble_hs_att.c | 315 +++++++++++++++++++
net/nimble/host/src/ble_hs_att.h | 22 ++
net/nimble/host/src/ble_hs_conn.c | 128 ++++++++
net/nimble/host/src/ble_hs_conn.h | 39 +++
net/nimble/host/src/ble_l2cap.c | 155 +++++++++
net/nimble/host/src/ble_l2cap.h | 67 ++++
net/nimble/host/src/host_dbg.h | 4 +-
net/nimble/host/src/host_hci.c | 54 +---
net/nimble/host/src/host_task.c | 72 ++---
net/nimble/host/src/itf.h | 16 +
net/nimble/host/src/l2cap.c | 43 ---
net/nimble/host/src/l2cap.h | 25 --
net/nimble/include/nimble/ble.h | 2 +-
net/nimble/include/nimble/hci_common.h | 3 +-
net/nimble/include/nimble/hci_transport.h | 5 +-
project/bletest/src/main.c | 52 +++
38 files changed, 1058 insertions(+), 481 deletions(-)
----------------------------------------------------------------------