RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
shell.c
浏览该文件的文档.
1/*
2 * Copyright (c) 2006-2021, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2006-04-30 Bernard the first version for FinSH
9 * 2006-05-08 Bernard change finsh thread stack to 2048
10 * 2006-06-03 Bernard add support for skyeye
11 * 2006-09-24 Bernard remove the code related with hardware
12 * 2010-01-18 Bernard fix down then up key bug.
13 * 2010-03-19 Bernard fix backspace issue and fix device read in shell.
14 * 2010-04-01 Bernard add prompt output when start and remove the empty history
15 * 2011-02-23 Bernard fix variable section end issue of finsh shell
16 * initialization when use GNU GCC compiler.
17 * 2016-11-26 armink add password authentication
18 * 2018-07-02 aozima add custom prompt support.
19 */
20
21#include <rthw.h>
22#include <string.h>
23#include <stdio.h>
24
25#ifdef RT_USING_FINSH
26
27#include "shell.h"
28#include "msh.h"
29
30#ifdef DFS_USING_POSIX
31#include <unistd.h>
32#include <fcntl.h>
33#endif /* DFS_USING_POSIX */
34
35#ifdef RT_USING_POSIX_STDIO
36#include <unistd.h>
37#include <posix/stdio.h>
38#endif /* RT_USING_POSIX_STDIO */
39
40/* finsh thread */
41#ifndef RT_USING_HEAP
42 static struct rt_thread finsh_thread;
43 rt_align(RT_ALIGN_SIZE)
44 static char finsh_thread_stack[FINSH_THREAD_STACK_SIZE];
45 struct finsh_shell _shell;
46#endif
47
48/* finsh symtab */
49#ifdef FINSH_USING_SYMTAB
52#endif
53
55static char *finsh_prompt_custom = RT_NULL;
56
57#if defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__))
58struct finsh_syscall *finsh_syscall_next(struct finsh_syscall *call)
59{
60 unsigned int *ptr;
61 ptr = (unsigned int *)(call + 1);
62 while ((*ptr == 0) && ((unsigned int *)ptr < (unsigned int *) _syscall_table_end))
63 ptr ++;
64
65 return (struct finsh_syscall *)ptr;
66}
67
68#endif /* defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__)) */
69
70#ifdef RT_USING_HEAP
71int finsh_set_prompt(const char *prompt)
72{
73 if (finsh_prompt_custom)
74 {
75 rt_free(finsh_prompt_custom);
76 finsh_prompt_custom = RT_NULL;
77 }
78
79 /* strdup */
80 if (prompt)
81 {
82 finsh_prompt_custom = (char *)rt_malloc(strlen(prompt) + 1);
83 if (finsh_prompt_custom)
84 {
85 strcpy(finsh_prompt_custom, prompt);
86 }
87 }
88
89 return 0;
90}
91#endif /* RT_USING_HEAP */
92
93#define _MSH_PROMPT "msh "
94
95const char *finsh_get_prompt(void)
96{
97 static char finsh_prompt[RT_CONSOLEBUF_SIZE + 1] = {0};
98
99 /* check prompt mode */
100 if (!shell->prompt_mode)
101 {
102 finsh_prompt[0] = '\0';
103 return finsh_prompt;
104 }
105
106 if (finsh_prompt_custom)
107 {
108 strncpy(finsh_prompt, finsh_prompt_custom, sizeof(finsh_prompt) - 1);
109 }
110 else
111 {
112 strcpy(finsh_prompt, _MSH_PROMPT);
113 }
114
115#if defined(DFS_USING_POSIX) && defined(DFS_USING_WORKDIR)
116 /* get current working directory */
117 getcwd(&finsh_prompt[rt_strlen(finsh_prompt)], RT_CONSOLEBUF_SIZE - rt_strlen(finsh_prompt));
118#endif
119
120 if (rt_strlen(finsh_prompt) + 2 < RT_CONSOLEBUF_SIZE)
121 {
122 finsh_prompt[rt_strlen(finsh_prompt)] = '>';
123 finsh_prompt[rt_strlen(finsh_prompt) + 1] = '\0';
124 }
125
126 return finsh_prompt;
127}
128
137{
139 return shell->prompt_mode;
140}
141
152{
154 shell->prompt_mode = prompt_mode;
155}
156
158{
159#ifdef RT_USING_DEVICE
160 char ch = 0;
161#ifdef RT_USING_POSIX_STDIO
162 if(read(rt_posix_stdio_get_console(), &ch, 1) > 0)
163 {
164 return ch;
165 }
166 else
167 {
168 return -1; /* EOF */
169 }
170#else
171 rt_device_t device;
172
174
175 device = shell->device;
176 if (device == RT_NULL)
177 {
178 return -1; /* EOF */
179 }
180
181 while (rt_device_read(device, -1, &ch, 1) != 1)
182 {
184 if (shell->device != device)
185 {
186 device = shell->device;
187 if (device == RT_NULL)
188 {
189 return -1;
190 }
191 }
192 }
193 return ch;
194#endif /* RT_USING_POSIX_STDIO */
195#else
196 extern char rt_hw_console_getchar(void);
197 return rt_hw_console_getchar();
198#endif /* RT_USING_DEVICE */
199}
200
201#if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
202static rt_err_t finsh_rx_ind(rt_device_t dev, rt_size_t size)
203{
205
206 /* release semaphore to let finsh thread rx data */
207 rt_sem_release(&shell->rx_sem);
208
209 return RT_EOK;
210}
211
219void finsh_set_device(const char *device_name)
220{
221 rt_device_t dev = RT_NULL;
222
224 dev = rt_device_find(device_name);
225 if (dev == RT_NULL)
226 {
227 rt_kprintf("finsh: can not find device: %s\n", device_name);
228 return;
229 }
230
231 /* check whether it's a same device */
232 if (dev == shell->device) return;
233 /* open this device and set the new device in finsh shell */
235 RT_DEVICE_FLAG_STREAM) == RT_EOK)
236 {
237 if (shell->device != RT_NULL)
238 {
239 /* close old finsh device */
240 rt_device_close(shell->device);
242 }
243
244 /* clear line buffer before switch to new device */
245 rt_memset(shell->line, 0, sizeof(shell->line));
246 shell->line_curpos = shell->line_position = 0;
247
248 shell->device = dev;
249 rt_device_set_rx_indicate(dev, finsh_rx_ind);
250 }
251}
252
260const char *finsh_get_device()
261{
263 return shell->device->parent.name;
264}
265#endif /* !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE) */
266
277{
279 shell->echo_mode = (rt_uint8_t)echo;
280}
281
290{
292
293 return shell->echo_mode;
294}
295
296#ifdef FINSH_USING_AUTH
305rt_err_t finsh_set_password(const char *password)
306{
307 rt_base_t level;
308 rt_size_t pw_len = rt_strlen(password);
309
310 if (pw_len < FINSH_PASSWORD_MIN || pw_len > FINSH_PASSWORD_MAX)
311 return -RT_ERROR;
312
313 level = rt_hw_interrupt_disable();
314 rt_strncpy(shell->password, password, FINSH_PASSWORD_MAX);
316
317 return RT_EOK;
318}
319
325const char *finsh_get_password(void)
326{
327 return shell->password;
328}
329
330static void finsh_wait_auth(void)
331{
332 int ch;
333 rt_bool_t input_finish = RT_FALSE;
334 char password[FINSH_PASSWORD_MAX] = { 0 };
335 rt_size_t cur_pos = 0;
336 /* password not set */
337 if (rt_strlen(finsh_get_password()) == 0) return;
338
339 while (1)
340 {
341 rt_kprintf("Password for login: ");
342 while (!input_finish)
343 {
344 while (1)
345 {
346 /* read one character from device */
347 ch = (int)finsh_getchar();
348 if (ch < 0)
349 {
350 continue;
351 }
352
353 if (ch >= ' ' && ch <= '~' && cur_pos < FINSH_PASSWORD_MAX)
354 {
355 /* change the printable characters to '*' */
356 rt_kprintf("*");
357 password[cur_pos++] = ch;
358 }
359 else if (ch == '\b' && cur_pos > 0)
360 {
361 /* backspace */
362 cur_pos--;
363 password[cur_pos] = '\0';
364 rt_kprintf("\b \b");
365 }
366 else if (ch == '\r' || ch == '\n')
367 {
368 rt_kprintf("\n");
369 input_finish = RT_TRUE;
370 break;
371 }
372 }
373 }
374 if (!rt_strncmp(shell->password, password, FINSH_PASSWORD_MAX)) return;
375 else
376 {
377 /* authentication failed, delay 2S for retry */
378 rt_thread_delay(2 * RT_TICK_PER_SECOND);
379 rt_kprintf("Sorry, try again.\n");
380 cur_pos = 0;
381 input_finish = RT_FALSE;
382 rt_memset(password, '\0', FINSH_PASSWORD_MAX);
383 }
384 }
385}
386#endif /* FINSH_USING_AUTH */
387
388static void shell_auto_complete(char *prefix)
389{
390 rt_kprintf("\n");
391 msh_auto_complete(prefix);
392
393#ifdef FINSH_USING_OPTION_COMPLETION
394 msh_opt_auto_complete(prefix);
395#endif
396
397 rt_kprintf("%s%s", FINSH_PROMPT, prefix);
398}
399
400#ifdef FINSH_USING_HISTORY
401static rt_bool_t shell_handle_history(struct finsh_shell *shell)
402{
403#if defined(_WIN32)
404 int i;
405 rt_kprintf("\r");
406
407 for (i = 0; i <= 60; i++)
408 putchar(' ');
409 rt_kprintf("\r");
410
411#else
412 rt_kprintf("\033[2K\r");
413#endif
414 rt_kprintf("%s%s", FINSH_PROMPT, shell->line);
415 return RT_FALSE;
416}
417
418static void shell_push_history(struct finsh_shell *shell)
419{
420 if (shell->line_position != 0)
421 {
422 /* push history */
423 if (shell->history_count >= FINSH_HISTORY_LINES)
424 {
425 /* if current cmd is same as last cmd, don't push */
426 if (memcmp(&shell->cmd_history[FINSH_HISTORY_LINES - 1], shell->line, FINSH_CMD_SIZE))
427 {
428 /* move history */
429 int index;
430 for (index = 0; index < FINSH_HISTORY_LINES - 1; index ++)
431 {
432 rt_memcpy(&shell->cmd_history[index][0],
433 &shell->cmd_history[index + 1][0], FINSH_CMD_SIZE);
434 }
435 rt_memset(&shell->cmd_history[index][0], 0, FINSH_CMD_SIZE);
436 rt_memcpy(&shell->cmd_history[index][0], shell->line, shell->line_position);
437
438 /* it's the maximum history */
439 shell->history_count = FINSH_HISTORY_LINES;
440 }
441 }
442 else
443 {
444 /* if current cmd is same as last cmd, don't push */
445 if (shell->history_count == 0 || memcmp(&shell->cmd_history[shell->history_count - 1], shell->line, FINSH_CMD_SIZE))
446 {
447 shell->current_history = shell->history_count;
448 rt_memset(&shell->cmd_history[shell->history_count][0], 0, FINSH_CMD_SIZE);
449 rt_memcpy(&shell->cmd_history[shell->history_count][0], shell->line, shell->line_position);
450
451 /* increase count and set current history position */
452 shell->history_count ++;
453 }
454 }
455 }
456 shell->current_history = shell->history_count;
457}
458#endif
459
460#ifdef RT_USING_HOOK
461static void (*_finsh_thread_entry_hook)(void);
462
470void finsh_thread_entry_sethook(void (*hook)(void))
471{
472 _finsh_thread_entry_hook = hook;
473}
474#endif /* RT_USING_HOOK */
475
476static void finsh_thread_entry(void *parameter)
477{
478 int ch;
479
480 RT_OBJECT_HOOK_CALL(_finsh_thread_entry_hook, ());
481
482 /* normal is echo mode */
483#ifndef FINSH_ECHO_DISABLE_DEFAULT
484 shell->echo_mode = 1;
485#else
486 shell->echo_mode = 0;
487#endif
488
489#if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
490 /* set console device as shell device */
491 if (shell->device == RT_NULL)
492 {
493 rt_device_t console = rt_console_get_device();
494 if (console)
495 {
496 finsh_set_device(console->parent.name);
497 }
498 }
499#endif /* !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE) */
500
501#ifdef FINSH_USING_AUTH
502 /* set the default password when the password isn't setting */
503 if (rt_strlen(finsh_get_password()) == 0)
504 {
505 if (finsh_set_password(FINSH_DEFAULT_PASSWORD) != RT_EOK)
506 {
507 rt_kprintf("Finsh password set failed.\n");
508 }
509 }
510 /* waiting authenticate success */
511 finsh_wait_auth();
512#endif
513
515
516 while (1)
517 {
518 ch = (int)finsh_getchar();
519 if (ch < 0)
520 {
521 continue;
522 }
523
524 /*
525 * handle control key
526 * up key : 0x1b 0x5b 0x41
527 * down key: 0x1b 0x5b 0x42
528 * right key:0x1b 0x5b 0x43
529 * left key: 0x1b 0x5b 0x44
530 */
531 if (ch == 0x1b)
532 {
533 shell->stat = WAIT_SPEC_KEY;
534 continue;
535 }
536 else if (shell->stat == WAIT_SPEC_KEY)
537 {
538 if (ch == 0x5b)
539 {
540 shell->stat = WAIT_FUNC_KEY;
541 continue;
542 }
543
544 shell->stat = WAIT_NORMAL;
545 }
546 else if (shell->stat == WAIT_FUNC_KEY)
547 {
548 shell->stat = WAIT_NORMAL;
549
550 if (ch == 0x41) /* up key */
551 {
552#ifdef FINSH_USING_HISTORY
553 /* prev history */
554 if (shell->current_history > 0)
555 shell->current_history --;
556 else
557 {
558 shell->current_history = 0;
559 continue;
560 }
561
562 /* copy the history command */
563 rt_memcpy(shell->line, &shell->cmd_history[shell->current_history][0],
565 shell->line_curpos = shell->line_position = (rt_uint16_t)strlen(shell->line);
566 shell_handle_history(shell);
567#endif
568 continue;
569 }
570 else if (ch == 0x42) /* down key */
571 {
572#ifdef FINSH_USING_HISTORY
573 /* next history */
574 if (shell->current_history < shell->history_count - 1)
575 shell->current_history ++;
576 else
577 {
578 /* set to the end of history */
579 if (shell->history_count != 0)
580 shell->current_history = shell->history_count - 1;
581 else
582 continue;
583 }
584
585 rt_memcpy(shell->line, &shell->cmd_history[shell->current_history][0],
587 shell->line_curpos = shell->line_position = (rt_uint16_t)strlen(shell->line);
588 shell_handle_history(shell);
589#endif
590 continue;
591 }
592 else if (ch == 0x44) /* left key */
593 {
594 if (shell->line_curpos)
595 {
596 rt_kprintf("\b");
597 shell->line_curpos --;
598 }
599
600 continue;
601 }
602 else if (ch == 0x43) /* right key */
603 {
604 if (shell->line_curpos < shell->line_position)
605 {
606 rt_kprintf("%c", shell->line[shell->line_curpos]);
607 shell->line_curpos ++;
608 }
609
610 continue;
611 }
612 }
613
614 /* received null or error */
615 if (ch == '\0' || ch == 0xFF) continue;
616 /* handle tab key */
617 else if (ch == '\t')
618 {
619 int i;
620 /* move the cursor to the beginning of line */
621 for (i = 0; i < shell->line_curpos; i++)
622 rt_kprintf("\b");
623
624 /* auto complete */
625 shell_auto_complete(&shell->line[0]);
626 /* re-calculate position */
627 shell->line_curpos = shell->line_position = (rt_uint16_t)strlen(shell->line);
628
629 continue;
630 }
631 /* handle backspace key */
632 else if (ch == 0x7f || ch == 0x08)
633 {
634 /* note that shell->line_curpos >= 0 */
635 if (shell->line_curpos == 0)
636 continue;
637
638 shell->line_position--;
639 shell->line_curpos--;
640
641 if (shell->line_position > shell->line_curpos)
642 {
643 int i;
644
645 rt_memmove(&shell->line[shell->line_curpos],
646 &shell->line[shell->line_curpos + 1],
647 shell->line_position - shell->line_curpos);
648 shell->line[shell->line_position] = 0;
649
650 rt_kprintf("\b%s \b", &shell->line[shell->line_curpos]);
651
652 /* move the cursor to the origin position */
653 for (i = shell->line_curpos; i <= shell->line_position; i++)
654 rt_kprintf("\b");
655 }
656 else
657 {
658 rt_kprintf("\b \b");
659 shell->line[shell->line_position] = 0;
660 }
661
662 continue;
663 }
664
665 /* handle end of line, break */
666 if (ch == '\r' || ch == '\n')
667 {
668#ifdef FINSH_USING_HISTORY
669 shell_push_history(shell);
670#endif
671 if (shell->echo_mode)
672 rt_kprintf("\n");
673 msh_exec(shell->line, shell->line_position);
674
676 rt_memset(shell->line, 0, sizeof(shell->line));
677 shell->line_curpos = shell->line_position = 0;
678 continue;
679 }
680
681 /* it's a large line, discard it */
682 if (shell->line_position >= FINSH_CMD_SIZE)
683 shell->line_position = 0;
684
685 /* normal character */
686 if (shell->line_curpos < shell->line_position)
687 {
688 int i;
689
690 rt_memmove(&shell->line[shell->line_curpos + 1],
691 &shell->line[shell->line_curpos],
692 shell->line_position - shell->line_curpos);
693 shell->line[shell->line_curpos] = ch;
694 if (shell->echo_mode)
695 rt_kprintf("%s", &shell->line[shell->line_curpos]);
696
697 /* move the cursor to new position */
698 for (i = shell->line_curpos; i < shell->line_position; i++)
699 rt_kprintf("\b");
700 }
701 else
702 {
703 shell->line[shell->line_position] = ch;
704 if (shell->echo_mode)
705 rt_kprintf("%c", ch);
706 }
707
708 ch = 0;
709 shell->line_position ++;
710 shell->line_curpos++;
711 if (shell->line_position >= FINSH_CMD_SIZE)
712 {
713 /* clear command line */
714 shell->line_position = 0;
715 shell->line_curpos = 0;
716 }
717 } /* end of device read */
718}
719
720static void finsh_system_function_init(const void *begin, const void *end)
721{
722 _syscall_table_begin = (struct finsh_syscall *) begin;
723 _syscall_table_end = (struct finsh_syscall *) end;
724}
725
726#if defined(__ICCARM__) || defined(__ICCRX__) /* for IAR compiler */
727#ifdef FINSH_USING_SYMTAB
728 #pragma section="FSymTab"
729#endif
730#elif defined(__ADSPBLACKFIN__) /* for VisaulDSP++ Compiler*/
731#ifdef FINSH_USING_SYMTAB
732 extern "asm" int __fsymtab_start;
733 extern "asm" int __fsymtab_end;
734#endif
735#elif defined(_MSC_VER)
736#pragma section("FSymTab$a", read)
737const char __fsym_begin_name[] = "__start";
738const char __fsym_begin_desc[] = "begin of finsh";
739__declspec(allocate("FSymTab$a")) const struct finsh_syscall __fsym_begin =
740{
741 __fsym_begin_name,
742 __fsym_begin_desc,
743 NULL
744};
745
746#pragma section("FSymTab$z", read)
747const char __fsym_end_name[] = "__end";
748const char __fsym_end_desc[] = "end of finsh";
749__declspec(allocate("FSymTab$z")) const struct finsh_syscall __fsym_end =
750{
751 __fsym_end_name,
752 __fsym_end_desc,
753 NULL
754};
755#endif
756
757/*
758 * @ingroup finsh
759 *
760 * This function will initialize finsh shell
761 */
763{
764 rt_err_t result = RT_EOK;
765 rt_thread_t tid;
766
767#ifdef FINSH_USING_SYMTAB
768#ifdef __ARMCC_VERSION /* ARM C Compiler */
769 extern const int FSymTab$$Base;
770 extern const int FSymTab$$Limit;
771 finsh_system_function_init(&FSymTab$$Base, &FSymTab$$Limit);
772#elif defined (__ICCARM__) || defined(__ICCRX__) /* for IAR Compiler */
773 finsh_system_function_init(__section_begin("FSymTab"),
774 __section_end("FSymTab"));
775#elif defined (__GNUC__) || defined(__TI_COMPILER_VERSION__) || defined(__TASKING__)
776 /* GNU GCC Compiler and TI CCS */
777 extern const int __fsymtab_start;
778 extern const int __fsymtab_end;
779 finsh_system_function_init(&__fsymtab_start, &__fsymtab_end);
780#elif defined(__ADSPBLACKFIN__) /* for VisualDSP++ Compiler */
781 finsh_system_function_init(&__fsymtab_start, &__fsymtab_end);
782#elif defined(_MSC_VER)
783 unsigned int *ptr_begin, *ptr_end;
784
785 if (shell)
786 {
787 rt_kprintf("finsh shell already init.\n");
788 return RT_EOK;
789 }
790
791 ptr_begin = (unsigned int *)&__fsym_begin;
792 ptr_begin += (sizeof(struct finsh_syscall) / sizeof(unsigned int));
793 while (*ptr_begin == 0) ptr_begin ++;
794
795 ptr_end = (unsigned int *) &__fsym_end;
796 ptr_end --;
797 while (*ptr_end == 0) ptr_end --;
798
799 finsh_system_function_init(ptr_begin, ptr_end);
800#endif
801#endif
802
803#ifdef RT_USING_HEAP
804 /* create or set shell structure */
805 shell = (struct finsh_shell *)rt_calloc(1, sizeof(struct finsh_shell));
806 if (shell == RT_NULL)
807 {
808 rt_kprintf("no memory for shell\n");
809 return -1;
810 }
812 finsh_thread_entry, RT_NULL,
814#else
815 shell = &_shell;
816 tid = &finsh_thread;
817 result = rt_thread_init(&finsh_thread,
819 finsh_thread_entry, RT_NULL,
820 &finsh_thread_stack[0], sizeof(finsh_thread_stack),
822#endif /* RT_USING_HEAP */
823
824 rt_sem_init(&(shell->rx_sem), "shrx", 0, 0);
826
827 if (tid != NULL && result == RT_EOK)
829 return 0;
830}
832
833#endif /* RT_USING_FINSH */
834
struct finsh_syscall * _syscall_table_end
struct finsh_syscall * _syscall_table_begin
定义 shell.c:50
rt_err_t rt_device_set_rx_indicate(rt_device_t dev, rt_err_t(*rx_ind)(rt_device_t dev, rt_size_t size))
#define RT_DEVICE_FLAG_INT_RX
#define RT_DEVICE_FLAG_STREAM
rt_ssize_t rt_device_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
rt_device_t rt_device_find(const char *name)
struct rt_device * rt_device_t
rt_err_t rt_device_close(rt_device_t dev)
rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
#define RT_DEVICE_OFLAG_RDWR
ssize_t read(int fd, void *buf, size_t len)
char * getcwd(char *buf, size_t size)
#define RT_WAITING_FOREVER
#define RT_OBJECT_HOOK_CALL(func, argv)
rt_weak void * rt_calloc(rt_size_t count, rt_size_t size)
This function will contiguously allocate enough space for count objects that are size bytes of memory...
#define rt_kprintf(...)
#define RT_ASSERT(EX)
rt_weak void rt_free(void *ptr)
This function will release the previously allocated memory block by rt_malloc. The released memory bl...
rt_weak void * rt_malloc(rt_size_t size)
Allocate a block of memory with a minimum of 'size' bytes.
rt_err_t rt_thread_startup(rt_thread_t thread)
This function will start a thread and put it to system ready queue.
rt_err_t rt_thread_delay(rt_tick_t tick)
This function will let current thread delay for some ticks.
rt_thread_t rt_thread_create(const char *name, void(*entry)(void *parameter), void *parameter, rt_uint32_t stack_size, rt_uint8_t priority, rt_uint32_t tick)
This function will create a thread object and allocate thread object memory. and stack.
rt_err_t rt_thread_init(struct rt_thread *thread, const char *name, void(*entry)(void *parameter), void *parameter, void *stack_start, rt_uint32_t stack_size, rt_uint8_t priority, rt_uint32_t tick)
This function will initialize a thread. It's used to initialize a static thread object.
struct rt_thread * rt_thread_t
void finsh_set_device(const char *device_name)
void finsh_thread_entry_sethook(void(*hook)(void))
This function set a hook function at the entry of finsh thread
rt_uint32_t finsh_get_echo()
rt_uint32_t finsh_get_prompt_mode(void)
void finsh_set_prompt_mode(rt_uint32_t prompt_mode)
void finsh_set_echo(rt_uint32_t echo)
const char * finsh_get_device()
rt_err_t rt_sem_init(rt_sem_t sem, const char *name, rt_uint32_t value, rt_uint8_t flag)
This function will initialize a static semaphore object.
定义 ipc.c:376
rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t time)
定义 ipc.c:644
rt_err_t rt_sem_release(rt_sem_t sem)
This function will release a semaphore. If there is thread suspended on the semaphore,...
定义 ipc.c:695
rt_align(RT_ALIGN_SIZE)
This function sets a hook function to idle thread loop. When the system performs idle loop,...
定义 idle.c:48
int msh_exec(char *cmd, rt_size_t length)
定义 msh.c:540
void msh_auto_complete(char *prefix)
定义 msh.c:775
#define INIT_APP_EXPORT(fn)
void rt_hw_interrupt_enable(rt_base_t level)
rt_base_t rt_hw_interrupt_disable(void)
rt_int32_t rt_base_t
int rt_bool_t
rt_base_t rt_err_t
unsigned char rt_uint8_t
unsigned short rt_uint16_t
#define RT_TRUE
rt_ubase_t rt_size_t
unsigned int rt_uint32_t
#define RT_FALSE
#define RT_NULL
int finsh_system_init(void)
const char * finsh_get_prompt(void)
定义 shell.c:95
int finsh_set_prompt(const char *prompt)
定义 shell.c:71
struct finsh_shell * shell
定义 shell.c:54
#define _MSH_PROMPT
定义 shell.c:93
int finsh_getchar(void)
@ WAIT_FUNC_KEY
定义 shell.h:59
@ WAIT_NORMAL
定义 shell.h:57
@ WAIT_SPEC_KEY
定义 shell.h:58
#define FINSH_CMD_SIZE
定义 shell.h:24
#define FINSH_THREAD_NAME
定义 shell.h:52
#define FINSH_THREAD_PRIORITY
定义 shell.h:18
#define FINSH_PROMPT
定义 shell.h:29
#define FINSH_THREAD_STACK_SIZE
定义 shell.h:21
struct rt_object parent
const char * name