RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
shell.c 文件参考
#include <rthw.h>
#include <string.h>
#include <stdio.h>
#include "shell.h"
#include "msh.h"
+ shell.c 的引用(Include)关系图:

浏览该文件的源代码.

宏定义

#define _MSH_PROMPT   "msh "
 

函数

int finsh_set_prompt (const char *prompt)
 
const char * finsh_get_prompt (void)
 
rt_uint32_t finsh_get_prompt_mode (void)
 
void finsh_set_prompt_mode (rt_uint32_t prompt_mode)
 
int finsh_getchar (void)
 
void finsh_set_device (const char *device_name)
 
const char * finsh_get_device ()
 
void finsh_set_echo (rt_uint32_t echo)
 
rt_uint32_t finsh_get_echo ()
 
void finsh_thread_entry_sethook (void(*hook)(void))
 
int finsh_system_init (void)
 
 INIT_APP_EXPORT (finsh_system_init)
 

变量

struct finsh_syscall_syscall_table_begin = NULL
 
struct finsh_syscall_syscall_table_end = NULL
 
struct finsh_shellshell
 

宏定义说明

◆ _MSH_PROMPT

#define _MSH_PROMPT   "msh "

在文件 shell.c93 行定义.

函数说明

◆ finsh_set_prompt()

int finsh_set_prompt ( const char * prompt)

在文件 shell.c71 行定义.

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}
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.
#define RT_NULL

引用了 rt_free(), rt_malloc() , 以及 RT_NULL.

+ 函数调用图:

◆ finsh_get_prompt()

const char * finsh_get_prompt ( void )

在文件 shell.c95 行定义.

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}
char * getcwd(char *buf, size_t size)
struct finsh_shell * shell
定义 shell.c:54
#define _MSH_PROMPT
定义 shell.c:93

引用了 _MSH_PROMPT, getcwd() , 以及 shell.

+ 函数调用图:

◆ finsh_getchar()

int finsh_getchar ( void )

在文件 shell.c157 行定义.

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}
rt_ssize_t rt_device_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
struct rt_device * rt_device_t
ssize_t read(int fd, void *buf, size_t len)
#define RT_WAITING_FOREVER
#define RT_ASSERT(EX)
rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t time)
定义 ipc.c:644

引用了 read(), RT_ASSERT, rt_device_read(), RT_NULL, rt_sem_take(), RT_WAITING_FOREVER , 以及 shell.

+ 函数调用图:

◆ finsh_system_init()

int finsh_system_init ( void )

在文件 shell.c762 行定义.

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}
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(...)
rt_err_t rt_thread_startup(rt_thread_t thread)
This function will start a thread and put it to system ready queue.
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_prompt_mode(rt_uint32_t prompt_mode)
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_base_t rt_err_t
#define FINSH_THREAD_NAME
定义 shell.h:52
#define FINSH_THREAD_PRIORITY
定义 shell.h:18
#define FINSH_THREAD_STACK_SIZE
定义 shell.h:21

引用了 finsh_set_prompt_mode(), FINSH_THREAD_NAME, FINSH_THREAD_PRIORITY, FINSH_THREAD_STACK_SIZE, rt_calloc(), rt_kprintf, RT_NULL, rt_sem_init(), rt_thread_create(), rt_thread_init(), rt_thread_startup() , 以及 shell.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ INIT_APP_EXPORT()

INIT_APP_EXPORT ( finsh_system_init )

引用了 finsh_system_init().

+ 函数调用图:

变量说明

◆ _syscall_table_begin

struct finsh_syscall* _syscall_table_begin = NULL

在文件 shell.c50 行定义.

◆ _syscall_table_end

struct finsh_syscall* _syscall_table_end = NULL

在文件 shell.c51 行定义.

◆ shell

struct finsh_shell* shell

在文件 shell.c54 行定义.