📄 shell.c.svn-base
字号:
/* * File : finsh.c * This file is part of RT-Thread RTOS * COPYRIGHT (C) 2006, RT-Thread Development Team * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at * http://www.fayfayspace.org/license/LICENSE. * * Change Logs: * Date Author Notes * 2006-04-30 Bernard the first verion for FinSH * 2006-05-08 Bernard change finsh thread stack to 2048 * 2006-06-03 Bernard Add support for skyeye */#include <rtthread.h>#include <rthw.h>#include "finsh.h"#define INTUART0_RX 5#define UARTSTAT0 (*(volatile unsigned int *)0x3ffd008)#define UARTRXB0 (*(volatile unsigned int *)0x3ffd010)#define USTAT_RCV_READY 0x20 /* receive data ready */#define USTAT_TXB_EMPTY 0x40 /* tx buffer empty *//* finsh thread */struct rt_thread finsh_thread;char finsh_thread_stack[2048];struct rt_semaphore uart_sem;void* memset(void * dst, int s, size_t count){ register char * a = dst; count++; while (--count) *a++ = s; return dst;}void *memccpy(void *dst, const void *src, int c, size_t count){ char *a = dst; const char *b = src; while (count--) { *a++ = *b; if (*b==c) { return (void *)a; } b++; } return 0;}size_t strlen(const char *s){ register size_t i; if (!s) return 0; for (i=0; *s; ++s) ++i; return i;}char *strncpy(char *dest, const char *src, size_t n){ memset(dest, 0, n); memccpy(dest, src, 0, n); return dest;}int strcmp (const char *s1, const char *s2){ while (*s1 && *s1 == *s2) s1++, s2++; return (*s1 - *s2);}int strncmp(const char *s1, const char *s2, size_t n){ register const unsigned char* a=(const unsigned char*)s1; register const unsigned char* b=(const unsigned char*)s2; register const unsigned char* fini=a+n; while (a<fini) { register int res=*a-*b; if (res) return res; if (!*a) return 0; ++a; ++b; } return 0;}int isalpha( int ch ){ return (unsigned int)((ch | 0x20) - 'a') < 26u;}int atoi(const char* s){ long int v=0; int sign=1; while ( *s == ' ' || (unsigned int)(*s - 9) < 5u) s++; switch (*s) { case '-': sign=-1; case '+': ++s; } while ((unsigned int) (*s - '0') < 10u) { v=v*10+*s-'0'; ++s; } return sign==-1?-v:v;}int isprint(unsigned char ch){ return (unsigned int)(ch - ' ') < 127u - ' ';}void finsh_thread_entry(void* parameter){ struct finsh_parser parser; char line[256]; int pos ; finsh_init(&parser); while (1) { rt_kprintf("finsh>>"); memset(line, 0, sizeof(line)); pos = 0; while (1) { if (rt_sem_take(&uart_sem, -1) == RT_EOK) { /* read one character from UART0 */ while ((UARTSTAT0 & USTAT_RCV_READY) == 0); line[pos] = UARTRXB0; rt_kprintf("%c", line[pos]); /* if it's the end of line, break */ if (line[pos] == 0xd || line[pos] == 0xa) { /* change to ';' and break */ line[pos] = ';'; break; } pos ++; } } finsh_parser_run(&parser, (unsigned char*)&line[0]); /* compile node root */ if (finsh_errno() == 0) { finsh_compiler_run(parser.root); } else { rt_kprintf("%s\n", finsh_error_string(finsh_errno())); } /* run virtual machine */ if (finsh_errno() == 0) { finsh_vm_run(); if (isprint((unsigned char)finsh_stack_bottom())) { rt_kprintf("\t'%c', %d, 0x%lu\n", (unsigned char)finsh_stack_bottom(), (unsigned int)finsh_stack_bottom(), (unsigned int)finsh_stack_bottom()); } else { rt_kprintf("\t%d, 0x%04x\n", (unsigned int)finsh_stack_bottom(), (unsigned int)finsh_stack_bottom()); } } finsh_flush(&parser); }}void uart_isr(int vector){ rt_sem_release(&uart_sem);}/* init finsh */void finsh_system_init(){ rt_thread_init(&finsh_thread, "tshell", finsh_thread_entry, RT_NULL, &finsh_thread_stack[0], sizeof(finsh_thread_stack), 80, 100); rt_thread_startup(&finsh_thread); /* install UART isr */ rt_sem_init(&uart_sem, "uart", 0, 0); rt_hw_interrupt_install(INTUART0_RX, uart_isr, RT_NULL); rt_hw_interrupt_umask(INTUART0_RX);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -