OSDN Git Service

First commitment for the BlackTank LPC1769.
[blacktank/blacktank.git] / cmd.c
1 /**
2  * @file cmd.c
3  * @author Shinichiro Nakamura
4  * @brief ナチュラルタイニーシェルタスクコマンドの実装
5  * @details
6  */
7
8 #include <kernel.h>
9 #include <t_syslog.h>
10 #include <target_syssvc.h>
11 #include <syssvc/serial.h>
12 #include <logtrace/trace_config.h>
13
14 #include "kernel_cfg.h"
15 #include "ntopt.h"
16 #include "ntlibc.h"
17 #include "ff.h"
18
19 #include "task_audio.h"
20 #include "task_led.h"
21 #include "task_display.h"
22
23 char curdir[32];
24 FATFS fatfs[_VOLUMES];
25 DIR dir;
26 FIL fil;
27 FILINFO filinfo;
28
29 void cmd_taskinfo(int argc, char **argv) {
30     int i;
31     T_ITSK itsk;
32     syslog(LOG_NOTICE, "TSKID\tSTACK ADDR (HEAD:TAIL)\tSTACK USED (USED/TOTAL)");
33     syslog(LOG_NOTICE, "=========================================================");
34     for (i = 0; i < TNUM_TSKID; i++) {
35         const int tskid = 1 + i;
36         inf_tsk(tskid, &itsk);
37         syslog(LOG_NOTICE, " %2d\t0x%x:0x%x\t%5d/%5d",
38                 tskid,
39                 itsk.stk_head, itsk.stk_tail,
40                 itsk.stk_used, itsk.stk_total);
41 #if 0
42         syslog(LOG_NOTICE, " (%02d:%02d)",
43                 itsk.tsk_pri_curr, itsk.tsk_pri_base);
44 #endif
45     }
46     syslog(LOG_NOTICE, "=========================================================");
47 }
48
49 void cmd_audio(int argc, char **argv) {
50     if (argc == 2) {
51         if (ntlibc_strcmp(argv[1], "through") == 0) {
52             TSKAPI_AUDIO_PARAM(AUDIO_PARAM_MODE, AUDIO_VALUE_MODE_THROUGH);
53             return;
54         }
55         if (ntlibc_strcmp(argv[1], "vocal_cancel") == 0) {
56             TSKAPI_AUDIO_PARAM(AUDIO_PARAM_MODE, AUDIO_VALUE_MODE_VOCAL_CANCEL);
57             return;
58         }
59         if (ntlibc_strcmp(argv[1], "fir") == 0) {
60             TSKAPI_AUDIO_PARAM(AUDIO_PARAM_MODE, AUDIO_VALUE_MODE_FIR);
61             return;
62         }
63         if (ntlibc_strcmp(argv[1], "iir") == 0) {
64             TSKAPI_AUDIO_PARAM(AUDIO_PARAM_MODE, AUDIO_VALUE_MODE_IIR);
65             return;
66         }
67     }
68     syslog(LOG_NOTICE, "audio [through | vocal_cancel | fir | iir]");
69 }
70
71 void cmd_lcd(int argc, char **argv) {
72     if (argc == 2) {
73         if (ntlibc_strcmp(argv[1], "cls") == 0) {
74             TSKAPI_DISPLAY_CLEAR(0x00, 0x00, 0x00);
75             return;
76         }
77     }
78     syslog(LOG_NOTICE, "lcd cls : Clear the LCD.");
79 }
80
81 void cmd_led(int argc, char **argv) {
82     if (argc != 3) {
83         syslog(LOG_NOTICE, "led [DBLEDn|SWLEDn] [ON|OFF]");
84         return;
85     }
86     if (ntlibc_strcmp(argv[1], "DBLED0") == 0) {
87         if (ntlibc_strcmp(argv[2], "ON") == 0) {
88             TSKAPI_LED_LEDMSG(DBLED0, LEDON);
89             return;
90         }
91         if (ntlibc_strcmp(argv[2], "OFF") == 0) {
92             TSKAPI_LED_LEDMSG(DBLED0, LEDOFF);
93             return;
94         }
95     }
96     if (ntlibc_strcmp(argv[1], "DBLED1") == 0) {
97         if (ntlibc_strcmp(argv[2], "ON") == 0) {
98             TSKAPI_LED_LEDMSG(DBLED1, LEDON);
99             return;
100         }
101         if (ntlibc_strcmp(argv[2], "OFF") == 0) {
102             TSKAPI_LED_LEDMSG(DBLED1, LEDOFF);
103             return;
104         }
105     }
106     if (ntlibc_strcmp(argv[1], "DBLED2") == 0) {
107         if (ntlibc_strcmp(argv[2], "ON") == 0) {
108             TSKAPI_LED_LEDMSG(DBLED2, LEDON);
109             return;
110         }
111         if (ntlibc_strcmp(argv[2], "OFF") == 0) {
112             TSKAPI_LED_LEDMSG(DBLED2, LEDOFF);
113             return;
114         }
115     }
116     if (ntlibc_strcmp(argv[1], "DBLED3") == 0) {
117         if (ntlibc_strcmp(argv[2], "ON") == 0) {
118             TSKAPI_LED_LEDMSG(DBLED3, LEDON);
119             return;
120         }
121         if (ntlibc_strcmp(argv[2], "OFF") == 0) {
122             TSKAPI_LED_LEDMSG(DBLED3, LEDOFF);
123             return;
124         }
125     }
126     if (ntlibc_strcmp(argv[1], "SWLED0") == 0) {
127         if (ntlibc_strcmp(argv[2], "ON") == 0) {
128             TSKAPI_LED_LEDMSG(SWLED0, LEDON);
129             return;
130         }
131         if (ntlibc_strcmp(argv[2], "OFF") == 0) {
132             TSKAPI_LED_LEDMSG(SWLED0, LEDOFF);
133             return;
134         }
135     }
136     if (ntlibc_strcmp(argv[1], "SWLED1") == 0) {
137         if (ntlibc_strcmp(argv[2], "ON") == 0) {
138             TSKAPI_LED_LEDMSG(SWLED1, LEDON);
139             return;
140         }
141         if (ntlibc_strcmp(argv[2], "OFF") == 0) {
142             TSKAPI_LED_LEDMSG(SWLED1, LEDOFF);
143             return;
144         }
145     }
146     if (ntlibc_strcmp(argv[1], "SWLED2") == 0) {
147         if (ntlibc_strcmp(argv[2], "ON") == 0) {
148             TSKAPI_LED_LEDMSG(SWLED2, LEDON);
149             return;
150         }
151         if (ntlibc_strcmp(argv[2], "OFF") == 0) {
152             TSKAPI_LED_LEDMSG(SWLED2, LEDOFF);
153             return;
154         }
155     }
156     if (ntlibc_strcmp(argv[1], "SWLED3") == 0) {
157         if (ntlibc_strcmp(argv[2], "ON") == 0) {
158             TSKAPI_LED_LEDMSG(SWLED3, LEDON);
159             return;
160         }
161         if (ntlibc_strcmp(argv[2], "OFF") == 0) {
162             TSKAPI_LED_LEDMSG(SWLED3, LEDOFF);
163             return;
164         }
165     }
166     syslog(LOG_NOTICE, "Invalid command.");
167 }
168
169 void cmd_mount(int argc, char **argv) {
170     int a = f_mount(0, &fatfs[0]);
171     int b = f_opendir(&dir, "");
172     ntlibc_strcpy(curdir, "");
173     if ((a == 0) && (b == 0)) {
174         syslog(LOG_NOTICE, "Mounted the SD card.");
175     } else {
176         syslog(LOG_NOTICE, "Failure to mount the SD card.");
177     }
178 }
179
180 void cmd_ls(int argc, char **argv) {
181     int r;
182     r = f_opendir(&dir, curdir);
183     if (r) {
184         syslog(LOG_NOTICE, "Failure to open the directory. (code=%d)", r);
185         return;
186     }
187     while (1) {
188         r = f_readdir(&dir, &filinfo);
189         if (r != FR_OK) {
190             syslog(LOG_NOTICE, "Failure to read the directory. (code=%d)", r);
191             return;
192         }
193         if (!filinfo.fname[0]) {
194             break;
195         }
196         if (filinfo.fattrib & AM_DIR) {
197             syslog(LOG_NOTICE, "<DIR>\t%s", filinfo.fname);
198         } else {
199             syslog(LOG_NOTICE, "%d\t%s", filinfo.fsize, filinfo.fname);
200         }
201         tslp_tsk(10);
202     }
203 }
204
205 void cmd_cd(int argc, char **argv) {
206     int r;
207     switch (argc) {
208         case 1:
209             r = f_opendir(&dir, "");
210             if (!r) {
211                 ntlibc_strcpy(curdir, "");
212             }
213             break;
214         case 2:
215             r = f_opendir(&dir, argv[1]);
216             if (!r) {
217                 ntlibc_strcpy(curdir, argv[1]);
218             }
219             break;
220         default:
221             syslog(LOG_NOTICE, "cd [dir]");
222             return;
223     }
224     if (r) {
225         syslog(LOG_NOTICE, "Failure to open the director. (code=%d)", r);
226         return;
227     }
228 }
229
230 void cmd_trace(int argc, char **argv) {
231 #ifdef TOPPERS_ENABLE_TRACE
232     syslog(LOG_NOTICE, "trace started.");
233     tslp_tsk(250);
234     trace_sta_log(TRACE_STOP);
235     trace_sta_log(TRACE_CLEAR);
236     trace_sta_log(TRACE_AUTOSTOP);
237 #else
238     syslog(LOG_NOTICE, "trace disabled in this build.");
239 #endif
240 }
241
242 void cmd_exit(int argc, char **argv) {
243     ext_ker();
244 }
245