Changeset 431
- Timestamp:
- Jul 5, 2020, 3:48:53 PM (3 years ago)
- Location:
- EcnlProtoTool/trunk/ntshell/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/ntshell/src/main.c
r427 r431 79 79 char command[NTOPT_TEXT_MAXLEN]; 80 80 ntstdio_t ntstdio; 81 ntshell_t ntshell; 82 83 unsigned char ntstdio_xi(struct ntstdio_t *handle) 84 { 85 char buf[1]; 86 if(serial_rea_dat(SIO_PORTID, buf, 1) != 1) 87 return -EIO; 88 return buf[0]; 89 } 90 91 void ntstdio_xo(struct ntstdio_t *handle, unsigned char c) 92 { 93 char buf[1]; 94 buf[0] = c; 95 serial_wri_dat(SIO_PORTID, buf, 1); 96 } 81 97 82 98 const uint8_t mac_addr[6] = {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC}; … … 90 106 }; 91 107 92 static void netif_link_callback(T_IFNET *ether); 93 extern int execute_command(int wait); 108 int shell_uname(struct utsname *uts) 109 { 110 memcpy(uts, &host_name, sizeof(host_name)); 111 return 0; 112 } 94 113 95 114 enum main_state_t { … … 98 117 }; 99 118 100 struct main_ t {119 struct main_obj_t { 101 120 TMO timer; 102 121 enum main_state_t state; … … 106 125 WS_FBS_ID sndmsg; 107 126 }; 108 struct main_t main_obj; 109 127 struct main_obj_t main_obj; 128 129 static void netif_link_callback(T_IFNET *ether); 110 130 static void main_initialize(); 111 131 static TMO main_get_timer(); 112 132 static void main_progress(TMO interval); 113 133 static void main_timeout(); 134 extern int execute_command(int wait); 135 static int usrcmd_ntopt_callback(long *args, void *extobj); 136 137 int shellcmd_exit_code; 138 volatile int shellcmd_state; 139 typedef void (*PowerOn_Reset_t)(long *args); 140 jmp_buf shellcmd_exit; 114 141 115 142 int uart_read(char *buf, int cnt, void *extobj) … … 225 252 } 226 253 227 unsigned char ntstdio_xi(struct ntstdio_t *handle) 228 { 229 char buf[1]; 230 if(serial_rea_dat(SIO_PORTID, buf, 1) != 1) 231 return -EIO; 232 return buf[0]; 233 } 234 235 void ntstdio_xo(struct ntstdio_t *handle, unsigned char c) 236 { 237 char buf[1]; 238 buf[0] = c; 239 serial_wri_dat(SIO_PORTID, buf, 1); 240 } 241 242 ntshell_t ntshell; 243 static int cmd_execute(const char *text, void *extobj); 254 static int cmd_execute(const char *text, void *extobj) 255 { 256 if (text != NULL) { 257 ntlibc_strlcpy(command, text, sizeof(command)); 258 } 259 ER ret; 260 ID tskid = 0; 261 262 ret = get_tid(&tskid); 263 if (ret != E_OK) { 264 syslog(LOG_ERROR, "get_tid %d", ret); 265 } 266 267 return execute_command(tskid == MAIN_TASK); 268 } 244 269 245 270 /* … … 363 388 ER ret; 364 389 365 ret = ref_tsk( MRUBY_TASK, &rtsk);390 ret = ref_tsk(SHELLCMD_TASK, &rtsk); 366 391 if ((ret != E_OK) || (rtsk.tskstat == TTS_DMT)) 367 392 return; … … 372 397 } 373 398 374 int shell_uname(struct utsname *uts)375 {376 return memcpy(uts, &host_name, sizeof(host_name));377 }378 379 static int usrcmd_ntopt_callback(long *args, void *extobj);380 int mruby_exit_code;381 volatile int mruby_state;382 typedef void (*PowerOn_Reset_t)(long *args);383 jmp_buf process_exit;384 385 399 /* 386 * mruby実行タスク400 * shellcmdタスク 387 401 */ 388 void mruby_task(intptr_t exinf)389 { 390 mruby_state = 1;391 mruby_exit_code = ntopt_parse(command, usrcmd_ntopt_callback, NULL);392 mruby_state = 2;402 void shellcmd_task(intptr_t exinf) 403 { 404 shellcmd_state = 1; 405 shellcmd_exit_code = ntopt_parse(command, usrcmd_ntopt_callback, NULL); 406 shellcmd_state = 2; 393 407 } 394 408 … … 424 438 p++; 425 439 } 426 if (setjmp( process_exit) == 0) {440 if (setjmp(shellcmd_exit) == 0) { 427 441 (*((PowerOn_Reset_t *)0x18220000))(args); 428 442 } … … 447 461 { 448 462 /* メインタスクの優先度より高くする */ 449 chg_pri( MRUBY_PRIORITY, MAIN_PRIORITY + 1);463 chg_pri(SHELLCMD_PRIORITY, MAIN_PRIORITY + 1); 450 464 } 451 465 452 466 void shellif_outof() 453 467 { 454 /* mruby実行タスクの優先度に戻す */455 chg_pri( MRUBY_PRIORITY, MRUBY_PRIORITY);468 /* shellcmdタスクの優先度に戻す */ 469 chg_pri(SHELLCMD_PRIORITY, SHELLCMD_PRIORITY); 456 470 } 457 471 … … 460 474 asm("bkpt #0"); 461 475 462 mruby_exit_code = -1;463 longjmp( process_exit, 1);476 shellcmd_exit_code = -1; 477 longjmp(shellcmd_exit, 1); 464 478 } 465 479 466 480 void shell_exit(int exitcd) 467 481 { 468 mruby_exit_code = exitcd;469 longjmp( process_exit, 1);482 shellcmd_exit_code = exitcd; 483 longjmp(shellcmd_exit, 1); 470 484 } 471 485 472 486 void shell_exit_group(int exitcd) 473 487 { 474 mruby_exit_code = exitcd;475 longjmp( process_exit, 1);488 shellcmd_exit_code = exitcd; 489 longjmp(shellcmd_exit, 1); 476 490 } 477 491 … … 480 494 ER ret; 481 495 482 ret = ter_tsk( MRUBY_TASK);496 ret = ter_tsk(SHELLCMD_TASK); 483 497 if ((ret != E_OK) && (ret != E_OBJ)) { 484 498 syslog(LOG_ERROR, "ter_tsk => %d", ret); … … 489 503 clean_fd(); 490 504 491 mruby_state = 0;492 ret = act_tsk( MRUBY_TASK);505 shellcmd_state = 0; 506 ret = act_tsk(SHELLCMD_TASK); 493 507 if (ret != E_OK) { 494 508 syslog(LOG_ERROR, "act_tsk => %d", ret); … … 500 514 do { 501 515 tslp_tsk(100000); 502 } while(mruby_state == 1); 503 504 return mruby_exit_code; 505 } 506 507 static int cmd_execute(const char *text, void *extobj) 508 { 509 ntlibc_strlcpy(command, text, sizeof(command)); 510 return execute_command(1); 516 } while(shellcmd_state == 1); 517 518 return shellcmd_exit_code; 519 } 520 521 int shell_clock_getres(clockid_t clk_id, struct timespec *res) 522 { 523 if (clk_id != CLOCK_REALTIME) 524 return -EINVAL; 525 526 memset(&res->tv_sec, 0xFF, sizeof(res->tv_sec)); 527 res->tv_nsec = 0; 528 529 return 0; 530 } 531 532 int shell_clock_gettime(clockid_t clk_id, struct timespec *tp) 533 { 534 SYSTIM now = 0; 535 536 if (clk_id != CLOCK_REALTIME) 537 return -EINVAL; 538 539 get_tim(&now); 540 tp->tv_sec = now / 1000000; 541 tp->tv_nsec = (now % 1000000) * 1000; 542 543 return 0; 544 } 545 546 int shell_clock_settime(clockid_t clk_id, const struct timespec *tp) 547 { 548 if (clk_id != CLOCK_REALTIME) 549 return -EINVAL; 550 551 rtc_write(tp->tv_sec); 552 553 return 0; 554 } 555 556 sigset_t g_sigmask; 557 558 int shell_sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict old) 559 { 560 if (old != NULL) 561 memcpy(old, &g_sigmask, sizeof(sigset_t)); 562 563 switch (how) { 564 case SIG_BLOCK: 565 for (int i = 0; i < sizeof(g_sigmask.__bits) / sizeof(g_sigmask.__bits[0]); i++) { 566 g_sigmask.__bits[i] |= set->__bits[i]; 567 } 568 break; 569 case SIG_UNBLOCK: 570 for (int i = 0; i < sizeof(g_sigmask.__bits) / sizeof(g_sigmask.__bits[0]); i++) { 571 g_sigmask.__bits[i] &= ~set->__bits[i]; 572 } 573 break; 574 case SIG_SETMASK: 575 memcpy(&g_sigmask, set, sizeof(sigset_t)); 576 break; 577 default: 578 return -EINVAL; 579 } 580 581 return 0; 582 } 583 584 struct sigaction sigtable[6]; 585 586 int shell_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old) 587 { 588 struct sigaction *sat; 589 590 switch(sig){ 591 case SIGALRM: 592 sat = &sigtable[0]; 593 break; 594 case SIGFPE: 595 sat = &sigtable[1]; 596 break; 597 case SIGILL: 598 sat = &sigtable[2]; 599 break; 600 case SIGSEGV: 601 sat = &sigtable[3]; 602 break; 603 case SIGBUS: 604 sat = &sigtable[4]; 605 break; 606 case SIGABRT: 607 sat = &sigtable[5]; 608 break; 609 default: 610 return -EINVAL; 611 } 612 613 if (old != NULL) 614 memcpy(old, sat, sizeof(struct sigaction)); 615 616 memcpy(sat, sa, sizeof(struct sigaction)); 617 618 return 0; 619 } 620 621 int shell_madvise(void *a, size_t b, int c) 622 { 623 return 0; 511 624 } 512 625 … … 590 703 } 591 704 592 int shell_clock_getres(clockid_t clk_id, struct timespec *res)593 {594 if (clk_id != CLOCK_REALTIME)595 return -EINVAL;596 597 memset(&res->tv_sec, 0xFF, sizeof(res->tv_sec));598 res->tv_nsec = 0;599 600 return 0;601 }602 603 int shell_clock_gettime(clockid_t clk_id, struct timespec *tp)604 {605 SYSTIM now = 0;606 607 if (clk_id != CLOCK_REALTIME)608 return -EINVAL;609 610 get_tim(&now);611 tp->tv_sec = now / 1000000;612 tp->tv_nsec = (now % 1000000) * 1000;613 614 return 0;615 }616 617 int shell_clock_settime(clockid_t clk_id, const struct timespec *tp)618 {619 if (clk_id != CLOCK_REALTIME)620 return -EINVAL;621 622 rtc_write(tp->tv_sec);623 624 return 0;625 }626 627 sigset_t g_sigmask;628 629 int shell_sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict old)630 {631 if (old != NULL)632 memcpy(old, &g_sigmask, sizeof(sigset_t));633 634 switch (how) {635 case SIG_BLOCK:636 for (int i = 0; i < sizeof(g_sigmask.__bits) / sizeof(g_sigmask.__bits[0]); i++) {637 g_sigmask.__bits[i] |= set->__bits[i];638 }639 break;640 case SIG_UNBLOCK:641 for (int i = 0; i < sizeof(g_sigmask.__bits) / sizeof(g_sigmask.__bits[0]); i++) {642 g_sigmask.__bits[i] &= ~set->__bits[i];643 }644 break;645 case SIG_SETMASK:646 memcpy(&g_sigmask, set, sizeof(sigset_t));647 break;648 default:649 return -EINVAL;650 }651 652 return 0;653 }654 655 struct sigaction sigtable[6];656 657 int shell_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)658 {659 struct sigaction *sat;660 661 switch(sig){662 case SIGALRM:663 sat = &sigtable[0];664 break;665 case SIGFPE:666 sat = &sigtable[1];667 break;668 case SIGILL:669 sat = &sigtable[2];670 break;671 case SIGSEGV:672 sat = &sigtable[3];673 break;674 case SIGBUS:675 sat = &sigtable[4];676 break;677 case SIGABRT:678 sat = &sigtable[5];679 break;680 default:681 return -EINVAL;682 }683 684 if (old != NULL)685 memcpy(old, sat, sizeof(struct sigaction));686 687 memcpy(sat, sa, sizeof(struct sigaction));688 689 return 0;690 }691 692 int shell_madvise(void *a, size_t b, int c)693 {694 return 0;695 }696 -
EcnlProtoTool/trunk/ntshell/src/main.cfg
r331 r431 61 61 CRE_SEM(SEM_FILESYSTEM, { TA_TPRI, 1, 1 }); 62 62 63 CRE_TSK( MRUBY_TASK, { TA_NULL, 0, mruby_task, MRUBY_PRIORITY, MRUBY_STACK_SIZE, (void *)0x20100000 });63 CRE_TSK(SHELLCMD_TASK, { TA_NULL, 0, shellcmd_task, SHELLCMD_PRIORITY, SHELLCMD_STACK_SIZE, (void *)0x20100000 }); 64 64 CRE_FLG(FLG_SELECT_WAIT, { TA_WMUL, 0x00 }); -
EcnlProtoTool/trunk/ntshell/src/main.h
r331 r431 53 53 54 54 #define MAIN_PRIORITY 5 /* メインタスクの優先度 */ 55 #define MRUBY_PRIORITY 4 /* mruby実行タスクの優先度 */55 #define SHELLCMD_PRIORITY 4 /* shellcmdタスクの優先度 */ 56 56 57 57 #define MAIN_STACK_SIZE 2048 /* メインタスクのスタック領域のサイズ */ 58 #define MRUBY_STACK_SIZE 0x00800000 /* mruby実行タスクのスタック領域のサイズ */58 #define SHELLCMD_STACK_SIZE 0x00800000 /* shellcmdタスクのスタック領域のサイズ */ 59 59 60 60 #define NUM_MAIN_DATAQUEUE 1 /* メインタスクで待ち受けているデータキューのサイズ */ 61 #define NUM_ MRUBY_DATAQUEUE 1 /* mruby実行タスクで待ち受けているデータキューのサイズ */61 #define NUM_SHELLCMD_DATAQUEUE 1 /* shellcmdタスクで待ち受けているデータキューのサイズ */ 62 62 63 63 /* … … 69 69 extern void main_task(intptr_t exinf); 70 70 71 /* mruby実行タスク */72 extern void mruby_task(intptr_t exinf);71 /* shellcmdタスク */ 72 extern void shellcmd_task(intptr_t exinf); 73 73 74 74 /*
Note:
See TracChangeset
for help on using the changeset viewer.