OSDN Git Service

\e$B%A%1%C%H\e(B #30713 \e$B%7%'%k%?%9%/$N%3%^%s%I<BAu%U%l!<%`%o!<%/$r2C$($k\e(B
authorShinichiro Nakamura <shinta.main.jp@gmail.com>
Sun, 10 Feb 2013 09:29:24 +0000 (18:29 +0900)
committerShinichiro Nakamura <shinta.main.jp@gmail.com>
Sun, 10 Feb 2013 09:29:24 +0000 (18:29 +0900)
\e$B$^$:$O\e(BNT-Shell\e$B$K<BD>$K<BAu$9$k7A<0$G%3%_%C%H!#\e(B
\e$BB3$/=$@5$G\e(Bcmd.h\e$B$KBP$9$k<BAu$r\e(BNT-Shell\e$B$r;HMQ$9$k\e(BBSP\e$B$KMW5a$9$k!#\e(B

uzumeapp/kernel/config/blackfin/bsp_bluetank/Makefile.config
uzumeapp/kernel/uzume/ntshell/cmd.c [new file with mode: 0644]
uzumeapp/kernel/uzume/ntshell/cmd.h [new file with mode: 0644]
uzumeapp/kernel/uzume/ntshell/ntshell_task.c
uzumeapp/kernel/uzume/ntshell/ntstdio.c
uzumeapp/kernel/uzume/ntshell/ntstdio.h

index 371641c..bd0cf71 100644 (file)
@@ -20,7 +20,7 @@ KERNEL_DIR := $(KERNEL_DIR) :$(SRCDIR)/config/$(CPU)/$(SYS) :$(SRCDIR)/config/$(
 KERNEL_ASMOBJS := $(KERNEL_ASMOBJS)
 KERNEL_COBJS := $(KERNEL_COBJS) chip_config.o uart.o chip_debugboot.o chip_dump.o
 KERNEL_COBJS := $(KERNEL_COBJS) i2s_subsystem.o i2c_subsystem.o rotenc.o uzume_callback.o sgtl5000.o bsp_bluetank.o
-KERNEL_COBJS := $(KERNEL_COBJS) ntlibc.o ntopt.o ntshell.o ntshell_task.o text_editor.o text_history.o vtrecv.o vtsend.o ntstdio.o
+KERNEL_COBJS := $(KERNEL_COBJS) ntlibc.o ntopt.o ntshell.o ntshell_task.o text_editor.o text_history.o vtrecv.o vtsend.o ntstdio.o cmd.o
 
 #
 # リンカスクリプトの定義
diff --git a/uzumeapp/kernel/uzume/ntshell/cmd.c b/uzumeapp/kernel/uzume/ntshell/cmd.c
new file mode 100644 (file)
index 0000000..909e665
--- /dev/null
@@ -0,0 +1,17 @@
+/**
+ * @file cmd.c
+ * @author Shinichiro Nakamura
+ * @brief \e$B%3%^%s%I$N<BAu!#\e(B
+ * @details
+ */
+
+#include "cmd.h"
+
+void cmd_execute(cmd_env_t *env, int argc, char **argv)
+{
+    int i;
+    for (i = 0; i < argc; i++) {
+        ntstdio_printf(CMD_NTSTDIO(env), "%d : '%s'\n", i, argv[i]);
+    }
+}
+
diff --git a/uzumeapp/kernel/uzume/ntshell/cmd.h b/uzumeapp/kernel/uzume/ntshell/cmd.h
new file mode 100644 (file)
index 0000000..c446671
--- /dev/null
@@ -0,0 +1,25 @@
+/**
+ * @file cmd.h
+ * @author Shinichiro Nakamura
+ * @brief コマンドの定義。
+ * @details
+ */
+
+#ifndef CMD_H
+#define CMD_H
+
+#include "ntshell.h"
+#include "ntstdio.h"
+
+#define CMD_NTSHELL(ENV)    (&((ENV)->ntshell))
+#define CMD_NTSTDIO(ENV)    (&((ENV)->ntstdio))
+
+typedef struct {
+    ntshell_t ntshell;
+    ntstdio_t ntstdio;
+} cmd_env_t;
+
+void cmd_execute(cmd_env_t *env, int argc, char **argv);
+
+#endif
+
index b3f37dc..239ac7e 100644 (file)
  */
 
 #include <t_services.h>
-#include "ntshell.h"
 #include "ntshell_task.h"
 #include "ntlibc.h"
+#include "ntshell.h"
 #include "ntstdio.h"
+#include "ntopt.h"
+#include "cmd.h"
 
 #define SERIAL_PORT_ID  (1)
 
-static ntshell_t ntshell;
-static NTSTDIO ntstdio;
+static cmd_env_t cmd_env;
 
 static int func_read(char *buf, int cnt, void *extobj)
 {
@@ -79,10 +80,17 @@ static unsigned char uxi(void)
     return c;
 }
 
-static int func_callback(const char *text, void *extobj)
+int ntopt_callback(int argc, char **argv, void *extobj)
+{
+    cmd_env_t *env = (cmd_env_t *)extobj;
+    cmd_execute(env, argc, argv);
+    return 0;
+}
+
+static int ntshell_callback(const char *text, void *extobj)
 {
     if (ntlibc_strlen(text) > 0) {
-        ntstdio_printf(&ntstdio, "User command is '%s'\r\n", text);
+        ntopt_parse(text, ntopt_callback, extobj);
     }
     return 0;
 }
@@ -94,9 +102,9 @@ void ntshell_task(VP_INT exinf)
                 (IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV))
             );
 
-    ntstdio_init(&ntstdio, uxo, uxi);
-    ntshell_init(&ntshell, func_read, func_write, func_callback, (void *)&ntshell);
-    ntshell_set_prompt(&ntshell, "UZUME>");
-    ntshell_execute(&ntshell);
+    ntstdio_init(&(cmd_env.ntstdio), uxo, uxi);
+    ntshell_init(&(cmd_env.ntshell), func_read, func_write, ntshell_callback, (void *)&cmd_env);
+    ntshell_set_prompt(&(cmd_env.ntshell), "UZUME>");
+    ntshell_execute(&(cmd_env.ntshell));
 }
 
index b09c33f..1b84c41 100644 (file)
@@ -72,7 +72,7 @@
  * ntstdio_printf("%f", 10.0);            <ntstdio_printf lacks floating point support>
  */
 
-static void xvprintf(NTSTDIO *handle, const char *fmt, va_list arp)
+static void xvprintf(ntstdio_t *handle, const char *fmt, va_list arp)
 {
     unsigned int i, j;
     unsigned int flag, radix, width;
@@ -215,14 +215,14 @@ static void xvprintf(NTSTDIO *handle, const char *fmt, va_list arp)
     }
 }
 
-void ntstdio_init(NTSTDIO *handle, NTSTDIO_XO xo, NTSTDIO_XI xi)
+void ntstdio_init(ntstdio_t *handle, NTSTDIO_XO xo, NTSTDIO_XI xi)
 {
     handle->xo = xo;
     handle->xi = xi;
     handle->outptr = 0;
 }
 
-void ntstdio_putc(NTSTDIO *handle, char c)
+void ntstdio_putc(ntstdio_t *handle, char c)
 {
     if ((NTSTDIO_CR_CRLF) && (c == '\n')) {
         ntstdio_putc(handle, '\r');
@@ -238,14 +238,14 @@ void ntstdio_putc(NTSTDIO *handle, char c)
     }
 }
 
-void ntstdio_puts(NTSTDIO *handle, const char *str)
+void ntstdio_puts(ntstdio_t *handle, const char *str)
 {
     while (*str) {
         ntstdio_putc(handle, *str++);
     }
 }
 
-void ntstdio_fputs(NTSTDIO *handle, NTSTDIO_XO xo, const char *str)
+void ntstdio_fputs(ntstdio_t *handle, NTSTDIO_XO xo, const char *str)
 {
     void (*pf)(unsigned char);
 
@@ -262,7 +262,7 @@ void ntstdio_fputs(NTSTDIO *handle, NTSTDIO_XO xo, const char *str)
     handle->xo = pf;
 }
 
-void ntstdio_printf(NTSTDIO *handle, const char *fmt, ...)
+void ntstdio_printf(ntstdio_t *handle, const char *fmt, ...)
 {
     va_list arp;
     va_start(arp, fmt);
@@ -270,7 +270,7 @@ void ntstdio_printf(NTSTDIO *handle, const char *fmt, ...)
     va_end(arp);
 }
 
-void ntstdio_sprintf(NTSTDIO *handle, char *buf, const char *fmt, ...)
+void ntstdio_sprintf(ntstdio_t *handle, char *buf, const char *fmt, ...)
 {
     va_list arp;
     /* Switch destination for memory */
@@ -285,7 +285,7 @@ void ntstdio_sprintf(NTSTDIO *handle, char *buf, const char *fmt, ...)
     handle->outptr = 0;
 }
 
-void ntstdio_fprintf(NTSTDIO *handle, NTSTDIO_XO xo, const char *fmt, ...)
+void ntstdio_fprintf(ntstdio_t *handle, NTSTDIO_XO xo, const char *fmt, ...)
 {
     va_list arp;
     void (*pf)(unsigned char);
@@ -304,7 +304,7 @@ void ntstdio_fprintf(NTSTDIO *handle, NTSTDIO_XO xo, const char *fmt, ...)
 }
 
 /* 0:End of stream, 1:A line arrived */
-int ntstdio_gets(NTSTDIO *handle, char *buf, int len)
+int ntstdio_gets(ntstdio_t *handle, char *buf, int len)
 {
     int c, i;
 
@@ -350,7 +350,7 @@ int ntstdio_gets(NTSTDIO *handle, char *buf, int len)
 }
 
 /* 0:End of stream, 1:A line arrived */
-int ntstdio_fgets(NTSTDIO *handle, NTSTDIO_XI xi, char *buf, int len)
+int ntstdio_fgets(ntstdio_t *handle, NTSTDIO_XI xi, char *buf, int len)
 {
     unsigned char (*pf)(void);
     int n;
index f0fd763..761e4fb 100644 (file)
@@ -69,19 +69,19 @@ typedef struct {
     NTSTDIO_XO xo;
     NTSTDIO_XI xi;
     char *outptr;
-} NTSTDIO;
+} ntstdio_t;
 
-void ntstdio_init(NTSTDIO *handle, NTSTDIO_XO xo, NTSTDIO_XI xi);
+void ntstdio_init(ntstdio_t *handle, NTSTDIO_XO xo, NTSTDIO_XI xi);
 
-void ntstdio_putc(NTSTDIO *handle, char c);
-void ntstdio_puts(NTSTDIO *handle, const char *str);
-void ntstdio_fputs(NTSTDIO *handle, NTSTDIO_XO xo, const char *str);
-void ntstdio_printf(NTSTDIO *handle, const char *fmt, ...);
-void ntstdio_sprintf(NTSTDIO *handle, char *buf, const char *fmt, ...);
-void ntstdio_fprintf(NTSTDIO *handle, NTSTDIO_XO xo, const char *fmt, ...);
+void ntstdio_putc(ntstdio_t *handle, char c);
+void ntstdio_puts(ntstdio_t *handle, const char *str);
+void ntstdio_fputs(ntstdio_t *handle, NTSTDIO_XO xo, const char *str);
+void ntstdio_printf(ntstdio_t *handle, const char *fmt, ...);
+void ntstdio_sprintf(ntstdio_t *handle, char *buf, const char *fmt, ...);
+void ntstdio_fprintf(ntstdio_t *handle, NTSTDIO_XO xo, const char *fmt, ...);
 
-int ntstdio_gets(NTSTDIO *handle, char *buf, int len);
-int ntstdio_fgets(NTSTDIO *handle, NTSTDIO_XI xi, char *buf, int len);
+int ntstdio_gets(ntstdio_t *handle, char *buf, int len);
+int ntstdio_fgets(ntstdio_t *handle, NTSTDIO_XI xi, char *buf, int len);
 
 #endif