OSDN Git Service

First commitment for the BlackTank LPC1769.
[blacktank/blacktank.git] / task_ntshell.c
1 /**
2  * @file task_ntshell.c
3  * @author Shinichiro Nakamura
4  * @brief ナチュラルタイニーシェルタスクの実装(task_ntshell)
5  * @details
6  * システムをコンソールから制御することのできるインターフェースタスク。
7  * 主に開発者のために提供される。
8  */
9
10 #include <kernel.h>
11 #include <t_syslog.h>
12 #include <target_syssvc.h>
13 #include <syssvc/serial.h>
14 #include <logtrace/trace_config.h>
15
16 #include "kernel_cfg.h"
17
18 #include "task_ntshell.h"
19 #include "task_led.h"
20 #include "task_display.h"
21 #include "task_audio.h"
22
23 #include "ntshell.h"
24 #include "ntopt.h"
25 #include "ntlibc.h"
26 #include "cmd.h"
27
28 ntshell_t ntshell;
29
30 int func_read(char *buf, int cnt);
31 int func_write(const char *buf, int cnt);
32 int func_ntopt(int argc, char **argv, void *extobj);
33 int func_ntshell(const char *text);
34
35 typedef struct {
36     char *command;
37     char *description;
38     void (*func)(int argc, char **argv);
39 } command_table_t;
40
41 const command_table_t table[] = {
42     {"taskinfo", "Task information.", cmd_taskinfo},
43     {"audio", "Audio task parameter.", cmd_audio},
44     {"lcd", "Control the LCD.", cmd_lcd},
45     {"led", "Set state of the debug purpose LED.", cmd_led},
46     {"mount", "Mount a SD card.", cmd_mount},
47     {"ls", "List contents on a SD card.", cmd_ls},
48     {"cd", "Change the current directory.", cmd_cd},
49     {"trace", "Trace the kernel conditions.", cmd_trace},
50     {"exit", "Exit the kernel.", cmd_exit},
51     {NULL, NULL, NULL}
52 };
53
54 void cmd_help(void) {
55     const command_table_t *p = &table[0];
56     char buf[64];
57     while (p->command != NULL) {
58         ntlibc_strcpy(buf, p->command);
59         ntlibc_strcat(buf, "\t:");
60         ntlibc_strcat(buf, p->description);
61         syslog(LOG_NOTICE, buf);
62         tslp_tsk(10);
63         p++;
64     }
65 }
66
67 int func_read(char *buf, int cnt)
68 {
69     return serial_rea_dat(SIO_PORTID, (char_t *)buf, cnt);
70 }
71
72 int func_write(const char *buf, int cnt)
73 {
74     return serial_wri_dat(SIO_PORTID, (const char_t *)buf, cnt);
75 }
76
77 int func_ntopt(int argc, char **argv, void *extobj)
78 {
79     if (argc == 0) {
80         return 0;
81     }
82
83     int execnt = 0;
84     const command_table_t *p = &table[0];
85     while (p->command != NULL) {
86         if (ntlibc_strcmp((const char *)argv[0], p->command) == 0) {
87             p->func(argc, argv);
88             execnt++;
89         }
90         p++;
91     }
92     if (execnt == 0) {
93         if (argc > 0) {
94             cmd_help();
95         } else {
96             syslog(LOG_NOTICE,
97                     "Found unknown command. (help: display help.)");
98         }
99     }
100
101     tslp_tsk(250);
102     return 0;
103 }
104
105 int func_ntshell(const char *text)
106 {
107     return ntopt_parse((const char *)text, NULL, func_ntopt);
108 }
109
110 /**
111  * \brief メインタスク
112  * \param exinf コンフィギュレータから渡す引数。今回は利用しない
113  * \details
114  */
115 void task_ntshell(intptr_t exinf)
116 {
117     serial_opn_por(SIO_PORTID);
118
119     ntshell_execute(&ntshell, func_read, func_write, func_ntshell);
120 }
121