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
#
# リンカスクリプトの定義
--- /dev/null
+/**
+ * @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]);
+ }
+}
+
--- /dev/null
+/**
+ * @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
+
*/
#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)
{
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;
}
(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));
}
* 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;
}
}
-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');
}
}
-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);
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);
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 */
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);
}
/* 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;
}
/* 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;
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