📄 shell.c
字号:
/*
* shell.c - demo of shell command
*
* Author: yu feng <progeryf@gmail.com>
* Date: 2007-5-27
*/
#include "my_string.h"
#include "my_printf.h"
#include "command.h"
#include "uart.h"
#include "xmodem.h"
#define download_addr 0x8000
/*get a char from shell*/
char shell_getchar()
{
char tempch;
uart_getchar( UART0_BASE, &tempch );
return tempch;
}
/*put a char to shell*/
char shell_putchar( char ch )
{
uart_putchar( UART0_BASE, ch );
return ch;
}
/* shell get a line from user input to uart0 */
int shell_gets( char * buf )
{
register char c;
register char * s;
for (s = buf; ((c = shell_getchar()) != '\n') && (c != '\r'); )
{
if(c == '\b') //back space
{
if(s > buf)
{
shell_putchar( '\b' );
shell_putchar( ' ' );
shell_putchar( '\b' );
s--;
}
else
{
shell_putchar( '\a' ); // Attention bell
}
}
else //echo back
{
shell_putchar( c );
*s++ = c;
}
}
shell_putchar( '\r' ); // echo a new line back
shell_putchar( '\n' );
*s = '\0';
return (s-buf);
}
/* shell get a line from user input to uart0 */
int shell_readline( char * buf )
{
register char c;
register char * s;
// do not echo
for (s = buf; ((c = shell_getchar()) != '\n') && (c != '\r'); *s++ = c) ;
*s = '\0';
return (s-buf);
}
/* an endless loop for shell command interpreter */
void shell_command( void )
{
char command_buf[256];
while( 1 )
{
// Prompt of lumit shell
my_printf( "\rFree-boot> " );
// empty the command buffer
my_strcpy( command_buf, "" );
// get a line from user input
shell_gets( command_buf );
my_printf( "\rGet Command: <%s> [len=%d] \n\r", command_buf, my_strlen(command_buf) );
// compare if we can interprete this command
if( my_strcmp( command_buf, "help" ) == 0 )
help();
else
if( my_strcmp( command_buf, "dn" ) == 0 )
xmodem_receive();
else
if( my_strcmp( command_buf, "go" ) == 0 )
go();
else
if( my_strcmp( command_buf, "dump" ) == 0 )
dump();
else
if( my_strcmp( command_buf, "flashw" ) == 0 )
flashw();
else
if( my_strcmp( command_buf, "flashl" ) == 0 )
{
flashl();
// ((void (*)(void))(download_addr)) ();
}
else
if( my_strlen( command_buf ) != 0 )
my_printf( "\rUnknow Command! \n" );
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -