Changeset 374 for asp3_tinet_ecnl_rx/trunk/ntshell/src/ntshell_main.c
- Timestamp:
- Apr 5, 2019, 9:26:53 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
asp3_tinet_ecnl_rx/trunk/ntshell/src/ntshell_main.c
r364 r374 59 59 #include "ntshell_main.h" 60 60 #include "socket_stub.h" 61 #include "usb_hbth.h"62 #include "mbed_api.h"63 64 extern int bt_bnep_mode;65 61 66 62 char command[NTOPT_TEXT_MAXLEN]; 67 ntstdio_t ntstdio;68 63 69 64 extern uint8_t mac_addr[6]; … … 88 83 volatile int ntshell_state; 89 84 jmp_buf process_exit; 90 void sys_init(void); 91 NTSHELL_SERIAL_READ ntshell_serial_read = 0; 92 NTSHELL_SERIAL_WRITE ntshell_serial_write = 0; 93 void *ntshell_serial_extobj; 94 95 unsigned char ntstdio_xi(struct ntstdio_t *handle) 96 { 97 unsigned char buf[1]; 98 ntshell_serial_read((char *)buf, 1, ntshell_serial_extobj); 99 return buf[0]; 100 } 101 102 void ntstdio_xo(struct ntstdio_t *handle, unsigned char c) 103 { 104 char buf[1]; 105 buf[0] = c; 106 ntshell_serial_write(buf, 1, ntshell_serial_extobj); 107 } 108 109 void ntshell_task_init(NTSHELL_SERIAL_READ func_read, 110 NTSHELL_SERIAL_WRITE func_write, void *extobj) 111 { 112 ntshell_serial_read = func_read; 113 ntshell_serial_write = func_write; 114 ntshell_serial_extobj = extobj; 115 116 sys_init(); 117 118 ntstdio_init(&ntstdio, NTSTDIO_OPTION_LINE_ECHO | NTSTDIO_OPTION_CANON | NTSTDIO_OPTION_LF_CRLF | NTSTDIO_OPTION_LF_CR, ntstdio_xi, ntstdio_xo); 85 86 void ntshell_task_init(ID portid) 87 { 88 serial_ctl_por(portid, IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV); 119 89 } 120 90 … … 178 148 const cmd_table_t *p = cmd_table_info.table; 179 149 for (int i = 0; i < cmd_table_info.count; i++) { 180 ntstdio_puts(&ntstdio, p->cmd); 181 ntstdio_puts(&ntstdio, "\t:"); 182 ntstdio_puts(&ntstdio, p->desc); 183 ntstdio_puts(&ntstdio, "\n"); 150 fwrite(p->cmd, strlen(p->cmd), 1, stdout); 151 fwrite("\t:", strlen("\t:"), 1, stdout); 152 puts(p->desc); 184 153 p++; 185 154 } … … 207 176 int execute_command(int wait) 208 177 { 178 T_RTSK rtsk; 209 179 ER ret; 210 180 … … 229 199 do { 230 200 tslp_tsk(100000); 201 202 ret = ref_tsk(NTSHELL_TASK, &rtsk); 203 if ((ret != E_OK) || (rtsk.tskstat == TTS_DMT)) 204 ntshell_state = 3; 231 205 } while(ntshell_state == 1); 232 206 … … 238 212 ntlibc_strlcpy(command, text, sizeof(command)); 239 213 return execute_command(1); 240 }241 242 int stdio_close(struct _IO_FILE *fp)243 {244 return -EPERM;245 }246 247 size_t stdio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)248 {249 return -EPERM;250 }251 252 size_t stdio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)253 {254 return -EPERM;255 }256 257 size_t stdin_read(struct _IO_FILE *fp, unsigned char *data, size_t len)258 {259 int i = 0;260 while (i < len) {261 int c = ntstdio_getc(&ntstdio);262 data[i++] = c;263 if ((c == EOF) || (c == '\n'))264 break;265 }266 return i;267 }268 269 size_t stdout_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)270 {271 for (int i = 0; i < len; i++) {272 ntstdio_putc(&ntstdio, data[i]);273 }274 return len;275 }276 277 size_t stderr_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)278 {279 for (int i = 0; i < len; i++) {280 ntstdio_putc(&ntstdio, data[i]);281 }282 return len;283 }284 285 int sio_close(struct _IO_FILE *fp)286 {287 return -EPERM;288 }289 290 size_t sio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)291 {292 return -EPERM;293 }294 295 size_t sio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)296 {297 return -EPERM;298 }299 300 off_t sio_seek(struct _IO_FILE *fp, off_t ofs, int org)301 {302 return -EPERM;303 }304 305 int sio_ioctl(struct _IO_FILE *fp, int request, void *arg)306 {307 switch (request) {308 case TIOCGWINSZ:309 return 0;310 case TCGETS:311 return sio_tcgetattr(fp->fd, (struct termios *)arg);312 case TCSETS + TCSANOW:313 case TCSETS + TCSADRAIN:314 case TCSETS + TCSAFLUSH:315 return sio_tcsetattr(fp->fd, request - TCSETS, (const struct termios *)arg);316 }317 318 return -EINVAL;319 214 } 320 215 … … 457 352 } 458 353 354 int shell_kill(int pid, int sig) 355 { 356 DebugBreak(); 357 return -1; 358 } 359 360 int shell_gettimeofday(struct timeval *tv, void *tzvp) 361 { 362 SYSTIM time; 363 if (!tv) return 0; 364 get_tim(&time); 365 tv->tv_sec = time / 1000000; 366 tv->tv_usec = time - (tv->tv_sec * 1000000); 367 return 0; 368 } 369
Note:
See TracChangeset
for help on using the changeset viewer.